beignet 0.0.21 → 0.0.23

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 (273) hide show
  1. package/dist/electrum/index.js +105 -42
  2. package/dist/electrum/index.js.map +1 -1
  3. package/dist/types/electrum/index.d.ts +11 -4
  4. package/dist/types/electrum.js +8 -1
  5. package/dist/types/electrum.js.map +1 -1
  6. package/dist/types/types/electrum.d.ts +6 -0
  7. package/dist/types/types/transaction.d.ts +4 -0
  8. package/dist/types/types/wallet.d.ts +7 -1
  9. package/dist/types/utils/helpers.d.ts +2 -0
  10. package/dist/types/utils/wallet.d.ts +19 -1
  11. package/dist/types/wallet/constants.d.ts +0 -5
  12. package/dist/types/wallet/index.d.ts +14 -3
  13. package/dist/types/wallet.js.map +1 -1
  14. package/dist/utils/helpers.js +11 -1
  15. package/dist/utils/helpers.js.map +1 -1
  16. package/dist/utils/wallet.js +48 -1
  17. package/dist/utils/wallet.js.map +1 -1
  18. package/dist/wallet/constants.js +1 -7
  19. package/dist/wallet/constants.js.map +1 -1
  20. package/dist/wallet/index.js +181 -86
  21. package/dist/wallet/index.js.map +1 -1
  22. package/docs/html/assets/search.js +1 -1
  23. package/docs/html/classes/Electrum.html +79 -70
  24. package/docs/html/classes/Transaction.html +59 -28
  25. package/docs/html/classes/Wallet.html +224 -174
  26. package/docs/html/enums/EAddressType.html +22 -7
  27. package/docs/html/enums/EAvailableNetworks.html +19 -11
  28. package/docs/html/enums/EBoostType.html +14 -6
  29. package/docs/html/enums/EElectrumNetworks.html +15 -7
  30. package/docs/html/enums/EFeeId.html +17 -9
  31. package/docs/html/enums/EPaymentType.html +14 -6
  32. package/docs/html/enums/EProtocol.html +14 -6
  33. package/docs/html/enums/EUnit.html +15 -7
  34. package/docs/html/functions/availableNetworks.html +12 -4
  35. package/docs/html/functions/constructByteCountParam.html +12 -4
  36. package/docs/html/functions/decodeOpReturnMessage.html +12 -4
  37. package/docs/html/functions/decodeRawTransaction.html +12 -4
  38. package/docs/html/functions/err.html +12 -4
  39. package/docs/html/functions/formatKeyDerivationPath.html +12 -4
  40. package/docs/html/functions/formatPeerData.html +12 -4
  41. package/docs/html/functions/generateMnemonic.html +12 -4
  42. package/docs/html/functions/generateWalletId.html +12 -4
  43. package/docs/html/functions/getAddressFromKeyPair.html +222 -0
  44. package/docs/html/functions/getAddressFromScriptPubKey.html +12 -4
  45. package/docs/html/functions/getAddressTypeFromPath.html +12 -4
  46. package/docs/html/functions/getAddressesFromPrivateKey.html +222 -0
  47. package/docs/html/functions/getByteCount.html +12 -4
  48. package/docs/html/functions/getDataFallback.html +12 -4
  49. package/docs/html/functions/getDefaultPort.html +12 -4
  50. package/docs/html/functions/getDefaultWalletData.html +12 -4
  51. package/docs/html/functions/getDefaultWalletDataKeys.html +12 -4
  52. package/docs/html/functions/getElectrumNetwork.html +216 -0
  53. package/docs/html/functions/getHighestUsedIndexFromTxHashes.html +12 -4
  54. package/docs/html/functions/getKeyDerivationPath.html +12 -4
  55. package/docs/html/functions/getKeyDerivationPathObject.html +12 -4
  56. package/docs/html/functions/getKeyDerivationPathString.html +12 -4
  57. package/docs/html/functions/getKeyValue.html +12 -4
  58. package/docs/html/functions/getPeers.html +12 -4
  59. package/docs/html/functions/getProtocolForPort.html +12 -4
  60. package/docs/html/functions/getScriptHash.html +12 -4
  61. package/docs/html/functions/getSeed.html +12 -4
  62. package/docs/html/functions/getSeedHash.html +12 -4
  63. package/docs/html/functions/getSha256.html +12 -4
  64. package/docs/html/functions/getStorageKeyValues.html +12 -4
  65. package/docs/html/{variables/mostUsedExchangeTickers.html → functions/getTapRootAddressFromPublicKey.html} +74 -97
  66. package/docs/html/functions/getTxFee.html +12 -4
  67. package/docs/html/functions/getWalletDataStorageKey.html +12 -4
  68. package/docs/html/functions/isP2trPrefix.html +217 -0
  69. package/docs/html/functions/isValidBech32mEncodedString.html +12 -4
  70. package/docs/html/functions/objectKeys-1.html +12 -4
  71. package/docs/html/functions/objectsMatch.html +12 -4
  72. package/docs/html/functions/ok.html +12 -4
  73. package/docs/html/functions/parseOnChainPaymentRequest.html +12 -4
  74. package/docs/html/functions/reduceValue.html +12 -4
  75. package/docs/html/functions/removeDustOutputs.html +12 -4
  76. package/docs/html/functions/setReplaceByFee.html +12 -4
  77. package/docs/html/functions/shuffleArray.html +12 -4
  78. package/docs/html/functions/{getExchangeRates.html → sleep.html} +22 -12
  79. package/docs/html/functions/validateAddress.html +12 -4
  80. package/docs/html/functions/validateMnemonic.html +12 -4
  81. package/docs/html/functions/validateTransaction.html +12 -4
  82. package/docs/html/index.html +22 -6
  83. package/docs/html/interfaces/IAddInput.html +16 -8
  84. package/docs/html/interfaces/IAddress.html +17 -9
  85. package/docs/html/interfaces/IAddressData.html +15 -7
  86. package/docs/html/interfaces/IAddressType.html +12 -4
  87. package/docs/html/interfaces/IAddressTypeData.html +18 -10
  88. package/docs/html/interfaces/IAddresses.html +12 -4
  89. package/docs/html/interfaces/IBoostedTransaction.html +16 -8
  90. package/docs/html/interfaces/IBoostedTransactions.html +12 -4
  91. package/docs/html/interfaces/ICreateTransaction.html +14 -6
  92. package/docs/html/interfaces/ICustomGetAddress.html +15 -7
  93. package/docs/html/interfaces/ICustomGetScriptHash.html +14 -6
  94. package/docs/html/interfaces/IElectrumGetAddressBalanceRes.html +15 -7
  95. package/docs/html/interfaces/IFormattedPeerData.html +17 -9
  96. package/docs/html/interfaces/IFormattedTransaction.html +31 -23
  97. package/docs/html/interfaces/IFormattedTransactions.html +12 -4
  98. package/docs/html/interfaces/IGenerateAddresses.html +19 -11
  99. package/docs/html/interfaces/IGenerateAddressesResponse.html +14 -6
  100. package/docs/html/interfaces/IGetAddress.html +15 -7
  101. package/docs/html/interfaces/IGetAddressBalanceRes.html +14 -6
  102. package/docs/html/interfaces/IGetAddressByPath.html +14 -6
  103. package/docs/html/interfaces/IGetAddressHistoryResponse.html +19 -11
  104. package/docs/html/interfaces/IGetAddressResponse.html +15 -7
  105. package/docs/html/interfaces/IGetAddressScriptHashBalances.html +17 -9
  106. package/docs/html/interfaces/IGetAddressScriptHashesHistoryResponse.html +17 -9
  107. package/docs/html/interfaces/{IExchangeRates.html → IGetAddressesFromKeyPair.html} +45 -23
  108. package/docs/html/interfaces/IGetAddressesFromPrivateKey.html +234 -0
  109. package/docs/html/interfaces/IGetDerivationPath.html +18 -10
  110. package/docs/html/interfaces/IGetFeeEstimatesResponse.html +16 -8
  111. package/docs/html/interfaces/IGetHeaderResponse.html +17 -9
  112. package/docs/html/interfaces/IGetNextAvailableAddressResponse.html +16 -8
  113. package/docs/html/interfaces/IGetTransactions.html +17 -9
  114. package/docs/html/interfaces/IGetTransactionsFromInputs.html +17 -9
  115. package/docs/html/interfaces/IGetUtxosResponse.html +14 -6
  116. package/docs/html/interfaces/IHeader.html +15 -7
  117. package/docs/html/interfaces/IIndexes.html +16 -8
  118. package/docs/html/interfaces/IKeyDerivationPath.html +17 -9
  119. package/docs/html/interfaces/IKeyDerivationPathData.html +14 -6
  120. package/docs/html/interfaces/INewBlock.html +14 -6
  121. package/docs/html/interfaces/IOnchainFees.html +17 -9
  122. package/docs/html/interfaces/IOutput.html +15 -7
  123. package/docs/html/interfaces/IPeerData.html +15 -7
  124. package/docs/html/interfaces/IPrivateKeyInfo.html +248 -0
  125. package/docs/html/interfaces/IRbfData.html +18 -10
  126. package/docs/html/interfaces/ISend.html +14 -6
  127. package/docs/html/interfaces/ISendTransaction.html +28 -20
  128. package/docs/html/interfaces/ISendTx.html +15 -7
  129. package/docs/html/interfaces/ISetupTransaction.html +17 -9
  130. package/docs/html/interfaces/ISubscribeToAddress.html +16 -8
  131. package/docs/html/interfaces/ISubscribeToHeader.html +16 -8
  132. package/docs/html/interfaces/ISweepPrivateKey.html +255 -0
  133. package/docs/html/interfaces/ISweepPrivateKeyRes.html +241 -0
  134. package/docs/html/interfaces/ITargets.html +16 -8
  135. package/docs/html/interfaces/ITransaction.html +17 -9
  136. package/docs/html/interfaces/ITxHash.html +13 -5
  137. package/docs/html/interfaces/ITxHashes.html +15 -7
  138. package/docs/html/interfaces/IUtxo.html +27 -21
  139. package/docs/html/interfaces/IVin.html +17 -9
  140. package/docs/html/interfaces/IVout.html +15 -7
  141. package/docs/html/interfaces/IWallet.html +53 -20
  142. package/docs/html/interfaces/IWalletData.html +30 -29
  143. package/docs/html/types/ElectrumConnectionPubSub.html +12 -4
  144. package/docs/html/types/ElectrumConnectionSubscription.html +13 -5
  145. package/docs/html/types/InputData.html +12 -4
  146. package/docs/html/types/ObjectKeys.html +12 -4
  147. package/docs/html/types/Result.html +12 -4
  148. package/docs/html/types/TAddressIndexInfo.html +12 -4
  149. package/docs/html/types/TAddressLabel.html +12 -4
  150. package/docs/html/types/TAddressType.html +12 -4
  151. package/docs/html/types/TAddressTypeContent.html +12 -4
  152. package/docs/html/types/TAddressTypes.html +12 -4
  153. package/docs/html/types/TAvailableNetworks.html +12 -4
  154. package/docs/html/types/TConnectToElectrumRes.html +12 -4
  155. package/docs/html/types/TDecodeRawTx.html +12 -4
  156. package/docs/html/types/TElectrumNetworks.html +12 -4
  157. package/docs/html/types/TGetAddressHistory.html +12 -4
  158. package/docs/html/types/TGetByteCountInput.html +12 -4
  159. package/docs/html/types/TGetByteCountInputs.html +12 -4
  160. package/docs/html/types/TGetByteCountOutput.html +12 -4
  161. package/docs/html/types/TGetByteCountOutputs.html +12 -4
  162. package/docs/html/types/TGetData.html +12 -4
  163. package/docs/html/types/TGetTotalFeeObj.html +12 -4
  164. package/docs/html/types/TKeyDerivationAccount.html +12 -4
  165. package/docs/html/types/TKeyDerivationChange.html +12 -4
  166. package/docs/html/types/TKeyDerivationCoinType.html +12 -4
  167. package/docs/html/types/TKeyDerivationIndex.html +12 -4
  168. package/docs/html/types/TKeyDerivationPurpose.html +12 -4
  169. package/docs/html/types/TMessageDataMap.html +12 -4
  170. package/docs/html/types/TMessageKeys.html +12 -4
  171. package/docs/html/types/TOnMessage.html +12 -4
  172. package/docs/html/types/TProcessUnconfirmedTransactions.html +12 -4
  173. package/docs/html/types/TProtocol.html +12 -4
  174. package/docs/html/types/TServer.html +12 -4
  175. package/docs/html/types/TSetData.html +12 -4
  176. package/docs/html/types/TSetupTransactionResponse.html +12 -4
  177. package/docs/html/types/TStorage.html +12 -4
  178. package/docs/html/types/TSubscribedReceive.html +12 -4
  179. package/docs/html/types/TTransactionMessage.html +12 -4
  180. package/docs/html/types/TTxResponse.html +12 -4
  181. package/docs/html/types/TTxResult.html +12 -4
  182. package/docs/html/types/TUnspentAddressScriptHashData.html +12 -4
  183. package/docs/html/types/TWalletDataKeys.html +12 -4
  184. package/docs/html/variables/defaultElectrumPorts.html +12 -4
  185. package/docs/html/variables/electrumConnection.html +12 -4
  186. package/docs/markdown/README.md +224 -128
  187. package/docs/markdown/classes/Electrum.md +74 -72
  188. package/docs/markdown/classes/Transaction.md +48 -23
  189. package/docs/markdown/classes/Wallet.md +240 -181
  190. package/docs/markdown/enums/EAddressType.md +14 -3
  191. package/docs/markdown/enums/EAvailableNetworks.md +7 -7
  192. package/docs/markdown/enums/EBoostType.md +2 -2
  193. package/docs/markdown/enums/EElectrumNetworks.md +3 -3
  194. package/docs/markdown/enums/EFeeId.md +5 -5
  195. package/docs/markdown/enums/EPaymentType.md +2 -2
  196. package/docs/markdown/enums/EProtocol.md +2 -2
  197. package/docs/markdown/enums/EUnit.md +3 -3
  198. package/docs/markdown/interfaces/IAddInput.md +4 -4
  199. package/docs/markdown/interfaces/IAddress.md +5 -5
  200. package/docs/markdown/interfaces/IAddressData.md +3 -3
  201. package/docs/markdown/interfaces/IAddressTypeData.md +6 -6
  202. package/docs/markdown/interfaces/IBoostedTransaction.md +4 -4
  203. package/docs/markdown/interfaces/ICreateTransaction.md +2 -2
  204. package/docs/markdown/interfaces/ICustomGetAddress.md +3 -3
  205. package/docs/markdown/interfaces/ICustomGetScriptHash.md +2 -2
  206. package/docs/markdown/interfaces/IElectrumGetAddressBalanceRes.md +3 -3
  207. package/docs/markdown/interfaces/IFormattedPeerData.md +5 -5
  208. package/docs/markdown/interfaces/IFormattedTransaction.md +19 -19
  209. package/docs/markdown/interfaces/IGenerateAddresses.md +7 -7
  210. package/docs/markdown/interfaces/IGenerateAddressesResponse.md +2 -2
  211. package/docs/markdown/interfaces/IGetAddress.md +3 -3
  212. package/docs/markdown/interfaces/IGetAddressBalanceRes.md +2 -2
  213. package/docs/markdown/interfaces/IGetAddressByPath.md +2 -2
  214. package/docs/markdown/interfaces/IGetAddressHistoryResponse.md +7 -7
  215. package/docs/markdown/interfaces/IGetAddressResponse.md +3 -3
  216. package/docs/markdown/interfaces/IGetAddressScriptHashBalances.md +5 -5
  217. package/docs/markdown/interfaces/IGetAddressScriptHashesHistoryResponse.md +5 -5
  218. package/docs/markdown/interfaces/IGetAddressesFromKeyPair.md +30 -0
  219. package/docs/markdown/interfaces/IGetAddressesFromPrivateKey.md +30 -0
  220. package/docs/markdown/interfaces/IGetDerivationPath.md +6 -6
  221. package/docs/markdown/interfaces/IGetFeeEstimatesResponse.md +4 -4
  222. package/docs/markdown/interfaces/IGetHeaderResponse.md +5 -5
  223. package/docs/markdown/interfaces/IGetNextAvailableAddressResponse.md +4 -4
  224. package/docs/markdown/interfaces/IGetTransactions.md +5 -5
  225. package/docs/markdown/interfaces/IGetTransactionsFromInputs.md +5 -5
  226. package/docs/markdown/interfaces/IGetUtxosResponse.md +2 -2
  227. package/docs/markdown/interfaces/IHeader.md +3 -3
  228. package/docs/markdown/interfaces/IIndexes.md +4 -4
  229. package/docs/markdown/interfaces/IKeyDerivationPath.md +5 -5
  230. package/docs/markdown/interfaces/IKeyDerivationPathData.md +2 -2
  231. package/docs/markdown/interfaces/INewBlock.md +2 -2
  232. package/docs/markdown/interfaces/IOnchainFees.md +5 -5
  233. package/docs/markdown/interfaces/IOutput.md +3 -3
  234. package/docs/markdown/interfaces/IPeerData.md +3 -3
  235. package/docs/markdown/interfaces/IPrivateKeyInfo.md +52 -0
  236. package/docs/markdown/interfaces/IRbfData.md +6 -6
  237. package/docs/markdown/interfaces/ISend.md +2 -2
  238. package/docs/markdown/interfaces/ISendTransaction.md +16 -16
  239. package/docs/markdown/interfaces/ISendTx.md +3 -3
  240. package/docs/markdown/interfaces/ISetupTransaction.md +5 -5
  241. package/docs/markdown/interfaces/ISubscribeToAddress.md +4 -4
  242. package/docs/markdown/interfaces/ISubscribeToHeader.md +4 -4
  243. package/docs/markdown/interfaces/ISweepPrivateKey.md +63 -0
  244. package/docs/markdown/interfaces/ISweepPrivateKeyRes.md +41 -0
  245. package/docs/markdown/interfaces/ITargets.md +4 -4
  246. package/docs/markdown/interfaces/ITransaction.md +5 -5
  247. package/docs/markdown/interfaces/ITxHash.md +1 -1
  248. package/docs/markdown/interfaces/ITxHashes.md +3 -3
  249. package/docs/markdown/interfaces/IUtxo.md +18 -23
  250. package/docs/markdown/interfaces/IVin.md +5 -5
  251. package/docs/markdown/interfaces/IVout.md +3 -3
  252. package/docs/markdown/interfaces/IWallet.md +50 -15
  253. package/docs/markdown/interfaces/IWalletData.md +18 -29
  254. package/package.json +3 -3
  255. package/src/electrum/index.ts +147 -60
  256. package/src/types/electrum.ts +7 -0
  257. package/src/types/transaction.ts +5 -0
  258. package/src/types/wallet.ts +7 -1
  259. package/src/utils/helpers.ts +14 -0
  260. package/src/utils/wallet.ts +73 -0
  261. package/src/wallet/constants.ts +0 -8
  262. package/src/wallet/index.ts +262 -118
  263. package/tests/wallet.test.ts +71 -1
  264. package/dist/mempool/index.js +0 -28
  265. package/dist/mempool/index.js.map +0 -1
  266. package/dist/types/mempool/index.d.ts +0 -15
  267. package/dist/types/mempool.js +0 -3
  268. package/dist/types/mempool.js.map +0 -1
  269. package/dist/types/types/mempool.d.ts +0 -16
  270. package/dist/types/utils/exchange-rate.d.ts +0 -30
  271. package/dist/utils/exchange-rate.js +0 -49
  272. package/dist/utils/exchange-rate.js.map +0 -1
  273. package/docs/markdown/interfaces/IExchangeRates.md +0 -7
@@ -11,6 +11,7 @@ import {
11
11
  ITxHashes,
12
12
  IWalletData,
13
13
  ObjectKeys,
14
+ TGapLimitOptions,
14
15
  TGetData,
15
16
  TKeyDerivationPurpose
16
17
  } from '../types';
@@ -26,6 +27,7 @@ import {
26
27
  WALLET_ID_PREFIX,
27
28
  BITKIT_WALLET_SEED_HASH_PREFIX
28
29
  } from '../wallet/constants';
30
+ import { getAddressIndexDiff } from './helpers';
29
31
 
30
32
  /**
31
33
  * Returns the default wallet data object.
@@ -349,3 +351,74 @@ export const getTxFee = ({
349
351
  satsPerByte: number;
350
352
  transactionByteCount: number;
351
353
  }): number => transactionByteCount * satsPerByte;
354
+
355
+ export const filterAddressesForGapLimit = ({
356
+ addresses,
357
+ index,
358
+ gapLimitOptions
359
+ }: {
360
+ addresses: IAddress[];
361
+ index: number;
362
+ gapLimitOptions: TGapLimitOptions;
363
+ }): IAddress[] => {
364
+ const { lookBehind, lookAhead } = gapLimitOptions;
365
+ return addresses.filter((a) => {
366
+ if (a.index >= index) {
367
+ return getAddressIndexDiff(index, a.index) <= lookAhead;
368
+ }
369
+ return getAddressIndexDiff(index, a.index) <= lookBehind;
370
+ });
371
+ };
372
+
373
+ export const filterAddressesObjForGapLimit = ({
374
+ addresses,
375
+ index,
376
+ gapLimitOptions
377
+ }: {
378
+ addresses: IAddresses;
379
+ index: number;
380
+ gapLimitOptions: TGapLimitOptions;
381
+ }): IAddresses => {
382
+ const { lookBehind, lookAhead } = gapLimitOptions;
383
+ const response: IAddresses = {};
384
+ Object.values(addresses).map((a) => {
385
+ if (a.index >= index) {
386
+ if (getAddressIndexDiff(a.index, index) <= lookAhead) {
387
+ response[a.scriptHash] = a;
388
+ }
389
+ } else {
390
+ if (getAddressIndexDiff(a.index, index) <= lookBehind) {
391
+ response[a.scriptHash] = a;
392
+ }
393
+ }
394
+ });
395
+ return response;
396
+ };
397
+
398
+ export const filterAddressesObjForStartingIndex = ({
399
+ addresses,
400
+ index
401
+ }: {
402
+ addresses: IAddresses;
403
+ index: number;
404
+ }): IAddresses => {
405
+ const response: IAddresses = {};
406
+ Object.values(addresses).map((a) => {
407
+ if (a.index >= index) response[a.scriptHash] = a;
408
+ });
409
+ return response;
410
+ };
411
+
412
+ export const filterAddressesObjForSingleIndex = ({
413
+ addresses,
414
+ addressIndex
415
+ }: {
416
+ addresses: IAddresses;
417
+ addressIndex: number;
418
+ }): IAddresses => {
419
+ const response: IAddresses = {};
420
+ Object.values(addresses).map((a) => {
421
+ if (a.index === addressIndex) response[a.scriptHash] = a;
422
+ });
423
+ return response;
424
+ };
@@ -1,5 +1,3 @@
1
- import { EAvailableNetworks } from '../types';
2
-
3
1
  export const BITKIT_WALLET_SEED_HASH_PREFIX = Buffer.from(
4
2
  '@Bitkit/wallet-uuid'
5
3
  );
@@ -12,12 +10,6 @@ export const GENERATE_ADDRESS_AMOUNT = 5;
12
10
  // TODO: Add this as a settings for users to adjust when needed.
13
11
  export const GAP_LIMIT = 20;
14
12
 
15
- export const CHUNK_LIMIT = {
16
- [EAvailableNetworks.bitcoin]: 10,
17
- [EAvailableNetworks.bitcoinTestnet]: 15,
18
- [EAvailableNetworks.bitcoinRegtest]: 4
19
- };
20
-
21
13
  //How much of the users funds we allow to be used for Lightning.
22
14
  export const SPENDING_LIMIT_RATIO = 0.8;
23
15