@onekeyfe/cardano-coin-selection-asmjs 1.1.10-alpha.9 → 1.1.10
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 +0 -1
- package/lib/cjs/utils/onekey/txToOneKey.d.ts +10 -1
- package/lib/cjs/utils/onekey/txToOneKey.js +81 -30
- package/lib/esm/utils/onekey/dapp.js +0 -1
- package/lib/esm/utils/onekey/txToOneKey.d.ts +10 -1
- package/lib/esm/utils/onekey/txToOneKey.js +80 -29
- package/package.json +6 -2
|
@@ -91,7 +91,6 @@ 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 : 333====>>>');
|
|
95
94
|
try {
|
|
96
95
|
const tx = CardanoWasm.Transaction.from_bytes(Buffer.from(txHex, 'hex'));
|
|
97
96
|
body = tx.body();
|
|
@@ -22,7 +22,16 @@ export declare enum CardanoCertificateType {
|
|
|
22
22
|
STAKE_REGISTRATION = 0,
|
|
23
23
|
STAKE_DEREGISTRATION = 1,
|
|
24
24
|
STAKE_DELEGATION = 2,
|
|
25
|
-
STAKE_POOL_REGISTRATION = 3
|
|
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
|
|
26
35
|
}
|
|
27
36
|
export declare enum CardanoPoolRelayType {
|
|
28
37
|
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.CardanoCertificateType = exports.CardanoTxSigningMode = exports.CardanoAddressType = void 0;
|
|
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
29
|
var CardanoAddressType;
|
|
@@ -53,7 +53,17 @@ 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";
|
|
56
59
|
})(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 = {}));
|
|
57
67
|
var CardanoPoolRelayType;
|
|
58
68
|
(function (CardanoPoolRelayType) {
|
|
59
69
|
CardanoPoolRelayType[CardanoPoolRelayType["SINGLE_HOST_IP"] = 0] = "SINGLE_HOST_IP";
|
|
@@ -197,7 +207,7 @@ const outputsToOneKey = (outputs, changeAddress) => {
|
|
|
197
207
|
* @param {Transaction} tx
|
|
198
208
|
*/
|
|
199
209
|
const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
200
|
-
var _a;
|
|
210
|
+
var _a, _b, _c, _d;
|
|
201
211
|
const keys = generateKeys(initKeys, xpub);
|
|
202
212
|
const tx = CardanoWasm.Transaction.from_bytes(Buffer.from(rawTx, 'hex'));
|
|
203
213
|
let signingMode = CardanoTxSigningMode.ORDINARY_TRANSACTION;
|
|
@@ -210,9 +220,20 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
|
210
220
|
for (let i = 0; i < certificates.len(); i++) {
|
|
211
221
|
const cert = certificates.get(i);
|
|
212
222
|
const certificate = {};
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
223
|
+
const certKind = cert.kind();
|
|
224
|
+
if (certKind === 0) {
|
|
225
|
+
const stakeRegistration = cert.as_stake_registration();
|
|
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
|
+
}
|
|
216
237
|
if ((credential === null || credential === void 0 ? void 0 : credential.kind()) === 0) {
|
|
217
238
|
certificate.path = keys.stake.path;
|
|
218
239
|
}
|
|
@@ -221,9 +242,19 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
|
221
242
|
certificate.scriptHash = scriptHash;
|
|
222
243
|
}
|
|
223
244
|
}
|
|
224
|
-
else if (
|
|
225
|
-
const
|
|
226
|
-
|
|
245
|
+
else if (certKind === 1) {
|
|
246
|
+
const stakeDeregistration = cert.as_stake_deregistration();
|
|
247
|
+
const credential = stakeDeregistration.stake_credential();
|
|
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
|
+
}
|
|
227
258
|
if (credential.kind() === 0) {
|
|
228
259
|
certificate.path = keys.stake.path;
|
|
229
260
|
}
|
|
@@ -232,7 +263,7 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
|
232
263
|
certificate.scriptHash = scriptHash;
|
|
233
264
|
}
|
|
234
265
|
}
|
|
235
|
-
else if (
|
|
266
|
+
else if (certKind === 2) {
|
|
236
267
|
const delegation = cert.as_stake_delegation();
|
|
237
268
|
const credential = delegation.stake_credential();
|
|
238
269
|
const poolKeyHashHex = Buffer.from(delegation.pool_keyhash().to_bytes()).toString('hex');
|
|
@@ -246,7 +277,7 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
|
246
277
|
}
|
|
247
278
|
certificate.pool = poolKeyHashHex;
|
|
248
279
|
}
|
|
249
|
-
else if (
|
|
280
|
+
else if (certKind === 3) {
|
|
250
281
|
const params = cert.as_pool_registration().pool_params();
|
|
251
282
|
certificate.type = CardanoCertificateType.STAKE_POOL_REGISTRATION;
|
|
252
283
|
const owners = params.pool_owners();
|
|
@@ -329,6 +360,41 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
|
329
360
|
metadata,
|
|
330
361
|
};
|
|
331
362
|
}
|
|
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
|
+
}
|
|
332
398
|
onekeyCertificates.push(certificate);
|
|
333
399
|
}
|
|
334
400
|
}
|
|
@@ -366,26 +432,13 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
|
366
432
|
mintBundle = [];
|
|
367
433
|
for (let j = 0; j < mint.keys().len(); j++) {
|
|
368
434
|
const policy = mint.keys().get(j);
|
|
435
|
+
// CSL 13: Mint.get(policy) returns MintsAssets — a list, one entry per
|
|
436
|
+
// occurrence of that policy in the original CBOR — to preserve byte-
|
|
437
|
+
// level round-trip (tx hash stability). Iterate the list, then each map.
|
|
369
438
|
const mintsAssets = mint.get(policy);
|
|
370
439
|
const tokens = [];
|
|
371
|
-
|
|
372
|
-
|
|
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;
|
|
440
|
+
for (let mai = 0; mai < mintsAssets.len(); mai++) {
|
|
441
|
+
const assets = mintsAssets.get(mai);
|
|
389
442
|
for (let k = 0; k < assets.keys().len(); k++) {
|
|
390
443
|
const assetName = assets.keys().get(k);
|
|
391
444
|
const amount = assets.get(assetName);
|
|
@@ -468,8 +521,6 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
|
468
521
|
for (let i = 0; i < ri.len(); i++) {
|
|
469
522
|
referenceInputs.push({
|
|
470
523
|
prev_hash: ri.get(i).transaction_id().to_hex(),
|
|
471
|
-
// CSL 13: TransactionInput.index() returns a number directly, not a
|
|
472
|
-
// BigNum — the legacy `.to_str()` call crashes at runtime.
|
|
473
524
|
prev_index: parseInt(String(ri.get(i).index())),
|
|
474
525
|
});
|
|
475
526
|
}
|
|
@@ -61,7 +61,6 @@ 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 : 333====>>>');
|
|
65
64
|
try {
|
|
66
65
|
const tx = CardanoWasm.Transaction.from_bytes(Buffer.from(txHex, 'hex'));
|
|
67
66
|
body = tx.body();
|
|
@@ -22,7 +22,16 @@ export declare enum CardanoCertificateType {
|
|
|
22
22
|
STAKE_REGISTRATION = 0,
|
|
23
23
|
STAKE_DEREGISTRATION = 1,
|
|
24
24
|
STAKE_DELEGATION = 2,
|
|
25
|
-
STAKE_POOL_REGISTRATION = 3
|
|
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
|
|
26
35
|
}
|
|
27
36
|
export declare enum CardanoPoolRelayType {
|
|
28
37
|
SINGLE_HOST_IP = 0,
|
|
@@ -27,7 +27,17 @@ 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";
|
|
30
33
|
})(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 = {}));
|
|
31
41
|
export var CardanoPoolRelayType;
|
|
32
42
|
(function (CardanoPoolRelayType) {
|
|
33
43
|
CardanoPoolRelayType[CardanoPoolRelayType["SINGLE_HOST_IP"] = 0] = "SINGLE_HOST_IP";
|
|
@@ -171,7 +181,7 @@ const outputsToOneKey = (outputs, changeAddress) => {
|
|
|
171
181
|
* @param {Transaction} tx
|
|
172
182
|
*/
|
|
173
183
|
export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
174
|
-
var _a;
|
|
184
|
+
var _a, _b, _c, _d;
|
|
175
185
|
const keys = generateKeys(initKeys, xpub);
|
|
176
186
|
const tx = CardanoWasm.Transaction.from_bytes(Buffer.from(rawTx, 'hex'));
|
|
177
187
|
let signingMode = CardanoTxSigningMode.ORDINARY_TRANSACTION;
|
|
@@ -184,9 +194,20 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
|
|
|
184
194
|
for (let i = 0; i < certificates.len(); i++) {
|
|
185
195
|
const cert = certificates.get(i);
|
|
186
196
|
const certificate = {};
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
197
|
+
const certKind = cert.kind();
|
|
198
|
+
if (certKind === 0) {
|
|
199
|
+
const stakeRegistration = cert.as_stake_registration();
|
|
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
|
+
}
|
|
190
211
|
if ((credential === null || credential === void 0 ? void 0 : credential.kind()) === 0) {
|
|
191
212
|
certificate.path = keys.stake.path;
|
|
192
213
|
}
|
|
@@ -195,9 +216,19 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
|
|
|
195
216
|
certificate.scriptHash = scriptHash;
|
|
196
217
|
}
|
|
197
218
|
}
|
|
198
|
-
else if (
|
|
199
|
-
const
|
|
200
|
-
|
|
219
|
+
else if (certKind === 1) {
|
|
220
|
+
const stakeDeregistration = cert.as_stake_deregistration();
|
|
221
|
+
const credential = stakeDeregistration.stake_credential();
|
|
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
|
+
}
|
|
201
232
|
if (credential.kind() === 0) {
|
|
202
233
|
certificate.path = keys.stake.path;
|
|
203
234
|
}
|
|
@@ -206,7 +237,7 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
|
|
|
206
237
|
certificate.scriptHash = scriptHash;
|
|
207
238
|
}
|
|
208
239
|
}
|
|
209
|
-
else if (
|
|
240
|
+
else if (certKind === 2) {
|
|
210
241
|
const delegation = cert.as_stake_delegation();
|
|
211
242
|
const credential = delegation.stake_credential();
|
|
212
243
|
const poolKeyHashHex = Buffer.from(delegation.pool_keyhash().to_bytes()).toString('hex');
|
|
@@ -220,7 +251,7 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
|
|
|
220
251
|
}
|
|
221
252
|
certificate.pool = poolKeyHashHex;
|
|
222
253
|
}
|
|
223
|
-
else if (
|
|
254
|
+
else if (certKind === 3) {
|
|
224
255
|
const params = cert.as_pool_registration().pool_params();
|
|
225
256
|
certificate.type = CardanoCertificateType.STAKE_POOL_REGISTRATION;
|
|
226
257
|
const owners = params.pool_owners();
|
|
@@ -303,6 +334,41 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
|
|
|
303
334
|
metadata,
|
|
304
335
|
};
|
|
305
336
|
}
|
|
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
|
+
}
|
|
306
372
|
onekeyCertificates.push(certificate);
|
|
307
373
|
}
|
|
308
374
|
}
|
|
@@ -340,26 +406,13 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
|
|
|
340
406
|
mintBundle = [];
|
|
341
407
|
for (let j = 0; j < mint.keys().len(); j++) {
|
|
342
408
|
const policy = mint.keys().get(j);
|
|
409
|
+
// CSL 13: Mint.get(policy) returns MintsAssets — a list, one entry per
|
|
410
|
+
// occurrence of that policy in the original CBOR — to preserve byte-
|
|
411
|
+
// level round-trip (tx hash stability). Iterate the list, then each map.
|
|
343
412
|
const mintsAssets = mint.get(policy);
|
|
344
413
|
const tokens = [];
|
|
345
|
-
|
|
346
|
-
|
|
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;
|
|
414
|
+
for (let mai = 0; mai < mintsAssets.len(); mai++) {
|
|
415
|
+
const assets = mintsAssets.get(mai);
|
|
363
416
|
for (let k = 0; k < assets.keys().len(); k++) {
|
|
364
417
|
const assetName = assets.keys().get(k);
|
|
365
418
|
const amount = assets.get(assetName);
|
|
@@ -442,8 +495,6 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
|
|
|
442
495
|
for (let i = 0; i < ri.len(); i++) {
|
|
443
496
|
referenceInputs.push({
|
|
444
497
|
prev_hash: ri.get(i).transaction_id().to_hex(),
|
|
445
|
-
// CSL 13: TransactionInput.index() returns a number directly, not a
|
|
446
|
-
// BigNum — the legacy `.to_str()` call crashes at runtime.
|
|
447
498
|
prev_index: parseInt(String(ri.get(i).index())),
|
|
448
499
|
});
|
|
449
500
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/cardano-coin-selection-asmjs",
|
|
3
|
-
"version": "1.1.10
|
|
3
|
+
"version": "1.1.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"coin selection"
|
|
@@ -29,7 +29,8 @@
|
|
|
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"
|
|
32
|
+
"test:badges": "make-coverage-badge --output-path ./docs/badge-coverage.svg",
|
|
33
|
+
"debug:watcher": "node scripts/sync-to-monorepo.js"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"@emurgo/cardano-serialization-lib-nodejs": "13.2.0",
|
|
@@ -42,10 +43,13 @@
|
|
|
42
43
|
"@typescript-eslint/eslint-plugin": "^8.8.0",
|
|
43
44
|
"@typescript-eslint/parser": "8.8.0",
|
|
44
45
|
"bignumber.js": "^9.0.1",
|
|
46
|
+
"chokidar": "^5.0.0",
|
|
47
|
+
"dotenv": "^17.2.3",
|
|
45
48
|
"eslint": "^9.11.1",
|
|
46
49
|
"eslint-config-prettier": "^9.1.0",
|
|
47
50
|
"eslint-plugin-import": "^2.30.0",
|
|
48
51
|
"eslint-plugin-prettier": "^5.2.1",
|
|
52
|
+
"fs-extra": "^11.3.2",
|
|
49
53
|
"jest": "^29.7.0",
|
|
50
54
|
"make-coverage-badge": "^1.2.0",
|
|
51
55
|
"npm-run-all": "^4.1.5",
|