@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
@@ -3,9 +3,10 @@ import { BIP32Factory } from '@btc-vision/bip32';
3
3
  import * as bip39 from 'bip39';
4
4
  import * as ecc from 'tiny-secp256k1';
5
5
  import { describe, it } from 'vitest';
6
- import { regtestUtils } from './_regtest.js';
6
+ import { regtestUtils, broadcastAndVerify } from './_regtest.js';
7
7
  import * as bitcoin from '../../src/index.js';
8
- import type { PsbtInput, TapLeaf, TapLeafScript, Taptree } from '../../src/index.js';
8
+ import { toHex, fromHex, concat } from '../../src/index.js';
9
+ import type { PsbtInput, TapLeaf, TapLeafScript, Taptree, XOnlyPublicKey, PublicKey, Satoshi, Bytes32, EccLib } from '../../src/index.js';
9
10
  import { LEAF_VERSION_TAPSCRIPT } from '../../src/payments/bip341.js';
10
11
  import { tapTreeFromList, tapTreeToList } from '../../src/psbt/bip371.js';
11
12
  import { witnessStackToScriptWitness } from '../../src/psbt/psbtutils.js';
@@ -14,7 +15,7 @@ import { toXOnly } from '../../src/pubkey.js';
14
15
  import rng from 'randombytes';
15
16
 
16
17
  const regtest = regtestUtils.network;
17
- bitcoin.initEccLib(ecc);
18
+ bitcoin.initEccLib(ecc as unknown as EccLib);
18
19
  const bip32 = BIP32Factory(ecc);
19
20
 
20
21
  describe('bitcoinjs-lib (transaction with taproot)', () => {
@@ -25,10 +26,9 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
25
26
  const xprv =
26
27
  'xprv9s21ZrQH143K3GJpoapnV8SFfukcVBSfeCficPSGfubmSFDxo1kuHnLisriDvSnRRuL2Qrg5ggqHKNVpxR86QEC8w35uxmGoggxtQTPvfUu';
27
28
  const path = `m/86'/0'/0'/0/0`; // Path to first child of receiving wallet on first account
28
- const internalPubkey = Buffer.from(
29
+ const internalPubkey = fromHex(
29
30
  'cc8a4bc64d897bddc5fbc2f670f7a8ba0b386779106cf1223c6fc5d7cd6fc115',
30
- 'hex',
31
- );
31
+ ) as XOnlyPublicKey;
32
32
  const expectedAddress = 'bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr';
33
33
 
34
34
  // Verify the above (Below is no different than other HD wallets)
@@ -37,7 +37,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
37
37
  assert.strictEqual(rootKey.toBase58(), xprv);
38
38
  const childNode = rootKey.derivePath(path);
39
39
  // Since internalKey is an xOnly pubkey, we drop the DER header byte
40
- const childNodeXOnlyPubkey = toXOnly(childNode.publicKey);
40
+ const childNodeXOnlyPubkey = toXOnly(childNode.publicKey as PublicKey);
41
41
  assert.deepEqual(childNodeXOnlyPubkey, internalPubkey);
42
42
 
43
43
  // This is new for taproot
@@ -59,18 +59,18 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
59
59
  // amount to send
60
60
  const sendAmount = amount - 1e4;
61
61
  // Send some sats to the address via faucet. Get the hash and index. (txid/vout)
62
- const { txId: hash, vout: index } = await regtestUtils.faucetComplex(output, amount);
62
+ const { txId: hash, vout: index } = await regtestUtils.faucetComplex(Buffer.from(output), amount);
63
63
  // Sent 420000 sats to taproot address
64
64
 
65
65
  const psbt = new bitcoin.Psbt({ network: regtest })
66
66
  .addInput({
67
67
  hash,
68
68
  index,
69
- witnessUtxo: { value: amount, script: output },
69
+ witnessUtxo: { value: BigInt(amount) as Satoshi as Satoshi, script: output },
70
70
  tapInternalKey: childNodeXOnlyPubkey,
71
71
  })
72
72
  .addOutput({
73
- value: sendAmount,
73
+ value: BigInt(sendAmount) as Satoshi as Satoshi,
74
74
  address: regtestUtils.RANDOM_ADDRESS,
75
75
  })
76
76
  .signInput(0, tweakedChildNode)
@@ -91,12 +91,12 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
91
91
  const p2pkhKey = bip32.fromSeed(rng(64), regtest);
92
92
 
93
93
  const { output } = bitcoin.payments.p2tr({
94
- internalPubkey: toXOnly(internalKey.publicKey),
94
+ internalPubkey: toXOnly(internalKey.publicKey as PublicKey),
95
95
  network: regtest,
96
96
  });
97
97
 
98
98
  const { output: p2pkhOutput } = bitcoin.payments.p2pkh({
99
- pubkey: p2pkhKey.publicKey,
99
+ pubkey: p2pkhKey.publicKey as PublicKey,
100
100
  network: regtest,
101
101
  });
102
102
 
@@ -105,46 +105,44 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
105
105
  // amount to send
106
106
  const sendAmount = amount - 1e4;
107
107
  // get faucet
108
- const unspent = await regtestUtils.faucetComplex(output!, amount);
108
+ const unspent = await regtestUtils.faucetComplex(Buffer.from(output!), amount);
109
109
 
110
110
  // non segwit utxo
111
- const p2pkhUnspent = await regtestUtils.faucetComplex(p2pkhOutput!, amount);
111
+ const p2pkhUnspent = await regtestUtils.faucetComplex(Buffer.from(p2pkhOutput!), amount);
112
112
  const utx = await regtestUtils.fetch(p2pkhUnspent.txId);
113
- const nonWitnessUtxo = Buffer.from(utx.txHex, 'hex');
113
+ const nonWitnessUtxo = fromHex(utx.txHex);
114
114
 
115
115
  const psbt = new bitcoin.Psbt({ network: regtest });
116
116
  psbt.addInput({
117
117
  hash: unspent.txId,
118
118
  index: 0,
119
- witnessUtxo: { value: amount, script: output! },
120
- tapInternalKey: toXOnly(internalKey.publicKey),
119
+ witnessUtxo: { value: BigInt(amount) as Satoshi, script: output! },
120
+ tapInternalKey: toXOnly(internalKey.publicKey as PublicKey),
121
121
  });
122
122
  psbt.addInput({ index: 0, hash: p2pkhUnspent.txId, nonWitnessUtxo });
123
123
 
124
124
  const sendInternalKey = bip32.fromSeed(rng(64), regtest);
125
- const sendPubKey = toXOnly(sendInternalKey.publicKey);
125
+ const sendPubKey = toXOnly(sendInternalKey.publicKey as PublicKey);
126
126
  const { address: sendAddress } = bitcoin.payments.p2tr({
127
127
  internalPubkey: sendPubKey,
128
128
  network: regtest,
129
129
  });
130
130
 
131
131
  psbt.addOutput({
132
- value: sendAmount,
132
+ value: BigInt(sendAmount) as Satoshi,
133
133
  address: sendAddress!,
134
134
  tapInternalKey: sendPubKey,
135
135
  });
136
136
 
137
137
  const tweakedSigner = internalKey.tweak(
138
- bitcoin.crypto.taggedHash('TapTweak', toXOnly(internalKey.publicKey)),
138
+ bitcoin.crypto.taggedHash('TapTweak', toXOnly(internalKey.publicKey as PublicKey)),
139
139
  );
140
140
  await psbt.signInputAsync(0, tweakedSigner);
141
141
  await psbt.signInputAsync(1, p2pkhKey);
142
142
 
143
143
  psbt.finalizeAllInputs();
144
144
  const tx = psbt.extractTransaction();
145
- const rawTx = tx.toBuffer();
146
-
147
- const hex = rawTx.toString('hex');
145
+ const hex = tx.toHex();
148
146
 
149
147
  await regtestUtils.broadcast(hex);
150
148
  await regtestUtils.verify({
@@ -159,7 +157,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
159
157
  const internalKey = bip32.fromSeed(rng(64), regtest);
160
158
  const leafKey = bip32.fromSeed(rng(64), regtest);
161
159
 
162
- const leafScriptAsm = `${toXOnly(leafKey.publicKey).toString('hex')} OP_CHECKSIG`;
160
+ const leafScriptAsm = `${toHex(toXOnly(leafKey.publicKey as PublicKey))} OP_CHECKSIG`;
163
161
  const leafScript = bitcoin.script.fromASM(leafScriptAsm);
164
162
 
165
163
  const scriptTree = {
@@ -167,7 +165,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
167
165
  };
168
166
 
169
167
  const { output, address, hash } = bitcoin.payments.p2tr({
170
- internalPubkey: toXOnly(internalKey.publicKey),
168
+ internalPubkey: toXOnly(internalKey.publicKey as PublicKey),
171
169
  scriptTree,
172
170
  network: regtest,
173
171
  });
@@ -177,31 +175,29 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
177
175
  // amount to send
178
176
  const sendAmount = amount - 1e4;
179
177
  // get faucet
180
- const unspent = await regtestUtils.faucetComplex(output!, amount);
178
+ const unspent = await regtestUtils.faucetComplex(Buffer.from(output!), amount);
181
179
 
182
180
  const psbt = new bitcoin.Psbt({ network: regtest });
183
181
  psbt.addInput({
184
182
  hash: unspent.txId,
185
183
  index: 0,
186
- witnessUtxo: { value: amount, script: output! },
187
- tapInternalKey: toXOnly(internalKey.publicKey),
188
- tapMerkleRoot: hash,
184
+ witnessUtxo: { value: BigInt(amount) as Satoshi, script: output! },
185
+ tapInternalKey: toXOnly(internalKey.publicKey as PublicKey),
186
+ ...(hash ? { tapMerkleRoot: hash } : {}),
189
187
  });
190
- psbt.addOutput({ value: sendAmount, address: address! });
188
+ psbt.addOutput({ value: BigInt(sendAmount) as Satoshi, address: address! });
191
189
 
192
190
  const tweakedSigner = internalKey.tweak(
193
191
  bitcoin.crypto.taggedHash(
194
192
  'TapTweak',
195
- Buffer.concat([toXOnly(internalKey.publicKey), hash!]),
193
+ concat([toXOnly(internalKey.publicKey as PublicKey), hash!]),
196
194
  ),
197
195
  );
198
196
  psbt.signInput(0, tweakedSigner);
199
197
 
200
198
  psbt.finalizeAllInputs();
201
199
  const tx = psbt.extractTransaction();
202
- const rawTx = tx.toBuffer();
203
-
204
- const hex = rawTx.toString('hex');
200
+ const hex = tx.toHex();
205
201
 
206
202
  await regtestUtils.broadcast(hex);
207
203
  await regtestUtils.verify({
@@ -216,7 +212,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
216
212
  const internalKey = bip32.fromSeed(rng(64), regtest);
217
213
  const leafKey = bip32.fromSeed(rng(64), regtest);
218
214
 
219
- const leafScriptAsm = `${toXOnly(leafKey.publicKey).toString('hex')} OP_CHECKSIG`;
215
+ const leafScriptAsm = `${toHex(toXOnly(leafKey.publicKey as PublicKey))} OP_CHECKSIG`;
220
216
  const leafScript = bitcoin.script.fromASM(leafScriptAsm);
221
217
 
222
218
  const scriptTree: Taptree = [
@@ -270,7 +266,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
270
266
  };
271
267
 
272
268
  const { output, witness } = bitcoin.payments.p2tr({
273
- internalPubkey: toXOnly(internalKey.publicKey),
269
+ internalPubkey: toXOnly(internalKey.publicKey as PublicKey),
274
270
  scriptTree,
275
271
  redeem,
276
272
  network: regtest,
@@ -281,26 +277,26 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
281
277
  // amount to send
282
278
  const sendAmount = amount - 1e4;
283
279
  // get faucet
284
- const unspent = await regtestUtils.faucetComplex(output!, amount);
280
+ const unspent = await regtestUtils.faucetComplex(Buffer.from(output!), amount);
285
281
 
286
282
  const psbt = new bitcoin.Psbt({ network: regtest });
287
283
  psbt.addInput({
288
284
  hash: unspent.txId,
289
285
  index: 0,
290
- witnessUtxo: { value: amount, script: output! },
286
+ witnessUtxo: { value: BigInt(amount) as Satoshi, script: output! },
291
287
  });
292
288
  psbt.updateInput(0, {
293
289
  tapLeafScript: [
294
290
  {
295
291
  leafVersion: redeem.redeemVersion,
296
292
  script: redeem.output,
297
- controlBlock: witness![witness!.length - 1],
293
+ controlBlock: witness![witness!.length - 1]!,
298
294
  },
299
295
  ],
300
296
  });
301
297
 
302
298
  const sendInternalKey = bip32.fromSeed(rng(64), regtest);
303
- const sendPubKey = toXOnly(sendInternalKey.publicKey);
299
+ const sendPubKey = toXOnly(sendInternalKey.publicKey as PublicKey);
304
300
  const { address: sendAddress } = bitcoin.payments.p2tr({
305
301
  internalPubkey: sendPubKey,
306
302
  scriptTree,
@@ -308,7 +304,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
308
304
  });
309
305
 
310
306
  psbt.addOutput({
311
- value: sendAmount,
307
+ value: BigInt(sendAmount) as Satoshi,
312
308
  address: sendAddress!,
313
309
  tapInternalKey: sendPubKey,
314
310
  tapTree: { leaves: tapTreeToList(scriptTree) },
@@ -317,8 +313,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
317
313
  psbt.signInput(0, leafKey);
318
314
  psbt.finalizeInput(0);
319
315
  const tx = psbt.extractTransaction();
320
- const rawTx = tx.toBuffer();
321
- const hex = rawTx.toString('hex');
316
+ const hex = tx.toHex();
322
317
 
323
318
  await regtestUtils.broadcast(hex);
324
319
  await regtestUtils.verify({
@@ -332,7 +327,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
332
327
  it('can create (and broadcast via 3PBP) a taproot script-path spend Transaction - OP_CHECKSEQUENCEVERIFY', async () => {
333
328
  const internalKey = bip32.fromSeed(rng(64), regtest);
334
329
  const leafKey = bip32.fromSeed(rng(64), regtest);
335
- const leafPubkey = toXOnly(leafKey.publicKey).toString('hex');
330
+ const leafPubkey = toHex(toXOnly(leafKey.publicKey as PublicKey));
336
331
 
337
332
  const leafScriptAsm = `OP_10 OP_CHECKSEQUENCEVERIFY OP_DROP ${leafPubkey} OP_CHECKSIG`;
338
333
  const leafScript = bitcoin.script.fromASM(leafScriptAsm);
@@ -360,7 +355,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
360
355
  };
361
356
 
362
357
  const { output, witness } = bitcoin.payments.p2tr({
363
- internalPubkey: toXOnly(internalKey.publicKey),
358
+ internalPubkey: toXOnly(internalKey.publicKey as PublicKey),
364
359
  scriptTree,
365
360
  redeem,
366
361
  network: regtest,
@@ -371,34 +366,34 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
371
366
  // amount to send
372
367
  const sendAmount = amount - 1e4;
373
368
  // get faucet
374
- const unspent = await regtestUtils.faucetComplex(output!, amount);
369
+ const unspent = await regtestUtils.faucetComplex(Buffer.from(output!), amount);
375
370
 
376
371
  const psbt = new bitcoin.Psbt({ network: regtest });
377
372
  psbt.addInput({
378
373
  hash: unspent.txId,
379
374
  index: 0,
380
375
  sequence: 10,
381
- witnessUtxo: { value: amount, script: output! },
376
+ witnessUtxo: { value: BigInt(amount) as Satoshi, script: output! },
382
377
  });
383
378
  psbt.updateInput(0, {
384
379
  tapLeafScript: [
385
380
  {
386
381
  leafVersion: redeem.redeemVersion,
387
382
  script: redeem.output,
388
- controlBlock: witness![witness!.length - 1],
383
+ controlBlock: witness![witness!.length - 1]!,
389
384
  },
390
385
  ],
391
386
  });
392
387
 
393
388
  const sendInternalKey = bip32.fromSeed(rng(64), regtest);
394
- const sendPubKey = toXOnly(sendInternalKey.publicKey);
389
+ const sendPubKey = toXOnly(sendInternalKey.publicKey as PublicKey);
395
390
  const { address: sendAddress } = bitcoin.payments.p2tr({
396
391
  internalPubkey: sendPubKey,
397
392
  scriptTree,
398
393
  network: regtest,
399
394
  });
400
395
 
401
- psbt.addOutput({ value: sendAmount, address: sendAddress! });
396
+ psbt.addOutput({ value: BigInt(sendAmount) as Satoshi, address: sendAddress! });
402
397
  // just to test that updateOutput works as expected
403
398
  psbt.updateOutput(0, {
404
399
  tapInternalKey: sendPubKey,
@@ -409,8 +404,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
409
404
 
410
405
  psbt.finalizeInput(0);
411
406
  const tx = psbt.extractTransaction();
412
- const rawTx = tx.toBuffer();
413
- const hex = rawTx.toString('hex');
407
+ const hex = tx.toHex();
414
408
 
415
409
  try {
416
410
  // broadcast before the confirmation period has expired
@@ -440,7 +434,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
440
434
  for (let i = 0; i < 3; i++) {
441
435
  const leafKey = bip32.fromSeed(rng(64), regtest);
442
436
  leafKeys.push(leafKey);
443
- leafPubkeys.push(toXOnly(leafKey.publicKey).toString('hex'));
437
+ leafPubkeys.push(toHex(toXOnly(leafKey.publicKey as PublicKey)));
444
438
  }
445
439
 
446
440
  const leafScriptAsm = `${leafPubkeys[2]} OP_CHECKSIG ${leafPubkeys[1]} OP_CHECKSIGADD ${leafPubkeys[0]} OP_CHECKSIGADD OP_3 OP_NUMEQUAL`;
@@ -470,7 +464,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
470
464
  };
471
465
 
472
466
  const { output, address, witness } = bitcoin.payments.p2tr({
473
- internalPubkey: toXOnly(internalKey.publicKey),
467
+ internalPubkey: toXOnly(internalKey.publicKey as PublicKey),
474
468
  scriptTree,
475
469
  redeem,
476
470
  network: regtest,
@@ -481,25 +475,25 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
481
475
  // amount to send
482
476
  const sendAmount = amount - 1e4;
483
477
  // get faucet
484
- const unspent = await regtestUtils.faucetComplex(output!, amount);
478
+ const unspent = await regtestUtils.faucetComplex(Buffer.from(output!), amount);
485
479
 
486
480
  const psbt = new bitcoin.Psbt({ network: regtest });
487
481
  psbt.addInput({
488
482
  hash: unspent.txId,
489
483
  index: 0,
490
- witnessUtxo: { value: amount, script: output! },
484
+ witnessUtxo: { value: BigInt(amount) as Satoshi, script: output! },
491
485
  });
492
486
  psbt.updateInput(0, {
493
487
  tapLeafScript: [
494
488
  {
495
489
  leafVersion: redeem.redeemVersion,
496
490
  script: redeem.output,
497
- controlBlock: witness![witness!.length - 1],
491
+ controlBlock: witness![witness!.length - 1]!,
498
492
  },
499
493
  ],
500
494
  });
501
495
 
502
- psbt.addOutput({ value: sendAmount, address: address! });
496
+ psbt.addOutput({ value: BigInt(sendAmount) as Satoshi, address: address! });
503
497
 
504
498
  // random order for signers
505
499
  psbt.signInput(0, leafKeys[1]);
@@ -508,8 +502,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
508
502
 
509
503
  psbt.finalizeInput(0);
510
504
  const tx = psbt.extractTransaction();
511
- const rawTx = tx.toBuffer();
512
- const hex = rawTx.toString('hex');
505
+ const hex = tx.toHex();
513
506
 
514
507
  await regtestUtils.broadcast(hex);
515
508
  await regtestUtils.verify({
@@ -540,7 +533,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
540
533
 
541
534
  const internalKey = bip32.fromSeed(rng(64), regtest);
542
535
  const { output, witness } = bitcoin.payments.p2tr({
543
- internalPubkey: toXOnly(internalKey.publicKey),
536
+ internalPubkey: toXOnly(internalKey.publicKey as PublicKey),
544
537
  scriptTree,
545
538
  redeem,
546
539
  network: regtest,
@@ -551,46 +544,46 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
551
544
  // amount to send
552
545
  const sendAmount = amount - 1e4;
553
546
  // get faucet
554
- const unspent = await regtestUtils.faucetComplex(output!, amount);
547
+ const unspent = await regtestUtils.faucetComplex(Buffer.from(output!), amount);
555
548
 
556
549
  const psbt = new bitcoin.Psbt({ network: regtest });
557
550
  psbt.addInput({
558
551
  hash: unspent.txId,
559
552
  index: 0,
560
- witnessUtxo: { value: amount, script: output! },
553
+ witnessUtxo: { value: BigInt(amount) as Satoshi, script: output! },
561
554
  });
562
555
 
563
556
  const tapLeafScript: TapLeafScript = {
564
557
  leafVersion: redeem.redeemVersion,
565
558
  script: redeem.output,
566
- controlBlock: witness![witness!.length - 1],
559
+ controlBlock: witness![witness!.length - 1]!,
567
560
  };
568
561
  psbt.updateInput(0, { tapLeafScript: [tapLeafScript] });
569
562
 
570
563
  const sendAddress = 'bcrt1pqknex3jwpsaatu5e5dcjw70nac3fr5k5y3hcxr4hgg6rljzp59nqs6a0vh';
571
564
  psbt.addOutput({
572
- value: sendAmount,
565
+ value: BigInt(sendAmount) as Satoshi,
573
566
  address: sendAddress,
574
567
  });
575
568
 
576
569
  const leafIndexFinalizerFn = buildLeafIndexFinalizer(tapLeafScript, leafIndex);
577
570
  psbt.finalizeInput(0, leafIndexFinalizerFn);
578
571
  const tx = psbt.extractTransaction();
579
- const rawTx = tx.toBuffer();
580
- const hex = rawTx.toString('hex');
581
-
582
- await regtestUtils.broadcast(hex);
583
- await regtestUtils.verify({
584
- txId: tx.getId(),
585
- address: sendAddress!,
586
- vout: 0,
587
- value: sendAmount,
588
- });
572
+ const hex = tx.toHex();
573
+
574
+ await broadcastAndVerify(hex, () =>
575
+ regtestUtils.verify({
576
+ txId: tx.getId(),
577
+ address: sendAddress!,
578
+ vout: 0,
579
+ value: sendAmount,
580
+ }),
581
+ );
589
582
  }
590
583
  });
591
584
 
592
585
  it('should fail validating invalid signatures for taproot (See issue #1931)', () => {
593
- const schnorrValidator = (pubkey: Buffer, msghash: Buffer, signature: Buffer) => {
586
+ const schnorrValidator = (pubkey: Uint8Array, msghash: Uint8Array, signature: Uint8Array) => {
594
587
  return ecc.verifySchnorr(msghash, pubkey, signature);
595
588
  };
596
589
 
@@ -614,7 +607,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
614
607
  });
615
608
 
616
609
  it('should succeed validating valid signatures for taproot (See issue #1934)', () => {
617
- const schnorrValidator = (pubkey: Buffer, msghash: Buffer, signature: Buffer) => {
610
+ const schnorrValidator = (pubkey: Uint8Array, msghash: Uint8Array, signature: Uint8Array) => {
618
611
  return ecc.verifySchnorr(msghash, pubkey, signature);
619
612
  };
620
613
 
@@ -639,20 +632,20 @@ function buildLeafIndexFinalizer(
639
632
  ): (
640
633
  inputIndex: number,
641
634
  _input: PsbtInput,
642
- _tapLeafHashToFinalize?: Buffer,
635
+ _tapLeafHashToFinalize?: Uint8Array,
643
636
  ) => {
644
- finalScriptWitness: Buffer | undefined;
637
+ finalScriptWitness: Uint8Array | undefined;
645
638
  } {
646
639
  return (
647
640
  inputIndex: number,
648
641
  _input: PsbtInput,
649
- _tapLeafHashToFinalize?: Buffer,
642
+ _tapLeafHashToFinalize?: Uint8Array,
650
643
  ): {
651
- finalScriptWitness: Buffer | undefined;
644
+ finalScriptWitness: Uint8Array | undefined;
652
645
  } => {
653
646
  try {
654
- const scriptSolution = [Buffer.from([leafIndex]), Buffer.from([leafIndex])];
655
- const witness: Buffer[] = [
647
+ const scriptSolution = [new Uint8Array([leafIndex]), new Uint8Array([leafIndex])];
648
+ const witness: Uint8Array[] = [
656
649
  ...scriptSolution,
657
650
  tapLeafScript.script,
658
651
  tapLeafScript.controlBlock,