@meshsdk/wallet 2.0.0-beta.5 → 2.0.0-beta.7

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
@@ -21883,7 +21883,7 @@ var require_src = __commonJS({
21883
21883
  return Buffer.from(res);
21884
21884
  }
21885
21885
  exports2.mnemonicToSeedSync = mnemonicToSeedSync;
21886
- function mnemonicToSeed(mnemonic, password) {
21886
+ function mnemonicToSeed2(mnemonic, password) {
21887
21887
  const mnemonicBuffer = Uint8Array.from(Buffer.from(normalize(mnemonic), "utf8"));
21888
21888
  const saltBuffer = Uint8Array.from(Buffer.from(salt(normalize(password)), "utf8"));
21889
21889
  return pbkdf2_1.pbkdf2Async(sha512_1.sha512, mnemonicBuffer, saltBuffer, {
@@ -21891,7 +21891,7 @@ var require_src = __commonJS({
21891
21891
  dkLen: 64
21892
21892
  }).then((res) => Buffer.from(res));
21893
21893
  }
21894
- exports2.mnemonicToSeed = mnemonicToSeed;
21894
+ exports2.mnemonicToSeed = mnemonicToSeed2;
21895
21895
  function mnemonicToEntropy3(mnemonic, wordlist) {
21896
21896
  wordlist = wordlist || DEFAULT_WORDLIST;
21897
21897
  if (!wordlist) {
@@ -21929,7 +21929,7 @@ var require_src = __commonJS({
21929
21929
  return entropy.toString("hex");
21930
21930
  }
21931
21931
  exports2.mnemonicToEntropy = mnemonicToEntropy3;
21932
- function entropyToMnemonic(entropy, wordlist) {
21932
+ function entropyToMnemonic2(entropy, wordlist) {
21933
21933
  if (!Buffer.isBuffer(entropy)) {
21934
21934
  entropy = Buffer.from(entropy, "hex");
21935
21935
  }
@@ -21956,14 +21956,14 @@ var require_src = __commonJS({
21956
21956
  });
21957
21957
  return wordlist[0] === "\u3042\u3044\u3053\u304F\u3057\u3093" ? words.join("\u3000") : words.join(" ");
21958
21958
  }
21959
- exports2.entropyToMnemonic = entropyToMnemonic;
21959
+ exports2.entropyToMnemonic = entropyToMnemonic2;
21960
21960
  function generateMnemonic2(strength, rng, wordlist) {
21961
21961
  strength = strength || 128;
21962
21962
  if (strength % 32 !== 0) {
21963
21963
  throw new TypeError(INVALID_ENTROPY);
21964
21964
  }
21965
21965
  rng = rng || ((size) => Buffer.from(utils_1.randomBytes(size)));
21966
- return entropyToMnemonic(rng(strength / 8), wordlist);
21966
+ return entropyToMnemonic2(rng(strength / 8), wordlist);
21967
21967
  }
21968
21968
  exports2.generateMnemonic = generateMnemonic2;
21969
21969
  function validateMnemonic(mnemonic, wordlist) {
@@ -23853,17 +23853,18 @@ var index_exports = {};
23853
23853
  __export(index_exports, {
23854
23854
  AddressType: () => AddressType,
23855
23855
  BaseSigner: () => BaseSigner,
23856
+ BitcoinInMemoryBip32: () => BitcoinInMemoryBip32,
23856
23857
  CardanoAddress: () => CardanoAddress,
23857
23858
  CardanoBrowserWallet: () => CardanoBrowserWallet,
23858
23859
  CardanoHeadlessWallet: () => CardanoHeadlessWallet,
23860
+ CardanoInMemoryBip32: () => CardanoInMemoryBip32,
23859
23861
  CredentialType: () => CredentialType,
23860
- InMemoryBip32: () => InMemoryBip32,
23861
23862
  MeshCardanoBrowserWallet: () => MeshCardanoBrowserWallet,
23862
23863
  MeshCardanoHeadlessWallet: () => MeshCardanoHeadlessWallet
23863
23864
  });
23864
23865
  module.exports = __toCommonJS(index_exports);
23865
23866
 
23866
- // src/bip32/in-memory-bip32.ts
23867
+ // src/bip32/cardano-in-memory-bip32.ts
23867
23868
  var import_crypto2 = require("@cardano-sdk/crypto");
23868
23869
 
23869
23870
  // node_modules/@scure/base/lib/esm/index.js
@@ -24124,7 +24125,7 @@ function genBech32(encoding) {
24124
24125
  }
24125
24126
  var bech32 = /* @__PURE__ */ genBech32("bech32");
24126
24127
 
24127
- // src/bip32/in-memory-bip32.ts
24128
+ // src/bip32/cardano-in-memory-bip32.ts
24128
24129
  var import_bip39 = __toESM(require_src(), 1);
24129
24130
 
24130
24131
  // src/cardano/utils/constants.ts
@@ -24149,9 +24150,6 @@ var DEFAULT_DREP_KEY_DERIVATION_PATH = [
24149
24150
 
24150
24151
  // src/interfaces/secret-manager.ts
24151
24152
  var derivationPathVectorFromString = (path) => {
24152
- if (!/^m?\/\d+(\/\d+)*$/.test(path)) {
24153
- throw new Error(`Invalid derivation path: ${path}`);
24154
- }
24155
24153
  let pathString = path;
24156
24154
  if (pathString.startsWith("m/")) {
24157
24155
  pathString = pathString.slice(2);
@@ -24164,6 +24162,15 @@ var derivationPathVectorFromString = (path) => {
24164
24162
  }
24165
24163
  });
24166
24164
  };
24165
+ var derivationPathStringFromVector = (path) => {
24166
+ return path.map((part) => {
24167
+ if (part >= HARDENED_OFFSET) {
24168
+ return part - HARDENED_OFFSET + "'";
24169
+ } else {
24170
+ return part.toString();
24171
+ }
24172
+ }).join("/");
24173
+ };
24167
24174
 
24168
24175
  // src/signer/base-signer.ts
24169
24176
  var import_core = require("@cardano-sdk/core");
@@ -24242,8 +24249,8 @@ var BaseSigner = class _BaseSigner {
24242
24249
  }
24243
24250
  };
24244
24251
 
24245
- // src/bip32/in-memory-bip32.ts
24246
- var InMemoryBip32 = class _InMemoryBip32 {
24252
+ // src/bip32/cardano-in-memory-bip32.ts
24253
+ var CardanoInMemoryBip32 = class _CardanoInMemoryBip32 {
24247
24254
  constructor(privateKey) {
24248
24255
  this.bip32PrivateKey = privateKey;
24249
24256
  }
@@ -24254,7 +24261,7 @@ var InMemoryBip32 = class _InMemoryBip32 {
24254
24261
  Buffer.from(entropy, "hex"),
24255
24262
  password || ""
24256
24263
  );
24257
- return new _InMemoryBip32(bip32PrivateKey);
24264
+ return new _CardanoInMemoryBip32(bip32PrivateKey);
24258
24265
  }
24259
24266
  static async fromEntropy(entropy, password) {
24260
24267
  await (0, import_crypto2.ready)();
@@ -24262,18 +24269,18 @@ var InMemoryBip32 = class _InMemoryBip32 {
24262
24269
  Buffer.from(entropy, "hex"),
24263
24270
  password || ""
24264
24271
  );
24265
- return new _InMemoryBip32(bip32PrivateKey);
24272
+ return new _CardanoInMemoryBip32(bip32PrivateKey);
24266
24273
  }
24267
24274
  static fromKeyHex(keyHex) {
24268
24275
  const bip32PrivateKey = import_crypto2.Bip32PrivateKey.fromHex(
24269
24276
  keyHex
24270
24277
  );
24271
- return new _InMemoryBip32(bip32PrivateKey);
24278
+ return new _CardanoInMemoryBip32(bip32PrivateKey);
24272
24279
  }
24273
24280
  static fromBech32(bech323) {
24274
24281
  const bech32DecodedBytes = bech32.decodeToBytes(bech323).bytes;
24275
24282
  const bip32PrivateKey = import_crypto2.Bip32PrivateKey.fromBytes(bech32DecodedBytes);
24276
- return new _InMemoryBip32(bip32PrivateKey);
24283
+ return new _CardanoInMemoryBip32(bip32PrivateKey);
24277
24284
  }
24278
24285
  /**
24279
24286
  * Get the Bip32 public key in hex format.
@@ -24294,6 +24301,44 @@ var InMemoryBip32 = class _InMemoryBip32 {
24294
24301
  }
24295
24302
  };
24296
24303
 
24304
+ // src/bip32/bitcoin-in-memory-bip32.ts
24305
+ var bip32 = __toESM(require("bip32"), 1);
24306
+ var ecc = __toESM(require("tiny-secp256k1"), 1);
24307
+ var import_bip392 = __toESM(require_src(), 1);
24308
+ var BitcoinInMemoryBip32 = class _BitcoinInMemoryBip32 {
24309
+ constructor(root) {
24310
+ this.root = root;
24311
+ }
24312
+ static async fromMnemonic(mnemonic, password) {
24313
+ const seed = await (0, import_bip392.mnemonicToSeed)(mnemonic.join(" "), password || "");
24314
+ const root = bip32.BIP32Factory(ecc).fromSeed(seed);
24315
+ return new _BitcoinInMemoryBip32(root);
24316
+ }
24317
+ static async fromEntropy(entropy, password) {
24318
+ const mnemonic = (0, import_bip392.entropyToMnemonic)(entropy);
24319
+ const seed = await (0, import_bip392.mnemonicToSeed)(mnemonic, password || "");
24320
+ const root = bip32.BIP32Factory(ecc).fromSeed(seed);
24321
+ return new _BitcoinInMemoryBip32(root);
24322
+ }
24323
+ /**
24324
+ * Get the private key (hex) for the provided derivation path.
24325
+ */
24326
+ getPrivateKey(derivationPath) {
24327
+ const path = Array.isArray(derivationPath) ? `m/${derivationPathStringFromVector(derivationPath)}` : derivationPath;
24328
+ const child = this.root.derivePath(path);
24329
+ if (!child?.privateKey) throw new Error("No private key at path");
24330
+ return Buffer.from(child.privateKey).toString("hex");
24331
+ }
24332
+ /**
24333
+ * Get the public key (hex) for the provided derivation path.
24334
+ */
24335
+ getPublicKey(derivationPath) {
24336
+ const path = Array.isArray(derivationPath) ? `m/${derivationPathStringFromVector(derivationPath)}` : derivationPath;
24337
+ const child = this.root.derivePath(path);
24338
+ return Buffer.from(child.publicKey).toString("hex");
24339
+ }
24340
+ };
24341
+
24297
24342
  // src/cardano/address/cardano-address.ts
24298
24343
  var import_core2 = require("@cardano-sdk/core");
24299
24344
  var import_crypto3 = require("@cardano-sdk/crypto");
@@ -24700,10 +24745,10 @@ var MeshCardanoBrowserWallet = class _MeshCardanoBrowserWallet extends CardanoBr
24700
24745
  }
24701
24746
  };
24702
24747
 
24703
- // src/cardano/wallet/mesh/cardano-base-wallet.ts
24748
+ // src/cardano/wallet/mesh/cardano-headless-wallet.ts
24704
24749
  var import_core9 = require("@cardano-sdk/core");
24705
24750
 
24706
- // src/utils/value.ts
24751
+ // src/cardano/utils/value.ts
24707
24752
  var import_core5 = require("@cardano-sdk/core");
24708
24753
  function mergeValue(a, b) {
24709
24754
  const ma = a.multiasset() ?? /* @__PURE__ */ new Map();
@@ -24878,7 +24923,7 @@ var import_cbor2 = require("@harmoniclabs/cbor");
24878
24923
  var import_bech32 = __toESM(require_dist(), 1);
24879
24924
  var import_blake2b = __toESM(require_blake2b2(), 1);
24880
24925
  var import_blakejs = __toESM(require_blakejs(), 1);
24881
- var import_bip392 = __toESM(require_src(), 1);
24926
+ var import_bip393 = __toESM(require_src(), 1);
24882
24927
  var stringToHex = (str) => Buffer.from(str, "utf8").toString("hex");
24883
24928
  var isHexString = (hex) => /^[0-9A-F]*$/i.test(hex);
24884
24929
  var SLOT_CONFIG_NETWORK = {
@@ -25284,7 +25329,11 @@ function getRequiredSignersFromWithdrawals(txBody) {
25284
25329
  const withdrawals = txBody.withdrawals();
25285
25330
  if (withdrawals) {
25286
25331
  for (const rewardAccount of withdrawals.keys()) {
25287
- requiredSigners.add(import_core8.Cardano.RewardAccount.toHash(rewardAccount));
25332
+ const address = import_core8.Cardano.Address.fromBech32(rewardAccount);
25333
+ const addressType = address.getType();
25334
+ if (addressType === import_core8.Cardano.AddressType.RewardKey) {
25335
+ requiredSigners.add(import_core8.Cardano.RewardAccount.toHash(rewardAccount));
25336
+ }
25288
25337
  }
25289
25338
  }
25290
25339
  return requiredSigners;
@@ -25340,7 +25389,7 @@ async function getTransactionRequiredSigners(transaction, fetcher) {
25340
25389
  return allRequiredSigners;
25341
25390
  }
25342
25391
 
25343
- // src/cardano/wallet/mesh/cardano-base-wallet.ts
25392
+ // src/cardano/wallet/mesh/cardano-headless-wallet.ts
25344
25393
  var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
25345
25394
  constructor(networkId, addressManager, walletAddressType, fetcher, submitter) {
25346
25395
  (0, import_core9.setInConwayEra)(true);
@@ -25369,9 +25418,9 @@ var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
25369
25418
  * @returns {Promise<CardanoHeadlessWallet>} A promise that resolves to a CardanoHeadlessWallet instance
25370
25419
  */
25371
25420
  static async fromBip32Root(config) {
25372
- const bip32 = InMemoryBip32.fromBech32(config.bech32);
25421
+ const bip322 = CardanoInMemoryBip32.fromBech32(config.bech32);
25373
25422
  return _CardanoHeadlessWallet.create({
25374
- addressSource: { type: "secretManager", secretManager: bip32 },
25423
+ addressSource: { type: "secretManager", secretManager: bip322 },
25375
25424
  networkId: config.networkId,
25376
25425
  walletAddressType: config.walletAddressType,
25377
25426
  fetcher: config.fetcher,
@@ -25384,9 +25433,9 @@ var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
25384
25433
  * @returns {Promise<CardanoHeadlessWallet>} A promise that resolves to a CardanoHeadlessWallet instance
25385
25434
  */
25386
25435
  static async fromBip32RootHex(config) {
25387
- const bip32 = InMemoryBip32.fromKeyHex(config.hex);
25436
+ const bip322 = CardanoInMemoryBip32.fromKeyHex(config.hex);
25388
25437
  return _CardanoHeadlessWallet.create({
25389
- addressSource: { type: "secretManager", secretManager: bip32 },
25438
+ addressSource: { type: "secretManager", secretManager: bip322 },
25390
25439
  networkId: config.networkId,
25391
25440
  walletAddressType: config.walletAddressType,
25392
25441
  fetcher: config.fetcher,
@@ -25399,12 +25448,12 @@ var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
25399
25448
  * @returns {Promise<CardanoHeadlessWallet>} A promise that resolves to a CardanoHeadlessWallet instance
25400
25449
  */
25401
25450
  static async fromMnemonic(config) {
25402
- const bip32 = await InMemoryBip32.fromMnemonic(
25451
+ const bip322 = await CardanoInMemoryBip32.fromMnemonic(
25403
25452
  config.mnemonic,
25404
25453
  config.password
25405
25454
  );
25406
25455
  return _CardanoHeadlessWallet.create({
25407
- addressSource: { type: "secretManager", secretManager: bip32 },
25456
+ addressSource: { type: "secretManager", secretManager: bip322 },
25408
25457
  networkId: config.networkId,
25409
25458
  walletAddressType: config.walletAddressType,
25410
25459
  fetcher: config.fetcher,
@@ -25675,12 +25724,12 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
25675
25724
  );
25676
25725
  }
25677
25726
  static async fromMnemonic(config) {
25678
- const bip32 = await InMemoryBip32.fromMnemonic(
25727
+ const bip322 = await CardanoInMemoryBip32.fromMnemonic(
25679
25728
  config.mnemonic,
25680
25729
  config.password
25681
25730
  );
25682
25731
  return _MeshCardanoHeadlessWallet.create({
25683
- addressSource: { type: "secretManager", secretManager: bip32 },
25732
+ addressSource: { type: "secretManager", secretManager: bip322 },
25684
25733
  networkId: config.networkId,
25685
25734
  walletAddressType: config.walletAddressType,
25686
25735
  fetcher: config.fetcher,
@@ -25688,9 +25737,9 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
25688
25737
  });
25689
25738
  }
25690
25739
  static async fromBip32Root(config) {
25691
- const bip32 = InMemoryBip32.fromBech32(config.bech32);
25740
+ const bip322 = CardanoInMemoryBip32.fromBech32(config.bech32);
25692
25741
  return _MeshCardanoHeadlessWallet.create({
25693
- addressSource: { type: "secretManager", secretManager: bip32 },
25742
+ addressSource: { type: "secretManager", secretManager: bip322 },
25694
25743
  networkId: config.networkId,
25695
25744
  walletAddressType: config.walletAddressType,
25696
25745
  fetcher: config.fetcher,
@@ -25698,9 +25747,9 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
25698
25747
  });
25699
25748
  }
25700
25749
  static async fromBip32RootHex(config) {
25701
- const bip32 = InMemoryBip32.fromKeyHex(config.hex);
25750
+ const bip322 = CardanoInMemoryBip32.fromKeyHex(config.hex);
25702
25751
  return _MeshCardanoHeadlessWallet.create({
25703
- addressSource: { type: "secretManager", secretManager: bip32 },
25752
+ addressSource: { type: "secretManager", secretManager: bip322 },
25704
25753
  networkId: config.networkId,
25705
25754
  walletAddressType: config.walletAddressType,
25706
25755
  fetcher: config.fetcher,
@@ -25894,11 +25943,12 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
25894
25943
  0 && (module.exports = {
25895
25944
  AddressType,
25896
25945
  BaseSigner,
25946
+ BitcoinInMemoryBip32,
25897
25947
  CardanoAddress,
25898
25948
  CardanoBrowserWallet,
25899
25949
  CardanoHeadlessWallet,
25950
+ CardanoInMemoryBip32,
25900
25951
  CredentialType,
25901
- InMemoryBip32,
25902
25952
  MeshCardanoBrowserWallet,
25903
25953
  MeshCardanoHeadlessWallet
25904
25954
  });
package/dist/index.d.ts CHANGED
@@ -13,13 +13,13 @@ interface ISecretManager {
13
13
  getSigner(derivationPath: DerivationPath): Promise<ISigner>;
14
14
  }
15
15
 
16
- declare class InMemoryBip32 implements ISecretManager {
16
+ declare class CardanoInMemoryBip32 implements ISecretManager {
17
17
  private bip32PrivateKey;
18
18
  private constructor();
19
- static fromMnemonic(mnemonic: string[], password?: string): Promise<InMemoryBip32>;
20
- static fromEntropy(entropy: string, password?: string): Promise<InMemoryBip32>;
21
- static fromKeyHex(keyHex: string): InMemoryBip32;
22
- static fromBech32(bech32: string): InMemoryBip32;
19
+ static fromMnemonic(mnemonic: string[], password?: string): Promise<CardanoInMemoryBip32>;
20
+ static fromEntropy(entropy: string, password?: string): Promise<CardanoInMemoryBip32>;
21
+ static fromKeyHex(keyHex: string): CardanoInMemoryBip32;
22
+ static fromBech32(bech32: string): CardanoInMemoryBip32;
23
23
  /**
24
24
  * Get the Bip32 public key in hex format.
25
25
  * @returns {Promise<string>} A promise that resolves to the public key in hex format.
@@ -32,6 +32,21 @@ declare class InMemoryBip32 implements ISecretManager {
32
32
  getSigner(derivationPath: DerivationPath): Promise<ISigner>;
33
33
  }
34
34
 
35
+ declare class BitcoinInMemoryBip32 {
36
+ private root;
37
+ private constructor();
38
+ static fromMnemonic(mnemonic: string[], password?: string): Promise<BitcoinInMemoryBip32>;
39
+ static fromEntropy(entropy: string, password?: string): Promise<BitcoinInMemoryBip32>;
40
+ /**
41
+ * Get the private key (hex) for the provided derivation path.
42
+ */
43
+ getPrivateKey(derivationPath: DerivationPath): string;
44
+ /**
45
+ * Get the public key (hex) for the provided derivation path.
46
+ */
47
+ getPublicKey(derivationPath: DerivationPath): string;
48
+ }
49
+
35
50
  /**
36
51
  * BaseSigner provides functionalities to sign and verify data using Ed25519 keys.
37
52
  * It supports construction from both extended and normal private key hex formats.
@@ -515,4 +530,4 @@ declare class MeshCardanoHeadlessWallet extends CardanoHeadlessWallet {
515
530
  signTxReturnFullTx(tx: string, partialSign?: boolean): Promise<string>;
516
531
  }
517
532
 
518
- export { AddressType, BaseSigner, type Cardano, CardanoAddress, CardanoBrowserWallet, CardanoHeadlessWallet, type CardanoHeadlessWalletConfig, type Credential, type CredentialSource, CredentialType, type ICardanoWallet, InMemoryBip32, MeshCardanoBrowserWallet, MeshCardanoHeadlessWallet, type WalletAddressType };
533
+ export { AddressType, BaseSigner, BitcoinInMemoryBip32, type Cardano, CardanoAddress, CardanoBrowserWallet, CardanoHeadlessWallet, type CardanoHeadlessWalletConfig, CardanoInMemoryBip32, type Credential, type CredentialSource, CredentialType, type ICardanoWallet, MeshCardanoBrowserWallet, MeshCardanoHeadlessWallet, type WalletAddressType };
package/dist/index.js CHANGED
@@ -21877,7 +21877,7 @@ var require_src = __commonJS({
21877
21877
  return Buffer.from(res);
21878
21878
  }
21879
21879
  exports.mnemonicToSeedSync = mnemonicToSeedSync;
21880
- function mnemonicToSeed(mnemonic, password) {
21880
+ function mnemonicToSeed2(mnemonic, password) {
21881
21881
  const mnemonicBuffer = Uint8Array.from(Buffer.from(normalize(mnemonic), "utf8"));
21882
21882
  const saltBuffer = Uint8Array.from(Buffer.from(salt(normalize(password)), "utf8"));
21883
21883
  return pbkdf2_1.pbkdf2Async(sha512_1.sha512, mnemonicBuffer, saltBuffer, {
@@ -21885,7 +21885,7 @@ var require_src = __commonJS({
21885
21885
  dkLen: 64
21886
21886
  }).then((res) => Buffer.from(res));
21887
21887
  }
21888
- exports.mnemonicToSeed = mnemonicToSeed;
21888
+ exports.mnemonicToSeed = mnemonicToSeed2;
21889
21889
  function mnemonicToEntropy3(mnemonic, wordlist) {
21890
21890
  wordlist = wordlist || DEFAULT_WORDLIST;
21891
21891
  if (!wordlist) {
@@ -21923,7 +21923,7 @@ var require_src = __commonJS({
21923
21923
  return entropy.toString("hex");
21924
21924
  }
21925
21925
  exports.mnemonicToEntropy = mnemonicToEntropy3;
21926
- function entropyToMnemonic(entropy, wordlist) {
21926
+ function entropyToMnemonic2(entropy, wordlist) {
21927
21927
  if (!Buffer.isBuffer(entropy)) {
21928
21928
  entropy = Buffer.from(entropy, "hex");
21929
21929
  }
@@ -21950,14 +21950,14 @@ var require_src = __commonJS({
21950
21950
  });
21951
21951
  return wordlist[0] === "\u3042\u3044\u3053\u304F\u3057\u3093" ? words.join("\u3000") : words.join(" ");
21952
21952
  }
21953
- exports.entropyToMnemonic = entropyToMnemonic;
21953
+ exports.entropyToMnemonic = entropyToMnemonic2;
21954
21954
  function generateMnemonic2(strength, rng, wordlist) {
21955
21955
  strength = strength || 128;
21956
21956
  if (strength % 32 !== 0) {
21957
21957
  throw new TypeError(INVALID_ENTROPY);
21958
21958
  }
21959
21959
  rng = rng || ((size) => Buffer.from(utils_1.randomBytes(size)));
21960
- return entropyToMnemonic(rng(strength / 8), wordlist);
21960
+ return entropyToMnemonic2(rng(strength / 8), wordlist);
21961
21961
  }
21962
21962
  exports.generateMnemonic = generateMnemonic2;
21963
21963
  function validateMnemonic(mnemonic, wordlist) {
@@ -22188,7 +22188,7 @@ var require_ascii = __commonJS({
22188
22188
  const len = buffer.byteLength;
22189
22189
  let result = "";
22190
22190
  for (let i = 0; i < len; i++) {
22191
- result += String.fromCharCode(buffer[i]);
22191
+ result += String.fromCharCode(buffer[i] & 127);
22192
22192
  }
22193
22193
  return result;
22194
22194
  }
@@ -22307,6 +22307,35 @@ var require_hex = __commonJS({
22307
22307
  }
22308
22308
  });
22309
22309
 
22310
+ // node_modules/b4a/lib/latin1.js
22311
+ var require_latin1 = __commonJS({
22312
+ "node_modules/b4a/lib/latin1.js"(exports, module) {
22313
+ function byteLength(string) {
22314
+ return string.length;
22315
+ }
22316
+ function toString(buffer) {
22317
+ const len = buffer.byteLength;
22318
+ let result = "";
22319
+ for (let i = 0; i < len; i++) {
22320
+ result += String.fromCharCode(buffer[i]);
22321
+ }
22322
+ return result;
22323
+ }
22324
+ function write(buffer, string) {
22325
+ const len = buffer.byteLength;
22326
+ for (let i = 0; i < len; i++) {
22327
+ buffer[i] = string.charCodeAt(i);
22328
+ }
22329
+ return len;
22330
+ }
22331
+ module.exports = {
22332
+ byteLength,
22333
+ toString,
22334
+ write
22335
+ };
22336
+ }
22337
+ });
22338
+
22310
22339
  // node_modules/b4a/lib/utf8.js
22311
22340
  var require_utf8 = __commonJS({
22312
22341
  "node_modules/b4a/lib/utf8.js"(exports, module) {
@@ -22465,6 +22494,7 @@ var require_browser = __commonJS({
22465
22494
  var ascii = require_ascii();
22466
22495
  var base64 = require_base64();
22467
22496
  var hex = require_hex();
22497
+ var latin1 = require_latin1();
22468
22498
  var utf8 = require_utf8();
22469
22499
  var utf16le = require_utf16le();
22470
22500
  var LE = new Uint8Array(Uint16Array.of(255).buffer)[0] === 255;
@@ -22476,6 +22506,9 @@ var require_browser = __commonJS({
22476
22506
  return base64;
22477
22507
  case "hex":
22478
22508
  return hex;
22509
+ case "binary":
22510
+ case "latin1":
22511
+ return latin1;
22479
22512
  case "utf8":
22480
22513
  case "utf-8":
22481
22514
  case void 0:
@@ -24402,7 +24435,7 @@ var require_blakejs = __commonJS({
24402
24435
  }
24403
24436
  });
24404
24437
 
24405
- // src/bip32/in-memory-bip32.ts
24438
+ // src/bip32/cardano-in-memory-bip32.ts
24406
24439
  import {
24407
24440
  Bip32PrivateKey,
24408
24441
  ready
@@ -24666,7 +24699,7 @@ function genBech32(encoding) {
24666
24699
  }
24667
24700
  var bech32 = /* @__PURE__ */ genBech32("bech32");
24668
24701
 
24669
- // src/bip32/in-memory-bip32.ts
24702
+ // src/bip32/cardano-in-memory-bip32.ts
24670
24703
  var import_bip39 = __toESM(require_src(), 1);
24671
24704
 
24672
24705
  // src/cardano/utils/constants.ts
@@ -24691,9 +24724,6 @@ var DEFAULT_DREP_KEY_DERIVATION_PATH = [
24691
24724
 
24692
24725
  // src/interfaces/secret-manager.ts
24693
24726
  var derivationPathVectorFromString = (path) => {
24694
- if (!/^m?\/\d+(\/\d+)*$/.test(path)) {
24695
- throw new Error(`Invalid derivation path: ${path}`);
24696
- }
24697
24727
  let pathString = path;
24698
24728
  if (pathString.startsWith("m/")) {
24699
24729
  pathString = pathString.slice(2);
@@ -24706,6 +24736,15 @@ var derivationPathVectorFromString = (path) => {
24706
24736
  }
24707
24737
  });
24708
24738
  };
24739
+ var derivationPathStringFromVector = (path) => {
24740
+ return path.map((part) => {
24741
+ if (part >= HARDENED_OFFSET) {
24742
+ return part - HARDENED_OFFSET + "'";
24743
+ } else {
24744
+ return part.toString();
24745
+ }
24746
+ }).join("/");
24747
+ };
24709
24748
 
24710
24749
  // src/signer/base-signer.ts
24711
24750
  import { setInConwayEra } from "@cardano-sdk/core";
@@ -24790,8 +24829,8 @@ var BaseSigner = class _BaseSigner {
24790
24829
  }
24791
24830
  };
24792
24831
 
24793
- // src/bip32/in-memory-bip32.ts
24794
- var InMemoryBip32 = class _InMemoryBip32 {
24832
+ // src/bip32/cardano-in-memory-bip32.ts
24833
+ var CardanoInMemoryBip32 = class _CardanoInMemoryBip32 {
24795
24834
  constructor(privateKey) {
24796
24835
  this.bip32PrivateKey = privateKey;
24797
24836
  }
@@ -24802,7 +24841,7 @@ var InMemoryBip32 = class _InMemoryBip32 {
24802
24841
  Buffer.from(entropy, "hex"),
24803
24842
  password || ""
24804
24843
  );
24805
- return new _InMemoryBip32(bip32PrivateKey);
24844
+ return new _CardanoInMemoryBip32(bip32PrivateKey);
24806
24845
  }
24807
24846
  static async fromEntropy(entropy, password) {
24808
24847
  await ready();
@@ -24810,18 +24849,18 @@ var InMemoryBip32 = class _InMemoryBip32 {
24810
24849
  Buffer.from(entropy, "hex"),
24811
24850
  password || ""
24812
24851
  );
24813
- return new _InMemoryBip32(bip32PrivateKey);
24852
+ return new _CardanoInMemoryBip32(bip32PrivateKey);
24814
24853
  }
24815
24854
  static fromKeyHex(keyHex) {
24816
24855
  const bip32PrivateKey = Bip32PrivateKey.fromHex(
24817
24856
  keyHex
24818
24857
  );
24819
- return new _InMemoryBip32(bip32PrivateKey);
24858
+ return new _CardanoInMemoryBip32(bip32PrivateKey);
24820
24859
  }
24821
24860
  static fromBech32(bech323) {
24822
24861
  const bech32DecodedBytes = bech32.decodeToBytes(bech323).bytes;
24823
24862
  const bip32PrivateKey = Bip32PrivateKey.fromBytes(bech32DecodedBytes);
24824
- return new _InMemoryBip32(bip32PrivateKey);
24863
+ return new _CardanoInMemoryBip32(bip32PrivateKey);
24825
24864
  }
24826
24865
  /**
24827
24866
  * Get the Bip32 public key in hex format.
@@ -24842,6 +24881,44 @@ var InMemoryBip32 = class _InMemoryBip32 {
24842
24881
  }
24843
24882
  };
24844
24883
 
24884
+ // src/bip32/bitcoin-in-memory-bip32.ts
24885
+ var import_bip392 = __toESM(require_src(), 1);
24886
+ import * as bip32 from "bip32";
24887
+ import * as ecc from "tiny-secp256k1";
24888
+ var BitcoinInMemoryBip32 = class _BitcoinInMemoryBip32 {
24889
+ constructor(root) {
24890
+ this.root = root;
24891
+ }
24892
+ static async fromMnemonic(mnemonic, password) {
24893
+ const seed = await (0, import_bip392.mnemonicToSeed)(mnemonic.join(" "), password || "");
24894
+ const root = bip32.BIP32Factory(ecc).fromSeed(seed);
24895
+ return new _BitcoinInMemoryBip32(root);
24896
+ }
24897
+ static async fromEntropy(entropy, password) {
24898
+ const mnemonic = (0, import_bip392.entropyToMnemonic)(entropy);
24899
+ const seed = await (0, import_bip392.mnemonicToSeed)(mnemonic, password || "");
24900
+ const root = bip32.BIP32Factory(ecc).fromSeed(seed);
24901
+ return new _BitcoinInMemoryBip32(root);
24902
+ }
24903
+ /**
24904
+ * Get the private key (hex) for the provided derivation path.
24905
+ */
24906
+ getPrivateKey(derivationPath) {
24907
+ const path = Array.isArray(derivationPath) ? `m/${derivationPathStringFromVector(derivationPath)}` : derivationPath;
24908
+ const child = this.root.derivePath(path);
24909
+ if (!child?.privateKey) throw new Error("No private key at path");
24910
+ return Buffer.from(child.privateKey).toString("hex");
24911
+ }
24912
+ /**
24913
+ * Get the public key (hex) for the provided derivation path.
24914
+ */
24915
+ getPublicKey(derivationPath) {
24916
+ const path = Array.isArray(derivationPath) ? `m/${derivationPathStringFromVector(derivationPath)}` : derivationPath;
24917
+ const child = this.root.derivePath(path);
24918
+ return Buffer.from(child.publicKey).toString("hex");
24919
+ }
24920
+ };
24921
+
24845
24922
  // src/cardano/address/cardano-address.ts
24846
24923
  import { Cardano, setInConwayEra as setInConwayEra2 } from "@cardano-sdk/core";
24847
24924
  import { Hash28ByteBase16 } from "@cardano-sdk/crypto";
@@ -25248,10 +25325,10 @@ var MeshCardanoBrowserWallet = class _MeshCardanoBrowserWallet extends CardanoBr
25248
25325
  }
25249
25326
  };
25250
25327
 
25251
- // src/cardano/wallet/mesh/cardano-base-wallet.ts
25328
+ // src/cardano/wallet/mesh/cardano-headless-wallet.ts
25252
25329
  import { Cardano as Cardano6, Serialization as Serialization6, setInConwayEra as setInConwayEra5 } from "@cardano-sdk/core";
25253
25330
 
25254
- // src/utils/value.ts
25331
+ // src/cardano/utils/value.ts
25255
25332
  import { Serialization as Serialization3 } from "@cardano-sdk/core";
25256
25333
  function mergeValue(a, b) {
25257
25334
  const ma = a.multiasset() ?? /* @__PURE__ */ new Map();
@@ -25432,7 +25509,7 @@ import {
25432
25509
  var import_bech32 = __toESM(require_dist(), 1);
25433
25510
  var import_blake2b = __toESM(require_blake2b2(), 1);
25434
25511
  var import_blakejs = __toESM(require_blakejs(), 1);
25435
- var import_bip392 = __toESM(require_src(), 1);
25512
+ var import_bip393 = __toESM(require_src(), 1);
25436
25513
  var stringToHex = (str) => Buffer.from(str, "utf8").toString("hex");
25437
25514
  var isHexString = (hex) => /^[0-9A-F]*$/i.test(hex);
25438
25515
  var SLOT_CONFIG_NETWORK = {
@@ -25849,7 +25926,11 @@ function getRequiredSignersFromWithdrawals(txBody) {
25849
25926
  const withdrawals = txBody.withdrawals();
25850
25927
  if (withdrawals) {
25851
25928
  for (const rewardAccount of withdrawals.keys()) {
25852
- requiredSigners.add(Cardano5.RewardAccount.toHash(rewardAccount));
25929
+ const address = Cardano5.Address.fromBech32(rewardAccount);
25930
+ const addressType = address.getType();
25931
+ if (addressType === Cardano5.AddressType.RewardKey) {
25932
+ requiredSigners.add(Cardano5.RewardAccount.toHash(rewardAccount));
25933
+ }
25853
25934
  }
25854
25935
  }
25855
25936
  return requiredSigners;
@@ -25905,7 +25986,7 @@ async function getTransactionRequiredSigners(transaction, fetcher) {
25905
25986
  return allRequiredSigners;
25906
25987
  }
25907
25988
 
25908
- // src/cardano/wallet/mesh/cardano-base-wallet.ts
25989
+ // src/cardano/wallet/mesh/cardano-headless-wallet.ts
25909
25990
  var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
25910
25991
  constructor(networkId, addressManager, walletAddressType, fetcher, submitter) {
25911
25992
  setInConwayEra5(true);
@@ -25934,9 +26015,9 @@ var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
25934
26015
  * @returns {Promise<CardanoHeadlessWallet>} A promise that resolves to a CardanoHeadlessWallet instance
25935
26016
  */
25936
26017
  static async fromBip32Root(config) {
25937
- const bip32 = InMemoryBip32.fromBech32(config.bech32);
26018
+ const bip322 = CardanoInMemoryBip32.fromBech32(config.bech32);
25938
26019
  return _CardanoHeadlessWallet.create({
25939
- addressSource: { type: "secretManager", secretManager: bip32 },
26020
+ addressSource: { type: "secretManager", secretManager: bip322 },
25940
26021
  networkId: config.networkId,
25941
26022
  walletAddressType: config.walletAddressType,
25942
26023
  fetcher: config.fetcher,
@@ -25949,9 +26030,9 @@ var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
25949
26030
  * @returns {Promise<CardanoHeadlessWallet>} A promise that resolves to a CardanoHeadlessWallet instance
25950
26031
  */
25951
26032
  static async fromBip32RootHex(config) {
25952
- const bip32 = InMemoryBip32.fromKeyHex(config.hex);
26033
+ const bip322 = CardanoInMemoryBip32.fromKeyHex(config.hex);
25953
26034
  return _CardanoHeadlessWallet.create({
25954
- addressSource: { type: "secretManager", secretManager: bip32 },
26035
+ addressSource: { type: "secretManager", secretManager: bip322 },
25955
26036
  networkId: config.networkId,
25956
26037
  walletAddressType: config.walletAddressType,
25957
26038
  fetcher: config.fetcher,
@@ -25964,12 +26045,12 @@ var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
25964
26045
  * @returns {Promise<CardanoHeadlessWallet>} A promise that resolves to a CardanoHeadlessWallet instance
25965
26046
  */
25966
26047
  static async fromMnemonic(config) {
25967
- const bip32 = await InMemoryBip32.fromMnemonic(
26048
+ const bip322 = await CardanoInMemoryBip32.fromMnemonic(
25968
26049
  config.mnemonic,
25969
26050
  config.password
25970
26051
  );
25971
26052
  return _CardanoHeadlessWallet.create({
25972
- addressSource: { type: "secretManager", secretManager: bip32 },
26053
+ addressSource: { type: "secretManager", secretManager: bip322 },
25973
26054
  networkId: config.networkId,
25974
26055
  walletAddressType: config.walletAddressType,
25975
26056
  fetcher: config.fetcher,
@@ -26240,12 +26321,12 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
26240
26321
  );
26241
26322
  }
26242
26323
  static async fromMnemonic(config) {
26243
- const bip32 = await InMemoryBip32.fromMnemonic(
26324
+ const bip322 = await CardanoInMemoryBip32.fromMnemonic(
26244
26325
  config.mnemonic,
26245
26326
  config.password
26246
26327
  );
26247
26328
  return _MeshCardanoHeadlessWallet.create({
26248
- addressSource: { type: "secretManager", secretManager: bip32 },
26329
+ addressSource: { type: "secretManager", secretManager: bip322 },
26249
26330
  networkId: config.networkId,
26250
26331
  walletAddressType: config.walletAddressType,
26251
26332
  fetcher: config.fetcher,
@@ -26253,9 +26334,9 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
26253
26334
  });
26254
26335
  }
26255
26336
  static async fromBip32Root(config) {
26256
- const bip32 = InMemoryBip32.fromBech32(config.bech32);
26337
+ const bip322 = CardanoInMemoryBip32.fromBech32(config.bech32);
26257
26338
  return _MeshCardanoHeadlessWallet.create({
26258
- addressSource: { type: "secretManager", secretManager: bip32 },
26339
+ addressSource: { type: "secretManager", secretManager: bip322 },
26259
26340
  networkId: config.networkId,
26260
26341
  walletAddressType: config.walletAddressType,
26261
26342
  fetcher: config.fetcher,
@@ -26263,9 +26344,9 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
26263
26344
  });
26264
26345
  }
26265
26346
  static async fromBip32RootHex(config) {
26266
- const bip32 = InMemoryBip32.fromKeyHex(config.hex);
26347
+ const bip322 = CardanoInMemoryBip32.fromKeyHex(config.hex);
26267
26348
  return _MeshCardanoHeadlessWallet.create({
26268
- addressSource: { type: "secretManager", secretManager: bip32 },
26349
+ addressSource: { type: "secretManager", secretManager: bip322 },
26269
26350
  networkId: config.networkId,
26270
26351
  walletAddressType: config.walletAddressType,
26271
26352
  fetcher: config.fetcher,
@@ -26458,11 +26539,12 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
26458
26539
  export {
26459
26540
  AddressType,
26460
26541
  BaseSigner,
26542
+ BitcoinInMemoryBip32,
26461
26543
  CardanoAddress,
26462
26544
  CardanoBrowserWallet,
26463
26545
  CardanoHeadlessWallet,
26546
+ CardanoInMemoryBip32,
26464
26547
  CredentialType,
26465
- InMemoryBip32,
26466
26548
  MeshCardanoBrowserWallet,
26467
26549
  MeshCardanoHeadlessWallet
26468
26550
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meshsdk/wallet",
3
- "version": "2.0.0-beta.5",
3
+ "version": "2.0.0-beta.7",
4
4
  "description": "Wallets - https://meshjs.dev/apis/wallets",
5
5
  "main": "./dist/index.cjs",
6
6
  "browser": "./dist/index.js",
@@ -31,8 +31,15 @@
31
31
  "test": "jest"
32
32
  },
33
33
  "devDependencies": {
34
+ "@meshsdk/common": "1.9.0-beta.100",
35
+ "@meshsdk/provider": "1.9.0-beta.99",
36
+ "@types/jest": "^29.5.12",
37
+ "dotenv": "^16.4.5",
34
38
  "eslint": "^8.57.0",
39
+ "jest": "^29.7.0",
35
40
  "patch-package": "^8.0.1",
41
+ "ts-jest": "^29.1.4",
42
+ "ts-node": "^10.9.2",
36
43
  "tsup": "^8.0.2",
37
44
  "typedoc": "^0.26.3",
38
45
  "typescript": "^5.3.3",
@@ -41,19 +48,21 @@
41
48
  "ts-node": "^10.9.2",
42
49
  "ts-jest": "^29.1.4",
43
50
  "dotenv": "^16.4.5",
44
- "@meshsdk/provider": "1.9.0-beta.90",
45
- "@meshsdk/common": "1.9.0-beta.90"
51
+ "@meshsdk/provider": "1.9.0-beta.99",
52
+ "@meshsdk/common": "1.9.0-beta.100"
46
53
  },
47
54
  "dependencies": {
48
55
  "@cardano-sdk/core": "0.46.11",
49
56
  "@cardano-sdk/crypto": "0.4.4",
50
57
  "@cardano-sdk/util": "0.17.1",
51
58
  "@harmoniclabs/cbor": "^1.6.6",
52
- "json-bigint": "^1.0.0",
53
59
  "@simplewebauthn/browser": "^13.0.0",
54
60
  "@types/base32-encoding": "^1.0.2",
55
61
  "@types/bn.js": "^5.1.5",
56
- "base32-encoding": "^1.0.0"
62
+ "base32-encoding": "^1.0.0",
63
+ "bip32": "^5.0.0",
64
+ "json-bigint": "^1.0.0",
65
+ "tiny-secp256k1": "^2.2.4"
57
66
  },
58
67
  "prettier": "./prettier.config.js",
59
68
  "publishConfig": {