diff --git a/libs/coin-modules/coin-tezos/src/bridge/signOperation.ts b/libs/coin-modules/coin-tezos/src/bridge/signOperation.ts index d65081d41165..81d0f031c7cd 100644 --- a/libs/coin-modules/coin-tezos/src/bridge/signOperation.ts +++ b/libs/coin-modules/coin-tezos/src/bridge/signOperation.ts @@ -121,45 +121,55 @@ const buildSignOperation = const tezos = new TezosToolkit(getEnv("API_TEZOS_NODE")); - const ledgerSigner = (await signerContext(deviceId, signer => - Promise.resolve(signer.createLedgerSigner(freshAddressPath, false, 0)), - )) as LedgerSigner; - - tezos.setProvider({ signer: ledgerSigner }); - - const publicKey = await ledgerSigner.publicKey(); - const publicKeyHash = await ledgerSigner.publicKeyHash(); - - const { rpc } = tezos; - const block = await rpc.getBlock(); - const sourceData = await rpc.getContract(freshAddress); - - o.next({ type: "device-signature-requested" }); + const signedInfo = await signerContext(deviceId, async signer => { + const ledgerSigner = signer.createLedgerSigner(freshAddressPath, false, 0); + + tezos.setProvider({ signer: ledgerSigner }); + + const publicKey = await ledgerSigner.publicKey(); + const publicKeyHash = await ledgerSigner.publicKeyHash(); + + const { rpc } = tezos; + const block = await rpc.getBlock(); + const sourceData = await rpc.getContract(freshAddress); + + o.next({ type: "device-signature-requested" }); + + if (cancelled) { + return; + } + + const { type, contents } = await getOperationContents({ + account: account as TezosAccount, + transaction, + tezos, + counter: Number(sourceData.counter), + public_key: publicKey, + public_key_hash: publicKeyHash, + }); + + const forgedBytes = await rpc.forgeOperations({ + branch: block.hash, + contents, + }); + + // 0x03 is a conventional prefix (aka a watermark) for tezos transactions + const signature = await ledgerSigner.sign( + Buffer.concat([Buffer.from("03", "hex"), Buffer.from(forgedBytes, "hex")]).toString( + "hex", + ), + ); + + return { + type, + signature, + }; + }); - if (cancelled) { + if (!signedInfo) { return; } - - const { type, contents } = await getOperationContents({ - account: account as TezosAccount, - transaction, - tezos, - counter: Number(sourceData.counter), - public_key: publicKey, - public_key_hash: publicKeyHash, - }); - - const forgedBytes = await rpc.forgeOperations({ - branch: block.hash, - contents, - }); - - // 0x03 is a conventional prefix (aka a watermark) for tezos transactions - const signature = await ledgerSigner.sign( - Buffer.concat([Buffer.from("03", "hex"), Buffer.from(forgedBytes, "hex")]).toString( - "hex", - ), - ); + const { type, signature } = signedInfo; o.next({ type: "device-signature-granted" }); diff --git a/libs/ledger-live-common/src/families/tezos/setup.ts b/libs/ledger-live-common/src/families/tezos/setup.ts index 9294778c0e9a..cf7c57d47511 100644 --- a/libs/ledger-live-common/src/families/tezos/setup.ts +++ b/libs/ledger-live-common/src/families/tezos/setup.ts @@ -33,7 +33,7 @@ const createSigner: CreateSigner = (transport: Transport) => { ) => xtz.signOperation(path, rawTxHex, options), // Tezos [LedgerSigner](https://www.npmjs.com/package/@taquito/ledger-signer) createLedgerSigner: (path: string, prompt: boolean, derivationType: DerivationType) => { - return new LedgerSigner(xtz.transport, path, prompt, derivationType); + return new LedgerSigner(transport, path, prompt, derivationType); }, }; };