@lucid-evolution/wallet 0.1.74 → 0.1.76

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/dist/index.cjs CHANGED
@@ -300,6 +300,45 @@ function discoverOwnUsedTxKeyHashes(tx, ownKeyHashes, ownUtxos) {
300
300
  var import_core_utils2 = require("@lucid-evolution/core-utils");
301
301
  var import_utils2 = require("@lucid-evolution/utils");
302
302
  var import_sign_data = require("@lucid-evolution/sign_data");
303
+ var signTxsSequentially = async (txs, signTx) => {
304
+ const witnessSets = [];
305
+ for (const tx of txs) {
306
+ witnessSets.push(await signTx(tx));
307
+ }
308
+ return witnessSets;
309
+ };
310
+ var submitTxsSequentially = async (txs, submitTx) => {
311
+ const results = [];
312
+ let hasFailure = false;
313
+ for (const tx of txs) {
314
+ try {
315
+ results.push(await submitTx(tx));
316
+ } catch (error) {
317
+ results.push(error);
318
+ hasFailure = true;
319
+ }
320
+ }
321
+ if (hasFailure) {
322
+ throw results;
323
+ }
324
+ return results;
325
+ };
326
+ var decodeWitnessSets = (witnessSets, expectedLength) => {
327
+ if (witnessSets.length !== expectedLength) {
328
+ throw new Error("Wallet returned an unexpected number of witness sets.");
329
+ }
330
+ return witnessSets.map(
331
+ (witnessSet) => CML.TransactionWitnessSet.from_cbor_hex(witnessSet)
332
+ );
333
+ };
334
+ var validateTxHashes = (txHashes, expectedLength) => {
335
+ if (txHashes.length !== expectedLength) {
336
+ throw new Error(
337
+ "Wallet returned an unexpected number of transaction hashes."
338
+ );
339
+ }
340
+ return txHashes;
341
+ };
303
342
  var makeWalletFromSeed = (provider, network, seed, options) => {
304
343
  const config = {
305
344
  overriddenUTxOs: []
@@ -319,6 +358,21 @@ var makeWalletFromSeed = (provider, network, seed, options) => {
319
358
  [paymentKeyHash]: paymentKey,
320
359
  [stakeKeyHash]: stakeKey
321
360
  };
361
+ const signTx = async (tx) => {
362
+ const utxos = config.overriddenUTxOs.length > 0 ? config.overriddenUTxOs : await provider.getUtxos(address);
363
+ const ownKeyHashes = [paymentKeyHash, stakeKeyHash];
364
+ const usedKeyHashes = discoverOwnUsedTxKeyHashes(tx, ownKeyHashes, utxos);
365
+ const txWitnessSetBuilder = CML.TransactionWitnessSetBuilder.new();
366
+ for (const keyHash of usedKeyHashes) {
367
+ const priv = CML.PrivateKey.from_bech32(privKeyHashMap[keyHash]);
368
+ const witness = CML.make_vkey_witness(
369
+ CML.hash_transaction(tx.body()),
370
+ priv
371
+ );
372
+ txWitnessSetBuilder.add_vkey(witness);
373
+ }
374
+ return txWitnessSetBuilder.build();
375
+ };
322
376
  return {
323
377
  overrideUTxOs: (utxos) => config.overriddenUTxOs = utxos,
324
378
  address: async () => address,
@@ -335,21 +389,8 @@ var makeWalletFromSeed = (provider, network, seed, options) => {
335
389
  getDelegation: async () => {
336
390
  return rewardAddress ? await provider.getDelegation(rewardAddress) : { poolId: null, rewards: 0n };
337
391
  },
338
- signTx: async (tx) => {
339
- const utxos = config.overriddenUTxOs.length > 0 ? config.overriddenUTxOs : await provider.getUtxos(address);
340
- const ownKeyHashes = [paymentKeyHash, stakeKeyHash];
341
- const usedKeyHashes = discoverOwnUsedTxKeyHashes(tx, ownKeyHashes, utxos);
342
- const txWitnessSetBuilder = CML.TransactionWitnessSetBuilder.new();
343
- for (const keyHash of usedKeyHashes) {
344
- const priv = CML.PrivateKey.from_bech32(privKeyHashMap[keyHash]);
345
- const witness = CML.make_vkey_witness(
346
- CML.hash_transaction(tx.body()),
347
- priv
348
- );
349
- txWitnessSetBuilder.add_vkey(witness);
350
- }
351
- return txWitnessSetBuilder.build();
352
- },
392
+ signTx,
393
+ signTxs: async (txs) => signTxsSequentially(txs, signTx),
353
394
  signMessage: async (address2, payload) => {
354
395
  const {
355
396
  paymentCredential,
@@ -363,7 +404,8 @@ var makeWalletFromSeed = (provider, network, seed, options) => {
363
404
  }
364
405
  return (0, import_sign_data.signData)(hexAddress, payload, privateKey);
365
406
  },
366
- submitTx: async (tx) => provider.submitTx(tx)
407
+ submitTx: async (tx) => provider.submitTx(tx),
408
+ submitTxs: async (txs) => submitTxsSequentially(txs, (tx) => provider.submitTx(tx))
367
409
  };
368
410
  };
369
411
  var makeWalletFromPrivateKey = (provider, network, privateKey) => {
@@ -376,6 +418,15 @@ var makeWalletFromPrivateKey = (provider, network, privateKey) => {
376
418
  const config = {
377
419
  overriddenUTxOs: []
378
420
  };
421
+ const signTx = async (tx) => {
422
+ const witness = CML.make_vkey_witness(
423
+ CML.hash_transaction(tx.body()),
424
+ priv
425
+ );
426
+ const txWitnessSetBuilder = CML.TransactionWitnessSetBuilder.new();
427
+ txWitnessSetBuilder.add_vkey(witness);
428
+ return txWitnessSetBuilder.build();
429
+ };
379
430
  return {
380
431
  overrideUTxOs: (utxos) => config.overriddenUTxOs = utxos,
381
432
  address: async () => address,
@@ -392,15 +443,8 @@ var makeWalletFromPrivateKey = (provider, network, privateKey) => {
392
443
  getDelegation: async () => {
393
444
  return { poolId: null, rewards: 0n };
394
445
  },
395
- signTx: async (tx) => {
396
- const witness = CML.make_vkey_witness(
397
- CML.hash_transaction(tx.body()),
398
- priv
399
- );
400
- const txWitnessSetBuilder = CML.TransactionWitnessSetBuilder.new();
401
- txWitnessSetBuilder.add_vkey(witness);
402
- return txWitnessSetBuilder.build();
403
- },
446
+ signTx,
447
+ signTxs: async (txs) => signTxsSequentially(txs, signTx),
404
448
  signMessage: async (address2, payload) => {
405
449
  const {
406
450
  paymentCredential,
@@ -415,7 +459,8 @@ var makeWalletFromPrivateKey = (provider, network, privateKey) => {
415
459
  },
416
460
  submitTx: async (tx) => {
417
461
  return await provider.submitTx(tx);
418
- }
462
+ },
463
+ submitTxs: async (txs) => submitTxsSequentially(txs, (tx) => provider.submitTx(tx))
419
464
  };
420
465
  };
421
466
  var makeWalletFromAPI = (provider, api) => {
@@ -459,11 +504,31 @@ var makeWalletFromAPI = (provider, api) => {
459
504
  const witnessSet = await api.signTx((0, import_core_utils2.toHex)(tx.to_cbor_bytes()), true);
460
505
  return CML.TransactionWitnessSet.from_cbor_hex(witnessSet);
461
506
  },
507
+ signTxs: async (txs) => {
508
+ const cbors = txs.map((tx) => (0, import_core_utils2.toHex)(tx.to_cbor_bytes()));
509
+ const requests = cbors.map((cbor) => ({
510
+ cbor,
511
+ partialSign: true
512
+ }));
513
+ const signTxs = api.cip103?.signTxs?.bind(api.cip103) ?? api.experimental?.signTxs?.bind(api.experimental) ?? api.signTxs?.bind(api);
514
+ const witnessSets = signTxs ? await signTxs(requests) : [];
515
+ if (!signTxs) {
516
+ for (const cbor of cbors) {
517
+ witnessSets.push(await api.signTx(cbor, true));
518
+ }
519
+ }
520
+ return decodeWitnessSets(witnessSets, txs.length);
521
+ },
462
522
  signMessage: async (address, payload) => {
463
523
  const hexAddress = (0, import_core_utils2.toHex)(CML.Address.from_bech32(address).to_raw_bytes());
464
524
  return await api.signData(hexAddress, payload);
465
525
  },
466
- submitTx: async (tx) => api.submitTx(tx)
526
+ submitTx: async (tx) => api.submitTx(tx),
527
+ submitTxs: async (txs) => {
528
+ const submitTxs = api.cip103?.submitTxs?.bind(api.cip103);
529
+ const txHashes = submitTxs ? await submitTxs(txs) : await submitTxsSequentially(txs, (tx) => api.submitTx(tx));
530
+ return validateTxHashes(txHashes, txs.length);
531
+ }
467
532
  };
468
533
  };
469
534
  var makeWalletFromAddress = (provider, network, address, utxos) => {
@@ -489,10 +554,14 @@ var makeWalletFromAddress = (provider, network, address, utxos) => {
489
554
  signTx: async (_tx) => {
490
555
  throw new Error("Not implemented");
491
556
  },
557
+ signTxs: async (_txs) => {
558
+ throw new Error("Not implemented");
559
+ },
492
560
  signMessage: async (_address, _payload) => {
493
561
  throw new Error("Not implemented");
494
562
  },
495
- submitTx: async (tx) => provider.submitTx(tx)
563
+ submitTx: async (tx) => provider.submitTx(tx),
564
+ submitTxs: async (txs) => submitTxsSequentially(txs, (tx) => provider.submitTx(tx))
496
565
  };
497
566
  };
498
567
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.js CHANGED
@@ -264,6 +264,45 @@ import {
264
264
  utxoToCore
265
265
  } from "@lucid-evolution/utils";
266
266
  import { signData } from "@lucid-evolution/sign_data";
267
+ var signTxsSequentially = async (txs, signTx) => {
268
+ const witnessSets = [];
269
+ for (const tx of txs) {
270
+ witnessSets.push(await signTx(tx));
271
+ }
272
+ return witnessSets;
273
+ };
274
+ var submitTxsSequentially = async (txs, submitTx) => {
275
+ const results = [];
276
+ let hasFailure = false;
277
+ for (const tx of txs) {
278
+ try {
279
+ results.push(await submitTx(tx));
280
+ } catch (error) {
281
+ results.push(error);
282
+ hasFailure = true;
283
+ }
284
+ }
285
+ if (hasFailure) {
286
+ throw results;
287
+ }
288
+ return results;
289
+ };
290
+ var decodeWitnessSets = (witnessSets, expectedLength) => {
291
+ if (witnessSets.length !== expectedLength) {
292
+ throw new Error("Wallet returned an unexpected number of witness sets.");
293
+ }
294
+ return witnessSets.map(
295
+ (witnessSet) => CML.TransactionWitnessSet.from_cbor_hex(witnessSet)
296
+ );
297
+ };
298
+ var validateTxHashes = (txHashes, expectedLength) => {
299
+ if (txHashes.length !== expectedLength) {
300
+ throw new Error(
301
+ "Wallet returned an unexpected number of transaction hashes."
302
+ );
303
+ }
304
+ return txHashes;
305
+ };
267
306
  var makeWalletFromSeed = (provider, network, seed, options) => {
268
307
  const config = {
269
308
  overriddenUTxOs: []
@@ -283,6 +322,21 @@ var makeWalletFromSeed = (provider, network, seed, options) => {
283
322
  [paymentKeyHash]: paymentKey,
284
323
  [stakeKeyHash]: stakeKey
285
324
  };
325
+ const signTx = async (tx) => {
326
+ const utxos = config.overriddenUTxOs.length > 0 ? config.overriddenUTxOs : await provider.getUtxos(address);
327
+ const ownKeyHashes = [paymentKeyHash, stakeKeyHash];
328
+ const usedKeyHashes = discoverOwnUsedTxKeyHashes(tx, ownKeyHashes, utxos);
329
+ const txWitnessSetBuilder = CML.TransactionWitnessSetBuilder.new();
330
+ for (const keyHash of usedKeyHashes) {
331
+ const priv = CML.PrivateKey.from_bech32(privKeyHashMap[keyHash]);
332
+ const witness = CML.make_vkey_witness(
333
+ CML.hash_transaction(tx.body()),
334
+ priv
335
+ );
336
+ txWitnessSetBuilder.add_vkey(witness);
337
+ }
338
+ return txWitnessSetBuilder.build();
339
+ };
286
340
  return {
287
341
  overrideUTxOs: (utxos) => config.overriddenUTxOs = utxos,
288
342
  address: async () => address,
@@ -299,21 +353,8 @@ var makeWalletFromSeed = (provider, network, seed, options) => {
299
353
  getDelegation: async () => {
300
354
  return rewardAddress ? await provider.getDelegation(rewardAddress) : { poolId: null, rewards: 0n };
301
355
  },
302
- signTx: async (tx) => {
303
- const utxos = config.overriddenUTxOs.length > 0 ? config.overriddenUTxOs : await provider.getUtxos(address);
304
- const ownKeyHashes = [paymentKeyHash, stakeKeyHash];
305
- const usedKeyHashes = discoverOwnUsedTxKeyHashes(tx, ownKeyHashes, utxos);
306
- const txWitnessSetBuilder = CML.TransactionWitnessSetBuilder.new();
307
- for (const keyHash of usedKeyHashes) {
308
- const priv = CML.PrivateKey.from_bech32(privKeyHashMap[keyHash]);
309
- const witness = CML.make_vkey_witness(
310
- CML.hash_transaction(tx.body()),
311
- priv
312
- );
313
- txWitnessSetBuilder.add_vkey(witness);
314
- }
315
- return txWitnessSetBuilder.build();
316
- },
356
+ signTx,
357
+ signTxs: async (txs) => signTxsSequentially(txs, signTx),
317
358
  signMessage: async (address2, payload) => {
318
359
  const {
319
360
  paymentCredential,
@@ -327,7 +368,8 @@ var makeWalletFromSeed = (provider, network, seed, options) => {
327
368
  }
328
369
  return signData(hexAddress, payload, privateKey);
329
370
  },
330
- submitTx: async (tx) => provider.submitTx(tx)
371
+ submitTx: async (tx) => provider.submitTx(tx),
372
+ submitTxs: async (txs) => submitTxsSequentially(txs, (tx) => provider.submitTx(tx))
331
373
  };
332
374
  };
333
375
  var makeWalletFromPrivateKey = (provider, network, privateKey) => {
@@ -340,6 +382,15 @@ var makeWalletFromPrivateKey = (provider, network, privateKey) => {
340
382
  const config = {
341
383
  overriddenUTxOs: []
342
384
  };
385
+ const signTx = async (tx) => {
386
+ const witness = CML.make_vkey_witness(
387
+ CML.hash_transaction(tx.body()),
388
+ priv
389
+ );
390
+ const txWitnessSetBuilder = CML.TransactionWitnessSetBuilder.new();
391
+ txWitnessSetBuilder.add_vkey(witness);
392
+ return txWitnessSetBuilder.build();
393
+ };
343
394
  return {
344
395
  overrideUTxOs: (utxos) => config.overriddenUTxOs = utxos,
345
396
  address: async () => address,
@@ -356,15 +407,8 @@ var makeWalletFromPrivateKey = (provider, network, privateKey) => {
356
407
  getDelegation: async () => {
357
408
  return { poolId: null, rewards: 0n };
358
409
  },
359
- signTx: async (tx) => {
360
- const witness = CML.make_vkey_witness(
361
- CML.hash_transaction(tx.body()),
362
- priv
363
- );
364
- const txWitnessSetBuilder = CML.TransactionWitnessSetBuilder.new();
365
- txWitnessSetBuilder.add_vkey(witness);
366
- return txWitnessSetBuilder.build();
367
- },
410
+ signTx,
411
+ signTxs: async (txs) => signTxsSequentially(txs, signTx),
368
412
  signMessage: async (address2, payload) => {
369
413
  const {
370
414
  paymentCredential,
@@ -379,7 +423,8 @@ var makeWalletFromPrivateKey = (provider, network, privateKey) => {
379
423
  },
380
424
  submitTx: async (tx) => {
381
425
  return await provider.submitTx(tx);
382
- }
426
+ },
427
+ submitTxs: async (txs) => submitTxsSequentially(txs, (tx) => provider.submitTx(tx))
383
428
  };
384
429
  };
385
430
  var makeWalletFromAPI = (provider, api) => {
@@ -423,11 +468,31 @@ var makeWalletFromAPI = (provider, api) => {
423
468
  const witnessSet = await api.signTx(toHex(tx.to_cbor_bytes()), true);
424
469
  return CML.TransactionWitnessSet.from_cbor_hex(witnessSet);
425
470
  },
471
+ signTxs: async (txs) => {
472
+ const cbors = txs.map((tx) => toHex(tx.to_cbor_bytes()));
473
+ const requests = cbors.map((cbor) => ({
474
+ cbor,
475
+ partialSign: true
476
+ }));
477
+ const signTxs = api.cip103?.signTxs?.bind(api.cip103) ?? api.experimental?.signTxs?.bind(api.experimental) ?? api.signTxs?.bind(api);
478
+ const witnessSets = signTxs ? await signTxs(requests) : [];
479
+ if (!signTxs) {
480
+ for (const cbor of cbors) {
481
+ witnessSets.push(await api.signTx(cbor, true));
482
+ }
483
+ }
484
+ return decodeWitnessSets(witnessSets, txs.length);
485
+ },
426
486
  signMessage: async (address, payload) => {
427
487
  const hexAddress = toHex(CML.Address.from_bech32(address).to_raw_bytes());
428
488
  return await api.signData(hexAddress, payload);
429
489
  },
430
- submitTx: async (tx) => api.submitTx(tx)
490
+ submitTx: async (tx) => api.submitTx(tx),
491
+ submitTxs: async (txs) => {
492
+ const submitTxs = api.cip103?.submitTxs?.bind(api.cip103);
493
+ const txHashes = submitTxs ? await submitTxs(txs) : await submitTxsSequentially(txs, (tx) => api.submitTx(tx));
494
+ return validateTxHashes(txHashes, txs.length);
495
+ }
431
496
  };
432
497
  };
433
498
  var makeWalletFromAddress = (provider, network, address, utxos) => {
@@ -453,10 +518,14 @@ var makeWalletFromAddress = (provider, network, address, utxos) => {
453
518
  signTx: async (_tx) => {
454
519
  throw new Error("Not implemented");
455
520
  },
521
+ signTxs: async (_txs) => {
522
+ throw new Error("Not implemented");
523
+ },
456
524
  signMessage: async (_address, _payload) => {
457
525
  throw new Error("Not implemented");
458
526
  },
459
- submitTx: async (tx) => provider.submitTx(tx)
527
+ submitTx: async (tx) => provider.submitTx(tx),
528
+ submitTxs: async (txs) => submitTxsSequentially(txs, (tx) => provider.submitTx(tx))
460
529
  };
461
530
  };
462
531
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lucid-evolution/wallet",
3
- "version": "0.1.74",
3
+ "version": "0.1.76",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -25,13 +25,13 @@
25
25
  "@anastasia-labs/cardano-multiplatform-lib-nodejs": "@anastasia-labs/cardano-multiplatform-lib-browser"
26
26
  },
27
27
  "dependencies": {
28
- "@anastasia-labs/cardano-multiplatform-lib-browser": "6.0.2-3",
29
- "@anastasia-labs/cardano-multiplatform-lib-nodejs": "6.0.2-3",
28
+ "@anastasia-labs/cardano-multiplatform-lib-browser": "6.2.0-1",
29
+ "@anastasia-labs/cardano-multiplatform-lib-nodejs": "6.2.0-1",
30
30
  "bip39": "^3.1.0",
31
- "@lucid-evolution/core-types": "0.1.24",
31
+ "@lucid-evolution/core-types": "0.2.1",
32
+ "@lucid-evolution/sign_data": "0.1.29",
32
33
  "@lucid-evolution/core-utils": "0.1.16",
33
- "@lucid-evolution/sign_data": "0.1.27",
34
- "@lucid-evolution/utils": "0.1.68"
34
+ "@lucid-evolution/utils": "0.1.70"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/node": "^20.12.8",