@onekeyfe/cardano-coin-selection-asmjs 1.1.10-alpha.0 → 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.
- package/lib/cjs/utils/onekey/dapp.js +11 -1
- package/lib/cjs/utils/onekey/txToOneKey.d.ts +1 -1
- package/lib/cjs/utils/onekey/txToOneKey.js +14 -2
- package/lib/cjs/utils/onekey/types.d.ts +1 -0
- package/lib/esm/utils/onekey/dapp.js +11 -1
- package/lib/esm/utils/onekey/txToOneKey.d.ts +1 -1
- package/lib/esm/utils/onekey/txToOneKey.js +14 -2
- package/lib/esm/utils/onekey/types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -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
|
-
//
|
|
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,
|
|
@@ -39,7 +39,7 @@ type Keys = {
|
|
|
39
39
|
};
|
|
40
40
|
/**
|
|
41
41
|
*
|
|
42
|
-
* @param {Transaction}
|
|
42
|
+
* @param {Transaction | TransactionBody} rawTx - can be full Transaction or just TransactionBody hex
|
|
43
43
|
*/
|
|
44
44
|
export declare const txToOneKey: (rawTx: string, network: number, initKeys: Keys, xpub: string, changeAddress: IChangeAddress) => Promise<{
|
|
45
45
|
signingMode: CardanoTxSigningMode.ORDINARY_TRANSACTION | CardanoTxSigningMode.POOL_REGISTRATION_AS_OWNER | CardanoTxSigningMode.PLUTUS_TRANSACTION;
|
|
@@ -194,12 +194,23 @@ const outputsToOneKey = (outputs, changeAddress) => {
|
|
|
194
194
|
};
|
|
195
195
|
/**
|
|
196
196
|
*
|
|
197
|
-
* @param {Transaction}
|
|
197
|
+
* @param {Transaction | TransactionBody} rawTx - can be full Transaction or just TransactionBody hex
|
|
198
198
|
*/
|
|
199
199
|
const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
200
200
|
var _a;
|
|
201
201
|
const keys = generateKeys(initKeys, xpub);
|
|
202
|
-
|
|
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
|
+
}
|
|
203
214
|
let signingMode = CardanoTxSigningMode.ORDINARY_TRANSACTION;
|
|
204
215
|
const outputs = tx.body().outputs();
|
|
205
216
|
const onekeyOutputs = outputsToOneKey(outputs, changeAddress);
|
|
@@ -508,6 +519,7 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
|
508
519
|
};
|
|
509
520
|
Object.keys(onekeyTx).forEach(key => !onekeyTx[key] && onekeyTx[key] != 0 && delete onekeyTx[key]);
|
|
510
521
|
console.log('format onekey cardano hardware Tx =====>>> : ', onekeyTx);
|
|
522
|
+
console.log('[txToOneKey] certificates detail:', JSON.stringify(onekeyCertificates, null, 2));
|
|
511
523
|
return Promise.resolve(onekeyTx);
|
|
512
524
|
};
|
|
513
525
|
exports.txToOneKey = txToOneKey;
|
|
@@ -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
|
-
//
|
|
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,
|
|
@@ -39,7 +39,7 @@ type Keys = {
|
|
|
39
39
|
};
|
|
40
40
|
/**
|
|
41
41
|
*
|
|
42
|
-
* @param {Transaction}
|
|
42
|
+
* @param {Transaction | TransactionBody} rawTx - can be full Transaction or just TransactionBody hex
|
|
43
43
|
*/
|
|
44
44
|
export declare const txToOneKey: (rawTx: string, network: number, initKeys: Keys, xpub: string, changeAddress: IChangeAddress) => Promise<{
|
|
45
45
|
signingMode: CardanoTxSigningMode.ORDINARY_TRANSACTION | CardanoTxSigningMode.POOL_REGISTRATION_AS_OWNER | CardanoTxSigningMode.PLUTUS_TRANSACTION;
|
|
@@ -168,12 +168,23 @@ const outputsToOneKey = (outputs, changeAddress) => {
|
|
|
168
168
|
};
|
|
169
169
|
/**
|
|
170
170
|
*
|
|
171
|
-
* @param {Transaction}
|
|
171
|
+
* @param {Transaction | TransactionBody} rawTx - can be full Transaction or just TransactionBody hex
|
|
172
172
|
*/
|
|
173
173
|
export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
174
174
|
var _a;
|
|
175
175
|
const keys = generateKeys(initKeys, xpub);
|
|
176
|
-
|
|
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
|
+
}
|
|
177
188
|
let signingMode = CardanoTxSigningMode.ORDINARY_TRANSACTION;
|
|
178
189
|
const outputs = tx.body().outputs();
|
|
179
190
|
const onekeyOutputs = outputsToOneKey(outputs, changeAddress);
|
|
@@ -482,6 +493,7 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
|
|
|
482
493
|
};
|
|
483
494
|
Object.keys(onekeyTx).forEach(key => !onekeyTx[key] && onekeyTx[key] != 0 && delete onekeyTx[key]);
|
|
484
495
|
console.log('format onekey cardano hardware Tx =====>>> : ', onekeyTx);
|
|
496
|
+
console.log('[txToOneKey] certificates detail:', JSON.stringify(onekeyCertificates, null, 2));
|
|
485
497
|
return Promise.resolve(onekeyTx);
|
|
486
498
|
};
|
|
487
499
|
const bytesToIp = bytes => {
|