@btc-vision/bitcoin 6.5.5 → 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 (457) hide show
  1. package/AUDIT/README.md +9 -0
  2. package/HOW_TO_WRITE_GOOD_CODE.md +2436 -0
  3. package/SECURITY.md +27 -0
  4. package/benchmark/psbt-2000-inputs.bench.ts +178 -0
  5. package/benchmark/signing.bench.ts +147 -0
  6. package/browser/address.d.ts +56 -9
  7. package/browser/address.d.ts.map +1 -0
  8. package/browser/bech32utils.d.ts +9 -1
  9. package/browser/bech32utils.d.ts.map +1 -0
  10. package/browser/bip66.d.ts +11 -6
  11. package/browser/bip66.d.ts.map +1 -0
  12. package/browser/block.d.ts +117 -11
  13. package/browser/block.d.ts.map +1 -0
  14. package/browser/branded.d.ts +20 -0
  15. package/browser/branded.d.ts.map +1 -0
  16. package/browser/crypto/crypto.d.ts +1 -0
  17. package/browser/crypto/crypto.d.ts.map +1 -0
  18. package/browser/crypto.d.ts +46 -7
  19. package/browser/crypto.d.ts.map +1 -0
  20. package/browser/ecc/context.d.ts +129 -0
  21. package/browser/ecc/context.d.ts.map +1 -0
  22. package/browser/ecc/index.d.ts +11 -0
  23. package/browser/ecc/index.d.ts.map +1 -0
  24. package/browser/ecc/types.d.ts +128 -0
  25. package/browser/ecc/types.d.ts.map +1 -0
  26. package/browser/ecpair.d.ts +99 -0
  27. package/browser/errors.d.ts +124 -0
  28. package/browser/errors.d.ts.map +1 -0
  29. package/browser/index.d.ts +32 -5
  30. package/browser/index.d.ts.map +1 -0
  31. package/browser/index.js +12482 -101
  32. package/browser/io/BinaryReader.d.ts +276 -0
  33. package/browser/io/BinaryReader.d.ts.map +1 -0
  34. package/browser/io/BinaryWriter.d.ts +391 -0
  35. package/browser/io/BinaryWriter.d.ts.map +1 -0
  36. package/browser/io/MemoryPool.d.ts +220 -0
  37. package/browser/io/MemoryPool.d.ts.map +1 -0
  38. package/browser/io/base64.d.ts +13 -0
  39. package/browser/io/base64.d.ts.map +1 -0
  40. package/browser/io/hex.d.ts +67 -0
  41. package/browser/io/hex.d.ts.map +1 -0
  42. package/browser/io/index.d.ts +17 -0
  43. package/browser/io/index.d.ts.map +1 -0
  44. package/browser/io/utils.d.ts +199 -0
  45. package/browser/io/utils.d.ts.map +1 -0
  46. package/browser/merkle.d.ts +10 -1
  47. package/browser/merkle.d.ts.map +1 -0
  48. package/browser/networks.d.ts +70 -9
  49. package/browser/networks.d.ts.map +1 -0
  50. package/browser/opcodes.d.ts +1 -0
  51. package/browser/opcodes.d.ts.map +1 -0
  52. package/browser/payments/bip341.d.ts +35 -9
  53. package/browser/payments/bip341.d.ts.map +1 -0
  54. package/browser/payments/embed.d.ts +112 -1
  55. package/browser/payments/embed.d.ts.map +1 -0
  56. package/browser/payments/index.d.ts +17 -10
  57. package/browser/payments/index.d.ts.map +1 -0
  58. package/browser/payments/p2ms.d.ts +150 -0
  59. package/browser/payments/p2ms.d.ts.map +1 -0
  60. package/browser/payments/p2op.d.ts +150 -24
  61. package/browser/payments/p2op.d.ts.map +1 -0
  62. package/browser/payments/p2pk.d.ts +154 -1
  63. package/browser/payments/p2pk.d.ts.map +1 -0
  64. package/browser/payments/p2pkh.d.ts +176 -1
  65. package/browser/payments/p2pkh.d.ts.map +1 -0
  66. package/browser/payments/p2sh.d.ts +150 -1
  67. package/browser/payments/p2sh.d.ts.map +1 -0
  68. package/browser/payments/p2tr.d.ts +185 -1
  69. package/browser/payments/p2tr.d.ts.map +1 -0
  70. package/browser/payments/p2wpkh.d.ts +161 -1
  71. package/browser/payments/p2wpkh.d.ts.map +1 -0
  72. package/browser/payments/p2wsh.d.ts +146 -1
  73. package/browser/payments/p2wsh.d.ts.map +1 -0
  74. package/browser/payments/types.d.ts +94 -64
  75. package/browser/payments/types.d.ts.map +1 -0
  76. package/browser/psbt/bip371.d.ts +34 -8
  77. package/browser/psbt/bip371.d.ts.map +1 -0
  78. package/browser/psbt/psbtutils.d.ts +56 -16
  79. package/browser/psbt/psbtutils.d.ts.map +1 -0
  80. package/browser/psbt/types.d.ts +245 -0
  81. package/browser/psbt/types.d.ts.map +1 -0
  82. package/browser/psbt/utils.d.ts +64 -0
  83. package/browser/psbt/utils.d.ts.map +1 -0
  84. package/browser/psbt/validation.d.ts +84 -0
  85. package/browser/psbt/validation.d.ts.map +1 -0
  86. package/browser/psbt.d.ts +82 -118
  87. package/browser/psbt.d.ts.map +1 -0
  88. package/browser/pubkey.d.ts +27 -6
  89. package/browser/pubkey.d.ts.map +1 -0
  90. package/browser/push_data.d.ts +24 -2
  91. package/browser/push_data.d.ts.map +1 -0
  92. package/browser/script.d.ts +33 -8
  93. package/browser/script.d.ts.map +1 -0
  94. package/browser/script_number.d.ts +17 -0
  95. package/browser/script_number.d.ts.map +1 -0
  96. package/browser/script_signature.d.ts +23 -5
  97. package/browser/script_signature.d.ts.map +1 -0
  98. package/browser/transaction.d.ts +160 -18
  99. package/browser/transaction.d.ts.map +1 -0
  100. package/browser/types.d.ts +36 -38
  101. package/browser/types.d.ts.map +1 -0
  102. package/browser/workers/WorkerSigningPool.d.ts +143 -0
  103. package/browser/workers/WorkerSigningPool.d.ts.map +1 -0
  104. package/browser/workers/WorkerSigningPool.node.d.ts +116 -0
  105. package/browser/workers/WorkerSigningPool.node.d.ts.map +1 -0
  106. package/browser/workers/ecc-bundle.d.ts +25 -0
  107. package/browser/workers/ecc-bundle.d.ts.map +1 -0
  108. package/browser/workers/index.d.ts +91 -0
  109. package/browser/workers/index.d.ts.map +1 -0
  110. package/browser/workers/psbt-parallel.d.ts +88 -0
  111. package/browser/workers/psbt-parallel.d.ts.map +1 -0
  112. package/browser/workers/signing-worker.d.ts +37 -0
  113. package/browser/workers/signing-worker.d.ts.map +1 -0
  114. package/browser/workers/types.d.ts +365 -0
  115. package/browser/workers/types.d.ts.map +1 -0
  116. package/build/address.d.ts +57 -10
  117. package/build/address.d.ts.map +1 -0
  118. package/build/address.js +80 -24
  119. package/build/address.js.map +1 -0
  120. package/build/bech32utils.d.ts +9 -1
  121. package/build/bech32utils.d.ts.map +1 -0
  122. package/build/bech32utils.js +10 -2
  123. package/build/bech32utils.js.map +1 -0
  124. package/build/bip66.d.ts +11 -6
  125. package/build/bip66.d.ts.map +1 -0
  126. package/build/bip66.js +32 -3
  127. package/build/bip66.js.map +1 -0
  128. package/build/block.d.ts +117 -11
  129. package/build/block.d.ts.map +1 -0
  130. package/build/block.js +204 -72
  131. package/build/block.js.map +1 -0
  132. package/build/branded.d.ts +20 -0
  133. package/build/branded.d.ts.map +1 -0
  134. package/build/branded.js +7 -0
  135. package/build/branded.js.map +1 -0
  136. package/build/crypto/crypto.d.ts +1 -0
  137. package/build/crypto/crypto.d.ts.map +1 -0
  138. package/build/crypto/crypto.js +1 -0
  139. package/build/crypto/crypto.js.map +1 -0
  140. package/build/crypto.d.ts +46 -7
  141. package/build/crypto.d.ts.map +1 -0
  142. package/build/crypto.js +65 -20
  143. package/build/crypto.js.map +1 -0
  144. package/build/ecc/context.d.ts +135 -0
  145. package/build/ecc/context.d.ts.map +1 -0
  146. package/build/ecc/context.js +232 -0
  147. package/build/ecc/context.js.map +1 -0
  148. package/build/ecc/index.d.ts +11 -0
  149. package/build/ecc/index.d.ts.map +1 -0
  150. package/build/ecc/index.js +11 -0
  151. package/build/ecc/index.js.map +1 -0
  152. package/build/ecc/types.d.ts +134 -0
  153. package/build/ecc/types.d.ts.map +1 -0
  154. package/build/ecc/types.js +8 -0
  155. package/build/ecc/types.js.map +1 -0
  156. package/build/errors.d.ts +124 -0
  157. package/build/errors.d.ts.map +1 -0
  158. package/build/errors.js +155 -0
  159. package/build/errors.js.map +1 -0
  160. package/build/index.d.ts +32 -5
  161. package/build/index.d.ts.map +1 -0
  162. package/build/index.js +26 -3
  163. package/build/index.js.map +1 -0
  164. package/build/io/BinaryReader.d.ts +276 -0
  165. package/build/io/BinaryReader.d.ts.map +1 -0
  166. package/build/io/BinaryReader.js +425 -0
  167. package/build/io/BinaryReader.js.map +1 -0
  168. package/build/io/BinaryWriter.d.ts +391 -0
  169. package/build/io/BinaryWriter.d.ts.map +1 -0
  170. package/build/io/BinaryWriter.js +611 -0
  171. package/build/io/BinaryWriter.js.map +1 -0
  172. package/build/io/MemoryPool.d.ts +220 -0
  173. package/build/io/MemoryPool.d.ts.map +1 -0
  174. package/build/io/MemoryPool.js +309 -0
  175. package/build/io/MemoryPool.js.map +1 -0
  176. package/build/io/base64.d.ts +13 -0
  177. package/build/io/base64.d.ts.map +1 -0
  178. package/build/io/base64.js +20 -0
  179. package/build/io/base64.js.map +1 -0
  180. package/build/io/hex.d.ts +67 -0
  181. package/build/io/hex.d.ts.map +1 -0
  182. package/build/io/hex.js +138 -0
  183. package/build/io/hex.js.map +1 -0
  184. package/build/io/index.d.ts +17 -0
  185. package/build/io/index.d.ts.map +1 -0
  186. package/build/io/index.js +23 -0
  187. package/build/io/index.js.map +1 -0
  188. package/build/io/utils.d.ts +199 -0
  189. package/build/io/utils.d.ts.map +1 -0
  190. package/build/io/utils.js +271 -0
  191. package/build/io/utils.js.map +1 -0
  192. package/build/merkle.d.ts +10 -1
  193. package/build/merkle.d.ts.map +1 -0
  194. package/build/merkle.js +12 -1
  195. package/build/merkle.js.map +1 -0
  196. package/build/networks.d.ts +70 -9
  197. package/build/networks.d.ts.map +1 -0
  198. package/build/networks.js +90 -4
  199. package/build/networks.js.map +1 -0
  200. package/build/opcodes.d.ts +1 -0
  201. package/build/opcodes.d.ts.map +1 -0
  202. package/build/opcodes.js +1 -0
  203. package/build/opcodes.js.map +1 -0
  204. package/build/payments/bip341.d.ts +36 -9
  205. package/build/payments/bip341.d.ts.map +1 -0
  206. package/build/payments/bip341.js +35 -15
  207. package/build/payments/bip341.js.map +1 -0
  208. package/build/payments/embed.d.ts +120 -1
  209. package/build/payments/embed.d.ts.map +1 -0
  210. package/build/payments/embed.js +215 -34
  211. package/build/payments/embed.js.map +1 -0
  212. package/build/payments/index.d.ts +17 -10
  213. package/build/payments/index.d.ts.map +1 -0
  214. package/build/payments/index.js +20 -10
  215. package/build/payments/index.js.map +1 -0
  216. package/build/payments/p2ms.d.ts +159 -1
  217. package/build/payments/p2ms.d.ts.map +1 -0
  218. package/build/payments/p2ms.js +427 -108
  219. package/build/payments/p2ms.js.map +1 -0
  220. package/build/payments/p2op.d.ts +158 -24
  221. package/build/payments/p2op.d.ts.map +1 -0
  222. package/build/payments/p2op.js +379 -93
  223. package/build/payments/p2op.js.map +1 -0
  224. package/build/payments/p2pk.d.ts +162 -1
  225. package/build/payments/p2pk.d.ts.map +1 -0
  226. package/build/payments/p2pk.js +327 -58
  227. package/build/payments/p2pk.js.map +1 -0
  228. package/build/payments/p2pkh.d.ts +185 -1
  229. package/build/payments/p2pkh.d.ts.map +1 -0
  230. package/build/payments/p2pkh.js +467 -114
  231. package/build/payments/p2pkh.js.map +1 -0
  232. package/build/payments/p2sh.d.ts +159 -1
  233. package/build/payments/p2sh.d.ts.map +1 -0
  234. package/build/payments/p2sh.js +500 -152
  235. package/build/payments/p2sh.js.map +1 -0
  236. package/build/payments/p2tr.d.ts +193 -1
  237. package/build/payments/p2tr.d.ts.map +1 -0
  238. package/build/payments/p2tr.js +592 -174
  239. package/build/payments/p2tr.js.map +1 -0
  240. package/build/payments/p2wpkh.d.ts +170 -1
  241. package/build/payments/p2wpkh.d.ts.map +1 -0
  242. package/build/payments/p2wpkh.js +429 -104
  243. package/build/payments/p2wpkh.js.map +1 -0
  244. package/build/payments/p2wsh.d.ts +155 -1
  245. package/build/payments/p2wsh.d.ts.map +1 -0
  246. package/build/payments/p2wsh.js +466 -144
  247. package/build/payments/p2wsh.js.map +1 -0
  248. package/build/payments/types.d.ts +98 -64
  249. package/build/payments/types.d.ts.map +1 -0
  250. package/build/payments/types.js +17 -13
  251. package/build/payments/types.js.map +1 -0
  252. package/build/psbt/bip371.d.ts +35 -9
  253. package/build/psbt/bip371.d.ts.map +1 -0
  254. package/build/psbt/bip371.js +113 -28
  255. package/build/psbt/bip371.js.map +1 -0
  256. package/build/psbt/psbtutils.d.ts +56 -16
  257. package/build/psbt/psbtutils.d.ts.map +1 -0
  258. package/build/psbt/psbtutils.js +71 -16
  259. package/build/psbt/psbtutils.js.map +1 -0
  260. package/build/psbt/types.d.ts +249 -0
  261. package/build/psbt/types.d.ts.map +1 -0
  262. package/build/psbt/types.js +6 -0
  263. package/build/psbt/types.js.map +1 -0
  264. package/build/psbt/utils.d.ts +68 -0
  265. package/build/psbt/utils.d.ts.map +1 -0
  266. package/build/psbt/utils.js +171 -0
  267. package/build/psbt/utils.js.map +1 -0
  268. package/build/psbt/validation.d.ts +88 -0
  269. package/build/psbt/validation.d.ts.map +1 -0
  270. package/build/psbt/validation.js +149 -0
  271. package/build/psbt/validation.js.map +1 -0
  272. package/build/psbt.d.ts +84 -120
  273. package/build/psbt.d.ts.map +1 -0
  274. package/build/psbt.js +411 -412
  275. package/build/psbt.js.map +1 -0
  276. package/build/pubkey.d.ts +27 -6
  277. package/build/pubkey.d.ts.map +1 -0
  278. package/build/pubkey.js +37 -13
  279. package/build/pubkey.js.map +1 -0
  280. package/build/push_data.d.ts +24 -2
  281. package/build/push_data.d.ts.map +1 -0
  282. package/build/push_data.js +44 -12
  283. package/build/push_data.js.map +1 -0
  284. package/build/script.d.ts +33 -8
  285. package/build/script.d.ts.map +1 -0
  286. package/build/script.js +100 -36
  287. package/build/script.js.map +1 -0
  288. package/build/script_number.d.ts +17 -0
  289. package/build/script_number.d.ts.map +1 -0
  290. package/build/script_number.js +19 -0
  291. package/build/script_number.js.map +1 -0
  292. package/build/script_signature.d.ts +23 -5
  293. package/build/script_signature.d.ts.map +1 -0
  294. package/build/script_signature.js +48 -15
  295. package/build/script_signature.js.map +1 -0
  296. package/build/transaction.d.ts +160 -18
  297. package/build/transaction.d.ts.map +1 -0
  298. package/build/transaction.js +443 -176
  299. package/build/transaction.js.map +1 -0
  300. package/build/tsconfig.build.tsbuildinfo +1 -0
  301. package/build/types.d.ts +36 -38
  302. package/build/types.d.ts.map +1 -0
  303. package/build/types.js +175 -57
  304. package/build/types.js.map +1 -0
  305. package/build/workers/WorkerSigningPool.d.ts +174 -0
  306. package/build/workers/WorkerSigningPool.d.ts.map +1 -0
  307. package/build/workers/WorkerSigningPool.js +553 -0
  308. package/build/workers/WorkerSigningPool.js.map +1 -0
  309. package/build/workers/WorkerSigningPool.node.d.ts +124 -0
  310. package/build/workers/WorkerSigningPool.node.d.ts.map +1 -0
  311. package/build/workers/WorkerSigningPool.node.js +753 -0
  312. package/build/workers/WorkerSigningPool.node.js.map +1 -0
  313. package/build/workers/ecc-bundle.d.ts +25 -0
  314. package/build/workers/ecc-bundle.d.ts.map +1 -0
  315. package/build/workers/ecc-bundle.js +25 -0
  316. package/build/workers/ecc-bundle.js.map +1 -0
  317. package/build/workers/index.d.ts +91 -0
  318. package/build/workers/index.d.ts.map +1 -0
  319. package/build/workers/index.js +114 -0
  320. package/build/workers/index.js.map +1 -0
  321. package/build/workers/psbt-parallel.d.ts +117 -0
  322. package/build/workers/psbt-parallel.d.ts.map +1 -0
  323. package/build/workers/psbt-parallel.js +233 -0
  324. package/build/workers/psbt-parallel.js.map +1 -0
  325. package/build/workers/signing-worker.d.ts +37 -0
  326. package/build/workers/signing-worker.d.ts.map +1 -0
  327. package/build/workers/signing-worker.js +350 -0
  328. package/build/workers/signing-worker.js.map +1 -0
  329. package/build/workers/types.d.ts +365 -0
  330. package/build/workers/types.d.ts.map +1 -0
  331. package/build/workers/types.js +60 -0
  332. package/build/workers/types.js.map +1 -0
  333. package/package.json +83 -25
  334. package/scripts/bundle-ecc.ts +111 -0
  335. package/src/address.ts +81 -44
  336. package/src/bech32utils.ts +3 -3
  337. package/src/bip66.ts +34 -24
  338. package/src/block.ts +196 -84
  339. package/src/branded.ts +18 -0
  340. package/src/crypto.ts +64 -26
  341. package/src/ecc/context.ts +277 -0
  342. package/src/ecc/index.ts +14 -0
  343. package/src/ecc/types.ts +154 -0
  344. package/src/ecpair.d.ts +99 -0
  345. package/src/errors.ts +163 -0
  346. package/src/index.ts +113 -9
  347. package/src/io/BinaryReader.ts +461 -0
  348. package/src/io/BinaryWriter.ts +696 -0
  349. package/src/io/MemoryPool.ts +343 -0
  350. package/src/io/base64.ts +20 -0
  351. package/src/io/hex.ts +155 -0
  352. package/src/io/index.ts +41 -0
  353. package/src/io/utils.ts +283 -0
  354. package/src/merkle.ts +14 -9
  355. package/src/networks.ts +9 -9
  356. package/src/payments/bip341.ts +34 -33
  357. package/src/payments/embed.ts +244 -41
  358. package/src/payments/index.ts +12 -10
  359. package/src/payments/p2ms.ts +490 -118
  360. package/src/payments/p2op.ts +431 -133
  361. package/src/payments/p2pk.ts +370 -72
  362. package/src/payments/p2pkh.ts +524 -130
  363. package/src/payments/p2sh.ts +572 -172
  364. package/src/payments/p2tr.ts +686 -194
  365. package/src/payments/p2wpkh.ts +484 -107
  366. package/src/payments/p2wsh.ts +526 -164
  367. package/src/payments/types.ts +80 -66
  368. package/src/psbt/bip371.ts +68 -51
  369. package/src/psbt/psbtutils.ts +39 -40
  370. package/src/psbt/types.ts +331 -0
  371. package/src/psbt/utils.ts +188 -0
  372. package/src/psbt/validation.ts +192 -0
  373. package/src/psbt.ts +566 -809
  374. package/src/pubkey.ts +24 -25
  375. package/src/push_data.ts +18 -16
  376. package/src/script.ts +82 -64
  377. package/src/script_number.ts +6 -6
  378. package/src/script_signature.ts +33 -36
  379. package/src/transaction.ts +458 -238
  380. package/src/types.ts +231 -100
  381. package/src/workers/WorkerSigningPool.node.ts +887 -0
  382. package/src/workers/WorkerSigningPool.ts +670 -0
  383. package/src/workers/ecc-bundle.ts +26 -0
  384. package/src/workers/index.ts +165 -0
  385. package/src/workers/psbt-parallel.ts +332 -0
  386. package/src/workers/signing-worker.ts +353 -0
  387. package/src/workers/types.ts +413 -0
  388. package/test/address.spec.ts +9 -6
  389. package/test/bitcoin.core.spec.ts +16 -17
  390. package/test/block.spec.ts +8 -7
  391. package/test/bufferutils.spec.ts +228 -214
  392. package/test/crypto.spec.ts +19 -11
  393. package/test/fixtures/p2pk.json +0 -8
  394. package/test/fixtures/p2pkh.json +1 -1
  395. package/test/fixtures/p2sh.json +1 -1
  396. package/test/fixtures/script.json +1 -1
  397. package/test/fixtures/transaction.json +2 -2
  398. package/test/integration/_regtest.ts +25 -0
  399. package/test/integration/addresses.spec.ts +4 -3
  400. package/test/integration/bip32.spec.ts +2 -1
  401. package/test/integration/blocks.spec.ts +1 -1
  402. package/test/integration/cltv.spec.ts +18 -16
  403. package/test/integration/csv.spec.ts +37 -64
  404. package/test/integration/payments.spec.ts +5 -3
  405. package/test/integration/taproot.spec.ts +76 -83
  406. package/test/integration/transactions.spec.ts +38 -35
  407. package/test/payments.spec.ts +35 -13
  408. package/test/payments.utils.ts +17 -16
  409. package/test/psbt.spec.ts +111 -100
  410. package/test/script.spec.ts +11 -10
  411. package/test/script_signature.spec.ts +9 -11
  412. package/test/taproot-cache.spec.ts +694 -0
  413. package/test/transaction.spec.ts +32 -40
  414. package/test/types.spec.ts +74 -29
  415. package/test/workers-pool.spec.ts +963 -0
  416. package/test/workers-signing.spec.ts +635 -0
  417. package/test/workers.spec.ts +1390 -0
  418. package/tsconfig.base.json +34 -18
  419. package/tsconfig.browser.json +15 -0
  420. package/tsconfig.build.json +5 -0
  421. package/tsconfig.json +5 -14
  422. package/vite.config.browser.ts +3 -42
  423. package/vitest.config.integration.ts +11 -0
  424. package/browser/bufferutils.d.ts +0 -34
  425. package/browser/chunks/crypto-BhCpKpek.js +0 -2033
  426. package/browser/chunks/payments-yjA0Evsv.js +0 -1089
  427. package/browser/chunks/psbt-URK2hBFc.js +0 -4039
  428. package/browser/chunks/script-DyPItFEl.js +0 -318
  429. package/browser/chunks/transaction-C_UbhMGn.js +0 -432
  430. package/browser/chunks/utils-DNZi-T5W.js +0 -761
  431. package/browser/ecc_lib.d.ts +0 -3
  432. package/browser/hooks/AdvancedSignatureManager.d.ts +0 -16
  433. package/browser/hooks/HookedSigner.d.ts +0 -4
  434. package/browser/hooks/SignatureManager.d.ts +0 -13
  435. package/browser/payments/lazy.d.ts +0 -2
  436. package/browser/typeforce.d.ts +0 -38
  437. package/build/bufferutils.d.ts +0 -34
  438. package/build/bufferutils.js +0 -141
  439. package/build/ecc_lib.d.ts +0 -3
  440. package/build/ecc_lib.js +0 -61
  441. package/build/hooks/AdvancedSignatureManager.d.ts +0 -16
  442. package/build/hooks/AdvancedSignatureManager.js +0 -52
  443. package/build/hooks/HookedSigner.d.ts +0 -4
  444. package/build/hooks/HookedSigner.js +0 -64
  445. package/build/hooks/SignatureManager.d.ts +0 -13
  446. package/build/hooks/SignatureManager.js +0 -45
  447. package/build/payments/lazy.d.ts +0 -2
  448. package/build/payments/lazy.js +0 -28
  449. package/build/tsconfig.tsbuildinfo +0 -1
  450. package/src/bufferutils.ts +0 -188
  451. package/src/ecc_lib.ts +0 -94
  452. package/src/hooks/AdvancedSignatureManager.ts +0 -104
  453. package/src/hooks/HookedSigner.ts +0 -108
  454. package/src/hooks/SignatureManager.ts +0 -84
  455. package/src/payments/lazy.ts +0 -28
  456. package/src/typeforce.d.ts +0 -38
  457. package/tsconfig.webpack.json +0 -18
@@ -0,0 +1,413 @@
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
+ /**
14
+ * Signature type enum for worker operations.
15
+ */
16
+ export const SignatureType = {
17
+ /** ECDSA signature (secp256k1) */
18
+ ECDSA: 0,
19
+ /** Schnorr signature (BIP340) */
20
+ Schnorr: 1,
21
+ } as const;
22
+
23
+ export type SignatureType = (typeof SignatureType)[keyof typeof SignatureType];
24
+
25
+ /**
26
+ * Message sent to worker for signing operation.
27
+ *
28
+ * SECURITY: privateKey is cloned via postMessage, NOT shared.
29
+ * Worker MUST zero the key after signing.
30
+ */
31
+ export interface SigningTaskMessage {
32
+ /** Message type discriminator */
33
+ readonly type: 'sign';
34
+ /** Task identifier for correlation */
35
+ readonly taskId: string;
36
+ /** Hash to sign (32 bytes) */
37
+ readonly hash: Uint8Array;
38
+ /** Private key (32 bytes) - WILL BE ZEROED after use */
39
+ readonly privateKey: Uint8Array;
40
+ /** Public key for verification (33 or 65 bytes) */
41
+ readonly publicKey: Uint8Array;
42
+ /** Signature type (ECDSA or Schnorr) */
43
+ readonly signatureType: SignatureType;
44
+ /** Low R signing for ECDSA (optional) */
45
+ readonly lowR?: boolean | undefined;
46
+ /** Input index this signature is for */
47
+ readonly inputIndex: number;
48
+ /** Sighash type for encoding */
49
+ readonly sighashType: number;
50
+ /** Leaf hash for Taproot script-path (optional) */
51
+ readonly leafHash?: Uint8Array | undefined;
52
+ }
53
+
54
+ /**
55
+ * Initialization message for worker with ECC library.
56
+ */
57
+ export interface WorkerInitMessage {
58
+ /** Message type discriminator */
59
+ readonly type: 'init';
60
+ /** Serialized ECC library functions (or library identifier) */
61
+ readonly eccLibId: string;
62
+ }
63
+
64
+ /**
65
+ * Shutdown message for worker.
66
+ */
67
+ export interface WorkerShutdownMessage {
68
+ /** Message type discriminator */
69
+ readonly type: 'shutdown';
70
+ }
71
+
72
+ /**
73
+ * Individual task in a batch (without privateKey - shared across batch).
74
+ */
75
+ export interface BatchSigningTask {
76
+ /** Task identifier */
77
+ readonly taskId: string;
78
+ /** Hash to sign (32 bytes) */
79
+ readonly hash: Uint8Array;
80
+ /** Public key for verification */
81
+ readonly publicKey: Uint8Array;
82
+ /** Signature type */
83
+ readonly signatureType: SignatureType;
84
+ /** Low R for ECDSA */
85
+ readonly lowR?: boolean | undefined;
86
+ /** Input index */
87
+ readonly inputIndex: number;
88
+ /** Sighash type */
89
+ readonly sighashType: number;
90
+ /** Leaf hash for Taproot */
91
+ readonly leafHash?: Uint8Array | undefined;
92
+ }
93
+
94
+ /**
95
+ * Batch signing message - multiple tasks with single private key.
96
+ * More efficient than sending tasks one at a time.
97
+ */
98
+ export interface BatchSigningMessage {
99
+ /** Message type discriminator */
100
+ readonly type: 'signBatch';
101
+ /** Batch identifier for correlation */
102
+ readonly batchId: string;
103
+ /** Tasks to sign */
104
+ readonly tasks: readonly BatchSigningTask[];
105
+ /** Private key (32 bytes) - WILL BE ZEROED after all tasks */
106
+ readonly privateKey: Uint8Array;
107
+ }
108
+
109
+ /**
110
+ * Individual result from a batch.
111
+ */
112
+ export interface BatchSigningTaskResult {
113
+ /** Task identifier */
114
+ readonly taskId: string;
115
+ /** Signature bytes */
116
+ readonly signature: Uint8Array;
117
+ /** Input index */
118
+ readonly inputIndex: number;
119
+ /** Public key used */
120
+ readonly publicKey: Uint8Array;
121
+ /** Signature type */
122
+ readonly signatureType: SignatureType;
123
+ /** Leaf hash (if applicable) */
124
+ readonly leafHash?: Uint8Array | undefined;
125
+ }
126
+
127
+ /**
128
+ * Individual error from a batch.
129
+ */
130
+ export interface BatchSigningTaskError {
131
+ /** Task identifier */
132
+ readonly taskId: string;
133
+ /** Input index */
134
+ readonly inputIndex: number;
135
+ /** Error message */
136
+ readonly error: string;
137
+ }
138
+
139
+ /**
140
+ * Batch result message from worker.
141
+ */
142
+ export interface BatchSigningResultMessage {
143
+ /** Message type discriminator */
144
+ readonly type: 'batchResult';
145
+ /** Batch identifier for correlation */
146
+ readonly batchId: string;
147
+ /** Successful results */
148
+ readonly results: readonly BatchSigningTaskResult[];
149
+ /** Errors */
150
+ readonly errors: readonly BatchSigningTaskError[];
151
+ }
152
+
153
+ /**
154
+ * All possible messages to worker.
155
+ */
156
+ export type WorkerMessage = SigningTaskMessage | BatchSigningMessage | WorkerInitMessage | WorkerShutdownMessage;
157
+
158
+ /**
159
+ * Result from worker after signing.
160
+ */
161
+ export interface SigningResultMessage {
162
+ /** Message type discriminator */
163
+ readonly type: 'result';
164
+ /** Task identifier for correlation */
165
+ readonly taskId: string;
166
+ /** Signature bytes (64 bytes raw for Schnorr, or with sighash for ECDSA) */
167
+ readonly signature: Uint8Array;
168
+ /** Input index this signature is for */
169
+ readonly inputIndex: number;
170
+ /** Public key used for signing */
171
+ readonly publicKey: Uint8Array;
172
+ /** Signature type that was used */
173
+ readonly signatureType: SignatureType;
174
+ /** Leaf hash for Taproot script-path spending (if applicable) */
175
+ readonly leafHash?: Uint8Array | undefined;
176
+ }
177
+
178
+ /**
179
+ * Error result from worker.
180
+ */
181
+ export interface SigningErrorMessage {
182
+ /** Message type discriminator */
183
+ readonly type: 'error';
184
+ /** Task identifier for correlation */
185
+ readonly taskId: string;
186
+ /** Error message */
187
+ readonly error: string;
188
+ /** Input index that failed */
189
+ readonly inputIndex: number;
190
+ }
191
+
192
+ /**
193
+ * Worker ready message.
194
+ */
195
+ export interface WorkerReadyMessage {
196
+ /** Message type discriminator */
197
+ readonly type: 'ready';
198
+ }
199
+
200
+ /**
201
+ * Worker shutdown acknowledgment.
202
+ */
203
+ export interface WorkerShutdownAckMessage {
204
+ /** Message type discriminator */
205
+ readonly type: 'shutdown-ack';
206
+ }
207
+
208
+ /**
209
+ * Union of all worker response types.
210
+ */
211
+ export type WorkerResponse =
212
+ | SigningResultMessage
213
+ | SigningErrorMessage
214
+ | BatchSigningResultMessage
215
+ | WorkerReadyMessage
216
+ | WorkerShutdownAckMessage;
217
+
218
+ /**
219
+ * Type guard for error responses.
220
+ */
221
+ export function isSigningError(response: WorkerResponse): response is SigningErrorMessage {
222
+ return response.type === 'error';
223
+ }
224
+
225
+ /**
226
+ * Type guard for success responses.
227
+ */
228
+ export function isSigningResult(response: WorkerResponse): response is SigningResultMessage {
229
+ return response.type === 'result';
230
+ }
231
+
232
+ /**
233
+ * Type guard for batch result responses.
234
+ */
235
+ export function isBatchResult(response: WorkerResponse): response is BatchSigningResultMessage {
236
+ return response.type === 'batchResult';
237
+ }
238
+
239
+ /**
240
+ * Type guard for ready responses.
241
+ */
242
+ export function isWorkerReady(response: WorkerResponse): response is WorkerReadyMessage {
243
+ return response.type === 'ready';
244
+ }
245
+
246
+ /**
247
+ * Interface for the ECC library used by workers.
248
+ * Provides signing functions for ECDSA and Schnorr signatures.
249
+ */
250
+ export interface WorkerEccLib {
251
+ /**
252
+ * Create an ECDSA signature.
253
+ *
254
+ * @param hash - 32-byte hash to sign
255
+ * @param privateKey - 32-byte private key
256
+ * @param lowR - Optional: grind for low R value
257
+ * @returns 64-byte raw signature (r || s)
258
+ */
259
+ sign(hash: Uint8Array, privateKey: Uint8Array, lowR?: boolean): Uint8Array;
260
+
261
+ /**
262
+ * Create a Schnorr signature (BIP340).
263
+ *
264
+ * @param hash - 32-byte hash to sign
265
+ * @param privateKey - 32-byte private key
266
+ * @returns 64-byte Schnorr signature
267
+ */
268
+ signSchnorr(hash: Uint8Array, privateKey: Uint8Array): Uint8Array;
269
+ }
270
+
271
+ /**
272
+ * Configuration for the worker signing pool.
273
+ */
274
+ export interface WorkerPoolConfig {
275
+ /**
276
+ * Number of workers to create.
277
+ * Default: number of CPU cores (navigator.hardwareConcurrency or os.cpus().length)
278
+ */
279
+ readonly workerCount?: number;
280
+
281
+ /**
282
+ * Timeout per signing operation in milliseconds.
283
+ * Worker is terminated if exceeded (key safety measure).
284
+ * Default: 30000 (30 seconds)
285
+ */
286
+ readonly taskTimeoutMs?: number;
287
+
288
+ /**
289
+ * Maximum time a worker can hold a private key in milliseconds.
290
+ * Acts as a safety net - worker is terminated if signing takes too long.
291
+ * Default: 5000 (5 seconds)
292
+ */
293
+ readonly maxKeyHoldTimeMs?: number;
294
+
295
+ /**
296
+ * Whether to verify signatures after signing.
297
+ * Adds overhead but ensures correctness.
298
+ * Default: true
299
+ */
300
+ readonly verifySignatures?: boolean;
301
+
302
+ /**
303
+ * Whether to preserve workers between signing batches.
304
+ * true = workers stay alive (faster for multiple batches)
305
+ * false = workers terminated after each batch (more secure)
306
+ * Default: true (use preserveWorkers() to enable)
307
+ */
308
+ readonly preserveWorkers?: boolean;
309
+ }
310
+
311
+ /**
312
+ * Signing task for the worker queue.
313
+ */
314
+ export interface SigningTask {
315
+ /** Task identifier */
316
+ readonly taskId: string;
317
+ /** Input index */
318
+ readonly inputIndex: number;
319
+ /** Hash to sign (32 bytes) */
320
+ readonly hash: Uint8Array;
321
+ /** Signature type */
322
+ readonly signatureType: SignatureType;
323
+ /** Low R for ECDSA */
324
+ readonly lowR?: boolean | undefined;
325
+ /** Sighash type */
326
+ readonly sighashType: number;
327
+ /** Leaf hash for Taproot script-path */
328
+ readonly leafHash?: Uint8Array | undefined;
329
+ }
330
+
331
+ /**
332
+ * Signer key pair interface for parallel signing.
333
+ *
334
+ * SECURITY: getPrivateKey() is only called when dispatching to worker.
335
+ * The returned bytes are cloned to the worker and then the original
336
+ * should be considered potentially compromised (in main thread memory).
337
+ *
338
+ * For maximum security, use a hardware wallet that never exposes keys.
339
+ */
340
+ export interface ParallelSignerKeyPair {
341
+ /** Public key (compressed 33 bytes or uncompressed 65 bytes) */
342
+ readonly publicKey: Uint8Array;
343
+
344
+ /**
345
+ * Get private key bytes (32 bytes).
346
+ *
347
+ * SECURITY WARNING: This exposes the raw private key.
348
+ * - Called only when dispatching to worker
349
+ * - Key is cloned to worker via postMessage
350
+ * - Original in main thread should be zeroed by caller if possible
351
+ *
352
+ * For high-security applications, use hardware wallets instead.
353
+ */
354
+ getPrivateKey(): Uint8Array;
355
+
356
+ /**
357
+ * Optional: Sign ECDSA directly (fallback if workers unavailable).
358
+ */
359
+ sign?(hash: Uint8Array, lowR?: boolean): Uint8Array;
360
+
361
+ /**
362
+ * Optional: Sign Schnorr directly (fallback if workers unavailable).
363
+ */
364
+ signSchnorr?(hash: Uint8Array): Uint8Array;
365
+ }
366
+
367
+ /**
368
+ * Result of a parallel signing batch.
369
+ */
370
+ export interface ParallelSigningResult {
371
+ /** Whether all signatures were created successfully */
372
+ readonly success: boolean;
373
+ /** Signatures indexed by input index */
374
+ readonly signatures: ReadonlyMap<number, SigningResultMessage>;
375
+ /** Errors indexed by input index */
376
+ readonly errors: ReadonlyMap<number, string>;
377
+ /** Total time taken in milliseconds */
378
+ readonly durationMs: number;
379
+ }
380
+
381
+ /**
382
+ * Worker state for pool management.
383
+ */
384
+ export const WorkerState = {
385
+ /** Worker is initializing */
386
+ Initializing: 0,
387
+ /** Worker is ready and idle */
388
+ Idle: 1,
389
+ /** Worker is processing a task */
390
+ Busy: 2,
391
+ /** Worker is shutting down */
392
+ ShuttingDown: 3,
393
+ /** Worker has terminated */
394
+ Terminated: 4,
395
+ } as const;
396
+
397
+ export type WorkerState = (typeof WorkerState)[keyof typeof WorkerState];
398
+
399
+ /**
400
+ * Internal worker wrapper for pool management.
401
+ */
402
+ export interface PooledWorker {
403
+ /** Unique worker identifier */
404
+ readonly id: number;
405
+ /** Current worker state */
406
+ state: WorkerState;
407
+ /** The actual worker instance */
408
+ readonly worker: Worker;
409
+ /** Current task ID (if busy) */
410
+ currentTaskId: string | null;
411
+ /** Timestamp when current task started */
412
+ taskStartTime: number | null;
413
+ }
@@ -7,8 +7,11 @@ import * as bscript from '../src/script.js';
7
7
  import fixtures from './fixtures/address.json' with { type: 'json' };
8
8
 
9
9
  import { initEccLib } from '../src/index.js';
10
+ import type { EccLib } from '../src/index.js';
10
11
  import type { Network } from '../src/networks.js';
11
12
  import * as networks from '../src/networks.js';
13
+ import { toHex, fromHex } from '../src/io/index.js';
14
+ import type { Bytes20 } from '../src/types.js';
12
15
 
13
16
  const NETWORKS: Record<string, Network> = Object.assign(
14
17
  {
@@ -37,7 +40,7 @@ describe('address', () => {
37
40
  const decode = baddress.fromBase58Check(f.base58check);
38
41
 
39
42
  assert.strictEqual(decode.version, f.version);
40
- assert.strictEqual(decode.hash.toString('hex'), f.hash);
43
+ assert.strictEqual(toHex(decode.hash), f.hash);
41
44
  });
42
45
  });
43
46
 
@@ -68,7 +71,7 @@ describe('address', () => {
68
71
  validPrefixes.includes(actual.prefix),
69
72
  `Expected prefix to be one of [${validPrefixes.join(', ')}], got ${actual.prefix}`,
70
73
  );
71
- assert.strictEqual(actual.data.toString('hex'), f.data);
74
+ assert.strictEqual(toHex(actual.data), f.data);
72
75
  });
73
76
  });
74
77
 
@@ -82,7 +85,7 @@ describe('address', () => {
82
85
  });
83
86
 
84
87
  describe('fromOutputScript', () => {
85
- initEccLib(ecc);
88
+ initEccLib(ecc as unknown as EccLib);
86
89
  fixtures.standard.forEach((f) => {
87
90
  it('encodes ' + f.script.slice(0, 30) + '... (' + f.network + ')', () => {
88
91
  const script = bscript.fromASM(f.script);
@@ -108,7 +111,7 @@ describe('address', () => {
108
111
  if (!f.base58check) return;
109
112
 
110
113
  it('encodes ' + f.hash + ' (' + f.network + ')', () => {
111
- const address = baddress.toBase58Check(Buffer.from(f.hash, 'hex'), f.version);
114
+ const address = baddress.toBase58Check(fromHex(f.hash) as Bytes20, f.version);
112
115
 
113
116
  assert.strictEqual(address, f.base58check);
114
117
  });
@@ -118,7 +121,7 @@ describe('address', () => {
118
121
  describe('toBech32', () => {
119
122
  fixtures.bech32.forEach((f) => {
120
123
  if (!f.address) return;
121
- const data = Buffer.from(f.data, 'hex');
124
+ const data = fromHex(f.data);
122
125
 
123
126
  it('encode ' + f.address, () => {
124
127
  assert.deepStrictEqual(
@@ -134,7 +137,7 @@ describe('address', () => {
134
137
 
135
138
  it('encode fails (' + f.exception, () => {
136
139
  assert.throws(() => {
137
- baddress.toBech32(Buffer.from(f.data, 'hex'), f.version, f.prefix);
140
+ baddress.toBech32(fromHex(f.data), f.version, f.prefix);
138
141
  }, new RegExp(f.exception));
139
142
  });
140
143
  });
@@ -2,6 +2,8 @@ import assert from 'assert';
2
2
  import base58 from 'bs58';
3
3
  import { describe, it } from 'vitest';
4
4
  import * as bitcoin from '../src/index.js';
5
+ import type { Bytes20, Satoshi, Script } from '../src/types.js';
6
+ import { toHex, fromHex, reverseCopy } from '../src/io/index.js';
5
7
  import base58EncodeDecode from './fixtures/core/base58_encode_decode.json' with { type: 'json' };
6
8
  import base58KeysInvalid from './fixtures/core/base58_keys_invalid.json' with { type: 'json' };
7
9
  import base58KeysValid from './fixtures/core/base58_keys_valid.json' with { type: 'json' };
@@ -20,13 +22,13 @@ describe('Bitcoin-core', () => {
20
22
 
21
23
  it('can decode ' + fb58, () => {
22
24
  const buffer = base58.decode(fb58);
23
- const actual = Buffer.from(buffer).toString('hex');
25
+ const actual = toHex(new Uint8Array(buffer));
24
26
 
25
27
  assert.strictEqual(actual, fhex);
26
28
  });
27
29
 
28
30
  it('can encode ' + fhex, () => {
29
- const buffer = Buffer.from(fhex, 'hex');
31
+ const buffer = fromHex(fhex);
30
32
  const actual = base58.encode(buffer);
31
33
 
32
34
  assert.strictEqual(actual, fb58);
@@ -43,7 +45,7 @@ describe('Bitcoin-core', () => {
43
45
 
44
46
  base58KeysValid.forEach((f) => {
45
47
  const expected = f[0];
46
- const hash = Buffer.from(f[1] as any, 'hex');
48
+ const hash = fromHex(f[1] as any);
47
49
  const params = f[2] as any;
48
50
 
49
51
  if (params.isPrivkey) return;
@@ -55,7 +57,7 @@ describe('Bitcoin-core', () => {
55
57
  const version = network[typeMap[params.addrType]];
56
58
 
57
59
  it(`can export ${expected as string}`, () => {
58
- assert.strictEqual(bitcoin.address.toBase58Check(hash, version), expected);
60
+ assert.strictEqual(bitcoin.address.toBase58Check(hash as Bytes20, version), expected);
59
61
  });
60
62
  });
61
63
  });
@@ -114,7 +116,7 @@ describe('Bitcoin-core', () => {
114
116
  const input = inputs[i];
115
117
 
116
118
  // reverse because test data is reversed
117
- const prevOutHash = Buffer.from(input[0] as string, 'hex').reverse();
119
+ const prevOutHash = reverseCopy(fromHex(input[0] as string));
118
120
  const prevOutIndex = input[1];
119
121
 
120
122
  assert.deepStrictEqual(txIn.hash, prevOutHash);
@@ -153,23 +155,20 @@ describe('Bitcoin-core', () => {
153
155
  const transaction = bitcoin.Transaction.fromHex(txHex);
154
156
  assert.strictEqual(transaction.toHex(), txHex);
155
157
 
156
- const script = Buffer.from(scriptHex, 'hex');
158
+ const script = fromHex(scriptHex);
157
159
  const scriptChunks = bitcoin.script.decompile(script);
158
- assert.strictEqual(
159
- bitcoin.script.compile(scriptChunks!).toString('hex'),
160
- scriptHex,
161
- );
160
+ assert.strictEqual(toHex(bitcoin.script.compile(scriptChunks!)), scriptHex);
162
161
 
163
- const hash = transaction.hashForSignature(inIndex, script, hashType);
162
+ const hash = transaction.hashForSignature(inIndex, script as Script, hashType);
164
163
 
165
164
  // reverse because test data is reversed
166
- assert.strictEqual((hash.reverse() as Buffer).toString('hex'), expectedHash);
165
+ assert.strictEqual(toHex(reverseCopy(hash)), expectedHash);
167
166
 
168
167
  assert.doesNotThrow(() =>
169
168
  transaction.hashForWitnessV0(
170
169
  inIndex,
171
- script,
172
- 0,
170
+ script as Script,
171
+ 0n as Satoshi,
173
172
  // convert to UInt32
174
173
  hashType < 0 ? 0x100000000 + hashType : hashType,
175
174
  ),
@@ -180,13 +179,13 @@ describe('Bitcoin-core', () => {
180
179
 
181
180
  describe('script.signature.decode', () => {
182
181
  sigCanonical.forEach((hex) => {
183
- const buffer = Buffer.from(hex, 'hex');
182
+ const buffer = fromHex(hex);
184
183
 
185
184
  it('can parse ' + hex, () => {
186
185
  const parsed = bitcoin.script.signature.decode(buffer);
187
186
  const actual = bitcoin.script.signature.encode(parsed.signature, parsed.hashType);
188
187
 
189
- assert.strictEqual(actual.toString('hex'), hex);
188
+ assert.strictEqual(toHex(actual), hex);
190
189
  });
191
190
  });
192
191
 
@@ -195,7 +194,7 @@ describe('Bitcoin-core', () => {
195
194
  if (i % 2 !== 0) return;
196
195
 
197
196
  const description = sigNoncanonical[i - 1].slice(0, -1);
198
- const buffer = Buffer.from(hex, 'hex');
197
+ const buffer = fromHex(hex);
199
198
 
200
199
  it('throws on ' + description, () => {
201
200
  const reg = new RegExp(
@@ -1,6 +1,7 @@
1
1
  import assert from 'assert';
2
2
  import { beforeEach, describe, it } from 'vitest';
3
3
  import { Block } from '../src/index.js';
4
+ import { toHex } from '../src/io/index.js';
4
5
 
5
6
  import fixtures from './fixtures/block.json' with { type: 'json' };
6
7
 
@@ -22,7 +23,7 @@ describe('Block', () => {
22
23
  it('returns ' + f.expected + ' for 0x' + f.bits, () => {
23
24
  const bits = parseInt(f.bits, 16);
24
25
 
25
- assert.strictEqual(Block.calculateTarget(bits).toString('hex'), f.expected);
26
+ assert.strictEqual(toHex(Block.calculateTarget(bits)), f.expected);
26
27
  });
27
28
  });
28
29
  });
@@ -33,10 +34,10 @@ describe('Block', () => {
33
34
  const block = Block.fromHex(f.hex);
34
35
 
35
36
  assert.strictEqual(block.version, f.version);
36
- assert.strictEqual(block.prevHash!.toString('hex'), f.prevHash);
37
- assert.strictEqual(block.merkleRoot!.toString('hex'), f.merkleRoot);
37
+ assert.strictEqual(toHex(block.prevHash!), f.prevHash);
38
+ assert.strictEqual(toHex(block.merkleRoot!), f.merkleRoot);
38
39
  if (block.witnessCommit) {
39
- assert.strictEqual(block.witnessCommit.toString('hex'), f.witnessCommit);
40
+ assert.strictEqual(toHex(block.witnessCommit), f.witnessCommit);
40
41
  }
41
42
  assert.strictEqual(block.timestamp, f.timestamp);
42
43
  assert.strictEqual(block.bits, f.bits);
@@ -83,7 +84,7 @@ describe('Block', () => {
83
84
  });
84
85
 
85
86
  it('returns ' + f.id + ' for ' + f.description, () => {
86
- assert.strictEqual(block.getHash().toString('hex'), f.hash);
87
+ assert.strictEqual(toHex(block.getHash()), f.hash);
87
88
  assert.strictEqual(block.getId(), f.id);
88
89
  });
89
90
  });
@@ -123,7 +124,7 @@ describe('Block', () => {
123
124
 
124
125
  it('returns ' + f.merkleRoot + ' for ' + f.id, () => {
125
126
  assert.strictEqual(
126
- Block.calculateMerkleRoot(block.transactions!).toString('hex'),
127
+ toHex(Block.calculateMerkleRoot(block.transactions!)),
127
128
  f.merkleRoot,
128
129
  );
129
130
  });
@@ -131,7 +132,7 @@ describe('Block', () => {
131
132
  if (f.witnessCommit) {
132
133
  it('returns witness commit ' + f.witnessCommit + ' for ' + f.id, () => {
133
134
  assert.strictEqual(
134
- Block.calculateMerkleRoot(block.transactions!, true).toString('hex'),
135
+ toHex(Block.calculateMerkleRoot(block.transactions!, true)),
135
136
  f.witnessCommit,
136
137
  );
137
138
  });