mainnet-js 1.1.14 → 1.1.15

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.
@@ -7,6 +7,8 @@ import { BalanceResponse } from "./util/balanceObjectFromSatoshi";
7
7
  import { ExchangeRate } from "./rate/ExchangeRate";
8
8
  import { initProviders, disconnectProviders } from "./network/Connection";
9
9
  import { toUtxoId } from "./wallet/model";
10
+ import { Config } from "./config";
11
+ import { binToHex } from "@bitauth/libauth";
10
12
 
11
13
  beforeAll(async () => {
12
14
  await initProviders();
@@ -495,4 +497,21 @@ describe(`Test Wallet library`, () => {
495
497
  const charlieFinalBalance = await charlie.getBalance("sat");
496
498
  expect(charlieFinalBalance).toBe(0);
497
499
  });
500
+
501
+ test("Set default derivation path", async () => {
502
+ const savedDerivationPath = Config.DefaultParentDerivationPath;
503
+
504
+ const wallet = await Wallet.newRandom();
505
+ expect(wallet.parentDerivationPath).toBe("m/44'/0'/0'");
506
+ expect(wallet.derivationPath).toBe("m/44'/0'/0'/0/0");
507
+
508
+ Config.DefaultParentDerivationPath = "m/44'/145'/0'"
509
+ const otherWallet = await Wallet.newRandom();
510
+ expect(otherWallet.parentDerivationPath).toBe("m/44'/145'/0'");
511
+ expect(otherWallet.derivationPath).toBe("m/44'/145'/0'/0/0");
512
+
513
+ expect(binToHex(wallet.privateKey!)).not.toBe(binToHex(otherWallet.privateKey!));
514
+
515
+ Config.DefaultParentDerivationPath = savedDerivationPath;
516
+ });
498
517
  });
package/src/config.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export class Config {
2
2
  // enforces all token-related methods to specify tokenaddr as recepient and change cashaddr
3
3
  static EnforceCashTokenReceiptAddresses = false;
4
+ static DefaultParentDerivationPath = "m/44'/0'/0'";
4
5
  }
@@ -216,8 +216,9 @@ describe(`Wallet should function in the browser`, () => {
216
216
 
217
217
  const registry_v1 = { ...registry };
218
218
  registry_v1.extensions = { authchain: {} };
219
- const contentHash_v1 = sha256
220
- .hash(utf8ToBin(JSON.stringify(registry_v1, null, 2)));
219
+ const contentHash_v1 = sha256.hash(
220
+ utf8ToBin(JSON.stringify(registry_v1, null, 2))
221
+ );
221
222
  setupAxiosMock(
222
223
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v1.json",
223
224
  JSON.stringify(registry_v1, null, 2)
@@ -241,8 +242,9 @@ describe(`Wallet should function in the browser`, () => {
241
242
  registry_v2.extensions = {
242
243
  authchain: { 0: await bob.provider.getRawTransaction(response.txId) },
243
244
  };
244
- const contentHash_v2 = sha256
245
- .hash(utf8ToBin(JSON.stringify(registry_v2, null, 2)));
245
+ const contentHash_v2 = sha256.hash(
246
+ utf8ToBin(JSON.stringify(registry_v2, null, 2))
247
+ );
246
248
  setupAxiosMock(
247
249
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v2.json",
248
250
  JSON.stringify(registry_v2, null, 2)
@@ -265,8 +267,9 @@ describe(`Wallet should function in the browser`, () => {
265
267
  1: await bob.provider.getRawTransaction(response2.txId),
266
268
  },
267
269
  };
268
- const contentHash_v3 = sha256
269
- .hash(utf8ToBin(JSON.stringify(registry_v3, null, 2)));
270
+ const contentHash_v3 = sha256.hash(
271
+ utf8ToBin(JSON.stringify(registry_v3, null, 2))
272
+ );
270
273
  setupAxiosMock(
271
274
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v3.json",
272
275
  JSON.stringify(registry_v3, null, 2)
@@ -284,8 +287,9 @@ describe(`Wallet should function in the browser`, () => {
284
287
 
285
288
  const registry_v4 = { ...registry };
286
289
  registry_v4.extensions = {};
287
- const contentHash_v4 = sha256
288
- .hash(utf8ToBin(JSON.stringify(registry_v4, null, 2)));
290
+ const contentHash_v4 = sha256.hash(
291
+ utf8ToBin(JSON.stringify(registry_v4, null, 2))
292
+ );
289
293
  setupAxiosMock(
290
294
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v4.json",
291
295
  JSON.stringify(registry_v4, null, 2)
@@ -485,8 +485,9 @@ describe(`Test BCMR support`, () => {
485
485
 
486
486
  const registry_v1 = { ...registry };
487
487
  registry_v1.extensions = { authchain: {} };
488
- const contentHash_v1 = sha256
489
- .hash(utf8ToBin(JSON.stringify(registry_v1, null, 2)));
488
+ const contentHash_v1 = sha256.hash(
489
+ utf8ToBin(JSON.stringify(registry_v1, null, 2))
490
+ );
490
491
  setupAxiosMock(
491
492
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v1.json",
492
493
  JSON.stringify(registry_v1, null, 2)
@@ -506,8 +507,9 @@ describe(`Test BCMR support`, () => {
506
507
  registry_v2.extensions = {
507
508
  authchain: { 0: await bob.provider!.getRawTransaction(response.txId) },
508
509
  };
509
- const contentHash_v2 = sha256
510
- .hash(utf8ToBin(JSON.stringify(registry_v2, null, 2)));
510
+ const contentHash_v2 = sha256.hash(
511
+ utf8ToBin(JSON.stringify(registry_v2, null, 2))
512
+ );
511
513
  setupAxiosMock(
512
514
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v2.json",
513
515
  JSON.stringify(registry_v2, null, 2)
@@ -530,8 +532,9 @@ describe(`Test BCMR support`, () => {
530
532
  1: await bob.provider!.getRawTransaction(response2.txId),
531
533
  },
532
534
  };
533
- const contentHash_v3 = sha256
534
- .hash(utf8ToBin(JSON.stringify(registry_v3, null, 2)));
535
+ const contentHash_v3 = sha256.hash(
536
+ utf8ToBin(JSON.stringify(registry_v3, null, 2))
537
+ );
535
538
  setupAxiosMock(
536
539
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v3.json",
537
540
  JSON.stringify(registry_v3, null, 2)
@@ -549,8 +552,9 @@ describe(`Test BCMR support`, () => {
549
552
 
550
553
  const registry_v4 = { ...registry };
551
554
  registry_v4.extensions = {};
552
- const contentHash_v4 = sha256
553
- .hash(utf8ToBin(JSON.stringify(registry_v4, null, 2)));
555
+ const contentHash_v4 = sha256.hash(
556
+ utf8ToBin(JSON.stringify(registry_v4, null, 2))
557
+ );
554
558
  setupAxiosMock(
555
559
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v4.json",
556
560
  JSON.stringify(registry_v4, null, 2)
package/src/wallet/Wif.ts CHANGED
@@ -115,6 +115,7 @@ import { IdentitySnapshot, Registry } from "./bcmr-v2.schema.js";
115
115
  import { BCMR } from "./Bcmr.js";
116
116
  import { qrAddress } from "../qr/Qr.js";
117
117
  import { ImageI } from "../qr/interface.js";
118
+ import { Config } from "../config.js";
118
119
 
119
120
  //#endregion Imports
120
121
 
@@ -124,8 +125,8 @@ import { ImageI } from "../qr/interface.js";
124
125
  export class Wallet extends BaseWallet {
125
126
  cashaddr?: string;
126
127
  tokenaddr?: string;
127
- derivationPath: string = "m/44'/0'/0'/0/0";
128
- parentDerivationPath: string = "m/44'/0'/0'";
128
+ derivationPath: string = Config.DefaultParentDerivationPath + "/0/0";
129
+ parentDerivationPath: string = Config.DefaultParentDerivationPath;
129
130
  parentXPubKey?: string;
130
131
  privateKey?: Uint8Array;
131
132
  publicKeyCompressed?: Uint8Array;