@btc-vision/bitcoin 6.5.6 → 7.0.0-alpha.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 (455) hide show
  1. package/HOW_TO_WRITE_GOOD_CODE.md +2436 -0
  2. package/benchmark/psbt-2000-inputs.bench.ts +178 -0
  3. package/benchmark/signing.bench.ts +147 -0
  4. package/browser/address.d.ts +56 -9
  5. package/browser/address.d.ts.map +1 -0
  6. package/browser/bech32utils.d.ts +9 -1
  7. package/browser/bech32utils.d.ts.map +1 -0
  8. package/browser/bip66.d.ts +11 -6
  9. package/browser/bip66.d.ts.map +1 -0
  10. package/browser/block.d.ts +117 -11
  11. package/browser/block.d.ts.map +1 -0
  12. package/browser/branded.d.ts +20 -0
  13. package/browser/branded.d.ts.map +1 -0
  14. package/browser/crypto/crypto.d.ts +1 -0
  15. package/browser/crypto/crypto.d.ts.map +1 -0
  16. package/browser/crypto.d.ts +46 -7
  17. package/browser/crypto.d.ts.map +1 -0
  18. package/browser/ecc/context.d.ts +129 -0
  19. package/browser/ecc/context.d.ts.map +1 -0
  20. package/browser/ecc/index.d.ts +11 -0
  21. package/browser/ecc/index.d.ts.map +1 -0
  22. package/browser/ecc/types.d.ts +128 -0
  23. package/browser/ecc/types.d.ts.map +1 -0
  24. package/browser/ecpair.d.ts +99 -0
  25. package/browser/errors.d.ts +124 -0
  26. package/browser/errors.d.ts.map +1 -0
  27. package/browser/index.d.ts +32 -5
  28. package/browser/index.d.ts.map +1 -0
  29. package/browser/index.js +12482 -101
  30. package/browser/io/BinaryReader.d.ts +276 -0
  31. package/browser/io/BinaryReader.d.ts.map +1 -0
  32. package/browser/io/BinaryWriter.d.ts +391 -0
  33. package/browser/io/BinaryWriter.d.ts.map +1 -0
  34. package/browser/io/MemoryPool.d.ts +220 -0
  35. package/browser/io/MemoryPool.d.ts.map +1 -0
  36. package/browser/io/base64.d.ts +13 -0
  37. package/browser/io/base64.d.ts.map +1 -0
  38. package/browser/io/hex.d.ts +67 -0
  39. package/browser/io/hex.d.ts.map +1 -0
  40. package/browser/io/index.d.ts +17 -0
  41. package/browser/io/index.d.ts.map +1 -0
  42. package/browser/io/utils.d.ts +199 -0
  43. package/browser/io/utils.d.ts.map +1 -0
  44. package/browser/merkle.d.ts +10 -1
  45. package/browser/merkle.d.ts.map +1 -0
  46. package/browser/networks.d.ts +70 -9
  47. package/browser/networks.d.ts.map +1 -0
  48. package/browser/opcodes.d.ts +1 -0
  49. package/browser/opcodes.d.ts.map +1 -0
  50. package/browser/payments/bip341.d.ts +35 -9
  51. package/browser/payments/bip341.d.ts.map +1 -0
  52. package/browser/payments/embed.d.ts +112 -1
  53. package/browser/payments/embed.d.ts.map +1 -0
  54. package/browser/payments/index.d.ts +17 -10
  55. package/browser/payments/index.d.ts.map +1 -0
  56. package/browser/payments/p2ms.d.ts +150 -0
  57. package/browser/payments/p2ms.d.ts.map +1 -0
  58. package/browser/payments/p2op.d.ts +150 -24
  59. package/browser/payments/p2op.d.ts.map +1 -0
  60. package/browser/payments/p2pk.d.ts +154 -1
  61. package/browser/payments/p2pk.d.ts.map +1 -0
  62. package/browser/payments/p2pkh.d.ts +176 -1
  63. package/browser/payments/p2pkh.d.ts.map +1 -0
  64. package/browser/payments/p2sh.d.ts +150 -1
  65. package/browser/payments/p2sh.d.ts.map +1 -0
  66. package/browser/payments/p2tr.d.ts +185 -1
  67. package/browser/payments/p2tr.d.ts.map +1 -0
  68. package/browser/payments/p2wpkh.d.ts +161 -1
  69. package/browser/payments/p2wpkh.d.ts.map +1 -0
  70. package/browser/payments/p2wsh.d.ts +146 -1
  71. package/browser/payments/p2wsh.d.ts.map +1 -0
  72. package/browser/payments/types.d.ts +94 -64
  73. package/browser/payments/types.d.ts.map +1 -0
  74. package/browser/psbt/bip371.d.ts +34 -8
  75. package/browser/psbt/bip371.d.ts.map +1 -0
  76. package/browser/psbt/psbtutils.d.ts +56 -16
  77. package/browser/psbt/psbtutils.d.ts.map +1 -0
  78. package/browser/psbt/types.d.ts +245 -0
  79. package/browser/psbt/types.d.ts.map +1 -0
  80. package/browser/psbt/utils.d.ts +64 -0
  81. package/browser/psbt/utils.d.ts.map +1 -0
  82. package/browser/psbt/validation.d.ts +84 -0
  83. package/browser/psbt/validation.d.ts.map +1 -0
  84. package/browser/psbt.d.ts +82 -118
  85. package/browser/psbt.d.ts.map +1 -0
  86. package/browser/pubkey.d.ts +27 -6
  87. package/browser/pubkey.d.ts.map +1 -0
  88. package/browser/push_data.d.ts +24 -2
  89. package/browser/push_data.d.ts.map +1 -0
  90. package/browser/script.d.ts +33 -8
  91. package/browser/script.d.ts.map +1 -0
  92. package/browser/script_number.d.ts +17 -0
  93. package/browser/script_number.d.ts.map +1 -0
  94. package/browser/script_signature.d.ts +23 -5
  95. package/browser/script_signature.d.ts.map +1 -0
  96. package/browser/transaction.d.ts +160 -18
  97. package/browser/transaction.d.ts.map +1 -0
  98. package/browser/types.d.ts +36 -38
  99. package/browser/types.d.ts.map +1 -0
  100. package/browser/workers/WorkerSigningPool.d.ts +143 -0
  101. package/browser/workers/WorkerSigningPool.d.ts.map +1 -0
  102. package/browser/workers/WorkerSigningPool.node.d.ts +116 -0
  103. package/browser/workers/WorkerSigningPool.node.d.ts.map +1 -0
  104. package/browser/workers/ecc-bundle.d.ts +25 -0
  105. package/browser/workers/ecc-bundle.d.ts.map +1 -0
  106. package/browser/workers/index.d.ts +91 -0
  107. package/browser/workers/index.d.ts.map +1 -0
  108. package/browser/workers/psbt-parallel.d.ts +88 -0
  109. package/browser/workers/psbt-parallel.d.ts.map +1 -0
  110. package/browser/workers/signing-worker.d.ts +37 -0
  111. package/browser/workers/signing-worker.d.ts.map +1 -0
  112. package/browser/workers/types.d.ts +365 -0
  113. package/browser/workers/types.d.ts.map +1 -0
  114. package/build/address.d.ts +57 -10
  115. package/build/address.d.ts.map +1 -0
  116. package/build/address.js +80 -24
  117. package/build/address.js.map +1 -0
  118. package/build/bech32utils.d.ts +9 -1
  119. package/build/bech32utils.d.ts.map +1 -0
  120. package/build/bech32utils.js +10 -2
  121. package/build/bech32utils.js.map +1 -0
  122. package/build/bip66.d.ts +11 -6
  123. package/build/bip66.d.ts.map +1 -0
  124. package/build/bip66.js +32 -3
  125. package/build/bip66.js.map +1 -0
  126. package/build/block.d.ts +117 -11
  127. package/build/block.d.ts.map +1 -0
  128. package/build/block.js +204 -72
  129. package/build/block.js.map +1 -0
  130. package/build/branded.d.ts +20 -0
  131. package/build/branded.d.ts.map +1 -0
  132. package/build/branded.js +7 -0
  133. package/build/branded.js.map +1 -0
  134. package/build/crypto/crypto.d.ts +1 -0
  135. package/build/crypto/crypto.d.ts.map +1 -0
  136. package/build/crypto/crypto.js +1 -0
  137. package/build/crypto/crypto.js.map +1 -0
  138. package/build/crypto.d.ts +46 -7
  139. package/build/crypto.d.ts.map +1 -0
  140. package/build/crypto.js +65 -20
  141. package/build/crypto.js.map +1 -0
  142. package/build/ecc/context.d.ts +135 -0
  143. package/build/ecc/context.d.ts.map +1 -0
  144. package/build/ecc/context.js +232 -0
  145. package/build/ecc/context.js.map +1 -0
  146. package/build/ecc/index.d.ts +11 -0
  147. package/build/ecc/index.d.ts.map +1 -0
  148. package/build/ecc/index.js +11 -0
  149. package/build/ecc/index.js.map +1 -0
  150. package/build/ecc/types.d.ts +134 -0
  151. package/build/ecc/types.d.ts.map +1 -0
  152. package/build/ecc/types.js +8 -0
  153. package/build/ecc/types.js.map +1 -0
  154. package/build/errors.d.ts +124 -0
  155. package/build/errors.d.ts.map +1 -0
  156. package/build/errors.js +155 -0
  157. package/build/errors.js.map +1 -0
  158. package/build/index.d.ts +32 -5
  159. package/build/index.d.ts.map +1 -0
  160. package/build/index.js +26 -3
  161. package/build/index.js.map +1 -0
  162. package/build/io/BinaryReader.d.ts +276 -0
  163. package/build/io/BinaryReader.d.ts.map +1 -0
  164. package/build/io/BinaryReader.js +425 -0
  165. package/build/io/BinaryReader.js.map +1 -0
  166. package/build/io/BinaryWriter.d.ts +391 -0
  167. package/build/io/BinaryWriter.d.ts.map +1 -0
  168. package/build/io/BinaryWriter.js +611 -0
  169. package/build/io/BinaryWriter.js.map +1 -0
  170. package/build/io/MemoryPool.d.ts +220 -0
  171. package/build/io/MemoryPool.d.ts.map +1 -0
  172. package/build/io/MemoryPool.js +309 -0
  173. package/build/io/MemoryPool.js.map +1 -0
  174. package/build/io/base64.d.ts +13 -0
  175. package/build/io/base64.d.ts.map +1 -0
  176. package/build/io/base64.js +20 -0
  177. package/build/io/base64.js.map +1 -0
  178. package/build/io/hex.d.ts +67 -0
  179. package/build/io/hex.d.ts.map +1 -0
  180. package/build/io/hex.js +138 -0
  181. package/build/io/hex.js.map +1 -0
  182. package/build/io/index.d.ts +17 -0
  183. package/build/io/index.d.ts.map +1 -0
  184. package/build/io/index.js +23 -0
  185. package/build/io/index.js.map +1 -0
  186. package/build/io/utils.d.ts +199 -0
  187. package/build/io/utils.d.ts.map +1 -0
  188. package/build/io/utils.js +271 -0
  189. package/build/io/utils.js.map +1 -0
  190. package/build/merkle.d.ts +10 -1
  191. package/build/merkle.d.ts.map +1 -0
  192. package/build/merkle.js +12 -1
  193. package/build/merkle.js.map +1 -0
  194. package/build/networks.d.ts +70 -9
  195. package/build/networks.d.ts.map +1 -0
  196. package/build/networks.js +90 -4
  197. package/build/networks.js.map +1 -0
  198. package/build/opcodes.d.ts +1 -0
  199. package/build/opcodes.d.ts.map +1 -0
  200. package/build/opcodes.js +1 -0
  201. package/build/opcodes.js.map +1 -0
  202. package/build/payments/bip341.d.ts +36 -9
  203. package/build/payments/bip341.d.ts.map +1 -0
  204. package/build/payments/bip341.js +35 -15
  205. package/build/payments/bip341.js.map +1 -0
  206. package/build/payments/embed.d.ts +120 -1
  207. package/build/payments/embed.d.ts.map +1 -0
  208. package/build/payments/embed.js +215 -34
  209. package/build/payments/embed.js.map +1 -0
  210. package/build/payments/index.d.ts +17 -10
  211. package/build/payments/index.d.ts.map +1 -0
  212. package/build/payments/index.js +20 -10
  213. package/build/payments/index.js.map +1 -0
  214. package/build/payments/p2ms.d.ts +159 -1
  215. package/build/payments/p2ms.d.ts.map +1 -0
  216. package/build/payments/p2ms.js +427 -108
  217. package/build/payments/p2ms.js.map +1 -0
  218. package/build/payments/p2op.d.ts +158 -24
  219. package/build/payments/p2op.d.ts.map +1 -0
  220. package/build/payments/p2op.js +379 -93
  221. package/build/payments/p2op.js.map +1 -0
  222. package/build/payments/p2pk.d.ts +162 -1
  223. package/build/payments/p2pk.d.ts.map +1 -0
  224. package/build/payments/p2pk.js +327 -58
  225. package/build/payments/p2pk.js.map +1 -0
  226. package/build/payments/p2pkh.d.ts +185 -1
  227. package/build/payments/p2pkh.d.ts.map +1 -0
  228. package/build/payments/p2pkh.js +467 -114
  229. package/build/payments/p2pkh.js.map +1 -0
  230. package/build/payments/p2sh.d.ts +159 -1
  231. package/build/payments/p2sh.d.ts.map +1 -0
  232. package/build/payments/p2sh.js +500 -152
  233. package/build/payments/p2sh.js.map +1 -0
  234. package/build/payments/p2tr.d.ts +193 -1
  235. package/build/payments/p2tr.d.ts.map +1 -0
  236. package/build/payments/p2tr.js +592 -174
  237. package/build/payments/p2tr.js.map +1 -0
  238. package/build/payments/p2wpkh.d.ts +170 -1
  239. package/build/payments/p2wpkh.d.ts.map +1 -0
  240. package/build/payments/p2wpkh.js +429 -104
  241. package/build/payments/p2wpkh.js.map +1 -0
  242. package/build/payments/p2wsh.d.ts +155 -1
  243. package/build/payments/p2wsh.d.ts.map +1 -0
  244. package/build/payments/p2wsh.js +466 -144
  245. package/build/payments/p2wsh.js.map +1 -0
  246. package/build/payments/types.d.ts +98 -64
  247. package/build/payments/types.d.ts.map +1 -0
  248. package/build/payments/types.js +17 -13
  249. package/build/payments/types.js.map +1 -0
  250. package/build/psbt/bip371.d.ts +35 -9
  251. package/build/psbt/bip371.d.ts.map +1 -0
  252. package/build/psbt/bip371.js +113 -28
  253. package/build/psbt/bip371.js.map +1 -0
  254. package/build/psbt/psbtutils.d.ts +56 -16
  255. package/build/psbt/psbtutils.d.ts.map +1 -0
  256. package/build/psbt/psbtutils.js +71 -16
  257. package/build/psbt/psbtutils.js.map +1 -0
  258. package/build/psbt/types.d.ts +249 -0
  259. package/build/psbt/types.d.ts.map +1 -0
  260. package/build/psbt/types.js +6 -0
  261. package/build/psbt/types.js.map +1 -0
  262. package/build/psbt/utils.d.ts +68 -0
  263. package/build/psbt/utils.d.ts.map +1 -0
  264. package/build/psbt/utils.js +171 -0
  265. package/build/psbt/utils.js.map +1 -0
  266. package/build/psbt/validation.d.ts +88 -0
  267. package/build/psbt/validation.d.ts.map +1 -0
  268. package/build/psbt/validation.js +149 -0
  269. package/build/psbt/validation.js.map +1 -0
  270. package/build/psbt.d.ts +84 -120
  271. package/build/psbt.d.ts.map +1 -0
  272. package/build/psbt.js +411 -412
  273. package/build/psbt.js.map +1 -0
  274. package/build/pubkey.d.ts +27 -6
  275. package/build/pubkey.d.ts.map +1 -0
  276. package/build/pubkey.js +36 -12
  277. package/build/pubkey.js.map +1 -0
  278. package/build/push_data.d.ts +24 -2
  279. package/build/push_data.d.ts.map +1 -0
  280. package/build/push_data.js +44 -12
  281. package/build/push_data.js.map +1 -0
  282. package/build/script.d.ts +33 -8
  283. package/build/script.d.ts.map +1 -0
  284. package/build/script.js +100 -36
  285. package/build/script.js.map +1 -0
  286. package/build/script_number.d.ts +17 -0
  287. package/build/script_number.d.ts.map +1 -0
  288. package/build/script_number.js +19 -0
  289. package/build/script_number.js.map +1 -0
  290. package/build/script_signature.d.ts +23 -5
  291. package/build/script_signature.d.ts.map +1 -0
  292. package/build/script_signature.js +48 -15
  293. package/build/script_signature.js.map +1 -0
  294. package/build/transaction.d.ts +160 -18
  295. package/build/transaction.d.ts.map +1 -0
  296. package/build/transaction.js +443 -176
  297. package/build/transaction.js.map +1 -0
  298. package/build/tsconfig.build.tsbuildinfo +1 -0
  299. package/build/types.d.ts +36 -38
  300. package/build/types.d.ts.map +1 -0
  301. package/build/types.js +175 -57
  302. package/build/types.js.map +1 -0
  303. package/build/workers/WorkerSigningPool.d.ts +174 -0
  304. package/build/workers/WorkerSigningPool.d.ts.map +1 -0
  305. package/build/workers/WorkerSigningPool.js +553 -0
  306. package/build/workers/WorkerSigningPool.js.map +1 -0
  307. package/build/workers/WorkerSigningPool.node.d.ts +124 -0
  308. package/build/workers/WorkerSigningPool.node.d.ts.map +1 -0
  309. package/build/workers/WorkerSigningPool.node.js +753 -0
  310. package/build/workers/WorkerSigningPool.node.js.map +1 -0
  311. package/build/workers/ecc-bundle.d.ts +25 -0
  312. package/build/workers/ecc-bundle.d.ts.map +1 -0
  313. package/build/workers/ecc-bundle.js +25 -0
  314. package/build/workers/ecc-bundle.js.map +1 -0
  315. package/build/workers/index.d.ts +91 -0
  316. package/build/workers/index.d.ts.map +1 -0
  317. package/build/workers/index.js +114 -0
  318. package/build/workers/index.js.map +1 -0
  319. package/build/workers/psbt-parallel.d.ts +117 -0
  320. package/build/workers/psbt-parallel.d.ts.map +1 -0
  321. package/build/workers/psbt-parallel.js +233 -0
  322. package/build/workers/psbt-parallel.js.map +1 -0
  323. package/build/workers/signing-worker.d.ts +37 -0
  324. package/build/workers/signing-worker.d.ts.map +1 -0
  325. package/build/workers/signing-worker.js +350 -0
  326. package/build/workers/signing-worker.js.map +1 -0
  327. package/build/workers/types.d.ts +365 -0
  328. package/build/workers/types.d.ts.map +1 -0
  329. package/build/workers/types.js +60 -0
  330. package/build/workers/types.js.map +1 -0
  331. package/package.json +66 -8
  332. package/scripts/bundle-ecc.ts +111 -0
  333. package/src/address.ts +81 -44
  334. package/src/bech32utils.ts +3 -3
  335. package/src/bip66.ts +34 -24
  336. package/src/block.ts +196 -84
  337. package/src/branded.ts +18 -0
  338. package/src/crypto.ts +64 -26
  339. package/src/ecc/context.ts +277 -0
  340. package/src/ecc/index.ts +14 -0
  341. package/src/ecc/types.ts +154 -0
  342. package/src/ecpair.d.ts +99 -0
  343. package/src/errors.ts +163 -0
  344. package/src/index.ts +113 -9
  345. package/src/io/BinaryReader.ts +461 -0
  346. package/src/io/BinaryWriter.ts +696 -0
  347. package/src/io/MemoryPool.ts +343 -0
  348. package/src/io/base64.ts +20 -0
  349. package/src/io/hex.ts +155 -0
  350. package/src/io/index.ts +41 -0
  351. package/src/io/utils.ts +283 -0
  352. package/src/merkle.ts +14 -9
  353. package/src/networks.ts +9 -9
  354. package/src/payments/bip341.ts +34 -33
  355. package/src/payments/embed.ts +244 -41
  356. package/src/payments/index.ts +12 -10
  357. package/src/payments/p2ms.ts +490 -118
  358. package/src/payments/p2op.ts +431 -133
  359. package/src/payments/p2pk.ts +370 -72
  360. package/src/payments/p2pkh.ts +524 -130
  361. package/src/payments/p2sh.ts +572 -172
  362. package/src/payments/p2tr.ts +686 -194
  363. package/src/payments/p2wpkh.ts +484 -107
  364. package/src/payments/p2wsh.ts +526 -164
  365. package/src/payments/types.ts +80 -66
  366. package/src/psbt/bip371.ts +68 -51
  367. package/src/psbt/psbtutils.ts +39 -40
  368. package/src/psbt/types.ts +331 -0
  369. package/src/psbt/utils.ts +188 -0
  370. package/src/psbt/validation.ts +192 -0
  371. package/src/psbt.ts +566 -809
  372. package/src/pubkey.ts +22 -23
  373. package/src/push_data.ts +18 -16
  374. package/src/script.ts +82 -64
  375. package/src/script_number.ts +6 -6
  376. package/src/script_signature.ts +33 -36
  377. package/src/transaction.ts +458 -238
  378. package/src/types.ts +231 -100
  379. package/src/workers/WorkerSigningPool.node.ts +887 -0
  380. package/src/workers/WorkerSigningPool.ts +670 -0
  381. package/src/workers/ecc-bundle.ts +26 -0
  382. package/src/workers/index.ts +165 -0
  383. package/src/workers/psbt-parallel.ts +332 -0
  384. package/src/workers/signing-worker.ts +353 -0
  385. package/src/workers/types.ts +413 -0
  386. package/test/address.spec.ts +9 -6
  387. package/test/bitcoin.core.spec.ts +16 -17
  388. package/test/block.spec.ts +8 -7
  389. package/test/bufferutils.spec.ts +228 -214
  390. package/test/crypto.spec.ts +19 -11
  391. package/test/fixtures/p2pk.json +0 -8
  392. package/test/fixtures/p2pkh.json +1 -1
  393. package/test/fixtures/p2sh.json +1 -1
  394. package/test/fixtures/script.json +1 -1
  395. package/test/fixtures/transaction.json +2 -2
  396. package/test/integration/_regtest.ts +25 -0
  397. package/test/integration/addresses.spec.ts +4 -3
  398. package/test/integration/bip32.spec.ts +2 -1
  399. package/test/integration/blocks.spec.ts +1 -1
  400. package/test/integration/cltv.spec.ts +18 -16
  401. package/test/integration/csv.spec.ts +37 -64
  402. package/test/integration/payments.spec.ts +5 -3
  403. package/test/integration/taproot.spec.ts +76 -83
  404. package/test/integration/transactions.spec.ts +38 -35
  405. package/test/payments.spec.ts +35 -13
  406. package/test/payments.utils.ts +17 -16
  407. package/test/psbt.spec.ts +111 -100
  408. package/test/script.spec.ts +11 -10
  409. package/test/script_signature.spec.ts +9 -11
  410. package/test/taproot-cache.spec.ts +694 -0
  411. package/test/transaction.spec.ts +32 -40
  412. package/test/types.spec.ts +74 -29
  413. package/test/workers-pool.spec.ts +963 -0
  414. package/test/workers-signing.spec.ts +635 -0
  415. package/test/workers.spec.ts +1390 -0
  416. package/tsconfig.base.json +34 -18
  417. package/tsconfig.browser.json +15 -0
  418. package/tsconfig.build.json +5 -0
  419. package/tsconfig.json +5 -14
  420. package/vite.config.browser.ts +3 -42
  421. package/vitest.config.integration.ts +2 -0
  422. package/browser/bufferutils.d.ts +0 -34
  423. package/browser/chunks/crypto-BhCpKpek.js +0 -2033
  424. package/browser/chunks/payments-B1wlSccx.js +0 -1089
  425. package/browser/chunks/psbt-BCNk7JUx.js +0 -4055
  426. package/browser/chunks/script-DyPItFEl.js +0 -318
  427. package/browser/chunks/transaction-C_UbhMGn.js +0 -432
  428. package/browser/chunks/utils-DNZi-T5W.js +0 -761
  429. package/browser/ecc_lib.d.ts +0 -3
  430. package/browser/hooks/AdvancedSignatureManager.d.ts +0 -16
  431. package/browser/hooks/HookedSigner.d.ts +0 -4
  432. package/browser/hooks/SignatureManager.d.ts +0 -13
  433. package/browser/payments/lazy.d.ts +0 -2
  434. package/browser/typeforce.d.ts +0 -38
  435. package/build/bufferutils.d.ts +0 -34
  436. package/build/bufferutils.js +0 -141
  437. package/build/ecc_lib.d.ts +0 -3
  438. package/build/ecc_lib.js +0 -61
  439. package/build/hooks/AdvancedSignatureManager.d.ts +0 -16
  440. package/build/hooks/AdvancedSignatureManager.js +0 -52
  441. package/build/hooks/HookedSigner.d.ts +0 -4
  442. package/build/hooks/HookedSigner.js +0 -64
  443. package/build/hooks/SignatureManager.d.ts +0 -13
  444. package/build/hooks/SignatureManager.js +0 -45
  445. package/build/payments/lazy.d.ts +0 -2
  446. package/build/payments/lazy.js +0 -28
  447. package/build/tsconfig.tsbuildinfo +0 -1
  448. package/src/bufferutils.ts +0 -188
  449. package/src/ecc_lib.ts +0 -94
  450. package/src/hooks/AdvancedSignatureManager.ts +0 -104
  451. package/src/hooks/HookedSigner.ts +0 -108
  452. package/src/hooks/SignatureManager.ts +0 -84
  453. package/src/payments/lazy.ts +0 -28
  454. package/src/typeforce.d.ts +0 -38
  455. package/tsconfig.webpack.json +0 -18
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Hex encoding and decoding utilities.
3
+ *
4
+ * Direct implementations with zero dependencies and no wrappers.
5
+ * Optimized for performance with lookup tables.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ /**
10
+ * Lookup table for byte to hex conversion.
11
+ * Pre-computed for O(1) lookup per byte.
12
+ */
13
+ const BYTE_TO_HEX = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));
14
+ /**
15
+ * Lookup table for hex character to nibble conversion.
16
+ * Returns -1 for invalid characters.
17
+ */
18
+ const HEX_TO_NIBBLE = (() => {
19
+ const table = new Array(128).fill(-1);
20
+ for (let i = 0; i < 10; i++) {
21
+ table[0x30 + i] = i; // '0'-'9'
22
+ }
23
+ for (let i = 0; i < 6; i++) {
24
+ table[0x41 + i] = 10 + i; // 'A'-'F'
25
+ table[0x61 + i] = 10 + i; // 'a'-'f'
26
+ }
27
+ return table;
28
+ })();
29
+ /**
30
+ * Converts a Uint8Array to a lowercase hex string.
31
+ *
32
+ * @param bytes - The byte array to convert
33
+ * @returns Lowercase hex string representation
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * import { toHex } from '@btc-vision/bitcoin';
38
+ *
39
+ * const bytes = new Uint8Array([0xde, 0xad, 0xbe, 0xef]);
40
+ * const hex = toHex(bytes);
41
+ * console.log(hex); // 'deadbeef'
42
+ * ```
43
+ */
44
+ export function toHex(bytes) {
45
+ let result = '';
46
+ for (let i = 0; i < bytes.length; i++) {
47
+ result += BYTE_TO_HEX[bytes[i]];
48
+ }
49
+ return result;
50
+ }
51
+ /**
52
+ * Converts a hex string to a Uint8Array.
53
+ *
54
+ * Accepts hex strings with or without '0x' prefix.
55
+ * Case-insensitive (accepts both 'DEADBEEF' and 'deadbeef').
56
+ *
57
+ * @param hex - The hex string to convert
58
+ * @returns Uint8Array containing the decoded bytes
59
+ * @throws TypeError if hex string has odd length
60
+ * @throws TypeError if hex string contains invalid characters
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * import { fromHex, toHex } from '@btc-vision/bitcoin';
65
+ *
66
+ * const bytes = fromHex('deadbeef');
67
+ * console.log(bytes); // Uint8Array [222, 173, 190, 239]
68
+ *
69
+ * // Also works with 0x prefix
70
+ * const bytes2 = fromHex('0xCAFEBABE');
71
+ * console.log(toHex(bytes2)); // 'cafebabe'
72
+ * ```
73
+ */
74
+ export function fromHex(hex) {
75
+ // Strip 0x prefix if present
76
+ if (hex.length >= 2 && hex[0] === '0' && (hex[1] === 'x' || hex[1] === 'X')) {
77
+ hex = hex.slice(2);
78
+ }
79
+ const len = hex.length;
80
+ if (len % 2 !== 0) {
81
+ throw new TypeError('Invalid hex string: odd length');
82
+ }
83
+ const byteLength = len / 2;
84
+ const result = new Uint8Array(byteLength);
85
+ for (let i = 0; i < byteLength; i++) {
86
+ const charIndex = i * 2;
87
+ const highCode = hex.charCodeAt(charIndex);
88
+ const lowCode = hex.charCodeAt(charIndex + 1);
89
+ // Bounds check for lookup table
90
+ if (highCode >= 128 || lowCode >= 128) {
91
+ throw new TypeError(`Invalid hex character at position ${charIndex}`);
92
+ }
93
+ const high = HEX_TO_NIBBLE[highCode];
94
+ const low = HEX_TO_NIBBLE[lowCode];
95
+ if (high === -1) {
96
+ throw new TypeError(`Invalid hex character at position ${charIndex}`);
97
+ }
98
+ if (low === -1) {
99
+ throw new TypeError(`Invalid hex character at position ${charIndex + 1}`);
100
+ }
101
+ result[i] = (high << 4) | low;
102
+ }
103
+ return result;
104
+ }
105
+ /**
106
+ * Checks if a string is valid hexadecimal.
107
+ *
108
+ * @param value - The string to check
109
+ * @returns True if the string is valid hex (even length, valid chars)
110
+ *
111
+ * @example
112
+ * ```typescript
113
+ * import { isHex } from '@btc-vision/bitcoin';
114
+ *
115
+ * isHex('deadbeef'); // true
116
+ * isHex('0xdeadbeef'); // true
117
+ * isHex('DEADBEEF'); // true
118
+ * isHex('deadbee'); // false (odd length)
119
+ * isHex('deadbeeg'); // false (invalid char)
120
+ * ```
121
+ */
122
+ export function isHex(value) {
123
+ let hex = value;
124
+ if (hex.length >= 2 && hex[0] === '0' && (hex[1] === 'x' || hex[1] === 'X')) {
125
+ hex = hex.slice(2);
126
+ }
127
+ if (hex.length % 2 !== 0) {
128
+ return false;
129
+ }
130
+ for (let i = 0; i < hex.length; i++) {
131
+ const code = hex.charCodeAt(i);
132
+ if (code >= 128 || HEX_TO_NIBBLE[code] === -1) {
133
+ return false;
134
+ }
135
+ }
136
+ return true;
137
+ }
138
+ //# sourceMappingURL=hex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hex.js","sourceRoot":"","sources":["../../src/io/hex.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;GAGG;AACH,MAAM,WAAW,GAAsB,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAA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,GAAG,CAAC,EAAE,CAAC,CAAC;QAC9E,CAAC;QAED,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,IAAK,IAAI,CAAC,CAAC,GAAG,GAAI,CAAC;IACpC,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,KAAK,CAAC,KAAa;IAC/B,IAAI,GAAG,GAAG,KAAK,CAAC;IAChB,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC;QAC1E,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACvB,CAAC;IAED,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC/B,IAAI,IAAI,IAAI,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YAC5C,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * High-performance binary I/O module.
3
+ *
4
+ * This module provides efficient binary reading and writing with
5
+ * zero-allocation operations through stateful DataView instances.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ import * as varuint from 'varuint-bitcoin';
10
+ export { BinaryReader } from './BinaryReader.js';
11
+ export { BinaryWriter, GrowableBinaryWriter } from './BinaryWriter.js';
12
+ export { toHex, fromHex, isHex } from './hex.js';
13
+ export { fromBase64 } from './base64.js';
14
+ export { concat, equals, compare, isZero, clone, reverse, reverseCopy, alloc, xor, fromUtf8, toUtf8, } from './utils.js';
15
+ export { MemoryPool, SimpleMemoryPool } from './MemoryPool.js';
16
+ export { varuint };
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/io/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,OAAO,MAAM,iBAAiB,CAAC;AAG3C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAGvE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAGjD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EACH,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,KAAK,EACL,OAAO,EACP,WAAW,EACX,KAAK,EACL,GAAG,EACH,QAAQ,EACR,MAAM,GACT,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAG/D,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * High-performance binary I/O module.
3
+ *
4
+ * This module provides efficient binary reading and writing with
5
+ * zero-allocation operations through stateful DataView instances.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ import * as varuint from 'varuint-bitcoin';
10
+ // Binary reading and writing
11
+ export { BinaryReader } from './BinaryReader.js';
12
+ export { BinaryWriter, GrowableBinaryWriter } from './BinaryWriter.js';
13
+ // Hex encoding/decoding
14
+ export { toHex, fromHex, isHex } from './hex.js';
15
+ // Base64 decoding
16
+ export { fromBase64 } from './base64.js';
17
+ // Utility functions
18
+ export { concat, equals, compare, isZero, clone, reverse, reverseCopy, alloc, xor, fromUtf8, toUtf8, } from './utils.js';
19
+ // Memory pools
20
+ export { MemoryPool, SimpleMemoryPool } from './MemoryPool.js';
21
+ // Re-export varuint for Bitcoin CompactSize encoding
22
+ export { varuint };
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/io/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,OAAO,MAAM,iBAAiB,CAAC;AAE3C,6BAA6B;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEvE,wBAAwB;AACxB,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjD,kBAAkB;AAClB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,oBAAoB;AACpB,OAAO,EACH,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,KAAK,EACL,OAAO,EACP,WAAW,EACX,KAAK,EACL,GAAG,EACH,QAAQ,EACR,MAAM,GACT,MAAM,YAAY,CAAC;AAEpB,eAAe;AACf,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAE/D,qDAAqD;AACrD,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -0,0 +1,199 @@
1
+ /**
2
+ * Pure utility functions for Uint8Array operations.
3
+ *
4
+ * No DataView allocations. No wrappers.
5
+ * Optimized for performance with minimal allocations.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ /**
10
+ * Concatenates multiple Uint8Arrays into a single Uint8Array.
11
+ *
12
+ * Allocates exactly once for the result array.
13
+ *
14
+ * @param arrays - Arrays to concatenate
15
+ * @returns A new Uint8Array containing all input arrays
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { concat, fromHex } from '@btc-vision/bitcoin';
20
+ *
21
+ * const a = fromHex('deadbeef');
22
+ * const b = fromHex('cafebabe');
23
+ * const result = concat([a, b]);
24
+ * // result contains deadbeefcafebabe
25
+ * ```
26
+ */
27
+ export declare function concat(arrays: readonly Uint8Array[]): Uint8Array;
28
+ /**
29
+ * Checks if two Uint8Arrays have identical contents.
30
+ *
31
+ * @param a - First array
32
+ * @param b - Second array
33
+ * @returns True if arrays have the same length and contents
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * import { equals, fromHex } from '@btc-vision/bitcoin';
38
+ *
39
+ * const a = fromHex('deadbeef');
40
+ * const b = fromHex('deadbeef');
41
+ * const c = fromHex('cafebabe');
42
+ *
43
+ * equals(a, b); // true
44
+ * equals(a, c); // false
45
+ * ```
46
+ */
47
+ export declare function equals(a: Uint8Array, b: Uint8Array): boolean;
48
+ /**
49
+ * Compares two Uint8Arrays lexicographically.
50
+ *
51
+ * @param a - First array
52
+ * @param b - Second array
53
+ * @returns Negative if a < b, positive if a > b, 0 if equal
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * import { compare, fromHex } from '@btc-vision/bitcoin';
58
+ *
59
+ * const a = fromHex('0001');
60
+ * const b = fromHex('0002');
61
+ *
62
+ * compare(a, b); // -1 (a < b)
63
+ * compare(b, a); // 1 (b > a)
64
+ * compare(a, a); // 0 (equal)
65
+ * ```
66
+ */
67
+ export declare function compare(a: Uint8Array, b: Uint8Array): number;
68
+ /**
69
+ * Checks if a Uint8Array contains only zero bytes.
70
+ *
71
+ * @param bytes - Array to check
72
+ * @returns True if all bytes are zero
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * import { isZero } from '@btc-vision/bitcoin';
77
+ *
78
+ * isZero(new Uint8Array(32)); // true
79
+ * isZero(new Uint8Array([0, 0, 1])); // false
80
+ * ```
81
+ */
82
+ export declare function isZero(bytes: Uint8Array): boolean;
83
+ /**
84
+ * Creates a copy of a Uint8Array.
85
+ *
86
+ * @param bytes - Array to clone
87
+ * @returns A new Uint8Array with the same contents
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * import { clone, fromHex } from '@btc-vision/bitcoin';
92
+ *
93
+ * const original = fromHex('deadbeef');
94
+ * const copy = clone(original);
95
+ * copy[0] = 0; // Modifying copy doesn't affect original
96
+ * ```
97
+ */
98
+ export declare function clone(bytes: Uint8Array): Uint8Array;
99
+ /**
100
+ * Reverses a Uint8Array in place.
101
+ *
102
+ * @param bytes - Array to reverse
103
+ * @returns The same array, reversed
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * import { reverse, fromHex, toHex } from '@btc-vision/bitcoin';
108
+ *
109
+ * const bytes = fromHex('01020304');
110
+ * reverse(bytes);
111
+ * toHex(bytes); // '04030201'
112
+ * ```
113
+ */
114
+ export declare function reverse(bytes: Uint8Array): Uint8Array;
115
+ /**
116
+ * Creates a reversed copy of a Uint8Array.
117
+ *
118
+ * @param bytes - Array to copy and reverse
119
+ * @returns A new reversed Uint8Array
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * import { reverseCopy, fromHex, toHex } from '@btc-vision/bitcoin';
124
+ *
125
+ * const bytes = fromHex('01020304');
126
+ * const reversed = reverseCopy(bytes);
127
+ * toHex(reversed); // '04030201'
128
+ * toHex(bytes); // '01020304' (original unchanged)
129
+ * ```
130
+ */
131
+ export declare function reverseCopy(bytes: Uint8Array): Uint8Array;
132
+ /**
133
+ * Allocates a new Uint8Array of the specified size.
134
+ *
135
+ * @param size - Number of bytes to allocate
136
+ * @param fill - Optional fill value (default 0)
137
+ * @returns A new Uint8Array filled with the specified value
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * import { alloc, toHex } from '@btc-vision/bitcoin';
142
+ *
143
+ * const zeros = alloc(4); // 4 zero bytes
144
+ * const ones = alloc(4, 0xff); // 4 bytes of 0xff
145
+ * toHex(ones); // 'ffffffff'
146
+ * ```
147
+ */
148
+ export declare function alloc(size: number, fill?: number): Uint8Array;
149
+ /**
150
+ * XORs two Uint8Arrays together.
151
+ *
152
+ * @param a - First array
153
+ * @param b - Second array
154
+ * @returns A new Uint8Array with the XOR result
155
+ * @throws TypeError if arrays have different lengths
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * import { xor, fromHex, toHex } from '@btc-vision/bitcoin';
160
+ *
161
+ * const a = fromHex('ff00ff00');
162
+ * const b = fromHex('0f0f0f0f');
163
+ * const result = xor(a, b);
164
+ * toHex(result); // 'f00ff00f'
165
+ * ```
166
+ */
167
+ export declare function xor(a: Uint8Array, b: Uint8Array): Uint8Array;
168
+ /**
169
+ * Creates a Uint8Array from a UTF-8 string.
170
+ *
171
+ * @param str - String to encode
172
+ * @returns Uint8Array containing UTF-8 encoded bytes
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * import { fromUtf8, toHex } from '@btc-vision/bitcoin';
177
+ *
178
+ * const bytes = fromUtf8('hello');
179
+ * toHex(bytes); // '68656c6c6f'
180
+ * ```
181
+ */
182
+ export declare function fromUtf8(str: string): Uint8Array;
183
+ /**
184
+ * Decodes a Uint8Array to a UTF-8 string.
185
+ *
186
+ * @param bytes - Uint8Array to decode
187
+ * @returns Decoded string
188
+ *
189
+ * @example
190
+ * ```typescript
191
+ * import { toUtf8, fromHex } from '@btc-vision/bitcoin';
192
+ *
193
+ * const bytes = fromHex('68656c6c6f');
194
+ * const str = toUtf8(bytes);
195
+ * // str is 'hello'
196
+ * ```
197
+ */
198
+ export declare function toUtf8(bytes: Uint8Array): string;
199
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/io/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,GAAG,UAAU,CAehE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,OAAO,CAU5D;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,MAAM,CAS5D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAOjD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAKnD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAGrD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAMzD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,MAAU,GAAG,UAAU,CAMhE;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,UAAU,CAS5D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAEhD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAEhD"}
@@ -0,0 +1,271 @@
1
+ /**
2
+ * Pure utility functions for Uint8Array operations.
3
+ *
4
+ * No DataView allocations. No wrappers.
5
+ * Optimized for performance with minimal allocations.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ /**
10
+ * Concatenates multiple Uint8Arrays into a single Uint8Array.
11
+ *
12
+ * Allocates exactly once for the result array.
13
+ *
14
+ * @param arrays - Arrays to concatenate
15
+ * @returns A new Uint8Array containing all input arrays
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { concat, fromHex } from '@btc-vision/bitcoin';
20
+ *
21
+ * const a = fromHex('deadbeef');
22
+ * const b = fromHex('cafebabe');
23
+ * const result = concat([a, b]);
24
+ * // result contains deadbeefcafebabe
25
+ * ```
26
+ */
27
+ export function concat(arrays) {
28
+ let totalLength = 0;
29
+ for (let i = 0; i < arrays.length; i++) {
30
+ totalLength += arrays[i].length;
31
+ }
32
+ const result = new Uint8Array(totalLength);
33
+ let offset = 0;
34
+ for (let i = 0; i < arrays.length; i++) {
35
+ const arr = arrays[i];
36
+ result.set(arr, offset);
37
+ offset += arr.length;
38
+ }
39
+ return result;
40
+ }
41
+ /**
42
+ * Checks if two Uint8Arrays have identical contents.
43
+ *
44
+ * @param a - First array
45
+ * @param b - Second array
46
+ * @returns True if arrays have the same length and contents
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * import { equals, fromHex } from '@btc-vision/bitcoin';
51
+ *
52
+ * const a = fromHex('deadbeef');
53
+ * const b = fromHex('deadbeef');
54
+ * const c = fromHex('cafebabe');
55
+ *
56
+ * equals(a, b); // true
57
+ * equals(a, c); // false
58
+ * ```
59
+ */
60
+ export function equals(a, b) {
61
+ if (a.length !== b.length) {
62
+ return false;
63
+ }
64
+ for (let i = 0; i < a.length; i++) {
65
+ if (a[i] !== b[i]) {
66
+ return false;
67
+ }
68
+ }
69
+ return true;
70
+ }
71
+ /**
72
+ * Compares two Uint8Arrays lexicographically.
73
+ *
74
+ * @param a - First array
75
+ * @param b - Second array
76
+ * @returns Negative if a < b, positive if a > b, 0 if equal
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * import { compare, fromHex } from '@btc-vision/bitcoin';
81
+ *
82
+ * const a = fromHex('0001');
83
+ * const b = fromHex('0002');
84
+ *
85
+ * compare(a, b); // -1 (a < b)
86
+ * compare(b, a); // 1 (b > a)
87
+ * compare(a, a); // 0 (equal)
88
+ * ```
89
+ */
90
+ export function compare(a, b) {
91
+ const minLength = Math.min(a.length, b.length);
92
+ for (let i = 0; i < minLength; i++) {
93
+ const diff = a[i] - b[i];
94
+ if (diff !== 0) {
95
+ return diff;
96
+ }
97
+ }
98
+ return a.length - b.length;
99
+ }
100
+ /**
101
+ * Checks if a Uint8Array contains only zero bytes.
102
+ *
103
+ * @param bytes - Array to check
104
+ * @returns True if all bytes are zero
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * import { isZero } from '@btc-vision/bitcoin';
109
+ *
110
+ * isZero(new Uint8Array(32)); // true
111
+ * isZero(new Uint8Array([0, 0, 1])); // false
112
+ * ```
113
+ */
114
+ export function isZero(bytes) {
115
+ for (let i = 0; i < bytes.length; i++) {
116
+ if (bytes[i] !== 0) {
117
+ return false;
118
+ }
119
+ }
120
+ return true;
121
+ }
122
+ /**
123
+ * Creates a copy of a Uint8Array.
124
+ *
125
+ * @param bytes - Array to clone
126
+ * @returns A new Uint8Array with the same contents
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * import { clone, fromHex } from '@btc-vision/bitcoin';
131
+ *
132
+ * const original = fromHex('deadbeef');
133
+ * const copy = clone(original);
134
+ * copy[0] = 0; // Modifying copy doesn't affect original
135
+ * ```
136
+ */
137
+ export function clone(bytes) {
138
+ // Create a true copy - .slice() on Buffer returns a view, not a copy
139
+ const copy = new Uint8Array(bytes.length);
140
+ copy.set(bytes);
141
+ return copy;
142
+ }
143
+ /**
144
+ * Reverses a Uint8Array in place.
145
+ *
146
+ * @param bytes - Array to reverse
147
+ * @returns The same array, reversed
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * import { reverse, fromHex, toHex } from '@btc-vision/bitcoin';
152
+ *
153
+ * const bytes = fromHex('01020304');
154
+ * reverse(bytes);
155
+ * toHex(bytes); // '04030201'
156
+ * ```
157
+ */
158
+ export function reverse(bytes) {
159
+ bytes.reverse();
160
+ return bytes;
161
+ }
162
+ /**
163
+ * Creates a reversed copy of a Uint8Array.
164
+ *
165
+ * @param bytes - Array to copy and reverse
166
+ * @returns A new reversed Uint8Array
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * import { reverseCopy, fromHex, toHex } from '@btc-vision/bitcoin';
171
+ *
172
+ * const bytes = fromHex('01020304');
173
+ * const reversed = reverseCopy(bytes);
174
+ * toHex(reversed); // '04030201'
175
+ * toHex(bytes); // '01020304' (original unchanged)
176
+ * ```
177
+ */
178
+ export function reverseCopy(bytes) {
179
+ const result = new Uint8Array(bytes.length);
180
+ for (let i = 0; i < bytes.length; i++) {
181
+ result[i] = bytes[bytes.length - 1 - i];
182
+ }
183
+ return result;
184
+ }
185
+ /**
186
+ * Allocates a new Uint8Array of the specified size.
187
+ *
188
+ * @param size - Number of bytes to allocate
189
+ * @param fill - Optional fill value (default 0)
190
+ * @returns A new Uint8Array filled with the specified value
191
+ *
192
+ * @example
193
+ * ```typescript
194
+ * import { alloc, toHex } from '@btc-vision/bitcoin';
195
+ *
196
+ * const zeros = alloc(4); // 4 zero bytes
197
+ * const ones = alloc(4, 0xff); // 4 bytes of 0xff
198
+ * toHex(ones); // 'ffffffff'
199
+ * ```
200
+ */
201
+ export function alloc(size, fill = 0) {
202
+ const result = new Uint8Array(size);
203
+ if (fill !== 0) {
204
+ result.fill(fill);
205
+ }
206
+ return result;
207
+ }
208
+ /**
209
+ * XORs two Uint8Arrays together.
210
+ *
211
+ * @param a - First array
212
+ * @param b - Second array
213
+ * @returns A new Uint8Array with the XOR result
214
+ * @throws TypeError if arrays have different lengths
215
+ *
216
+ * @example
217
+ * ```typescript
218
+ * import { xor, fromHex, toHex } from '@btc-vision/bitcoin';
219
+ *
220
+ * const a = fromHex('ff00ff00');
221
+ * const b = fromHex('0f0f0f0f');
222
+ * const result = xor(a, b);
223
+ * toHex(result); // 'f00ff00f'
224
+ * ```
225
+ */
226
+ export function xor(a, b) {
227
+ if (a.length !== b.length) {
228
+ throw new TypeError('Arrays must have the same length for XOR operation');
229
+ }
230
+ const result = new Uint8Array(a.length);
231
+ for (let i = 0; i < a.length; i++) {
232
+ result[i] = a[i] ^ b[i];
233
+ }
234
+ return result;
235
+ }
236
+ /**
237
+ * Creates a Uint8Array from a UTF-8 string.
238
+ *
239
+ * @param str - String to encode
240
+ * @returns Uint8Array containing UTF-8 encoded bytes
241
+ *
242
+ * @example
243
+ * ```typescript
244
+ * import { fromUtf8, toHex } from '@btc-vision/bitcoin';
245
+ *
246
+ * const bytes = fromUtf8('hello');
247
+ * toHex(bytes); // '68656c6c6f'
248
+ * ```
249
+ */
250
+ export function fromUtf8(str) {
251
+ return new TextEncoder().encode(str);
252
+ }
253
+ /**
254
+ * Decodes a Uint8Array to a UTF-8 string.
255
+ *
256
+ * @param bytes - Uint8Array to decode
257
+ * @returns Decoded string
258
+ *
259
+ * @example
260
+ * ```typescript
261
+ * import { toUtf8, fromHex } from '@btc-vision/bitcoin';
262
+ *
263
+ * const bytes = fromHex('68656c6c6f');
264
+ * const str = toUtf8(bytes);
265
+ * // str is 'hello'
266
+ * ```
267
+ */
268
+ export function toUtf8(bytes) {
269
+ return new TextDecoder().decode(bytes);
270
+ }
271
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/io/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,MAAM,CAAC,MAA6B;IAChD,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,WAAW,IAAI,MAAM,CAAC,CAAC,CAAE,CAAC,MAAM,CAAC;IACrC,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;IAC3C,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MA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IAAI,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,GAAG,CAAC,CAAa,EAAE,CAAa;IAC5C,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;QACxB,MAAM,IAAI,SAAS,CAAC,oDAAoD,CAAC,CAAC;IAC9E,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IACxC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC;IAC9B,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAW;IAChC,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACzC,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,MAAM,CAAC,KAAiB;IACpC,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC3C,CAAC"}
package/build/merkle.d.ts CHANGED
@@ -1 +1,10 @@
1
- export declare function fastMerkleRoot(values: Buffer[], digestFn: (b: Buffer) => Buffer): Buffer;
1
+ /**
2
+ * Calculates the Merkle root of an array of Uint8Arrays using a specified digest function.
3
+ *
4
+ * @param values - The array of Uint8Arrays.
5
+ * @param digestFn - The digest function used to calculate the hash of the concatenated arrays.
6
+ * @returns The Merkle root as a Uint8Array.
7
+ * @throws {TypeError} If the values parameter is not an array or the digestFn parameter is not a function.
8
+ */
9
+ export declare function fastMerkleRoot(values: Uint8Array[], digestFn: (b: Uint8Array) => Uint8Array): Uint8Array;
10
+ //# sourceMappingURL=merkle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merkle.d.ts","sourceRoot":"","sources":["../src/merkle.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC1B,MAAM,EAAE,UAAU,EAAE,EACpB,QAAQ,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,UAAU,GACxC,UAAU,CAwBZ"}