@onekeyfe/cardano-coin-selection-asmjs 1.1.9 → 1.1.10-alpha.1

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,7 +22,14 @@ 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
+ STAKE_AND_VOTE_DELEGATION = 10,
30
+ STAKE_REGISTRATION_AND_DELEGATION = 11,
31
+ VOTE_REGISTRATION_AND_DELEGATION = 12,
32
+ STAKE_VOTE_REGISTRATION_AND_DELEGATION = 13
26
33
  }
27
34
  export declare enum CardanoPoolRelayType {
28
35
  SINGLE_HOST_IP = 0,
@@ -53,6 +53,14 @@ 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
+ // Conway era
57
+ CardanoCertificateType[CardanoCertificateType["STAKE_REGISTRATION_CONWAY"] = 7] = "STAKE_REGISTRATION_CONWAY";
58
+ CardanoCertificateType[CardanoCertificateType["STAKE_DEREGISTRATION_CONWAY"] = 8] = "STAKE_DEREGISTRATION_CONWAY";
59
+ CardanoCertificateType[CardanoCertificateType["VOTE_DELEGATION"] = 9] = "VOTE_DELEGATION";
60
+ CardanoCertificateType[CardanoCertificateType["STAKE_AND_VOTE_DELEGATION"] = 10] = "STAKE_AND_VOTE_DELEGATION";
61
+ CardanoCertificateType[CardanoCertificateType["STAKE_REGISTRATION_AND_DELEGATION"] = 11] = "STAKE_REGISTRATION_AND_DELEGATION";
62
+ CardanoCertificateType[CardanoCertificateType["VOTE_REGISTRATION_AND_DELEGATION"] = 12] = "VOTE_REGISTRATION_AND_DELEGATION";
63
+ CardanoCertificateType[CardanoCertificateType["STAKE_VOTE_REGISTRATION_AND_DELEGATION"] = 13] = "STAKE_VOTE_REGISTRATION_AND_DELEGATION";
56
64
  })(CardanoCertificateType || (exports.CardanoCertificateType = CardanoCertificateType = {}));
57
65
  var CardanoPoolRelayType;
58
66
  (function (CardanoPoolRelayType) {
@@ -197,7 +205,7 @@ const outputsToOneKey = (outputs, changeAddress) => {
197
205
  * @param {Transaction} tx
198
206
  */
199
207
  const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
200
- var _a;
208
+ var _a, _b, _c, _d;
201
209
  const keys = generateKeys(initKeys, xpub);
202
210
  const tx = CardanoWasm.Transaction.from_bytes(Buffer.from(rawTx, 'hex'));
203
211
  let signingMode = CardanoTxSigningMode.ORDINARY_TRANSACTION;
@@ -210,7 +218,8 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
210
218
  for (let i = 0; i < certificates.len(); i++) {
211
219
  const cert = certificates.get(i);
212
220
  const certificate = {};
213
- if (cert.kind() === 0) {
221
+ const certKind = cert.kind();
222
+ if (certKind === 0) {
214
223
  const credential = (_a = cert.as_stake_registration()) === null || _a === void 0 ? void 0 : _a.stake_credential();
215
224
  certificate.type = CardanoCertificateType.STAKE_REGISTRATION;
216
225
  if ((credential === null || credential === void 0 ? void 0 : credential.kind()) === 0) {
@@ -221,7 +230,7 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
221
230
  certificate.scriptHash = scriptHash;
222
231
  }
223
232
  }
224
- else if (cert.kind() === 1) {
233
+ else if (certKind === 1) {
225
234
  const credential = cert.as_stake_deregistration().stake_credential();
226
235
  certificate.type = CardanoCertificateType.STAKE_DEREGISTRATION;
227
236
  if (credential.kind() === 0) {
@@ -232,7 +241,7 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
232
241
  certificate.scriptHash = scriptHash;
233
242
  }
234
243
  }
235
- else if (cert.kind() === 2) {
244
+ else if (certKind === 2) {
236
245
  const delegation = cert.as_stake_delegation();
237
246
  const credential = delegation.stake_credential();
238
247
  const poolKeyHashHex = Buffer.from(delegation.pool_keyhash().to_bytes()).toString('hex');
@@ -246,7 +255,7 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
246
255
  }
247
256
  certificate.pool = poolKeyHashHex;
248
257
  }
249
- else if (cert.kind() === 3) {
258
+ else if (certKind === 3) {
250
259
  const params = cert.as_pool_registration().pool_params();
251
260
  certificate.type = CardanoCertificateType.STAKE_POOL_REGISTRATION;
252
261
  const owners = params.pool_owners();
@@ -329,6 +338,54 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
329
338
  metadata,
330
339
  };
331
340
  }
341
+ else if (certKind === 9 || certKind === 15) {
342
+ // Conway era: Vote Delegation (kind 9 in CDDL, may appear as 15 in some lib versions)
343
+ // For hardware wallet signing, we need the stake key path
344
+ const voteDelegation = (_b = cert.as_vote_delegation) === null || _b === void 0 ? void 0 : _b.call(cert);
345
+ if (voteDelegation) {
346
+ const credential = voteDelegation.stake_credential();
347
+ certificate.type = CardanoCertificateType.VOTE_DELEGATION;
348
+ if (credential.kind() === 0) {
349
+ certificate.path = keys.stake.path;
350
+ }
351
+ else {
352
+ const scriptHash = Buffer.from(credential.to_scripthash().to_bytes()).toString('hex');
353
+ certificate.scriptHash = scriptHash;
354
+ }
355
+ // drep can be key hash, script hash, or abstain/no_confidence
356
+ const drep = voteDelegation.drep();
357
+ if ((_c = drep.to_key_hash) === null || _c === void 0 ? void 0 : _c.call(drep)) {
358
+ certificate.dRep = {
359
+ type: 0, // key hash
360
+ keyHash: Buffer.from(drep.to_key_hash().to_bytes()).toString('hex'),
361
+ };
362
+ }
363
+ else if ((_d = drep.to_script_hash) === null || _d === void 0 ? void 0 : _d.call(drep)) {
364
+ certificate.dRep = {
365
+ type: 1, // script hash
366
+ scriptHash: Buffer.from(drep.to_script_hash().to_bytes()).toString('hex'),
367
+ };
368
+ }
369
+ else {
370
+ // abstain or no_confidence
371
+ certificate.dRep = {
372
+ type: drep.kind(), // 2 = abstain, 3 = no_confidence
373
+ };
374
+ }
375
+ }
376
+ else {
377
+ // Fallback: just include stake path for signing
378
+ console.log(`[txToOneKey] Vote delegation cert kind ${certKind}, using stake path for signing`);
379
+ certificate.type = CardanoCertificateType.VOTE_DELEGATION;
380
+ certificate.path = keys.stake.path;
381
+ }
382
+ }
383
+ else {
384
+ // Skip unsupported certificate types
385
+ // Don't push empty certificate objects
386
+ console.log(`[txToOneKey] Unsupported certificate kind: ${certKind}, cert:`, cert.to_hex());
387
+ continue;
388
+ }
332
389
  onekeyCertificates.push(certificate);
333
390
  }
334
391
  }
@@ -22,7 +22,14 @@ 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
+ STAKE_AND_VOTE_DELEGATION = 10,
30
+ STAKE_REGISTRATION_AND_DELEGATION = 11,
31
+ VOTE_REGISTRATION_AND_DELEGATION = 12,
32
+ STAKE_VOTE_REGISTRATION_AND_DELEGATION = 13
26
33
  }
27
34
  export declare enum CardanoPoolRelayType {
28
35
  SINGLE_HOST_IP = 0,
@@ -27,6 +27,14 @@ 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
+ // Conway era
31
+ CardanoCertificateType[CardanoCertificateType["STAKE_REGISTRATION_CONWAY"] = 7] = "STAKE_REGISTRATION_CONWAY";
32
+ CardanoCertificateType[CardanoCertificateType["STAKE_DEREGISTRATION_CONWAY"] = 8] = "STAKE_DEREGISTRATION_CONWAY";
33
+ CardanoCertificateType[CardanoCertificateType["VOTE_DELEGATION"] = 9] = "VOTE_DELEGATION";
34
+ CardanoCertificateType[CardanoCertificateType["STAKE_AND_VOTE_DELEGATION"] = 10] = "STAKE_AND_VOTE_DELEGATION";
35
+ CardanoCertificateType[CardanoCertificateType["STAKE_REGISTRATION_AND_DELEGATION"] = 11] = "STAKE_REGISTRATION_AND_DELEGATION";
36
+ CardanoCertificateType[CardanoCertificateType["VOTE_REGISTRATION_AND_DELEGATION"] = 12] = "VOTE_REGISTRATION_AND_DELEGATION";
37
+ CardanoCertificateType[CardanoCertificateType["STAKE_VOTE_REGISTRATION_AND_DELEGATION"] = 13] = "STAKE_VOTE_REGISTRATION_AND_DELEGATION";
30
38
  })(CardanoCertificateType || (CardanoCertificateType = {}));
31
39
  export var CardanoPoolRelayType;
32
40
  (function (CardanoPoolRelayType) {
@@ -171,7 +179,7 @@ const outputsToOneKey = (outputs, changeAddress) => {
171
179
  * @param {Transaction} tx
172
180
  */
173
181
  export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
174
- var _a;
182
+ var _a, _b, _c, _d;
175
183
  const keys = generateKeys(initKeys, xpub);
176
184
  const tx = CardanoWasm.Transaction.from_bytes(Buffer.from(rawTx, 'hex'));
177
185
  let signingMode = CardanoTxSigningMode.ORDINARY_TRANSACTION;
@@ -184,7 +192,8 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
184
192
  for (let i = 0; i < certificates.len(); i++) {
185
193
  const cert = certificates.get(i);
186
194
  const certificate = {};
187
- if (cert.kind() === 0) {
195
+ const certKind = cert.kind();
196
+ if (certKind === 0) {
188
197
  const credential = (_a = cert.as_stake_registration()) === null || _a === void 0 ? void 0 : _a.stake_credential();
189
198
  certificate.type = CardanoCertificateType.STAKE_REGISTRATION;
190
199
  if ((credential === null || credential === void 0 ? void 0 : credential.kind()) === 0) {
@@ -195,7 +204,7 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
195
204
  certificate.scriptHash = scriptHash;
196
205
  }
197
206
  }
198
- else if (cert.kind() === 1) {
207
+ else if (certKind === 1) {
199
208
  const credential = cert.as_stake_deregistration().stake_credential();
200
209
  certificate.type = CardanoCertificateType.STAKE_DEREGISTRATION;
201
210
  if (credential.kind() === 0) {
@@ -206,7 +215,7 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
206
215
  certificate.scriptHash = scriptHash;
207
216
  }
208
217
  }
209
- else if (cert.kind() === 2) {
218
+ else if (certKind === 2) {
210
219
  const delegation = cert.as_stake_delegation();
211
220
  const credential = delegation.stake_credential();
212
221
  const poolKeyHashHex = Buffer.from(delegation.pool_keyhash().to_bytes()).toString('hex');
@@ -220,7 +229,7 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
220
229
  }
221
230
  certificate.pool = poolKeyHashHex;
222
231
  }
223
- else if (cert.kind() === 3) {
232
+ else if (certKind === 3) {
224
233
  const params = cert.as_pool_registration().pool_params();
225
234
  certificate.type = CardanoCertificateType.STAKE_POOL_REGISTRATION;
226
235
  const owners = params.pool_owners();
@@ -303,6 +312,54 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
303
312
  metadata,
304
313
  };
305
314
  }
315
+ else if (certKind === 9 || certKind === 15) {
316
+ // Conway era: Vote Delegation (kind 9 in CDDL, may appear as 15 in some lib versions)
317
+ // For hardware wallet signing, we need the stake key path
318
+ const voteDelegation = (_b = cert.as_vote_delegation) === null || _b === void 0 ? void 0 : _b.call(cert);
319
+ if (voteDelegation) {
320
+ const credential = voteDelegation.stake_credential();
321
+ certificate.type = CardanoCertificateType.VOTE_DELEGATION;
322
+ if (credential.kind() === 0) {
323
+ certificate.path = keys.stake.path;
324
+ }
325
+ else {
326
+ const scriptHash = Buffer.from(credential.to_scripthash().to_bytes()).toString('hex');
327
+ certificate.scriptHash = scriptHash;
328
+ }
329
+ // drep can be key hash, script hash, or abstain/no_confidence
330
+ const drep = voteDelegation.drep();
331
+ if ((_c = drep.to_key_hash) === null || _c === void 0 ? void 0 : _c.call(drep)) {
332
+ certificate.dRep = {
333
+ type: 0, // key hash
334
+ keyHash: Buffer.from(drep.to_key_hash().to_bytes()).toString('hex'),
335
+ };
336
+ }
337
+ else if ((_d = drep.to_script_hash) === null || _d === void 0 ? void 0 : _d.call(drep)) {
338
+ certificate.dRep = {
339
+ type: 1, // script hash
340
+ scriptHash: Buffer.from(drep.to_script_hash().to_bytes()).toString('hex'),
341
+ };
342
+ }
343
+ else {
344
+ // abstain or no_confidence
345
+ certificate.dRep = {
346
+ type: drep.kind(), // 2 = abstain, 3 = no_confidence
347
+ };
348
+ }
349
+ }
350
+ else {
351
+ // Fallback: just include stake path for signing
352
+ console.log(`[txToOneKey] Vote delegation cert kind ${certKind}, using stake path for signing`);
353
+ certificate.type = CardanoCertificateType.VOTE_DELEGATION;
354
+ certificate.path = keys.stake.path;
355
+ }
356
+ }
357
+ else {
358
+ // Skip unsupported certificate types
359
+ // Don't push empty certificate objects
360
+ console.log(`[txToOneKey] Unsupported certificate kind: ${certKind}, cert:`, cert.to_hex());
361
+ continue;
362
+ }
306
363
  onekeyCertificates.push(certificate);
307
364
  }
308
365
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/cardano-coin-selection-asmjs",
3
- "version": "1.1.9",
3
+ "version": "1.1.10-alpha.1",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "coin selection"