Skip to content

Commit aa77b74

Browse files
AngelCastilloBrhyslbw
authored andcommitted
fix(hardware-trezor): txToTrezor now sets the includeNetworkId field
1 parent 9d32624 commit aa77b74

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

packages/hardware-trezor/src/transformers/tx.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export const trezorTxTransformer: Transformer<
1111
Omit<Trezor.CardanoSignTransaction, 'signingMode' | 'derivationType' | 'includeNetworkId' | 'chunkify' | 'ttl'> & {
1212
/* eslint-disable @typescript-eslint/no-explicit-any */
1313
ttl: any; // TODO: the Transformer util cant handle ttl as TOptional<string | number>
14+
/* eslint-disable @typescript-eslint/no-explicit-any */
15+
includeNetworkId: any; // TODO: the Transformer util cant handle TOptional<string | boolean>
1416
},
1517
TrezorTxTransformerContext
1618
> = {
@@ -21,6 +23,7 @@ export const trezorTxTransformer: Transformer<
2123
collateralReturn: ({ collateralReturn }, context) =>
2224
collateralReturn ? toTxOut({ index: 0, isCollateral: true, txOut: collateralReturn }, context!) : undefined,
2325
fee: ({ fee }) => fee.toString(),
26+
includeNetworkId: ({ networkId }) => !!networkId,
2427
inputs: ({ inputs }, context) => mapTxIns(inputs, context!),
2528
mint: ({ mint }) => mapTokenMap(mint, true),
2629
networkId: (_, context) => context!.chainId.networkId,

packages/hardware-trezor/test/transformers/tx.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as Trezor from '@trezor/connect';
2+
import { Cardano } from '@cardano-sdk/core';
23
import { CardanoKeyConst, TxInId, util } from '@cardano-sdk/key-management';
34
import {
45
babbageTxBodyWithScripts,
@@ -22,6 +23,34 @@ describe('tx', () => {
2223
expect(await txToTrezor(minValidTxBody, contextWithoutKnownAddresses)).toEqual({
2324
additionalWitnessRequests: [],
2425
fee: '10',
26+
includeNetworkId: false,
27+
inputs: [
28+
{
29+
prev_hash: txIn.txId,
30+
prev_index: txIn.index
31+
}
32+
],
33+
networkId: 0,
34+
outputs: [
35+
{
36+
address:
37+
'addr_test1qz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3jcu5d8ps7zex2k2xt3uqxgjqnnj83ws8lhrn648jjxtwq2ytjqp',
38+
amount: '10',
39+
format: Trezor.PROTO.CardanoTxOutputSerializationFormat.ARRAY_LEGACY
40+
}
41+
],
42+
protocolMagic: 999,
43+
tagCborSets: false
44+
});
45+
});
46+
47+
test('can set includeNetworkId if network field is set', async () => {
48+
expect(
49+
await txToTrezor({ ...minValidTxBody, networkId: Cardano.NetworkId.Mainnet }, contextWithoutKnownAddresses)
50+
).toEqual({
51+
additionalWitnessRequests: [],
52+
fee: '10',
53+
includeNetworkId: true,
2554
inputs: [
2655
{
2756
prev_hash: txIn.txId,
@@ -69,6 +98,7 @@ describe('tx', () => {
6998
}
7099
],
71100
fee: '10',
101+
includeNetworkId: false,
72102
inputs: [
73103
{
74104
path: knownAddressKeyPath,
@@ -232,6 +262,7 @@ describe('tx', () => {
232262
}
233263
],
234264
fee: '10',
265+
includeNetworkId: false,
235266
inputs: [
236267
{
237268
path: knownAddressKeyPath,
@@ -315,6 +346,7 @@ describe('tx', () => {
315346
format: Trezor.PROTO.CardanoTxOutputSerializationFormat.ARRAY_LEGACY
316347
},
317348
fee: '10',
349+
includeNetworkId: false,
318350
inputs: [
319351
{
320352
prev_hash: txIn.txId,
@@ -385,6 +417,7 @@ describe('tx', () => {
385417
format: Trezor.PROTO.CardanoTxOutputSerializationFormat.MAP_BABBAGE
386418
},
387419
fee: '10',
420+
includeNetworkId: false,
388421
inputs: [
389422
{
390423
path: knownAddressKeyPath,

0 commit comments

Comments
 (0)