crypto-aio 0.0.3 → 0.2.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 (700) hide show
  1. package/CHANGELOG.md +167 -0
  2. package/README.md +163 -13
  3. package/dist/adapters/avalanche/address.d.ts +15 -0
  4. package/dist/adapters/avalanche/address.js +74 -0
  5. package/dist/adapters/avalanche/address.js.map +1 -0
  6. package/dist/adapters/avalanche/api.d.ts +100 -0
  7. package/dist/adapters/avalanche/api.js +381 -0
  8. package/dist/adapters/avalanche/api.js.map +1 -0
  9. package/dist/adapters/avalanche/builder.d.ts +13 -0
  10. package/dist/adapters/avalanche/builder.js +336 -0
  11. package/dist/adapters/avalanche/builder.js.map +1 -0
  12. package/dist/adapters/avalanche/cb58.d.ts +7 -0
  13. package/dist/adapters/avalanche/cb58.js +49 -0
  14. package/dist/adapters/avalanche/cb58.js.map +1 -0
  15. package/dist/adapters/avalanche/chains.d.ts +21 -0
  16. package/dist/adapters/avalanche/chains.js +79 -0
  17. package/dist/adapters/avalanche/chains.js.map +1 -0
  18. package/dist/adapters/avalanche/codec.d.ts +94 -0
  19. package/dist/adapters/avalanche/codec.js +371 -0
  20. package/dist/adapters/avalanche/codec.js.map +1 -0
  21. package/dist/adapters/avalanche/context.d.ts +59 -0
  22. package/dist/adapters/avalanche/context.js +114 -0
  23. package/dist/adapters/avalanche/context.js.map +1 -0
  24. package/dist/adapters/avalanche/decode.d.ts +16 -0
  25. package/dist/adapters/avalanche/decode.js +101 -0
  26. package/dist/adapters/avalanche/decode.js.map +1 -0
  27. package/dist/adapters/avalanche/driver.d.ts +22 -0
  28. package/dist/adapters/avalanche/driver.js +81 -0
  29. package/dist/adapters/avalanche/driver.js.map +1 -0
  30. package/dist/adapters/avalanche/errors.d.ts +18 -0
  31. package/dist/adapters/avalanche/errors.js +61 -0
  32. package/dist/adapters/avalanche/errors.js.map +1 -0
  33. package/dist/adapters/avalanche/fees.d.ts +23 -0
  34. package/dist/adapters/avalanche/fees.js +105 -0
  35. package/dist/adapters/avalanche/fees.js.map +1 -0
  36. package/dist/adapters/avalanche/index.d.ts +19 -0
  37. package/dist/adapters/avalanche/index.js +8 -0
  38. package/dist/adapters/avalanche/index.js.map +1 -0
  39. package/dist/adapters/avalanche/network.d.ts +37 -0
  40. package/dist/adapters/avalanche/network.js +135 -0
  41. package/dist/adapters/avalanche/network.js.map +1 -0
  42. package/dist/adapters/avalanche/plugin.d.ts +21 -0
  43. package/dist/adapters/avalanche/plugin.js +46 -0
  44. package/dist/adapters/avalanche/plugin.js.map +1 -0
  45. package/dist/adapters/avalanche/presets.d.ts +6 -0
  46. package/dist/adapters/avalanche/presets.js +86 -0
  47. package/dist/adapters/avalanche/presets.js.map +1 -0
  48. package/dist/adapters/avalanche/proofs.d.ts +41 -0
  49. package/dist/adapters/avalanche/proofs.js +270 -0
  50. package/dist/adapters/avalanche/proofs.js.map +1 -0
  51. package/dist/adapters/avalanche/reader.d.ts +40 -0
  52. package/dist/adapters/avalanche/reader.js +231 -0
  53. package/dist/adapters/avalanche/reader.js.map +1 -0
  54. package/dist/adapters/avalanche/sdk.d.ts +182 -0
  55. package/dist/adapters/avalanche/sdk.js +21 -0
  56. package/dist/adapters/avalanche/sdk.js.map +1 -0
  57. package/dist/adapters/avalanche/types.d.ts +86 -0
  58. package/dist/{type/common.js → adapters/avalanche/types.js} +1 -1
  59. package/dist/adapters/avalanche/types.js.map +1 -0
  60. package/dist/adapters/evm/builder.d.ts +11 -0
  61. package/dist/adapters/evm/builder.js +386 -0
  62. package/dist/adapters/evm/builder.js.map +1 -0
  63. package/dist/adapters/evm/chains.d.ts +6 -0
  64. package/dist/adapters/evm/chains.js +203 -0
  65. package/dist/adapters/evm/chains.js.map +1 -0
  66. package/dist/adapters/evm/client.d.ts +84 -0
  67. package/dist/adapters/evm/client.js +335 -0
  68. package/dist/adapters/evm/client.js.map +1 -0
  69. package/dist/adapters/evm/decode.d.ts +35 -0
  70. package/dist/adapters/evm/decode.js +175 -0
  71. package/dist/adapters/evm/decode.js.map +1 -0
  72. package/dist/adapters/evm/driver.d.ts +8 -0
  73. package/dist/adapters/evm/driver.js +61 -0
  74. package/dist/adapters/evm/driver.js.map +1 -0
  75. package/dist/adapters/evm/errors.d.ts +20 -0
  76. package/dist/adapters/evm/errors.js +110 -0
  77. package/dist/adapters/evm/errors.js.map +1 -0
  78. package/dist/adapters/evm/ethers-client.d.ts +43 -0
  79. package/dist/adapters/evm/ethers-client.js +139 -0
  80. package/dist/adapters/evm/ethers-client.js.map +1 -0
  81. package/dist/adapters/evm/fees.d.ts +103 -0
  82. package/dist/adapters/evm/fees.js +277 -0
  83. package/dist/adapters/evm/fees.js.map +1 -0
  84. package/dist/adapters/evm/index.d.ts +20 -0
  85. package/dist/adapters/evm/index.js +12 -0
  86. package/dist/adapters/evm/index.js.map +1 -0
  87. package/dist/adapters/evm/network.d.ts +65 -0
  88. package/dist/adapters/evm/network.js +150 -0
  89. package/dist/adapters/evm/network.js.map +1 -0
  90. package/dist/adapters/evm/plugin.d.ts +35 -0
  91. package/dist/adapters/evm/plugin.js +150 -0
  92. package/dist/adapters/evm/plugin.js.map +1 -0
  93. package/dist/adapters/evm/presets.d.ts +2 -0
  94. package/dist/adapters/evm/presets.js +105 -0
  95. package/dist/adapters/evm/presets.js.map +1 -0
  96. package/dist/adapters/evm/proofs.d.ts +19 -0
  97. package/dist/adapters/evm/proofs.js +370 -0
  98. package/dist/adapters/evm/proofs.js.map +1 -0
  99. package/dist/adapters/evm/rawtx.d.ts +25 -0
  100. package/dist/adapters/evm/rawtx.js +176 -0
  101. package/dist/adapters/evm/rawtx.js.map +1 -0
  102. package/dist/adapters/evm/reader.d.ts +83 -0
  103. package/dist/adapters/evm/reader.js +326 -0
  104. package/dist/adapters/evm/reader.js.map +1 -0
  105. package/dist/adapters/evm/rpc.d.ts +39 -0
  106. package/dist/adapters/evm/rpc.js +152 -0
  107. package/dist/adapters/evm/rpc.js.map +1 -0
  108. package/dist/adapters/evm/tokens.d.ts +10 -0
  109. package/dist/adapters/evm/tokens.js +23 -0
  110. package/dist/adapters/evm/tokens.js.map +1 -0
  111. package/dist/adapters/evm/types.d.ts +265 -0
  112. package/dist/{type/account.js → adapters/evm/types.js} +1 -1
  113. package/dist/adapters/evm/types.js.map +1 -0
  114. package/dist/adapters/evm/web3-client.d.ts +26 -0
  115. package/dist/adapters/evm/web3-client.js +176 -0
  116. package/dist/adapters/evm/web3-client.js.map +1 -0
  117. package/dist/adapters/solana/builder.d.ts +18 -0
  118. package/dist/adapters/solana/builder.js +556 -0
  119. package/dist/adapters/solana/builder.js.map +1 -0
  120. package/dist/adapters/solana/chains.d.ts +13 -0
  121. package/dist/adapters/solana/chains.js +37 -0
  122. package/dist/adapters/solana/chains.js.map +1 -0
  123. package/dist/adapters/solana/decode.d.ts +111 -0
  124. package/dist/adapters/solana/decode.js +595 -0
  125. package/dist/adapters/solana/decode.js.map +1 -0
  126. package/dist/adapters/solana/driver.d.ts +15 -0
  127. package/dist/adapters/solana/driver.js +72 -0
  128. package/dist/adapters/solana/driver.js.map +1 -0
  129. package/dist/adapters/solana/errors.d.ts +36 -0
  130. package/dist/adapters/solana/errors.js +154 -0
  131. package/dist/adapters/solana/errors.js.map +1 -0
  132. package/dist/adapters/solana/fees.d.ts +77 -0
  133. package/dist/adapters/solana/fees.js +214 -0
  134. package/dist/adapters/solana/fees.js.map +1 -0
  135. package/dist/adapters/solana/heights.d.ts +47 -0
  136. package/dist/adapters/solana/heights.js +185 -0
  137. package/dist/adapters/solana/heights.js.map +1 -0
  138. package/dist/adapters/solana/history.d.ts +10 -0
  139. package/dist/adapters/solana/history.js +71 -0
  140. package/dist/adapters/solana/history.js.map +1 -0
  141. package/dist/adapters/solana/index.d.ts +16 -0
  142. package/dist/adapters/solana/index.js +9 -0
  143. package/dist/adapters/solana/index.js.map +1 -0
  144. package/dist/adapters/solana/keys.d.ts +13 -0
  145. package/dist/adapters/solana/keys.js +69 -0
  146. package/dist/adapters/solana/keys.js.map +1 -0
  147. package/dist/adapters/solana/message.d.ts +15 -0
  148. package/dist/adapters/solana/message.js +120 -0
  149. package/dist/adapters/solana/message.js.map +1 -0
  150. package/dist/adapters/solana/network.d.ts +24 -0
  151. package/dist/adapters/solana/network.js +95 -0
  152. package/dist/adapters/solana/network.js.map +1 -0
  153. package/dist/adapters/solana/plugin.d.ts +18 -0
  154. package/dist/adapters/solana/plugin.js +44 -0
  155. package/dist/adapters/solana/plugin.js.map +1 -0
  156. package/dist/adapters/solana/presets.d.ts +2 -0
  157. package/dist/adapters/solana/presets.js +77 -0
  158. package/dist/adapters/solana/presets.js.map +1 -0
  159. package/dist/adapters/solana/programs.d.ts +44 -0
  160. package/dist/adapters/solana/programs.js +159 -0
  161. package/dist/adapters/solana/programs.js.map +1 -0
  162. package/dist/adapters/solana/proofs.d.ts +56 -0
  163. package/dist/adapters/solana/proofs.js +540 -0
  164. package/dist/adapters/solana/proofs.js.map +1 -0
  165. package/dist/adapters/solana/reader.d.ts +82 -0
  166. package/dist/adapters/solana/reader.js +326 -0
  167. package/dist/adapters/solana/reader.js.map +1 -0
  168. package/dist/adapters/solana/rpc.d.ts +102 -0
  169. package/dist/adapters/solana/rpc.js +301 -0
  170. package/dist/adapters/solana/rpc.js.map +1 -0
  171. package/dist/adapters/solana/tokens.d.ts +7 -0
  172. package/dist/adapters/solana/tokens.js +19 -0
  173. package/dist/adapters/solana/tokens.js.map +1 -0
  174. package/dist/adapters/solana/types.d.ts +124 -0
  175. package/dist/{type/contract.js → adapters/solana/types.js} +1 -1
  176. package/dist/adapters/solana/types.js.map +1 -0
  177. package/dist/adapters/solana/web3.d.ts +5 -0
  178. package/dist/adapters/solana/web3.js +61 -0
  179. package/dist/adapters/solana/web3.js.map +1 -0
  180. package/dist/adapters/solana/wire.d.ts +62 -0
  181. package/dist/adapters/solana/wire.js +168 -0
  182. package/dist/adapters/solana/wire.js.map +1 -0
  183. package/dist/adapters/ton/address.d.ts +43 -0
  184. package/dist/adapters/ton/address.js +168 -0
  185. package/dist/adapters/ton/address.js.map +1 -0
  186. package/dist/adapters/ton/api.d.ts +344 -0
  187. package/dist/adapters/ton/api.js +942 -0
  188. package/dist/adapters/ton/api.js.map +1 -0
  189. package/dist/adapters/ton/builder.d.ts +18 -0
  190. package/dist/adapters/ton/builder.js +701 -0
  191. package/dist/adapters/ton/builder.js.map +1 -0
  192. package/dist/adapters/ton/chains.d.ts +16 -0
  193. package/dist/adapters/ton/chains.js +39 -0
  194. package/dist/adapters/ton/chains.js.map +1 -0
  195. package/dist/adapters/ton/decode.d.ts +43 -0
  196. package/dist/adapters/ton/decode.js +219 -0
  197. package/dist/adapters/ton/decode.js.map +1 -0
  198. package/dist/adapters/ton/driver.d.ts +10 -0
  199. package/dist/adapters/ton/driver.js +117 -0
  200. package/dist/adapters/ton/driver.js.map +1 -0
  201. package/dist/adapters/ton/errors.d.ts +36 -0
  202. package/dist/adapters/ton/errors.js +89 -0
  203. package/dist/adapters/ton/errors.js.map +1 -0
  204. package/dist/adapters/ton/fees.d.ts +28 -0
  205. package/dist/adapters/ton/fees.js +121 -0
  206. package/dist/adapters/ton/fees.js.map +1 -0
  207. package/dist/adapters/ton/index.d.ts +16 -0
  208. package/dist/adapters/ton/index.js +9 -0
  209. package/dist/adapters/ton/index.js.map +1 -0
  210. package/dist/adapters/ton/messages.d.ts +157 -0
  211. package/dist/adapters/ton/messages.js +397 -0
  212. package/dist/adapters/ton/messages.js.map +1 -0
  213. package/dist/adapters/ton/native-client.d.ts +10 -0
  214. package/dist/adapters/ton/native-client.js +47 -0
  215. package/dist/adapters/ton/native-client.js.map +1 -0
  216. package/dist/adapters/ton/network.d.ts +58 -0
  217. package/dist/adapters/ton/network.js +207 -0
  218. package/dist/adapters/ton/network.js.map +1 -0
  219. package/dist/adapters/ton/plugin.d.ts +24 -0
  220. package/dist/adapters/ton/plugin.js +57 -0
  221. package/dist/adapters/ton/plugin.js.map +1 -0
  222. package/dist/adapters/ton/presets.d.ts +6 -0
  223. package/dist/adapters/ton/presets.js +94 -0
  224. package/dist/adapters/ton/presets.js.map +1 -0
  225. package/dist/adapters/ton/proofs.d.ts +66 -0
  226. package/dist/adapters/ton/proofs.js +755 -0
  227. package/dist/adapters/ton/proofs.js.map +1 -0
  228. package/dist/adapters/ton/reader.d.ts +235 -0
  229. package/dist/adapters/ton/reader.js +976 -0
  230. package/dist/adapters/ton/reader.js.map +1 -0
  231. package/dist/adapters/ton/tokens.d.ts +10 -0
  232. package/dist/adapters/ton/tokens.js +27 -0
  233. package/dist/adapters/ton/tokens.js.map +1 -0
  234. package/dist/adapters/ton/trace.d.ts +74 -0
  235. package/dist/adapters/ton/trace.js +303 -0
  236. package/dist/adapters/ton/trace.js.map +1 -0
  237. package/dist/adapters/ton/types.d.ts +105 -0
  238. package/dist/{type/transact.js → adapters/ton/types.js} +1 -1
  239. package/dist/adapters/ton/types.js.map +1 -0
  240. package/dist/adapters/ton/wallets.d.ts +86 -0
  241. package/dist/adapters/ton/wallets.js +373 -0
  242. package/dist/adapters/ton/wallets.js.map +1 -0
  243. package/dist/adapters/tron/abi.d.ts +41 -0
  244. package/dist/adapters/tron/abi.js +112 -0
  245. package/dist/adapters/tron/abi.js.map +1 -0
  246. package/dist/adapters/tron/address.d.ts +20 -0
  247. package/dist/adapters/tron/address.js +110 -0
  248. package/dist/adapters/tron/address.js.map +1 -0
  249. package/dist/adapters/tron/builder.d.ts +12 -0
  250. package/dist/adapters/tron/builder.js +569 -0
  251. package/dist/adapters/tron/builder.js.map +1 -0
  252. package/dist/adapters/tron/chains.d.ts +12 -0
  253. package/dist/adapters/tron/chains.js +35 -0
  254. package/dist/adapters/tron/chains.js.map +1 -0
  255. package/dist/adapters/tron/codec.d.ts +10 -0
  256. package/dist/adapters/tron/codec.js +322 -0
  257. package/dist/adapters/tron/codec.js.map +1 -0
  258. package/dist/adapters/tron/decode.d.ts +52 -0
  259. package/dist/adapters/tron/decode.js +280 -0
  260. package/dist/adapters/tron/decode.js.map +1 -0
  261. package/dist/adapters/tron/driver.d.ts +12 -0
  262. package/dist/adapters/tron/driver.js +106 -0
  263. package/dist/adapters/tron/driver.js.map +1 -0
  264. package/dist/adapters/tron/errors.d.ts +74 -0
  265. package/dist/adapters/tron/errors.js +261 -0
  266. package/dist/adapters/tron/errors.js.map +1 -0
  267. package/dist/adapters/tron/fees.d.ts +49 -0
  268. package/dist/adapters/tron/fees.js +166 -0
  269. package/dist/adapters/tron/fees.js.map +1 -0
  270. package/dist/adapters/tron/http.d.ts +173 -0
  271. package/dist/adapters/tron/http.js +729 -0
  272. package/dist/adapters/tron/http.js.map +1 -0
  273. package/dist/adapters/tron/index.d.ts +16 -0
  274. package/dist/adapters/tron/index.js +15 -0
  275. package/dist/adapters/tron/index.js.map +1 -0
  276. package/dist/adapters/tron/network.d.ts +44 -0
  277. package/dist/adapters/tron/network.js +163 -0
  278. package/dist/adapters/tron/network.js.map +1 -0
  279. package/dist/adapters/tron/plugin.d.ts +17 -0
  280. package/dist/adapters/tron/plugin.js +39 -0
  281. package/dist/adapters/tron/plugin.js.map +1 -0
  282. package/dist/adapters/tron/presets.d.ts +5 -0
  283. package/dist/adapters/tron/presets.js +68 -0
  284. package/dist/adapters/tron/presets.js.map +1 -0
  285. package/dist/adapters/tron/proofs.d.ts +80 -0
  286. package/dist/adapters/tron/proofs.js +371 -0
  287. package/dist/adapters/tron/proofs.js.map +1 -0
  288. package/dist/adapters/tron/protobuf.d.ts +36 -0
  289. package/dist/adapters/tron/protobuf.js +90 -0
  290. package/dist/adapters/tron/protobuf.js.map +1 -0
  291. package/dist/adapters/tron/reader.d.ts +57 -0
  292. package/dist/adapters/tron/reader.js +220 -0
  293. package/dist/adapters/tron/reader.js.map +1 -0
  294. package/dist/adapters/tron/tokens.d.ts +9 -0
  295. package/dist/adapters/tron/tokens.js +14 -0
  296. package/dist/adapters/tron/tokens.js.map +1 -0
  297. package/dist/adapters/tron/types.d.ts +166 -0
  298. package/dist/adapters/tron/types.js +3 -0
  299. package/dist/adapters/tron/types.js.map +1 -0
  300. package/dist/adapters/utxo/address.d.ts +51 -0
  301. package/dist/adapters/utxo/address.js +341 -0
  302. package/dist/adapters/utxo/address.js.map +1 -0
  303. package/dist/adapters/utxo/builder.d.ts +35 -0
  304. package/dist/adapters/utxo/builder.js +380 -0
  305. package/dist/adapters/utxo/builder.js.map +1 -0
  306. package/dist/adapters/utxo/chains.d.ts +17 -0
  307. package/dist/adapters/utxo/chains.js +100 -0
  308. package/dist/adapters/utxo/chains.js.map +1 -0
  309. package/dist/adapters/utxo/codec.d.ts +120 -0
  310. package/dist/adapters/utxo/codec.js +408 -0
  311. package/dist/adapters/utxo/codec.js.map +1 -0
  312. package/dist/adapters/utxo/coinselect.d.ts +48 -0
  313. package/dist/adapters/utxo/coinselect.js +131 -0
  314. package/dist/adapters/utxo/coinselect.js.map +1 -0
  315. package/dist/adapters/utxo/context.d.ts +63 -0
  316. package/dist/adapters/utxo/context.js +125 -0
  317. package/dist/adapters/utxo/context.js.map +1 -0
  318. package/dist/adapters/utxo/decode.d.ts +22 -0
  319. package/dist/adapters/utxo/decode.js +121 -0
  320. package/dist/adapters/utxo/decode.js.map +1 -0
  321. package/dist/adapters/utxo/driver.d.ts +16 -0
  322. package/dist/adapters/utxo/driver.js +79 -0
  323. package/dist/adapters/utxo/driver.js.map +1 -0
  324. package/dist/adapters/utxo/ecc.d.ts +9 -0
  325. package/dist/adapters/utxo/ecc.js +26 -0
  326. package/dist/adapters/utxo/ecc.js.map +1 -0
  327. package/dist/adapters/utxo/errors.d.ts +52 -0
  328. package/dist/adapters/utxo/errors.js +191 -0
  329. package/dist/adapters/utxo/errors.js.map +1 -0
  330. package/dist/adapters/utxo/esplora.d.ts +100 -0
  331. package/dist/adapters/utxo/esplora.js +498 -0
  332. package/dist/adapters/utxo/esplora.js.map +1 -0
  333. package/dist/adapters/utxo/fees.d.ts +41 -0
  334. package/dist/adapters/utxo/fees.js +125 -0
  335. package/dist/adapters/utxo/fees.js.map +1 -0
  336. package/dist/adapters/utxo/index.d.ts +17 -0
  337. package/dist/adapters/utxo/index.js +8 -0
  338. package/dist/adapters/utxo/index.js.map +1 -0
  339. package/dist/adapters/utxo/network.d.ts +50 -0
  340. package/dist/adapters/utxo/network.js +165 -0
  341. package/dist/adapters/utxo/network.js.map +1 -0
  342. package/dist/adapters/utxo/plugin.d.ts +17 -0
  343. package/dist/adapters/utxo/plugin.js +41 -0
  344. package/dist/adapters/utxo/plugin.js.map +1 -0
  345. package/dist/adapters/utxo/presets.d.ts +12 -0
  346. package/dist/adapters/utxo/presets.js +47 -0
  347. package/dist/adapters/utxo/presets.js.map +1 -0
  348. package/dist/adapters/utxo/preview.d.ts +3 -0
  349. package/dist/adapters/utxo/preview.js +65 -0
  350. package/dist/adapters/utxo/preview.js.map +1 -0
  351. package/dist/adapters/utxo/proofs.d.ts +66 -0
  352. package/dist/adapters/utxo/proofs.js +469 -0
  353. package/dist/adapters/utxo/proofs.js.map +1 -0
  354. package/dist/adapters/utxo/rawblock.d.ts +46 -0
  355. package/dist/adapters/utxo/rawblock.js +159 -0
  356. package/dist/adapters/utxo/rawblock.js.map +1 -0
  357. package/dist/adapters/utxo/rawtx.d.ts +73 -0
  358. package/dist/adapters/utxo/rawtx.js +264 -0
  359. package/dist/adapters/utxo/rawtx.js.map +1 -0
  360. package/dist/adapters/utxo/reader.d.ts +36 -0
  361. package/dist/adapters/utxo/reader.js +265 -0
  362. package/dist/adapters/utxo/reader.js.map +1 -0
  363. package/dist/adapters/utxo/sdk.d.ts +18 -0
  364. package/dist/adapters/utxo/sdk.js +17 -0
  365. package/dist/adapters/utxo/sdk.js.map +1 -0
  366. package/dist/adapters/utxo/signed-psbt.d.ts +36 -0
  367. package/dist/adapters/utxo/signed-psbt.js +428 -0
  368. package/dist/adapters/utxo/signed-psbt.js.map +1 -0
  369. package/dist/adapters/utxo/spend.d.ts +59 -0
  370. package/dist/adapters/utxo/spend.js +230 -0
  371. package/dist/adapters/utxo/spend.js.map +1 -0
  372. package/dist/adapters/utxo/types.d.ts +167 -0
  373. package/dist/adapters/utxo/types.js +3 -0
  374. package/dist/adapters/utxo/types.js.map +1 -0
  375. package/dist/core/assets/service.d.ts +18 -0
  376. package/dist/core/assets/service.js +69 -0
  377. package/dist/core/assets/service.js.map +1 -0
  378. package/dist/core/blockchain/default-ref.d.ts +4 -0
  379. package/dist/core/blockchain/default-ref.js +16 -0
  380. package/dist/core/blockchain/default-ref.js.map +1 -0
  381. package/dist/core/blockchain/handle.d.ts +179 -0
  382. package/dist/core/blockchain/handle.js +579 -0
  383. package/dist/core/blockchain/handle.js.map +1 -0
  384. package/dist/core/blockchain/internal.d.ts +19 -0
  385. package/dist/core/blockchain/internal.js +16 -0
  386. package/dist/core/blockchain/internal.js.map +1 -0
  387. package/dist/core/blockchain/mapping.d.ts +22 -0
  388. package/dist/core/blockchain/mapping.js +136 -0
  389. package/dist/core/blockchain/mapping.js.map +1 -0
  390. package/dist/core/config/env.d.ts +8 -0
  391. package/dist/core/config/env.js +60 -0
  392. package/dist/core/config/env.js.map +1 -0
  393. package/dist/core/config/merge.d.ts +26 -0
  394. package/dist/core/config/merge.js +144 -0
  395. package/dist/core/config/merge.js.map +1 -0
  396. package/dist/core/config/resolve.d.ts +12 -0
  397. package/dist/core/config/resolve.js +251 -0
  398. package/dist/core/config/resolve.js.map +1 -0
  399. package/dist/core/config/types.d.ts +180 -0
  400. package/dist/core/config/types.js +3 -0
  401. package/dist/core/config/types.js.map +1 -0
  402. package/dist/core/container/builtins.d.ts +4 -0
  403. package/dist/core/container/builtins.js +13 -0
  404. package/dist/core/container/builtins.js.map +1 -0
  405. package/dist/core/container/container.d.ts +62 -0
  406. package/dist/core/container/container.js +500 -0
  407. package/dist/core/container/container.js.map +1 -0
  408. package/dist/core/container/default.d.ts +15 -0
  409. package/dist/core/container/default.js +70 -0
  410. package/dist/core/container/default.js.map +1 -0
  411. package/dist/core/container/internals.d.ts +54 -0
  412. package/dist/core/container/internals.js +21 -0
  413. package/dist/core/container/internals.js.map +1 -0
  414. package/dist/core/container/pool.d.ts +27 -0
  415. package/dist/core/container/pool.js +77 -0
  416. package/dist/core/container/pool.js.map +1 -0
  417. package/dist/core/driver/types.d.ts +379 -0
  418. package/dist/core/driver/types.js +3 -0
  419. package/dist/core/driver/types.js.map +1 -0
  420. package/dist/core/errors/codes.d.ts +163 -0
  421. package/dist/core/errors/codes.js +53 -0
  422. package/dist/core/errors/codes.js.map +1 -0
  423. package/dist/core/errors/error.d.ts +66 -0
  424. package/dist/core/errors/error.js +129 -0
  425. package/dist/core/errors/error.js.map +1 -0
  426. package/dist/core/events/bus.d.ts +12 -0
  427. package/dist/core/events/bus.js +46 -0
  428. package/dist/core/events/bus.js.map +1 -0
  429. package/dist/core/events/logger.d.ts +13 -0
  430. package/dist/core/events/logger.js +42 -0
  431. package/dist/core/events/logger.js.map +1 -0
  432. package/dist/core/events/types.d.ts +131 -0
  433. package/dist/core/events/types.js +3 -0
  434. package/dist/core/events/types.js.map +1 -0
  435. package/dist/core/lifecycle/engine-rules.d.ts +106 -0
  436. package/dist/core/lifecycle/engine-rules.js +267 -0
  437. package/dist/core/lifecycle/engine-rules.js.map +1 -0
  438. package/dist/core/lifecycle/engine.d.ts +502 -0
  439. package/dist/core/lifecycle/engine.js +1750 -0
  440. package/dist/core/lifecycle/engine.js.map +1 -0
  441. package/dist/core/lifecycle/evaluate.d.ts +19 -0
  442. package/dist/core/lifecycle/evaluate.js +77 -0
  443. package/dist/core/lifecycle/evaluate.js.map +1 -0
  444. package/dist/core/lifecycle/intent.d.ts +11 -0
  445. package/dist/core/lifecycle/intent.js +88 -0
  446. package/dist/core/lifecycle/intent.js.map +1 -0
  447. package/dist/core/lifecycle/monitor.d.ts +138 -0
  448. package/dist/core/lifecycle/monitor.js +616 -0
  449. package/dist/core/lifecycle/monitor.js.map +1 -0
  450. package/dist/core/lifecycle/observations.d.ts +17 -0
  451. package/dist/core/lifecycle/observations.js +59 -0
  452. package/dist/core/lifecycle/observations.js.map +1 -0
  453. package/dist/core/lifecycle/reconcile.d.ts +58 -0
  454. package/dist/core/lifecycle/reconcile.js +112 -0
  455. package/dist/core/lifecycle/reconcile.js.map +1 -0
  456. package/dist/core/lifecycle/views.d.ts +49 -0
  457. package/dist/core/lifecycle/views.js +57 -0
  458. package/dist/core/lifecycle/views.js.map +1 -0
  459. package/dist/core/lifecycle/workers.d.ts +88 -0
  460. package/dist/core/lifecycle/workers.js +347 -0
  461. package/dist/core/lifecycle/workers.js.map +1 -0
  462. package/dist/core/model/address.d.ts +32 -0
  463. package/dist/core/model/address.js +43 -0
  464. package/dist/core/model/address.js.map +1 -0
  465. package/dist/core/model/amount.d.ts +25 -0
  466. package/dist/core/model/amount.js +102 -0
  467. package/dist/core/model/amount.js.map +1 -0
  468. package/dist/core/model/asset.d.ts +28 -0
  469. package/dist/core/model/asset.js +47 -0
  470. package/dist/core/model/asset.js.map +1 -0
  471. package/dist/core/model/capability.d.ts +3 -0
  472. package/dist/core/model/capability.js +18 -0
  473. package/dist/core/model/capability.js.map +1 -0
  474. package/dist/core/model/chain.d.ts +63 -0
  475. package/dist/core/model/chain.js +8 -0
  476. package/dist/core/model/chain.js.map +1 -0
  477. package/dist/core/model/fee.d.ts +36 -0
  478. package/dist/core/model/fee.js +17 -0
  479. package/dist/core/model/fee.js.map +1 -0
  480. package/dist/core/model/ids.d.ts +38 -0
  481. package/dist/core/model/ids.js +14 -0
  482. package/dist/core/model/ids.js.map +1 -0
  483. package/dist/core/model/intent.d.ts +63 -0
  484. package/dist/core/model/intent.js +81 -0
  485. package/dist/core/model/intent.js.map +1 -0
  486. package/dist/core/model/ordering.d.ts +28 -0
  487. package/dist/core/model/ordering.js +29 -0
  488. package/dist/core/model/ordering.js.map +1 -0
  489. package/dist/core/model/transaction.d.ts +123 -0
  490. package/dist/{type/lib-types.js → core/model/transaction.js} +1 -1
  491. package/dist/core/model/transaction.js.map +1 -0
  492. package/dist/core/observe/scanner.d.ts +135 -0
  493. package/dist/core/observe/scanner.js +358 -0
  494. package/dist/core/observe/scanner.js.map +1 -0
  495. package/dist/core/ordering/reservations.d.ts +16 -0
  496. package/dist/core/ordering/reservations.js +53 -0
  497. package/dist/core/ordering/reservations.js.map +1 -0
  498. package/dist/core/ordering/sequence.d.ts +61 -0
  499. package/dist/core/ordering/sequence.js +155 -0
  500. package/dist/core/ordering/sequence.js.map +1 -0
  501. package/dist/core/registry/adapters.d.ts +10 -0
  502. package/dist/core/registry/adapters.js +56 -0
  503. package/dist/core/registry/adapters.js.map +1 -0
  504. package/dist/core/registry/assets.d.ts +18 -0
  505. package/dist/core/registry/assets.js +90 -0
  506. package/dist/core/registry/assets.js.map +1 -0
  507. package/dist/core/registry/chains.d.ts +10 -0
  508. package/dist/core/registry/chains.js +80 -0
  509. package/dist/core/registry/chains.js.map +1 -0
  510. package/dist/core/registry/plugin.d.ts +41 -0
  511. package/dist/core/registry/plugin.js +109 -0
  512. package/dist/core/registry/plugin.js.map +1 -0
  513. package/dist/core/registry/providers.d.ts +31 -0
  514. package/dist/core/registry/providers.js +43 -0
  515. package/dist/core/registry/providers.js.map +1 -0
  516. package/dist/core/registry/schemes.d.ts +30 -0
  517. package/dist/core/registry/schemes.js +84 -0
  518. package/dist/core/registry/schemes.js.map +1 -0
  519. package/dist/core/secret/fragments.d.ts +33 -0
  520. package/dist/core/secret/fragments.js +110 -0
  521. package/dist/core/secret/fragments.js.map +1 -0
  522. package/dist/core/secret/redact.d.ts +10 -0
  523. package/dist/core/secret/redact.js +110 -0
  524. package/dist/core/secret/redact.js.map +1 -0
  525. package/dist/core/secret/secret.d.ts +14 -0
  526. package/dist/core/secret/secret.js +42 -0
  527. package/dist/core/secret/secret.js.map +1 -0
  528. package/dist/core/signing/callback.d.ts +10 -0
  529. package/dist/core/signing/callback.js +22 -0
  530. package/dist/core/signing/callback.js.map +1 -0
  531. package/dist/core/signing/guard.d.ts +18 -0
  532. package/dist/core/signing/guard.js +72 -0
  533. package/dist/core/signing/guard.js.map +1 -0
  534. package/dist/core/signing/hd.d.ts +36 -0
  535. package/dist/core/signing/hd.js +167 -0
  536. package/dist/core/signing/hd.js.map +1 -0
  537. package/dist/core/signing/local.d.ts +48 -0
  538. package/dist/core/signing/local.js +190 -0
  539. package/dist/core/signing/local.js.map +1 -0
  540. package/dist/core/signing/orchestrator.d.ts +40 -0
  541. package/dist/core/signing/orchestrator.js +300 -0
  542. package/dist/core/signing/orchestrator.js.map +1 -0
  543. package/dist/core/signing/types.d.ts +64 -0
  544. package/dist/core/signing/types.js +3 -0
  545. package/dist/core/signing/types.js.map +1 -0
  546. package/dist/core/signing/wallet.d.ts +48 -0
  547. package/dist/core/signing/wallet.js +161 -0
  548. package/dist/core/signing/wallet.js.map +1 -0
  549. package/dist/core/store/clone.d.ts +25 -0
  550. package/dist/core/store/clone.js +71 -0
  551. package/dist/core/store/clone.js.map +1 -0
  552. package/dist/core/store/format.d.ts +20 -0
  553. package/dist/core/store/format.js +86 -0
  554. package/dist/core/store/format.js.map +1 -0
  555. package/dist/core/store/memory.d.ts +38 -0
  556. package/dist/core/store/memory.js +325 -0
  557. package/dist/core/store/memory.js.map +1 -0
  558. package/dist/core/store/types.d.ts +258 -0
  559. package/dist/core/store/types.js +119 -0
  560. package/dist/core/store/types.js.map +1 -0
  561. package/dist/core/transport/backoff.d.ts +8 -0
  562. package/dist/core/transport/backoff.js +27 -0
  563. package/dist/core/transport/backoff.js.map +1 -0
  564. package/dist/core/transport/circuit.d.ts +25 -0
  565. package/dist/core/transport/circuit.js +61 -0
  566. package/dist/core/transport/circuit.js.map +1 -0
  567. package/dist/core/transport/http-transport.d.ts +30 -0
  568. package/dist/core/transport/http-transport.js +1703 -0
  569. package/dist/core/transport/http-transport.js.map +1 -0
  570. package/dist/core/transport/rate-limit.d.ts +27 -0
  571. package/dist/core/transport/rate-limit.js +78 -0
  572. package/dist/core/transport/rate-limit.js.map +1 -0
  573. package/dist/core/transport/stale-view.d.ts +11 -0
  574. package/dist/core/transport/stale-view.js +17 -0
  575. package/dist/core/transport/stale-view.js.map +1 -0
  576. package/dist/core/transport/types.d.ts +159 -0
  577. package/dist/core/transport/types.js +6 -0
  578. package/dist/core/transport/types.js.map +1 -0
  579. package/dist/core/util/bytes.d.ts +9 -0
  580. package/dist/core/util/bytes.js +40 -0
  581. package/dist/core/util/bytes.js.map +1 -0
  582. package/dist/core/util/clock.d.ts +6 -0
  583. package/dist/core/util/clock.js +26 -0
  584. package/dist/core/util/clock.js.map +1 -0
  585. package/dist/core/util/freeze.d.ts +8 -0
  586. package/dist/core/util/freeze.js +31 -0
  587. package/dist/core/util/freeze.js.map +1 -0
  588. package/dist/core/util/json.d.ts +35 -0
  589. package/dist/core/util/json.js +174 -0
  590. package/dist/core/util/json.js.map +1 -0
  591. package/dist/core/util/names.d.ts +27 -0
  592. package/dist/core/util/names.js +56 -0
  593. package/dist/core/util/names.js.map +1 -0
  594. package/dist/index.d.ts +65 -14
  595. package/dist/index.js +107 -49
  596. package/dist/index.js.map +1 -1
  597. package/dist/native.d.ts +21 -0
  598. package/dist/native.js +44 -0
  599. package/dist/native.js.map +1 -0
  600. package/dist/testing/contracts/api.d.ts +12 -0
  601. package/dist/testing/contracts/api.js +58 -0
  602. package/dist/testing/contracts/api.js.map +1 -0
  603. package/dist/testing/contracts/cursors.d.ts +6 -0
  604. package/dist/testing/contracts/cursors.js +43 -0
  605. package/dist/testing/contracts/cursors.js.map +1 -0
  606. package/dist/testing/contracts/locks.d.ts +10 -0
  607. package/dist/testing/contracts/locks.js +63 -0
  608. package/dist/testing/contracts/locks.js.map +1 -0
  609. package/dist/testing/contracts/operations.d.ts +21 -0
  610. package/dist/testing/contracts/operations.js +737 -0
  611. package/dist/testing/contracts/operations.js.map +1 -0
  612. package/dist/testing/contracts/sequences.d.ts +6 -0
  613. package/dist/testing/contracts/sequences.js +68 -0
  614. package/dist/testing/contracts/sequences.js.map +1 -0
  615. package/dist/testing/env.d.ts +68 -0
  616. package/dist/testing/env.js +105 -0
  617. package/dist/testing/env.js.map +1 -0
  618. package/dist/testing/fake-chain.d.ts +118 -0
  619. package/dist/testing/fake-chain.js +536 -0
  620. package/dist/testing/fake-chain.js.map +1 -0
  621. package/dist/testing/fake-clock.d.ts +15 -0
  622. package/dist/testing/fake-clock.js +86 -0
  623. package/dist/testing/fake-clock.js.map +1 -0
  624. package/dist/testing/fake-driver.d.ts +15 -0
  625. package/dist/testing/fake-driver.js +458 -0
  626. package/dist/testing/fake-driver.js.map +1 -0
  627. package/dist/testing/fake-fetch.d.ts +32 -0
  628. package/dist/testing/fake-fetch.js +81 -0
  629. package/dist/testing/fake-fetch.js.map +1 -0
  630. package/dist/testing/fake-plugin.d.ts +30 -0
  631. package/dist/testing/fake-plugin.js +66 -0
  632. package/dist/testing/fake-plugin.js.map +1 -0
  633. package/dist/testing/faulty-store.d.ts +38 -0
  634. package/dist/testing/faulty-store.js +71 -0
  635. package/dist/testing/faulty-store.js.map +1 -0
  636. package/dist/testing/generation.d.ts +60 -0
  637. package/dist/testing/generation.js +252 -0
  638. package/dist/testing/generation.js.map +1 -0
  639. package/dist/testing/index.d.ts +28 -0
  640. package/dist/testing/index.js +51 -0
  641. package/dist/testing/index.js.map +1 -0
  642. package/package.json +198 -45
  643. package/dist/libs/eth/account.d.ts +0 -9
  644. package/dist/libs/eth/account.js +0 -58
  645. package/dist/libs/eth/account.js.map +0 -1
  646. package/dist/libs/eth/contract.d.ts +0 -7
  647. package/dist/libs/eth/contract.js +0 -42
  648. package/dist/libs/eth/contract.js.map +0 -1
  649. package/dist/libs/eth/index.d.ts +0 -24
  650. package/dist/libs/eth/index.js +0 -72
  651. package/dist/libs/eth/index.js.map +0 -1
  652. package/dist/libs/eth/transact.d.ts +0 -7
  653. package/dist/libs/eth/transact.js +0 -26
  654. package/dist/libs/eth/transact.js.map +0 -1
  655. package/dist/libs/index.d.ts +0 -2
  656. package/dist/libs/index.js +0 -19
  657. package/dist/libs/index.js.map +0 -1
  658. package/dist/libs/trx/account.d.ts +0 -9
  659. package/dist/libs/trx/account.js +0 -55
  660. package/dist/libs/trx/account.js.map +0 -1
  661. package/dist/libs/trx/contract.d.ts +0 -7
  662. package/dist/libs/trx/contract.js +0 -27
  663. package/dist/libs/trx/contract.js.map +0 -1
  664. package/dist/libs/trx/index.d.ts +0 -22
  665. package/dist/libs/trx/index.js +0 -64
  666. package/dist/libs/trx/index.js.map +0 -1
  667. package/dist/libs/trx/transact.d.ts +0 -7
  668. package/dist/libs/trx/transact.js +0 -26
  669. package/dist/libs/trx/transact.js.map +0 -1
  670. package/dist/tool/common.d.ts +0 -28
  671. package/dist/tool/common.js +0 -33
  672. package/dist/tool/common.js.map +0 -1
  673. package/dist/tool/eth-tools.d.ts +0 -3
  674. package/dist/tool/eth-tools.js +0 -33
  675. package/dist/tool/eth-tools.js.map +0 -1
  676. package/dist/tool/index.d.ts +0 -5
  677. package/dist/tool/index.js +0 -22
  678. package/dist/tool/index.js.map +0 -1
  679. package/dist/tool/logging.d.ts +0 -3
  680. package/dist/tool/logging.js +0 -11
  681. package/dist/tool/logging.js.map +0 -1
  682. package/dist/tool/options.d.ts +0 -6
  683. package/dist/tool/options.js +0 -41
  684. package/dist/tool/options.js.map +0 -1
  685. package/dist/tool/trx-tools.d.ts +0 -3
  686. package/dist/tool/trx-tools.js +0 -20
  687. package/dist/tool/trx-tools.js.map +0 -1
  688. package/dist/type/account.d.ts +0 -9
  689. package/dist/type/account.js.map +0 -1
  690. package/dist/type/common.d.ts +0 -18
  691. package/dist/type/common.js.map +0 -1
  692. package/dist/type/contract.d.ts +0 -10
  693. package/dist/type/contract.js.map +0 -1
  694. package/dist/type/index.d.ts +0 -5
  695. package/dist/type/index.js +0 -22
  696. package/dist/type/index.js.map +0 -1
  697. package/dist/type/lib-types.d.ts +0 -9
  698. package/dist/type/lib-types.js.map +0 -1
  699. package/dist/type/transact.d.ts +0 -7
  700. package/dist/type/transact.js.map +0 -1
@@ -0,0 +1,498 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EsploraClient = exports.isHash = exports.MAX_MONEY = exports.PREVIOUS_TX_CACHE = void 0;
4
+ exports.malformed = malformed;
5
+ exports.isNotFound = isNotFound;
6
+ exports.parseHeight = parseHeight;
7
+ exports.parseHash = parseHash;
8
+ exports.parseStatus = parseStatus;
9
+ exports.parseTx = parseTx;
10
+ exports.parseOutspend = parseOutspend;
11
+ exports.parseFeeEstimates = parseFeeEstimates;
12
+ /**
13
+ * The Esplora REST API, sent directly over the core transport. Every call carries the
14
+ * calling driver method's tags and a `route` template with no identifiers in it, which
15
+ * events and logs show instead of the path. Answers are validated strictly: a malformed
16
+ * one is a retryable `ProviderError('PROVIDER_UNAVAILABLE')`, a missing or ill-typed
17
+ * field is malformed and never a default, an answer for another id than the one asked for is
18
+ * refused, and a 404 is `null`. Chain data is read as the chain allows it, never bounded by
19
+ * what this library builds (lenient readers). Chain reads use the `rpc` transport; address
20
+ * reads use the `indexer`. Only raw transactions and blocks are decoded, by the strict
21
+ * linear readers (`rawtx.ts`, `rawblock.ts`), to bind them to their txid or block hash.
22
+ */
23
+ const error_1 = require("../../core/errors/error");
24
+ const codec_1 = require("./codec");
25
+ const rawblock_1 = require("./rawblock");
26
+ const rawtx_1 = require("./rawtx");
27
+ const HEX64 = /^[0-9a-f]{64}$/;
28
+ /**
29
+ * The previous transactions one client keeps, by count and by bytes without the
30
+ * witness (a larger one is not kept). A typical one is a few hundred bytes.
31
+ */
32
+ exports.PREVIOUS_TX_CACHE = Object.freeze({ entries: 1_000, bytes: 8_000_000 });
33
+ /** Bitcoin Core's `MAX_MONEY`: no output, and no balance, is larger. */
34
+ exports.MAX_MONEY = 2100000000000000n;
35
+ /**
36
+ * Lowercase hex of whole bytes. A flat character class, not `([0-9a-f]{2})+`: that pattern
37
+ * overflows V8's regexp stack on the hex of a transaction of about 3.5 MB, which is valid.
38
+ */
39
+ const isHex = (value) => value.length % 2 === 0 && /^[0-9a-f]*$/.test(value);
40
+ function malformed(what) {
41
+ return new error_1.ProviderError('PROVIDER_UNAVAILABLE', `malformed Esplora answer: ${what}`);
42
+ }
43
+ /** A definitive 404 (not an ambiguous or retried failure): the resource is not there. */
44
+ function isNotFound(error) {
45
+ return ((0, error_1.isCryptoAioError)(error, 'RPC_ERROR') &&
46
+ !error.ambiguous &&
47
+ error.details?.status === 404);
48
+ }
49
+ const record = (value, what) => {
50
+ if (value === null || typeof value !== 'object' || Array.isArray(value))
51
+ throw malformed(what);
52
+ return value;
53
+ };
54
+ const hash = (value, what) => {
55
+ if (typeof value !== 'string' || !HEX64.test(value))
56
+ throw malformed(what);
57
+ return value;
58
+ };
59
+ const integer = (value, what, max = Number.MAX_SAFE_INTEGER) => {
60
+ if (!Number.isSafeInteger(value) || value < 0 || value > max) {
61
+ throw malformed(what);
62
+ }
63
+ return value;
64
+ };
65
+ const sats = (value, what) => BigInt(integer(value, what, Number(exports.MAX_MONEY)));
66
+ const u32 = (value, what) => integer(value, what, 0xffffffff);
67
+ /**
68
+ * A transaction's 32-bit version, which Esplora servers print signed or unsigned, as one
69
+ * signed value (`v | 0`), so both printings agree. Chain data: any version a block holds is
70
+ * read, whatever this library builds (version 2).
71
+ */
72
+ const txVersion = (value) => {
73
+ if (!Number.isSafeInteger(value) ||
74
+ value < -0x80000000 ||
75
+ value > 0xffffffff) {
76
+ throw malformed('tx.version');
77
+ }
78
+ return value | 0;
79
+ };
80
+ /**
81
+ * A cumulative total of an address (every output it ever received or spent), read exactly
82
+ * (`exactIntegers`): a busy address's totals exceed 21 million bitcoin, and may exceed 2^53.
83
+ */
84
+ const total = (value, what) => {
85
+ if (typeof value === 'bigint') {
86
+ if (value < 0n)
87
+ throw malformed(what);
88
+ return value;
89
+ }
90
+ return BigInt(integer(value, what));
91
+ };
92
+ function parseHeight(text) {
93
+ if (typeof text !== 'string' || !/^(0|[1-9][0-9]{0,9})$/.test(text.trim())) {
94
+ throw malformed('block height');
95
+ }
96
+ return BigInt(text.trim());
97
+ }
98
+ function parseHash(text) {
99
+ return hash(typeof text === 'string' ? text.trim() : text, 'block hash');
100
+ }
101
+ function parseStatus(value) {
102
+ const status = record(value, 'status');
103
+ if (typeof status.confirmed !== 'boolean')
104
+ throw malformed('status.confirmed');
105
+ if (!status.confirmed)
106
+ return { confirmed: false };
107
+ return {
108
+ confirmed: true,
109
+ blockHeight: BigInt(integer(status.block_height, 'status.block_height')),
110
+ blockHash: hash(status.block_hash, 'status.block_hash'),
111
+ ...(status.block_time !== undefined && status.block_time !== null
112
+ ? { blockTime: integer(status.block_time, 'status.block_time') }
113
+ : {}),
114
+ };
115
+ }
116
+ function parseOutput(value) {
117
+ const output = record(value, 'vout');
118
+ if (typeof output.scriptpubkey !== 'string' || !isHex(output.scriptpubkey)) {
119
+ throw malformed('vout.scriptpubkey');
120
+ }
121
+ if (typeof output.scriptpubkey_type !== 'string')
122
+ throw malformed('vout.scriptpubkey_type');
123
+ const address = output.scriptpubkey_address;
124
+ if (address !== undefined && address !== null && typeof address !== 'string') {
125
+ throw malformed('vout.scriptpubkey_address');
126
+ }
127
+ return {
128
+ script: output.scriptpubkey,
129
+ type: output.scriptpubkey_type,
130
+ ...(typeof address === 'string' ? { address } : {}),
131
+ value: sats(output.value, 'vout.value'),
132
+ };
133
+ }
134
+ function parseInput(value) {
135
+ const input = record(value, 'vin');
136
+ // It decides whether the input has a previous output and the transaction a fee.
137
+ if (typeof input.is_coinbase !== 'boolean')
138
+ throw malformed('vin.is_coinbase');
139
+ const coinbase = input.is_coinbase;
140
+ return {
141
+ txid: hash(input.txid, 'vin.txid'),
142
+ vout: u32(input.vout, 'vin.vout'),
143
+ coinbase,
144
+ sequence: u32(input.sequence, 'vin.sequence'),
145
+ ...(coinbase ? {} : { prevout: parseOutput(input.prevout) }),
146
+ };
147
+ }
148
+ function parseTx(value) {
149
+ const tx = record(value, 'tx');
150
+ if (!Array.isArray(tx.vin) || !Array.isArray(tx.vout))
151
+ throw malformed('tx.vin/vout');
152
+ return {
153
+ txid: hash(tx.txid, 'tx.txid'),
154
+ version: txVersion(tx.version),
155
+ locktime: u32(tx.locktime, 'tx.locktime'),
156
+ weight: integer(tx.weight, 'tx.weight'),
157
+ // Esplora answers `fee` for every transaction (0 for a coinbase): missing is malformed.
158
+ fee: sats(tx.fee, 'tx.fee'),
159
+ vin: tx.vin.map(parseInput),
160
+ vout: tx.vout.map(parseOutput),
161
+ status: parseStatus(tx.status),
162
+ };
163
+ }
164
+ function parseBlock(value) {
165
+ const block = record(value, 'block');
166
+ const height = BigInt(integer(block.height, 'block.height'));
167
+ return {
168
+ hash: hash(block.id, 'block.id'),
169
+ height,
170
+ parentHash: height === 0n && block.previousblockhash === null
171
+ ? '0'.repeat(64)
172
+ : hash(block.previousblockhash, 'block.previousblockhash'),
173
+ timestamp: integer(block.timestamp, 'block.timestamp'),
174
+ txCount: integer(block.tx_count, 'block.tx_count'),
175
+ };
176
+ }
177
+ function parseOutspend(value) {
178
+ const spend = record(value, 'outspend');
179
+ if (typeof spend.spent !== 'boolean')
180
+ throw malformed('outspend.spent');
181
+ if (!spend.spent)
182
+ return { spent: false };
183
+ return {
184
+ spent: true,
185
+ txid: hash(spend.txid, 'outspend.txid'),
186
+ vin: u32(spend.vin, 'outspend.vin'),
187
+ status: parseStatus(spend.status),
188
+ };
189
+ }
190
+ function parseUtxo(value) {
191
+ const utxo = record(value, 'utxo');
192
+ return {
193
+ txid: hash(utxo.txid, 'utxo.txid'),
194
+ vout: u32(utxo.vout, 'utxo.vout'),
195
+ value: sats(utxo.value, 'utxo.value'),
196
+ status: parseStatus(utxo.status),
197
+ };
198
+ }
199
+ function list(value, what, parse) {
200
+ if (!Array.isArray(value))
201
+ throw malformed(what);
202
+ return value.map(parse);
203
+ }
204
+ /** Esplora's `/fee-estimates`: confirmation target (blocks) → sat/vB (a float). */
205
+ function parseFeeEstimates(value) {
206
+ const estimates = record(value, 'fee-estimates');
207
+ const out = new Map();
208
+ for (const [target, rate] of Object.entries(estimates)) {
209
+ if (!/^[1-9][0-9]{0,3}$/.test(target))
210
+ throw malformed('fee-estimates target');
211
+ if (typeof rate !== 'number' || !Number.isFinite(rate) || rate < 0 || rate > 1e7) {
212
+ throw malformed('fee-estimates rate');
213
+ }
214
+ out.set(Number(target), rate);
215
+ }
216
+ return out;
217
+ }
218
+ /** Whether a caller's id is a txid or block hash (64 lowercase hex characters). */
219
+ const isHash = (value) => typeof value === 'string' && HEX64.test(value);
220
+ exports.isHash = isHash;
221
+ /**
222
+ * A URL path segment from a caller must be exactly an id or an address, so no `..`, `/`
223
+ * or query can reach another route. The reader maps a malformed id to "not found" first.
224
+ */
225
+ function segment(value, kind) {
226
+ if (kind === 'id' && !(0, exports.isHash)(value)) {
227
+ throw new error_1.ValidationError('INVALID_INTENT', 'a transaction or block id must be 64 lowercase hex digits');
228
+ }
229
+ if (kind === 'address' && !/^[0-9A-Za-z]{1,90}$/.test(value)) {
230
+ throw new error_1.ValidationError('INVALID_ADDRESS', 'invalid Bitcoin address');
231
+ }
232
+ return value;
233
+ }
234
+ /** The txid of strictly decoded transaction hex, or `undefined`. */
235
+ function txidOf(hex) {
236
+ try {
237
+ return { txid: (0, codec_1.txidOfHex)(hex) };
238
+ }
239
+ catch {
240
+ return undefined;
241
+ }
242
+ }
243
+ /** The txid and outputs (copied) of strictly decoded transaction hex, or `undefined`. */
244
+ function outputsOfHex(hex) {
245
+ const tx = (0, rawtx_1.readTxHex)(hex);
246
+ return (tx && {
247
+ txid: tx.txid,
248
+ outputs: tx.outputs.map(({ value, script }) => ({
249
+ value,
250
+ script: Uint8Array.from(script),
251
+ })),
252
+ });
253
+ }
254
+ /** Transactions kept per txid, oldest out first, by count and by bytes without witness. */
255
+ class TxCache {
256
+ bounds;
257
+ #txs = new Map();
258
+ #bytes = 0;
259
+ constructor(bounds) {
260
+ this.bounds = bounds;
261
+ }
262
+ has(txid) {
263
+ return this.#txs.has(txid);
264
+ }
265
+ /** The transaction, now the most recently used, or `undefined`. */
266
+ get(txid) {
267
+ const tx = this.#txs.get(txid);
268
+ if (tx) {
269
+ this.#txs.delete(txid);
270
+ this.#txs.set(txid, tx);
271
+ }
272
+ return tx;
273
+ }
274
+ set(tx) {
275
+ if (tx.bytes.length > this.bounds.bytes)
276
+ return;
277
+ const old = this.#txs.get(tx.txid);
278
+ if (old) {
279
+ this.#txs.delete(tx.txid);
280
+ this.#bytes -= old.bytes.length;
281
+ }
282
+ this.#txs.set(tx.txid, tx);
283
+ this.#bytes += tx.bytes.length;
284
+ // The oldest go first (a Map iterates in insertion order).
285
+ for (const [id, entry] of this.#txs) {
286
+ if (this.#txs.size <= this.bounds.entries && this.#bytes <= this.bounds.bytes)
287
+ break;
288
+ this.#txs.delete(id);
289
+ this.#bytes -= entry.bytes.length;
290
+ }
291
+ }
292
+ }
293
+ /** One Esplora endpoint family (the `rpc` transport) and its address index (`indexer`). */
294
+ class EsploraClient {
295
+ chain;
296
+ indexer;
297
+ cache;
298
+ #previous;
299
+ #own;
300
+ constructor(chain, indexer, cache = exports.PREVIOUS_TX_CACHE) {
301
+ this.chain = chain;
302
+ this.indexer = indexer;
303
+ this.cache = cache;
304
+ this.#previous = new TxCache(cache);
305
+ this.#own = new TxCache(cache);
306
+ }
307
+ #get(transport, path, route, tags, responseType = 'json', exactIntegers = false) {
308
+ const request = { method: 'GET', path, route, responseType };
309
+ return transport.http(request, exactIntegers ? { ...tags, exactIntegers } : tags);
310
+ }
311
+ async #orNull(work) {
312
+ try {
313
+ return await work();
314
+ }
315
+ catch (error) {
316
+ if (isNotFound(error))
317
+ return null;
318
+ throw error;
319
+ }
320
+ }
321
+ async tipHeight(tags) {
322
+ return parseHeight(await this.#get(this.chain, '/blocks/tip/height', '/blocks/tip/height', tags, 'text'));
323
+ }
324
+ /** The hash of the block at `height` on this endpoint's best chain, or `null` above its tip. */
325
+ blockHashAt(height, tags) {
326
+ return this.#orNull(async () => parseHash(await this.#get(this.chain, `/block-height/${height}`, '/block-height/:height', tags, 'text')));
327
+ }
328
+ block(blockHash, tags) {
329
+ return this.#orNull(async () => {
330
+ const block = parseBlock(await this.#get(this.chain, `/block/${segment(blockHash, 'id')}`, '/block/:hash', tags));
331
+ // The answer must be the block asked for.
332
+ if (block.hash !== blockHash)
333
+ throw malformed('block.id');
334
+ return block;
335
+ });
336
+ }
337
+ /**
338
+ * `/block/:hash/raw`, the block's own bytes, read strictly once (`rawblock.ts`) and bound to
339
+ * `blockHash`: bytes that do not decode are malformed, and bytes whose header hashes to
340
+ * another block, or whose transactions are not the ones that header commits to, are a
341
+ * retryable `PROVIDER_INCONSISTENT`. So no endpoint can add, drop or alter a transaction of
342
+ * a block whose hash is right. A 404 (a backend that does not have the block) is `null`.
343
+ */
344
+ rawBlock(blockHash, tags) {
345
+ return this.#orNull(async () => {
346
+ const answer = await this.#get(this.chain, `/block/${segment(blockHash, 'id')}/raw`, '/block/:hash/raw', tags, 'bytes');
347
+ const block = answer instanceof Uint8Array ? (0, rawblock_1.readBlock)(answer) : undefined;
348
+ if (!block)
349
+ throw malformed('raw block');
350
+ if (block.hash !== blockHash) {
351
+ throw new error_1.ProviderError('PROVIDER_INCONSISTENT', 'the block bytes do not hash to the block asked for', { retryable: true });
352
+ }
353
+ if (!(0, rawblock_1.commitsToTransactions)(block)) {
354
+ throw new error_1.ProviderError('PROVIDER_INCONSISTENT', "the block's transactions are not the ones its header commits to", { retryable: true });
355
+ }
356
+ return block;
357
+ });
358
+ }
359
+ async blockTxids(blockHash, tags) {
360
+ const ids = await this.#get(this.chain, `/block/${segment(blockHash, 'id')}/txids`, '/block/:hash/txids', tags);
361
+ return list(ids, 'txids', (id) => hash(id, 'txid'));
362
+ }
363
+ /** Up to 25 transactions of a block from `start` (a multiple of 25). */
364
+ async blockTxs(blockHash, start, tags) {
365
+ const txs = await this.#get(this.chain, `/block/${segment(blockHash, 'id')}/txs/${start}`, '/block/:hash/txs/:start', tags);
366
+ return list(txs, 'block txs', parseTx);
367
+ }
368
+ tx(txid, tags) {
369
+ return this.#orNull(async () => {
370
+ const tx = parseTx(await this.#get(this.chain, `/tx/${segment(txid, 'id')}`, '/tx/:txid', tags));
371
+ // The answer must be the transaction asked for.
372
+ if (tx.txid !== txid)
373
+ throw malformed('tx.txid');
374
+ return tx;
375
+ });
376
+ }
377
+ /**
378
+ * `/tx/:txid/hex`, decoded strictly once and bound to `txid`: bytes that do not decode are
379
+ * malformed, and the bytes of another transaction are a retryable `PROVIDER_INCONSISTENT`,
380
+ * so a garbled answer is never taken for the caller's error. The decoder's cap is the
381
+ * largest transaction a block can hold, never what this library builds. Under
382
+ * a quorum, each endpoint's answer is keyed on the txid its bytes hash to, and the answer
383
+ * the quorum returns is not decoded again.
384
+ */
385
+ async #rawTx(txid, tags, decode) {
386
+ const decoded = new Map();
387
+ const read = (answer) => {
388
+ const hex = typeof answer === 'string' ? answer.trim() : '';
389
+ if (!decoded.has(hex)) {
390
+ decoded.set(hex, hex.length > 0 && isHex(hex) ? decode(hex) : undefined);
391
+ }
392
+ return { hex, tx: decoded.get(hex) };
393
+ };
394
+ const keyed = tags.quorum === undefined
395
+ ? tags
396
+ : {
397
+ ...tags,
398
+ // A throwing key counts as a disagreement.
399
+ quorumKey: (answer) => {
400
+ const { tx } = read(answer);
401
+ if (!tx)
402
+ throw malformed('tx hex');
403
+ return tx.txid;
404
+ },
405
+ };
406
+ const answer = await this.#get(this.chain, `/tx/${segment(txid, 'id')}/hex`, '/tx/:txid/hex', keyed, 'text');
407
+ const { hex, tx } = read(answer);
408
+ if (!tx)
409
+ throw malformed('tx hex');
410
+ if (tx.txid !== txid) {
411
+ throw new error_1.ProviderError('PROVIDER_INCONSISTENT', 'the transaction bytes do not hash to the id asked for', { retryable: true });
412
+ }
413
+ return { hex, tx };
414
+ }
415
+ /** The raw transaction, as hex, bound to `txid` (see `#rawTx`). */
416
+ txHex(txid, tags) {
417
+ return this.#orNull(async () => (await this.#rawTx(txid, tags, txidOf)).hex);
418
+ }
419
+ /**
420
+ * An input's previous transaction, decoded once and bound to `txid` (see
421
+ * `#rawTx`). Its bytes authenticate themselves, so it is kept per txid, whatever endpoint
422
+ * served it, in a bounded cache: a replacement's inputs are read once per client.
423
+ */
424
+ async previousTx(txid, tags) {
425
+ const known = this.#own.get(txid) ?? this.#previous.get(txid);
426
+ if (known)
427
+ return known;
428
+ const found = await this.#orNull(async () => (await this.#rawTx(txid, tags, codec_1.previousTxOf)).tx);
429
+ if (found)
430
+ this.#previous.set(found);
431
+ return found;
432
+ }
433
+ /**
434
+ * The outputs of transaction `txid`, from its bytes, bound to `txid` (see `#rawTx`), or
435
+ * `null` when the endpoint does not have it: what an input naming `txid:vout` spends. A
436
+ * previous transaction this client keeps answers without a read; one read here is not kept,
437
+ * since a block scan reads thousands, which would evict a build's.
438
+ */
439
+ async outputsOf(txid, tags) {
440
+ const known = this.#own.get(txid) ?? this.#previous.get(txid);
441
+ if (known)
442
+ return known.outputs;
443
+ return this.#orNull(async () => (await this.#rawTx(txid, tags, outputsOfHex)).tx.outputs);
444
+ }
445
+ /**
446
+ * A transaction this client sent for an Attempt and a node took. Its bytes are
447
+ * known here, so its outputs are not an indexer's word even before a block holds it, and
448
+ * under `minInputConfirmations: 0` they may be spent unconfirmed. Kept like the cache.
449
+ */
450
+ rememberOwn(tx) {
451
+ this.#own.set(tx);
452
+ }
453
+ isOwn(txid) {
454
+ return this.#own.has(txid);
455
+ }
456
+ async outspend(txid, vout, tags) {
457
+ return parseOutspend(await this.#get(this.chain, `/tx/${segment(txid, 'id')}/outspend/${vout}`, '/tx/:txid/outspend/:vout', tags));
458
+ }
459
+ async feeEstimates(tags) {
460
+ return parseFeeEstimates(await this.#get(this.chain, '/fee-estimates', '/fee-estimates', tags));
461
+ }
462
+ /** `POST /tx`: the node's txid on success; a node refusal is the transport's `RPC_ERROR`. */
463
+ async broadcast(hex, tags) {
464
+ const answer = await this.chain.http({ method: 'POST', path: '/tx', route: '/tx', body: hex, responseType: 'text' }, tags);
465
+ if (typeof answer !== 'string' || !HEX64.test(answer.trim())) {
466
+ // The node answered 2xx, so the bytes may have been accepted.
467
+ throw new error_1.ProviderError('PROVIDER_UNAVAILABLE', 'malformed Esplora answer: broadcast txid', {
468
+ ambiguous: true,
469
+ });
470
+ }
471
+ return answer.trim();
472
+ }
473
+ async addressUtxos(address, tags) {
474
+ const utxos = await this.#get(this.indexer, `/address/${segment(address, 'address')}/utxo`, '/address/:address/utxo', tags);
475
+ return list(utxos, 'utxo list', parseUtxo);
476
+ }
477
+ async addressStats(address, tags) {
478
+ const info = record(await this.#get(this.indexer, `/address/${segment(address, 'address')}`, '/address/:address', tags, 'json', true), 'address');
479
+ const chain = record(info.chain_stats, 'chain_stats');
480
+ const funded = total(chain.funded_txo_sum, 'funded_txo_sum');
481
+ const spent = total(chain.spent_txo_sum, 'spent_txo_sum');
482
+ // The totals are unbounded; the balance is the chain's: 0 to 21 million bitcoin.
483
+ if (spent > funded || funded - spent > exports.MAX_MONEY)
484
+ throw malformed('address balance');
485
+ return { funded, spent };
486
+ }
487
+ /** Confirmed history, newest first, 25 per page, after `lastSeen` when given. */
488
+ async addressTxs(address, lastSeen, tags) {
489
+ const base = `/address/${segment(address, 'address')}/txs/chain`;
490
+ const path = lastSeen ? `${base}/${segment(lastSeen, 'id')}` : base;
491
+ const route = lastSeen
492
+ ? '/address/:address/txs/chain/:last_seen_txid'
493
+ : '/address/:address/txs/chain';
494
+ return list(await this.#get(this.indexer, path, route, tags), 'address txs', parseTx);
495
+ }
496
+ }
497
+ exports.EsploraClient = EsploraClient;
498
+ //# sourceMappingURL=esplora.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"esplora.js","sourceRoot":"","sources":["../../../src/adapters/utxo/esplora.ts"],"names":[],"mappings":";;;AAkDA,8BAEC;AAGD,gCAMC;AA+CD,kCAKC;AAED,8BAEC;AAED,kCAYC;AAmCD,0BAcC;AAiBD,sCAUC;AAkBD,8CAWC;AA5OD;;;;;;;;;;GAUG;AACH,mDAIiC;AAEjC,mCAAmE;AACnE,yCAA6E;AAC7E,mCAAoC;AAepC,MAAM,KAAK,GAAG,gBAAgB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,KAAK,GAAG,MAAM,IAAI,MAAM,GAAG,KAAK,GAAG,iBAAS;YAAE,MAAM,SAAS,CAAC,iBAAiB,CAAC,CAAC;QACrF,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAC3B,CAAC;IAED,iFAAiF;IACjF,KAAK,CAAC,UAAU,CACd,OAAe,EACf,QAA4B,EAC5B,IAAkB;QAElB,MAAM,IAAI,GAAG,YAAY,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,YAAY,CAAC;QACjE,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QACpE,MAAM,KAAK,GAAG,QAAQ;YACpB,CAAC,CAAC,6CAA6C;YAC/C,CAAC,CAAC,6BAA6B,CAAC;QAClC,OAAO,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;IACxF,CAAC;CACF;AA9UD,sCA8UC","sourcesContent":["/**\n * The Esplora REST API, sent directly over the core transport. Every call carries the\n * calling driver method's tags and a `route` template with no identifiers in it, which\n * events and logs show instead of the path. Answers are validated strictly: a malformed\n * one is a retryable `ProviderError('PROVIDER_UNAVAILABLE')`, a missing or ill-typed\n * field is malformed and never a default, an answer for another id than the one asked for is\n * refused, and a 404 is `null`. Chain data is read as the chain allows it, never bounded by\n * what this library builds (lenient readers). Chain reads use the `rpc` transport; address\n * reads use the `indexer`. Only raw transactions and blocks are decoded, by the strict\n * linear readers (`rawtx.ts`, `rawblock.ts`), to bind them to their txid or block hash.\n */\nimport {\n ProviderError,\n ValidationError,\n isCryptoAioError,\n} from '../../core/errors/error';\nimport type { HttpRequest, Transport } from '../../core/transport/types';\nimport { previousTxOf, txidOfHex, type PreviousTx } from './codec';\nimport { commitsToTransactions, readBlock, type RawBlock } from './rawblock';\nimport { readTxHex } from './rawtx';\nimport type {\n EsploraAddressStats,\n EsploraBlock,\n EsploraInput,\n EsploraOutput,\n EsploraOutspend,\n EsploraStatus,\n EsploraTx,\n EsploraUtxo,\n UtxoCallTags,\n} from './types';\n\ntype Json = Readonly<Record<string, unknown>>;\n\nconst HEX64 = /^[0-9a-f]{64}$/;\n/**\n * The previous transactions one client keeps, by count and by bytes without the\n * witness (a larger one is not kept). A typical one is a few hundred bytes.\n */\nexport const PREVIOUS_TX_CACHE = Object.freeze({ entries: 1_000, bytes: 8_000_000 });\n/** Bitcoin Core's `MAX_MONEY`: no output, and no balance, is larger. */\nexport const MAX_MONEY = 2_100_000_000_000_000n;\n\n/**\n * Lowercase hex of whole bytes. A flat character class, not `([0-9a-f]{2})+`: that pattern\n * overflows V8's regexp stack on the hex of a transaction of about 3.5 MB, which is valid.\n */\nconst isHex = (value: string): boolean =>\n value.length % 2 === 0 && /^[0-9a-f]*$/.test(value);\n\nexport function malformed(what: string): ProviderError {\n return new ProviderError('PROVIDER_UNAVAILABLE', `malformed Esplora answer: ${what}`);\n}\n\n/** A definitive 404 (not an ambiguous or retried failure): the resource is not there. */\nexport function isNotFound(error: unknown): boolean {\n return (\n isCryptoAioError(error, 'RPC_ERROR') &&\n !error.ambiguous &&\n error.details?.status === 404\n );\n}\n\nconst record = (value: unknown, what: string): Json => {\n if (value === null || typeof value !== 'object' || Array.isArray(value))\n throw malformed(what);\n return value as Json;\n};\nconst hash = (value: unknown, what: string): string => {\n if (typeof value !== 'string' || !HEX64.test(value)) throw malformed(what);\n return value;\n};\nconst integer = (value: unknown, what: string, max = Number.MAX_SAFE_INTEGER): number => {\n if (!Number.isSafeInteger(value) || (value as number) < 0 || (value as number) > max) {\n throw malformed(what);\n }\n return value as number;\n};\nconst sats = (value: unknown, what: string): bigint =>\n BigInt(integer(value, what, Number(MAX_MONEY)));\nconst u32 = (value: unknown, what: string): number => integer(value, what, 0xffffffff);\n/**\n * A transaction's 32-bit version, which Esplora servers print signed or unsigned, as one\n * signed value (`v | 0`), so both printings agree. Chain data: any version a block holds is\n * read, whatever this library builds (version 2).\n */\nconst txVersion = (value: unknown): number => {\n if (\n !Number.isSafeInteger(value) ||\n (value as number) < -0x80000000 ||\n (value as number) > 0xffffffff\n ) {\n throw malformed('tx.version');\n }\n return (value as number) | 0;\n};\n/**\n * A cumulative total of an address (every output it ever received or spent), read exactly\n * (`exactIntegers`): a busy address's totals exceed 21 million bitcoin, and may exceed 2^53.\n */\nconst total = (value: unknown, what: string): bigint => {\n if (typeof value === 'bigint') {\n if (value < 0n) throw malformed(what);\n return value;\n }\n return BigInt(integer(value, what));\n};\n\nexport function parseHeight(text: unknown): bigint {\n if (typeof text !== 'string' || !/^(0|[1-9][0-9]{0,9})$/.test(text.trim())) {\n throw malformed('block height');\n }\n return BigInt(text.trim());\n}\n\nexport function parseHash(text: unknown): string {\n return hash(typeof text === 'string' ? text.trim() : text, 'block hash');\n}\n\nexport function parseStatus(value: unknown): EsploraStatus {\n const status = record(value, 'status');\n if (typeof status.confirmed !== 'boolean') throw malformed('status.confirmed');\n if (!status.confirmed) return { confirmed: false };\n return {\n confirmed: true,\n blockHeight: BigInt(integer(status.block_height, 'status.block_height')),\n blockHash: hash(status.block_hash, 'status.block_hash'),\n ...(status.block_time !== undefined && status.block_time !== null\n ? { blockTime: integer(status.block_time, 'status.block_time') }\n : {}),\n };\n}\n\nfunction parseOutput(value: unknown): EsploraOutput {\n const output = record(value, 'vout');\n if (typeof output.scriptpubkey !== 'string' || !isHex(output.scriptpubkey)) {\n throw malformed('vout.scriptpubkey');\n }\n if (typeof output.scriptpubkey_type !== 'string')\n throw malformed('vout.scriptpubkey_type');\n const address = output.scriptpubkey_address;\n if (address !== undefined && address !== null && typeof address !== 'string') {\n throw malformed('vout.scriptpubkey_address');\n }\n return {\n script: output.scriptpubkey,\n type: output.scriptpubkey_type,\n ...(typeof address === 'string' ? { address } : {}),\n value: sats(output.value, 'vout.value'),\n };\n}\n\nfunction parseInput(value: unknown): EsploraInput {\n const input = record(value, 'vin');\n // It decides whether the input has a previous output and the transaction a fee.\n if (typeof input.is_coinbase !== 'boolean') throw malformed('vin.is_coinbase');\n const coinbase = input.is_coinbase;\n return {\n txid: hash(input.txid, 'vin.txid'),\n vout: u32(input.vout, 'vin.vout'),\n coinbase,\n sequence: u32(input.sequence, 'vin.sequence'),\n ...(coinbase ? {} : { prevout: parseOutput(input.prevout) }),\n };\n}\n\nexport function parseTx(value: unknown): EsploraTx {\n const tx = record(value, 'tx');\n if (!Array.isArray(tx.vin) || !Array.isArray(tx.vout)) throw malformed('tx.vin/vout');\n return {\n txid: hash(tx.txid, 'tx.txid'),\n version: txVersion(tx.version),\n locktime: u32(tx.locktime, 'tx.locktime'),\n weight: integer(tx.weight, 'tx.weight'),\n // Esplora answers `fee` for every transaction (0 for a coinbase): missing is malformed.\n fee: sats(tx.fee, 'tx.fee'),\n vin: tx.vin.map(parseInput),\n vout: tx.vout.map(parseOutput),\n status: parseStatus(tx.status),\n };\n}\n\nfunction parseBlock(value: unknown): EsploraBlock {\n const block = record(value, 'block');\n const height = BigInt(integer(block.height, 'block.height'));\n return {\n hash: hash(block.id, 'block.id'),\n height,\n parentHash:\n height === 0n && block.previousblockhash === null\n ? '0'.repeat(64)\n : hash(block.previousblockhash, 'block.previousblockhash'),\n timestamp: integer(block.timestamp, 'block.timestamp'),\n txCount: integer(block.tx_count, 'block.tx_count'),\n };\n}\n\nexport function parseOutspend(value: unknown): EsploraOutspend {\n const spend = record(value, 'outspend');\n if (typeof spend.spent !== 'boolean') throw malformed('outspend.spent');\n if (!spend.spent) return { spent: false };\n return {\n spent: true,\n txid: hash(spend.txid, 'outspend.txid'),\n vin: u32(spend.vin, 'outspend.vin'),\n status: parseStatus(spend.status),\n };\n}\n\nfunction parseUtxo(value: unknown): EsploraUtxo {\n const utxo = record(value, 'utxo');\n return {\n txid: hash(utxo.txid, 'utxo.txid'),\n vout: u32(utxo.vout, 'utxo.vout'),\n value: sats(utxo.value, 'utxo.value'),\n status: parseStatus(utxo.status),\n };\n}\n\nfunction list<T>(value: unknown, what: string, parse: (item: unknown) => T): T[] {\n if (!Array.isArray(value)) throw malformed(what);\n return value.map(parse);\n}\n\n/** Esplora's `/fee-estimates`: confirmation target (blocks) → sat/vB (a float). */\nexport function parseFeeEstimates(value: unknown): ReadonlyMap<number, number> {\n const estimates = record(value, 'fee-estimates');\n const out = new Map<number, number>();\n for (const [target, rate] of Object.entries(estimates)) {\n if (!/^[1-9][0-9]{0,3}$/.test(target)) throw malformed('fee-estimates target');\n if (typeof rate !== 'number' || !Number.isFinite(rate) || rate < 0 || rate > 1e7) {\n throw malformed('fee-estimates rate');\n }\n out.set(Number(target), rate);\n }\n return out;\n}\n\n/** Whether a caller's id is a txid or block hash (64 lowercase hex characters). */\nexport const isHash = (value: unknown): value is string =>\n typeof value === 'string' && HEX64.test(value);\n\n/**\n * A URL path segment from a caller must be exactly an id or an address, so no `..`, `/`\n * or query can reach another route. The reader maps a malformed id to \"not found\" first.\n */\nfunction segment(value: string, kind: 'id' | 'address'): string {\n if (kind === 'id' && !isHash(value)) {\n throw new ValidationError(\n 'INVALID_INTENT',\n 'a transaction or block id must be 64 lowercase hex digits',\n );\n }\n if (kind === 'address' && !/^[0-9A-Za-z]{1,90}$/.test(value)) {\n throw new ValidationError('INVALID_ADDRESS', 'invalid Bitcoin address');\n }\n return value;\n}\n\n/** The txid of strictly decoded transaction hex, or `undefined`. */\nfunction txidOf(hex: string): { readonly txid: string } | undefined {\n try {\n return { txid: txidOfHex(hex) };\n } catch {\n return undefined;\n }\n}\n\n/** An output as a transaction's bytes hold it: its value, signed as bitcoind reads it. */\nexport interface TxOutput {\n readonly value: bigint;\n readonly script: Uint8Array;\n}\n\n/** The txid and outputs (copied) of strictly decoded transaction hex, or `undefined`. */\nfunction outputsOfHex(\n hex: string,\n): { readonly txid: string; readonly outputs: readonly TxOutput[] } | undefined {\n const tx = readTxHex(hex);\n return (\n tx && {\n txid: tx.txid,\n outputs: tx.outputs.map(({ value, script }) => ({\n value,\n script: Uint8Array.from(script),\n })),\n }\n );\n}\n\n/** Transactions kept per txid, oldest out first, by count and by bytes without witness. */\nclass TxCache {\n readonly #txs = new Map<string, PreviousTx>();\n #bytes = 0;\n\n constructor(\n private readonly bounds: { readonly entries: number; readonly bytes: number },\n ) {}\n\n has(txid: string): boolean {\n return this.#txs.has(txid);\n }\n\n /** The transaction, now the most recently used, or `undefined`. */\n get(txid: string): PreviousTx | undefined {\n const tx = this.#txs.get(txid);\n if (tx) {\n this.#txs.delete(txid);\n this.#txs.set(txid, tx);\n }\n return tx;\n }\n\n set(tx: PreviousTx): void {\n if (tx.bytes.length > this.bounds.bytes) return;\n const old = this.#txs.get(tx.txid);\n if (old) {\n this.#txs.delete(tx.txid);\n this.#bytes -= old.bytes.length;\n }\n this.#txs.set(tx.txid, tx);\n this.#bytes += tx.bytes.length;\n // The oldest go first (a Map iterates in insertion order).\n for (const [id, entry] of this.#txs) {\n if (this.#txs.size <= this.bounds.entries && this.#bytes <= this.bounds.bytes)\n break;\n this.#txs.delete(id);\n this.#bytes -= entry.bytes.length;\n }\n }\n}\n\n/** One Esplora endpoint family (the `rpc` transport) and its address index (`indexer`). */\nexport class EsploraClient {\n readonly #previous: TxCache;\n readonly #own: TxCache;\n\n constructor(\n private readonly chain: Transport,\n private readonly indexer: Transport,\n private readonly cache: {\n readonly entries: number;\n readonly bytes: number;\n } = PREVIOUS_TX_CACHE,\n ) {\n this.#previous = new TxCache(cache);\n this.#own = new TxCache(cache);\n }\n\n #get<T>(\n transport: Transport,\n path: string,\n route: string,\n tags: UtxoCallTags,\n responseType: 'json' | 'text' | 'bytes' = 'json',\n exactIntegers = false,\n ): Promise<T> {\n const request: HttpRequest = { method: 'GET', path, route, responseType };\n return transport.http<T>(request, exactIntegers ? { ...tags, exactIntegers } : tags);\n }\n\n async #orNull<T>(work: () => Promise<T>): Promise<T | null> {\n try {\n return await work();\n } catch (error) {\n if (isNotFound(error)) return null;\n throw error;\n }\n }\n\n async tipHeight(tags: UtxoCallTags): Promise<bigint> {\n return parseHeight(\n await this.#get(\n this.chain,\n '/blocks/tip/height',\n '/blocks/tip/height',\n tags,\n 'text',\n ),\n );\n }\n\n /** The hash of the block at `height` on this endpoint's best chain, or `null` above its tip. */\n blockHashAt(height: bigint, tags: UtxoCallTags): Promise<string | null> {\n return this.#orNull(async () =>\n parseHash(\n await this.#get(\n this.chain,\n `/block-height/${height}`,\n '/block-height/:height',\n tags,\n 'text',\n ),\n ),\n );\n }\n\n block(blockHash: string, tags: UtxoCallTags): Promise<EsploraBlock | null> {\n return this.#orNull(async () => {\n const block = parseBlock(\n await this.#get(\n this.chain,\n `/block/${segment(blockHash, 'id')}`,\n '/block/:hash',\n tags,\n ),\n );\n // The answer must be the block asked for.\n if (block.hash !== blockHash) throw malformed('block.id');\n return block;\n });\n }\n\n /**\n * `/block/:hash/raw`, the block's own bytes, read strictly once (`rawblock.ts`) and bound to\n * `blockHash`: bytes that do not decode are malformed, and bytes whose header hashes to\n * another block, or whose transactions are not the ones that header commits to, are a\n * retryable `PROVIDER_INCONSISTENT`. So no endpoint can add, drop or alter a transaction of\n * a block whose hash is right. A 404 (a backend that does not have the block) is `null`.\n */\n rawBlock(blockHash: string, tags: UtxoCallTags): Promise<RawBlock | null> {\n return this.#orNull(async () => {\n const answer = await this.#get<unknown>(\n this.chain,\n `/block/${segment(blockHash, 'id')}/raw`,\n '/block/:hash/raw',\n tags,\n 'bytes',\n );\n const block = answer instanceof Uint8Array ? readBlock(answer) : undefined;\n if (!block) throw malformed('raw block');\n if (block.hash !== blockHash) {\n throw new ProviderError(\n 'PROVIDER_INCONSISTENT',\n 'the block bytes do not hash to the block asked for',\n { retryable: true },\n );\n }\n if (!commitsToTransactions(block)) {\n throw new ProviderError(\n 'PROVIDER_INCONSISTENT',\n \"the block's transactions are not the ones its header commits to\",\n { retryable: true },\n );\n }\n return block;\n });\n }\n\n async blockTxids(blockHash: string, tags: UtxoCallTags): Promise<string[]> {\n const ids = await this.#get(\n this.chain,\n `/block/${segment(blockHash, 'id')}/txids`,\n '/block/:hash/txids',\n tags,\n );\n return list(ids, 'txids', (id) => hash(id, 'txid'));\n }\n\n /** Up to 25 transactions of a block from `start` (a multiple of 25). */\n async blockTxs(\n blockHash: string,\n start: number,\n tags: UtxoCallTags,\n ): Promise<EsploraTx[]> {\n const txs = await this.#get(\n this.chain,\n `/block/${segment(blockHash, 'id')}/txs/${start}`,\n '/block/:hash/txs/:start',\n tags,\n );\n return list(txs, 'block txs', parseTx);\n }\n\n tx(txid: string, tags: UtxoCallTags): Promise<EsploraTx | null> {\n return this.#orNull(async () => {\n const tx = parseTx(\n await this.#get(this.chain, `/tx/${segment(txid, 'id')}`, '/tx/:txid', tags),\n );\n // The answer must be the transaction asked for.\n if (tx.txid !== txid) throw malformed('tx.txid');\n return tx;\n });\n }\n\n /**\n * `/tx/:txid/hex`, decoded strictly once and bound to `txid`: bytes that do not decode are\n * malformed, and the bytes of another transaction are a retryable `PROVIDER_INCONSISTENT`,\n * so a garbled answer is never taken for the caller's error. The decoder's cap is the\n * largest transaction a block can hold, never what this library builds. Under\n * a quorum, each endpoint's answer is keyed on the txid its bytes hash to, and the answer\n * the quorum returns is not decoded again.\n */\n async #rawTx<T extends { readonly txid: string }>(\n txid: string,\n tags: UtxoCallTags,\n decode: (hex: string) => T | undefined,\n ): Promise<{ readonly hex: string; readonly tx: T }> {\n const decoded = new Map<string, T | undefined>();\n const read = (answer: unknown): { hex: string; tx: T | undefined } => {\n const hex = typeof answer === 'string' ? answer.trim() : '';\n if (!decoded.has(hex)) {\n decoded.set(hex, hex.length > 0 && isHex(hex) ? decode(hex) : undefined);\n }\n return { hex, tx: decoded.get(hex) };\n };\n const keyed: UtxoCallTags =\n tags.quorum === undefined\n ? tags\n : {\n ...tags,\n // A throwing key counts as a disagreement.\n quorumKey: (answer) => {\n const { tx } = read(answer);\n if (!tx) throw malformed('tx hex');\n return tx.txid;\n },\n };\n const answer = await this.#get(\n this.chain,\n `/tx/${segment(txid, 'id')}/hex`,\n '/tx/:txid/hex',\n keyed,\n 'text',\n );\n const { hex, tx } = read(answer);\n if (!tx) throw malformed('tx hex');\n if (tx.txid !== txid) {\n throw new ProviderError(\n 'PROVIDER_INCONSISTENT',\n 'the transaction bytes do not hash to the id asked for',\n { retryable: true },\n );\n }\n return { hex, tx };\n }\n\n /** The raw transaction, as hex, bound to `txid` (see `#rawTx`). */\n txHex(txid: string, tags: UtxoCallTags): Promise<string | null> {\n return this.#orNull(async () => (await this.#rawTx(txid, tags, txidOf)).hex);\n }\n\n /**\n * An input's previous transaction, decoded once and bound to `txid` (see\n * `#rawTx`). Its bytes authenticate themselves, so it is kept per txid, whatever endpoint\n * served it, in a bounded cache: a replacement's inputs are read once per client.\n */\n async previousTx(txid: string, tags: UtxoCallTags): Promise<PreviousTx | null> {\n const known = this.#own.get(txid) ?? this.#previous.get(txid);\n if (known) return known;\n const found = await this.#orNull(\n async () => (await this.#rawTx(txid, tags, previousTxOf)).tx,\n );\n if (found) this.#previous.set(found);\n return found;\n }\n\n /**\n * The outputs of transaction `txid`, from its bytes, bound to `txid` (see `#rawTx`), or\n * `null` when the endpoint does not have it: what an input naming `txid:vout` spends. A\n * previous transaction this client keeps answers without a read; one read here is not kept,\n * since a block scan reads thousands, which would evict a build's.\n */\n async outputsOf(txid: string, tags: UtxoCallTags): Promise<readonly TxOutput[] | null> {\n const known = this.#own.get(txid) ?? this.#previous.get(txid);\n if (known) return known.outputs;\n return this.#orNull(\n async () => (await this.#rawTx(txid, tags, outputsOfHex)).tx.outputs,\n );\n }\n\n /**\n * A transaction this client sent for an Attempt and a node took. Its bytes are\n * known here, so its outputs are not an indexer's word even before a block holds it, and\n * under `minInputConfirmations: 0` they may be spent unconfirmed. Kept like the cache.\n */\n rememberOwn(tx: PreviousTx): void {\n this.#own.set(tx);\n }\n\n isOwn(txid: string): boolean {\n return this.#own.has(txid);\n }\n\n async outspend(\n txid: string,\n vout: number,\n tags: UtxoCallTags,\n ): Promise<EsploraOutspend> {\n return parseOutspend(\n await this.#get(\n this.chain,\n `/tx/${segment(txid, 'id')}/outspend/${vout}`,\n '/tx/:txid/outspend/:vout',\n tags,\n ),\n );\n }\n\n async feeEstimates(tags: UtxoCallTags): Promise<ReadonlyMap<number, number>> {\n return parseFeeEstimates(\n await this.#get(this.chain, '/fee-estimates', '/fee-estimates', tags),\n );\n }\n\n /** `POST /tx`: the node's txid on success; a node refusal is the transport's `RPC_ERROR`. */\n async broadcast(hex: string, tags: UtxoCallTags): Promise<string> {\n const answer = await this.chain.http<string>(\n { method: 'POST', path: '/tx', route: '/tx', body: hex, responseType: 'text' },\n tags,\n );\n if (typeof answer !== 'string' || !HEX64.test(answer.trim())) {\n // The node answered 2xx, so the bytes may have been accepted.\n throw new ProviderError(\n 'PROVIDER_UNAVAILABLE',\n 'malformed Esplora answer: broadcast txid',\n {\n ambiguous: true,\n },\n );\n }\n return answer.trim();\n }\n\n async addressUtxos(address: string, tags: UtxoCallTags): Promise<EsploraUtxo[]> {\n const utxos = await this.#get(\n this.indexer,\n `/address/${segment(address, 'address')}/utxo`,\n '/address/:address/utxo',\n tags,\n );\n return list(utxos, 'utxo list', parseUtxo);\n }\n\n async addressStats(address: string, tags: UtxoCallTags): Promise<EsploraAddressStats> {\n const info = record(\n await this.#get(\n this.indexer,\n `/address/${segment(address, 'address')}`,\n '/address/:address',\n tags,\n 'json',\n true,\n ),\n 'address',\n );\n const chain = record(info.chain_stats, 'chain_stats');\n const funded = total(chain.funded_txo_sum, 'funded_txo_sum');\n const spent = total(chain.spent_txo_sum, 'spent_txo_sum');\n // The totals are unbounded; the balance is the chain's: 0 to 21 million bitcoin.\n if (spent > funded || funded - spent > MAX_MONEY) throw malformed('address balance');\n return { funded, spent };\n }\n\n /** Confirmed history, newest first, 25 per page, after `lastSeen` when given. */\n async addressTxs(\n address: string,\n lastSeen: string | undefined,\n tags: UtxoCallTags,\n ): Promise<EsploraTx[]> {\n const base = `/address/${segment(address, 'address')}/txs/chain`;\n const path = lastSeen ? `${base}/${segment(lastSeen, 'id')}` : base;\n const route = lastSeen\n ? '/address/:address/txs/chain/:last_seen_txid'\n : '/address/:address/txs/chain';\n return list(await this.#get(this.indexer, path, route, tags), 'address txs', parseTx);\n }\n}\n"]}
@@ -0,0 +1,41 @@
1
+ import type { FeeOverride, FeeSpeed } from '../../core/model/fee';
2
+ import type { UtxoNetworkConfig } from './network';
3
+ /** Confirmation targets (blocks) per speed: library policy, not a network fact. */
4
+ export declare const SPEED_TARGETS: Readonly<Record<FeeSpeed, number>>;
5
+ type FeePolicy = Pick<UtxoNetworkConfig, 'minRelayFee' | 'feeFallback' | 'maxFeeRate' | 'maxFee' | 'maxEstimatedFeeRate'>;
6
+ /** Esplora's sat/vB float as sat/kvB, rounded up after removing float noise. */
7
+ export declare function satPerKvB(satPerVByte: number): bigint;
8
+ /**
9
+ * The rate for a speed: the estimate at its target, else at the nearest faster target the
10
+ * endpoint has; never below the minimum relay fee. With no usable estimate, a test
11
+ * network's `feeFallback`, else a retryable `PROVIDER_UNAVAILABLE` (nothing is guessed).
12
+ * The relay floor clamps the fallback too: it is registry data, never checked against
13
+ * `minRelayFee`.
14
+ */
15
+ export declare function rateForSpeed(estimates: ReadonlyMap<number, number>, speed: FeeSpeed, policy: FeePolicy): bigint;
16
+ /** `{ satPerVByte }` as sat/kvB. `INVALID_INTENT` when malformed, `FEE_TOO_LOW` below relay. */
17
+ export declare function rateFromOverride(override: FeeOverride, policy: FeePolicy): bigint;
18
+ /** Bitcoin Core's `CFeeRate::GetFee`: `rate × vsize / 1000`, rounded up. */
19
+ export declare function feeAt(rate: bigint, vsize: number): bigint;
20
+ /**
21
+ * The absurd-fee guard (a burn of funds by a fee bug or a fat-fingered override): refuses
22
+ * a fee above `maxFee` or a rate above `maxFeeRate` before anything is signed.
23
+ */
24
+ export declare function assertSaneFee(fee: bigint, vsize: number, policy: FeePolicy): void;
25
+ export interface PaidFee {
26
+ readonly fee: bigint;
27
+ /** Estimated with worst-case signatures (an upper bound of the real size). */
28
+ readonly vsize: number;
29
+ /**
30
+ * A lower bound of the real size: a signature can be shorter than the worst case the
31
+ * estimate assumes. Default `vsize`.
32
+ */
33
+ readonly minVsize?: number;
34
+ }
35
+ /**
36
+ * The least fee a replacement of `vsize` may pay over `previous` (rules 3, 4 and 6). It does
37
+ * not count descendants of the replaced transaction (a recipient's CPFP): a node then refuses
38
+ * with `FEE_TOO_LOW`, and a higher explicit fee resolves it.
39
+ */
40
+ export declare function replacementFloor(previous: PaidFee, vsize: number, incrementalRelayFee: bigint): bigint;
41
+ export {};