Skip to content

Commit 9d32624

Browse files
AngelCastilloBrhyslbw
authored andcommitted
fix(hardware-trezor): matchSigningMode now also takes into account requiredSigners field
1 parent ec23c9e commit 9d32624

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

packages/hardware-trezor/src/TrezorKeyAgent.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,14 @@ const multiSigWitnessPaths: BIP32Path[] = [
9292

9393
const isMultiSig = (tx: Omit<Trezor.CardanoSignTransaction, 'signingMode'>): boolean => {
9494
const allThirdPartyInputs = !tx.inputs.some((input) => input.path);
95+
const allThirdRequiredSigner = !tx.requiredSigners?.some((signer) => signer.keyPath);
9596
// Trezor doesn't allow change outputs to address controlled by your keys and instead you have to use script address for change out
9697
const allThirdPartyOutputs = !tx.outputs.some((out) => 'addressParameters' in out);
9798

9899
return (
99100
allThirdPartyInputs &&
100101
allThirdPartyOutputs &&
102+
allThirdRequiredSigner &&
101103
!tx.collateralInputs &&
102104
!tx.collateralReturn &&
103105
!tx.totalCollateral &&
@@ -325,7 +327,9 @@ export class TrezorKeyAgent extends KeyAgentBase {
325327
const signedData = result.payload;
326328

327329
if (!areStringsEqualInConstantTime(signedData.hash, hash)) {
328-
throw new errors.HwMappingError('Trezor computed a different transaction id');
330+
throw new errors.HwMappingError(
331+
`Trezor computed a different transaction id: ${signedData.hash} than expected: ${hash}`
332+
);
329333
}
330334

331335
return new Map<Crypto.Ed25519PublicKeyHex, Crypto.Ed25519SignatureHex>(
@@ -340,7 +344,7 @@ export class TrezorKeyAgent extends KeyAgentBase {
340344
)
341345
);
342346
} catch (error: any) {
343-
if (error.innerError.code === 'Failure_ActionCancelled') {
347+
if (error.innerError?.code === 'Failure_ActionCancelled') {
344348
throw new errors.AuthenticationError('Transaction signing aborted', error);
345349
}
346350
throw transportTypedError(error);

packages/hardware-trezor/test/TrezorKeyAgent.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ describe('TrezorKeyAgent', () => {
125125
expect(signingMode).toEqual(Trezor.PROTO.CardanoTxSigningMode.ORDINARY_TRANSACTION);
126126
});
127127

128+
it('can detect ordinary transaction signing mode when we own a required signer', async () => {
129+
const signingMode = TrezorKeyAgent.matchSigningMode({
130+
...validMultisigTx,
131+
requiredSigners: [{ keyPath: knownAddressKeyPath }]
132+
});
133+
expect(signingMode).toEqual(Trezor.PROTO.CardanoTxSigningMode.ORDINARY_TRANSACTION);
134+
});
135+
128136
it('can detect pool registrations signing mode', async () => {
129137
const signingMode = TrezorKeyAgent.matchSigningMode({
130138
...simpleTx,

0 commit comments

Comments
 (0)