@bigmi/core 0.8.0 → 0.9.0

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 (499) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +2 -2
  3. package/dist/cjs/actions/getBalance.d.ts +2 -2
  4. package/dist/cjs/actions/getBalance.js.map +1 -1
  5. package/dist/cjs/actions/getBlock.d.ts +1 -5
  6. package/dist/cjs/actions/getBlock.js +0 -1
  7. package/dist/cjs/actions/getBlock.js.map +1 -1
  8. package/dist/cjs/actions/getBlockCount.d.ts +0 -1
  9. package/dist/cjs/actions/getBlockCount.js.map +1 -1
  10. package/dist/cjs/actions/getBlockStats.d.ts +1 -6
  11. package/dist/cjs/actions/getBlockStats.js.map +1 -1
  12. package/dist/cjs/actions/getTransactionFee.d.ts +1 -4
  13. package/dist/cjs/actions/getTransactionFee.js.map +1 -1
  14. package/dist/cjs/actions/getTransactions.d.ts +1 -7
  15. package/dist/cjs/actions/getTransactions.js.map +1 -1
  16. package/dist/cjs/actions/getUTXOTransaction.d.ts +4 -6
  17. package/dist/cjs/actions/getUTXOTransaction.js.map +1 -1
  18. package/dist/cjs/actions/getUTXOs.d.ts +1 -5
  19. package/dist/cjs/actions/getUTXOs.js.map +1 -1
  20. package/dist/cjs/actions/getXPubAddresses.d.ts +22 -22
  21. package/dist/cjs/actions/getXPubAddresses.js.map +1 -1
  22. package/dist/cjs/actions/sendUTXOTransaction.d.ts +4 -6
  23. package/dist/cjs/actions/sendUTXOTransaction.js.map +1 -1
  24. package/dist/cjs/actions/signPsbt.d.ts +0 -1
  25. package/dist/cjs/actions/signPsbt.js.map +1 -1
  26. package/dist/cjs/actions/waitForTransaction.d.ts +43 -49
  27. package/dist/cjs/actions/waitForTransaction.js +0 -1
  28. package/dist/cjs/actions/waitForTransaction.js.map +1 -1
  29. package/dist/cjs/actions/watchBlockNumber.d.ts +14 -16
  30. package/dist/cjs/actions/watchBlockNumber.js.map +1 -1
  31. package/dist/cjs/chains/bitcoin.d.ts +0 -1
  32. package/dist/cjs/chains/bitcoin.js +3 -3
  33. package/dist/cjs/chains/bitcoin.js.map +1 -1
  34. package/dist/cjs/chains/defineChain.d.ts +0 -1
  35. package/dist/cjs/chains/defineChain.js.map +1 -1
  36. package/dist/cjs/chains/signet.d.ts +0 -1
  37. package/dist/cjs/chains/signet.js +3 -3
  38. package/dist/cjs/chains/signet.js.map +1 -1
  39. package/dist/cjs/clients/decorators/public.d.ts +0 -1
  40. package/dist/cjs/clients/decorators/public.js.map +1 -1
  41. package/dist/cjs/clients/decorators/wallet.d.ts +2 -3
  42. package/dist/cjs/clients/decorators/wallet.js.map +1 -1
  43. package/dist/cjs/errors/address.d.ts +1 -4
  44. package/dist/cjs/errors/address.js.map +1 -1
  45. package/dist/cjs/errors/base.js.map +1 -1
  46. package/dist/cjs/errors/block.d.ts +1 -5
  47. package/dist/cjs/errors/block.js.map +1 -1
  48. package/dist/cjs/errors/provider.d.ts +0 -1
  49. package/dist/cjs/errors/provider.js.map +1 -1
  50. package/dist/cjs/errors/request.d.ts +5 -28
  51. package/dist/cjs/errors/request.js.map +1 -1
  52. package/dist/cjs/errors/rpc.d.ts +23 -24
  53. package/dist/cjs/errors/rpc.js +3 -3
  54. package/dist/cjs/errors/rpc.js.map +1 -1
  55. package/dist/cjs/errors/transaction.d.ts +3 -14
  56. package/dist/cjs/errors/transaction.js.map +1 -1
  57. package/dist/cjs/errors/transport.d.ts +2 -10
  58. package/dist/cjs/errors/transport.js.map +1 -1
  59. package/dist/cjs/errors/utils.d.ts +0 -1
  60. package/dist/cjs/errors/utxo.d.ts +1 -6
  61. package/dist/cjs/errors/utxo.js.map +1 -1
  62. package/dist/cjs/factories/createClient.d.ts +49 -30
  63. package/dist/cjs/factories/createClient.js.map +1 -1
  64. package/dist/cjs/factories/createTransport.d.ts +3 -13
  65. package/dist/cjs/factories/createTransport.js.map +1 -1
  66. package/dist/cjs/test/utils.js.map +1 -1
  67. package/dist/cjs/transports/ankr/ankr.d.ts +0 -1
  68. package/dist/cjs/transports/ankr/ankr.js.map +1 -1
  69. package/dist/cjs/transports/ankr/getBalance.d.ts +0 -1
  70. package/dist/cjs/transports/ankr/getBalance.js +2 -2
  71. package/dist/cjs/transports/ankr/getBalance.js.map +1 -1
  72. package/dist/cjs/transports/ankr/getTransactionFee.d.ts +0 -1
  73. package/dist/cjs/transports/ankr/getTransactionFee.js.map +1 -1
  74. package/dist/cjs/transports/ankr/getTransactions.d.ts +0 -1
  75. package/dist/cjs/transports/ankr/getTransactions.js.map +1 -1
  76. package/dist/cjs/transports/ankr/methods.d.ts +0 -1
  77. package/dist/cjs/transports/ankr/methods.js.map +1 -1
  78. package/dist/cjs/transports/ankr/utils.d.ts +0 -1
  79. package/dist/cjs/transports/ankr/utils.js.map +1 -1
  80. package/dist/cjs/transports/blockchair/blockchair.d.ts +0 -1
  81. package/dist/cjs/transports/blockchair/blockchair.js.map +1 -1
  82. package/dist/cjs/transports/blockchair/getBalance.d.ts +0 -1
  83. package/dist/cjs/transports/blockchair/getBalance.js +2 -2
  84. package/dist/cjs/transports/blockchair/getBalance.js.map +1 -1
  85. package/dist/cjs/transports/blockchair/getTransactionFee.d.ts +0 -1
  86. package/dist/cjs/transports/blockchair/getTransactionFee.js +2 -2
  87. package/dist/cjs/transports/blockchair/getTransactionFee.js.map +1 -1
  88. package/dist/cjs/transports/blockchair/getUTXOs.d.ts +0 -1
  89. package/dist/cjs/transports/blockchair/getUTXOs.js +2 -2
  90. package/dist/cjs/transports/blockchair/getUTXOs.js.map +1 -1
  91. package/dist/cjs/transports/blockchair/getXPubAddresses.d.ts +0 -1
  92. package/dist/cjs/transports/blockchair/getXPubAddresses.js +2 -2
  93. package/dist/cjs/transports/blockchair/getXPubAddresses.js.map +1 -1
  94. package/dist/cjs/transports/blockchair/methods.d.ts +0 -1
  95. package/dist/cjs/transports/blockchair/methods.js.map +1 -1
  96. package/dist/cjs/transports/blockcypher/blockcypher.d.ts +0 -1
  97. package/dist/cjs/transports/blockcypher/blockcypher.js.map +1 -1
  98. package/dist/cjs/transports/blockcypher/getBalance.d.ts +0 -1
  99. package/dist/cjs/transports/blockcypher/getBalance.js.map +1 -1
  100. package/dist/cjs/transports/blockcypher/getTransactionFee.d.ts +0 -1
  101. package/dist/cjs/transports/blockcypher/getTransactionFee.js.map +1 -1
  102. package/dist/cjs/transports/blockcypher/getUTXOs.d.ts +0 -1
  103. package/dist/cjs/transports/blockcypher/getUTXOs.js.map +1 -1
  104. package/dist/cjs/transports/blockcypher/methods.d.ts +0 -1
  105. package/dist/cjs/transports/blockcypher/methods.js.map +1 -1
  106. package/dist/cjs/transports/blockcypher/utils.d.ts +0 -1
  107. package/dist/cjs/transports/blockcypher/utils.js +3 -3
  108. package/dist/cjs/transports/blockcypher/utils.js.map +1 -1
  109. package/dist/cjs/transports/custom.d.ts +11 -7
  110. package/dist/cjs/transports/custom.js.map +1 -1
  111. package/dist/cjs/transports/fallback.d.ts +32 -36
  112. package/dist/cjs/transports/fallback.js +2 -2
  113. package/dist/cjs/transports/fallback.js.map +1 -1
  114. package/dist/cjs/transports/getHttpRpcClient.d.ts +17 -9
  115. package/dist/cjs/transports/getHttpRpcClient.js.map +1 -1
  116. package/dist/cjs/transports/getRpcProviderMethods.d.ts +0 -1
  117. package/dist/cjs/transports/getRpcProviderMethods.js.map +1 -1
  118. package/dist/cjs/transports/http.d.ts +31 -20
  119. package/dist/cjs/transports/http.js.map +1 -1
  120. package/dist/cjs/transports/mempool/getBalance.d.ts +0 -1
  121. package/dist/cjs/transports/mempool/getBalance.js.map +1 -1
  122. package/dist/cjs/transports/mempool/getTransactionFee.d.ts +0 -1
  123. package/dist/cjs/transports/mempool/getTransactionFee.js.map +1 -1
  124. package/dist/cjs/transports/mempool/getTransactions.d.ts +0 -1
  125. package/dist/cjs/transports/mempool/getTransactions.js.map +1 -1
  126. package/dist/cjs/transports/mempool/mempool.d.ts +0 -1
  127. package/dist/cjs/transports/mempool/mempool.js.map +1 -1
  128. package/dist/cjs/transports/mempool/methods.d.ts +0 -1
  129. package/dist/cjs/transports/mempool/methods.js.map +1 -1
  130. package/dist/cjs/transports/mempool/utils.d.ts +0 -1
  131. package/dist/cjs/transports/mempool/utils.js.map +1 -1
  132. package/dist/cjs/transports/types.d.ts +17 -15
  133. package/dist/cjs/transports/types.js.map +1 -1
  134. package/dist/cjs/transports/utxo.d.ts +0 -1
  135. package/dist/cjs/transports/utxo.js.map +1 -1
  136. package/dist/cjs/types/account.d.ts +0 -1
  137. package/dist/cjs/types/address.d.ts +0 -1
  138. package/dist/cjs/types/address.js.map +1 -1
  139. package/dist/cjs/types/block.d.ts +17 -17
  140. package/dist/cjs/types/chain.d.ts +20 -9
  141. package/dist/cjs/types/chain.js.map +1 -1
  142. package/dist/cjs/types/client.d.ts +40 -25
  143. package/dist/cjs/types/request.d.ts +12 -8
  144. package/dist/cjs/types/transport.d.ts +16 -11
  145. package/dist/cjs/types/utils.d.ts +31 -31
  146. package/dist/cjs/types/xpub.d.ts +0 -1
  147. package/dist/cjs/utils/buildRequest.d.ts +0 -1
  148. package/dist/cjs/utils/buildRequest.js +3 -3
  149. package/dist/cjs/utils/buildRequest.js.map +1 -1
  150. package/dist/cjs/utils/cancelTransaction.d.ts +0 -1
  151. package/dist/cjs/utils/cancelTransaction.js +0 -1
  152. package/dist/cjs/utils/cancelTransaction.js.map +1 -1
  153. package/dist/cjs/utils/converter.js.map +1 -1
  154. package/dist/cjs/utils/createBatchScheduler.d.ts +1 -8
  155. package/dist/cjs/utils/createBatchScheduler.js +1 -1
  156. package/dist/cjs/utils/createBatchScheduler.js.map +1 -1
  157. package/dist/cjs/utils/deepEqual.js.map +1 -1
  158. package/dist/cjs/utils/getAction.d.ts +6 -7
  159. package/dist/cjs/utils/getAction.js.map +1 -1
  160. package/dist/cjs/utils/getAddressInfo.d.ts +0 -1
  161. package/dist/cjs/utils/getAddressInfo.js +26 -26
  162. package/dist/cjs/utils/getAddressInfo.js.map +1 -1
  163. package/dist/cjs/utils/idCache.js.map +1 -1
  164. package/dist/cjs/utils/isAddress.d.ts +0 -1
  165. package/dist/cjs/utils/isAddress.js.map +1 -1
  166. package/dist/cjs/utils/lru.d.ts +4 -4
  167. package/dist/cjs/utils/lru.js.map +1 -1
  168. package/dist/cjs/utils/modifyFee.d.ts +0 -1
  169. package/dist/cjs/utils/modifyFee.js +0 -1
  170. package/dist/cjs/utils/modifyFee.js.map +1 -1
  171. package/dist/cjs/utils/observe.d.ts +4 -5
  172. package/dist/cjs/utils/observe.js +2 -2
  173. package/dist/cjs/utils/observe.js.map +1 -1
  174. package/dist/cjs/utils/parseAccount.d.ts +0 -1
  175. package/dist/cjs/utils/parseAccount.js.map +1 -1
  176. package/dist/cjs/utils/poll.d.ts +4 -10
  177. package/dist/cjs/utils/poll.js.map +1 -1
  178. package/dist/cjs/utils/retryUntil.d.ts +17 -15
  179. package/dist/cjs/utils/retryUntil.js.map +1 -1
  180. package/dist/cjs/utils/sleep.js.map +1 -1
  181. package/dist/cjs/utils/stringify.d.ts +0 -1
  182. package/dist/cjs/utils/stringify.js.map +1 -1
  183. package/dist/cjs/utils/uid.js.map +1 -1
  184. package/dist/cjs/utils/url.js.map +1 -1
  185. package/dist/cjs/utils/wait.js.map +1 -1
  186. package/dist/cjs/utils/withDedupe.d.ts +1 -5
  187. package/dist/cjs/utils/withDedupe.js +1 -1
  188. package/dist/cjs/utils/withDedupe.js.map +1 -1
  189. package/dist/cjs/utils/withResolvers.js.map +1 -1
  190. package/dist/cjs/utils/withRetry.d.ts +2 -10
  191. package/dist/cjs/utils/withRetry.js.map +1 -1
  192. package/dist/cjs/utils/withTimeout.d.ts +2 -9
  193. package/dist/cjs/utils/withTimeout.js.map +1 -1
  194. package/dist/cjs/version.d.ts +1 -1
  195. package/dist/cjs/version.js +1 -1
  196. package/dist/cjs/version.js.map +1 -1
  197. package/dist/esm/actions/getBalance.d.ts +2 -2
  198. package/dist/esm/actions/getBalance.d.ts.map +1 -1
  199. package/dist/esm/actions/getBalance.js.map +1 -1
  200. package/dist/esm/actions/getBlock.d.ts +1 -5
  201. package/dist/esm/actions/getBlock.d.ts.map +1 -1
  202. package/dist/esm/actions/getBlock.js.map +1 -1
  203. package/dist/esm/actions/getBlockCount.d.ts +0 -1
  204. package/dist/esm/actions/getBlockCount.d.ts.map +1 -1
  205. package/dist/esm/actions/getBlockCount.js.map +1 -1
  206. package/dist/esm/actions/getBlockStats.d.ts +1 -6
  207. package/dist/esm/actions/getBlockStats.d.ts.map +1 -1
  208. package/dist/esm/actions/getBlockStats.js.map +1 -1
  209. package/dist/esm/actions/getTransactionFee.d.ts +1 -4
  210. package/dist/esm/actions/getTransactionFee.d.ts.map +1 -1
  211. package/dist/esm/actions/getTransactionFee.js.map +1 -1
  212. package/dist/esm/actions/getTransactions.d.ts +1 -7
  213. package/dist/esm/actions/getTransactions.d.ts.map +1 -1
  214. package/dist/esm/actions/getTransactions.js.map +1 -1
  215. package/dist/esm/actions/getUTXOTransaction.d.ts +4 -6
  216. package/dist/esm/actions/getUTXOTransaction.d.ts.map +1 -1
  217. package/dist/esm/actions/getUTXOTransaction.js.map +1 -1
  218. package/dist/esm/actions/getUTXOs.d.ts +1 -5
  219. package/dist/esm/actions/getUTXOs.d.ts.map +1 -1
  220. package/dist/esm/actions/getUTXOs.js.map +1 -1
  221. package/dist/esm/actions/getXPubAddresses.d.ts +22 -22
  222. package/dist/esm/actions/getXPubAddresses.d.ts.map +1 -1
  223. package/dist/esm/actions/getXPubAddresses.js.map +1 -1
  224. package/dist/esm/actions/sendUTXOTransaction.d.ts +4 -6
  225. package/dist/esm/actions/sendUTXOTransaction.d.ts.map +1 -1
  226. package/dist/esm/actions/sendUTXOTransaction.js.map +1 -1
  227. package/dist/esm/actions/signPsbt.d.ts +0 -1
  228. package/dist/esm/actions/signPsbt.d.ts.map +1 -1
  229. package/dist/esm/actions/signPsbt.js.map +1 -1
  230. package/dist/esm/actions/waitForTransaction.d.ts +43 -49
  231. package/dist/esm/actions/waitForTransaction.d.ts.map +1 -1
  232. package/dist/esm/actions/waitForTransaction.js.map +1 -1
  233. package/dist/esm/actions/watchBlockNumber.d.ts +14 -16
  234. package/dist/esm/actions/watchBlockNumber.d.ts.map +1 -1
  235. package/dist/esm/actions/watchBlockNumber.js.map +1 -1
  236. package/dist/esm/chains/bitcoin.d.ts +0 -1
  237. package/dist/esm/chains/bitcoin.d.ts.map +1 -1
  238. package/dist/esm/chains/bitcoin.js +3 -3
  239. package/dist/esm/chains/bitcoin.js.map +1 -1
  240. package/dist/esm/chains/defineChain.d.ts +0 -1
  241. package/dist/esm/chains/defineChain.d.ts.map +1 -1
  242. package/dist/esm/chains/defineChain.js.map +1 -1
  243. package/dist/esm/chains/signet.d.ts +0 -1
  244. package/dist/esm/chains/signet.d.ts.map +1 -1
  245. package/dist/esm/chains/signet.js +3 -3
  246. package/dist/esm/chains/signet.js.map +1 -1
  247. package/dist/esm/clients/decorators/public.d.ts +0 -1
  248. package/dist/esm/clients/decorators/public.d.ts.map +1 -1
  249. package/dist/esm/clients/decorators/public.js.map +1 -1
  250. package/dist/esm/clients/decorators/wallet.d.ts +2 -3
  251. package/dist/esm/clients/decorators/wallet.d.ts.map +1 -1
  252. package/dist/esm/clients/decorators/wallet.js.map +1 -1
  253. package/dist/esm/errors/address.d.ts +1 -4
  254. package/dist/esm/errors/address.d.ts.map +1 -1
  255. package/dist/esm/errors/address.js.map +1 -1
  256. package/dist/esm/errors/base.d.ts.map +1 -1
  257. package/dist/esm/errors/base.js.map +1 -1
  258. package/dist/esm/errors/block.d.ts +1 -5
  259. package/dist/esm/errors/block.d.ts.map +1 -1
  260. package/dist/esm/errors/block.js.map +1 -1
  261. package/dist/esm/errors/provider.d.ts +0 -1
  262. package/dist/esm/errors/provider.d.ts.map +1 -1
  263. package/dist/esm/errors/provider.js.map +1 -1
  264. package/dist/esm/errors/request.d.ts +5 -28
  265. package/dist/esm/errors/request.d.ts.map +1 -1
  266. package/dist/esm/errors/request.js.map +1 -1
  267. package/dist/esm/errors/rpc.d.ts +23 -24
  268. package/dist/esm/errors/rpc.d.ts.map +1 -1
  269. package/dist/esm/errors/rpc.js +3 -3
  270. package/dist/esm/errors/rpc.js.map +1 -1
  271. package/dist/esm/errors/transaction.d.ts +3 -14
  272. package/dist/esm/errors/transaction.d.ts.map +1 -1
  273. package/dist/esm/errors/transaction.js.map +1 -1
  274. package/dist/esm/errors/transport.d.ts +2 -10
  275. package/dist/esm/errors/transport.d.ts.map +1 -1
  276. package/dist/esm/errors/transport.js.map +1 -1
  277. package/dist/esm/errors/utils.d.ts +0 -1
  278. package/dist/esm/errors/utils.d.ts.map +1 -1
  279. package/dist/esm/errors/utxo.d.ts +1 -6
  280. package/dist/esm/errors/utxo.d.ts.map +1 -1
  281. package/dist/esm/errors/utxo.js.map +1 -1
  282. package/dist/esm/factories/createClient.d.ts +49 -30
  283. package/dist/esm/factories/createClient.d.ts.map +1 -1
  284. package/dist/esm/factories/createClient.js.map +1 -1
  285. package/dist/esm/factories/createTransport.d.ts +3 -13
  286. package/dist/esm/factories/createTransport.d.ts.map +1 -1
  287. package/dist/esm/factories/createTransport.js.map +1 -1
  288. package/dist/esm/test/utils.d.ts.map +1 -1
  289. package/dist/esm/test/utils.js.map +1 -1
  290. package/dist/esm/transports/ankr/ankr.d.ts +0 -1
  291. package/dist/esm/transports/ankr/ankr.d.ts.map +1 -1
  292. package/dist/esm/transports/ankr/ankr.js.map +1 -1
  293. package/dist/esm/transports/ankr/ankr.types.d.ts.map +1 -1
  294. package/dist/esm/transports/ankr/getBalance.d.ts +0 -1
  295. package/dist/esm/transports/ankr/getBalance.d.ts.map +1 -1
  296. package/dist/esm/transports/ankr/getBalance.js +2 -2
  297. package/dist/esm/transports/ankr/getBalance.js.map +1 -1
  298. package/dist/esm/transports/ankr/getTransactionFee.d.ts +0 -1
  299. package/dist/esm/transports/ankr/getTransactionFee.d.ts.map +1 -1
  300. package/dist/esm/transports/ankr/getTransactionFee.js.map +1 -1
  301. package/dist/esm/transports/ankr/getTransactions.d.ts +0 -1
  302. package/dist/esm/transports/ankr/getTransactions.d.ts.map +1 -1
  303. package/dist/esm/transports/ankr/getTransactions.js.map +1 -1
  304. package/dist/esm/transports/ankr/methods.d.ts +0 -1
  305. package/dist/esm/transports/ankr/methods.d.ts.map +1 -1
  306. package/dist/esm/transports/ankr/methods.js.map +1 -1
  307. package/dist/esm/transports/ankr/utils.d.ts +0 -1
  308. package/dist/esm/transports/ankr/utils.d.ts.map +1 -1
  309. package/dist/esm/transports/ankr/utils.js.map +1 -1
  310. package/dist/esm/transports/blockchair/blockchair.d.ts +0 -1
  311. package/dist/esm/transports/blockchair/blockchair.d.ts.map +1 -1
  312. package/dist/esm/transports/blockchair/blockchair.js.map +1 -1
  313. package/dist/esm/transports/blockchair/blockchair.types.d.ts.map +1 -1
  314. package/dist/esm/transports/blockchair/getBalance.d.ts +0 -1
  315. package/dist/esm/transports/blockchair/getBalance.d.ts.map +1 -1
  316. package/dist/esm/transports/blockchair/getBalance.js +2 -2
  317. package/dist/esm/transports/blockchair/getBalance.js.map +1 -1
  318. package/dist/esm/transports/blockchair/getTransactionFee.d.ts +0 -1
  319. package/dist/esm/transports/blockchair/getTransactionFee.d.ts.map +1 -1
  320. package/dist/esm/transports/blockchair/getTransactionFee.js +2 -2
  321. package/dist/esm/transports/blockchair/getTransactionFee.js.map +1 -1
  322. package/dist/esm/transports/blockchair/getUTXOs.d.ts +0 -1
  323. package/dist/esm/transports/blockchair/getUTXOs.d.ts.map +1 -1
  324. package/dist/esm/transports/blockchair/getUTXOs.js +2 -2
  325. package/dist/esm/transports/blockchair/getUTXOs.js.map +1 -1
  326. package/dist/esm/transports/blockchair/getXPubAddresses.d.ts +0 -1
  327. package/dist/esm/transports/blockchair/getXPubAddresses.d.ts.map +1 -1
  328. package/dist/esm/transports/blockchair/getXPubAddresses.js +2 -2
  329. package/dist/esm/transports/blockchair/getXPubAddresses.js.map +1 -1
  330. package/dist/esm/transports/blockchair/methods.d.ts +0 -1
  331. package/dist/esm/transports/blockchair/methods.d.ts.map +1 -1
  332. package/dist/esm/transports/blockchair/methods.js.map +1 -1
  333. package/dist/esm/transports/blockcypher/blockcypher.d.ts +0 -1
  334. package/dist/esm/transports/blockcypher/blockcypher.d.ts.map +1 -1
  335. package/dist/esm/transports/blockcypher/blockcypher.js.map +1 -1
  336. package/dist/esm/transports/blockcypher/blockcypher.types.d.ts.map +1 -1
  337. package/dist/esm/transports/blockcypher/getBalance.d.ts +0 -1
  338. package/dist/esm/transports/blockcypher/getBalance.d.ts.map +1 -1
  339. package/dist/esm/transports/blockcypher/getBalance.js.map +1 -1
  340. package/dist/esm/transports/blockcypher/getTransactionFee.d.ts +0 -1
  341. package/dist/esm/transports/blockcypher/getTransactionFee.d.ts.map +1 -1
  342. package/dist/esm/transports/blockcypher/getTransactionFee.js.map +1 -1
  343. package/dist/esm/transports/blockcypher/getUTXOs.d.ts +0 -1
  344. package/dist/esm/transports/blockcypher/getUTXOs.d.ts.map +1 -1
  345. package/dist/esm/transports/blockcypher/getUTXOs.js.map +1 -1
  346. package/dist/esm/transports/blockcypher/methods.d.ts +0 -1
  347. package/dist/esm/transports/blockcypher/methods.d.ts.map +1 -1
  348. package/dist/esm/transports/blockcypher/methods.js.map +1 -1
  349. package/dist/esm/transports/blockcypher/utils.d.ts +0 -1
  350. package/dist/esm/transports/blockcypher/utils.d.ts.map +1 -1
  351. package/dist/esm/transports/blockcypher/utils.js +3 -3
  352. package/dist/esm/transports/blockcypher/utils.js.map +1 -1
  353. package/dist/esm/transports/custom.d.ts +11 -7
  354. package/dist/esm/transports/custom.d.ts.map +1 -1
  355. package/dist/esm/transports/custom.js.map +1 -1
  356. package/dist/esm/transports/fallback.d.ts +32 -36
  357. package/dist/esm/transports/fallback.d.ts.map +1 -1
  358. package/dist/esm/transports/fallback.js +2 -2
  359. package/dist/esm/transports/fallback.js.map +1 -1
  360. package/dist/esm/transports/getHttpRpcClient.d.ts +17 -9
  361. package/dist/esm/transports/getHttpRpcClient.d.ts.map +1 -1
  362. package/dist/esm/transports/getHttpRpcClient.js.map +1 -1
  363. package/dist/esm/transports/getRpcProviderMethods.d.ts +0 -1
  364. package/dist/esm/transports/getRpcProviderMethods.d.ts.map +1 -1
  365. package/dist/esm/transports/getRpcProviderMethods.js.map +1 -1
  366. package/dist/esm/transports/http.d.ts +31 -20
  367. package/dist/esm/transports/http.d.ts.map +1 -1
  368. package/dist/esm/transports/http.js.map +1 -1
  369. package/dist/esm/transports/mempool/getBalance.d.ts +0 -1
  370. package/dist/esm/transports/mempool/getBalance.d.ts.map +1 -1
  371. package/dist/esm/transports/mempool/getBalance.js.map +1 -1
  372. package/dist/esm/transports/mempool/getTransactionFee.d.ts +0 -1
  373. package/dist/esm/transports/mempool/getTransactionFee.d.ts.map +1 -1
  374. package/dist/esm/transports/mempool/getTransactionFee.js.map +1 -1
  375. package/dist/esm/transports/mempool/getTransactions.d.ts +0 -1
  376. package/dist/esm/transports/mempool/getTransactions.d.ts.map +1 -1
  377. package/dist/esm/transports/mempool/getTransactions.js.map +1 -1
  378. package/dist/esm/transports/mempool/mempool.d.ts +0 -1
  379. package/dist/esm/transports/mempool/mempool.d.ts.map +1 -1
  380. package/dist/esm/transports/mempool/mempool.js.map +1 -1
  381. package/dist/esm/transports/mempool/mempool.types.d.ts.map +1 -1
  382. package/dist/esm/transports/mempool/methods.d.ts +0 -1
  383. package/dist/esm/transports/mempool/methods.d.ts.map +1 -1
  384. package/dist/esm/transports/mempool/methods.js.map +1 -1
  385. package/dist/esm/transports/mempool/utils.d.ts +0 -1
  386. package/dist/esm/transports/mempool/utils.d.ts.map +1 -1
  387. package/dist/esm/transports/mempool/utils.js.map +1 -1
  388. package/dist/esm/transports/types.d.ts +17 -15
  389. package/dist/esm/transports/types.d.ts.map +1 -1
  390. package/dist/esm/transports/types.js.map +1 -1
  391. package/dist/esm/transports/utxo.d.ts +0 -1
  392. package/dist/esm/transports/utxo.d.ts.map +1 -1
  393. package/dist/esm/transports/utxo.js.map +1 -1
  394. package/dist/esm/types/account.d.ts +0 -1
  395. package/dist/esm/types/account.d.ts.map +1 -1
  396. package/dist/esm/types/address.d.ts +0 -1
  397. package/dist/esm/types/address.d.ts.map +1 -1
  398. package/dist/esm/types/address.js.map +1 -1
  399. package/dist/esm/types/block.d.ts +17 -17
  400. package/dist/esm/types/block.d.ts.map +1 -1
  401. package/dist/esm/types/blockStats.d.ts.map +1 -1
  402. package/dist/esm/types/chain.d.ts +20 -9
  403. package/dist/esm/types/chain.d.ts.map +1 -1
  404. package/dist/esm/types/chain.js.map +1 -1
  405. package/dist/esm/types/client.d.ts +40 -25
  406. package/dist/esm/types/client.d.ts.map +1 -1
  407. package/dist/esm/types/hash.d.ts.map +1 -1
  408. package/dist/esm/types/request.d.ts +12 -8
  409. package/dist/esm/types/request.d.ts.map +1 -1
  410. package/dist/esm/types/rpc.d.ts.map +1 -1
  411. package/dist/esm/types/transaction.d.ts.map +1 -1
  412. package/dist/esm/types/transport.d.ts +16 -11
  413. package/dist/esm/types/transport.d.ts.map +1 -1
  414. package/dist/esm/types/utils.d.ts +31 -31
  415. package/dist/esm/types/utils.d.ts.map +1 -1
  416. package/dist/esm/types/xpub.d.ts +0 -1
  417. package/dist/esm/types/xpub.d.ts.map +1 -1
  418. package/dist/esm/utils/buildRequest.d.ts +0 -1
  419. package/dist/esm/utils/buildRequest.d.ts.map +1 -1
  420. package/dist/esm/utils/buildRequest.js +4 -4
  421. package/dist/esm/utils/buildRequest.js.map +1 -1
  422. package/dist/esm/utils/cancelTransaction.d.ts +0 -1
  423. package/dist/esm/utils/cancelTransaction.d.ts.map +1 -1
  424. package/dist/esm/utils/cancelTransaction.js.map +1 -1
  425. package/dist/esm/utils/converter.d.ts.map +1 -1
  426. package/dist/esm/utils/converter.js.map +1 -1
  427. package/dist/esm/utils/createBatchScheduler.d.ts +1 -8
  428. package/dist/esm/utils/createBatchScheduler.d.ts.map +1 -1
  429. package/dist/esm/utils/createBatchScheduler.js +1 -1
  430. package/dist/esm/utils/createBatchScheduler.js.map +1 -1
  431. package/dist/esm/utils/deepEqual.d.ts.map +1 -1
  432. package/dist/esm/utils/deepEqual.js.map +1 -1
  433. package/dist/esm/utils/getAction.d.ts +6 -7
  434. package/dist/esm/utils/getAction.d.ts.map +1 -1
  435. package/dist/esm/utils/getAction.js.map +1 -1
  436. package/dist/esm/utils/getAddressInfo.d.ts +0 -1
  437. package/dist/esm/utils/getAddressInfo.d.ts.map +1 -1
  438. package/dist/esm/utils/getAddressInfo.js +25 -25
  439. package/dist/esm/utils/getAddressInfo.js.map +1 -1
  440. package/dist/esm/utils/idCache.d.ts.map +1 -1
  441. package/dist/esm/utils/idCache.js.map +1 -1
  442. package/dist/esm/utils/isAddress.d.ts +0 -1
  443. package/dist/esm/utils/isAddress.d.ts.map +1 -1
  444. package/dist/esm/utils/isAddress.js.map +1 -1
  445. package/dist/esm/utils/lru.d.ts +4 -4
  446. package/dist/esm/utils/lru.d.ts.map +1 -1
  447. package/dist/esm/utils/lru.js.map +1 -1
  448. package/dist/esm/utils/modifyFee.d.ts +0 -1
  449. package/dist/esm/utils/modifyFee.d.ts.map +1 -1
  450. package/dist/esm/utils/modifyFee.js.map +1 -1
  451. package/dist/esm/utils/observe.d.ts +4 -5
  452. package/dist/esm/utils/observe.d.ts.map +1 -1
  453. package/dist/esm/utils/observe.js +2 -2
  454. package/dist/esm/utils/observe.js.map +1 -1
  455. package/dist/esm/utils/parseAccount.d.ts +0 -1
  456. package/dist/esm/utils/parseAccount.d.ts.map +1 -1
  457. package/dist/esm/utils/parseAccount.js.map +1 -1
  458. package/dist/esm/utils/poll.d.ts +4 -10
  459. package/dist/esm/utils/poll.d.ts.map +1 -1
  460. package/dist/esm/utils/poll.js.map +1 -1
  461. package/dist/esm/utils/retryUntil.d.ts +17 -15
  462. package/dist/esm/utils/retryUntil.d.ts.map +1 -1
  463. package/dist/esm/utils/retryUntil.js.map +1 -1
  464. package/dist/esm/utils/sleep.d.ts.map +1 -1
  465. package/dist/esm/utils/sleep.js.map +1 -1
  466. package/dist/esm/utils/stringify.d.ts +0 -1
  467. package/dist/esm/utils/stringify.d.ts.map +1 -1
  468. package/dist/esm/utils/stringify.js.map +1 -1
  469. package/dist/esm/utils/uid.d.ts.map +1 -1
  470. package/dist/esm/utils/uid.js.map +1 -1
  471. package/dist/esm/utils/url.d.ts.map +1 -1
  472. package/dist/esm/utils/url.js.map +1 -1
  473. package/dist/esm/utils/wait.d.ts.map +1 -1
  474. package/dist/esm/utils/wait.js.map +1 -1
  475. package/dist/esm/utils/withDedupe.d.ts +1 -5
  476. package/dist/esm/utils/withDedupe.d.ts.map +1 -1
  477. package/dist/esm/utils/withDedupe.js +1 -1
  478. package/dist/esm/utils/withDedupe.js.map +1 -1
  479. package/dist/esm/utils/withResolvers.d.ts.map +1 -1
  480. package/dist/esm/utils/withResolvers.js.map +1 -1
  481. package/dist/esm/utils/withRetry.d.ts +2 -10
  482. package/dist/esm/utils/withRetry.d.ts.map +1 -1
  483. package/dist/esm/utils/withRetry.js.map +1 -1
  484. package/dist/esm/utils/withTimeout.d.ts +2 -9
  485. package/dist/esm/utils/withTimeout.d.ts.map +1 -1
  486. package/dist/esm/utils/withTimeout.js.map +1 -1
  487. package/dist/esm/version.d.ts +1 -1
  488. package/dist/esm/version.d.ts.map +1 -1
  489. package/dist/esm/version.js +1 -1
  490. package/dist/esm/version.js.map +1 -1
  491. package/package.json +3 -2
  492. package/src/version.ts +1 -1
  493. package/dist/cjs/transports/__mocks__/getTransactionFee.d.ts +0 -7
  494. package/dist/cjs/transports/__mocks__/getTransactionFee.js +0 -11
  495. package/dist/cjs/transports/__mocks__/getTransactionFee.js.map +0 -1
  496. package/dist/esm/transports/__mocks__/getTransactionFee.d.ts +0 -7
  497. package/dist/esm/transports/__mocks__/getTransactionFee.d.ts.map +0 -1
  498. package/dist/esm/transports/__mocks__/getTransactionFee.js +0 -8
  499. package/dist/esm/transports/__mocks__/getTransactionFee.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"getUTXOs.js","names":["urlWithParams","RpcRequestError","RpcErrorCode","getBalance","BaseError","InsufficientUTXOBalanceError"],"sources":["../../../../src/transports/blockchair/getUTXOs.ts"],"sourcesContent":["import { BaseError } from '../../errors/base.js'\nimport { RpcRequestError } from '../../errors/request.js'\nimport { RpcErrorCode } from '../../errors/rpc.js'\nimport { InsufficientUTXOBalanceError } from '../../errors/utxo.js'\nimport type { UTXO } from '../../types/transaction.js'\n\nimport { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type {\n BlockChairDashboardAddressResponse,\n BlockchairResponse,\n BlockchairUTXO,\n} from './blockchair.types.js'\nimport { getBalance } from './getBalance.js'\n\nconst blockChairUTXOTransformer =\n (scriptHex: string) =>\n (data: BlockchairUTXO): UTXO => ({\n blockHeight: data.block_id,\n scriptHex,\n txId: data.transaction_hash,\n value: data.value,\n vout: data.index,\n })\n\nconst MAX_API_LIMIT = '100,100'\n\nexport const getUTXOs: RpcMethodHandler<'getUTXOs'> = async (\n client,\n { baseUrl, apiKey },\n { address, minValue }\n) => {\n async function* fetchUTXOs() {\n let offset = 0\n let hasMore = true\n\n while (hasMore) {\n const apiUrl = urlWithParams(\n `${baseUrl}/dashboards/addresses/${address}`,\n {\n key: apiKey,\n offset: `0,${offset}`,\n limit: MAX_API_LIMIT,\n }\n )\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as BlockchairResponse<BlockChairDashboardAddressResponse>\n\n if (response.context?.code !== 200 && response.context?.code !== 404) {\n throw new RpcRequestError({\n url: apiUrl,\n body: {\n method: 'fetchUTXOs',\n params: {\n address,\n minValue,\n },\n },\n error: {\n code:\n response.context.code === 429\n ? RpcErrorCode.ACCESS_DENIED\n : RpcErrorCode.MISC_ERROR,\n message: response.context.error || 'Error fetching utxos',\n },\n })\n }\n\n if (!response.data || response.data.utxo.length === 0) {\n hasMore = false\n continue\n }\n\n const { limit } = response.context\n const totalRows = response.data.addresses[address].unspent_output_count\n if (limit && totalRows) {\n const [, utxoLimit] = String(limit)\n .split(',')\n .map((val) => Number(val))\n hasMore = offset + utxoLimit < totalRows\n offset += utxoLimit\n } else {\n hasMore = false\n offset += 0\n }\n\n yield response.data\n }\n }\n\n if (minValue) {\n const { error, result: balance } = await getBalance(\n client,\n { baseUrl, apiKey },\n { address }\n )\n\n if (error) {\n throw new BaseError('Error fetching balance', {\n cause: error,\n })\n }\n\n if (balance === undefined) {\n throw new BaseError('Balance is undefined', {\n cause: new Error('Unable to determine balance'),\n })\n }\n\n if (minValue > Number(balance)) {\n throw new InsufficientUTXOBalanceError({\n minValue,\n address,\n balance: Number(balance),\n })\n }\n }\n const utxos: UTXO[] = []\n let valueCount = 0\n\n for await (const batch of fetchUTXOs()) {\n const addressScriptHex = batch.addresses[address].script_hex\n const utxoBatch = batch.utxo.map(\n blockChairUTXOTransformer(addressScriptHex)\n )\n utxos.push(...utxoBatch)\n\n if (minValue) {\n valueCount += utxoBatch.reduce((sum, utxo) => sum + utxo.value, 0)\n if (valueCount >= minValue) {\n break\n }\n }\n }\n\n return { result: utxos }\n}\n"],"mappings":";;;;;;;;AAeA,MAAM,6BACH,eACA,UAAgC;CAC/B,aAAa,KAAK;CAClB;CACA,MAAM,KAAK;CACX,OAAO,KAAK;CACZ,MAAM,KAAK;CACZ;AAEH,MAAM,gBAAgB;AAEtB,MAAa,WAAyC,OACpD,QACA,EAAE,SAAS,UACX,EAAE,SAAS,eACR;CACH,gBAAgB,aAAa;EAC3B,IAAI,SAAS;EACb,IAAI,UAAU;AAEd,SAAO,SAAS;GACd,MAAM,SAASA,kBAAAA,cACb,GAAG,QAAQ,wBAAwB,WACnC;IACE,KAAK;IACL,QAAQ,KAAK;IACb,OAAO;IACR,CACF;GACD,MAAM,WAAY,MAAM,OAAO,QAAQ;IACrC,KAAK;IACL,cAAc,EAAE,QAAQ,OAAO;IAChC,CAAC;AAEF,OAAI,SAAS,SAAS,SAAS,OAAO,S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KAAK,GAAG,UAAU;AAExB,MAAI,UAAU;AACZ,iBAAc,UAAU,QAAQ,KAAK,SAAS,MAAM,KAAK,OAAO,EAAE;AAClE,OAAI,cAAc,SAChB;;;AAKN,QAAO,EAAE,QAAQ,OAAO"}
1
+ {"version":3,"file":"getUTXOs.js","names":["urlWithParams","RpcRequestError","getBalance","BaseError","InsufficientUTXOBalanceError"],"sources":["../../../../src/transports/blockchair/getUTXOs.ts"],"sourcesContent":["import { BaseError } from '../../errors/base.js'\nimport { RpcRequestError } from '../../errors/request.js'\nimport { RpcErrorCode } from '../../errors/rpc.js'\nimport { InsufficientUTXOBalanceError } from '../../errors/utxo.js'\nimport type { UTXO } from '../../types/transaction.js'\n\nimport { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type {\n BlockChairDashboardAddressResponse,\n BlockchairResponse,\n BlockchairUTXO,\n} from './blockchair.types.js'\nimport { getBalance } from './getBalance.js'\n\nconst blockChairUTXOTransformer =\n (scriptHex: string) =>\n (data: BlockchairUTXO): UTXO => ({\n blockHeight: data.block_id,\n scriptHex,\n txId: data.transaction_hash,\n value: data.value,\n vout: data.index,\n })\n\nconst MAX_API_LIMIT = '100,100'\n\nexport const getUTXOs: RpcMethodHandler<'getUTXOs'> = async (\n client,\n { baseUrl, apiKey },\n { address, minValue }\n) => {\n async function* fetchUTXOs() {\n let offset = 0\n let hasMore = true\n\n while (hasMore) {\n const apiUrl = urlWithParams(\n `${baseUrl}/dashboards/addresses/${address}`,\n {\n key: apiKey,\n offset: `0,${offset}`,\n limit: MAX_API_LIMIT,\n }\n )\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as BlockchairResponse<BlockChairDashboardAddressResponse>\n\n if (response.context?.code !== 200 && response.context?.code !== 404) {\n throw new RpcRequestError({\n url: apiUrl,\n body: {\n method: 'fetchUTXOs',\n params: {\n address,\n minValue,\n },\n },\n error: {\n code:\n response.context.code === 429\n ? RpcErrorCode.ACCESS_DENIED\n : RpcErrorCode.MISC_ERROR,\n message: response.context.error || 'Error fetching utxos',\n },\n })\n }\n\n if (!response.data || response.data.utxo.length === 0) {\n hasMore = false\n continue\n }\n\n const { limit } = response.context\n const totalRows = response.data.addresses[address].unspent_output_count\n if (limit && totalRows) {\n const [, utxoLimit] = String(limit)\n .split(',')\n .map((val) => Number(val))\n hasMore = offset + utxoLimit < totalRows\n offset += utxoLimit\n } else {\n hasMore = false\n offset += 0\n }\n\n yield response.data\n }\n }\n\n if (minValue) {\n const { error, result: balance } = await getBalance(\n client,\n { baseUrl, apiKey },\n { address }\n )\n\n if (error) {\n throw new BaseError('Error fetching balance', {\n cause: error,\n })\n }\n\n if (balance === undefined) {\n throw new BaseError('Balance is undefined', {\n cause: new Error('Unable to determine balance'),\n })\n }\n\n if (minValue > Number(balance)) {\n throw new InsufficientUTXOBalanceError({\n minValue,\n address,\n balance: Number(balance),\n })\n }\n }\n const utxos: UTXO[] = []\n let valueCount = 0\n\n for await (const batch of fetchUTXOs()) {\n const addressScriptHex = batch.addresses[address].script_hex\n const utxoBatch = batch.utxo.map(\n blockChairUTXOTransformer(addressScriptHex)\n )\n utxos.push(...utxoBatch)\n\n if (minValue) {\n valueCount += utxoBatch.reduce((sum, utxo) => sum + utxo.value, 0)\n if (valueCount >= minValue) {\n break\n }\n }\n }\n\n return { result: utxos }\n}\n"],"mappings":";;;;;;;;AAeA,MAAM,6BACH,eACA,UAAgC;CAC/B,aAAa,KAAK;CAClB;CACA,MAAM,KAAK;CACX,OAAO,KAAK;CACZ,MAAM,KAAK;AACb;AAEF,MAAM,gBAAgB;AAEtB,MAAa,WAAyC,OACpD,QACA,EAAE,SAAS,UACX,EAAE,SAAS,eACR;CACH,gBAAgB,aAAa;EAC3B,IAAI,SAAS;EACb,IAAI,UAAU;EAEd,OAAO,SAAS;GACd,MAAM,SAASA,kBAAAA,cACb,GAAG,QAAQ,wBAAwB,WACnC;IACE,KAAK;IACL,QAAQ,KAAK;IACb,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AAa;CAEjB,WAAW,MAAM,SAAS,WAAW,GAAG;EACtC,MAAM,mBAAmB,MAAM,UAAU,QAAQ,CAAC;EAClD,MAAM,YAAY,MAAM,KAAK,IAC3B,0BAA0B,gBAAgB,CAC5C;EACA,MAAM,KAAK,GAAG,SAAS;EAEvB,IAAI,UAAU;GACZ,cAAc,UAAU,QAAQ,KAAK,SAAS,MAAM,KAAK,OAAO,CAAC;GACjE,IAAI,cAAc,UAChB;EAEJ;CACF;CAEA,OAAO,EAAE,QAAQ,MAAM;AACzB"}
@@ -1,5 +1,4 @@
1
1
  import { RpcMethodHandler } from "../types.js";
2
-
3
2
  //#region src/transports/blockchair/getXPubAddresses.d.ts
4
3
  declare const getXPubAddresses: RpcMethodHandler<"getXPubAddresses">;
5
4
  //#endregion
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_errors_rpc = require("../../errors/rpc.js");
2
+ require("../../errors/rpc.js");
3
3
  const require_utils_url = require("../../utils/url.js");
4
4
  //#region src/transports/blockchair/getXPubAddresses.ts
5
5
  const getXPubAddresses = async (client, { baseUrl, apiKey }, { xPubKey }) => {
@@ -9,7 +9,7 @@ const getXPubAddresses = async (client, { baseUrl, apiKey }, { xPubKey }) => {
9
9
  fetchOptions: { method: "GET" }
10
10
  });
11
11
  if (response.context.error || response.context?.code !== 200) return { error: {
12
- code: response.context.code === 429 ? require_errors_rpc.RpcErrorCode.ACCESS_DENIED : require_errors_rpc.RpcErrorCode.MISC_ERROR,
12
+ code: response.context.code === 429 ? -32002 : -1,
13
13
  message: response.context?.error
14
14
  } };
15
15
  if (response.data[xPubKey] === void 0) return { result: {
@@ -1 +1 @@
1
- {"version":3,"file":"getXPubAddresses.js","names":["urlWithParams","RpcErrorCode"],"sources":["../../../../src/transports/blockchair/getXPubAddresses.ts"],"sourcesContent":["import { RpcErrorCode } from '../../errors/rpc.js'\nimport { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type {\n BlockchairResponse,\n BlockchairXpubResponse,\n} from './blockchair.types.js'\n\nexport const getXPubAddresses: RpcMethodHandler<'getXPubAddresses'> = async (\n client,\n { baseUrl, apiKey },\n { xPubKey }\n) => {\n const apiUrl = urlWithParams(`${baseUrl}/dashboards/xpub/${xPubKey}`, {\n key: apiKey,\n })\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as BlockchairResponse<BlockchairXpubResponse>\n\n if (response.context.error || response.context?.code !== 200) {\n return {\n error: {\n code:\n response.context.code === 429\n ? RpcErrorCode.ACCESS_DENIED\n : RpcErrorCode.MISC_ERROR,\n message: response.context?.error,\n },\n }\n }\n\n if (response.data[xPubKey] === undefined) {\n return {\n result: {\n balance: 0n,\n addresses: [],\n },\n }\n }\n\n const xpubData = response.data[xPubKey]\n\n const result = {\n balance: BigInt(xpubData.xpub.balance),\n addresses: Object.entries(xpubData.addresses).map(([address, data]) => ({\n address,\n balance: BigInt(data.balance),\n path: data.path,\n scriptHex: data.script_hex,\n })),\n }\n\n return {\n result,\n }\n}\n"],"mappings":";;;;AAQA,MAAa,mBAAyD,OACpE,QACA,EAAE,SAAS,UACX,EAAE,cACC;CACH,MAAM,SAASA,kBAAAA,cAAc,GAAG,QAAQ,mBAAmB,WAAW,EACpE,KAAK,QACN,CAAC;CACF,MAAM,WAAY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EAAE,QAAQ,OAAO;EAChC,CAAC;AAEF,KAAI,SAAS,QAAQ,SAAS,SAAS,SAAS,SAAS,IACvD,QAAO,EACL,OAAO;EACL,MACE,SAAS,QAAQ,SAAS,MACtBC,mBAAAA,aAAa,gBACbA,mBAAAA,aAAa;EACnB,SAAS,SAAS,SAAS;EAC5B,EACF;AAGH,KAAI,SAAS,KAAK,aAAa,KAAA,EAC7B,QAAO,EACL,QAAQ;EACN,SAAS;EACT,WAAW,EAAE;EACd,EACF;CAGH,MAAM,WAAW,SAAS,KAAK;AAY/B,QAAO,EACL,QAXa;EACb,SAAS,OAAO,SAAS,KAAK,QAAQ;EACtC,WAAW,OAAO,QAAQ,SAAS,UAAU,CAAC,KAAK,CAAC,SAAS,WAAW;GACtE;GACA,SAAS,OAAO,KAAK,QAAQ;GAC7B,MAAM,KAAK;GACX,WAAW,KAAK;GACjB,EAAE;EACJ,EAIA"}
1
+ {"version":3,"file":"getXPubAddresses.js","names":["urlWithParams"],"sources":["../../../../src/transports/blockchair/getXPubAddresses.ts"],"sourcesContent":["import { RpcErrorCode } from '../../errors/rpc.js'\nimport { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type {\n BlockchairResponse,\n BlockchairXpubResponse,\n} from './blockchair.types.js'\n\nexport const getXPubAddresses: RpcMethodHandler<'getXPubAddresses'> = async (\n client,\n { baseUrl, apiKey },\n { xPubKey }\n) => {\n const apiUrl = urlWithParams(`${baseUrl}/dashboards/xpub/${xPubKey}`, {\n key: apiKey,\n })\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as BlockchairResponse<BlockchairXpubResponse>\n\n if (response.context.error || response.context?.code !== 200) {\n return {\n error: {\n code:\n response.context.code === 429\n ? RpcErrorCode.ACCESS_DENIED\n : RpcErrorCode.MISC_ERROR,\n message: response.context?.error,\n },\n }\n }\n\n if (response.data[xPubKey] === undefined) {\n return {\n result: {\n balance: 0n,\n addresses: [],\n },\n }\n }\n\n const xpubData = response.data[xPubKey]\n\n const result = {\n balance: BigInt(xpubData.xpub.balance),\n addresses: Object.entries(xpubData.addresses).map(([address, data]) => ({\n address,\n balance: BigInt(data.balance),\n path: data.path,\n scriptHex: data.script_hex,\n })),\n }\n\n return {\n result,\n }\n}\n"],"mappings":";;;;AAQA,MAAa,mBAAyD,OACpE,QACA,EAAE,SAAS,UACX,EAAE,cACC;CACH,MAAM,SAASA,kBAAAA,cAAc,GAAG,QAAQ,mBAAmB,WAAW,EACpE,KAAK,OACP,CAAC;CACD,MAAM,WAAY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EAAE,QAAQ,MAAM;CAChC,CAAC;CAED,IAAI,SAAS,QAAQ,SAAS,SAAS,SAAS,SAAS,KACvD,OAAO,EACL,OAAO;EACL,MACE,SAAS,QAAQ,SAAS,MAAA,SAAA;EAG5B,SAAS,SAAS,SAAS;CAC7B,EACF;CAGF,IAAI,SAAS,KAAK,aAAa,KAAA,GAC7B,OAAO,EACL,QAAQ;EACN,SAAS;EACT,WAAW,CAAC;CACd,EACF;CAGF,MAAM,WAAW,SAAS,KAAK;CAY/B,OAAO,EACL,QAAA;EAVA,SAAS,OAAO,SAAS,KAAK,OAAO;EACrC,WAAW,OAAO,QAAQ,SAAS,SAAS,CAAC,CAAC,KAAK,CAAC,SAAS,WAAW;GACtE;GACA,SAAS,OAAO,KAAK,OAAO;GAC5B,MAAM,KAAK;GACX,WAAW,KAAK;EAClB,EAAE;CAIG,EACP;AACF"}
@@ -1,5 +1,4 @@
1
1
  import { RpcMethods } from "../types.js";
2
-
3
2
  //#region src/transports/blockchair/methods.d.ts
4
3
  declare const blockchairMethods: RpcMethods;
5
4
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"methods.js","names":[],"sources":["../../../../src/transports/blockchair/methods.ts"],"sourcesContent":["import type { RpcMethods } from '../types.js'\nimport { getBalance } from './getBalance.js'\nimport { getTransactionFee } from './getTransactionFee.js'\nimport { getUTXOs } from './getUTXOs.js'\nimport { getXPubAddresses } from './getXPubAddresses.js'\n\nexport const blockchairMethods: RpcMethods = {\n getBalance,\n getUTXOs,\n getTransactionFee,\n getXPubAddresses,\n}\n"],"mappings":";;;;;;AAMA,MAAa,oBAAgC;CAC3C,YAAA,yCAAA;CACA,UAAA,uCAAA;CACA,mBAAA,gDAAA;CACA,kBAAA,+CAAA;CACD"}
1
+ {"version":3,"file":"methods.js","names":[],"sources":["../../../../src/transports/blockchair/methods.ts"],"sourcesContent":["import type { RpcMethods } from '../types.js'\nimport { getBalance } from './getBalance.js'\nimport { getTransactionFee } from './getTransactionFee.js'\nimport { getUTXOs } from './getUTXOs.js'\nimport { getXPubAddresses } from './getXPubAddresses.js'\n\nexport const blockchairMethods: RpcMethods = {\n getBalance,\n getUTXOs,\n getTransactionFee,\n getXPubAddresses,\n}\n"],"mappings":";;;;;;AAMA,MAAa,oBAAgC;CAC3C,YAAA,yCAAA;CACA,UAAA,uCAAA;CACA,mBAAA,gDAAA;CACA,kBAAA,+CAAA;AACF"}
@@ -1,5 +1,4 @@
1
1
  import { HttpTransport, HttpTransportConfig } from "../http.js";
2
-
3
2
  //#region src/transports/blockcypher/blockcypher.d.ts
4
3
  type BlockcypherConfig = {
5
4
  baseUrl?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"blockcypher.js","names":["utxo","blockcypherMethods"],"sources":["../../../../src/transports/blockcypher/blockcypher.ts"],"sourcesContent":["import type { HttpTransport, HttpTransportConfig } from '../http.js'\nimport type { UTXOMethod } from '../types.js'\nimport { utxo } from '../utxo.js'\nimport { blockcypherMethods } from './methods.js'\n\ntype BlockcypherConfig = {\n baseUrl?: string\n apiKey?: string\n} & HttpTransportConfig\n\nexport const blockcypher = (config?: BlockcypherConfig): HttpTransport =>\n utxo(config?.baseUrl || 'https://api.blockcypher.com/v1/btc/main', {\n name: 'Blockcypher API',\n key: 'blockcypher',\n methods: {\n include: Object.keys(blockcypherMethods) as UTXOMethod[],\n },\n ...config,\n })\n"],"mappings":";;;;AAUA,MAAa,eAAe,WAC1BA,wBAAAA,KAAK,QAAQ,WAAW,2CAA2C;CACjE,MAAM;CACN,KAAK;CACL,SAAS,EACP,SAAS,OAAO,KAAKC,uCAAAA,mBAAmB,EACzC;CACD,GAAG;CACJ,CAAC"}
1
+ {"version":3,"file":"blockcypher.js","names":["utxo","blockcypherMethods"],"sources":["../../../../src/transports/blockcypher/blockcypher.ts"],"sourcesContent":["import type { HttpTransport, HttpTransportConfig } from '../http.js'\nimport type { UTXOMethod } from '../types.js'\nimport { utxo } from '../utxo.js'\nimport { blockcypherMethods } from './methods.js'\n\ntype BlockcypherConfig = {\n baseUrl?: string\n apiKey?: string\n} & HttpTransportConfig\n\nexport const blockcypher = (config?: BlockcypherConfig): HttpTransport =>\n utxo(config?.baseUrl || 'https://api.blockcypher.com/v1/btc/main', {\n name: 'Blockcypher API',\n key: 'blockcypher',\n methods: {\n include: Object.keys(blockcypherMethods) as UTXOMethod[],\n },\n ...config,\n })\n"],"mappings":";;;;AAUA,MAAa,eAAe,WAC1BA,wBAAAA,KAAK,QAAQ,WAAW,2CAA2C;CACjE,MAAM;CACN,KAAK;CACL,SAAS,EACP,SAAS,OAAO,KAAKC,uCAAAA,kBAAkB,EACzC;CACA,GAAG;AACL,CAAC"}
@@ -1,5 +1,4 @@
1
1
  import { RpcMethodHandler } from "../types.js";
2
-
3
2
  //#region src/transports/blockcypher/getBalance.d.ts
4
3
  declare const getBalance: RpcMethodHandler<"getBalance">;
5
4
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"getBalance.js","names":["urlWithParams","getRpcErrorCode"],"sources":["../../../../src/transports/blockcypher/getBalance.ts"],"sourcesContent":["import { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type { BlockcypherBalanceResponse } from './blockcypher.types.js'\nimport { getRpcErrorCode } from './utils.js'\n\nexport const getBalance: RpcMethodHandler<'getBalance'> = async (\n client,\n { baseUrl, apiKey },\n { address }\n) => {\n const apiUrl = urlWithParams(`${baseUrl}/addrs/${address}`, {\n token: apiKey,\n })\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as BlockcypherBalanceResponse\n if (response.error) {\n return {\n error: {\n code: getRpcErrorCode(response.error),\n message: response.error,\n },\n }\n }\n return {\n result: BigInt(response.balance),\n }\n}\n"],"mappings":";;;;AAKA,MAAa,aAA6C,OACxD,QACA,EAAE,SAAS,UACX,EAAE,cACC;CACH,MAAM,SAASA,kBAAAA,cAAc,GAAG,QAAQ,SAAS,WAAW,EAC1D,OAAO,QACR,CAAC;CACF,MAAM,WAAY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EAAE,QAAQ,OAAO;EAChC,CAAC;AACF,KAAI,SAAS,MACX,QAAO,EACL,OAAO;EACL,MAAMC,qCAAAA,gBAAgB,SAAS,MAAM;EACrC,SAAS,SAAS;EACnB,EACF;AAEH,QAAO,EACL,QAAQ,OAAO,SAAS,QAAQ,EACjC"}
1
+ {"version":3,"file":"getBalance.js","names":["urlWithParams","getRpcErrorCode"],"sources":["../../../../src/transports/blockcypher/getBalance.ts"],"sourcesContent":["import { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type { BlockcypherBalanceResponse } from './blockcypher.types.js'\nimport { getRpcErrorCode } from './utils.js'\n\nexport const getBalance: RpcMethodHandler<'getBalance'> = async (\n client,\n { baseUrl, apiKey },\n { address }\n) => {\n const apiUrl = urlWithParams(`${baseUrl}/addrs/${address}`, {\n token: apiKey,\n })\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as BlockcypherBalanceResponse\n if (response.error) {\n return {\n error: {\n code: getRpcErrorCode(response.error),\n message: response.error,\n },\n }\n }\n return {\n result: BigInt(response.balance),\n }\n}\n"],"mappings":";;;;AAKA,MAAa,aAA6C,OACxD,QACA,EAAE,SAAS,UACX,EAAE,cACC;CACH,MAAM,SAASA,kBAAAA,cAAc,GAAG,QAAQ,SAAS,WAAW,EAC1D,OAAO,OACT,CAAC;CACD,MAAM,WAAY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EAAE,QAAQ,MAAM;CAChC,CAAC;CACD,IAAI,SAAS,OACX,OAAO,EACL,OAAO;EACL,MAAMC,qCAAAA,gBAAgB,SAAS,KAAK;EACpC,SAAS,SAAS;CACpB,EACF;CAEF,OAAO,EACL,QAAQ,OAAO,SAAS,OAAO,EACjC;AACF"}
@@ -1,5 +1,4 @@
1
1
  import { RpcMethodHandler } from "../types.js";
2
-
3
2
  //#region src/transports/blockcypher/getTransactionFee.d.ts
4
3
  declare const getTransactionFee: RpcMethodHandler<"getTransactionFee">;
5
4
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"getTransactionFee.js","names":["urlWithParams","getRpcErrorCode"],"sources":["../../../../src/transports/blockcypher/getTransactionFee.ts"],"sourcesContent":["import { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type { BlockcypherTransactionReponse } from './blockcypher.types.js'\nimport { getRpcErrorCode } from './utils.js'\n\nexport const getTransactionFee: RpcMethodHandler<'getTransactionFee'> = async (\n client,\n { baseUrl, apiKey },\n { txId }\n) => {\n const apiUrl = urlWithParams(`${baseUrl}/txs/${txId}`, {\n token: apiKey,\n })\n\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as BlockcypherTransactionReponse\n\n if (response.error) {\n return {\n error: { code: getRpcErrorCode(response.error), message: response.error },\n }\n }\n\n return {\n result: BigInt(response.fees),\n }\n}\n"],"mappings":";;;;AAKA,MAAa,oBAA2D,OACtE,QACA,EAAE,SAAS,UACX,EAAE,WACC;CACH,MAAM,SAASA,kBAAAA,cAAc,GAAG,QAAQ,OAAO,QAAQ,EACrD,OAAO,QACR,CAAC;CAEF,MAAM,WAAY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EAAE,QAAQ,OAAO;EAChC,CAAC;AAEF,KAAI,SAAS,MACX,QAAO,EACL,OAAO;EAAE,MAAMC,qCAAAA,gBAAgB,SAAS,MAAM;EAAE,SAAS,SAAS;EAAO,EAC1E;AAGH,QAAO,EACL,QAAQ,OAAO,SAAS,KAAK,EAC9B"}
1
+ {"version":3,"file":"getTransactionFee.js","names":["urlWithParams","getRpcErrorCode"],"sources":["../../../../src/transports/blockcypher/getTransactionFee.ts"],"sourcesContent":["import { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type { BlockcypherTransactionReponse } from './blockcypher.types.js'\nimport { getRpcErrorCode } from './utils.js'\n\nexport const getTransactionFee: RpcMethodHandler<'getTransactionFee'> = async (\n client,\n { baseUrl, apiKey },\n { txId }\n) => {\n const apiUrl = urlWithParams(`${baseUrl}/txs/${txId}`, {\n token: apiKey,\n })\n\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as BlockcypherTransactionReponse\n\n if (response.error) {\n return {\n error: { code: getRpcErrorCode(response.error), message: response.error },\n }\n }\n\n return {\n result: BigInt(response.fees),\n }\n}\n"],"mappings":";;;;AAKA,MAAa,oBAA2D,OACtE,QACA,EAAE,SAAS,UACX,EAAE,WACC;CACH,MAAM,SAASA,kBAAAA,cAAc,GAAG,QAAQ,OAAO,QAAQ,EACrD,OAAO,OACT,CAAC;CAED,MAAM,WAAY,MAAM,OAAO,QAAQ;EACrC,KAAK;EACL,cAAc,EAAE,QAAQ,MAAM;CAChC,CAAC;CAED,IAAI,SAAS,OACX,OAAO,EACL,OAAO;EAAE,MAAMC,qCAAAA,gBAAgB,SAAS,KAAK;EAAG,SAAS,SAAS;CAAM,EAC1E;CAGF,OAAO,EACL,QAAQ,OAAO,SAAS,IAAI,EAC9B;AACF"}
@@ -1,5 +1,4 @@
1
1
  import { RpcMethodHandler } from "../types.js";
2
-
3
2
  //#region src/transports/blockcypher/getUTXOs.d.ts
4
3
  declare const getUTXOs: RpcMethodHandler<"getUTXOs">;
5
4
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"getUTXOs.js","names":["urlWithParams","RpcRequestError","getRpcErrorCode","InsufficientUTXOBalanceError"],"sources":["../../../../src/transports/blockcypher/getUTXOs.ts"],"sourcesContent":["import { RpcRequestError } from '../../errors/request.js'\nimport { InsufficientUTXOBalanceError } from '../../errors/utxo.js'\nimport type { UTXO } from '../../types/transaction.js'\nimport { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type {\n BlockcypherUTXO,\n BlockcypherUTXOsResponse,\n} from './blockcypher.types.js'\nimport { getRpcErrorCode } from './utils.js'\n\nconst blockcypherUTXOTransformer = (utxo: BlockcypherUTXO): UTXO => ({\n blockHeight: utxo.block_height,\n isConfirmed: Boolean(utxo.confirmations),\n confirmations: utxo.confirmations,\n value: utxo.value,\n vout: utxo.tx_output_n,\n txId: utxo.tx_hash,\n scriptHex: utxo.script,\n})\n\nconst MAX_API_LIMIT = 2000\n\nexport const getUTXOs: RpcMethodHandler<'getUTXOs'> = async (\n client,\n { baseUrl, apiKey },\n { address, minValue }\n) => {\n async function* fetchUTXOs() {\n let hasMore = true\n let beforeBlock: number | undefined\n\n while (hasMore) {\n const apiUrl = urlWithParams(`${baseUrl}/addrs/${address}`, {\n token: apiKey,\n unspentOnly: 'true',\n includeScript: 'true',\n before: beforeBlock,\n limit: MAX_API_LIMIT,\n })\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as BlockcypherUTXOsResponse\n\n if (response.error) {\n throw new RpcRequestError({\n url: apiUrl,\n body: {\n method: 'fetchUTXOs',\n params: {\n address,\n minValue,\n },\n },\n error: {\n code: getRpcErrorCode(response.error),\n message: response.error,\n },\n })\n }\n\n if (minValue && minValue > response.final_balance) {\n throw new InsufficientUTXOBalanceError({\n minValue,\n address,\n balance: response.final_balance,\n })\n }\n\n if (!response.txrefs || response.txrefs.length === 0) {\n hasMore = false\n continue\n }\n\n const { hasMore: apiHasMore } = response\n\n hasMore = Boolean(apiHasMore)\n beforeBlock = response.txrefs[response.txrefs.length - 1].block_height\n\n yield response.txrefs\n }\n }\n\n const utxos: UTXO[] = []\n let valueCount = 0\n\n for await (const batch of fetchUTXOs()) {\n const utxoBatch = batch.map(blockcypherUTXOTransformer)\n utxos.push(...utxoBatch)\n\n if (minValue) {\n valueCount += utxoBatch.reduce((sum, utxo) => sum + utxo.value, 0)\n if (valueCount >= minValue) {\n break\n }\n }\n }\n\n return { result: utxos }\n}\n"],"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U;AACZ,iBAAc,UAAU,QAAQ,KAAK,SAAS,MAAM,KAAK,OAAO,EAAE;AAClE,OAAI,cAAc,SAChB;;;AAKN,QAAO,EAAE,QAAQ,OAAO"}
1
+ {"version":3,"file":"getUTXOs.js","names":["urlWithParams","RpcRequestError","getRpcErrorCode","InsufficientUTXOBalanceError"],"sources":["../../../../src/transports/blockcypher/getUTXOs.ts"],"sourcesContent":["import { RpcRequestError } from '../../errors/request.js'\nimport { InsufficientUTXOBalanceError } from '../../errors/utxo.js'\nimport type { UTXO } from '../../types/transaction.js'\nimport { urlWithParams } from '../../utils/url.js'\nimport type { RpcMethodHandler } from '../types.js'\nimport type {\n BlockcypherUTXO,\n BlockcypherUTXOsResponse,\n} from './blockcypher.types.js'\nimport { getRpcErrorCode } from './utils.js'\n\nconst blockcypherUTXOTransformer = (utxo: BlockcypherUTXO): UTXO => ({\n blockHeight: utxo.block_height,\n isConfirmed: Boolean(utxo.confirmations),\n confirmations: utxo.confirmations,\n value: utxo.value,\n vout: utxo.tx_output_n,\n txId: utxo.tx_hash,\n scriptHex: utxo.script,\n})\n\nconst MAX_API_LIMIT = 2000\n\nexport const getUTXOs: RpcMethodHandler<'getUTXOs'> = async (\n client,\n { baseUrl, apiKey },\n { address, minValue }\n) => {\n async function* fetchUTXOs() {\n let hasMore = true\n let beforeBlock: number | undefined\n\n while (hasMore) {\n const apiUrl = urlWithParams(`${baseUrl}/addrs/${address}`, {\n token: apiKey,\n unspentOnly: 'true',\n includeScript: 'true',\n before: beforeBlock,\n limit: MAX_API_LIMIT,\n })\n const response = (await client.request({\n url: apiUrl,\n fetchOptions: { method: 'GET' },\n })) as unknown as BlockcypherUTXOsResponse\n\n if (response.error) {\n throw new RpcRequestError({\n url: apiUrl,\n body: {\n method: 'fetchUTXOs',\n params: {\n address,\n minValue,\n },\n },\n error: {\n code: getRpcErrorCode(response.error),\n message: response.error,\n },\n })\n }\n\n if (minValue && minValue > response.final_balance) {\n throw new InsufficientUTXOBalanceError({\n minValue,\n address,\n balance: response.final_balance,\n })\n }\n\n if (!response.txrefs || response.txrefs.length === 0) {\n hasMore = false\n continue\n }\n\n const { hasMore: apiHasMore } = response\n\n hasMore = Boolean(apiHasMore)\n beforeBlock = response.txrefs[response.txrefs.length - 1].block_height\n\n yield response.txrefs\n }\n }\n\n const utxos: UTXO[] = []\n let valueCount = 0\n\n for await (const batch of fetchUTXOs()) {\n const utxoBatch = batch.map(blockcypherUTXOTransformer)\n utxos.push(...utxoBatch)\n\n if (minValue) {\n valueCount += utxoBatch.reduce((sum, utxo) => sum + utxo.value, 0)\n if (valueCount >= minValue) {\n break\n }\n }\n }\n\n return { result: utxos }\n}\n"],"mappings":";;;;;;AAWA,MAAM,8BAA8B,UAAiC;CACnE,aAAa,KAAK;CAClB,aAAa,QAAQ,KAAK,aAAa;CACvC,eAAe,KAAK;CACpB,OAAO,KAAK;CACZ,MAAM,KAAK;CACX,MAAM,KAAK;CACX,WAAW,KAAK;AAClB;AAEA,MAAM,gBAAgB;AAEtB,MAAa,WAAyC,OACpD,QACA,EAAE,SAAS,UACX,EAAE,SAAS,eACR;CACH,gBAAgB,aAAa;EAC3B,IAAI,UAAU;EACd,IAAI;EAEJ,OAAO,SAAS;GACd,MAAM,SAASA,kBAAAA,cAAc,GAAG,QAAQ,SAAS,WAAW;IAC1D,OAAO;IACP,aAAa;IACb,eAAe;IACf,QAAQ;IACR,OAAO;GACT,CAAC;GACD,MAAM,WAAY,MAAM,OAAO,QAAQ;IACrC,KAAK;IACL,cAAc,EAAE,QAAQ,MAAM;GAChC,CAAC;GAED,IAAI,SAAS,OACX,MAAM,IAAIC,uBAAAA,gBAAgB;IACxB,KAAK;IACL,MAAM;KACJ,QAAQ;KACR,QAAQ;MACN;MACA;KACF;IACF;IACA,OAAO;KACL,MAAMC,qCAAAA,gBAAgB,SAAS,KAAK;KACpC,SAAS,SAAS;IACpB;GACF,CAAC;GAGH,IAAI,YAAY,WAAW,SAAS,eAClC,MAAM,IAAIC,oBAAAA,6BAA6B;IACrC;IACA;IACA,SAAS,SAAS;GACpB,CAAC;GAGH,IAAI,CAAC,SAAS,UAAU,SAAS,OAAO,WAAW,GAAG;IACpD,UAAU;IACV;GACF;GAEA,MAAM,EAAE,SAAS,eAAe;GAEhC,UAAU,QAAQ,UAAU;GAC5B,cAAc,SAAS,OAAO,SAAS,OAAO,SAAS,EAAE,CAAC;GAE1D,MAAM,SAAS;EACjB;CACF;CAEA,MAAM,QAAgB,CAAC;CACvB,IAAI,aAAa;CAEjB,WAAW,MAAM,SAAS,WAAW,GAAG;EACtC,MAAM,YAAY,MAAM,IAAI,0BAA0B;EACtD,MAAM,KAAK,GAAG,SAAS;EAEvB,IAAI,UAAU;GACZ,cAAc,UAAU,QAAQ,KAAK,SAAS,MAAM,KAAK,OAAO,CAAC;GACjE,IAAI,cAAc,UAChB;EAEJ;CACF;CAEA,OAAO,EAAE,QAAQ,MAAM;AACzB"}
@@ -1,5 +1,4 @@
1
1
  import { RpcMethods } from "../types.js";
2
-
3
2
  //#region src/transports/blockcypher/methods.d.ts
4
3
  declare const blockcypherMethods: RpcMethods;
5
4
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"methods.js","names":[],"sources":["../../../../src/transports/blockcypher/methods.ts"],"sourcesContent":["import type { RpcMethods } from '../types.js'\nimport { getBalance } from './getBalance.js'\nimport { getTransactionFee } from './getTransactionFee.js'\nimport { getUTXOs } from './getUTXOs.js'\n\nexport const blockcypherMethods: RpcMethods = {\n getBalance,\n getUTXOs,\n getTransactionFee,\n}\n"],"mappings":";;;;;AAKA,MAAa,qBAAiC;CAC5C,YAAA,0CAAA;CACA,UAAA,wCAAA;CACA,mBAAA,iDAAA;CACD"}
1
+ {"version":3,"file":"methods.js","names":[],"sources":["../../../../src/transports/blockcypher/methods.ts"],"sourcesContent":["import type { RpcMethods } from '../types.js'\nimport { getBalance } from './getBalance.js'\nimport { getTransactionFee } from './getTransactionFee.js'\nimport { getUTXOs } from './getUTXOs.js'\n\nexport const blockcypherMethods: RpcMethods = {\n getBalance,\n getUTXOs,\n getTransactionFee,\n}\n"],"mappings":";;;;;AAKA,MAAa,qBAAiC;CAC5C,YAAA,0CAAA;CACA,UAAA,wCAAA;CACA,mBAAA,iDAAA;AACF"}
@@ -1,5 +1,4 @@
1
1
  import { RpcErrorCode } from "../../errors/rpc.js";
2
-
3
2
  //#region src/transports/blockcypher/utils.d.ts
4
3
  declare function getRpcErrorCode(error: string): RpcErrorCode;
5
4
  //#endregion
@@ -1,9 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_errors_rpc = require("../../errors/rpc.js");
2
+ require("../../errors/rpc.js");
3
3
  //#region src/transports/blockcypher/utils.ts
4
4
  function getRpcErrorCode(error) {
5
- if (error.toLowerCase().startsWith("rate limit exceeded")) return require_errors_rpc.RpcErrorCode.ACCESS_DENIED;
6
- return require_errors_rpc.RpcErrorCode.MISC_ERROR;
5
+ if (error.toLowerCase().startsWith("rate limit exceeded")) return -32002;
6
+ return -1;
7
7
  }
8
8
  //#endregion
9
9
  exports.getRpcErrorCode = getRpcErrorCode;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":["RpcErrorCode"],"sources":["../../../../src/transports/blockcypher/utils.ts"],"sourcesContent":["import { RpcErrorCode } from '../../errors/rpc.js'\n\nexport function getRpcErrorCode(error: string): RpcErrorCode {\n if (error.toLowerCase().startsWith('rate limit exceeded')) {\n return RpcErrorCode.ACCESS_DENIED\n }\n return RpcErrorCode.MISC_ERROR\n}\n"],"mappings":";;;AAEA,SAAgB,gBAAgB,OAA6B;AAC3D,KAAI,MAAM,aAAa,CAAC,WAAW,sBAAsB,CACvD,QAAOA,mBAAAA,aAAa;AAEtB,QAAOA,mBAAAA,aAAa"}
1
+ {"version":3,"file":"utils.js","names":[],"sources":["../../../../src/transports/blockcypher/utils.ts"],"sourcesContent":["import { RpcErrorCode } from '../../errors/rpc.js'\n\nexport function getRpcErrorCode(error: string): RpcErrorCode {\n if (error.toLowerCase().startsWith('rate limit exceeded')) {\n return RpcErrorCode.ACCESS_DENIED\n }\n return RpcErrorCode.MISC_ERROR\n}\n"],"mappings":";;;AAEA,SAAgB,gBAAgB,OAA6B;CAC3D,IAAI,MAAM,YAAY,CAAC,CAAC,WAAW,qBAAqB,GACtD,OAAA;CAEF,OAAA;AACF"}
@@ -1,22 +1,26 @@
1
1
  import { ErrorType } from "../errors/utils.js";
2
2
  import { CreateTransportErrorType, Transport, TransportConfig } from "../types/transport.js";
3
-
4
3
  //#region src/transports/custom.d.ts
5
4
  type BitcoinProvider = {
6
5
  request(...args: any): Promise<any>;
7
6
  };
8
7
  type CustomTransportConfig = {
9
- /** The key of the transport. */key?: TransportConfig["key"] | undefined; /** Methods to include or exclude from executing RPC requests. */
10
- methods?: TransportConfig["methods"] | undefined; /** The name of the transport. */
11
- name?: TransportConfig["name"] | undefined; /** The max number of times to retry. */
12
- retryCount?: TransportConfig["retryCount"] | undefined; /** The base delay (in ms) between retries. */
8
+ /** The key of the transport. */
9
+ key?: TransportConfig["key"] | undefined;
10
+ /** Methods to include or exclude from executing RPC requests. */
11
+ methods?: TransportConfig["methods"] | undefined;
12
+ /** The name of the transport. */
13
+ name?: TransportConfig["name"] | undefined;
14
+ /** The max number of times to retry. */
15
+ retryCount?: TransportConfig["retryCount"] | undefined;
16
+ /** The base delay (in ms) between retries. */
13
17
  retryDelay?: TransportConfig["retryDelay"] | undefined;
14
18
  };
15
19
  type CustomTransport = Transport<"custom", {}, BitcoinProvider["request"]>;
16
20
  type CustomTransportErrorType = CreateTransportErrorType | ErrorType;
17
21
  /**
18
- * @description Creates a custom transport given an EIP-1193 compliant `request` attribute.
19
- */
22
+ * @description Creates a custom transport given an EIP-1193 compliant `request` attribute.
23
+ */
20
24
  declare function custom<provider extends BitcoinProvider>(provider: provider, config?: CustomTransportConfig): CustomTransport;
21
25
  //#endregion
22
26
  export { CustomTransport, CustomTransportConfig, CustomTransportErrorType, custom };
@@ -1 +1 @@
1
- {"version":3,"file":"custom.js","names":["createTransport"],"sources":["../../../src/transports/custom.ts"],"sourcesContent":["import type { ErrorType } from '../errors/utils.js'\nimport { createTransport } from '../factories/createTransport.js'\nimport type {\n CreateTransportErrorType,\n Transport,\n TransportConfig,\n} from '../types/transport.js'\n\ntype BitcoinProvider = { request(...args: any): Promise<any> }\n\nexport type CustomTransportConfig = {\n /** The key of the transport. */\n key?: TransportConfig['key'] | undefined\n /** Methods to include or exclude from executing RPC requests. */\n methods?: TransportConfig['methods'] | undefined\n /** The name of the transport. */\n name?: TransportConfig['name'] | undefined\n /** The max number of times to retry. */\n retryCount?: TransportConfig['retryCount'] | undefined\n /** The base delay (in ms) between retries. */\n retryDelay?: TransportConfig['retryDelay'] | undefined\n}\n\nexport type CustomTransport = Transport<\n 'custom',\n // biome-ignore lint/complexity/noBannedTypes: part of the types\n {},\n BitcoinProvider['request']\n>\n\nexport type CustomTransportErrorType = CreateTransportErrorType | ErrorType\n\n/**\n * @description Creates a custom transport given an EIP-1193 compliant `request` attribute.\n */\nexport function custom<provider extends BitcoinProvider>(\n provider: provider,\n config: CustomTransportConfig = {}\n): CustomTransport {\n const {\n key = 'custom',\n methods,\n name = 'Custom Provider',\n retryDelay,\n } = config\n return ({ retryCount: defaultRetryCount }) =>\n createTransport({\n key,\n methods,\n name,\n request: provider.request.bind(provider),\n retryCount: config.retryCount ?? defaultRetryCount,\n retryDelay,\n type: 'custom',\n })\n}\n"],"mappings":";;;;;;AAmCA,SAAgB,OACd,UACA,SAAgC,EAAE,EACjB;CACjB,MAAM,EACJ,MAAM,UACN,SACA,OAAO,mBACP,eACE;AACJ,SAAQ,EAAE,YAAY,wBACpBA,kCAAAA,gBAAgB;EACd;EACA;EACA;EACA,SAAS,SAAS,QAAQ,KAAK,SAAS;EACxC,YAAY,OAAO,cAAc;EACjC;EACA,MAAM;EACP,CAAC"}
1
+ {"version":3,"file":"custom.js","names":["createTransport"],"sources":["../../../src/transports/custom.ts"],"sourcesContent":["import type { ErrorType } from '../errors/utils.js'\nimport { createTransport } from '../factories/createTransport.js'\nimport type {\n CreateTransportErrorType,\n Transport,\n TransportConfig,\n} from '../types/transport.js'\n\ntype BitcoinProvider = { request(...args: any): Promise<any> }\n\nexport type CustomTransportConfig = {\n /** The key of the transport. */\n key?: TransportConfig['key'] | undefined\n /** Methods to include or exclude from executing RPC requests. */\n methods?: TransportConfig['methods'] | undefined\n /** The name of the transport. */\n name?: TransportConfig['name'] | undefined\n /** The max number of times to retry. */\n retryCount?: TransportConfig['retryCount'] | undefined\n /** The base delay (in ms) between retries. */\n retryDelay?: TransportConfig['retryDelay'] | undefined\n}\n\nexport type CustomTransport = Transport<\n 'custom',\n // biome-ignore lint/complexity/noBannedTypes: part of the types\n {},\n BitcoinProvider['request']\n>\n\nexport type CustomTransportErrorType = CreateTransportErrorType | ErrorType\n\n/**\n * @description Creates a custom transport given an EIP-1193 compliant `request` attribute.\n */\nexport function custom<provider extends BitcoinProvider>(\n provider: provider,\n config: CustomTransportConfig = {}\n): CustomTransport {\n const {\n key = 'custom',\n methods,\n name = 'Custom Provider',\n retryDelay,\n } = config\n return ({ retryCount: defaultRetryCount }) =>\n createTransport({\n key,\n methods,\n name,\n request: provider.request.bind(provider),\n retryCount: config.retryCount ?? defaultRetryCount,\n retryDelay,\n type: 'custom',\n })\n}\n"],"mappings":";;;;;;AAmCA,SAAgB,OACd,UACA,SAAgC,CAAC,GAChB;CACjB,MAAM,EACJ,MAAM,UACN,SACA,OAAO,mBACP,eACE;CACJ,QAAQ,EAAE,YAAY,wBACpBA,kCAAAA,gBAAgB;EACd;EACA;EACA;EACA,SAAS,SAAS,QAAQ,KAAK,QAAQ;EACvC,YAAY,OAAO,cAAc;EACjC;EACA,MAAM;CACR,CAAC;AACL"}
@@ -1,7 +1,6 @@
1
1
  import { Chain } from "../types/chain.js";
2
2
  import { ErrorType } from "../errors/utils.js";
3
3
  import { CreateTransportErrorType, Transport, TransportConfig } from "../types/transport.js";
4
-
5
4
  //#region src/transports/fallback.d.ts
6
5
  type OnResponseFn = (args: {
7
6
  method: string;
@@ -18,68 +17,65 @@ type OnResponseFn = (args: {
18
17
  })) => void;
19
18
  type RankOptions = {
20
19
  /**
21
- * The polling interval (in ms) at which the ranker should ping the RPC URL.
22
- * @default client.pollingInterval
23
- */
20
+ * The polling interval (in ms) at which the ranker should ping the RPC URL.
21
+ * @default client.pollingInterval
22
+ */
24
23
  interval?: number | undefined;
25
24
  /**
26
- * Ping method to determine latency.
27
- */
25
+ * Ping method to determine latency.
26
+ */
28
27
  ping?: (parameters: {
29
28
  transport: ReturnType<Transport>;
30
29
  }) => Promise<unknown> | undefined;
31
30
  /**
32
- * The number of previous samples to perform ranking on.
33
- * @default 10
34
- */
31
+ * The number of previous samples to perform ranking on.
32
+ * @default 10
33
+ */
35
34
  sampleCount?: number | undefined;
36
35
  /**
37
- * Timeout when sampling transports.
38
- * @default 1_000
39
- */
36
+ * Timeout when sampling transports.
37
+ * @default 1_000
38
+ */
40
39
  timeout?: number | undefined;
41
40
  /**
42
- * Weights to apply to the scores. Weight values are proportional.
43
- */
41
+ * Weights to apply to the scores. Weight values are proportional.
42
+ */
44
43
  weights?: {
45
44
  /**
46
- * The weight to apply to the latency score.
47
- * @default 0.3
48
- */
45
+ * The weight to apply to the latency score.
46
+ * @default 0.3
47
+ */
49
48
  latency?: number | undefined;
50
49
  /**
51
- * The weight to apply to the stability score.
52
- * @default 0.7
53
- */
50
+ * The weight to apply to the stability score.
51
+ * @default 0.7
52
+ */
54
53
  stability?: number | undefined;
55
54
  } | undefined;
56
55
  };
57
56
  type FallbackTransportConfig = {
58
- /** The key of the Fallback transport. */key?: TransportConfig["key"] | undefined; /** The name of the Fallback transport. */
59
- name?: TransportConfig["name"] | undefined; /** Toggle to enable ranking, or rank options. */
60
- rank?: boolean | RankOptions | undefined; /** The max number of times to retry. */
61
- retryCount?: TransportConfig["retryCount"] | undefined; /** The base delay (in ms) between retries. */
62
- retryDelay?: TransportConfig["retryDelay"] | undefined; /** Callback on whether an error should throw or try the next transport in the fallback. */
57
+ /** The key of the Fallback transport. */
58
+ key?: TransportConfig["key"] | undefined;
59
+ /** The name of the Fallback transport. */
60
+ name?: TransportConfig["name"] | undefined;
61
+ /** Toggle to enable ranking, or rank options. */
62
+ rank?: boolean | RankOptions | undefined;
63
+ /** The max number of times to retry. */
64
+ retryCount?: TransportConfig["retryCount"] | undefined;
65
+ /** The base delay (in ms) between retries. */
66
+ retryDelay?: TransportConfig["retryDelay"] | undefined;
67
+ /** Callback on whether an error should throw or try the next transport in the fallback. */
63
68
  shouldThrow?: (error: Error) => boolean | undefined;
64
69
  };
65
70
  type FallbackTransport<transports extends readonly Transport[] = readonly Transport[]> = Transport<"fallback", {
66
71
  onResponse: (fn: OnResponseFn) => void;
67
- transports: { [key in keyof transports]: ReturnType<transports[key]> };
72
+ transports: { [key in keyof transports]: ReturnType<transports[key]>; };
68
73
  }>;
69
74
  type FallbackTransportErrorType = CreateTransportErrorType | ErrorType;
70
75
  declare function fallback<const transports extends readonly Transport[]>(transports_: transports, config?: FallbackTransportConfig): FallbackTransport<transports>;
71
76
  declare function shouldThrow(error: Error): boolean;
72
77
  /** @internal */
73
- declare function rankTransports({
74
- chain,
75
- interval,
76
- onTransports,
77
- ping,
78
- sampleCount,
79
- timeout,
80
- transports,
81
- weights
82
- }: {
78
+ declare function rankTransports({ chain, interval, onTransports, ping, sampleCount, timeout, transports, weights }: {
83
79
  chain?: Chain | undefined;
84
80
  interval: RankOptions["interval"];
85
81
  onTransports: (transports: readonly Transport[]) => void;
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_utils_wait = require("../utils/wait.js");
3
- const require_errors_rpc = require("../errors/rpc.js");
3
+ require("../errors/rpc.js");
4
4
  const require_errors_transport = require("../errors/transport.js");
5
5
  const require_errors_utxo = require("../errors/utxo.js");
6
6
  const require_factories_createTransport = require("../factories/createTransport.js");
@@ -108,7 +108,7 @@ function fallback(transports_, config = {}) {
108
108
  function shouldThrow(error) {
109
109
  if (error instanceof require_errors_utxo.InsufficientUTXOBalanceError) return true;
110
110
  if ("code" in error && typeof error.code === "number") {
111
- if (error.code === require_errors_rpc.RpcErrorCode.INTERNAL_ERROR || error.code === require_errors_rpc.RpcErrorCode.USER_REJECTION || error.code === 5e3) return true;
111
+ if (error.code === -32603 || error.code === -32e3 || error.code === 5e3) return true;
112
112
  }
113
113
  return false;
114
114
  }
@@ -1 +1 @@
1
- {"version":3,"file":"fallback.js","names":["createTransport","TransportMethodNotSupportedError","AllTransportsFailedError","InsufficientUTXOBalanceError","RpcErrorCode","wait"],"sources":["../../../src/transports/fallback.ts"],"sourcesContent":["import { RpcErrorCode } from '../errors/rpc.js'\nimport {\n AllTransportsFailedError,\n TransportMethodNotSupportedError,\n} from '../errors/transport.js'\nimport type { ErrorType } from '../errors/utils.js'\nimport { InsufficientUTXOBalanceError } from '../errors/utxo.js'\nimport { createTransport } from '../factories/createTransport.js'\nimport type { Chain } from '../types/chain.js'\nimport type {\n CreateTransportErrorType,\n Transport,\n TransportConfig,\n} from '../types/transport.js'\nimport { wait } from '../utils/wait.js'\n\n// TODO: Narrow `method` & `params` types.\nexport type OnResponseFn = (\n args: {\n method: string\n params: unknown[]\n transport: ReturnType<Transport>\n } & (\n | {\n error?: undefined\n response: unknown\n status: 'success'\n }\n | {\n error: Error\n response?: undefined\n status: 'error'\n }\n )\n) => void\n\ntype RankOptions = {\n /**\n * The polling interval (in ms) at which the ranker should ping the RPC URL.\n * @default client.pollingInterval\n */\n interval?: number | undefined\n /**\n * Ping method to determine latency.\n */\n ping?: (parameters: {\n transport: ReturnType<Transport>\n }) => Promise<unknown> | undefined\n /**\n * The number of previous samples to perform ranking on.\n * @default 10\n */\n sampleCount?: number | undefined\n /**\n * Timeout when sampling transports.\n * @default 1_000\n */\n timeout?: number | undefined\n /**\n * Weights to apply to the scores. Weight values are proportional.\n */\n weights?:\n | {\n /**\n * The weight to apply to the latency score.\n * @default 0.3\n */\n latency?: number | undefined\n /**\n * The weight to apply to the stability score.\n * @default 0.7\n */\n stability?: number | undefined\n }\n | undefined\n}\n\nexport type FallbackTransportConfig = {\n /** The key of the Fallback transport. */\n key?: TransportConfig['key'] | undefined\n /** The name of the Fallback transport. */\n name?: TransportConfig['name'] | undefined\n /** Toggle to enable ranking, or rank options. */\n rank?: boolean | RankOptions | undefined\n /** The max number of times to retry. */\n retryCount?: TransportConfig['retryCount'] | undefined\n /** The base delay (in ms) between retries. */\n retryDelay?: TransportConfig['retryDelay'] | undefined\n /** Callback on whether an error should throw or try the next transport in the fallback. */\n shouldThrow?: (error: Error) => boolean | undefined\n}\n\nexport type FallbackTransport<\n transports extends readonly Transport[] = readonly Transport[],\n> = Transport<\n 'fallback',\n {\n onResponse: (fn: OnResponseFn) => void\n transports: {\n [key in keyof transports]: ReturnType<transports[key]>\n }\n }\n>\n\nexport type FallbackTransportErrorType = CreateTransportErrorType | ErrorType\n\nexport function fallback<const transports extends readonly Transport[]>(\n transports_: transports,\n config: FallbackTransportConfig = {}\n): FallbackTransport<transports> {\n const {\n key = 'fallback',\n name = 'Fallback',\n rank = false,\n shouldThrow: shouldThrow_ = shouldThrow,\n retryCount,\n retryDelay,\n } = config\n return (({ chain, pollingInterval = 4_000, timeout, ...rest }) => {\n let transports = transports_\n\n let onResponse: OnResponseFn = () => {}\n\n const transport = createTransport(\n {\n key,\n name,\n async request({ method, params }) {\n // Filter transports to only those that support the requested method\n const supportedTransports = transports.reduce<\n ReturnType<Transport>[]\n >((supportedTransports, transport) => {\n const instance = transport({\n ...rest,\n chain,\n retryCount: 0,\n timeout,\n })\n const { include, exclude } = instance.config.methods || {}\n if (include) {\n if (include.includes(method)) {\n supportedTransports.push(instance)\n }\n return supportedTransports\n }\n if (exclude) {\n if (!exclude.includes(method)) {\n supportedTransports.push(instance)\n }\n return supportedTransports\n }\n supportedTransports.push(instance)\n return supportedTransports\n }, [])\n\n if (!supportedTransports.length) {\n throw new TransportMethodNotSupportedError({ method })\n }\n\n const collectedErrors: Array<{\n transport: string\n error: Error\n attempt: number\n }> = []\n\n const fetch = async (i = 0): Promise<any> => {\n const transport = supportedTransports[i]\n try {\n const response = await transport.request({\n method,\n params,\n })\n\n onResponse({\n method,\n params: params as unknown[],\n response,\n transport,\n status: 'success',\n })\n\n return response\n } catch (err) {\n onResponse({\n error: err as Error,\n method,\n params: params as unknown[],\n transport,\n status: 'error',\n })\n\n if (shouldThrow_(err as Error)) {\n throw err\n }\n\n collectedErrors.push({\n transport: transport.config.name,\n error: err as Error,\n attempt: i + 1,\n })\n\n // If we've reached the end of the fallbacks, throw all collected errors.\n if (i === supportedTransports.length - 1) {\n throw new AllTransportsFailedError({\n method,\n params,\n errors: collectedErrors,\n totalAttempts: i + 1,\n })\n }\n\n // Otherwise, try the next fallback.\n return fetch(i + 1)\n }\n }\n return fetch()\n },\n retryCount,\n retryDelay,\n type: 'fallback',\n },\n {\n onResponse: (fn: OnResponseFn) => {\n onResponse = fn\n },\n transports: transports.map((fn) => fn({ chain, retryCount: 0 })),\n }\n )\n\n if (rank) {\n const rankOptions = (typeof rank === 'object' ? rank : {}) as RankOptions\n rankTransports({\n chain,\n interval: rankOptions.interval ?? pollingInterval,\n onTransports: (transports_) => {\n transports = transports_ as transports\n },\n ping: rankOptions.ping,\n sampleCount: rankOptions.sampleCount,\n timeout: rankOptions.timeout,\n transports,\n weights: rankOptions.weights,\n })\n }\n return transport\n }) as FallbackTransport<transports>\n}\n\nexport function shouldThrow(error: Error): boolean {\n if (error instanceof InsufficientUTXOBalanceError) {\n return true\n }\n\n if ('code' in error && typeof error.code === 'number') {\n if (\n error.code === RpcErrorCode.INTERNAL_ERROR ||\n error.code === RpcErrorCode.USER_REJECTION ||\n error.code === 5000 // CAIP UserRejectedRequestError\n ) {\n return true\n }\n }\n\n return false\n}\n\n/** @internal */\nexport function rankTransports({\n chain,\n interval = 4_000,\n onTransports,\n ping,\n sampleCount = 10,\n timeout = 1_000,\n transports,\n weights = {},\n}: {\n chain?: Chain | undefined\n interval: RankOptions['interval']\n onTransports: (transports: readonly Transport[]) => void\n ping?: RankOptions['ping'] | undefined\n sampleCount?: RankOptions['sampleCount'] | undefined\n timeout?: RankOptions['timeout'] | undefined\n transports: readonly Transport[]\n weights?: RankOptions['weights'] | undefined\n}): void {\n const { stability: stabilityWeight = 0.7, latency: latencyWeight = 0.3 } =\n weights\n\n type SampleData = { latency: number; success: number }\n type Sample = SampleData[]\n const samples: Sample[] = []\n\n const rankTransports_ = async () => {\n // 1. Take a sample from each Transport.\n const sample: Sample = await Promise.all(\n transports.map(async (transport) => {\n const transport_ = transport({ chain, retryCount: 0, timeout })\n\n const start = Date.now()\n let end: number\n let success: number\n try {\n await (ping\n ? ping({ transport: transport_ })\n : transport_.request({\n method: 'net_listening',\n params: undefined,\n }))\n success = 1\n } catch {\n success = 0\n } finally {\n end = Date.now()\n }\n const latency = end - start\n return { latency, success }\n })\n )\n\n // 2. Store the sample. If we have more than `sampleCount` samples, remove\n // the oldest sample.\n samples.push(sample)\n if (samples.length > sampleCount) {\n samples.shift()\n }\n\n // 3. Calculate the max latency from samples.\n const maxLatency = Math.max(\n ...samples.map((sample) =>\n Math.max(...sample.map(({ latency }) => latency))\n )\n )\n\n // 4. Calculate the score for each Transport.\n const scores = transports\n .map((_, i) => {\n const latencies = samples.map((sample) => sample[i].latency)\n const meanLatency =\n latencies.reduce((acc, latency) => acc + latency, 0) /\n latencies.length\n const latencyScore = 1 - meanLatency / maxLatency\n\n const successes = samples.map((sample) => sample[i].success)\n const stabilityScore =\n successes.reduce((acc, success) => acc + success, 0) /\n successes.length\n\n if (stabilityScore === 0) {\n return [0, i]\n }\n return [\n latencyWeight * latencyScore + stabilityWeight * stabilityScore,\n i,\n ]\n })\n .sort((a, b) => b[0] - a[0])\n\n // 5. Sort the Transports by score.\n onTransports(scores.map(([, i]) => transports[i]))\n\n // 6. Wait, and then rank again.\n await wait(interval)\n rankTransports_()\n }\n rankTransports_()\n}\n"],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YAAY,CAAC,GAC/B,WAAW,QAAQ;KACjB,QAAQ;KACR,QAAQ,KAAA;KACT,CAAC;AACN,cAAU;WACJ;AACN,cAAU;aACF;AACR,UAAM,KAAK,KAAK;;AAGlB,UAAO;IAAE,SADO,MAAM;IACJ;IAAS;IAC3B,CACH;AAID,UAAQ,KAAK,OAAO;AACpB,MAAI,QAAQ,SAAS,YACnB,SAAQ,OAAO;EAIjB,MAAM,aAAa,KAAK,IACtB,GAAG,QAAQ,KAAK,WACd,KAAK,IAAI,GAAG,OAAO,KAAK,EAAE,cAAc,QAAQ,CAAC,CAClD,CACF;AA2BD,eAxBe,WACZ,KAAK,GAAG,MAAM;GACb,MAAM,YAAY,QAAQ,KAAK,WAAW,OAAO,GAAG,QAAQ;GAI5D,MAAM,eAAe,IAFnB,UAAU,QAAQ,KAAK,YAAY,MAAM,SAAS,EAAE,GACpD,UAAU,SAC2B;GAEvC,MAAM,YAAY,QAAQ,KAAK,WAAW,OAAO,GAAG,QAAQ;GAC5D,MAAM,iBACJ,UAAU,QAAQ,KAAK,YAAY,MAAM,SAAS,EAAE,GACpD,UAAU;AAEZ,OAAI,mBAAmB,EACrB,QAAO,CAAC,GAAG,EAAE;AAEf,UAAO,CACL,gBAAgB,eAAe,kBAAkB,gBACjD,EACD;IACD,CACD,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,GAAG,CAGV,KAAK,GAAG,OAAO,WAAW,GAAG,CAAC;AAGlD,QAAMC,mBAAAA,KAAK,SAAS;AACpB,mBAAiB;;AAEnB,kBAAiB"}
1
+ {"version":3,"file":"fallback.js","names":["createTransport","TransportMethodNotSupportedError","AllTransportsFailedError","InsufficientUTXOBalanceError","wait"],"sources":["../../../src/transports/fallback.ts"],"sourcesContent":["import { RpcErrorCode } from '../errors/rpc.js'\nimport {\n AllTransportsFailedError,\n TransportMethodNotSupportedError,\n} from '../errors/transport.js'\nimport type { ErrorType } from '../errors/utils.js'\nimport { InsufficientUTXOBalanceError } from '../errors/utxo.js'\nimport { createTransport } from '../factories/createTransport.js'\nimport type { Chain } from '../types/chain.js'\nimport type {\n CreateTransportErrorType,\n Transport,\n TransportConfig,\n} from '../types/transport.js'\nimport { wait } from '../utils/wait.js'\n\n// TODO: Narrow `method` & `params` types.\nexport type OnResponseFn = (\n args: {\n method: string\n params: unknown[]\n transport: ReturnType<Transport>\n } & (\n | {\n error?: undefined\n response: unknown\n status: 'success'\n }\n | {\n error: Error\n response?: undefined\n status: 'error'\n }\n )\n) => void\n\ntype RankOptions = {\n /**\n * The polling interval (in ms) at which the ranker should ping the RPC URL.\n * @default client.pollingInterval\n */\n interval?: number | undefined\n /**\n * Ping method to determine latency.\n */\n ping?: (parameters: {\n transport: ReturnType<Transport>\n }) => Promise<unknown> | undefined\n /**\n * The number of previous samples to perform ranking on.\n * @default 10\n */\n sampleCount?: number | undefined\n /**\n * Timeout when sampling transports.\n * @default 1_000\n */\n timeout?: number | undefined\n /**\n * Weights to apply to the scores. Weight values are proportional.\n */\n weights?:\n | {\n /**\n * The weight to apply to the latency score.\n * @default 0.3\n */\n latency?: number | undefined\n /**\n * The weight to apply to the stability score.\n * @default 0.7\n */\n stability?: number | undefined\n }\n | undefined\n}\n\nexport type FallbackTransportConfig = {\n /** The key of the Fallback transport. */\n key?: TransportConfig['key'] | undefined\n /** The name of the Fallback transport. */\n name?: TransportConfig['name'] | undefined\n /** Toggle to enable ranking, or rank options. */\n rank?: boolean | RankOptions | undefined\n /** The max number of times to retry. */\n retryCount?: TransportConfig['retryCount'] | undefined\n /** The base delay (in ms) between retries. */\n retryDelay?: TransportConfig['retryDelay'] | undefined\n /** Callback on whether an error should throw or try the next transport in the fallback. */\n shouldThrow?: (error: Error) => boolean | undefined\n}\n\nexport type FallbackTransport<\n transports extends readonly Transport[] = readonly Transport[],\n> = Transport<\n 'fallback',\n {\n onResponse: (fn: OnResponseFn) => void\n transports: {\n [key in keyof transports]: ReturnType<transports[key]>\n }\n }\n>\n\nexport type FallbackTransportErrorType = CreateTransportErrorType | ErrorType\n\nexport function fallback<const transports extends readonly Transport[]>(\n transports_: transports,\n config: FallbackTransportConfig = {}\n): FallbackTransport<transports> {\n const {\n key = 'fallback',\n name = 'Fallback',\n rank = false,\n shouldThrow: shouldThrow_ = shouldThrow,\n retryCount,\n retryDelay,\n } = config\n return (({ chain, pollingInterval = 4_000, timeout, ...rest }) => {\n let transports = transports_\n\n let onResponse: OnResponseFn = () => {}\n\n const transport = createTransport(\n {\n key,\n name,\n async request({ method, params }) {\n // Filter transports to only those that support the requested method\n const supportedTransports = transports.reduce<\n ReturnType<Transport>[]\n >((supportedTransports, transport) => {\n const instance = transport({\n ...rest,\n chain,\n retryCount: 0,\n timeout,\n })\n const { include, exclude } = instance.config.methods || {}\n if (include) {\n if (include.includes(method)) {\n supportedTransports.push(instance)\n }\n return supportedTransports\n }\n if (exclude) {\n if (!exclude.includes(method)) {\n supportedTransports.push(instance)\n }\n return supportedTransports\n }\n supportedTransports.push(instance)\n return supportedTransports\n }, [])\n\n if (!supportedTransports.length) {\n throw new TransportMethodNotSupportedError({ method })\n }\n\n const collectedErrors: Array<{\n transport: string\n error: Error\n attempt: number\n }> = []\n\n const fetch = async (i = 0): Promise<any> => {\n const transport = supportedTransports[i]\n try {\n const response = await transport.request({\n method,\n params,\n })\n\n onResponse({\n method,\n params: params as unknown[],\n response,\n transport,\n status: 'success',\n })\n\n return response\n } catch (err) {\n onResponse({\n error: err as Error,\n method,\n params: params as unknown[],\n transport,\n status: 'error',\n })\n\n if (shouldThrow_(err as Error)) {\n throw err\n }\n\n collectedErrors.push({\n transport: transport.config.name,\n error: err as Error,\n attempt: i + 1,\n })\n\n // If we've reached the end of the fallbacks, throw all collected errors.\n if (i === supportedTransports.length - 1) {\n throw new AllTransportsFailedError({\n method,\n params,\n errors: collectedErrors,\n totalAttempts: i + 1,\n })\n }\n\n // Otherwise, try the next fallback.\n return fetch(i + 1)\n }\n }\n return fetch()\n },\n retryCount,\n retryDelay,\n type: 'fallback',\n },\n {\n onResponse: (fn: OnResponseFn) => {\n onResponse = fn\n },\n transports: transports.map((fn) => fn({ chain, retryCount: 0 })),\n }\n )\n\n if (rank) {\n const rankOptions = (typeof rank === 'object' ? rank : {}) as RankOptions\n rankTransports({\n chain,\n interval: rankOptions.interval ?? pollingInterval,\n onTransports: (transports_) => {\n transports = transports_ as transports\n },\n ping: rankOptions.ping,\n sampleCount: rankOptions.sampleCount,\n timeout: rankOptions.timeout,\n transports,\n weights: rankOptions.weights,\n })\n }\n return transport\n }) as FallbackTransport<transports>\n}\n\nexport function shouldThrow(error: Error): boolean {\n if (error instanceof InsufficientUTXOBalanceError) {\n return true\n }\n\n if ('code' in error && typeof error.code === 'number') {\n if (\n error.code === RpcErrorCode.INTERNAL_ERROR ||\n error.code === RpcErrorCode.USER_REJECTION ||\n error.code === 5000 // CAIP UserRejectedRequestError\n ) {\n return true\n }\n }\n\n return false\n}\n\n/** @internal */\nexport function rankTransports({\n chain,\n interval = 4_000,\n onTransports,\n ping,\n sampleCount = 10,\n timeout = 1_000,\n transports,\n weights = {},\n}: {\n chain?: Chain | undefined\n interval: RankOptions['interval']\n onTransports: (transports: readonly Transport[]) => void\n ping?: RankOptions['ping'] | undefined\n sampleCount?: RankOptions['sampleCount'] | undefined\n timeout?: RankOptions['timeout'] | undefined\n transports: readonly Transport[]\n weights?: RankOptions['weights'] | undefined\n}): void {\n const { stability: stabilityWeight = 0.7, latency: latencyWeight = 0.3 } =\n weights\n\n type SampleData = { latency: number; success: number }\n type Sample = SampleData[]\n const samples: Sample[] = []\n\n const rankTransports_ = async () => {\n // 1. Take a sample from each Transport.\n const sample: Sample = await Promise.all(\n transports.map(async (transport) => {\n const transport_ = transport({ chain, retryCount: 0, timeout })\n\n const start = Date.now()\n let end: number\n let success: number\n try {\n await (ping\n ? ping({ transport: transport_ })\n : transport_.request({\n method: 'net_listening',\n params: undefined,\n }))\n success = 1\n } catch {\n success = 0\n } finally {\n end = Date.now()\n }\n const latency = end - start\n return { latency, success }\n })\n )\n\n // 2. Store the sample. If we have more than `sampleCount` samples, remove\n // the oldest sample.\n samples.push(sample)\n if (samples.length > sampleCount) {\n samples.shift()\n }\n\n // 3. Calculate the max latency from samples.\n const maxLatency = Math.max(\n ...samples.map((sample) =>\n Math.max(...sample.map(({ latency }) => latency))\n )\n )\n\n // 4. Calculate the score for each Transport.\n const scores = transports\n .map((_, i) => {\n const latencies = samples.map((sample) => sample[i].latency)\n const meanLatency =\n latencies.reduce((acc, latency) => acc + latency, 0) /\n latencies.length\n const latencyScore = 1 - meanLatency / maxLatency\n\n const successes = samples.map((sample) => sample[i].success)\n const stabilityScore =\n successes.reduce((acc, success) => acc + success, 0) /\n successes.length\n\n if (stabilityScore === 0) {\n return [0, i]\n }\n return [\n latencyWeight * latencyScore + stabilityWeight * stabilityScore,\n i,\n ]\n })\n .sort((a, b) => b[0] - a[0])\n\n // 5. Sort the Transports by score.\n onTransports(scores.map(([, i]) => transports[i]))\n\n // 6. Wait, and then rank again.\n await wait(interval)\n rankTransports_()\n }\n rankTransports_()\n}\n"],"mappings":";;;;;;;AA0GA,SAAgB,SACd,aACA,SAAkC,CAAC,GACJ;CAC/B,MAAM,EACJ,MAAM,YACN,OAAO,YACP,OAAO,OACP,aAAa,eAAe,aAC5B,YACA,eACE;CACJ,SAAS,EAAE,OAAO,kBAAkB,KAAO,SAAS,GAAG,WAAW;EAChE,IAAI,aAAa;EAEjB,IAAI,mBAAiC,CAAC;EAEtC,MAAM,YAAYA,kCAAAA,gBAChB;GACE;GACA;GACA,MAAM,QAAQ,EAAE,QAAQ,UAAU;IAEhC,MAAM,sBAAsB,WAAW,QAEpC,qBAAqB,cAAc;KACpC,MAAM,WAAW,UAAU;MACzB,GAAG;MACH;MACA,YAAY;MACZ;KACF,CAAC;KACD,MAAM,EAAE,SAAS,YAAY,SAAS,OAAO,WAAW,CAAC;KACzD,IAAI,SAAS;MACX,IAAI,QAAQ,SAAS,MAAM,GACzB,oBAAoB,KAAK,QAAQ;MAEnC,OAAO;K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nD,UAAU,SAC2B;GAEvC,MAAM,YAAY,QAAQ,KAAK,WAAW,OAAO,EAAE,CAAC,OAAO;GAC3D,MAAM,iBACJ,UAAU,QAAQ,KAAK,YAAY,MAAM,SAAS,CAAC,IACnD,UAAU;GAEZ,IAAI,mBAAmB,GACrB,OAAO,CAAC,GAAG,CAAC;GAEd,OAAO,CACL,gBAAgB,eAAe,kBAAkB,gBACjD,CACF;EACF,CAAC,CAAC,CACD,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,EAGT,CAAC,CAAC,KAAK,GAAG,OAAO,WAAW,EAAE,CAAC;EAGjD,MAAMC,mBAAAA,KAAK,QAAQ;EACnB,gBAAgB;CAClB;CACA,gBAAgB;AAClB"}
@@ -1,6 +1,5 @@
1
1
  import { RpcResponse } from "../types/rpc.js";
2
2
  import { MaybePromise } from "../types/utils.js";
3
-
4
3
  //#region src/transports/getHttpRpcClient.d.ts
5
4
  type RpcRequest = {
6
5
  jsonrpc?: "2.0";
@@ -10,19 +9,28 @@ type RpcRequest = {
10
9
  };
11
10
  type HttpRequestReturnType<body extends RpcRequest | RpcRequest[] = RpcRequest> = body extends RpcRequest[] ? RpcResponse[] : RpcResponse;
12
11
  type HttpRpcClientOptions = {
13
- /** Request configuration to pass to `fetch`. */fetchOptions?: Omit<RequestInit, "body"> | undefined; /** A callback to handle the request. */
12
+ /** Request configuration to pass to `fetch`. */
13
+ fetchOptions?: Omit<RequestInit, "body"> | undefined;
14
+ /** A callback to handle the request. */
14
15
  onRequest?: ((request: Request, init: RequestInit) => MaybePromise<void | undefined | (RequestInit & {
15
16
  url?: string | undefined;
16
- })>) | undefined; /** A callback to handle the response. */
17
- onResponse?: ((response: Response) => Promise<void> | void) | undefined; /** The timeout (in ms) for the request. */
17
+ })>) | undefined;
18
+ /** A callback to handle the response. */
19
+ onResponse?: ((response: Response) => Promise<void> | void) | undefined;
20
+ /** The timeout (in ms) for the request. */
18
21
  timeout?: number | undefined;
19
22
  };
20
23
  type HttpRequestParameters<body extends RpcRequest | RpcRequest[] = RpcRequest> = {
21
- url?: string; /** The RPC request body. */
22
- body?: body; /** Request configuration to pass to `fetch`. */
23
- fetchOptions?: HttpRpcClientOptions["fetchOptions"] | undefined; /** A callback to handle the response. */
24
- onRequest?: ((request: Request) => Promise<void> | void) | undefined; /** A callback to handle the response. */
25
- onResponse?: ((response: Response) => Promise<void> | void) | undefined; /** The timeout (in ms) for the request. */
24
+ url?: string;
25
+ /** The RPC request body. */
26
+ body?: body;
27
+ /** Request configuration to pass to `fetch`. */
28
+ fetchOptions?: HttpRpcClientOptions["fetchOptions"] | undefined;
29
+ /** A callback to handle the response. */
30
+ onRequest?: ((request: Request) => Promise<void> | void) | undefined;
31
+ /** A callback to handle the response. */
32
+ onResponse?: ((response: Response) => Promise<void> | void) | undefined;
33
+ /** The timeout (in ms) for the request. */
26
34
  timeout?: HttpRpcClientOptions["timeout"] | undefined;
27
35
  };
28
36
  type HttpRpcClient = {
@@ -1 +1 @@
1
- {"version":3,"file":"getHttpRpcClient.js","names":["withTimeout","idCache","stringify","TimeoutError","HttpRequestError"],"sources":["../../../src/transports/getHttpRpcClient.ts"],"sourcesContent":["import { HttpRequestError, TimeoutError } from '../errors/request.js'\nimport type { RpcResponse } from '../types/rpc.js'\nimport type { MaybePromise } from '../types/utils.js'\nimport { idCache } from '../utils/idCache.js'\nimport { stringify } from '../utils/stringify.js'\nimport { withTimeout } from '../utils/withTimeout.js'\n\nexport type RpcRequest = {\n jsonrpc?: '2.0'\n method: string\n params?: any\n id?: number\n}\n\nexport type HttpRequestReturnType<\n body extends RpcRequest | RpcRequest[] = RpcRequest,\n> = body extends RpcRequest[] ? RpcResponse[] : RpcResponse\n\nexport type HttpRpcClientOptions = {\n /** Request configuration to pass to `fetch`. */\n fetchOptions?: Omit<RequestInit, 'body'> | undefined\n /** A callback to handle the request. */\n onRequest?:\n | ((\n request: Request,\n init: RequestInit\n ) => MaybePromise<\n void | undefined | (RequestInit & { url?: string | undefined })\n >)\n | undefined\n /** A callback to handle the response. */\n onResponse?: ((response: Response) => Promise<void> | void) | undefined\n /** The timeout (in ms) for the request. */\n timeout?: number | undefined\n}\n\nexport type HttpRequestParameters<\n body extends RpcRequest | RpcRequest[] = RpcRequest,\n> = {\n url?: string\n /** The RPC request body. */\n body?: body\n /** Request configuration to pass to `fetch`. */\n fetchOptions?: HttpRpcClientOptions['fetchOptions'] | undefined\n /** A callback to handle the response. */\n onRequest?: ((request: Request) => Promise<void> | void) | undefined\n /** A callback to handle the response. */\n onResponse?: ((response: Response) => Promise<void> | void) | undefined\n /** The timeout (in ms) for the request. */\n timeout?: HttpRpcClientOptions['timeout'] | undefined\n}\n\nexport type HttpRpcClient = {\n request<body extends RpcRequest | RpcRequest[]>(\n params: HttpRequestParameters<body>\n ): Promise<HttpRequestReturnType<body>>\n}\n\nexport function getHttpRpcClient(\n url: string,\n options: HttpRpcClientOptions = {}\n): HttpRpcClient {\n return {\n async request(params) {\n const {\n body,\n onRequest = options.onRequest,\n onResponse = options.onResponse,\n timeout = options.timeout ?? 10_000,\n } = params\n\n const fetchOptions = {\n ...(options.fetchOptions ?? {}),\n ...(params.fetchOptions ?? {}),\n }\n\n const { headers, method, signal: signal_ } = fetchOptions\n\n try {\n const response = await withTimeout(\n async ({ signal }) => {\n const preparedBody = body\n ? Array.isArray(body)\n ? body.map((b) => ({\n jsonrpc: '2.0' as const,\n id: b.id ?? idCache.take(),\n ...b,\n }))\n : {\n jsonrpc: '2.0' as const,\n id: body.id ?? idCache.take(),\n ...body,\n }\n : undefined\n const init: RequestInit = {\n ...fetchOptions,\n body: preparedBody ? stringify(preparedBody) : undefined,\n headers: {\n ...(method !== 'GET'\n ? { 'Content-Type': 'application/json' }\n : undefined),\n ...headers,\n },\n method: method || 'POST',\n signal: signal_ || (timeout > 0 ? signal : null),\n }\n const request = new Request(params.url ?? url, init)\n if (onRequest) {\n await onRequest(request, init)\n }\n const response = await fetch(params.url ?? url, init)\n return response\n },\n {\n errorInstance: new TimeoutError({\n body: body ?? {},\n url: params.url ?? url,\n timeout,\n }),\n timeout,\n signal: true,\n }\n )\n\n if (onResponse) {\n await onResponse(response)\n }\n\n let data: any\n if (\n response.headers.get('Content-Type')?.startsWith('application/json')\n ) {\n data = await response.json()\n } else {\n data = await response.text()\n data = JSON.parse(data || '{}')\n }\n\n if (!response.ok) {\n throw new HttpRequestError({\n body,\n details: stringify(data.error) || response.statusText,\n headers: response.headers,\n status: response.status,\n url,\n })\n }\n return data\n } catch (err) {\n if (err instanceof HttpRequestError) {\n throw err\n }\n if (err instanceof TimeoutError) {\n throw err\n }\n throw new HttpRequestError({\n body,\n cause: err as Error,\n url,\n })\n }\n },\n }\n}\n"],"mappings":";;;;;;AA0DA,SAAgB,iBACd,KACA,UAAgC,EAAE,EACnB;AACf,QAAO,EACL,MAAM,QAAQ,QAAQ;EACpB,MAAM,EACJ,MACA,YAAY,QAAQ,WACpB,aAAa,QAAQ,YACrB,UAAU,QAAQ,WAAW,QAC3B;EAEJ,MAAM,eAAe;GACnB,GAAI,QAAQ,gBAAgB,EAAE;GAC9B,GAAI,OAAO,gBAAgB,EAAE;GAC9B;EAED,MAAM,EAAE,SAAS,QAAQ,QAAQ,YAAY;AAE7C,MAAI;GACF,MAAM,WAAW,MAAMA,0BAAAA,YACrB,OAAO,EAAE,aAAa;IACpB,MAAM,eAAe,OACjB,MAAM,QAAQ,KAAK,GACjB,KAAK,KAAK,OAAO;KACf,SAAS;KACT,IAAI,EAAE,MAAMC,sBAAAA,QAAQ,MAAM;KAC1B,GAAG;KACJ,EAAE,GACH;KACE,SAAS;KACT,IAAI,KAAK,MAAMA,sBAAAA,QAAQ,MAAM;KAC7B,GAAG;KACJ,GACH,KAAA;IACJ,MAAM,OAAoB;KACxB,GAAG;KACH,MAAM,eAAeC,wBAAAA,UAAU,aAAa,GAAG,KAAA;KAC/C,SAAS;MACP,GAAI,WAAW,QACX,EAAE,gBAAgB,oBAAoB,GACtC,KAAA;MACJ,GAAG;MACJ;KACD,QAAQ,UAAU;KAClB,QAAQ,YAAY,UAAU,IAAI,SAAS;KAC5C;IACD,MAAM,UAAU,IAAI,QAAQ,OAAO,OAAO,KAAK,KAAK;AACpD,QAAI,UACF,OAAM,UAAU,SAAS,KAAK;AAGhC,WADiB,MAAM,MAAM,OAAO,OAAO,KAAK,KAAK;MAGvD;IACE,eAAe,IAAIC,uBAAAA,aAAa;KAC9B,MAAM,QAAQ,EAAE;KAChB,KAAK,OAAO,OAAO;KACnB;KACD,CAAC;IACF;IACA,QAAQ;IACT,CACF;AAED,OAAI,WACF,OAAM,WAAW,SAAS;GAG5B,IAAI;AACJ,OACE,SAAS,QAAQ,IAAI,eAAe,EAAE,WAAW,mBAAmB,CAEpE,QAAO,MAAM,SAAS,MAAM;QACvB;AACL,WAAO,MAAM,SAAS,MAAM;AAC5B,WAAO,KAAK,MAAM,QAAQ,KAAK;;AAGjC,OAAI,CAAC,SAAS,GACZ,OAAM,IAAIC,uBAAAA,iBAAiB;IACzB;IACA,SAASF,wBAAAA,UAAU,KAAK,MAAM,IAAI,SAAS;IAC3C,SAAS,SAAS;IAClB,QAAQ,SAAS;IACjB;IACD,CAAC;AAEJ,UAAO;WACA,KAAK;AACZ,OAAI,eAAeE,uBAAAA,iBACjB,OAAM;AAER,OAAI,eAAeD,uBAAAA,aACjB,OAAM;AAER,SAAM,IAAIC,uBAAAA,iBAAiB;IACzB;IACA,OAAO;IACP;IACD,CAAC;;IAGP"}
1
+ {"version":3,"file":"getHttpRpcClient.js","names":["withTimeout","idCache","stringify","TimeoutError","HttpRequestError"],"sources":["../../../src/transports/getHttpRpcClient.ts"],"sourcesContent":["import { HttpRequestError, TimeoutError } from '../errors/request.js'\nimport type { RpcResponse } from '../types/rpc.js'\nimport type { MaybePromise } from '../types/utils.js'\nimport { idCache } from '../utils/idCache.js'\nimport { stringify } from '../utils/stringify.js'\nimport { withTimeout } from '../utils/withTimeout.js'\n\nexport type RpcRequest = {\n jsonrpc?: '2.0'\n method: string\n params?: any\n id?: number\n}\n\nexport type HttpRequestReturnType<\n body extends RpcRequest | RpcRequest[] = RpcRequest,\n> = body extends RpcRequest[] ? RpcResponse[] : RpcResponse\n\nexport type HttpRpcClientOptions = {\n /** Request configuration to pass to `fetch`. */\n fetchOptions?: Omit<RequestInit, 'body'> | undefined\n /** A callback to handle the request. */\n onRequest?:\n | ((\n request: Request,\n init: RequestInit\n ) => MaybePromise<\n void | undefined | (RequestInit & { url?: string | undefined })\n >)\n | undefined\n /** A callback to handle the response. */\n onResponse?: ((response: Response) => Promise<void> | void) | undefined\n /** The timeout (in ms) for the request. */\n timeout?: number | undefined\n}\n\nexport type HttpRequestParameters<\n body extends RpcRequest | RpcRequest[] = RpcRequest,\n> = {\n url?: string\n /** The RPC request body. */\n body?: body\n /** Request configuration to pass to `fetch`. */\n fetchOptions?: HttpRpcClientOptions['fetchOptions'] | undefined\n /** A callback to handle the response. */\n onRequest?: ((request: Request) => Promise<void> | void) | undefined\n /** A callback to handle the response. */\n onResponse?: ((response: Response) => Promise<void> | void) | undefined\n /** The timeout (in ms) for the request. */\n timeout?: HttpRpcClientOptions['timeout'] | undefined\n}\n\nexport type HttpRpcClient = {\n request<body extends RpcRequest | RpcRequest[]>(\n params: HttpRequestParameters<body>\n ): Promise<HttpRequestReturnType<body>>\n}\n\nexport function getHttpRpcClient(\n url: string,\n options: HttpRpcClientOptions = {}\n): HttpRpcClient {\n return {\n async request(params) {\n const {\n body,\n onRequest = options.onRequest,\n onResponse = options.onResponse,\n timeout = options.timeout ?? 10_000,\n } = params\n\n const fetchOptions = {\n ...(options.fetchOptions ?? {}),\n ...(params.fetchOptions ?? {}),\n }\n\n const { headers, method, signal: signal_ } = fetchOptions\n\n try {\n const response = await withTimeout(\n async ({ signal }) => {\n const preparedBody = body\n ? Array.isArray(body)\n ? body.map((b) => ({\n jsonrpc: '2.0' as const,\n id: b.id ?? idCache.take(),\n ...b,\n }))\n : {\n jsonrpc: '2.0' as const,\n id: body.id ?? idCache.take(),\n ...body,\n }\n : undefined\n const init: RequestInit = {\n ...fetchOptions,\n body: preparedBody ? stringify(preparedBody) : undefined,\n headers: {\n ...(method !== 'GET'\n ? { 'Content-Type': 'application/json' }\n : undefined),\n ...headers,\n },\n method: method || 'POST',\n signal: signal_ || (timeout > 0 ? signal : null),\n }\n const request = new Request(params.url ?? url, init)\n if (onRequest) {\n await onRequest(request, init)\n }\n const response = await fetch(params.url ?? url, init)\n return response\n },\n {\n errorInstance: new TimeoutError({\n body: body ?? {},\n url: params.url ?? url,\n timeout,\n }),\n timeout,\n signal: true,\n }\n )\n\n if (onResponse) {\n await onResponse(response)\n }\n\n let data: any\n if (\n response.headers.get('Content-Type')?.startsWith('application/json')\n ) {\n data = await response.json()\n } else {\n data = await response.text()\n data = JSON.parse(data || '{}')\n }\n\n if (!response.ok) {\n throw new HttpRequestError({\n body,\n details: stringify(data.error) || response.statusText,\n headers: response.headers,\n status: response.status,\n url,\n })\n }\n return data\n } catch (err) {\n if (err instanceof HttpRequestError) {\n throw err\n }\n if (err instanceof TimeoutError) {\n throw err\n }\n throw new HttpRequestError({\n body,\n cause: err as Error,\n url,\n })\n }\n },\n }\n}\n"],"mappings":";;;;;;AA0DA,SAAgB,iBACd,KACA,UAAgC,CAAC,GAClB;CACf,OAAO,EACL,MAAM,QAAQ,QAAQ;EACpB,MAAM,EACJ,MACA,YAAY,QAAQ,WACpB,aAAa,QAAQ,YACrB,UAAU,QAAQ,WAAW,QAC3B;EAEJ,MAAM,eAAe;GACnB,GAAI,QAAQ,gBAAgB,CAAC;GAC7B,GAAI,OAAO,gBAAgB,CAAC;EAC9B;EAEA,MAAM,EAAE,SAAS,QAAQ,QAAQ,YAAY;EAE7C,IAAI;GACF,MAAM,WAAW,MAAMA,0BAAAA,YACrB,OAAO,EAAE,aAAa;IACpB,MAAM,eAAe,OACjB,MAAM,QAAQ,IAAI,IAChB,KAAK,KAAK,OAAO;KACf,SAAS;KACT,IAAI,EAAE,MAAMC,sBAAAA,QAAQ,KAAK;KAC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
1
1
  import { RpcMethods } from "./types.js";
2
-
3
2
  //#region src/transports/getRpcProviderMethods.d.ts
4
3
  type providers = "blockchair" | "ankr" | "blockcypher" | "mempool" | string;
5
4
  declare function getRpcProviderMethods(key: providers): RpcMethods | null;
@@ -1 +1 @@
1
- {"version":3,"file":"getRpcProviderMethods.js","names":["blockchairMethods","ankrMethods","blockcypherMethods","mempoolMethods"],"sources":["../../../src/transports/getRpcProviderMethods.ts"],"sourcesContent":["import { ankrMethods } from './ankr/methods.js'\nimport { blockchairMethods } from './blockchair/methods.js'\nimport { blockcypherMethods } from './blockcypher/methods.js'\nimport { mempoolMethods } from './mempool/methods.js'\nimport type { RpcMethods } from './types.js'\n\ntype providers = 'blockchair' | 'ankr' | 'blockcypher' | 'mempool' | string\n\nexport function getRpcProviderMethods(key: providers): RpcMethods | null {\n switch (key) {\n case 'blockchair':\n return blockchairMethods\n case 'ankr':\n return ankrMethods\n case 'blockcypher':\n return blockcypherMethods\n case 'mempool':\n return mempoolMethods\n default:\n return null\n }\n}\n"],"mappings":";;;;;;AAQA,SAAgB,sBAAsB,KAAmC;AACvE,SAAQ,KAAR;EACE,KAAK,aACH,QAAOA,sCAAAA;EACT,KAAK,OACH,QAAOC,gCAAAA;EACT,KAAK,cACH,QAAOC,uCAAAA;EACT,KAAK,UACH,QAAOC,mCAAAA;EACT,QACE,QAAO"}
1
+ {"version":3,"file":"getRpcProviderMethods.js","names":["blockchairMethods","ankrMethods","blockcypherMethods","mempoolMethods"],"sources":["../../../src/transports/getRpcProviderMethods.ts"],"sourcesContent":["import { ankrMethods } from './ankr/methods.js'\nimport { blockchairMethods } from './blockchair/methods.js'\nimport { blockcypherMethods } from './blockcypher/methods.js'\nimport { mempoolMethods } from './mempool/methods.js'\nimport type { RpcMethods } from './types.js'\n\ntype providers = 'blockchair' | 'ankr' | 'blockcypher' | 'mempool' | string\n\nexport function getRpcProviderMethods(key: providers): RpcMethods | null {\n switch (key) {\n case 'blockchair':\n return blockchairMethods\n case 'ankr':\n return ankrMethods\n case 'blockcypher':\n return blockcypherMethods\n case 'mempool':\n return mempoolMethods\n default:\n return null\n }\n}\n"],"mappings":";;;;;;AAQA,SAAgB,sBAAsB,KAAmC;CACvE,QAAQ,KAAR;EACE,KAAK,cACH,OAAOA,sCAAAA;EACT,KAAK,QACH,OAAOC,gCAAAA;EACT,KAAK,eACH,OAAOC,uCAAAA;EACT,KAAK,WACH,OAAOC,mCAAAA;EACT,SACE,OAAO;CACX;AACF"}