Skip to content

Commit 194c4db

Browse files
fix(hardware-trezor): matchSigningMode now also takes into account requiredSigners field
1 parent d1fc834 commit 194c4db

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
@@ -76,12 +76,14 @@ const multiSigWitnessPaths: BIP32Path[] = [
7676

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

8283
return (
8384
allThirdPartyInputs &&
8485
allThirdPartyOutputs &&
86+
allThirdRequiredSigner &&
8587
!tx.collateralInputs &&
8688
!tx.collateralReturn &&
8789
!tx.totalCollateral &&
@@ -291,7 +293,9 @@ export class TrezorKeyAgent extends KeyAgentBase {
291293
const signedData = result.payload;
292294

293295
if (!areStringsEqualInConstantTime(signedData.hash, hash)) {
294-
throw new errors.HwMappingError('Trezor computed a different transaction id');
296+
throw new errors.HwMappingError(
297+
`Trezor computed a different transaction id: ${signedData.hash} than expected: ${hash}`
298+
);
295299
}
296300

297301
return new Map<Crypto.Ed25519PublicKeyHex, Crypto.Ed25519SignatureHex>(
@@ -306,7 +310,7 @@ export class TrezorKeyAgent extends KeyAgentBase {
306310
)
307311
);
308312
} catch (error: any) {
309-
if (error.innerError.code === 'Failure_ActionCancelled') {
313+
if (error.innerError?.code === 'Failure_ActionCancelled') {
310314
throw new errors.AuthenticationError('Transaction signing aborted', error);
311315
}
312316
throw transportTypedError(error);

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

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

124+
it('can detect ordinary transaction signing mode when we own a required signer', async () => {
125+
const signingMode = TrezorKeyAgent.matchSigningMode({
126+
...validMultisigTx,
127+
requiredSigners: [{ keyPath: knownAddressKeyPath }]
128+
});
129+
expect(signingMode).toEqual(Trezor.PROTO.CardanoTxSigningMode.ORDINARY_TRANSACTION);
130+
});
131+
124132
it('can detect pool registrations signing mode', async () => {
125133
const signingMode = TrezorKeyAgent.matchSigningMode({
126134
...simpleTx,

0 commit comments

Comments
 (0)