@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
package/test/psbt.spec.ts CHANGED
@@ -3,14 +3,15 @@ import { BIP32Factory } from '@btc-vision/bip32';
3
3
  import * as ecc from 'tiny-secp256k1';
4
4
  import * as crypto from 'crypto';
5
5
  import { ECPairFactory } from 'ecpair';
6
- import { describe, it } from 'vitest';
6
+ import { beforeEach, describe, it } from 'vitest';
7
7
 
8
8
  import { convertScriptTree } from './payments.utils.js';
9
9
  import { LEAF_VERSION_TAPSCRIPT } from '../src/payments/bip341.js';
10
10
  import { tapTreeFromList, tapTreeToList } from '../src/psbt/bip371.js';
11
- import type { Taptree } from '../src/types.js';
11
+ import type { Taptree, Bytes32, Script, Satoshi, PublicKey, Signature, EccLib } from '../src/types.js';
12
12
  import { initEccLib, networks as NETWORKS, payments, Psbt } from '../src/index.js';
13
- import type { Signer, SignerAsync } from '../src/index.js';
13
+ import type { Signer, SignerAsync, HDSigner, HDSignerAsync, ValidateSigFunction } from '../src/index.js';
14
+ import { equals } from '../src/io/index.js';
14
15
 
15
16
  import preFixtures from './fixtures/psbt.json' with { type: 'json' };
16
17
  import taprootFixtures from './fixtures/p2tr.json' with { type: 'json' };
@@ -18,10 +19,10 @@ import taprootFixtures from './fixtures/p2tr.json' with { type: 'json' };
18
19
  const bip32 = BIP32Factory(ecc);
19
20
  const ECPair = ECPairFactory(ecc);
20
21
 
21
- const validator = (pubkey: Buffer, msghash: Buffer, signature: Buffer): boolean =>
22
+ const validator: ValidateSigFunction = (pubkey, msghash, signature): boolean =>
22
23
  ECPair.fromPublicKey(pubkey).verify(msghash, signature);
23
24
 
24
- const schnorrValidator = (pubkey: Buffer, msghash: Buffer, signature: Buffer): boolean =>
25
+ const schnorrValidator: ValidateSigFunction = (pubkey, msghash, signature): boolean =>
25
26
  ecc.verifySchnorr(msghash, pubkey, signature);
26
27
 
27
28
  const initBuffers = (object: any): typeof preFixtures =>
@@ -43,7 +44,7 @@ const upperCaseFirstLetter = (str: string): string => str.replace(/^./, (s) => s
43
44
  const toAsyncSigner = (signer: Signer): SignerAsync => {
44
45
  return {
45
46
  publicKey: signer.publicKey,
46
- sign: (hash: Buffer, lowerR: boolean | undefined): Promise<Buffer> => {
47
+ sign: (hash: Bytes32, lowerR: boolean | undefined): Promise<Signature> => {
47
48
  return new Promise((resolve, rejects): void => {
48
49
  setTimeout(() => {
49
50
  try {
@@ -59,8 +60,8 @@ const toAsyncSigner = (signer: Signer): SignerAsync => {
59
60
  };
60
61
  const failedAsyncSigner = (publicKey: Buffer): SignerAsync => {
61
62
  return <SignerAsync>{
62
- publicKey,
63
- sign: (__: Buffer): Promise<Buffer> => {
63
+ publicKey: publicKey as unknown as PublicKey,
64
+ sign: (__: Bytes32): Promise<Signature> => {
64
65
  return new Promise((_, reject): void => {
65
66
  setTimeout(() => {
66
67
  reject(new Error('sign failed'));
@@ -110,8 +111,9 @@ describe(`Psbt`, () => {
110
111
  psbt.addInput(input);
111
112
  }
112
113
  for (const output of f.outputs) {
113
- const script = Buffer.from(output.script, 'hex');
114
- psbt.addOutput({ ...output, script });
114
+ const script = Buffer.from(output.script, 'hex') as unknown as Script;
115
+ const value = BigInt(output.value) as Satoshi;
116
+ psbt.addOutput({ ...output, script, value });
115
117
  }
116
118
  assert.strictEqual(psbt.toBase64(), f.result);
117
119
  });
@@ -119,7 +121,7 @@ describe(`Psbt`, () => {
119
121
 
120
122
  fixtures.bip174.updater.forEach((f) => {
121
123
  it('Updates PSBT to the expected result', () => {
122
- if (f.isTaproot) initEccLib(ecc);
124
+ if (f.isTaproot) initEccLib(ecc as unknown as EccLib);
123
125
  const psbt = Psbt.fromBase64(f.psbt);
124
126
 
125
127
  for (const inputOrOutput of ['input', 'output']) {
@@ -138,7 +140,7 @@ describe(`Psbt`, () => {
138
140
 
139
141
  fixtures.bip174.signer.forEach((f) => {
140
142
  it('Signs PSBT to the expected result', () => {
141
- if (f.isTaproot) initEccLib(ecc);
143
+ if (f.isTaproot) initEccLib(ecc as unknown as EccLib);
142
144
  const psbt = Psbt.fromBase64(f.psbt);
143
145
 
144
146
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -168,17 +170,17 @@ describe(`Psbt`, () => {
168
170
 
169
171
  psbts[0].combine(psbts[1]);
170
172
 
171
- // Produces a different Base64 string due to implemetation specific key-value ordering.
173
+ // Produces a different Base64 string due to implementation specific key-value ordering.
172
174
  // That means this test will fail:
173
175
  // assert.strictEqual(psbts[0].toBase64(), f.result)
174
- // However, if we compare the actual PSBT properties we can see they are logically identical:
175
- assert.deepStrictEqual(psbts[0], Psbt.fromBase64(f.result));
176
+ // Compare the serialized PSBT hex instead - this is deterministic
177
+ assert.strictEqual(psbts[0].toHex(), Psbt.fromBase64(f.result).toHex());
176
178
  });
177
179
  });
178
180
 
179
181
  fixtures.bip174.finalizer.forEach((f) => {
180
182
  it('Finalizes inputs and gives the expected PSBT', () => {
181
- if (f.isTaproot) initEccLib(ecc);
183
+ if (f.isTaproot) initEccLib(ecc as unknown as EccLib);
182
184
  const psbt = Psbt.fromBase64(f.psbt);
183
185
 
184
186
  psbt.finalizeAllInputs();
@@ -228,7 +230,7 @@ describe(`Psbt`, () => {
228
230
  describe('signInputAsync', () => {
229
231
  fixtures.signInput.checks.forEach((f) => {
230
232
  it(f.description, async () => {
231
- if (f.isTaproot) initEccLib(ecc);
233
+ if (f.isTaproot) initEccLib(ecc as unknown as EccLib);
232
234
  if (f.shouldSign) {
233
235
  const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt);
234
236
  await assert.doesNotReject(async () => {
@@ -289,7 +291,7 @@ describe(`Psbt`, () => {
289
291
  describe('signInput', () => {
290
292
  fixtures.signInput.checks.forEach((f) => {
291
293
  it(f.description, () => {
292
- if (f.isTaproot) initEccLib(ecc);
294
+ if (f.isTaproot) initEccLib(ecc as unknown as EccLib);
293
295
  if (f.shouldSign) {
294
296
  const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt);
295
297
  assert.doesNotThrow(() => {
@@ -322,7 +324,7 @@ describe(`Psbt`, () => {
322
324
  fixtures.signInput.checks.forEach((f) => {
323
325
  if (f.description === 'checks the input exists') return;
324
326
  it(f.description, async () => {
325
- if (f.isTaproot) initEccLib(ecc);
327
+ if (f.isTaproot) initEccLib(ecc as unknown as EccLib);
326
328
  if (f.shouldSign) {
327
329
  const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt);
328
330
  await assert.doesNotReject(async () => {
@@ -353,7 +355,7 @@ describe(`Psbt`, () => {
353
355
  fixtures.signInput.checks.forEach((f) => {
354
356
  if (f.description === 'checks the input exists') return;
355
357
  it(f.description, () => {
356
- if (f.isTaproot) initEccLib(ecc);
358
+ if (f.isTaproot) initEccLib(ecc as unknown as EccLib);
357
359
  if (f.shouldSign) {
358
360
  const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt);
359
361
  assert.doesNotThrow(() => {
@@ -388,7 +390,7 @@ describe(`Psbt`, () => {
388
390
  await assert.doesNotReject(async () => {
389
391
  await psbtThatShouldsign.signInputHDAsync(
390
392
  f.shouldSign.inputToCheck,
391
- bip32.fromBase58(f.shouldSign.xprv),
393
+ bip32.fromBase58(f.shouldSign.xprv) as unknown as HDSigner,
392
394
  (f.shouldSign as any).sighashTypes || undefined,
393
395
  );
394
396
  });
@@ -399,7 +401,7 @@ describe(`Psbt`, () => {
399
401
  await assert.rejects(async () => {
400
402
  await psbtThatShouldThrow.signInputHDAsync(
401
403
  f.shouldThrow.inputToCheck,
402
- bip32.fromBase58(f.shouldThrow.xprv),
404
+ bip32.fromBase58(f.shouldThrow.xprv) as unknown as HDSigner,
403
405
  (f.shouldThrow as any).sighashTypes || undefined,
404
406
  );
405
407
  }, new RegExp(f.shouldThrow.errorMessage));
@@ -421,7 +423,7 @@ describe(`Psbt`, () => {
421
423
  assert.doesNotThrow(() => {
422
424
  psbtThatShouldsign.signInputHD(
423
425
  f.shouldSign.inputToCheck,
424
- bip32.fromBase58(f.shouldSign.xprv),
426
+ bip32.fromBase58(f.shouldSign.xprv) as unknown as HDSigner,
425
427
  (f.shouldSign as any).sighashTypes || undefined,
426
428
  );
427
429
  });
@@ -432,7 +434,7 @@ describe(`Psbt`, () => {
432
434
  assert.throws(() => {
433
435
  psbtThatShouldThrow.signInputHD(
434
436
  f.shouldThrow.inputToCheck,
435
- bip32.fromBase58(f.shouldThrow.xprv),
437
+ bip32.fromBase58(f.shouldThrow.xprv) as unknown as HDSigner,
436
438
  (f.shouldThrow as any).sighashTypes || undefined,
437
439
  );
438
440
  }, new RegExp(f.shouldThrow.errorMessage));
@@ -451,7 +453,7 @@ describe(`Psbt`, () => {
451
453
  const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt);
452
454
  await assert.doesNotReject(async () => {
453
455
  await psbtThatShouldsign.signAllInputsHDAsync(
454
- bip32.fromBase58(f.shouldSign.xprv),
456
+ bip32.fromBase58(f.shouldSign.xprv) as unknown as HDSigner,
455
457
  (f.shouldSign as any).sighashTypes || undefined,
456
458
  );
457
459
  });
@@ -461,7 +463,7 @@ describe(`Psbt`, () => {
461
463
  const psbtThatShouldThrow = Psbt.fromBase64(f.shouldThrow.psbt);
462
464
  await assert.rejects(async () => {
463
465
  await psbtThatShouldThrow.signAllInputsHDAsync(
464
- bip32.fromBase58(f.shouldThrow.xprv),
466
+ bip32.fromBase58(f.shouldThrow.xprv) as unknown as HDSigner,
465
467
  (f.shouldThrow as any).sighashTypes || undefined,
466
468
  );
467
469
  }, new RegExp('No inputs were signed'));
@@ -480,7 +482,7 @@ describe(`Psbt`, () => {
480
482
  const psbtThatShouldsign = Psbt.fromBase64(f.shouldSign.psbt);
481
483
  assert.doesNotThrow(() => {
482
484
  psbtThatShouldsign.signAllInputsHD(
483
- bip32.fromBase58(f.shouldSign.xprv),
485
+ bip32.fromBase58(f.shouldSign.xprv) as unknown as HDSigner,
484
486
  (f.shouldSign as any).sighashTypes || undefined,
485
487
  );
486
488
  });
@@ -490,7 +492,7 @@ describe(`Psbt`, () => {
490
492
  const psbtThatShouldThrow = Psbt.fromBase64(f.shouldThrow.psbt);
491
493
  assert.throws(() => {
492
494
  psbtThatShouldThrow.signAllInputsHD(
493
- bip32.fromBase58(f.shouldThrow.xprv),
495
+ bip32.fromBase58(f.shouldThrow.xprv) as unknown as HDSigner,
494
496
  (f.shouldThrow as any).sighashTypes || undefined,
495
497
  );
496
498
  }, new RegExp('No inputs were signed'));
@@ -507,7 +509,7 @@ describe(`Psbt`, () => {
507
509
  const f = fixtures.finalizeInput.finalizeTapleafByHash;
508
510
  const psbt = Psbt.fromBase64(f.psbt);
509
511
 
510
- psbt.finalizeTaprootInput(f.index, Buffer.from(f.leafHash, 'hex'));
512
+ psbt.finalizeTaprootInput(f.index, Buffer.from(f.leafHash, 'hex') as unknown as Bytes32);
511
513
 
512
514
  assert.strictEqual(psbt.toBase64(), f.result);
513
515
  });
@@ -517,7 +519,7 @@ describe(`Psbt`, () => {
517
519
  const psbt = Psbt.fromBase64(f.psbt);
518
520
 
519
521
  assert.throws(() => {
520
- psbt.finalizeTaprootInput(f.index, Buffer.from(f.leafHash, 'hex').reverse());
522
+ psbt.finalizeTaprootInput(f.index, Buffer.from(f.leafHash, 'hex').reverse() as unknown as Bytes32);
521
523
  }, new RegExp('Can not finalize taproot input #0. Signature for tapleaf script not found.'));
522
524
  });
523
525
 
@@ -555,8 +557,8 @@ describe(`Psbt`, () => {
555
557
  }, new RegExp('No script found for input #0'));
556
558
  psbt.updateInput(0, {
557
559
  witnessUtxo: {
558
- script: Buffer.from('0014d85c2b71d0060b09c9886aeb815e50991dda124d', 'hex'),
559
- value: 2e5,
560
+ script: Buffer.from('0014d85c2b71d0060b09c9886aeb815e50991dda124d', 'hex') as unknown as Script,
561
+ value: 200000n as Satoshi,
560
562
  },
561
563
  });
562
564
  assert.throws(() => {
@@ -609,9 +611,15 @@ describe(`Psbt`, () => {
609
611
  describe('addOutput', () => {
610
612
  fixtures.addOutput.checks.forEach((f) => {
611
613
  it(f.description, () => {
612
- if (f.isTaproot) initEccLib(ecc);
614
+ if (f.isTaproot) initEccLib(ecc as unknown as EccLib);
613
615
  const psbt = f.psbt ? Psbt.fromBase64(f.psbt) : new Psbt();
614
616
 
617
+ // Convert numeric value to bigint for valid outputs
618
+ const outputData =
619
+ f.outputData && typeof f.outputData.value === 'number'
620
+ ? { ...f.outputData, value: BigInt(f.outputData.value) }
621
+ : f.outputData;
622
+
615
623
  if (f.exception) {
616
624
  assert.throws(() => {
617
625
  psbt.addOutput(f.outputData as any);
@@ -621,13 +629,13 @@ describe(`Psbt`, () => {
621
629
  }, new RegExp(f.exception));
622
630
  } else {
623
631
  assert.doesNotThrow(() => {
624
- psbt.addOutput(f.outputData as any);
632
+ psbt.addOutput(outputData as any);
625
633
  });
626
634
  if (f.result) {
627
635
  assert.strictEqual(psbt.toBase64(), f.result);
628
636
  }
629
637
  assert.doesNotThrow(() => {
630
- psbt.addOutputs([f.outputData as any]);
638
+ psbt.addOutputs([outputData as any]);
631
639
  });
632
640
  }
633
641
  });
@@ -684,24 +692,24 @@ describe(`Psbt`, () => {
684
692
  describe('getInputType', () => {
685
693
  const key = ECPair.makeRandom();
686
694
  const { publicKey } = key;
687
- const p2wpkhPub = (pubkey: Buffer): Buffer =>
695
+ const p2wpkhPub = (pubkey: Buffer): Script =>
688
696
  payments.p2wpkh({
689
- pubkey,
697
+ pubkey: pubkey as unknown as PublicKey,
690
698
  }).output!;
691
- const p2pkhPub = (pubkey: Buffer): Buffer =>
699
+ const p2pkhPub = (pubkey: Buffer): Script =>
692
700
  payments.p2pkh({
693
- pubkey,
701
+ pubkey: pubkey as unknown as PublicKey,
694
702
  }).output!;
695
- const p2shOut = (output: Buffer): Buffer =>
703
+ const p2shOut = (output: Uint8Array): Script =>
696
704
  payments.p2sh({
697
- redeem: { output },
705
+ redeem: { output: output as Script },
698
706
  }).output!;
699
- const p2wshOut = (output: Buffer): Buffer =>
707
+ const p2wshOut = (output: Uint8Array): Script =>
700
708
  payments.p2wsh({
701
- redeem: { output },
709
+ redeem: { output: output as Script },
702
710
  }).output!;
703
- const p2shp2wshOut = (output: Buffer): Buffer => p2shOut(p2wshOut(output));
704
- const noOuter = (output: Buffer): Buffer => output;
711
+ const p2shp2wshOut = (output: Uint8Array): Script => p2shOut(p2wshOut(output));
712
+ const noOuter = (output: Uint8Array): Script => output as Script;
705
713
 
706
714
  function getInputTypeTest({
707
715
  innerScript,
@@ -717,13 +725,13 @@ describe(`Psbt`, () => {
717
725
  index: 0,
718
726
  witnessUtxo: {
719
727
  script: outerScript(innerScript(publicKey)),
720
- value: 2e3,
728
+ value: 2000n,
721
729
  },
722
730
  ...(redeemGetter ? { redeemScript: redeemGetter(publicKey) } : {}),
723
731
  ...(witnessGetter ? { witnessScript: witnessGetter(publicKey) } : {}),
724
732
  }).addOutput({
725
- script: Buffer.from('0014d85c2b71d0060b09c9886aeb815e50991dda124d'),
726
- value: 1800,
733
+ script: Buffer.from('0014d85c2b71d0060b09c9886aeb815e50991dda124d', 'hex') as unknown as Script,
734
+ value: 1800n as Satoshi,
727
735
  });
728
736
  if (finalize) psbt.signInput(0, key).finalizeInput(0);
729
737
  const type = psbt.getInputType(0);
@@ -771,7 +779,7 @@ describe(`Psbt`, () => {
771
779
  {
772
780
  innerScript: p2pkhPub,
773
781
  outerScript: p2shp2wshOut,
774
- redeemGetter: (pk: Buffer): Buffer => p2wshOut(p2pkhPub(pk)),
782
+ redeemGetter: (pk: Buffer): Script => p2wshOut(p2pkhPub(pk)),
775
783
  witnessGetter: p2pkhPub,
776
784
  expectedType: 'p2sh-p2wsh-pubkeyhash',
777
785
  },
@@ -800,8 +808,8 @@ describe(`Psbt`, () => {
800
808
  },
801
809
  ],
802
810
  });
803
- assert.strictEqual(psbt.inputHasHDKey(0, root), true);
804
- assert.strictEqual(psbt.inputHasHDKey(0, root2), false);
811
+ assert.strictEqual(psbt.inputHasHDKey(0, root as unknown as HDSigner), true);
812
+ assert.strictEqual(psbt.inputHasHDKey(0, root2 as unknown as HDSigner), false);
805
813
  });
806
814
  });
807
815
 
@@ -822,9 +830,9 @@ describe(`Psbt`, () => {
822
830
 
823
831
  psbt.updateInput(0, {
824
832
  witnessUtxo: {
825
- value: 1337,
833
+ value: 1337n as Satoshi,
826
834
  script: payments.p2sh({
827
- redeem: { output: Buffer.from([0x51]) },
835
+ redeem: { output: Buffer.from([0x51]) as unknown as Script },
828
836
  }).output!,
829
837
  },
830
838
  });
@@ -837,9 +845,9 @@ describe(`Psbt`, () => {
837
845
 
838
846
  psbt.updateInput(0, {
839
847
  witnessUtxo: {
840
- value: 1337,
848
+ value: 1337n as Satoshi,
841
849
  script: payments.p2wsh({
842
- redeem: { output: Buffer.from([0x51]) },
850
+ redeem: { output: Buffer.from([0x51]) as unknown as Script },
843
851
  }).output!,
844
852
  },
845
853
  });
@@ -859,15 +867,15 @@ describe(`Psbt`, () => {
859
867
 
860
868
  psbt.updateInput(0, {
861
869
  witnessUtxo: {
862
- value: 1337,
870
+ value: 1337n as Satoshi,
863
871
  script: payments.p2sh({
864
872
  redeem: payments.p2wsh({
865
- redeem: { output: scriptWithPubkey },
873
+ redeem: { output: scriptWithPubkey as unknown as Script },
866
874
  }),
867
875
  }).output!,
868
876
  },
869
877
  redeemScript: payments.p2wsh({
870
- redeem: { output: scriptWithPubkey },
878
+ redeem: { output: scriptWithPubkey as unknown as Script },
871
879
  }).output!,
872
880
  });
873
881
 
@@ -896,8 +904,8 @@ describe(`Psbt`, () => {
896
904
  hash: '0000000000000000000000000000000000000000000000000000000000000000',
897
905
  index: 0,
898
906
  }).addOutput({
899
- script: Buffer.from('0014000102030405060708090a0b0c0d0e0f00010203', 'hex'),
900
- value: 2000,
907
+ script: Buffer.from('0014000102030405060708090a0b0c0d0e0f00010203', 'hex') as unknown as Script,
908
+ value: 2000n as Satoshi,
901
909
  bip32Derivation: [
902
910
  {
903
911
  masterFingerprint: Buffer.from(root.fingerprint),
@@ -906,8 +914,8 @@ describe(`Psbt`, () => {
906
914
  },
907
915
  ],
908
916
  });
909
- assert.strictEqual(psbt.outputHasHDKey(0, root), true);
910
- assert.strictEqual(psbt.outputHasHDKey(0, root2), false);
917
+ assert.strictEqual(psbt.outputHasHDKey(0, root as unknown as HDSigner), true);
918
+ assert.strictEqual(psbt.outputHasHDKey(0, root2 as unknown as HDSigner), false);
911
919
  });
912
920
  });
913
921
 
@@ -928,32 +936,32 @@ describe(`Psbt`, () => {
928
936
  index: 0,
929
937
  }).addOutput({
930
938
  script: payments.p2sh({
931
- redeem: { output: Buffer.from([0x51]) },
939
+ redeem: { output: Buffer.from([0x51]) as unknown as Script },
932
940
  }).output!,
933
- value: 1337,
941
+ value: 1337n as Satoshi,
934
942
  });
935
943
 
936
944
  assert.throws(() => {
937
945
  psbt.outputHasPubkey(0, testPubkey);
938
946
  }, new RegExp('scriptPubkey is P2SH but redeemScript missing'));
939
947
 
940
- (psbt as any).__CACHE.__TX.outs[0].script = payments.p2wsh({
941
- redeem: { output: Buffer.from([0x51]) },
948
+ (psbt as any).__CACHE.tx.outs[0].script = payments.p2wsh({
949
+ redeem: { output: Buffer.from([0x51]) as unknown as Script },
942
950
  }).output!;
943
951
 
944
952
  assert.throws(() => {
945
953
  psbt.outputHasPubkey(0, testPubkey);
946
954
  }, new RegExp('scriptPubkey or redeemScript is P2WSH but witnessScript missing'));
947
955
 
948
- (psbt as any).__CACHE.__TX.outs[0].script = payments.p2sh({
956
+ (psbt as any).__CACHE.tx.outs[0].script = payments.p2sh({
949
957
  redeem: payments.p2wsh({
950
- redeem: { output: scriptWithPubkey },
958
+ redeem: { output: scriptWithPubkey as unknown as Script },
951
959
  }),
952
960
  }).output!;
953
961
 
954
962
  psbt.updateOutput(0, {
955
963
  redeemScript: payments.p2wsh({
956
- redeem: { output: scriptWithPubkey },
964
+ redeem: { output: scriptWithPubkey as unknown as Script },
957
965
  }).output!,
958
966
  });
959
967
 
@@ -973,7 +981,7 @@ describe(`Psbt`, () => {
973
981
 
974
982
  psbt.updateOutput(0, {
975
983
  redeemScript: payments.p2wsh({
976
- redeem: { output: scriptWithPubkey },
984
+ redeem: { output: scriptWithPubkey as unknown as Script },
977
985
  }).output!,
978
986
  });
979
987
 
@@ -995,7 +1003,7 @@ describe(`Psbt`, () => {
995
1003
  assert.strictEqual(clone.toBase64(), psbt.toBase64());
996
1004
  assert.strictEqual(clone.toBase64(), notAClone.toBase64());
997
1005
  assert.strictEqual(psbt.toBase64(), notAClone.toBase64());
998
- (psbt as any).__CACHE.__TX.version |= 0xff0000;
1006
+ (psbt as any).__CACHE.tx.version |= 0xff0000;
999
1007
  assert.notStrictEqual(clone.toBase64(), psbt.toBase64());
1000
1008
  assert.notStrictEqual(clone.toBase64(), notAClone.toBase64());
1001
1009
  assert.strictEqual(psbt.toBase64(), notAClone.toBase64());
@@ -1038,13 +1046,13 @@ describe(`Psbt`, () => {
1038
1046
  describe('validateSignaturesOfTapKeyInput', () => {
1039
1047
  const f = fixtures.validateSignaturesOfTapKeyInput;
1040
1048
  it('Correctly validates all signatures', () => {
1041
- initEccLib(ecc);
1049
+ initEccLib(ecc as unknown as EccLib);
1042
1050
  const psbt = Psbt.fromBase64(f.psbt);
1043
1051
  assert.strictEqual(psbt.validateSignaturesOfInput(f.index, schnorrValidator), true);
1044
1052
  });
1045
1053
 
1046
1054
  it('Correctly validates a signature against a pubkey', () => {
1047
- initEccLib(ecc);
1055
+ initEccLib(ecc as unknown as EccLib);
1048
1056
  const psbt = Psbt.fromBase64(f.psbt);
1049
1057
  assert.strictEqual(
1050
1058
  psbt.validateSignaturesOfInput(f.index, schnorrValidator, f.pubkey as any),
@@ -1059,13 +1067,13 @@ describe(`Psbt`, () => {
1059
1067
  describe('validateSignaturesOfTapScriptInput', () => {
1060
1068
  const f = fixtures.validateSignaturesOfTapScriptInput;
1061
1069
  it('Correctly validates all signatures', () => {
1062
- initEccLib(ecc);
1070
+ initEccLib(ecc as unknown as EccLib);
1063
1071
  const psbt = Psbt.fromBase64(f.psbt);
1064
1072
  assert.strictEqual(psbt.validateSignaturesOfInput(f.index, schnorrValidator), true);
1065
1073
  });
1066
1074
 
1067
1075
  it('Correctly validates a signature against a pubkey', () => {
1068
- initEccLib(ecc);
1076
+ initEccLib(ecc as unknown as EccLib);
1069
1077
  const psbt = Psbt.fromBase64(f.psbt);
1070
1078
  assert.strictEqual(
1071
1079
  psbt.validateSignaturesOfInput(f.index, schnorrValidator, f.pubkey as any),
@@ -1129,7 +1137,7 @@ describe(`Psbt`, () => {
1129
1137
  }));
1130
1138
 
1131
1139
  assert.throws(() => {
1132
- tapTreeToList(tree as Taptree);
1140
+ tapTreeToList(tree as unknown as Taptree);
1133
1141
  }, new RegExp('Cannot convert taptree to tapleaf list. Expecting a tapree structure.'));
1134
1142
  });
1135
1143
  });
@@ -1146,7 +1154,7 @@ describe(`Psbt`, () => {
1146
1154
  psbt.finalizeAllInputs();
1147
1155
 
1148
1156
  assert.strictEqual(psbt.getFeeRate(), f.fee);
1149
- (psbt as any).__CACHE.__FEE_RATE = undefined;
1157
+ (psbt as any).__CACHE.feeRate = undefined;
1150
1158
  assert.strictEqual(psbt.getFeeRate(), f.fee);
1151
1159
  });
1152
1160
  });
@@ -1171,7 +1179,7 @@ describe(`Psbt`, () => {
1171
1179
  });
1172
1180
  psbt.addOutput({
1173
1181
  address: '1KRMKfeZcmosxALVYESdPNez1AP1mEtywp',
1174
- value: 80000,
1182
+ value: 80000n as Satoshi,
1175
1183
  });
1176
1184
  psbt.signInput(0, alice);
1177
1185
  assert.throws(() => {
@@ -1205,17 +1213,17 @@ describe(`Psbt`, () => {
1205
1213
  ),
1206
1214
  );
1207
1215
  assert.strictEqual(psbt instanceof Psbt, true);
1208
- assert.ok((psbt as any).__CACHE.__TX);
1216
+ assert.ok((psbt as any).__CACHE.tx);
1209
1217
  });
1210
1218
  it('fromBase64 returns Psbt type (not base class)', () => {
1211
1219
  const psbt = Psbt.fromBase64('cHNidP8BAAoBAAAAAAAAAAAAAAAA');
1212
1220
  assert.strictEqual(psbt instanceof Psbt, true);
1213
- assert.ok((psbt as any).__CACHE.__TX);
1221
+ assert.ok((psbt as any).__CACHE.tx);
1214
1222
  });
1215
1223
  it('fromHex returns Psbt type (not base class)', () => {
1216
1224
  const psbt = Psbt.fromHex('70736274ff01000a01000000000000000000000000');
1217
1225
  assert.strictEqual(psbt instanceof Psbt, true);
1218
- assert.ok((psbt as any).__CACHE.__TX);
1226
+ assert.ok((psbt as any).__CACHE.tx);
1219
1227
  });
1220
1228
  });
1221
1229
 
@@ -1227,7 +1235,7 @@ describe(`Psbt`, () => {
1227
1235
 
1228
1236
  // Cache is empty
1229
1237
  assert.strictEqual(
1230
- (psbt as any).__CACHE.__NON_WITNESS_UTXO_BUF_CACHE[index],
1238
+ (psbt as any).__CACHE.nonWitnessUtxoBufCache[index],
1231
1239
  undefined,
1232
1240
  );
1233
1241
 
@@ -1236,15 +1244,18 @@ describe(`Psbt`, () => {
1236
1244
  nonWitnessUtxo: f.nonWitnessUtxo as any,
1237
1245
  });
1238
1246
  const value = psbt.data.inputs[index].nonWitnessUtxo;
1239
- assert.ok((psbt as any).__CACHE.__NON_WITNESS_UTXO_BUF_CACHE[index].equals(value));
1247
+ assert.ok(equals((psbt as any).__CACHE.nonWitnessUtxoBufCache[index], value));
1240
1248
  assert.ok(
1241
- (psbt as any).__CACHE.__NON_WITNESS_UTXO_BUF_CACHE[index].equals(f.nonWitnessUtxo),
1249
+ equals(
1250
+ (psbt as any).__CACHE.nonWitnessUtxoBufCache[index],
1251
+ f.nonWitnessUtxo as any,
1252
+ ),
1242
1253
  );
1243
1254
 
1244
1255
  // Cache is rebuilt from internal transaction object when cleared
1245
- psbt.data.inputs[index].nonWitnessUtxo = Buffer.from([1, 2, 3]);
1246
- (psbt as any).__CACHE.__NON_WITNESS_UTXO_BUF_CACHE[index] = undefined;
1247
- assert.ok((psbt as any).data.inputs[index].nonWitnessUtxo.equals(value));
1256
+ psbt.data.inputs[index].nonWitnessUtxo = new Uint8Array([1, 2, 3]);
1257
+ (psbt as any).__CACHE.nonWitnessUtxoBufCache[index] = undefined;
1258
+ assert.ok(equals((psbt as any).data.inputs[index].nonWitnessUtxo!, value!));
1248
1259
  });
1249
1260
  });
1250
1261
 
@@ -1253,34 +1264,34 @@ describe(`Psbt`, () => {
1253
1264
  const psbt = new Psbt();
1254
1265
 
1255
1266
  assert.strictEqual(psbt.version, 2);
1256
- assert.strictEqual(psbt.version, (psbt as any).__CACHE.__TX.version);
1267
+ assert.strictEqual(psbt.version, (psbt as any).__CACHE.tx.version);
1257
1268
 
1258
1269
  psbt.version = 1;
1259
1270
  assert.strictEqual(psbt.version, 1);
1260
- assert.strictEqual(psbt.version, (psbt as any).__CACHE.__TX.version);
1271
+ assert.strictEqual(psbt.version, (psbt as any).__CACHE.tx.version);
1261
1272
  });
1262
1273
 
1263
1274
  it('.locktime is exposed and is settable', () => {
1264
1275
  const psbt = new Psbt();
1265
1276
 
1266
1277
  assert.strictEqual(psbt.locktime, 0);
1267
- assert.strictEqual(psbt.locktime, (psbt as any).__CACHE.__TX.locktime);
1278
+ assert.strictEqual(psbt.locktime, (psbt as any).__CACHE.tx.locktime);
1268
1279
 
1269
1280
  psbt.locktime = 123;
1270
1281
  assert.strictEqual(psbt.locktime, 123);
1271
- assert.strictEqual(psbt.locktime, (psbt as any).__CACHE.__TX.locktime);
1282
+ assert.strictEqual(psbt.locktime, (psbt as any).__CACHE.tx.locktime);
1272
1283
  });
1273
1284
 
1274
1285
  it('.txInputs is exposed as a readonly clone', () => {
1275
1286
  const psbt = new Psbt();
1276
- const hash = Buffer.alloc(32);
1287
+ const hash = Buffer.alloc(32) as unknown as Bytes32;
1277
1288
  const index = 0;
1278
1289
  psbt.addInput({ hash, index });
1279
1290
 
1280
1291
  const input = psbt.txInputs[0];
1281
- const internalInput = (psbt as any).__CACHE.__TX.ins[0];
1292
+ const internalInput = (psbt as any).__CACHE.tx.ins[0];
1282
1293
 
1283
- assert.ok(input.hash.equals(internalInput.hash));
1294
+ assert.ok(equals(input.hash, internalInput.hash));
1284
1295
  assert.strictEqual(input.index, internalInput.index);
1285
1296
  assert.strictEqual(input.sequence, internalInput.sequence);
1286
1297
 
@@ -1288,7 +1299,7 @@ describe(`Psbt`, () => {
1288
1299
  input.index = 123;
1289
1300
  input.sequence = 123;
1290
1301
 
1291
- assert.ok(!input.hash.equals(internalInput.hash));
1302
+ assert.ok(!equals(input.hash, internalInput.hash));
1292
1303
  assert.notEqual(input.index, internalInput.index);
1293
1304
  assert.notEqual(input.sequence, internalInput.sequence);
1294
1305
  });
@@ -1296,21 +1307,21 @@ describe(`Psbt`, () => {
1296
1307
  it('.txOutputs is exposed as a readonly clone', () => {
1297
1308
  const psbt = new Psbt();
1298
1309
  const address = '1LukeQU5jwebXbMLDVydeH4vFSobRV9rkj';
1299
- const value = 100000;
1310
+ const value = 100000n as Satoshi;
1300
1311
  psbt.addOutput({ address, value });
1301
1312
 
1302
1313
  const output = psbt.txOutputs[0];
1303
- const internalInput = (psbt as any).__CACHE.__TX.outs[0];
1314
+ const internalInput = (psbt as any).__CACHE.tx.outs[0];
1304
1315
 
1305
1316
  assert.strictEqual(output.address, address);
1306
1317
 
1307
- assert.ok(output.script.equals(internalInput.script));
1318
+ assert.ok(equals(output.script, internalInput.script));
1308
1319
  assert.strictEqual(output.value, internalInput.value);
1309
1320
 
1310
1321
  output.script[0] = 123;
1311
- output.value = 123;
1322
+ output.value = 123n;
1312
1323
 
1313
- assert.ok(!output.script.equals(internalInput.script));
1324
+ assert.ok(!equals(output.script, internalInput.script));
1314
1325
  assert.notEqual(output.value, internalInput.value);
1315
1326
  });
1316
1327
  });