Skip to content

Commit

Permalink
Add option to sign transaction hash with Ledger device (#838)
Browse files Browse the repository at this point in the history
  • Loading branch information
quietbits authored Apr 30, 2024
1 parent ed2094d commit 7f26d29
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/actions/transactionSigner.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const ALBEDO_WALLET_SIGN_START = "ALBEDO_WALLET_SIGN_START";
export const ALBEDO_WALLET_SIGN_SUCCESS = "ALBEDO_WALLET_SIGN_SUCCESS";
export const ALBEDO_WALLET_SIGN_ERROR = "ALBEDO_WALLET_SIGN_ERROR";

export function signWithLedger(txXDR, bipPath, networkPassphrase) {
export function signWithLedger(txXDR, bipPath, networkPassphrase, isHash) {
return (dispatch) => {
dispatch({ type: LEDGER_WALLET_SIGN_START });

Expand All @@ -77,9 +77,15 @@ export function signWithLedger(txXDR, bipPath, networkPassphrase) {
ledgerApi
.getPublicKey(bipPath)
.then((result) => (publicKey = result.publicKey))
.then(() =>
ledgerApi.signTransaction(bipPath, transaction.signatureBase()),
)
.then(() => {
if (isHash) {
return ledgerApi.signHash(bipPath, transaction.hash());
}
return ledgerApi.signTransaction(
bipPath,
transaction.signatureBase(),
);
})
.then((result) => {
let { signature } = result;
let keyPair = Keypair.fromPublicKey(publicKey);
Expand Down
11 changes: 11 additions & 0 deletions src/views/TransactionSigner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,17 @@ export const TransactionSigner = () => {
>
Sign with Ledger
</button>
<button
className="s-button"
data-testid="transaction-signer-ledger-sign-button"
onClick={() => {
dispatch(
signWithLedger(xdr, bipPath, networkPassphrase, true),
);
}}
>
Sign hash with Ledger
</button>
<button
className="s-button"
data-testid="transaction-signer-trezor-sign-button"
Expand Down

0 comments on commit 7f26d29

Please sign in to comment.