Skip to content

Commit

Permalink
fix: transport lost during signOperation
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Prohaszka <stephane.prohaszka@ledger.fr>
  • Loading branch information
sprohaszka-ledger committed May 3, 2024
1 parent 495b213 commit eec3be5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 37 deletions.
82 changes: 46 additions & 36 deletions libs/coin-modules/coin-tezos/src/bridge/signOperation.ts
Expand Up @@ -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" });

Expand Down
2 changes: 1 addition & 1 deletion libs/ledger-live-common/src/families/tezos/setup.ts
Expand Up @@ -33,7 +33,7 @@ const createSigner: CreateSigner<TezosSigner> = (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);
},
};
};
Expand Down

0 comments on commit eec3be5

Please sign in to comment.