beignet 0.0.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 (329) hide show
  1. package/.eslintignore +4 -0
  2. package/.eslintrc +40 -0
  3. package/.prettierrc +9 -0
  4. package/LICENSE +21 -0
  5. package/README.md +166 -0
  6. package/dist/electrum/constants.js +31 -0
  7. package/dist/electrum/constants.js.map +1 -0
  8. package/dist/electrum/index.js +552 -0
  9. package/dist/electrum/index.js.map +1 -0
  10. package/dist/index.js +23 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/shapes/electrum.js +14 -0
  13. package/dist/shapes/electrum.js.map +1 -0
  14. package/dist/shapes/index.js +19 -0
  15. package/dist/shapes/index.js.map +1 -0
  16. package/dist/shapes/wallet.js +115 -0
  17. package/dist/shapes/wallet.js.map +1 -0
  18. package/dist/transaction/index.js +692 -0
  19. package/dist/transaction/index.js.map +1 -0
  20. package/dist/types/electrum/constants.d.ts +7 -0
  21. package/dist/types/electrum/index.d.ts +85 -0
  22. package/dist/types/electrum.js +9 -0
  23. package/dist/types/electrum.js.map +1 -0
  24. package/dist/types/index.d.ts +6 -0
  25. package/dist/types/index.js +20 -0
  26. package/dist/types/index.js.map +1 -0
  27. package/dist/types/shapes/electrum.d.ts +5 -0
  28. package/dist/types/shapes/index.d.ts +2 -0
  29. package/dist/types/shapes/wallet.d.ts +10 -0
  30. package/dist/types/transaction/index.d.ts +92 -0
  31. package/dist/types/transaction.js +12 -0
  32. package/dist/types/transaction.js.map +1 -0
  33. package/dist/types/types/electrum.d.ts +113 -0
  34. package/dist/types/types/index.d.ts +3 -0
  35. package/dist/types/types/transaction.d.ts +51 -0
  36. package/dist/types/types/wallet.d.ts +400 -0
  37. package/dist/types/utils/conversion.d.ts +10 -0
  38. package/dist/types/utils/derivation-path.d.ts +19 -0
  39. package/dist/types/utils/electrum.d.ts +10 -0
  40. package/dist/types/utils/exchange-rate.d.ts +30 -0
  41. package/dist/types/utils/helpers.d.ts +23 -0
  42. package/dist/types/utils/index.d.ts +7 -0
  43. package/dist/types/utils/result.d.ts +16 -0
  44. package/dist/types/utils/transaction.d.ts +21 -0
  45. package/dist/types/utils/wallet.d.ts +47 -0
  46. package/dist/types/wallet/constants.d.ts +12 -0
  47. package/dist/types/wallet/index.d.ts +214 -0
  48. package/dist/types/wallet.js +36 -0
  49. package/dist/types/wallet.js.map +1 -0
  50. package/dist/utils/conversion.js +52 -0
  51. package/dist/utils/conversion.js.map +1 -0
  52. package/dist/utils/derivation-path.js +104 -0
  53. package/dist/utils/derivation-path.js.map +1 -0
  54. package/dist/utils/electrum.js +149 -0
  55. package/dist/utils/electrum.js.map +1 -0
  56. package/dist/utils/exchange-rate.js +49 -0
  57. package/dist/utils/exchange-rate.js.map +1 -0
  58. package/dist/utils/helpers.js +137 -0
  59. package/dist/utils/helpers.js.map +1 -0
  60. package/dist/utils/index.js +24 -0
  61. package/dist/utils/index.js.map +1 -0
  62. package/dist/utils/result.js +36 -0
  63. package/dist/utils/result.js.map +1 -0
  64. package/dist/utils/transaction.js +327 -0
  65. package/dist/utils/transaction.js.map +1 -0
  66. package/dist/utils/wallet.js +227 -0
  67. package/dist/utils/wallet.js.map +1 -0
  68. package/dist/wallet/constants.js +15 -0
  69. package/dist/wallet/constants.js.map +1 -0
  70. package/dist/wallet/index.js +2113 -0
  71. package/dist/wallet/index.js.map +1 -0
  72. package/docs/html/.nojekyll +1 -0
  73. package/docs/html/assets/highlight.css +22 -0
  74. package/docs/html/assets/main.js +58 -0
  75. package/docs/html/assets/search.js +1 -0
  76. package/docs/html/assets/style.css +1367 -0
  77. package/docs/html/classes/Electrum.html +812 -0
  78. package/docs/html/classes/Transaction.html +687 -0
  79. package/docs/html/classes/Wallet.html +2030 -0
  80. package/docs/html/enums/EAddressType.html +227 -0
  81. package/docs/html/enums/EAvailableNetworks.html +255 -0
  82. package/docs/html/enums/EBoostType.html +220 -0
  83. package/docs/html/enums/EFeeId.html +241 -0
  84. package/docs/html/enums/EPaymentType.html +220 -0
  85. package/docs/html/enums/EProtocol.html +220 -0
  86. package/docs/html/enums/EUnit.html +227 -0
  87. package/docs/html/functions/availableNetworks.html +200 -0
  88. package/docs/html/functions/constructByteCountParam.html +210 -0
  89. package/docs/html/functions/decodeOpReturnMessage.html +202 -0
  90. package/docs/html/functions/decodeRawTransaction.html +210 -0
  91. package/docs/html/functions/err.html +214 -0
  92. package/docs/html/functions/formatKeyDerivationPath.html +219 -0
  93. package/docs/html/functions/formatPeerData.html +207 -0
  94. package/docs/html/functions/generateMnemonic.html +223 -0
  95. package/docs/html/functions/generateWalletId.html +202 -0
  96. package/docs/html/functions/getAddressFromScriptPubKey.html +209 -0
  97. package/docs/html/functions/getAddressTypeFromPath.html +206 -0
  98. package/docs/html/functions/getByteCount.html +206 -0
  99. package/docs/html/functions/getDataFallback.html +207 -0
  100. package/docs/html/functions/getDefaultPort.html +209 -0
  101. package/docs/html/functions/getDefaultWalletData.html +200 -0
  102. package/docs/html/functions/getDefaultWalletDataKeys.html +200 -0
  103. package/docs/html/functions/getExchangeRates.html +200 -0
  104. package/docs/html/functions/getHighestUsedIndexFromTxHashes.html +216 -0
  105. package/docs/html/functions/getKeyDerivationPath.html +211 -0
  106. package/docs/html/functions/getKeyDerivationPathObject.html +216 -0
  107. package/docs/html/functions/getKeyDerivationPathString.html +220 -0
  108. package/docs/html/functions/getKeyValue.html +206 -0
  109. package/docs/html/functions/getPeers.html +211 -0
  110. package/docs/html/functions/getProtocolForPort.html +209 -0
  111. package/docs/html/functions/getScriptHash.html +210 -0
  112. package/docs/html/functions/getSeed.html +209 -0
  113. package/docs/html/functions/getSeedHash.html +206 -0
  114. package/docs/html/functions/getSha256.html +206 -0
  115. package/docs/html/functions/getStorageKeyValues.html +209 -0
  116. package/docs/html/functions/getTxFee.html +210 -0
  117. package/docs/html/functions/getWalletDataStorageKey.html +206 -0
  118. package/docs/html/functions/isValidBech32mEncodedString.html +211 -0
  119. package/docs/html/functions/objectKeys-1.html +211 -0
  120. package/docs/html/functions/objectsMatch.html +210 -0
  121. package/docs/html/functions/ok.html +214 -0
  122. package/docs/html/functions/parseOnChainPaymentRequest.html +204 -0
  123. package/docs/html/functions/reduceValue.html +215 -0
  124. package/docs/html/functions/removeDustOutputs.html +206 -0
  125. package/docs/html/functions/setReplaceByFee.html +210 -0
  126. package/docs/html/functions/shuffleArray.html +211 -0
  127. package/docs/html/functions/validateAddress.html +216 -0
  128. package/docs/html/functions/validateMnemonic.html +206 -0
  129. package/docs/html/functions/validateTransaction.html +206 -0
  130. package/docs/html/index.html +360 -0
  131. package/docs/html/interfaces/IAddInput.html +231 -0
  132. package/docs/html/interfaces/IAddress.html +247 -0
  133. package/docs/html/interfaces/IAddressData.html +231 -0
  134. package/docs/html/interfaces/IAddressType.html +199 -0
  135. package/docs/html/interfaces/IAddressTypeData.html +252 -0
  136. package/docs/html/interfaces/IAddresses.html +199 -0
  137. package/docs/html/interfaces/IBoostedTransaction.html +238 -0
  138. package/docs/html/interfaces/IBoostedTransactions.html +199 -0
  139. package/docs/html/interfaces/ICreateTransaction.html +224 -0
  140. package/docs/html/interfaces/ICustomGetAddress.html +231 -0
  141. package/docs/html/interfaces/ICustomGetScriptHash.html +224 -0
  142. package/docs/html/interfaces/IElectrumGetAddressBalanceRes.html +235 -0
  143. package/docs/html/interfaces/IExchangeRates.html +210 -0
  144. package/docs/html/interfaces/IFormattedPeerData.html +245 -0
  145. package/docs/html/interfaces/IFormattedTransaction.html +343 -0
  146. package/docs/html/interfaces/IFormattedTransactions.html +199 -0
  147. package/docs/html/interfaces/IGenerateAddresses.html +252 -0
  148. package/docs/html/interfaces/IGenerateAddressesResponse.html +224 -0
  149. package/docs/html/interfaces/IGetAddress.html +231 -0
  150. package/docs/html/interfaces/IGetAddressBalanceRes.html +226 -0
  151. package/docs/html/interfaces/IGetAddressByPath.html +224 -0
  152. package/docs/html/interfaces/IGetAddressHistoryResponse.html +269 -0
  153. package/docs/html/interfaces/IGetAddressResponse.html +231 -0
  154. package/docs/html/interfaces/IGetAddressScriptHashesHistoryResponse.html +245 -0
  155. package/docs/html/interfaces/IGetDerivationPath.html +259 -0
  156. package/docs/html/interfaces/IGetFeeEstimatesResponse.html +238 -0
  157. package/docs/html/interfaces/IGetHeaderResponse.html +245 -0
  158. package/docs/html/interfaces/IGetNextAvailableAddressResponse.html +238 -0
  159. package/docs/html/interfaces/IGetTransactions.html +245 -0
  160. package/docs/html/interfaces/IGetTransactionsFromInputs.html +245 -0
  161. package/docs/html/interfaces/IGetUtxosResponse.html +224 -0
  162. package/docs/html/interfaces/IHeader.html +231 -0
  163. package/docs/html/interfaces/IIndexes.html +238 -0
  164. package/docs/html/interfaces/IKeyDerivationPath.html +247 -0
  165. package/docs/html/interfaces/IKeyDerivationPathData.html +224 -0
  166. package/docs/html/interfaces/INewBlock.html +224 -0
  167. package/docs/html/interfaces/IOnchainFees.html +245 -0
  168. package/docs/html/interfaces/IOutput.html +231 -0
  169. package/docs/html/interfaces/IPeerData.html +231 -0
  170. package/docs/html/interfaces/IRbfData.html +252 -0
  171. package/docs/html/interfaces/ISend.html +224 -0
  172. package/docs/html/interfaces/ISendTransaction.html +322 -0
  173. package/docs/html/interfaces/ISendTx.html +231 -0
  174. package/docs/html/interfaces/ISetupTransaction.html +238 -0
  175. package/docs/html/interfaces/ISubscribeToAddress.html +247 -0
  176. package/docs/html/interfaces/ISubscribeToHeader.html +245 -0
  177. package/docs/html/interfaces/ITargets.html +238 -0
  178. package/docs/html/interfaces/ITransaction.html +281 -0
  179. package/docs/html/interfaces/ITxHash.html +217 -0
  180. package/docs/html/interfaces/ITxHashes.html +235 -0
  181. package/docs/html/interfaces/IUtxo.html +275 -0
  182. package/docs/html/interfaces/IVin.html +252 -0
  183. package/docs/html/interfaces/IVout.html +246 -0
  184. package/docs/html/interfaces/IWallet.html +350 -0
  185. package/docs/html/interfaces/IWalletData.html +343 -0
  186. package/docs/html/types/ElectrumConnectionPubSub.html +233 -0
  187. package/docs/html/types/ElectrumConnectionSubscription.html +204 -0
  188. package/docs/html/types/InputData.html +203 -0
  189. package/docs/html/types/ObjectKeys.html +198 -0
  190. package/docs/html/types/Result.html +201 -0
  191. package/docs/html/types/TAddressIndexInfo.html +204 -0
  192. package/docs/html/types/TAddressLabel.html +193 -0
  193. package/docs/html/types/TAddressType.html +193 -0
  194. package/docs/html/types/TAddressTypeContent.html +198 -0
  195. package/docs/html/types/TAddressTypes.html +193 -0
  196. package/docs/html/types/TAvailableNetworks.html +193 -0
  197. package/docs/html/types/TConnectToElectrumRes.html +193 -0
  198. package/docs/html/types/TDecodeRawTx.html +214 -0
  199. package/docs/html/types/TElectrumNetworks.html +193 -0
  200. package/docs/html/types/TGetAddressHistory.html +200 -0
  201. package/docs/html/types/TGetByteCountInput.html +193 -0
  202. package/docs/html/types/TGetByteCountInputs.html +193 -0
  203. package/docs/html/types/TGetByteCountOutput.html +193 -0
  204. package/docs/html/types/TGetByteCountOutputs.html +193 -0
  205. package/docs/html/types/TGetData.html +211 -0
  206. package/docs/html/types/TGetTotalFeeObj.html +204 -0
  207. package/docs/html/types/TKeyDerivationAccount.html +193 -0
  208. package/docs/html/types/TKeyDerivationChange.html +193 -0
  209. package/docs/html/types/TKeyDerivationCoinType.html +193 -0
  210. package/docs/html/types/TKeyDerivationIndex.html +193 -0
  211. package/docs/html/types/TKeyDerivationPurpose.html +193 -0
  212. package/docs/html/types/TMessageDataMap.html +210 -0
  213. package/docs/html/types/TMessageKeys.html +193 -0
  214. package/docs/html/types/TOnMessage.html +213 -0
  215. package/docs/html/types/TProcessUnconfirmedTransactions.html +202 -0
  216. package/docs/html/types/TProtocol.html +193 -0
  217. package/docs/html/types/TServer.html +204 -0
  218. package/docs/html/types/TSetData.html +213 -0
  219. package/docs/html/types/TSetupTransactionResponse.html +193 -0
  220. package/docs/html/types/TStorage.html +200 -0
  221. package/docs/html/types/TSubscribedReceive.html +193 -0
  222. package/docs/html/types/TTransactionMessage.html +198 -0
  223. package/docs/html/types/TTxResponse.html +206 -0
  224. package/docs/html/types/TTxResult.html +200 -0
  225. package/docs/html/types/TUnspentAddressScriptHashData.html +198 -0
  226. package/docs/html/types/TWalletDataKeys.html +193 -0
  227. package/docs/html/variables/defaultElectrumPorts.html +193 -0
  228. package/docs/html/variables/electrumConnection.html +199 -0
  229. package/docs/html/variables/mostUsedExchangeTickers.html +241 -0
  230. package/docs/markdown/.nojekyll +1 -0
  231. package/docs/markdown/README.md +1875 -0
  232. package/docs/markdown/classes/Electrum.md +718 -0
  233. package/docs/markdown/classes/Transaction.md +536 -0
  234. package/docs/markdown/classes/Wallet.md +2189 -0
  235. package/docs/markdown/enums/EAddressType.md +41 -0
  236. package/docs/markdown/enums/EAvailableNetworks.md +85 -0
  237. package/docs/markdown/enums/EBoostType.md +30 -0
  238. package/docs/markdown/enums/EFeeId.md +63 -0
  239. package/docs/markdown/enums/EPaymentType.md +30 -0
  240. package/docs/markdown/enums/EProtocol.md +30 -0
  241. package/docs/markdown/enums/EUnit.md +41 -0
  242. package/docs/markdown/interfaces/IAddInput.md +41 -0
  243. package/docs/markdown/interfaces/IAddress.md +69 -0
  244. package/docs/markdown/interfaces/IAddressData.md +41 -0
  245. package/docs/markdown/interfaces/IAddressType.md +7 -0
  246. package/docs/markdown/interfaces/IAddressTypeData.md +74 -0
  247. package/docs/markdown/interfaces/IAddresses.md +7 -0
  248. package/docs/markdown/interfaces/IBoostedTransaction.md +52 -0
  249. package/docs/markdown/interfaces/IBoostedTransactions.md +7 -0
  250. package/docs/markdown/interfaces/ICreateTransaction.md +30 -0
  251. package/docs/markdown/interfaces/ICustomGetAddress.md +41 -0
  252. package/docs/markdown/interfaces/ICustomGetScriptHash.md +30 -0
  253. package/docs/markdown/interfaces/IElectrumGetAddressBalanceRes.md +55 -0
  254. package/docs/markdown/interfaces/IExchangeRates.md +7 -0
  255. package/docs/markdown/interfaces/IFormattedPeerData.md +63 -0
  256. package/docs/markdown/interfaces/IFormattedTransaction.md +217 -0
  257. package/docs/markdown/interfaces/IFormattedTransactions.md +7 -0
  258. package/docs/markdown/interfaces/IGenerateAddresses.md +74 -0
  259. package/docs/markdown/interfaces/IGenerateAddressesResponse.md +30 -0
  260. package/docs/markdown/interfaces/IGetAddress.md +41 -0
  261. package/docs/markdown/interfaces/IGetAddressBalanceRes.md +36 -0
  262. package/docs/markdown/interfaces/IGetAddressByPath.md +30 -0
  263. package/docs/markdown/interfaces/IGetAddressHistoryResponse.md +121 -0
  264. package/docs/markdown/interfaces/IGetAddressResponse.md +41 -0
  265. package/docs/markdown/interfaces/IGetAddressScriptHashesHistoryResponse.md +63 -0
  266. package/docs/markdown/interfaces/IGetDerivationPath.md +100 -0
  267. package/docs/markdown/interfaces/IGetFeeEstimatesResponse.md +52 -0
  268. package/docs/markdown/interfaces/IGetHeaderResponse.md +63 -0
  269. package/docs/markdown/interfaces/IGetNextAvailableAddressResponse.md +52 -0
  270. package/docs/markdown/interfaces/IGetTransactions.md +63 -0
  271. package/docs/markdown/interfaces/IGetTransactionsFromInputs.md +63 -0
  272. package/docs/markdown/interfaces/IGetUtxosResponse.md +30 -0
  273. package/docs/markdown/interfaces/IHeader.md +41 -0
  274. package/docs/markdown/interfaces/IIndexes.md +52 -0
  275. package/docs/markdown/interfaces/IKeyDerivationPath.md +69 -0
  276. package/docs/markdown/interfaces/IKeyDerivationPathData.md +30 -0
  277. package/docs/markdown/interfaces/INewBlock.md +30 -0
  278. package/docs/markdown/interfaces/IOnchainFees.md +63 -0
  279. package/docs/markdown/interfaces/IOutput.md +41 -0
  280. package/docs/markdown/interfaces/IPeerData.md +41 -0
  281. package/docs/markdown/interfaces/IRbfData.md +74 -0
  282. package/docs/markdown/interfaces/ISend.md +30 -0
  283. package/docs/markdown/interfaces/ISendTransaction.md +184 -0
  284. package/docs/markdown/interfaces/ISendTx.md +41 -0
  285. package/docs/markdown/interfaces/ISetupTransaction.md +52 -0
  286. package/docs/markdown/interfaces/ISubscribeToAddress.md +60 -0
  287. package/docs/markdown/interfaces/ISubscribeToHeader.md +59 -0
  288. package/docs/markdown/interfaces/ITargets.md +52 -0
  289. package/docs/markdown/interfaces/ITransaction.md +88 -0
  290. package/docs/markdown/interfaces/ITxHash.md +19 -0
  291. package/docs/markdown/interfaces/ITxHashes.md +55 -0
  292. package/docs/markdown/interfaces/IUtxo.md +112 -0
  293. package/docs/markdown/interfaces/IVin.md +70 -0
  294. package/docs/markdown/interfaces/IVout.md +52 -0
  295. package/docs/markdown/interfaces/IWallet.md +209 -0
  296. package/docs/markdown/interfaces/IWalletData.md +217 -0
  297. package/example/helpers.ts +76 -0
  298. package/example/index.ts +77 -0
  299. package/package.json +69 -0
  300. package/src/electrum/constants.ts +28 -0
  301. package/src/electrum/index.ts +838 -0
  302. package/src/index.ts +6 -0
  303. package/src/shapes/electrum.ts +13 -0
  304. package/src/shapes/index.ts +2 -0
  305. package/src/shapes/wallet.ts +133 -0
  306. package/src/transaction/index.ts +1078 -0
  307. package/src/types/electrum.ts +139 -0
  308. package/src/types/index.ts +3 -0
  309. package/src/types/transaction.ts +58 -0
  310. package/src/types/wallet.ts +503 -0
  311. package/src/utils/conversion.ts +88 -0
  312. package/src/utils/derivation-path.ts +171 -0
  313. package/src/utils/electrum.ts +188 -0
  314. package/src/utils/exchange-rate.ts +70 -0
  315. package/src/utils/helpers.ts +191 -0
  316. package/src/utils/index.ts +7 -0
  317. package/src/utils/result.ts +79 -0
  318. package/src/utils/transaction.ts +417 -0
  319. package/src/utils/wallet.ts +351 -0
  320. package/src/wallet/constants.ts +24 -0
  321. package/src/wallet/index.ts +3304 -0
  322. package/tests/constants.ts +9 -0
  323. package/tests/derivation.test.ts +146 -0
  324. package/tests/electrum.test.ts +137 -0
  325. package/tests/storage.test.ts +222 -0
  326. package/tests/transaction.test.ts +187 -0
  327. package/tests/wallet.test.ts +307 -0
  328. package/tsconfig.json +32 -0
  329. package/typedoc.json +5 -0
@@ -0,0 +1,139 @@
1
+ import {
2
+ EAvailableNetworks,
3
+ IAddress,
4
+ IGetAddressBalanceRes,
5
+ ITransaction,
6
+ IUtxo
7
+ } from './wallet';
8
+
9
+ export type TElectrumNetworks = 'bitcoin' | 'bitcoinTestnet' | 'bitcoinRegtest';
10
+
11
+ export type TConnectToElectrumRes = string;
12
+
13
+ export interface IElectrumGetAddressBalanceRes extends IGetAddressBalanceRes {
14
+ error: boolean;
15
+ }
16
+
17
+ export type TServer = {
18
+ host: string;
19
+ ssl: number;
20
+ tcp: number;
21
+ protocol: EProtocol;
22
+ };
23
+ export type TProtocol = 'tcp' | 'ssl';
24
+ export enum EProtocol {
25
+ tcp = 'tcp',
26
+ ssl = 'ssl'
27
+ }
28
+
29
+ export interface IGetUtxosResponse {
30
+ utxos: IUtxo[];
31
+ balance: number;
32
+ }
33
+
34
+ export type TUnspentAddressScriptHashData = {
35
+ [x: string]: IUtxo | IAddress;
36
+ };
37
+
38
+ export type TTxResult = {
39
+ tx_hash: string;
40
+ height: number;
41
+ };
42
+
43
+ export interface IGetAddressScriptHashesHistoryResponse {
44
+ data: TTxResponse[];
45
+ error: boolean;
46
+ id: number;
47
+ method: string;
48
+ network: string;
49
+ }
50
+
51
+ export type TTxResponse = {
52
+ data: IAddress;
53
+ id: number;
54
+ jsonrpc: string;
55
+ param: string;
56
+ result: TTxResult[];
57
+ };
58
+
59
+ export interface IGetAddressHistoryResponse extends TTxResult, IAddress {}
60
+
61
+ export interface IHeader {
62
+ height: number;
63
+ hash: string;
64
+ hex: string;
65
+ }
66
+
67
+ export interface INewBlock {
68
+ height: number;
69
+ hex: string;
70
+ }
71
+
72
+ export interface IGetHeaderResponse {
73
+ id: number;
74
+ error: boolean;
75
+ method: 'getHeader';
76
+ data: string;
77
+ network: EAvailableNetworks;
78
+ }
79
+
80
+ export interface IGetTransactionsFromInputs {
81
+ error: boolean;
82
+ id: number;
83
+ method: string;
84
+ network: string;
85
+ data: ITransaction<{
86
+ tx_hash: string;
87
+ vout: number;
88
+ }>[];
89
+ }
90
+
91
+ export interface ISubscribeToHeader {
92
+ data: {
93
+ height: number;
94
+ hex: string;
95
+ };
96
+ error: boolean;
97
+ id: string;
98
+ method: string;
99
+ }
100
+
101
+ export interface ISubscribeToAddress {
102
+ data: {
103
+ id: number;
104
+ jsonrpc: string;
105
+ result: null;
106
+ };
107
+ error: boolean;
108
+ id: number;
109
+ method: string;
110
+ }
111
+
112
+ export type TSubscribedReceive = [string, string];
113
+
114
+ export interface IFormattedPeerData {
115
+ ip?: string;
116
+ host: string;
117
+ version?: string;
118
+ ssl: string | number;
119
+ tcp: string | number;
120
+ }
121
+
122
+ export interface IPeerData {
123
+ host: string;
124
+ port: string;
125
+ protocol: TProtocol;
126
+ }
127
+
128
+ export type ElectrumConnectionPubSub = {
129
+ publish: (isConnected: boolean) => void;
130
+ subscribe: (
131
+ callback: (isConnected: boolean) => void
132
+ ) => ElectrumConnectionSubscription;
133
+ };
134
+
135
+ export type ElectrumConnectionSubscription = {
136
+ remove(): void;
137
+ };
138
+
139
+ export type TGetAddressHistory = { txid: string; height: number };
@@ -0,0 +1,3 @@
1
+ export * from './wallet';
2
+ export * from './electrum';
3
+ export * from './transaction';
@@ -0,0 +1,58 @@
1
+ import { ISendTransaction, IUtxo, IVin, IVout } from './wallet';
2
+ import { BIP32Interface } from 'bip32';
3
+ import { Psbt } from 'bitcoinjs-lib';
4
+ import { Result } from '../utils';
5
+
6
+ export interface ICreateTransaction {
7
+ transactionData?: ISendTransaction;
8
+ shuffleOutputs?: boolean;
9
+ }
10
+
11
+ export interface IAddInput {
12
+ psbt: Psbt;
13
+ keyPair: BIP32Interface;
14
+ input: IUtxo;
15
+ }
16
+
17
+ export interface ITargets {
18
+ value: number; // Amount denominated in sats.
19
+ index: number; // Used to specify which output to update or edit when using updateSendTransaction.
20
+ address?: string; // Amount denominated in sats.
21
+ script?: Buffer;
22
+ }
23
+
24
+ export interface ISetupTransaction {
25
+ inputTxHashes?: string[]; // Used to pre-specify inputs to use by tx_hash
26
+ utxos?: IUtxo[]; // Used to pre-specify utxos to use
27
+ rbf?: boolean; // Enable or disable rbf
28
+ satsPerByte?: number; // Used to specify the fee rate in sats per vbyte
29
+ }
30
+
31
+ export enum EFeeId {
32
+ fast = 'fast',
33
+ normal = 'normal',
34
+ slow = 'slow',
35
+ custom = 'custom',
36
+ none = 'none'
37
+ }
38
+
39
+ export type TSetupTransactionResponse = Result<Partial<ISendTransaction>>;
40
+
41
+ export type TDecodeRawTx = {
42
+ txid: string;
43
+ tx_hash: string;
44
+ size: number;
45
+ vsize: number;
46
+ weight: number;
47
+ version: number;
48
+ locktime: number;
49
+ vin: IVin[];
50
+ vout: IVout[];
51
+ };
52
+
53
+ export type TGetTotalFeeObj = {
54
+ totalFee: number;
55
+ transactionByteCount: number;
56
+ satsPerByte: number;
57
+ maxSatPerByte: number; // Max sats per byte that can be used for a given transaction without exceeding 50% of the balance.
58
+ };
@@ -0,0 +1,503 @@
1
+ import { Result } from '../utils';
2
+ import {
3
+ IHeader,
4
+ INewBlock,
5
+ TElectrumNetworks,
6
+ TServer,
7
+ TTxResult
8
+ } from './electrum';
9
+ import { EFeeId } from './transaction';
10
+ import { TLSSocket } from 'tls';
11
+ import { Server } from 'net';
12
+
13
+ export type TAvailableNetworks = 'bitcoin' | 'testnet' | 'regtest';
14
+ export type TAddressType = 'p2wpkh' | 'p2sh' | 'p2pkh';
15
+ export type TAddressLabel = 'bech32' | 'segwit' | 'legacy';
16
+ export type TKeyDerivationPurpose = '84' | '49' | '44' | string; //"p2wpkh" | "p2sh" | "p2pkh";
17
+ export type TKeyDerivationCoinType = '0' | '1' | string; //"mainnet" | "testnet";
18
+ export type TKeyDerivationAccount = '0' | string;
19
+ export type TKeyDerivationChange = '0' | '1'; //"Receiving Address" | "Change Address";
20
+ export type TKeyDerivationIndex = string;
21
+ export type TAddressTypes = {
22
+ [key in EAddressType]: Readonly<IAddressTypeData>;
23
+ };
24
+ export enum EAvailableNetworks {
25
+ bitcoin = 'bitcoin',
26
+ mainnet = 'bitcoin',
27
+ bitcoinMainnet = 'bitcoin',
28
+ testnet = 'testnet',
29
+ bitcoinTestnet = 'testnet',
30
+ regtest = 'regtest',
31
+ bitcoinRegtest = 'regtest'
32
+ }
33
+ export enum EAddressType {
34
+ p2wpkh = 'p2wpkh',
35
+ p2sh = 'p2sh',
36
+ p2pkh = 'p2pkh'
37
+ // p2wsh = 'p2wsh',
38
+ // p2tr = 'p2tr',
39
+ }
40
+
41
+ export enum EPaymentType {
42
+ sent = 'sent',
43
+ received = 'received'
44
+ }
45
+
46
+ export type TAddressTypeContent<T> = {
47
+ [key in EAddressType]: T;
48
+ };
49
+
50
+ export interface IAddressTypeData {
51
+ type: EAddressType;
52
+ path: string;
53
+ name: string;
54
+ shortName: string;
55
+ description: string;
56
+ example: string;
57
+ }
58
+
59
+ export interface IUtxo {
60
+ address: string;
61
+ index: number;
62
+ path: string;
63
+ scriptHash: string;
64
+ height: number;
65
+ tx_hash: string;
66
+ tx_pos: number;
67
+ value: number;
68
+ }
69
+
70
+ export interface IVin {
71
+ scriptSig: {
72
+ asm: string;
73
+ hex: string;
74
+ };
75
+ sequence: number;
76
+ txid: string;
77
+ txinwitness: string[];
78
+ vout: number;
79
+ }
80
+
81
+ export interface IFormattedTransaction {
82
+ address: string;
83
+ height: number;
84
+ scriptHash: string;
85
+ totalInputValue: number;
86
+ matchedInputValue: number;
87
+ totalOutputValue: number;
88
+ matchedOutputValue: number;
89
+ fee: number;
90
+ satsPerByte: number;
91
+ type: EPaymentType;
92
+ value: number;
93
+ txid: string;
94
+ messages: string[];
95
+ vin: IVin[];
96
+ timestamp: number;
97
+ confirmTimestamp?: number;
98
+ exists?: boolean;
99
+ rbf?: boolean;
100
+ vsize: number;
101
+ }
102
+
103
+ export interface IFormattedTransactions {
104
+ [key: string]: IFormattedTransaction;
105
+ }
106
+
107
+ export interface IOutput {
108
+ address: string; // Address to send to.
109
+ value: number; // Amount denominated in sats.
110
+ index: number; // Used to specify which output to update or edit when using updateSendTransaction.
111
+ }
112
+
113
+ export enum EBoostType {
114
+ rbf = 'rbf',
115
+ cpfp = 'cpfp'
116
+ }
117
+
118
+ export interface ISendTransaction {
119
+ outputs: IOutput[];
120
+ inputs: IUtxo[];
121
+ changeAddress: string;
122
+ fiatAmount: number;
123
+ fee: number; //Total fee in sats
124
+ satsPerByte: number;
125
+ selectedFeeId: EFeeId;
126
+ message: string; // OP_RETURN data for a given transaction.
127
+ label: string; // User set label for a given transaction.
128
+ rbf: boolean;
129
+ boostType: EBoostType;
130
+ minFee: number; // (sats) Used for RBF/CPFP transactions where the fee needs to be greater than the original.
131
+ max: boolean; // If the user intends to send the max amount.
132
+ tags: string[];
133
+ slashTagsUrl?: string;
134
+ lightningInvoice?: string;
135
+ }
136
+
137
+ export interface IAddresses {
138
+ [scriptHash: string]: IAddress;
139
+ }
140
+
141
+ export interface IAddress {
142
+ index: number;
143
+ path: string;
144
+ address: string;
145
+ scriptHash: string;
146
+ publicKey: string;
147
+ }
148
+
149
+ export interface IWalletData {
150
+ id: string;
151
+ addressType: EAddressType;
152
+ header: IHeader;
153
+ addresses: TAddressTypeContent<IAddresses>;
154
+ changeAddresses: TAddressTypeContent<IAddresses>;
155
+ addressIndex: TAddressTypeContent<IAddress>;
156
+ changeAddressIndex: TAddressTypeContent<IAddress>;
157
+ lastUsedAddressIndex: TAddressTypeContent<IAddress>;
158
+ lastUsedChangeAddressIndex: TAddressTypeContent<IAddress>;
159
+ utxos: IUtxo[];
160
+ blacklistedUtxos: IUtxo[];
161
+ unconfirmedTransactions: IFormattedTransactions;
162
+ transactions: IFormattedTransactions;
163
+ boostedTransactions: IBoostedTransactions;
164
+ transaction: ISendTransaction;
165
+ balance: number;
166
+ selectedFeeId: EFeeId;
167
+ exchangeRates: IExchangeRates;
168
+ feeEstimates: IOnchainFees;
169
+ }
170
+
171
+ export type TWalletDataKeys = keyof IWalletData;
172
+
173
+ export type TGetData = <K extends keyof IWalletData>(
174
+ key: string
175
+ ) => Promise<Result<IWalletData[K]>>;
176
+ export type TSetData = <K extends keyof IWalletData>(
177
+ key: string,
178
+ value: IWalletData[K]
179
+ ) => Promise<Result<boolean>>;
180
+
181
+ export interface IWallet {
182
+ mnemonic: string;
183
+ id?: string;
184
+ name?: string;
185
+ passphrase?: string;
186
+ network?: EAvailableNetworks;
187
+ addressType?: EAddressType;
188
+ data?: IWalletData;
189
+ storage?: TStorage;
190
+ electrumOptions?: {
191
+ servers?: TServer | TServer[];
192
+ tls?: TLSSocket;
193
+ net?: Server;
194
+ };
195
+ remainOffline?: boolean;
196
+ onMessage?: TOnMessage;
197
+ customGetAddress?: (
198
+ data: ICustomGetAddress
199
+ ) => Promise<Result<IGetAddressResponse>>;
200
+ customGetScriptHash?: (data: ICustomGetScriptHash) => Promise<string>;
201
+ rbf?: boolean;
202
+ selectedFeeId?: EFeeId;
203
+ }
204
+
205
+ export interface IAddressData {
206
+ path: string;
207
+ type: 'p2wpkh' | 'p2sh' | 'p2pkh';
208
+ label: string;
209
+ }
210
+
211
+ export interface IAddressType {
212
+ [key: string]: IAddressData;
213
+ }
214
+
215
+ // m / purpose' / coin_type' / account' / change / index
216
+ export interface IKeyDerivationPath {
217
+ purpose?: TKeyDerivationPurpose;
218
+ coinType?: TKeyDerivationCoinType;
219
+ account?: TKeyDerivationAccount;
220
+ change?: TKeyDerivationChange;
221
+ index?: TKeyDerivationIndex;
222
+ }
223
+
224
+ export interface IGetDerivationPath extends IKeyDerivationPath {
225
+ addressType?: EAddressType;
226
+ }
227
+
228
+ export interface IGetAddress {
229
+ index?: TKeyDerivationIndex;
230
+ changeAddress?: boolean;
231
+ addressType?: EAddressType;
232
+ }
233
+
234
+ export interface ICustomGetAddress {
235
+ path: string;
236
+ type: EAddressType;
237
+ selectedNetwork?: TElectrumNetworks;
238
+ }
239
+
240
+ export interface ICustomGetScriptHash {
241
+ address: string;
242
+ selectedNetwork?: TElectrumNetworks;
243
+ }
244
+
245
+ export interface IGetAddressByPath {
246
+ path: string;
247
+ addressType?: EAddressType;
248
+ }
249
+
250
+ export interface IGetAddressBalanceRes {
251
+ confirmed: number;
252
+ unconfirmed: number;
253
+ }
254
+
255
+ export interface IUtxo {
256
+ address: string;
257
+ index: number;
258
+ path: string;
259
+ scriptHash: string;
260
+ height: number;
261
+ tx_hash: string;
262
+ tx_pos: number;
263
+ value: number;
264
+ }
265
+
266
+ export interface IGenerateAddresses {
267
+ addressAmount?: number;
268
+ changeAddressAmount?: number;
269
+ addressIndex?: number;
270
+ changeAddressIndex?: number;
271
+ keyDerivationPath?: IKeyDerivationPath;
272
+ addressType?: EAddressType;
273
+ }
274
+
275
+ export interface IKeyDerivationPathData {
276
+ pathString: string;
277
+ pathObject: IKeyDerivationPath;
278
+ }
279
+
280
+ export interface IGenerateAddressesResponse {
281
+ addresses: IAddresses;
282
+ changeAddresses: IAddresses;
283
+ }
284
+
285
+ export interface IGetAddressResponse {
286
+ address: string;
287
+ path: string;
288
+ publicKey: string;
289
+ }
290
+
291
+ export interface IGetNextAvailableAddressResponse {
292
+ addressIndex: IAddress;
293
+ lastUsedAddressIndex: IAddress;
294
+ changeAddressIndex: IAddress;
295
+ lastUsedChangeAddressIndex: IAddress;
296
+ }
297
+
298
+ export interface ITxHashes extends TTxResult {
299
+ scriptHash: string;
300
+ }
301
+
302
+ export interface IIndexes {
303
+ addressIndex: IAddress;
304
+ changeAddressIndex: IAddress;
305
+ foundAddressIndex: boolean;
306
+ foundChangeAddressIndex: boolean;
307
+ }
308
+
309
+ export interface ITxHash {
310
+ tx_hash: string;
311
+ }
312
+
313
+ export interface IGetTransactions {
314
+ error: boolean;
315
+ id: number;
316
+ method: string;
317
+ network: string;
318
+ data: ITransaction<IUtxo>[];
319
+ }
320
+
321
+ export interface ITransaction<T> {
322
+ id: number;
323
+ jsonrpc: string;
324
+ param: string;
325
+ data: T;
326
+ result: {
327
+ blockhash: string;
328
+ confirmations: number;
329
+ hash: string;
330
+ hex: string;
331
+ locktime: number;
332
+ size: number;
333
+ txid: string;
334
+ version: number;
335
+ vin: IVin[];
336
+ vout: IVout[];
337
+ vsize: number;
338
+ weight: number;
339
+ blocktime?: number;
340
+ time?: number;
341
+ };
342
+ }
343
+
344
+ export interface IVout {
345
+ n: number; //0
346
+ scriptPubKey: {
347
+ addresses?: string[];
348
+ address?: string;
349
+ asm: string;
350
+ hex: string;
351
+ reqSigs?: number;
352
+ type?: string;
353
+ };
354
+ value: number;
355
+ }
356
+
357
+ export type TProcessUnconfirmedTransactions = {
358
+ unconfirmedTxs: IFormattedTransactions; // zero-conf transactions
359
+ outdatedTxs: IUtxo[]; // Transactions that are no longer confirmed.
360
+ ghostTxs: string[]; // Transactions that have been removed from the mempool.
361
+ };
362
+
363
+ export enum EUnit {
364
+ satoshi = 'satoshi',
365
+ BTC = 'BTC',
366
+ fiat = 'fiat'
367
+ }
368
+
369
+ export interface IExchangeRates {
370
+ [key: string]: {
371
+ currencySymbol: string;
372
+ quote: string;
373
+ quoteName: string;
374
+ rate: number;
375
+ lastUpdatedAt: number;
376
+ };
377
+ }
378
+
379
+ export type InputData = {
380
+ [key: string]: {
381
+ addresses: string[];
382
+ value: number;
383
+ };
384
+ };
385
+
386
+ export type TGetByteCountInputs = {
387
+ [key in TGetByteCountInput]?: number;
388
+ };
389
+
390
+ export type TGetByteCountOutputs = {
391
+ [key in TGetByteCountOutput]?: number;
392
+ };
393
+
394
+ export type TGetByteCountInput =
395
+ | `MULTISIG-P2SH:${number}-${number}`
396
+ | `MULTISIG-P2WSH:${number}-${number}`
397
+ | `MULTISIG-P2SH-P2WSH:${number}-${number}`
398
+ | 'P2SH-P2WPKH'
399
+ | 'P2PKH'
400
+ | 'p2pkh'
401
+ | 'P2WPKH'
402
+ | 'p2wpkh'
403
+ | 'P2SH'
404
+ | 'p2sh'
405
+ | 'P2TR'
406
+ | 'p2tr';
407
+
408
+ export type TGetByteCountOutput =
409
+ | 'P2SH'
410
+ | 'P2PKH'
411
+ | 'P2WPKH'
412
+ | 'P2WSH'
413
+ | 'p2wpkh'
414
+ | 'p2sh'
415
+ | 'p2pkh'
416
+ | 'P2TR'
417
+ | 'p2tr';
418
+
419
+ export interface IGetFeeEstimatesResponse {
420
+ fastestFee: number;
421
+ halfHourFee: number;
422
+ hourFee: number;
423
+ minimumFee: number;
424
+ }
425
+
426
+ //On-chain fee estimates in sats/vbyte
427
+ export interface IOnchainFees {
428
+ fast: number; // 10-20 mins
429
+ normal: number; // 20-60 mins
430
+ slow: number; // 1-2 hrs
431
+ minimum: number;
432
+ timestamp: number;
433
+ }
434
+
435
+ export type TMessageDataMap = {
436
+ newBlock: INewBlock;
437
+ transactionReceived: TTransactionMessage;
438
+ transactionConfirmed: TTransactionMessage;
439
+ transactionSent: TTransactionMessage;
440
+ reorg: IUtxo[];
441
+ rbf: string[];
442
+ connectedToElectrum: boolean; // True if connected, false if disconnected.
443
+ };
444
+
445
+ export type TTransactionMessage = {
446
+ transaction: IFormattedTransaction;
447
+ };
448
+
449
+ // MIT License
450
+ // Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
451
+ // https://github.com/sindresorhus/ts-extras
452
+ export type ObjectKeys<T extends object> = `${Exclude<keyof T, symbol>}`;
453
+
454
+ // Define the type of the onMessage function
455
+ export type TOnMessage = <K extends keyof TMessageDataMap>(
456
+ key: K,
457
+ data: TMessageDataMap[K]
458
+ ) => void;
459
+
460
+ export type TMessageKeys = keyof TMessageDataMap;
461
+
462
+ export interface ISendTx {
463
+ address: string;
464
+ amount: number;
465
+ message?: string;
466
+ }
467
+
468
+ export interface ISend {
469
+ txs: ISendTx | ISendTx[];
470
+ satsPerByte?: number;
471
+ }
472
+
473
+ export type TAddressIndexInfo = {
474
+ addressIndex: IAddress;
475
+ changeAddressIndex: IAddress;
476
+ lastUsedAddressIndex: IAddress;
477
+ lastUsedChangeAddressIndex: IAddress;
478
+ };
479
+
480
+ export type TStorage = {
481
+ getData?: TGetData;
482
+ setData?: TSetData;
483
+ };
484
+
485
+ export interface IRbfData {
486
+ outputs: IOutput[];
487
+ balance: number;
488
+ addressType: EAddressType;
489
+ fee: number; // Total fee in sats.
490
+ inputs: IUtxo[];
491
+ message: string;
492
+ }
493
+
494
+ export interface IBoostedTransaction {
495
+ parentTransactions: string[]; // Array of parent txids to the currently boosted transaction.
496
+ childTransaction: string; // Child txid of the currently boosted transaction.
497
+ type: EBoostType;
498
+ fee: number;
499
+ }
500
+
501
+ export interface IBoostedTransactions {
502
+ [txId: string]: IBoostedTransaction;
503
+ }