@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,365 @@
1
+ /**
2
+ * Worker thread types for parallel signing operations.
3
+ *
4
+ * SECURITY NOTES:
5
+ * - Private keys are NEVER shared via SharedArrayBuffer
6
+ * - Keys are cloned via postMessage (isolated per worker)
7
+ * - Keys are zeroed immediately after signing
8
+ * - Workers are pooled for performance but keys don't persist
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+ /**
13
+ * Signature type enum for worker operations.
14
+ */
15
+ export declare const SignatureType: {
16
+ /** ECDSA signature (secp256k1) */
17
+ readonly ECDSA: 0;
18
+ /** Schnorr signature (BIP340) */
19
+ readonly Schnorr: 1;
20
+ };
21
+ export type SignatureType = (typeof SignatureType)[keyof typeof SignatureType];
22
+ /**
23
+ * Message sent to worker for signing operation.
24
+ *
25
+ * SECURITY: privateKey is cloned via postMessage, NOT shared.
26
+ * Worker MUST zero the key after signing.
27
+ */
28
+ export interface SigningTaskMessage {
29
+ /** Message type discriminator */
30
+ readonly type: 'sign';
31
+ /** Task identifier for correlation */
32
+ readonly taskId: string;
33
+ /** Hash to sign (32 bytes) */
34
+ readonly hash: Uint8Array;
35
+ /** Private key (32 bytes) - WILL BE ZEROED after use */
36
+ readonly privateKey: Uint8Array;
37
+ /** Public key for verification (33 or 65 bytes) */
38
+ readonly publicKey: Uint8Array;
39
+ /** Signature type (ECDSA or Schnorr) */
40
+ readonly signatureType: SignatureType;
41
+ /** Low R signing for ECDSA (optional) */
42
+ readonly lowR?: boolean | undefined;
43
+ /** Input index this signature is for */
44
+ readonly inputIndex: number;
45
+ /** Sighash type for encoding */
46
+ readonly sighashType: number;
47
+ /** Leaf hash for Taproot script-path (optional) */
48
+ readonly leafHash?: Uint8Array | undefined;
49
+ }
50
+ /**
51
+ * Initialization message for worker with ECC library.
52
+ */
53
+ export interface WorkerInitMessage {
54
+ /** Message type discriminator */
55
+ readonly type: 'init';
56
+ /** Serialized ECC library functions (or library identifier) */
57
+ readonly eccLibId: string;
58
+ }
59
+ /**
60
+ * Shutdown message for worker.
61
+ */
62
+ export interface WorkerShutdownMessage {
63
+ /** Message type discriminator */
64
+ readonly type: 'shutdown';
65
+ }
66
+ /**
67
+ * Individual task in a batch (without privateKey - shared across batch).
68
+ */
69
+ export interface BatchSigningTask {
70
+ /** Task identifier */
71
+ readonly taskId: string;
72
+ /** Hash to sign (32 bytes) */
73
+ readonly hash: Uint8Array;
74
+ /** Public key for verification */
75
+ readonly publicKey: Uint8Array;
76
+ /** Signature type */
77
+ readonly signatureType: SignatureType;
78
+ /** Low R for ECDSA */
79
+ readonly lowR?: boolean | undefined;
80
+ /** Input index */
81
+ readonly inputIndex: number;
82
+ /** Sighash type */
83
+ readonly sighashType: number;
84
+ /** Leaf hash for Taproot */
85
+ readonly leafHash?: Uint8Array | undefined;
86
+ }
87
+ /**
88
+ * Batch signing message - multiple tasks with single private key.
89
+ * More efficient than sending tasks one at a time.
90
+ */
91
+ export interface BatchSigningMessage {
92
+ /** Message type discriminator */
93
+ readonly type: 'signBatch';
94
+ /** Batch identifier for correlation */
95
+ readonly batchId: string;
96
+ /** Tasks to sign */
97
+ readonly tasks: readonly BatchSigningTask[];
98
+ /** Private key (32 bytes) - WILL BE ZEROED after all tasks */
99
+ readonly privateKey: Uint8Array;
100
+ }
101
+ /**
102
+ * Individual result from a batch.
103
+ */
104
+ export interface BatchSigningTaskResult {
105
+ /** Task identifier */
106
+ readonly taskId: string;
107
+ /** Signature bytes */
108
+ readonly signature: Uint8Array;
109
+ /** Input index */
110
+ readonly inputIndex: number;
111
+ /** Public key used */
112
+ readonly publicKey: Uint8Array;
113
+ /** Signature type */
114
+ readonly signatureType: SignatureType;
115
+ /** Leaf hash (if applicable) */
116
+ readonly leafHash?: Uint8Array | undefined;
117
+ }
118
+ /**
119
+ * Individual error from a batch.
120
+ */
121
+ export interface BatchSigningTaskError {
122
+ /** Task identifier */
123
+ readonly taskId: string;
124
+ /** Input index */
125
+ readonly inputIndex: number;
126
+ /** Error message */
127
+ readonly error: string;
128
+ }
129
+ /**
130
+ * Batch result message from worker.
131
+ */
132
+ export interface BatchSigningResultMessage {
133
+ /** Message type discriminator */
134
+ readonly type: 'batchResult';
135
+ /** Batch identifier for correlation */
136
+ readonly batchId: string;
137
+ /** Successful results */
138
+ readonly results: readonly BatchSigningTaskResult[];
139
+ /** Errors */
140
+ readonly errors: readonly BatchSigningTaskError[];
141
+ }
142
+ /**
143
+ * All possible messages to worker.
144
+ */
145
+ export type WorkerMessage = SigningTaskMessage | BatchSigningMessage | WorkerInitMessage | WorkerShutdownMessage;
146
+ /**
147
+ * Result from worker after signing.
148
+ */
149
+ export interface SigningResultMessage {
150
+ /** Message type discriminator */
151
+ readonly type: 'result';
152
+ /** Task identifier for correlation */
153
+ readonly taskId: string;
154
+ /** Signature bytes (64 bytes raw for Schnorr, or with sighash for ECDSA) */
155
+ readonly signature: Uint8Array;
156
+ /** Input index this signature is for */
157
+ readonly inputIndex: number;
158
+ /** Public key used for signing */
159
+ readonly publicKey: Uint8Array;
160
+ /** Signature type that was used */
161
+ readonly signatureType: SignatureType;
162
+ /** Leaf hash for Taproot script-path spending (if applicable) */
163
+ readonly leafHash?: Uint8Array | undefined;
164
+ }
165
+ /**
166
+ * Error result from worker.
167
+ */
168
+ export interface SigningErrorMessage {
169
+ /** Message type discriminator */
170
+ readonly type: 'error';
171
+ /** Task identifier for correlation */
172
+ readonly taskId: string;
173
+ /** Error message */
174
+ readonly error: string;
175
+ /** Input index that failed */
176
+ readonly inputIndex: number;
177
+ }
178
+ /**
179
+ * Worker ready message.
180
+ */
181
+ export interface WorkerReadyMessage {
182
+ /** Message type discriminator */
183
+ readonly type: 'ready';
184
+ }
185
+ /**
186
+ * Worker shutdown acknowledgment.
187
+ */
188
+ export interface WorkerShutdownAckMessage {
189
+ /** Message type discriminator */
190
+ readonly type: 'shutdown-ack';
191
+ }
192
+ /**
193
+ * Union of all worker response types.
194
+ */
195
+ export type WorkerResponse = SigningResultMessage | SigningErrorMessage | BatchSigningResultMessage | WorkerReadyMessage | WorkerShutdownAckMessage;
196
+ /**
197
+ * Type guard for error responses.
198
+ */
199
+ export declare function isSigningError(response: WorkerResponse): response is SigningErrorMessage;
200
+ /**
201
+ * Type guard for success responses.
202
+ */
203
+ export declare function isSigningResult(response: WorkerResponse): response is SigningResultMessage;
204
+ /**
205
+ * Type guard for batch result responses.
206
+ */
207
+ export declare function isBatchResult(response: WorkerResponse): response is BatchSigningResultMessage;
208
+ /**
209
+ * Type guard for ready responses.
210
+ */
211
+ export declare function isWorkerReady(response: WorkerResponse): response is WorkerReadyMessage;
212
+ /**
213
+ * Interface for the ECC library used by workers.
214
+ * Provides signing functions for ECDSA and Schnorr signatures.
215
+ */
216
+ export interface WorkerEccLib {
217
+ /**
218
+ * Create an ECDSA signature.
219
+ *
220
+ * @param hash - 32-byte hash to sign
221
+ * @param privateKey - 32-byte private key
222
+ * @param lowR - Optional: grind for low R value
223
+ * @returns 64-byte raw signature (r || s)
224
+ */
225
+ sign(hash: Uint8Array, privateKey: Uint8Array, lowR?: boolean): Uint8Array;
226
+ /**
227
+ * Create a Schnorr signature (BIP340).
228
+ *
229
+ * @param hash - 32-byte hash to sign
230
+ * @param privateKey - 32-byte private key
231
+ * @returns 64-byte Schnorr signature
232
+ */
233
+ signSchnorr(hash: Uint8Array, privateKey: Uint8Array): Uint8Array;
234
+ }
235
+ /**
236
+ * Configuration for the worker signing pool.
237
+ */
238
+ export interface WorkerPoolConfig {
239
+ /**
240
+ * Number of workers to create.
241
+ * Default: number of CPU cores (navigator.hardwareConcurrency or os.cpus().length)
242
+ */
243
+ readonly workerCount?: number;
244
+ /**
245
+ * Timeout per signing operation in milliseconds.
246
+ * Worker is terminated if exceeded (key safety measure).
247
+ * Default: 30000 (30 seconds)
248
+ */
249
+ readonly taskTimeoutMs?: number;
250
+ /**
251
+ * Maximum time a worker can hold a private key in milliseconds.
252
+ * Acts as a safety net - worker is terminated if signing takes too long.
253
+ * Default: 5000 (5 seconds)
254
+ */
255
+ readonly maxKeyHoldTimeMs?: number;
256
+ /**
257
+ * Whether to verify signatures after signing.
258
+ * Adds overhead but ensures correctness.
259
+ * Default: true
260
+ */
261
+ readonly verifySignatures?: boolean;
262
+ /**
263
+ * Whether to preserve workers between signing batches.
264
+ * true = workers stay alive (faster for multiple batches)
265
+ * false = workers terminated after each batch (more secure)
266
+ * Default: true (use preserveWorkers() to enable)
267
+ */
268
+ readonly preserveWorkers?: boolean;
269
+ }
270
+ /**
271
+ * Signing task for the worker queue.
272
+ */
273
+ export interface SigningTask {
274
+ /** Task identifier */
275
+ readonly taskId: string;
276
+ /** Input index */
277
+ readonly inputIndex: number;
278
+ /** Hash to sign (32 bytes) */
279
+ readonly hash: Uint8Array;
280
+ /** Signature type */
281
+ readonly signatureType: SignatureType;
282
+ /** Low R for ECDSA */
283
+ readonly lowR?: boolean | undefined;
284
+ /** Sighash type */
285
+ readonly sighashType: number;
286
+ /** Leaf hash for Taproot script-path */
287
+ readonly leafHash?: Uint8Array | undefined;
288
+ }
289
+ /**
290
+ * Signer key pair interface for parallel signing.
291
+ *
292
+ * SECURITY: getPrivateKey() is only called when dispatching to worker.
293
+ * The returned bytes are cloned to the worker and then the original
294
+ * should be considered potentially compromised (in main thread memory).
295
+ *
296
+ * For maximum security, use a hardware wallet that never exposes keys.
297
+ */
298
+ export interface ParallelSignerKeyPair {
299
+ /** Public key (compressed 33 bytes or uncompressed 65 bytes) */
300
+ readonly publicKey: Uint8Array;
301
+ /**
302
+ * Get private key bytes (32 bytes).
303
+ *
304
+ * SECURITY WARNING: This exposes the raw private key.
305
+ * - Called only when dispatching to worker
306
+ * - Key is cloned to worker via postMessage
307
+ * - Original in main thread should be zeroed by caller if possible
308
+ *
309
+ * For high-security applications, use hardware wallets instead.
310
+ */
311
+ getPrivateKey(): Uint8Array;
312
+ /**
313
+ * Optional: Sign ECDSA directly (fallback if workers unavailable).
314
+ */
315
+ sign?(hash: Uint8Array, lowR?: boolean): Uint8Array;
316
+ /**
317
+ * Optional: Sign Schnorr directly (fallback if workers unavailable).
318
+ */
319
+ signSchnorr?(hash: Uint8Array): Uint8Array;
320
+ }
321
+ /**
322
+ * Result of a parallel signing batch.
323
+ */
324
+ export interface ParallelSigningResult {
325
+ /** Whether all signatures were created successfully */
326
+ readonly success: boolean;
327
+ /** Signatures indexed by input index */
328
+ readonly signatures: ReadonlyMap<number, SigningResultMessage>;
329
+ /** Errors indexed by input index */
330
+ readonly errors: ReadonlyMap<number, string>;
331
+ /** Total time taken in milliseconds */
332
+ readonly durationMs: number;
333
+ }
334
+ /**
335
+ * Worker state for pool management.
336
+ */
337
+ export declare const WorkerState: {
338
+ /** Worker is initializing */
339
+ readonly Initializing: 0;
340
+ /** Worker is ready and idle */
341
+ readonly Idle: 1;
342
+ /** Worker is processing a task */
343
+ readonly Busy: 2;
344
+ /** Worker is shutting down */
345
+ readonly ShuttingDown: 3;
346
+ /** Worker has terminated */
347
+ readonly Terminated: 4;
348
+ };
349
+ export type WorkerState = (typeof WorkerState)[keyof typeof WorkerState];
350
+ /**
351
+ * Internal worker wrapper for pool management.
352
+ */
353
+ export interface PooledWorker {
354
+ /** Unique worker identifier */
355
+ readonly id: number;
356
+ /** Current worker state */
357
+ state: WorkerState;
358
+ /** The actual worker instance */
359
+ readonly worker: Worker;
360
+ /** Current task ID (if busy) */
361
+ currentTaskId: string | null;
362
+ /** Timestamp when current task started */
363
+ taskStartTime: number | null;
364
+ }
365
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/workers/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;GAEG;AACH,eAAO,MAAM,aAAa;IACtB,kCAAkC;;IAElC,iCAAiC;;CAE3B,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC;AAE/E;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IAC/B,iCAAiC;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,sCAAsC;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,8BAA8B;IAC9B,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,wDAAwD;IACxD,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,mDAAmD;IACnD,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;IAC/B,wCAAwC;IACxC,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,yCAAyC;IACzC,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACpC,wCAAwC;IACxC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,gCAAgC;IAChC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,mDAAmD;IACnD,QAAQ,CAAC,QAAQ,CAA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AC,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,UAAU,CAAC;IAEpD;;OAEG;IACH,WAAW,CAAC,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAAC;CAC9C;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IAClC,uDAAuD;IACvD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,wCAAwC;IACxC,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;IAC/D,oCAAoC;IACpC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7C,uCAAuC;IACvC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC/B;AAED;;GAEG;AACH,eAAO,MAAM,WAAW;IACpB,6BAA6B;;IAE7B,+BAA+B;;IAE/B,kCAAkC;;IAElC,8BAA8B;;IAE9B,4BAA4B;;CAEtB,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;AAEzE;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,+BAA+B;IAC/B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,2BAA2B;IAC3B,KAAK,EAAE,WAAW,CAAC;IACnB,iCAAiC;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,gCAAgC;IAChC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,0CAA0C;IAC1C,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Worker thread types for parallel signing operations.
3
+ *
4
+ * SECURITY NOTES:
5
+ * - Private keys are NEVER shared via SharedArrayBuffer
6
+ * - Keys are cloned via postMessage (isolated per worker)
7
+ * - Keys are zeroed immediately after signing
8
+ * - Workers are pooled for performance but keys don't persist
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+ /**
13
+ * Signature type enum for worker operations.
14
+ */
15
+ export const SignatureType = {
16
+ /** ECDSA signature (secp256k1) */
17
+ ECDSA: 0,
18
+ /** Schnorr signature (BIP340) */
19
+ Schnorr: 1,
20
+ };
21
+ /**
22
+ * Type guard for error responses.
23
+ */
24
+ export function isSigningError(response) {
25
+ return response.type === 'error';
26
+ }
27
+ /**
28
+ * Type guard for success responses.
29
+ */
30
+ export function isSigningResult(response) {
31
+ return response.type === 'result';
32
+ }
33
+ /**
34
+ * Type guard for batch result responses.
35
+ */
36
+ export function isBatchResult(response) {
37
+ return response.type === 'batchResult';
38
+ }
39
+ /**
40
+ * Type guard for ready responses.
41
+ */
42
+ export function isWorkerReady(response) {
43
+ return response.type === 'ready';
44
+ }
45
+ /**
46
+ * Worker state for pool management.
47
+ */
48
+ export const WorkerState = {
49
+ /** Worker is initializing */
50
+ Initializing: 0,
51
+ /** Worker is ready and idle */
52
+ Idle: 1,
53
+ /** Worker is processing a task */
54
+ Busy: 2,
55
+ /** Worker is shutting down */
56
+ ShuttingDown: 3,
57
+ /** Worker has terminated */
58
+ Terminated: 4,
59
+ };
60
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/workers/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;IACzB,kCAAkC;IAClC,KAAK,EAAE,CAAC;IACR,iCAAiC;IACjC,OAAO,EAAE,CAAC;CACJ,CAAC;AAqMX;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,QAAwB;IACnD,OAAO,QAAQ,CAAC,IAAI,KAAK,OAAO,CAAC;AACrC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,QAAwB;IACpD,OAAO,QAAQ,CAAC,IAAI,KAAK,QAAQ,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,QAAwB;IAClD,OAAO,QAAQ,CAAC,IAAI,KAAK,aAAa,CAAC;AAC3C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,QAAwB;IAClD,OAAO,QAAQ,CAAC,IAAI,KAAK,OAAO,CAAC;AACrC,CAAC;AAyID;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACvB,6BAA6B;IAC7B,YAAY,EAAE,CAAC;IACf,+BAA+B;IAC/B,IAAI,EAAE,CAAC;IACP,kCAAkC;IAClC,IAAI,EAAE,CAAC;IACP,8BAA8B;IAC9B,YAAY,EAAE,CAAC;IACf,4BAA4B;IAC5B,UAAU,EAAE,CAAC;CACP,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,13 @@
1
1
  {
2
2
  "name": "@btc-vision/bitcoin",
3
3
  "type": "module",
4
- "version": "6.5.6",
4
+ "version": "7.0.0-alpha.0",
5
+ "sideEffects": false,
6
+ "overrides": {
7
+ "ecpair": {
8
+ "valibot": "^1.2.0"
9
+ }
10
+ },
5
11
  "description": "Client-side Bitcoin JavaScript library",
6
12
  "engines": {
7
13
  "node": ">=24.0.0"
@@ -26,6 +32,58 @@
26
32
  "types": "./browser/index.d.ts",
27
33
  "import": "./browser/index.js",
28
34
  "default": "./browser/index.js"
35
+ },
36
+ "./address": {
37
+ "types": "./build/address.d.ts",
38
+ "import": "./build/address.js"
39
+ },
40
+ "./script": {
41
+ "types": "./build/script.d.ts",
42
+ "import": "./build/script.js"
43
+ },
44
+ "./crypto": {
45
+ "types": "./build/crypto.d.ts",
46
+ "import": "./build/crypto.js"
47
+ },
48
+ "./transaction": {
49
+ "types": "./build/transaction.d.ts",
50
+ "import": "./build/transaction.js"
51
+ },
52
+ "./block": {
53
+ "types": "./build/block.d.ts",
54
+ "import": "./build/block.js"
55
+ },
56
+ "./psbt": {
57
+ "types": "./build/psbt.d.ts",
58
+ "import": "./build/psbt.js"
59
+ },
60
+ "./networks": {
61
+ "types": "./build/networks.d.ts",
62
+ "import": "./build/networks.js"
63
+ },
64
+ "./payments": {
65
+ "types": "./build/payments/index.d.ts",
66
+ "import": "./build/payments/index.js"
67
+ },
68
+ "./payments/*": {
69
+ "types": "./build/payments/*.d.ts",
70
+ "import": "./build/payments/*.js"
71
+ },
72
+ "./io": {
73
+ "types": "./build/io/index.d.ts",
74
+ "import": "./build/io/index.js"
75
+ },
76
+ "./ecc": {
77
+ "types": "./build/ecc/index.d.ts",
78
+ "import": "./build/ecc/index.js"
79
+ },
80
+ "./types": {
81
+ "types": "./build/types.d.ts",
82
+ "import": "./build/types.js"
83
+ },
84
+ "./errors": {
85
+ "types": "./build/errors.d.ts",
86
+ "import": "./build/errors.js"
29
87
  }
30
88
  },
31
89
  "browser": {
@@ -58,15 +116,13 @@
58
116
  },
59
117
  "scripts": {
60
118
  "watch": "tsc --watch",
61
- "build": "eslint src && tsc",
119
+ "build": "eslint src && tsc --build tsconfig.build.json",
62
120
  "setup": "npm i && npm run build",
63
121
  "browserBuild": "vite build --config vite.config.browser.ts",
64
122
  "audit": "better-npm-audit audit -l high",
65
123
  "clean": "rimraf build",
66
124
  "coverage": "vitest run --coverage",
67
125
  "doc": "typedoc",
68
- "format": "npm run prettier -- --write",
69
- "formatjs": "npm run prettier -- --write",
70
126
  "format:ci": "npm run prettier -- --check && npm run prettier -- --check",
71
127
  "gitdiff:ci": "npm run build && git diff --exit-code",
72
128
  "integration": "vitest run --config vitest.config.integration.ts",
@@ -76,8 +132,11 @@
76
132
  "test": "npm run build && npm run lint && vitest run",
77
133
  "test:watch": "vitest",
78
134
  "unit": "vitest run",
135
+ "bench": "vitest bench benchmark/",
136
+ "bench:run": "npx tsx benchmark/signing.bench.ts",
79
137
  "check:circular": "madge --circular --extensions ts,tsx src/",
80
- "prebuild": "npm run check:circular"
138
+ "prebuild:ecc": "npx tsx scripts/bundle-ecc.ts",
139
+ "prebuild": "npm run prebuild:ecc && npm run check:circular"
81
140
  },
82
141
  "devDependencies": {
83
142
  "@eslint/js": "^9.39.2",
@@ -91,7 +150,7 @@
91
150
  "bip68": "^1.0.4",
92
151
  "bs58": "^6.0.0",
93
152
  "dhttp": "^3.0.3",
94
- "ecpair": "^2.1.0",
153
+ "ecpair": "^3.0.0",
95
154
  "eslint": "^9.39.2",
96
155
  "https-browserify": "^1.0.0",
97
156
  "madge": "^8.0.0",
@@ -120,12 +179,11 @@
120
179
  "@noble/secp256k1": "^3.0.0",
121
180
  "assert": "^2.1.0",
122
181
  "bech32": "^2.0.0",
123
- "bip174": "^2.1.1",
182
+ "bip174": "^3.0.0",
124
183
  "browserify-zlib": "^0.2.0",
125
184
  "bs58check": "^4.0.0",
126
185
  "buffer": "^6.0.3",
127
186
  "process": "^0.11.10",
128
- "typeforce": "^1.18.0",
129
187
  "varuint-bitcoin": "^2.0.0"
130
188
  }
131
189
  }
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Build script to bundle @noble/secp256k1 + hashes for embedding in workers.
3
+ *
4
+ * This creates a self-contained IIFE that can be executed in a worker
5
+ * without any network requests or module system dependencies.
6
+ *
7
+ * Usage: npx tsx scripts/bundle-ecc.ts
8
+ */
9
+
10
+ import { build } from 'esbuild';
11
+ import { writeFileSync, mkdirSync } from 'fs';
12
+ import { dirname, resolve } from 'path';
13
+ import { fileURLToPath } from 'url';
14
+
15
+ const __dirname = dirname(fileURLToPath(import.meta.url));
16
+ const projectRoot = resolve(__dirname, '..');
17
+
18
+ async function bundleEcc(): Promise<void> {
19
+ console.log('Bundling @noble/secp256k1 + hashes for worker embedding...');
20
+
21
+ // Create a wrapper that exports everything we need
22
+ const entryCode = `
23
+ import * as secp from '@noble/secp256k1';
24
+ import { sha256 } from '@noble/hashes/sha2.js';
25
+ import { hmac } from '@noble/hashes/hmac.js';
26
+
27
+ // Configure hashes for sync operations
28
+ secp.hashes.sha256 = sha256;
29
+ secp.hashes.hmacSha256 = (key, ...msgs) => {
30
+ const merged = new Uint8Array(msgs.reduce((acc, m) => acc + m.length, 0));
31
+ let offset = 0;
32
+ for (const m of msgs) {
33
+ merged.set(m, offset);
34
+ offset += m.length;
35
+ }
36
+ return hmac(sha256, key, merged);
37
+ };
38
+
39
+ export { secp, sha256, hmac };
40
+ `;
41
+
42
+ // Write temp entry file
43
+ const tempEntry = resolve(projectRoot, 'scripts/.temp-ecc-entry.js');
44
+ writeFileSync(tempEntry, entryCode);
45
+
46
+ // Bundle everything as IIFE
47
+ const result = await build({
48
+ entryPoints: [tempEntry],
49
+ bundle: true,
50
+ format: 'iife',
51
+ globalName: 'nobleBundle',
52
+ platform: 'browser',
53
+ target: 'es2020',
54
+ minify: true,
55
+ write: false,
56
+ });
57
+
58
+ // Clean up temp file
59
+ const { unlinkSync } = await import('fs');
60
+ unlinkSync(tempEntry);
61
+
62
+ if (result.outputFiles.length === 0) {
63
+ throw new Error('esbuild produced no output');
64
+ }
65
+
66
+ const bundledCode = result.outputFiles[0].text;
67
+
68
+ // Generate TypeScript file with the bundled code as a constant
69
+ const outputContent = `/**
70
+ * Bundled @noble/secp256k1 + hashes for worker embedding.
71
+ *
72
+ * AUTO-GENERATED FILE - DO NOT EDIT
73
+ * Generated by: scripts/bundle-ecc.ts
74
+ *
75
+ * This embeds the entire @noble/secp256k1 library with sha256/hmac
76
+ * as an IIFE string that can be executed in a Web Worker without network requests.
77
+ *
78
+ * @packageDocumentation
79
+ */
80
+
81
+ /**
82
+ * Bundled @noble/secp256k1 + hashes library as an IIFE string.
83
+ *
84
+ * When executed, this creates a global \`nobleBundle\` object with:
85
+ * - secp: The full @noble/secp256k1 module (with hashes configured)
86
+ * - sha256: The sha256 hash function
87
+ * - hmac: The hmac function
88
+ */
89
+ export const ECC_BUNDLE = ${JSON.stringify(bundledCode)};
90
+
91
+ /**
92
+ * Size of the bundled code in bytes.
93
+ */
94
+ export const ECC_BUNDLE_SIZE = ${bundledCode.length};
95
+ `;
96
+
97
+ // Ensure output directory exists
98
+ const outputPath = resolve(projectRoot, 'src/workers/ecc-bundle.ts');
99
+ mkdirSync(dirname(outputPath), { recursive: true });
100
+
101
+ // Write the output file
102
+ writeFileSync(outputPath, outputContent, 'utf-8');
103
+
104
+ console.log('Bundle created: ' + outputPath);
105
+ console.log('Bundle size: ' + (bundledCode.length / 1024).toFixed(2) + ' KB');
106
+ }
107
+
108
+ bundleEcc().catch((error) => {
109
+ console.error('Failed to bundle ECC library:', error);
110
+ process.exit(1);
111
+ });