mainnet-js 0.5.4 → 0.5.8

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 (36) hide show
  1. package/dist/index.html +1 -1
  2. package/dist/main/history/electrumTransformer.d.ts +4 -0
  3. package/dist/main/history/electrumTransformer.js +214 -0
  4. package/dist/main/history/electrumTransformer.js.map +1 -0
  5. package/dist/main/history/interface.d.ts +16 -0
  6. package/dist/main/history/interface.js +3 -0
  7. package/dist/main/history/interface.js.map +1 -0
  8. package/dist/main/util/checkForEmptySeed.d.ts +2 -0
  9. package/dist/main/util/checkForEmptySeed.js +12 -0
  10. package/dist/main/util/checkForEmptySeed.js.map +1 -0
  11. package/dist/main/wallet/Wif.d.ts +3 -1
  12. package/dist/main/wallet/Wif.js +17 -2
  13. package/dist/main/wallet/Wif.js.map +1 -1
  14. package/dist/{mainnet-0.5.4.js → mainnet-0.5.8.js} +2 -2
  15. package/dist/{mainnet-0.5.4.js.LICENSE.txt → mainnet-0.5.8.js.LICENSE.txt} +0 -0
  16. package/dist/module/history/electrumTransformer.d.ts +4 -0
  17. package/dist/module/history/electrumTransformer.js +209 -0
  18. package/dist/module/history/electrumTransformer.js.map +1 -0
  19. package/dist/module/history/interface.d.ts +16 -0
  20. package/dist/module/history/interface.js +2 -0
  21. package/dist/module/history/interface.js.map +1 -0
  22. package/dist/module/util/checkForEmptySeed.d.ts +2 -0
  23. package/dist/module/util/checkForEmptySeed.js +8 -0
  24. package/dist/module/util/checkForEmptySeed.js.map +1 -0
  25. package/dist/module/wallet/Wif.d.ts +3 -1
  26. package/dist/module/wallet/Wif.js +17 -2
  27. package/dist/module/wallet/Wif.js.map +1 -1
  28. package/dist/tsconfig.browser.tsbuildinfo +1 -1
  29. package/dist/tsconfig.tsbuildinfo +1 -1
  30. package/package.json +4 -4
  31. package/src/history/electrumTransformer.test.ts +252 -0
  32. package/src/history/electrumTransformer.ts +318 -0
  33. package/src/history/interface.ts +18 -0
  34. package/src/util/checkForEmptySeed.ts +9 -0
  35. package/src/wallet/Wif.bip39.test.ts +23 -0
  36. package/src/wallet/Wif.ts +32 -3
package/src/wallet/Wif.ts CHANGED
@@ -65,6 +65,7 @@ import {
65
65
  import { checkWifNetwork } from "../util/checkWifNetwork";
66
66
  import { deriveCashaddr } from "../util/deriveCashaddr";
67
67
  import { derivePrefix, derivePublicKeyHash } from "../util/derivePublicKeyHash";
68
+ import { checkForEmptySeed } from "../util/checkForEmptySeed";
68
69
  import { sanitizeUnit } from "../util/sanitizeUnit";
69
70
  import { sumUtxoValue } from "../util/sumUtxoValue";
70
71
  import { sumSendRequestAmounts } from "../util/sumSendRequestAmounts";
@@ -103,6 +104,9 @@ import { amountInSatoshi } from "../util/amountInSatoshi";
103
104
  import { getXPubKey } from "../util/getXPubKey";
104
105
  import { DERIVATION_PATHS, DUST_UTXO_THRESHOLD } from "../constant";
105
106
 
107
+ import { TransactionHistoryI } from "../history/interface";
108
+ import { getAddressHistory } from "../history/electrumTransformer";
109
+
106
110
  //#endregion Imports
107
111
 
108
112
  const secp256k1Promise = instantiateSecp256k1();
@@ -335,7 +339,10 @@ export class Wallet extends BaseWallet {
335
339
 
336
340
  private async _generateMnemonic() {
337
341
  this.mnemonic = generateMnemonic();
342
+ if (this.mnemonic.length == 0)
343
+ throw Error("refusing to create wallet from empty mnemonic");
338
344
  let seed = mnemonicToSeedSync(this.mnemonic!);
345
+ checkForEmptySeed(seed);
339
346
  let network = this.isTestnet ? "testnet" : "mainnet";
340
347
  this.parentXPubKey = await getXPubKey(
341
348
  seed,
@@ -394,8 +401,10 @@ export class Wallet extends BaseWallet {
394
401
  this.mnemonic = mnemonic;
395
402
 
396
403
  const crypto = await instantiateBIP32Crypto();
404
+ if (this.mnemonic.length == 0)
405
+ throw Error("refusing to create wallet from empty mnemonic");
397
406
  let seed = mnemonicToSeedSync(this.mnemonic);
398
-
407
+ checkForEmptySeed(seed);
399
408
  let hdNode = deriveHdPrivateNodeFromSeed(crypto, seed);
400
409
  if (!hdNode.valid) {
401
410
  throw Error("Invalid private key derived from mnemonic seed");
@@ -431,7 +440,10 @@ export class Wallet extends BaseWallet {
431
440
  // Get common xpub paths from zerothChild privateKey
432
441
  public async deriveHdPaths(hdPaths: string[]): Promise<any[]> {
433
442
  const crypto = await instantiateBIP32Crypto();
443
+ if (!this.mnemonic)
444
+ throw Error("refusing to create wallet from empty mnemonic");
434
445
  let seed = mnemonicToSeedSync(this.mnemonic!);
446
+ checkForEmptySeed(seed);
435
447
  let hdNode = deriveHdPrivateNodeFromSeed(crypto, seed);
436
448
  if (!hdNode.valid) {
437
449
  throw Error("Invalid private key derived from mnemonic seed");
@@ -1056,15 +1068,32 @@ export class Wallet extends BaseWallet {
1056
1068
  }
1057
1069
 
1058
1070
  // gets transaction history of this wallet
1059
- public async getHistory(): Promise<TxI[]> {
1071
+ public async getRawHistory(): Promise<TxI[]> {
1060
1072
  return await this.provider!.getHistory(this.cashaddr!);
1061
1073
  }
1062
1074
 
1075
+ // gets transaction history of this wallet
1076
+ public async getHistory(
1077
+ unit: UnitEnum,
1078
+ start?: number,
1079
+ count?: number,
1080
+ collapseChange?: boolean
1081
+ ): Promise<TransactionHistoryI> {
1082
+ return getAddressHistory(
1083
+ this.cashaddr!,
1084
+ this.provider!,
1085
+ unit,
1086
+ start,
1087
+ count,
1088
+ collapseChange
1089
+ );
1090
+ }
1091
+
1063
1092
  // gets last transaction of this wallet
1064
1093
  public async getLastTransaction(
1065
1094
  confirmedOnly: boolean = false
1066
1095
  ): Promise<ElectrumRawTransaction | null> {
1067
- let history: TxI[] = await this.getHistory();
1096
+ let history: TxI[] = await this.getRawHistory();
1068
1097
  if (confirmedOnly) {
1069
1098
  history = history.filter((val) => val.height > 0);
1070
1099
  }