Skip to content

Commit 98230e2

Browse files
AngelCastilloBrhyslbw
authored andcommitted
fix(hardware-ledger): getSigningMode now also takes into account requiredSigners field
1 parent c018743 commit 98230e2

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

packages/hardware-ledger/src/LedgerKeyAgent.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import _LedgerConnection, {
5353
Transaction,
5454
TransactionSigningMode,
5555
TxOutputDestinationType,
56+
TxRequiredSignerType,
5657
VoterType,
5758
VoterVotes
5859
} from '@cardano-foundation/ledgerjs-hw-app-cardano';
@@ -207,10 +208,12 @@ const isMultiSig = (tx: Transaction): boolean => {
207208
const result = false;
208209

209210
const allThirdPartyInputs = !tx.inputs.some((input) => input.path !== null);
211+
const allThirdPartyRequiredSigner = !tx.requiredSigners?.some((signer) => signer.type === TxRequiredSignerType.PATH);
210212
// Ledger doesn't allow change outputs to address controlled by your keys and instead you have to use script address for change out
211213
const allThirdPartyOutputs = !tx.outputs.some((out) => out.destination.type !== TxOutputDestinationType.THIRD_PARTY);
212214

213215
if (
216+
allThirdPartyRequiredSigner &&
214217
allThirdPartyInputs &&
215218
allThirdPartyOutputs &&
216219
!tx.collateralInputs &&

packages/hardware-ledger/test/LedgerKeyAgent.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,56 @@ describe('LedgerKeyAgent', () => {
359359

360360
expect(LedgerKeyAgent.getSigningMode(tx)).toEqual(Ledger.TransactionSigningMode.MULTISIG_TRANSACTION);
361361
});
362+
363+
it('can detect ordinary transaction signing mode when we own a required signer', async () => {
364+
const tx: Ledger.Transaction = {
365+
certificates: [
366+
{
367+
params: {
368+
stakeCredential: {
369+
scriptHashHex: 'cb0ec2692497b458e46812c8a5bfa2931d1a2d965a99893828ec810f',
370+
type: Ledger.CredentialParamsType.SCRIPT_HASH
371+
}
372+
},
373+
type: Ledger.CertificateType.STAKE_DEREGISTRATION
374+
}
375+
],
376+
fee: 10n,
377+
includeNetworkId: false,
378+
inputs: [
379+
{
380+
outputIndex: 0,
381+
path: null,
382+
txHashHex: '0f3abbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0e78f190000'
383+
}
384+
],
385+
network: {
386+
networkId: Ledger.Networks.Testnet.networkId,
387+
protocolMagic: 999
388+
},
389+
outputs: [
390+
{
391+
amount: 10n,
392+
datumHashHex: '0f3abbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0e78f19d9d5',
393+
destination: {
394+
params: {
395+
addressHex:
396+
'009493315cd92eb5d8c4304e67b7e16ae36d61d34502694657811a2c8e32c728d3861e164cab28cb8f006448139c8f1740ffb8e7aa9e5232dc'
397+
},
398+
type: Ledger.TxOutputDestinationType.THIRD_PARTY
399+
},
400+
format: Ledger.TxOutputFormat.ARRAY_LEGACY
401+
}
402+
],
403+
requiredSigners: [
404+
{ path: [util.harden(1852), util.harden(1815), util.harden(0), 2, 0], type: Ledger.TxRequiredSignerType.PATH }
405+
],
406+
ttl: 1000,
407+
validityIntervalStart: 100
408+
};
409+
410+
expect(LedgerKeyAgent.getSigningMode(tx)).toEqual(Ledger.TransactionSigningMode.ORDINARY_TRANSACTION);
411+
});
362412
});
363413

364414
describe('Unsupported Transaction Errors', () => {

0 commit comments

Comments
 (0)