mainnet-js 3.0.0-next.0 → 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 (118) hide show
  1. package/dist/index.html +1 -1
  2. package/dist/{mainnet-3.0.0-next.0.js → mainnet-3.0.0-next.1.js} +21 -41
  3. package/dist/module/cache/walletCache.d.ts +10 -4
  4. package/dist/module/cache/walletCache.d.ts.map +1 -1
  5. package/dist/module/cache/walletCache.js +12 -13
  6. package/dist/module/cache/walletCache.js.map +1 -1
  7. package/dist/module/chain.d.ts +1 -1
  8. package/dist/module/chain.js +1 -1
  9. package/dist/module/chain.js.map +1 -1
  10. package/dist/module/constant.d.ts +1 -1
  11. package/dist/module/constant.d.ts.map +1 -1
  12. package/dist/module/constant.js +1 -1
  13. package/dist/module/constant.js.map +1 -1
  14. package/dist/module/enum.d.ts +1 -7
  15. package/dist/module/enum.d.ts.map +1 -1
  16. package/dist/module/enum.js +0 -6
  17. package/dist/module/enum.js.map +1 -1
  18. package/dist/module/history/getHistory.d.ts.map +1 -1
  19. package/dist/module/history/getHistory.js +0 -30
  20. package/dist/module/history/getHistory.js.map +1 -1
  21. package/dist/module/interface.d.ts +1 -2
  22. package/dist/module/interface.d.ts.map +1 -1
  23. package/dist/module/interface.js.map +1 -1
  24. package/dist/module/network/ElectrumNetworkProvider.js +1 -1
  25. package/dist/module/network/ElectrumNetworkProvider.js.map +1 -1
  26. package/dist/module/network/getRelayFeeCache.js +2 -2
  27. package/dist/module/network/getRelayFeeCache.js.map +1 -1
  28. package/dist/module/rate/ExchangeRate.d.ts +2 -1
  29. package/dist/module/rate/ExchangeRate.d.ts.map +1 -1
  30. package/dist/module/rate/ExchangeRate.js +4 -1
  31. package/dist/module/rate/ExchangeRate.js.map +1 -1
  32. package/dist/module/transaction/Wif.d.ts +9 -9
  33. package/dist/module/transaction/Wif.d.ts.map +1 -1
  34. package/dist/module/transaction/Wif.js +11 -13
  35. package/dist/module/transaction/Wif.js.map +1 -1
  36. package/dist/module/transaction/allocateFee.d.ts +3 -3
  37. package/dist/module/transaction/allocateFee.d.ts.map +1 -1
  38. package/dist/module/transaction/allocateFee.js +5 -6
  39. package/dist/module/transaction/allocateFee.js.map +1 -1
  40. package/dist/module/util/amountInSatoshi.d.ts +1 -1
  41. package/dist/module/util/amountInSatoshi.d.ts.map +1 -1
  42. package/dist/module/util/amountInSatoshi.js +3 -9
  43. package/dist/module/util/amountInSatoshi.js.map +1 -1
  44. package/dist/module/util/asSendRequestObject.d.ts.map +1 -1
  45. package/dist/module/util/asSendRequestObject.js +10 -7
  46. package/dist/module/util/asSendRequestObject.js.map +1 -1
  47. package/dist/module/util/convert.d.ts +3 -0
  48. package/dist/module/util/convert.d.ts.map +1 -1
  49. package/dist/module/util/convert.js +12 -0
  50. package/dist/module/util/convert.js.map +1 -1
  51. package/dist/module/util/index.d.ts +2 -3
  52. package/dist/module/util/index.d.ts.map +1 -1
  53. package/dist/module/util/index.js +2 -3
  54. package/dist/module/util/index.js.map +1 -1
  55. package/dist/module/util/satoshiToAmount.d.ts +1 -1
  56. package/dist/module/util/satoshiToAmount.d.ts.map +1 -1
  57. package/dist/module/util/satoshiToAmount.js +3 -9
  58. package/dist/module/util/satoshiToAmount.js.map +1 -1
  59. package/dist/module/util/sumSendRequestAmounts.d.ts.map +1 -1
  60. package/dist/module/util/sumSendRequestAmounts.js +3 -4
  61. package/dist/module/util/sumSendRequestAmounts.js.map +1 -1
  62. package/dist/module/util/sumUtxoValue.d.ts +1 -1
  63. package/dist/module/util/sumUtxoValue.js +2 -2
  64. package/dist/module/util/sumUtxoValue.js.map +1 -1
  65. package/dist/module/wallet/Base.d.ts +10 -12
  66. package/dist/module/wallet/Base.d.ts.map +1 -1
  67. package/dist/module/wallet/Base.js +18 -50
  68. package/dist/module/wallet/Base.js.map +1 -1
  69. package/dist/module/wallet/Util.js +1 -1
  70. package/dist/module/wallet/Util.js.map +1 -1
  71. package/dist/module/wallet/interface.d.ts +2 -3
  72. package/dist/module/wallet/interface.d.ts.map +1 -1
  73. package/dist/module/wallet/model.d.ts +12 -16
  74. package/dist/module/wallet/model.d.ts.map +1 -1
  75. package/dist/module/wallet/model.js +4 -8
  76. package/dist/module/wallet/model.js.map +1 -1
  77. package/dist/tsconfig.tsbuildinfo +1 -1
  78. package/package.json +1 -1
  79. package/src/cache/walletCache.ts +23 -36
  80. package/src/chain.ts +1 -1
  81. package/src/constant.ts +1 -1
  82. package/src/enum.ts +0 -6
  83. package/src/history/getHistory.test.ts +20 -34
  84. package/src/history/getHistory.ts +0 -32
  85. package/src/interface.ts +1 -2
  86. package/src/network/Connection.test.ts +3 -3
  87. package/src/network/ElectrumNetworkProvider.ts +1 -1
  88. package/src/network/Rpc.test.ts +2 -3
  89. package/src/network/getRelayFeeCache.ts +2 -2
  90. package/src/rate/ExchangeRate.test.ts +2 -44
  91. package/src/rate/ExchangeRate.ts +5 -2
  92. package/src/transaction/Wif.ts +24 -23
  93. package/src/transaction/allocateFee.test.ts +110 -131
  94. package/src/transaction/allocateFee.ts +14 -15
  95. package/src/util/amountInSatoshi.test.ts +1 -9
  96. package/src/util/amountInSatoshi.ts +6 -10
  97. package/src/util/asSendRequestObject.ts +12 -7
  98. package/src/util/convert.ts +18 -0
  99. package/src/util/index.ts +2 -7
  100. package/src/util/satoshiToAmount.test.ts +1 -1
  101. package/src/util/satoshiToAmount.ts +4 -10
  102. package/src/util/sumSendRequestAmounts.ts +3 -4
  103. package/src/util/sumUtxoValue.ts +3 -3
  104. package/src/wallet/Base.ts +28 -92
  105. package/src/wallet/Cashtokens.test.headless.js +11 -11
  106. package/src/wallet/Cashtokens.test.ts +36 -37
  107. package/src/wallet/HDWallet.test.ts +211 -68
  108. package/src/wallet/Util.ts +1 -1
  109. package/src/wallet/Wif.test.ts +108 -133
  110. package/src/wallet/interface.ts +2 -3
  111. package/src/wallet/model.test.ts +2 -5
  112. package/src/wallet/model.ts +15 -30
  113. package/dist/module/util/balanceObjectFromSatoshi.d.ts +0 -8
  114. package/dist/module/util/balanceObjectFromSatoshi.d.ts.map +0 -1
  115. package/dist/module/util/balanceObjectFromSatoshi.js +0 -35
  116. package/dist/module/util/balanceObjectFromSatoshi.js.map +0 -1
  117. package/src/util/balanceObjectFromSatoshi.test.ts +0 -58
  118. package/src/util/balanceObjectFromSatoshi.ts +0 -52
@@ -3,7 +3,6 @@ import {
3
3
  SendRequest,
4
4
  TokenSendRequest,
5
5
  } from "../wallet/model.js";
6
- import { amountInSatoshi } from "./amountInSatoshi.js";
7
6
 
8
7
  // This function sums a list of send request objects
9
8
  export async function sumSendRequestAmounts(
@@ -13,10 +12,10 @@ export async function sumSendRequestAmounts(
13
12
  const balanceArray: (BigInt | Error)[] = await Promise.all(
14
13
  requests.map(async (r: SendRequest | TokenSendRequest | OpReturnData) => {
15
14
  if (r instanceof SendRequest) {
16
- return BigInt(await amountInSatoshi(r.value, r.unit));
15
+ return r.value;
17
16
  } else if (r instanceof TokenSendRequest) {
18
- return BigInt(r.value || 1000);
19
- } else return BigInt(0);
17
+ return r.value || 1000n;
18
+ } else return 0n;
20
19
  })
21
20
  );
22
21
  const balance = balanceArray.reduce(sumBalance, BigInt(0));
@@ -2,13 +2,13 @@ import { Utxo } from "../interface.js";
2
2
 
3
3
  export function sumUtxoValue(utxos: Utxo[]) {
4
4
  if (utxos.length > 0) {
5
- const balanceArray: number[] = utxos.map((o: Utxo) => {
5
+ const balanceArray: bigint[] = utxos.map((o: Utxo) => {
6
6
  return o.satoshis;
7
7
  });
8
- const balance = balanceArray.reduce((a: number, b: number) => a + b, 0);
8
+ const balance = balanceArray.reduce((a: bigint, b: bigint) => a + b, 0n);
9
9
  return balance;
10
10
  } else {
11
- return 0;
11
+ return 0n;
12
12
  }
13
13
  }
14
14
 
@@ -1,7 +1,7 @@
1
1
  import { binToHex, CashAddressNetworkPrefix } from "@bitauth/libauth";
2
- import { WalletCacheI } from "../cache/walletCache.js";
2
+ import { WalletCache } from "../cache/walletCache.js";
3
3
  import StorageProvider from "../db/StorageProvider.js";
4
- import { NetworkType, prefixFromNetworkMap, UnitEnum } from "../enum.js";
4
+ import { NetworkType, prefixFromNetworkMap } from "../enum.js";
5
5
  import { HexHeaderI, NFTCapability, TxI, Utxo, UtxoId } from "../interface.js";
6
6
  import {
7
7
  SignedMessageResponseI,
@@ -18,21 +18,14 @@ import {
18
18
  getSuitableUtxos,
19
19
  placeholderPrivateKeyBin,
20
20
  } from "../transaction/Wif.js";
21
- import {
22
- balanceFromSatoshi,
23
- BalanceResponse,
24
- balanceResponseFromSatoshi,
25
- } from "../util/balanceObjectFromSatoshi.js";
26
21
  import { checkUtxos } from "../util/checkUtxos.js";
27
22
  import {
28
- amountInSatoshi,
29
23
  asSendRequestObject,
30
24
  getRuntimePlatform,
31
25
  sumTokenAmounts,
32
26
  sumUtxoValue,
33
27
  toTokenaddr,
34
28
  } from "../util/index.js";
35
- import { sanitizeUnit } from "../util/sanitizeUnit.js";
36
29
  import { sumSendRequestAmounts } from "../util/sumSendRequestAmounts.js";
37
30
  import { FeePaidByEnum, WalletTypeEnum } from "./enum.js";
38
31
  import {
@@ -70,7 +63,7 @@ export const placeholderTokenAddr =
70
63
  export class BaseWallet implements WalletI {
71
64
  public static StorageProvider?: typeof StorageProvider;
72
65
 
73
- readonly walletCache?: WalletCacheI;
66
+ readonly walletCache?: WalletCache;
74
67
  readonly provider: ElectrumNetworkProvider;
75
68
  readonly network: NetworkType;
76
69
  readonly walletType: WalletTypeEnum;
@@ -412,28 +405,13 @@ export class BaseWallet implements WalletI {
412
405
  throw Error("getUtxos not implemented in BaseWallet");
413
406
  }
414
407
 
415
- // gets wallet balance in sats, bch and currency
416
- public async getBalance(
417
- rawUnit?: string,
418
- priceCache = true
419
- ): Promise<BalanceResponse | number> {
420
- if (rawUnit) {
421
- const unit = sanitizeUnit(rawUnit);
422
- return await balanceFromSatoshi(
423
- await this.getBalanceFromProvider(),
424
- unit,
425
- priceCache
426
- );
427
- } else {
428
- return await balanceResponseFromSatoshi(
429
- await this.getBalanceFromProvider(),
430
- priceCache
431
- );
432
- }
408
+ // gets wallet balance in sats
409
+ public async getBalance(): Promise<bigint> {
410
+ return this.getBalanceFromProvider();
433
411
  }
434
412
 
435
413
  // Gets balance by summing value in all utxos in stats
436
- public async getBalanceFromUtxos(): Promise<number> {
414
+ public async getBalanceFromUtxos(): Promise<bigint> {
437
415
  const utxos = (await this.getUtxos()).filter(
438
416
  (val) => val.token === undefined
439
417
  );
@@ -441,7 +419,7 @@ export class BaseWallet implements WalletI {
441
419
  }
442
420
 
443
421
  // Gets balance from fulcrum
444
- public async getBalanceFromProvider(): Promise<number> {
422
+ public async getBalanceFromProvider(): Promise<bigint> {
445
423
  // Fulcrum reports balance of all utxos, including tokens, which is undesirable
446
424
  // // TODO not sure why getting the balance from a provider doesn't work
447
425
  // if (this._slpAware || this._slpSemiAware) {
@@ -488,68 +466,28 @@ export class BaseWallet implements WalletI {
488
466
  // sets up a callback to be called upon wallet's balance change
489
467
  // can be cancelled by calling the function returned from this one
490
468
  public async watchBalance(
491
- callback: (balance: BalanceResponse) => void
469
+ callback: (balance: bigint) => void
492
470
  ): Promise<CancelFn> {
493
471
  return this.provider.watchAddressStatus(
494
472
  this.getDepositAddress(),
495
473
  async (_status: string) => {
496
- const balance = (await this.getBalance()) as BalanceResponse;
497
- callback(balance);
498
- }
499
- );
500
- }
501
-
502
- // sets up a callback to be called upon wallet's BCH or USD balance change
503
- // if BCH balance does not change, the callback will be triggered every
504
- // @param `usdPriceRefreshInterval` milliseconds by polling for new BCH USD price
505
- // Since we want to be most sensitive to usd value change, we do not use the cached exchange rates
506
- // can be cancelled by calling the function returned from this one
507
- public async watchBalanceUsd(
508
- callback: (balance: BalanceResponse) => void,
509
- usdPriceRefreshInterval = 30000
510
- ): Promise<CancelFn> {
511
- let usdPrice = -1;
512
-
513
- const _callback = async () => {
514
- const balance = (await this.getBalance(
515
- undefined,
516
- false
517
- )) as BalanceResponse;
518
- if (usdPrice !== balance.usd!) {
519
- usdPrice = balance.usd;
474
+ const balance = await this.getBalanceFromProvider();
520
475
  callback(balance);
521
476
  }
522
- };
523
-
524
- const watchCancel = await this.provider.watchAddressStatus(
525
- this.getDepositAddress(),
526
- _callback
527
477
  );
528
- const interval = setInterval(_callback, usdPriceRefreshInterval);
529
-
530
- return async () => {
531
- await watchCancel?.();
532
- clearInterval(interval);
533
- };
534
478
  }
535
479
 
536
480
  // waits for address balance to be greater than or equal to the target value
537
481
  // this call halts the execution
538
- public async waitForBalance(
539
- value: number,
540
- rawUnit: UnitEnum = UnitEnum.BCH
541
- ): Promise<BalanceResponse> {
482
+ public async waitForBalance(value: bigint): Promise<bigint> {
542
483
  return new Promise(async (resolve) => {
543
484
  let watchCancel: CancelFn;
544
- watchCancel = await this.watchBalance(
545
- async (balance: BalanceResponse) => {
546
- const satoshiBalance = await amountInSatoshi(value, rawUnit);
547
- if (balance.sat! >= satoshiBalance) {
548
- await watchCancel?.();
549
- resolve(balance);
550
- }
485
+ watchCancel = await this.watchBalance(async (balance: bigint) => {
486
+ if (balance >= value) {
487
+ await watchCancel?.();
488
+ resolve(balance);
551
489
  }
552
- );
490
+ });
553
491
  });
554
492
  }
555
493
 
@@ -601,7 +539,7 @@ export class BaseWallet implements WalletI {
601
539
  outputCount: 1,
602
540
  options: {},
603
541
  }
604
- ): Promise<{ value: number; utxos: Utxo[] }> {
542
+ ): Promise<{ value: bigint; utxos: Utxo[] }> {
605
543
  if (params.options && params.options.slpSemiAware) {
606
544
  this._slpSemiAware = true;
607
545
  }
@@ -632,8 +570,7 @@ export class BaseWallet implements WalletI {
632
570
  // simulate outputs using the sender's address
633
571
  const sendRequest = new SendRequest({
634
572
  cashaddr: placeholderCashAddr,
635
- value: 100,
636
- unit: "sat",
573
+ value: 100n,
637
574
  });
638
575
  const sendRequests = Array(params.outputCount)
639
576
  .fill(0)
@@ -657,8 +594,8 @@ export class BaseWallet implements WalletI {
657
594
  const spendableAmount = sumUtxoValue(fundingUtxos);
658
595
 
659
596
  let result = spendableAmount - fee;
660
- if (result < 0) {
661
- result = 0;
597
+ if (result < 0n) {
598
+ result = 0n;
662
599
  }
663
600
 
664
601
  return { value: result, utxos: fundingUtxos };
@@ -672,10 +609,10 @@ export class BaseWallet implements WalletI {
672
609
  outputCount: 1,
673
610
  options: {},
674
611
  }
675
- ): Promise<BalanceResponse> {
612
+ ): Promise<bigint> {
676
613
  const { value: result } = await this._getMaxAmountToSend(params);
677
614
 
678
- return await balanceResponseFromSatoshi(result);
615
+ return result;
679
616
  }
680
617
 
681
618
  /**
@@ -715,7 +652,7 @@ export class BaseWallet implements WalletI {
715
652
  options?.queryBalance === undefined ||
716
653
  options?.queryBalance === true
717
654
  ) {
718
- resp.balance = (await this.getBalance()) as BalanceResponse;
655
+ resp.balance = await this.getBalance();
719
656
  }
720
657
  } else {
721
658
  resp.unsignedTransaction = binToHex(encodedTransaction);
@@ -770,7 +707,6 @@ export class BaseWallet implements WalletI {
770
707
  const sendRequest = new SendRequest({
771
708
  cashaddr: cashaddr,
772
709
  value: maxSpendableAmount,
773
- unit: "sat",
774
710
  });
775
711
 
776
712
  const { encodedTransaction, tokenIds, sourceOutputs } =
@@ -793,7 +729,7 @@ export class BaseWallet implements WalletI {
793
729
  options?.queryBalance === undefined ||
794
730
  options?.queryBalance === true
795
731
  ) {
796
- resp.balance = (await this.getBalance()) as BalanceResponse;
732
+ resp.balance = await this.getBalance();
797
733
  }
798
734
  } else {
799
735
  resp.unsignedTransaction = binToHex(encodedTransaction);
@@ -964,7 +900,7 @@ export class BaseWallet implements WalletI {
964
900
 
965
901
  const fundingUtxos = await getSuitableUtxos(
966
902
  utxos,
967
- BigInt(spendAmount) + BigInt(Math.ceil(feeEstimate)),
903
+ spendAmount + feeEstimate,
968
904
  bestHeight,
969
905
  feePaidBy,
970
906
  sendRequests,
@@ -1194,7 +1130,7 @@ export class BaseWallet implements WalletI {
1194
1130
  const genesisSendRequest = new TokenSendRequest({
1195
1131
  cashaddr: genesisRequest.cashaddr || this.getTokenDepositAddress(),
1196
1132
  amount: genesisRequest.amount,
1197
- value: genesisRequest.value || 1000,
1133
+ value: genesisRequest.value || 1000n,
1198
1134
  capability: genesisRequest.capability,
1199
1135
  commitment: genesisRequest.commitment,
1200
1136
  tokenId: genesisInputs[0].txid,
@@ -1267,7 +1203,7 @@ export class BaseWallet implements WalletI {
1267
1203
  (val) =>
1268
1204
  new TokenSendRequest({
1269
1205
  cashaddr: val.cashaddr || this.getTokenDepositAddress(),
1270
- amount: 0,
1206
+ amount: 0n,
1271
1207
  tokenId: tokenId,
1272
1208
  value: val.value,
1273
1209
  capability: val.capability,
@@ -1389,7 +1325,7 @@ export class BaseWallet implements WalletI {
1389
1325
  burnRequest.cashaddr || toTokenaddr(this.getChangeAddress()),
1390
1326
  tokenId: burnRequest.tokenId,
1391
1327
  amount: safeNewAmount,
1392
- value: tokenUtxos.reduce((a, c) => a + c.satoshis, 0),
1328
+ value: tokenUtxos.reduce((a, c) => a + c.satoshis, 0n),
1393
1329
  }),
1394
1330
  ];
1395
1331
  }
@@ -389,7 +389,7 @@ describe(`Wallet should function in the browser`, () => {
389
389
  const bob = await RegTestWallet.newRandom();
390
390
  const genesisResponse = await alice.tokenGenesis({
391
391
  amount: 100,
392
- value: 7000,
392
+ value: 7000n,
393
393
  cashaddr: bob.cashaddr,
394
394
  });
395
395
 
@@ -398,7 +398,7 @@ describe(`Wallet should function in the browser`, () => {
398
398
  expect(tokenBalance).toBe(100n);
399
399
  const tokenUtxos = await bob.getTokenUtxos(tokenId);
400
400
  expect(tokenUtxos.length).toBe(1);
401
- expect(tokenUtxos[0].satoshis).toBe(7000);
401
+ expect(tokenUtxos[0].satoshis).toBe(7000n);
402
402
 
403
403
  // lower the token satoshi value
404
404
  const response = await bob.send([
@@ -406,7 +406,7 @@ describe(`Wallet should function in the browser`, () => {
406
406
  cashaddr: bob.cashaddr,
407
407
  amount: 100,
408
408
  tokenId: tokenId,
409
- value: 1500,
409
+ value: 1500n,
410
410
  }),
411
411
  ]);
412
412
  let newTokenUtxos = await bob.getTokenUtxos(tokenId);
@@ -415,8 +415,8 @@ describe(`Wallet should function in the browser`, () => {
415
415
 
416
416
  let bobUtxos = await bob.getAddressUtxos(bob.cashaddr);
417
417
  expect(bobUtxos.length).toBe(2);
418
- expect(bobUtxos[0].satoshis).toBe(1500);
419
- expect(bobUtxos[1].satoshis).toBe(5245);
418
+ expect(bobUtxos[0].satoshis).toBe(1500n);
419
+ expect(bobUtxos[1].satoshis).toBe(5245n);
420
420
 
421
421
  // raise the token satoshi value
422
422
  await bob.send([
@@ -424,7 +424,7 @@ describe(`Wallet should function in the browser`, () => {
424
424
  cashaddr: bob.cashaddr,
425
425
  amount: 100,
426
426
  tokenId: tokenId,
427
- value: 3000,
427
+ value: 3000n,
428
428
  }),
429
429
  ]);
430
430
  newTokenUtxos = await bob.getTokenUtxos(tokenId);
@@ -433,8 +433,8 @@ describe(`Wallet should function in the browser`, () => {
433
433
 
434
434
  bobUtxos = await bob.getAddressUtxos(bob.cashaddr);
435
435
  expect(bobUtxos.length).toBe(2);
436
- expect(bobUtxos[0].satoshis).toBe(3000);
437
- expect(bobUtxos[1].satoshis).toBe(3349);
436
+ expect(bobUtxos[0].satoshis).toBe(3000n);
437
+ expect(bobUtxos[1].satoshis).toBe(3349n);
438
438
  }, process.env.ALICE_ID);
439
439
  });
440
440
 
@@ -445,7 +445,7 @@ describe(`Wallet should function in the browser`, () => {
445
445
 
446
446
  const genesisResponse = await alice.tokenGenesis({
447
447
  amount: 100,
448
- value: 5000,
448
+ value: 5000n,
449
449
  capability: NFTCapability.minting,
450
450
  commitment: "test",
451
451
  cashaddr: alice.cashaddr,
@@ -456,7 +456,7 @@ describe(`Wallet should function in the browser`, () => {
456
456
  expect(tokenBalance).toBe(100n);
457
457
  const tokenUtxos = await alice.getTokenUtxos(tokenId);
458
458
  expect(tokenUtxos.length).toBe(1);
459
- expect(tokenUtxos[0].satoshis).toBe(5000);
459
+ expect(tokenUtxos[0].satoshis).toBe(5000n);
460
460
 
461
461
  let seenBalance = 0;
462
462
  setTimeout(
@@ -466,7 +466,7 @@ describe(`Wallet should function in the browser`, () => {
466
466
  cashaddr: bob.cashaddr,
467
467
  amount: 100,
468
468
  tokenId: tokenId,
469
- value: 1500,
469
+ value: 1500n,
470
470
  capability: NFTCapability.minting,
471
471
  commitment: "test",
472
472
  }),
@@ -14,7 +14,7 @@ import {
14
14
  hexToBin,
15
15
  utf8ToBin,
16
16
  } from "@bitauth/libauth";
17
- import { delay } from "../util";
17
+ import { convert, delay } from "../util";
18
18
  import { Config } from "../config";
19
19
  import json from "../test/json.test";
20
20
 
@@ -37,14 +37,16 @@ describe(`Test cashtokens`, () => {
37
37
  test("Test token genesis and max amount to send", async () => {
38
38
  const alice = await RegTestWallet.fromId(process.env.ALICE_ID!);
39
39
  const bob = await RegTestWallet.newRandom();
40
- await alice.send([[bob.cashaddr!, 0.101, "bch"]]);
40
+ await alice.send([
41
+ [bob.cashaddr!, BigInt(await convert(0.101, "bch", "sat"))],
42
+ ]);
41
43
  const genesisResponse = await bob.tokenGenesis({
42
44
  amount: 100n,
43
45
  });
44
46
 
45
47
  const maxAmountToSend = await bob.getMaxAmountToSend();
46
- await bob.send([[alice.cashaddr!, maxAmountToSend.sat!, "sat"]]);
47
- expect(await bob.getBalance("sat")).toBe(0);
48
+ await bob.send([[alice.cashaddr!, maxAmountToSend]]);
49
+ expect(await bob.getBalance()).toBe(0n);
48
50
  });
49
51
 
50
52
  test("Test tokens will not be burned when sending bch value", async () => {
@@ -62,8 +64,7 @@ describe(`Test cashtokens`, () => {
62
64
  await alice.send([
63
65
  new SendRequest({
64
66
  cashaddr: bob.cashaddr!,
65
- value: 5000,
66
- unit: "sat",
67
+ value: 5000n,
67
68
  }),
68
69
  new TokenSendRequest({
69
70
  cashaddr: bob.cashaddr!,
@@ -72,21 +73,20 @@ describe(`Test cashtokens`, () => {
72
73
  }),
73
74
  ]);
74
75
  expect(await bob.getTokenBalance(tokenId)).toBe(25n);
75
- expect(await bob.getBalance("sat")).toBe(5000);
76
+ expect(await bob.getBalance()).toBe(5000n);
76
77
 
77
78
  await bob.send(
78
79
  new SendRequest({
79
80
  cashaddr: alice.cashaddr!,
80
- value: 1000,
81
- unit: "sat",
81
+ value: 1000n,
82
82
  })
83
83
  );
84
84
  expect(await bob.getTokenBalance(tokenId)).toBe(25n);
85
- expect(await bob.getBalance("sat")).toBe(3780);
85
+ expect(await bob.getBalance()).toBe(3780n);
86
86
 
87
87
  await bob.sendMax(alice.cashaddr!);
88
88
  expect(await bob.getTokenBalance(tokenId)).toBe(25n);
89
- expect(await bob.getBalance("sat")).toBe(0);
89
+ expect(await bob.getBalance()).toBe(0n);
90
90
  });
91
91
 
92
92
  test("Test fungible cashtoken genesis and sending", async () => {
@@ -114,8 +114,7 @@ describe(`Test cashtokens`, () => {
114
114
  }),
115
115
  new SendRequest({
116
116
  cashaddr: bob.cashaddr!,
117
- value: 20000,
118
- unit: "sat",
117
+ value: 20000n,
119
118
  }),
120
119
  ]);
121
120
  const newTokenUtxos = await alice.getTokenUtxos(tokenId);
@@ -536,7 +535,7 @@ describe(`Test cashtokens`, () => {
536
535
  const bob = await RegTestWallet.newRandom();
537
536
  const genesisResponse = await alice.tokenGenesis({
538
537
  amount: 100n,
539
- value: 7000,
538
+ value: 7000n,
540
539
  cashaddr: bob.cashaddr!,
541
540
  });
542
541
 
@@ -545,7 +544,7 @@ describe(`Test cashtokens`, () => {
545
544
  expect(tokenBalance).toBe(100n);
546
545
  const tokenUtxos = await bob.getTokenUtxos(tokenId);
547
546
  expect(tokenUtxos.length).toBe(1);
548
- expect(tokenUtxos[0].satoshis).toBe(7000);
547
+ expect(tokenUtxos[0].satoshis).toBe(7000n);
549
548
 
550
549
  // lower the token satoshi value
551
550
  const response = await bob.send([
@@ -553,7 +552,7 @@ describe(`Test cashtokens`, () => {
553
552
  cashaddr: bob.cashaddr!,
554
553
  amount: 100n,
555
554
  tokenId: tokenId,
556
- value: 1500,
555
+ value: 1500n,
557
556
  }),
558
557
  ]);
559
558
  let newTokenUtxos = await bob.getTokenUtxos(tokenId);
@@ -562,8 +561,8 @@ describe(`Test cashtokens`, () => {
562
561
 
563
562
  let bobUtxos = await bob.getAddressUtxos(bob.cashaddr!);
564
563
  expect(bobUtxos.length).toBe(2);
565
- expect(bobUtxos[0].satoshis).toBe(1500);
566
- expect(bobUtxos[1].satoshis).toBe(5245);
564
+ expect(bobUtxos[0].satoshis).toBe(1500n);
565
+ expect(bobUtxos[1].satoshis).toBe(5245n);
567
566
 
568
567
  // raise the token satoshi value
569
568
  await bob.send([
@@ -571,7 +570,7 @@ describe(`Test cashtokens`, () => {
571
570
  cashaddr: bob.cashaddr!,
572
571
  amount: 100n,
573
572
  tokenId: tokenId,
574
- value: 3000,
573
+ value: 3000n,
575
574
  }),
576
575
  ]);
577
576
  newTokenUtxos = await bob.getTokenUtxos(tokenId);
@@ -580,8 +579,8 @@ describe(`Test cashtokens`, () => {
580
579
 
581
580
  bobUtxos = await bob.getAddressUtxos(bob.cashaddr!);
582
581
  expect(bobUtxos.length).toBe(2);
583
- expect(bobUtxos[0].satoshis).toBe(3000);
584
- expect(bobUtxos[1].satoshis).toBe(3349);
582
+ expect(bobUtxos[0].satoshis).toBe(3000n);
583
+ expect(bobUtxos[1].satoshis).toBe(3349n);
585
584
  });
586
585
 
587
586
  test("Test cashtoken waiting and watching", async () => {
@@ -590,7 +589,7 @@ describe(`Test cashtokens`, () => {
590
589
 
591
590
  const genesisResponse = await alice.tokenGenesis({
592
591
  amount: 100n,
593
- value: 5000,
592
+ value: 5000n,
594
593
  capability: NFTCapability.minting,
595
594
  commitment: "test",
596
595
  cashaddr: alice.cashaddr!,
@@ -601,7 +600,7 @@ describe(`Test cashtokens`, () => {
601
600
  expect(tokenBalance).toBe(100n);
602
601
  const tokenUtxos = await alice.getTokenUtxos(tokenId);
603
602
  expect(tokenUtxos.length).toBe(1);
604
- expect(tokenUtxos[0].satoshis).toBe(5000);
603
+ expect(tokenUtxos[0].satoshis).toBe(5000n);
605
604
 
606
605
  let seenBalance = 0n;
607
606
  let sendResponse: SendResponse = {};
@@ -612,7 +611,7 @@ describe(`Test cashtokens`, () => {
612
611
  cashaddr: bob.cashaddr!,
613
612
  amount: 100n,
614
613
  tokenId: tokenId,
615
- value: 1500,
614
+ value: 1500n,
616
615
  capability: NFTCapability.minting,
617
616
  commitment: "test",
618
617
  }),
@@ -644,8 +643,8 @@ describe(`Test cashtokens`, () => {
644
643
  const bob = await RegTestWallet.newRandom();
645
644
 
646
645
  // prepare inputs for two token geneses
647
- await alice.send({ cashaddr: bob.cashaddr!, value: 10000, unit: "sat" });
648
- await alice.send({ cashaddr: bob.cashaddr!, value: 10000, unit: "sat" });
646
+ await alice.send({ cashaddr: bob.cashaddr!, value: 10000n });
647
+ await alice.send({ cashaddr: bob.cashaddr!, value: 10000n });
649
648
 
650
649
  const genesisResponse = await bob.tokenGenesis({
651
650
  amount: 100n,
@@ -676,8 +675,8 @@ describe(`Test cashtokens`, () => {
676
675
  const bob = await RegTestWallet.newRandom();
677
676
 
678
677
  // prepare inputs for two token geneses
679
- await alice.send({ cashaddr: bob.cashaddr!, value: 10000, unit: "sat" });
680
- await alice.send({ cashaddr: bob.cashaddr!, value: 10000, unit: "sat" });
678
+ await alice.send({ cashaddr: bob.cashaddr!, value: 10000n });
679
+ await alice.send({ cashaddr: bob.cashaddr!, value: 10000n });
681
680
 
682
681
  const genesisResponse = await bob.tokenGenesis({
683
682
  amount: 100n,
@@ -719,7 +718,7 @@ describe(`Test cashtokens`, () => {
719
718
  const bob = await RegTestWallet.newRandom();
720
719
 
721
720
  // prepare inputs for two token geneses
722
- await alice.send({ cashaddr: bob.cashaddr!, value: 10000, unit: "sat" });
721
+ await alice.send({ cashaddr: bob.cashaddr!, value: 10000n });
723
722
 
724
723
  const genesisResponse = await bob.tokenGenesis({
725
724
  amount: 100n,
@@ -732,7 +731,7 @@ describe(`Test cashtokens`, () => {
732
731
  const tokenUtxos = await bob.getTokenUtxos(tokenId);
733
732
  expect(tokenUtxos.length).toBe(1);
734
733
 
735
- await bob.send({ cashaddr: alice.cashaddr!, value: 1000, unit: "sat" });
734
+ await bob.send({ cashaddr: alice.cashaddr!, value: 1000n });
736
735
 
737
736
  const tokenBalance2 = await bob.getTokenBalance(tokenId);
738
737
  expect(tokenBalance2).toBe(100n);
@@ -746,8 +745,8 @@ describe(`Test cashtokens`, () => {
746
745
  const charlie = await RegTestWallet.newRandom();
747
746
  // prepare inputs for two token geneses
748
747
  await alice.send([
749
- { cashaddr: bob.cashaddr!, value: 10000, unit: "sat" },
750
- { cashaddr: charlie.cashaddr!, value: 10000, unit: "sat" },
748
+ { cashaddr: bob.cashaddr!, value: 10000n },
749
+ { cashaddr: charlie.cashaddr!, value: 10000n },
751
750
  ]);
752
751
 
753
752
  const genesisResponse = await bob.tokenGenesis({
@@ -761,7 +760,7 @@ describe(`Test cashtokens`, () => {
761
760
  const tokenUtxos = await bob.getTokenUtxos(tokenId);
762
761
  expect(tokenUtxos.length).toBe(1);
763
762
 
764
- await bob.send({ cashaddr: alice.cashaddr!, value: 1000, unit: "sat" });
763
+ await bob.send({ cashaddr: alice.cashaddr!, value: 1000n });
765
764
 
766
765
  await bob.send([
767
766
  {
@@ -826,7 +825,7 @@ describe(`Test cashtokens`, () => {
826
825
  const charlie = await RegTestWallet.newRandom();
827
826
 
828
827
  // prepare inputs for two token geneses
829
- await alice.send({ cashaddr: bob.cashaddr!, value: 10000, unit: "sat" });
828
+ await alice.send({ cashaddr: bob.cashaddr!, value: 10000n });
830
829
 
831
830
  const genesisResponse = await bob.tokenGenesis({
832
831
  capability: "minting",
@@ -871,7 +870,7 @@ describe(`Test cashtokens`, () => {
871
870
  const charlie = await RegTestWallet.newRandom();
872
871
 
873
872
  // prepare inputs for two token geneses
874
- await alice.send({ cashaddr: bob.cashaddr!, value: 10000, unit: "sat" });
873
+ await alice.send({ cashaddr: bob.cashaddr!, value: 10000n });
875
874
 
876
875
  const genesisResponse = await bob.tokenGenesis({
877
876
  capability: "minting",
@@ -951,7 +950,7 @@ describe(`Test cashtokens`, () => {
951
950
  const charlie = await RegTestWallet.newRandom();
952
951
 
953
952
  // prepare inputs for two token geneses
954
- await alice.send({ cashaddr: bob.cashaddr!, value: 10000, unit: "sat" });
953
+ await alice.send({ cashaddr: bob.cashaddr!, value: 10000n });
955
954
 
956
955
  const genesisResponse = await bob.tokenGenesis({
957
956
  capability: "minting",
@@ -1014,7 +1013,7 @@ describe(`Test cashtokens`, () => {
1014
1013
  const alice = await RegTestWallet.fromId(process.env.ALICE_ID!);
1015
1014
  const bob = await RegTestWallet.newRandom();
1016
1015
 
1017
- await alice.send({ cashaddr: bob.cashaddr!, value: 10000, unit: "sat" });
1016
+ await alice.send({ cashaddr: bob.cashaddr!, value: 10000n });
1018
1017
 
1019
1018
  const genesisResponse = await bob.tokenGenesis({
1020
1019
  capability: "none",