@meshsdk/wallet 1.9.0-beta.2 → 1.9.0-beta.4

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
@@ -569,23 +569,23 @@ var bech32 = /* @__PURE__ */ genBech32("bech32");
569
569
  var import_common = require("@meshsdk/common");
570
570
  var import_core_cst = require("@meshsdk/core-cst");
571
571
  var WalletStaticMethods = class {
572
- static privateKeyToEntropy(_bech32) {
572
+ static privateKeyBech32ToPrivateKeyHex(_bech32) {
573
573
  const bech32DecodedBytes = bech32.decodeToBytes(_bech32).bytes;
574
574
  const bip32PrivateKey = import_core_cst.Bip32PrivateKey.fromBytes(bech32DecodedBytes);
575
575
  return (0, import_common.bytesToHex)(bip32PrivateKey.bytes());
576
576
  }
577
- static mnemonicToEntropy(words) {
577
+ static mnemonicToPrivateKeyHex(words) {
578
578
  const entropy = (0, import_common.mnemonicToEntropy)(words.join(" "));
579
579
  const bip32PrivateKey = (0, import_core_cst.buildBip32PrivateKey)(entropy);
580
580
  return (0, import_common.bytesToHex)(bip32PrivateKey.bytes());
581
581
  }
582
- static signingKeyToEntropy(paymentKey, stakeKey) {
582
+ static signingKeyToHexes(paymentKey, stakeKey) {
583
583
  return [
584
584
  paymentKey.startsWith("5820") ? paymentKey.slice(4) : paymentKey,
585
585
  stakeKey.startsWith("5820") ? stakeKey.slice(4) : stakeKey
586
586
  ];
587
587
  }
588
- static bip32BytesToEntropy(bip32Bytes) {
588
+ static bip32BytesToPrivateKeyHex(bip32Bytes) {
589
589
  const bip32PrivateKey = import_core_cst.Bip32PrivateKey.fromBytes(bip32Bytes);
590
590
  return (0, import_common.bytesToHex)(bip32PrivateKey.bytes());
591
591
  }
@@ -593,22 +593,22 @@ var WalletStaticMethods = class {
593
593
  const baseAddress = (0, import_core_cst.buildBaseAddress)(
594
594
  networkId,
595
595
  import_core_cst.Hash28ByteBase16.fromEd25519KeyHashHex(
596
- (0, import_core_cst.Ed25519KeyHashHex)(paymentKey.toPublicKey().hash().toString("hex"))
596
+ paymentKey.toPublic().hash().hex()
597
597
  ),
598
598
  import_core_cst.Hash28ByteBase16.fromEd25519KeyHashHex(
599
- (0, import_core_cst.Ed25519KeyHashHex)(stakingKey.toPublicKey().hash().toString("hex"))
599
+ stakingKey.toPublic().hash().hex()
600
600
  )
601
601
  ).toAddress();
602
602
  const enterpriseAddress = (0, import_core_cst.buildEnterpriseAddress)(
603
603
  networkId,
604
604
  import_core_cst.Hash28ByteBase16.fromEd25519KeyHashHex(
605
- (0, import_core_cst.Ed25519KeyHashHex)(paymentKey.toPublicKey().hash().toString("hex"))
605
+ paymentKey.toPublic().hash().hex()
606
606
  )
607
607
  ).toAddress();
608
608
  const rewardAddress = (0, import_core_cst.buildRewardAddress)(
609
609
  networkId,
610
610
  import_core_cst.Hash28ByteBase16.fromEd25519KeyHashHex(
611
- (0, import_core_cst.Ed25519KeyHashHex)(stakingKey.toPublicKey().hash().toString("hex"))
611
+ stakingKey.toPublic().hash().hex()
612
612
  )
613
613
  ).toAddress();
614
614
  return {
@@ -618,15 +618,12 @@ var WalletStaticMethods = class {
618
618
  };
619
619
  }
620
620
  static getDRepKey(dRepKey, networkId = 0) {
621
- const pubKey = dRepKey.toPublicKey().pubKey;
622
- const pubDRepKey = pubKey.toString("hex");
621
+ const pubDRepKey = dRepKey.toPublic().hex().toString();
623
622
  const dRepIDBech32 = (0, import_core_cst.buildDRepID)(
624
623
  (0, import_core_cst.Ed25519PublicKeyHex)(pubDRepKey),
625
624
  networkId
626
625
  );
627
- const dRep = import_core_cst.DRep.newKeyHash(
628
- (0, import_core_cst.Ed25519KeyHashHex)(dRepKey.toPublicKey().hash().toString("hex"))
629
- );
626
+ const dRep = import_core_cst.DRep.newKeyHash(dRepKey.toPublic().hash().hex());
630
627
  const dRepIDHash = dRep.toKeyHash();
631
628
  return {
632
629
  pubDRepKey,
@@ -653,40 +650,43 @@ var WalletStaticMethods = class {
653
650
  }
654
651
  };
655
652
  var EmbeddedWallet = class extends WalletStaticMethods {
656
- _entropy;
653
+ _walletSecret;
657
654
  _networkId;
658
655
  constructor(options) {
659
656
  super();
660
657
  this._networkId = options.networkId;
661
658
  switch (options.key.type) {
662
659
  case "mnemonic":
663
- this._entropy = WalletStaticMethods.mnemonicToEntropy(
660
+ this._walletSecret = WalletStaticMethods.mnemonicToPrivateKeyHex(
664
661
  options.key.words
665
662
  );
666
663
  break;
667
664
  case "root":
668
- this._entropy = WalletStaticMethods.privateKeyToEntropy(
665
+ this._walletSecret = WalletStaticMethods.privateKeyBech32ToPrivateKeyHex(
669
666
  options.key.bech32
670
667
  );
671
668
  break;
672
669
  case "cli":
673
- this._entropy = WalletStaticMethods.signingKeyToEntropy(
670
+ this._walletSecret = WalletStaticMethods.signingKeyToHexes(
674
671
  options.key.payment,
675
672
  options.key.stake ?? "f0".repeat(32)
676
673
  );
677
674
  break;
678
675
  case "bip32Bytes":
679
- this._entropy = WalletStaticMethods.bip32BytesToEntropy(
676
+ this._walletSecret = WalletStaticMethods.bip32BytesToPrivateKeyHex(
680
677
  options.key.bip32Bytes
681
678
  );
682
679
  break;
683
680
  }
684
681
  }
682
+ async init() {
683
+ await import_core_cst.Crypto.ready();
684
+ }
685
685
  getAccount(accountIndex = 0, keyIndex = 0) {
686
- if (this._entropy == void 0)
686
+ if (this._walletSecret == void 0)
687
687
  throw new Error("[EmbeddedWallet] No keys initialized");
688
688
  const { paymentKey, stakeKey, dRepKey } = (0, import_core_cst.buildKeys)(
689
- this._entropy,
689
+ this._walletSecret,
690
690
  accountIndex,
691
691
  keyIndex
692
692
  );
@@ -700,8 +700,8 @@ var EmbeddedWallet = class extends WalletStaticMethods {
700
700
  rewardAddressBech32: rewardAddress.toBech32(),
701
701
  paymentKey,
702
702
  stakeKey,
703
- paymentKeyHex: paymentKey.toBytes().toString("hex"),
704
- stakeKeyHex: stakeKey.toBytes().toString("hex")
703
+ paymentKeyHex: paymentKey.hex(),
704
+ stakeKeyHex: stakeKey.hex()
705
705
  };
706
706
  if (dRepKey) {
707
707
  const { pubDRepKey, dRepIDBech32, dRepIDHash } = WalletStaticMethods.getDRepKey(dRepKey, this._networkId);
@@ -760,10 +760,8 @@ var EmbeddedWallet = class extends WalletStaticMethods {
760
760
  const txHash = (0, import_core_cst.deserializeTxHash)((0, import_core_cst.resolveTxHash)(unsignedTx));
761
761
  const { paymentKey } = this.getAccount(accountIndex, keyIndex);
762
762
  const vKeyWitness = new import_core_cst.VkeyWitness(
763
- (0, import_core_cst.Ed25519PublicKeyHex)(paymentKey.toPublicKey().toBytes().toString("hex")),
764
- (0, import_core_cst.Ed25519SignatureHex)(
765
- paymentKey.sign(Buffer.from(txHash, "hex")).toString("hex")
766
- )
763
+ paymentKey.toPublic().hex(),
764
+ paymentKey.sign((0, import_core_cst.HexBlob)(txHash)).hex()
767
765
  );
768
766
  return vKeyWitness;
769
767
  } catch (error) {
@@ -812,6 +810,15 @@ var AppWallet = class {
812
810
  });
813
811
  }
814
812
  }
813
+ /**
814
+ * Initializes the wallet. This is a required call as fetching addresses from the wallet is an async operation.
815
+ * @returns void
816
+ */
817
+ async init() {
818
+ if (this._wallet) {
819
+ await this._wallet.init();
820
+ }
821
+ }
815
822
  /**
816
823
  * Get a list of UTXOs to be used as collateral inputs for transactions with plutus script inputs.
817
824
  *
@@ -1578,6 +1585,7 @@ var import_common4 = require("@meshsdk/common");
1578
1585
  var import_core_cst5 = require("@meshsdk/core-cst");
1579
1586
  var import_transaction = require("@meshsdk/transaction");
1580
1587
  var MeshWallet = class {
1588
+ _keyType;
1581
1589
  _wallet;
1582
1590
  _accountIndex = 0;
1583
1591
  _keyIndex = 0;
@@ -1587,6 +1595,7 @@ var MeshWallet = class {
1587
1595
  addresses = {};
1588
1596
  constructor(options) {
1589
1597
  this._networkId = options.networkId;
1598
+ this._keyType = options.key.type;
1590
1599
  if (options.fetcher) this._fetcher = options.fetcher;
1591
1600
  if (options.submitter) this._submitter = options.submitter;
1592
1601
  if (options.accountIndex) this._accountIndex = options.accountIndex;
@@ -1600,7 +1609,6 @@ var MeshWallet = class {
1600
1609
  bech32: options.key.bech32
1601
1610
  }
1602
1611
  });
1603
- this.getAddressesFromWallet(this._wallet);
1604
1612
  break;
1605
1613
  case "cli":
1606
1614
  this._wallet = new EmbeddedWallet({
@@ -1611,7 +1619,6 @@ var MeshWallet = class {
1611
1619
  stake: options.key.stake
1612
1620
  }
1613
1621
  });
1614
- this.getAddressesFromWallet(this._wallet);
1615
1622
  break;
1616
1623
  case "mnemonic":
1617
1624
  this._wallet = new EmbeddedWallet({
@@ -1621,7 +1628,6 @@ var MeshWallet = class {
1621
1628
  words: options.key.words
1622
1629
  }
1623
1630
  });
1624
- this.getAddressesFromWallet(this._wallet);
1625
1631
  break;
1626
1632
  case "bip32Bytes":
1627
1633
  this._wallet = new EmbeddedWallet({
@@ -1631,7 +1637,6 @@ var MeshWallet = class {
1631
1637
  bip32Bytes: options.key.bip32Bytes
1632
1638
  }
1633
1639
  });
1634
- this.getAddressesFromWallet(this._wallet);
1635
1640
  break;
1636
1641
  case "address":
1637
1642
  this._wallet = null;
@@ -1639,6 +1644,16 @@ var MeshWallet = class {
1639
1644
  break;
1640
1645
  }
1641
1646
  }
1647
+ /**
1648
+ * Initializes the wallet. This is a required call as fetching addresses from the wallet is an async operation.
1649
+ * @returns void
1650
+ */
1651
+ async init() {
1652
+ if (this._wallet) {
1653
+ await this._wallet.init();
1654
+ this.getAddressesFromWallet(this._wallet);
1655
+ }
1656
+ }
1642
1657
  /**
1643
1658
  * Returns all derived addresses from the wallet.
1644
1659
  * @returns a list of addresses
@@ -1680,7 +1695,7 @@ var MeshWallet = class {
1680
1695
  *
1681
1696
  * @returns an address
1682
1697
  */
1683
- getChangeAddress() {
1698
+ async getChangeAddress() {
1684
1699
  return this.addresses.baseAddressBech32 ? this.addresses.baseAddressBech32 : this.addresses.enterpriseAddressBech32;
1685
1700
  }
1686
1701
  /**
@@ -1760,7 +1775,7 @@ var MeshWallet = class {
1760
1775
  * @returns a list of unused addresses
1761
1776
  */
1762
1777
  async getUnusedAddresses() {
1763
- return [this.getChangeAddress()];
1778
+ return [await this.getChangeAddress()];
1764
1779
  }
1765
1780
  /**
1766
1781
  * Returns a list of used addresses controlled by the wallet.
@@ -1768,7 +1783,7 @@ var MeshWallet = class {
1768
1783
  * @returns a list of used addresses
1769
1784
  */
1770
1785
  async getUsedAddresses() {
1771
- return [this.getChangeAddress()];
1786
+ return [await this.getChangeAddress()];
1772
1787
  }
1773
1788
  /**
1774
1789
  * Get a list of UTXOs to be used for transaction building.
@@ -1805,7 +1820,7 @@ var MeshWallet = class {
1805
1820
  );
1806
1821
  }
1807
1822
  if (address === void 0) {
1808
- address = this.getChangeAddress();
1823
+ address = await this.getChangeAddress();
1809
1824
  }
1810
1825
  return this._wallet.signData(
1811
1826
  address,
@@ -1976,7 +1991,7 @@ var MeshWallet = class {
1976
1991
  */
1977
1992
  async createCollateral() {
1978
1993
  const tx = new import_transaction.Transaction({ initiator: this });
1979
- tx.sendLovelace(this.getChangeAddress(), "5000000");
1994
+ tx.sendLovelace(await this.getChangeAddress(), "5000000");
1980
1995
  const unsignedTx = await tx.build();
1981
1996
  const signedTx = await this.signTx(unsignedTx);
1982
1997
  const txHash = await this.submitTx(signedTx);
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { DataSignature, IFetcher, ISubmitter, ISigner, IWallet, Wallet, Asset, UTxO, AssetExtended } from '@meshsdk/common';
2
- import { Ed25519PublicKeyHex, TransactionUnspentOutput, Address, StricaPrivateKey, DRepID, Ed25519KeyHashHex, VkeyWitness } from '@meshsdk/core-cst';
2
+ import { Ed25519PublicKeyHex, TransactionUnspentOutput, Address, Ed25519PrivateKey, DRepID, Ed25519KeyHashHex, VkeyWitness } from '@meshsdk/core-cst';
3
3
  import * as _simplewebauthn_browser from '@simplewebauthn/browser';
4
4
 
5
5
  type Cardano = {
@@ -77,6 +77,11 @@ declare class AppWallet implements ISigner, ISubmitter {
77
77
  private readonly _submitter?;
78
78
  private readonly _wallet;
79
79
  constructor(options: CreateAppWalletOptions);
80
+ /**
81
+ * Initializes the wallet. This is a required call as fetching addresses from the wallet is an async operation.
82
+ * @returns void
83
+ */
84
+ init(): Promise<void>;
80
85
  /**
81
86
  * Get a list of UTXOs to be used as collateral inputs for transactions with plutus script inputs.
82
87
  *
@@ -384,8 +389,8 @@ type Account = {
384
389
  baseAddressBech32: string;
385
390
  enterpriseAddressBech32: string;
386
391
  rewardAddressBech32: string;
387
- paymentKey: StricaPrivateKey;
388
- stakeKey: StricaPrivateKey;
392
+ paymentKey: Ed25519PrivateKey;
393
+ stakeKey: Ed25519PrivateKey;
389
394
  paymentKeyHex: string;
390
395
  stakeKeyHex: string;
391
396
  pubDRepKey?: string;
@@ -411,16 +416,16 @@ type CreateEmbeddedWalletOptions = {
411
416
  key: EmbeddedWalletKeyType;
412
417
  };
413
418
  declare class WalletStaticMethods {
414
- static privateKeyToEntropy(_bech32: string): string;
415
- static mnemonicToEntropy(words: string[]): string;
416
- static signingKeyToEntropy(paymentKey: string, stakeKey: string): [string, string];
417
- static bip32BytesToEntropy(bip32Bytes: Uint8Array): string;
418
- static getAddresses(paymentKey: StricaPrivateKey, stakingKey: StricaPrivateKey, networkId?: number): {
419
+ static privateKeyBech32ToPrivateKeyHex(_bech32: string): string;
420
+ static mnemonicToPrivateKeyHex(words: string[]): string;
421
+ static signingKeyToHexes(paymentKey: string, stakeKey: string): [string, string];
422
+ static bip32BytesToPrivateKeyHex(bip32Bytes: Uint8Array): string;
423
+ static getAddresses(paymentKey: Ed25519PrivateKey, stakingKey: Ed25519PrivateKey, networkId?: number): {
419
424
  baseAddress: Address;
420
425
  enterpriseAddress: Address;
421
426
  rewardAddress: Address;
422
427
  };
423
- static getDRepKey(dRepKey: StricaPrivateKey, networkId?: number): {
428
+ static getDRepKey(dRepKey: Ed25519PrivateKey, networkId?: number): {
424
429
  pubDRepKey: string;
425
430
  dRepIDBech32: DRepID;
426
431
  dRepIDHash: Ed25519KeyHashHex;
@@ -429,9 +434,10 @@ declare class WalletStaticMethods {
429
434
  static addWitnessSets(txHex: string, witnesses: VkeyWitness[]): string;
430
435
  }
431
436
  declare class EmbeddedWallet extends WalletStaticMethods {
432
- private readonly _entropy?;
437
+ private readonly _walletSecret?;
433
438
  private readonly _networkId;
434
439
  constructor(options: CreateEmbeddedWalletOptions);
440
+ init(): Promise<void>;
435
441
  getAccount(accountIndex?: number, keyIndex?: number): Account;
436
442
  /**
437
443
  * Get wallet network ID.
@@ -507,8 +513,11 @@ type CreateMeshWalletOptions = {
507
513
  * },
508
514
  * });
509
515
  * ```
516
+ *
517
+ * Please call `await wallet.init()` after creating the wallet to fetch the addresses from the wallet.
510
518
  */
511
519
  declare class MeshWallet implements IWallet {
520
+ private readonly _keyType;
512
521
  private readonly _wallet;
513
522
  private readonly _accountIndex;
514
523
  private readonly _keyIndex;
@@ -527,6 +536,11 @@ declare class MeshWallet implements IWallet {
527
536
  dRepIDHash?: Ed25519KeyHashHex;
528
537
  };
529
538
  constructor(options: CreateMeshWalletOptions);
539
+ /**
540
+ * Initializes the wallet. This is a required call as fetching addresses from the wallet is an async operation.
541
+ * @returns void
542
+ */
543
+ init(): Promise<void>;
530
544
  /**
531
545
  * Returns all derived addresses from the wallet.
532
546
  * @returns a list of addresses
@@ -555,7 +569,7 @@ declare class MeshWallet implements IWallet {
555
569
  *
556
570
  * @returns an address
557
571
  */
558
- getChangeAddress(): string;
572
+ getChangeAddress(): Promise<string>;
559
573
  /**
560
574
  * This function shall return a list of one or more UTXOs (unspent transaction outputs) controlled by the wallet that are required to reach AT LEAST the combined ADA value target specified in amount AND the best suitable to be used as collateral inputs for transactions with plutus script inputs (pure ADA-only UTXOs).
561
575
  *
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { DataSignature, IFetcher, ISubmitter, ISigner, IWallet, Wallet, Asset, UTxO, AssetExtended } from '@meshsdk/common';
2
- import { Ed25519PublicKeyHex, TransactionUnspentOutput, Address, StricaPrivateKey, DRepID, Ed25519KeyHashHex, VkeyWitness } from '@meshsdk/core-cst';
2
+ import { Ed25519PublicKeyHex, TransactionUnspentOutput, Address, Ed25519PrivateKey, DRepID, Ed25519KeyHashHex, VkeyWitness } from '@meshsdk/core-cst';
3
3
  import * as _simplewebauthn_browser from '@simplewebauthn/browser';
4
4
 
5
5
  type Cardano = {
@@ -77,6 +77,11 @@ declare class AppWallet implements ISigner, ISubmitter {
77
77
  private readonly _submitter?;
78
78
  private readonly _wallet;
79
79
  constructor(options: CreateAppWalletOptions);
80
+ /**
81
+ * Initializes the wallet. This is a required call as fetching addresses from the wallet is an async operation.
82
+ * @returns void
83
+ */
84
+ init(): Promise<void>;
80
85
  /**
81
86
  * Get a list of UTXOs to be used as collateral inputs for transactions with plutus script inputs.
82
87
  *
@@ -384,8 +389,8 @@ type Account = {
384
389
  baseAddressBech32: string;
385
390
  enterpriseAddressBech32: string;
386
391
  rewardAddressBech32: string;
387
- paymentKey: StricaPrivateKey;
388
- stakeKey: StricaPrivateKey;
392
+ paymentKey: Ed25519PrivateKey;
393
+ stakeKey: Ed25519PrivateKey;
389
394
  paymentKeyHex: string;
390
395
  stakeKeyHex: string;
391
396
  pubDRepKey?: string;
@@ -411,16 +416,16 @@ type CreateEmbeddedWalletOptions = {
411
416
  key: EmbeddedWalletKeyType;
412
417
  };
413
418
  declare class WalletStaticMethods {
414
- static privateKeyToEntropy(_bech32: string): string;
415
- static mnemonicToEntropy(words: string[]): string;
416
- static signingKeyToEntropy(paymentKey: string, stakeKey: string): [string, string];
417
- static bip32BytesToEntropy(bip32Bytes: Uint8Array): string;
418
- static getAddresses(paymentKey: StricaPrivateKey, stakingKey: StricaPrivateKey, networkId?: number): {
419
+ static privateKeyBech32ToPrivateKeyHex(_bech32: string): string;
420
+ static mnemonicToPrivateKeyHex(words: string[]): string;
421
+ static signingKeyToHexes(paymentKey: string, stakeKey: string): [string, string];
422
+ static bip32BytesToPrivateKeyHex(bip32Bytes: Uint8Array): string;
423
+ static getAddresses(paymentKey: Ed25519PrivateKey, stakingKey: Ed25519PrivateKey, networkId?: number): {
419
424
  baseAddress: Address;
420
425
  enterpriseAddress: Address;
421
426
  rewardAddress: Address;
422
427
  };
423
- static getDRepKey(dRepKey: StricaPrivateKey, networkId?: number): {
428
+ static getDRepKey(dRepKey: Ed25519PrivateKey, networkId?: number): {
424
429
  pubDRepKey: string;
425
430
  dRepIDBech32: DRepID;
426
431
  dRepIDHash: Ed25519KeyHashHex;
@@ -429,9 +434,10 @@ declare class WalletStaticMethods {
429
434
  static addWitnessSets(txHex: string, witnesses: VkeyWitness[]): string;
430
435
  }
431
436
  declare class EmbeddedWallet extends WalletStaticMethods {
432
- private readonly _entropy?;
437
+ private readonly _walletSecret?;
433
438
  private readonly _networkId;
434
439
  constructor(options: CreateEmbeddedWalletOptions);
440
+ init(): Promise<void>;
435
441
  getAccount(accountIndex?: number, keyIndex?: number): Account;
436
442
  /**
437
443
  * Get wallet network ID.
@@ -507,8 +513,11 @@ type CreateMeshWalletOptions = {
507
513
  * },
508
514
  * });
509
515
  * ```
516
+ *
517
+ * Please call `await wallet.init()` after creating the wallet to fetch the addresses from the wallet.
510
518
  */
511
519
  declare class MeshWallet implements IWallet {
520
+ private readonly _keyType;
512
521
  private readonly _wallet;
513
522
  private readonly _accountIndex;
514
523
  private readonly _keyIndex;
@@ -527,6 +536,11 @@ declare class MeshWallet implements IWallet {
527
536
  dRepIDHash?: Ed25519KeyHashHex;
528
537
  };
529
538
  constructor(options: CreateMeshWalletOptions);
539
+ /**
540
+ * Initializes the wallet. This is a required call as fetching addresses from the wallet is an async operation.
541
+ * @returns void
542
+ */
543
+ init(): Promise<void>;
530
544
  /**
531
545
  * Returns all derived addresses from the wallet.
532
546
  * @returns a list of addresses
@@ -555,7 +569,7 @@ declare class MeshWallet implements IWallet {
555
569
  *
556
570
  * @returns an address
557
571
  */
558
- getChangeAddress(): string;
572
+ getChangeAddress(): Promise<string>;
559
573
  /**
560
574
  * This function shall return a list of one or more UTXOs (unspent transaction outputs) controlled by the wallet that are required to reach AT LEAST the combined ADA value target specified in amount AND the best suitable to be used as collateral inputs for transactions with plutus script inputs (pure ADA-only UTXOs).
561
575
  *
package/dist/index.js CHANGED
@@ -564,13 +564,13 @@ import {
564
564
  buildEnterpriseAddress,
565
565
  buildKeys,
566
566
  buildRewardAddress,
567
+ Crypto,
567
568
  deserializeTx,
568
569
  deserializeTxHash,
569
570
  DRep,
570
- Ed25519KeyHashHex,
571
571
  Ed25519PublicKeyHex,
572
- Ed25519SignatureHex,
573
572
  Hash28ByteBase16,
573
+ HexBlob,
574
574
  resolveTxHash,
575
575
  Serialization,
576
576
  signData,
@@ -578,23 +578,23 @@ import {
578
578
  VkeyWitness
579
579
  } from "@meshsdk/core-cst";
580
580
  var WalletStaticMethods = class {
581
- static privateKeyToEntropy(_bech32) {
581
+ static privateKeyBech32ToPrivateKeyHex(_bech32) {
582
582
  const bech32DecodedBytes = bech32.decodeToBytes(_bech32).bytes;
583
583
  const bip32PrivateKey = Bip32PrivateKey.fromBytes(bech32DecodedBytes);
584
584
  return bytesToHex(bip32PrivateKey.bytes());
585
585
  }
586
- static mnemonicToEntropy(words) {
586
+ static mnemonicToPrivateKeyHex(words) {
587
587
  const entropy = mnemonicToEntropy(words.join(" "));
588
588
  const bip32PrivateKey = buildBip32PrivateKey(entropy);
589
589
  return bytesToHex(bip32PrivateKey.bytes());
590
590
  }
591
- static signingKeyToEntropy(paymentKey, stakeKey) {
591
+ static signingKeyToHexes(paymentKey, stakeKey) {
592
592
  return [
593
593
  paymentKey.startsWith("5820") ? paymentKey.slice(4) : paymentKey,
594
594
  stakeKey.startsWith("5820") ? stakeKey.slice(4) : stakeKey
595
595
  ];
596
596
  }
597
- static bip32BytesToEntropy(bip32Bytes) {
597
+ static bip32BytesToPrivateKeyHex(bip32Bytes) {
598
598
  const bip32PrivateKey = Bip32PrivateKey.fromBytes(bip32Bytes);
599
599
  return bytesToHex(bip32PrivateKey.bytes());
600
600
  }
@@ -602,22 +602,22 @@ var WalletStaticMethods = class {
602
602
  const baseAddress = buildBaseAddress(
603
603
  networkId,
604
604
  Hash28ByteBase16.fromEd25519KeyHashHex(
605
- Ed25519KeyHashHex(paymentKey.toPublicKey().hash().toString("hex"))
605
+ paymentKey.toPublic().hash().hex()
606
606
  ),
607
607
  Hash28ByteBase16.fromEd25519KeyHashHex(
608
- Ed25519KeyHashHex(stakingKey.toPublicKey().hash().toString("hex"))
608
+ stakingKey.toPublic().hash().hex()
609
609
  )
610
610
  ).toAddress();
611
611
  const enterpriseAddress = buildEnterpriseAddress(
612
612
  networkId,
613
613
  Hash28ByteBase16.fromEd25519KeyHashHex(
614
- Ed25519KeyHashHex(paymentKey.toPublicKey().hash().toString("hex"))
614
+ paymentKey.toPublic().hash().hex()
615
615
  )
616
616
  ).toAddress();
617
617
  const rewardAddress = buildRewardAddress(
618
618
  networkId,
619
619
  Hash28ByteBase16.fromEd25519KeyHashHex(
620
- Ed25519KeyHashHex(stakingKey.toPublicKey().hash().toString("hex"))
620
+ stakingKey.toPublic().hash().hex()
621
621
  )
622
622
  ).toAddress();
623
623
  return {
@@ -627,15 +627,12 @@ var WalletStaticMethods = class {
627
627
  };
628
628
  }
629
629
  static getDRepKey(dRepKey, networkId = 0) {
630
- const pubKey = dRepKey.toPublicKey().pubKey;
631
- const pubDRepKey = pubKey.toString("hex");
630
+ const pubDRepKey = dRepKey.toPublic().hex().toString();
632
631
  const dRepIDBech32 = buildDRepID(
633
632
  Ed25519PublicKeyHex(pubDRepKey),
634
633
  networkId
635
634
  );
636
- const dRep = DRep.newKeyHash(
637
- Ed25519KeyHashHex(dRepKey.toPublicKey().hash().toString("hex"))
638
- );
635
+ const dRep = DRep.newKeyHash(dRepKey.toPublic().hash().hex());
639
636
  const dRepIDHash = dRep.toKeyHash();
640
637
  return {
641
638
  pubDRepKey,
@@ -662,40 +659,43 @@ var WalletStaticMethods = class {
662
659
  }
663
660
  };
664
661
  var EmbeddedWallet = class extends WalletStaticMethods {
665
- _entropy;
662
+ _walletSecret;
666
663
  _networkId;
667
664
  constructor(options) {
668
665
  super();
669
666
  this._networkId = options.networkId;
670
667
  switch (options.key.type) {
671
668
  case "mnemonic":
672
- this._entropy = WalletStaticMethods.mnemonicToEntropy(
669
+ this._walletSecret = WalletStaticMethods.mnemonicToPrivateKeyHex(
673
670
  options.key.words
674
671
  );
675
672
  break;
676
673
  case "root":
677
- this._entropy = WalletStaticMethods.privateKeyToEntropy(
674
+ this._walletSecret = WalletStaticMethods.privateKeyBech32ToPrivateKeyHex(
678
675
  options.key.bech32
679
676
  );
680
677
  break;
681
678
  case "cli":
682
- this._entropy = WalletStaticMethods.signingKeyToEntropy(
679
+ this._walletSecret = WalletStaticMethods.signingKeyToHexes(
683
680
  options.key.payment,
684
681
  options.key.stake ?? "f0".repeat(32)
685
682
  );
686
683
  break;
687
684
  case "bip32Bytes":
688
- this._entropy = WalletStaticMethods.bip32BytesToEntropy(
685
+ this._walletSecret = WalletStaticMethods.bip32BytesToPrivateKeyHex(
689
686
  options.key.bip32Bytes
690
687
  );
691
688
  break;
692
689
  }
693
690
  }
691
+ async init() {
692
+ await Crypto.ready();
693
+ }
694
694
  getAccount(accountIndex = 0, keyIndex = 0) {
695
- if (this._entropy == void 0)
695
+ if (this._walletSecret == void 0)
696
696
  throw new Error("[EmbeddedWallet] No keys initialized");
697
697
  const { paymentKey, stakeKey, dRepKey } = buildKeys(
698
- this._entropy,
698
+ this._walletSecret,
699
699
  accountIndex,
700
700
  keyIndex
701
701
  );
@@ -709,8 +709,8 @@ var EmbeddedWallet = class extends WalletStaticMethods {
709
709
  rewardAddressBech32: rewardAddress.toBech32(),
710
710
  paymentKey,
711
711
  stakeKey,
712
- paymentKeyHex: paymentKey.toBytes().toString("hex"),
713
- stakeKeyHex: stakeKey.toBytes().toString("hex")
712
+ paymentKeyHex: paymentKey.hex(),
713
+ stakeKeyHex: stakeKey.hex()
714
714
  };
715
715
  if (dRepKey) {
716
716
  const { pubDRepKey, dRepIDBech32, dRepIDHash } = WalletStaticMethods.getDRepKey(dRepKey, this._networkId);
@@ -769,10 +769,8 @@ var EmbeddedWallet = class extends WalletStaticMethods {
769
769
  const txHash = deserializeTxHash(resolveTxHash(unsignedTx));
770
770
  const { paymentKey } = this.getAccount(accountIndex, keyIndex);
771
771
  const vKeyWitness = new VkeyWitness(
772
- Ed25519PublicKeyHex(paymentKey.toPublicKey().toBytes().toString("hex")),
773
- Ed25519SignatureHex(
774
- paymentKey.sign(Buffer.from(txHash, "hex")).toString("hex")
775
- )
772
+ paymentKey.toPublic().hex(),
773
+ paymentKey.sign(HexBlob(txHash)).hex()
776
774
  );
777
775
  return vKeyWitness;
778
776
  } catch (error) {
@@ -821,6 +819,15 @@ var AppWallet = class {
821
819
  });
822
820
  }
823
821
  }
822
+ /**
823
+ * Initializes the wallet. This is a required call as fetching addresses from the wallet is an async operation.
824
+ * @returns void
825
+ */
826
+ async init() {
827
+ if (this._wallet) {
828
+ await this._wallet.init();
829
+ }
830
+ }
824
831
  /**
825
832
  * Get a list of UTXOs to be used as collateral inputs for transactions with plutus script inputs.
826
833
  *
@@ -1447,13 +1454,13 @@ var BrowserWallet = class _BrowserWallet {
1447
1454
  // src/browser/webauthn/cardano/build-wallet-from-passkey.ts
1448
1455
  var import_base32_encoding = __toESM(require_base32_encoding(), 1);
1449
1456
  var import_bech32 = __toESM(require_dist(), 1);
1450
- import { Crypto } from "@meshsdk/core-cst";
1457
+ import { Crypto as Crypto2 } from "@meshsdk/core-cst";
1451
1458
  async function buildWalletFromPasskey(rawId, password, appSalt = "appSalt") {
1452
1459
  const entropy = await createEntropy(rawId, appSalt);
1453
1460
  return buildKey(Buffer.from(entropy), password);
1454
1461
  }
1455
1462
  function buildKey(entropy, password) {
1456
- const bip32Key = Crypto.Bip32PrivateKey.fromBip39Entropy(entropy, password);
1463
+ const bip32Key = Crypto2.Bip32PrivateKey.fromBip39Entropy(entropy, password);
1457
1464
  const bytes = import_base32_encoding.default.encode(bip32Key.bytes());
1458
1465
  const bech32PrivateKey = import_bech32.bech32.encode("xprv", bytes, 1023);
1459
1466
  return {
@@ -1625,6 +1632,7 @@ import {
1625
1632
  } from "@meshsdk/core-cst";
1626
1633
  import { Transaction as Transaction3 } from "@meshsdk/transaction";
1627
1634
  var MeshWallet = class {
1635
+ _keyType;
1628
1636
  _wallet;
1629
1637
  _accountIndex = 0;
1630
1638
  _keyIndex = 0;
@@ -1634,6 +1642,7 @@ var MeshWallet = class {
1634
1642
  addresses = {};
1635
1643
  constructor(options) {
1636
1644
  this._networkId = options.networkId;
1645
+ this._keyType = options.key.type;
1637
1646
  if (options.fetcher) this._fetcher = options.fetcher;
1638
1647
  if (options.submitter) this._submitter = options.submitter;
1639
1648
  if (options.accountIndex) this._accountIndex = options.accountIndex;
@@ -1647,7 +1656,6 @@ var MeshWallet = class {
1647
1656
  bech32: options.key.bech32
1648
1657
  }
1649
1658
  });
1650
- this.getAddressesFromWallet(this._wallet);
1651
1659
  break;
1652
1660
  case "cli":
1653
1661
  this._wallet = new EmbeddedWallet({
@@ -1658,7 +1666,6 @@ var MeshWallet = class {
1658
1666
  stake: options.key.stake
1659
1667
  }
1660
1668
  });
1661
- this.getAddressesFromWallet(this._wallet);
1662
1669
  break;
1663
1670
  case "mnemonic":
1664
1671
  this._wallet = new EmbeddedWallet({
@@ -1668,7 +1675,6 @@ var MeshWallet = class {
1668
1675
  words: options.key.words
1669
1676
  }
1670
1677
  });
1671
- this.getAddressesFromWallet(this._wallet);
1672
1678
  break;
1673
1679
  case "bip32Bytes":
1674
1680
  this._wallet = new EmbeddedWallet({
@@ -1678,7 +1684,6 @@ var MeshWallet = class {
1678
1684
  bip32Bytes: options.key.bip32Bytes
1679
1685
  }
1680
1686
  });
1681
- this.getAddressesFromWallet(this._wallet);
1682
1687
  break;
1683
1688
  case "address":
1684
1689
  this._wallet = null;
@@ -1686,6 +1691,16 @@ var MeshWallet = class {
1686
1691
  break;
1687
1692
  }
1688
1693
  }
1694
+ /**
1695
+ * Initializes the wallet. This is a required call as fetching addresses from the wallet is an async operation.
1696
+ * @returns void
1697
+ */
1698
+ async init() {
1699
+ if (this._wallet) {
1700
+ await this._wallet.init();
1701
+ this.getAddressesFromWallet(this._wallet);
1702
+ }
1703
+ }
1689
1704
  /**
1690
1705
  * Returns all derived addresses from the wallet.
1691
1706
  * @returns a list of addresses
@@ -1727,7 +1742,7 @@ var MeshWallet = class {
1727
1742
  *
1728
1743
  * @returns an address
1729
1744
  */
1730
- getChangeAddress() {
1745
+ async getChangeAddress() {
1731
1746
  return this.addresses.baseAddressBech32 ? this.addresses.baseAddressBech32 : this.addresses.enterpriseAddressBech32;
1732
1747
  }
1733
1748
  /**
@@ -1807,7 +1822,7 @@ var MeshWallet = class {
1807
1822
  * @returns a list of unused addresses
1808
1823
  */
1809
1824
  async getUnusedAddresses() {
1810
- return [this.getChangeAddress()];
1825
+ return [await this.getChangeAddress()];
1811
1826
  }
1812
1827
  /**
1813
1828
  * Returns a list of used addresses controlled by the wallet.
@@ -1815,7 +1830,7 @@ var MeshWallet = class {
1815
1830
  * @returns a list of used addresses
1816
1831
  */
1817
1832
  async getUsedAddresses() {
1818
- return [this.getChangeAddress()];
1833
+ return [await this.getChangeAddress()];
1819
1834
  }
1820
1835
  /**
1821
1836
  * Get a list of UTXOs to be used for transaction building.
@@ -1852,7 +1867,7 @@ var MeshWallet = class {
1852
1867
  );
1853
1868
  }
1854
1869
  if (address === void 0) {
1855
- address = this.getChangeAddress();
1870
+ address = await this.getChangeAddress();
1856
1871
  }
1857
1872
  return this._wallet.signData(
1858
1873
  address,
@@ -2023,7 +2038,7 @@ var MeshWallet = class {
2023
2038
  */
2024
2039
  async createCollateral() {
2025
2040
  const tx = new Transaction3({ initiator: this });
2026
- tx.sendLovelace(this.getChangeAddress(), "5000000");
2041
+ tx.sendLovelace(await this.getChangeAddress(), "5000000");
2027
2042
  const unsignedTx = await tx.build();
2028
2043
  const signedTx = await this.signTx(unsignedTx);
2029
2044
  const txHash = await this.submitTx(signedTx);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meshsdk/wallet",
3
- "version": "1.9.0-beta.2",
3
+ "version": "1.9.0-beta.4",
4
4
  "description": "Wallets - https://meshjs.dev/apis/wallets",
5
5
  "main": "./dist/index.cjs",
6
6
  "browser": "./dist/index.js",
@@ -35,9 +35,9 @@
35
35
  "typescript": "^5.3.3"
36
36
  },
37
37
  "dependencies": {
38
- "@meshsdk/common": "1.9.0-beta.2",
39
- "@meshsdk/core-cst": "1.9.0-beta.2",
40
- "@meshsdk/transaction": "1.9.0-beta.2",
38
+ "@meshsdk/common": "1.9.0-beta.4",
39
+ "@meshsdk/core-cst": "1.9.0-beta.4",
40
+ "@meshsdk/transaction": "1.9.0-beta.4",
41
41
  "@simplewebauthn/browser": "^13.0.0"
42
42
  },
43
43
  "prettier": "@meshsdk/configs/prettier",