@meshsdk/wallet 1.9.0-beta.10 → 1.9.0-beta.101

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.js CHANGED
@@ -287,8 +287,11 @@ var require_dist = __commonJS({
287
287
  // src/app/index.ts
288
288
  import {
289
289
  deserializeTx as deserializeTx2,
290
+ Serialization as Serialization2,
290
291
  toAddress,
291
- toTxUnspentOutput
292
+ toTxUnspentOutput,
293
+ TransactionWitnessSet,
294
+ VkeyWitness as VkeyWitness2
292
295
  } from "@meshsdk/core-cst";
293
296
 
294
297
  // ../../node_modules/@scure/base/lib/esm/index.js
@@ -551,7 +554,6 @@ var bech32 = /* @__PURE__ */ genBech32("bech32");
551
554
 
552
555
  // src/embedded/index.ts
553
556
  import {
554
- bytesToHex,
555
557
  generateMnemonic,
556
558
  mnemonicToEntropy
557
559
  } from "@meshsdk/common";
@@ -571,6 +573,7 @@ import {
571
573
  Ed25519PublicKeyHex,
572
574
  Hash28ByteBase16,
573
575
  HexBlob,
576
+ hexToBech32,
574
577
  resolveTxHash,
575
578
  Serialization,
576
579
  signData,
@@ -581,12 +584,12 @@ var WalletStaticMethods = class {
581
584
  static privateKeyBech32ToPrivateKeyHex(_bech32) {
582
585
  const bech32DecodedBytes = bech32.decodeToBytes(_bech32).bytes;
583
586
  const bip32PrivateKey = Bip32PrivateKey.fromBytes(bech32DecodedBytes);
584
- return bytesToHex(bip32PrivateKey.bytes());
587
+ return bip32PrivateKey.hex();
585
588
  }
586
589
  static mnemonicToPrivateKeyHex(words) {
587
590
  const entropy = mnemonicToEntropy(words.join(" "));
588
591
  const bip32PrivateKey = buildBip32PrivateKey(entropy);
589
- return bytesToHex(bip32PrivateKey.bytes());
592
+ return bip32PrivateKey.hex();
590
593
  }
591
594
  static signingKeyToHexes(paymentKey, stakeKey) {
592
595
  return [
@@ -596,29 +599,21 @@ var WalletStaticMethods = class {
596
599
  }
597
600
  static bip32BytesToPrivateKeyHex(bip32Bytes) {
598
601
  const bip32PrivateKey = Bip32PrivateKey.fromBytes(bip32Bytes);
599
- return bytesToHex(bip32PrivateKey.bytes());
602
+ return bip32PrivateKey.hex();
600
603
  }
601
604
  static getAddresses(paymentKey, stakingKey, networkId = 0) {
602
605
  const baseAddress = buildBaseAddress(
603
606
  networkId,
604
- Hash28ByteBase16.fromEd25519KeyHashHex(
605
- paymentKey.toPublic().hash().hex()
606
- ),
607
- Hash28ByteBase16.fromEd25519KeyHashHex(
608
- stakingKey.toPublic().hash().hex()
609
- )
607
+ Hash28ByteBase16(paymentKey.toPublic().hash().hex()),
608
+ Hash28ByteBase16(stakingKey.toPublic().hash().hex())
610
609
  ).toAddress();
611
610
  const enterpriseAddress = buildEnterpriseAddress(
612
611
  networkId,
613
- Hash28ByteBase16.fromEd25519KeyHashHex(
614
- paymentKey.toPublic().hash().hex()
615
- )
612
+ Hash28ByteBase16(paymentKey.toPublic().hash().hex())
616
613
  ).toAddress();
617
614
  const rewardAddress = buildRewardAddress(
618
615
  networkId,
619
- Hash28ByteBase16.fromEd25519KeyHashHex(
620
- stakingKey.toPublic().hash().hex()
621
- )
616
+ Hash28ByteBase16(stakingKey.toPublic().hash().hex())
622
617
  ).toAddress();
623
618
  return {
624
619
  baseAddress,
@@ -627,17 +622,19 @@ var WalletStaticMethods = class {
627
622
  };
628
623
  }
629
624
  static getDRepKey(dRepKey, networkId = 0) {
630
- const pubDRepKey = dRepKey.toPublic().hex().toString();
625
+ const pubDRepKey = dRepKey.toPublic().hex();
631
626
  const dRepIDBech32 = buildDRepID(
632
627
  Ed25519PublicKeyHex(pubDRepKey),
633
628
  networkId
634
629
  );
635
630
  const dRep = DRep.newKeyHash(dRepKey.toPublic().hash().hex());
636
631
  const dRepIDHash = dRep.toKeyHash();
632
+ const dRepIDCip105 = hexToBech32("drep", dRepIDHash);
637
633
  return {
638
634
  pubDRepKey,
639
635
  dRepIDBech32,
640
- dRepIDHash
636
+ dRepIDHash,
637
+ dRepIDCip105
641
638
  };
642
639
  }
643
640
  static generateMnemonic(strength = 256) {
@@ -661,6 +658,7 @@ var WalletStaticMethods = class {
661
658
  var EmbeddedWallet = class extends WalletStaticMethods {
662
659
  _walletSecret;
663
660
  _networkId;
661
+ cryptoIsReady = false;
664
662
  constructor(options) {
665
663
  super();
666
664
  this._networkId = options.networkId;
@@ -690,6 +688,7 @@ var EmbeddedWallet = class extends WalletStaticMethods {
690
688
  }
691
689
  async init() {
692
690
  await Crypto.ready();
691
+ this.cryptoIsReady = true;
693
692
  }
694
693
  getAccount(accountIndex = 0, keyIndex = 0) {
695
694
  if (this._walletSecret == void 0)
@@ -713,10 +712,12 @@ var EmbeddedWallet = class extends WalletStaticMethods {
713
712
  stakeKeyHex: stakeKey.hex()
714
713
  };
715
714
  if (dRepKey) {
716
- const { pubDRepKey, dRepIDBech32, dRepIDHash } = WalletStaticMethods.getDRepKey(dRepKey, this._networkId);
715
+ const { pubDRepKey, dRepIDBech32, dRepIDHash, dRepIDCip105 } = WalletStaticMethods.getDRepKey(dRepKey, this._networkId);
716
+ _account.drepKey = dRepKey;
717
717
  _account.pubDRepKey = pubDRepKey;
718
718
  _account.dRepIDBech32 = dRepIDBech32;
719
719
  _account.dRepIDHash = dRepIDHash;
720
+ _account.dRepIDCip105 = dRepIDCip105;
720
721
  }
721
722
  return _account;
722
723
  }
@@ -738,7 +739,13 @@ var EmbeddedWallet = class extends WalletStaticMethods {
738
739
  */
739
740
  signData(address, payload, accountIndex = 0, keyIndex = 0) {
740
741
  try {
741
- const { baseAddress, enterpriseAddress, rewardAddress, paymentKey } = this.getAccount(accountIndex, keyIndex);
742
+ const {
743
+ baseAddress,
744
+ enterpriseAddress,
745
+ rewardAddress,
746
+ paymentKey,
747
+ stakeKey
748
+ } = this.getAccount(accountIndex, keyIndex);
742
749
  const foundAddress = [baseAddress, enterpriseAddress, rewardAddress].find(
743
750
  (a) => a.toBech32() === address
744
751
  );
@@ -748,7 +755,7 @@ var EmbeddedWallet = class extends WalletStaticMethods {
748
755
  );
749
756
  return signData(payload, {
750
757
  address: Address.fromBech32(address),
751
- key: paymentKey
758
+ key: address === rewardAddress.toBech32() ? stakeKey : paymentKey
752
759
  });
753
760
  } catch (error) {
754
761
  throw new Error(
@@ -762,15 +769,26 @@ var EmbeddedWallet = class extends WalletStaticMethods {
762
769
  * @param unsignedTx - a transaction in CBOR
763
770
  * @param accountIndex account index (default: 0)
764
771
  * @param keyIndex key index (default: 0)
772
+ * @param accountType - type of the account (default: payment)
765
773
  * @returns VkeyWitness
766
774
  */
767
- signTx(unsignedTx, accountIndex = 0, keyIndex = 0) {
775
+ signTx(unsignedTx, accountIndex = 0, keyIndex = 0, accountType = "payment") {
768
776
  try {
769
777
  const txHash = deserializeTxHash(resolveTxHash(unsignedTx));
770
- const { paymentKey } = this.getAccount(accountIndex, keyIndex);
778
+ const { paymentKey, stakeKey, drepKey } = this.getAccount(
779
+ accountIndex,
780
+ keyIndex
781
+ );
782
+ let key = paymentKey;
783
+ if (accountType === "stake") {
784
+ key = stakeKey;
785
+ } else if (accountType === "drep") {
786
+ if (!drepKey) throw new Error("DRep key not found");
787
+ key = drepKey;
788
+ }
771
789
  const vKeyWitness = new VkeyWitness(
772
- paymentKey.toPublic().hex(),
773
- paymentKey.sign(HexBlob(txHash)).hex()
790
+ key.toPublic().hex(),
791
+ key.sign(HexBlob(txHash)).hex()
774
792
  );
775
793
  return vKeyWitness;
776
794
  } catch (error) {
@@ -893,7 +911,7 @@ var AppWallet = class {
893
911
  );
894
912
  }
895
913
  }
896
- async signTx(unsignedTx, partialSign = false, accountIndex = 0, keyIndex = 0) {
914
+ async signTx(unsignedTx, partialSign = false, returnFullTx = true, accountIndex = 0, keyIndex = 0) {
897
915
  try {
898
916
  const tx = deserializeTx2(unsignedTx);
899
917
  if (!partialSign && tx.witnessSet().vkeys() !== void 0 && tx.witnessSet().vkeys().size() !== 0)
@@ -905,6 +923,16 @@ var AppWallet = class {
905
923
  accountIndex,
906
924
  keyIndex
907
925
  );
926
+ if (!returnFullTx) {
927
+ let witnessSet = new TransactionWitnessSet();
928
+ witnessSet.setVkeys(
929
+ Serialization2.CborSet.fromCore(
930
+ [newSignatures.toCore()],
931
+ VkeyWitness2.fromCore
932
+ )
933
+ );
934
+ return witnessSet.toCbor();
935
+ }
908
936
  let signedTx = EmbeddedWallet.addWitnessSets(unsignedTx, [newSignatures]);
909
937
  return signedTx;
910
938
  } catch (error) {
@@ -943,7 +971,6 @@ import {
943
971
  } from "@meshsdk/common";
944
972
  import {
945
973
  addressToBech32,
946
- blake2b,
947
974
  CardanoSDKUtil,
948
975
  deserializeAddress,
949
976
  deserializeTx as deserializeTx3,
@@ -953,11 +980,11 @@ import {
953
980
  Ed25519PublicKeyHex as Ed25519PublicKeyHex2,
954
981
  fromTxUnspentOutput,
955
982
  fromValue,
956
- hexToBech32,
957
- Serialization as Serialization2,
983
+ hexToBech32 as hexToBech322,
984
+ Serialization as Serialization3,
958
985
  toAddress as toAddress2,
959
986
  Transaction as Transaction2,
960
- VkeyWitness as VkeyWitness2
987
+ VkeyWitness as VkeyWitness3
961
988
  } from "@meshsdk/core-cst";
962
989
  var BrowserWallet = class _BrowserWallet {
963
990
  constructor(_walletInstance, _walletName) {
@@ -1012,7 +1039,7 @@ var BrowserWallet = class _BrowserWallet {
1012
1039
  return wallets;
1013
1040
  }
1014
1041
  /**
1015
- * 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.
1042
+ * 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.
1016
1043
  *
1017
1044
  * 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.
1018
1045
  *
@@ -1135,31 +1162,36 @@ var BrowserWallet = class _BrowserWallet {
1135
1162
  * @param address - optional, if not provided, the first staking address will be used
1136
1163
  * @returns a signature
1137
1164
  */
1138
- async signData(payload, address) {
1165
+ async signData(payload, address, convertFromUTF8 = true) {
1139
1166
  if (address === void 0) {
1140
1167
  address = (await this.getUsedAddresses())[0];
1141
1168
  if (address === void 0) {
1142
1169
  address = await this.getChangeAddress();
1143
1170
  }
1144
1171
  }
1172
+ const _payload = convertFromUTF8 ? fromUTF8(payload) : payload;
1145
1173
  if (address.startsWith("drep1")) {
1146
- return this._walletInstance.cip95.signData(address, fromUTF8(payload));
1174
+ return this._walletInstance.cip95.signData(address, _payload);
1147
1175
  }
1148
1176
  const signerAddress = toAddress2(address).toBytes().toString();
1149
- return this._walletInstance.signData(signerAddress, fromUTF8(payload));
1177
+ return this._walletInstance.signData(signerAddress, _payload);
1150
1178
  }
1151
1179
  /**
1152
1180
  * Requests user to sign the provided transaction (tx). The wallet should ask the user for permission, and if given, try to sign the supplied body and return a signed transaction. partialSign should be true if the transaction provided requires multiple signatures.
1153
1181
  *
1154
1182
  * @param unsignedTx - a transaction in CBOR
1155
1183
  * @param partialSign - if the transaction is signed partially
1184
+ * @param returnFullTx - if the full tx should be returned or only the witness set (default: true)
1156
1185
  * @returns a signed transaction in CBOR
1157
1186
  */
1158
- async signTx(unsignedTx, partialSign = false) {
1187
+ async signTx(unsignedTx, partialSign = false, returnFullTx = true) {
1159
1188
  const witness = await this._walletInstance.signTx(unsignedTx, partialSign);
1160
1189
  if (witness === "") {
1161
1190
  return unsignedTx;
1162
1191
  }
1192
+ if (!returnFullTx) {
1193
+ return witness;
1194
+ }
1163
1195
  return _BrowserWallet.addBrowserWitnesses(unsignedTx, witness);
1164
1196
  }
1165
1197
  /**
@@ -1218,7 +1250,7 @@ var BrowserWallet = class _BrowserWallet {
1218
1250
  /**
1219
1251
  * Submits the signed transaction to the blockchain network.
1220
1252
  *
1221
- * 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.
1253
+ * 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.
1222
1254
  *
1223
1255
  * @param tx
1224
1256
  * @returns a transaction hash
@@ -1324,19 +1356,18 @@ var BrowserWallet = class _BrowserWallet {
1324
1356
  * The connected wallet account provides the account's public DRep Key, derivation as described in CIP-0105.
1325
1357
  * 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.
1326
1358
  *
1327
- * @returns wallet account's public DRep Key
1359
+ * @returns DRep object
1328
1360
  */
1329
1361
  async getDRep() {
1362
+ const pubDRepKey = await this.getPubDRepKey();
1330
1363
  try {
1331
- if (this._walletInstance.cip95 === void 0) return void 0;
1332
- const dRepKey = await this._walletInstance.cip95.getPubDRepKey();
1333
- const { dRepIDHash } = await _BrowserWallet.dRepKeyToDRepID(dRepKey);
1334
- const csldRepIdKeyHash = blake2b(28).update(Buffer.from(dRepKey, "hex")).digest("hex");
1335
- const dRepId = hexToBech32("drep", csldRepIdKeyHash);
1364
+ if (pubDRepKey === void 0) return void 0;
1365
+ const { dRepIDHash } = await _BrowserWallet.dRepKeyToDRepID(pubDRepKey);
1366
+ const dRepIDCip105 = hexToBech322("drep", dRepIDHash);
1336
1367
  return {
1337
- publicKey: dRepKey,
1368
+ publicKey: pubDRepKey,
1338
1369
  publicKeyHash: dRepIDHash,
1339
- dRepIDCip105: dRepId
1370
+ dRepIDCip105
1340
1371
  };
1341
1372
  } catch (e) {
1342
1373
  console.error(e);
@@ -1352,15 +1383,8 @@ var BrowserWallet = class _BrowserWallet {
1352
1383
  async getPubDRepKey() {
1353
1384
  try {
1354
1385
  if (this._walletInstance.cip95 === void 0) return void 0;
1355
- const dRepKey = await this._walletInstance.cip95.getPubDRepKey();
1356
- const { dRepIDHash } = await _BrowserWallet.dRepKeyToDRepID(dRepKey);
1357
- const csldRepIdKeyHash = blake2b(28).update(Buffer.from(dRepKey, "hex")).digest("hex");
1358
- const dRepId = hexToBech32("drep", csldRepIdKeyHash);
1359
- return {
1360
- pubDRepKey: dRepKey,
1361
- dRepIDHash,
1362
- dRepIDBech32: dRepId
1363
- };
1386
+ const pubDRepKey = await this._walletInstance.cip95.getPubDRepKey();
1387
+ return pubDRepKey;
1364
1388
  } catch (e) {
1365
1389
  console.error(e);
1366
1390
  return void 0;
@@ -1419,14 +1443,13 @@ var BrowserWallet = class _BrowserWallet {
1419
1443
  if (window.cardano[walletName] === void 0) return void 0;
1420
1444
  const wallet = window.cardano[walletName];
1421
1445
  if (extensions.length > 0) {
1422
- const _extensions = extensions.map((e) => ({ cip: e }));
1423
- return wallet.enable({ extensions: _extensions });
1446
+ return wallet.enable({ extensions });
1424
1447
  } else {
1425
1448
  return wallet?.enable();
1426
1449
  }
1427
1450
  }
1428
1451
  static addBrowserWitnesses(unsignedTx, witnesses) {
1429
- const cWitness = Serialization2.TransactionWitnessSet.fromCbor(
1452
+ const cWitness = Serialization3.TransactionWitnessSet.fromCbor(
1430
1453
  CardanoSDKUtil.HexBlob(witnesses)
1431
1454
  ).vkeys()?.values();
1432
1455
  if (cWitness === void 0) {
@@ -1437,9 +1460,9 @@ var BrowserWallet = class _BrowserWallet {
1437
1460
  let witnessSetVkeys = witnessSet.vkeys();
1438
1461
  let witnessSetVkeysValues = witnessSetVkeys ? [...witnessSetVkeys.values(), ...cWitness] : [...cWitness];
1439
1462
  witnessSet.setVkeys(
1440
- Serialization2.CborSet.fromCore(
1463
+ Serialization3.CborSet.fromCore(
1441
1464
  witnessSetVkeysValues.map((vkw) => vkw.toCore()),
1442
- VkeyWitness2.fromCore
1465
+ VkeyWitness3.fromCore
1443
1466
  )
1444
1467
  );
1445
1468
  return new Transaction2(tx.body(), witnessSet, tx.auxiliaryData()).toCbor();
@@ -1627,12 +1650,16 @@ import {
1627
1650
  fromTxUnspentOutput as fromTxUnspentOutput2,
1628
1651
  Hash28ByteBase16 as Hash28ByteBase162,
1629
1652
  resolvePrivateKey,
1653
+ Serialization as Serialization4,
1630
1654
  toAddress as toAddress3,
1631
- toTxUnspentOutput as toTxUnspentOutput2
1655
+ toTxUnspentOutput as toTxUnspentOutput2,
1656
+ TransactionWitnessSet as TransactionWitnessSet2,
1657
+ VkeyWitness as VkeyWitness4
1632
1658
  } from "@meshsdk/core-cst";
1633
1659
  import { Transaction as Transaction3 } from "@meshsdk/transaction";
1634
1660
  var MeshWallet = class {
1635
1661
  _keyType;
1662
+ _accountType = "payment";
1636
1663
  _wallet;
1637
1664
  _accountIndex = 0;
1638
1665
  _keyIndex = 0;
@@ -1647,6 +1674,7 @@ var MeshWallet = class {
1647
1674
  if (options.submitter) this._submitter = options.submitter;
1648
1675
  if (options.accountIndex) this._accountIndex = options.accountIndex;
1649
1676
  if (options.keyIndex) this._keyIndex = options.keyIndex;
1677
+ if (options.accountType) this._accountType = options.accountType;
1650
1678
  switch (options.key.type) {
1651
1679
  case "root":
1652
1680
  this._wallet = new EmbeddedWallet({
@@ -1696,7 +1724,7 @@ var MeshWallet = class {
1696
1724
  * @returns void
1697
1725
  */
1698
1726
  async init() {
1699
- if (this._wallet) {
1727
+ if (this._wallet && !this._wallet.cryptoIsReady) {
1700
1728
  await this._wallet.init();
1701
1729
  this.getAddressesFromWallet(this._wallet);
1702
1730
  }
@@ -1716,6 +1744,7 @@ var MeshWallet = class {
1716
1744
  * @returns a list of assets and their quantities
1717
1745
  */
1718
1746
  async getBalance() {
1747
+ await this.init();
1719
1748
  const utxos = await this.getUnspentOutputs();
1720
1749
  const assets = /* @__PURE__ */ new Map();
1721
1750
  utxos.map((utxo) => {
@@ -1742,8 +1771,24 @@ var MeshWallet = class {
1742
1771
  *
1743
1772
  * @returns an address
1744
1773
  */
1745
- async getChangeAddress() {
1746
- return this.addresses.baseAddressBech32 ? this.addresses.baseAddressBech32 : this.addresses.enterpriseAddressBech32;
1774
+ async getChangeAddress(addressType = "payment") {
1775
+ await this.init();
1776
+ if (this.addresses.baseAddressBech32 && addressType === "payment") {
1777
+ return this.addresses.baseAddressBech32;
1778
+ }
1779
+ return this.addresses.enterpriseAddressBech32;
1780
+ }
1781
+ /**
1782
+ * Returns an address owned by the wallet that should be used as a change address to return leftover assets during transaction creation back to the connected wallet in hex format.
1783
+ *
1784
+ * @returns an address in hex format
1785
+ */
1786
+ async getChangeAddressHex(addressType = "payment") {
1787
+ await this.init();
1788
+ if (this.addresses.baseAddress && addressType === "payment") {
1789
+ return this.addresses.baseAddress.toBytes().toString();
1790
+ }
1791
+ return this.addresses.enterpriseAddress.toBytes().toString();
1747
1792
  }
1748
1793
  /**
1749
1794
  * 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).
@@ -1754,11 +1799,27 @@ var MeshWallet = class {
1754
1799
  * @returns a list of UTXOs
1755
1800
  */
1756
1801
  async getCollateral(addressType = "payment") {
1802
+ await this.init();
1757
1803
  const utxos = await this.getCollateralUnspentOutput(addressType);
1758
1804
  return utxos.map((utxo, i) => {
1759
1805
  return fromTxUnspentOutput2(utxo);
1760
1806
  });
1761
1807
  }
1808
+ /**
1809
+ * 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).
1810
+ *
1811
+ * If this cannot be attained, an error message with an explanation of the blocking problem shall be returned. NOTE: wallets are free to return UTXOs that add up to a greater total ADA value than requested in the amount parameter, but wallets must never return any result where UTXOs would sum up to a smaller total ADA value, instead in a case like that an error message must be returned.
1812
+ *
1813
+ * @param addressType - the type of address to fetch UTXOs from (default: payment)
1814
+ * @returns a list of UTXOs in hex format
1815
+ */
1816
+ async getCollateralHex(addressType = "payment") {
1817
+ await this.init();
1818
+ const utxos = await this.getCollateralUnspentOutput(addressType);
1819
+ return utxos.map((utxo) => {
1820
+ return utxo.toCbor().toString();
1821
+ });
1822
+ }
1762
1823
  /**
1763
1824
  * Return a list of supported CIPs of the wallet.
1764
1825
  *
@@ -1776,6 +1837,7 @@ var MeshWallet = class {
1776
1837
  * @returns a list of UTXOs
1777
1838
  */
1778
1839
  async getCollateralUnspentOutput(addressType = "payment") {
1840
+ await this.init();
1779
1841
  const utxos = await this.getUnspentOutputs(addressType);
1780
1842
  const pureAdaUtxos = utxos.filter((utxo) => {
1781
1843
  return utxo.output().amount().multiasset() === void 0;
@@ -1794,10 +1856,16 @@ var MeshWallet = class {
1794
1856
  * The connected wallet account provides the account's public DRep Key, derivation as described in CIP-0105.
1795
1857
  * 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.
1796
1858
  *
1797
- * @returns wallet account's public DRep Key
1859
+ * @returns DRep object
1798
1860
  */
1799
1861
  async getDRep() {
1800
- console.warn("Not implemented yet");
1862
+ await this.init();
1863
+ if (this.addresses.pubDRepKey && this.addresses.dRepIDHash && this.addresses.dRepIDCip105)
1864
+ return {
1865
+ publicKey: this.addresses.pubDRepKey,
1866
+ publicKeyHash: this.addresses.dRepIDHash,
1867
+ dRepIDCip105: this.addresses.dRepIDCip105
1868
+ };
1801
1869
  return void 0;
1802
1870
  }
1803
1871
  /**
@@ -1816,6 +1884,13 @@ var MeshWallet = class {
1816
1884
  async getRewardAddresses() {
1817
1885
  return [this.addresses.rewardAddressBech32];
1818
1886
  }
1887
+ /**
1888
+ * Returns a list of reward addresses owned by the wallet. A reward address is a stake address that is used to receive rewards from staking.
1889
+ * @returns a list of reward addresses in hex format
1890
+ */
1891
+ async getRewardAddressesHex() {
1892
+ return [this.addresses.rewardAddress.toBytes().toString()];
1893
+ }
1819
1894
  /**
1820
1895
  * Returns a list of unused addresses controlled by the wallet.
1821
1896
  *
@@ -1824,6 +1899,14 @@ var MeshWallet = class {
1824
1899
  async getUnusedAddresses() {
1825
1900
  return [await this.getChangeAddress()];
1826
1901
  }
1902
+ /**
1903
+ * Returns a list of unused addresses controlled by the wallet.
1904
+ *
1905
+ * @returns a list of unused addresses in hex format
1906
+ */
1907
+ async getUnusedAddressesHex() {
1908
+ return [await this.getChangeAddressHex()];
1909
+ }
1827
1910
  /**
1828
1911
  * Returns a list of used addresses controlled by the wallet.
1829
1912
  *
@@ -1832,6 +1915,14 @@ var MeshWallet = class {
1832
1915
  async getUsedAddresses() {
1833
1916
  return [await this.getChangeAddress()];
1834
1917
  }
1918
+ /**
1919
+ * Returns a list of used addresses controlled by the wallet.
1920
+ *
1921
+ * @returns a list of used addresses in hex format
1922
+ */
1923
+ async getUsedAddressesHex() {
1924
+ return [await this.getChangeAddressHex()];
1925
+ }
1835
1926
  /**
1836
1927
  * Get a list of UTXOs to be used for transaction building.
1837
1928
  *
@@ -1841,6 +1932,7 @@ var MeshWallet = class {
1841
1932
  * @returns a list of UTXOs
1842
1933
  */
1843
1934
  async getUsedUTxOs(addressType = "payment") {
1935
+ await this.init();
1844
1936
  return await this.getUnspentOutputs(addressType);
1845
1937
  }
1846
1938
  /**
@@ -1853,6 +1945,16 @@ var MeshWallet = class {
1853
1945
  const utxos = await this.getUsedUTxOs(addressType);
1854
1946
  return utxos.map((c) => fromTxUnspentOutput2(c));
1855
1947
  }
1948
+ /**
1949
+ * Return a list of all UTXOs (unspent transaction outputs) controlled by the wallet.
1950
+ *
1951
+ * @param addressType - the type of address to fetch UTXOs from (default: payment)
1952
+ * @returns a list of UTXOs in hex format
1953
+ */
1954
+ async getUtxosHex(addressType = "payment") {
1955
+ const utxos = await this.getUsedUTxOs(addressType);
1956
+ return utxos.map((c) => c.toCbor().toString());
1957
+ }
1856
1958
  /**
1857
1959
  * This endpoint utilizes the [CIP-8 - Message Signing](https://cips.cardano.org/cips/cip8/) to sign arbitrary data, to verify the data was signed by the owner of the private key.
1858
1960
  *
@@ -1861,6 +1963,7 @@ var MeshWallet = class {
1861
1963
  * @returns a signature
1862
1964
  */
1863
1965
  async signData(payload, address) {
1966
+ await this.init();
1864
1967
  if (!this._wallet) {
1865
1968
  throw new Error(
1866
1969
  "[MeshWallet] Read only wallet does not support signing data."
@@ -1881,9 +1984,11 @@ var MeshWallet = class {
1881
1984
  *
1882
1985
  * @param unsignedTx - a transaction in CBOR
1883
1986
  * @param partialSign - if the transaction is partially signed (default: false)
1987
+ * @param returnFullTx - if the full tx should be returned or only the witness set (default: true)
1884
1988
  * @returns a signed transaction in CBOR
1885
1989
  */
1886
- async signTx(unsignedTx, partialSign = false) {
1990
+ async signTx(unsignedTx, partialSign = false, returnFullTx = true) {
1991
+ await this.init();
1887
1992
  if (!this._wallet) {
1888
1993
  throw new Error(
1889
1994
  "[MeshWallet] Read only wallet does not support signing data."
@@ -1897,8 +2002,19 @@ var MeshWallet = class {
1897
2002
  const newSignatures = this._wallet.signTx(
1898
2003
  unsignedTx,
1899
2004
  this._accountIndex,
1900
- this._keyIndex
2005
+ this._keyIndex,
2006
+ this._accountType
1901
2007
  );
2008
+ if (!returnFullTx) {
2009
+ let witnessSet = new TransactionWitnessSet2();
2010
+ witnessSet.setVkeys(
2011
+ Serialization4.CborSet.fromCore(
2012
+ [newSignatures.toCore()],
2013
+ VkeyWitness4.fromCore
2014
+ )
2015
+ );
2016
+ return witnessSet.toCbor().toString();
2017
+ }
1902
2018
  let signedTx = EmbeddedWallet.addWitnessSets(unsignedTx, [newSignatures]);
1903
2019
  return signedTx;
1904
2020
  }
@@ -1909,7 +2025,8 @@ var MeshWallet = class {
1909
2025
  * @param partialSign - if the transactions are signed partially
1910
2026
  * @returns array of signed transactions CborHex string
1911
2027
  */
1912
- async signTxs(unsignedTxs, partialSign = false) {
2028
+ async signTxs(unsignedTxs, partialSign = false, returnFullTx = true) {
2029
+ await this.init();
1913
2030
  if (!this._wallet) {
1914
2031
  throw new Error(
1915
2032
  "[MeshWallet] Read only wallet does not support signing data."
@@ -1917,7 +2034,7 @@ var MeshWallet = class {
1917
2034
  }
1918
2035
  const signedTxs = [];
1919
2036
  for (const unsignedTx of unsignedTxs) {
1920
- const signedTx = await this.signTx(unsignedTx, partialSign);
2037
+ const signedTx = await this.signTx(unsignedTx, partialSign, returnFullTx);
1921
2038
  signedTxs.push(signedTx);
1922
2039
  }
1923
2040
  return signedTxs;
@@ -1925,7 +2042,7 @@ var MeshWallet = class {
1925
2042
  /**
1926
2043
  * Submits the signed transaction to the blockchain network.
1927
2044
  *
1928
- * 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.
2045
+ * 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.
1929
2046
  *
1930
2047
  * @param tx - a signed transaction in CBOR
1931
2048
  * @returns a transaction hash
@@ -2048,7 +2165,8 @@ var MeshWallet = class {
2048
2165
  return {
2049
2166
  pubDRepKey: this.addresses.pubDRepKey,
2050
2167
  dRepIDBech32: this.addresses.dRepIDBech32,
2051
- dRepIDHash: this.addresses.dRepIDHash
2168
+ dRepIDHash: this.addresses.dRepIDHash,
2169
+ dRepIDCip105: this.addresses.dRepIDCip105
2052
2170
  };
2053
2171
  }
2054
2172
  /**
@@ -2075,7 +2193,8 @@ var MeshWallet = class {
2075
2193
  rewardAddressBech32: account.rewardAddressBech32,
2076
2194
  pubDRepKey: account.pubDRepKey,
2077
2195
  dRepIDBech32: account.dRepIDBech32,
2078
- dRepIDHash: account.dRepIDHash
2196
+ dRepIDHash: account.dRepIDHash,
2197
+ dRepIDCip105: account.dRepIDCip105
2079
2198
  };
2080
2199
  }
2081
2200
  buildAddressFromBech32Address(address) {
@@ -2097,24 +2216,22 @@ var MeshWallet = class {
2097
2216
  if (pubKeyHash && stakeKeyHash) {
2098
2217
  this.addresses.baseAddress = buildBaseAddress2(
2099
2218
  this._networkId,
2100
- Hash28ByteBase162.fromEd25519KeyHashHex(Ed25519KeyHashHex3(pubKeyHash)),
2101
- Hash28ByteBase162.fromEd25519KeyHashHex(
2102
- Ed25519KeyHashHex3(Ed25519KeyHashHex3(stakeKeyHash))
2103
- )
2219
+ Hash28ByteBase162(pubKeyHash),
2220
+ Hash28ByteBase162(stakeKeyHash)
2104
2221
  ).toAddress();
2105
2222
  this.addresses.baseAddressBech32 = this.addresses.baseAddress.toBech32();
2106
2223
  }
2107
2224
  if (pubKeyHash) {
2108
2225
  this.addresses.enterpriseAddress = buildEnterpriseAddress2(
2109
2226
  this._networkId,
2110
- Hash28ByteBase162.fromEd25519KeyHashHex(Ed25519KeyHashHex3(pubKeyHash))
2227
+ Hash28ByteBase162(Ed25519KeyHashHex3(pubKeyHash))
2111
2228
  ).toAddress();
2112
2229
  this.addresses.enterpriseAddressBech32 = this.addresses.enterpriseAddress.toBech32();
2113
2230
  }
2114
2231
  if (stakeKeyHash) {
2115
2232
  this.addresses.rewardAddress = buildRewardAddress2(
2116
2233
  this._networkId,
2117
- Hash28ByteBase162.fromEd25519KeyHashHex(Ed25519KeyHashHex3(stakeKeyHash))
2234
+ Hash28ByteBase162(stakeKeyHash)
2118
2235
  ).toAddress();
2119
2236
  this.addresses.rewardAddressBech32 = this.addresses.rewardAddress.toBech32();
2120
2237
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meshsdk/wallet",
3
- "version": "1.9.0-beta.10",
3
+ "version": "1.9.0-beta.101",
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.10",
39
- "@meshsdk/core-cst": "1.9.0-beta.10",
40
- "@meshsdk/transaction": "1.9.0-beta.10",
38
+ "@meshsdk/common": "1.9.0-beta.101",
39
+ "@meshsdk/core-cst": "1.9.0-beta.101",
40
+ "@meshsdk/transaction": "1.9.0-beta.101",
41
41
  "@simplewebauthn/browser": "^13.0.0"
42
42
  },
43
43
  "prettier": "@meshsdk/configs/prettier",