@onekeyfe/cardano-coin-selection-asmjs 1.1.10-alpha.7 → 1.1.10-alpha.9
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 +24 -25
- package/lib/cjs/utils/onekey/txToOneKey.d.ts +1 -8
- package/lib/cjs/utils/onekey/txToOneKey.js +38 -61
- package/lib/esm/utils/onekey/dapp.js +24 -25
- package/lib/esm/utils/onekey/txToOneKey.d.ts +1 -8
- package/lib/esm/utils/onekey/txToOneKey.js +37 -60
- package/package.json +1 -1
|
@@ -91,7 +91,7 @@ const convertCborTxToEncodeTx = async ({ txHex, utxos, addresses, changeAddress,
|
|
|
91
91
|
var _a, _b, _c, _d;
|
|
92
92
|
let body;
|
|
93
93
|
let rawTxHex;
|
|
94
|
-
console.log('CARDANO LOCAL_VERSION :
|
|
94
|
+
// console.log('CARDANO LOCAL_VERSION : 333====>>>');
|
|
95
95
|
try {
|
|
96
96
|
const tx = CardanoWasm.Transaction.from_bytes(Buffer.from(txHex, 'hex'));
|
|
97
97
|
body = tx.body();
|
|
@@ -108,22 +108,7 @@ const convertCborTxToEncodeTx = async ({ txHex, utxos, addresses, changeAddress,
|
|
|
108
108
|
// Fee
|
|
109
109
|
const fee = body.fee().to_str();
|
|
110
110
|
const totalFeeInNative = new bignumber_js_1.default(fee).shiftedBy(-1 * 6).toFixed();
|
|
111
|
-
//
|
|
112
|
-
const encodeInputs = [];
|
|
113
|
-
const inputs = [];
|
|
114
|
-
const inputsLen = body.inputs().len();
|
|
115
|
-
for (let i = 0; i < inputsLen; i++) {
|
|
116
|
-
const input = body.inputs().get(i);
|
|
117
|
-
const txHash = Buffer.from(input.transaction_id().to_bytes(), 'utf8').toString('hex');
|
|
118
|
-
const index = input.index();
|
|
119
|
-
inputs.push({ tx_hash: txHash, tx_index: index });
|
|
120
|
-
const utxo = utxos.find(utxo => utxo.tx_hash === txHash && +utxo.tx_index === +index);
|
|
121
|
-
// Only push matched UTXOs, skip external inputs (e.g., from DeFi protocols)
|
|
122
|
-
if (utxo) {
|
|
123
|
-
encodeInputs.push(utxo);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
// Parse certificates (for staking transactions)
|
|
111
|
+
// Parse certificates first (needed to determine if this is a staking transaction)
|
|
127
112
|
const certificates = [];
|
|
128
113
|
let poolId;
|
|
129
114
|
const certs = body.certs();
|
|
@@ -183,12 +168,27 @@ const convertCborTxToEncodeTx = async ({ txHex, utxos, addresses, changeAddress,
|
|
|
183
168
|
const stakingInfo = isStakingTx
|
|
184
169
|
? { isStakingTx: true, certificates, poolId }
|
|
185
170
|
: undefined;
|
|
171
|
+
// inputs txs
|
|
172
|
+
const encodeInputs = [];
|
|
173
|
+
const inputs = [];
|
|
174
|
+
const inputsLen = body.inputs().len();
|
|
175
|
+
for (let i = 0; i < inputsLen; i++) {
|
|
176
|
+
const input = body.inputs().get(i);
|
|
177
|
+
const txHash = Buffer.from(input.transaction_id().to_bytes(), 'utf8').toString('hex');
|
|
178
|
+
const index = input.index();
|
|
179
|
+
inputs.push({ tx_hash: txHash, tx_index: index });
|
|
180
|
+
const utxo = utxos.find(utxo => utxo.tx_hash === txHash && +utxo.tx_index === +index);
|
|
181
|
+
// Only push matched UTXOs, skip external inputs (e.g., from DeFi protocols)
|
|
182
|
+
if (utxo) {
|
|
183
|
+
encodeInputs.push(utxo);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
186
|
// outputs txs
|
|
187
187
|
const outputs = [];
|
|
188
188
|
const outputsLen = body.outputs().len();
|
|
189
|
-
//
|
|
190
|
-
//
|
|
191
|
-
if (outputsLen === 0) {
|
|
189
|
+
// Staking transactions (delegation, registration, deregistration) can have empty outputs
|
|
190
|
+
// Regular transactions must have at least one output
|
|
191
|
+
if (outputsLen === 0 && !isStakingTx) {
|
|
192
192
|
console.log('[convertCborTxToEncodeTx] Empty outputs detected, transaction data:', {
|
|
193
193
|
fee,
|
|
194
194
|
totalFeeInNative,
|
|
@@ -199,9 +199,6 @@ const convertCborTxToEncodeTx = async ({ txHex, utxos, addresses, changeAddress,
|
|
|
199
199
|
tx_index: u.tx_index,
|
|
200
200
|
amount: u.amount,
|
|
201
201
|
})),
|
|
202
|
-
isStakingTx,
|
|
203
|
-
certificates,
|
|
204
|
-
poolId,
|
|
205
202
|
});
|
|
206
203
|
throw new errors_1.CoinSelectionError(constants_1.ERROR.UTXO_BALANCE_INSUFFICIENT);
|
|
207
204
|
}
|
|
@@ -244,7 +241,9 @@ const convertCborTxToEncodeTx = async ({ txHex, utxos, addresses, changeAddress,
|
|
|
244
241
|
isChange,
|
|
245
242
|
});
|
|
246
243
|
}
|
|
247
|
-
const totalSpent =
|
|
244
|
+
const totalSpent = outputs.length > 0
|
|
245
|
+
? bignumber_js_1.default.sum(...outputs.map(o => o.amount)).toFixed()
|
|
246
|
+
: '0';
|
|
248
247
|
const token = (_b = (_a = outputs
|
|
249
248
|
.filter(o => !addresses.includes(o.address))
|
|
250
249
|
.find(o => o.assets.length > 0)) === null || _a === void 0 ? void 0 : _a.assets) === null || _b === void 0 ? void 0 : _b[0].unit;
|
|
@@ -252,7 +251,7 @@ const convertCborTxToEncodeTx = async ({ txHex, utxos, addresses, changeAddress,
|
|
|
252
251
|
const fromAddress = ((_c = encodeInputs[0]) === null || _c === void 0 ? void 0 : _c.address) || changeAddress.address || '';
|
|
253
252
|
// For staking transactions, 'to' can be the pool id or empty
|
|
254
253
|
const toAddress = isStakingTx
|
|
255
|
-
?
|
|
254
|
+
? fromAddress || ''
|
|
256
255
|
: ((_d = outputs[0]) === null || _d === void 0 ? void 0 : _d.address) || '';
|
|
257
256
|
const encodedTx = {
|
|
258
257
|
inputs: encodeInputs.map(input => (Object.assign(Object.assign({}, input), { txHash: input.tx_hash, outputIndex: input.tx_index }))),
|
|
@@ -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
|
-
VOTE_DELEGATION = 9
|
|
27
|
-
}
|
|
28
|
-
export declare enum CardanoDRepType {
|
|
29
|
-
KEY_HASH = 0,
|
|
30
|
-
SCRIPT_HASH = 1,
|
|
31
|
-
ABSTAIN = 2,
|
|
32
|
-
NO_CONFIDENCE = 3
|
|
25
|
+
STAKE_POOL_REGISTRATION = 3
|
|
33
26
|
}
|
|
34
27
|
export declare enum CardanoPoolRelayType {
|
|
35
28
|
SINGLE_HOST_IP = 0,
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.txToOneKey = exports.CardanoPoolRelayType = exports.
|
|
26
|
+
exports.txToOneKey = exports.CardanoPoolRelayType = exports.CardanoCertificateType = exports.CardanoTxSigningMode = exports.CardanoAddressType = void 0;
|
|
27
27
|
// @ts-nocheck
|
|
28
28
|
const CardanoWasm = __importStar(require("@emurgo/cardano-serialization-lib-asmjs"));
|
|
29
29
|
var CardanoAddressType;
|
|
@@ -53,15 +53,7 @@ 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
|
-
CardanoCertificateType[CardanoCertificateType["VOTE_DELEGATION"] = 9] = "VOTE_DELEGATION";
|
|
57
56
|
})(CardanoCertificateType || (exports.CardanoCertificateType = CardanoCertificateType = {}));
|
|
58
|
-
var CardanoDRepType;
|
|
59
|
-
(function (CardanoDRepType) {
|
|
60
|
-
CardanoDRepType[CardanoDRepType["KEY_HASH"] = 0] = "KEY_HASH";
|
|
61
|
-
CardanoDRepType[CardanoDRepType["SCRIPT_HASH"] = 1] = "SCRIPT_HASH";
|
|
62
|
-
CardanoDRepType[CardanoDRepType["ABSTAIN"] = 2] = "ABSTAIN";
|
|
63
|
-
CardanoDRepType[CardanoDRepType["NO_CONFIDENCE"] = 3] = "NO_CONFIDENCE";
|
|
64
|
-
})(CardanoDRepType || (exports.CardanoDRepType = CardanoDRepType = {}));
|
|
65
57
|
var CardanoPoolRelayType;
|
|
66
58
|
(function (CardanoPoolRelayType) {
|
|
67
59
|
CardanoPoolRelayType[CardanoPoolRelayType["SINGLE_HOST_IP"] = 0] = "SINGLE_HOST_IP";
|
|
@@ -205,7 +197,7 @@ const outputsToOneKey = (outputs, changeAddress) => {
|
|
|
205
197
|
* @param {Transaction} tx
|
|
206
198
|
*/
|
|
207
199
|
const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
208
|
-
var _a
|
|
200
|
+
var _a;
|
|
209
201
|
const keys = generateKeys(initKeys, xpub);
|
|
210
202
|
const tx = CardanoWasm.Transaction.from_bytes(Buffer.from(rawTx, 'hex'));
|
|
211
203
|
let signingMode = CardanoTxSigningMode.ORDINARY_TRANSACTION;
|
|
@@ -218,8 +210,7 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
|
218
210
|
for (let i = 0; i < certificates.len(); i++) {
|
|
219
211
|
const cert = certificates.get(i);
|
|
220
212
|
const certificate = {};
|
|
221
|
-
|
|
222
|
-
if (certKind === 0) {
|
|
213
|
+
if (cert.kind() === 0) {
|
|
223
214
|
const credential = (_a = cert.as_stake_registration()) === null || _a === void 0 ? void 0 : _a.stake_credential();
|
|
224
215
|
certificate.type = CardanoCertificateType.STAKE_REGISTRATION;
|
|
225
216
|
if ((credential === null || credential === void 0 ? void 0 : credential.kind()) === 0) {
|
|
@@ -230,7 +221,7 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
|
230
221
|
certificate.scriptHash = scriptHash;
|
|
231
222
|
}
|
|
232
223
|
}
|
|
233
|
-
else if (
|
|
224
|
+
else if (cert.kind() === 1) {
|
|
234
225
|
const credential = cert.as_stake_deregistration().stake_credential();
|
|
235
226
|
certificate.type = CardanoCertificateType.STAKE_DEREGISTRATION;
|
|
236
227
|
if (credential.kind() === 0) {
|
|
@@ -241,7 +232,7 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
|
241
232
|
certificate.scriptHash = scriptHash;
|
|
242
233
|
}
|
|
243
234
|
}
|
|
244
|
-
else if (
|
|
235
|
+
else if (cert.kind() === 2) {
|
|
245
236
|
const delegation = cert.as_stake_delegation();
|
|
246
237
|
const credential = delegation.stake_credential();
|
|
247
238
|
const poolKeyHashHex = Buffer.from(delegation.pool_keyhash().to_bytes()).toString('hex');
|
|
@@ -255,7 +246,7 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
|
255
246
|
}
|
|
256
247
|
certificate.pool = poolKeyHashHex;
|
|
257
248
|
}
|
|
258
|
-
else if (
|
|
249
|
+
else if (cert.kind() === 3) {
|
|
259
250
|
const params = cert.as_pool_registration().pool_params();
|
|
260
251
|
certificate.type = CardanoCertificateType.STAKE_POOL_REGISTRATION;
|
|
261
252
|
const owners = params.pool_owners();
|
|
@@ -338,41 +329,6 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
|
338
329
|
metadata,
|
|
339
330
|
};
|
|
340
331
|
}
|
|
341
|
-
else if (certKind === 15) {
|
|
342
|
-
// VoteDelegation (CertificateKind.VoteDelegation = 15 in WASM lib)
|
|
343
|
-
const voteDelegation = cert.as_vote_delegation();
|
|
344
|
-
const credential = voteDelegation.stake_credential();
|
|
345
|
-
certificate.type = CardanoCertificateType.VOTE_DELEGATION;
|
|
346
|
-
if (credential.kind() === 0) {
|
|
347
|
-
certificate.path = keys.stake.path;
|
|
348
|
-
}
|
|
349
|
-
else {
|
|
350
|
-
const scriptHash = Buffer.from(credential.to_scripthash().to_bytes()).toString('hex');
|
|
351
|
-
certificate.scriptHash = scriptHash;
|
|
352
|
-
}
|
|
353
|
-
// Parse DRep
|
|
354
|
-
const drep = voteDelegation.drep();
|
|
355
|
-
const drepKind = drep.kind();
|
|
356
|
-
// DRepKind: KeyHash = 0, ScriptHash = 1, AlwaysAbstain = 2, AlwaysNoConfidence = 3
|
|
357
|
-
certificate.dRep = {
|
|
358
|
-
type: drepKind,
|
|
359
|
-
};
|
|
360
|
-
if (drepKind === 0) {
|
|
361
|
-
// KEY_HASH
|
|
362
|
-
certificate.dRep.keyHash = (_b = drep.to_key_hash()) === null || _b === void 0 ? void 0 : _b.to_hex();
|
|
363
|
-
}
|
|
364
|
-
else if (drepKind === 1) {
|
|
365
|
-
// SCRIPT_HASH
|
|
366
|
-
certificate.dRep.scriptHash = (_c = drep.to_script_hash()) === null || _c === void 0 ? void 0 : _c.to_hex();
|
|
367
|
-
}
|
|
368
|
-
// ABSTAIN (2) and NO_CONFIDENCE (3) don't need additional fields
|
|
369
|
-
}
|
|
370
|
-
else {
|
|
371
|
-
// Skip unsupported certificate types (kind 4, 5, 6, etc.)
|
|
372
|
-
// Don't push empty certificate objects
|
|
373
|
-
console.warn(`[txToOneKey] Unsupported certificate kind: ${certKind}, cert:`, cert.to_hex());
|
|
374
|
-
continue;
|
|
375
|
-
}
|
|
376
332
|
onekeyCertificates.push(certificate);
|
|
377
333
|
}
|
|
378
334
|
}
|
|
@@ -410,17 +366,36 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
|
410
366
|
mintBundle = [];
|
|
411
367
|
for (let j = 0; j < mint.keys().len(); j++) {
|
|
412
368
|
const policy = mint.keys().get(j);
|
|
413
|
-
const
|
|
369
|
+
const mintsAssets = mint.get(policy);
|
|
414
370
|
const tokens = [];
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
371
|
+
// CSL 13: Mint.get(policy) returns MintsAssets (a list of MintAssets),
|
|
372
|
+
// not a single MintAssets map. Iterate the list, then iterate each map.
|
|
373
|
+
// The runtime shape is detected so pre-CSL-13 builds still work.
|
|
374
|
+
const mintsLen =
|
|
375
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
376
|
+
typeof mintsAssets.len === 'function'
|
|
377
|
+
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
378
|
+
mintsAssets.len()
|
|
379
|
+
: 1;
|
|
380
|
+
for (let mai = 0; mai < mintsLen; mai++) {
|
|
381
|
+
const assets =
|
|
382
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
383
|
+
typeof mintsAssets.get === 'function' &&
|
|
384
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
385
|
+
typeof mintsAssets.len === 'function'
|
|
386
|
+
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
387
|
+
mintsAssets.get(mai)
|
|
388
|
+
: mintsAssets;
|
|
389
|
+
for (let k = 0; k < assets.keys().len(); k++) {
|
|
390
|
+
const assetName = assets.keys().get(k);
|
|
391
|
+
const amount = assets.get(assetName);
|
|
392
|
+
tokens.push({
|
|
393
|
+
assetNameBytes: Buffer.from(assetName.name()).toString('hex'),
|
|
394
|
+
mintAmount: amount.is_positive()
|
|
395
|
+
? amount.as_positive().to_str()
|
|
396
|
+
: '-' + amount.as_negative().to_str(),
|
|
397
|
+
});
|
|
398
|
+
}
|
|
424
399
|
}
|
|
425
400
|
// sort canonical
|
|
426
401
|
sortCanonicallyInPlace(tokens, item => item.assetNameBytes);
|
|
@@ -493,7 +468,9 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
|
493
468
|
for (let i = 0; i < ri.len(); i++) {
|
|
494
469
|
referenceInputs.push({
|
|
495
470
|
prev_hash: ri.get(i).transaction_id().to_hex(),
|
|
496
|
-
|
|
471
|
+
// CSL 13: TransactionInput.index() returns a number directly, not a
|
|
472
|
+
// BigNum — the legacy `.to_str()` call crashes at runtime.
|
|
473
|
+
prev_index: parseInt(String(ri.get(i).index())),
|
|
497
474
|
});
|
|
498
475
|
}
|
|
499
476
|
signingMode = CardanoTxSigningMode.PLUTUS_TRANSACTION;
|
|
@@ -61,7 +61,7 @@ const convertCborTxToEncodeTx = async ({ txHex, utxos, addresses, changeAddress,
|
|
|
61
61
|
var _a, _b, _c, _d;
|
|
62
62
|
let body;
|
|
63
63
|
let rawTxHex;
|
|
64
|
-
console.log('CARDANO LOCAL_VERSION :
|
|
64
|
+
// console.log('CARDANO LOCAL_VERSION : 333====>>>');
|
|
65
65
|
try {
|
|
66
66
|
const tx = CardanoWasm.Transaction.from_bytes(Buffer.from(txHex, 'hex'));
|
|
67
67
|
body = tx.body();
|
|
@@ -78,22 +78,7 @@ const convertCborTxToEncodeTx = async ({ txHex, utxos, addresses, changeAddress,
|
|
|
78
78
|
// Fee
|
|
79
79
|
const fee = body.fee().to_str();
|
|
80
80
|
const totalFeeInNative = new BigNumber(fee).shiftedBy(-1 * 6).toFixed();
|
|
81
|
-
//
|
|
82
|
-
const encodeInputs = [];
|
|
83
|
-
const inputs = [];
|
|
84
|
-
const inputsLen = body.inputs().len();
|
|
85
|
-
for (let i = 0; i < inputsLen; i++) {
|
|
86
|
-
const input = body.inputs().get(i);
|
|
87
|
-
const txHash = Buffer.from(input.transaction_id().to_bytes(), 'utf8').toString('hex');
|
|
88
|
-
const index = input.index();
|
|
89
|
-
inputs.push({ tx_hash: txHash, tx_index: index });
|
|
90
|
-
const utxo = utxos.find(utxo => utxo.tx_hash === txHash && +utxo.tx_index === +index);
|
|
91
|
-
// Only push matched UTXOs, skip external inputs (e.g., from DeFi protocols)
|
|
92
|
-
if (utxo) {
|
|
93
|
-
encodeInputs.push(utxo);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
// Parse certificates (for staking transactions)
|
|
81
|
+
// Parse certificates first (needed to determine if this is a staking transaction)
|
|
97
82
|
const certificates = [];
|
|
98
83
|
let poolId;
|
|
99
84
|
const certs = body.certs();
|
|
@@ -153,12 +138,27 @@ const convertCborTxToEncodeTx = async ({ txHex, utxos, addresses, changeAddress,
|
|
|
153
138
|
const stakingInfo = isStakingTx
|
|
154
139
|
? { isStakingTx: true, certificates, poolId }
|
|
155
140
|
: undefined;
|
|
141
|
+
// inputs txs
|
|
142
|
+
const encodeInputs = [];
|
|
143
|
+
const inputs = [];
|
|
144
|
+
const inputsLen = body.inputs().len();
|
|
145
|
+
for (let i = 0; i < inputsLen; i++) {
|
|
146
|
+
const input = body.inputs().get(i);
|
|
147
|
+
const txHash = Buffer.from(input.transaction_id().to_bytes(), 'utf8').toString('hex');
|
|
148
|
+
const index = input.index();
|
|
149
|
+
inputs.push({ tx_hash: txHash, tx_index: index });
|
|
150
|
+
const utxo = utxos.find(utxo => utxo.tx_hash === txHash && +utxo.tx_index === +index);
|
|
151
|
+
// Only push matched UTXOs, skip external inputs (e.g., from DeFi protocols)
|
|
152
|
+
if (utxo) {
|
|
153
|
+
encodeInputs.push(utxo);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
156
|
// outputs txs
|
|
157
157
|
const outputs = [];
|
|
158
158
|
const outputsLen = body.outputs().len();
|
|
159
|
-
//
|
|
160
|
-
//
|
|
161
|
-
if (outputsLen === 0) {
|
|
159
|
+
// Staking transactions (delegation, registration, deregistration) can have empty outputs
|
|
160
|
+
// Regular transactions must have at least one output
|
|
161
|
+
if (outputsLen === 0 && !isStakingTx) {
|
|
162
162
|
console.log('[convertCborTxToEncodeTx] Empty outputs detected, transaction data:', {
|
|
163
163
|
fee,
|
|
164
164
|
totalFeeInNative,
|
|
@@ -169,9 +169,6 @@ const convertCborTxToEncodeTx = async ({ txHex, utxos, addresses, changeAddress,
|
|
|
169
169
|
tx_index: u.tx_index,
|
|
170
170
|
amount: u.amount,
|
|
171
171
|
})),
|
|
172
|
-
isStakingTx,
|
|
173
|
-
certificates,
|
|
174
|
-
poolId,
|
|
175
172
|
});
|
|
176
173
|
throw new CoinSelectionError(ERROR.UTXO_BALANCE_INSUFFICIENT);
|
|
177
174
|
}
|
|
@@ -214,7 +211,9 @@ const convertCborTxToEncodeTx = async ({ txHex, utxos, addresses, changeAddress,
|
|
|
214
211
|
isChange,
|
|
215
212
|
});
|
|
216
213
|
}
|
|
217
|
-
const totalSpent =
|
|
214
|
+
const totalSpent = outputs.length > 0
|
|
215
|
+
? BigNumber.sum(...outputs.map(o => o.amount)).toFixed()
|
|
216
|
+
: '0';
|
|
218
217
|
const token = (_b = (_a = outputs
|
|
219
218
|
.filter(o => !addresses.includes(o.address))
|
|
220
219
|
.find(o => o.assets.length > 0)) === null || _a === void 0 ? void 0 : _a.assets) === null || _b === void 0 ? void 0 : _b[0].unit;
|
|
@@ -222,7 +221,7 @@ const convertCborTxToEncodeTx = async ({ txHex, utxos, addresses, changeAddress,
|
|
|
222
221
|
const fromAddress = ((_c = encodeInputs[0]) === null || _c === void 0 ? void 0 : _c.address) || changeAddress.address || '';
|
|
223
222
|
// For staking transactions, 'to' can be the pool id or empty
|
|
224
223
|
const toAddress = isStakingTx
|
|
225
|
-
?
|
|
224
|
+
? fromAddress || ''
|
|
226
225
|
: ((_d = outputs[0]) === null || _d === void 0 ? void 0 : _d.address) || '';
|
|
227
226
|
const encodedTx = {
|
|
228
227
|
inputs: encodeInputs.map(input => (Object.assign(Object.assign({}, input), { txHash: input.tx_hash, outputIndex: input.tx_index }))),
|
|
@@ -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
|
-
VOTE_DELEGATION = 9
|
|
27
|
-
}
|
|
28
|
-
export declare enum CardanoDRepType {
|
|
29
|
-
KEY_HASH = 0,
|
|
30
|
-
SCRIPT_HASH = 1,
|
|
31
|
-
ABSTAIN = 2,
|
|
32
|
-
NO_CONFIDENCE = 3
|
|
25
|
+
STAKE_POOL_REGISTRATION = 3
|
|
33
26
|
}
|
|
34
27
|
export declare enum CardanoPoolRelayType {
|
|
35
28
|
SINGLE_HOST_IP = 0,
|
|
@@ -27,15 +27,7 @@ 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
|
-
CardanoCertificateType[CardanoCertificateType["VOTE_DELEGATION"] = 9] = "VOTE_DELEGATION";
|
|
31
30
|
})(CardanoCertificateType || (CardanoCertificateType = {}));
|
|
32
|
-
export var CardanoDRepType;
|
|
33
|
-
(function (CardanoDRepType) {
|
|
34
|
-
CardanoDRepType[CardanoDRepType["KEY_HASH"] = 0] = "KEY_HASH";
|
|
35
|
-
CardanoDRepType[CardanoDRepType["SCRIPT_HASH"] = 1] = "SCRIPT_HASH";
|
|
36
|
-
CardanoDRepType[CardanoDRepType["ABSTAIN"] = 2] = "ABSTAIN";
|
|
37
|
-
CardanoDRepType[CardanoDRepType["NO_CONFIDENCE"] = 3] = "NO_CONFIDENCE";
|
|
38
|
-
})(CardanoDRepType || (CardanoDRepType = {}));
|
|
39
31
|
export var CardanoPoolRelayType;
|
|
40
32
|
(function (CardanoPoolRelayType) {
|
|
41
33
|
CardanoPoolRelayType[CardanoPoolRelayType["SINGLE_HOST_IP"] = 0] = "SINGLE_HOST_IP";
|
|
@@ -179,7 +171,7 @@ const outputsToOneKey = (outputs, changeAddress) => {
|
|
|
179
171
|
* @param {Transaction} tx
|
|
180
172
|
*/
|
|
181
173
|
export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
182
|
-
var _a
|
|
174
|
+
var _a;
|
|
183
175
|
const keys = generateKeys(initKeys, xpub);
|
|
184
176
|
const tx = CardanoWasm.Transaction.from_bytes(Buffer.from(rawTx, 'hex'));
|
|
185
177
|
let signingMode = CardanoTxSigningMode.ORDINARY_TRANSACTION;
|
|
@@ -192,8 +184,7 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
|
|
|
192
184
|
for (let i = 0; i < certificates.len(); i++) {
|
|
193
185
|
const cert = certificates.get(i);
|
|
194
186
|
const certificate = {};
|
|
195
|
-
|
|
196
|
-
if (certKind === 0) {
|
|
187
|
+
if (cert.kind() === 0) {
|
|
197
188
|
const credential = (_a = cert.as_stake_registration()) === null || _a === void 0 ? void 0 : _a.stake_credential();
|
|
198
189
|
certificate.type = CardanoCertificateType.STAKE_REGISTRATION;
|
|
199
190
|
if ((credential === null || credential === void 0 ? void 0 : credential.kind()) === 0) {
|
|
@@ -204,7 +195,7 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
|
|
|
204
195
|
certificate.scriptHash = scriptHash;
|
|
205
196
|
}
|
|
206
197
|
}
|
|
207
|
-
else if (
|
|
198
|
+
else if (cert.kind() === 1) {
|
|
208
199
|
const credential = cert.as_stake_deregistration().stake_credential();
|
|
209
200
|
certificate.type = CardanoCertificateType.STAKE_DEREGISTRATION;
|
|
210
201
|
if (credential.kind() === 0) {
|
|
@@ -215,7 +206,7 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
|
|
|
215
206
|
certificate.scriptHash = scriptHash;
|
|
216
207
|
}
|
|
217
208
|
}
|
|
218
|
-
else if (
|
|
209
|
+
else if (cert.kind() === 2) {
|
|
219
210
|
const delegation = cert.as_stake_delegation();
|
|
220
211
|
const credential = delegation.stake_credential();
|
|
221
212
|
const poolKeyHashHex = Buffer.from(delegation.pool_keyhash().to_bytes()).toString('hex');
|
|
@@ -229,7 +220,7 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
|
|
|
229
220
|
}
|
|
230
221
|
certificate.pool = poolKeyHashHex;
|
|
231
222
|
}
|
|
232
|
-
else if (
|
|
223
|
+
else if (cert.kind() === 3) {
|
|
233
224
|
const params = cert.as_pool_registration().pool_params();
|
|
234
225
|
certificate.type = CardanoCertificateType.STAKE_POOL_REGISTRATION;
|
|
235
226
|
const owners = params.pool_owners();
|
|
@@ -312,41 +303,6 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
|
|
|
312
303
|
metadata,
|
|
313
304
|
};
|
|
314
305
|
}
|
|
315
|
-
else if (certKind === 15) {
|
|
316
|
-
// VoteDelegation (CertificateKind.VoteDelegation = 15 in WASM lib)
|
|
317
|
-
const voteDelegation = cert.as_vote_delegation();
|
|
318
|
-
const credential = voteDelegation.stake_credential();
|
|
319
|
-
certificate.type = CardanoCertificateType.VOTE_DELEGATION;
|
|
320
|
-
if (credential.kind() === 0) {
|
|
321
|
-
certificate.path = keys.stake.path;
|
|
322
|
-
}
|
|
323
|
-
else {
|
|
324
|
-
const scriptHash = Buffer.from(credential.to_scripthash().to_bytes()).toString('hex');
|
|
325
|
-
certificate.scriptHash = scriptHash;
|
|
326
|
-
}
|
|
327
|
-
// Parse DRep
|
|
328
|
-
const drep = voteDelegation.drep();
|
|
329
|
-
const drepKind = drep.kind();
|
|
330
|
-
// DRepKind: KeyHash = 0, ScriptHash = 1, AlwaysAbstain = 2, AlwaysNoConfidence = 3
|
|
331
|
-
certificate.dRep = {
|
|
332
|
-
type: drepKind,
|
|
333
|
-
};
|
|
334
|
-
if (drepKind === 0) {
|
|
335
|
-
// KEY_HASH
|
|
336
|
-
certificate.dRep.keyHash = (_b = drep.to_key_hash()) === null || _b === void 0 ? void 0 : _b.to_hex();
|
|
337
|
-
}
|
|
338
|
-
else if (drepKind === 1) {
|
|
339
|
-
// SCRIPT_HASH
|
|
340
|
-
certificate.dRep.scriptHash = (_c = drep.to_script_hash()) === null || _c === void 0 ? void 0 : _c.to_hex();
|
|
341
|
-
}
|
|
342
|
-
// ABSTAIN (2) and NO_CONFIDENCE (3) don't need additional fields
|
|
343
|
-
}
|
|
344
|
-
else {
|
|
345
|
-
// Skip unsupported certificate types (kind 4, 5, 6, etc.)
|
|
346
|
-
// Don't push empty certificate objects
|
|
347
|
-
console.warn(`[txToOneKey] Unsupported certificate kind: ${certKind}, cert:`, cert.to_hex());
|
|
348
|
-
continue;
|
|
349
|
-
}
|
|
350
306
|
onekeyCertificates.push(certificate);
|
|
351
307
|
}
|
|
352
308
|
}
|
|
@@ -384,17 +340,36 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
|
|
|
384
340
|
mintBundle = [];
|
|
385
341
|
for (let j = 0; j < mint.keys().len(); j++) {
|
|
386
342
|
const policy = mint.keys().get(j);
|
|
387
|
-
const
|
|
343
|
+
const mintsAssets = mint.get(policy);
|
|
388
344
|
const tokens = [];
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
345
|
+
// CSL 13: Mint.get(policy) returns MintsAssets (a list of MintAssets),
|
|
346
|
+
// not a single MintAssets map. Iterate the list, then iterate each map.
|
|
347
|
+
// The runtime shape is detected so pre-CSL-13 builds still work.
|
|
348
|
+
const mintsLen =
|
|
349
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
350
|
+
typeof mintsAssets.len === 'function'
|
|
351
|
+
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
352
|
+
mintsAssets.len()
|
|
353
|
+
: 1;
|
|
354
|
+
for (let mai = 0; mai < mintsLen; mai++) {
|
|
355
|
+
const assets =
|
|
356
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
357
|
+
typeof mintsAssets.get === 'function' &&
|
|
358
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
359
|
+
typeof mintsAssets.len === 'function'
|
|
360
|
+
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
361
|
+
mintsAssets.get(mai)
|
|
362
|
+
: mintsAssets;
|
|
363
|
+
for (let k = 0; k < assets.keys().len(); k++) {
|
|
364
|
+
const assetName = assets.keys().get(k);
|
|
365
|
+
const amount = assets.get(assetName);
|
|
366
|
+
tokens.push({
|
|
367
|
+
assetNameBytes: Buffer.from(assetName.name()).toString('hex'),
|
|
368
|
+
mintAmount: amount.is_positive()
|
|
369
|
+
? amount.as_positive().to_str()
|
|
370
|
+
: '-' + amount.as_negative().to_str(),
|
|
371
|
+
});
|
|
372
|
+
}
|
|
398
373
|
}
|
|
399
374
|
// sort canonical
|
|
400
375
|
sortCanonicallyInPlace(tokens, item => item.assetNameBytes);
|
|
@@ -467,7 +442,9 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
|
|
|
467
442
|
for (let i = 0; i < ri.len(); i++) {
|
|
468
443
|
referenceInputs.push({
|
|
469
444
|
prev_hash: ri.get(i).transaction_id().to_hex(),
|
|
470
|
-
|
|
445
|
+
// CSL 13: TransactionInput.index() returns a number directly, not a
|
|
446
|
+
// BigNum — the legacy `.to_str()` call crashes at runtime.
|
|
447
|
+
prev_index: parseInt(String(ri.get(i).index())),
|
|
471
448
|
});
|
|
472
449
|
}
|
|
473
450
|
signingMode = CardanoTxSigningMode.PLUTUS_TRANSACTION;
|