@btc-vision/bitcoin 6.5.6 → 7.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (456) 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 +57 -10
  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 +12477 -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 +58 -11
  115. package/build/address.d.ts.map +1 -0
  116. package/build/address.js +82 -25
  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 +202 -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 +35 -9
  203. package/build/payments/bip341.d.ts.map +1 -0
  204. package/build/payments/bip341.js +34 -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 -150
  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 +428 -103
  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 +465 -143
  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 +117 -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 +406 -413
  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 +101 -37
  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 +169 -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 +68 -9
  332. package/scripts/bundle-ecc.ts +111 -0
  333. package/src/address.ts +91 -45
  334. package/src/bech32utils.ts +3 -3
  335. package/src/bip66.ts +34 -24
  336. package/src/block.ts +205 -86
  337. package/src/branded.ts +18 -0
  338. package/src/crypto.ts +64 -26
  339. package/src/ecc/context.ts +280 -0
  340. package/src/ecc/index.ts +14 -0
  341. package/src/ecc/types.ts +147 -0
  342. package/src/ecpair.d.ts +99 -0
  343. package/src/errors.ts +163 -0
  344. package/src/index.ts +112 -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 +32 -33
  355. package/src/payments/embed.ts +244 -41
  356. package/src/payments/index.ts +12 -10
  357. package/src/payments/p2ms.ts +497 -118
  358. package/src/payments/p2op.ts +432 -134
  359. package/src/payments/p2pk.ts +370 -72
  360. package/src/payments/p2pkh.ts +524 -130
  361. package/src/payments/p2sh.ts +572 -169
  362. package/src/payments/p2tr.ts +686 -194
  363. package/src/payments/p2wpkh.ts +482 -105
  364. package/src/payments/p2wsh.ts +524 -162
  365. package/src/payments/types.ts +80 -66
  366. package/src/psbt/bip371.ts +72 -51
  367. package/src/psbt/psbtutils.ts +39 -40
  368. package/src/psbt/types.ts +324 -0
  369. package/src/psbt/utils.ts +188 -0
  370. package/src/psbt/validation.ts +185 -0
  371. package/src/psbt.ts +608 -827
  372. package/src/pubkey.ts +22 -23
  373. package/src/push_data.ts +18 -16
  374. package/src/script.ts +81 -66
  375. package/src/script_number.ts +6 -6
  376. package/src/script_signature.ts +33 -36
  377. package/src/transaction.ts +462 -239
  378. package/src/types.ts +229 -100
  379. package/src/workers/WorkerSigningPool.node.ts +887 -0
  380. package/src/workers/WorkerSigningPool.ts +666 -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 +327 -0
  384. package/src/workers/signing-worker.ts +353 -0
  385. package/src/workers/types.ts +417 -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/typedoc.json +29 -0
  421. package/vite.config.browser.ts +3 -42
  422. package/vitest.config.integration.ts +2 -0
  423. package/browser/bufferutils.d.ts +0 -34
  424. package/browser/chunks/crypto-BhCpKpek.js +0 -2033
  425. package/browser/chunks/payments-B1wlSccx.js +0 -1089
  426. package/browser/chunks/psbt-BCNk7JUx.js +0 -4055
  427. package/browser/chunks/script-DyPItFEl.js +0 -318
  428. package/browser/chunks/transaction-C_UbhMGn.js +0 -432
  429. package/browser/chunks/utils-DNZi-T5W.js +0 -761
  430. package/browser/ecc_lib.d.ts +0 -3
  431. package/browser/hooks/AdvancedSignatureManager.d.ts +0 -16
  432. package/browser/hooks/HookedSigner.d.ts +0 -4
  433. package/browser/hooks/SignatureManager.d.ts +0 -13
  434. package/browser/payments/lazy.d.ts +0 -2
  435. package/browser/typeforce.d.ts +0 -38
  436. package/build/bufferutils.d.ts +0 -34
  437. package/build/bufferutils.js +0 -141
  438. package/build/ecc_lib.d.ts +0 -3
  439. package/build/ecc_lib.js +0 -61
  440. package/build/hooks/AdvancedSignatureManager.d.ts +0 -16
  441. package/build/hooks/AdvancedSignatureManager.js +0 -52
  442. package/build/hooks/HookedSigner.d.ts +0 -4
  443. package/build/hooks/HookedSigner.js +0 -64
  444. package/build/hooks/SignatureManager.d.ts +0 -13
  445. package/build/hooks/SignatureManager.js +0 -45
  446. package/build/payments/lazy.d.ts +0 -2
  447. package/build/payments/lazy.js +0 -28
  448. package/build/tsconfig.tsbuildinfo +0 -1
  449. package/src/bufferutils.ts +0 -188
  450. package/src/ecc_lib.ts +0 -94
  451. package/src/hooks/AdvancedSignatureManager.ts +0 -104
  452. package/src/hooks/HookedSigner.ts +0 -108
  453. package/src/hooks/SignatureManager.ts +0 -84
  454. package/src/payments/lazy.ts +0 -28
  455. package/src/typeforce.d.ts +0 -38
  456. package/tsconfig.webpack.json +0 -18
@@ -0,0 +1,178 @@
1
+ /**
2
+ * PSBT 2000 Input Benchmark - Tests Taproot signing performance
3
+ *
4
+ * This benchmark measures the O(n^2) -> O(n) optimization for Taproot signing.
5
+ *
6
+ * Run with: npx tsx benchmark/psbt-2000-inputs.bench.ts
7
+ */
8
+
9
+ import * as ecc from 'tiny-secp256k1';
10
+ import { randomBytes } from 'crypto';
11
+ import { BIP32Factory } from '@btc-vision/bip32';
12
+ import { initEccLib, Psbt, payments, crypto, Transaction } from '../src/index.js';
13
+ import { toXOnly } from '../src/pubkey.js';
14
+
15
+ // Initialize ECC library
16
+ initEccLib(ecc);
17
+ const bip32 = BIP32Factory(ecc);
18
+
19
+ // Generate a test keypair for taproot key-path spending
20
+ function generateTaprootKeyPair() {
21
+ const node = bip32.fromSeed(randomBytes(64));
22
+ const xOnlyPubkey = toXOnly(node.publicKey);
23
+
24
+ // Create tweaked signer for taproot key-path spending
25
+ const tweakedNode = node.tweak(crypto.taggedHash('TapTweak', xOnlyPubkey));
26
+
27
+ return {
28
+ xOnlyPubkey,
29
+ signer: tweakedNode,
30
+ };
31
+ }
32
+
33
+ // Create a fake previous transaction for nonWitnessUtxo
34
+ function createFakePrevTx(outputScript: Uint8Array, value: bigint, index: number): Buffer {
35
+ const tx = new Transaction();
36
+ tx.version = 2;
37
+ const inputHash = Buffer.alloc(32);
38
+ inputHash.writeUInt32LE(index, 0);
39
+ tx.addInput(inputHash, 0);
40
+ tx.addOutput(outputScript, value);
41
+ return tx.toBuffer();
42
+ }
43
+
44
+ async function runBenchmark(inputCount: number, iterations: number = 5) {
45
+ console.log(`\n--- Benchmarking ${inputCount} P2TR inputs ---`);
46
+
47
+ const keyPair = generateTaprootKeyPair();
48
+
49
+ const { output } = payments.p2tr({
50
+ internalPubkey: keyPair.xOnlyPubkey,
51
+ });
52
+ if (!output) throw new Error('Failed to create P2TR output');
53
+
54
+ const inputValue = 10000n;
55
+ const totalInput = inputValue * BigInt(inputCount);
56
+ const fee = 1000n;
57
+ const outputValue = (totalInput - fee) / 5n;
58
+
59
+ console.log(` Generating ${inputCount} fake previous transactions...`);
60
+ const setupStart = performance.now();
61
+
62
+ const prevTxs: Buffer[] = [];
63
+ const txIds: Buffer[] = [];
64
+ for (let i = 0; i < inputCount; i++) {
65
+ const prevTx = createFakePrevTx(output, inputValue, i);
66
+ prevTxs.push(prevTx);
67
+ const hash1 = crypto.sha256(prevTx);
68
+ const hash2 = crypto.sha256(hash1);
69
+ const txId = Buffer.from(hash2).reverse();
70
+ txIds.push(txId);
71
+ }
72
+
73
+ console.log(` Setup done in ${((performance.now() - setupStart) / 1000).toFixed(2)}s`);
74
+
75
+ // Warmup
76
+ console.log(' Warming up...');
77
+ {
78
+ const psbt = new Psbt();
79
+ for (let i = 0; i < Math.min(100, inputCount); i++) {
80
+ psbt.addInput({
81
+ hash: txIds[i],
82
+ index: 0,
83
+ nonWitnessUtxo: prevTxs[i],
84
+ tapInternalKey: keyPair.xOnlyPubkey,
85
+ });
86
+ }
87
+ for (let i = 0; i < 5; i++) {
88
+ psbt.addOutput({ script: output, value: outputValue });
89
+ }
90
+ psbt.signAllInputs(keyPair.signer);
91
+ }
92
+
93
+ const times: number[] = [];
94
+
95
+ for (let iter = 0; iter < iterations; iter++) {
96
+ const psbt = new Psbt();
97
+
98
+ for (let i = 0; i < inputCount; i++) {
99
+ psbt.addInput({
100
+ hash: txIds[i],
101
+ index: 0,
102
+ nonWitnessUtxo: prevTxs[i],
103
+ tapInternalKey: keyPair.xOnlyPubkey,
104
+ });
105
+ }
106
+
107
+ for (let i = 0; i < 5; i++) {
108
+ psbt.addOutput({ script: output, value: outputValue });
109
+ }
110
+
111
+ const start = performance.now();
112
+ psbt.signAllInputs(keyPair.signer);
113
+ const elapsed = performance.now() - start;
114
+ times.push(elapsed);
115
+
116
+ console.log(` Iteration ${iter + 1}: ${elapsed.toFixed(2)}ms`);
117
+ }
118
+
119
+ const avg = times.reduce((a, b) => a + b, 0) / times.length;
120
+ const min = Math.min(...times);
121
+ const max = Math.max(...times);
122
+
123
+ console.log(`\n Results for ${inputCount} inputs:`);
124
+ console.log(` Average: ${avg.toFixed(2)}ms`);
125
+ console.log(` Min: ${min.toFixed(2)}ms`);
126
+ console.log(` Max: ${max.toFixed(2)}ms`);
127
+ console.log(` Per-input: ${(avg / inputCount).toFixed(4)}ms`);
128
+
129
+ return { inputCount, avg, min, max };
130
+ }
131
+
132
+ async function main() {
133
+ console.log('='.repeat(70));
134
+ console.log(' PSBT Taproot Signing Benchmark (prevOuts caching optimization)');
135
+ console.log('='.repeat(70));
136
+
137
+ const inputCounts = [100, 500, 1000, 2000];
138
+ const results: Array<{ inputCount: number; avg: number; min: number; max: number }> = [];
139
+
140
+ for (const count of inputCounts) {
141
+ const result = await runBenchmark(count, 3);
142
+ results.push(result);
143
+ }
144
+
145
+ console.log('\n' + '='.repeat(70));
146
+ console.log(' SUMMARY');
147
+ console.log('='.repeat(70));
148
+ console.log('\n Inputs | Avg (ms) | Min (ms) | Max (ms) | Per-input (ms)');
149
+ console.log(' -------|----------|----------|----------|---------------');
150
+ for (const r of results) {
151
+ console.log(
152
+ ` ${String(r.inputCount).padStart(6)} | ${r.avg.toFixed(2).padStart(8)} | ${r.min.toFixed(2).padStart(8)} | ${r.max.toFixed(2).padStart(8)} | ${(r.avg / r.inputCount).toFixed(4).padStart(13)}`,
153
+ );
154
+ }
155
+
156
+ console.log('\n Scaling Analysis:');
157
+ if (results.length >= 2) {
158
+ const first = results[0];
159
+ const last = results[results.length - 1];
160
+ const perInputFirst = first.avg / first.inputCount;
161
+ const perInputLast = last.avg / last.inputCount;
162
+ const ratio = perInputLast / perInputFirst;
163
+
164
+ console.log(` Per-input time at ${first.inputCount} inputs: ${perInputFirst.toFixed(4)}ms`);
165
+ console.log(` Per-input time at ${last.inputCount} inputs: ${perInputLast.toFixed(4)}ms`);
166
+ console.log(` Ratio: ${ratio.toFixed(2)}x`);
167
+
168
+ if (ratio < 2) {
169
+ console.log(' Result: O(n) scaling achieved!');
170
+ } else {
171
+ console.log(' Result: Scaling is worse than O(n).');
172
+ }
173
+ }
174
+
175
+ console.log();
176
+ }
177
+
178
+ main().catch(console.error);
@@ -0,0 +1,147 @@
1
+ /**
2
+ * Standalone Worker Signing Benchmark
3
+ *
4
+ * Run with: npx tsx benchmark/signing.bench.ts
5
+ */
6
+
7
+ import * as ecc from 'tiny-secp256k1';
8
+ import { randomBytes } from 'crypto';
9
+ import { initEccLib } from '../src/ecc/context.js';
10
+ import { SignatureType, type SigningTask } from '../src/workers/types.js';
11
+
12
+ // Initialize ECC
13
+ initEccLib(ecc);
14
+
15
+ // Test key pair
16
+ const TEST_PRIVATE_KEY = randomBytes(32);
17
+ const TEST_PUBLIC_KEY = ecc.pointFromScalar(TEST_PRIVATE_KEY, true)!;
18
+
19
+ const signer = {
20
+ publicKey: TEST_PUBLIC_KEY,
21
+ sign: (hash: Uint8Array) => ecc.sign(hash, TEST_PRIVATE_KEY),
22
+ getPrivateKey: () => new Uint8Array(TEST_PRIVATE_KEY),
23
+ };
24
+
25
+ async function main() {
26
+ console.log('='.repeat(70));
27
+ console.log(' WORKER SIGNING BENCHMARK');
28
+ console.log('='.repeat(70));
29
+ console.log();
30
+
31
+ const inputCounts = [4, 8, 16, 32, 64, 100, 200, 2000];
32
+ const iterations = 50;
33
+
34
+ // Pre-generate ALL hashes upfront (just random 32-byte arrays)
35
+ console.log('Generating test hashes...');
36
+ const setupStart = performance.now();
37
+
38
+ const allTasks: Map<number, SigningTask[][]> = new Map();
39
+ for (const inputCount of inputCounts) {
40
+ const iters = inputCount >= 2000 ? 10 : iterations;
41
+ const tasksForCount: SigningTask[][] = [];
42
+
43
+ for (let i = 0; i < iters + 5; i++) {
44
+ const tasks: SigningTask[] = [];
45
+ for (let j = 0; j < inputCount; j++) {
46
+ tasks.push({
47
+ taskId: `task-${i}-${j}`,
48
+ inputIndex: j,
49
+ hash: randomBytes(32),
50
+ signatureType: SignatureType.ECDSA,
51
+ sighashType: 0x01,
52
+ });
53
+ }
54
+ tasksForCount.push(tasks);
55
+ }
56
+ allTasks.set(inputCount, tasksForCount);
57
+ }
58
+
59
+ console.log(`Setup done in ${((performance.now() - setupStart) / 1000).toFixed(2)}s`);
60
+ console.log();
61
+
62
+ // Initialize worker pool
63
+ const { NodeWorkerSigningPool } = await import('../src/workers/WorkerSigningPool.node.js');
64
+ NodeWorkerSigningPool.resetInstance();
65
+ const pool = NodeWorkerSigningPool.getInstance({ workerCount: 4 });
66
+ await pool.initialize();
67
+ pool.preserveWorkers();
68
+
69
+ console.log(`Worker pool: ${pool.workerCount} workers`);
70
+ console.log(`Iterations: ${iterations} (10 for 2000 inputs)`);
71
+ console.log();
72
+
73
+ const results: Array<{
74
+ inputs: number;
75
+ seqAvg: number;
76
+ parAvg: number;
77
+ speedup: number;
78
+ }> = [];
79
+
80
+ for (const inputCount of inputCounts) {
81
+ console.log(`--- ${inputCount} Inputs ---`);
82
+
83
+ const testIterations = inputCount >= 2000 ? 10 : iterations;
84
+ const tasks = allTasks.get(inputCount)!;
85
+
86
+ // Warmup sequential
87
+ for (let i = 0; i < 5; i++) {
88
+ for (const task of tasks[i]) {
89
+ signer.sign(task.hash);
90
+ }
91
+ }
92
+
93
+ // Benchmark sequential
94
+ const seqTimes: number[] = [];
95
+ for (let i = 5; i < testIterations + 5; i++) {
96
+ const start = performance.now();
97
+ for (const task of tasks[i]) {
98
+ signer.sign(task.hash);
99
+ }
100
+ seqTimes.push(performance.now() - start);
101
+ }
102
+
103
+ // Warmup parallel
104
+ for (let i = 0; i < 5; i++) {
105
+ await pool.signBatch(tasks[i], signer);
106
+ }
107
+
108
+ // Benchmark parallel
109
+ const parTimes: number[] = [];
110
+ for (let i = 5; i < testIterations + 5; i++) {
111
+ const start = performance.now();
112
+ await pool.signBatch(tasks[i], signer);
113
+ parTimes.push(performance.now() - start);
114
+ }
115
+
116
+ const seqTotal = seqTimes.reduce((a, b) => a + b, 0);
117
+ const seqAvg = seqTotal / seqTimes.length;
118
+ const parTotal = parTimes.reduce((a, b) => a + b, 0);
119
+ const parAvg = parTotal / parTimes.length;
120
+ const speedup = seqAvg / parAvg;
121
+
122
+ console.log(` Sequential: ${seqAvg.toFixed(2)}ms avg (total: ${(seqTotal / 1000).toFixed(2)}s)`);
123
+ console.log(` Parallel: ${parAvg.toFixed(2)}ms avg (total: ${(parTotal / 1000).toFixed(2)}s)`);
124
+ console.log(` Speedup: ${speedup.toFixed(2)}x`);
125
+ console.log();
126
+
127
+ results.push({ inputs: inputCount, seqAvg, parAvg, speedup });
128
+ }
129
+
130
+ await pool.shutdown();
131
+
132
+ // Summary
133
+ console.log('='.repeat(70));
134
+ console.log(' SUMMARY');
135
+ console.log('='.repeat(70));
136
+ console.log();
137
+ console.log(' Inputs | Sequential (avg) | Parallel (avg) | Speedup');
138
+ console.log(' -------|------------------|----------------|--------');
139
+ for (const r of results) {
140
+ console.log(
141
+ ` ${String(r.inputs).padStart(6)} | ${r.seqAvg.toFixed(2).padStart(14)}ms | ${r.parAvg.toFixed(2).padStart(12)}ms | ${r.speedup.toFixed(2).padStart(6)}x`,
142
+ );
143
+ }
144
+ console.log();
145
+ }
146
+
147
+ main().catch(console.error);
@@ -1,9 +1,13 @@
1
- import { fromBech32, Bech32Result } from './bech32utils.js';
1
+ import { Bech32Result, fromBech32 } from './bech32utils.js';
2
2
  import { Network } from './networks.js';
3
+ import { Bytes20 } from './types.js';
3
4
  export { fromBech32, type Bech32Result };
5
+ /** base58check decode result */
4
6
  export interface Base58CheckResult {
5
- hash: Buffer;
6
- version: number;
7
+ /** address hash */
8
+ readonly hash: Bytes20;
9
+ /** address version: 0x00 for P2PKH, 0x05 for P2SH */
10
+ readonly version: number;
7
11
  }
8
12
  export declare const FUTURE_SEGWIT_MAX_SIZE: number;
9
13
  export declare const FUTURE_SEGWIT_MIN_SIZE: number;
@@ -12,11 +16,54 @@ export declare const FUTURE_MAX_VERSION: number;
12
16
  export declare const FUTURE_OPNET_VERSION: number;
13
17
  export declare const FUTURE_SEGWIT_MIN_VERSION: number;
14
18
  export declare const FUTURE_SEGWIT_VERSION_DIFF: number;
15
- export declare const isUnknownSegwitVersion: (output: Buffer) => boolean;
16
- export declare function toFutureOPNetAddress(output: Buffer, network: Network): string;
17
- export declare function _toFutureSegwitAddress(output: Buffer, network: Network): string;
19
+ export declare const isUnknownSegwitVersion: (output: Uint8Array) => boolean;
20
+ /**
21
+ * Encode a future Taproot-style segwit address (SegWit v2 - v16) using bech32m.
22
+ * Only for versions not yet assigned specific meanings (future use).
23
+ *
24
+ * @param output - Output script buffer containing the version and witness program
25
+ * @param network - Network object containing bech32 and optional bech32Opnet prefix
26
+ * @returns Bech32m-encoded future Taproot-style address
27
+ */
28
+ export declare function toFutureOPNetAddress(output: Uint8Array, network: Network): string;
29
+ export declare function _toFutureSegwitAddress(output: Uint8Array, network: Network): string;
30
+ /**
31
+ * decode address with base58 specification, return address version and address hash if valid
32
+ */
18
33
  export declare function fromBase58Check(address: string): Base58CheckResult;
19
- export declare function toBase58Check(hash: Buffer, version: number): string;
20
- export declare function toBech32(data: Buffer, version: number, prefix: string, prefixOpnet?: string): string;
21
- export declare function fromOutputScript(output: Buffer, network?: Network): string;
22
- export declare function toOutputScript(address: string, network?: Network): Buffer;
34
+ /**
35
+ * encode address hash to base58 address with version
36
+ */
37
+ export declare function toBase58Check(hash: Bytes20, version: number): string;
38
+ /**
39
+ * encode address hash to bech32 address with version and prefix
40
+ */
41
+ export declare function toBech32(data: Uint8Array, version: number, prefix: string, prefixOpnet?: string): string;
42
+ /**
43
+ * decode address from output script with network, return address if matched
44
+ */
45
+ export declare function fromOutputScript(output: Uint8Array, network?: Network): string;
46
+ /**
47
+ * Options for toOutputScript function.
48
+ */
49
+ export interface ToOutputScriptOptions {
50
+ /**
51
+ * Network to use for encoding. Defaults to bitcoin mainnet.
52
+ */
53
+ readonly network?: Network;
54
+ /**
55
+ * Optional callback for future segwit version warnings.
56
+ * If provided, called with FUTURE_SEGWIT_VERSION_WARNING when encoding
57
+ * to a future segwit version (v2-v15) address.
58
+ * If not provided, no warning is emitted.
59
+ */
60
+ readonly onFutureSegwitWarning?: (warning: string) => void;
61
+ }
62
+ /**
63
+ * Encodes address to output script with network, return output script if address matched.
64
+ * @param address - The address to encode
65
+ * @param networkOrOptions - Network or options object
66
+ * @returns The output script as Uint8Array
67
+ */
68
+ export declare function toOutputScript(address: string, networkOrOptions?: Network | ToOutputScriptOptions): Uint8Array;
69
+ //# sourceMappingURL=address.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../src/address.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,KAAK,YAAY,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEjE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAU7C,OAAO,EACH,KAAK,OAAO,EAOf,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,UAAU,EAAE,KAAK,YAAY,EAAE,CAAC;AAEzC,gCAAgC;AAChC,MAAM,WAAW,iBAAiB;IAC9B,mBAAmB;IACnB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,qDAAqD;IACrD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC5B;AAED,eAAO,MAAM,sBAAsB,EAAE,MAAW,CAAC;AACjD,eAAO,MAAM,sBAAsB,EAAE,MAAU,CAAC;AAChD,eAAO,MAAM,yBAAyB,EAAE,MAAW,CAAC;AACpD,eAAO,MAAM,kBAAkB,EAAE,MAAW,CAAC;AAC7C,eAAO,MAAM,oBAAoB,EAAE,MAAW,CAAC;AAC/C,eAAO,MAAM,yBAAyB,EAAE,MAAU,CAAC;AACnD,eAAO,MAAM,0BAA0B,EAAE,MAAa,CAAC;AAOvD,eAAO,MAAM,sBAAsB,GAAI,QAAQ,UAAU,KAAG,OAkB3D,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAoCjF;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAgBnF;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,iBAAiB,CAWlE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CASpE;AAED;;GAEG;AACH,wBAAgB,QAAQ,CACpB,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,MAAM,GACrB,MAAM,CASR;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CA2B9E;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IAClC;;OAEG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;;OAKG;IACH,QAAQ,CAAC,qBAAqB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC1B,OAAO,EAAE,MAAM,EACf,gBAAgB,CAAC,EAAE,OAAO,GAAG,qBAAqB,GACnD,UAAU,CAwEZ"}
@@ -1,6 +1,14 @@
1
+ /** bech32 decode result */
1
2
  export interface Bech32Result {
3
+ /** address version: 0x00 for P2WPKH、P2WSH, 0x01 for P2TR*/
2
4
  version: number;
5
+ /** address prefix: bc for P2WPKH、P2WSH、P2TR */
3
6
  prefix: string;
4
- data: Buffer;
7
+ /** address data:20 bytes for P2WPKH, 32 bytes for P2WSH、P2TR */
8
+ data: Uint8Array;
5
9
  }
10
+ /**
11
+ * decode address with bech32 specification, return address version、address prefix and address data if valid
12
+ */
6
13
  export declare function fromBech32(address: string): Bech32Result;
14
+ //# sourceMappingURL=bech32utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bech32utils.d.ts","sourceRoot":"","sources":["../src/bech32utils.ts"],"names":[],"mappings":"AAMA,2BAA2B;AAC3B,MAAM,WAAW,YAAY;IACzB,2DAA2D;IAC3D,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,gEAAgE;IAChE,IAAI,EAAE,UAAU,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,CAuBxD"}
@@ -1,6 +1,11 @@
1
- export declare function check(buffer: Buffer): boolean;
2
- export declare function decode(buffer: Buffer): {
3
- r: Buffer;
4
- s: Buffer;
5
- };
6
- export declare function encode(r: Buffer, s: Buffer): Buffer;
1
+ /**
2
+ * DER-encoded signature components.
3
+ */
4
+ export interface DerSignature {
5
+ readonly r: Uint8Array;
6
+ readonly s: Uint8Array;
7
+ }
8
+ export declare function check(buffer: Uint8Array): boolean;
9
+ export declare function decode(buffer: Uint8Array): DerSignature;
10
+ export declare function encode(r: Uint8Array, s: Uint8Array): Uint8Array;
11
+ //# sourceMappingURL=bip66.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bip66.d.ts","sourceRoot":"","sources":["../src/bip66.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,QAAQ,CAAC,CAAC,EAAE,UAAU,CAAC;IACvB,QAAQ,CAAC,CAAC,EAAE,UAAU,CAAC;CAC1B;AAED,wBAAgB,KAAK,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAsBjD;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,YAAY,CA6BvD;AAwBD,wBAAgB,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,UAAU,CAyB/D"}
@@ -1,29 +1,135 @@
1
1
  import { Transaction } from './transaction.js';
2
+ import { Bytes32 } from './types.js';
3
+ /**
4
+ * Represents a Bitcoin block with header fields and optional transactions.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import { Block, fromHex } from '@btc-vision/bitcoin';
9
+ *
10
+ * // Parse a block from hex
11
+ * const block = Block.fromHex('0100000000000000...');
12
+ *
13
+ * // Access block properties
14
+ * console.log(block.version);
15
+ * console.log(block.getId());
16
+ * console.log(block.timestamp);
17
+ *
18
+ * // Check proof of work
19
+ * if (block.checkProofOfWork()) {
20
+ * console.log('Valid PoW');
21
+ * }
22
+ * ```
23
+ */
2
24
  export declare class Block {
25
+ #private;
26
+ /** Block version number */
3
27
  version: number;
4
- prevHash?: Buffer;
5
- merkleRoot?: Buffer;
28
+ /** Hash of the previous block (32 bytes) */
29
+ prevHash?: Bytes32;
30
+ /** Merkle root of the transactions (32 bytes) */
31
+ merkleRoot?: Bytes32;
32
+ /** Block timestamp (Unix time) */
6
33
  timestamp: number;
7
- witnessCommit?: Buffer;
34
+ /** Witness commitment for SegWit blocks (32 bytes) */
35
+ witnessCommit?: Bytes32;
36
+ /** Compact representation of the target threshold */
8
37
  bits: number;
38
+ /** Nonce used for proof of work */
9
39
  nonce: number;
40
+ /** Array of transactions included in the block */
10
41
  transactions?: Transaction[];
11
- static fromBuffer(buffer: Buffer): Block;
42
+ /**
43
+ * Parses a Block from a Uint8Array.
44
+ * @param buffer - The raw block data (minimum 80 bytes for header only)
45
+ * @returns Parsed Block instance
46
+ * @throws Error if buffer is too small
47
+ */
48
+ static fromBuffer(buffer: Uint8Array): Block;
49
+ /**
50
+ * Parses a Block from a hex string.
51
+ * @param hex - Hexadecimal representation of the block
52
+ * @returns Parsed Block instance
53
+ */
12
54
  static fromHex(hex: string): Block;
13
- static calculateTarget(bits: number): Buffer;
14
- static calculateMerkleRoot(transactions: Transaction[], forWitness?: boolean): Buffer;
15
- getWitnessCommit(): Buffer | null;
55
+ /**
56
+ * Calculates the target threshold from the compact bits representation.
57
+ * @param bits - Compact bits value from block header
58
+ * @returns 32-byte target threshold
59
+ */
60
+ static calculateTarget(bits: number): Bytes32;
61
+ /**
62
+ * Calculates the merkle root for a list of transactions.
63
+ * @param transactions - Array of transactions
64
+ * @param forWitness - If true, calculate witness merkle root (for SegWit)
65
+ * @returns 32-byte merkle root hash
66
+ * @throws TypeError if transactions is empty or not an array
67
+ */
68
+ static calculateMerkleRoot(transactions: Transaction[], forWitness?: boolean): Bytes32;
69
+ /**
70
+ * Extracts the witness commitment from the coinbase transaction.
71
+ * @returns 32-byte witness commitment or null if not found
72
+ */
73
+ getWitnessCommit(): Bytes32 | null;
74
+ /**
75
+ * Checks if this block has a witness commitment.
76
+ * @returns True if the block has a witness commitment
77
+ */
16
78
  hasWitnessCommit(): boolean;
79
+ /**
80
+ * Checks if any transaction in this block has witness data.
81
+ * @returns True if any transaction has witness data
82
+ */
17
83
  hasWitness(): boolean;
84
+ /**
85
+ * Calculates the weight of this block.
86
+ * Weight = (base size * 3) + total size
87
+ * @returns Block weight in weight units
88
+ */
18
89
  weight(): number;
90
+ /**
91
+ * Calculates the serialized byte length of this block.
92
+ * @param headersOnly - If true, return only header size (80 bytes)
93
+ * @param allowWitness - If true, include witness data in calculation
94
+ * @returns Byte length of the serialized block
95
+ */
19
96
  byteLength(headersOnly?: boolean, allowWitness?: boolean): number;
20
- getHash(): Buffer;
97
+ /**
98
+ * Computes the double-SHA256 hash of the block header.
99
+ * @returns 32-byte block hash
100
+ */
101
+ getHash(): Bytes32;
102
+ /**
103
+ * Returns the block ID (hash in reversed hex format, as displayed in block explorers).
104
+ * @returns Block ID as hex string
105
+ */
21
106
  getId(): string;
107
+ /**
108
+ * Converts the block timestamp to a Date object.
109
+ * @returns UTC date of the block
110
+ */
22
111
  getUTCDate(): Date;
23
- toBuffer(headersOnly?: boolean): Buffer;
112
+ /**
113
+ * Serializes the block to a Uint8Array.
114
+ * @param headersOnly - If true, only serialize the 80-byte header
115
+ * @returns Serialized block data
116
+ */
117
+ toBuffer(headersOnly?: boolean): Uint8Array;
118
+ /**
119
+ * Serializes the block to a hex string.
120
+ * @param headersOnly - If true, only serialize the 80-byte header
121
+ * @returns Hex string representation of the block
122
+ */
24
123
  toHex(headersOnly?: boolean): string;
124
+ /**
125
+ * Validates the merkle root and witness commitment (if present).
126
+ * @returns True if the transaction roots are valid
127
+ */
25
128
  checkTxRoots(): boolean;
129
+ /**
130
+ * Validates that the block hash meets the target threshold (proof of work).
131
+ * @returns True if the block's proof of work is valid
132
+ */
26
133
  checkProofOfWork(): boolean;
27
- private __checkMerkleRoot;
28
- private __checkWitnessCommit;
29
134
  }
135
+ //# sourceMappingURL=block.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../src/block.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAO1C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,KAAK;;IACd,2BAA2B;IAC3B,OAAO,EAAE,MAAM,CAAK;IACpB,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,OAAO,CAAa;IAC/B,iDAAiD;IACjD,UAAU,CAAC,EAAE,OAAO,CAAa;IACjC,kCAAkC;IAClC,SAAS,EAAE,MAAM,CAAK;IACtB,sDAAsD;IACtD,aAAa,CAAC,EAAE,OAAO,CAAa;IACpC,qDAAqD;IACrD,IAAI,EAAE,MAAM,CAAK;IACjB,mCAAmC;IACnC,KAAK,EAAE,MAAM,CAAK;IAClB,kDAAkD;IAClD,YAAY,CAAC,EAAE,WAAW,EAAE,CAAa;IAEzC;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,KAAK;IAoC5C;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK;IAIlC;;;;OAIG;IACH,MAAM,CAAC,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAY7C;;;;;;OAMG;IACH,MAAM,CAAC,mBAAmB,CAAC,YAAY,EAAE,WAAW,EAAE,EAAE,UAAU,CAAC,EAAE,OAAO,GAAG,OAAO;IAqBtF;;;OAGG;IACH,gBAAgB,IAAI,OAAO,GAAG,IAAI;IAkBlC;;;OAGG;IACH,gBAAgB,IAAI,OAAO;IAO3B;;;OAGG;IACH,UAAU,IAAI,OAAO;IAIrB;;;;OAIG;IACH,MAAM,IAAI,MAAM;IAMhB;;;;;OAKG;IACH,UAAU,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,YAAY,GAAE,OAAc,GAAG,MAAM;IAUvE;;;OAGG;IACH,OAAO,IAAI,OAAO;IAIlB;;;OAGG;IACH,KAAK,IAAI,MAAM;IAIf;;;OAGG;IACH,UAAU,IAAI,IAAI;IAOlB;;;;OAIG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,GAAG,UAAU;IA4B3C;;;;OAIG;IACH,KAAK,CAAC,WAAW,CAAC,EAAE,OAAO,GAAG,MAAM;IAIpC;;;OAGG;IACH,YAAY,IAAI,OAAO;IAQvB;;;OAGG;IACH,gBAAgB,IAAI,OAAO;CAuB9B"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Branded type definitions for type-safe primitives.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ declare const __brand: unique symbol;
7
+ type Brand<T, B extends string> = T & {
8
+ readonly [__brand]: B;
9
+ };
10
+ export type Bytes32 = Brand<Uint8Array, 'Bytes32'>;
11
+ export type Bytes20 = Brand<Uint8Array, 'Bytes20'>;
12
+ export type PublicKey = Brand<Uint8Array, 'PublicKey'>;
13
+ export type XOnlyPublicKey = Brand<Uint8Array, 'XOnlyPublicKey'>;
14
+ export type Satoshi = Brand<bigint, 'Satoshi'>;
15
+ export type PrivateKey = Brand<Uint8Array, 'PrivateKey'>;
16
+ export type Signature = Brand<Uint8Array, 'Signature'>;
17
+ export type SchnorrSignature = Brand<Uint8Array, 'SchnorrSignature'>;
18
+ export type Script = Brand<Uint8Array, 'Script'>;
19
+ export {};
20
+ //# sourceMappingURL=branded.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"branded.d.ts","sourceRoot":"","sources":["../src/branded.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,CAAC,MAAM,OAAO,EAAE,OAAO,MAAM,CAAC;AACrC,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,IAAI,CAAC,GAAG;IAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;CAAE,CAAC;AAEhE,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AACnD,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AACnD,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;AACvD,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC;AACjE,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAC/C,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;AACzD,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;AACvD,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;AACrE,MAAM,MAAM,MAAM,GAAG,KAAK,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC"}
@@ -1 +1,2 @@
1
1
  export { createHash, createHmac, pbkdf2Sync, randomBytes } from './crypto-browser.js';
2
+ //# sourceMappingURL=crypto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../src/crypto/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC"}