Skip to content

Commit 1e88a96

Browse files
authored
Merge pull request #1667 from input-output-hk/feat/lw-13641-fix-ledger-hw-mapping
fix(hardware-ledger): fix ledger hardware wallet mapping when there are reference inputs and no collateral [LW-13641]
2 parents 7ec7f87 + 8c1f5cc commit 1e88a96

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

packages/hardware-ledger/src/LedgerKeyAgent.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@ export class LedgerKeyAgent extends KeyAgentBase {
703703
* Ledger has certain limitations due to which it cannot sign arbitrary combination of all transaction features.
704704
* The mode specifies which use-case the user want to use and triggers additional validation on `tx` field.
705705
*/
706+
// eslint-disable-next-line complexity
706707
static getSigningMode(tx: Transaction): TransactionSigningMode {
707708
if (tx.certificates) {
708709
for (const cert of tx.certificates) {
@@ -726,7 +727,11 @@ export class LedgerKeyAgent extends KeyAgentBase {
726727
* VotingProcedures: We are currently supporting only keyHash and scriptHash voter types in voting procedures.
727728
* To sign tx with keyHash and scriptHash voter type we have to use PLUTUS_TRANSACTION signing mode
728729
*/
729-
if (tx.collateralInputs || LedgerKeyAgent.isKeyHashOrScriptHashVoter(tx.votingProcedures)) {
730+
if (
731+
tx.collateralInputs ||
732+
LedgerKeyAgent.isKeyHashOrScriptHashVoter(tx.votingProcedures) ||
733+
(tx.referenceInputs && tx.referenceInputs.length > 0)
734+
) {
730735
return TransactionSigningMode.PLUTUS_TRANSACTION;
731736
}
732737

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,49 @@ describe('LedgerKeyAgent', () => {
313313
expect(LedgerKeyAgent.getSigningMode(tx)).toEqual(Ledger.TransactionSigningMode.PLUTUS_TRANSACTION);
314314
});
315315

316+
it('can detect plutus transaction signing mode if there is a reference input', async () => {
317+
const tx: Ledger.Transaction = {
318+
fee: 10n,
319+
includeNetworkId: false,
320+
inputs: [
321+
{
322+
outputIndex: 0,
323+
path: [util.harden(CardanoKeyConst.PURPOSE), util.harden(CardanoKeyConst.COIN_TYPE), util.harden(0), 1, 0],
324+
txHashHex: '0f3abbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0e78f19d9d5'
325+
}
326+
],
327+
network: {
328+
networkId: Ledger.Networks.Testnet.networkId,
329+
protocolMagic: 999
330+
},
331+
outputs: [
332+
{
333+
amount: 10n,
334+
datumHashHex: '0f3abbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0e78f19d9d5',
335+
destination: {
336+
params: {
337+
addressHex:
338+
'009493315cd92eb5d8c4304e67b7e16ae36d61d34502694657811a2c8e32c728d3861e164cab28cb8f006448139c8f1740ffb8e7aa9e5232dc'
339+
},
340+
type: Ledger.TxOutputDestinationType.THIRD_PARTY
341+
},
342+
format: Ledger.TxOutputFormat.ARRAY_LEGACY
343+
}
344+
],
345+
referenceInputs: [
346+
{
347+
outputIndex: 0,
348+
path: [util.harden(CardanoKeyConst.PURPOSE), util.harden(CardanoKeyConst.COIN_TYPE), util.harden(0), 1, 0],
349+
txHashHex: '0f3abbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0e78f19d9d5'
350+
}
351+
],
352+
ttl: 1000,
353+
validityIntervalStart: 100
354+
};
355+
356+
expect(LedgerKeyAgent.getSigningMode(tx)).toEqual(Ledger.TransactionSigningMode.PLUTUS_TRANSACTION);
357+
});
358+
316359
it('can detect multisig transaction signing mode', async () => {
317360
const tx: Ledger.Transaction = {
318361
certificates: [

0 commit comments

Comments
 (0)