@meshsdk/wallet 1.9.0-beta.3 → 1.9.0-beta.31

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,20 +618,19 @@ 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();
628
+ const dRepIDCip105 = (0, import_core_cst.hexToBech32)("drep", dRepIDHash);
631
629
  return {
632
630
  pubDRepKey,
633
631
  dRepIDBech32,
634
- dRepIDHash
632
+ dRepIDHash,
633
+ dRepIDCip105
635
634
  };
636
635
  }
637
636
  static generateMnemonic(strength = 256) {
@@ -653,40 +652,45 @@ var WalletStaticMethods = class {
653
652
  }
654
653
  };
655
654
  var EmbeddedWallet = class extends WalletStaticMethods {
656
- _entropy;
655
+ _walletSecret;
657
656
  _networkId;
657
+ cryptoIsReady = false;
658
658
  constructor(options) {
659
659
  super();
660
660
  this._networkId = options.networkId;
661
661
  switch (options.key.type) {
662
662
  case "mnemonic":
663
- this._entropy = WalletStaticMethods.mnemonicToEntropy(
663
+ this._walletSecret = WalletStaticMethods.mnemonicToPrivateKeyHex(
664
664
  options.key.words
665
665
  );
666
666
  break;
667
667
  case "root":
668
- this._entropy = WalletStaticMethods.privateKeyToEntropy(
668
+ this._walletSecret = WalletStaticMethods.privateKeyBech32ToPrivateKeyHex(
669
669
  options.key.bech32
670
670
  );
671
671
  break;
672
672
  case "cli":
673
- this._entropy = WalletStaticMethods.signingKeyToEntropy(
673
+ this._walletSecret = WalletStaticMethods.signingKeyToHexes(
674
674
  options.key.payment,
675
675
  options.key.stake ?? "f0".repeat(32)
676
676
  );
677
677
  break;
678
678
  case "bip32Bytes":
679
- this._entropy = WalletStaticMethods.bip32BytesToEntropy(
679
+ this._walletSecret = WalletStaticMethods.bip32BytesToPrivateKeyHex(
680
680
  options.key.bip32Bytes
681
681
  );
682
682
  break;
683
683
  }
684
684
  }
685
+ async init() {
686
+ await import_core_cst.Crypto.ready();
687
+ this.cryptoIsReady = true;
688
+ }
685
689
  getAccount(accountIndex = 0, keyIndex = 0) {
686
- if (this._entropy == void 0)
690
+ if (this._walletSecret == void 0)
687
691
  throw new Error("[EmbeddedWallet] No keys initialized");
688
692
  const { paymentKey, stakeKey, dRepKey } = (0, import_core_cst.buildKeys)(
689
- this._entropy,
693
+ this._walletSecret,
690
694
  accountIndex,
691
695
  keyIndex
692
696
  );
@@ -700,14 +704,15 @@ var EmbeddedWallet = class extends WalletStaticMethods {
700
704
  rewardAddressBech32: rewardAddress.toBech32(),
701
705
  paymentKey,
702
706
  stakeKey,
703
- paymentKeyHex: paymentKey.toBytes().toString("hex"),
704
- stakeKeyHex: stakeKey.toBytes().toString("hex")
707
+ paymentKeyHex: paymentKey.hex(),
708
+ stakeKeyHex: stakeKey.hex()
705
709
  };
706
710
  if (dRepKey) {
707
- const { pubDRepKey, dRepIDBech32, dRepIDHash } = WalletStaticMethods.getDRepKey(dRepKey, this._networkId);
711
+ const { pubDRepKey, dRepIDBech32, dRepIDHash, dRepIDCip105 } = WalletStaticMethods.getDRepKey(dRepKey, this._networkId);
708
712
  _account.pubDRepKey = pubDRepKey;
709
713
  _account.dRepIDBech32 = dRepIDBech32;
710
714
  _account.dRepIDHash = dRepIDHash;
715
+ _account.dRepIDCip105 = dRepIDCip105;
711
716
  }
712
717
  return _account;
713
718
  }
@@ -760,10 +765,8 @@ var EmbeddedWallet = class extends WalletStaticMethods {
760
765
  const txHash = (0, import_core_cst.deserializeTxHash)((0, import_core_cst.resolveTxHash)(unsignedTx));
761
766
  const { paymentKey } = this.getAccount(accountIndex, keyIndex);
762
767
  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
- )
768
+ paymentKey.toPublic().hex(),
769
+ paymentKey.sign((0, import_core_cst.HexBlob)(txHash)).hex()
767
770
  );
768
771
  return vKeyWitness;
769
772
  } catch (error) {
@@ -812,6 +815,15 @@ var AppWallet = class {
812
815
  });
813
816
  }
814
817
  }
818
+ /**
819
+ * Initializes the wallet. This is a required call as fetching addresses from the wallet is an async operation.
820
+ * @returns void
821
+ */
822
+ async init() {
823
+ if (this._wallet) {
824
+ await this._wallet.init();
825
+ }
826
+ }
815
827
  /**
816
828
  * Get a list of UTXOs to be used as collateral inputs for transactions with plutus script inputs.
817
829
  *
@@ -974,7 +986,7 @@ var BrowserWallet = class _BrowserWallet {
974
986
  return wallets;
975
987
  }
976
988
  /**
977
- * This is the entrypoint to start communication with the user's wallet. The wallet should request the user's permission to connect the web page to the user's wallet, and if permission has been granted, the wallet will be returned and exposing the full API for the dApp to use.
989
+ * This is the entrypoint to start communication with the user's wallet. The wallet should request the user's permission to connect the web page to the user's wallet, and if permission has been granted, the wallet will be returned and exposing the full API for the app to use.
978
990
  *
979
991
  * Query BrowserWallet.getInstalledWallets() to get a list of available wallets, then provide the wallet name for which wallet the user would like to connect with.
980
992
  *
@@ -1180,7 +1192,7 @@ var BrowserWallet = class _BrowserWallet {
1180
1192
  /**
1181
1193
  * Submits the signed transaction to the blockchain network.
1182
1194
  *
1183
- * As wallets should already have this ability to submit transaction, we allow dApps to request that a transaction be sent through it. If the wallet accepts the transaction and tries to send it, it shall return the transaction ID for the dApp to track. The wallet can return error messages or failure if there was an error in sending it.
1195
+ * As wallets should already have this ability to submit transaction, we allow apps to request that a transaction be sent through it. If the wallet accepts the transaction and tries to send it, it shall return the transaction ID for the app to track. The wallet can return error messages or failure if there was an error in sending it.
1184
1196
  *
1185
1197
  * @param tx
1186
1198
  * @returns a transaction hash
@@ -1286,19 +1298,18 @@ var BrowserWallet = class _BrowserWallet {
1286
1298
  * The connected wallet account provides the account's public DRep Key, derivation as described in CIP-0105.
1287
1299
  * These are used by the client to identify the user's on-chain CIP-1694 interactions, i.e. if a user has registered to be a DRep.
1288
1300
  *
1289
- * @returns wallet account's public DRep Key
1301
+ * @returns DRep object
1290
1302
  */
1291
1303
  async getDRep() {
1304
+ const pubDRepKey = await this.getPubDRepKey();
1292
1305
  try {
1293
- if (this._walletInstance.cip95 === void 0) return void 0;
1294
- const dRepKey = await this._walletInstance.cip95.getPubDRepKey();
1295
- const { dRepIDHash } = await _BrowserWallet.dRepKeyToDRepID(dRepKey);
1296
- const csldRepIdKeyHash = (0, import_core_cst3.blake2b)(28).update(Buffer.from(dRepKey, "hex")).digest("hex");
1297
- const dRepId = (0, import_core_cst3.hexToBech32)("drep", csldRepIdKeyHash);
1306
+ if (pubDRepKey === void 0) return void 0;
1307
+ const { dRepIDHash } = await _BrowserWallet.dRepKeyToDRepID(pubDRepKey);
1308
+ const dRepIDCip105 = (0, import_core_cst3.hexToBech32)("drep", dRepIDHash);
1298
1309
  return {
1299
- publicKey: dRepKey,
1310
+ publicKey: pubDRepKey,
1300
1311
  publicKeyHash: dRepIDHash,
1301
- dRepIDCip105: dRepId
1312
+ dRepIDCip105
1302
1313
  };
1303
1314
  } catch (e) {
1304
1315
  console.error(e);
@@ -1314,15 +1325,8 @@ var BrowserWallet = class _BrowserWallet {
1314
1325
  async getPubDRepKey() {
1315
1326
  try {
1316
1327
  if (this._walletInstance.cip95 === void 0) return void 0;
1317
- const dRepKey = await this._walletInstance.cip95.getPubDRepKey();
1318
- const { dRepIDHash } = await _BrowserWallet.dRepKeyToDRepID(dRepKey);
1319
- const csldRepIdKeyHash = (0, import_core_cst3.blake2b)(28).update(Buffer.from(dRepKey, "hex")).digest("hex");
1320
- const dRepId = (0, import_core_cst3.hexToBech32)("drep", csldRepIdKeyHash);
1321
- return {
1322
- pubDRepKey: dRepKey,
1323
- dRepIDHash,
1324
- dRepIDBech32: dRepId
1325
- };
1328
+ const pubDRepKey = await this._walletInstance.cip95.getPubDRepKey();
1329
+ return pubDRepKey;
1326
1330
  } catch (e) {
1327
1331
  console.error(e);
1328
1332
  return void 0;
@@ -1381,8 +1385,7 @@ var BrowserWallet = class _BrowserWallet {
1381
1385
  if (window.cardano[walletName] === void 0) return void 0;
1382
1386
  const wallet = window.cardano[walletName];
1383
1387
  if (extensions.length > 0) {
1384
- const _extensions = extensions.map((e) => ({ cip: e }));
1385
- return wallet.enable({ extensions: _extensions });
1388
+ return wallet.enable({ extensions });
1386
1389
  } else {
1387
1390
  return wallet?.enable();
1388
1391
  }
@@ -1578,6 +1581,7 @@ var import_common4 = require("@meshsdk/common");
1578
1581
  var import_core_cst5 = require("@meshsdk/core-cst");
1579
1582
  var import_transaction = require("@meshsdk/transaction");
1580
1583
  var MeshWallet = class {
1584
+ _keyType;
1581
1585
  _wallet;
1582
1586
  _accountIndex = 0;
1583
1587
  _keyIndex = 0;
@@ -1587,6 +1591,7 @@ var MeshWallet = class {
1587
1591
  addresses = {};
1588
1592
  constructor(options) {
1589
1593
  this._networkId = options.networkId;
1594
+ this._keyType = options.key.type;
1590
1595
  if (options.fetcher) this._fetcher = options.fetcher;
1591
1596
  if (options.submitter) this._submitter = options.submitter;
1592
1597
  if (options.accountIndex) this._accountIndex = options.accountIndex;
@@ -1600,7 +1605,6 @@ var MeshWallet = class {
1600
1605
  bech32: options.key.bech32
1601
1606
  }
1602
1607
  });
1603
- this.getAddressesFromWallet(this._wallet);
1604
1608
  break;
1605
1609
  case "cli":
1606
1610
  this._wallet = new EmbeddedWallet({
@@ -1611,7 +1615,6 @@ var MeshWallet = class {
1611
1615
  stake: options.key.stake
1612
1616
  }
1613
1617
  });
1614
- this.getAddressesFromWallet(this._wallet);
1615
1618
  break;
1616
1619
  case "mnemonic":
1617
1620
  this._wallet = new EmbeddedWallet({
@@ -1621,7 +1624,6 @@ var MeshWallet = class {
1621
1624
  words: options.key.words
1622
1625
  }
1623
1626
  });
1624
- this.getAddressesFromWallet(this._wallet);
1625
1627
  break;
1626
1628
  case "bip32Bytes":
1627
1629
  this._wallet = new EmbeddedWallet({
@@ -1631,7 +1633,6 @@ var MeshWallet = class {
1631
1633
  bip32Bytes: options.key.bip32Bytes
1632
1634
  }
1633
1635
  });
1634
- this.getAddressesFromWallet(this._wallet);
1635
1636
  break;
1636
1637
  case "address":
1637
1638
  this._wallet = null;
@@ -1639,6 +1640,16 @@ var MeshWallet = class {
1639
1640
  break;
1640
1641
  }
1641
1642
  }
1643
+ /**
1644
+ * Initializes the wallet. This is a required call as fetching addresses from the wallet is an async operation.
1645
+ * @returns void
1646
+ */
1647
+ async init() {
1648
+ if (this._wallet && !this._wallet.cryptoIsReady) {
1649
+ await this._wallet.init();
1650
+ this.getAddressesFromWallet(this._wallet);
1651
+ }
1652
+ }
1642
1653
  /**
1643
1654
  * Returns all derived addresses from the wallet.
1644
1655
  * @returns a list of addresses
@@ -1654,6 +1665,7 @@ var MeshWallet = class {
1654
1665
  * @returns a list of assets and their quantities
1655
1666
  */
1656
1667
  async getBalance() {
1668
+ await this.init();
1657
1669
  const utxos = await this.getUnspentOutputs();
1658
1670
  const assets = /* @__PURE__ */ new Map();
1659
1671
  utxos.map((utxo) => {
@@ -1680,8 +1692,12 @@ var MeshWallet = class {
1680
1692
  *
1681
1693
  * @returns an address
1682
1694
  */
1683
- getChangeAddress() {
1684
- return this.addresses.baseAddressBech32 ? this.addresses.baseAddressBech32 : this.addresses.enterpriseAddressBech32;
1695
+ async getChangeAddress(addressType = "payment") {
1696
+ await this.init();
1697
+ if (this.addresses.baseAddressBech32 && addressType === "payment") {
1698
+ return this.addresses.baseAddressBech32;
1699
+ }
1700
+ return this.addresses.enterpriseAddressBech32;
1685
1701
  }
1686
1702
  /**
1687
1703
  * 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).
@@ -1692,6 +1708,7 @@ var MeshWallet = class {
1692
1708
  * @returns a list of UTXOs
1693
1709
  */
1694
1710
  async getCollateral(addressType = "payment") {
1711
+ await this.init();
1695
1712
  const utxos = await this.getCollateralUnspentOutput(addressType);
1696
1713
  return utxos.map((utxo, i) => {
1697
1714
  return (0, import_core_cst5.fromTxUnspentOutput)(utxo);
@@ -1714,6 +1731,7 @@ var MeshWallet = class {
1714
1731
  * @returns a list of UTXOs
1715
1732
  */
1716
1733
  async getCollateralUnspentOutput(addressType = "payment") {
1734
+ await this.init();
1717
1735
  const utxos = await this.getUnspentOutputs(addressType);
1718
1736
  const pureAdaUtxos = utxos.filter((utxo) => {
1719
1737
  return utxo.output().amount().multiasset() === void 0;
@@ -1732,10 +1750,16 @@ var MeshWallet = class {
1732
1750
  * The connected wallet account provides the account's public DRep Key, derivation as described in CIP-0105.
1733
1751
  * These are used by the client to identify the user's on-chain CIP-1694 interactions, i.e. if a user has registered to be a DRep.
1734
1752
  *
1735
- * @returns wallet account's public DRep Key
1753
+ * @returns DRep object
1736
1754
  */
1737
1755
  async getDRep() {
1738
- console.warn("Not implemented yet");
1756
+ await this.init();
1757
+ if (this.addresses.pubDRepKey && this.addresses.dRepIDHash && this.addresses.dRepIDCip105)
1758
+ return {
1759
+ publicKey: this.addresses.pubDRepKey,
1760
+ publicKeyHash: this.addresses.dRepIDHash,
1761
+ dRepIDCip105: this.addresses.dRepIDCip105
1762
+ };
1739
1763
  return void 0;
1740
1764
  }
1741
1765
  /**
@@ -1760,7 +1784,7 @@ var MeshWallet = class {
1760
1784
  * @returns a list of unused addresses
1761
1785
  */
1762
1786
  async getUnusedAddresses() {
1763
- return [this.getChangeAddress()];
1787
+ return [await this.getChangeAddress()];
1764
1788
  }
1765
1789
  /**
1766
1790
  * Returns a list of used addresses controlled by the wallet.
@@ -1768,7 +1792,7 @@ var MeshWallet = class {
1768
1792
  * @returns a list of used addresses
1769
1793
  */
1770
1794
  async getUsedAddresses() {
1771
- return [this.getChangeAddress()];
1795
+ return [await this.getChangeAddress()];
1772
1796
  }
1773
1797
  /**
1774
1798
  * Get a list of UTXOs to be used for transaction building.
@@ -1799,13 +1823,14 @@ var MeshWallet = class {
1799
1823
  * @returns a signature
1800
1824
  */
1801
1825
  async signData(payload, address) {
1826
+ await this.init();
1802
1827
  if (!this._wallet) {
1803
1828
  throw new Error(
1804
1829
  "[MeshWallet] Read only wallet does not support signing data."
1805
1830
  );
1806
1831
  }
1807
1832
  if (address === void 0) {
1808
- address = this.getChangeAddress();
1833
+ address = await this.getChangeAddress();
1809
1834
  }
1810
1835
  return this._wallet.signData(
1811
1836
  address,
@@ -1822,6 +1847,7 @@ var MeshWallet = class {
1822
1847
  * @returns a signed transaction in CBOR
1823
1848
  */
1824
1849
  async signTx(unsignedTx, partialSign = false) {
1850
+ await this.init();
1825
1851
  if (!this._wallet) {
1826
1852
  throw new Error(
1827
1853
  "[MeshWallet] Read only wallet does not support signing data."
@@ -1848,6 +1874,7 @@ var MeshWallet = class {
1848
1874
  * @returns array of signed transactions CborHex string
1849
1875
  */
1850
1876
  async signTxs(unsignedTxs, partialSign = false) {
1877
+ await this.init();
1851
1878
  if (!this._wallet) {
1852
1879
  throw new Error(
1853
1880
  "[MeshWallet] Read only wallet does not support signing data."
@@ -1863,7 +1890,7 @@ var MeshWallet = class {
1863
1890
  /**
1864
1891
  * Submits the signed transaction to the blockchain network.
1865
1892
  *
1866
- * As wallets should already have this ability to submit transaction, we allow dApps to request that a transaction be sent through it. If the wallet accepts the transaction and tries to send it, it shall return the transaction ID for the dApp to track. The wallet can return error messages or failure if there was an error in sending it.
1893
+ * As wallets should already have this ability to submit transaction, we allow apps to request that a transaction be sent through it. If the wallet accepts the transaction and tries to send it, it shall return the transaction ID for the app to track. The wallet can return error messages or failure if there was an error in sending it.
1867
1894
  *
1868
1895
  * @param tx - a signed transaction in CBOR
1869
1896
  * @returns a transaction hash
@@ -1976,7 +2003,7 @@ var MeshWallet = class {
1976
2003
  */
1977
2004
  async createCollateral() {
1978
2005
  const tx = new import_transaction.Transaction({ initiator: this });
1979
- tx.sendLovelace(this.getChangeAddress(), "5000000");
2006
+ tx.sendLovelace(await this.getChangeAddress(), "5000000");
1980
2007
  const unsignedTx = await tx.build();
1981
2008
  const signedTx = await this.signTx(unsignedTx);
1982
2009
  const txHash = await this.submitTx(signedTx);
@@ -1986,7 +2013,8 @@ var MeshWallet = class {
1986
2013
  return {
1987
2014
  pubDRepKey: this.addresses.pubDRepKey,
1988
2015
  dRepIDBech32: this.addresses.dRepIDBech32,
1989
- dRepIDHash: this.addresses.dRepIDHash
2016
+ dRepIDHash: this.addresses.dRepIDHash,
2017
+ dRepIDCip105: this.addresses.dRepIDCip105
1990
2018
  };
1991
2019
  }
1992
2020
  /**
@@ -2013,7 +2041,8 @@ var MeshWallet = class {
2013
2041
  rewardAddressBech32: account.rewardAddressBech32,
2014
2042
  pubDRepKey: account.pubDRepKey,
2015
2043
  dRepIDBech32: account.dRepIDBech32,
2016
- dRepIDHash: account.dRepIDHash
2044
+ dRepIDHash: account.dRepIDHash,
2045
+ dRepIDCip105: account.dRepIDCip105
2017
2046
  };
2018
2047
  }
2019
2048
  buildAddressFromBech32Address(address) {
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
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';
1
+ import { DataSignature, IFetcher, ISubmitter, ISigner, IWallet, Wallet, Extension, Asset, UTxO, AssetExtended } from '@meshsdk/common';
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
  *
@@ -107,7 +112,7 @@ declare global {
107
112
  /**
108
113
  * Browser Wallet provides a set of APIs to interact with the blockchain. This wallet is compatible with Mesh transaction builders.
109
114
  *
110
- * These wallets APIs are in accordance to CIP-30, which defines the API for dApps to communicate with the user's wallet. Additional utility functions provided for developers that are useful for building dApps.
115
+ * These wallets APIs are in accordance to CIP-30, which defines the API for apps to communicate with the user's wallet. Additional utility functions provided for developers that are useful for building applications.
111
116
  * ```javascript
112
117
  * import { BrowserWallet } from '@meshsdk/core';
113
118
  *
@@ -140,7 +145,7 @@ declare class BrowserWallet implements IWallet {
140
145
  */
141
146
  static getInstalledWallets(): Wallet[];
142
147
  /**
143
- * This is the entrypoint to start communication with the user's wallet. The wallet should request the user's permission to connect the web page to the user's wallet, and if permission has been granted, the wallet will be returned and exposing the full API for the dApp to use.
148
+ * This is the entrypoint to start communication with the user's wallet. The wallet should request the user's permission to connect the web page to the user's wallet, and if permission has been granted, the wallet will be returned and exposing the full API for the app to use.
144
149
  *
145
150
  * Query BrowserWallet.getInstalledWallets() to get a list of available wallets, then provide the wallet name for which wallet the user would like to connect with.
146
151
  *
@@ -148,7 +153,7 @@ declare class BrowserWallet implements IWallet {
148
153
  * @param extensions - optional, a list of CIPs that the wallet should support
149
154
  * @returns WalletInstance
150
155
  */
151
- static enable(walletName: string, extensions?: number[]): Promise<BrowserWallet>;
156
+ static enable(walletName: string, extensions?: Extension[]): Promise<BrowserWallet>;
152
157
  /**
153
158
  * Returns a list of assets in the wallet. This API will return every assets in the wallet. Each asset is an object with the following properties:
154
159
  * - A unit is provided to display asset's name on the user interface.
@@ -235,7 +240,7 @@ declare class BrowserWallet implements IWallet {
235
240
  /**
236
241
  * Submits the signed transaction to the blockchain network.
237
242
  *
238
- * As wallets should already have this ability to submit transaction, we allow dApps to request that a transaction be sent through it. If the wallet accepts the transaction and tries to send it, it shall return the transaction ID for the dApp to track. The wallet can return error messages or failure if there was an error in sending it.
243
+ * As wallets should already have this ability to submit transaction, we allow apps to request that a transaction be sent through it. If the wallet accepts the transaction and tries to send it, it shall return the transaction ID for the app to track. The wallet can return error messages or failure if there was an error in sending it.
239
244
  *
240
245
  * @param tx
241
246
  * @returns a transaction hash
@@ -294,7 +299,7 @@ declare class BrowserWallet implements IWallet {
294
299
  * The connected wallet account provides the account's public DRep Key, derivation as described in CIP-0105.
295
300
  * These are used by the client to identify the user's on-chain CIP-1694 interactions, i.e. if a user has registered to be a DRep.
296
301
  *
297
- * @returns wallet account's public DRep Key
302
+ * @returns DRep object
298
303
  */
299
304
  getDRep(): Promise<{
300
305
  publicKey: string;
@@ -307,11 +312,7 @@ declare class BrowserWallet implements IWallet {
307
312
  *
308
313
  * @returns wallet account's public DRep Key
309
314
  */
310
- getPubDRepKey(): Promise<{
311
- pubDRepKey: string;
312
- dRepIDHash: string;
313
- dRepIDBech32: string;
314
- } | undefined>;
315
+ getPubDRepKey(): Promise<string | undefined>;
315
316
  getRegisteredPubStakeKeys(): Promise<{
316
317
  pubStakeKeys: string[];
317
318
  pubStakeKeyHashes: string[];
@@ -384,13 +385,14 @@ type Account = {
384
385
  baseAddressBech32: string;
385
386
  enterpriseAddressBech32: string;
386
387
  rewardAddressBech32: string;
387
- paymentKey: StricaPrivateKey;
388
- stakeKey: StricaPrivateKey;
388
+ paymentKey: Ed25519PrivateKey;
389
+ stakeKey: Ed25519PrivateKey;
389
390
  paymentKeyHex: string;
390
391
  stakeKeyHex: string;
391
392
  pubDRepKey?: string;
392
393
  dRepIDBech32?: DRepID;
393
394
  dRepIDHash?: Ed25519KeyHashHex;
395
+ dRepIDCip105?: string;
394
396
  };
395
397
  type EmbeddedWalletKeyType = {
396
398
  type: "root";
@@ -411,27 +413,30 @@ type CreateEmbeddedWalletOptions = {
411
413
  key: EmbeddedWalletKeyType;
412
414
  };
413
415
  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): {
416
+ static privateKeyBech32ToPrivateKeyHex(_bech32: string): string;
417
+ static mnemonicToPrivateKeyHex(words: string[]): string;
418
+ static signingKeyToHexes(paymentKey: string, stakeKey: string): [string, string];
419
+ static bip32BytesToPrivateKeyHex(bip32Bytes: Uint8Array): string;
420
+ static getAddresses(paymentKey: Ed25519PrivateKey, stakingKey: Ed25519PrivateKey, networkId?: number): {
419
421
  baseAddress: Address;
420
422
  enterpriseAddress: Address;
421
423
  rewardAddress: Address;
422
424
  };
423
- static getDRepKey(dRepKey: StricaPrivateKey, networkId?: number): {
425
+ static getDRepKey(dRepKey: Ed25519PrivateKey, networkId?: number): {
424
426
  pubDRepKey: string;
425
427
  dRepIDBech32: DRepID;
426
428
  dRepIDHash: Ed25519KeyHashHex;
429
+ dRepIDCip105: string;
427
430
  };
428
431
  static generateMnemonic(strength?: number): string[];
429
432
  static addWitnessSets(txHex: string, witnesses: VkeyWitness[]): string;
430
433
  }
431
434
  declare class EmbeddedWallet extends WalletStaticMethods {
432
- private readonly _entropy?;
435
+ private readonly _walletSecret?;
433
436
  private readonly _networkId;
437
+ cryptoIsReady: boolean;
434
438
  constructor(options: CreateEmbeddedWalletOptions);
439
+ init(): Promise<void>;
435
440
  getAccount(accountIndex?: number, keyIndex?: number): Account;
436
441
  /**
437
442
  * Get wallet network ID.
@@ -495,20 +500,23 @@ type CreateMeshWalletOptions = {
495
500
  * ```javascript
496
501
  * import { MeshWallet, BlockfrostProvider } from '@meshsdk/core';
497
502
  *
498
- * const blockchainProvider = new BlockfrostProvider('<BLOCKFROST_API_KEY>');
503
+ * const provider = new BlockfrostProvider('<BLOCKFROST_API_KEY>');
499
504
  *
500
505
  * const wallet = new MeshWallet({
501
506
  * networkId: 0,
502
- * fetcher: blockchainProvider,
503
- * submitter: blockchainProvider,
507
+ * fetcher: provider,
508
+ * submitter: provider,
504
509
  * key: {
505
510
  * type: 'mnemonic',
506
511
  * words: ["solution","solution","solution","solution","solution",","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution"],
507
512
  * },
508
513
  * });
509
514
  * ```
515
+ *
516
+ * Please call `await wallet.init()` after creating the wallet to fetch the addresses from the wallet.
510
517
  */
511
518
  declare class MeshWallet implements IWallet {
519
+ private readonly _keyType;
512
520
  private readonly _wallet;
513
521
  private readonly _accountIndex;
514
522
  private readonly _keyIndex;
@@ -525,8 +533,14 @@ declare class MeshWallet implements IWallet {
525
533
  pubDRepKey?: string;
526
534
  dRepIDBech32?: DRepID;
527
535
  dRepIDHash?: Ed25519KeyHashHex;
536
+ dRepIDCip105?: string;
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
@@ -541,6 +555,7 @@ declare class MeshWallet implements IWallet {
541
555
  pubDRepKey?: string;
542
556
  dRepIDBech32?: DRepID;
543
557
  dRepIDHash?: Ed25519KeyHashHex;
558
+ dRepIDCip105?: string;
544
559
  };
545
560
  /**
546
561
  * Returns a list of assets in the wallet. This API will return every assets in the wallet. Each asset is an object with the following properties:
@@ -555,7 +570,7 @@ declare class MeshWallet implements IWallet {
555
570
  *
556
571
  * @returns an address
557
572
  */
558
- getChangeAddress(): string;
573
+ getChangeAddress(addressType?: GetAddressType): Promise<string>;
559
574
  /**
560
575
  * 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
576
  *
@@ -584,7 +599,7 @@ declare class MeshWallet implements IWallet {
584
599
  * The connected wallet account provides the account's public DRep Key, derivation as described in CIP-0105.
585
600
  * These are used by the client to identify the user's on-chain CIP-1694 interactions, i.e. if a user has registered to be a DRep.
586
601
  *
587
- * @returns wallet account's public DRep Key
602
+ * @returns DRep object
588
603
  */
589
604
  getDRep(): Promise<{
590
605
  publicKey: string;
@@ -658,7 +673,7 @@ declare class MeshWallet implements IWallet {
658
673
  /**
659
674
  * Submits the signed transaction to the blockchain network.
660
675
  *
661
- * As wallets should already have this ability to submit transaction, we allow dApps to request that a transaction be sent through it. If the wallet accepts the transaction and tries to send it, it shall return the transaction ID for the dApp to track. The wallet can return error messages or failure if there was an error in sending it.
676
+ * As wallets should already have this ability to submit transaction, we allow apps to request that a transaction be sent through it. If the wallet accepts the transaction and tries to send it, it shall return the transaction ID for the app to track. The wallet can return error messages or failure if there was an error in sending it.
662
677
  *
663
678
  * @param tx - a signed transaction in CBOR
664
679
  * @returns a transaction hash
@@ -725,6 +740,7 @@ declare class MeshWallet implements IWallet {
725
740
  pubDRepKey: string | undefined;
726
741
  dRepIDBech32: string | undefined;
727
742
  dRepIDHash: string | undefined;
743
+ dRepIDCip105: string | undefined;
728
744
  };
729
745
  /**
730
746
  * Generate mnemonic or private key