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 @@
1
+ {"version":3,"file":"proofs.js","sourceRoot":"","sources":["../../../src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,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,EACzC,MAAM,CAAC,OAAO,CACf;iBACF,CACN,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Proofs (finalized-state checks behind `proven` verdicts) and the block source.\n *\n * Finality is N confirmations. Every fact is attested at its own height with a monotone\n * predicate quorum key, and no endpoint proposes a height. \"Block h is final\" is \"every\n * proof endpoint holds a block at h + N − 1\": the quorum reads the head with the key\n * `head >= h + N − 1`, so endpoints further ahead agree, and one that trails decides\n * nothing. Only `finalizedHead` (no anchor of its own) takes one endpoint's head, trails\n * it by `PEER_SKEW`, then attests it. One endpoint's head never decides finality.\n *\n * `includedFinal` answers \"not included\" only when an input of our Attempt has a\n * quorum-attested final spender that is neither our txid nor a malleated copy of it.\n * Every other case decides nothing (a retryable `ProviderError`): our transaction in a\n * mempool or in a block not yet final, an unknown spender, a lagging or load-balanced\n * backend. A stale inclusion (its block is no longer the block at its height) is a\n * retryable `PROVIDER_INCONSISTENT`, and so is a transaction view that puts ours in a\n * block while another transaction's spend of its input is final: both cannot hold. So\n * `includedFinal` never answers \"not included\" without its own attestation of a different\n * final spend, and an endpoint-set change between the monitor's `slotConsumed` and\n * `includedFinal` calls cannot produce a false proven `replaced`.\n *\n * The block source delivers only what authenticated bytes say. A block's transactions are\n * decoded from its own bytes (`rawBlock`), which must hash to the block the scan asked for\n * and commit to every transaction and witness, and the header read at its height must be\n * those bytes' own (parent and time). The outputs a delivered transaction's inputs spend,\n * which give its `from`, input values and fee, are read from the block itself or from each\n * previous transaction's bytes, bound to the txid the input names. So no endpoint can add,\n * drop or alter a transaction, an output or a sender of what is delivered. A filtered scan\n * picks transactions by their outputs (the bytes) and by the inputs the index's pages say\n * spend from a watched address; each page must be the bytes' own, confirmed in that block,\n * and its claims must hold for every transaction delivered, so a lying index can at most\n * hide a watched address's spend that pays no watched address. Which block is at a height\n * stays the endpoint's word, as in every family (the proof quorum confirms rollbacks). A\n * reorg while reading, or a block, page or previous transaction the endpoint does not have,\n * decides nothing (retryable). Address filters match output and prevout scripts, so a\n * watched address's spend is kept even when no output of it has an address.\n */\nimport type {\n BlockSource,\n DriverBlock,\n FinalityLevel,\n ProofSource,\n} from '../../core/driver/types';\nimport { ProviderError } from '../../core/errors/error';\nimport type { OrderingData } from '../../core/model/ordering';\nimport type { AttemptRef } from '../../core/model/transaction';\nimport { toHex } from '../../core/util/bytes';\nimport { decodeAddress } from './address';\nimport {\n MONITOR,\n PROOF,\n forEachBounded,\n parseOutpoint,\n proofRead,\n withSignal,\n type UtxoContext,\n} from './context';\nimport { decodeTransaction, scriptType } from './decode';\nimport {\n MAX_MONEY,\n isHash,\n isNotFound,\n type EsploraClient,\n malformed,\n parseHash,\n parseHeight,\n parseOutspend,\n parseTx,\n type TxOutput,\n} from './esplora';\nimport { isNullOutpoint, type RawBlock } from './rawblock';\nimport type { ParsedTx } from './rawtx';\nimport { isOwnCopy } from './reader';\nimport type { EsploraInput, EsploraOutput, EsploraStatus, EsploraTx } from './types';\n\n/** Blocks `finalizedHead` trails one endpoint's head by, so peers can attest it. */\nexport const PEER_SKEW = 2n;\n\n/** Esplora's page of block transactions (electrs' `CHAIN_TXS_PER_PAGE`). */\nconst PAGE = 25;\n/**\n * How many previous transactions a block scan reads at once: a full block's delivered\n * transactions spend outputs of thousands. The transport's rate limit still paces them.\n */\nconst PREVIOUS_READS = 8;\n/** No height is below 0 or beyond what a server parses: such a height is never sent. */\nconst MAX_HEIGHT = BigInt(Number.MAX_SAFE_INTEGER);\nconst outOfRange = (height: bigint): boolean => height < 0n || height > MAX_HEIGHT;\n\nconst undecided = (reason: string): ProviderError =>\n new ProviderError('PROVIDER_UNAVAILABLE', reason);\n\n/** Two quorum reads that cannot both hold decide nothing (retryable). */\nconst contradiction = (reason: string): ProviderError =>\n new ProviderError('PROVIDER_INCONSISTENT', reason, { retryable: true });\n\nconst stale = (): ProviderError =>\n contradiction('the including block is no longer the block at its height');\n\n/** The block a scan reads is gone from the endpoint's chain, or was never on it. */\nconst changed = (block: DriverBlock): ProviderError =>\n contradiction(`block ${block.height} changed while scanning`);\n\n/**\n * An output of a block's or a previous transaction's bytes as an Esplora page shows it.\n * Its value is in range (consensus), so out of range the bytes are not chain data.\n */\nfunction outputView(output: TxOutput): EsploraOutput {\n if (output.value < 0n || output.value > MAX_MONEY) throw malformed('output value');\n return {\n script: toHex(output.script),\n type: scriptType(output.script),\n value: output.value,\n };\n}\n\n/**\n * Whether a page's transaction is `own`, the one the block's bytes hold at its place: the\n * same txid, and the same inputs (outpoints, sequences, coinbase) and outputs.\n */\nfunction samePageTx(page: EsploraTx, own: ParsedTx): boolean {\n return (\n page.txid === own.txid &&\n page.version === own.version &&\n page.locktime === own.locktime &&\n page.vin.length === own.inputs.length &&\n page.vout.length === own.outputs.length &&\n page.vin.every((input, n) => {\n const mine = own.inputs[n];\n return (\n mine !== undefined &&\n input.txid === mine.txid &&\n input.vout === mine.vout &&\n input.sequence === mine.sequence &&\n input.coinbase === isNullOutpoint(mine)\n );\n }) &&\n page.vout.every((output, n) => {\n const mine = own.outputs[n];\n return (\n mine !== undefined &&\n output.value === mine.value &&\n output.script === toHex(mine.script)\n );\n })\n );\n}\n\n/**\n * A block hash read under the proof quorum is compared as `parseHash` reads it, so two\n * honest endpoints that differ only by whitespace agree, and the key is exactly the value\n * the verdict uses. Compared as raw text, one endpoint's trailing newline would split the\n * quorum forever.\n */\nconst HASH_PROOF = { ...PROOF, quorumKey: parseHash };\n\n/** A transaction view as the proof quorum compares it: its txid, and its block and height. */\nconst txViewKey = (answer: unknown): string => {\n const t = parseTx(answer);\n return t.status.confirmed\n ? `${t.txid}@${t.status.blockHash}:${t.status.blockHeight}`\n : `${t.txid}:unconfirmed`;\n};\n\n/**\n * The reads a proof attests under the proof quorum, each fact at its own height. The\n * proof source and the builder share them: the builder's proof-tagged reads are this\n * module's, never a copy.\n */\nexport function attestedReads(ctx: UtxoContext, signal?: AbortSignal) {\n const { esplora } = ctx;\n /** \"I hold a block at `height`\" (monotone in the head, so endpoints further ahead agree). */\n const holds = async (height: bigint): Promise<boolean> => {\n const head = await esplora.tipHeight({\n ...withSignal(PROOF, signal),\n quorumKey: (answer) => parseHeight(answer) >= height,\n });\n return head >= height;\n };\n /** The hash of the block at `height` on the proof endpoints' chain. */\n const hashAt = (height: bigint): Promise<string | null> =>\n esplora.blockHashAt(height, withSignal(HASH_PROOF, signal));\n /** The quorum's hash at `height` must be `hash`; otherwise the answer was stale. */\n const assertCanonical = async (height: bigint, hash: string): Promise<void> => {\n if ((await hashAt(height)) !== hash) throw stale();\n };\n /** A transaction and the block it is in, as the proof endpoints agree on it. */\n const txView = (txid: string): Promise<EsploraTx | null> =>\n esplora.tx(txid, { ...withSignal(PROOF, signal), quorumKey: txViewKey });\n return { holds, hashAt, assertCanonical, txView };\n}\n\n/** How many parents `assertConfirmed` reads at once, and keeps once final. */\nconst PARENT_READS = 4;\nconst FINAL_PARENTS = 10_000;\nconst finalParents = new WeakMap<EsploraClient, Map<string, true>>();\n\nconst notConfirmed = (): ProviderError =>\n new ProviderError(\n 'PROVIDER_UNAVAILABLE',\n \"an input's previous transaction is not in a block the proof endpoints hold yet\",\n );\n\n/**\n * Each of `txids` (the previous transactions of the inputs a build adds) is in a\n * block, attested under the proof quorum at its own height: the proof endpoints agree on the\n * transaction and its block, all hold a block `confirmations − 1` above it, and have that\n * block at that height. Its bytes authenticate themselves, but only this proves a\n * chain holds it: an indexer's invented transaction, or one a reorg took out, would stall an\n * Attempt for good, since nothing would ever spend its outpoint. Anything short of that is a\n * retryable `PROVIDER_UNAVAILABLE` (a stale view `PROVIDER_INCONSISTENT`), and every read\n * decides nothing on failure. A parent found final is not read again.\n */\nexport async function assertConfirmed(\n ctx: UtxoContext,\n txids: readonly string[],\n confirmations: number,\n signal?: AbortSignal,\n): Promise<void> {\n let final = finalParents.get(ctx.esplora);\n if (!final) {\n final = new Map();\n finalParents.set(ctx.esplora, final);\n }\n const known = final;\n const pending = [...new Set(txids)].filter((txid) => !known.has(txid));\n if (pending.length === 0) return;\n await proofRead(async () => {\n const reads = attestedReads(ctx, signal);\n const blocks = new Map<string, bigint>();\n let top = 0n;\n await forEachBounded(pending, PARENT_READS, async (txid) => {\n const tx = await reads.txView(txid);\n if (!tx?.status.confirmed) throw notConfirmed();\n const height = tx.status.blockHeight as bigint;\n blocks.set(tx.status.blockHash as string, height);\n if (height > top) top = height;\n });\n // Monotone: the proof endpoints hold `top + confirmations − 1` only if they hold every\n // lower height, so one read attests every parent's depth.\n if (!(await reads.holds(top + BigInt(Math.max(1, confirmations)) - 1n))) {\n throw notConfirmed();\n }\n for (const [hash, height] of blocks) await reads.assertCanonical(height, hash);\n if (await reads.holds(top + BigInt(ctx.config.confirmations) - 1n)) {\n for (const txid of pending) {\n known.set(txid, true);\n if (known.size > FINAL_PARENTS) known.delete(known.keys().next().value as string);\n }\n }\n });\n}\n\nexport function proofSource(ctx: UtxoContext): ProofSource {\n const { esplora, config } = ctx;\n const depth = BigInt(config.confirmations) - 1n;\n const { holds, hashAt, assertCanonical, txView } = attestedReads(ctx);\n\n /** The transaction that spent `input` in a final, canonical block (quorum-attested). */\n const finalSpender = async (input: {\n txid: string;\n vout: number;\n }): Promise<{ txid: string; height: bigint; hash: string } | undefined> => {\n const spend = await esplora.outspend(input.txid, input.vout, {\n ...PROOF,\n quorumKey: (answer) => {\n const s = parseOutspend(answer);\n return s.spent && s.status?.confirmed\n ? `${s.txid}@${s.status.blockHash}:${s.status.blockHeight}`\n : 'not-in-a-block';\n },\n });\n const status = spend.status;\n if (!spend.spent || spend.txid === undefined || !status?.confirmed) return undefined;\n const height = status.blockHeight as bigint;\n const hash = status.blockHash as string;\n if (!(await holds(height + depth))) return undefined;\n await assertCanonical(height, hash);\n return { txid: spend.txid, height, hash };\n };\n\n const inputsOf = (ordering: OrderingData): { txid: string; vout: number }[] =>\n ordering.kind === 'inputs' ? ordering.inputs.map(parseOutpoint) : [];\n\n const source: ProofSource = {\n async finalizedHead() {\n const anchor = (await esplora.tipHeight(MONITOR)) - PEER_SKEW;\n if (anchor < 0n || !(await holds(anchor))) {\n throw undecided('the proof endpoints have not reached the head');\n }\n const final = anchor - depth;\n const height = final < 0n ? 0n : final;\n const hash = await hashAt(height);\n if (hash === null)\n throw undecided('the final block is not visible to the proof endpoints');\n return { height, hash };\n },\n\n async includedFinal(ref: AttemptRef, ordering: OrderingData, from: string) {\n if (!isHash(ref.id)) throw undecided('malformed transaction id');\n const tx = await txView(ref.id);\n if (tx?.status.confirmed) {\n const height = tx.status.blockHeight as bigint;\n const hash = tx.status.blockHash as string;\n if (await holds(height + depth)) {\n await assertCanonical(height, hash);\n // A transaction in a block has executed; its txid commits to its outputs.\n return {\n included: true,\n success: true,\n blockHeight: height,\n blockHash: hash,\n txHash: tx.txid,\n };\n }\n }\n // Unknown, in a mempool, or not yet final: only a final spender of one of our inputs\n // decides. Our own txid there means the views are inconsistent (decide nothing); a\n // malleated copy of ours is our payment; any other transaction proves ours dead,\n // unless the quorum also puts ours in a block (the views contradict each other).\n for (const input of inputsOf(ordering)) {\n const spender = await finalSpender(input);\n if (spender === undefined) continue;\n if (spender.txid === ref.id) {\n throw undecided('the spend and the transaction views disagree');\n }\n if (await isOwnCopy(ctx, ref.id, from, spender.txid, PROOF)) {\n return {\n included: true,\n success: true,\n blockHeight: spender.height,\n blockHash: spender.hash,\n txHash: spender.txid,\n };\n }\n if (tx?.status.confirmed) {\n throw contradiction(\n 'the transaction is in a block while another spend of its input is final',\n );\n }\n return { included: false };\n }\n throw undecided(\n tx\n ? 'the transaction is not final yet'\n : 'the indexer does not know this transaction yet',\n );\n },\n\n async slotConsumed(ordering, _from, level: FinalityLevel) {\n for (const input of inputsOf(ordering)) {\n if (level === 'latest') {\n if ((await esplora.outspend(input.txid, input.vout, MONITOR)).spent)\n return true;\n } else if ((await finalSpender(input)) !== undefined) {\n return true;\n }\n }\n return false;\n },\n\n expired: async () => false,\n\n async blockHash(height, level) {\n if (outOfRange(height)) return null;\n if (level === 'finalized' && !(await holds(height + depth))) return null;\n return hashAt(height);\n },\n };\n\n // Every read of every proof decides nothing on \"not available here\".\n return {\n finalizedHead: () => proofRead(() => source.finalizedHead()),\n includedFinal: (ref, ordering, from) =>\n proofRead(() => source.includedFinal(ref, ordering, from)),\n slotConsumed: (ordering, from, level) =>\n proofRead(() => source.slotConsumed(ordering, from, level)),\n expired: (ordering) => source.expired(ordering),\n blockHash: (height, level) => proofRead(() => source.blockHash(height, level)),\n };\n}\n\nexport function blockSource(ctx: UtxoContext): BlockSource {\n const { esplora, config } = ctx;\n\n /** The output scripts of the watched addresses; `undefined` means no filter. */\n const scriptsOf = (addresses: readonly string[] | undefined) => {\n if (addresses === undefined || addresses.length === 0) return undefined;\n const scripts = new Set<string>();\n for (const address of addresses) {\n try {\n scripts.add(toHex(decodeAddress(address, config.address).script));\n } catch {\n // Not an address of this network: it matches nothing.\n }\n }\n return scripts;\n };\n\n /**\n * The places of `raw`'s transactions that touch `wanted`, with each one's page: an output\n * to it, read from the block's own bytes, or an input that, by the index's pages, spends\n * from it. Every page is bound to the bytes: exactly the transactions they hold at its\n * places, with the same inputs and outputs, confirmed in this block. So a page only claims\n * which outputs the block's inputs spend, and `viewOf` checks the claims of every\n * transaction delivered against the previous transactions' own bytes: all a lying index\n * can do is hide a spend from a watched address that pays no watched address.\n */\n const touching = async (\n block: DriverBlock,\n raw: RawBlock,\n wanted: ReadonlySet<string>,\n ): Promise<Map<number, EsploraTx>> => {\n const picked = new Map<number, EsploraTx>();\n for (let start = 0; start < raw.txs.length; start += PAGE) {\n let page: EsploraTx[];\n try {\n page = await esplora.blockTxs(block.hash, start, MONITOR);\n } catch (error) {\n // A backend that does not have the block (lagging, load-balanced) decides nothing.\n if (isNotFound(error)) throw changed(block);\n throw error;\n }\n // Each page holds exactly what the block leaves for it.\n if (page.length !== Math.min(PAGE, raw.txs.length - start)) {\n throw malformed('block txs page');\n }\n page.forEach((tx, offset) => {\n const own = raw.txs[start + offset] as ParsedTx;\n if (!samePageTx(tx, own)) {\n throw contradiction(\"a block page differs from the block's own bytes\");\n }\n const { status } = tx;\n if (\n !status.confirmed ||\n status.blockHash !== block.hash ||\n status.blockHeight !== block.height\n ) {\n throw changed(block);\n }\n if (\n own.outputs.some((output) => wanted.has(toHex(output.script))) ||\n tx.vin.some((input) => input.prevout && wanted.has(input.prevout.script))\n ) {\n picked.set(start + offset, tx);\n }\n });\n }\n return picked;\n };\n\n /**\n * The outputs the inputs of `txs` spend, by previous txid: a transaction of the block\n * itself, or the previous transaction's own bytes, bound to its txid (`outputsOf`). One\n * endpoint answers, so one that does not have a previous transaction decides nothing.\n */\n const spentOutputs = async (\n raw: RawBlock,\n txs: readonly ParsedTx[],\n ): Promise<ReadonlyMap<string, readonly TxOutput[]>> => {\n const known = new Map<string, readonly TxOutput[]>(\n raw.txs.map((tx) => [tx.txid, tx.outputs]),\n );\n const missing = new Set<string>();\n for (const tx of txs) {\n for (const input of tx.inputs) {\n if (!isNullOutpoint(input) && !known.has(input.txid)) missing.add(input.txid);\n }\n }\n await forEachBounded([...missing], PREVIOUS_READS, async (txid) => {\n const outputs = await esplora.outputsOf(txid, MONITOR);\n if (!outputs) throw undecided(\"an input's previous transaction is not available\");\n known.set(txid, outputs);\n });\n return known;\n };\n\n /**\n * A transaction of the block as Esplora shows it, from its own bytes and the outputs its\n * inputs spend, so it decodes as a page of it would. A page's claims about those outputs\n * (`page`) must be what the previous transactions hold.\n */\n const viewOf = (\n tx: ParsedTx,\n spent: ReadonlyMap<string, readonly TxOutput[]>,\n status: EsploraStatus,\n page: EsploraTx | undefined,\n ): EsploraTx => {\n const vout = tx.outputs.map(outputView);\n let coinbase = false;\n let fee = -vout.reduce((sum, output) => sum + output.value, 0n);\n const vin = tx.inputs.map((input, n): EsploraInput => {\n const outpoint = { txid: input.txid, vout: input.vout, sequence: input.sequence };\n if (isNullOutpoint(input)) {\n coinbase = true;\n return { ...outpoint, coinbase: true };\n }\n const output = spent.get(input.txid)?.[input.vout];\n if (!output)\n throw contradiction('a block input spends an output that does not exist');\n const prevout = outputView(output);\n const claim = page?.vin[n]?.prevout;\n if (claim && (claim.script !== prevout.script || claim.value !== prevout.value)) {\n throw contradiction(\n 'the index names another output than the one an input spends',\n );\n }\n fee += prevout.value;\n return { ...outpoint, coinbase: false, prevout };\n });\n // Esplora's convention: a coinbase's fee is 0.\n if (coinbase) fee = 0n;\n if (fee < 0n || fee > MAX_MONEY) throw malformed('tx fee');\n return {\n txid: tx.txid,\n version: tx.version,\n locktime: tx.locktime,\n weight: tx.strippedSize * 3 + tx.bytes.length,\n fee,\n vin,\n vout,\n status,\n };\n };\n\n return {\n async header(height): Promise<DriverBlock | null> {\n if (outOfRange(height)) return null;\n const hash = await esplora.blockHashAt(height, MONITOR);\n if (!hash) return null;\n const block = await esplora.block(hash, MONITOR);\n if (!block) return null;\n // The block at `height` must say it is at `height`.\n if (block.height !== height) {\n throw contradiction(`block ${height} changed while reading`);\n }\n return {\n height: block.height,\n hash: block.hash,\n parentHash: block.parentHash,\n timestamp: block.timestamp,\n };\n },\n\n async transactions(block, filter) {\n // `filter.assets` is a hint: a list without the native asset wants tokens only, and a\n // Bitcoin block has none, so nothing is read.\n if (filter?.assets?.length && !filter.assets.includes('native')) return [];\n // The block's own bytes, bound to its hash (`rawBlock`): every transaction delivered\n // is the block's, byte for byte, whatever the index's pages say.\n const raw = await esplora.rawBlock(block.hash, MONITOR);\n // A backend that does not have the block (lagging, load-balanced, or a full-mode\n // electrs, which serves its best chain's only) decides nothing.\n if (!raw) throw changed(block);\n // The header read at this height must be the bytes' own, so the block delivered (its\n // parent link and time) is the one its hash names.\n if (raw.parentHash !== block.parentHash || raw.time !== block.timestamp) {\n throw contradiction(`the header of block ${block.height} is not its own`);\n }\n const wanted = scriptsOf(filter?.addresses);\n const picked = wanted && (await touching(block, raw, wanted));\n const txs = picked ? raw.txs.filter((_, i) => picked.has(i)) : raw.txs;\n const spent = await spentOutputs(raw, txs);\n // Checked after the reads, so a reorg while reading is caught.\n if ((await esplora.blockHashAt(block.height, MONITOR)) !== block.hash) {\n throw changed(block);\n }\n const status: EsploraStatus = {\n confirmed: true,\n blockHeight: block.height,\n blockHash: block.hash,\n blockTime: raw.time,\n };\n return raw.txs.flatMap((tx, i) =>\n picked && !picked.has(i)\n ? []\n : [\n decodeTransaction(\n viewOf(tx, spent, status, picked?.get(i)),\n config.address,\n ),\n ],\n );\n },\n };\n}\n"]}
@@ -0,0 +1,46 @@
1
+ import { type ParsedInput, type ParsedTx } from './rawtx';
2
+ /** Bitcoin Core's `MAX_BLOCK_SERIALIZED_SIZE`: no block's bytes are more. */
3
+ export declare const MAX_BLOCK_BYTES = 4000000;
4
+ export interface RawBlock {
5
+ /** The block hash in display order: the double SHA-256 of the header. */
6
+ readonly hash: string;
7
+ /** The previous block's hash in display order (zeros for a genesis block). */
8
+ readonly parentHash: string;
9
+ /** The header's time, in seconds. */
10
+ readonly time: number;
11
+ /** The header's merkle root of the txids, in internal byte order. */
12
+ readonly merkleRoot: Uint8Array;
13
+ /** Every transaction, the coinbase first, as the bytes hold them. */
14
+ readonly txs: readonly ParsedTx[];
15
+ }
16
+ /** An input that spends no output (`COutPoint::IsNull`): a coinbase's. */
17
+ export declare const isNullOutpoint: (input: ParsedInput) => boolean;
18
+ /** Block bytes, read in one pass; `undefined` when bitcoind would not decode them. */
19
+ export declare function readBlock(bytes: Uint8Array): RawBlock | undefined;
20
+ /**
21
+ * Bitcoin Core's `ComputeMerkleRoot`: the root of `leaves`, each level's odd last node
22
+ * paired with itself, and whether a level holds two equal nodes at a pair's places. That
23
+ * flags CVE-2012-2459: a list whose last transactions are repeated has the root of the list
24
+ * without them, so equal pairs are refused rather than read as a different block.
25
+ */
26
+ export declare function merkleRootOf(leaves: readonly Uint8Array[]): {
27
+ readonly root: Uint8Array;
28
+ readonly mutated: boolean;
29
+ };
30
+ /**
31
+ * Whether `block`'s transactions are the ones its header commits to, as bitcoind's
32
+ * `CheckMerkleRoot`, `bad-cb-missing` and `CheckWitnessMalleation` check them:
33
+ * - the merkle root of the txids is the header's, with no repeated pair (CVE-2012-2459) and
34
+ * no txid twice: no valid block holds one twice;
35
+ * - the first transaction is a coinbase (one input, spending nothing). A 64-byte
36
+ * transaction's txid is the hash of two merkle nodes, so a list with such "transactions"
37
+ * in place of the nodes' subtrees has the same root. Its leftmost one stands for the
38
+ * subtree that holds the coinbase, so it would have to be a coinbase made of hash output,
39
+ * with a null outpoint's 36 fixed bytes in it, which no one can find;
40
+ * - when any transaction carries a witness, the coinbase commits to every witness (BIP141):
41
+ * its last output that starts `OP_RETURN aa21a9ed` holds the double SHA-256 of the
42
+ * wtxids' merkle root (the coinbase's taken as zero) and the coinbase's one 32-byte
43
+ * witness item. A block with no witness at all is checked by its txids alone: an
44
+ * earlier block's coinbase may carry a commitment that segwit's rules did not cover yet.
45
+ */
46
+ export declare function commitsToTransactions(block: RawBlock): boolean;
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNullOutpoint = exports.MAX_BLOCK_BYTES = void 0;
4
+ exports.readBlock = readBlock;
5
+ exports.merkleRootOf = merkleRootOf;
6
+ exports.commitsToTransactions = commitsToTransactions;
7
+ /**
8
+ * A linear, SDK-free reader of untrusted block bytes (Esplora's `/block/:hash/raw`), and the
9
+ * checks that bind a block's transactions to its header.
10
+ *
11
+ * A block hash is the double SHA-256 of the 80-byte header, and the header commits to the
12
+ * transactions through the merkle root of their txids, and (BIP141) to their witnesses
13
+ * through the coinbase's witness commitment. So bytes that hash to the block asked for and
14
+ * pass `commitsToTransactions` are that block's transactions, byte for byte, whoever served
15
+ * them: an indexer can neither add, drop nor alter one. bitcoinjs-lib's `Block.fromBuffer`
16
+ * copies the rest of the block for every transaction it reads (quadratic in the block's
17
+ * size), so each transaction is read here by `rawtx.ts`, in one pass over views of the bytes.
18
+ *
19
+ * The format is bitcoind's: the header, a canonical CompactSize count of at most `MAX_SIZE`,
20
+ * then each transaction with witness support, and nothing after the last one.
21
+ */
22
+ const bytes_1 = require("../../core/util/bytes");
23
+ const rawtx_1 = require("./rawtx");
24
+ /** Bitcoin Core's `MAX_BLOCK_SERIALIZED_SIZE`: no block's bytes are more. */
25
+ exports.MAX_BLOCK_BYTES = 4_000_000;
26
+ const HEADER = 80;
27
+ /** bitcoind's `MAX_SIZE`: the largest CompactSize a deserializer accepts. */
28
+ const MAX_SIZE = 0x02000000;
29
+ /** The fewest bytes `rawtx.ts` decodes as a transaction (version, two zero bytes, lock time). */
30
+ const MIN_TX = 10;
31
+ /** BIP141: an output script of at least 38 bytes that starts `OP_RETURN 0x24 aa21a9ed`. */
32
+ const COMMITMENT_HEADER = Uint8Array.of(0x6a, 0x24, 0xaa, 0x21, 0xa9, 0xed);
33
+ const COMMITMENT_SIZE = 38;
34
+ const ZERO_HASH = new Uint8Array(32);
35
+ /** An input that spends no output (`COutPoint::IsNull`): a coinbase's. */
36
+ const isNullOutpoint = (input) => input.vout === 0xffffffff && (0, bytes_1.equalBytes)(input.hash, ZERO_HASH);
37
+ exports.isNullOutpoint = isNullOutpoint;
38
+ /** Block bytes, read in one pass; `undefined` when bitcoind would not decode them. */
39
+ function readBlock(bytes) {
40
+ if (!(bytes instanceof Uint8Array))
41
+ return undefined;
42
+ if (bytes.length < HEADER + 1 || bytes.length > exports.MAX_BLOCK_BYTES)
43
+ return undefined;
44
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
45
+ let pos = HEADER;
46
+ // A canonical CompactSize of at most `MAX_SIZE` (bitcoind's `ReadCompactSize`).
47
+ const first = bytes[pos++];
48
+ let count = first;
49
+ if (first === 0xfd) {
50
+ if (pos + 2 > bytes.length)
51
+ return undefined;
52
+ count = view.getUint16(pos, true);
53
+ pos += 2;
54
+ if (count < 0xfd)
55
+ return undefined;
56
+ }
57
+ else if (first === 0xfe) {
58
+ if (pos + 4 > bytes.length)
59
+ return undefined;
60
+ count = view.getUint32(pos, true);
61
+ pos += 4;
62
+ if (count < 0x1_0000)
63
+ return undefined;
64
+ }
65
+ else if (first === 0xff) {
66
+ return undefined; // 8 bytes: at least 2^32, beyond MAX_SIZE
67
+ }
68
+ // Every block has a coinbase, and the count is bounded by the bytes left before
69
+ // anything is kept for it.
70
+ if (count < 1 || count > MAX_SIZE || count * MIN_TX > bytes.length - pos) {
71
+ return undefined;
72
+ }
73
+ const txs = [];
74
+ for (let i = 0; i < count; i++) {
75
+ const tx = (0, rawtx_1.readTxAt)(bytes, pos);
76
+ if (!tx)
77
+ return undefined;
78
+ txs.push(tx);
79
+ pos += tx.bytes.length;
80
+ }
81
+ if (pos !== bytes.length)
82
+ return undefined;
83
+ const header = bytes.subarray(0, HEADER);
84
+ return {
85
+ hash: (0, rawtx_1.displayHex)((0, rawtx_1.hash256)([header])),
86
+ parentHash: (0, rawtx_1.displayHex)(header.subarray(4, 36)),
87
+ time: view.getUint32(68, true),
88
+ merkleRoot: header.subarray(36, 68),
89
+ txs,
90
+ };
91
+ }
92
+ /**
93
+ * Bitcoin Core's `ComputeMerkleRoot`: the root of `leaves`, each level's odd last node
94
+ * paired with itself, and whether a level holds two equal nodes at a pair's places. That
95
+ * flags CVE-2012-2459: a list whose last transactions are repeated has the root of the list
96
+ * without them, so equal pairs are refused rather than read as a different block.
97
+ */
98
+ function merkleRootOf(leaves) {
99
+ let level = [...leaves];
100
+ let mutated = false;
101
+ while (level.length > 1) {
102
+ for (let i = 0; i + 1 < level.length; i += 2) {
103
+ if ((0, bytes_1.equalBytes)(level[i], level[i + 1]))
104
+ mutated = true;
105
+ }
106
+ const next = [];
107
+ for (let i = 0; i < level.length; i += 2) {
108
+ const left = level[i];
109
+ next.push((0, rawtx_1.hash256)([left, level[i + 1] ?? left]));
110
+ }
111
+ level = next;
112
+ }
113
+ return { root: level[0] ?? ZERO_HASH, mutated };
114
+ }
115
+ /**
116
+ * Whether `block`'s transactions are the ones its header commits to, as bitcoind's
117
+ * `CheckMerkleRoot`, `bad-cb-missing` and `CheckWitnessMalleation` check them:
118
+ * - the merkle root of the txids is the header's, with no repeated pair (CVE-2012-2459) and
119
+ * no txid twice: no valid block holds one twice;
120
+ * - the first transaction is a coinbase (one input, spending nothing). A 64-byte
121
+ * transaction's txid is the hash of two merkle nodes, so a list with such "transactions"
122
+ * in place of the nodes' subtrees has the same root. Its leftmost one stands for the
123
+ * subtree that holds the coinbase, so it would have to be a coinbase made of hash output,
124
+ * with a null outpoint's 36 fixed bytes in it, which no one can find;
125
+ * - when any transaction carries a witness, the coinbase commits to every witness (BIP141):
126
+ * its last output that starts `OP_RETURN aa21a9ed` holds the double SHA-256 of the
127
+ * wtxids' merkle root (the coinbase's taken as zero) and the coinbase's one 32-byte
128
+ * witness item. A block with no witness at all is checked by its txids alone: an
129
+ * earlier block's coinbase may carry a commitment that segwit's rules did not cover yet.
130
+ */
131
+ function commitsToTransactions(block) {
132
+ const { txs } = block;
133
+ const coinbase = txs[0];
134
+ const input = coinbase?.inputs[0];
135
+ if (!coinbase || coinbase.inputs.length !== 1 || !input || !(0, exports.isNullOutpoint)(input)) {
136
+ return false;
137
+ }
138
+ if (new Set(txs.map((tx) => tx.txid)).size !== txs.length)
139
+ return false;
140
+ const ids = merkleRootOf(txs.map((tx) => tx.hash));
141
+ if (ids.mutated || !(0, bytes_1.equalBytes)(ids.root, block.merkleRoot))
142
+ return false;
143
+ if (!txs.some((tx) => tx.hasWitness))
144
+ return true;
145
+ let commitment;
146
+ for (const output of coinbase.outputs) {
147
+ const script = output.script;
148
+ if (script.length >= COMMITMENT_SIZE &&
149
+ (0, bytes_1.equalBytes)(script.subarray(0, COMMITMENT_HEADER.length), COMMITMENT_HEADER)) {
150
+ commitment = script.subarray(COMMITMENT_HEADER.length, COMMITMENT_SIZE);
151
+ }
152
+ }
153
+ const reserved = input.witness;
154
+ if (!commitment || reserved.length !== 1 || reserved[0]?.length !== 32)
155
+ return false;
156
+ const witnesses = merkleRootOf(txs.map((tx, i) => i === 0 ? ZERO_HASH : tx.hasWitness ? (0, rawtx_1.hash256)([tx.bytes]) : tx.hash));
157
+ return (0, bytes_1.equalBytes)((0, rawtx_1.hash256)([witnesses.root, reserved[0]]), commitment);
158
+ }
159
+ //# sourceMappingURL=rawblock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rawblock.js","sourceRoot":"","sources":["../../../src/adapters/utxo/rawblock.ts"],"names":[],"mappings":";;;AAgDA,8BA0CC;AAQD,oCAkBC;AAkBD,sDA6BC;AAnKD;;;;;;;;;;;;;;GAcG;AACH,iDAAmD;AACnD,mCAAyF;AAEzF,6EAA6E;AAChE,QAAA,eAAe,GAAG,SAAS,CAAC;AACzC,MAAM,MAAM,GAAG,EAAE,CAAC;AAClB,6EAA6E;AAC7E,MAAM,QAAQ,GAAG,UAAU,CAAC;AAC5B,iGAAiG;AACjG,MAAM,MAAM,GAAG,EAAE,CAAC;AAClB,2FAA2F;AAC3F,MAAM,iBAAiB,GAAG,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAC5E,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;AAerC,0EAA0E;AACnE,MAAM,cAAc,GAAG,CAAC,KAAkB,EAAW,EAAE,CAC5D,KAAK,CAAC,IAAI,KAAK,UAAU,IAAI,IAAA,kBAAU,EAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;AADpD,QAAA,cAAc,kBACsC;AAEjE,sFAAsF;AACtF,SAAgB,SAAS,CAAC,KAAiB;IACzC,IAAI,CAAC,CAAC,KAAK,YAAY,UAAU,CAAC;QAAE,OAAO,SAAS,CAAC;IACrD,IAAI,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,uBAAe;QAAE,OAAO,SAAS,CAAC;IAClF,MAAM,IAAI,GAAG,IA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,UAAU,CAAC,CAAC;AACxE,CAAC","sourcesContent":["/**\n * A linear, SDK-free reader of untrusted block bytes (Esplora's `/block/:hash/raw`), and the\n * checks that bind a block's transactions to its header.\n *\n * A block hash is the double SHA-256 of the 80-byte header, and the header commits to the\n * transactions through the merkle root of their txids, and (BIP141) to their witnesses\n * through the coinbase's witness commitment. So bytes that hash to the block asked for and\n * pass `commitsToTransactions` are that block's transactions, byte for byte, whoever served\n * them: an indexer can neither add, drop nor alter one. bitcoinjs-lib's `Block.fromBuffer`\n * copies the rest of the block for every transaction it reads (quadratic in the block's\n * size), so each transaction is read here by `rawtx.ts`, in one pass over views of the bytes.\n *\n * The format is bitcoind's: the header, a canonical CompactSize count of at most `MAX_SIZE`,\n * then each transaction with witness support, and nothing after the last one.\n */\nimport { equalBytes } from '../../core/util/bytes';\nimport { displayHex, hash256, readTxAt, type ParsedInput, type ParsedTx } from './rawtx';\n\n/** Bitcoin Core's `MAX_BLOCK_SERIALIZED_SIZE`: no block's bytes are more. */\nexport const MAX_BLOCK_BYTES = 4_000_000;\nconst HEADER = 80;\n/** bitcoind's `MAX_SIZE`: the largest CompactSize a deserializer accepts. */\nconst MAX_SIZE = 0x02000000;\n/** The fewest bytes `rawtx.ts` decodes as a transaction (version, two zero bytes, lock time). */\nconst MIN_TX = 10;\n/** BIP141: an output script of at least 38 bytes that starts `OP_RETURN 0x24 aa21a9ed`. */\nconst COMMITMENT_HEADER = Uint8Array.of(0x6a, 0x24, 0xaa, 0x21, 0xa9, 0xed);\nconst COMMITMENT_SIZE = 38;\nconst ZERO_HASH = new Uint8Array(32);\n\nexport interface RawBlock {\n /** The block hash in display order: the double SHA-256 of the header. */\n readonly hash: string;\n /** The previous block's hash in display order (zeros for a genesis block). */\n readonly parentHash: string;\n /** The header's time, in seconds. */\n readonly time: number;\n /** The header's merkle root of the txids, in internal byte order. */\n readonly merkleRoot: Uint8Array;\n /** Every transaction, the coinbase first, as the bytes hold them. */\n readonly txs: readonly ParsedTx[];\n}\n\n/** An input that spends no output (`COutPoint::IsNull`): a coinbase's. */\nexport const isNullOutpoint = (input: ParsedInput): boolean =>\n input.vout === 0xffffffff && equalBytes(input.hash, ZERO_HASH);\n\n/** Block bytes, read in one pass; `undefined` when bitcoind would not decode them. */\nexport function readBlock(bytes: Uint8Array): RawBlock | undefined {\n if (!(bytes instanceof Uint8Array)) return undefined;\n if (bytes.length < HEADER + 1 || bytes.length > MAX_BLOCK_BYTES) return undefined;\n const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n let pos = HEADER;\n // A canonical CompactSize of at most `MAX_SIZE` (bitcoind's `ReadCompactSize`).\n const first = bytes[pos++] as number;\n let count = first;\n if (first === 0xfd) {\n if (pos + 2 > bytes.length) return undefined;\n count = view.getUint16(pos, true);\n pos += 2;\n if (count < 0xfd) return undefined;\n } else if (first === 0xfe) {\n if (pos + 4 > bytes.length) return undefined;\n count = view.getUint32(pos, true);\n pos += 4;\n if (count < 0x1_0000) return undefined;\n } else if (first === 0xff) {\n return undefined; // 8 bytes: at least 2^32, beyond MAX_SIZE\n }\n // Every block has a coinbase, and the count is bounded by the bytes left before\n // anything is kept for it.\n if (count < 1 || count > MAX_SIZE || count * MIN_TX > bytes.length - pos) {\n return undefined;\n }\n const txs: ParsedTx[] = [];\n for (let i = 0; i < count; i++) {\n const tx = readTxAt(bytes, pos);\n if (!tx) return undefined;\n txs.push(tx);\n pos += tx.bytes.length;\n }\n if (pos !== bytes.length) return undefined;\n const header = bytes.subarray(0, HEADER);\n return {\n hash: displayHex(hash256([header])),\n parentHash: displayHex(header.subarray(4, 36)),\n time: view.getUint32(68, true),\n merkleRoot: header.subarray(36, 68),\n txs,\n };\n}\n\n/**\n * Bitcoin Core's `ComputeMerkleRoot`: the root of `leaves`, each level's odd last node\n * paired with itself, and whether a level holds two equal nodes at a pair's places. That\n * flags CVE-2012-2459: a list whose last transactions are repeated has the root of the list\n * without them, so equal pairs are refused rather than read as a different block.\n */\nexport function merkleRootOf(leaves: readonly Uint8Array[]): {\n readonly root: Uint8Array;\n readonly mutated: boolean;\n} {\n let level = [...leaves];\n let mutated = false;\n while (level.length > 1) {\n for (let i = 0; i + 1 < level.length; i += 2) {\n if (equalBytes(level[i] as Uint8Array, level[i + 1] as Uint8Array)) mutated = true;\n }\n const next: Uint8Array[] = [];\n for (let i = 0; i < level.length; i += 2) {\n const left = level[i] as Uint8Array;\n next.push(hash256([left, level[i + 1] ?? left]));\n }\n level = next;\n }\n return { root: level[0] ?? ZERO_HASH, mutated };\n}\n\n/**\n * Whether `block`'s transactions are the ones its header commits to, as bitcoind's\n * `CheckMerkleRoot`, `bad-cb-missing` and `CheckWitnessMalleation` check them:\n * - the merkle root of the txids is the header's, with no repeated pair (CVE-2012-2459) and\n * no txid twice: no valid block holds one twice;\n * - the first transaction is a coinbase (one input, spending nothing). A 64-byte\n * transaction's txid is the hash of two merkle nodes, so a list with such \"transactions\"\n * in place of the nodes' subtrees has the same root. Its leftmost one stands for the\n * subtree that holds the coinbase, so it would have to be a coinbase made of hash output,\n * with a null outpoint's 36 fixed bytes in it, which no one can find;\n * - when any transaction carries a witness, the coinbase commits to every witness (BIP141):\n * its last output that starts `OP_RETURN aa21a9ed` holds the double SHA-256 of the\n * wtxids' merkle root (the coinbase's taken as zero) and the coinbase's one 32-byte\n * witness item. A block with no witness at all is checked by its txids alone: an\n * earlier block's coinbase may carry a commitment that segwit's rules did not cover yet.\n */\nexport function commitsToTransactions(block: RawBlock): boolean {\n const { txs } = block;\n const coinbase = txs[0];\n const input = coinbase?.inputs[0];\n if (!coinbase || coinbase.inputs.length !== 1 || !input || !isNullOutpoint(input)) {\n return false;\n }\n if (new Set(txs.map((tx) => tx.txid)).size !== txs.length) return false;\n const ids = merkleRootOf(txs.map((tx) => tx.hash));\n if (ids.mutated || !equalBytes(ids.root, block.merkleRoot)) return false;\n if (!txs.some((tx) => tx.hasWitness)) return true;\n let commitment: Uint8Array | undefined;\n for (const output of coinbase.outputs) {\n const script = output.script;\n if (\n script.length >= COMMITMENT_SIZE &&\n equalBytes(script.subarray(0, COMMITMENT_HEADER.length), COMMITMENT_HEADER)\n ) {\n commitment = script.subarray(COMMITMENT_HEADER.length, COMMITMENT_SIZE);\n }\n }\n const reserved = input.witness;\n if (!commitment || reserved.length !== 1 || reserved[0]?.length !== 32) return false;\n const witnesses = merkleRootOf(\n txs.map((tx, i) =>\n i === 0 ? ZERO_HASH : tx.hasWitness ? hash256([tx.bytes]) : tx.hash,\n ),\n );\n return equalBytes(hash256([witnesses.root, reserved[0]]), commitment);\n}\n"]}
@@ -0,0 +1,73 @@
1
+ /** Bitcoin Core's `MAX_BLOCK_SERIALIZED_SIZE`: no transaction's bytes are more. */
2
+ export declare const MAX_TX_BYTES = 4000000;
3
+ /**
4
+ * Consensus: a transaction's weight (4 × its size without witness data, at least) is at most
5
+ * `MAX_BLOCK_WEIGHT` (4,000,000), so a transaction a chain holds has at most 1,000,000 bytes
6
+ * without its witness.
7
+ */
8
+ export declare const MAX_STRIPPED_BYTES = 1000000;
9
+ export interface ParsedInput {
10
+ /** The previous txid, in display order (the reverse of the serialized hash). */
11
+ readonly txid: string;
12
+ /** The previous transaction's hash as serialized (internal byte order): a view. */
13
+ readonly hash: Uint8Array;
14
+ readonly vout: number;
15
+ readonly script: Uint8Array;
16
+ readonly sequence: number;
17
+ readonly witness: readonly Uint8Array[];
18
+ }
19
+ export interface ParsedOutput {
20
+ /** As bitcoind reads it: a signed 64-bit integer. */
21
+ readonly value: bigint;
22
+ readonly script: Uint8Array;
23
+ }
24
+ export interface ParsedTx {
25
+ readonly txid: string;
26
+ /** The txid's hash in internal byte order: a block's merkle tree leaf. */
27
+ readonly hash: Uint8Array;
28
+ readonly version: number;
29
+ readonly locktime: number;
30
+ readonly inputs: readonly ParsedInput[];
31
+ readonly outputs: readonly ParsedOutput[];
32
+ readonly hasWitness: boolean;
33
+ /** The size without witness data (bitcoind's `TX_NO_WITNESS` serialization). */
34
+ readonly strippedSize: number;
35
+ /** The serialization as read, witness included: a view. */
36
+ readonly bytes: Uint8Array;
37
+ /** The output list as serialized (its count, then each output): a view. */
38
+ readonly outputBytes: Uint8Array;
39
+ /** The serialization without witness data (BIP174 `non_witness_utxo`). */
40
+ stripped(): Uint8Array;
41
+ }
42
+ export interface ReadOptions {
43
+ /**
44
+ * The most bytes without witness data: `MAX_STRIPPED_BYTES` (the default) for data a chain
45
+ * holds; the broadcaster reads what it sent with `MAX_TX_BYTES`, so every size bitcoind
46
+ * decodes is read (bitcoind refuses a larger one later, as `bad-txns-oversize`).
47
+ */
48
+ readonly maxStripped?: number;
49
+ }
50
+ /** Double SHA-256 of the given stretches, as one message. */
51
+ export declare function hash256(parts: readonly Uint8Array[]): Uint8Array;
52
+ /** A txid (or block hash) in display order. */
53
+ export declare const displayHex: (hash: Uint8Array) => string;
54
+ /** The txid of a serialization without witness data, given as consecutive stretches. */
55
+ export declare const txidOfParts: (parts: readonly Uint8Array[]) => string;
56
+ /** A little-endian 32-bit field, as bitcoind writes it. */
57
+ export declare function writeU32(n: number): Uint8Array;
58
+ /** A CompactSize, as bitcoind writes it (at most `MAX_SIZE` here). */
59
+ export declare function writeSize(n: number): Uint8Array;
60
+ /** Transaction bytes, read in one pass; `undefined` when bitcoind would not decode them. */
61
+ export declare function readTx(bytes: Uint8Array, options?: ReadOptions): ParsedTx | undefined;
62
+ /**
63
+ * The transaction that starts at `start` of `bytes` (a block's transaction list), read as
64
+ * `readTx` reads one; the next one starts where its `bytes` end. `undefined` when bitcoind
65
+ * would not decode it there.
66
+ */
67
+ export declare function readTxAt(bytes: Uint8Array, start: number): ParsedTx | undefined;
68
+ /**
69
+ * Transaction hex (either case, no prefix), capped at `MAX_TX_BYTES` before it is
70
+ * decoded, then read by `readTx`. Node's hex decoder is native and linear, and stops at
71
+ * the first pair that is not hex, so a short result means the text was not plain hex.
72
+ */
73
+ export declare function readTxHex(hex: string, options?: ReadOptions): ParsedTx | undefined;