@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
@@ -1,15 +1,45 @@
1
+ import { Bytes32, Satoshi, Script } from './types.js';
2
+ /**
3
+ * Cache for Taproot sighash intermediate values.
4
+ * These are identical for all inputs with SIGHASH_ALL, so compute once and reuse.
5
+ */
6
+ export interface TaprootHashCache {
7
+ readonly hashPrevouts: Bytes32;
8
+ readonly hashAmounts: Bytes32;
9
+ readonly hashScriptPubKeys: Bytes32;
10
+ readonly hashSequences: Bytes32;
11
+ readonly hashOutputs: Bytes32;
12
+ }
1
13
  export interface Output {
2
- script: Buffer;
3
- value: number;
14
+ readonly script: Script;
15
+ readonly value: Satoshi;
4
16
  }
5
17
  export interface Input {
6
- hash: Buffer;
7
- index: number;
8
- script: Buffer;
18
+ readonly hash: Bytes32;
19
+ readonly index: number;
20
+ script: Script;
9
21
  sequence: number;
10
- witness: Buffer[];
22
+ witness: Uint8Array[];
11
23
  }
24
+ /**
25
+ * Represents a Bitcoin transaction.
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * import { Transaction, fromHex } from '@btc-vision/bitcoin';
30
+ *
31
+ * // Parse a transaction from hex
32
+ * const tx = Transaction.fromHex('0100000001...');
33
+ *
34
+ * // Create a new transaction
35
+ * const newTx = new Transaction();
36
+ * newTx.version = 2;
37
+ * newTx.addInput(prevTxHash, 0);
38
+ * newTx.addOutput(scriptPubKey, 50000n);
39
+ * ```
40
+ */
12
41
  export declare class Transaction {
42
+ #private;
13
43
  static readonly DEFAULT_SEQUENCE = 4294967295;
14
44
  static readonly SIGHASH_DEFAULT = 0;
15
45
  static readonly SIGHASH_ALL = 1;
@@ -27,25 +57,137 @@ export declare class Transaction {
27
57
  locktime: number;
28
58
  ins: Input[];
29
59
  outs: Output[];
30
- static fromBuffer(buffer: Buffer, _NO_STRICT?: boolean): Transaction;
60
+ /**
61
+ * Parse a transaction from a Uint8Array buffer.
62
+ *
63
+ * @param buffer - The raw transaction bytes
64
+ * @param _NO_STRICT - If true, allow extra data after transaction
65
+ * @returns Parsed Transaction instance
66
+ */
67
+ static fromBuffer(buffer: Uint8Array, _NO_STRICT?: boolean): Transaction;
68
+ /**
69
+ * Parse a transaction from a hex string.
70
+ *
71
+ * @param hex - The transaction as a hex string
72
+ * @returns Parsed Transaction instance
73
+ */
31
74
  static fromHex(hex: string): Transaction;
32
- static isCoinbaseHash(buffer: Buffer): boolean;
75
+ /**
76
+ * Check if a hash is a coinbase hash (all zeros).
77
+ *
78
+ * @param hash - 32-byte hash to check
79
+ * @returns true if hash is all zeros (coinbase)
80
+ */
81
+ static isCoinbaseHash(hash: Bytes32): boolean;
33
82
  isCoinbase(): boolean;
34
- addInput(hash: Buffer, index: number, sequence?: number, scriptSig?: Buffer): number;
35
- addOutput(scriptPubKey: Buffer, value: number): number;
83
+ /**
84
+ * Add an input to this transaction.
85
+ *
86
+ * @param hash - 32-byte hash of the previous transaction
87
+ * @param index - Output index in the previous transaction
88
+ * @param sequence - Sequence number (defaults to 0xffffffff)
89
+ * @param scriptSig - Input script (defaults to empty)
90
+ * @returns The index of the newly added input
91
+ */
92
+ addInput(hash: Bytes32, index: number, sequence?: number, scriptSig?: Script): number;
93
+ /**
94
+ * Add an output to this transaction.
95
+ *
96
+ * @param scriptPubKey - Output script (locking script)
97
+ * @param value - Output value in satoshis (bigint)
98
+ * @returns The index of the newly added output
99
+ */
100
+ addOutput(scriptPubKey: Script, value: Satoshi): number;
36
101
  hasWitnesses(): boolean;
37
102
  weight(): number;
38
103
  virtualSize(): number;
39
104
  byteLength(_ALLOW_WITNESS?: boolean): number;
40
105
  clone(): Transaction;
41
- hashForSignature(inIndex: number, prevOutScript: Buffer, hashType: number): Buffer;
42
- hashForWitnessV1(inIndex: number, prevOutScripts: Buffer[], values: number[], hashType: number, leafHash?: Buffer, annex?: Buffer): Buffer;
43
- hashForWitnessV0(inIndex: number, prevOutScript: Buffer, value: number, hashType: number): Buffer;
44
- getHash(forWitness?: boolean): Buffer;
106
+ /**
107
+ * Hash transaction for signing a specific input.
108
+ *
109
+ * Bitcoin uses a different hash for each signed transaction input.
110
+ * This method copies the transaction, makes the necessary changes based on the
111
+ * hashType, and then hashes the result.
112
+ * This hash can then be used to sign the provided transaction input.
113
+ *
114
+ * @param inIndex - Index of the input being signed
115
+ * @param prevOutScript - The script of the output being spent
116
+ * @param hashType - Signature hash type
117
+ * @returns 32-byte hash for signing
118
+ */
119
+ hashForSignature(inIndex: number, prevOutScript: Script, hashType: number): Bytes32;
120
+ /**
121
+ * Hash transaction for signing a Taproot (witness v1) input.
122
+ *
123
+ * @param inIndex - Index of the input being signed
124
+ * @param prevOutScripts - Scripts of all inputs being spent
125
+ * @param values - Values of all inputs being spent (bigint satoshis)
126
+ * @param hashType - Signature hash type
127
+ * @param leafHash - Optional leaf hash for script path spending
128
+ * @param annex - Optional annex data
129
+ * @returns 32-byte hash for signing
130
+ */
131
+ hashForWitnessV1(inIndex: number, prevOutScripts: readonly Script[], values: readonly Satoshi[], hashType: number, leafHash?: Bytes32, annex?: Uint8Array, taprootCache?: TaprootHashCache): Bytes32;
132
+ /**
133
+ * Pre-compute intermediate hashes for Taproot signing.
134
+ * Call this once before signing multiple inputs to avoid O(n^2) performance.
135
+ *
136
+ * @param prevOutScripts - Array of previous output scripts for all inputs
137
+ * @param values - Array of previous output values for all inputs
138
+ * @returns Cache object to pass to hashForWitnessV1
139
+ */
140
+ getTaprootHashCache(prevOutScripts: readonly Script[], values: readonly Satoshi[]): TaprootHashCache;
141
+ /**
142
+ * Hash transaction for signing a SegWit v0 (P2WPKH/P2WSH) input.
143
+ *
144
+ * @param inIndex - Index of the input being signed
145
+ * @param prevOutScript - The script of the output being spent
146
+ * @param value - Value of the output being spent (bigint satoshis)
147
+ * @param hashType - Signature hash type
148
+ * @returns 32-byte hash for signing
149
+ */
150
+ hashForWitnessV0(inIndex: number, prevOutScript: Script, value: Satoshi, hashType: number): Bytes32;
151
+ /**
152
+ * Get the transaction hash.
153
+ *
154
+ * @param forWitness - If true, include witness data (wtxid)
155
+ * @returns 32-byte transaction hash
156
+ */
157
+ getHash(forWitness?: boolean): Bytes32;
158
+ /**
159
+ * Get the transaction ID (txid) as a hex string.
160
+ *
161
+ * @returns Transaction ID in reversed hex format
162
+ */
45
163
  getId(): string;
46
- toBuffer(buffer?: Buffer, initialOffset?: number): Buffer;
164
+ /**
165
+ * Serialize the transaction to a Uint8Array buffer.
166
+ *
167
+ * @param buffer - Optional pre-allocated buffer
168
+ * @param initialOffset - Optional starting offset in buffer
169
+ * @returns Serialized transaction bytes
170
+ */
171
+ toBuffer(buffer?: Uint8Array, initialOffset?: number): Uint8Array;
172
+ /**
173
+ * Serialize the transaction to a hex string.
174
+ *
175
+ * @returns Transaction as hex string
176
+ */
47
177
  toHex(): string;
48
- setInputScript(index: number, scriptSig: Buffer): void;
49
- setWitness(index: number, witness: Buffer[]): void;
50
- private __toBuffer;
178
+ /**
179
+ * Set the input script for a specific input.
180
+ *
181
+ * @param index - Input index
182
+ * @param scriptSig - The script to set
183
+ */
184
+ setInputScript(index: number, scriptSig: Script): void;
185
+ /**
186
+ * Set the witness data for a specific input.
187
+ *
188
+ * @param index - Input index
189
+ * @param witness - Array of witness elements
190
+ */
191
+ setWitness(index: number, witness: Uint8Array[]): void;
51
192
  }
193
+ //# sourceMappingURL=transaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"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"}
@@ -1,42 +1,40 @@
1
- import { default as typeforce } from 'typeforce';
2
- export { typeforce };
3
- export type TypeforceValidator = (value: unknown) => boolean;
4
- export declare function stacksEqual(a: Buffer[], b: Buffer[]): boolean;
5
- export declare function isPoint(p: Buffer | number | undefined | null): boolean;
6
- export declare function Satoshi(value: number): boolean;
7
- export interface XOnlyPointAddTweakResult {
8
- parity: 1 | 0;
9
- xOnlyPubkey: Uint8Array;
10
- }
1
+ import { Bytes32, Bytes20, Satoshi, PrivateKey, XOnlyPublicKey, PublicKey, SchnorrSignature, Signature, Script } from './branded.js';
2
+ export type { Bytes32, Bytes20, PublicKey, XOnlyPublicKey, Satoshi, PrivateKey, Signature, SchnorrSignature, Script, } from './branded.js';
3
+ export declare const SATOSHI_MAX: bigint;
4
+ export declare const TAPLEAF_VERSION_MASK = 254;
5
+ export declare function isUInt8(value: unknown): value is number;
6
+ export declare function isUInt32(value: unknown): value is number;
7
+ export declare function isNumber(value: unknown): value is number;
8
+ export declare function isUint8Array(value: unknown): value is Uint8Array;
9
+ export declare function isUint8ArrayN<N extends number>(value: unknown, n: N): value is Uint8Array & {
10
+ readonly length: N;
11
+ };
12
+ export declare function isArray(value: unknown): value is unknown[];
13
+ export declare function isHex(value: unknown): value is string;
14
+ export declare function isBytes32(value: unknown): value is Bytes32;
15
+ export declare function isBytes20(value: unknown): value is Bytes20;
16
+ export declare function isXOnlyPublicKey(value: unknown): value is XOnlyPublicKey;
17
+ export declare function isPoint(value: unknown): value is PublicKey;
18
+ export declare function isSatoshi(value: unknown): value is Satoshi;
19
+ export declare function isPrivateKey(value: unknown): value is PrivateKey;
20
+ export declare function isSchnorrSignature(value: unknown): value is SchnorrSignature;
21
+ export declare function isSignature(value: unknown): value is Signature;
22
+ export declare function isScript(value: unknown): value is Script;
11
23
  export interface Tapleaf {
12
- output: Buffer;
13
- version?: number;
24
+ readonly output: Uint8Array;
25
+ readonly version?: number;
14
26
  }
15
- export declare const TAPLEAF_VERSION_MASK = 254;
16
- export declare function isTapleaf(o: unknown): o is Tapleaf;
17
27
  export type Taptree = [Taptree | Tapleaf, Taptree | Tapleaf] | Tapleaf;
18
- export declare function isTaptree(scriptTree: unknown): scriptTree is Taptree;
19
- export interface TinySecp256k1Interface {
20
- isXOnlyPoint(p: Uint8Array): boolean;
21
- xOnlyPointAddTweak(p: Uint8Array, tweak: Uint8Array): XOnlyPointAddTweakResult | null;
22
- }
23
- export declare const Buffer256bit: TypeforceValidator;
24
- export declare const Hash160bit: TypeforceValidator;
25
- export declare const Hash256bit: TypeforceValidator;
26
- export declare const Number: TypeforceValidator;
27
- export declare const Array: TypeforceValidator;
28
- export declare const Boolean: TypeforceValidator;
29
- export declare const String: TypeforceValidator;
30
- export declare const Buffer: TypeforceValidator;
31
- export declare const Hex: TypeforceValidator;
32
- export declare const maybe: (type: unknown) => TypeforceValidator;
33
- export declare const tuple: (...types: unknown[]) => TypeforceValidator;
34
- export declare const UInt8: TypeforceValidator;
35
- export declare const UInt32: TypeforceValidator;
36
- export declare const Function: TypeforceValidator;
37
- export declare const BufferN: (n: number) => TypeforceValidator;
38
- export declare const Null: TypeforceValidator;
39
- export declare const oneOf: (...types: unknown[]) => TypeforceValidator;
40
- export type StackElement = globalThis.Buffer | number;
41
- export type Stack = StackElement[];
28
+ export declare function isTapleaf(value: unknown): value is Tapleaf;
29
+ export declare function isTaptree(value: unknown): value is Taptree;
30
+ export type { XOnlyPointAddTweakResult, EccLib, Parity } from './ecc/types.js';
31
+ export type StackElement = Uint8Array | number;
32
+ export type Stack = readonly StackElement[];
42
33
  export type StackFunction = () => Stack;
34
+ export declare function stacksEqual(a: Uint8Array[], b: Uint8Array[]): boolean;
35
+ export declare function toBytes32(value: Uint8Array): Bytes32;
36
+ export declare function toBytes20(value: Uint8Array): Bytes20;
37
+ export declare function toSatoshi(value: bigint): Satoshi;
38
+ export declare function assertXOnlyPublicKey(value: unknown, name: string): asserts value is XOnlyPublicKey;
39
+ export declare function assertPrivateKey(value: unknown, name: string): asserts value is PrivateKey;
40
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,143 @@
1
+ import { WorkerPoolConfig, SigningTask, ParallelSignerKeyPair, ParallelSigningResult } from './types.js';
2
+ /**
3
+ * Worker-based parallel signing pool.
4
+ *
5
+ * Manages a pool of worker threads for parallel signature computation.
6
+ * Provides secure key handling with immediate zeroing after use.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * // Initialize pool at app startup
11
+ * const pool = WorkerSigningPool.getInstance({ workerCount: 4 });
12
+ * pool.preserveWorkers();
13
+ *
14
+ * // Use for PSBT signing
15
+ * const tasks = prepareSigningTasks(psbt, keyPair);
16
+ * const result = await pool.signBatch(tasks, keyPair);
17
+ *
18
+ * // Apply signatures to PSBT
19
+ * applySignatures(psbt, result.signatures);
20
+ * ```
21
+ */
22
+ export declare class WorkerSigningPool {
23
+ #private;
24
+ /**
25
+ * Creates a new WorkerSigningPool.
26
+ *
27
+ * @param config - Pool configuration
28
+ */
29
+ private constructor();
30
+ /**
31
+ * Gets the singleton pool instance.
32
+ *
33
+ * @param config - Optional configuration (only used on first call)
34
+ * @returns The singleton pool instance
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const pool = WorkerSigningPool.getInstance({ workerCount: 8 });
39
+ * ```
40
+ */
41
+ static getInstance(config?: WorkerPoolConfig): WorkerSigningPool;
42
+ /**
43
+ * Resets the singleton instance (for testing).
44
+ */
45
+ static resetInstance(): void;
46
+ /**
47
+ * Number of workers in the pool.
48
+ */
49
+ get workerCount(): number;
50
+ /**
51
+ * Number of idle workers available.
52
+ */
53
+ get idleWorkerCount(): number;
54
+ /**
55
+ * Number of busy workers.
56
+ */
57
+ get busyWorkerCount(): number;
58
+ /**
59
+ * Whether workers are being preserved between batches.
60
+ */
61
+ get isPreservingWorkers(): boolean;
62
+ /**
63
+ * Enables worker preservation between signing batches.
64
+ *
65
+ * When enabled, workers remain alive after completing a batch,
66
+ * ready for the next signing operation. This is faster but
67
+ * keeps workers in memory.
68
+ *
69
+ * Call shutdown() when done to terminate all workers.
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * const pool = WorkerSigningPool.getInstance();
74
+ * pool.preserveWorkers(); // Enable at app startup
75
+ *
76
+ * // ... do many signing operations ...
77
+ *
78
+ * await pool.shutdown(); // Cleanup at app shutdown
79
+ * ```
80
+ */
81
+ preserveWorkers(): void;
82
+ /**
83
+ * Disables worker preservation.
84
+ *
85
+ * Workers will be terminated after each signing batch.
86
+ * More secure (no persistent workers) but slower for multiple batches.
87
+ */
88
+ releaseWorkers(): void;
89
+ /**
90
+ * Initializes the worker pool.
91
+ *
92
+ * Creates workers and waits for them to be ready.
93
+ * Called automatically on first signBatch() if not called manually.
94
+ *
95
+ * @returns Promise that resolves when all workers are ready
96
+ */
97
+ initialize(): Promise<void>;
98
+ /**
99
+ * Signs a batch of tasks in parallel.
100
+ *
101
+ * SECURITY: Private keys are obtained via keyPair.getPrivateKey() and
102
+ * cloned to workers. Keys are zeroed in workers immediately after signing.
103
+ *
104
+ * Tasks are distributed across workers and processed in batches for efficiency.
105
+ *
106
+ * @param tasks - Signing tasks (hashes, input indices, etc.)
107
+ * @param keyPair - Key pair with getPrivateKey() method
108
+ * @returns Promise resolving to signing results
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * const tasks: SigningTask[] = [
113
+ * { taskId: '1', inputIndex: 0, hash: hash0, signatureType: SignatureType.ECDSA, sighashType: 0x01 },
114
+ * { taskId: '2', inputIndex: 1, hash: hash1, signatureType: SignatureType.Schnorr, sighashType: 0x00 },
115
+ * ];
116
+ *
117
+ * const result = await pool.signBatch(tasks, keyPair);
118
+ *
119
+ * if (result.success) {
120
+ * for (const [inputIndex, sig] of result.signatures) {
121
+ * console.log(`Input ${inputIndex}: ${sig.signature}`);
122
+ * }
123
+ * }
124
+ * ```
125
+ */
126
+ signBatch(tasks: readonly SigningTask[], keyPair: ParallelSignerKeyPair): Promise<ParallelSigningResult>;
127
+ /**
128
+ * Shuts down the pool and terminates all workers.
129
+ *
130
+ * Call this when the application is done with signing operations.
131
+ *
132
+ * @returns Promise that resolves when all workers are terminated
133
+ */
134
+ shutdown(): Promise<void>;
135
+ }
136
+ /**
137
+ * Convenience function to get the singleton pool instance.
138
+ *
139
+ * @param config - Optional configuration
140
+ * @returns The singleton pool instance
141
+ */
142
+ export declare function getSigningPool(config?: WorkerPoolConfig): WorkerSigningPool;
143
+ //# sourceMappingURL=WorkerSigningPool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WorkerSigningPool.d.ts","sourceRoot":"","sources":["../../src/workers/WorkerSigningPool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,KAAK,EACR,gBAAgB,EAChB,WAAW,EACX,qBAAqB,EACrB,qBAAqB,EAOxB,MAAM,YAAY,CAAC;AA6BpB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,iBAAiB;;IAmD1B;;;;OAIG;IACH,OAAO;IAKP;;;;;;;;;;OAUG;WACW,WAAW,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,iBAAiB;IAOvE;;OAEG;WACW,aAAa,IAAI,IAAI;IAOnC;;OAEG;IACH,IAAW,WAAW,IAAI,MAAM,CAE/B;IAED;;OAEG;IACH,IAAW,eAAe,IAAI,MAAM,CAEnC;IAED;;OAEG;IACH,IAAW,eAAe,IAAI,MAAM,CAEnC;IAED;;OAEG;IACH,IAAW,mBAAmB,IAAI,OAAO,CAExC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACI,eAAe,IAAI,IAAI;IAI9B;;;;;OAKG;IACI,cAAc,IAAI,IAAI;IAI7B;;;;;;;OAOG;IACU,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAsBxC;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACU,SAAS,CAClB,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,OAAO,EAAE,qBAAqB,GAC/B,OAAO,CAAC,qBAAqB,CAAC;IA4FjC;;;;;;OAMG;IACU,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAiQzC;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,iBAAiB,CAE3E"}
@@ -0,0 +1,116 @@
1
+ import { WorkerPoolConfig, SigningTask, ParallelSignerKeyPair, ParallelSigningResult } from './types.js';
2
+ /**
3
+ * ECC library types for Node.js worker.
4
+ */
5
+ export declare const NodeEccLibrary: {
6
+ /** Pure JS @noble/secp256k1 (default, ~12KB) */
7
+ readonly Noble: "noble";
8
+ /** WASM-based tiny-secp256k1 (faster, ~1.2MB) */
9
+ readonly TinySecp256k1: "tiny-secp256k1";
10
+ };
11
+ export type NodeEccLibrary = (typeof NodeEccLibrary)[keyof typeof NodeEccLibrary];
12
+ /**
13
+ * Extended configuration for Node.js worker pool.
14
+ */
15
+ export interface NodeWorkerPoolConfig extends WorkerPoolConfig {
16
+ /**
17
+ * ECC library type for signing.
18
+ * - NodeEccLibrary.Noble: Pure JS @noble/secp256k1 (default, ~12KB)
19
+ * - NodeEccLibrary.TinySecp256k1: WASM-based tiny-secp256k1 (faster)
20
+ *
21
+ * Default: NodeEccLibrary.Noble
22
+ */
23
+ readonly eccLibrary?: NodeEccLibrary;
24
+ }
25
+ /**
26
+ * Worker-based parallel signing pool for Node.js.
27
+ *
28
+ * Uses worker_threads for true parallel execution.
29
+ * Provides secure key handling with immediate zeroing after use.
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * import { NodeWorkerSigningPool } from '@btc-vision/bitcoin/workers';
34
+ *
35
+ * // Initialize pool at app startup
36
+ * const pool = NodeWorkerSigningPool.getInstance({ workerCount: 4 });
37
+ * pool.preserveWorkers();
38
+ *
39
+ * // Sign batch
40
+ * const result = await pool.signBatch(tasks, keyPair);
41
+ *
42
+ * // Cleanup at app shutdown
43
+ * await pool.shutdown();
44
+ * ```
45
+ */
46
+ export declare class NodeWorkerSigningPool {
47
+ #private;
48
+ /**
49
+ * Creates a new NodeWorkerSigningPool.
50
+ *
51
+ * @param config - Pool configuration
52
+ */
53
+ private constructor();
54
+ /**
55
+ * Gets the singleton pool instance.
56
+ *
57
+ * @param config - Optional configuration (only used on first call)
58
+ * @returns The singleton pool instance
59
+ */
60
+ static getInstance(config?: NodeWorkerPoolConfig): NodeWorkerSigningPool;
61
+ /**
62
+ * Resets the singleton instance (for testing).
63
+ */
64
+ static resetInstance(): void;
65
+ /**
66
+ * Number of workers in the pool.
67
+ */
68
+ get workerCount(): number;
69
+ /**
70
+ * Number of idle workers available.
71
+ */
72
+ get idleWorkerCount(): number;
73
+ /**
74
+ * Number of busy workers.
75
+ */
76
+ get busyWorkerCount(): number;
77
+ /**
78
+ * Whether workers are being preserved between batches.
79
+ */
80
+ get isPreservingWorkers(): boolean;
81
+ /**
82
+ * Enables worker preservation between signing batches.
83
+ */
84
+ preserveWorkers(): void;
85
+ /**
86
+ * Disables worker preservation.
87
+ */
88
+ releaseWorkers(): void;
89
+ /**
90
+ * Initializes the worker pool.
91
+ *
92
+ * @returns Promise that resolves when all workers are ready
93
+ */
94
+ initialize(): Promise<void>;
95
+ /**
96
+ * Signs a batch of tasks in parallel.
97
+ *
98
+ * Tasks are distributed across workers and processed in batches for efficiency.
99
+ *
100
+ * @param tasks - Signing tasks
101
+ * @param keyPair - Key pair with getPrivateKey() method
102
+ * @returns Promise resolving to signing results
103
+ */
104
+ signBatch(tasks: readonly SigningTask[], keyPair: ParallelSignerKeyPair): Promise<ParallelSigningResult>;
105
+ /**
106
+ * Shuts down the pool and terminates all workers.
107
+ *
108
+ * @returns Promise that resolves when all workers are terminated
109
+ */
110
+ shutdown(): Promise<void>;
111
+ }
112
+ /**
113
+ * Convenience function to get the singleton pool instance.
114
+ */
115
+ export declare function getNodeSigningPool(config?: NodeWorkerPoolConfig): NodeWorkerSigningPool;
116
+ //# sourceMappingURL=WorkerSigningPool.node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WorkerSigningPool.node.d.ts","sourceRoot":"","sources":["../../src/workers/WorkerSigningPool.node.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EACR,gBAAgB,EAChB,WAAW,EACX,qBAAqB,EACrB,qBAAqB,EAOxB,MAAM,YAAY,CAAC;AAGpB;;GAEG;AACH,eAAO,MAAM,cAAc;IACvB,gDAAgD;;IAEhD,iDAAiD;;CAE3C,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,OAAO,cAAc,CAAC,CAAC;AAElF;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,gBAAgB;IAC1D;;;;;;OAMG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,cAAc,CAAC;CACxC;AA+BD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,qBAAqB;;IAmD9B;;;;OAIG;IACH,OAAO;IAQP;;;;;OAKG;WACW,WAAW,CAAC,MAAM,CAAC,EAAE,oBAAoB,GAAG,qBAAqB;IAO/E;;OAEG;WACW,aAAa,IAAI,IAAI;IAOnC;;OAEG;IACH,IAAW,WAAW,IAAI,MAAM,CAE/B;IAED;;OAEG;IACH,IAAW,eAAe,IAAI,MAAM,CAEnC;IAED;;OAEG;IACH,IAAW,eAAe,IAAI,MAAM,CAEnC;IAED;;OAEG;IACH,IAAW,mBAAmB,IAAI,OAAO,CAExC;IAED;;OAEG;IACI,eAAe,IAAI,IAAI;IAI9B;;OAEG;IACI,cAAc,IAAI,IAAI;IAI7B;;;;OAIG;IACU,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAsBxC;;;;;;;;OAQG;IACU,SAAS,CAClB,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,OAAO,EAAE,qBAAqB,GAC/B,OAAO,CAAC,qBAAqB,CAAC;IAsFjC;;;;OAIG;IACU,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAugBzC;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,oBAAoB,GAAG,qBAAqB,CAEvF"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Bundled @noble/secp256k1 + hashes for worker embedding.
3
+ *
4
+ * AUTO-GENERATED FILE - DO NOT EDIT
5
+ * Generated by: scripts/bundle-ecc.ts
6
+ *
7
+ * This embeds the entire @noble/secp256k1 library with sha256/hmac
8
+ * as an IIFE string that can be executed in a Web Worker without network requests.
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+ /**
13
+ * Bundled @noble/secp256k1 + hashes library as an IIFE string.
14
+ *
15
+ * When executed, this creates a global `nobleBundle` object with:
16
+ * - secp: The full @noble/secp256k1 module (with hashes configured)
17
+ * - sha256: The sha256 hash function
18
+ * - hmac: The hmac function
19
+ */
20
+ export declare const ECC_BUNDLE = "\"use strict\";var nobleBundle=(()=>{var rt=Object.defineProperty;var _e=Object.getOwnPropertyDescriptor;var Ce=Object.getOwnPropertyNames;var ke=Object.prototype.hasOwnProperty;var Ve=(e,t,n)=>t in e?rt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Ct=(e,t)=>{for(var n in t)rt(e,n,{get:t[n],enumerable:!0})},Te=(e,t,n,s)=>{if(t&&typeof t==\"object\"||typeof t==\"function\")for(let r of Ce(t))!ke.call(e,r)&&r!==n&&rt(e,r,{get:()=>t[r],enumerable:!(s=_e(t,r))||s.enumerable});return e};var Ge=e=>Te(rt({},\"__esModule\",{value:!0}),e);var l=(e,t,n)=>Ve(e,typeof t!=\"symbol\"?t+\"\":t,n);var yn={};Ct(yn,{hmac:()=>lt,secp:()=>Lt,sha256:()=>ht});var Lt={};Ct(Lt,{Point:()=>U,Signature:()=>R,etc:()=>sn,getPublicKey:()=>Pt,getSharedSecret:()=>en,hash:()=>je,hashes:()=>K,keygen:()=>nn,recoverPublicKey:()=>Qe,recoverPublicKeyAsync:()=>tn,schnorr:()=>un,sign:()=>We,signAsync:()=>ze,utils:()=>rn,verify:()=>qe,verifyAsync:()=>Je});var Nt={p:0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,n:0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n,h:1n,a:0n,b:7n,Gx:0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,Gy:0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n},{p:D,n:v,Gx:Fe,Gy:De,b:Zt}=Nt,w=32,Z=64,et={publicKey:w+1,publicKeyUncompressed:Z+1,signature:Z,seed:w+w/2},Ke=(...e)=>{\"captureStackTrace\"in Error&&typeof Error.captureStackTrace==\"function\"&&Error.captureStackTrace(...e)},b=(e=\"\")=>{let t=new Error(e);throw Ke(t,b),t},Oe=e=>typeof e==\"bigint\",Ne=e=>typeof e==\"string\",Ze=e=>e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===\"Uint8Array\",A=(e,t,n=\"\")=>{let s=Ze(e),r=e?.length,o=t!==void 0;if(!s||o&&r!==t){let c=n&&`\"${n}\" `,i=o?` of length ${t}`:\"\",u=s?`length=${r}`:`type=${typeof e}`;b(c+\"expected Uint8Array\"+i+\", got \"+u)}return e},k=e=>new Uint8Array(e),jt=(e,t)=>e.toString(16).padStart(t,\"0\"),wt=e=>Array.from(A(e)).map(t=>jt(t,2)).join(\"\"),V={_0:48,_9:57,A:65,F:70,a:97,f:102},kt=e=>{if(e>=V._0&&e<=V._9)return e-V._0;if(e>=V.A&&e<=V.F)return e-(V.A-10);if(e>=V.a&&e<=V.f)return e-(V.a-10)},mt=e=>{let t=\"hex invalid\";if(!Ne(e))return b(t);let n=e.length,s=n/2;if(n%2)return b(t);let r=k(s);for(let o=0,c=0;o<s;o++,c+=2){let i=kt(e.charCodeAt(c)),u=kt(e.charCodeAt(c+1));if(i===void 0||u===void 0)return b(t);r[o]=i*16+u}return r},Rt=()=>globalThis?.crypto,Vt=()=>Rt()?.subtle??b(\"crypto.subtle must be defined, consider polyfill\"),L=(...e)=>{let t=k(e.reduce((s,r)=>s+A(r).length,0)),n=0;return e.forEach(s=>{t.set(s,n),n+=s.length}),t},nt=(e=w)=>Rt().getRandomValues(k(e)),Y=BigInt,j=(e,t,n,s=\"bad number: out of range\")=>Oe(e)&&t<=e&&e<n?e:b(s),a=(e,t=D)=>{let n=e%t;return n>=0n?n:t+n},E=e=>a(e,v),st=(e,t)=>{(e===0n||t<=0n)&&b(\"no inverse n=\"+e+\" mod=\"+t);let n=a(e,t),s=t,r=0n,o=1n,c=1n,i=0n;for(;n!==0n;){let u=s/n,d=s%n,f=r-c*u,h=o-i*u;s=n,n=d,r=c,o=i,c=f,i=h}return s===1n?a(r,t):b(\"no inverse\")},it=e=>{let t=K[e];return typeof t!=\"function\"&&b(\"hashes.\"+e+\" not set\"),t},je=e=>it(\"sha256\")(e),xt=e=>e instanceof U?e:b(\"Point expected\"),Xt=e=>a(a(e*e)*e+Zt),Tt=e=>j(e,0n,D),tt=e=>j(e,1n,D),bt=e=>j(e,1n,v),M=e=>(e&1n)===0n,ft=e=>Uint8Array.of(e),Yt=e=>ft(M(e)?2:3),Mt=e=>{let t=Xt(tt(e)),n=1n;for(let s=t,r=(D+1n)/4n;r>0n;r>>=1n)r&1n&&(n=n*s%D),s=s*s%D;return a(n*n)===t?n:b(\"sqrt invalid\")},C=class C{constructor(t,n,s){l(this,\"X\");l(this,\"Y\");l(this,\"Z\");this.X=Tt(t),this.Y=tt(n),this.Z=Tt(s),Object.freeze(this)}static CURVE(){return Nt}static fromAffine(t){let{x:n,y:s}=t;return n===0n&&s===0n?N:new C(n,s,1n)}static fromBytes(t){A(t);let{publicKey:n,publicKeyUncompressed:s}=et,r,o=t.length,c=t[0],i=t.subarray(1),u=P(i,0,w);if(o===n&&(c===2||c===3)){let d=Mt(u),f=M(d);M(Y(c))!==f&&(d=a(-d)),r=new C(u,d,1n)}return o===s&&c===4&&(r=new C(u,P(i,w,Z),1n)),r?r.assertValidity():b(\"bad point: not on curve\")}static fromHex(t){return C.fromBytes(mt(t))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}equals(t){let{X:n,Y:s,Z:r}=this,{X:o,Y:c,Z:i}=xt(t),u=a(n*i),d=a(o*r),f=a(s*i),h=a(c*r);return u===d&&f===h}is0(){return this.equals(N)}negate(){return new C(this.X,a(-this.Y),this.Z)}double(){return this.add(this)}add(t){let{X:n,Y:s,Z:r}=this,{X:o,Y:c,Z:i}=xt(t),u=0n,d=Zt,f=0n,h=0n,x=0n,y=a(d*3n),p=a(n*o),g=a(s*c),H=a(r*i),I=a(n+s),m=a(o+c);I=a(I*m),m=a(p+g),I=a(I-m),m=a(n+r);let S=a(o+i);return m=a(m*S),S=a(p+H),m=a(m-S),S=a(s+r),f=a(c+i),S=a(S*f),f=a(g+H),S=a(S-f),x=a(u*m),f=a(y*H),x=a(f+x),f=a(g-x),x=a(g+x),h=a(f*x),g=a(p+p),g=a(g+p),H=a(u*H),m=a(y*m),g=a(g+H),H=a(p-H),H=a(u*H),m=a(m+H),p=a(g*m),h=a(h+p),p=a(S*m),f=a(I*f),f=a(f-p),p=a(I*g),x=a(S*x),x=a(x+p),new C(f,h,x)}subtract(t){return this.add(xt(t).negate())}multiply(t,n=!0){if(!n&&t===0n)return N;if(bt(t),t===1n)return this;if(this.equals(T))return ln(t).p;let s=N,r=T;for(let o=this;t>0n;o=o.double(),t>>=1n)t&1n?s=s.add(o):n&&(r=r.add(o));return s}multiplyUnsafe(t){return this.multiply(t,!1)}toAffine(){let{X:t,Y:n,Z:s}=this;if(this.equals(N))return{x:0n,y:0n};if(s===1n)return{x:t,y:n};let r=st(s,D);return a(s*r)!==1n&&b(\"inverse invalid\"),{x:a(t*r),y:a(n*r)}}assertValidity(){let{x:t,y:n}=this.toAffine();return tt(t),tt(n),a(n*n)===Xt(t)?this:b(\"bad point: not on curve\")}toBytes(t=!0){let{x:n,y:s}=this.assertValidity().toAffine(),r=B(n);return t?L(Yt(s),r):L(ft(4),r,B(s))}toHex(t){return wt(this.toBytes(t))}};l(C,\"BASE\"),l(C,\"ZERO\");var U=C,T=new U(Fe,De,1n),N=new U(0n,1n,0n);U.BASE=T;U.ZERO=N;var At=(e,t,n)=>T.multiply(t,!1).add(e.multiply(n,!1)).assertValidity(),G=e=>Y(\"0x\"+(wt(e)||\"0\")),P=(e,t,n)=>G(e.subarray(t,n)),Re=2n**256n,B=e=>mt(jt(j(e,0n,Re),Z)),W=e=>{let t=G(A(e,w,\"secret key\"));return j(t,1n,v,\"invalid secret key: outside of range\")},Ht=e=>e>v>>1n,Pt=(e,t=!0)=>T.multiply(W(e)).toBytes(t),Xe=e=>{try{return!!W(e)}catch{return!1}},Ye=(e,t)=>{let{publicKey:n,publicKeyUncompressed:s}=et;try{let r=e.length;return t===!0&&r!==n||t===!1&&r!==s?!1:!!U.fromBytes(e)}catch{return!1}},$t=e=>{[0,1,2,3].includes(e)||b(\"recovery id must be valid and present\")},Me=e=>{e!=null&&!Gt.includes(e)&&b(`Signature format must be one of: ${Gt.join(\", \")}`),e===qt&&b('Signature format \"der\" is not supported: switch to noble-curves')},Wt=(e,t=$)=>{Me(t);let n=et.signature,s=n+1,r=`Signature format \"${t}\" expects Uint8Array with length `;t===$&&e.length!==n&&b(r+n),t===ot&&e.length!==s&&b(r+s)},R=class e{constructor(t,n,s){l(this,\"r\");l(this,\"s\");l(this,\"recovery\");this.r=bt(t),this.s=bt(n),s!=null&&(this.recovery=s),Object.freeze(this)}static fromBytes(t,n=$){Wt(t,n);let s;n===ot&&(s=t[0],t=t.subarray(1));let r=P(t,0,w),o=P(t,w,Z);return new e(r,o,s)}addRecoveryBit(t){return new e(this.r,this.s,t)}hasHighS(){return Ht(this.s)}toBytes(t=$){let{r:n,s,recovery:r}=this,o=L(B(n),B(s));return t===ot?($t(r),L(Uint8Array.of(r),o)):o}},zt=e=>{let t=e.length*8-256;t>1024&&b(\"msg invalid\");let n=G(e);return t>0?n>>Y(t):n},St=e=>E(zt(A(e))),$=\"compact\",ot=\"recovered\",qt=\"der\",Gt=[$,ot,qt],Ft={lowS:!0,prehash:!0,format:$,extraEntropy:!1},Dt=\"SHA-256\",K={hmacSha256Async:async(e,t)=>{let n=Vt(),s=\"HMAC\",r=await n.importKey(\"raw\",e,{name:s,hash:{name:Dt}},!1,[\"sign\"]);return k(await n.sign(s,r,t))},hmacSha256:void 0,sha256Async:async e=>k(await Vt().digest(Dt,e)),sha256:void 0},z=(e,t,n)=>(A(e,void 0,\"message\"),t.prehash?n?K.sha256Async(e):it(\"sha256\")(e):e),Jt=k(0),Qt=ft(0),te=ft(1),ee=1e3,ne=\"drbg: tried max amount of iterations\",Pe=(e,t)=>{let n=k(w),s=k(w),r=0,o=()=>{n.fill(1),s.fill(0)},c=(...f)=>it(\"hmacSha256\")(s,L(n,...f)),i=(f=Jt)=>{s=c(Qt,f),n=c(),f.length!==0&&(s=c(te,f),n=c())},u=()=>(r++>=ee&&b(ne),n=c(),n);o(),i(e);let d;for(;!(d=t(u()));)i();return o(),d},$e=async(e,t)=>{let n=k(w),s=k(w),r=0,o=()=>{n.fill(1),s.fill(0)},c=(...f)=>K.hmacSha256Async(s,L(n,...f)),i=async(f=Jt)=>{s=await c(Qt,f),n=await c(),f.length!==0&&(s=await c(te,f),n=await c())},u=async()=>(r++>=ee&&b(ne),n=await c(),n);o(),await i(e);let d;for(;!(d=t(await u()));)await i();return o(),d},se=(e,t,n,s)=>{let{lowS:r,extraEntropy:o}=n,c=B,i=St(e),u=c(i),d=W(t),f=[c(d),u];if(o!=null&&o!==!1){let p=o===!0?nt(w):o;f.push(A(p,void 0,\"extraEntropy\"))}let h=L(...f),x=i;return s(h,p=>{let g=zt(p);if(!(1n<=g&&g<v))return;let H=st(g,v),I=T.multiply(g).toAffine(),m=E(I.x);if(m===0n)return;let S=E(H*E(x+m*d));if(S===0n)return;let vt=(I.x===m?0:2)|Number(I.y&1n),_t=S;return r&&Ht(S)&&(_t=E(-S),vt^=1),new R(m,_t,vt).toBytes(n.format)})},re=(e,t,n,s={})=>{let{lowS:r,format:o}=s;e instanceof R&&b(\"Signature must be in Uint8Array, use .toBytes()\"),Wt(e,o),A(n,void 0,\"publicKey\");try{let{r:c,s:i}=R.fromBytes(e,o),u=St(t),d=U.fromBytes(n);if(r&&Ht(i))return!1;let f=st(i,v),h=E(u*f),x=E(c*f),y=At(d,h,x).toAffine();return E(y.x)===c}catch{return!1}},q=e=>{let t={};return Object.keys(Ft).forEach(n=>{t[n]=e[n]??Ft[n]}),t},We=(e,t,n={})=>(n=q(n),e=z(e,n,!1),se(e,t,n,Pe)),ze=async(e,t,n={})=>(n=q(n),e=await z(e,n,!0),se(e,t,n,$e)),qe=(e,t,n,s={})=>(s=q(s),t=z(t,s,!1),re(e,t,n,s)),Je=async(e,t,n,s={})=>(s=q(s),t=await z(t,s,!0),re(e,t,n,s)),oe=(e,t)=>{let n=R.fromBytes(e,\"recovered\"),{r:s,s:r,recovery:o}=n;$t(o);let c=St(A(t,w)),i=o===2||o===3?s+v:s;tt(i);let u=Yt(Y(o)),d=L(u,B(i)),f=U.fromBytes(d),h=st(i,v),x=E(-c*h),y=E(r*h);return At(f,x,y).toBytes()},Qe=(e,t,n={})=>(t=z(t,q(n),!1),oe(e,t)),tn=async(e,t,n={})=>(t=await z(t,q(n),!0),oe(e,t)),en=(e,t,n=!0)=>U.fromBytes(t).multiply(W(e)).toBytes(n),ce=(e=nt(et.seed))=>{A(e),(e.length<et.seed||e.length>1024)&&b(\"expected 40-1024b\");let t=a(G(e),v-1n);return B(t+1n)},ie=e=>t=>{let n=ce(t);return{secretKey:n,publicKey:e(n)}},nn=ie(Pt),sn={hexToBytes:mt,bytesToHex:wt,concatBytes:L,bytesToNumberBE:G,numberToBytesBE:B,mod:a,invert:st,randomBytes:nt,secretKeyToScalar:W,abytes:A},rn={isValidSecretKey:Xe,isValidPublicKey:Ye,randomSecretKey:ce},fe=e=>Uint8Array.from(\"BIP0340/\"+e,t=>t.charCodeAt(0)),ae=\"aux\",ue=\"nonce\",he=\"challenge\",yt=(e,...t)=>{let n=it(\"sha256\"),s=n(fe(e));return n(L(s,s,...t))},pt=async(e,...t)=>{let n=K.sha256Async,s=await n(fe(e));return await n(L(s,s,...t))},Bt=e=>{let t=W(e),n=T.multiply(t),{x:s,y:r}=n.assertValidity().toAffine(),o=M(r)?t:E(-t),c=B(s);return{d:o,px:c}},Et=e=>E(G(e)),de=(...e)=>Et(yt(he,...e)),le=async(...e)=>Et(await pt(he,...e)),xe=e=>Bt(e).px,on=ie(xe),be=(e,t,n)=>{let{px:s,d:r}=Bt(t);return{m:A(e),px:s,d:r,a:A(n,w)}},ye=e=>{let t=Et(e);t===0n&&b(\"sign failed: k is zero\");let{px:n,d:s}=Bt(B(t));return{rx:n,k:s}},pe=(e,t,n,s)=>L(t,B(E(e+n*s))),ge=\"invalid signature produced\",cn=(e,t,n=nt(w))=>{let{m:s,px:r,d:o,a:c}=be(e,t,n),i=yt(ae,c),u=B(o^G(i)),d=yt(ue,u,r,s),{rx:f,k:h}=ye(d),x=de(f,r,s),y=pe(h,f,x,o);return me(y,s,r)||b(ge),y},fn=async(e,t,n=nt(w))=>{let{m:s,px:r,d:o,a:c}=be(e,t,n),i=await pt(ae,c),u=B(o^G(i)),d=await pt(ue,u,r,s),{rx:f,k:h}=ye(d),x=await le(f,r,s),y=pe(h,f,x,o);return await Ae(y,s,r)||b(ge),y},an=(e,t)=>e instanceof Promise?e.then(t):t(e),we=(e,t,n,s)=>{let r=A(e,Z,\"signature\"),o=A(t,void 0,\"message\"),c=A(n,w,\"publicKey\");try{let i=G(c),u=Mt(i),d=M(u)?u:a(-u),f=new U(i,d,1n).assertValidity(),h=B(f.toAffine().x),x=P(r,0,w);j(x,1n,D);let y=P(r,w,Z);j(y,1n,v);let p=L(B(x),h,o);return an(s(p),g=>{let{x:H,y:I}=At(f,y,E(-g)).toAffine();return!(!M(I)||H!==x)})}catch{return!1}},me=(e,t,n)=>we(e,t,n,de),Ae=async(e,t,n)=>we(e,t,n,le),un={keygen:on,getPublicKey:xe,sign:cn,verify:me,signAsync:fn,verifyAsync:Ae},ct=8,hn=256,He=Math.ceil(hn/ct)+1,gt=2**(ct-1),dn=()=>{let e=[],t=T,n=t;for(let s=0;s<He;s++){n=t,e.push(n);for(let r=1;r<gt;r++)n=n.add(t),e.push(n);t=n.double()}return e},Kt,Ot=(e,t)=>{let n=t.negate();return e?n:t},ln=e=>{let t=Kt||(Kt=dn()),n=N,s=T,r=2**ct,o=r,c=Y(r-1),i=Y(ct);for(let u=0;u<He;u++){let d=Number(e&c);e>>=i,d>gt&&(d-=o,e+=1n);let f=u*gt,h=f,x=f+Math.abs(d)-1,y=u%2!==0,p=d<0;d===0?s=s.add(Ot(y,t[h])):n=n.add(Ot(p,t[x]))}return e!==0n&&b(\"invalid wnaf\"),{p:n,f:s}};function xn(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===\"Uint8Array\"}function Se(e,t=\"\"){if(!Number.isSafeInteger(e)||e<0){let n=t&&`\"${t}\" `;throw new Error(`${n}expected integer >= 0, got ${e}`)}}function J(e,t,n=\"\"){let s=xn(e),r=e?.length,o=t!==void 0;if(!s||o&&r!==t){let c=n&&`\"${n}\" `,i=o?` of length ${t}`:\"\",u=s?`length=${r}`:`type=${typeof e}`;throw new Error(c+\"expected Uint8Array\"+i+\", got \"+u)}return e}function Be(e){if(typeof e!=\"function\"||typeof e.create!=\"function\")throw new Error(\"Hash must wrapped by utils.createHasher\");Se(e.outputLen),Se(e.blockLen)}function Q(e,t=!0){if(e.destroyed)throw new Error(\"Hash instance has been destroyed\");if(t&&e.finished)throw new Error(\"Hash#digest() has already been called\")}function Ee(e,t){J(e,void 0,\"digestInto() output\");let n=t.outputLen;if(e.length<n)throw new Error('\"digestInto() output\" expected to be of length >='+n)}function X(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function at(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function _(e,t){return e<<32-t|e>>>t}function Le(e,t={}){let n=(r,o)=>e(o).update(r).digest(),s=e(void 0);return n.outputLen=s.outputLen,n.blockLen=s.blockLen,n.create=r=>e(r),Object.assign(n,t),Object.freeze(n)}var Ue=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function Ie(e,t,n){return e&t^~e&n}function ve(e,t,n){return e&t^e&n^t&n}var ut=class{constructor(t,n,s,r){l(this,\"blockLen\");l(this,\"outputLen\");l(this,\"padOffset\");l(this,\"isLE\");l(this,\"buffer\");l(this,\"view\");l(this,\"finished\",!1);l(this,\"length\",0);l(this,\"pos\",0);l(this,\"destroyed\",!1);this.blockLen=t,this.outputLen=n,this.padOffset=s,this.isLE=r,this.buffer=new Uint8Array(t),this.view=at(this.buffer)}update(t){Q(this),J(t);let{view:n,buffer:s,blockLen:r}=this,o=t.length;for(let c=0;c<o;){let i=Math.min(r-this.pos,o-c);if(i===r){let u=at(t);for(;r<=o-c;c+=r)this.process(u,c);continue}s.set(t.subarray(c,c+i),this.pos),this.pos+=i,c+=i,this.pos===r&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Q(this),Ee(t,this),this.finished=!0;let{buffer:n,view:s,blockLen:r,isLE:o}=this,{pos:c}=this;n[c++]=128,X(this.buffer.subarray(c)),this.padOffset>r-c&&(this.process(s,0),c=0);for(let h=c;h<r;h++)n[h]=0;s.setBigUint64(r-8,BigInt(this.length*8),o),this.process(s,0);let i=at(t),u=this.outputLen;if(u%4)throw new Error(\"_sha2: outputLen must be aligned to 32bit\");let d=u/4,f=this.get();if(d>f.length)throw new Error(\"_sha2: outputLen bigger than state\");for(let h=0;h<d;h++)i.setUint32(4*h,f[h],o)}digest(){let{buffer:t,outputLen:n}=this;this.digestInto(t);let s=t.slice(0,n);return this.destroy(),s}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:n,buffer:s,length:r,finished:o,destroyed:c,pos:i}=this;return t.destroyed=c,t.finished=o,t.length=r,t.pos=i,r%n&&t.buffer.set(s),t}clone(){return this._cloneInto()}},F=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var bn=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),O=new Uint32Array(64),Ut=class extends ut{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:n,C:s,D:r,E:o,F:c,G:i,H:u}=this;return[t,n,s,r,o,c,i,u]}set(t,n,s,r,o,c,i,u){this.A=t|0,this.B=n|0,this.C=s|0,this.D=r|0,this.E=o|0,this.F=c|0,this.G=i|0,this.H=u|0}process(t,n){for(let h=0;h<16;h++,n+=4)O[h]=t.getUint32(n,!1);for(let h=16;h<64;h++){let x=O[h-15],y=O[h-2],p=_(x,7)^_(x,18)^x>>>3,g=_(y,17)^_(y,19)^y>>>10;O[h]=g+O[h-7]+p+O[h-16]|0}let{A:s,B:r,C:o,D:c,E:i,F:u,G:d,H:f}=this;for(let h=0;h<64;h++){let x=_(i,6)^_(i,11)^_(i,25),y=f+x+Ie(i,u,d)+bn[h]+O[h]|0,g=(_(s,2)^_(s,13)^_(s,22))+ve(s,r,o)|0;f=d,d=u,u=i,i=c+y|0,c=o,o=r,r=s,s=y+g|0}s=s+this.A|0,r=r+this.B|0,o=o+this.C|0,c=c+this.D|0,i=i+this.E|0,u=u+this.F|0,d=d+this.G|0,f=f+this.H|0,this.set(s,r,o,c,i,u,d,f)}roundClean(){X(O)}destroy(){this.set(0,0,0,0,0,0,0,0),X(this.buffer)}},It=class extends Ut{constructor(){super(32);l(this,\"A\",F[0]|0);l(this,\"B\",F[1]|0);l(this,\"C\",F[2]|0);l(this,\"D\",F[3]|0);l(this,\"E\",F[4]|0);l(this,\"F\",F[5]|0);l(this,\"G\",F[6]|0);l(this,\"H\",F[7]|0)}};var ht=Le(()=>new It,Ue(1));var dt=class{constructor(t,n){l(this,\"oHash\");l(this,\"iHash\");l(this,\"blockLen\");l(this,\"outputLen\");l(this,\"finished\",!1);l(this,\"destroyed\",!1);if(Be(t),J(n,void 0,\"key\"),this.iHash=t.create(),typeof this.iHash.update!=\"function\")throw new Error(\"Expected instance of class which extends utils.Hash\");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let s=this.blockLen,r=new Uint8Array(s);r.set(n.length>s?t.create().update(n).digest():n);for(let o=0;o<r.length;o++)r[o]^=54;this.iHash.update(r),this.oHash=t.create();for(let o=0;o<r.length;o++)r[o]^=106;this.oHash.update(r),X(r)}update(t){return Q(this),this.iHash.update(t),this}digestInto(t){Q(this),J(t,this.outputLen,\"output\"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:n,iHash:s,finished:r,destroyed:o,blockLen:c,outputLen:i}=this;return t=t,t.finished=r,t.destroyed=o,t.blockLen=c,t.outputLen=i,t.oHash=n._cloneInto(t.oHash),t.iHash=s._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},lt=(e,t,n)=>new dt(e,t).update(n).digest();lt.create=(e,t)=>new dt(e,t);K.sha256=ht;K.hmacSha256=(e,...t)=>{let n=new Uint8Array(t.reduce((r,o)=>r+o.length,0)),s=0;for(let r of t)n.set(r,s),s+=r.length;return lt(ht,e,n)};return Ge(yn);})();\n/*! Bundled license information:\n\n@noble/secp256k1/index.js:\n (*! noble-secp256k1 - MIT License (c) 2019 Paul Miller (paulmillr.com) *)\n\n@noble/hashes/utils.js:\n (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)\n*/\n";
21
+ /**
22
+ * Size of the bundled code in bytes.
23
+ */
24
+ export declare const ECC_BUNDLE_SIZE = 18327;
25
+ //# sourceMappingURL=ecc-bundle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ecc-bundle.d.ts","sourceRoot":"","sources":["../../src/workers/ecc-bundle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,2pkBAA2pkB,CAAC;AAEnrkB;;GAEG;AACH,eAAO,MAAM,eAAe,QAAQ,CAAC"}