Skip to content

Commit bf355c1

Browse files
fix: ledger hardware wallets can now create byron era outputs
1 parent d1fc834 commit bf355c1

File tree

5 files changed

+62
-1
lines changed

5 files changed

+62
-1
lines changed

packages/core/src/Cardano/util/isScriptAddress.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { Address, CredentialType, PaymentAddress } from '../Address';
22

33
export const isScriptAddress = (address: PaymentAddress): boolean => {
4+
if (!Address.isValidBech32(address)) {
5+
return false;
6+
}
7+
48
const baseAddress = Address.fromBech32(address).asBase();
59
const paymentCredential = baseAddress?.getPaymentCredential();
610
const stakeCredential = baseAddress?.getStakeCredential();

packages/hardware-ledger/src/transformers/txOut.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,15 @@ const toDestination: Transform<Cardano.TxOut, Ledger.TxOutputDestination, Ledger
4040
};
4141
}
4242

43+
const address = Cardano.Address.fromString(txOut.address);
44+
45+
if (!address) {
46+
throw new InvalidArgumentError('txOut', 'Invalid address format.');
47+
}
48+
4349
return {
4450
params: {
45-
addressHex: Cardano.Address.fromBech32(txOut.address).toBytes()
51+
addressHex: address.toBytes()
4652
},
4753
type: Ledger.TxOutputDestinationType.THIRD_PARTY
4854
};

packages/hardware-ledger/test/testData.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ export const txOut: Cardano.TxOut = {
126126
value: valueWithAssets
127127
};
128128

129+
export const byronEraTxOut: Cardano.TxOut = {
130+
address: Cardano.PaymentAddress('Ae2tdPwUPEZ5DW1am2FnANGLW2qReao5xXX7dcC86x2JAg39oo7oanFNbrd'),
131+
value: {
132+
coins: 20_000_000n
133+
}
134+
};
135+
129136
export const txOutToOwnedAddress: Cardano.TxOut = {
130137
address: paymentAddress,
131138
datumHash: Crypto.Hash32ByteBase16('0f3abbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0e78f19d9d5'),

packages/hardware-ledger/test/transformers/txOut.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as Ledger from '@cardano-foundation/ledgerjs-hw-app-cardano';
22
import {
3+
CONTEXT_WITHOUT_KNOWN_ADDRESSES,
34
CONTEXT_WITH_KNOWN_ADDRESSES,
5+
byronEraTxOut,
46
txOut,
57
txOutToOwnedAddress,
68
txOutWithReferenceScript,
@@ -120,6 +122,23 @@ describe('txOut', () => {
120122
});
121123
});
122124

125+
it('can map a simple txOut to Byron era address', async () => {
126+
const out = toTxOut({ index: 0, isCollateral: false, txOut: byronEraTxOut }, CONTEXT_WITHOUT_KNOWN_ADDRESSES);
127+
128+
expect(out).toEqual({
129+
amount: 20_000_000n,
130+
datumHashHex: null,
131+
destination: {
132+
params: {
133+
addressHex: '82d818582183581c54473376651c3d50b7a85055bb2395751e2db78bcb65410e1624989ca0001a73156e8e'
134+
},
135+
type: Ledger.TxOutputDestinationType.THIRD_PARTY
136+
},
137+
format: Ledger.TxOutputFormat.ARRAY_LEGACY,
138+
tokenBundle: null
139+
});
140+
});
141+
123142
it('can map a simple txOut to owned address', async () => {
124143
const out = toTxOut({ index: 0, isCollateral: false, txOut: txOutToOwnedAddress }, CONTEXT_WITH_KNOWN_ADDRESSES);
125144

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,24 @@ describe('LedgerKeyAgent', () => {
183183
}
184184
}
185185
];
186+
187+
const byronOutputs = [
188+
{
189+
address: Cardano.PaymentAddress('FHnt4NL7yPXtsWVUqTv1Tr1ZSarFUYHS2DFLRUJwtqx8RnpZ8s8JefSYTekFcSF'),
190+
value: { coins: 11_111_111n }
191+
}
192+
];
193+
194+
const byronProps: InitializeTxProps = {
195+
options: {
196+
validityInterval: {
197+
invalidBefore: Cardano.Slot(1),
198+
invalidHereafter: Cardano.Slot(999_999_999)
199+
}
200+
},
201+
outputs: new Set<Cardano.TxOut>(byronOutputs)
202+
};
203+
186204
const props: InitializeTxProps = {
187205
options: {
188206
validityInterval: {
@@ -233,6 +251,13 @@ describe('LedgerKeyAgent', () => {
233251
expect(signatures.size).toBe(2);
234252
});
235253

254+
it('successfully signs a transaction with byron address output', async () => {
255+
const {
256+
witness: { signatures }
257+
} = await wallet.finalizeTx({ tx: await wallet.initializeTx(byronProps) });
258+
expect(signatures.size).toBe(2);
259+
});
260+
236261
it('successfully signs ADA handle mint transaction', async () => {
237262
const cbor =
238263
'84a500818258207aa1264bcd0c06f34a49ed1dd7307a2bdec5a97bdeb546498759ad5b8ed42fd5010182a200583930195bde3deacb613b7e9eb6280b14db4e353e475e96d19f3f7a5e2d66195bde3deacb613b7e9eb6280b14db4e353e475e96d19f3f7a5e2d66011a00e4e1c0a2005839003d3246dc0c50ab3c74a8ffdd8068313ff99d341c461a8fe31f416d0a8fba06d60d71edc077cc5ebcb8ff82137afbce68df98271909332348011b000000025106a838021a00029309031a04a07bc6081a04a07a40a0f5f6';

0 commit comments

Comments
 (0)