@onekeyfe/cardano-coin-selection-asmjs 1.1.10-alpha.8 → 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.
|
@@ -22,16 +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
|
-
}
|
|
30
|
-
export declare enum CardanoDRepType {
|
|
31
|
-
KEY_HASH = 0,
|
|
32
|
-
SCRIPT_HASH = 1,
|
|
33
|
-
ABSTAIN = 2,
|
|
34
|
-
NO_CONFIDENCE = 3
|
|
25
|
+
STAKE_POOL_REGISTRATION = 3
|
|
35
26
|
}
|
|
36
27
|
export declare enum CardanoPoolRelayType {
|
|
37
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,17 +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["STAKE_REGISTRATION_CONWAY"] = 7] = "STAKE_REGISTRATION_CONWAY";
|
|
57
|
-
CardanoCertificateType[CardanoCertificateType["STAKE_DEREGISTRATION_CONWAY"] = 8] = "STAKE_DEREGISTRATION_CONWAY";
|
|
58
|
-
CardanoCertificateType[CardanoCertificateType["VOTE_DELEGATION"] = 9] = "VOTE_DELEGATION";
|
|
59
56
|
})(CardanoCertificateType || (exports.CardanoCertificateType = CardanoCertificateType = {}));
|
|
60
|
-
var CardanoDRepType;
|
|
61
|
-
(function (CardanoDRepType) {
|
|
62
|
-
CardanoDRepType[CardanoDRepType["KEY_HASH"] = 0] = "KEY_HASH";
|
|
63
|
-
CardanoDRepType[CardanoDRepType["SCRIPT_HASH"] = 1] = "SCRIPT_HASH";
|
|
64
|
-
CardanoDRepType[CardanoDRepType["ABSTAIN"] = 2] = "ABSTAIN";
|
|
65
|
-
CardanoDRepType[CardanoDRepType["NO_CONFIDENCE"] = 3] = "NO_CONFIDENCE";
|
|
66
|
-
})(CardanoDRepType || (exports.CardanoDRepType = CardanoDRepType = {}));
|
|
67
57
|
var CardanoPoolRelayType;
|
|
68
58
|
(function (CardanoPoolRelayType) {
|
|
69
59
|
CardanoPoolRelayType[CardanoPoolRelayType["SINGLE_HOST_IP"] = 0] = "SINGLE_HOST_IP";
|
|
@@ -207,7 +197,7 @@ const outputsToOneKey = (outputs, changeAddress) => {
|
|
|
207
197
|
* @param {Transaction} tx
|
|
208
198
|
*/
|
|
209
199
|
const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
210
|
-
var _a
|
|
200
|
+
var _a;
|
|
211
201
|
const keys = generateKeys(initKeys, xpub);
|
|
212
202
|
const tx = CardanoWasm.Transaction.from_bytes(Buffer.from(rawTx, 'hex'));
|
|
213
203
|
let signingMode = CardanoTxSigningMode.ORDINARY_TRANSACTION;
|
|
@@ -220,20 +210,9 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
|
220
210
|
for (let i = 0; i < certificates.len(); i++) {
|
|
221
211
|
const cert = certificates.get(i);
|
|
222
212
|
const certificate = {};
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
const credential = stakeRegistration === null || stakeRegistration === void 0 ? void 0 : stakeRegistration.stake_credential();
|
|
227
|
-
const deposit = (_a = stakeRegistration === null || stakeRegistration === void 0 ? void 0 : stakeRegistration.coin) === null || _a === void 0 ? void 0 : _a.call(stakeRegistration);
|
|
228
|
-
if (deposit) {
|
|
229
|
-
// Conway era - reg_cert with deposit
|
|
230
|
-
certificate.type = CardanoCertificateType.STAKE_REGISTRATION_CONWAY;
|
|
231
|
-
certificate.deposit = deposit.to_str();
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
// Pre-Conway - stake_registration without deposit
|
|
235
|
-
certificate.type = CardanoCertificateType.STAKE_REGISTRATION;
|
|
236
|
-
}
|
|
213
|
+
if (cert.kind() === 0) {
|
|
214
|
+
const credential = (_a = cert.as_stake_registration()) === null || _a === void 0 ? void 0 : _a.stake_credential();
|
|
215
|
+
certificate.type = CardanoCertificateType.STAKE_REGISTRATION;
|
|
237
216
|
if ((credential === null || credential === void 0 ? void 0 : credential.kind()) === 0) {
|
|
238
217
|
certificate.path = keys.stake.path;
|
|
239
218
|
}
|
|
@@ -242,19 +221,9 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
|
242
221
|
certificate.scriptHash = scriptHash;
|
|
243
222
|
}
|
|
244
223
|
}
|
|
245
|
-
else if (
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
const deposit = (_b = stakeDeregistration.coin) === null || _b === void 0 ? void 0 : _b.call(stakeDeregistration);
|
|
249
|
-
if (deposit) {
|
|
250
|
-
// Conway era - unreg_cert with deposit
|
|
251
|
-
certificate.type = CardanoCertificateType.STAKE_DEREGISTRATION_CONWAY;
|
|
252
|
-
certificate.deposit = deposit.to_str();
|
|
253
|
-
}
|
|
254
|
-
else {
|
|
255
|
-
// Pre-Conway - stake_deregistration without deposit
|
|
256
|
-
certificate.type = CardanoCertificateType.STAKE_DEREGISTRATION;
|
|
257
|
-
}
|
|
224
|
+
else if (cert.kind() === 1) {
|
|
225
|
+
const credential = cert.as_stake_deregistration().stake_credential();
|
|
226
|
+
certificate.type = CardanoCertificateType.STAKE_DEREGISTRATION;
|
|
258
227
|
if (credential.kind() === 0) {
|
|
259
228
|
certificate.path = keys.stake.path;
|
|
260
229
|
}
|
|
@@ -263,7 +232,7 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
|
263
232
|
certificate.scriptHash = scriptHash;
|
|
264
233
|
}
|
|
265
234
|
}
|
|
266
|
-
else if (
|
|
235
|
+
else if (cert.kind() === 2) {
|
|
267
236
|
const delegation = cert.as_stake_delegation();
|
|
268
237
|
const credential = delegation.stake_credential();
|
|
269
238
|
const poolKeyHashHex = Buffer.from(delegation.pool_keyhash().to_bytes()).toString('hex');
|
|
@@ -277,7 +246,7 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
|
277
246
|
}
|
|
278
247
|
certificate.pool = poolKeyHashHex;
|
|
279
248
|
}
|
|
280
|
-
else if (
|
|
249
|
+
else if (cert.kind() === 3) {
|
|
281
250
|
const params = cert.as_pool_registration().pool_params();
|
|
282
251
|
certificate.type = CardanoCertificateType.STAKE_POOL_REGISTRATION;
|
|
283
252
|
const owners = params.pool_owners();
|
|
@@ -360,41 +329,6 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
|
360
329
|
metadata,
|
|
361
330
|
};
|
|
362
331
|
}
|
|
363
|
-
else if (certKind === 15) {
|
|
364
|
-
// VoteDelegation (CertificateKind.VoteDelegation = 15 in WASM lib)
|
|
365
|
-
const voteDelegation = cert.as_vote_delegation();
|
|
366
|
-
const credential = voteDelegation.stake_credential();
|
|
367
|
-
certificate.type = CardanoCertificateType.VOTE_DELEGATION;
|
|
368
|
-
if (credential.kind() === 0) {
|
|
369
|
-
certificate.path = keys.stake.path;
|
|
370
|
-
}
|
|
371
|
-
else {
|
|
372
|
-
const scriptHash = Buffer.from(credential.to_scripthash().to_bytes()).toString('hex');
|
|
373
|
-
certificate.scriptHash = scriptHash;
|
|
374
|
-
}
|
|
375
|
-
// Parse DRep
|
|
376
|
-
const drep = voteDelegation.drep();
|
|
377
|
-
const drepKind = drep.kind();
|
|
378
|
-
// DRepKind: KeyHash = 0, ScriptHash = 1, AlwaysAbstain = 2, AlwaysNoConfidence = 3
|
|
379
|
-
certificate.dRep = {
|
|
380
|
-
type: drepKind,
|
|
381
|
-
};
|
|
382
|
-
if (drepKind === 0) {
|
|
383
|
-
// KEY_HASH
|
|
384
|
-
certificate.dRep.keyHash = (_c = drep.to_key_hash()) === null || _c === void 0 ? void 0 : _c.to_hex();
|
|
385
|
-
}
|
|
386
|
-
else if (drepKind === 1) {
|
|
387
|
-
// SCRIPT_HASH
|
|
388
|
-
certificate.dRep.scriptHash = (_d = drep.to_script_hash()) === null || _d === void 0 ? void 0 : _d.to_hex();
|
|
389
|
-
}
|
|
390
|
-
// ABSTAIN (2) and NO_CONFIDENCE (3) don't need additional fields
|
|
391
|
-
}
|
|
392
|
-
else {
|
|
393
|
-
// Skip unsupported certificate types (kind 4, 5, 6, etc.)
|
|
394
|
-
// Don't push empty certificate objects
|
|
395
|
-
console.warn(`[txToOneKey] Unsupported certificate kind: ${certKind}, cert:`, cert.to_hex());
|
|
396
|
-
continue;
|
|
397
|
-
}
|
|
398
332
|
onekeyCertificates.push(certificate);
|
|
399
333
|
}
|
|
400
334
|
}
|
|
@@ -432,17 +366,36 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
|
432
366
|
mintBundle = [];
|
|
433
367
|
for (let j = 0; j < mint.keys().len(); j++) {
|
|
434
368
|
const policy = mint.keys().get(j);
|
|
435
|
-
const
|
|
369
|
+
const mintsAssets = mint.get(policy);
|
|
436
370
|
const tokens = [];
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
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
|
+
}
|
|
446
399
|
}
|
|
447
400
|
// sort canonical
|
|
448
401
|
sortCanonicallyInPlace(tokens, item => item.assetNameBytes);
|
|
@@ -515,7 +468,9 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
|
515
468
|
for (let i = 0; i < ri.len(); i++) {
|
|
516
469
|
referenceInputs.push({
|
|
517
470
|
prev_hash: ri.get(i).transaction_id().to_hex(),
|
|
518
|
-
|
|
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())),
|
|
519
474
|
});
|
|
520
475
|
}
|
|
521
476
|
signingMode = CardanoTxSigningMode.PLUTUS_TRANSACTION;
|
|
@@ -22,16 +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
|
-
}
|
|
30
|
-
export declare enum CardanoDRepType {
|
|
31
|
-
KEY_HASH = 0,
|
|
32
|
-
SCRIPT_HASH = 1,
|
|
33
|
-
ABSTAIN = 2,
|
|
34
|
-
NO_CONFIDENCE = 3
|
|
25
|
+
STAKE_POOL_REGISTRATION = 3
|
|
35
26
|
}
|
|
36
27
|
export declare enum CardanoPoolRelayType {
|
|
37
28
|
SINGLE_HOST_IP = 0,
|
|
@@ -27,17 +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["STAKE_REGISTRATION_CONWAY"] = 7] = "STAKE_REGISTRATION_CONWAY";
|
|
31
|
-
CardanoCertificateType[CardanoCertificateType["STAKE_DEREGISTRATION_CONWAY"] = 8] = "STAKE_DEREGISTRATION_CONWAY";
|
|
32
|
-
CardanoCertificateType[CardanoCertificateType["VOTE_DELEGATION"] = 9] = "VOTE_DELEGATION";
|
|
33
30
|
})(CardanoCertificateType || (CardanoCertificateType = {}));
|
|
34
|
-
export var CardanoDRepType;
|
|
35
|
-
(function (CardanoDRepType) {
|
|
36
|
-
CardanoDRepType[CardanoDRepType["KEY_HASH"] = 0] = "KEY_HASH";
|
|
37
|
-
CardanoDRepType[CardanoDRepType["SCRIPT_HASH"] = 1] = "SCRIPT_HASH";
|
|
38
|
-
CardanoDRepType[CardanoDRepType["ABSTAIN"] = 2] = "ABSTAIN";
|
|
39
|
-
CardanoDRepType[CardanoDRepType["NO_CONFIDENCE"] = 3] = "NO_CONFIDENCE";
|
|
40
|
-
})(CardanoDRepType || (CardanoDRepType = {}));
|
|
41
31
|
export var CardanoPoolRelayType;
|
|
42
32
|
(function (CardanoPoolRelayType) {
|
|
43
33
|
CardanoPoolRelayType[CardanoPoolRelayType["SINGLE_HOST_IP"] = 0] = "SINGLE_HOST_IP";
|
|
@@ -181,7 +171,7 @@ const outputsToOneKey = (outputs, changeAddress) => {
|
|
|
181
171
|
* @param {Transaction} tx
|
|
182
172
|
*/
|
|
183
173
|
export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
184
|
-
var _a
|
|
174
|
+
var _a;
|
|
185
175
|
const keys = generateKeys(initKeys, xpub);
|
|
186
176
|
const tx = CardanoWasm.Transaction.from_bytes(Buffer.from(rawTx, 'hex'));
|
|
187
177
|
let signingMode = CardanoTxSigningMode.ORDINARY_TRANSACTION;
|
|
@@ -194,20 +184,9 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
|
|
|
194
184
|
for (let i = 0; i < certificates.len(); i++) {
|
|
195
185
|
const cert = certificates.get(i);
|
|
196
186
|
const certificate = {};
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const credential = stakeRegistration === null || stakeRegistration === void 0 ? void 0 : stakeRegistration.stake_credential();
|
|
201
|
-
const deposit = (_a = stakeRegistration === null || stakeRegistration === void 0 ? void 0 : stakeRegistration.coin) === null || _a === void 0 ? void 0 : _a.call(stakeRegistration);
|
|
202
|
-
if (deposit) {
|
|
203
|
-
// Conway era - reg_cert with deposit
|
|
204
|
-
certificate.type = CardanoCertificateType.STAKE_REGISTRATION_CONWAY;
|
|
205
|
-
certificate.deposit = deposit.to_str();
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
// Pre-Conway - stake_registration without deposit
|
|
209
|
-
certificate.type = CardanoCertificateType.STAKE_REGISTRATION;
|
|
210
|
-
}
|
|
187
|
+
if (cert.kind() === 0) {
|
|
188
|
+
const credential = (_a = cert.as_stake_registration()) === null || _a === void 0 ? void 0 : _a.stake_credential();
|
|
189
|
+
certificate.type = CardanoCertificateType.STAKE_REGISTRATION;
|
|
211
190
|
if ((credential === null || credential === void 0 ? void 0 : credential.kind()) === 0) {
|
|
212
191
|
certificate.path = keys.stake.path;
|
|
213
192
|
}
|
|
@@ -216,19 +195,9 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
|
|
|
216
195
|
certificate.scriptHash = scriptHash;
|
|
217
196
|
}
|
|
218
197
|
}
|
|
219
|
-
else if (
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
const deposit = (_b = stakeDeregistration.coin) === null || _b === void 0 ? void 0 : _b.call(stakeDeregistration);
|
|
223
|
-
if (deposit) {
|
|
224
|
-
// Conway era - unreg_cert with deposit
|
|
225
|
-
certificate.type = CardanoCertificateType.STAKE_DEREGISTRATION_CONWAY;
|
|
226
|
-
certificate.deposit = deposit.to_str();
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
// Pre-Conway - stake_deregistration without deposit
|
|
230
|
-
certificate.type = CardanoCertificateType.STAKE_DEREGISTRATION;
|
|
231
|
-
}
|
|
198
|
+
else if (cert.kind() === 1) {
|
|
199
|
+
const credential = cert.as_stake_deregistration().stake_credential();
|
|
200
|
+
certificate.type = CardanoCertificateType.STAKE_DEREGISTRATION;
|
|
232
201
|
if (credential.kind() === 0) {
|
|
233
202
|
certificate.path = keys.stake.path;
|
|
234
203
|
}
|
|
@@ -237,7 +206,7 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
|
|
|
237
206
|
certificate.scriptHash = scriptHash;
|
|
238
207
|
}
|
|
239
208
|
}
|
|
240
|
-
else if (
|
|
209
|
+
else if (cert.kind() === 2) {
|
|
241
210
|
const delegation = cert.as_stake_delegation();
|
|
242
211
|
const credential = delegation.stake_credential();
|
|
243
212
|
const poolKeyHashHex = Buffer.from(delegation.pool_keyhash().to_bytes()).toString('hex');
|
|
@@ -251,7 +220,7 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
|
|
|
251
220
|
}
|
|
252
221
|
certificate.pool = poolKeyHashHex;
|
|
253
222
|
}
|
|
254
|
-
else if (
|
|
223
|
+
else if (cert.kind() === 3) {
|
|
255
224
|
const params = cert.as_pool_registration().pool_params();
|
|
256
225
|
certificate.type = CardanoCertificateType.STAKE_POOL_REGISTRATION;
|
|
257
226
|
const owners = params.pool_owners();
|
|
@@ -334,41 +303,6 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
|
|
|
334
303
|
metadata,
|
|
335
304
|
};
|
|
336
305
|
}
|
|
337
|
-
else if (certKind === 15) {
|
|
338
|
-
// VoteDelegation (CertificateKind.VoteDelegation = 15 in WASM lib)
|
|
339
|
-
const voteDelegation = cert.as_vote_delegation();
|
|
340
|
-
const credential = voteDelegation.stake_credential();
|
|
341
|
-
certificate.type = CardanoCertificateType.VOTE_DELEGATION;
|
|
342
|
-
if (credential.kind() === 0) {
|
|
343
|
-
certificate.path = keys.stake.path;
|
|
344
|
-
}
|
|
345
|
-
else {
|
|
346
|
-
const scriptHash = Buffer.from(credential.to_scripthash().to_bytes()).toString('hex');
|
|
347
|
-
certificate.scriptHash = scriptHash;
|
|
348
|
-
}
|
|
349
|
-
// Parse DRep
|
|
350
|
-
const drep = voteDelegation.drep();
|
|
351
|
-
const drepKind = drep.kind();
|
|
352
|
-
// DRepKind: KeyHash = 0, ScriptHash = 1, AlwaysAbstain = 2, AlwaysNoConfidence = 3
|
|
353
|
-
certificate.dRep = {
|
|
354
|
-
type: drepKind,
|
|
355
|
-
};
|
|
356
|
-
if (drepKind === 0) {
|
|
357
|
-
// KEY_HASH
|
|
358
|
-
certificate.dRep.keyHash = (_c = drep.to_key_hash()) === null || _c === void 0 ? void 0 : _c.to_hex();
|
|
359
|
-
}
|
|
360
|
-
else if (drepKind === 1) {
|
|
361
|
-
// SCRIPT_HASH
|
|
362
|
-
certificate.dRep.scriptHash = (_d = drep.to_script_hash()) === null || _d === void 0 ? void 0 : _d.to_hex();
|
|
363
|
-
}
|
|
364
|
-
// ABSTAIN (2) and NO_CONFIDENCE (3) don't need additional fields
|
|
365
|
-
}
|
|
366
|
-
else {
|
|
367
|
-
// Skip unsupported certificate types (kind 4, 5, 6, etc.)
|
|
368
|
-
// Don't push empty certificate objects
|
|
369
|
-
console.warn(`[txToOneKey] Unsupported certificate kind: ${certKind}, cert:`, cert.to_hex());
|
|
370
|
-
continue;
|
|
371
|
-
}
|
|
372
306
|
onekeyCertificates.push(certificate);
|
|
373
307
|
}
|
|
374
308
|
}
|
|
@@ -406,17 +340,36 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
|
|
|
406
340
|
mintBundle = [];
|
|
407
341
|
for (let j = 0; j < mint.keys().len(); j++) {
|
|
408
342
|
const policy = mint.keys().get(j);
|
|
409
|
-
const
|
|
343
|
+
const mintsAssets = mint.get(policy);
|
|
410
344
|
const tokens = [];
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
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
|
+
}
|
|
420
373
|
}
|
|
421
374
|
// sort canonical
|
|
422
375
|
sortCanonicallyInPlace(tokens, item => item.assetNameBytes);
|
|
@@ -489,7 +442,9 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
|
|
|
489
442
|
for (let i = 0; i < ri.len(); i++) {
|
|
490
443
|
referenceInputs.push({
|
|
491
444
|
prev_hash: ri.get(i).transaction_id().to_hex(),
|
|
492
|
-
|
|
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())),
|
|
493
448
|
});
|
|
494
449
|
}
|
|
495
450
|
signingMode = CardanoTxSigningMode.PLUTUS_TRANSACTION;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/cardano-coin-selection-asmjs",
|
|
3
|
-
"version": "1.1.10-alpha.
|
|
3
|
+
"version": "1.1.10-alpha.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"coin selection"
|
|
@@ -29,8 +29,7 @@
|
|
|
29
29
|
"type-check": "yarn tsc -p tsconfig.types.json",
|
|
30
30
|
"test": "yarn run-s 'test:*'",
|
|
31
31
|
"test:unit": "jest -c ./jest.config.js",
|
|
32
|
-
"test:badges": "make-coverage-badge --output-path ./docs/badge-coverage.svg"
|
|
33
|
-
"debug:watcher": "node scripts/sync-to-monorepo.js"
|
|
32
|
+
"test:badges": "make-coverage-badge --output-path ./docs/badge-coverage.svg"
|
|
34
33
|
},
|
|
35
34
|
"devDependencies": {
|
|
36
35
|
"@emurgo/cardano-serialization-lib-nodejs": "13.2.0",
|
|
@@ -43,13 +42,10 @@
|
|
|
43
42
|
"@typescript-eslint/eslint-plugin": "^8.8.0",
|
|
44
43
|
"@typescript-eslint/parser": "8.8.0",
|
|
45
44
|
"bignumber.js": "^9.0.1",
|
|
46
|
-
"chokidar": "^5.0.0",
|
|
47
|
-
"dotenv": "^17.2.3",
|
|
48
45
|
"eslint": "^9.11.1",
|
|
49
46
|
"eslint-config-prettier": "^9.1.0",
|
|
50
47
|
"eslint-plugin-import": "^2.30.0",
|
|
51
48
|
"eslint-plugin-prettier": "^5.2.1",
|
|
52
|
-
"fs-extra": "^11.3.2",
|
|
53
49
|
"jest": "^29.7.0",
|
|
54
50
|
"make-coverage-badge": "^1.2.0",
|
|
55
51
|
"npm-run-all": "^4.1.5",
|