Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/core/src/Cardano/util/isScriptAddress.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Address, CredentialType, PaymentAddress } from '../Address';

export const isScriptAddress = (address: PaymentAddress): boolean => {
if (!Address.isValidBech32(address)) {
return false;
}

const baseAddress = Address.fromBech32(address).asBase();
const paymentCredential = baseAddress?.getPaymentCredential();
const stakeCredential = baseAddress?.getStakeCredential();
Expand Down
8 changes: 7 additions & 1 deletion packages/hardware-ledger/src/transformers/txOut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,15 @@ const toDestination: Transform<Cardano.TxOut, Ledger.TxOutputDestination, Ledger
};
}

const address = Cardano.Address.fromString(txOut.address);

if (!address) {
throw new InvalidArgumentError('txOut', 'Invalid address format.');
}

return {
params: {
addressHex: Cardano.Address.fromBech32(txOut.address).toBytes()
addressHex: address.toBytes()
},
type: Ledger.TxOutputDestinationType.THIRD_PARTY
};
Expand Down
7 changes: 7 additions & 0 deletions packages/hardware-ledger/test/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ export const txOut: Cardano.TxOut = {
value: valueWithAssets
};

export const byronEraTxOut: Cardano.TxOut = {
address: Cardano.PaymentAddress('Ae2tdPwUPEZ5DW1am2FnANGLW2qReao5xXX7dcC86x2JAg39oo7oanFNbrd'),
value: {
coins: 20_000_000n
}
};

export const txOutToOwnedAddress: Cardano.TxOut = {
address: paymentAddress,
datumHash: Crypto.Hash32ByteBase16('0f3abbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0e78f19d9d5'),
Expand Down
19 changes: 19 additions & 0 deletions packages/hardware-ledger/test/transformers/txOut.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as Ledger from '@cardano-foundation/ledgerjs-hw-app-cardano';
import {
CONTEXT_WITHOUT_KNOWN_ADDRESSES,
CONTEXT_WITH_KNOWN_ADDRESSES,
byronEraTxOut,
txOut,
txOutToOwnedAddress,
txOutWithReferenceScript,
Expand Down Expand Up @@ -120,6 +122,23 @@ describe('txOut', () => {
});
});

it('can map a simple txOut to Byron era address', async () => {
const out = toTxOut({ index: 0, isCollateral: false, txOut: byronEraTxOut }, CONTEXT_WITHOUT_KNOWN_ADDRESSES);

expect(out).toEqual({
amount: 20_000_000n,
datumHashHex: null,
destination: {
params: {
addressHex: '82d818582183581c54473376651c3d50b7a85055bb2395751e2db78bcb65410e1624989ca0001a73156e8e'
},
type: Ledger.TxOutputDestinationType.THIRD_PARTY
},
format: Ledger.TxOutputFormat.ARRAY_LEGACY,
tokenBundle: null
});
});

it('can map a simple txOut to owned address', async () => {
const out = toTxOut({ index: 0, isCollateral: false, txOut: txOutToOwnedAddress }, CONTEXT_WITH_KNOWN_ADDRESSES);

Expand Down
25 changes: 25 additions & 0 deletions packages/wallet/test/hardware/ledger/LedgerKeyAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,24 @@ describe('LedgerKeyAgent', () => {
}
}
];

const byronOutputs = [
{
address: Cardano.PaymentAddress('FHnt4NL7yPXtsWVUqTv1Tr1ZSarFUYHS2DFLRUJwtqx8RnpZ8s8JefSYTekFcSF'),
value: { coins: 11_111_111n }
}
];

const byronProps: InitializeTxProps = {
options: {
validityInterval: {
invalidBefore: Cardano.Slot(1),
invalidHereafter: Cardano.Slot(999_999_999)
}
},
outputs: new Set<Cardano.TxOut>(byronOutputs)
};

const props: InitializeTxProps = {
options: {
validityInterval: {
Expand Down Expand Up @@ -233,6 +251,13 @@ describe('LedgerKeyAgent', () => {
expect(signatures.size).toBe(2);
});

it('successfully signs a transaction with byron address output', async () => {
const {
witness: { signatures }
} = await wallet.finalizeTx({ tx: await wallet.initializeTx(byronProps) });
expect(signatures.size).toBe(2);
});

it('successfully signs ADA handle mint transaction', async () => {
const cbor =
'84a500818258207aa1264bcd0c06f34a49ed1dd7307a2bdec5a97bdeb546498759ad5b8ed42fd5010182a200583930195bde3deacb613b7e9eb6280b14db4e353e475e96d19f3f7a5e2d66195bde3deacb613b7e9eb6280b14db4e353e475e96d19f3f7a5e2d66011a00e4e1c0a2005839003d3246dc0c50ab3c74a8ffdd8068313ff99d341c461a8fe31f416d0a8fba06d60d71edc077cc5ebcb8ff82137afbce68df98271909332348011b000000025106a838021a00029309031a04a07bc6081a04a07a40a0f5f6';
Expand Down
Loading