@onekeyfe/cardano-coin-selection-asmjs 1.1.10-alpha.9 → 1.1.11

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,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();
@@ -46,5 +46,8 @@ declare const onekeyUtils: {
46
46
  tagCborSets: boolean;
47
47
  }>;
48
48
  hasSetTagWithBody: (txBodyHex: string) => Promise<boolean>;
49
+ parseRawTxInputs: (rawTxHex: string) => Promise<import("./parseRawTx").IParsedRawTxInput[]>;
50
+ parseRawTxBodyStakeInfo: (rawTxHex: string) => Promise<import("./parseRawTx").IParsedRawTxBodyStakeInfo>;
51
+ extractStakeKeyHashFromBaseAddress: (addr: string) => Promise<string | null>;
49
52
  };
50
53
  export { onekeyUtils, dAppUtils };
@@ -7,11 +7,15 @@ const dapp_1 = require("./dapp");
7
7
  Object.defineProperty(exports, "dAppUtils", { enumerable: true, get: function () { return dapp_1.dAppUtils; } });
8
8
  const txToOneKey_1 = require("./txToOneKey");
9
9
  const hasSetTag_1 = require("./hasSetTag");
10
+ const parseRawTx_1 = require("./parseRawTx");
10
11
  const onekeyUtils = {
11
12
  composeTxPlan: transaction_1.composeTxPlan,
12
13
  signTransaction: signTx_1.signTransaction,
13
14
  signTx: signTx_1.signTx,
14
15
  txToOneKey: txToOneKey_1.txToOneKey,
15
16
  hasSetTagWithBody: hasSetTag_1.hasSetTagWithBody,
17
+ parseRawTxInputs: parseRawTx_1.parseRawTxInputs,
18
+ parseRawTxBodyStakeInfo: parseRawTx_1.parseRawTxBodyStakeInfo,
19
+ extractStakeKeyHashFromBaseAddress: parseRawTx_1.extractStakeKeyHashFromBaseAddress,
16
20
  };
17
21
  exports.onekeyUtils = onekeyUtils;
@@ -0,0 +1,12 @@
1
+ export type IParsedRawTxInput = {
2
+ prev_hash: string;
3
+ prev_index: number;
4
+ };
5
+ export type IParsedRawTxBodyStakeInfo = {
6
+ hasCertificates: boolean;
7
+ hasWithdrawals: boolean;
8
+ requiredSignerHashes: string[];
9
+ };
10
+ export declare const parseRawTxInputs: (rawTxHex: string) => Promise<IParsedRawTxInput[]>;
11
+ export declare const parseRawTxBodyStakeInfo: (rawTxHex: string) => Promise<IParsedRawTxBodyStakeInfo>;
12
+ export declare const extractStakeKeyHashFromBaseAddress: (addr: string) => Promise<string | null>;
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.extractStakeKeyHashFromBaseAddress = exports.parseRawTxBodyStakeInfo = exports.parseRawTxInputs = void 0;
27
+ const CardanoWasm = __importStar(require("@emurgo/cardano-serialization-lib-asmjs"));
28
+ const parseRawTxInputs = (rawTxHex) => {
29
+ const tx = CardanoWasm.Transaction.from_hex(rawTxHex);
30
+ const inputs = tx.body().inputs();
31
+ const out = [];
32
+ for (let i = 0; i < inputs.len(); i += 1) {
33
+ const input = inputs.get(i);
34
+ out.push({
35
+ prev_hash: input.transaction_id().to_hex(),
36
+ prev_index: input.index(),
37
+ });
38
+ }
39
+ return Promise.resolve(out);
40
+ };
41
+ exports.parseRawTxInputs = parseRawTxInputs;
42
+ const parseRawTxBodyStakeInfo = (rawTxHex) => {
43
+ const tx = CardanoWasm.Transaction.from_hex(rawTxHex);
44
+ const body = tx.body();
45
+ const certs = body.certs();
46
+ const hasCertificates = !!certs && certs.len() > 0;
47
+ const withdrawals = body.withdrawals();
48
+ const hasWithdrawals = !!withdrawals && withdrawals.keys().len() > 0;
49
+ const requiredSigners = body.required_signers();
50
+ const requiredSignerHashes = [];
51
+ if (requiredSigners) {
52
+ for (let i = 0; i < requiredSigners.len(); i += 1) {
53
+ requiredSignerHashes.push(requiredSigners.get(i).to_hex());
54
+ }
55
+ }
56
+ return Promise.resolve({
57
+ hasCertificates,
58
+ hasWithdrawals,
59
+ requiredSignerHashes,
60
+ });
61
+ };
62
+ exports.parseRawTxBodyStakeInfo = parseRawTxBodyStakeInfo;
63
+ // Returns the hex stake key hash for key-credential base addresses (types 0
64
+ // and 1 in Cardano address layout); returns null for script-credential stakes
65
+ // or non-base addresses. Caller should treat null as "cannot safely filter
66
+ // stake witness".
67
+ const extractStakeKeyHashFromBaseAddress = (addr) => {
68
+ try {
69
+ const address = CardanoWasm.Address.from_bech32(addr);
70
+ const baseAddress = CardanoWasm.BaseAddress.from_address(address);
71
+ if (!baseAddress)
72
+ return Promise.resolve(null);
73
+ const stakeCred = baseAddress.stake_cred();
74
+ if (stakeCred.kind() !== CardanoWasm.CredKind.Key) {
75
+ return Promise.resolve(null);
76
+ }
77
+ // spell-checker:disable-next-line
78
+ const stakeKey = stakeCred.to_keyhash();
79
+ if (!stakeKey)
80
+ return Promise.resolve(null);
81
+ return Promise.resolve(stakeKey.to_hex());
82
+ }
83
+ catch (_a) {
84
+ return Promise.resolve(null);
85
+ }
86
+ };
87
+ exports.extractStakeKeyHashFromBaseAddress = extractStakeKeyHashFromBaseAddress;
@@ -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
- 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;
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 (cert.kind() === 1) {
225
- const credential = cert.as_stake_deregistration().stake_credential();
226
- certificate.type = CardanoCertificateType.STAKE_DEREGISTRATION;
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 (cert.kind() === 2) {
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 (cert.kind() === 3) {
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
- // 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;
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();
@@ -46,5 +46,8 @@ declare const onekeyUtils: {
46
46
  tagCborSets: boolean;
47
47
  }>;
48
48
  hasSetTagWithBody: (txBodyHex: string) => Promise<boolean>;
49
+ parseRawTxInputs: (rawTxHex: string) => Promise<import("./parseRawTx").IParsedRawTxInput[]>;
50
+ parseRawTxBodyStakeInfo: (rawTxHex: string) => Promise<import("./parseRawTx").IParsedRawTxBodyStakeInfo>;
51
+ extractStakeKeyHashFromBaseAddress: (addr: string) => Promise<string | null>;
49
52
  };
50
53
  export { onekeyUtils, dAppUtils };
@@ -3,11 +3,15 @@ import { signTransaction, signTx } from './signTx';
3
3
  import { dAppUtils } from './dapp';
4
4
  import { txToOneKey } from './txToOneKey';
5
5
  import { hasSetTagWithBody } from './hasSetTag';
6
+ import { parseRawTxInputs, parseRawTxBodyStakeInfo, extractStakeKeyHashFromBaseAddress, } from './parseRawTx';
6
7
  const onekeyUtils = {
7
8
  composeTxPlan,
8
9
  signTransaction,
9
10
  signTx,
10
11
  txToOneKey,
11
12
  hasSetTagWithBody,
13
+ parseRawTxInputs,
14
+ parseRawTxBodyStakeInfo,
15
+ extractStakeKeyHashFromBaseAddress,
12
16
  };
13
17
  export { onekeyUtils, dAppUtils };
@@ -0,0 +1,12 @@
1
+ export type IParsedRawTxInput = {
2
+ prev_hash: string;
3
+ prev_index: number;
4
+ };
5
+ export type IParsedRawTxBodyStakeInfo = {
6
+ hasCertificates: boolean;
7
+ hasWithdrawals: boolean;
8
+ requiredSignerHashes: string[];
9
+ };
10
+ export declare const parseRawTxInputs: (rawTxHex: string) => Promise<IParsedRawTxInput[]>;
11
+ export declare const parseRawTxBodyStakeInfo: (rawTxHex: string) => Promise<IParsedRawTxBodyStakeInfo>;
12
+ export declare const extractStakeKeyHashFromBaseAddress: (addr: string) => Promise<string | null>;
@@ -0,0 +1,58 @@
1
+ import * as CardanoWasm from '@emurgo/cardano-serialization-lib-asmjs';
2
+ export const parseRawTxInputs = (rawTxHex) => {
3
+ const tx = CardanoWasm.Transaction.from_hex(rawTxHex);
4
+ const inputs = tx.body().inputs();
5
+ const out = [];
6
+ for (let i = 0; i < inputs.len(); i += 1) {
7
+ const input = inputs.get(i);
8
+ out.push({
9
+ prev_hash: input.transaction_id().to_hex(),
10
+ prev_index: input.index(),
11
+ });
12
+ }
13
+ return Promise.resolve(out);
14
+ };
15
+ export const parseRawTxBodyStakeInfo = (rawTxHex) => {
16
+ const tx = CardanoWasm.Transaction.from_hex(rawTxHex);
17
+ const body = tx.body();
18
+ const certs = body.certs();
19
+ const hasCertificates = !!certs && certs.len() > 0;
20
+ const withdrawals = body.withdrawals();
21
+ const hasWithdrawals = !!withdrawals && withdrawals.keys().len() > 0;
22
+ const requiredSigners = body.required_signers();
23
+ const requiredSignerHashes = [];
24
+ if (requiredSigners) {
25
+ for (let i = 0; i < requiredSigners.len(); i += 1) {
26
+ requiredSignerHashes.push(requiredSigners.get(i).to_hex());
27
+ }
28
+ }
29
+ return Promise.resolve({
30
+ hasCertificates,
31
+ hasWithdrawals,
32
+ requiredSignerHashes,
33
+ });
34
+ };
35
+ // Returns the hex stake key hash for key-credential base addresses (types 0
36
+ // and 1 in Cardano address layout); returns null for script-credential stakes
37
+ // or non-base addresses. Caller should treat null as "cannot safely filter
38
+ // stake witness".
39
+ export const extractStakeKeyHashFromBaseAddress = (addr) => {
40
+ try {
41
+ const address = CardanoWasm.Address.from_bech32(addr);
42
+ const baseAddress = CardanoWasm.BaseAddress.from_address(address);
43
+ if (!baseAddress)
44
+ return Promise.resolve(null);
45
+ const stakeCred = baseAddress.stake_cred();
46
+ if (stakeCred.kind() !== CardanoWasm.CredKind.Key) {
47
+ return Promise.resolve(null);
48
+ }
49
+ // spell-checker:disable-next-line
50
+ const stakeKey = stakeCred.to_keyhash();
51
+ if (!stakeKey)
52
+ return Promise.resolve(null);
53
+ return Promise.resolve(stakeKey.to_hex());
54
+ }
55
+ catch (_a) {
56
+ return Promise.resolve(null);
57
+ }
58
+ };
@@ -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
- 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;
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 (cert.kind() === 1) {
199
- const credential = cert.as_stake_deregistration().stake_credential();
200
- certificate.type = CardanoCertificateType.STAKE_DEREGISTRATION;
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 (cert.kind() === 2) {
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 (cert.kind() === 3) {
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
- // 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;
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-alpha.9",
3
+ "version": "1.1.11",
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",