@meshsdk/wallet 2.0.0-beta.6 → 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) {
@@ -24435,7 +24435,7 @@ var require_blakejs = __commonJS({
24435
24435
  }
24436
24436
  });
24437
24437
 
24438
- // src/bip32/in-memory-bip32.ts
24438
+ // src/bip32/cardano-in-memory-bip32.ts
24439
24439
  import {
24440
24440
  Bip32PrivateKey,
24441
24441
  ready
@@ -24699,7 +24699,7 @@ function genBech32(encoding) {
24699
24699
  }
24700
24700
  var bech32 = /* @__PURE__ */ genBech32("bech32");
24701
24701
 
24702
- // src/bip32/in-memory-bip32.ts
24702
+ // src/bip32/cardano-in-memory-bip32.ts
24703
24703
  var import_bip39 = __toESM(require_src(), 1);
24704
24704
 
24705
24705
  // src/cardano/utils/constants.ts
@@ -24724,9 +24724,6 @@ var DEFAULT_DREP_KEY_DERIVATION_PATH = [
24724
24724
 
24725
24725
  // src/interfaces/secret-manager.ts
24726
24726
  var derivationPathVectorFromString = (path) => {
24727
- if (!/^m?\/\d+(\/\d+)*$/.test(path)) {
24728
- throw new Error(`Invalid derivation path: ${path}`);
24729
- }
24730
24727
  let pathString = path;
24731
24728
  if (pathString.startsWith("m/")) {
24732
24729
  pathString = pathString.slice(2);
@@ -24739,6 +24736,15 @@ var derivationPathVectorFromString = (path) => {
24739
24736
  }
24740
24737
  });
24741
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
+ };
24742
24748
 
24743
24749
  // src/signer/base-signer.ts
24744
24750
  import { setInConwayEra } from "@cardano-sdk/core";
@@ -24823,8 +24829,8 @@ var BaseSigner = class _BaseSigner {
24823
24829
  }
24824
24830
  };
24825
24831
 
24826
- // src/bip32/in-memory-bip32.ts
24827
- var InMemoryBip32 = class _InMemoryBip32 {
24832
+ // src/bip32/cardano-in-memory-bip32.ts
24833
+ var CardanoInMemoryBip32 = class _CardanoInMemoryBip32 {
24828
24834
  constructor(privateKey) {
24829
24835
  this.bip32PrivateKey = privateKey;
24830
24836
  }
@@ -24835,7 +24841,7 @@ var InMemoryBip32 = class _InMemoryBip32 {
24835
24841
  Buffer.from(entropy, "hex"),
24836
24842
  password || ""
24837
24843
  );
24838
- return new _InMemoryBip32(bip32PrivateKey);
24844
+ return new _CardanoInMemoryBip32(bip32PrivateKey);
24839
24845
  }
24840
24846
  static async fromEntropy(entropy, password) {
24841
24847
  await ready();
@@ -24843,18 +24849,18 @@ var InMemoryBip32 = class _InMemoryBip32 {
24843
24849
  Buffer.from(entropy, "hex"),
24844
24850
  password || ""
24845
24851
  );
24846
- return new _InMemoryBip32(bip32PrivateKey);
24852
+ return new _CardanoInMemoryBip32(bip32PrivateKey);
24847
24853
  }
24848
24854
  static fromKeyHex(keyHex) {
24849
24855
  const bip32PrivateKey = Bip32PrivateKey.fromHex(
24850
24856
  keyHex
24851
24857
  );
24852
- return new _InMemoryBip32(bip32PrivateKey);
24858
+ return new _CardanoInMemoryBip32(bip32PrivateKey);
24853
24859
  }
24854
24860
  static fromBech32(bech323) {
24855
24861
  const bech32DecodedBytes = bech32.decodeToBytes(bech323).bytes;
24856
24862
  const bip32PrivateKey = Bip32PrivateKey.fromBytes(bech32DecodedBytes);
24857
- return new _InMemoryBip32(bip32PrivateKey);
24863
+ return new _CardanoInMemoryBip32(bip32PrivateKey);
24858
24864
  }
24859
24865
  /**
24860
24866
  * Get the Bip32 public key in hex format.
@@ -24875,6 +24881,44 @@ var InMemoryBip32 = class _InMemoryBip32 {
24875
24881
  }
24876
24882
  };
24877
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
+
24878
24922
  // src/cardano/address/cardano-address.ts
24879
24923
  import { Cardano, setInConwayEra as setInConwayEra2 } from "@cardano-sdk/core";
24880
24924
  import { Hash28ByteBase16 } from "@cardano-sdk/crypto";
@@ -25281,10 +25325,10 @@ var MeshCardanoBrowserWallet = class _MeshCardanoBrowserWallet extends CardanoBr
25281
25325
  }
25282
25326
  };
25283
25327
 
25284
- // src/cardano/wallet/mesh/cardano-base-wallet.ts
25328
+ // src/cardano/wallet/mesh/cardano-headless-wallet.ts
25285
25329
  import { Cardano as Cardano6, Serialization as Serialization6, setInConwayEra as setInConwayEra5 } from "@cardano-sdk/core";
25286
25330
 
25287
- // src/utils/value.ts
25331
+ // src/cardano/utils/value.ts
25288
25332
  import { Serialization as Serialization3 } from "@cardano-sdk/core";
25289
25333
  function mergeValue(a, b) {
25290
25334
  const ma = a.multiasset() ?? /* @__PURE__ */ new Map();
@@ -25465,7 +25509,7 @@ import {
25465
25509
  var import_bech32 = __toESM(require_dist(), 1);
25466
25510
  var import_blake2b = __toESM(require_blake2b2(), 1);
25467
25511
  var import_blakejs = __toESM(require_blakejs(), 1);
25468
- var import_bip392 = __toESM(require_src(), 1);
25512
+ var import_bip393 = __toESM(require_src(), 1);
25469
25513
  var stringToHex = (str) => Buffer.from(str, "utf8").toString("hex");
25470
25514
  var isHexString = (hex) => /^[0-9A-F]*$/i.test(hex);
25471
25515
  var SLOT_CONFIG_NETWORK = {
@@ -25882,7 +25926,11 @@ function getRequiredSignersFromWithdrawals(txBody) {
25882
25926
  const withdrawals = txBody.withdrawals();
25883
25927
  if (withdrawals) {
25884
25928
  for (const rewardAccount of withdrawals.keys()) {
25885
- 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
+ }
25886
25934
  }
25887
25935
  }
25888
25936
  return requiredSigners;
@@ -25938,7 +25986,7 @@ async function getTransactionRequiredSigners(transaction, fetcher) {
25938
25986
  return allRequiredSigners;
25939
25987
  }
25940
25988
 
25941
- // src/cardano/wallet/mesh/cardano-base-wallet.ts
25989
+ // src/cardano/wallet/mesh/cardano-headless-wallet.ts
25942
25990
  var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
25943
25991
  constructor(networkId, addressManager, walletAddressType, fetcher, submitter) {
25944
25992
  setInConwayEra5(true);
@@ -25967,9 +26015,9 @@ var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
25967
26015
  * @returns {Promise<CardanoHeadlessWallet>} A promise that resolves to a CardanoHeadlessWallet instance
25968
26016
  */
25969
26017
  static async fromBip32Root(config) {
25970
- const bip32 = InMemoryBip32.fromBech32(config.bech32);
26018
+ const bip322 = CardanoInMemoryBip32.fromBech32(config.bech32);
25971
26019
  return _CardanoHeadlessWallet.create({
25972
- addressSource: { type: "secretManager", secretManager: bip32 },
26020
+ addressSource: { type: "secretManager", secretManager: bip322 },
25973
26021
  networkId: config.networkId,
25974
26022
  walletAddressType: config.walletAddressType,
25975
26023
  fetcher: config.fetcher,
@@ -25982,9 +26030,9 @@ var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
25982
26030
  * @returns {Promise<CardanoHeadlessWallet>} A promise that resolves to a CardanoHeadlessWallet instance
25983
26031
  */
25984
26032
  static async fromBip32RootHex(config) {
25985
- const bip32 = InMemoryBip32.fromKeyHex(config.hex);
26033
+ const bip322 = CardanoInMemoryBip32.fromKeyHex(config.hex);
25986
26034
  return _CardanoHeadlessWallet.create({
25987
- addressSource: { type: "secretManager", secretManager: bip32 },
26035
+ addressSource: { type: "secretManager", secretManager: bip322 },
25988
26036
  networkId: config.networkId,
25989
26037
  walletAddressType: config.walletAddressType,
25990
26038
  fetcher: config.fetcher,
@@ -25997,12 +26045,12 @@ var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
25997
26045
  * @returns {Promise<CardanoHeadlessWallet>} A promise that resolves to a CardanoHeadlessWallet instance
25998
26046
  */
25999
26047
  static async fromMnemonic(config) {
26000
- const bip32 = await InMemoryBip32.fromMnemonic(
26048
+ const bip322 = await CardanoInMemoryBip32.fromMnemonic(
26001
26049
  config.mnemonic,
26002
26050
  config.password
26003
26051
  );
26004
26052
  return _CardanoHeadlessWallet.create({
26005
- addressSource: { type: "secretManager", secretManager: bip32 },
26053
+ addressSource: { type: "secretManager", secretManager: bip322 },
26006
26054
  networkId: config.networkId,
26007
26055
  walletAddressType: config.walletAddressType,
26008
26056
  fetcher: config.fetcher,
@@ -26273,12 +26321,12 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
26273
26321
  );
26274
26322
  }
26275
26323
  static async fromMnemonic(config) {
26276
- const bip32 = await InMemoryBip32.fromMnemonic(
26324
+ const bip322 = await CardanoInMemoryBip32.fromMnemonic(
26277
26325
  config.mnemonic,
26278
26326
  config.password
26279
26327
  );
26280
26328
  return _MeshCardanoHeadlessWallet.create({
26281
- addressSource: { type: "secretManager", secretManager: bip32 },
26329
+ addressSource: { type: "secretManager", secretManager: bip322 },
26282
26330
  networkId: config.networkId,
26283
26331
  walletAddressType: config.walletAddressType,
26284
26332
  fetcher: config.fetcher,
@@ -26286,9 +26334,9 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
26286
26334
  });
26287
26335
  }
26288
26336
  static async fromBip32Root(config) {
26289
- const bip32 = InMemoryBip32.fromBech32(config.bech32);
26337
+ const bip322 = CardanoInMemoryBip32.fromBech32(config.bech32);
26290
26338
  return _MeshCardanoHeadlessWallet.create({
26291
- addressSource: { type: "secretManager", secretManager: bip32 },
26339
+ addressSource: { type: "secretManager", secretManager: bip322 },
26292
26340
  networkId: config.networkId,
26293
26341
  walletAddressType: config.walletAddressType,
26294
26342
  fetcher: config.fetcher,
@@ -26296,9 +26344,9 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
26296
26344
  });
26297
26345
  }
26298
26346
  static async fromBip32RootHex(config) {
26299
- const bip32 = InMemoryBip32.fromKeyHex(config.hex);
26347
+ const bip322 = CardanoInMemoryBip32.fromKeyHex(config.hex);
26300
26348
  return _MeshCardanoHeadlessWallet.create({
26301
- addressSource: { type: "secretManager", secretManager: bip32 },
26349
+ addressSource: { type: "secretManager", secretManager: bip322 },
26302
26350
  networkId: config.networkId,
26303
26351
  walletAddressType: config.walletAddressType,
26304
26352
  fetcher: config.fetcher,
@@ -26491,11 +26539,12 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
26491
26539
  export {
26492
26540
  AddressType,
26493
26541
  BaseSigner,
26542
+ BitcoinInMemoryBip32,
26494
26543
  CardanoAddress,
26495
26544
  CardanoBrowserWallet,
26496
26545
  CardanoHeadlessWallet,
26546
+ CardanoInMemoryBip32,
26497
26547
  CredentialType,
26498
- InMemoryBip32,
26499
26548
  MeshCardanoBrowserWallet,
26500
26549
  MeshCardanoHeadlessWallet
26501
26550
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meshsdk/wallet",
3
- "version": "2.0.0-beta.6",
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",
@@ -49,11 +56,13 @@
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": {