crypto-aio 0.0.3 → 0.1.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 (691) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +144 -14
  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 +326 -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 +170 -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 +135 -0
  80. package/dist/adapters/evm/ethers-client.js.map +1 -0
  81. package/dist/adapters/evm/fees.d.ts +79 -0
  82. package/dist/adapters/evm/fees.js +234 -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 +11 -0
  86. package/dist/adapters/evm/index.js.map +1 -0
  87. package/dist/adapters/evm/network.d.ts +60 -0
  88. package/dist/adapters/evm/network.js +131 -0
  89. package/dist/adapters/evm/network.js.map +1 -0
  90. package/dist/adapters/evm/plugin.d.ts +36 -0
  91. package/dist/adapters/evm/plugin.js +102 -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 +358 -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 +65 -0
  103. package/dist/adapters/evm/reader.js +292 -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 +7 -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 +255 -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 +23 -0
  115. package/dist/adapters/evm/web3-client.js +159 -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 +545 -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 +68 -0
  133. package/dist/adapters/solana/fees.js +205 -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/network.d.ts +24 -0
  148. package/dist/adapters/solana/network.js +95 -0
  149. package/dist/adapters/solana/network.js.map +1 -0
  150. package/dist/adapters/solana/plugin.d.ts +18 -0
  151. package/dist/adapters/solana/plugin.js +41 -0
  152. package/dist/adapters/solana/plugin.js.map +1 -0
  153. package/dist/adapters/solana/presets.d.ts +2 -0
  154. package/dist/adapters/solana/presets.js +77 -0
  155. package/dist/adapters/solana/presets.js.map +1 -0
  156. package/dist/adapters/solana/programs.d.ts +44 -0
  157. package/dist/adapters/solana/programs.js +159 -0
  158. package/dist/adapters/solana/programs.js.map +1 -0
  159. package/dist/adapters/solana/proofs.d.ts +56 -0
  160. package/dist/adapters/solana/proofs.js +540 -0
  161. package/dist/adapters/solana/proofs.js.map +1 -0
  162. package/dist/adapters/solana/reader.d.ts +82 -0
  163. package/dist/adapters/solana/reader.js +326 -0
  164. package/dist/adapters/solana/reader.js.map +1 -0
  165. package/dist/adapters/solana/rpc.d.ts +102 -0
  166. package/dist/adapters/solana/rpc.js +301 -0
  167. package/dist/adapters/solana/rpc.js.map +1 -0
  168. package/dist/adapters/solana/tokens.d.ts +7 -0
  169. package/dist/adapters/solana/tokens.js +19 -0
  170. package/dist/adapters/solana/tokens.js.map +1 -0
  171. package/dist/adapters/solana/types.d.ts +121 -0
  172. package/dist/{type/contract.js → adapters/solana/types.js} +1 -1
  173. package/dist/adapters/solana/types.js.map +1 -0
  174. package/dist/adapters/solana/web3.d.ts +5 -0
  175. package/dist/adapters/solana/web3.js +83 -0
  176. package/dist/adapters/solana/web3.js.map +1 -0
  177. package/dist/adapters/solana/wire.d.ts +62 -0
  178. package/dist/adapters/solana/wire.js +168 -0
  179. package/dist/adapters/solana/wire.js.map +1 -0
  180. package/dist/adapters/ton/address.d.ts +43 -0
  181. package/dist/adapters/ton/address.js +168 -0
  182. package/dist/adapters/ton/address.js.map +1 -0
  183. package/dist/adapters/ton/api.d.ts +344 -0
  184. package/dist/adapters/ton/api.js +942 -0
  185. package/dist/adapters/ton/api.js.map +1 -0
  186. package/dist/adapters/ton/builder.d.ts +18 -0
  187. package/dist/adapters/ton/builder.js +701 -0
  188. package/dist/adapters/ton/builder.js.map +1 -0
  189. package/dist/adapters/ton/chains.d.ts +16 -0
  190. package/dist/adapters/ton/chains.js +39 -0
  191. package/dist/adapters/ton/chains.js.map +1 -0
  192. package/dist/adapters/ton/decode.d.ts +43 -0
  193. package/dist/adapters/ton/decode.js +219 -0
  194. package/dist/adapters/ton/decode.js.map +1 -0
  195. package/dist/adapters/ton/driver.d.ts +10 -0
  196. package/dist/adapters/ton/driver.js +117 -0
  197. package/dist/adapters/ton/driver.js.map +1 -0
  198. package/dist/adapters/ton/errors.d.ts +36 -0
  199. package/dist/adapters/ton/errors.js +89 -0
  200. package/dist/adapters/ton/errors.js.map +1 -0
  201. package/dist/adapters/ton/fees.d.ts +28 -0
  202. package/dist/adapters/ton/fees.js +121 -0
  203. package/dist/adapters/ton/fees.js.map +1 -0
  204. package/dist/adapters/ton/index.d.ts +16 -0
  205. package/dist/adapters/ton/index.js +9 -0
  206. package/dist/adapters/ton/index.js.map +1 -0
  207. package/dist/adapters/ton/messages.d.ts +157 -0
  208. package/dist/adapters/ton/messages.js +397 -0
  209. package/dist/adapters/ton/messages.js.map +1 -0
  210. package/dist/adapters/ton/native-client.d.ts +10 -0
  211. package/dist/adapters/ton/native-client.js +47 -0
  212. package/dist/adapters/ton/native-client.js.map +1 -0
  213. package/dist/adapters/ton/network.d.ts +58 -0
  214. package/dist/adapters/ton/network.js +207 -0
  215. package/dist/adapters/ton/network.js.map +1 -0
  216. package/dist/adapters/ton/plugin.d.ts +24 -0
  217. package/dist/adapters/ton/plugin.js +57 -0
  218. package/dist/adapters/ton/plugin.js.map +1 -0
  219. package/dist/adapters/ton/presets.d.ts +6 -0
  220. package/dist/adapters/ton/presets.js +94 -0
  221. package/dist/adapters/ton/presets.js.map +1 -0
  222. package/dist/adapters/ton/proofs.d.ts +66 -0
  223. package/dist/adapters/ton/proofs.js +813 -0
  224. package/dist/adapters/ton/proofs.js.map +1 -0
  225. package/dist/adapters/ton/reader.d.ts +194 -0
  226. package/dist/adapters/ton/reader.js +781 -0
  227. package/dist/adapters/ton/reader.js.map +1 -0
  228. package/dist/adapters/ton/tokens.d.ts +10 -0
  229. package/dist/adapters/ton/tokens.js +27 -0
  230. package/dist/adapters/ton/tokens.js.map +1 -0
  231. package/dist/adapters/ton/trace.d.ts +48 -0
  232. package/dist/adapters/ton/trace.js +277 -0
  233. package/dist/adapters/ton/trace.js.map +1 -0
  234. package/dist/adapters/ton/types.d.ts +105 -0
  235. package/dist/{type/transact.js → adapters/ton/types.js} +1 -1
  236. package/dist/adapters/ton/types.js.map +1 -0
  237. package/dist/adapters/ton/wallets.d.ts +86 -0
  238. package/dist/adapters/ton/wallets.js +373 -0
  239. package/dist/adapters/ton/wallets.js.map +1 -0
  240. package/dist/adapters/tron/abi.d.ts +39 -0
  241. package/dist/adapters/tron/abi.js +110 -0
  242. package/dist/adapters/tron/abi.js.map +1 -0
  243. package/dist/adapters/tron/address.d.ts +20 -0
  244. package/dist/adapters/tron/address.js +110 -0
  245. package/dist/adapters/tron/address.js.map +1 -0
  246. package/dist/adapters/tron/builder.d.ts +12 -0
  247. package/dist/adapters/tron/builder.js +553 -0
  248. package/dist/adapters/tron/builder.js.map +1 -0
  249. package/dist/adapters/tron/chains.d.ts +12 -0
  250. package/dist/adapters/tron/chains.js +35 -0
  251. package/dist/adapters/tron/chains.js.map +1 -0
  252. package/dist/adapters/tron/codec.d.ts +10 -0
  253. package/dist/adapters/tron/codec.js +322 -0
  254. package/dist/adapters/tron/codec.js.map +1 -0
  255. package/dist/adapters/tron/decode.d.ts +50 -0
  256. package/dist/adapters/tron/decode.js +280 -0
  257. package/dist/adapters/tron/decode.js.map +1 -0
  258. package/dist/adapters/tron/driver.d.ts +12 -0
  259. package/dist/adapters/tron/driver.js +106 -0
  260. package/dist/adapters/tron/driver.js.map +1 -0
  261. package/dist/adapters/tron/errors.d.ts +74 -0
  262. package/dist/adapters/tron/errors.js +261 -0
  263. package/dist/adapters/tron/errors.js.map +1 -0
  264. package/dist/adapters/tron/fees.d.ts +49 -0
  265. package/dist/adapters/tron/fees.js +166 -0
  266. package/dist/adapters/tron/fees.js.map +1 -0
  267. package/dist/adapters/tron/http.d.ts +173 -0
  268. package/dist/adapters/tron/http.js +729 -0
  269. package/dist/adapters/tron/http.js.map +1 -0
  270. package/dist/adapters/tron/index.d.ts +16 -0
  271. package/dist/adapters/tron/index.js +15 -0
  272. package/dist/adapters/tron/index.js.map +1 -0
  273. package/dist/adapters/tron/network.d.ts +44 -0
  274. package/dist/adapters/tron/network.js +163 -0
  275. package/dist/adapters/tron/network.js.map +1 -0
  276. package/dist/adapters/tron/plugin.d.ts +17 -0
  277. package/dist/adapters/tron/plugin.js +39 -0
  278. package/dist/adapters/tron/plugin.js.map +1 -0
  279. package/dist/adapters/tron/presets.d.ts +5 -0
  280. package/dist/adapters/tron/presets.js +68 -0
  281. package/dist/adapters/tron/presets.js.map +1 -0
  282. package/dist/adapters/tron/proofs.d.ts +80 -0
  283. package/dist/adapters/tron/proofs.js +370 -0
  284. package/dist/adapters/tron/proofs.js.map +1 -0
  285. package/dist/adapters/tron/protobuf.d.ts +36 -0
  286. package/dist/adapters/tron/protobuf.js +90 -0
  287. package/dist/adapters/tron/protobuf.js.map +1 -0
  288. package/dist/adapters/tron/reader.d.ts +47 -0
  289. package/dist/adapters/tron/reader.js +203 -0
  290. package/dist/adapters/tron/reader.js.map +1 -0
  291. package/dist/adapters/tron/tokens.d.ts +7 -0
  292. package/dist/adapters/tron/tokens.js +14 -0
  293. package/dist/adapters/tron/tokens.js.map +1 -0
  294. package/dist/adapters/tron/types.d.ts +166 -0
  295. package/dist/adapters/tron/types.js +3 -0
  296. package/dist/adapters/tron/types.js.map +1 -0
  297. package/dist/adapters/utxo/address.d.ts +51 -0
  298. package/dist/adapters/utxo/address.js +341 -0
  299. package/dist/adapters/utxo/address.js.map +1 -0
  300. package/dist/adapters/utxo/builder.d.ts +35 -0
  301. package/dist/adapters/utxo/builder.js +380 -0
  302. package/dist/adapters/utxo/builder.js.map +1 -0
  303. package/dist/adapters/utxo/chains.d.ts +17 -0
  304. package/dist/adapters/utxo/chains.js +99 -0
  305. package/dist/adapters/utxo/chains.js.map +1 -0
  306. package/dist/adapters/utxo/codec.d.ts +120 -0
  307. package/dist/adapters/utxo/codec.js +408 -0
  308. package/dist/adapters/utxo/codec.js.map +1 -0
  309. package/dist/adapters/utxo/coinselect.d.ts +48 -0
  310. package/dist/adapters/utxo/coinselect.js +131 -0
  311. package/dist/adapters/utxo/coinselect.js.map +1 -0
  312. package/dist/adapters/utxo/context.d.ts +57 -0
  313. package/dist/adapters/utxo/context.js +118 -0
  314. package/dist/adapters/utxo/context.js.map +1 -0
  315. package/dist/adapters/utxo/decode.d.ts +14 -0
  316. package/dist/adapters/utxo/decode.js +85 -0
  317. package/dist/adapters/utxo/decode.js.map +1 -0
  318. package/dist/adapters/utxo/driver.d.ts +16 -0
  319. package/dist/adapters/utxo/driver.js +74 -0
  320. package/dist/adapters/utxo/driver.js.map +1 -0
  321. package/dist/adapters/utxo/ecc.d.ts +9 -0
  322. package/dist/adapters/utxo/ecc.js +26 -0
  323. package/dist/adapters/utxo/ecc.js.map +1 -0
  324. package/dist/adapters/utxo/errors.d.ts +52 -0
  325. package/dist/adapters/utxo/errors.js +191 -0
  326. package/dist/adapters/utxo/errors.js.map +1 -0
  327. package/dist/adapters/utxo/esplora.d.ts +79 -0
  328. package/dist/adapters/utxo/esplora.js +451 -0
  329. package/dist/adapters/utxo/esplora.js.map +1 -0
  330. package/dist/adapters/utxo/fees.d.ts +41 -0
  331. package/dist/adapters/utxo/fees.js +125 -0
  332. package/dist/adapters/utxo/fees.js.map +1 -0
  333. package/dist/adapters/utxo/index.d.ts +17 -0
  334. package/dist/adapters/utxo/index.js +8 -0
  335. package/dist/adapters/utxo/index.js.map +1 -0
  336. package/dist/adapters/utxo/network.d.ts +50 -0
  337. package/dist/adapters/utxo/network.js +165 -0
  338. package/dist/adapters/utxo/network.js.map +1 -0
  339. package/dist/adapters/utxo/plugin.d.ts +17 -0
  340. package/dist/adapters/utxo/plugin.js +41 -0
  341. package/dist/adapters/utxo/plugin.js.map +1 -0
  342. package/dist/adapters/utxo/presets.d.ts +12 -0
  343. package/dist/adapters/utxo/presets.js +47 -0
  344. package/dist/adapters/utxo/presets.js.map +1 -0
  345. package/dist/adapters/utxo/preview.d.ts +3 -0
  346. package/dist/adapters/utxo/preview.js +65 -0
  347. package/dist/adapters/utxo/preview.js.map +1 -0
  348. package/dist/adapters/utxo/proofs.d.ts +57 -0
  349. package/dist/adapters/utxo/proofs.js +331 -0
  350. package/dist/adapters/utxo/proofs.js.map +1 -0
  351. package/dist/adapters/utxo/rawtx.d.ts +59 -0
  352. package/dist/adapters/utxo/rawtx.js +234 -0
  353. package/dist/adapters/utxo/rawtx.js.map +1 -0
  354. package/dist/adapters/utxo/reader.d.ts +36 -0
  355. package/dist/adapters/utxo/reader.js +265 -0
  356. package/dist/adapters/utxo/reader.js.map +1 -0
  357. package/dist/adapters/utxo/sdk.d.ts +18 -0
  358. package/dist/adapters/utxo/sdk.js +17 -0
  359. package/dist/adapters/utxo/sdk.js.map +1 -0
  360. package/dist/adapters/utxo/signed-psbt.d.ts +36 -0
  361. package/dist/adapters/utxo/signed-psbt.js +428 -0
  362. package/dist/adapters/utxo/signed-psbt.js.map +1 -0
  363. package/dist/adapters/utxo/spend.d.ts +59 -0
  364. package/dist/adapters/utxo/spend.js +230 -0
  365. package/dist/adapters/utxo/spend.js.map +1 -0
  366. package/dist/adapters/utxo/types.d.ts +167 -0
  367. package/dist/adapters/utxo/types.js +3 -0
  368. package/dist/adapters/utxo/types.js.map +1 -0
  369. package/dist/core/assets/service.d.ts +18 -0
  370. package/dist/core/assets/service.js +69 -0
  371. package/dist/core/assets/service.js.map +1 -0
  372. package/dist/core/blockchain/default-ref.d.ts +4 -0
  373. package/dist/core/blockchain/default-ref.js +16 -0
  374. package/dist/core/blockchain/default-ref.js.map +1 -0
  375. package/dist/core/blockchain/handle.d.ts +200 -0
  376. package/dist/core/blockchain/handle.js +579 -0
  377. package/dist/core/blockchain/handle.js.map +1 -0
  378. package/dist/core/blockchain/internal.d.ts +19 -0
  379. package/dist/core/blockchain/internal.js +16 -0
  380. package/dist/core/blockchain/internal.js.map +1 -0
  381. package/dist/core/blockchain/mapping.d.ts +22 -0
  382. package/dist/core/blockchain/mapping.js +136 -0
  383. package/dist/core/blockchain/mapping.js.map +1 -0
  384. package/dist/core/config/env.d.ts +8 -0
  385. package/dist/core/config/env.js +60 -0
  386. package/dist/core/config/env.js.map +1 -0
  387. package/dist/core/config/merge.d.ts +26 -0
  388. package/dist/core/config/merge.js +144 -0
  389. package/dist/core/config/merge.js.map +1 -0
  390. package/dist/core/config/resolve.d.ts +12 -0
  391. package/dist/core/config/resolve.js +251 -0
  392. package/dist/core/config/resolve.js.map +1 -0
  393. package/dist/core/config/types.d.ts +165 -0
  394. package/dist/core/config/types.js +3 -0
  395. package/dist/core/config/types.js.map +1 -0
  396. package/dist/core/container/builtins.d.ts +4 -0
  397. package/dist/core/container/builtins.js +13 -0
  398. package/dist/core/container/builtins.js.map +1 -0
  399. package/dist/core/container/container.d.ts +69 -0
  400. package/dist/core/container/container.js +466 -0
  401. package/dist/core/container/container.js.map +1 -0
  402. package/dist/core/container/default.d.ts +15 -0
  403. package/dist/core/container/default.js +70 -0
  404. package/dist/core/container/default.js.map +1 -0
  405. package/dist/core/container/internals.d.ts +54 -0
  406. package/dist/core/container/internals.js +21 -0
  407. package/dist/core/container/internals.js.map +1 -0
  408. package/dist/core/container/pool.d.ts +27 -0
  409. package/dist/core/container/pool.js +77 -0
  410. package/dist/core/container/pool.js.map +1 -0
  411. package/dist/core/driver/types.d.ts +346 -0
  412. package/dist/core/driver/types.js +3 -0
  413. package/dist/core/driver/types.js.map +1 -0
  414. package/dist/core/errors/codes.d.ts +153 -0
  415. package/dist/core/errors/codes.js +49 -0
  416. package/dist/core/errors/codes.js.map +1 -0
  417. package/dist/core/errors/error.d.ts +66 -0
  418. package/dist/core/errors/error.js +129 -0
  419. package/dist/core/errors/error.js.map +1 -0
  420. package/dist/core/events/bus.d.ts +12 -0
  421. package/dist/core/events/bus.js +46 -0
  422. package/dist/core/events/bus.js.map +1 -0
  423. package/dist/core/events/logger.d.ts +13 -0
  424. package/dist/core/events/logger.js +42 -0
  425. package/dist/core/events/logger.js.map +1 -0
  426. package/dist/core/events/types.d.ts +131 -0
  427. package/dist/core/events/types.js +3 -0
  428. package/dist/core/events/types.js.map +1 -0
  429. package/dist/core/lifecycle/engine-rules.d.ts +107 -0
  430. package/dist/core/lifecycle/engine-rules.js +257 -0
  431. package/dist/core/lifecycle/engine-rules.js.map +1 -0
  432. package/dist/core/lifecycle/engine.d.ts +500 -0
  433. package/dist/core/lifecycle/engine.js +1732 -0
  434. package/dist/core/lifecycle/engine.js.map +1 -0
  435. package/dist/core/lifecycle/evaluate.d.ts +19 -0
  436. package/dist/core/lifecycle/evaluate.js +72 -0
  437. package/dist/core/lifecycle/evaluate.js.map +1 -0
  438. package/dist/core/lifecycle/intent.d.ts +11 -0
  439. package/dist/core/lifecycle/intent.js +88 -0
  440. package/dist/core/lifecycle/intent.js.map +1 -0
  441. package/dist/core/lifecycle/monitor.d.ts +138 -0
  442. package/dist/core/lifecycle/monitor.js +606 -0
  443. package/dist/core/lifecycle/monitor.js.map +1 -0
  444. package/dist/core/lifecycle/observations.d.ts +17 -0
  445. package/dist/core/lifecycle/observations.js +59 -0
  446. package/dist/core/lifecycle/observations.js.map +1 -0
  447. package/dist/core/lifecycle/reconcile.d.ts +58 -0
  448. package/dist/core/lifecycle/reconcile.js +112 -0
  449. package/dist/core/lifecycle/reconcile.js.map +1 -0
  450. package/dist/core/lifecycle/views.d.ts +49 -0
  451. package/dist/core/lifecycle/views.js +57 -0
  452. package/dist/core/lifecycle/views.js.map +1 -0
  453. package/dist/core/lifecycle/workers.d.ts +82 -0
  454. package/dist/core/lifecycle/workers.js +329 -0
  455. package/dist/core/lifecycle/workers.js.map +1 -0
  456. package/dist/core/model/address.d.ts +32 -0
  457. package/dist/core/model/address.js +43 -0
  458. package/dist/core/model/address.js.map +1 -0
  459. package/dist/core/model/amount.d.ts +25 -0
  460. package/dist/core/model/amount.js +102 -0
  461. package/dist/core/model/amount.js.map +1 -0
  462. package/dist/core/model/asset.d.ts +28 -0
  463. package/dist/core/model/asset.js +47 -0
  464. package/dist/core/model/asset.js.map +1 -0
  465. package/dist/core/model/capability.d.ts +3 -0
  466. package/dist/core/model/capability.js +18 -0
  467. package/dist/core/model/capability.js.map +1 -0
  468. package/dist/core/model/chain.d.ts +63 -0
  469. package/dist/core/model/chain.js +8 -0
  470. package/dist/core/model/chain.js.map +1 -0
  471. package/dist/core/model/fee.d.ts +36 -0
  472. package/dist/core/model/fee.js +17 -0
  473. package/dist/core/model/fee.js.map +1 -0
  474. package/dist/core/model/ids.d.ts +37 -0
  475. package/dist/core/model/ids.js +13 -0
  476. package/dist/core/model/ids.js.map +1 -0
  477. package/dist/core/model/intent.d.ts +63 -0
  478. package/dist/core/model/intent.js +81 -0
  479. package/dist/core/model/intent.js.map +1 -0
  480. package/dist/core/model/ordering.d.ts +20 -0
  481. package/dist/core/model/ordering.js +29 -0
  482. package/dist/core/model/ordering.js.map +1 -0
  483. package/dist/core/model/transaction.d.ts +116 -0
  484. package/dist/{type/lib-types.js → core/model/transaction.js} +1 -1
  485. package/dist/core/model/transaction.js.map +1 -0
  486. package/dist/core/observe/scanner.d.ts +135 -0
  487. package/dist/core/observe/scanner.js +355 -0
  488. package/dist/core/observe/scanner.js.map +1 -0
  489. package/dist/core/ordering/reservations.d.ts +16 -0
  490. package/dist/core/ordering/reservations.js +53 -0
  491. package/dist/core/ordering/reservations.js.map +1 -0
  492. package/dist/core/ordering/sequence.d.ts +61 -0
  493. package/dist/core/ordering/sequence.js +155 -0
  494. package/dist/core/ordering/sequence.js.map +1 -0
  495. package/dist/core/registry/adapters.d.ts +10 -0
  496. package/dist/core/registry/adapters.js +56 -0
  497. package/dist/core/registry/adapters.js.map +1 -0
  498. package/dist/core/registry/assets.d.ts +18 -0
  499. package/dist/core/registry/assets.js +90 -0
  500. package/dist/core/registry/assets.js.map +1 -0
  501. package/dist/core/registry/chains.d.ts +10 -0
  502. package/dist/core/registry/chains.js +80 -0
  503. package/dist/core/registry/chains.js.map +1 -0
  504. package/dist/core/registry/plugin.d.ts +41 -0
  505. package/dist/core/registry/plugin.js +109 -0
  506. package/dist/core/registry/plugin.js.map +1 -0
  507. package/dist/core/registry/providers.d.ts +31 -0
  508. package/dist/core/registry/providers.js +43 -0
  509. package/dist/core/registry/providers.js.map +1 -0
  510. package/dist/core/registry/schemes.d.ts +30 -0
  511. package/dist/core/registry/schemes.js +84 -0
  512. package/dist/core/registry/schemes.js.map +1 -0
  513. package/dist/core/secret/fragments.d.ts +33 -0
  514. package/dist/core/secret/fragments.js +110 -0
  515. package/dist/core/secret/fragments.js.map +1 -0
  516. package/dist/core/secret/redact.d.ts +10 -0
  517. package/dist/core/secret/redact.js +110 -0
  518. package/dist/core/secret/redact.js.map +1 -0
  519. package/dist/core/secret/secret.d.ts +14 -0
  520. package/dist/core/secret/secret.js +42 -0
  521. package/dist/core/secret/secret.js.map +1 -0
  522. package/dist/core/signing/callback.d.ts +10 -0
  523. package/dist/core/signing/callback.js +22 -0
  524. package/dist/core/signing/callback.js.map +1 -0
  525. package/dist/core/signing/guard.d.ts +18 -0
  526. package/dist/core/signing/guard.js +72 -0
  527. package/dist/core/signing/guard.js.map +1 -0
  528. package/dist/core/signing/hd.d.ts +36 -0
  529. package/dist/core/signing/hd.js +167 -0
  530. package/dist/core/signing/hd.js.map +1 -0
  531. package/dist/core/signing/local.d.ts +48 -0
  532. package/dist/core/signing/local.js +190 -0
  533. package/dist/core/signing/local.js.map +1 -0
  534. package/dist/core/signing/orchestrator.d.ts +40 -0
  535. package/dist/core/signing/orchestrator.js +300 -0
  536. package/dist/core/signing/orchestrator.js.map +1 -0
  537. package/dist/core/signing/types.d.ts +64 -0
  538. package/dist/core/signing/types.js +3 -0
  539. package/dist/core/signing/types.js.map +1 -0
  540. package/dist/core/signing/wallet.d.ts +48 -0
  541. package/dist/core/signing/wallet.js +153 -0
  542. package/dist/core/signing/wallet.js.map +1 -0
  543. package/dist/core/store/clone.d.ts +25 -0
  544. package/dist/core/store/clone.js +71 -0
  545. package/dist/core/store/clone.js.map +1 -0
  546. package/dist/core/store/memory.d.ts +38 -0
  547. package/dist/core/store/memory.js +325 -0
  548. package/dist/core/store/memory.js.map +1 -0
  549. package/dist/core/store/types.d.ts +246 -0
  550. package/dist/core/store/types.js +117 -0
  551. package/dist/core/store/types.js.map +1 -0
  552. package/dist/core/transport/backoff.d.ts +8 -0
  553. package/dist/core/transport/backoff.js +27 -0
  554. package/dist/core/transport/backoff.js.map +1 -0
  555. package/dist/core/transport/circuit.d.ts +25 -0
  556. package/dist/core/transport/circuit.js +61 -0
  557. package/dist/core/transport/circuit.js.map +1 -0
  558. package/dist/core/transport/http-transport.d.ts +30 -0
  559. package/dist/core/transport/http-transport.js +1695 -0
  560. package/dist/core/transport/http-transport.js.map +1 -0
  561. package/dist/core/transport/rate-limit.d.ts +27 -0
  562. package/dist/core/transport/rate-limit.js +78 -0
  563. package/dist/core/transport/rate-limit.js.map +1 -0
  564. package/dist/core/transport/stale-view.d.ts +11 -0
  565. package/dist/core/transport/stale-view.js +17 -0
  566. package/dist/core/transport/stale-view.js.map +1 -0
  567. package/dist/core/transport/types.d.ts +144 -0
  568. package/dist/core/transport/types.js +6 -0
  569. package/dist/core/transport/types.js.map +1 -0
  570. package/dist/core/util/bytes.d.ts +9 -0
  571. package/dist/core/util/bytes.js +40 -0
  572. package/dist/core/util/bytes.js.map +1 -0
  573. package/dist/core/util/clock.d.ts +6 -0
  574. package/dist/core/util/clock.js +26 -0
  575. package/dist/core/util/clock.js.map +1 -0
  576. package/dist/core/util/freeze.d.ts +8 -0
  577. package/dist/core/util/freeze.js +31 -0
  578. package/dist/core/util/freeze.js.map +1 -0
  579. package/dist/core/util/json.d.ts +29 -0
  580. package/dist/core/util/json.js +165 -0
  581. package/dist/core/util/json.js.map +1 -0
  582. package/dist/core/util/names.d.ts +21 -0
  583. package/dist/core/util/names.js +46 -0
  584. package/dist/core/util/names.js.map +1 -0
  585. package/dist/index.d.ts +64 -14
  586. package/dist/index.js +105 -49
  587. package/dist/index.js.map +1 -1
  588. package/dist/native.d.ts +21 -0
  589. package/dist/native.js +44 -0
  590. package/dist/native.js.map +1 -0
  591. package/dist/testing/contracts/api.d.ts +12 -0
  592. package/dist/testing/contracts/api.js +58 -0
  593. package/dist/testing/contracts/api.js.map +1 -0
  594. package/dist/testing/contracts/cursors.d.ts +6 -0
  595. package/dist/testing/contracts/cursors.js +43 -0
  596. package/dist/testing/contracts/cursors.js.map +1 -0
  597. package/dist/testing/contracts/locks.d.ts +10 -0
  598. package/dist/testing/contracts/locks.js +63 -0
  599. package/dist/testing/contracts/locks.js.map +1 -0
  600. package/dist/testing/contracts/operations.d.ts +21 -0
  601. package/dist/testing/contracts/operations.js +718 -0
  602. package/dist/testing/contracts/operations.js.map +1 -0
  603. package/dist/testing/contracts/sequences.d.ts +6 -0
  604. package/dist/testing/contracts/sequences.js +68 -0
  605. package/dist/testing/contracts/sequences.js.map +1 -0
  606. package/dist/testing/env.d.ts +63 -0
  607. package/dist/testing/env.js +105 -0
  608. package/dist/testing/env.js.map +1 -0
  609. package/dist/testing/fake-chain.d.ts +118 -0
  610. package/dist/testing/fake-chain.js +536 -0
  611. package/dist/testing/fake-chain.js.map +1 -0
  612. package/dist/testing/fake-clock.d.ts +15 -0
  613. package/dist/testing/fake-clock.js +86 -0
  614. package/dist/testing/fake-clock.js.map +1 -0
  615. package/dist/testing/fake-driver.d.ts +15 -0
  616. package/dist/testing/fake-driver.js +458 -0
  617. package/dist/testing/fake-driver.js.map +1 -0
  618. package/dist/testing/fake-fetch.d.ts +32 -0
  619. package/dist/testing/fake-fetch.js +81 -0
  620. package/dist/testing/fake-fetch.js.map +1 -0
  621. package/dist/testing/fake-plugin.d.ts +30 -0
  622. package/dist/testing/fake-plugin.js +66 -0
  623. package/dist/testing/fake-plugin.js.map +1 -0
  624. package/dist/testing/faulty-store.d.ts +36 -0
  625. package/dist/testing/faulty-store.js +66 -0
  626. package/dist/testing/faulty-store.js.map +1 -0
  627. package/dist/testing/generation.d.ts +60 -0
  628. package/dist/testing/generation.js +252 -0
  629. package/dist/testing/generation.js.map +1 -0
  630. package/dist/testing/index.d.ts +28 -0
  631. package/dist/testing/index.js +51 -0
  632. package/dist/testing/index.js.map +1 -0
  633. package/package.json +188 -45
  634. package/dist/libs/eth/account.d.ts +0 -9
  635. package/dist/libs/eth/account.js +0 -58
  636. package/dist/libs/eth/account.js.map +0 -1
  637. package/dist/libs/eth/contract.d.ts +0 -7
  638. package/dist/libs/eth/contract.js +0 -42
  639. package/dist/libs/eth/contract.js.map +0 -1
  640. package/dist/libs/eth/index.d.ts +0 -24
  641. package/dist/libs/eth/index.js +0 -72
  642. package/dist/libs/eth/index.js.map +0 -1
  643. package/dist/libs/eth/transact.d.ts +0 -7
  644. package/dist/libs/eth/transact.js +0 -26
  645. package/dist/libs/eth/transact.js.map +0 -1
  646. package/dist/libs/index.d.ts +0 -2
  647. package/dist/libs/index.js +0 -19
  648. package/dist/libs/index.js.map +0 -1
  649. package/dist/libs/trx/account.d.ts +0 -9
  650. package/dist/libs/trx/account.js +0 -55
  651. package/dist/libs/trx/account.js.map +0 -1
  652. package/dist/libs/trx/contract.d.ts +0 -7
  653. package/dist/libs/trx/contract.js +0 -27
  654. package/dist/libs/trx/contract.js.map +0 -1
  655. package/dist/libs/trx/index.d.ts +0 -22
  656. package/dist/libs/trx/index.js +0 -64
  657. package/dist/libs/trx/index.js.map +0 -1
  658. package/dist/libs/trx/transact.d.ts +0 -7
  659. package/dist/libs/trx/transact.js +0 -26
  660. package/dist/libs/trx/transact.js.map +0 -1
  661. package/dist/tool/common.d.ts +0 -28
  662. package/dist/tool/common.js +0 -33
  663. package/dist/tool/common.js.map +0 -1
  664. package/dist/tool/eth-tools.d.ts +0 -3
  665. package/dist/tool/eth-tools.js +0 -33
  666. package/dist/tool/eth-tools.js.map +0 -1
  667. package/dist/tool/index.d.ts +0 -5
  668. package/dist/tool/index.js +0 -22
  669. package/dist/tool/index.js.map +0 -1
  670. package/dist/tool/logging.d.ts +0 -3
  671. package/dist/tool/logging.js +0 -11
  672. package/dist/tool/logging.js.map +0 -1
  673. package/dist/tool/options.d.ts +0 -6
  674. package/dist/tool/options.js +0 -41
  675. package/dist/tool/options.js.map +0 -1
  676. package/dist/tool/trx-tools.d.ts +0 -3
  677. package/dist/tool/trx-tools.js +0 -20
  678. package/dist/tool/trx-tools.js.map +0 -1
  679. package/dist/type/account.d.ts +0 -9
  680. package/dist/type/account.js.map +0 -1
  681. package/dist/type/common.d.ts +0 -18
  682. package/dist/type/common.js.map +0 -1
  683. package/dist/type/contract.d.ts +0 -10
  684. package/dist/type/contract.js.map +0 -1
  685. package/dist/type/index.d.ts +0 -5
  686. package/dist/type/index.js +0 -22
  687. package/dist/type/index.js.map +0 -1
  688. package/dist/type/lib-types.d.ts +0 -9
  689. package/dist/type/lib-types.js.map +0 -1
  690. package/dist/type/transact.d.ts +0 -7
  691. package/dist/type/transact.js.map +0 -1
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.txidOfParts = exports.MAX_STRIPPED_BYTES = exports.MAX_TX_BYTES = void 0;
4
+ exports.writeU32 = writeU32;
5
+ exports.writeSize = writeSize;
6
+ exports.readTx = readTx;
7
+ exports.readTxHex = readTxHex;
8
+ /**
9
+ * A linear, SDK-free reader of untrusted transaction bytes.
10
+ *
11
+ * bitcoinjs-lib 7's `Transaction.fromBuffer` is quadratic in the number of inputs and
12
+ * outputs: a 3.98 MB transaction with 92,500 outputs took 53 s. So bytes from a node, an
13
+ * indexer or a coordinator are read here instead, in one pass. Every count is checked
14
+ * against the bytes left before anything is kept, scripts and witness items are views into
15
+ * the input (never copies), and the txid is hashed from the three stretches of the
16
+ * serialization it covers, without copying them.
17
+ *
18
+ * The format is exactly bitcoind's `UnserializeTransaction` with witness support (as
19
+ * `sendrawtransaction` decodes): an empty input list is followed by a flags byte; flags 1
20
+ * marks the witness (BIP144), and a witness record whose stacks are all empty, or any other
21
+ * flag, does not decode. Sizes are canonical CompactSize values of at most `MAX_SIZE`, and
22
+ * nothing may follow the lock time. So when this reader refuses bytes, bitcoind refuses them
23
+ * too, which lets the broadcaster check a node's `TX decode failed` itself: a node's
24
+ * rejection is a claim, kept only when it holds for our own bytes.
25
+ */
26
+ const sha256_1 = require("@noble/hashes/sha256");
27
+ const bytes_1 = require("../../core/util/bytes");
28
+ /** Bitcoin Core's `MAX_BLOCK_SERIALIZED_SIZE`: no transaction's bytes are more. */
29
+ exports.MAX_TX_BYTES = 4_000_000;
30
+ /**
31
+ * Consensus: a transaction's weight (4 × its size without witness data, at least) is at most
32
+ * `MAX_BLOCK_WEIGHT` (4,000,000), so a transaction a chain holds has at most 1,000,000 bytes
33
+ * without its witness.
34
+ */
35
+ exports.MAX_STRIPPED_BYTES = 1_000_000;
36
+ /** bitcoind's `MAX_SIZE`: the largest CompactSize a deserializer accepts. */
37
+ const MAX_SIZE = 0x02000000;
38
+ /** The fewest bytes an input (outpoint, empty script, sequence) and an output can take. */
39
+ const MIN_INPUT = 41;
40
+ const MIN_OUTPUT = 9;
41
+ class Malformed extends Error {
42
+ }
43
+ /** Double SHA-256 of the given stretches, as one message. */
44
+ function hash256(parts) {
45
+ const inner = sha256_1.sha256.create();
46
+ for (const part of parts)
47
+ inner.update(part);
48
+ return (0, sha256_1.sha256)(inner.digest());
49
+ }
50
+ /** A txid (or block hash) in display order. */
51
+ const displayHex = (hash) => (0, bytes_1.toHex)(Uint8Array.from(hash).reverse());
52
+ /** The txid of a serialization without witness data, given as consecutive stretches. */
53
+ const txidOfParts = (parts) => displayHex(hash256(parts));
54
+ exports.txidOfParts = txidOfParts;
55
+ /** A little-endian 32-bit field, as bitcoind writes it. */
56
+ function writeU32(n) {
57
+ const out = new Uint8Array(4);
58
+ new DataView(out.buffer).setUint32(0, n >>> 0, true);
59
+ return out;
60
+ }
61
+ /** A CompactSize, as bitcoind writes it (at most `MAX_SIZE` here). */
62
+ function writeSize(n) {
63
+ if (n < 0xfd)
64
+ return Uint8Array.of(n);
65
+ if (n <= 0xffff)
66
+ return Uint8Array.of(0xfd, n & 0xff, n >>> 8);
67
+ return (0, bytes_1.concatBytes)(Uint8Array.of(0xfe), writeU32(n));
68
+ }
69
+ /** Transaction bytes, read in one pass; `undefined` when bitcoind would not decode them. */
70
+ function readTx(bytes, options = {}) {
71
+ const maxStripped = options.maxStripped ?? exports.MAX_STRIPPED_BYTES;
72
+ if (!(bytes instanceof Uint8Array) || bytes.length > exports.MAX_TX_BYTES)
73
+ return undefined;
74
+ try {
75
+ return parse(bytes, maxStripped);
76
+ }
77
+ catch (error) {
78
+ if (error instanceof Malformed)
79
+ return undefined;
80
+ throw error;
81
+ }
82
+ }
83
+ /**
84
+ * Transaction hex (either case, no prefix), capped at `MAX_TX_BYTES` before it is
85
+ * decoded, then read by `readTx`. Node's hex decoder is native and linear, and stops at
86
+ * the first pair that is not hex, so a short result means the text was not plain hex.
87
+ */
88
+ function readTxHex(hex, options = {}) {
89
+ if (typeof hex !== 'string' || hex.length > 2 * exports.MAX_TX_BYTES)
90
+ return undefined;
91
+ if (hex.length % 2 !== 0)
92
+ return undefined;
93
+ const decoded = Buffer.from(hex, 'hex');
94
+ if (decoded.length * 2 !== hex.length)
95
+ return undefined;
96
+ return readTx(new Uint8Array(decoded.buffer, decoded.byteOffset, decoded.length), options);
97
+ }
98
+ function parse(bytes, maxStripped) {
99
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
100
+ let pos = 0;
101
+ const need = (n) => {
102
+ if (n < 0 || pos + n > bytes.length)
103
+ throw new Malformed();
104
+ };
105
+ const u8 = () => {
106
+ need(1);
107
+ return bytes[pos++];
108
+ };
109
+ const u32 = () => {
110
+ need(4);
111
+ const value = view.getUint32(pos, true);
112
+ pos += 4;
113
+ return value;
114
+ };
115
+ const slice = (n) => {
116
+ need(n);
117
+ const part = bytes.subarray(pos, pos + n);
118
+ pos += n;
119
+ return part;
120
+ };
121
+ /** A canonical CompactSize of at most `MAX_SIZE` (bitcoind's `ReadCompactSize`). */
122
+ const size = () => {
123
+ const first = u8();
124
+ let value;
125
+ if (first < 0xfd)
126
+ return first;
127
+ if (first === 0xfd) {
128
+ need(2);
129
+ value = view.getUint16(pos, true);
130
+ pos += 2;
131
+ if (value < 0xfd)
132
+ throw new Malformed();
133
+ }
134
+ else if (first === 0xfe) {
135
+ value = u32();
136
+ if (value < 0x1_0000)
137
+ throw new Malformed();
138
+ }
139
+ else {
140
+ throw new Malformed(); // 8 bytes: at least 2^32, beyond MAX_SIZE
141
+ }
142
+ if (value > MAX_SIZE)
143
+ throw new Malformed();
144
+ return value;
145
+ };
146
+ /** Bounds a count by the bytes left, before anything is kept for it. */
147
+ const count = (least) => {
148
+ const n = size();
149
+ if (n * least > bytes.length - pos)
150
+ throw new Malformed();
151
+ return n;
152
+ };
153
+ // `skipped`: the marker and flag bytes, which the stripped serialization leaves out.
154
+ let skipped = 0;
155
+ const strippedSoFar = () => pos - skipped + 4; // with the lock time still to come
156
+ const version = u32() | 0;
157
+ let vinStart = pos;
158
+ let inputCount = count(MIN_INPUT);
159
+ let extended = false;
160
+ let outputsKnown = true;
161
+ if (inputCount === 0) {
162
+ const flags = u8();
163
+ if (flags === 0) {
164
+ outputsKnown = false; // bitcoind reads no output list after an empty one and no flags
165
+ }
166
+ else {
167
+ if (flags !== 1)
168
+ throw new Malformed(); // unknown optional data
169
+ extended = true;
170
+ skipped = 2;
171
+ vinStart = pos;
172
+ inputCount = count(MIN_INPUT);
173
+ }
174
+ }
175
+ const inputs = [];
176
+ for (let i = 0; i < inputCount; i++) {
177
+ const hash = slice(32);
178
+ const vout = u32();
179
+ const script = slice(size());
180
+ const sequence = u32();
181
+ inputs.push({ txid: displayHex(hash), hash, vout, script, sequence, witness: [] });
182
+ if (strippedSoFar() > maxStripped)
183
+ throw new Malformed();
184
+ }
185
+ const outputStart = pos;
186
+ const outputs = [];
187
+ if (outputsKnown) {
188
+ const outputCount = count(MIN_OUTPUT);
189
+ for (let i = 0; i < outputCount; i++) {
190
+ need(8);
191
+ const value = view.getBigInt64(pos, true);
192
+ pos += 8;
193
+ outputs.push({ value, script: slice(size()) });
194
+ if (strippedSoFar() > maxStripped)
195
+ throw new Malformed();
196
+ }
197
+ }
198
+ const outputEnd = pos;
199
+ let hasWitness = false;
200
+ if (extended) {
201
+ for (const input of inputs) {
202
+ const items = count(1);
203
+ const stack = [];
204
+ for (let i = 0; i < items; i++)
205
+ stack.push(slice(size()));
206
+ input.witness = stack;
207
+ if (items > 0)
208
+ hasWitness = true;
209
+ }
210
+ if (!hasWitness)
211
+ throw new Malformed(); // a superfluous witness record
212
+ }
213
+ const locktime = u32();
214
+ if (pos !== bytes.length)
215
+ throw new Malformed();
216
+ const parts = extended
217
+ ? [bytes.subarray(0, 4), bytes.subarray(vinStart, outputEnd), bytes.subarray(pos - 4)]
218
+ : [bytes];
219
+ const stripped = parts.reduce((sum, part) => sum + part.length, 0);
220
+ if (stripped > maxStripped)
221
+ throw new Malformed();
222
+ return {
223
+ txid: (0, exports.txidOfParts)(parts),
224
+ version,
225
+ locktime,
226
+ inputs,
227
+ outputs,
228
+ hasWitness,
229
+ strippedSize: stripped,
230
+ outputBytes: bytes.subarray(outputStart, outputEnd),
231
+ stripped: () => (parts.length === 1 ? bytes : (0, bytes_1.concatBytes)(...parts)),
232
+ };
233
+ }
234
+ //# sourceMappingURL=rawtx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rawtx.js","sourceRoot":"","sources":["../../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GAAG,QAAQ;QACpB,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;QACtF,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACZ,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACnE,IAAI,QAAQ,GAAG,WAAW;QAAE,MAAM,IAAI,SAAS,EAAE,CAAC;IAClD,OAAO;QACL,IAAI,EAAE,IAAA,mBAAW,EAAC,KAAK,CAAC;QACxB,OAAO;QACP,QAAQ;QACR,MAAM;QACN,OAAO;QACP,UAAU;QACV,YAAY,EAAE,QAAQ;QACtB,WAAW,EAAE,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE,SAAS,CAAC;QACnD,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAA,mBAAW,EAAC,GAAG,KAAK,CAAC,CAAC;KACrE,CAAC;AACJ,CAAC","sourcesContent":["/**\n * A linear, SDK-free reader of untrusted transaction bytes.\n *\n * bitcoinjs-lib 7's `Transaction.fromBuffer` is quadratic in the number of inputs and\n * outputs: a 3.98 MB transaction with 92,500 outputs took 53 s. So bytes from a node, an\n * indexer or a coordinator are read here instead, in one pass. Every count is checked\n * against the bytes left before anything is kept, scripts and witness items are views into\n * the input (never copies), and the txid is hashed from the three stretches of the\n * serialization it covers, without copying them.\n *\n * The format is exactly bitcoind's `UnserializeTransaction` with witness support (as\n * `sendrawtransaction` decodes): an empty input list is followed by a flags byte; flags 1\n * marks the witness (BIP144), and a witness record whose stacks are all empty, or any other\n * flag, does not decode. Sizes are canonical CompactSize values of at most `MAX_SIZE`, and\n * nothing may follow the lock time. So when this reader refuses bytes, bitcoind refuses them\n * too, which lets the broadcaster check a node's `TX decode failed` itself: a node's\n * rejection is a claim, kept only when it holds for our own bytes.\n */\nimport { sha256 } from '@noble/hashes/sha256';\nimport { concatBytes, toHex } from '../../core/util/bytes';\n\n/** Bitcoin Core's `MAX_BLOCK_SERIALIZED_SIZE`: no transaction's bytes are more. */\nexport const MAX_TX_BYTES = 4_000_000;\n/**\n * Consensus: a transaction's weight (4 × its size without witness data, at least) is at most\n * `MAX_BLOCK_WEIGHT` (4,000,000), so a transaction a chain holds has at most 1,000,000 bytes\n * without its witness.\n */\nexport const MAX_STRIPPED_BYTES = 1_000_000;\n/** bitcoind's `MAX_SIZE`: the largest CompactSize a deserializer accepts. */\nconst MAX_SIZE = 0x02000000;\n/** The fewest bytes an input (outpoint, empty script, sequence) and an output can take. */\nconst MIN_INPUT = 41;\nconst MIN_OUTPUT = 9;\n\nexport interface ParsedInput {\n /** The previous txid, in display order (the reverse of the serialized hash). */\n readonly txid: string;\n /** The previous transaction's hash as serialized (internal byte order): a view. */\n readonly hash: Uint8Array;\n readonly vout: number;\n readonly script: Uint8Array;\n readonly sequence: number;\n readonly witness: readonly Uint8Array[];\n}\n\nexport interface ParsedOutput {\n /** As bitcoind reads it: a signed 64-bit integer. */\n readonly value: bigint;\n readonly script: Uint8Array;\n}\n\nexport interface ParsedTx {\n readonly txid: string;\n readonly version: number;\n readonly locktime: number;\n readonly inputs: readonly ParsedInput[];\n readonly outputs: readonly ParsedOutput[];\n readonly hasWitness: boolean;\n /** The size without witness data (bitcoind's `TX_NO_WITNESS` serialization). */\n readonly strippedSize: number;\n /** The output list as serialized (its count, then each output): a view. */\n readonly outputBytes: Uint8Array;\n /** The serialization without witness data (BIP174 `non_witness_utxo`). */\n stripped(): Uint8Array;\n}\n\nexport interface ReadOptions {\n /**\n * The most bytes without witness data: `MAX_STRIPPED_BYTES` (the default) for data a chain\n * holds; the broadcaster reads what it sent with `MAX_TX_BYTES`, so every size bitcoind\n * decodes is read (bitcoind refuses a larger one later, as `bad-txns-oversize`).\n */\n readonly maxStripped?: number;\n}\n\nclass Malformed extends Error {}\n\n/** Double SHA-256 of the given stretches, as one message. */\nfunction hash256(parts: readonly Uint8Array[]): Uint8Array {\n const inner = sha256.create();\n for (const part of parts) inner.update(part);\n return sha256(inner.digest());\n}\n\n/** A txid (or block hash) in display order. */\nconst displayHex = (hash: Uint8Array): string => toHex(Uint8Array.from(hash).reverse());\n\n/** The txid of a serialization without witness data, given as consecutive stretches. */\nexport const txidOfParts = (parts: readonly Uint8Array[]): string =>\n displayHex(hash256(parts));\n\n/** A little-endian 32-bit field, as bitcoind writes it. */\nexport function writeU32(n: number): Uint8Array {\n const out = new Uint8Array(4);\n new DataView(out.buffer).setUint32(0, n >>> 0, true);\n return out;\n}\n\n/** A CompactSize, as bitcoind writes it (at most `MAX_SIZE` here). */\nexport function writeSize(n: number): Uint8Array {\n if (n < 0xfd) return Uint8Array.of(n);\n if (n <= 0xffff) return Uint8Array.of(0xfd, n & 0xff, n >>> 8);\n return concatBytes(Uint8Array.of(0xfe), writeU32(n));\n}\n\n/** Transaction bytes, read in one pass; `undefined` when bitcoind would not decode them. */\nexport function readTx(\n bytes: Uint8Array,\n options: ReadOptions = {},\n): ParsedTx | undefined {\n const maxStripped = options.maxStripped ?? MAX_STRIPPED_BYTES;\n if (!(bytes instanceof Uint8Array) || bytes.length > MAX_TX_BYTES) return undefined;\n try {\n return parse(bytes, maxStripped);\n } catch (error) {\n if (error instanceof Malformed) return undefined;\n throw error;\n }\n}\n\n/**\n * Transaction hex (either case, no prefix), capped at `MAX_TX_BYTES` before it is\n * decoded, then read by `readTx`. Node's hex decoder is native and linear, and stops at\n * the first pair that is not hex, so a short result means the text was not plain hex.\n */\nexport function readTxHex(hex: string, options: ReadOptions = {}): ParsedTx | undefined {\n if (typeof hex !== 'string' || hex.length > 2 * MAX_TX_BYTES) return undefined;\n if (hex.length % 2 !== 0) return undefined;\n const decoded = Buffer.from(hex, 'hex');\n if (decoded.length * 2 !== hex.length) return undefined;\n return readTx(\n new Uint8Array(decoded.buffer, decoded.byteOffset, decoded.length),\n options,\n );\n}\n\nfunction parse(bytes: Uint8Array, maxStripped: number): ParsedTx {\n const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n let pos = 0;\n const need = (n: number): void => {\n if (n < 0 || pos + n > bytes.length) throw new Malformed();\n };\n const u8 = (): number => {\n need(1);\n return bytes[pos++] as number;\n };\n const u32 = (): number => {\n need(4);\n const value = view.getUint32(pos, true);\n pos += 4;\n return value;\n };\n const slice = (n: number): Uint8Array => {\n need(n);\n const part = bytes.subarray(pos, pos + n);\n pos += n;\n return part;\n };\n /** A canonical CompactSize of at most `MAX_SIZE` (bitcoind's `ReadCompactSize`). */\n const size = (): number => {\n const first = u8();\n let value: number;\n if (first < 0xfd) return first;\n if (first === 0xfd) {\n need(2);\n value = view.getUint16(pos, true);\n pos += 2;\n if (value < 0xfd) throw new Malformed();\n } else if (first === 0xfe) {\n value = u32();\n if (value < 0x1_0000) throw new Malformed();\n } else {\n throw new Malformed(); // 8 bytes: at least 2^32, beyond MAX_SIZE\n }\n if (value > MAX_SIZE) throw new Malformed();\n return value;\n };\n /** Bounds a count by the bytes left, before anything is kept for it. */\n const count = (least: number): number => {\n const n = size();\n if (n * least > bytes.length - pos) throw new Malformed();\n return n;\n };\n\n // `skipped`: the marker and flag bytes, which the stripped serialization leaves out.\n let skipped = 0;\n const strippedSoFar = (): number => pos - skipped + 4; // with the lock time still to come\n const version = u32() | 0;\n let vinStart = pos;\n let inputCount = count(MIN_INPUT);\n let extended = false;\n let outputsKnown = true;\n if (inputCount === 0) {\n const flags = u8();\n if (flags === 0) {\n outputsKnown = false; // bitcoind reads no output list after an empty one and no flags\n } else {\n if (flags !== 1) throw new Malformed(); // unknown optional data\n extended = true;\n skipped = 2;\n vinStart = pos;\n inputCount = count(MIN_INPUT);\n }\n }\n const inputs: {\n txid: string;\n hash: Uint8Array;\n vout: number;\n script: Uint8Array;\n sequence: number;\n witness: readonly Uint8Array[];\n }[] = [];\n for (let i = 0; i < inputCount; i++) {\n const hash = slice(32);\n const vout = u32();\n const script = slice(size());\n const sequence = u32();\n inputs.push({ txid: displayHex(hash), hash, vout, script, sequence, witness: [] });\n if (strippedSoFar() > maxStripped) throw new Malformed();\n }\n const outputStart = pos;\n const outputs: ParsedOutput[] = [];\n if (outputsKnown) {\n const outputCount = count(MIN_OUTPUT);\n for (let i = 0; i < outputCount; i++) {\n need(8);\n const value = view.getBigInt64(pos, true);\n pos += 8;\n outputs.push({ value, script: slice(size()) });\n if (strippedSoFar() > maxStripped) throw new Malformed();\n }\n }\n const outputEnd = pos;\n let hasWitness = false;\n if (extended) {\n for (const input of inputs) {\n const items = count(1);\n const stack: Uint8Array[] = [];\n for (let i = 0; i < items; i++) stack.push(slice(size()));\n input.witness = stack;\n if (items > 0) hasWitness = true;\n }\n if (!hasWitness) throw new Malformed(); // a superfluous witness record\n }\n const locktime = u32();\n if (pos !== bytes.length) throw new Malformed();\n const parts = extended\n ? [bytes.subarray(0, 4), bytes.subarray(vinStart, outputEnd), bytes.subarray(pos - 4)]\n : [bytes];\n const stripped = parts.reduce((sum, part) => sum + part.length, 0);\n if (stripped > maxStripped) throw new Malformed();\n return {\n txid: txidOfParts(parts),\n version,\n locktime,\n inputs,\n outputs,\n hasWitness,\n strippedSize: stripped,\n outputBytes: bytes.subarray(outputStart, outputEnd),\n stripped: () => (parts.length === 1 ? bytes : concatBytes(...parts)),\n };\n}\n"]}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Bitcoin addresses, point reads, observation, address history and `ext.utxo.listUnspent`.
3
+ * Every call carries the tags of the `ChainDriver` contract table: `read` for point
4
+ * queries, `monitor` for heights and observations; address reads go to the indexer.
5
+ */
6
+ import type { AddressCodec, AddressHistorySource, ChainReader } from '../../core/driver/types';
7
+ import { type UtxoContext } from './context';
8
+ import type { UtxoCallTags, UtxoUnspent } from './types';
9
+ export declare function addressCodec(ctx: UtxoContext): AddressCodec;
10
+ /**
11
+ * Whether `spender` is a miner-malleated copy of our p2pkh Attempt `refId`. Its raw
12
+ * bytes are read under `tags` and authenticate themselves: under a quorum the client keys
13
+ * the answers on the txid they hash to, and it refuses bytes that do not hash to `spender`
14
+ * (a retryable `PROVIDER_INCONSISTENT`). They are then canonicalized: equality with `refId`
15
+ * proves the same version, lock time, outpoints, sequences and outputs. Segwit and taproot
16
+ * txids exclude the witness and cannot be malleated, so nothing is read for them.
17
+ */
18
+ export declare function isOwnCopy(ctx: UtxoContext, refId: string, from: string, spender: string, tags: UtxoCallTags): Promise<boolean>;
19
+ /** The highest block with the network's confirmations, from one `monitor` read. */
20
+ export declare function finalizedFromHead(ctx: UtxoContext, head: bigint): bigint;
21
+ export declare function chainReader(ctx: UtxoContext): ChainReader;
22
+ /**
23
+ * Confirmed history, newest first (Esplora pages of 25; the cursor is the last txid). A full
24
+ * page, of any size a server chooses, may have a next one. The answer is filtered to the
25
+ * address asked for: a server that dropped its filter never lists another
26
+ * address's transaction, and every transaction served counts toward `limit`, so paging stays
27
+ * bounded.
28
+ */
29
+ export declare function addressHistory(ctx: UtxoContext): AddressHistorySource;
30
+ /**
31
+ * `ext.utxo.listUnspent`: confirmed first (oldest first), then unconfirmed. An output the
32
+ * indexer names twice alike is listed once; named twice differently (another value or
33
+ * status), the answer is malformed, and so is a list worth more than every bitcoin. Coin
34
+ * selection reads the wallet's outputs through it (`spendable`, with the build's signal).
35
+ */
36
+ export declare function listUnspent(ctx: UtxoContext, address: string, signal?: AbortSignal): Promise<UtxoUnspent[]>;
@@ -0,0 +1,265 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addressCodec = addressCodec;
4
+ exports.isOwnCopy = isOwnCopy;
5
+ exports.finalizedFromHead = finalizedFromHead;
6
+ exports.chainReader = chainReader;
7
+ exports.addressHistory = addressHistory;
8
+ exports.listUnspent = listUnspent;
9
+ const error_1 = require("../../core/errors/error");
10
+ const bytes_1 = require("../../core/util/bytes");
11
+ const address_1 = require("./address");
12
+ const context_1 = require("./context");
13
+ const codec_1 = require("./codec");
14
+ const decode_1 = require("./decode");
15
+ const esplora_1 = require("./esplora");
16
+ /** Esplora's page of address history (electrs' `CHAIN_TXS_PER_PAGE`). */
17
+ const HISTORY_PAGE = 25;
18
+ const MAX_HEIGHT = BigInt(Number.MAX_SAFE_INTEGER);
19
+ /** Two reads of one index that contradict each other decide nothing (retryable). */
20
+ const contradiction = (reason) => new error_1.ProviderError('PROVIDER_INCONSISTENT', reason, { retryable: true });
21
+ const normalized = (canonical, type) => ({
22
+ canonical,
23
+ display: canonical,
24
+ variant: { type },
25
+ });
26
+ function addressCodec(ctx) {
27
+ const params = ctx.config.address;
28
+ return {
29
+ validate: (address) => {
30
+ try {
31
+ (0, address_1.decodeAddress)(address, params);
32
+ return true;
33
+ }
34
+ catch {
35
+ return false;
36
+ }
37
+ },
38
+ normalize: (address) => {
39
+ const decoded = (0, address_1.decodeAddress)(address, params);
40
+ return normalized(decoded.canonical, decoded.type);
41
+ },
42
+ fromPublicKey: (publicKey, wallet) => {
43
+ const { addressType } = (0, context_1.parseWalletOptions)(wallet, ctx.config);
44
+ const derived = (0, address_1.walletAddress)(publicKey, addressType, params);
45
+ return normalized(derived.address, derived.type === 'p2sh-p2wpkh' ? 'p2sh' : derived.type);
46
+ },
47
+ };
48
+ }
49
+ /** The key hash of a p2pkh sending address, or `undefined` for every other type. */
50
+ function p2pkhKeyHash(ctx, from) {
51
+ try {
52
+ const decoded = (0, address_1.decodeAddress)(from, ctx.config.address);
53
+ return decoded.type === 'p2pkh' ? decoded.script.slice(3, 23) : undefined;
54
+ }
55
+ catch {
56
+ return undefined;
57
+ }
58
+ }
59
+ /**
60
+ * Whether `spender` is a miner-malleated copy of our p2pkh Attempt `refId`. Its raw
61
+ * bytes are read under `tags` and authenticate themselves: under a quorum the client keys
62
+ * the answers on the txid they hash to, and it refuses bytes that do not hash to `spender`
63
+ * (a retryable `PROVIDER_INCONSISTENT`). They are then canonicalized: equality with `refId`
64
+ * proves the same version, lock time, outpoints, sequences and outputs. Segwit and taproot
65
+ * txids exclude the witness and cannot be malleated, so nothing is read for them.
66
+ */
67
+ async function isOwnCopy(ctx, refId, from, spender, tags) {
68
+ const keyHash = p2pkhKeyHash(ctx, from);
69
+ if (!keyHash)
70
+ return false;
71
+ const hex = await ctx.esplora.txHex(spender, tags);
72
+ if (hex === null) {
73
+ throw new error_1.ProviderError('PROVIDER_UNAVAILABLE', 'the spending transaction is not available');
74
+ }
75
+ return (0, codec_1.canonicalTwinTxid)(hex, keyHash) === refId;
76
+ }
77
+ /** The highest block with the network's confirmations, from one `monitor` read. */
78
+ function finalizedFromHead(ctx, head) {
79
+ const height = head - BigInt(ctx.config.confirmations) + 1n;
80
+ return height < 0n ? 0n : height;
81
+ }
82
+ function chainReader(ctx) {
83
+ const { esplora, config } = ctx;
84
+ const block = async (hash, height) => {
85
+ const found = await esplora.block(hash, context_1.READ);
86
+ if (!found)
87
+ return null;
88
+ // The block at a height must say it is at that height. A block's height never
89
+ // changes, so only a lie or a server bug trips this; it decides nothing (retryable).
90
+ if (height !== undefined && found.height !== height) {
91
+ throw contradiction('the block at the height asked for is at another height');
92
+ }
93
+ const transactionIds = await esplora.blockTxids(found.hash, context_1.READ);
94
+ if (transactionIds.length !== found.txCount)
95
+ throw (0, esplora_1.malformed)('block txids');
96
+ return {
97
+ height: found.height,
98
+ hash: found.hash,
99
+ parentHash: found.parentHash,
100
+ timestamp: found.timestamp,
101
+ transactionIds,
102
+ };
103
+ };
104
+ return {
105
+ getBalance: async (address, asset) => {
106
+ (0, context_1.assertNative)(asset);
107
+ const stats = await esplora.addressStats((0, address_1.decodeAddress)(address, config.address).canonical, context_1.READ);
108
+ return stats.funded - stats.spent;
109
+ },
110
+ getBlockHeight: () => esplora.tipHeight(context_1.MONITOR),
111
+ getFinalizedHeight: async () => finalizedFromHead(ctx, await esplora.tipHeight(context_1.MONITOR)),
112
+ getBlock: async (ref) => {
113
+ if (typeof ref === 'string') {
114
+ const id = ref.toLowerCase();
115
+ return (0, esplora_1.isHash)(id) ? block(id) : null; // a malformed id never reaches a path
116
+ }
117
+ // No block is below 0 or beyond what a server can parse: never sent.
118
+ if (ref < 0n || ref > MAX_HEIGHT)
119
+ return null;
120
+ const hash = await esplora.blockHashAt(ref, context_1.READ);
121
+ return hash ? block(hash, ref) : null;
122
+ },
123
+ getTransaction: async (raw) => {
124
+ const id = raw.toLowerCase();
125
+ if (!(0, esplora_1.isHash)(id))
126
+ return null; // a malformed id never reaches a path
127
+ const tx = await esplora.tx(id, context_1.READ);
128
+ return tx ? (0, decode_1.decodeTransaction)(tx, config.address) : null;
129
+ },
130
+ observe: async (ref, ordering, from) => {
131
+ const id = ref.id.toLowerCase();
132
+ if (!(0, esplora_1.isHash)(id))
133
+ return { seen: 'none' }; // a malformed id never reaches a path
134
+ // A refusal on any of these reads decides nothing (retryable).
135
+ return (0, context_1.proofRead)(async () => {
136
+ // `/tx/:txid/status` answers `confirmed: false` for a transaction it does not know,
137
+ // so visibility is read from `/tx/:txid`, which is a 404 then.
138
+ const tx = await esplora.tx(id, context_1.MONITOR);
139
+ if (tx?.status.confirmed)
140
+ return (0, decode_1.observationOf)(tx.txid, tx.status);
141
+ const first = ordering?.kind === 'inputs' ? ordering.inputs[0] : undefined;
142
+ // A status lookup by id (no ordering) reports the index as it is.
143
+ if (first === undefined)
144
+ return tx ? (0, decode_1.observationOf)(tx.txid, tx.status) : { seen: 'none' };
145
+ const legacy = from !== undefined && p2pkhKeyHash(ctx, from) ? from : undefined;
146
+ // Unknown, and a segwit or taproot txid cannot be malleated: nothing more to learn.
147
+ if (!tx && legacy === undefined)
148
+ return { seen: 'none' };
149
+ const input = (0, context_1.parseOutpoint)(first);
150
+ // Full-mode electrs keeps serving a reorg-dropped transaction as unconfirmed,
151
+ // and `/status` cannot tell a mempool transaction from one only in its txstore. The
152
+ // first input's spender can: chain spends of a disconnected block are gone, then the
153
+ // mempool's are read. Ours: in a mempool. None: in no mempool of this index (the core
154
+ // rebroadcasts a dropped Attempt). Another: conflicted, or our malleated copy.
155
+ // Observed evidence only: an index still syncing can briefly say otherwise.
156
+ const spend = await esplora.outspend(input.txid, input.vout, context_1.MONITOR);
157
+ if (!spend.spent || spend.txid === undefined)
158
+ return { seen: 'none' };
159
+ if (spend.txid === id) {
160
+ if (tx)
161
+ return (0, decode_1.observationOf)(tx.txid, tx.status);
162
+ throw contradiction('the index spends with a transaction it does not know');
163
+ }
164
+ // Our own p2pkh Attempt, mined as a malleated copy (observed evidence only; only
165
+ // `includedFinal`'s quorum path can make it terminal).
166
+ if (legacy === undefined ||
167
+ !(await isOwnCopy(ctx, id, legacy, spend.txid, context_1.MONITOR)))
168
+ return { seen: 'none' };
169
+ const copy = await esplora.tx(spend.txid, context_1.MONITOR);
170
+ if (!copy)
171
+ throw contradiction('the index spends with a transaction it does not know');
172
+ return (0, decode_1.observationOf)(copy.txid, copy.status);
173
+ });
174
+ },
175
+ };
176
+ }
177
+ /**
178
+ * Confirmed history, newest first (Esplora pages of 25; the cursor is the last txid). A full
179
+ * page, of any size a server chooses, may have a next one. The answer is filtered to the
180
+ * address asked for: a server that dropped its filter never lists another
181
+ * address's transaction, and every transaction served counts toward `limit`, so paging stays
182
+ * bounded.
183
+ */
184
+ function addressHistory(ctx) {
185
+ return {
186
+ async list(address, { cursor, limit }) {
187
+ if (!Number.isSafeInteger(limit) || limit < 1) {
188
+ throw new error_1.ValidationError('INVALID_INTENT', 'limit must be a positive integer');
189
+ }
190
+ if (cursor !== undefined && !/^[0-9a-f]{64}$/.test(cursor)) {
191
+ throw new error_1.ValidationError('INVALID_INTENT', 'malformed history cursor');
192
+ }
193
+ const decoded = (0, address_1.decodeAddress)(address, ctx.config.address);
194
+ const script = (0, bytes_1.toHex)(decoded.script);
195
+ const touches = (tx) => tx.vout.some((output) => output.script === script) ||
196
+ tx.vin.some((input) => input.prevout?.script === script);
197
+ const items = [];
198
+ let served = 0;
199
+ let last = cursor;
200
+ let more = true;
201
+ while (served < limit && more) {
202
+ const page = await ctx.esplora.addressTxs(decoded.canonical, last, context_1.READ);
203
+ const taken = page.slice(0, limit - served);
204
+ for (const tx of taken) {
205
+ if (touches(tx))
206
+ items.push((0, decode_1.decodeTransaction)(tx, ctx.config.address));
207
+ last = tx.txid;
208
+ served++;
209
+ }
210
+ more = taken.length < page.length || page.length >= HISTORY_PAGE;
211
+ }
212
+ return { items, ...(more && last !== undefined ? { next: last } : {}) };
213
+ },
214
+ };
215
+ }
216
+ /**
217
+ * `ext.utxo.listUnspent`: confirmed first (oldest first), then unconfirmed. An output the
218
+ * indexer names twice alike is listed once; named twice differently (another value or
219
+ * status), the answer is malformed, and so is a list worth more than every bitcoin. Coin
220
+ * selection reads the wallet's outputs through it (`spendable`, with the build's signal).
221
+ */
222
+ async function listUnspent(ctx, address, signal) {
223
+ const canonical = (0, address_1.decodeAddress)(address, ctx.config.address).canonical;
224
+ const listed = await ctx.esplora.addressUtxos(canonical, (0, context_1.withSignal)(context_1.READ, signal));
225
+ const seen = new Map();
226
+ const utxos = listed.filter((u) => {
227
+ const key = `${u.txid}:${u.vout}`;
228
+ const { confirmed, blockHeight, blockHash, blockTime } = u.status;
229
+ const facts = `${u.value}|${confirmed}|${blockHeight}|${blockHash}|${blockTime}`;
230
+ const known = seen.get(key);
231
+ if (known === undefined) {
232
+ seen.set(key, facts);
233
+ return true;
234
+ }
235
+ if (known !== facts)
236
+ throw (0, esplora_1.malformed)('an unspent output listed twice, differently');
237
+ return false;
238
+ });
239
+ // Each value is in range (the parser), but no address holds more than every bitcoin: under
240
+ // coinSelection `all`, such a listing would build change above MAX_MONEY.
241
+ if (utxos.reduce((sum, u) => sum + u.value, 0n) > esplora_1.MAX_MONEY) {
242
+ throw (0, esplora_1.malformed)('unspent outputs worth more than every bitcoin');
243
+ }
244
+ const height = (u) => u.status.confirmed
245
+ ? u.status.blockHeight
246
+ : BigInt(Number.MAX_SAFE_INTEGER);
247
+ return utxos
248
+ .map((u) => ({ u, key: `${u.txid}:${u.vout}` }))
249
+ .sort((a, b) => height(a.u) === height(b.u)
250
+ ? a.key < b.key
251
+ ? -1
252
+ : 1
253
+ : height(a.u) < height(b.u)
254
+ ? -1
255
+ : 1)
256
+ .map(({ u, key }) => ({
257
+ outpoint: key,
258
+ txid: u.txid,
259
+ vout: u.vout,
260
+ value: u.value,
261
+ confirmed: u.status.confirmed,
262
+ ...(u.status.confirmed ? { blockHeight: u.status.blockHeight } : {}),
263
+ }));
264
+ }
265
+ //# sourceMappingURL=reader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reader.js","sourceRoot":"","sources":["../../../src/adapters/utxo/reader.ts"],"names":[],"mappings":";;AA6CA,oCAwBC;AAoBD,8BAiBC;AAGD,8CAGC;AAED,kCA2FC;AASD,wCA+BC;AAQD,kCAgDC;AAjSD,mDAAyE;AAEzE,iDAA8C;AAC9C,uCAAyD;AACzD,uCASmB;AACnB,mCAA4C;AAC5C,qCAA4D;AAC5D,uCAAyD;AAGzD,yEAAyE;AACzE,MAAM,YAAY,GAAG,EAAE,CAAC;AACxB,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAEnD,oFAAoF;AACpF,MAAM,aAAa,GAAG,CAAC,MAAc,EAAiB,EAAE,CACtD,IAAI,qBAAa,CAAC,uBAAuB,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAE1E,MAAM,UAAU,GAAG,CAAC,SAAiB,EAAE,IAAoB,EAAqB,EAAE,CAAC,CAAC;IAClF,SAAS;IACT,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,EAAE,IAAI,EAAE;CAClB,CAAC,CAAC;AAEH,SAAgB,YAAY,CAAC,GAAgB;IAC3C,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM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AC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,WAAqB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC/E,CAAC,CAAC,CAAC;AACR,CAAC","sourcesContent":["/**\n * Bitcoin addresses, point reads, observation, address history and `ext.utxo.listUnspent`.\n * Every call carries the tags of the `ChainDriver` contract table: `read` for point\n * queries, `monitor` for heights and observations; address reads go to the indexer.\n */\nimport type {\n AddressCodec,\n AddressHistorySource,\n ChainReader,\n DriverBlock,\n DriverTransaction,\n} from '../../core/driver/types';\nimport { ProviderError, ValidationError } from '../../core/errors/error';\nimport type { NormalizedAddress } from '../../core/model/address';\nimport { toHex } from '../../core/util/bytes';\nimport { decodeAddress, walletAddress } from './address';\nimport {\n MONITOR,\n READ,\n assertNative,\n parseOutpoint,\n proofRead,\n parseWalletOptions,\n withSignal,\n type UtxoContext,\n} from './context';\nimport { canonicalTwinTxid } from './codec';\nimport { decodeTransaction, observationOf } from './decode';\nimport { MAX_MONEY, isHash, malformed } from './esplora';\nimport type { EsploraTx, UtxoCallTags, UtxoOutputType, UtxoUnspent } from './types';\n\n/** Esplora's page of address history (electrs' `CHAIN_TXS_PER_PAGE`). */\nconst HISTORY_PAGE = 25;\nconst MAX_HEIGHT = BigInt(Number.MAX_SAFE_INTEGER);\n\n/** Two reads of one index that contradict each other decide nothing (retryable). */\nconst contradiction = (reason: string): ProviderError =>\n new ProviderError('PROVIDER_INCONSISTENT', reason, { retryable: true });\n\nconst normalized = (canonical: string, type: UtxoOutputType): NormalizedAddress => ({\n canonical,\n display: canonical,\n variant: { type },\n});\n\nexport function addressCodec(ctx: UtxoContext): AddressCodec {\n const params = ctx.config.address;\n return {\n validate: (address) => {\n try {\n decodeAddress(address, params);\n return true;\n } catch {\n return false;\n }\n },\n normalize: (address) => {\n const decoded = decodeAddress(address, params);\n return normalized(decoded.canonical, decoded.type);\n },\n fromPublicKey: (publicKey, wallet) => {\n const { addressType } = parseWalletOptions(wallet, ctx.config);\n const derived = walletAddress(publicKey, addressType, params);\n return normalized(\n derived.address,\n derived.type === 'p2sh-p2wpkh' ? 'p2sh' : derived.type,\n );\n },\n };\n}\n\n/** The key hash of a p2pkh sending address, or `undefined` for every other type. */\nfunction p2pkhKeyHash(ctx: UtxoContext, from: string): Uint8Array | undefined {\n try {\n const decoded = decodeAddress(from, ctx.config.address);\n return decoded.type === 'p2pkh' ? decoded.script.slice(3, 23) : undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Whether `spender` is a miner-malleated copy of our p2pkh Attempt `refId`. Its raw\n * bytes are read under `tags` and authenticate themselves: under a quorum the client keys\n * the answers on the txid they hash to, and it refuses bytes that do not hash to `spender`\n * (a retryable `PROVIDER_INCONSISTENT`). They are then canonicalized: equality with `refId`\n * proves the same version, lock time, outpoints, sequences and outputs. Segwit and taproot\n * txids exclude the witness and cannot be malleated, so nothing is read for them.\n */\nexport async function isOwnCopy(\n ctx: UtxoContext,\n refId: string,\n from: string,\n spender: string,\n tags: UtxoCallTags,\n): Promise<boolean> {\n const keyHash = p2pkhKeyHash(ctx, from);\n if (!keyHash) return false;\n const hex = await ctx.esplora.txHex(spender, tags);\n if (hex === null) {\n throw new ProviderError(\n 'PROVIDER_UNAVAILABLE',\n 'the spending transaction is not available',\n );\n }\n return canonicalTwinTxid(hex, keyHash) === refId;\n}\n\n/** The highest block with the network's confirmations, from one `monitor` read. */\nexport function finalizedFromHead(ctx: UtxoContext, head: bigint): bigint {\n const height = head - BigInt(ctx.config.confirmations) + 1n;\n return height < 0n ? 0n : height;\n}\n\nexport function chainReader(ctx: UtxoContext): ChainReader {\n const { esplora, config } = ctx;\n const block = async (hash: string, height?: bigint): Promise<DriverBlock | null> => {\n const found = await esplora.block(hash, READ);\n if (!found) return null;\n // The block at a height must say it is at that height. A block's height never\n // changes, so only a lie or a server bug trips this; it decides nothing (retryable).\n if (height !== undefined && found.height !== height) {\n throw contradiction('the block at the height asked for is at another height');\n }\n const transactionIds = await esplora.blockTxids(found.hash, READ);\n if (transactionIds.length !== found.txCount) throw malformed('block txids');\n return {\n height: found.height,\n hash: found.hash,\n parentHash: found.parentHash,\n timestamp: found.timestamp,\n transactionIds,\n };\n };\n return {\n getBalance: async (address, asset) => {\n assertNative(asset);\n const stats = await esplora.addressStats(\n decodeAddress(address, config.address).canonical,\n READ,\n );\n return stats.funded - stats.spent;\n },\n getBlockHeight: () => esplora.tipHeight(MONITOR),\n getFinalizedHeight: async () =>\n finalizedFromHead(ctx, await esplora.tipHeight(MONITOR)),\n getBlock: async (ref) => {\n if (typeof ref === 'string') {\n const id = ref.toLowerCase();\n return isHash(id) ? block(id) : null; // a malformed id never reaches a path\n }\n // No block is below 0 or beyond what a server can parse: never sent.\n if (ref < 0n || ref > MAX_HEIGHT) return null;\n const hash = await esplora.blockHashAt(ref, READ);\n return hash ? block(hash, ref) : null;\n },\n getTransaction: async (raw) => {\n const id = raw.toLowerCase();\n if (!isHash(id)) return null; // a malformed id never reaches a path\n const tx = await esplora.tx(id, READ);\n return tx ? decodeTransaction(tx, config.address) : null;\n },\n observe: async (ref, ordering, from) => {\n const id = ref.id.toLowerCase();\n if (!isHash(id)) return { seen: 'none' }; // a malformed id never reaches a path\n // A refusal on any of these reads decides nothing (retryable).\n return proofRead(async () => {\n // `/tx/:txid/status` answers `confirmed: false` for a transaction it does not know,\n // so visibility is read from `/tx/:txid`, which is a 404 then.\n const tx = await esplora.tx(id, MONITOR);\n if (tx?.status.confirmed) return observationOf(tx.txid, tx.status);\n const first = ordering?.kind === 'inputs' ? ordering.inputs[0] : undefined;\n // A status lookup by id (no ordering) reports the index as it is.\n if (first === undefined)\n return tx ? observationOf(tx.txid, tx.status) : { seen: 'none' };\n const legacy = from !== undefined && p2pkhKeyHash(ctx, from) ? from : undefined;\n // Unknown, and a segwit or taproot txid cannot be malleated: nothing more to learn.\n if (!tx && legacy === undefined) return { seen: 'none' };\n const input = parseOutpoint(first);\n // Full-mode electrs keeps serving a reorg-dropped transaction as unconfirmed,\n // and `/status` cannot tell a mempool transaction from one only in its txstore. The\n // first input's spender can: chain spends of a disconnected block are gone, then the\n // mempool's are read. Ours: in a mempool. None: in no mempool of this index (the core\n // rebroadcasts a dropped Attempt). Another: conflicted, or our malleated copy.\n // Observed evidence only: an index still syncing can briefly say otherwise.\n const spend = await esplora.outspend(input.txid, input.vout, MONITOR);\n if (!spend.spent || spend.txid === undefined) return { seen: 'none' };\n if (spend.txid === id) {\n if (tx) return observationOf(tx.txid, tx.status);\n throw contradiction('the index spends with a transaction it does not know');\n }\n // Our own p2pkh Attempt, mined as a malleated copy (observed evidence only; only\n // `includedFinal`'s quorum path can make it terminal).\n if (\n legacy === undefined ||\n !(await isOwnCopy(ctx, id, legacy, spend.txid, MONITOR))\n )\n return { seen: 'none' };\n const copy = await esplora.tx(spend.txid, MONITOR);\n if (!copy)\n throw contradiction('the index spends with a transaction it does not know');\n return observationOf(copy.txid, copy.status);\n });\n },\n };\n}\n\n/**\n * Confirmed history, newest first (Esplora pages of 25; the cursor is the last txid). A full\n * page, of any size a server chooses, may have a next one. The answer is filtered to the\n * address asked for: a server that dropped its filter never lists another\n * address's transaction, and every transaction served counts toward `limit`, so paging stays\n * bounded.\n */\nexport function addressHistory(ctx: UtxoContext): AddressHistorySource {\n return {\n async list(address, { cursor, limit }) {\n if (!Number.isSafeInteger(limit) || limit < 1) {\n throw new ValidationError('INVALID_INTENT', 'limit must be a positive integer');\n }\n if (cursor !== undefined && !/^[0-9a-f]{64}$/.test(cursor)) {\n throw new ValidationError('INVALID_INTENT', 'malformed history cursor');\n }\n const decoded = decodeAddress(address, ctx.config.address);\n const script = toHex(decoded.script);\n const touches = (tx: EsploraTx) =>\n tx.vout.some((output) => output.script === script) ||\n tx.vin.some((input) => input.prevout?.script === script);\n const items: DriverTransaction[] = [];\n let served = 0;\n let last = cursor;\n let more = true;\n while (served < limit && more) {\n const page = await ctx.esplora.addressTxs(decoded.canonical, last, READ);\n const taken = page.slice(0, limit - served);\n for (const tx of taken) {\n if (touches(tx)) items.push(decodeTransaction(tx, ctx.config.address));\n last = tx.txid;\n served++;\n }\n more = taken.length < page.length || page.length >= HISTORY_PAGE;\n }\n return { items, ...(more && last !== undefined ? { next: last } : {}) };\n },\n };\n}\n\n/**\n * `ext.utxo.listUnspent`: confirmed first (oldest first), then unconfirmed. An output the\n * indexer names twice alike is listed once; named twice differently (another value or\n * status), the answer is malformed, and so is a list worth more than every bitcoin. Coin\n * selection reads the wallet's outputs through it (`spendable`, with the build's signal).\n */\nexport async function listUnspent(\n ctx: UtxoContext,\n address: string,\n signal?: AbortSignal,\n): Promise<UtxoUnspent[]> {\n const canonical = decodeAddress(address, ctx.config.address).canonical;\n const listed = await ctx.esplora.addressUtxos(canonical, withSignal(READ, signal));\n const seen = new Map<string, string>();\n const utxos = listed.filter((u) => {\n const key = `${u.txid}:${u.vout}`;\n const { confirmed, blockHeight, blockHash, blockTime } = u.status;\n const facts = `${u.value}|${confirmed}|${blockHeight}|${blockHash}|${blockTime}`;\n const known = seen.get(key);\n if (known === undefined) {\n seen.set(key, facts);\n return true;\n }\n if (known !== facts) throw malformed('an unspent output listed twice, differently');\n return false;\n });\n // Each value is in range (the parser), but no address holds more than every bitcoin: under\n // coinSelection `all`, such a listing would build change above MAX_MONEY.\n if (utxos.reduce((sum, u) => sum + u.value, 0n) > MAX_MONEY) {\n throw malformed('unspent outputs worth more than every bitcoin');\n }\n const height = (u: (typeof utxos)[number]) =>\n u.status.confirmed\n ? (u.status.blockHeight as bigint)\n : BigInt(Number.MAX_SAFE_INTEGER);\n return utxos\n .map((u) => ({ u, key: `${u.txid}:${u.vout}` }))\n .sort((a, b) =>\n height(a.u) === height(b.u)\n ? a.key < b.key\n ? -1\n : 1\n : height(a.u) < height(b.u)\n ? -1\n : 1,\n )\n .map(({ u, key }) => ({\n outpoint: key,\n txid: u.txid,\n vout: u.vout,\n value: u.value,\n confirmed: u.status.confirmed,\n ...(u.status.confirmed ? { blockHeight: u.status.blockHeight as bigint } : {}),\n }));\n}\n"]}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The one place that loads bitcoinjs-lib. Its 7.x package is an ES module with a CommonJS
3
+ * build (`require` condition), so this CommonJS library `require()`s it at run time and
4
+ * takes its types with `resolution-mode: 'import'` (TypeScript refuses a plain CommonJS
5
+ * import of an ES module's types, TS1479). Loaded only through the manifest's `load()`.
6
+ */
7
+ import type * as Bitcoin from 'bitcoinjs-lib' with { 'resolution-mode': 'import' };
8
+ export declare const bitcoin: typeof Bitcoin;
9
+ export type Network = Bitcoin.Network;
10
+ export type Psbt = Bitcoin.Psbt;
11
+ export type Transaction = Bitcoin.Transaction;
12
+ /**
13
+ * Installs the `@noble/curves` backend (no WASM, no tiny-secp256k1). bitcoinjs
14
+ * verifies it against its own test vectors the first time, and skips a repeat install of
15
+ * the same object, so calling this before every taproot use is cheap and undoes a
16
+ * `native()` caller who swapped the library-global backend.
17
+ */
18
+ export declare function useNobleEcc(): void;