@onekeyfe/cardano-coin-selection-asmjs 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -43,6 +43,7 @@ declare const onekeyUtils: {
43
43
  collateralReturn: null;
44
44
  totalCollateral: string | null;
45
45
  referenceInputs: null;
46
+ tagCborSets: boolean;
46
47
  }>;
47
48
  };
48
49
  export { onekeyUtils, dAppUtils };
@@ -63,5 +63,6 @@ export declare const txToOneKey: (rawTx: string, network: number, initKeys: Keys
63
63
  collateralReturn: null;
64
64
  totalCollateral: string | null;
65
65
  referenceInputs: null;
66
+ tagCborSets: boolean;
66
67
  }>;
67
68
  export {};
@@ -71,6 +71,19 @@ const generateKeys = (keys, xpub) => {
71
71
  stake: Object.assign(Object.assign({}, keys.stake), { hash: stakeKeyHash }),
72
72
  };
73
73
  };
74
+ const sortCanonicallyInPlace = (items, selector) => {
75
+ return items.sort((a, b) => {
76
+ const itemA = selector(a);
77
+ const itemB = selector(b);
78
+ if (itemA.length === itemB.length) {
79
+ return itemA > itemB ? 1 : -1;
80
+ }
81
+ else if (itemA.length > itemB.length)
82
+ return 1;
83
+ else
84
+ return -1;
85
+ });
86
+ };
74
87
  const outputsToOneKey = (outputs, changeAddress) => {
75
88
  const onekeyOutputs = [];
76
89
  for (let i = 0; i < outputs.len(); i++) {
@@ -92,20 +105,13 @@ const outputsToOneKey = (outputs, changeAddress) => {
92
105
  });
93
106
  }
94
107
  // sort canonical
95
- tokens.sort((a, b) => {
96
- if (a.assetNameBytes.length == b.assetNameBytes.length) {
97
- return a.assetNameBytes > b.assetNameBytes ? 1 : -1;
98
- }
99
- else if (a.assetNameBytes.length > b.assetNameBytes.length)
100
- return 1;
101
- else
102
- return -1;
103
- });
108
+ sortCanonicallyInPlace(tokens, item => item.assetNameBytes);
104
109
  tokenBundle.push({
105
110
  policyId: Buffer.from(policy.to_bytes()).toString('hex'),
106
111
  tokenAmounts: tokens,
107
112
  });
108
113
  }
114
+ sortCanonicallyInPlace(tokenBundle, item => item.policyId);
109
115
  }
110
116
  const outputAddressBech32 = output.address().to_bech32();
111
117
  const outputAddressHuman = (() => {
@@ -373,15 +379,7 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
373
379
  });
374
380
  }
375
381
  // sort canonical
376
- tokens.sort((a, b) => {
377
- if (a.assetNameBytes.length == b.assetNameBytes.length) {
378
- return a.assetNameBytes > b.assetNameBytes ? 1 : -1;
379
- }
380
- else if (a.assetNameBytes.length > b.assetNameBytes.length)
381
- return 1;
382
- else
383
- return -1;
384
- });
382
+ sortCanonicallyInPlace(tokens, item => item.assetNameBytes);
385
383
  mintBundle.push({
386
384
  policyId: Buffer.from(policy.to_bytes()).toString('hex'),
387
385
  tokenAmounts: tokens,
@@ -469,6 +467,16 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
469
467
  return null;
470
468
  })();
471
469
  const includeNetworkId = !!tx.body().network_id();
470
+ let tagCborSets = false;
471
+ try {
472
+ const tagCBOR = CardanoWasm.has_transaction_set_tag(tx.to_bytes()).valueOf();
473
+ tagCborSets =
474
+ tagCBOR === CardanoWasm.TransactionSetsState.AllSetsHaveTag.valueOf() ||
475
+ tagCBOR === CardanoWasm.TransactionSetsState.MixedSets.valueOf();
476
+ }
477
+ catch (error) {
478
+ // ignore
479
+ }
472
480
  const onekeyTx = {
473
481
  signingMode,
474
482
  outputs: onekeyOutputs,
@@ -489,6 +497,7 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
489
497
  collateralReturn,
490
498
  totalCollateral,
491
499
  referenceInputs,
500
+ tagCborSets,
492
501
  };
493
502
  Object.keys(onekeyTx).forEach(key => !onekeyTx[key] && onekeyTx[key] != 0 && delete onekeyTx[key]);
494
503
  console.log('format onekey cardano hardware Tx =====>>> : ', onekeyTx);
@@ -43,6 +43,7 @@ declare const onekeyUtils: {
43
43
  collateralReturn: null;
44
44
  totalCollateral: string | null;
45
45
  referenceInputs: null;
46
+ tagCborSets: boolean;
46
47
  }>;
47
48
  };
48
49
  export { onekeyUtils, dAppUtils };
@@ -63,5 +63,6 @@ export declare const txToOneKey: (rawTx: string, network: number, initKeys: Keys
63
63
  collateralReturn: null;
64
64
  totalCollateral: string | null;
65
65
  referenceInputs: null;
66
+ tagCborSets: boolean;
66
67
  }>;
67
68
  export {};
@@ -45,6 +45,19 @@ const generateKeys = (keys, xpub) => {
45
45
  stake: Object.assign(Object.assign({}, keys.stake), { hash: stakeKeyHash }),
46
46
  };
47
47
  };
48
+ const sortCanonicallyInPlace = (items, selector) => {
49
+ return items.sort((a, b) => {
50
+ const itemA = selector(a);
51
+ const itemB = selector(b);
52
+ if (itemA.length === itemB.length) {
53
+ return itemA > itemB ? 1 : -1;
54
+ }
55
+ else if (itemA.length > itemB.length)
56
+ return 1;
57
+ else
58
+ return -1;
59
+ });
60
+ };
48
61
  const outputsToOneKey = (outputs, changeAddress) => {
49
62
  const onekeyOutputs = [];
50
63
  for (let i = 0; i < outputs.len(); i++) {
@@ -66,20 +79,13 @@ const outputsToOneKey = (outputs, changeAddress) => {
66
79
  });
67
80
  }
68
81
  // sort canonical
69
- tokens.sort((a, b) => {
70
- if (a.assetNameBytes.length == b.assetNameBytes.length) {
71
- return a.assetNameBytes > b.assetNameBytes ? 1 : -1;
72
- }
73
- else if (a.assetNameBytes.length > b.assetNameBytes.length)
74
- return 1;
75
- else
76
- return -1;
77
- });
82
+ sortCanonicallyInPlace(tokens, item => item.assetNameBytes);
78
83
  tokenBundle.push({
79
84
  policyId: Buffer.from(policy.to_bytes()).toString('hex'),
80
85
  tokenAmounts: tokens,
81
86
  });
82
87
  }
88
+ sortCanonicallyInPlace(tokenBundle, item => item.policyId);
83
89
  }
84
90
  const outputAddressBech32 = output.address().to_bech32();
85
91
  const outputAddressHuman = (() => {
@@ -347,15 +353,7 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
347
353
  });
348
354
  }
349
355
  // sort canonical
350
- tokens.sort((a, b) => {
351
- if (a.assetNameBytes.length == b.assetNameBytes.length) {
352
- return a.assetNameBytes > b.assetNameBytes ? 1 : -1;
353
- }
354
- else if (a.assetNameBytes.length > b.assetNameBytes.length)
355
- return 1;
356
- else
357
- return -1;
358
- });
356
+ sortCanonicallyInPlace(tokens, item => item.assetNameBytes);
359
357
  mintBundle.push({
360
358
  policyId: Buffer.from(policy.to_bytes()).toString('hex'),
361
359
  tokenAmounts: tokens,
@@ -443,6 +441,16 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
443
441
  return null;
444
442
  })();
445
443
  const includeNetworkId = !!tx.body().network_id();
444
+ let tagCborSets = false;
445
+ try {
446
+ const tagCBOR = CardanoWasm.has_transaction_set_tag(tx.to_bytes()).valueOf();
447
+ tagCborSets =
448
+ tagCBOR === CardanoWasm.TransactionSetsState.AllSetsHaveTag.valueOf() ||
449
+ tagCBOR === CardanoWasm.TransactionSetsState.MixedSets.valueOf();
450
+ }
451
+ catch (error) {
452
+ // ignore
453
+ }
446
454
  const onekeyTx = {
447
455
  signingMode,
448
456
  outputs: onekeyOutputs,
@@ -463,6 +471,7 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
463
471
  collateralReturn,
464
472
  totalCollateral,
465
473
  referenceInputs,
474
+ tagCborSets,
466
475
  };
467
476
  Object.keys(onekeyTx).forEach(key => !onekeyTx[key] && onekeyTx[key] != 0 && delete onekeyTx[key]);
468
477
  console.log('format onekey cardano hardware Tx =====>>> : ', onekeyTx);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/cardano-coin-selection-asmjs",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "coin selection"