@bigmi/core 0.1.1 → 0.2.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (574) hide show
  1. package/README.md +7 -5
  2. package/dist/cjs/actions/getBalance.d.ts +6 -3
  3. package/dist/cjs/actions/getBalance.js.map +1 -1
  4. package/dist/cjs/actions/getBlock.d.ts +4 -1
  5. package/dist/cjs/actions/getBlock.js +3 -3
  6. package/dist/cjs/actions/getBlock.js.map +1 -1
  7. package/dist/cjs/actions/getBlockCount.d.ts +4 -1
  8. package/dist/cjs/actions/getBlockCount.js.map +1 -1
  9. package/dist/cjs/actions/getBlockStats.d.ts +4 -1
  10. package/dist/cjs/actions/getBlockStats.js +3 -3
  11. package/dist/cjs/actions/getBlockStats.js.map +1 -1
  12. package/dist/cjs/actions/getUTXOTransaction.d.ts +4 -1
  13. package/dist/cjs/actions/getUTXOTransaction.js +2 -2
  14. package/dist/cjs/actions/getUTXOTransaction.js.map +1 -1
  15. package/dist/cjs/actions/sendUTXOTransaction.d.ts +4 -1
  16. package/dist/cjs/actions/sendUTXOTransaction.js.map +1 -1
  17. package/dist/cjs/actions/signPsbt.d.ts +5 -2
  18. package/dist/cjs/actions/signPsbt.js.map +1 -1
  19. package/dist/cjs/actions/waitForTransaction.d.ts +3 -1
  20. package/dist/cjs/actions/waitForTransaction.js +16 -14
  21. package/dist/cjs/actions/waitForTransaction.js.map +1 -1
  22. package/dist/cjs/actions/watchBlockNumber.d.ts +3 -1
  23. package/dist/cjs/actions/watchBlockNumber.js +4 -4
  24. package/dist/cjs/actions/watchBlockNumber.js.map +1 -1
  25. package/dist/cjs/chains/bitcoin.d.ts +5 -17
  26. package/dist/cjs/chains/bitcoin.js +2 -2
  27. package/dist/cjs/chains/bitcoin.js.map +1 -1
  28. package/dist/cjs/chains/defineChain.d.ts +3 -0
  29. package/dist/cjs/chains/defineChain.js +12 -0
  30. package/dist/cjs/chains/defineChain.js.map +1 -0
  31. package/dist/cjs/clients/decorators/public.d.ts +18 -0
  32. package/dist/cjs/clients/decorators/public.js +18 -0
  33. package/dist/cjs/clients/decorators/public.js.map +1 -0
  34. package/dist/cjs/clients/decorators/wallet.d.ts +11 -0
  35. package/dist/cjs/clients/decorators/wallet.js +12 -0
  36. package/dist/cjs/clients/decorators/wallet.js.map +1 -0
  37. package/dist/cjs/errors/address.d.ts +9 -0
  38. package/dist/cjs/errors/address.js +17 -0
  39. package/dist/cjs/errors/address.js.map +1 -0
  40. package/dist/cjs/errors/base.d.ts +27 -0
  41. package/dist/cjs/errors/base.js +55 -0
  42. package/dist/cjs/errors/base.js.map +1 -0
  43. package/dist/cjs/errors/block.d.ts +11 -0
  44. package/dist/cjs/errors/block.js +18 -0
  45. package/dist/cjs/errors/block.js.map +1 -0
  46. package/dist/cjs/errors/config.d.ts +61 -0
  47. package/dist/cjs/errors/config.js +65 -0
  48. package/dist/cjs/errors/config.js.map +1 -0
  49. package/dist/cjs/errors/provider.d.ts +4 -0
  50. package/dist/cjs/errors/provider.js +15 -0
  51. package/dist/cjs/errors/provider.js.map +1 -0
  52. package/dist/cjs/errors/request.d.ts +80 -0
  53. package/dist/cjs/errors/request.js +72 -0
  54. package/dist/cjs/errors/request.js.map +1 -0
  55. package/dist/cjs/errors/rpc.d.ts +23 -0
  56. package/dist/cjs/errors/rpc.js +49 -0
  57. package/dist/cjs/errors/rpc.js.map +1 -0
  58. package/dist/cjs/errors/transaction.d.ts +31 -0
  59. package/dist/cjs/errors/transaction.js +40 -0
  60. package/dist/cjs/errors/transaction.js.map +1 -0
  61. package/dist/cjs/errors/transport.d.ts +7 -0
  62. package/dist/cjs/errors/transport.js +13 -0
  63. package/dist/cjs/errors/transport.js.map +1 -0
  64. package/dist/cjs/errors/utils.d.ts +6 -0
  65. package/dist/cjs/errors/utils.js +8 -0
  66. package/dist/cjs/errors/utils.js.map +1 -0
  67. package/dist/cjs/factories/createClient.d.ts +50 -0
  68. package/dist/cjs/factories/createClient.js +45 -0
  69. package/dist/cjs/factories/createClient.js.map +1 -0
  70. package/dist/cjs/factories/createTransport.d.ts +31 -0
  71. package/dist/cjs/factories/createTransport.js +23 -0
  72. package/dist/cjs/factories/createTransport.js.map +1 -0
  73. package/dist/cjs/index.d.ts +37 -4
  74. package/dist/cjs/index.js +63 -5
  75. package/dist/cjs/index.js.map +1 -1
  76. package/dist/cjs/transports/custom.d.ts +16 -0
  77. package/dist/cjs/transports/custom.js +17 -0
  78. package/dist/cjs/transports/custom.js.map +1 -0
  79. package/dist/cjs/transports/fallback.d.ts +56 -0
  80. package/dist/cjs/transports/fallback.js +165 -0
  81. package/dist/cjs/transports/fallback.js.map +1 -0
  82. package/dist/cjs/transports/getHttpRpcClient.d.ts +11 -1
  83. package/dist/cjs/transports/getHttpRpcClient.js +12 -10
  84. package/dist/cjs/transports/getHttpRpcClient.js.map +1 -1
  85. package/dist/cjs/transports/http.d.ts +28 -0
  86. package/dist/cjs/transports/http.js +72 -0
  87. package/dist/cjs/transports/http.js.map +1 -0
  88. package/dist/cjs/transports/types.d.ts +20 -5
  89. package/dist/cjs/transports/utxo.d.ts +1 -1
  90. package/dist/cjs/transports/utxo.js +6 -4
  91. package/dist/cjs/transports/utxo.js.map +1 -1
  92. package/dist/cjs/types/account.d.ts +9 -0
  93. package/dist/cjs/types/account.js +3 -0
  94. package/dist/cjs/types/account.js.map +1 -0
  95. package/dist/cjs/types/actions.d.ts +17 -0
  96. package/dist/cjs/types/actions.js +3 -0
  97. package/dist/cjs/types/actions.js.map +1 -0
  98. package/dist/cjs/types/address.d.ts +1 -0
  99. package/dist/cjs/types/address.js +3 -0
  100. package/dist/cjs/types/address.js.map +1 -0
  101. package/dist/cjs/types/base.d.ts +0 -0
  102. package/dist/cjs/types/base.js +2 -0
  103. package/dist/cjs/types/base.js.map +1 -0
  104. package/dist/cjs/types/block.d.ts +1 -0
  105. package/dist/cjs/{clients/types.js → types/block.js} +1 -1
  106. package/dist/cjs/types/block.js.map +1 -0
  107. package/dist/cjs/types/chain.d.ts +37 -0
  108. package/dist/cjs/types/chain.js +3 -0
  109. package/dist/cjs/types/chain.js.map +1 -0
  110. package/dist/cjs/types/client.d.ts +41 -0
  111. package/dist/cjs/types/client.js +3 -0
  112. package/dist/cjs/types/client.js.map +1 -0
  113. package/dist/cjs/types/hash.d.ts +1 -0
  114. package/dist/cjs/types/hash.js +3 -0
  115. package/dist/cjs/types/hash.js.map +1 -0
  116. package/dist/cjs/types/request.d.ts +43 -0
  117. package/dist/cjs/types/request.js +3 -0
  118. package/dist/cjs/types/request.js.map +1 -0
  119. package/dist/cjs/types/rpc.d.ts +34 -0
  120. package/dist/cjs/types/rpc.js +3 -0
  121. package/dist/cjs/types/rpc.js.map +1 -0
  122. package/dist/cjs/types/storage.d.ts +22 -0
  123. package/dist/cjs/types/storage.js +3 -0
  124. package/dist/cjs/types/storage.js.map +1 -0
  125. package/dist/cjs/types/transport.d.ts +29 -0
  126. package/dist/cjs/types/transport.js +3 -0
  127. package/dist/cjs/types/transport.js.map +1 -0
  128. package/dist/cjs/types/utils.d.ts +36 -0
  129. package/dist/cjs/types/utils.js +3 -0
  130. package/dist/cjs/types/utils.js.map +1 -0
  131. package/dist/cjs/utils/buildRequest.d.ts +5 -0
  132. package/dist/cjs/utils/buildRequest.js +102 -0
  133. package/dist/cjs/utils/buildRequest.js.map +1 -0
  134. package/dist/cjs/utils/converter.d.ts +3 -0
  135. package/dist/cjs/utils/converter.js +28 -0
  136. package/dist/cjs/utils/converter.js.map +1 -0
  137. package/dist/cjs/utils/createBatchScheduler.d.ts +20 -0
  138. package/dist/cjs/utils/createBatchScheduler.js +54 -0
  139. package/dist/cjs/utils/createBatchScheduler.js.map +1 -0
  140. package/dist/cjs/utils/deepEqual.d.ts +1 -0
  141. package/dist/cjs/utils/deepEqual.js +52 -0
  142. package/dist/cjs/utils/deepEqual.js.map +1 -0
  143. package/dist/cjs/utils/getAction.d.ts +10 -0
  144. package/dist/cjs/utils/getAction.js +15 -0
  145. package/dist/cjs/utils/getAction.js.map +1 -0
  146. package/dist/cjs/utils/getUTXOAddress.d.ts +3 -2
  147. package/dist/cjs/utils/getUTXOAddress.js.map +1 -1
  148. package/dist/cjs/utils/isUTXOAddress.js.map +1 -1
  149. package/dist/cjs/utils/lru.d.ts +6 -0
  150. package/dist/cjs/utils/lru.js +29 -0
  151. package/dist/cjs/utils/lru.js.map +1 -0
  152. package/dist/cjs/utils/observe.d.ts +1 -1
  153. package/dist/cjs/utils/parseAccount.d.ts +5 -0
  154. package/dist/cjs/utils/parseAccount.js +10 -0
  155. package/dist/cjs/utils/parseAccount.js.map +1 -0
  156. package/dist/cjs/utils/stringify.d.ts +3 -0
  157. package/dist/cjs/utils/stringify.js +9 -0
  158. package/dist/cjs/utils/stringify.js.map +1 -0
  159. package/dist/cjs/utils/uid.d.ts +1 -0
  160. package/dist/cjs/utils/uid.js +17 -0
  161. package/dist/cjs/utils/uid.js.map +1 -0
  162. package/dist/cjs/utils/wait.d.ts +1 -0
  163. package/dist/cjs/utils/wait.js +7 -0
  164. package/dist/cjs/utils/wait.js.map +1 -0
  165. package/dist/cjs/utils/withDedupe.d.ts +8 -0
  166. package/dist/cjs/utils/withDedupe.js +18 -0
  167. package/dist/cjs/utils/withDedupe.js.map +1 -0
  168. package/dist/cjs/utils/withResolvers.d.ts +6 -0
  169. package/dist/cjs/utils/withResolvers.js +13 -0
  170. package/dist/cjs/utils/withResolvers.js.map +1 -0
  171. package/dist/cjs/utils/withRetry.d.ts +14 -0
  172. package/dist/cjs/utils/withRetry.js +30 -0
  173. package/dist/cjs/utils/withRetry.js.map +1 -0
  174. package/dist/cjs/utils/withTimeout.d.ts +9 -0
  175. package/dist/cjs/utils/withTimeout.js +35 -0
  176. package/dist/cjs/utils/withTimeout.js.map +1 -0
  177. package/dist/cjs/version.d.ts +1 -0
  178. package/dist/cjs/version.js +5 -0
  179. package/dist/cjs/version.js.map +1 -0
  180. package/dist/esm/actions/getBalance.d.ts +6 -3
  181. package/dist/esm/actions/getBalance.js.map +1 -1
  182. package/dist/esm/actions/getBlock.d.ts +4 -1
  183. package/dist/esm/actions/getBlock.js +1 -1
  184. package/dist/esm/actions/getBlock.js.map +1 -1
  185. package/dist/esm/actions/getBlockCount.d.ts +4 -1
  186. package/dist/esm/actions/getBlockCount.js.map +1 -1
  187. package/dist/esm/actions/getBlockStats.d.ts +4 -1
  188. package/dist/esm/actions/getBlockStats.js +1 -1
  189. package/dist/esm/actions/getBlockStats.js.map +1 -1
  190. package/dist/esm/actions/getUTXOTransaction.d.ts +4 -1
  191. package/dist/esm/actions/getUTXOTransaction.js +1 -1
  192. package/dist/esm/actions/getUTXOTransaction.js.map +1 -1
  193. package/dist/esm/actions/sendUTXOTransaction.d.ts +4 -1
  194. package/dist/esm/actions/sendUTXOTransaction.js.map +1 -1
  195. package/dist/esm/actions/signPsbt.d.ts +5 -2
  196. package/dist/esm/actions/signPsbt.js.map +1 -1
  197. package/dist/esm/actions/waitForTransaction.d.ts +3 -1
  198. package/dist/esm/actions/waitForTransaction.js +4 -2
  199. package/dist/esm/actions/waitForTransaction.js.map +1 -1
  200. package/dist/esm/actions/watchBlockNumber.d.ts +3 -1
  201. package/dist/esm/actions/watchBlockNumber.js +2 -2
  202. package/dist/esm/actions/watchBlockNumber.js.map +1 -1
  203. package/dist/esm/chains/bitcoin.d.ts +5 -17
  204. package/dist/esm/chains/bitcoin.js +1 -1
  205. package/dist/esm/chains/bitcoin.js.map +1 -1
  206. package/dist/esm/chains/defineChain.d.ts +3 -0
  207. package/dist/esm/chains/defineChain.js +9 -0
  208. package/dist/esm/chains/defineChain.js.map +1 -0
  209. package/dist/esm/clients/decorators/public.d.ts +18 -0
  210. package/dist/esm/clients/decorators/public.js +15 -0
  211. package/dist/esm/clients/decorators/public.js.map +1 -0
  212. package/dist/esm/clients/decorators/wallet.d.ts +14 -0
  213. package/dist/esm/clients/decorators/wallet.js +9 -0
  214. package/dist/esm/clients/decorators/wallet.js.map +1 -0
  215. package/dist/esm/errors/address.d.ts +9 -0
  216. package/dist/esm/errors/address.js +13 -0
  217. package/dist/esm/errors/address.js.map +1 -0
  218. package/dist/esm/errors/base.d.ts +27 -0
  219. package/dist/esm/errors/base.js +50 -0
  220. package/dist/esm/errors/base.js.map +1 -0
  221. package/dist/esm/errors/block.d.ts +11 -0
  222. package/dist/esm/errors/block.js +14 -0
  223. package/dist/esm/errors/block.js.map +1 -0
  224. package/dist/esm/errors/config.d.ts +61 -0
  225. package/dist/esm/errors/config.js +55 -0
  226. package/dist/esm/errors/config.js.map +1 -0
  227. package/dist/esm/errors/provider.d.ts +4 -0
  228. package/dist/esm/errors/provider.js +11 -0
  229. package/dist/esm/errors/provider.js.map +1 -0
  230. package/dist/esm/errors/request.d.ts +80 -0
  231. package/dist/esm/errors/request.js +64 -0
  232. package/dist/esm/errors/request.js.map +1 -0
  233. package/dist/esm/errors/rpc.d.ts +53 -0
  234. package/dist/esm/errors/rpc.js +73 -0
  235. package/dist/esm/errors/rpc.js.map +1 -0
  236. package/dist/esm/errors/transaction.d.ts +31 -0
  237. package/dist/esm/errors/transaction.js +34 -0
  238. package/dist/esm/errors/transaction.js.map +1 -0
  239. package/dist/esm/errors/transport.d.ts +7 -0
  240. package/dist/esm/errors/transport.js +9 -0
  241. package/dist/esm/errors/transport.js.map +1 -0
  242. package/dist/esm/errors/utils.d.ts +6 -0
  243. package/dist/esm/errors/utils.js +3 -0
  244. package/dist/esm/errors/utils.js.map +1 -0
  245. package/dist/esm/factories/createClient.d.ts +85 -0
  246. package/dist/esm/factories/createClient.js +45 -0
  247. package/dist/esm/factories/createClient.js.map +1 -0
  248. package/dist/esm/factories/createTransport.d.ts +42 -0
  249. package/dist/esm/factories/createTransport.js +23 -0
  250. package/dist/esm/factories/createTransport.js.map +1 -0
  251. package/dist/esm/index.d.ts +37 -4
  252. package/dist/esm/index.js +26 -3
  253. package/dist/esm/index.js.map +1 -1
  254. package/dist/esm/transports/custom.d.ts +24 -0
  255. package/dist/esm/transports/custom.js +17 -0
  256. package/dist/esm/transports/custom.js.map +1 -0
  257. package/dist/esm/transports/fallback.d.ts +89 -0
  258. package/dist/esm/transports/fallback.js +172 -0
  259. package/dist/esm/transports/fallback.js.map +1 -0
  260. package/dist/esm/transports/getHttpRpcClient.d.ts +15 -1
  261. package/dist/esm/transports/getHttpRpcClient.js +4 -2
  262. package/dist/esm/transports/getHttpRpcClient.js.map +1 -1
  263. package/dist/esm/transports/http.d.ts +53 -0
  264. package/dist/esm/transports/http.js +74 -0
  265. package/dist/esm/transports/http.js.map +1 -0
  266. package/dist/esm/transports/types.d.ts +36 -5
  267. package/dist/esm/transports/utxo.d.ts +1 -1
  268. package/dist/esm/transports/utxo.js +3 -1
  269. package/dist/esm/transports/utxo.js.map +1 -1
  270. package/dist/esm/types/account.d.ts +9 -0
  271. package/dist/esm/types/account.js +2 -0
  272. package/dist/esm/types/account.js.map +1 -0
  273. package/dist/esm/types/actions.d.ts +20 -0
  274. package/dist/esm/types/actions.js +2 -0
  275. package/dist/esm/types/actions.js.map +1 -0
  276. package/dist/esm/types/address.d.ts +1 -0
  277. package/dist/esm/types/address.js +2 -0
  278. package/dist/esm/types/address.js.map +1 -0
  279. package/dist/esm/types/base.d.ts +0 -0
  280. package/dist/esm/types/base.js +2 -0
  281. package/dist/esm/types/base.js.map +1 -0
  282. package/dist/esm/types/block.d.ts +19 -0
  283. package/dist/esm/types/block.js +2 -0
  284. package/dist/esm/types/block.js.map +1 -0
  285. package/dist/esm/types/chain.d.ts +48 -0
  286. package/dist/esm/types/chain.js +2 -0
  287. package/dist/esm/types/chain.js.map +1 -0
  288. package/dist/esm/types/client.d.ts +68 -0
  289. package/dist/esm/types/client.js +2 -0
  290. package/dist/esm/types/client.js.map +1 -0
  291. package/dist/esm/types/hash.d.ts +1 -0
  292. package/dist/esm/types/hash.js +2 -0
  293. package/dist/esm/types/hash.js.map +1 -0
  294. package/dist/esm/types/request.d.ts +48 -0
  295. package/dist/esm/types/request.js +2 -0
  296. package/dist/esm/types/request.js.map +1 -0
  297. package/dist/esm/types/rpc.d.ts +34 -0
  298. package/dist/esm/types/rpc.js +2 -0
  299. package/dist/esm/types/rpc.js.map +1 -0
  300. package/dist/esm/types/storage.d.ts +22 -0
  301. package/dist/esm/types/storage.js +2 -0
  302. package/dist/esm/types/storage.js.map +1 -0
  303. package/dist/esm/types/transport.d.ts +37 -0
  304. package/dist/esm/types/transport.js +2 -0
  305. package/dist/esm/types/transport.js.map +1 -0
  306. package/dist/esm/types/utils.d.ts +72 -0
  307. package/dist/esm/types/utils.js +2 -0
  308. package/dist/esm/types/utils.js.map +1 -0
  309. package/dist/esm/utils/buildRequest.d.ts +6 -0
  310. package/dist/esm/utils/buildRequest.js +111 -0
  311. package/dist/esm/utils/buildRequest.js.map +1 -0
  312. package/dist/esm/utils/converter.d.ts +3 -0
  313. package/dist/esm/utils/converter.js +23 -0
  314. package/dist/esm/utils/converter.js.map +1 -0
  315. package/dist/esm/utils/createBatchScheduler.d.ts +21 -0
  316. package/dist/esm/utils/createBatchScheduler.js +52 -0
  317. package/dist/esm/utils/createBatchScheduler.js.map +1 -0
  318. package/dist/esm/utils/deepEqual.d.ts +2 -0
  319. package/dist/esm/utils/deepEqual.js +52 -0
  320. package/dist/esm/utils/deepEqual.js.map +1 -0
  321. package/dist/esm/utils/getAction.d.ts +17 -0
  322. package/dist/esm/utils/getAction.js +23 -0
  323. package/dist/esm/utils/getAction.js.map +1 -0
  324. package/dist/esm/utils/getUTXOAddress.d.ts +3 -2
  325. package/dist/esm/utils/getUTXOAddress.js.map +1 -1
  326. package/dist/esm/utils/isUTXOAddress.js.map +1 -1
  327. package/dist/esm/utils/lru.d.ts +11 -0
  328. package/dist/esm/utils/lru.js +30 -0
  329. package/dist/esm/utils/lru.js.map +1 -0
  330. package/dist/esm/utils/observe.d.ts +1 -1
  331. package/dist/esm/utils/parseAccount.d.ts +5 -0
  332. package/dist/esm/utils/parseAccount.js +7 -0
  333. package/dist/esm/utils/parseAccount.js.map +1 -0
  334. package/dist/esm/utils/stringify.d.ts +3 -0
  335. package/dist/esm/utils/stringify.js +5 -0
  336. package/dist/esm/utils/stringify.js.map +1 -0
  337. package/dist/esm/utils/uid.d.ts +1 -0
  338. package/dist/esm/utils/uid.js +14 -0
  339. package/dist/esm/utils/uid.js.map +1 -0
  340. package/dist/esm/utils/wait.d.ts +1 -0
  341. package/dist/esm/utils/wait.js +4 -0
  342. package/dist/esm/utils/wait.js.map +1 -0
  343. package/dist/esm/utils/withDedupe.d.ts +10 -0
  344. package/dist/esm/utils/withDedupe.js +16 -0
  345. package/dist/esm/utils/withDedupe.js.map +1 -0
  346. package/dist/esm/utils/withResolvers.d.ts +8 -0
  347. package/dist/esm/utils/withResolvers.js +11 -0
  348. package/dist/esm/utils/withResolvers.js.map +1 -0
  349. package/dist/esm/utils/withRetry.d.ts +14 -0
  350. package/dist/esm/utils/withRetry.js +27 -0
  351. package/dist/esm/utils/withRetry.js.map +1 -0
  352. package/dist/esm/utils/withTimeout.d.ts +9 -0
  353. package/dist/esm/utils/withTimeout.js +32 -0
  354. package/dist/esm/utils/withTimeout.js.map +1 -0
  355. package/dist/esm/version.d.ts +1 -0
  356. package/dist/esm/version.js +2 -0
  357. package/dist/esm/version.js.map +1 -0
  358. package/dist/types/actions/getBalance.d.ts +6 -3
  359. package/dist/types/actions/getBalance.d.ts.map +1 -1
  360. package/dist/types/actions/getBlock.d.ts +4 -1
  361. package/dist/types/actions/getBlock.d.ts.map +1 -1
  362. package/dist/types/actions/getBlockCount.d.ts +4 -1
  363. package/dist/types/actions/getBlockCount.d.ts.map +1 -1
  364. package/dist/types/actions/getBlockStats.d.ts +4 -1
  365. package/dist/types/actions/getBlockStats.d.ts.map +1 -1
  366. package/dist/types/actions/getUTXOTransaction.d.ts +4 -1
  367. package/dist/types/actions/getUTXOTransaction.d.ts.map +1 -1
  368. package/dist/types/actions/sendUTXOTransaction.d.ts +4 -1
  369. package/dist/types/actions/sendUTXOTransaction.d.ts.map +1 -1
  370. package/dist/types/actions/signPsbt.d.ts +5 -2
  371. package/dist/types/actions/signPsbt.d.ts.map +1 -1
  372. package/dist/types/actions/waitForTransaction.d.ts +3 -1
  373. package/dist/types/actions/waitForTransaction.d.ts.map +1 -1
  374. package/dist/types/actions/watchBlockNumber.d.ts +3 -1
  375. package/dist/types/actions/watchBlockNumber.d.ts.map +1 -1
  376. package/dist/types/chains/bitcoin.d.ts +5 -17
  377. package/dist/types/chains/bitcoin.d.ts.map +1 -1
  378. package/dist/types/chains/defineChain.d.ts +4 -0
  379. package/dist/types/chains/defineChain.d.ts.map +1 -0
  380. package/dist/types/clients/decorators/public.d.ts +19 -0
  381. package/dist/types/clients/decorators/public.d.ts.map +1 -0
  382. package/dist/types/clients/decorators/wallet.d.ts +15 -0
  383. package/dist/types/clients/decorators/wallet.d.ts.map +1 -0
  384. package/dist/types/errors/address.d.ts +10 -0
  385. package/dist/types/errors/address.d.ts.map +1 -0
  386. package/dist/types/errors/base.d.ts +28 -0
  387. package/dist/types/errors/base.d.ts.map +1 -0
  388. package/dist/types/errors/block.d.ts +12 -0
  389. package/dist/types/errors/block.d.ts.map +1 -0
  390. package/dist/types/errors/config.d.ts +62 -0
  391. package/dist/types/errors/config.d.ts.map +1 -0
  392. package/dist/types/errors/provider.d.ts +5 -0
  393. package/dist/types/errors/provider.d.ts.map +1 -0
  394. package/dist/types/errors/request.d.ts +81 -0
  395. package/dist/types/errors/request.d.ts.map +1 -0
  396. package/dist/types/errors/rpc.d.ts +54 -0
  397. package/dist/types/errors/rpc.d.ts.map +1 -0
  398. package/dist/types/errors/transaction.d.ts +32 -0
  399. package/dist/types/errors/transaction.d.ts.map +1 -0
  400. package/dist/types/errors/transport.d.ts +8 -0
  401. package/dist/types/errors/transport.d.ts.map +1 -0
  402. package/dist/types/errors/utils.d.ts +7 -0
  403. package/dist/types/errors/utils.d.ts.map +1 -0
  404. package/dist/types/factories/createClient.d.ts +86 -0
  405. package/dist/types/factories/createClient.d.ts.map +1 -0
  406. package/dist/types/factories/createTransport.d.ts +43 -0
  407. package/dist/types/factories/createTransport.d.ts.map +1 -0
  408. package/dist/types/index.d.ts +37 -4
  409. package/dist/types/index.d.ts.map +1 -1
  410. package/dist/types/transports/custom.d.ts +25 -0
  411. package/dist/types/transports/custom.d.ts.map +1 -0
  412. package/dist/types/transports/fallback.d.ts +90 -0
  413. package/dist/types/transports/fallback.d.ts.map +1 -0
  414. package/dist/types/transports/getHttpRpcClient.d.ts +15 -1
  415. package/dist/types/transports/getHttpRpcClient.d.ts.map +1 -1
  416. package/dist/types/transports/http.d.ts +54 -0
  417. package/dist/types/transports/http.d.ts.map +1 -0
  418. package/dist/types/transports/types.d.ts +36 -5
  419. package/dist/types/transports/types.d.ts.map +1 -1
  420. package/dist/types/transports/utxo.d.ts +1 -1
  421. package/dist/types/transports/utxo.d.ts.map +1 -1
  422. package/dist/types/types/account.d.ts +10 -0
  423. package/dist/types/types/account.d.ts.map +1 -0
  424. package/dist/types/types/actions.d.ts +21 -0
  425. package/dist/types/types/actions.d.ts.map +1 -0
  426. package/dist/types/types/address.d.ts +2 -0
  427. package/dist/types/types/address.d.ts.map +1 -0
  428. package/dist/types/types/base.d.ts +1 -0
  429. package/dist/types/types/base.d.ts.map +1 -0
  430. package/dist/types/types/block.d.ts +20 -0
  431. package/dist/types/types/block.d.ts.map +1 -0
  432. package/dist/types/types/chain.d.ts +49 -0
  433. package/dist/types/types/chain.d.ts.map +1 -0
  434. package/dist/types/types/client.d.ts +69 -0
  435. package/dist/types/types/client.d.ts.map +1 -0
  436. package/dist/types/types/hash.d.ts +2 -0
  437. package/dist/types/types/hash.d.ts.map +1 -0
  438. package/dist/types/types/request.d.ts +49 -0
  439. package/dist/types/types/request.d.ts.map +1 -0
  440. package/dist/types/types/rpc.d.ts +35 -0
  441. package/dist/types/types/rpc.d.ts.map +1 -0
  442. package/dist/types/types/storage.d.ts +23 -0
  443. package/dist/types/types/storage.d.ts.map +1 -0
  444. package/dist/types/types/transport.d.ts +38 -0
  445. package/dist/types/types/transport.d.ts.map +1 -0
  446. package/dist/types/types/utils.d.ts +73 -0
  447. package/dist/types/types/utils.d.ts.map +1 -0
  448. package/dist/types/utils/buildRequest.d.ts +7 -0
  449. package/dist/types/utils/buildRequest.d.ts.map +1 -0
  450. package/dist/types/utils/converter.d.ts +4 -0
  451. package/dist/types/utils/converter.d.ts.map +1 -0
  452. package/dist/types/utils/createBatchScheduler.d.ts +22 -0
  453. package/dist/types/utils/createBatchScheduler.d.ts.map +1 -0
  454. package/dist/types/utils/deepEqual.d.ts +3 -0
  455. package/dist/types/utils/deepEqual.d.ts.map +1 -0
  456. package/dist/types/utils/getAction.d.ts +18 -0
  457. package/dist/types/utils/getAction.d.ts.map +1 -0
  458. package/dist/types/utils/getUTXOAddress.d.ts +3 -2
  459. package/dist/types/utils/getUTXOAddress.d.ts.map +1 -1
  460. package/dist/types/utils/isUTXOAddress.d.ts.map +1 -1
  461. package/dist/types/utils/lru.d.ts +12 -0
  462. package/dist/types/utils/lru.d.ts.map +1 -0
  463. package/dist/types/utils/observe.d.ts +1 -1
  464. package/dist/types/utils/observe.d.ts.map +1 -1
  465. package/dist/types/utils/parseAccount.d.ts +6 -0
  466. package/dist/types/utils/parseAccount.d.ts.map +1 -0
  467. package/dist/types/utils/stringify.d.ts +4 -0
  468. package/dist/types/utils/stringify.d.ts.map +1 -0
  469. package/dist/types/utils/uid.d.ts +2 -0
  470. package/dist/types/utils/uid.d.ts.map +1 -0
  471. package/dist/types/utils/wait.d.ts +2 -0
  472. package/dist/types/utils/wait.d.ts.map +1 -0
  473. package/dist/types/utils/withDedupe.d.ts +11 -0
  474. package/dist/types/utils/withDedupe.d.ts.map +1 -0
  475. package/dist/types/utils/withResolvers.d.ts +9 -0
  476. package/dist/types/utils/withResolvers.d.ts.map +1 -0
  477. package/dist/types/utils/withRetry.d.ts +15 -0
  478. package/dist/types/utils/withRetry.d.ts.map +1 -0
  479. package/dist/types/utils/withTimeout.d.ts +10 -0
  480. package/dist/types/utils/withTimeout.d.ts.map +1 -0
  481. package/dist/types/version.d.ts +2 -0
  482. package/dist/types/version.d.ts.map +1 -0
  483. package/package.json +4 -3
  484. package/package.json.tmp +4 -3
  485. package/src/actions/getBalance.ts +6 -3
  486. package/src/actions/getBlock.ts +7 -7
  487. package/src/actions/getBlockCount.ts +4 -1
  488. package/src/actions/getBlockStats.ts +5 -7
  489. package/src/actions/getUTXOTransaction.ts +5 -7
  490. package/src/actions/sendUTXOTransaction.ts +4 -1
  491. package/src/actions/signPsbt.ts +5 -2
  492. package/src/actions/waitForTransaction.ts +9 -7
  493. package/src/actions/watchBlockNumber.ts +5 -2
  494. package/src/chains/bitcoin.ts +1 -1
  495. package/src/chains/defineChain.ts +14 -0
  496. package/src/clients/decorators/public.ts +62 -0
  497. package/src/clients/decorators/wallet.ts +37 -0
  498. package/src/errors/address.ts +16 -0
  499. package/src/errors/base.ts +85 -0
  500. package/src/errors/block.ts +24 -0
  501. package/src/errors/config.ts +102 -0
  502. package/src/errors/provider.ts +11 -0
  503. package/src/errors/request.ts +134 -0
  504. package/src/errors/rpc.ts +77 -0
  505. package/src/errors/transaction.ts +67 -0
  506. package/src/errors/transport.ts +15 -0
  507. package/src/errors/utils.ts +6 -0
  508. package/src/factories/createClient.ts +199 -0
  509. package/src/factories/createTransport.ts +93 -0
  510. package/src/index.ts +114 -13
  511. package/src/transports/custom.ts +56 -0
  512. package/src/transports/fallback.ts +332 -0
  513. package/src/transports/getHttpRpcClient.ts +28 -4
  514. package/src/transports/http.ts +176 -0
  515. package/src/transports/types.ts +38 -5
  516. package/src/transports/utxo.ts +6 -9
  517. package/src/types/account.ts +10 -0
  518. package/src/types/actions.ts +38 -0
  519. package/src/types/address.ts +1 -0
  520. package/src/types/base.ts +0 -0
  521. package/src/types/block.ts +19 -0
  522. package/src/types/chain.ts +72 -0
  523. package/src/types/client.ts +108 -0
  524. package/src/types/hash.ts +1 -0
  525. package/src/types/request.ts +87 -0
  526. package/src/types/rpc.ts +37 -0
  527. package/src/types/storage.ts +44 -0
  528. package/src/types/transport.ts +54 -0
  529. package/src/types/utils.ts +131 -0
  530. package/src/utils/buildRequest.ts +145 -0
  531. package/src/utils/converter.ts +25 -0
  532. package/src/utils/createBatchScheduler.ts +116 -0
  533. package/src/utils/deepEqual.ts +62 -0
  534. package/src/utils/getAction.ts +45 -0
  535. package/src/utils/getUTXOAddress.ts +4 -3
  536. package/src/utils/isUTXOAddress.ts +2 -1
  537. package/src/utils/lru.ts +35 -0
  538. package/src/utils/observe.ts +1 -1
  539. package/src/utils/parseAccount.ts +14 -0
  540. package/src/utils/stringify.ts +13 -0
  541. package/src/utils/uid.ts +14 -0
  542. package/src/utils/wait.ts +3 -0
  543. package/src/utils/withDedupe.ts +25 -0
  544. package/src/utils/withResolvers.ts +19 -0
  545. package/src/utils/withRetry.ts +60 -0
  546. package/src/utils/withTimeout.ts +47 -0
  547. package/src/version.ts +1 -0
  548. package/tsconfig.json +2 -1
  549. package/dist/cjs/clients/types.d.ts +0 -27
  550. package/dist/cjs/clients/types.js.map +0 -1
  551. package/dist/cjs/decorators/UTXOAPIActions.d.ts +0 -6
  552. package/dist/cjs/decorators/UTXOAPIActions.js +0 -10
  553. package/dist/cjs/decorators/UTXOAPIActions.js.map +0 -1
  554. package/dist/cjs/decorators/UTXOActions.d.ts +0 -10
  555. package/dist/cjs/decorators/UTXOActions.js +0 -14
  556. package/dist/cjs/decorators/UTXOActions.js.map +0 -1
  557. package/dist/esm/clients/types.d.ts +0 -43
  558. package/dist/esm/clients/types.js +0 -2
  559. package/dist/esm/clients/types.js.map +0 -1
  560. package/dist/esm/decorators/UTXOAPIActions.d.ts +0 -6
  561. package/dist/esm/decorators/UTXOAPIActions.js +0 -7
  562. package/dist/esm/decorators/UTXOAPIActions.js.map +0 -1
  563. package/dist/esm/decorators/UTXOActions.d.ts +0 -10
  564. package/dist/esm/decorators/UTXOActions.js +0 -11
  565. package/dist/esm/decorators/UTXOActions.js.map +0 -1
  566. package/dist/types/clients/types.d.ts +0 -44
  567. package/dist/types/clients/types.d.ts.map +0 -1
  568. package/dist/types/decorators/UTXOAPIActions.d.ts +0 -7
  569. package/dist/types/decorators/UTXOAPIActions.d.ts.map +0 -1
  570. package/dist/types/decorators/UTXOActions.d.ts +0 -11
  571. package/dist/types/decorators/UTXOActions.d.ts.map +0 -1
  572. package/src/clients/types.ts +0 -48
  573. package/src/decorators/UTXOAPIActions.ts +0 -20
  574. package/src/decorators/UTXOActions.ts +0 -37
@@ -0,0 +1,145 @@
1
+ import { BaseError } from '../errors/base.js'
2
+ import { HttpRequestError } from '../errors/request.js'
3
+ import {
4
+ MethodNotSupportedRpcError,
5
+ RpcErrorCode,
6
+ UserRejectedRequestError,
7
+ } from '../errors/rpc.js'
8
+ import type { ErrorType } from '../errors/utils.js'
9
+ import type {
10
+ BtcRpcRequestFn,
11
+ BtcRpcRequestOptions,
12
+ RpcSchema,
13
+ } from '../types/request.js'
14
+ import { stringToHex } from './converter.js'
15
+ import { stringify } from './stringify.js'
16
+ import { withDedupe } from './withDedupe.js'
17
+ import { withRetry } from './withRetry.js'
18
+
19
+ export type RequestErrorType = ErrorType
20
+
21
+ export function buildRequest<request extends BtcRpcRequestFn<RpcSchema>>(
22
+ request: request,
23
+ options: BtcRpcRequestOptions = {}
24
+ ): BtcRpcRequestFn {
25
+ return async (args, overrideOptions = {}) => {
26
+ const {
27
+ dedupe = false,
28
+ methods,
29
+ retryDelay = 150,
30
+ retryCount = 3,
31
+ uid,
32
+ } = {
33
+ ...options,
34
+ ...overrideOptions,
35
+ }
36
+
37
+ const { method } = args
38
+ if (methods?.exclude?.includes(method)) {
39
+ throw new MethodNotSupportedRpcError(method)
40
+ }
41
+ if (methods?.include && !methods.include.includes(method)) {
42
+ throw new MethodNotSupportedRpcError(method)
43
+ }
44
+
45
+ const requestId = dedupe
46
+ ? stringToHex(`${uid}.${stringify(args)}`)
47
+ : undefined
48
+ return withDedupe(
49
+ () =>
50
+ withRetry(
51
+ async () => {
52
+ try {
53
+ return await request(args)
54
+ } catch (err_) {
55
+ const err = err_ as unknown as BaseError
56
+ switch (err.code) {
57
+ case RpcErrorCode.METHOD_NOT_SUPPORTED:
58
+ throw new MethodNotSupportedRpcError(method)
59
+
60
+ case RpcErrorCode.USER_REJECTION:
61
+ throw new UserRejectedRequestError(err.message)
62
+
63
+ // CAIP-25: User Rejected Error
64
+ // https://docs.walletconnect.com/2.0/specs/clients/sign/error-codes#rejected-caip-25
65
+ case 5000:
66
+ throw new UserRejectedRequestError(err.message)
67
+
68
+ default:
69
+ if (err_ instanceof BaseError) {
70
+ throw err_
71
+ }
72
+ throw new BaseError('Unknown Error', { cause: err_ as Error })
73
+ }
74
+ }
75
+ },
76
+ {
77
+ delay: ({ count, error }) => {
78
+ // If we find a Retry-After header, let's retry after the given time.
79
+ if (error && error instanceof HttpRequestError) {
80
+ const retryAfter = error?.headers?.get('Retry-After')
81
+ if (retryAfter?.match(/\d/)) {
82
+ return Number.parseInt(retryAfter) * 1000
83
+ }
84
+ }
85
+
86
+ // Otherwise, let's retry with an exponential backoff.
87
+ return ~~(1 << count) * retryDelay
88
+ },
89
+ retryCount,
90
+ shouldRetry: ({ error }) => shouldRetry(error),
91
+ }
92
+ ),
93
+ { enabled: dedupe, id: requestId }
94
+ )
95
+ }
96
+ }
97
+
98
+ /** @internal */
99
+ export function shouldRetry(error: Error) {
100
+ if ('code' in error && typeof error.code === 'number') {
101
+ if (error.code === -1) {
102
+ return true // Unknown error
103
+ }
104
+ if (error.code === RpcErrorCode.INTERNAL_ERROR) {
105
+ return true
106
+ }
107
+ return false
108
+ }
109
+ if (error instanceof HttpRequestError && error.status) {
110
+ // Forbidden
111
+ if (error.status === 403) {
112
+ return true
113
+ }
114
+ // Request Timeout
115
+ if (error.status === 408) {
116
+ return true
117
+ }
118
+ // Request Entity Too Large
119
+ if (error.status === 413) {
120
+ return true
121
+ }
122
+ // Too Many Requests
123
+ if (error.status === 429) {
124
+ return true
125
+ }
126
+ // Internal Server Error
127
+ if (error.status === 500) {
128
+ return true
129
+ }
130
+ // Bad Gateway
131
+ if (error.status === 502) {
132
+ return true
133
+ }
134
+ // Service Unavailable
135
+ if (error.status === 503) {
136
+ return true
137
+ }
138
+ // Gateway Timeout
139
+ if (error.status === 504) {
140
+ return true
141
+ }
142
+ return false
143
+ }
144
+ return true
145
+ }
@@ -0,0 +1,25 @@
1
+ export function hexToBase64(hex: string): string {
2
+ const raw = hex
3
+ .match(/.{1,2}/g)!
4
+ .map((byte: string) => String.fromCharCode(Number.parseInt(byte, 16)))
5
+ .join('')
6
+ return btoa(raw)
7
+ }
8
+
9
+ export function base64ToHex(base64: string): string {
10
+ const raw = atob(base64)
11
+ let hex = ''
12
+ for (let i = 0; i < raw.length; i++) {
13
+ const hexByte = raw.charCodeAt(i).toString(16)
14
+ hex += hexByte.length === 2 ? hexByte : `0${hexByte}`
15
+ }
16
+ return hex
17
+ }
18
+
19
+ export function stringToHex(value: string): string {
20
+ const hex = Array.from(value)
21
+ .map((char: string) => char.charCodeAt(0).toString(16).padStart(2, '0'))
22
+ .join('')
23
+
24
+ return `0x${hex}`
25
+ }
@@ -0,0 +1,116 @@
1
+ import type { ErrorType } from '../errors/utils.js'
2
+ import { withResolvers } from './withResolvers.js'
3
+
4
+ type Resolved<returnType extends readonly unknown[] = any> = [
5
+ result: returnType[number],
6
+ results: returnType,
7
+ ]
8
+
9
+ type SchedulerItem = {
10
+ args: unknown
11
+ resolve: PromiseWithResolvers<unknown>['resolve']
12
+ reject: PromiseWithResolvers<unknown>['reject']
13
+ }
14
+
15
+ type BatchResultsCompareFn<result = unknown> = (a: result, b: result) => number
16
+
17
+ type CreateBatchSchedulerArguments<
18
+ parameters = unknown,
19
+ returnType extends readonly unknown[] = readonly unknown[],
20
+ > = {
21
+ fn: (args: parameters[]) => Promise<returnType>
22
+ id: number | string
23
+ shouldSplitBatch?: ((args: parameters[]) => boolean) | undefined
24
+ wait?: number | undefined
25
+ sort?: BatchResultsCompareFn<returnType[number]> | undefined
26
+ }
27
+
28
+ type CreateBatchSchedulerReturnType<
29
+ parameters = unknown,
30
+ returnType extends readonly unknown[] = readonly unknown[],
31
+ > = {
32
+ flush: () => void
33
+ schedule: parameters extends undefined
34
+ ? (args?: parameters | undefined) => Promise<Resolved<returnType>>
35
+ : (args: parameters) => Promise<Resolved<returnType>>
36
+ }
37
+
38
+ export type CreateBatchSchedulerErrorType = ErrorType
39
+
40
+ const schedulerCache = /*#__PURE__*/ new Map<number | string, SchedulerItem[]>()
41
+
42
+ /** @internal */
43
+ export function createBatchScheduler<
44
+ parameters,
45
+ returnType extends readonly unknown[],
46
+ >({
47
+ fn,
48
+ id,
49
+ shouldSplitBatch,
50
+ wait = 0,
51
+ sort,
52
+ }: CreateBatchSchedulerArguments<
53
+ parameters,
54
+ returnType
55
+ >): CreateBatchSchedulerReturnType<parameters, returnType> {
56
+ const exec = async () => {
57
+ const scheduler = getScheduler()
58
+ flush()
59
+
60
+ const args = scheduler.map(({ args }) => args)
61
+
62
+ if (args.length === 0) {
63
+ return
64
+ }
65
+
66
+ fn(args as parameters[])
67
+ .then((data) => {
68
+ if (sort && Array.isArray(data)) {
69
+ data.sort(sort)
70
+ }
71
+ for (let i = 0; i < scheduler.length; i++) {
72
+ const { resolve } = scheduler[i]
73
+ resolve?.([data[i], data])
74
+ }
75
+ })
76
+ .catch((err) => {
77
+ for (let i = 0; i < scheduler.length; i++) {
78
+ const { reject } = scheduler[i]
79
+ reject?.(err)
80
+ }
81
+ })
82
+ }
83
+
84
+ const flush = () => schedulerCache.delete(id)
85
+
86
+ const getBatchedArgs = () =>
87
+ getScheduler().map(({ args }) => args) as parameters[]
88
+
89
+ const getScheduler = () => schedulerCache.get(id) || []
90
+
91
+ const setScheduler = (item: SchedulerItem) =>
92
+ schedulerCache.set(id, [...getScheduler(), item])
93
+
94
+ return {
95
+ flush,
96
+ async schedule(args: parameters) {
97
+ const { promise, resolve, reject } = withResolvers()
98
+
99
+ const split = shouldSplitBatch?.([...getBatchedArgs(), args])
100
+
101
+ if (split) {
102
+ exec()
103
+ }
104
+
105
+ const hasActiveScheduler = getScheduler().length > 0
106
+ if (hasActiveScheduler) {
107
+ setScheduler({ args, resolve, reject })
108
+ return promise
109
+ }
110
+
111
+ setScheduler({ args, resolve, reject })
112
+ setTimeout(exec, wait)
113
+ return promise
114
+ },
115
+ } as unknown as CreateBatchSchedulerReturnType<parameters, returnType>
116
+ }
@@ -0,0 +1,62 @@
1
+ /** Forked from https://github.com/epoberezkin/fast-deep-equal */
2
+
3
+ export function deepEqual(a: any, b: any) {
4
+ if (a === b) {
5
+ return true
6
+ }
7
+
8
+ if (a && b && typeof a === 'object' && typeof b === 'object') {
9
+ if (a.constructor !== b.constructor) {
10
+ return false
11
+ }
12
+
13
+ let length: number
14
+ let i: number
15
+
16
+ if (Array.isArray(a) && Array.isArray(b)) {
17
+ length = a.length
18
+ if (length !== b.length) {
19
+ return false
20
+ }
21
+ for (i = length; i-- !== 0; ) {
22
+ if (!deepEqual(a[i], b[i])) {
23
+ return false
24
+ }
25
+ }
26
+ return true
27
+ }
28
+
29
+ if (a.valueOf !== Object.prototype.valueOf) {
30
+ return a.valueOf() === b.valueOf()
31
+ }
32
+ if (a.toString !== Object.prototype.toString) {
33
+ return a.toString() === b.toString()
34
+ }
35
+
36
+ const keys = Object.keys(a)
37
+ length = keys.length
38
+ if (length !== Object.keys(b).length) {
39
+ return false
40
+ }
41
+
42
+ for (i = length; i-- !== 0; ) {
43
+ if (!Object.prototype.hasOwnProperty.call(b, keys[i]!)) {
44
+ return false
45
+ }
46
+ }
47
+
48
+ for (i = length; i-- !== 0; ) {
49
+ const key = keys[i]
50
+
51
+ if (key && !deepEqual(a[key], b[key])) {
52
+ return false
53
+ }
54
+ }
55
+
56
+ return true
57
+ }
58
+
59
+ // true if both NaN, false otherwise
60
+ // biome-ignore lint/suspicious/noSelfCompare: <explanation>
61
+ return a !== a && b !== b
62
+ }
@@ -0,0 +1,45 @@
1
+ import type { PublicActions } from '../clients/decorators/public.js'
2
+ import type { WalletActions } from '../clients/decorators/wallet.js'
3
+ import type { Transport } from '../factories/createTransport.js'
4
+ import type { UTXOSchema } from '../transports/types.js'
5
+ import type { Client } from '../types/client.js'
6
+
7
+ import type { Account } from '../types/account.js'
8
+ import type { Chain } from '../types/chain.js'
9
+
10
+ /**
11
+ * Retrieves and returns an action from the client (if exists), and falls
12
+ * back to the tree-shakable action.
13
+ *
14
+ * Useful for extracting overridden actions from a client (ie. if a consumer
15
+ * wants to override the `sendTransaction` implementation).
16
+ */
17
+ export function getAction<
18
+ transport extends Transport,
19
+ chain extends Chain | undefined,
20
+ account extends Account | undefined,
21
+ rpcSchema extends UTXOSchema | undefined,
22
+ extended extends { [key: string]: unknown },
23
+ client extends Client<transport, chain, account, rpcSchema, extended>,
24
+ parameters,
25
+ returnType,
26
+ >(
27
+ client: client,
28
+ actionFn: (_: any, parameters: parameters) => returnType,
29
+ // Some minifiers drop `Function.prototype.name`, or replace it with short letters,
30
+ // meaning that `actionFn.name` will not always work. For that case, the consumer
31
+ // needs to pass the name explicitly.
32
+ name: keyof PublicActions | keyof WalletActions | (string & {})
33
+ ): (parameters: parameters) => returnType {
34
+ const action_implicit = client[actionFn.name]
35
+ if (typeof action_implicit === 'function') {
36
+ return action_implicit as (params: parameters) => returnType
37
+ }
38
+
39
+ const action_explicit = client[name]
40
+ if (typeof action_explicit === 'function') {
41
+ return action_explicit as (params: parameters) => returnType
42
+ }
43
+
44
+ return (params) => actionFn(client, params)
45
+ }
@@ -1,6 +1,7 @@
1
1
  import { sha256 } from '@noble/hashes/sha256'
2
2
  import { type Decoded, bech32, bech32m } from 'bech32'
3
3
  import bs58 from 'bs58'
4
+ import type { Address } from '../types/address.ts'
4
5
 
5
6
  export enum UTXONetwork {
6
7
  Mainnet = 'mainnet',
@@ -19,7 +20,7 @@ export enum UTXOAddressType {
19
20
  export type UTXOAddress = {
20
21
  bech32: boolean
21
22
  network: UTXONetwork
22
- address: string
23
+ address: Address
23
24
  type: UTXOAddressType
24
25
  }
25
26
 
@@ -44,7 +45,7 @@ const addressTypes: {
44
45
  },
45
46
  }
46
47
 
47
- const parseBech32 = (address: string): UTXOAddress => {
48
+ const parseBech32 = (address: Address): UTXOAddress => {
48
49
  let decoded: Decoded
49
50
 
50
51
  try {
@@ -97,7 +98,7 @@ const parseBech32 = (address: string): UTXOAddress => {
97
98
  }
98
99
  }
99
100
 
100
- export const getUTXOAddress = (address: string): UTXOAddress => {
101
+ export const getUTXOAddress = (address: Address): UTXOAddress => {
101
102
  let decoded: Uint8Array
102
103
  const prefix = address.substring(0, 2).toLowerCase()
103
104
 
@@ -1,3 +1,4 @@
1
+ import type { Address } from '../types/address.js'
1
2
  import { type UTXONetwork, getUTXOAddress } from './getUTXOAddress.js'
2
3
 
3
4
  export const isUTXOAddress = (
@@ -5,7 +6,7 @@ export const isUTXOAddress = (
5
6
  network?: UTXONetwork
6
7
  ): boolean => {
7
8
  try {
8
- const utxoAddress = getUTXOAddress(address)
9
+ const utxoAddress = getUTXOAddress(address as Address)
9
10
 
10
11
  if (network) {
11
12
  return network === utxoAddress.network
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Map with a LRU (Least recently used) policy.
3
+ *
4
+ * @link https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU
5
+ */
6
+ export class LruMap<value = unknown> extends Map<string, value> {
7
+ maxSize: number
8
+
9
+ constructor(size: number) {
10
+ super()
11
+ this.maxSize = size
12
+ }
13
+
14
+ override get(key: string) {
15
+ const value = super.get(key)
16
+
17
+ if (super.has(key) && value !== undefined) {
18
+ this.delete(key)
19
+ super.set(key, value)
20
+ }
21
+
22
+ return value
23
+ }
24
+
25
+ override set(key: string, value: value) {
26
+ super.set(key, value)
27
+ if (this.maxSize && this.size > this.maxSize) {
28
+ const firstKey = this.keys().next().value
29
+ if (firstKey) {
30
+ this.delete(firstKey)
31
+ }
32
+ }
33
+ return this
34
+ }
35
+ }
@@ -1,4 +1,4 @@
1
- import type { MaybePromise } from 'viem'
1
+ import type { MaybePromise } from '../types/utils.js'
2
2
 
3
3
  type Callback = ((...args: any[]) => any) | undefined
4
4
  type Callbacks = Record<string, Callback>
@@ -0,0 +1,14 @@
1
+ import type { ErrorType } from '../errors/utils.js'
2
+ import type { Account } from '../types/account.js'
3
+ import type { Address } from '../types/address.js'
4
+
5
+ export type ParseAccountErrorType = ErrorType
6
+
7
+ export function parseAccount<accountOrAddress extends Address | Account>(
8
+ account: accountOrAddress
9
+ ): accountOrAddress extends Address ? Account : accountOrAddress {
10
+ if (typeof account === 'string') {
11
+ return { address: account, type: 'json-rpc' } as any
12
+ }
13
+ return account as any
14
+ }
@@ -0,0 +1,13 @@
1
+ import type { ErrorType } from '../errors/utils.js'
2
+
3
+ export type StringifyErrorType = ErrorType
4
+
5
+ export const stringify: typeof JSON.stringify = (value, replacer, space) =>
6
+ JSON.stringify(
7
+ value,
8
+ (key, value_) => {
9
+ const value = typeof value_ === 'bigint' ? value_.toString() : value_
10
+ return typeof replacer === 'function' ? replacer(key, value) : value
11
+ },
12
+ space
13
+ )
@@ -0,0 +1,14 @@
1
+ const size = 256
2
+ let index = size
3
+ let buffer: string
4
+
5
+ export function uid(length = 11) {
6
+ if (!buffer || index + length > size * 2) {
7
+ buffer = ''
8
+ index = 0
9
+ for (let i = 0; i < size; i++) {
10
+ buffer += ((256 + Math.random() * 256) | 0).toString(16).substring(1)
11
+ }
12
+ }
13
+ return buffer.substring(index, index++ + length)
14
+ }
@@ -0,0 +1,3 @@
1
+ export async function wait(time: number) {
2
+ return new Promise((res) => setTimeout(res, time))
3
+ }
@@ -0,0 +1,25 @@
1
+ import { LruMap } from './lru.js'
2
+
3
+ /** @internal */
4
+ export const promiseCache = /*#__PURE__*/ new LruMap<Promise<any>>(8192)
5
+
6
+ type WithDedupeOptions = {
7
+ enabled?: boolean | undefined
8
+ id?: string | undefined
9
+ }
10
+
11
+ /** Deduplicates in-flight promises. */
12
+ export function withDedupe<data>(
13
+ fn: () => Promise<data>,
14
+ { enabled = true, id }: WithDedupeOptions
15
+ ): Promise<data> {
16
+ if (!enabled || !id) {
17
+ return fn()
18
+ }
19
+ if (promiseCache.get(id)) {
20
+ return promiseCache.get(id)!
21
+ }
22
+ const promise = fn().finally(() => promiseCache.delete(id))
23
+ promiseCache.set(id, promise)
24
+ return promise
25
+ }
@@ -0,0 +1,19 @@
1
+ /** @internal */
2
+ export type PromiseWithResolvers<type> = {
3
+ promise: Promise<type>
4
+ resolve: (value: type | PromiseLike<type>) => void
5
+ reject: (reason?: unknown) => void
6
+ }
7
+
8
+ /** @internal */
9
+ export function withResolvers<type>(): PromiseWithResolvers<type> {
10
+ let resolve: PromiseWithResolvers<type>['resolve'] = () => undefined
11
+ let reject: PromiseWithResolvers<type>['reject'] = () => undefined
12
+
13
+ const promise = new Promise<type>((resolve_, reject_) => {
14
+ resolve = resolve_
15
+ reject = reject_
16
+ })
17
+
18
+ return { promise, resolve, reject }
19
+ }
@@ -0,0 +1,60 @@
1
+ import type { ErrorType } from '../errors/utils.js'
2
+ import { wait } from './wait.js'
3
+
4
+ export type WithRetryParameters = {
5
+ // The delay (in ms) between retries.
6
+ delay?:
7
+ | ((config: { count: number; error: Error }) => number)
8
+ | number
9
+ | undefined
10
+ // The max number of times to retry.
11
+ retryCount?: number | undefined
12
+ // Whether or not to retry when an error is thrown.
13
+ shouldRetry?:
14
+ | (({
15
+ count,
16
+ error,
17
+ }: {
18
+ count: number
19
+ error: Error
20
+ }) => Promise<boolean> | boolean)
21
+ | undefined
22
+ }
23
+
24
+ export type WithRetryErrorType = ErrorType
25
+
26
+ export function withRetry<data>(
27
+ fn: () => Promise<data>,
28
+ {
29
+ delay: delay_ = 100,
30
+ retryCount = 2,
31
+ shouldRetry = () => true,
32
+ }: WithRetryParameters = {}
33
+ ) {
34
+ return new Promise<data>((resolve, reject) => {
35
+ const attemptRetry = async ({ count = 0 } = {}) => {
36
+ const retry = async ({ error }: { error: Error }) => {
37
+ const delay =
38
+ typeof delay_ === 'function' ? delay_({ count, error }) : delay_
39
+ if (delay) {
40
+ await wait(delay)
41
+ }
42
+ attemptRetry({ count: count + 1 })
43
+ }
44
+
45
+ try {
46
+ const data = await fn()
47
+ resolve(data)
48
+ } catch (err) {
49
+ if (
50
+ count < retryCount &&
51
+ (await shouldRetry({ count, error: err as Error }))
52
+ ) {
53
+ return retry({ error: err as Error })
54
+ }
55
+ reject(err)
56
+ }
57
+ }
58
+ attemptRetry()
59
+ })
60
+ }
@@ -0,0 +1,47 @@
1
+ import type { ErrorType } from '../errors/utils.js'
2
+
3
+ export type WithTimeoutErrorType = ErrorType
4
+
5
+ export function withTimeout<data>(
6
+ fn: ({
7
+ signal,
8
+ }: { signal: AbortController['signal'] | null }) => Promise<data>,
9
+ {
10
+ errorInstance = new Error('timed out'),
11
+ timeout,
12
+ signal,
13
+ }: {
14
+ // The error instance to throw when the timeout is reached.
15
+ errorInstance?: Error | undefined
16
+ // The timeout (in ms).
17
+ timeout: number
18
+ // Whether or not the timeout should use an abort signal.
19
+ signal?: boolean | undefined
20
+ }
21
+ ): Promise<data> {
22
+ return new Promise((resolve, reject) => {
23
+ ;(async () => {
24
+ let timeoutId!: NodeJS.Timeout
25
+ try {
26
+ const controller = new AbortController()
27
+ if (timeout > 0) {
28
+ timeoutId = setTimeout(() => {
29
+ if (signal) {
30
+ controller.abort()
31
+ } else {
32
+ reject(errorInstance)
33
+ }
34
+ }, timeout) as NodeJS.Timeout // need to cast because bun globals.d.ts overrides @types/node
35
+ }
36
+ resolve(await fn({ signal: controller?.signal || null }))
37
+ } catch (err) {
38
+ if ((err as Error)?.name === 'AbortError') {
39
+ reject(errorInstance)
40
+ }
41
+ reject(err)
42
+ } finally {
43
+ clearTimeout(timeoutId)
44
+ }
45
+ })()
46
+ })
47
+ }
package/src/version.ts ADDED
@@ -0,0 +1 @@
1
+ export const version = '0.1.1'