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

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