Skip to content

Commit

Permalink
fix(hardware-trezor): fix trezor tx signing LW-6522
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikGuzei committed Oct 19, 2023
1 parent e8a2e87 commit 0f6cff0
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions packages/hardware-trezor/src/TrezorKeyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
SerializableTrezorKeyAgentData,
SignBlobResult,
TrezorConfig,
errors
errors,
util
} from '@cardano-sdk/key-management';
import { txToTrezor } from './transformers/tx';
import TrezorConnectWeb from '@trezor/connect-web';
Expand Down Expand Up @@ -175,6 +176,13 @@ export class TrezorKeyAgent extends KeyAgentBase {
...trezorTxData,
signingMode
});

const expectedPublicKeys = await Promise.all(
(
await util.ownSignatureKeyPaths(tx.body, this.knownAddresses, this.inputResolver)
).map((derivationPath) => this.derivePublicKey(derivationPath))
);

if (!result.success) {
throw new errors.TransportError('Failed to export extended account public key', result.payload);
}
Expand All @@ -187,11 +195,13 @@ export class TrezorKeyAgent extends KeyAgentBase {

return new Map<Crypto.Ed25519PublicKeyHex, Crypto.Ed25519SignatureHex>(
await Promise.all(
signedData.witnesses.map(async (witness) => {
const publicKey = Crypto.Ed25519PublicKeyHex(witness.pubKey);
const signature = Crypto.Ed25519SignatureHex(witness.signature);
return [publicKey, signature] as const;
})
signedData.witnesses
.filter((witness) => expectedPublicKeys.includes(Crypto.Ed25519PublicKeyHex(witness.pubKey)))
.map(async (witness) => {
const publicKey = Crypto.Ed25519PublicKeyHex(witness.pubKey);
const signature = Crypto.Ed25519SignatureHex(witness.signature);
return [publicKey, signature] as const;
})
)
);
} catch (error: any) {
Expand Down

0 comments on commit 0f6cff0

Please sign in to comment.