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
@@ -14,7 +14,6 @@
14
14
  - [boostedTransactions](IWalletData.md#boostedtransactions)
15
15
  - [changeAddressIndex](IWalletData.md#changeaddressindex)
16
16
  - [changeAddresses](IWalletData.md#changeaddresses)
17
- - [exchangeRates](IWalletData.md#exchangerates)
18
17
  - [feeEstimates](IWalletData.md#feeestimates)
19
18
  - [header](IWalletData.md#header)
20
19
  - [id](IWalletData.md#id)
@@ -34,7 +33,7 @@
34
33
 
35
34
  #### Defined in
36
35
 
37
- [types/wallet.ts:155](https://github.com/synonymdev/beignet/blob/583604f/src/types/wallet.ts#L155)
36
+ [types/wallet.ts:158](https://github.com/synonymdev/beignet/blob/05d5011/src/types/wallet.ts#L158)
38
37
 
39
38
  ___
40
39
 
@@ -44,7 +43,7 @@ ___
44
43
 
45
44
  #### Defined in
46
45
 
47
- [types/wallet.ts:151](https://github.com/synonymdev/beignet/blob/583604f/src/types/wallet.ts#L151)
46
+ [types/wallet.ts:154](https://github.com/synonymdev/beignet/blob/05d5011/src/types/wallet.ts#L154)
48
47
 
49
48
  ___
50
49
 
@@ -54,7 +53,7 @@ ___
54
53
 
55
54
  #### Defined in
56
55
 
57
- [types/wallet.ts:153](https://github.com/synonymdev/beignet/blob/583604f/src/types/wallet.ts#L153)
56
+ [types/wallet.ts:156](https://github.com/synonymdev/beignet/blob/05d5011/src/types/wallet.ts#L156)
58
57
 
59
58
  ___
60
59
 
@@ -64,7 +63,7 @@ ___
64
63
 
65
64
  #### Defined in
66
65
 
67
- [types/wallet.ts:165](https://github.com/synonymdev/beignet/blob/583604f/src/types/wallet.ts#L165)
66
+ [types/wallet.ts:168](https://github.com/synonymdev/beignet/blob/05d5011/src/types/wallet.ts#L168)
68
67
 
69
68
  ___
70
69
 
@@ -74,7 +73,7 @@ ___
74
73
 
75
74
  #### Defined in
76
75
 
77
- [types/wallet.ts:160](https://github.com/synonymdev/beignet/blob/583604f/src/types/wallet.ts#L160)
76
+ [types/wallet.ts:163](https://github.com/synonymdev/beignet/blob/05d5011/src/types/wallet.ts#L163)
78
77
 
79
78
  ___
80
79
 
@@ -84,7 +83,7 @@ ___
84
83
 
85
84
  #### Defined in
86
85
 
87
- [types/wallet.ts:163](https://github.com/synonymdev/beignet/blob/583604f/src/types/wallet.ts#L163)
86
+ [types/wallet.ts:166](https://github.com/synonymdev/beignet/blob/05d5011/src/types/wallet.ts#L166)
88
87
 
89
88
  ___
90
89
 
@@ -94,7 +93,7 @@ ___
94
93
 
95
94
  #### Defined in
96
95
 
97
- [types/wallet.ts:156](https://github.com/synonymdev/beignet/blob/583604f/src/types/wallet.ts#L156)
96
+ [types/wallet.ts:159](https://github.com/synonymdev/beignet/blob/05d5011/src/types/wallet.ts#L159)
98
97
 
99
98
  ___
100
99
 
@@ -104,17 +103,7 @@ ___
104
103
 
105
104
  #### Defined in
106
105
 
107
- [types/wallet.ts:154](https://github.com/synonymdev/beignet/blob/583604f/src/types/wallet.ts#L154)
108
-
109
- ___
110
-
111
- ### exchangeRates
112
-
113
- • **exchangeRates**: [`IExchangeRates`](IExchangeRates.md)
114
-
115
- #### Defined in
116
-
117
- [types/wallet.ts:167](https://github.com/synonymdev/beignet/blob/583604f/src/types/wallet.ts#L167)
106
+ [types/wallet.ts:157](https://github.com/synonymdev/beignet/blob/05d5011/src/types/wallet.ts#L157)
118
107
 
119
108
  ___
120
109
 
@@ -124,7 +113,7 @@ ___
124
113
 
125
114
  #### Defined in
126
115
 
127
- [types/wallet.ts:168](https://github.com/synonymdev/beignet/blob/583604f/src/types/wallet.ts#L168)
116
+ [types/wallet.ts:170](https://github.com/synonymdev/beignet/blob/05d5011/src/types/wallet.ts#L170)
128
117
 
129
118
  ___
130
119
 
@@ -134,7 +123,7 @@ ___
134
123
 
135
124
  #### Defined in
136
125
 
137
- [types/wallet.ts:152](https://github.com/synonymdev/beignet/blob/583604f/src/types/wallet.ts#L152)
126
+ [types/wallet.ts:155](https://github.com/synonymdev/beignet/blob/05d5011/src/types/wallet.ts#L155)
138
127
 
139
128
  ___
140
129
 
@@ -144,7 +133,7 @@ ___
144
133
 
145
134
  #### Defined in
146
135
 
147
- [types/wallet.ts:150](https://github.com/synonymdev/beignet/blob/583604f/src/types/wallet.ts#L150)
136
+ [types/wallet.ts:153](https://github.com/synonymdev/beignet/blob/05d5011/src/types/wallet.ts#L153)
148
137
 
149
138
  ___
150
139
 
@@ -154,7 +143,7 @@ ___
154
143
 
155
144
  #### Defined in
156
145
 
157
- [types/wallet.ts:157](https://github.com/synonymdev/beignet/blob/583604f/src/types/wallet.ts#L157)
146
+ [types/wallet.ts:160](https://github.com/synonymdev/beignet/blob/05d5011/src/types/wallet.ts#L160)
158
147
 
159
148
  ___
160
149
 
@@ -164,7 +153,7 @@ ___
164
153
 
165
154
  #### Defined in
166
155
 
167
- [types/wallet.ts:158](https://github.com/synonymdev/beignet/blob/583604f/src/types/wallet.ts#L158)
156
+ [types/wallet.ts:161](https://github.com/synonymdev/beignet/blob/05d5011/src/types/wallet.ts#L161)
168
157
 
169
158
  ___
170
159
 
@@ -174,7 +163,7 @@ ___
174
163
 
175
164
  #### Defined in
176
165
 
177
- [types/wallet.ts:166](https://github.com/synonymdev/beignet/blob/583604f/src/types/wallet.ts#L166)
166
+ [types/wallet.ts:169](https://github.com/synonymdev/beignet/blob/05d5011/src/types/wallet.ts#L169)
178
167
 
179
168
  ___
180
169
 
@@ -184,7 +173,7 @@ ___
184
173
 
185
174
  #### Defined in
186
175
 
187
- [types/wallet.ts:164](https://github.com/synonymdev/beignet/blob/583604f/src/types/wallet.ts#L164)
176
+ [types/wallet.ts:167](https://github.com/synonymdev/beignet/blob/05d5011/src/types/wallet.ts#L167)
188
177
 
189
178
  ___
190
179
 
@@ -194,7 +183,7 @@ ___
194
183
 
195
184
  #### Defined in
196
185
 
197
- [types/wallet.ts:162](https://github.com/synonymdev/beignet/blob/583604f/src/types/wallet.ts#L162)
186
+ [types/wallet.ts:165](https://github.com/synonymdev/beignet/blob/05d5011/src/types/wallet.ts#L165)
198
187
 
199
188
  ___
200
189
 
@@ -204,7 +193,7 @@ ___
204
193
 
205
194
  #### Defined in
206
195
 
207
- [types/wallet.ts:161](https://github.com/synonymdev/beignet/blob/583604f/src/types/wallet.ts#L161)
196
+ [types/wallet.ts:164](https://github.com/synonymdev/beignet/blob/05d5011/src/types/wallet.ts#L164)
208
197
 
209
198
  ___
210
199
 
@@ -214,4 +203,4 @@ ___
214
203
 
215
204
  #### Defined in
216
205
 
217
- [types/wallet.ts:159](https://github.com/synonymdev/beignet/blob/583604f/src/types/wallet.ts#L159)
206
+ [types/wallet.ts:162](https://github.com/synonymdev/beignet/blob/05d5011/src/types/wallet.ts#L162)
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "beignet",
3
- "version": "0.0.21",
3
+ "version": "0.0.23",
4
4
  "description": "A self-custodial, JS Bitcoin wallet management library.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
7
  "test": "yarn build && env mocha --exit -r ts-node/register 'tests/**/*.ts'",
8
8
  "test:wallet": "yarn build && env mocha --exit -r ts-node/register 'tests/wallet.test.ts'",
9
9
  "test:electrum": "yarn build && env mocha --exit -r ts-node/register 'tests/electrum.test.ts'",
10
- "test:derivation": " yarn build && env mocha --exit -r ts-node/register 'tests/derivation.test.ts'",
11
- "test:transaction": " yarn build && env mocha --exit -r ts-node/register 'tests/transaction.test.ts'",
10
+ "test:derivation": "yarn build && env mocha --exit -r ts-node/register 'tests/derivation.test.ts'",
11
+ "test:transaction": "yarn build && env mocha --exit -r ts-node/register 'tests/transaction.test.ts'",
12
12
  "test:storage": "yarn build && env mocha --exit -r ts-node/register 'tests/storage.test.ts'",
13
13
  "example": "ts-node example",
14
14
  "lint": "eslint . --ext .js,.jsx,.ts,.tsx",
@@ -1,11 +1,13 @@
1
1
  import {
2
+ EAddressType,
2
3
  EAvailableNetworks,
4
+ EElectrumNetworks,
5
+ EScanningStrategy,
3
6
  IAddress,
4
7
  IAddresses,
5
- TAddressTypeContent,
6
- TConnectToElectrumRes,
7
8
  IElectrumGetAddressBalanceRes,
8
9
  IGetAddressHistoryResponse,
10
+ IGetAddressScriptHashBalances,
9
11
  IGetAddressScriptHashesHistoryResponse,
10
12
  IGetHeaderResponse,
11
13
  IGetTransactions,
@@ -13,37 +15,39 @@ import {
13
15
  IGetUtxosResponse,
14
16
  IHeader,
15
17
  INewBlock,
18
+ IPeerData,
16
19
  ISubscribeToAddress,
17
20
  ISubscribeToHeader,
18
21
  ITransaction,
19
22
  ITxHash,
20
23
  IUtxo,
21
- EElectrumNetworks,
24
+ TAddressTypeContent,
25
+ TConnectToElectrumRes,
26
+ TGetAddressHistory,
27
+ TOnMessage,
22
28
  TServer,
23
29
  TSubscribedReceive,
24
30
  TTxResponse,
25
31
  TTxResult,
26
- TUnspentAddressScriptHashData,
27
- IPeerData,
28
- TGetAddressHistory,
29
- TOnMessage,
30
- IGetAddressScriptHashBalances
32
+ TUnspentAddressScriptHashData
31
33
  } from '../types';
32
34
  import * as electrum from 'rn-electrum-client/helpers';
33
35
  import {
34
36
  err,
37
+ filterAddressesForGapLimit,
38
+ filterAddressesObjForGapLimit,
39
+ filterAddressesObjForSingleIndex,
40
+ filterAddressesObjForStartingIndex,
35
41
  getAddressFromScriptPubKey,
36
42
  getElectrumNetwork,
43
+ getScriptHash,
37
44
  ok,
38
45
  Result,
39
46
  sleep
40
47
  } from '../utils';
41
48
  import { Wallet } from '../wallet';
42
- import { CHUNK_LIMIT, GAP_LIMIT } from '../wallet/constants';
43
- import { getScriptHash } from '../utils';
44
- import { POLLING_INTERVAL } from '../shapes';
49
+ import { onMessageKeys, POLLING_INTERVAL } from '../shapes';
45
50
  import { Block } from 'bitcoinjs-lib';
46
- import { onMessageKeys } from '../shapes';
47
51
  import { Server } from 'net';
48
52
  import { TLSSocket } from 'tls';
49
53
 
@@ -68,13 +72,17 @@ export class Electrum {
68
72
  public electrumNetwork: EElectrumNetworks;
69
73
  public connectedToElectrum: boolean;
70
74
  public onReceive?: (data: unknown) => void;
75
+ public batchLimit: number;
76
+ public batchDelay: number;
71
77
  constructor({
72
78
  wallet,
73
79
  servers,
74
80
  network,
75
81
  onReceive,
76
82
  tls: _tls,
77
- net: _net
83
+ net: _net,
84
+ batchLimit = 20,
85
+ batchDelay = 50
78
86
  }: {
79
87
  wallet: Wallet;
80
88
  servers?: TServer | TServer[];
@@ -82,6 +90,8 @@ export class Electrum {
82
90
  onReceive?: (data: unknown) => void;
83
91
  tls?: TLSSocket;
84
92
  net?: Server;
93
+ batchLimit?: number;
94
+ batchDelay?: number;
85
95
  }) {
86
96
  this._wallet = wallet;
87
97
  this.sendMessage = wallet.sendMessage;
@@ -92,6 +102,8 @@ export class Electrum {
92
102
  this.onReceive = onReceive;
93
103
  this.tls = _tls ?? tls;
94
104
  this.net = _net ?? net;
105
+ this.batchLimit = batchLimit;
106
+ this.batchDelay = batchDelay;
95
107
  if (!this.tls || !this.net) {
96
108
  throw new Error(
97
109
  'TLS and NET modules are not available and were not passed as instances'
@@ -286,15 +298,21 @@ export class Electrum {
286
298
  addressIndex >= 0 &&
287
299
  changeAddressIndex >= 0
288
300
  ) {
289
- addressValues = addressValues.filter(
290
- (a) => Math.abs(addressIndex - a.index) <= GAP_LIMIT
291
- );
292
- changeAddressValues = changeAddressValues.filter(
293
- (a) => Math.abs(changeAddressIndex - a.index) <= GAP_LIMIT
294
- );
301
+ addressValues = filterAddressesForGapLimit({
302
+ addresses: addressValues,
303
+ index: addressIndex,
304
+ gapLimitOptions: this._wallet.gapLimitOptions
305
+ });
306
+ changeAddressValues = filterAddressesForGapLimit({
307
+ addresses: changeAddressValues,
308
+ index: changeAddressIndex,
309
+ gapLimitOptions: this._wallet.gapLimitOptions
310
+ });
295
311
  }
312
+ const utxoScriptHashes: IAddress[] = currentWallet.utxos;
296
313
 
297
314
  scriptHashes = [
315
+ ...utxoScriptHashes,
298
316
  ...scriptHashes,
299
317
  ...addressValues,
300
318
  ...changeAddressValues
@@ -312,10 +330,9 @@ export class Electrum {
312
330
  const combinedResponse: TTxResponse[] = [];
313
331
  const promises: Promise<IGetAddressScriptHashesHistoryResponse>[] = [];
314
332
 
315
- const chunkLimit = CHUNK_LIMIT[this.network];
316
333
  // split payload in chunks of 10 addresses per-request
317
- for (let i = 0; i < scriptHashes.length; i += chunkLimit) {
318
- const chunk = scriptHashes.slice(i, i + chunkLimit);
334
+ for (let i = 0; i < scriptHashes.length; i += this.batchLimit) {
335
+ const chunk = scriptHashes.slice(i, i + this.batchLimit);
319
336
  const payload = {
320
337
  key: 'scriptHash',
321
338
  data: chunk
@@ -326,14 +343,14 @@ export class Electrum {
326
343
  network: this.electrumNetwork
327
344
  })
328
345
  );
329
- await sleep(50);
346
+ await sleep(this.batchDelay);
330
347
  promises.push(
331
348
  electrum.getAddressScriptHashesMempool({
332
349
  scriptHashes: payload,
333
350
  network: this.electrumNetwork
334
351
  })
335
352
  );
336
- await sleep(50);
353
+ await sleep(this.batchDelay);
337
354
  }
338
355
 
339
356
  const responses = await Promise.all(promises);
@@ -403,13 +420,22 @@ export class Electrum {
403
420
 
404
421
  /**
405
422
  * Returns UTXO's for a given wallet and network along with the available balance.
406
- * @param {boolean} [scanAllAddresses]
423
+ * @param {EScanningStrategy} [scanningStrategy]
424
+ * @param {number} addressIndex
425
+ * @param {number} changeAddressIndex
426
+ * @param {EAddressType[]} [addressTypesToCheck]
407
427
  * @returns {Promise<Result<IGetUtxosResponse>>}
408
428
  */
409
429
  async getUtxos({
410
- scanAllAddresses = false
430
+ scanningStrategy = EScanningStrategy.gapLimit,
431
+ addressIndex,
432
+ changeAddressIndex,
433
+ addressTypesToCheck = this._wallet.addressTypesToMonitor
411
434
  }: {
412
- scanAllAddresses?: boolean;
435
+ scanningStrategy?: EScanningStrategy;
436
+ addressIndex?: number;
437
+ changeAddressIndex?: number;
438
+ addressTypesToCheck?: EAddressType[];
413
439
  }): Promise<Result<IGetUtxosResponse>> {
414
440
  try {
415
441
  if (!this.connectedToElectrum)
@@ -419,12 +445,11 @@ export class Electrum {
419
445
  });
420
446
  const currentWallet = this._wallet.data;
421
447
 
422
- const addressTypeKeys = this._wallet.addressTypesToMonitor;
423
448
  let addresses = {} as IAddresses;
424
449
  let changeAddresses = {} as IAddresses;
425
450
  const existingUtxos: { [key: string]: IUtxo } = {};
426
451
 
427
- for (const addressType of addressTypeKeys) {
452
+ for (const addressType of addressTypesToCheck) {
428
453
  const addressCount = Object.keys(currentWallet.addresses[addressType])
429
454
  ?.length;
430
455
 
@@ -433,30 +458,66 @@ export class Electrum {
433
458
  break;
434
459
  }
435
460
 
436
- // Grab the current index for both addresses and change addresses.
437
- const addressIndex = currentWallet.addressIndex[addressType].index;
438
- const changeAddressIndex =
439
- currentWallet.changeAddressIndex[addressType].index;
440
-
441
461
  // Grab all addresses and change addresses.
442
462
  const allAddresses = currentWallet.addresses[addressType];
443
463
  const allChangeAddresses = currentWallet.changeAddresses[addressType];
444
464
 
445
- // Instead of scanning all addresses, adhere to the gap limit.
446
- if (!scanAllAddresses && addressIndex >= 0 && changeAddressIndex >= 0) {
447
- Object.values(allAddresses).map((a) => {
448
- if (Math.abs(a.index - addressIndex) <= GAP_LIMIT) {
449
- addresses[a.scriptHash] = a;
450
- }
451
- });
452
- Object.values(allChangeAddresses).map((a) => {
453
- if (Math.abs(a.index - changeAddressIndex) <= GAP_LIMIT) {
454
- changeAddresses[a.scriptHash] = a;
455
- }
456
- });
457
- } else {
465
+ if (scanningStrategy === EScanningStrategy.all) {
458
466
  addresses = { ...addresses, ...allAddresses };
459
467
  changeAddresses = { ...changeAddresses, ...allChangeAddresses };
468
+ } else {
469
+ // Grab the current index for address/change addresses if none were provided.
470
+ if (!addressIndex)
471
+ addressIndex = currentWallet.addressIndex[addressType].index;
472
+ if (!changeAddressIndex)
473
+ changeAddressIndex =
474
+ currentWallet.changeAddressIndex[addressType].index;
475
+
476
+ // Use the lowest index to ensure we're not starting above our current index.
477
+ // TODO: Consider removing this entirely or at least updating it to allow up to the max stored address/change address index.
478
+ const lowestAddressIndex = Math.min(
479
+ addressIndex,
480
+ currentWallet.addressIndex[addressType].index
481
+ );
482
+ const lowestChangeAddressIndex = Math.min(
483
+ changeAddressIndex,
484
+ currentWallet.changeAddressIndex[addressType].index
485
+ );
486
+
487
+ switch (scanningStrategy) {
488
+ case EScanningStrategy.gapLimit:
489
+ addresses = filterAddressesObjForGapLimit({
490
+ addresses: allAddresses,
491
+ index: lowestAddressIndex,
492
+ gapLimitOptions: this._wallet.gapLimitOptions
493
+ });
494
+ changeAddresses = filterAddressesObjForGapLimit({
495
+ addresses: allChangeAddresses,
496
+ index: lowestChangeAddressIndex,
497
+ gapLimitOptions: this._wallet.gapLimitOptions
498
+ });
499
+ break;
500
+ case EScanningStrategy.startingIndex:
501
+ addresses = filterAddressesObjForStartingIndex({
502
+ addresses: allAddresses,
503
+ index: lowestAddressIndex
504
+ });
505
+ changeAddresses = filterAddressesObjForStartingIndex({
506
+ addresses: allChangeAddresses,
507
+ index: lowestChangeAddressIndex
508
+ });
509
+ break;
510
+ case EScanningStrategy.singleIndex:
511
+ addresses = filterAddressesObjForSingleIndex({
512
+ addresses: allAddresses,
513
+ addressIndex
514
+ });
515
+ changeAddresses = filterAddressesObjForSingleIndex({
516
+ addresses: allChangeAddresses,
517
+ addressIndex: changeAddressIndex
518
+ });
519
+ break;
520
+ }
460
521
  }
461
522
  }
462
523
 
@@ -501,10 +562,9 @@ export class Electrum {
501
562
  const result: ITransaction<IUtxo>[] = [];
502
563
  const promises: Promise<IGetTransactions>[] = [];
503
564
 
504
- const chunkLimit = CHUNK_LIMIT[this.network];
505
565
  // split payload in chunks of 10 transactions per-request
506
- for (let i = 0; i < txHashes.length; i += chunkLimit) {
507
- const chunk = txHashes.slice(i, i + chunkLimit);
566
+ for (let i = 0; i < txHashes.length; i += this.batchLimit) {
567
+ const chunk = txHashes.slice(i, i + this.batchLimit);
508
568
 
509
569
  const data = {
510
570
  key: 'tx_hash',
@@ -517,7 +577,7 @@ export class Electrum {
517
577
  network: this.electrumNetwork
518
578
  })
519
579
  );
520
- await sleep(50);
580
+ await sleep(this.batchDelay);
521
581
  }
522
582
  const responses = await Promise.all(promises);
523
583
  responses.forEach((response) => {
@@ -704,6 +764,7 @@ export class Electrum {
704
764
  scriptHashes?: string[];
705
765
  onReceive?: (data: TSubscribedReceive) => void;
706
766
  } = {}): Promise<Result<string>> {
767
+ const allUtxos: IUtxo[] = [];
707
768
  const currentWallet = this._wallet.data;
708
769
  const addressTypeKeys = this._wallet.addressTypesToMonitor;
709
770
  // Gather the receiving address scripthash for each address type if no scripthashes were provided.
@@ -718,20 +779,27 @@ export class Electrum {
718
779
  addressIndex = addressIndex > 0 ? addressIndex : 0;
719
780
 
720
781
  // Only subscribe up to the gap limit.
721
- const addressesInRange = Object.values(addresses).filter(
722
- (address) => Math.abs(address.index - addressIndex) <= GAP_LIMIT
723
- );
724
- const addressesToSubscribe = addressesInRange.slice(-GAP_LIMIT);
725
- const addressScriptHashes = addressesToSubscribe.map(
726
- ({ scriptHash }) => scriptHash
782
+ const addressesInRangeToSubscribe = filterAddressesForGapLimit({
783
+ addresses: Object.values(addresses),
784
+ index: addressIndex,
785
+ gapLimitOptions: this._wallet.gapLimitOptions
786
+ });
787
+ const _scriptHashes = addressesInRangeToSubscribe.map(
788
+ (address) => address.scriptHash
727
789
  );
728
- scriptHashes.push(...addressScriptHashes);
790
+ scriptHashes.push(..._scriptHashes);
729
791
  }
730
792
  }
793
+ // Keep an eye on existing UTXO's regardless of the gap limit.
794
+ currentWallet.utxos.forEach((utxo) => {
795
+ if (!scriptHashes.includes(utxo.scriptHash)) {
796
+ allUtxos.push(utxo);
797
+ }
798
+ });
731
799
  }
732
800
 
733
801
  // Subscribe to all provided script hashes.
734
- const promises = scriptHashes.map(async (scriptHash) => {
802
+ const allScriptHashesPromise = scriptHashes.map(async (scriptHash) => {
735
803
  const response: ISubscribeToAddress = await electrum.subscribeAddress({
736
804
  scriptHash,
737
805
  network: this.electrumNetwork,
@@ -745,8 +813,27 @@ export class Electrum {
745
813
  }
746
814
  });
747
815
 
816
+ const allUtxosPromise = allUtxos.map(async (utxo) => {
817
+ const response: ISubscribeToAddress = await electrum.subscribeAddress({
818
+ scriptHash: utxo.scriptHash,
819
+ network: this.electrumNetwork,
820
+ onReceive: async (data: TSubscribedReceive): Promise<void> => {
821
+ onReceive?.(data);
822
+ await this.getUtxos({
823
+ scanningStrategy: EScanningStrategy.singleIndex,
824
+ addressIndex: utxo.index,
825
+ changeAddressIndex: utxo.index
826
+ });
827
+ this._wallet.refreshWallet({});
828
+ }
829
+ });
830
+ if (response.error) {
831
+ throw Error('Unable to subscribe to receiving addresses.');
832
+ }
833
+ });
834
+
748
835
  try {
749
- await Promise.all(promises);
836
+ await Promise.all([allScriptHashesPromise, allUtxosPromise]);
750
837
  } catch (e) {
751
838
  return err(e);
752
839
  }
@@ -30,6 +30,13 @@ export enum EProtocol {
30
30
  ssl = 'ssl'
31
31
  }
32
32
 
33
+ export enum EScanningStrategy {
34
+ all = 'all', // Scan all addresses/scripthashes
35
+ gapLimit = 'gapLimit', // Adhere to the gap limit within range of the provided index when scanning addresses/scripthashes. If higher than the current index, it will be ignored
36
+ startingIndex = 'startingIndex', // Scan all addresses/scripthashes starting from the provided index. If higher than the current index, it will be ignored
37
+ singleIndex = 'singleIndex' // Scan the single provided address/scripthash
38
+ }
39
+
33
40
  export interface IGetUtxosResponse {
34
41
  utxos: IUtxo[];
35
42
  balance: number;
@@ -58,3 +58,8 @@ export type TGetTotalFeeObj = {
58
58
  satsPerByte: number;
59
59
  maxSatPerByte: number; // Max sats per byte that can be used for a given transaction without exceeding 50% of the balance.
60
60
  };
61
+
62
+ export type TGapLimitOptions = {
63
+ lookAhead: number;
64
+ lookBehind: number;
65
+ };
@@ -6,7 +6,7 @@ import {
6
6
  TServer,
7
7
  TTxResult
8
8
  } from './electrum';
9
- import { EFeeId } from './transaction';
9
+ import { EFeeId, TGapLimitOptions } from './transaction';
10
10
  import { TLSSocket } from 'tls';
11
11
  import { Server } from 'net';
12
12
  import { ECPairInterface } from 'ecpair';
@@ -67,6 +67,7 @@ export interface IUtxo {
67
67
  tx_hash: string;
68
68
  tx_pos: number;
69
69
  value: number;
70
+ publicKey: string;
70
71
  keyPair?: BIP32Interface | ECPairInterface;
71
72
  }
72
73
 
@@ -193,6 +194,8 @@ export interface IWallet {
193
194
  servers?: TServer | TServer[];
194
195
  tls?: TLSSocket;
195
196
  net?: Server;
197
+ batchLimit?: number; // Maximum number of requests to be sent in a single batch
198
+ batchDelay?: number; // Delay (in milliseconds) between each batch of requests
196
199
  };
197
200
  remainOffline?: boolean;
198
201
  onMessage?: TOnMessage;
@@ -205,6 +208,9 @@ export interface IWallet {
205
208
  disableMessages?: boolean;
206
209
  disableMessagesOnCreate?: boolean;
207
210
  addressTypesToMonitor?: EAddressType[];
211
+ gapLimitOptions?: TGapLimitOptions;
212
+ addressLookBehind?: number;
213
+ addressLookAhead?: number;
208
214
  }
209
215
 
210
216
  export interface IAddressData {
@@ -331,3 +331,17 @@ export const sleep = (ms): Promise<void> => {
331
331
  setTimeout(resolve, ms);
332
332
  });
333
333
  };
334
+
335
+ /**
336
+ * Returns the difference between two address indexes.
337
+ * @param addrIndex1
338
+ * @param addrIndex2
339
+ * @returns number
340
+ */
341
+ export const getAddressIndexDiff = (addrIndex1 = 0, addrIndex2 = 0): number => {
342
+ if (addrIndex1 < 0) addrIndex1 = -1;
343
+ if (addrIndex2 < 0) addrIndex2 = -1;
344
+ return Math.abs(addrIndex1 - addrIndex2);
345
+ };
346
+
347
+ export const isPositive = (num: number): boolean => num > 0;