@onekeyfe/cardano-coin-selection-asmjs 1.1.11 → 1.1.12

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.
@@ -89,21 +89,18 @@ const getUtxos = async (address, utxos, amount) => {
89
89
  };
90
90
  const convertCborTxToEncodeTx = async ({ txHex, utxos, addresses, changeAddress, isSignOnly, }) => {
91
91
  var _a, _b, _c, _d;
92
- let body;
92
+ let tx;
93
93
  let rawTxHex;
94
94
  try {
95
- const tx = CardanoWasm.Transaction.from_bytes(Buffer.from(txHex, 'hex'));
96
- body = tx.body();
95
+ tx = CardanoWasm.FixedTransaction.from_hex(txHex);
97
96
  rawTxHex = txHex;
98
97
  }
99
98
  catch (_e) {
100
- // Input is TransactionBody only (e.g., from staking providers like stakefish)
101
- // Build a complete Transaction with empty witness set
102
- body = CardanoWasm.TransactionBody.from_bytes(Buffer.from(txHex, 'hex'));
103
- const emptyWitnessSet = CardanoWasm.TransactionWitnessSet.new();
104
- const tx = CardanoWasm.Transaction.new(body, emptyWitnessSet);
105
- rawTxHex = Buffer.from(tx.to_bytes(), 'hex').toString('hex');
99
+ // Staking providers may supply only a transaction body.
100
+ tx = CardanoWasm.FixedTransaction.new_from_body_bytes(Buffer.from(txHex, 'hex'));
101
+ rawTxHex = tx.to_hex();
106
102
  }
103
+ const body = tx.body();
107
104
  // Fee
108
105
  const fee = body.fee().to_str();
109
106
  const totalFeeInNative = new bignumber_js_1.default(fee).shiftedBy(-1 * 6).toFixed();
@@ -265,10 +262,8 @@ const convertCborTxToEncodeTx = async ({ txHex, utxos, addresses, changeAddress,
265
262
  token,
266
263
  },
267
264
  tx: {
268
- body: body.to_hex(),
269
- hash: CardanoWasm.FixedTransaction.new_from_body_bytes(body.to_bytes())
270
- .transaction_hash()
271
- .to_hex(),
265
+ body: Buffer.from(tx.raw_body()).toString('hex'),
266
+ hash: tx.transaction_hash().to_hex(),
272
267
  size: 0,
273
268
  rawTxHex,
274
269
  },
@@ -26,9 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.hasSetTagWithBody = void 0;
27
27
  const CardanoWasm = __importStar(require("@emurgo/cardano-serialization-lib-asmjs"));
28
28
  const hasSetTagWithBody = (txBodyHex) => {
29
- const txBody = CardanoWasm.TransactionBody.from_bytes(Uint8Array.from(Buffer.from(txBodyHex, 'hex')));
30
- const witnesses = CardanoWasm.TransactionWitnessSet.new();
31
- const tx = CardanoWasm.Transaction.new(txBody, witnesses);
29
+ const tx = CardanoWasm.FixedTransaction.new_from_body_bytes(Buffer.from(txBodyHex, 'hex'));
32
30
  let tagCborSets = false;
33
31
  try {
34
32
  const tagCBOR = CardanoWasm.has_transaction_set_tag(tx.to_bytes()).valueOf();
@@ -26,7 +26,7 @@ declare const onekeyUtils: {
26
26
  outputs: never[];
27
27
  fee: string;
28
28
  ttl: string | null;
29
- validityIntervalStart: any;
29
+ validityIntervalStart: string | null;
30
30
  certificates: [] | null;
31
31
  withdrawals: null;
32
32
  auxiliaryData: {
@@ -32,8 +32,7 @@ const signTransaction = async (txBodyHex, address, accountIndex, utxos, xprv, si
32
32
  if (!serializedUtxos || serializedUtxos === null) {
33
33
  throw new Error('no utxos');
34
34
  }
35
- const transactionWitnessSet = CardanoWasm.TransactionWitnessSet.new();
36
- const rawTx = CardanoWasm.Transaction.new(CardanoWasm.TransactionBody.from_hex(txBodyHex), CardanoWasm.TransactionWitnessSet.from_bytes(transactionWitnessSet.to_bytes()));
35
+ const rawTx = CardanoWasm.FixedTransaction.new_from_body_bytes(Buffer.from(txBodyHex, 'hex'));
37
36
  const keyHashes = await getKeyHashes(rawTx, serializedUtxos, { paymentAddr: address });
38
37
  const witnessSet = await (0, exports.signTx)({ paymentKey, stakeKey, accountKey }, Buffer.from(rawTx.to_bytes(), 'utf8').toString('hex'), keyHashes.key, partialSign);
39
38
  if (signOnly) {
@@ -42,11 +41,9 @@ const signTransaction = async (txBodyHex, address, accountIndex, utxos, xprv, si
42
41
  txid: '',
43
42
  };
44
43
  }
45
- const transaction = CardanoWasm.Transaction.new(rawTx.body(), witnessSet, rawTx.auxiliary_data());
44
+ const transaction = CardanoWasm.FixedTransaction.new(rawTx.raw_body(), witnessSet.to_bytes(), rawTx.is_valid());
46
45
  const signedTx = Buffer.from(transaction.to_bytes(), 'hex').toString('hex');
47
- const hash = CardanoWasm.FixedTransaction.new_from_body_bytes(transaction.body().to_bytes())
48
- .transaction_hash()
49
- .to_hex();
46
+ const hash = transaction.transaction_hash().to_hex();
50
47
  return {
51
48
  signedTx,
52
49
  txid: hash,
@@ -64,10 +61,10 @@ const signTx = async (keys, tx, keyHashes, partialSign = false) => {
64
61
  const { paymentKey, stakeKey } = keys;
65
62
  const paymentKeyHash = Buffer.from(paymentKey === null || paymentKey === void 0 ? void 0 : paymentKey.to_public().hash().to_bytes(), 'hex').toString('hex');
66
63
  const stakeKeyHash = Buffer.from(stakeKey.to_public().hash().to_bytes(), 'hex').toString('hex');
67
- const rawTx = CardanoWasm.Transaction.from_bytes(Buffer.from(tx, 'hex'));
64
+ const rawTx = CardanoWasm.FixedTransaction.from_hex(tx);
68
65
  const txWitnessSet = CardanoWasm.TransactionWitnessSet.new();
69
66
  const vkeyWitnesses = CardanoWasm.Vkeywitnesses.new();
70
- const txHash = CardanoWasm.FixedTransaction.new_from_body_bytes(rawTx.body().to_bytes()).transaction_hash();
67
+ const txHash = rawTx.transaction_hash();
71
68
  keyHashes.forEach(keyHash => {
72
69
  let signingKey;
73
70
  if (keyHash === paymentKeyHash)
@@ -55,7 +55,7 @@ export declare const txToOneKey: (rawTx: string, network: number, initKeys: Keys
55
55
  outputs: never[];
56
56
  fee: string;
57
57
  ttl: string | null;
58
- validityIntervalStart: any;
58
+ validityIntervalStart: string | null;
59
59
  certificates: [] | null;
60
60
  withdrawals: null;
61
61
  auxiliaryData: {
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.txToOneKey = exports.CardanoPoolRelayType = exports.CardanoDRepType = exports.CardanoCertificateType = exports.CardanoTxSigningMode = exports.CardanoAddressType = void 0;
27
27
  // @ts-nocheck
28
28
  const CardanoWasm = __importStar(require("@emurgo/cardano-serialization-lib-asmjs"));
29
+ const hasSetTag_1 = require("./hasSetTag");
29
30
  var CardanoAddressType;
30
31
  (function (CardanoAddressType) {
31
32
  CardanoAddressType[CardanoAddressType["BASE"] = 0] = "BASE";
@@ -95,6 +96,7 @@ const sortCanonicallyInPlace = (items, selector) => {
95
96
  });
96
97
  };
97
98
  const outputsToOneKey = (outputs, changeAddress) => {
99
+ var _a;
98
100
  const onekeyOutputs = [];
99
101
  for (let i = 0; i < outputs.len(); i++) {
100
102
  const output = outputs.get(i);
@@ -186,9 +188,9 @@ const outputsToOneKey = (outputs, changeAddress) => {
186
188
  const outputRes = Object.assign({ amount: output.amount().coin().to_str(), tokenBundle,
187
189
  datumHash,
188
190
  // https://github.com/input-output-hk/nami/commit/a5f5a9357da81307bff9bc77ef2476f1746c134a#diff-1c7110974e24c349d96acac1989fe76c94b0031ab0f5a114e10823e5d74549deR421-R423
189
- format: Buffer.from(output.to_bytes()).toString('hex').startsWith('a')
191
+ format: (_a = output.serialization_format()) !== null && _a !== void 0 ? _a : (Buffer.from(output.to_bytes()).toString('hex').startsWith('a')
190
192
  ? 1
191
- : 0, inlineDatum,
193
+ : 0), inlineDatum,
192
194
  referenceScript }, destination);
193
195
  if (!tokenBundle)
194
196
  delete outputRes.tokenBundle;
@@ -207,9 +209,9 @@ const outputsToOneKey = (outputs, changeAddress) => {
207
209
  * @param {Transaction} tx
208
210
  */
209
211
  const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
210
- var _a, _b, _c, _d;
212
+ var _a, _b, _c, _d, _e, _f;
211
213
  const keys = generateKeys(initKeys, xpub);
212
- const tx = CardanoWasm.Transaction.from_bytes(Buffer.from(rawTx, 'hex'));
214
+ const tx = CardanoWasm.FixedTransaction.from_hex(rawTx);
213
215
  let signingMode = CardanoTxSigningMode.ORDINARY_TRANSACTION;
214
216
  const outputs = tx.body().outputs();
215
217
  const onekeyOutputs = outputsToOneKey(outputs, changeAddress);
@@ -422,9 +424,7 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
422
424
  hash: Buffer.from(tx.body().auxiliary_data_hash().to_bytes()).toString('hex'),
423
425
  }
424
426
  : null;
425
- const validityIntervalStart = tx.body().validity_start_interval()
426
- ? tx.body().validity_start_interval().to_str()
427
- : null;
427
+ const validityIntervalStart = (_f = (_e = tx.body().validity_start_interval_bignum()) === null || _e === void 0 ? void 0 : _e.to_str()) !== null && _f !== void 0 ? _f : null;
428
428
  const mint = tx.body().mint();
429
429
  let additionalWitnessRequests = null;
430
430
  let mintBundle = null;
@@ -541,10 +541,7 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
541
541
  const includeNetworkId = !!tx.body().network_id();
542
542
  let tagCborSets = false;
543
543
  try {
544
- const tagCBOR = CardanoWasm.has_transaction_set_tag(tx.to_bytes()).valueOf();
545
- tagCborSets =
546
- tagCBOR === CardanoWasm.TransactionSetsState.AllSetsHaveTag.valueOf() ||
547
- tagCBOR === CardanoWasm.TransactionSetsState.MixedSets.valueOf();
544
+ tagCborSets = await (0, hasSetTag_1.hasSetTagWithBody)(Buffer.from(tx.raw_body()).toString('hex'));
548
545
  }
549
546
  catch (error) {
550
547
  // ignore
@@ -27,10 +27,11 @@ exports.signTransaction = void 0;
27
27
  const CardanoWasm = __importStar(require("@emurgo/cardano-serialization-lib-asmjs"));
28
28
  const trezor_1 = require("../../types/trezor");
29
29
  const common_1 = require("../common");
30
+ const error_1 = require("../onekey/error");
30
31
  const signTransaction = (txBodyHex,
31
32
  // txMetadata: CardanoWasm.AuxiliaryData,
32
33
  signedWitnesses, options) => {
33
- const txBody = CardanoWasm.TransactionBody.from_bytes(Uint8Array.from(Buffer.from(txBodyHex, 'hex')));
34
+ const tx = CardanoWasm.FixedTransaction.new_from_body_bytes(Buffer.from(txBodyHex, 'hex'));
34
35
  const witnesses = CardanoWasm.TransactionWitnessSet.new();
35
36
  const vkeyWitnesses = CardanoWasm.Vkeywitnesses.new();
36
37
  const bootstrapWitnesses = CardanoWasm.BootstrapWitnesses.new();
@@ -38,6 +39,9 @@ signedWitnesses, options) => {
38
39
  const vKey = CardanoWasm.Vkey.new(CardanoWasm.PublicKey.from_bytes(Buffer.from(w.pubKey, 'hex')));
39
40
  const signature = CardanoWasm.Ed25519Signature.from_bytes(Buffer.from(w.signature, 'hex'));
40
41
  if (w.type === trezor_1.CardanoTxWitnessType.SHELLEY_WITNESS) {
42
+ if (!vKey.public_key().verify(tx.transaction_hash().to_bytes(), signature)) {
43
+ throw error_1.TxSignError.ProofGeneration;
44
+ }
41
45
  // Shelley witness
42
46
  const vKeyWitness = CardanoWasm.Vkeywitness.new(vKey, signature);
43
47
  vkeyWitnesses.add(vKeyWitness);
@@ -62,7 +66,7 @@ signedWitnesses, options) => {
62
66
  if (options === null || options === void 0 ? void 0 : options.signOnly) {
63
67
  return Promise.resolve(Buffer.from(witnesses.to_bytes(), 'utf8').toString('hex'));
64
68
  }
65
- const transaction = CardanoWasm.Transaction.new(txBody, witnesses);
69
+ const transaction = CardanoWasm.FixedTransaction.new(tx.raw_body(), witnesses.to_bytes(), tx.is_valid());
66
70
  const serializedTx = Buffer.from(transaction.to_bytes()).toString('hex');
67
71
  return Promise.resolve(serializedTx);
68
72
  };
@@ -59,21 +59,18 @@ const getUtxos = async (address, utxos, amount) => {
59
59
  };
60
60
  const convertCborTxToEncodeTx = async ({ txHex, utxos, addresses, changeAddress, isSignOnly, }) => {
61
61
  var _a, _b, _c, _d;
62
- let body;
62
+ let tx;
63
63
  let rawTxHex;
64
64
  try {
65
- const tx = CardanoWasm.Transaction.from_bytes(Buffer.from(txHex, 'hex'));
66
- body = tx.body();
65
+ tx = CardanoWasm.FixedTransaction.from_hex(txHex);
67
66
  rawTxHex = txHex;
68
67
  }
69
68
  catch (_e) {
70
- // Input is TransactionBody only (e.g., from staking providers like stakefish)
71
- // Build a complete Transaction with empty witness set
72
- body = CardanoWasm.TransactionBody.from_bytes(Buffer.from(txHex, 'hex'));
73
- const emptyWitnessSet = CardanoWasm.TransactionWitnessSet.new();
74
- const tx = CardanoWasm.Transaction.new(body, emptyWitnessSet);
75
- rawTxHex = Buffer.from(tx.to_bytes(), 'hex').toString('hex');
69
+ // Staking providers may supply only a transaction body.
70
+ tx = CardanoWasm.FixedTransaction.new_from_body_bytes(Buffer.from(txHex, 'hex'));
71
+ rawTxHex = tx.to_hex();
76
72
  }
73
+ const body = tx.body();
77
74
  // Fee
78
75
  const fee = body.fee().to_str();
79
76
  const totalFeeInNative = new BigNumber(fee).shiftedBy(-1 * 6).toFixed();
@@ -235,10 +232,8 @@ const convertCborTxToEncodeTx = async ({ txHex, utxos, addresses, changeAddress,
235
232
  token,
236
233
  },
237
234
  tx: {
238
- body: body.to_hex(),
239
- hash: CardanoWasm.FixedTransaction.new_from_body_bytes(body.to_bytes())
240
- .transaction_hash()
241
- .to_hex(),
235
+ body: Buffer.from(tx.raw_body()).toString('hex'),
236
+ hash: tx.transaction_hash().to_hex(),
242
237
  size: 0,
243
238
  rawTxHex,
244
239
  },
@@ -1,8 +1,6 @@
1
1
  import * as CardanoWasm from '@emurgo/cardano-serialization-lib-asmjs';
2
2
  export const hasSetTagWithBody = (txBodyHex) => {
3
- const txBody = CardanoWasm.TransactionBody.from_bytes(Uint8Array.from(Buffer.from(txBodyHex, 'hex')));
4
- const witnesses = CardanoWasm.TransactionWitnessSet.new();
5
- const tx = CardanoWasm.Transaction.new(txBody, witnesses);
3
+ const tx = CardanoWasm.FixedTransaction.new_from_body_bytes(Buffer.from(txBodyHex, 'hex'));
6
4
  let tagCborSets = false;
7
5
  try {
8
6
  const tagCBOR = CardanoWasm.has_transaction_set_tag(tx.to_bytes()).valueOf();
@@ -26,7 +26,7 @@ declare const onekeyUtils: {
26
26
  outputs: never[];
27
27
  fee: string;
28
28
  ttl: string | null;
29
- validityIntervalStart: any;
29
+ validityIntervalStart: string | null;
30
30
  certificates: [] | null;
31
31
  withdrawals: null;
32
32
  auxiliaryData: {
@@ -6,8 +6,7 @@ export const signTransaction = async (txBodyHex, address, accountIndex, utxos, x
6
6
  if (!serializedUtxos || serializedUtxos === null) {
7
7
  throw new Error('no utxos');
8
8
  }
9
- const transactionWitnessSet = CardanoWasm.TransactionWitnessSet.new();
10
- const rawTx = CardanoWasm.Transaction.new(CardanoWasm.TransactionBody.from_hex(txBodyHex), CardanoWasm.TransactionWitnessSet.from_bytes(transactionWitnessSet.to_bytes()));
9
+ const rawTx = CardanoWasm.FixedTransaction.new_from_body_bytes(Buffer.from(txBodyHex, 'hex'));
11
10
  const keyHashes = await getKeyHashes(rawTx, serializedUtxos, { paymentAddr: address });
12
11
  const witnessSet = await signTx({ paymentKey, stakeKey, accountKey }, Buffer.from(rawTx.to_bytes(), 'utf8').toString('hex'), keyHashes.key, partialSign);
13
12
  if (signOnly) {
@@ -16,11 +15,9 @@ export const signTransaction = async (txBodyHex, address, accountIndex, utxos, x
16
15
  txid: '',
17
16
  };
18
17
  }
19
- const transaction = CardanoWasm.Transaction.new(rawTx.body(), witnessSet, rawTx.auxiliary_data());
18
+ const transaction = CardanoWasm.FixedTransaction.new(rawTx.raw_body(), witnessSet.to_bytes(), rawTx.is_valid());
20
19
  const signedTx = Buffer.from(transaction.to_bytes(), 'hex').toString('hex');
21
- const hash = CardanoWasm.FixedTransaction.new_from_body_bytes(transaction.body().to_bytes())
22
- .transaction_hash()
23
- .to_hex();
20
+ const hash = transaction.transaction_hash().to_hex();
24
21
  return {
25
22
  signedTx,
26
23
  txid: hash,
@@ -37,10 +34,10 @@ export const signTx = async (keys, tx, keyHashes, partialSign = false) => {
37
34
  const { paymentKey, stakeKey } = keys;
38
35
  const paymentKeyHash = Buffer.from(paymentKey === null || paymentKey === void 0 ? void 0 : paymentKey.to_public().hash().to_bytes(), 'hex').toString('hex');
39
36
  const stakeKeyHash = Buffer.from(stakeKey.to_public().hash().to_bytes(), 'hex').toString('hex');
40
- const rawTx = CardanoWasm.Transaction.from_bytes(Buffer.from(tx, 'hex'));
37
+ const rawTx = CardanoWasm.FixedTransaction.from_hex(tx);
41
38
  const txWitnessSet = CardanoWasm.TransactionWitnessSet.new();
42
39
  const vkeyWitnesses = CardanoWasm.Vkeywitnesses.new();
43
- const txHash = CardanoWasm.FixedTransaction.new_from_body_bytes(rawTx.body().to_bytes()).transaction_hash();
40
+ const txHash = rawTx.transaction_hash();
44
41
  keyHashes.forEach(keyHash => {
45
42
  let signingKey;
46
43
  if (keyHash === paymentKeyHash)
@@ -55,7 +55,7 @@ export declare const txToOneKey: (rawTx: string, network: number, initKeys: Keys
55
55
  outputs: never[];
56
56
  fee: string;
57
57
  ttl: string | null;
58
- validityIntervalStart: any;
58
+ validityIntervalStart: string | null;
59
59
  certificates: [] | null;
60
60
  withdrawals: null;
61
61
  auxiliaryData: {
@@ -1,5 +1,6 @@
1
1
  // @ts-nocheck
2
2
  import * as CardanoWasm from '@emurgo/cardano-serialization-lib-asmjs';
3
+ import { hasSetTagWithBody } from './hasSetTag';
3
4
  export var CardanoAddressType;
4
5
  (function (CardanoAddressType) {
5
6
  CardanoAddressType[CardanoAddressType["BASE"] = 0] = "BASE";
@@ -69,6 +70,7 @@ const sortCanonicallyInPlace = (items, selector) => {
69
70
  });
70
71
  };
71
72
  const outputsToOneKey = (outputs, changeAddress) => {
73
+ var _a;
72
74
  const onekeyOutputs = [];
73
75
  for (let i = 0; i < outputs.len(); i++) {
74
76
  const output = outputs.get(i);
@@ -160,9 +162,9 @@ const outputsToOneKey = (outputs, changeAddress) => {
160
162
  const outputRes = Object.assign({ amount: output.amount().coin().to_str(), tokenBundle,
161
163
  datumHash,
162
164
  // https://github.com/input-output-hk/nami/commit/a5f5a9357da81307bff9bc77ef2476f1746c134a#diff-1c7110974e24c349d96acac1989fe76c94b0031ab0f5a114e10823e5d74549deR421-R423
163
- format: Buffer.from(output.to_bytes()).toString('hex').startsWith('a')
165
+ format: (_a = output.serialization_format()) !== null && _a !== void 0 ? _a : (Buffer.from(output.to_bytes()).toString('hex').startsWith('a')
164
166
  ? 1
165
- : 0, inlineDatum,
167
+ : 0), inlineDatum,
166
168
  referenceScript }, destination);
167
169
  if (!tokenBundle)
168
170
  delete outputRes.tokenBundle;
@@ -181,9 +183,9 @@ const outputsToOneKey = (outputs, changeAddress) => {
181
183
  * @param {Transaction} tx
182
184
  */
183
185
  export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
184
- var _a, _b, _c, _d;
186
+ var _a, _b, _c, _d, _e, _f;
185
187
  const keys = generateKeys(initKeys, xpub);
186
- const tx = CardanoWasm.Transaction.from_bytes(Buffer.from(rawTx, 'hex'));
188
+ const tx = CardanoWasm.FixedTransaction.from_hex(rawTx);
187
189
  let signingMode = CardanoTxSigningMode.ORDINARY_TRANSACTION;
188
190
  const outputs = tx.body().outputs();
189
191
  const onekeyOutputs = outputsToOneKey(outputs, changeAddress);
@@ -396,9 +398,7 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
396
398
  hash: Buffer.from(tx.body().auxiliary_data_hash().to_bytes()).toString('hex'),
397
399
  }
398
400
  : null;
399
- const validityIntervalStart = tx.body().validity_start_interval()
400
- ? tx.body().validity_start_interval().to_str()
401
- : null;
401
+ const validityIntervalStart = (_f = (_e = tx.body().validity_start_interval_bignum()) === null || _e === void 0 ? void 0 : _e.to_str()) !== null && _f !== void 0 ? _f : null;
402
402
  const mint = tx.body().mint();
403
403
  let additionalWitnessRequests = null;
404
404
  let mintBundle = null;
@@ -515,10 +515,7 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
515
515
  const includeNetworkId = !!tx.body().network_id();
516
516
  let tagCborSets = false;
517
517
  try {
518
- const tagCBOR = CardanoWasm.has_transaction_set_tag(tx.to_bytes()).valueOf();
519
- tagCborSets =
520
- tagCBOR === CardanoWasm.TransactionSetsState.AllSetsHaveTag.valueOf() ||
521
- tagCBOR === CardanoWasm.TransactionSetsState.MixedSets.valueOf();
518
+ tagCborSets = await hasSetTagWithBody(Buffer.from(tx.raw_body()).toString('hex'));
522
519
  }
523
520
  catch (error) {
524
521
  // ignore
@@ -1,10 +1,11 @@
1
1
  import * as CardanoWasm from '@emurgo/cardano-serialization-lib-asmjs';
2
2
  import { CardanoTxWitnessType, } from '../../types/trezor';
3
3
  import { getProtocolMagic } from '../common';
4
+ import { TxSignError } from '../onekey/error';
4
5
  export const signTransaction = (txBodyHex,
5
6
  // txMetadata: CardanoWasm.AuxiliaryData,
6
7
  signedWitnesses, options) => {
7
- const txBody = CardanoWasm.TransactionBody.from_bytes(Uint8Array.from(Buffer.from(txBodyHex, 'hex')));
8
+ const tx = CardanoWasm.FixedTransaction.new_from_body_bytes(Buffer.from(txBodyHex, 'hex'));
8
9
  const witnesses = CardanoWasm.TransactionWitnessSet.new();
9
10
  const vkeyWitnesses = CardanoWasm.Vkeywitnesses.new();
10
11
  const bootstrapWitnesses = CardanoWasm.BootstrapWitnesses.new();
@@ -12,6 +13,9 @@ signedWitnesses, options) => {
12
13
  const vKey = CardanoWasm.Vkey.new(CardanoWasm.PublicKey.from_bytes(Buffer.from(w.pubKey, 'hex')));
13
14
  const signature = CardanoWasm.Ed25519Signature.from_bytes(Buffer.from(w.signature, 'hex'));
14
15
  if (w.type === CardanoTxWitnessType.SHELLEY_WITNESS) {
16
+ if (!vKey.public_key().verify(tx.transaction_hash().to_bytes(), signature)) {
17
+ throw TxSignError.ProofGeneration;
18
+ }
15
19
  // Shelley witness
16
20
  const vKeyWitness = CardanoWasm.Vkeywitness.new(vKey, signature);
17
21
  vkeyWitnesses.add(vKeyWitness);
@@ -36,7 +40,7 @@ signedWitnesses, options) => {
36
40
  if (options === null || options === void 0 ? void 0 : options.signOnly) {
37
41
  return Promise.resolve(Buffer.from(witnesses.to_bytes(), 'utf8').toString('hex'));
38
42
  }
39
- const transaction = CardanoWasm.Transaction.new(txBody, witnesses);
43
+ const transaction = CardanoWasm.FixedTransaction.new(tx.raw_body(), witnesses.to_bytes(), tx.is_valid());
40
44
  const serializedTx = Buffer.from(transaction.to_bytes()).toString('hex');
41
45
  return Promise.resolve(serializedTx);
42
46
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/cardano-coin-selection-asmjs",
3
- "version": "1.1.11",
3
+ "version": "1.1.12",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "coin selection"