mainnet-js 2.3.14 → 2.3.16

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 (38) hide show
  1. package/dist/index.html +1 -1
  2. package/dist/{mainnet-2.3.14.js → mainnet-2.3.16.js} +14 -4
  3. package/dist/module/config.d.ts +1 -0
  4. package/dist/module/config.d.ts.map +1 -1
  5. package/dist/module/config.js +3 -0
  6. package/dist/module/config.js.map +1 -1
  7. package/dist/module/interface.d.ts +10 -1
  8. package/dist/module/interface.d.ts.map +1 -1
  9. package/dist/module/interface.js.map +1 -1
  10. package/dist/module/network/ElectrumNetworkProvider.d.ts +7 -5
  11. package/dist/module/network/ElectrumNetworkProvider.d.ts.map +1 -1
  12. package/dist/module/network/ElectrumNetworkProvider.js +40 -4
  13. package/dist/module/network/ElectrumNetworkProvider.js.map +1 -1
  14. package/dist/module/network/NetworkProvider.d.ts +7 -2
  15. package/dist/module/network/NetworkProvider.d.ts.map +1 -1
  16. package/dist/module/util/header.d.ts +3 -0
  17. package/dist/module/util/header.d.ts.map +1 -0
  18. package/dist/module/util/header.js +13 -0
  19. package/dist/module/util/header.js.map +1 -0
  20. package/dist/module/util/index.d.ts +1 -0
  21. package/dist/module/util/index.d.ts.map +1 -1
  22. package/dist/module/util/index.js +1 -0
  23. package/dist/module/util/index.js.map +1 -1
  24. package/dist/module/wallet/Wif.d.ts +3 -3
  25. package/dist/module/wallet/Wif.d.ts.map +1 -1
  26. package/dist/module/wallet/Wif.js.map +1 -1
  27. package/dist/tsconfig.tsbuildinfo +1 -1
  28. package/package.json +1 -1
  29. package/src/config.ts +3 -0
  30. package/src/interface.ts +11 -1
  31. package/src/network/ElectrumNetworkProvider.ts +50 -10
  32. package/src/network/NetworkProvider.ts +8 -2
  33. package/src/util/balanceObjectFromSatoshi.test.ts +7 -1
  34. package/src/util/header.test.ts +28 -0
  35. package/src/util/header.ts +16 -0
  36. package/src/util/index.ts +1 -0
  37. package/src/wallet/Wif.test.ts +30 -0
  38. package/src/wallet/Wif.ts +3 -3
@@ -18,6 +18,7 @@ import {
18
18
  import { mine } from "../mine";
19
19
  import json from "../../polyfill/json";
20
20
  import ElectrumNetworkProvider from "../network/ElectrumNetworkProvider";
21
+ import { Config } from "../config";
21
22
 
22
23
  beforeAll(async () => {
23
24
  await initProviders();
@@ -458,6 +459,23 @@ describe(`Watch only Wallets`, () => {
458
459
  }
459
460
  });
460
461
 
462
+ test("Should get the regtest wallet balance in eur", async () => {
463
+ // Build Alice's wallet from Wallet Import Format string, send some sats
464
+ if (!process.env.ADDRESS) {
465
+ throw Error("Attempted to pass an empty address");
466
+ } else {
467
+ Config.DefaultCurrency = "eur";
468
+ let alice = await RegTestWallet.watchOnly(process.env.ADDRESS); // insert WIF from #1
469
+ // Build Bob's wallet from a public address, check his balance.
470
+ 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);
475
+ Config.DefaultCurrency = "usd";
476
+ }
477
+ });
478
+
461
479
  test("Should send to testnet coins to a random address", async () => {
462
480
  if (!process.env.ALICE_TESTNET_WALLET_ID) {
463
481
  throw Error("Attempted to pass an empty address");
@@ -525,6 +543,18 @@ describe(`Watch only Wallets`, () => {
525
543
 
526
544
  expect(await bobWallet.getLastTransaction()).not.toBeNull();
527
545
  });
546
+
547
+ test("Should fail localStorage cache", async () => {
548
+ const aliceWif = `wif:regtest:${process.env.PRIVATE_WIF!}`;
549
+ const aliceWallet = await RegTestWallet.fromId(aliceWif);
550
+
551
+ expect(await aliceWallet.getLastTransaction()).not.toBeNull();
552
+ Config.UseLocalStorageCache = true;
553
+ await expect(aliceWallet.getLastTransaction()).rejects.toThrow(
554
+ "localStorage is not defined"
555
+ );
556
+ Config.UseLocalStorageCache = false;
557
+ });
528
558
  });
529
559
  describe(`Wallet subscriptions`, () => {
530
560
  test("Should wait for transaction", async () => {
package/src/wallet/Wif.ts CHANGED
@@ -25,7 +25,7 @@ import {
25
25
  import { mnemonicToSeedSync, generateMnemonic } from "@scure/bip39";
26
26
  import { NetworkType, prefixFromNetworkMap, UnitEnum } from "../enum.js";
27
27
 
28
- import { Network, HeaderI, TxI, NFTCapability } from "../interface.js";
28
+ import { Network, HexHeaderI, TxI, NFTCapability } from "../interface.js";
29
29
 
30
30
  import { networkPrefixMap } from "../enum.js";
31
31
  import { PrivateKeyI, UtxoI } from "../interface.js";
@@ -1396,7 +1396,7 @@ export class Wallet extends BaseWallet {
1396
1396
  *
1397
1397
  * @returns a function which will cancel watching upon evaluation
1398
1398
  */
1399
- public watchBlocks(callback: (header: HeaderI) => void): CancelWatchFn {
1399
+ public watchBlocks(callback: (header: HexHeaderI) => void): CancelWatchFn {
1400
1400
  return (this.provider! as ElectrumNetworkProvider).watchBlocks(callback);
1401
1401
  }
1402
1402
 
@@ -1406,7 +1406,7 @@ export class Wallet extends BaseWallet {
1406
1406
  * @param height if specified waits for this exact blockchain height, otherwise resolves with the next block
1407
1407
  *
1408
1408
  */
1409
- public async waitForBlock(height?: number): Promise<HeaderI> {
1409
+ public async waitForBlock(height?: number): Promise<HexHeaderI> {
1410
1410
  return (this.provider! as ElectrumNetworkProvider).waitForBlock(height);
1411
1411
  }
1412
1412
  //#endregion Funds