@onekeyfe/cardano-coin-selection-asmjs 1.1.10-alpha.1 → 1.1.10-alpha.2

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.
@@ -91,20 +91,27 @@ const convertCborTxToEncodeTx = async (txHex, utxos, addresses, changeAddress) =
91
91
  var _a, _b, _c, _d;
92
92
  let body;
93
93
  let rawTxHex;
94
+ let originalBodyHex;
95
+ let isBodyOnly = false;
94
96
  console.log('CARDANO LOCAL_VERSION : 1');
95
97
  try {
96
98
  const tx = CardanoWasm.Transaction.from_bytes(Buffer.from(txHex, 'hex'));
97
99
  body = tx.body();
98
100
  rawTxHex = txHex;
101
+ // No originalBodyHex needed for full Transaction
99
102
  }
100
103
  catch (_e) {
101
104
  // Input is TransactionBody only (e.g., from staking providers like stakefish)
102
- // Build a complete Transaction with empty witness set
105
+ // IMPORTANT: Preserve the original body hex for signing to maintain CBOR encoding
106
+ isBodyOnly = true;
107
+ originalBodyHex = txHex; // Save original body hex
103
108
  body = CardanoWasm.TransactionBody.from_bytes(Buffer.from(txHex, 'hex'));
109
+ // For rawTxHex, we need to build a Transaction for compatibility
104
110
  const emptyWitnessSet = CardanoWasm.TransactionWitnessSet.new();
105
111
  const tx = CardanoWasm.Transaction.new(body, emptyWitnessSet);
106
112
  rawTxHex = Buffer.from(tx.to_bytes(), 'hex').toString('hex');
107
113
  }
114
+ console.log('[convertCborTxToEncodeTx] isBodyOnly:', isBodyOnly, 'originalBodyHex:', !!originalBodyHex);
108
115
  // Fee
109
116
  const fee = body.fee().to_str();
110
117
  const totalFeeInNative = new bignumber_js_1.default(fee).shiftedBy(-1 * 6).toFixed();
@@ -259,6 +266,9 @@ const convertCborTxToEncodeTx = async (txHex, utxos, addresses, changeAddress) =
259
266
  .to_hex(),
260
267
  size: 0,
261
268
  rawTxHex,
269
+ // Original body hex from external provider, use this for signing
270
+ // to preserve CBOR encoding (important for Conway era transactions)
271
+ originalBodyHex,
262
272
  },
263
273
  signOnly: true,
264
274
  staking: stakingInfo,
@@ -22,14 +22,7 @@ export declare enum CardanoCertificateType {
22
22
  STAKE_REGISTRATION = 0,
23
23
  STAKE_DEREGISTRATION = 1,
24
24
  STAKE_DELEGATION = 2,
25
- STAKE_POOL_REGISTRATION = 3,
26
- STAKE_REGISTRATION_CONWAY = 7,
27
- STAKE_DEREGISTRATION_CONWAY = 8,
28
- VOTE_DELEGATION = 9,
29
- STAKE_AND_VOTE_DELEGATION = 10,
30
- STAKE_REGISTRATION_AND_DELEGATION = 11,
31
- VOTE_REGISTRATION_AND_DELEGATION = 12,
32
- STAKE_VOTE_REGISTRATION_AND_DELEGATION = 13
25
+ STAKE_POOL_REGISTRATION = 3
33
26
  }
34
27
  export declare enum CardanoPoolRelayType {
35
28
  SINGLE_HOST_IP = 0,
@@ -46,7 +39,7 @@ type Keys = {
46
39
  };
47
40
  /**
48
41
  *
49
- * @param {Transaction} tx
42
+ * @param {Transaction | TransactionBody} rawTx - can be full Transaction or just TransactionBody hex
50
43
  */
51
44
  export declare const txToOneKey: (rawTx: string, network: number, initKeys: Keys, xpub: string, changeAddress: IChangeAddress) => Promise<{
52
45
  signingMode: CardanoTxSigningMode.ORDINARY_TRANSACTION | CardanoTxSigningMode.POOL_REGISTRATION_AS_OWNER | CardanoTxSigningMode.PLUTUS_TRANSACTION;
@@ -53,14 +53,6 @@ var CardanoCertificateType;
53
53
  CardanoCertificateType[CardanoCertificateType["STAKE_DEREGISTRATION"] = 1] = "STAKE_DEREGISTRATION";
54
54
  CardanoCertificateType[CardanoCertificateType["STAKE_DELEGATION"] = 2] = "STAKE_DELEGATION";
55
55
  CardanoCertificateType[CardanoCertificateType["STAKE_POOL_REGISTRATION"] = 3] = "STAKE_POOL_REGISTRATION";
56
- // Conway era
57
- CardanoCertificateType[CardanoCertificateType["STAKE_REGISTRATION_CONWAY"] = 7] = "STAKE_REGISTRATION_CONWAY";
58
- CardanoCertificateType[CardanoCertificateType["STAKE_DEREGISTRATION_CONWAY"] = 8] = "STAKE_DEREGISTRATION_CONWAY";
59
- CardanoCertificateType[CardanoCertificateType["VOTE_DELEGATION"] = 9] = "VOTE_DELEGATION";
60
- CardanoCertificateType[CardanoCertificateType["STAKE_AND_VOTE_DELEGATION"] = 10] = "STAKE_AND_VOTE_DELEGATION";
61
- CardanoCertificateType[CardanoCertificateType["STAKE_REGISTRATION_AND_DELEGATION"] = 11] = "STAKE_REGISTRATION_AND_DELEGATION";
62
- CardanoCertificateType[CardanoCertificateType["VOTE_REGISTRATION_AND_DELEGATION"] = 12] = "VOTE_REGISTRATION_AND_DELEGATION";
63
- CardanoCertificateType[CardanoCertificateType["STAKE_VOTE_REGISTRATION_AND_DELEGATION"] = 13] = "STAKE_VOTE_REGISTRATION_AND_DELEGATION";
64
56
  })(CardanoCertificateType || (exports.CardanoCertificateType = CardanoCertificateType = {}));
65
57
  var CardanoPoolRelayType;
66
58
  (function (CardanoPoolRelayType) {
@@ -202,12 +194,23 @@ const outputsToOneKey = (outputs, changeAddress) => {
202
194
  };
203
195
  /**
204
196
  *
205
- * @param {Transaction} tx
197
+ * @param {Transaction | TransactionBody} rawTx - can be full Transaction or just TransactionBody hex
206
198
  */
207
199
  const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
208
- var _a, _b, _c, _d;
200
+ var _a;
209
201
  const keys = generateKeys(initKeys, xpub);
210
- const tx = CardanoWasm.Transaction.from_bytes(Buffer.from(rawTx, 'hex'));
202
+ // Try to parse as full Transaction first, fallback to TransactionBody
203
+ let tx;
204
+ try {
205
+ tx = CardanoWasm.Transaction.from_bytes(Buffer.from(rawTx, 'hex'));
206
+ }
207
+ catch (_b) {
208
+ // Input is TransactionBody only, wrap it with empty witness set
209
+ const body = CardanoWasm.TransactionBody.from_bytes(Buffer.from(rawTx, 'hex'));
210
+ const emptyWitnessSet = CardanoWasm.TransactionWitnessSet.new();
211
+ tx = CardanoWasm.Transaction.new(body, emptyWitnessSet);
212
+ console.log('[txToOneKey] Input is TransactionBody, wrapped with empty witness set');
213
+ }
211
214
  let signingMode = CardanoTxSigningMode.ORDINARY_TRANSACTION;
212
215
  const outputs = tx.body().outputs();
213
216
  const onekeyOutputs = outputsToOneKey(outputs, changeAddress);
@@ -338,52 +341,10 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
338
341
  metadata,
339
342
  };
340
343
  }
341
- else if (certKind === 9 || certKind === 15) {
342
- // Conway era: Vote Delegation (kind 9 in CDDL, may appear as 15 in some lib versions)
343
- // For hardware wallet signing, we need the stake key path
344
- const voteDelegation = (_b = cert.as_vote_delegation) === null || _b === void 0 ? void 0 : _b.call(cert);
345
- if (voteDelegation) {
346
- const credential = voteDelegation.stake_credential();
347
- certificate.type = CardanoCertificateType.VOTE_DELEGATION;
348
- if (credential.kind() === 0) {
349
- certificate.path = keys.stake.path;
350
- }
351
- else {
352
- const scriptHash = Buffer.from(credential.to_scripthash().to_bytes()).toString('hex');
353
- certificate.scriptHash = scriptHash;
354
- }
355
- // drep can be key hash, script hash, or abstain/no_confidence
356
- const drep = voteDelegation.drep();
357
- if ((_c = drep.to_key_hash) === null || _c === void 0 ? void 0 : _c.call(drep)) {
358
- certificate.dRep = {
359
- type: 0, // key hash
360
- keyHash: Buffer.from(drep.to_key_hash().to_bytes()).toString('hex'),
361
- };
362
- }
363
- else if ((_d = drep.to_script_hash) === null || _d === void 0 ? void 0 : _d.call(drep)) {
364
- certificate.dRep = {
365
- type: 1, // script hash
366
- scriptHash: Buffer.from(drep.to_script_hash().to_bytes()).toString('hex'),
367
- };
368
- }
369
- else {
370
- // abstain or no_confidence
371
- certificate.dRep = {
372
- type: drep.kind(), // 2 = abstain, 3 = no_confidence
373
- };
374
- }
375
- }
376
- else {
377
- // Fallback: just include stake path for signing
378
- console.log(`[txToOneKey] Vote delegation cert kind ${certKind}, using stake path for signing`);
379
- certificate.type = CardanoCertificateType.VOTE_DELEGATION;
380
- certificate.path = keys.stake.path;
381
- }
382
- }
383
344
  else {
384
- // Skip unsupported certificate types
345
+ // Skip unsupported certificate types (kind 4, 5, 6, etc.)
385
346
  // Don't push empty certificate objects
386
- console.log(`[txToOneKey] Unsupported certificate kind: ${certKind}, cert:`, cert.to_hex());
347
+ console.warn(`[txToOneKey] Unsupported certificate kind: ${certKind}, cert:`, cert.to_hex());
387
348
  continue;
388
349
  }
389
350
  onekeyCertificates.push(certificate);
@@ -558,6 +519,7 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
558
519
  };
559
520
  Object.keys(onekeyTx).forEach(key => !onekeyTx[key] && onekeyTx[key] != 0 && delete onekeyTx[key]);
560
521
  console.log('format onekey cardano hardware Tx =====>>> : ', onekeyTx);
522
+ console.log('[txToOneKey] certificates detail:', JSON.stringify(onekeyCertificates, null, 2));
561
523
  return Promise.resolve(onekeyTx);
562
524
  };
563
525
  exports.txToOneKey = txToOneKey;
@@ -45,6 +45,7 @@ type ITxInfo = {
45
45
  hash: string;
46
46
  size: number;
47
47
  rawTxHex?: string;
48
+ originalBodyHex?: string;
48
49
  };
49
50
  export type IEncodedTxADA = {
50
51
  inputs: IEncodeInput[];
@@ -61,20 +61,27 @@ const convertCborTxToEncodeTx = async (txHex, utxos, addresses, changeAddress) =
61
61
  var _a, _b, _c, _d;
62
62
  let body;
63
63
  let rawTxHex;
64
+ let originalBodyHex;
65
+ let isBodyOnly = false;
64
66
  console.log('CARDANO LOCAL_VERSION : 1');
65
67
  try {
66
68
  const tx = CardanoWasm.Transaction.from_bytes(Buffer.from(txHex, 'hex'));
67
69
  body = tx.body();
68
70
  rawTxHex = txHex;
71
+ // No originalBodyHex needed for full Transaction
69
72
  }
70
73
  catch (_e) {
71
74
  // Input is TransactionBody only (e.g., from staking providers like stakefish)
72
- // Build a complete Transaction with empty witness set
75
+ // IMPORTANT: Preserve the original body hex for signing to maintain CBOR encoding
76
+ isBodyOnly = true;
77
+ originalBodyHex = txHex; // Save original body hex
73
78
  body = CardanoWasm.TransactionBody.from_bytes(Buffer.from(txHex, 'hex'));
79
+ // For rawTxHex, we need to build a Transaction for compatibility
74
80
  const emptyWitnessSet = CardanoWasm.TransactionWitnessSet.new();
75
81
  const tx = CardanoWasm.Transaction.new(body, emptyWitnessSet);
76
82
  rawTxHex = Buffer.from(tx.to_bytes(), 'hex').toString('hex');
77
83
  }
84
+ console.log('[convertCborTxToEncodeTx] isBodyOnly:', isBodyOnly, 'originalBodyHex:', !!originalBodyHex);
78
85
  // Fee
79
86
  const fee = body.fee().to_str();
80
87
  const totalFeeInNative = new BigNumber(fee).shiftedBy(-1 * 6).toFixed();
@@ -229,6 +236,9 @@ const convertCborTxToEncodeTx = async (txHex, utxos, addresses, changeAddress) =
229
236
  .to_hex(),
230
237
  size: 0,
231
238
  rawTxHex,
239
+ // Original body hex from external provider, use this for signing
240
+ // to preserve CBOR encoding (important for Conway era transactions)
241
+ originalBodyHex,
232
242
  },
233
243
  signOnly: true,
234
244
  staking: stakingInfo,
@@ -22,14 +22,7 @@ export declare enum CardanoCertificateType {
22
22
  STAKE_REGISTRATION = 0,
23
23
  STAKE_DEREGISTRATION = 1,
24
24
  STAKE_DELEGATION = 2,
25
- STAKE_POOL_REGISTRATION = 3,
26
- STAKE_REGISTRATION_CONWAY = 7,
27
- STAKE_DEREGISTRATION_CONWAY = 8,
28
- VOTE_DELEGATION = 9,
29
- STAKE_AND_VOTE_DELEGATION = 10,
30
- STAKE_REGISTRATION_AND_DELEGATION = 11,
31
- VOTE_REGISTRATION_AND_DELEGATION = 12,
32
- STAKE_VOTE_REGISTRATION_AND_DELEGATION = 13
25
+ STAKE_POOL_REGISTRATION = 3
33
26
  }
34
27
  export declare enum CardanoPoolRelayType {
35
28
  SINGLE_HOST_IP = 0,
@@ -46,7 +39,7 @@ type Keys = {
46
39
  };
47
40
  /**
48
41
  *
49
- * @param {Transaction} tx
42
+ * @param {Transaction | TransactionBody} rawTx - can be full Transaction or just TransactionBody hex
50
43
  */
51
44
  export declare const txToOneKey: (rawTx: string, network: number, initKeys: Keys, xpub: string, changeAddress: IChangeAddress) => Promise<{
52
45
  signingMode: CardanoTxSigningMode.ORDINARY_TRANSACTION | CardanoTxSigningMode.POOL_REGISTRATION_AS_OWNER | CardanoTxSigningMode.PLUTUS_TRANSACTION;
@@ -27,14 +27,6 @@ export var CardanoCertificateType;
27
27
  CardanoCertificateType[CardanoCertificateType["STAKE_DEREGISTRATION"] = 1] = "STAKE_DEREGISTRATION";
28
28
  CardanoCertificateType[CardanoCertificateType["STAKE_DELEGATION"] = 2] = "STAKE_DELEGATION";
29
29
  CardanoCertificateType[CardanoCertificateType["STAKE_POOL_REGISTRATION"] = 3] = "STAKE_POOL_REGISTRATION";
30
- // Conway era
31
- CardanoCertificateType[CardanoCertificateType["STAKE_REGISTRATION_CONWAY"] = 7] = "STAKE_REGISTRATION_CONWAY";
32
- CardanoCertificateType[CardanoCertificateType["STAKE_DEREGISTRATION_CONWAY"] = 8] = "STAKE_DEREGISTRATION_CONWAY";
33
- CardanoCertificateType[CardanoCertificateType["VOTE_DELEGATION"] = 9] = "VOTE_DELEGATION";
34
- CardanoCertificateType[CardanoCertificateType["STAKE_AND_VOTE_DELEGATION"] = 10] = "STAKE_AND_VOTE_DELEGATION";
35
- CardanoCertificateType[CardanoCertificateType["STAKE_REGISTRATION_AND_DELEGATION"] = 11] = "STAKE_REGISTRATION_AND_DELEGATION";
36
- CardanoCertificateType[CardanoCertificateType["VOTE_REGISTRATION_AND_DELEGATION"] = 12] = "VOTE_REGISTRATION_AND_DELEGATION";
37
- CardanoCertificateType[CardanoCertificateType["STAKE_VOTE_REGISTRATION_AND_DELEGATION"] = 13] = "STAKE_VOTE_REGISTRATION_AND_DELEGATION";
38
30
  })(CardanoCertificateType || (CardanoCertificateType = {}));
39
31
  export var CardanoPoolRelayType;
40
32
  (function (CardanoPoolRelayType) {
@@ -176,12 +168,23 @@ const outputsToOneKey = (outputs, changeAddress) => {
176
168
  };
177
169
  /**
178
170
  *
179
- * @param {Transaction} tx
171
+ * @param {Transaction | TransactionBody} rawTx - can be full Transaction or just TransactionBody hex
180
172
  */
181
173
  export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
182
- var _a, _b, _c, _d;
174
+ var _a;
183
175
  const keys = generateKeys(initKeys, xpub);
184
- const tx = CardanoWasm.Transaction.from_bytes(Buffer.from(rawTx, 'hex'));
176
+ // Try to parse as full Transaction first, fallback to TransactionBody
177
+ let tx;
178
+ try {
179
+ tx = CardanoWasm.Transaction.from_bytes(Buffer.from(rawTx, 'hex'));
180
+ }
181
+ catch (_b) {
182
+ // Input is TransactionBody only, wrap it with empty witness set
183
+ const body = CardanoWasm.TransactionBody.from_bytes(Buffer.from(rawTx, 'hex'));
184
+ const emptyWitnessSet = CardanoWasm.TransactionWitnessSet.new();
185
+ tx = CardanoWasm.Transaction.new(body, emptyWitnessSet);
186
+ console.log('[txToOneKey] Input is TransactionBody, wrapped with empty witness set');
187
+ }
185
188
  let signingMode = CardanoTxSigningMode.ORDINARY_TRANSACTION;
186
189
  const outputs = tx.body().outputs();
187
190
  const onekeyOutputs = outputsToOneKey(outputs, changeAddress);
@@ -312,52 +315,10 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
312
315
  metadata,
313
316
  };
314
317
  }
315
- else if (certKind === 9 || certKind === 15) {
316
- // Conway era: Vote Delegation (kind 9 in CDDL, may appear as 15 in some lib versions)
317
- // For hardware wallet signing, we need the stake key path
318
- const voteDelegation = (_b = cert.as_vote_delegation) === null || _b === void 0 ? void 0 : _b.call(cert);
319
- if (voteDelegation) {
320
- const credential = voteDelegation.stake_credential();
321
- certificate.type = CardanoCertificateType.VOTE_DELEGATION;
322
- if (credential.kind() === 0) {
323
- certificate.path = keys.stake.path;
324
- }
325
- else {
326
- const scriptHash = Buffer.from(credential.to_scripthash().to_bytes()).toString('hex');
327
- certificate.scriptHash = scriptHash;
328
- }
329
- // drep can be key hash, script hash, or abstain/no_confidence
330
- const drep = voteDelegation.drep();
331
- if ((_c = drep.to_key_hash) === null || _c === void 0 ? void 0 : _c.call(drep)) {
332
- certificate.dRep = {
333
- type: 0, // key hash
334
- keyHash: Buffer.from(drep.to_key_hash().to_bytes()).toString('hex'),
335
- };
336
- }
337
- else if ((_d = drep.to_script_hash) === null || _d === void 0 ? void 0 : _d.call(drep)) {
338
- certificate.dRep = {
339
- type: 1, // script hash
340
- scriptHash: Buffer.from(drep.to_script_hash().to_bytes()).toString('hex'),
341
- };
342
- }
343
- else {
344
- // abstain or no_confidence
345
- certificate.dRep = {
346
- type: drep.kind(), // 2 = abstain, 3 = no_confidence
347
- };
348
- }
349
- }
350
- else {
351
- // Fallback: just include stake path for signing
352
- console.log(`[txToOneKey] Vote delegation cert kind ${certKind}, using stake path for signing`);
353
- certificate.type = CardanoCertificateType.VOTE_DELEGATION;
354
- certificate.path = keys.stake.path;
355
- }
356
- }
357
318
  else {
358
- // Skip unsupported certificate types
319
+ // Skip unsupported certificate types (kind 4, 5, 6, etc.)
359
320
  // Don't push empty certificate objects
360
- console.log(`[txToOneKey] Unsupported certificate kind: ${certKind}, cert:`, cert.to_hex());
321
+ console.warn(`[txToOneKey] Unsupported certificate kind: ${certKind}, cert:`, cert.to_hex());
361
322
  continue;
362
323
  }
363
324
  onekeyCertificates.push(certificate);
@@ -532,6 +493,7 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
532
493
  };
533
494
  Object.keys(onekeyTx).forEach(key => !onekeyTx[key] && onekeyTx[key] != 0 && delete onekeyTx[key]);
534
495
  console.log('format onekey cardano hardware Tx =====>>> : ', onekeyTx);
496
+ console.log('[txToOneKey] certificates detail:', JSON.stringify(onekeyCertificates, null, 2));
535
497
  return Promise.resolve(onekeyTx);
536
498
  };
537
499
  const bytesToIp = bytes => {
@@ -45,6 +45,7 @@ type ITxInfo = {
45
45
  hash: string;
46
46
  size: number;
47
47
  rawTxHex?: string;
48
+ originalBodyHex?: string;
48
49
  };
49
50
  export type IEncodedTxADA = {
50
51
  inputs: IEncodeInput[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/cardano-coin-selection-asmjs",
3
- "version": "1.1.10-alpha.1",
3
+ "version": "1.1.10-alpha.2",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "coin selection"