@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
@@ -4,6 +4,7 @@ import { crypto as bcrypto } from '../src/index.js';
4
4
  import type { TaggedHashPrefix } from '../src/crypto.js';
5
5
  import fixtures from './fixtures/crypto.json' with { type: 'json' };
6
6
  import { sha256, TAGGED_HASH_PREFIXES, TAGS } from '../src/crypto.js';
7
+ import { toHex, fromHex, fromUtf8, concat, equals } from '../src/io/index.js';
7
8
 
8
9
  describe('crypto', () => {
9
10
  ['hash160', 'hash256', 'ripemd160', 'sha1', 'sha256'].forEach((algorithm) => {
@@ -13,8 +14,8 @@ describe('crypto', () => {
13
14
  const expected = (f as any)[algorithm];
14
15
 
15
16
  it('returns ' + expected + ' for ' + f.hex, () => {
16
- const data = Buffer.from(f.hex, 'hex');
17
- const actual = fn(data).toString('hex');
17
+ const data = fromHex(f.hex);
18
+ const actual = toHex(fn(data));
18
19
 
19
20
  assert.strictEqual(actual, expected);
20
21
  });
@@ -24,11 +25,11 @@ describe('crypto', () => {
24
25
 
25
26
  describe('taggedHash', () => {
26
27
  fixtures.taggedHash.forEach((f) => {
27
- const bytes = Buffer.from(f.hex, 'hex');
28
- const expected = Buffer.from(f.result, 'hex');
28
+ const bytes = fromHex(f.hex);
29
+ const expected = fromHex(f.result);
29
30
  it(`returns ${f.result} for taggedHash "${f.tag}" of ${f.hex}`, () => {
30
31
  const actual = bcrypto.taggedHash(f.tag as TaggedHashPrefix, bytes);
31
- assert.strictEqual(actual.toString('hex'), expected.toString('hex'));
32
+ assert.strictEqual(toHex(actual), toHex(expected));
32
33
  });
33
34
  });
34
35
  });
@@ -36,15 +37,22 @@ describe('crypto', () => {
36
37
  describe('TAGGED_HASH_PREFIXES', () => {
37
38
  const taggedHashPrefixes = Object.fromEntries(
38
39
  TAGS.map((tag: TaggedHashPrefix) => {
39
- const tagHash = sha256(Buffer.from(tag));
40
- return [tag, Buffer.concat([tagHash, tagHash])];
40
+ const tagHash = sha256(fromUtf8(tag));
41
+ return [tag, concat([tagHash, tagHash])];
41
42
  }),
42
43
  );
43
44
  it('stored the result of operation', () => {
44
- assert.strictEqual(
45
- JSON.stringify(TAGGED_HASH_PREFIXES),
46
- JSON.stringify(taggedHashPrefixes),
47
- );
45
+ // Compare that all keys match and all values are equal
46
+ const storedKeys = Object.keys(TAGGED_HASH_PREFIXES);
47
+ const computedKeys = Object.keys(taggedHashPrefixes);
48
+ assert.deepStrictEqual(storedKeys.sort(), computedKeys.sort());
49
+
50
+ for (const key of storedKeys) {
51
+ assert.ok(
52
+ equals(TAGGED_HASH_PREFIXES[key as TaggedHashPrefix], taggedHashPrefixes[key]),
53
+ `Mismatch for tag ${key}`,
54
+ );
55
+ }
48
56
  });
49
57
  });
50
58
  });
@@ -72,14 +72,6 @@
72
72
  "exception": "Not enough data",
73
73
  "arguments": {}
74
74
  },
75
- {
76
- "description": "Non-canonical signature",
77
- "exception": "Expected property \"signature\" of type \\?isCanonicalScriptSignature, got Buffer",
78
- "arguments": {
79
- "pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
80
- "signature": "3044"
81
- }
82
- },
83
75
  {
84
76
  "description": "Unexpected OP_RESERVED",
85
77
  "exception": "Output is invalid",
@@ -124,7 +124,7 @@
124
124
  },
125
125
  {
126
126
  "description": "Non-minimally encoded (non BIP62 compliant)",
127
- "exception": "Expected property \"output\" of type Buffer\\(Length: 25\\), got Buffer\\(Length: 26\\)",
127
+ "exception": "Output is invalid",
128
128
  "arguments": {
129
129
  "outputHex": "76a94c14aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac"
130
130
  }
@@ -204,7 +204,7 @@
204
204
  },
205
205
  {
206
206
  "description": "Non-minimally encoded (non BIP62 compliant)",
207
- "exception": "Expected property \"output\" of type Buffer\\(Length: 23\\), got Buffer\\(Length: 24\\)",
207
+ "exception": "Output is invalid",
208
208
  "arguments": {
209
209
  "outputHex": "a94c14c286a1af0947f58d1ad787385b1c2c4a976f9e7187"
210
210
  }
@@ -457,7 +457,7 @@
457
457
  ],
458
458
  "fromASM": [
459
459
  {
460
- "description": "Expected Hex, got String \"0xff\"",
460
+ "description": "Expected hex string",
461
461
  "script": "0xff OP_CHECKSIG"
462
462
  }
463
463
  ]
@@ -892,12 +892,12 @@
892
892
  "invalid": {
893
893
  "addInput": [
894
894
  {
895
- "exception": "Expected property \"0\" of type Buffer\\(Length: 32\\), got Buffer\\(Length: 30\\)",
895
+ "exception": "Expected 32-byte hash",
896
896
  "hash": "0aed1366a73b6057ee7800d737bff1bdf8c448e98d86bc0998f2b009816d",
897
897
  "index": 0
898
898
  },
899
899
  {
900
- "exception": "Expected property \"0\" of type Buffer\\(Length: 32\\), got Buffer\\(Length: 34\\)",
900
+ "exception": "Expected 32-byte hash",
901
901
  "hash": "0aed1366a73b6057ee7800d737bff1bdf8c448e98d86bc0998f2b009816da9b0ffff",
902
902
  "index": 0
903
903
  }
@@ -4,3 +4,28 @@ const APIPASS = process.env.APIPASS || 'satoshi';
4
4
  const APIURL = process.env.APIURL || 'https://regtest.bitbank.cc/1';
5
5
 
6
6
  export const regtestUtils = new RegtestUtils({ APIPASS, APIURL });
7
+
8
+ /**
9
+ * Broadcast with retry logic.
10
+ * The regtest node sometimes returns Bad Request when the faucet
11
+ * transaction hasn't fully propagated yet (race with indexer).
12
+ */
13
+ export async function broadcastAndVerify(
14
+ txHex: string,
15
+ verify: () => Promise<void>,
16
+ maxRetries: number = 3,
17
+ ): Promise<void> {
18
+ for (let attempt = 0; attempt < maxRetries; attempt++) {
19
+ try {
20
+ await regtestUtils.broadcast(txHex);
21
+ await verify();
22
+ return;
23
+ } catch (err: unknown) {
24
+ if (attempt === maxRetries - 1) throw err;
25
+ const msg = err instanceof Error ? err.message : String(err);
26
+ if (msg !== 'Bad Request') throw err;
27
+ console.log(`Bad Request, retry #${attempt + 1}`);
28
+ await new Promise((r) => setTimeout(r, 200 * (attempt + 1)));
29
+ }
30
+ }
31
+ }
@@ -3,6 +3,7 @@ import { ECPairFactory } from 'ecpair';
3
3
  import * as ecc from 'tiny-secp256k1';
4
4
  import { describe, it } from 'vitest';
5
5
  import * as bitcoin from '../../src/index.js';
6
+ import type { PublicKey } from '../../src/index.js';
6
7
  import { regtestUtils } from './_regtest.js';
7
8
 
8
9
  const ECPair = ECPairFactory(ecc);
@@ -48,7 +49,7 @@ describe('bitcoinjs-lib (addresses)', () => {
48
49
  '026477115981fe981a6918a6297d9803c4dc04f328f22041bedff886bbc2962e01',
49
50
  '02c96db2302d19b43d4c69368babace7854cc84eb9e061cde51cfa77ca4a22b8b9',
50
51
  '03c6103b3b83e4a24a0e33a4df246ef11772f9992663db0c35759a5e2ebf68d8e9',
51
- ].map((hex) => Buffer.from(hex, 'hex'));
52
+ ].map((hex) => Buffer.from(hex, 'hex')) as unknown as PublicKey[];
52
53
  const { address } = bitcoin.payments.p2sh({
53
54
  redeem: bitcoin.payments.p2ms({ m: 2, pubkeys }),
54
55
  });
@@ -80,7 +81,7 @@ describe('bitcoinjs-lib (addresses)', () => {
80
81
  '02c96db2302d19b43d4c69368babace7854cc84eb9e061cde51cfa77ca4a22b8b9',
81
82
  '023e4740d0ba639e28963f3476157b7cf2fb7c6fdf4254f97099cf8670b505ea59',
82
83
  '03c6103b3b83e4a24a0e33a4df246ef11772f9992663db0c35759a5e2ebf68d8e9',
83
- ].map((hex) => Buffer.from(hex, 'hex'));
84
+ ].map((hex) => Buffer.from(hex, 'hex')) as unknown as PublicKey[];
84
85
  const { address } = bitcoin.payments.p2wsh({
85
86
  redeem: bitcoin.payments.p2ms({ m: 3, pubkeys }),
86
87
  });
@@ -95,7 +96,7 @@ describe('bitcoinjs-lib (addresses)', () => {
95
96
  const pubkeys = [
96
97
  '026477115981fe981a6918a6297d9803c4dc04f328f22041bedff886bbc2962e01',
97
98
  '02c96db2302d19b43d4c69368babace7854cc84eb9e061cde51cfa77ca4a22b8b9',
98
- ].map((hex) => Buffer.from(hex, 'hex'));
99
+ ].map((hex) => Buffer.from(hex, 'hex')) as unknown as PublicKey[];
99
100
  const { address } = bitcoin.payments.p2sh({
100
101
  redeem: bitcoin.payments.p2wsh({
101
102
  redeem: bitcoin.payments.p2ms({ m: 2, pubkeys }),
@@ -4,6 +4,7 @@ import * as ecc from 'tiny-secp256k1';
4
4
  import * as bip39 from 'bip39';
5
5
  import { describe, it } from 'vitest';
6
6
  import * as bitcoin from '../../src/index.js';
7
+ import type { PublicKey } from '../../src/index.js';
7
8
 
8
9
  const bip32 = BIP32Factory(ecc);
9
10
 
@@ -90,7 +91,7 @@ describe('bitcoinjs-lib (BIP32)', () => {
90
91
 
91
92
  const { address } = bitcoin.payments.p2sh({
92
93
  redeem: bitcoin.payments.p2wpkh({
93
- pubkey: child.publicKey,
94
+ pubkey: child.publicKey as PublicKey,
94
95
  network: bitcoin.networks.testnet,
95
96
  }),
96
97
  network: bitcoin.networks.testnet,
@@ -22,7 +22,7 @@ describe('bitcoinjs-lib (blocks)', () => {
22
22
 
23
23
  assert.strictEqual(script[0], 0x03);
24
24
  const heightBuffer = script.slice(1, 4);
25
- const height = bitcoin.script.number.decode(heightBuffer);
25
+ const height = bitcoin.script.number.decode(heightBuffer as Buffer);
26
26
  assert.strictEqual(height, 498303);
27
27
  });
28
28
  });
@@ -3,6 +3,8 @@ import { ECPairFactory } from 'ecpair';
3
3
  import * as ecc from 'tiny-secp256k1';
4
4
  import { beforeAll, describe, it } from 'vitest';
5
5
  import * as bitcoin from '../../src/index.js';
6
+ import { toHex, fromHex, reverseCopy } from '../../src/index.js';
7
+ import type { Script, Bytes32, Satoshi } from '../../src/index.js';
6
8
  import { regtestUtils } from './_regtest.js';
7
9
 
8
10
  // @ts-ignore
@@ -11,12 +13,12 @@ import bip65 from 'bip65';
11
13
  const ECPair = ECPairFactory(ecc);
12
14
  const regtest = regtestUtils.network;
13
15
 
14
- function toOutputScript(address: string): Buffer {
15
- return bitcoin.address.toOutputScript(address, regtest);
16
+ function toOutputScript(address: string): Script {
17
+ return bitcoin.address.toOutputScript(address, regtest) as Script;
16
18
  }
17
19
 
18
- function idToHash(txid: string): Buffer {
19
- return Buffer.from(txid, 'hex').reverse();
20
+ function idToHash(txid: string): Bytes32 {
21
+ return reverseCopy(fromHex(txid)) as Bytes32;
20
22
  }
21
23
 
22
24
  const alice = ECPair.fromWIF('cScfkGjbzzoeewVWmU2hYPUHeVGJRDdFt7WhmrVVGkxpmPP8BHWe', regtest);
@@ -31,10 +33,10 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', () => {
31
33
  const hashType = bitcoin.Transaction.SIGHASH_ALL;
32
34
 
33
35
  interface KeyPair {
34
- publicKey: Buffer;
36
+ publicKey: Uint8Array;
35
37
  }
36
38
 
37
- function cltvCheckSigOutput(aQ: KeyPair, bQ: KeyPair, lockTime: number): Buffer {
39
+ function cltvCheckSigOutput(aQ: KeyPair, bQ: KeyPair, lockTime: number): Script {
38
40
  return bitcoin.script.fromASM(
39
41
  `
40
42
  OP_IF
@@ -42,10 +44,10 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', () => {
42
44
  OP_CHECKLOCKTIMEVERIFY
43
45
  OP_DROP
44
46
  OP_ELSE
45
- ${bQ.publicKey.toString('hex')}
47
+ ${toHex(bQ.publicKey)}
46
48
  OP_CHECKSIGVERIFY
47
49
  OP_ENDIF
48
- ${aQ.publicKey.toString('hex')}
50
+ ${toHex(aQ.publicKey)}
49
51
  OP_CHECKSIG
50
52
  `
51
53
  .trim()
@@ -76,7 +78,7 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', () => {
76
78
  tx.locktime = lockTime;
77
79
  // Note: nSequence MUST be <= 0xfffffffe otherwise OP_CHECKLOCKTIMEVERIFY will fail.
78
80
  tx.addInput(idToHash(unspent.txId), unspent.vout, 0xfffffffe);
79
- tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 7e4);
81
+ tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 70000n as Satoshi);
80
82
 
81
83
  // {Alice's signature} OP_TRUE
82
84
  const signatureHash = tx.hashForSignature(0, redeemScript, hashType);
@@ -89,7 +91,7 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', () => {
89
91
  output: redeemScript,
90
92
  },
91
93
  }).input;
92
- tx.setInputScript(0, redeemScriptSig!);
94
+ tx.setInputScript(0, redeemScriptSig! as Script);
93
95
 
94
96
  await regtestUtils.broadcast(tx.toHex());
95
97
 
@@ -122,7 +124,7 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', () => {
122
124
  tx.locktime = lockTime;
123
125
  // Note: nSequence MUST be <= 0xfffffffe otherwise OP_CHECKLOCKTIMEVERIFY will fail.
124
126
  tx.addInput(idToHash(unspent.txId), unspent.vout, 0xfffffffe);
125
- tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 7e4);
127
+ tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 70000n as Satoshi);
126
128
 
127
129
  // {Alice's signature} OP_TRUE
128
130
  const signatureHash = tx.hashForSignature(0, redeemScript, hashType);
@@ -135,7 +137,7 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', () => {
135
137
  output: redeemScript,
136
138
  },
137
139
  }).input;
138
- tx.setInputScript(0, redeemScriptSig!);
140
+ tx.setInputScript(0, redeemScriptSig! as Script);
139
141
 
140
142
  // TODO: test that it failures _prior_ to expiry, unfortunately, race conditions when run concurrently
141
143
  // ...
@@ -170,7 +172,7 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', () => {
170
172
  tx.locktime = lockTime;
171
173
  // Note: nSequence MUST be <= 0xfffffffe otherwise OP_CHECKLOCKTIMEVERIFY will fail.
172
174
  tx.addInput(idToHash(unspent.txId), unspent.vout, 0xfffffffe);
173
- tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 8e4);
175
+ tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 80000n as Satoshi);
174
176
 
175
177
  // {Alice's signature} {Bob's signature} OP_FALSE
176
178
  const signatureHash = tx.hashForSignature(0, redeemScript, hashType);
@@ -184,7 +186,7 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', () => {
184
186
  output: redeemScript,
185
187
  },
186
188
  }).input;
187
- tx.setInputScript(0, redeemScriptSig!);
189
+ tx.setInputScript(0, redeemScriptSig! as Script);
188
190
 
189
191
  await regtestUtils.broadcast(tx.toHex());
190
192
  await regtestUtils.verify({
@@ -215,7 +217,7 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', () => {
215
217
  tx.locktime = lockTime;
216
218
  // Note: nSequence MUST be <= 0xfffffffe otherwise OP_CHECKLOCKTIMEVERIFY will fail.
217
219
  tx.addInput(idToHash(unspent.txId), unspent.vout, 0xfffffffe);
218
- tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 1e4);
220
+ tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 10000n as Satoshi);
219
221
 
220
222
  // {Alice's signature} OP_TRUE
221
223
  const signatureHash = tx.hashForSignature(0, redeemScript, hashType);
@@ -229,7 +231,7 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', () => {
229
231
  output: redeemScript,
230
232
  },
231
233
  }).input;
232
- tx.setInputScript(0, redeemScriptSig!);
234
+ tx.setInputScript(0, redeemScriptSig! as Script);
233
235
 
234
236
  await regtestUtils.broadcast(tx.toHex()).catch((err: unknown) => {
235
237
  assert.throws(() => {
@@ -4,21 +4,24 @@ import * as ecc from 'tiny-secp256k1';
4
4
  import { beforeAll, describe, it } from 'vitest';
5
5
  import * as bitcoin from '../../src/index.js';
6
6
  import type { PsbtInput } from '../../src/index.js';
7
+ import { toHex, fromHex, reverseCopy } from '../../src/index.js';
8
+ import type { Script, Bytes32, Satoshi } from '../../src/index.js';
7
9
  import { regtestUtils } from './_regtest.js';
8
10
 
9
11
  // @ts-ignore
10
12
  import bip68 from 'bip68';
11
- import * as varuint from 'varuint-bitcoin';
13
+
14
+
12
15
 
13
16
  const ECPair = ECPairFactory(ecc);
14
17
  const regtest = regtestUtils.network;
15
18
 
16
- function toOutputScript(address: string): Buffer {
17
- return bitcoin.address.toOutputScript(address, regtest);
19
+ function toOutputScript(address: string): Script {
20
+ return bitcoin.address.toOutputScript(address, regtest) as Script;
18
21
  }
19
22
 
20
- function idToHash(txid: string): Buffer {
21
- return Buffer.from(txid, 'hex').reverse();
23
+ function idToHash(txid: string): Bytes32 {
24
+ return reverseCopy(fromHex(txid)) as Bytes32;
22
25
  }
23
26
 
24
27
  const alice = ECPair.fromWIF('cScfkGjbzzoeewVWmU2hYPUHeVGJRDdFt7WhmrVVGkxpmPP8BHWe', regtest);
@@ -35,11 +38,11 @@ describe('bitcoinjs-lib (transactions w/ CSV)', () => {
35
38
  const hashType = bitcoin.Transaction.SIGHASH_ALL;
36
39
 
37
40
  interface KeyPair {
38
- publicKey: Buffer;
41
+ publicKey: Uint8Array;
39
42
  }
40
43
 
41
44
  // IF MTP (from when confirmed) > seconds, _alice can redeem
42
- function csvCheckSigOutput(_alice: KeyPair, _bob: KeyPair, sequence: number): Buffer {
45
+ function csvCheckSigOutput(_alice: KeyPair, _bob: KeyPair, sequence: number): Script {
43
46
  return bitcoin.script.fromASM(
44
47
  `
45
48
  OP_IF
@@ -47,10 +50,10 @@ describe('bitcoinjs-lib (transactions w/ CSV)', () => {
47
50
  OP_CHECKSEQUENCEVERIFY
48
51
  OP_DROP
49
52
  OP_ELSE
50
- ${_bob.publicKey.toString('hex')}
53
+ ${toHex(_bob.publicKey)}
51
54
  OP_CHECKSIGVERIFY
52
55
  OP_ENDIF
53
- ${_alice.publicKey.toString('hex')}
56
+ ${toHex(_alice.publicKey)}
54
57
  OP_CHECKSIG
55
58
  `
56
59
  .trim()
@@ -73,7 +76,7 @@ describe('bitcoinjs-lib (transactions w/ CSV)', () => {
73
76
  _dave: KeyPair,
74
77
  sequence1: number,
75
78
  sequence2: number,
76
- ): Buffer {
79
+ ): Script {
77
80
  return bitcoin.script.fromASM(
78
81
  `
79
82
  OP_IF
@@ -83,20 +86,20 @@ describe('bitcoinjs-lib (transactions w/ CSV)', () => {
83
86
  ${bitcoin.script.number.encode(sequence1).toString('hex')}
84
87
  OP_CHECKSEQUENCEVERIFY
85
88
  OP_DROP
86
- ${_alice.publicKey.toString('hex')}
89
+ ${toHex(_alice.publicKey)}
87
90
  OP_CHECKSIGVERIFY
88
91
  OP_1
89
92
  OP_ENDIF
90
- ${_bob.publicKey.toString('hex')}
91
- ${_charles.publicKey.toString('hex')}
92
- ${_dave.publicKey.toString('hex')}
93
+ ${toHex(_bob.publicKey)}
94
+ ${toHex(_charles.publicKey)}
95
+ ${toHex(_dave.publicKey)}
93
96
  OP_3
94
97
  OP_CHECKMULTISIG
95
98
  OP_ELSE
96
99
  ${bitcoin.script.number.encode(sequence2).toString('hex')}
97
100
  OP_CHECKSEQUENCEVERIFY
98
101
  OP_DROP
99
- ${_alice.publicKey.toString('hex')}
102
+ ${toHex(_alice.publicKey)}
100
103
  OP_CHECKSIG
101
104
  OP_ENDIF
102
105
  `
@@ -123,7 +126,7 @@ describe('bitcoinjs-lib (transactions w/ CSV)', () => {
123
126
  const unspent = await regtestUtils.faucet(p2sh.address!, 1e5);
124
127
  const utx = await regtestUtils.fetch(unspent.txId);
125
128
  // for non segwit inputs, you must pass the full transaction buffer
126
- const nonWitnessUtxo = Buffer.from(utx.txHex, 'hex');
129
+ const nonWitnessUtxo = fromHex(utx.txHex);
127
130
 
128
131
  // This is an example of using the finalizeInput second parameter to
129
132
  // define how you finalize the inputs, allowing for any type of script.
@@ -138,10 +141,10 @@ describe('bitcoinjs-lib (transactions w/ CSV)', () => {
138
141
  })
139
142
  .addOutput({
140
143
  address: regtestUtils.RANDOM_ADDRESS,
141
- value: 7e4,
144
+ value: 70000n as Satoshi,
142
145
  })
143
146
  .signInput(0, alice)
144
- .finalizeInput(0, csvGetFinalScripts) // See csvGetFinalScripts below
147
+ .finalizeInput(0, csvGetFinalScripts as any) // See csvGetFinalScripts below
145
148
  .extractTransaction();
146
149
 
147
150
  // TODO: test that it failures _prior_ to expiry, unfortunately, race conditions when run concurrently
@@ -180,10 +183,10 @@ describe('bitcoinjs-lib (transactions w/ CSV)', () => {
180
183
  const tx = new bitcoin.Transaction();
181
184
  tx.version = 2;
182
185
  tx.addInput(idToHash(unspent.txId), unspent.vout, sequence);
183
- tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 1e4);
186
+ tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 10000n as Satoshi);
184
187
 
185
188
  // {Alice's signature} OP_TRUE
186
- const signatureHash = tx.hashForSignature(0, p2sh.redeem!.output!, hashType);
189
+ const signatureHash = tx.hashForSignature(0, p2sh.redeem!.output! as Script, hashType);
187
190
  const redeemScriptSig = bitcoin.payments.p2sh({
188
191
  network: regtest,
189
192
  redeem: {
@@ -196,7 +199,7 @@ describe('bitcoinjs-lib (transactions w/ CSV)', () => {
196
199
  ]),
197
200
  },
198
201
  }).input;
199
- tx.setInputScript(0, redeemScriptSig!);
202
+ tx.setInputScript(0, redeemScriptSig! as Script);
200
203
 
201
204
  await regtestUtils.broadcast(tx.toHex()).catch((err: unknown) => {
202
205
  assert.throws(() => {
@@ -228,10 +231,10 @@ describe('bitcoinjs-lib (transactions w/ CSV)', () => {
228
231
  const tx = new bitcoin.Transaction();
229
232
  tx.version = 2;
230
233
  tx.addInput(idToHash(unspent.txId), unspent.vout);
231
- tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 7e4);
234
+ tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 70000n as Satoshi);
232
235
 
233
236
  // OP_0 {Bob sig} {Charles sig} OP_TRUE OP_TRUE
234
- const signatureHash = tx.hashForSignature(0, p2sh.redeem!.output!, hashType);
237
+ const signatureHash = tx.hashForSignature(0, p2sh.redeem!.output! as Script, hashType);
235
238
  const redeemScriptSig = bitcoin.payments.p2sh({
236
239
  network: regtest,
237
240
  redeem: {
@@ -246,7 +249,7 @@ describe('bitcoinjs-lib (transactions w/ CSV)', () => {
246
249
  ]),
247
250
  },
248
251
  }).input;
249
- tx.setInputScript(0, redeemScriptSig!);
252
+ tx.setInputScript(0, redeemScriptSig! as Script);
250
253
 
251
254
  await regtestUtils.broadcast(tx.toHex());
252
255
 
@@ -281,10 +284,10 @@ describe('bitcoinjs-lib (transactions w/ CSV)', () => {
281
284
  const tx = new bitcoin.Transaction();
282
285
  tx.version = 2;
283
286
  tx.addInput(idToHash(unspent.txId), unspent.vout, sequence1); // Set sequence1 for input
284
- tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 7e4);
287
+ tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 70000n as Satoshi);
285
288
 
286
289
  // OP_0 {Bob sig} {Alice mediator sig} OP_FALSE OP_TRUE
287
- const signatureHash = tx.hashForSignature(0, p2sh.redeem!.output!, hashType);
290
+ const signatureHash = tx.hashForSignature(0, p2sh.redeem!.output! as Script, hashType);
288
291
  const redeemScriptSig = bitcoin.payments.p2sh({
289
292
  network: regtest,
290
293
  redeem: {
@@ -299,7 +302,7 @@ describe('bitcoinjs-lib (transactions w/ CSV)', () => {
299
302
  ]),
300
303
  },
301
304
  }).input;
302
- tx.setInputScript(0, redeemScriptSig!);
305
+ tx.setInputScript(0, redeemScriptSig! as Script);
303
306
 
304
307
  // Wait 2 blocks
305
308
  await regtestUtils.mine(2);
@@ -337,10 +340,10 @@ describe('bitcoinjs-lib (transactions w/ CSV)', () => {
337
340
  const tx = new bitcoin.Transaction();
338
341
  tx.version = 2;
339
342
  tx.addInput(idToHash(unspent.txId), unspent.vout, sequence2); // Set sequence2 for input
340
- tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 7e4);
343
+ tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 70000n as Satoshi);
341
344
 
342
345
  // {Alice mediator sig} OP_FALSE
343
- const signatureHash = tx.hashForSignature(0, p2sh.redeem!.output!, hashType);
346
+ const signatureHash = tx.hashForSignature(0, p2sh.redeem!.output! as Script, hashType);
344
347
  const redeemScriptSig = bitcoin.payments.p2sh({
345
348
  network: regtest,
346
349
  redeem: {
@@ -352,7 +355,7 @@ describe('bitcoinjs-lib (transactions w/ CSV)', () => {
352
355
  ]),
353
356
  },
354
357
  }).input;
355
- tx.setInputScript(0, redeemScriptSig!);
358
+ tx.setInputScript(0, redeemScriptSig! as Script);
356
359
 
357
360
  // Wait 5 blocks
358
361
  await regtestUtils.mine(5);
@@ -374,13 +377,13 @@ describe('bitcoinjs-lib (transactions w/ CSV)', () => {
374
377
  function csvGetFinalScripts(
375
378
  inputIndex: number,
376
379
  input: PsbtInput,
377
- script: Buffer,
380
+ script: Script,
378
381
  isSegwit: boolean,
379
382
  isP2SH: boolean,
380
383
  isP2WSH: boolean,
381
384
  ): {
382
- finalScriptSig: Buffer | undefined;
383
- finalScriptWitness: Buffer | undefined;
385
+ finalScriptSig: Script | undefined;
386
+ finalScriptWitness: Uint8Array | undefined;
384
387
  } {
385
388
  // Step 1: Check to make sure the meaningful script matches what you expect.
386
389
  const decompiled = bitcoin.script.decompile(script);
@@ -412,41 +415,11 @@ function csvGetFinalScripts(
412
415
  redeem: payment,
413
416
  });
414
417
 
415
- function witnessStackToScriptWitness(witness: Buffer[]): Buffer {
416
- let buffer = Buffer.allocUnsafe(0);
417
-
418
- function writeSlice(slice: Buffer): void {
419
- buffer = Buffer.concat([buffer, Buffer.from(slice)]);
420
- }
421
-
422
- function writeVarInt(i: number): void {
423
- const currentLen = buffer.length;
424
- const varintLen = varuint.encodingLength(i);
425
-
426
- buffer = Buffer.concat([buffer, Buffer.allocUnsafe(varintLen)]);
427
- varuint.encode(i, buffer, currentLen);
428
- }
429
-
430
- function writeVarSlice(slice: Buffer): void {
431
- writeVarInt(slice.length);
432
- writeSlice(slice);
433
- }
434
-
435
- function writeVector(vector: Buffer[]): void {
436
- writeVarInt(vector.length);
437
- vector.forEach(writeVarSlice);
438
- }
439
-
440
- writeVector(witness);
441
-
442
- return buffer;
443
- }
444
-
445
418
  return {
446
419
  finalScriptSig: payment.input,
447
420
  finalScriptWitness:
448
421
  payment.witness && payment.witness.length > 0
449
- ? witnessStackToScriptWitness(payment.witness)
422
+ ? bitcoin.witnessStackToScriptWitness(payment.witness)
450
423
  : undefined,
451
424
  };
452
425
  }
@@ -2,6 +2,8 @@ import { ECPairFactory } from 'ecpair';
2
2
  import * as ecc from 'tiny-secp256k1';
3
3
  import { describe, it } from 'vitest';
4
4
  import * as bitcoin from '../../src/index.js';
5
+ import { fromHex } from '../../src/index.js';
6
+ import type { Satoshi } from '../../src/index.js';
5
7
  import { regtestUtils } from './_regtest.js';
6
8
  import * as fs from 'node:fs';
7
9
 
@@ -15,20 +17,20 @@ async function buildAndSign(
15
17
  redeemScript: any,
16
18
  witnessScript: any,
17
19
  ): Promise<null> {
18
- const unspent = await regtestUtils.faucetComplex(prevOutput, 5e4);
20
+ const unspent = await regtestUtils.faucetComplex(Buffer.from(prevOutput), 5e4);
19
21
  const utx = await regtestUtils.fetch(unspent.txId);
20
22
 
21
23
  const psbt = new bitcoin.Psbt({ network: NETWORK })
22
24
  .addInput({
23
25
  hash: unspent.txId,
24
26
  index: unspent.vout,
25
- nonWitnessUtxo: Buffer.from(utx.txHex, 'hex'),
27
+ nonWitnessUtxo: fromHex(utx.txHex),
26
28
  ...(redeemScript ? { redeemScript } : {}),
27
29
  ...(witnessScript ? { witnessScript } : {}),
28
30
  })
29
31
  .addOutput({
30
32
  address: regtestUtils.RANDOM_ADDRESS,
31
- value: 2e4,
33
+ value: 20000n as Satoshi,
32
34
  });
33
35
 
34
36
  if (depends.signatures) {