@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,91 @@
1
+ /**
2
+ * Worker-based parallel signing module.
3
+ *
4
+ * Provides secure parallel signature computation using worker threads.
5
+ * Works in both Node.js (worker_threads) and browsers (Web Workers).
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { WorkerSigningPool, SignatureType } from '@btc-vision/bitcoin/workers';
10
+ *
11
+ * // Get singleton pool
12
+ * const pool = WorkerSigningPool.getInstance({ workerCount: 4 });
13
+ *
14
+ * // Keep workers alive for multiple signing operations
15
+ * pool.preserveWorkers();
16
+ *
17
+ * // Prepare signing tasks (one per input)
18
+ * const tasks = [
19
+ * {
20
+ * taskId: 'input-0',
21
+ * inputIndex: 0,
22
+ * hash: hash0,
23
+ * signatureType: SignatureType.ECDSA,
24
+ * sighashType: 0x01,
25
+ * },
26
+ * {
27
+ * taskId: 'input-1',
28
+ * inputIndex: 1,
29
+ * hash: hash1,
30
+ * signatureType: SignatureType.Schnorr,
31
+ * sighashType: 0x00,
32
+ * },
33
+ * ];
34
+ *
35
+ * // Sign ALL inputs in parallel
36
+ * const result = await pool.signBatch(tasks, keyPair);
37
+ *
38
+ * if (result.success) {
39
+ * console.log(`Signed ${result.signatures.size} inputs in ${result.durationMs}ms`);
40
+ * }
41
+ *
42
+ * // Cleanup when done (optional)
43
+ * await pool.shutdown();
44
+ * ```
45
+ *
46
+ * @packageDocumentation
47
+ */
48
+ export { SignatureType, type SigningTaskMessage, type BatchSigningMessage, type BatchSigningTask, type BatchSigningResultMessage, type BatchSigningTaskResult, type BatchSigningTaskError, type WorkerInitMessage, type WorkerShutdownMessage, type WorkerMessage, type SigningResultMessage, type SigningErrorMessage, type WorkerReadyMessage, type WorkerShutdownAckMessage, type WorkerResponse, isSigningError, isSigningResult, isBatchResult, isWorkerReady, type WorkerEccLib, type WorkerPoolConfig, type SigningTask, type ParallelSignerKeyPair, type ParallelSigningResult, WorkerState, type PooledWorker, } from './types.js';
49
+ export { WorkerSigningPool, getSigningPool } from './WorkerSigningPool.js';
50
+ export { generateWorkerCode, createWorkerBlobUrl, revokeWorkerBlobUrl } from './signing-worker.js';
51
+ export { ECC_BUNDLE, ECC_BUNDLE_SIZE } from './ecc-bundle.js';
52
+ export { type NodeWorkerPoolConfig } from './WorkerSigningPool.node.js';
53
+ export { signPsbtParallel, prepareSigningTasks, applySignaturesToPsbt, type ParallelSignOptions, type PsbtParallelKeyPair, } from './psbt-parallel.js';
54
+ /**
55
+ * Detects the runtime environment and returns the appropriate signing pool.
56
+ *
57
+ * @returns 'node' for Node.js, 'browser' for browsers, 'unknown' otherwise
58
+ */
59
+ export declare function detectRuntime(): 'node' | 'browser' | 'unknown';
60
+ /**
61
+ * Creates a signing pool appropriate for the current runtime.
62
+ *
63
+ * In Node.js, uses worker_threads.
64
+ * In browsers, uses Web Workers.
65
+ *
66
+ * @param config - Optional pool configuration
67
+ * @returns A promise resolving to the initialized signing pool
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * import { createSigningPool } from '@btc-vision/bitcoin/workers';
72
+ *
73
+ * const pool = await createSigningPool({ workerCount: 4 });
74
+ * pool.preserveWorkers();
75
+ *
76
+ * // Use pool...
77
+ *
78
+ * await pool.shutdown();
79
+ * ```
80
+ */
81
+ export declare function createSigningPool(config?: import('./types.js').WorkerPoolConfig): Promise<{
82
+ signBatch: (tasks: readonly import('./types.js').SigningTask[], keyPair: import('./types.js').ParallelSignerKeyPair) => Promise<import('./types.js').ParallelSigningResult>;
83
+ preserveWorkers: () => void;
84
+ releaseWorkers: () => void;
85
+ shutdown: () => Promise<void>;
86
+ workerCount: number;
87
+ idleWorkerCount: number;
88
+ busyWorkerCount: number;
89
+ isPreservingWorkers: boolean;
90
+ }>;
91
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/workers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAGH,OAAO,EACH,aAAa,EACb,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,yBAAyB,EAC9B,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,cAAc,EACnB,cAAc,EACd,eAAe,EACf,aAAa,EACb,aAAa,EACb,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,WAAW,EACX,KAAK,YAAY,GACpB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAG3E,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAGnG,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAG9D,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAGxE,OAAO,EACH,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,GAC3B,MAAM,oBAAoB,CAAC;AAE5B;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,MAAM,GAAG,SAAS,GAAG,SAAS,CAQ9D;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,iBAAiB,CAAC,MAAM,CAAC,EAAE,OAAO,YAAY,EAAE,gBAAgB,GAAG,OAAO,CAAC;IAC7F,SAAS,EAAE,CACP,KAAK,EAAE,SAAS,OAAO,YAAY,EAAE,WAAW,EAAE,EAClD,OAAO,EAAE,OAAO,YAAY,EAAE,qBAAqB,KAClD,OAAO,CAAC,OAAO,YAAY,EAAE,qBAAqB,CAAC,CAAC;IACzD,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,mBAAmB,EAAE,OAAO,CAAC;CAChC,CAAC,CAiBD"}
@@ -0,0 +1,88 @@
1
+ import { Psbt } from '../psbt.js';
2
+ import { SigningTask, ParallelSignerKeyPair, ParallelSigningResult, WorkerPoolConfig } from './types.js';
3
+ import { WorkerSigningPool } from './WorkerSigningPool.js';
4
+ /**
5
+ * Options for parallel PSBT signing.
6
+ */
7
+ export interface ParallelSignOptions {
8
+ /**
9
+ * Sighash types allowed for signing.
10
+ * Default: [SIGHASH_ALL] for legacy, [SIGHASH_DEFAULT] for Taproot
11
+ */
12
+ readonly sighashTypes?: readonly number[];
13
+ /**
14
+ * Tap leaf hash to sign (for Taproot script-path).
15
+ */
16
+ readonly tapLeafHash?: Uint8Array;
17
+ /**
18
+ * Worker pool configuration (if pool not provided).
19
+ */
20
+ readonly poolConfig?: WorkerPoolConfig;
21
+ /**
22
+ * Whether to use low-R signing for ECDSA.
23
+ * Default: false
24
+ */
25
+ readonly lowR?: boolean;
26
+ }
27
+ /**
28
+ * Key pair interface that extends ParallelSignerKeyPair with PSBT compatibility.
29
+ */
30
+ export interface PsbtParallelKeyPair extends ParallelSignerKeyPair {
31
+ /** Network (optional, for validation) */
32
+ readonly network?: {
33
+ messagePrefix: string;
34
+ };
35
+ }
36
+ /**
37
+ * Signs all PSBT inputs in parallel using worker threads.
38
+ *
39
+ * This is the main entry point for parallel PSBT signing.
40
+ * All inputs that can be signed with the provided key pair
41
+ * will be signed simultaneously.
42
+ *
43
+ * SECURITY: Private keys are isolated per-worker and zeroed after signing.
44
+ *
45
+ * @param psbt - The PSBT to sign
46
+ * @param keyPair - Key pair with getPrivateKey() method
47
+ * @param poolOrConfig - Existing pool instance or configuration for new pool
48
+ * @param options - Signing options
49
+ * @returns Promise resolving to signing result
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * // With existing pool (recommended for multiple operations)
54
+ * const pool = WorkerSigningPool.getInstance();
55
+ * pool.preserveWorkers();
56
+ *
57
+ * const result = await signPsbtParallel(psbt, keyPair, pool);
58
+ *
59
+ * if (result.success) {
60
+ * psbt.finalizeAllInputs();
61
+ * }
62
+ *
63
+ * // With inline pool (creates and destroys pool)
64
+ * const result = await signPsbtParallel(psbt, keyPair, { workerCount: 4 });
65
+ * ```
66
+ */
67
+ export declare function signPsbtParallel(psbt: Psbt, keyPair: PsbtParallelKeyPair, poolOrConfig?: WorkerSigningPool | WorkerPoolConfig, options?: ParallelSignOptions): Promise<ParallelSigningResult>;
68
+ /**
69
+ * Prepares signing tasks from a PSBT.
70
+ *
71
+ * Analyzes each input and creates a signing task for inputs
72
+ * that can be signed with the provided key pair.
73
+ *
74
+ * @param psbt - The PSBT to analyze
75
+ * @param keyPair - Key pair to check against
76
+ * @param options - Signing options
77
+ * @returns Array of signing tasks
78
+ */
79
+ export declare function prepareSigningTasks(psbt: Psbt, keyPair: PsbtParallelKeyPair, options?: ParallelSignOptions): SigningTask[];
80
+ /**
81
+ * Applies parallel signing results to a PSBT.
82
+ *
83
+ * @param psbt - The PSBT to update
84
+ * @param result - Signing results from parallel signing
85
+ * @param keyPair - Key pair used for signing
86
+ */
87
+ export declare function applySignaturesToPsbt(psbt: Psbt, result: ParallelSigningResult, keyPair: PsbtParallelKeyPair): void;
88
+ //# sourceMappingURL=psbt-parallel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"psbt-parallel.d.ts","sourceRoot":"","sources":["../../src/workers/psbt-parallel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAIH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,KAAK,EACR,WAAW,EACX,qBAAqB,EACrB,qBAAqB,EACrB,gBAAgB,EACnB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAK3D;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC;;;OAGG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAE1C;;OAEG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,UAAU,CAAC;IAElC;;OAEG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAEvC;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,qBAAqB;IAC9D,yCAAyC;IACzC,QAAQ,CAAC,OAAO,CAAC,EAAE;QAAE,aAAa,EAAE,MAAM,CAAA;KAAE,CAAC;CAChD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAsB,gBAAgB,CAClC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,mBAAmB,EAC5B,YAAY,CAAC,EAAE,iBAAiB,GAAG,gBAAgB,EACnD,OAAO,GAAE,mBAAwB,GAClC,OAAO,CAAC,qBAAqB,CAAC,CA4ChC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAC/B,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,mBAAmB,EAC5B,OAAO,GAAE,mBAAwB,GAClC,WAAW,EAAE,CA4Bf;AAuED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACjC,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,qBAAqB,EAC7B,OAAO,EAAE,mBAAmB,GAC7B,IAAI,CAyCN"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Inline signing worker code.
3
+ *
4
+ * This module generates the worker code as a string that can be
5
+ * loaded via Blob URL. The worker uses the bundled @noble/secp256k1
6
+ * library embedded at compile time - no network requests required.
7
+ *
8
+ * SECURITY CRITICAL:
9
+ * - Private keys are zeroed immediately after signing
10
+ * - No key data is logged or stored
11
+ * - Worker only holds key during active signing operation
12
+ * - ECC library is bundled at compile time (no CDN dependency)
13
+ *
14
+ * @packageDocumentation
15
+ */
16
+ /**
17
+ * Generates the inline worker code as a string.
18
+ *
19
+ * The worker uses the bundled @noble/secp256k1 library directly,
20
+ * eliminating any network dependencies.
21
+ *
22
+ * @returns Worker code as a string for Blob URL creation
23
+ */
24
+ export declare function generateWorkerCode(): string;
25
+ /**
26
+ * Creates a Blob URL for the worker code.
27
+ *
28
+ * @returns Blob URL that can be used with new Worker()
29
+ */
30
+ export declare function createWorkerBlobUrl(): string;
31
+ /**
32
+ * Revokes a previously created worker Blob URL.
33
+ *
34
+ * @param url - The Blob URL to revoke
35
+ */
36
+ export declare function revokeWorkerBlobUrl(url: string): void;
37
+ //# sourceMappingURL=signing-worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signing-worker.d.ts","sourceRoot":"","sources":["../../src/workers/signing-worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAkT3C;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAI5C;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAErD"}
@@ -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,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;CAC9C;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAC9B,iCAAiC;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,+DAA+D;IAC/D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IAClC,iCAAiC;IACjC,QAAQ,C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