mainnet-js 2.7.34 → 3.0.0-next.1

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.
Files changed (195) hide show
  1. package/dist/index.html +1 -1
  2. package/dist/{mainnet-2.7.34.js → mainnet-3.0.0-next.1.js} +728 -708
  3. package/dist/module/cache/MemoryCache.d.ts +0 -1
  4. package/dist/module/cache/MemoryCache.d.ts.map +1 -1
  5. package/dist/module/cache/MemoryCache.js +5 -7
  6. package/dist/module/cache/MemoryCache.js.map +1 -1
  7. package/dist/module/cache/index.d.ts +1 -0
  8. package/dist/module/cache/index.d.ts.map +1 -1
  9. package/dist/module/cache/index.js +1 -0
  10. package/dist/module/cache/index.js.map +1 -1
  11. package/dist/module/cache/walletCache.d.ts +45 -0
  12. package/dist/module/cache/walletCache.d.ts.map +1 -0
  13. package/dist/module/cache/walletCache.js +140 -0
  14. package/dist/module/cache/walletCache.js.map +1 -0
  15. package/dist/module/chain.d.ts +1 -1
  16. package/dist/module/chain.js +1 -1
  17. package/dist/module/chain.js.map +1 -1
  18. package/dist/module/constant.d.ts +1 -1
  19. package/dist/module/constant.d.ts.map +1 -1
  20. package/dist/module/constant.js +1 -1
  21. package/dist/module/constant.js.map +1 -1
  22. package/dist/module/enum.d.ts +1 -7
  23. package/dist/module/enum.d.ts.map +1 -1
  24. package/dist/module/enum.js +0 -6
  25. package/dist/module/enum.js.map +1 -1
  26. package/dist/module/history/{electrumTransformer.d.ts → getHistory.d.ts} +3 -3
  27. package/dist/module/history/getHistory.d.ts.map +1 -0
  28. package/dist/module/history/{electrumTransformer.js → getHistory.js} +17 -14
  29. package/dist/module/history/getHistory.js.map +1 -0
  30. package/dist/module/index.d.ts +3 -1
  31. package/dist/module/index.d.ts.map +1 -1
  32. package/dist/module/index.js +3 -1
  33. package/dist/module/index.js.map +1 -1
  34. package/dist/module/interface.d.ts +7 -2
  35. package/dist/module/interface.d.ts.map +1 -1
  36. package/dist/module/interface.js.map +1 -1
  37. package/dist/module/message/interface.d.ts +2 -2
  38. package/dist/module/message/interface.d.ts.map +1 -1
  39. package/dist/module/message/interface.js +0 -3
  40. package/dist/module/message/interface.js.map +1 -1
  41. package/dist/module/message/signed.d.ts +5 -5
  42. package/dist/module/message/signed.d.ts.map +1 -1
  43. package/dist/module/message/signed.js +8 -8
  44. package/dist/module/message/signed.js.map +1 -1
  45. package/dist/module/network/ElectrumNetworkProvider.d.ts +2 -2
  46. package/dist/module/network/ElectrumNetworkProvider.d.ts.map +1 -1
  47. package/dist/module/network/ElectrumNetworkProvider.js +3 -2
  48. package/dist/module/network/ElectrumNetworkProvider.js.map +1 -1
  49. package/dist/module/network/NetworkProvider.d.ts +2 -2
  50. package/dist/module/network/NetworkProvider.d.ts.map +1 -1
  51. package/dist/module/network/constant.js +4 -4
  52. package/dist/module/network/constant.js.map +1 -1
  53. package/dist/module/network/getRelayFeeCache.js +2 -2
  54. package/dist/module/network/getRelayFeeCache.js.map +1 -1
  55. package/dist/module/rate/ExchangeRate.d.ts +2 -1
  56. package/dist/module/rate/ExchangeRate.d.ts.map +1 -1
  57. package/dist/module/rate/ExchangeRate.js +4 -1
  58. package/dist/module/rate/ExchangeRate.js.map +1 -1
  59. package/dist/module/transaction/Wif.d.ts +25 -23
  60. package/dist/module/transaction/Wif.d.ts.map +1 -1
  61. package/dist/module/transaction/Wif.js +26 -25
  62. package/dist/module/transaction/Wif.js.map +1 -1
  63. package/dist/module/transaction/allocateFee.d.ts +3 -3
  64. package/dist/module/transaction/allocateFee.d.ts.map +1 -1
  65. package/dist/module/transaction/allocateFee.js +5 -6
  66. package/dist/module/transaction/allocateFee.js.map +1 -1
  67. package/dist/module/util/amountInSatoshi.d.ts +1 -1
  68. package/dist/module/util/amountInSatoshi.d.ts.map +1 -1
  69. package/dist/module/util/amountInSatoshi.js +3 -9
  70. package/dist/module/util/amountInSatoshi.js.map +1 -1
  71. package/dist/module/util/asSendRequestObject.d.ts.map +1 -1
  72. package/dist/module/util/asSendRequestObject.js +10 -7
  73. package/dist/module/util/asSendRequestObject.js.map +1 -1
  74. package/dist/module/util/checkUtxos.d.ts +2 -2
  75. package/dist/module/util/checkUtxos.d.ts.map +1 -1
  76. package/dist/module/util/checkUtxos.js +11 -12
  77. package/dist/module/util/checkUtxos.js.map +1 -1
  78. package/dist/module/util/convert.d.ts +3 -0
  79. package/dist/module/util/convert.d.ts.map +1 -1
  80. package/dist/module/util/convert.js +12 -0
  81. package/dist/module/util/convert.js.map +1 -1
  82. package/dist/module/util/deriveCashaddr.d.ts.map +1 -1
  83. package/dist/module/util/deriveCashaddr.js +6 -0
  84. package/dist/module/util/deriveCashaddr.js.map +1 -1
  85. package/dist/module/util/deriveNetwork.js +1 -1
  86. package/dist/module/util/deriveNetwork.js.map +1 -1
  87. package/dist/module/util/hd.d.ts +3 -0
  88. package/dist/module/util/hd.d.ts.map +1 -0
  89. package/dist/module/util/hd.js +11 -0
  90. package/dist/module/util/hd.js.map +1 -0
  91. package/dist/module/util/index.d.ts +3 -3
  92. package/dist/module/util/index.d.ts.map +1 -1
  93. package/dist/module/util/index.js +3 -3
  94. package/dist/module/util/index.js.map +1 -1
  95. package/dist/module/util/satoshiToAmount.d.ts +1 -1
  96. package/dist/module/util/satoshiToAmount.d.ts.map +1 -1
  97. package/dist/module/util/satoshiToAmount.js +3 -9
  98. package/dist/module/util/satoshiToAmount.js.map +1 -1
  99. package/dist/module/util/sumSendRequestAmounts.d.ts.map +1 -1
  100. package/dist/module/util/sumSendRequestAmounts.js +3 -4
  101. package/dist/module/util/sumSendRequestAmounts.js.map +1 -1
  102. package/dist/module/util/sumUtxoValue.d.ts +3 -3
  103. package/dist/module/util/sumUtxoValue.d.ts.map +1 -1
  104. package/dist/module/util/sumUtxoValue.js +2 -2
  105. package/dist/module/util/sumUtxoValue.js.map +1 -1
  106. package/dist/module/wallet/Base.d.ts +45 -103
  107. package/dist/module/wallet/Base.d.ts.map +1 -1
  108. package/dist/module/wallet/Base.js +99 -298
  109. package/dist/module/wallet/Base.js.map +1 -1
  110. package/dist/module/wallet/HDWallet.d.ts +164 -0
  111. package/dist/module/wallet/HDWallet.d.ts.map +1 -0
  112. package/dist/module/wallet/HDWallet.js +486 -0
  113. package/dist/module/wallet/HDWallet.js.map +1 -0
  114. package/dist/module/wallet/Util.js +1 -1
  115. package/dist/module/wallet/Util.js.map +1 -1
  116. package/dist/module/wallet/Watch.d.ts +151 -0
  117. package/dist/module/wallet/Watch.d.ts.map +1 -0
  118. package/dist/module/wallet/Watch.js +307 -0
  119. package/dist/module/wallet/Watch.js.map +1 -0
  120. package/dist/module/wallet/Wif.d.ts +23 -29
  121. package/dist/module/wallet/Wif.d.ts.map +1 -1
  122. package/dist/module/wallet/Wif.js +204 -267
  123. package/dist/module/wallet/Wif.js.map +1 -1
  124. package/dist/module/wallet/createWallet.d.ts +7 -1
  125. package/dist/module/wallet/createWallet.d.ts.map +1 -1
  126. package/dist/module/wallet/createWallet.js +26 -17
  127. package/dist/module/wallet/createWallet.js.map +1 -1
  128. package/dist/module/wallet/interface.d.ts +5 -6
  129. package/dist/module/wallet/interface.d.ts.map +1 -1
  130. package/dist/module/wallet/model.d.ts +15 -19
  131. package/dist/module/wallet/model.d.ts.map +1 -1
  132. package/dist/module/wallet/model.js +5 -25
  133. package/dist/module/wallet/model.js.map +1 -1
  134. package/dist/tsconfig.tsbuildinfo +1 -1
  135. package/package.json +1 -1
  136. package/src/cache/MemoryCache.ts +5 -5
  137. package/src/cache/index.ts +1 -0
  138. package/src/cache/walletCache.ts +239 -0
  139. package/src/chain.ts +1 -1
  140. package/src/constant.ts +1 -1
  141. package/src/enum.ts +0 -6
  142. package/src/history/{electrumTransformer.test.ts → getHistory.test.ts} +26 -53
  143. package/src/history/{electrumTransformer.ts → getHistory.ts} +31 -15
  144. package/src/index.ts +3 -1
  145. package/src/interface.ts +8 -2
  146. package/src/message/interface.ts +2 -28
  147. package/src/message/signed.test.ts +36 -48
  148. package/src/message/signed.ts +9 -12
  149. package/src/network/Connection.test.ts +3 -3
  150. package/src/network/ElectrumNetworkProvider.ts +5 -5
  151. package/src/network/NetworkProvider.ts +2 -2
  152. package/src/network/Rpc.test.ts +3 -4
  153. package/src/network/constant.ts +4 -4
  154. package/src/network/getRelayFeeCache.ts +2 -2
  155. package/src/rate/ExchangeRate.test.ts +2 -44
  156. package/src/rate/ExchangeRate.ts +5 -2
  157. package/src/transaction/Wif.ts +59 -52
  158. package/src/transaction/allocateFee.test.ts +110 -131
  159. package/src/transaction/allocateFee.ts +14 -15
  160. package/src/util/amountInSatoshi.test.ts +1 -9
  161. package/src/util/amountInSatoshi.ts +6 -10
  162. package/src/util/asSendRequestObject.ts +12 -7
  163. package/src/util/checkUtxos.ts +21 -26
  164. package/src/util/convert.ts +18 -0
  165. package/src/util/deriveCashaddr.ts +8 -0
  166. package/src/util/deriveNetwork.ts +1 -1
  167. package/src/util/derivePublicKeyHash.test.ts +0 -13
  168. package/src/util/hd.ts +16 -0
  169. package/src/util/index.ts +3 -7
  170. package/src/util/satoshiToAmount.test.ts +1 -1
  171. package/src/util/satoshiToAmount.ts +4 -10
  172. package/src/util/sumSendRequestAmounts.ts +3 -4
  173. package/src/util/sumUtxoValue.ts +7 -7
  174. package/src/wallet/Base.ts +147 -420
  175. package/src/wallet/Cashtokens.test.headless.js +11 -11
  176. package/src/wallet/Cashtokens.test.ts +36 -37
  177. package/src/wallet/HDWallet.test.ts +515 -0
  178. package/src/wallet/HDWallet.ts +764 -0
  179. package/src/wallet/Util.ts +1 -1
  180. package/src/wallet/Watch.ts +447 -0
  181. package/src/wallet/Wif.bip39.test.ts +1 -1
  182. package/src/wallet/Wif.test.ts +108 -133
  183. package/src/wallet/Wif.ts +258 -283
  184. package/src/wallet/createWallet.ts +28 -18
  185. package/src/wallet/interface.ts +5 -6
  186. package/src/wallet/model.test.ts +4 -7
  187. package/src/wallet/model.ts +19 -51
  188. package/dist/module/history/electrumTransformer.d.ts.map +0 -1
  189. package/dist/module/history/electrumTransformer.js.map +0 -1
  190. package/dist/module/util/balanceObjectFromSatoshi.d.ts +0 -8
  191. package/dist/module/util/balanceObjectFromSatoshi.d.ts.map +0 -1
  192. package/dist/module/util/balanceObjectFromSatoshi.js +0 -35
  193. package/dist/module/util/balanceObjectFromSatoshi.js.map +0 -1
  194. package/src/util/balanceObjectFromSatoshi.test.ts +0 -58
  195. package/src/util/balanceObjectFromSatoshi.ts +0 -52
@@ -1,7 +1,5 @@
1
1
  import { RegTestWallet, TestNetWallet, Wallet } from "./Wif";
2
2
  import { bchParam } from "../chain";
3
- import { BalanceResponse } from "../util/balanceObjectFromSatoshi";
4
- import { UnitEnum } from "../enum";
5
3
  import { initProviders, disconnectProviders } from "../network/Connection";
6
4
  import { DERIVATION_PATHS, DUST_UTXO_THRESHOLD as DUST } from "../constant";
7
5
  import { delay } from "../util/delay";
@@ -19,6 +17,7 @@ import { mine } from "../mine";
19
17
  import { Config } from "../config";
20
18
  import { CancelFn } from "./interface";
21
19
  import json from "../test/json.test";
20
+ import { convert, toBch, toCurrency, toSat } from "../util";
22
21
 
23
22
  beforeAll(async () => {
24
23
  await initProviders();
@@ -423,8 +422,7 @@ describe(`Watch only Wallets`, () => {
423
422
  }
424
423
 
425
424
  // the balance unit may also be empty
426
- let unit;
427
- expect(((await w.getBalance(unit)) as BalanceResponse).sat).toBe(0);
425
+ expect(await w.getBalance()).toBe(0n);
428
426
  expect(w.network).toBe("regtest");
429
427
  expect(w.networkPrefix).toBe("bchreg");
430
428
  expect(w.cashaddr).toBe(
@@ -451,10 +449,10 @@ describe(`Watch only Wallets`, () => {
451
449
  let alice = await RegTestWallet.watchOnly(process.env.ADDRESS); // insert WIF from #1
452
450
  // Build Bob's wallet from a public address, check his balance.
453
451
  expect(alice.getPublicKeyHash()!.length).toBe(20);
454
- const aliceBalance = (await alice.getBalance()) as BalanceResponse;
455
- expect(aliceBalance.bch).toBeGreaterThan(5000);
456
- expect(await alice.getBalance("sat")).toBeGreaterThan(
457
- 5000 * bchParam.subUnits
452
+ const aliceBalance = await alice.getBalance();
453
+ expect(toBch(aliceBalance)).toBeGreaterThan(5000);
454
+ expect(await alice.getBalance()).toBeGreaterThan(
455
+ 5000n * bchParam.subUnits
458
456
  );
459
457
  }
460
458
  });
@@ -468,10 +466,17 @@ describe(`Watch only Wallets`, () => {
468
466
  let alice = await RegTestWallet.watchOnly(process.env.ADDRESS); // insert WIF from #1
469
467
  // Build Bob's wallet from a public address, check his balance.
470
468
  expect(alice.getPublicKeyHash()!.length).toBe(20);
471
- const aliceBalance = (await alice.getBalance()) as BalanceResponse;
472
- expect(aliceBalance.bch).toBeGreaterThan(5000);
473
- expect(await alice.getBalance("eur")).toBeGreaterThan(0);
474
- expect(await (await RegTestWallet.newRandom()).getBalance("eur")).toBe(0);
469
+ const aliceBalance = await alice.getBalance();
470
+ expect(toBch(aliceBalance)).toBeGreaterThan(5000);
471
+ expect(await toCurrency(await alice.getBalance(), "eur")).toBeGreaterThan(
472
+ 0
473
+ );
474
+ expect(
475
+ await toCurrency(
476
+ await (await RegTestWallet.newRandom()).getBalance(),
477
+ "eur"
478
+ )
479
+ ).toBe(0);
475
480
  Config.DefaultCurrency = "usd";
476
481
  }
477
482
  });
@@ -486,9 +491,9 @@ describe(`Watch only Wallets`, () => {
486
491
  // Build Bob's wallet from a public address, check his balance.
487
492
  expect(alice.getPublicKeyHash()!.length).toBe(20);
488
493
  let aliceBalance = await alice.send([
489
- { cashaddr: alice.cashaddr!, value: 720, unit: "sat" },
494
+ { cashaddr: alice.cashaddr!, value: 720n },
490
495
  ]);
491
- expect(aliceBalance.balance!.sat!).toBeGreaterThan(5000);
496
+ expect(aliceBalance.balance).toBeGreaterThan(5000n);
492
497
  }
493
498
  });
494
499
 
@@ -501,8 +506,8 @@ describe(`Watch only Wallets`, () => {
501
506
  process.env.ALICE_TESTNET_ADDRESS!
502
507
  ); // insert WIF from #1
503
508
  // Build Bob's wallet from a public address, check his balance.
504
- const aliceBalance = (await alice.getBalance()) as BalanceResponse;
505
- expect(aliceBalance.sat).toBeGreaterThan(2000);
509
+ const aliceBalance = await alice.getBalance();
510
+ expect(aliceBalance).toBeGreaterThan(2000n);
506
511
  }
507
512
  });
508
513
 
@@ -514,8 +519,7 @@ describe(`Watch only Wallets`, () => {
514
519
  const { encodedTransaction } = await aliceWallet.encodeTransaction([
515
520
  {
516
521
  cashaddr: bobWallet.cashaddr!,
517
- value: 2000,
518
- unit: "satoshis",
522
+ value: 2000n,
519
523
  },
520
524
  ]);
521
525
  expect(encodedTransaction.length).toBeGreaterThan(0);
@@ -523,7 +527,7 @@ describe(`Watch only Wallets`, () => {
523
527
  const txId = await aliceWallet.submitTransaction(encodedTransaction, true);
524
528
  expect(txId.length).toBeGreaterThan(0);
525
529
 
526
- expect(await bobWallet.getBalance("sat")).toBe(2000);
530
+ expect(await bobWallet.getBalance()).toBe(2000n);
527
531
  });
528
532
 
529
533
  test("Should get last transaction", async () => {
@@ -536,8 +540,7 @@ describe(`Watch only Wallets`, () => {
536
540
  await aliceWallet.send([
537
541
  {
538
542
  cashaddr: bobWallet.cashaddr!,
539
- value: 2000,
540
- unit: "satoshis",
543
+ value: 2000n,
541
544
  },
542
545
  ]);
543
546
 
@@ -555,8 +558,7 @@ describe(`Wallet subscriptions`, () => {
555
558
  aliceWallet.send([
556
559
  {
557
560
  cashaddr: bobWallet.cashaddr!,
558
- value: 1000,
559
- unit: "satoshis",
561
+ value: 1000n,
560
562
  },
561
563
  ]),
562
564
  0
@@ -566,7 +568,7 @@ describe(`Wallet subscriptions`, () => {
566
568
  getTransactionInfo: true,
567
569
  getBalance: true,
568
570
  });
569
- expect(response.balance!.sat).toBeGreaterThan(0);
571
+ expect(response.balance).toBeGreaterThan(0);
570
572
  expect(response.transactionInfo!.hash).not.toBe("");
571
573
 
572
574
  await bobWallet.sendMax(aliceWallet.cashaddr!);
@@ -577,66 +579,63 @@ describe(`Wallet subscriptions`, () => {
577
579
  const bobWallet = await RegTestWallet.newRandom();
578
580
 
579
581
  let balance, newBalance;
580
- balance = await aliceWallet.getBalance("sat");
582
+ balance = await aliceWallet.getBalance();
581
583
 
582
584
  aliceWallet.send(
583
585
  [
584
586
  {
585
587
  cashaddr: bobWallet.cashaddr!,
586
- value: 1000,
587
- unit: "satoshis",
588
+ value: 1000n,
588
589
  },
589
590
  ],
590
591
  { awaitTransactionPropagation: false }
591
592
  );
592
- newBalance = await aliceWallet.getBalance("sat");
593
+ newBalance = await aliceWallet.getBalance();
593
594
  expect(balance).toBe(newBalance);
594
595
 
595
596
  await delay(1500);
596
597
 
597
- balance = await aliceWallet.getBalance("sat");
598
+ balance = await aliceWallet.getBalance();
598
599
  await aliceWallet.send(
599
600
  [
600
601
  {
601
602
  cashaddr: bobWallet.cashaddr!,
602
- value: 1000,
603
- unit: "satoshis",
603
+ value: 1000n,
604
604
  },
605
605
  ],
606
606
  { awaitTransactionPropagation: false }
607
607
  );
608
608
 
609
- newBalance = await aliceWallet.getBalance("sat");
609
+ newBalance = await aliceWallet.getBalance();
610
610
  expect(balance).toBe(newBalance);
611
611
 
612
- balance = await aliceWallet.getBalance("sat");
612
+ balance = await aliceWallet.getBalance();
613
613
  await aliceWallet.send(
614
614
  [
615
615
  {
616
616
  cashaddr: bobWallet.cashaddr!,
617
- value: 1000,
618
- unit: "satoshis",
617
+ value: 1000n,
619
618
  },
620
619
  ],
621
620
  { awaitTransactionPropagation: true }
622
621
  );
623
622
 
624
- newBalance = await aliceWallet.getBalance("sat");
623
+ newBalance = await aliceWallet.getBalance();
625
624
  expect(balance).toBeGreaterThan(newBalance);
626
625
  });
627
626
 
628
627
  test("Create two wallets, get balances concurrently", async () => {
629
- let balance1 = 999,
630
- balance2 = 666;
628
+ let balance1 = 999n;
629
+ let balance2 = 666n;
631
630
  Wallet.newRandom().then((wallet) =>
632
- wallet.getBalance("sat").then((balance) => (balance1 = balance as number))
631
+ wallet.getBalance().then((balance) => (balance1 = balance))
633
632
  );
634
633
  Wallet.newRandom().then((wallet) =>
635
- wallet.getBalance("sat").then((balance) => (balance2 = balance as number))
634
+ wallet.getBalance().then((balance) => (balance2 = balance))
636
635
  );
637
636
  await delay(5000);
638
- expect(balance1).toBe(0);
639
- expect(balance2).toBe(0);
637
+ expect(balance1).toBe(0n);
638
+ expect(balance2).toBe(0n);
640
639
  });
641
640
 
642
641
  test("Should watch then wait", async () => {
@@ -655,13 +654,12 @@ describe(`Wallet subscriptions`, () => {
655
654
  aliceWallet.send([
656
655
  {
657
656
  cashaddr: bobWallet.cashaddr!,
658
- value: 2000,
659
- unit: "satoshis",
657
+ value: 2000n,
660
658
  },
661
659
  ]);
662
660
 
663
- let balance = await bobWallet.waitForBalance(2000, UnitEnum.SATOSHIS);
664
- expect(balance.sat!).toBeGreaterThanOrEqual(2000);
661
+ let balance = await bobWallet.waitForBalance(2000n);
662
+ expect(balance).toBeGreaterThanOrEqual(2000n);
665
663
  await bobWallet.sendMax(aliceWallet.cashaddr!);
666
664
  });
667
665
 
@@ -672,14 +670,13 @@ describe(`Wallet subscriptions`, () => {
672
670
  alice.send([
673
671
  {
674
672
  cashaddr: bob.cashaddr!,
675
- value: 2000,
676
- unit: "satoshis",
673
+ value: 2000n,
677
674
  },
678
675
  ]);
679
676
 
680
677
  let cancel = await bob.watchBalance(() => {});
681
- let balance = await bob.waitForBalance(2000, "sat");
682
- expect(balance.sat!).toBe(2000);
678
+ let balance = await bob.waitForBalance(2000n);
679
+ expect(balance).toBe(2000n);
683
680
  await cancel();
684
681
  });
685
682
 
@@ -695,14 +692,13 @@ describe(`Wallet subscriptions`, () => {
695
692
  alice.send([
696
693
  {
697
694
  cashaddr: bob.cashaddr!,
698
- value: 1000,
699
- unit: "satoshis",
695
+ value: 1000n,
700
696
  },
701
697
  ]),
702
698
  600
703
699
  );
704
700
 
705
- let bobBalance = await bob.waitForBalance(1000, "sat").catch((e) => {
701
+ let bobBalance = await bob.waitForBalance(1000n).catch((e) => {
706
702
  throw e;
707
703
  });
708
704
  setTimeout(
@@ -710,35 +706,32 @@ describe(`Wallet subscriptions`, () => {
710
706
  alice.send([
711
707
  {
712
708
  cashaddr: charlie.cashaddr!,
713
- value: 1000,
714
- unit: "satoshis",
709
+ value: 1000n,
715
710
  },
716
711
  ]),
717
712
  600
718
713
  );
719
- let charlieBalance = await charlie.waitForBalance(1000, "sat");
714
+ let charlieBalance = await charlie.waitForBalance(1000n);
720
715
  setTimeout(
721
716
  () =>
722
717
  alice.send([
723
718
  {
724
719
  cashaddr: dave.cashaddr!,
725
- value: 1000,
726
- unit: "satoshis",
720
+ value: 1000n,
727
721
  },
728
722
  ]),
729
723
  600
730
724
  );
731
- let daveBalance = await dave.waitForBalance(1000, "sat");
732
- expect(bobBalance.sat!).toBe(1000);
733
- expect(charlieBalance.sat!).toBe(1000);
734
- expect(daveBalance.sat!).toBe(1000);
725
+ let daveBalance = await dave.waitForBalance(1000n);
726
+ expect(bobBalance).toBe(1000n);
727
+ expect(charlieBalance).toBe(1000n);
728
+ expect(daveBalance).toBe(1000n);
735
729
  setTimeout(
736
730
  () =>
737
731
  alice.send([
738
732
  {
739
733
  cashaddr: bob.cashaddr!,
740
- value: 1000,
741
- unit: "satoshis",
734
+ value: 1000n,
742
735
  },
743
736
  ]),
744
737
  600
@@ -750,8 +743,7 @@ describe(`Wallet subscriptions`, () => {
750
743
  alice.send([
751
744
  {
752
745
  cashaddr: bob.cashaddr!,
753
- value: 1000,
754
- unit: "satoshis",
746
+ value: 1000n,
755
747
  },
756
748
  ]),
757
749
  600
@@ -763,15 +755,14 @@ describe(`Wallet subscriptions`, () => {
763
755
  alice.send([
764
756
  {
765
757
  cashaddr: bob.cashaddr!,
766
- value: 1000,
767
- unit: "satoshis",
758
+ value: 1000n,
768
759
  },
769
760
  ]),
770
761
  600
771
762
  );
772
763
  bobResponse = await bob.waitForTransaction();
773
764
  expect(bobResponse.transactionInfo!.version).toBe(2);
774
- expect(await bob.getBalance("sat")).toBe(4000);
765
+ expect(await bob.getBalance()).toBe(4000n);
775
766
  });
776
767
 
777
768
  test("Test waiting and watching", async () => {
@@ -785,18 +776,15 @@ describe(`Wallet subscriptions`, () => {
785
776
  getBalance: true,
786
777
  getTransactionInfo: true,
787
778
  });
788
- expect(result.balance!.sat!).toBeGreaterThan(0);
779
+ expect(result.balance!).toBeGreaterThan(0);
789
780
  expect(result.transactionInfo!.hash.length).toBe(64);
790
781
  waitTxResult = true;
791
782
  }, 0);
792
783
 
793
784
  let waitBalanceResult = false;
794
785
  setTimeout(async () => {
795
- const result = (await alice.waitForBalance(
796
- 0.001,
797
- "bch"
798
- )) as BalanceResponse;
799
- expect(result.sat!).toBeGreaterThan(0);
786
+ const result = await alice.waitForBalance(toSat(0.001));
787
+ expect(result).toBeGreaterThan(0n);
800
788
  waitBalanceResult = true;
801
789
  }, 0);
802
790
 
@@ -823,11 +811,11 @@ describe(`Wallet subscriptions`, () => {
823
811
  let bobBalanceWatchCancel: CancelFn;
824
812
  bobBalanceWatchCancel = await bob.watchBalance(async (balance) => {
825
813
  // skip if balance is zero yet
826
- if (!balance.bch) {
814
+ if (!balance) {
827
815
  return;
828
816
  }
829
817
 
830
- expect(balance.bch!).toBe(0.001);
818
+ expect(balance).toBe(toSat(0.001));
831
819
  await bobBalanceWatchCancel?.();
832
820
  bobBalanceWatchResult = true;
833
821
  });
@@ -858,8 +846,7 @@ describe(`Wallet subscriptions`, () => {
858
846
 
859
847
  const sendResponse = await alice.send({
860
848
  cashaddr: bob.getDepositAddress(),
861
- value: 0.001,
862
- unit: "bch",
849
+ value: BigInt(await convert(0.001, "bch", "sat")),
863
850
  });
864
851
 
865
852
  await mine({ cashaddr: alice.cashaddr!, blocks: 1 });
@@ -881,7 +868,7 @@ describe(`Wallet subscriptions`, () => {
881
868
 
882
869
  describe(`Wallet extrema behavior regression testing`, () => {
883
870
  test(`Should operate very well above dust threshold (${
884
- DUST * 3
871
+ DUST * 3n
885
872
  }), 'min relay fee not met (code 66)' regression`, async () => {
886
873
  const aliceWif = `wif:regtest:${process.env.PRIVATE_WIF!}`;
887
874
  const aliceWallet = await RegTestWallet.fromId(aliceWif);
@@ -889,20 +876,19 @@ describe(`Wallet extrema behavior regression testing`, () => {
889
876
  const charlieWallet = await RegTestWallet.newRandom();
890
877
 
891
878
  await aliceWallet.send([
892
- { cashaddr: bobWallet.cashaddr!, value: DUST, unit: "sat" },
893
- { cashaddr: bobWallet.cashaddr!, value: DUST * 3, unit: "sat" },
879
+ { cashaddr: bobWallet.cashaddr!, value: DUST },
880
+ { cashaddr: bobWallet.cashaddr!, value: DUST * 3n },
894
881
  ]);
895
882
 
896
883
  await bobWallet.send({
897
884
  cashaddr: charlieWallet.cashaddr!,
898
885
  value: DUST,
899
- unit: "sat",
900
886
  });
901
- expect(await charlieWallet.getBalance("sat")).toBe(DUST);
887
+ expect(await charlieWallet.getBalance()).toBe(DUST);
902
888
  });
903
889
 
904
890
  test(`Should operate very well above dust threshold (${
905
- DUST * 2
891
+ DUST * 2n
906
892
  }), 'min relay fee not met (code 66)' regression`, async () => {
907
893
  const aliceWif = `wif:regtest:${process.env.PRIVATE_WIF!}`;
908
894
  const aliceWallet = await RegTestWallet.fromId(aliceWif);
@@ -910,20 +896,19 @@ describe(`Wallet extrema behavior regression testing`, () => {
910
896
  const charlieWallet = await RegTestWallet.newRandom();
911
897
 
912
898
  await aliceWallet.send([
913
- { cashaddr: bobWallet.cashaddr!, value: DUST, unit: "sat" },
914
- { cashaddr: bobWallet.cashaddr!, value: DUST * 2, unit: "sat" },
899
+ { cashaddr: bobWallet.cashaddr!, value: DUST },
900
+ { cashaddr: bobWallet.cashaddr!, value: DUST * 2n },
915
901
  ]);
916
902
 
917
903
  await bobWallet.send({
918
904
  cashaddr: charlieWallet.cashaddr!,
919
905
  value: DUST,
920
- unit: "sat",
921
906
  });
922
- expect(await charlieWallet.getBalance("sat")).toBe(DUST);
907
+ expect(await charlieWallet.getBalance()).toBe(DUST);
923
908
  });
924
909
 
925
910
  test(`Should operate well above dust threshold (${
926
- DUST + 328
911
+ DUST + 328n
927
912
  }), 'min relay fee not met (code 66)' regression`, async () => {
928
913
  const aliceWif = `wif:regtest:${process.env.PRIVATE_WIF!}`;
929
914
  const aliceWallet = await RegTestWallet.fromId(aliceWif);
@@ -931,18 +916,16 @@ describe(`Wallet extrema behavior regression testing`, () => {
931
916
  const charlieWallet = await RegTestWallet.newRandom();
932
917
 
933
918
  await aliceWallet.send([
934
- { cashaddr: bobWallet.cashaddr!, value: DUST, unit: "sat" },
935
- { cashaddr: bobWallet.cashaddr!, value: DUST + 328, unit: "sat" },
919
+ { cashaddr: bobWallet.cashaddr!, value: DUST },
920
+ { cashaddr: bobWallet.cashaddr!, value: DUST + 328n },
936
921
  ]);
937
922
 
938
- await bobWallet.send([
939
- { cashaddr: charlieWallet.cashaddr!, value: DUST, unit: "sat" },
940
- ]);
941
- expect(await charlieWallet.getBalance("sat")).toBe(DUST);
923
+ await bobWallet.send([{ cashaddr: charlieWallet.cashaddr!, value: DUST }]);
924
+ expect(await charlieWallet.getBalance()).toBe(DUST);
942
925
  });
943
926
 
944
927
  test(`Should operate slightly above dust threshold (${
945
- DUST + 1
928
+ DUST + 1n
946
929
  }), 'min relay fee not met (code 66)' regression`, async () => {
947
930
  const aliceWif = `wif:regtest:${process.env.PRIVATE_WIF!}`;
948
931
  const aliceWallet = await RegTestWallet.fromId(aliceWif);
@@ -950,14 +933,12 @@ describe(`Wallet extrema behavior regression testing`, () => {
950
933
  const charlieWallet = await RegTestWallet.newRandom();
951
934
 
952
935
  await aliceWallet.send([
953
- { cashaddr: bobWallet.cashaddr!, value: DUST, unit: "sat" },
954
- { cashaddr: bobWallet.cashaddr!, value: DUST + 1, unit: "sat" },
936
+ { cashaddr: bobWallet.cashaddr!, value: DUST },
937
+ { cashaddr: bobWallet.cashaddr!, value: DUST + 1n },
955
938
  ]);
956
939
 
957
- await bobWallet.send([
958
- { cashaddr: charlieWallet.cashaddr!, value: DUST, unit: "sat" },
959
- ]);
960
- expect(await charlieWallet.getBalance("sat")).toBe(DUST);
940
+ await bobWallet.send([{ cashaddr: charlieWallet.cashaddr!, value: DUST }]);
941
+ expect(await charlieWallet.getBalance()).toBe(DUST);
961
942
  });
962
943
 
963
944
  test(`Should operate with dust threshold (${DUST}), 'min relay fee not met (code 66)' regression`, async () => {
@@ -967,17 +948,15 @@ describe(`Wallet extrema behavior regression testing`, () => {
967
948
  const charlieWallet = await RegTestWallet.newRandom();
968
949
 
969
950
  await aliceWallet.send([
970
- { cashaddr: bobWallet.cashaddr!, value: DUST, unit: "sat" },
971
- { cashaddr: bobWallet.cashaddr!, value: DUST, unit: "sat" },
951
+ { cashaddr: bobWallet.cashaddr!, value: DUST },
952
+ { cashaddr: bobWallet.cashaddr!, value: DUST },
972
953
  ]);
973
954
 
974
- await bobWallet.send([
975
- { cashaddr: charlieWallet.cashaddr!, value: DUST, unit: "sat" },
976
- ]);
977
- expect(await charlieWallet.getBalance("sat")).toBe(DUST);
955
+ await bobWallet.send([{ cashaddr: charlieWallet.cashaddr!, value: DUST }]);
956
+ expect(await charlieWallet.getBalance()).toBe(DUST);
978
957
  });
979
958
  test(`Should throw error with dust amounts (${
980
- DUST - 1
959
+ DUST - 1n
981
960
  }), 'min relay fee not met (code 66)' regression`, async () => {
982
961
  expect.assertions(1);
983
962
  try {
@@ -987,12 +966,12 @@ describe(`Wallet extrema behavior regression testing`, () => {
987
966
  const charlieWallet = await RegTestWallet.newRandom();
988
967
 
989
968
  await aliceWallet.send([
990
- { cashaddr: bobWallet.cashaddr!, value: DUST, unit: "sat" },
991
- { cashaddr: bobWallet.cashaddr!, value: DUST - 1, unit: "sat" },
969
+ { cashaddr: bobWallet.cashaddr!, value: DUST },
970
+ { cashaddr: bobWallet.cashaddr!, value: DUST - 1n },
992
971
  ]);
993
972
 
994
973
  await bobWallet.send([
995
- { cashaddr: charlieWallet.cashaddr!, value: DUST, unit: "sat" },
974
+ { cashaddr: charlieWallet.cashaddr!, value: DUST },
996
975
  ]);
997
976
  } catch (e: any) {
998
977
  expect(e.message).toBe(
@@ -1007,7 +986,7 @@ describe(`Wallet extrema behavior regression testing`, () => {
1007
986
 
1008
987
  result = await wallet.send([
1009
988
  OpReturnData.from("MEMO\x10LÖL😅"),
1010
- { cashaddr: wallet.cashaddr!, value: 546, unit: "sats" },
989
+ { cashaddr: wallet.cashaddr!, value: 546n },
1011
990
  ]);
1012
991
  transaction = (await wallet.provider!.getRawTransactionObject(
1013
992
  result.txId!
@@ -1018,7 +997,7 @@ describe(`Wallet extrema behavior regression testing`, () => {
1018
997
  );
1019
998
 
1020
999
  result = await wallet.send([
1021
- [wallet.cashaddr!, 546, "sats"],
1000
+ [wallet.cashaddr!, 546n],
1022
1001
  ["OP_RETURN", Uint8Array.from([0x00, 0x01, 0x02])],
1023
1002
  ]);
1024
1003
  transaction = (await wallet.provider!.getRawTransactionObject(
@@ -1050,24 +1029,24 @@ describe(`Wallet extrema behavior regression testing`, () => {
1050
1029
  const alice = await RegTestWallet.fromId(process.env.ALICE_ID!);
1051
1030
  const bob = await RegTestWallet.newRandom();
1052
1031
  await alice.send([
1053
- { cashaddr: bob.getDepositAddress(), unit: UnitEnum.SAT, value: 546 },
1054
- { cashaddr: bob.getDepositAddress(), unit: UnitEnum.SAT, value: 1000 },
1032
+ { cashaddr: bob.getDepositAddress(), value: 546n },
1033
+ { cashaddr: bob.getDepositAddress(), value: 1000n },
1055
1034
  ]);
1056
- expect(await bob.getBalance("sat")).toBe(1546);
1035
+ expect(await bob.getBalance()).toBe(1546n);
1057
1036
  bob.slpSemiAware();
1058
- expect(await bob.getBalance("sat")).toBe(1000);
1037
+ expect(await bob.getBalance()).toBe(1000n);
1059
1038
 
1060
1039
  expect(
1061
- (await bob.getMaxAmountToSend({ options: { slpSemiAware: true } })).sat
1062
- ).toBe(768);
1040
+ await bob.getMaxAmountToSend({ options: { slpSemiAware: true } })
1041
+ ).toBe(768n);
1063
1042
  await bob.sendMax(alice.getDepositAddress());
1064
- expect(await bob.getBalance("sat")).toBe(0);
1043
+ expect(await bob.getBalance()).toBe(0n);
1065
1044
 
1066
1045
  bob.slpSemiAware(false);
1067
- expect(await bob.getBalance("sat")).toBe(546);
1046
+ expect(await bob.getBalance()).toBe(546n);
1068
1047
  expect(
1069
- (await bob.getMaxAmountToSend({ options: { slpSemiAware: false } })).sat
1070
- ).toBeLessThanOrEqual(546);
1048
+ await bob.getMaxAmountToSend({ options: { slpSemiAware: false } })
1049
+ ).toBeLessThanOrEqual(546n);
1071
1050
  });
1072
1051
 
1073
1052
  test("Should encode unsigned transactions", async () => {
@@ -1084,8 +1063,7 @@ describe(`Wallet extrema behavior regression testing`, () => {
1084
1063
  [
1085
1064
  {
1086
1065
  cashaddr: bobWallet.cashaddr!,
1087
- value: 2000,
1088
- unit: "satoshis",
1066
+ value: 2000n,
1089
1067
  },
1090
1068
  ],
1091
1069
  false,
@@ -1130,8 +1108,7 @@ describe(`Wallet extrema behavior regression testing`, () => {
1130
1108
  [
1131
1109
  {
1132
1110
  cashaddr: bobWallet.cashaddr!,
1133
- value: 2000,
1134
- unit: "satoshis",
1111
+ value: 2000n,
1135
1112
  },
1136
1113
  ],
1137
1114
  { buildUnsigned: true }
@@ -1187,8 +1164,7 @@ describe(`Wallet extrema behavior regression testing`, () => {
1187
1164
  aliceWallet.send(
1188
1165
  {
1189
1166
  cashaddr: bobWallet.cashaddr!,
1190
- value: 1000,
1191
- unit: "sat",
1167
+ value: 1000n,
1192
1168
  },
1193
1169
  { utxoIds: ["00ab:1", "00cd:2"] }
1194
1170
  )
@@ -1198,8 +1174,7 @@ describe(`Wallet extrema behavior regression testing`, () => {
1198
1174
  aliceWallet.send(
1199
1175
  {
1200
1176
  cashaddr: bobWallet.cashaddr!,
1201
- value: 1000,
1202
- unit: "sat",
1177
+ value: 1000n,
1203
1178
  },
1204
1179
  {
1205
1180
  utxoIds: [