@btc-vision/bitcoin 6.5.5 → 7.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (457) hide show
  1. package/AUDIT/README.md +9 -0
  2. package/HOW_TO_WRITE_GOOD_CODE.md +2436 -0
  3. package/SECURITY.md +27 -0
  4. package/benchmark/psbt-2000-inputs.bench.ts +178 -0
  5. package/benchmark/signing.bench.ts +147 -0
  6. package/browser/address.d.ts +56 -9
  7. package/browser/address.d.ts.map +1 -0
  8. package/browser/bech32utils.d.ts +9 -1
  9. package/browser/bech32utils.d.ts.map +1 -0
  10. package/browser/bip66.d.ts +11 -6
  11. package/browser/bip66.d.ts.map +1 -0
  12. package/browser/block.d.ts +117 -11
  13. package/browser/block.d.ts.map +1 -0
  14. package/browser/branded.d.ts +20 -0
  15. package/browser/branded.d.ts.map +1 -0
  16. package/browser/crypto/crypto.d.ts +1 -0
  17. package/browser/crypto/crypto.d.ts.map +1 -0
  18. package/browser/crypto.d.ts +46 -7
  19. package/browser/crypto.d.ts.map +1 -0
  20. package/browser/ecc/context.d.ts +129 -0
  21. package/browser/ecc/context.d.ts.map +1 -0
  22. package/browser/ecc/index.d.ts +11 -0
  23. package/browser/ecc/index.d.ts.map +1 -0
  24. package/browser/ecc/types.d.ts +128 -0
  25. package/browser/ecc/types.d.ts.map +1 -0
  26. package/browser/ecpair.d.ts +99 -0
  27. package/browser/errors.d.ts +124 -0
  28. package/browser/errors.d.ts.map +1 -0
  29. package/browser/index.d.ts +32 -5
  30. package/browser/index.d.ts.map +1 -0
  31. package/browser/index.js +12482 -101
  32. package/browser/io/BinaryReader.d.ts +276 -0
  33. package/browser/io/BinaryReader.d.ts.map +1 -0
  34. package/browser/io/BinaryWriter.d.ts +391 -0
  35. package/browser/io/BinaryWriter.d.ts.map +1 -0
  36. package/browser/io/MemoryPool.d.ts +220 -0
  37. package/browser/io/MemoryPool.d.ts.map +1 -0
  38. package/browser/io/base64.d.ts +13 -0
  39. package/browser/io/base64.d.ts.map +1 -0
  40. package/browser/io/hex.d.ts +67 -0
  41. package/browser/io/hex.d.ts.map +1 -0
  42. package/browser/io/index.d.ts +17 -0
  43. package/browser/io/index.d.ts.map +1 -0
  44. package/browser/io/utils.d.ts +199 -0
  45. package/browser/io/utils.d.ts.map +1 -0
  46. package/browser/merkle.d.ts +10 -1
  47. package/browser/merkle.d.ts.map +1 -0
  48. package/browser/networks.d.ts +70 -9
  49. package/browser/networks.d.ts.map +1 -0
  50. package/browser/opcodes.d.ts +1 -0
  51. package/browser/opcodes.d.ts.map +1 -0
  52. package/browser/payments/bip341.d.ts +35 -9
  53. package/browser/payments/bip341.d.ts.map +1 -0
  54. package/browser/payments/embed.d.ts +112 -1
  55. package/browser/payments/embed.d.ts.map +1 -0
  56. package/browser/payments/index.d.ts +17 -10
  57. package/browser/payments/index.d.ts.map +1 -0
  58. package/browser/payments/p2ms.d.ts +150 -0
  59. package/browser/payments/p2ms.d.ts.map +1 -0
  60. package/browser/payments/p2op.d.ts +150 -24
  61. package/browser/payments/p2op.d.ts.map +1 -0
  62. package/browser/payments/p2pk.d.ts +154 -1
  63. package/browser/payments/p2pk.d.ts.map +1 -0
  64. package/browser/payments/p2pkh.d.ts +176 -1
  65. package/browser/payments/p2pkh.d.ts.map +1 -0
  66. package/browser/payments/p2sh.d.ts +150 -1
  67. package/browser/payments/p2sh.d.ts.map +1 -0
  68. package/browser/payments/p2tr.d.ts +185 -1
  69. package/browser/payments/p2tr.d.ts.map +1 -0
  70. package/browser/payments/p2wpkh.d.ts +161 -1
  71. package/browser/payments/p2wpkh.d.ts.map +1 -0
  72. package/browser/payments/p2wsh.d.ts +146 -1
  73. package/browser/payments/p2wsh.d.ts.map +1 -0
  74. package/browser/payments/types.d.ts +94 -64
  75. package/browser/payments/types.d.ts.map +1 -0
  76. package/browser/psbt/bip371.d.ts +34 -8
  77. package/browser/psbt/bip371.d.ts.map +1 -0
  78. package/browser/psbt/psbtutils.d.ts +56 -16
  79. package/browser/psbt/psbtutils.d.ts.map +1 -0
  80. package/browser/psbt/types.d.ts +245 -0
  81. package/browser/psbt/types.d.ts.map +1 -0
  82. package/browser/psbt/utils.d.ts +64 -0
  83. package/browser/psbt/utils.d.ts.map +1 -0
  84. package/browser/psbt/validation.d.ts +84 -0
  85. package/browser/psbt/validation.d.ts.map +1 -0
  86. package/browser/psbt.d.ts +82 -118
  87. package/browser/psbt.d.ts.map +1 -0
  88. package/browser/pubkey.d.ts +27 -6
  89. package/browser/pubkey.d.ts.map +1 -0
  90. package/browser/push_data.d.ts +24 -2
  91. package/browser/push_data.d.ts.map +1 -0
  92. package/browser/script.d.ts +33 -8
  93. package/browser/script.d.ts.map +1 -0
  94. package/browser/script_number.d.ts +17 -0
  95. package/browser/script_number.d.ts.map +1 -0
  96. package/browser/script_signature.d.ts +23 -5
  97. package/browser/script_signature.d.ts.map +1 -0
  98. package/browser/transaction.d.ts +160 -18
  99. package/browser/transaction.d.ts.map +1 -0
  100. package/browser/types.d.ts +36 -38
  101. package/browser/types.d.ts.map +1 -0
  102. package/browser/workers/WorkerSigningPool.d.ts +143 -0
  103. package/browser/workers/WorkerSigningPool.d.ts.map +1 -0
  104. package/browser/workers/WorkerSigningPool.node.d.ts +116 -0
  105. package/browser/workers/WorkerSigningPool.node.d.ts.map +1 -0
  106. package/browser/workers/ecc-bundle.d.ts +25 -0
  107. package/browser/workers/ecc-bundle.d.ts.map +1 -0
  108. package/browser/workers/index.d.ts +91 -0
  109. package/browser/workers/index.d.ts.map +1 -0
  110. package/browser/workers/psbt-parallel.d.ts +88 -0
  111. package/browser/workers/psbt-parallel.d.ts.map +1 -0
  112. package/browser/workers/signing-worker.d.ts +37 -0
  113. package/browser/workers/signing-worker.d.ts.map +1 -0
  114. package/browser/workers/types.d.ts +365 -0
  115. package/browser/workers/types.d.ts.map +1 -0
  116. package/build/address.d.ts +57 -10
  117. package/build/address.d.ts.map +1 -0
  118. package/build/address.js +80 -24
  119. package/build/address.js.map +1 -0
  120. package/build/bech32utils.d.ts +9 -1
  121. package/build/bech32utils.d.ts.map +1 -0
  122. package/build/bech32utils.js +10 -2
  123. package/build/bech32utils.js.map +1 -0
  124. package/build/bip66.d.ts +11 -6
  125. package/build/bip66.d.ts.map +1 -0
  126. package/build/bip66.js +32 -3
  127. package/build/bip66.js.map +1 -0
  128. package/build/block.d.ts +117 -11
  129. package/build/block.d.ts.map +1 -0
  130. package/build/block.js +204 -72
  131. package/build/block.js.map +1 -0
  132. package/build/branded.d.ts +20 -0
  133. package/build/branded.d.ts.map +1 -0
  134. package/build/branded.js +7 -0
  135. package/build/branded.js.map +1 -0
  136. package/build/crypto/crypto.d.ts +1 -0
  137. package/build/crypto/crypto.d.ts.map +1 -0
  138. package/build/crypto/crypto.js +1 -0
  139. package/build/crypto/crypto.js.map +1 -0
  140. package/build/crypto.d.ts +46 -7
  141. package/build/crypto.d.ts.map +1 -0
  142. package/build/crypto.js +65 -20
  143. package/build/crypto.js.map +1 -0
  144. package/build/ecc/context.d.ts +135 -0
  145. package/build/ecc/context.d.ts.map +1 -0
  146. package/build/ecc/context.js +232 -0
  147. package/build/ecc/context.js.map +1 -0
  148. package/build/ecc/index.d.ts +11 -0
  149. package/build/ecc/index.d.ts.map +1 -0
  150. package/build/ecc/index.js +11 -0
  151. package/build/ecc/index.js.map +1 -0
  152. package/build/ecc/types.d.ts +134 -0
  153. package/build/ecc/types.d.ts.map +1 -0
  154. package/build/ecc/types.js +8 -0
  155. package/build/ecc/types.js.map +1 -0
  156. package/build/errors.d.ts +124 -0
  157. package/build/errors.d.ts.map +1 -0
  158. package/build/errors.js +155 -0
  159. package/build/errors.js.map +1 -0
  160. package/build/index.d.ts +32 -5
  161. package/build/index.d.ts.map +1 -0
  162. package/build/index.js +26 -3
  163. package/build/index.js.map +1 -0
  164. package/build/io/BinaryReader.d.ts +276 -0
  165. package/build/io/BinaryReader.d.ts.map +1 -0
  166. package/build/io/BinaryReader.js +425 -0
  167. package/build/io/BinaryReader.js.map +1 -0
  168. package/build/io/BinaryWriter.d.ts +391 -0
  169. package/build/io/BinaryWriter.d.ts.map +1 -0
  170. package/build/io/BinaryWriter.js +611 -0
  171. package/build/io/BinaryWriter.js.map +1 -0
  172. package/build/io/MemoryPool.d.ts +220 -0
  173. package/build/io/MemoryPool.d.ts.map +1 -0
  174. package/build/io/MemoryPool.js +309 -0
  175. package/build/io/MemoryPool.js.map +1 -0
  176. package/build/io/base64.d.ts +13 -0
  177. package/build/io/base64.d.ts.map +1 -0
  178. package/build/io/base64.js +20 -0
  179. package/build/io/base64.js.map +1 -0
  180. package/build/io/hex.d.ts +67 -0
  181. package/build/io/hex.d.ts.map +1 -0
  182. package/build/io/hex.js +138 -0
  183. package/build/io/hex.js.map +1 -0
  184. package/build/io/index.d.ts +17 -0
  185. package/build/io/index.d.ts.map +1 -0
  186. package/build/io/index.js +23 -0
  187. package/build/io/index.js.map +1 -0
  188. package/build/io/utils.d.ts +199 -0
  189. package/build/io/utils.d.ts.map +1 -0
  190. package/build/io/utils.js +271 -0
  191. package/build/io/utils.js.map +1 -0
  192. package/build/merkle.d.ts +10 -1
  193. package/build/merkle.d.ts.map +1 -0
  194. package/build/merkle.js +12 -1
  195. package/build/merkle.js.map +1 -0
  196. package/build/networks.d.ts +70 -9
  197. package/build/networks.d.ts.map +1 -0
  198. package/build/networks.js +90 -4
  199. package/build/networks.js.map +1 -0
  200. package/build/opcodes.d.ts +1 -0
  201. package/build/opcodes.d.ts.map +1 -0
  202. package/build/opcodes.js +1 -0
  203. package/build/opcodes.js.map +1 -0
  204. package/build/payments/bip341.d.ts +36 -9
  205. package/build/payments/bip341.d.ts.map +1 -0
  206. package/build/payments/bip341.js +35 -15
  207. package/build/payments/bip341.js.map +1 -0
  208. package/build/payments/embed.d.ts +120 -1
  209. package/build/payments/embed.d.ts.map +1 -0
  210. package/build/payments/embed.js +215 -34
  211. package/build/payments/embed.js.map +1 -0
  212. package/build/payments/index.d.ts +17 -10
  213. package/build/payments/index.d.ts.map +1 -0
  214. package/build/payments/index.js +20 -10
  215. package/build/payments/index.js.map +1 -0
  216. package/build/payments/p2ms.d.ts +159 -1
  217. package/build/payments/p2ms.d.ts.map +1 -0
  218. package/build/payments/p2ms.js +427 -108
  219. package/build/payments/p2ms.js.map +1 -0
  220. package/build/payments/p2op.d.ts +158 -24
  221. package/build/payments/p2op.d.ts.map +1 -0
  222. package/build/payments/p2op.js +379 -93
  223. package/build/payments/p2op.js.map +1 -0
  224. package/build/payments/p2pk.d.ts +162 -1
  225. package/build/payments/p2pk.d.ts.map +1 -0
  226. package/build/payments/p2pk.js +327 -58
  227. package/build/payments/p2pk.js.map +1 -0
  228. package/build/payments/p2pkh.d.ts +185 -1
  229. package/build/payments/p2pkh.d.ts.map +1 -0
  230. package/build/payments/p2pkh.js +467 -114
  231. package/build/payments/p2pkh.js.map +1 -0
  232. package/build/payments/p2sh.d.ts +159 -1
  233. package/build/payments/p2sh.d.ts.map +1 -0
  234. package/build/payments/p2sh.js +500 -152
  235. package/build/payments/p2sh.js.map +1 -0
  236. package/build/payments/p2tr.d.ts +193 -1
  237. package/build/payments/p2tr.d.ts.map +1 -0
  238. package/build/payments/p2tr.js +592 -174
  239. package/build/payments/p2tr.js.map +1 -0
  240. package/build/payments/p2wpkh.d.ts +170 -1
  241. package/build/payments/p2wpkh.d.ts.map +1 -0
  242. package/build/payments/p2wpkh.js +429 -104
  243. package/build/payments/p2wpkh.js.map +1 -0
  244. package/build/payments/p2wsh.d.ts +155 -1
  245. package/build/payments/p2wsh.d.ts.map +1 -0
  246. package/build/payments/p2wsh.js +466 -144
  247. package/build/payments/p2wsh.js.map +1 -0
  248. package/build/payments/types.d.ts +98 -64
  249. package/build/payments/types.d.ts.map +1 -0
  250. package/build/payments/types.js +17 -13
  251. package/build/payments/types.js.map +1 -0
  252. package/build/psbt/bip371.d.ts +35 -9
  253. package/build/psbt/bip371.d.ts.map +1 -0
  254. package/build/psbt/bip371.js +113 -28
  255. package/build/psbt/bip371.js.map +1 -0
  256. package/build/psbt/psbtutils.d.ts +56 -16
  257. package/build/psbt/psbtutils.d.ts.map +1 -0
  258. package/build/psbt/psbtutils.js +71 -16
  259. package/build/psbt/psbtutils.js.map +1 -0
  260. package/build/psbt/types.d.ts +249 -0
  261. package/build/psbt/types.d.ts.map +1 -0
  262. package/build/psbt/types.js +6 -0
  263. package/build/psbt/types.js.map +1 -0
  264. package/build/psbt/utils.d.ts +68 -0
  265. package/build/psbt/utils.d.ts.map +1 -0
  266. package/build/psbt/utils.js +171 -0
  267. package/build/psbt/utils.js.map +1 -0
  268. package/build/psbt/validation.d.ts +88 -0
  269. package/build/psbt/validation.d.ts.map +1 -0
  270. package/build/psbt/validation.js +149 -0
  271. package/build/psbt/validation.js.map +1 -0
  272. package/build/psbt.d.ts +84 -120
  273. package/build/psbt.d.ts.map +1 -0
  274. package/build/psbt.js +411 -412
  275. package/build/psbt.js.map +1 -0
  276. package/build/pubkey.d.ts +27 -6
  277. package/build/pubkey.d.ts.map +1 -0
  278. package/build/pubkey.js +37 -13
  279. package/build/pubkey.js.map +1 -0
  280. package/build/push_data.d.ts +24 -2
  281. package/build/push_data.d.ts.map +1 -0
  282. package/build/push_data.js +44 -12
  283. package/build/push_data.js.map +1 -0
  284. package/build/script.d.ts +33 -8
  285. package/build/script.d.ts.map +1 -0
  286. package/build/script.js +100 -36
  287. package/build/script.js.map +1 -0
  288. package/build/script_number.d.ts +17 -0
  289. package/build/script_number.d.ts.map +1 -0
  290. package/build/script_number.js +19 -0
  291. package/build/script_number.js.map +1 -0
  292. package/build/script_signature.d.ts +23 -5
  293. package/build/script_signature.d.ts.map +1 -0
  294. package/build/script_signature.js +48 -15
  295. package/build/script_signature.js.map +1 -0
  296. package/build/transaction.d.ts +160 -18
  297. package/build/transaction.d.ts.map +1 -0
  298. package/build/transaction.js +443 -176
  299. package/build/transaction.js.map +1 -0
  300. package/build/tsconfig.build.tsbuildinfo +1 -0
  301. package/build/types.d.ts +36 -38
  302. package/build/types.d.ts.map +1 -0
  303. package/build/types.js +175 -57
  304. package/build/types.js.map +1 -0
  305. package/build/workers/WorkerSigningPool.d.ts +174 -0
  306. package/build/workers/WorkerSigningPool.d.ts.map +1 -0
  307. package/build/workers/WorkerSigningPool.js +553 -0
  308. package/build/workers/WorkerSigningPool.js.map +1 -0
  309. package/build/workers/WorkerSigningPool.node.d.ts +124 -0
  310. package/build/workers/WorkerSigningPool.node.d.ts.map +1 -0
  311. package/build/workers/WorkerSigningPool.node.js +753 -0
  312. package/build/workers/WorkerSigningPool.node.js.map +1 -0
  313. package/build/workers/ecc-bundle.d.ts +25 -0
  314. package/build/workers/ecc-bundle.d.ts.map +1 -0
  315. package/build/workers/ecc-bundle.js +25 -0
  316. package/build/workers/ecc-bundle.js.map +1 -0
  317. package/build/workers/index.d.ts +91 -0
  318. package/build/workers/index.d.ts.map +1 -0
  319. package/build/workers/index.js +114 -0
  320. package/build/workers/index.js.map +1 -0
  321. package/build/workers/psbt-parallel.d.ts +117 -0
  322. package/build/workers/psbt-parallel.d.ts.map +1 -0
  323. package/build/workers/psbt-parallel.js +233 -0
  324. package/build/workers/psbt-parallel.js.map +1 -0
  325. package/build/workers/signing-worker.d.ts +37 -0
  326. package/build/workers/signing-worker.d.ts.map +1 -0
  327. package/build/workers/signing-worker.js +350 -0
  328. package/build/workers/signing-worker.js.map +1 -0
  329. package/build/workers/types.d.ts +365 -0
  330. package/build/workers/types.d.ts.map +1 -0
  331. package/build/workers/types.js +60 -0
  332. package/build/workers/types.js.map +1 -0
  333. package/package.json +83 -25
  334. package/scripts/bundle-ecc.ts +111 -0
  335. package/src/address.ts +81 -44
  336. package/src/bech32utils.ts +3 -3
  337. package/src/bip66.ts +34 -24
  338. package/src/block.ts +196 -84
  339. package/src/branded.ts +18 -0
  340. package/src/crypto.ts +64 -26
  341. package/src/ecc/context.ts +277 -0
  342. package/src/ecc/index.ts +14 -0
  343. package/src/ecc/types.ts +154 -0
  344. package/src/ecpair.d.ts +99 -0
  345. package/src/errors.ts +163 -0
  346. package/src/index.ts +113 -9
  347. package/src/io/BinaryReader.ts +461 -0
  348. package/src/io/BinaryWriter.ts +696 -0
  349. package/src/io/MemoryPool.ts +343 -0
  350. package/src/io/base64.ts +20 -0
  351. package/src/io/hex.ts +155 -0
  352. package/src/io/index.ts +41 -0
  353. package/src/io/utils.ts +283 -0
  354. package/src/merkle.ts +14 -9
  355. package/src/networks.ts +9 -9
  356. package/src/payments/bip341.ts +34 -33
  357. package/src/payments/embed.ts +244 -41
  358. package/src/payments/index.ts +12 -10
  359. package/src/payments/p2ms.ts +490 -118
  360. package/src/payments/p2op.ts +431 -133
  361. package/src/payments/p2pk.ts +370 -72
  362. package/src/payments/p2pkh.ts +524 -130
  363. package/src/payments/p2sh.ts +572 -172
  364. package/src/payments/p2tr.ts +686 -194
  365. package/src/payments/p2wpkh.ts +484 -107
  366. package/src/payments/p2wsh.ts +526 -164
  367. package/src/payments/types.ts +80 -66
  368. package/src/psbt/bip371.ts +68 -51
  369. package/src/psbt/psbtutils.ts +39 -40
  370. package/src/psbt/types.ts +331 -0
  371. package/src/psbt/utils.ts +188 -0
  372. package/src/psbt/validation.ts +192 -0
  373. package/src/psbt.ts +566 -809
  374. package/src/pubkey.ts +24 -25
  375. package/src/push_data.ts +18 -16
  376. package/src/script.ts +82 -64
  377. package/src/script_number.ts +6 -6
  378. package/src/script_signature.ts +33 -36
  379. package/src/transaction.ts +458 -238
  380. package/src/types.ts +231 -100
  381. package/src/workers/WorkerSigningPool.node.ts +887 -0
  382. package/src/workers/WorkerSigningPool.ts +670 -0
  383. package/src/workers/ecc-bundle.ts +26 -0
  384. package/src/workers/index.ts +165 -0
  385. package/src/workers/psbt-parallel.ts +332 -0
  386. package/src/workers/signing-worker.ts +353 -0
  387. package/src/workers/types.ts +413 -0
  388. package/test/address.spec.ts +9 -6
  389. package/test/bitcoin.core.spec.ts +16 -17
  390. package/test/block.spec.ts +8 -7
  391. package/test/bufferutils.spec.ts +228 -214
  392. package/test/crypto.spec.ts +19 -11
  393. package/test/fixtures/p2pk.json +0 -8
  394. package/test/fixtures/p2pkh.json +1 -1
  395. package/test/fixtures/p2sh.json +1 -1
  396. package/test/fixtures/script.json +1 -1
  397. package/test/fixtures/transaction.json +2 -2
  398. package/test/integration/_regtest.ts +25 -0
  399. package/test/integration/addresses.spec.ts +4 -3
  400. package/test/integration/bip32.spec.ts +2 -1
  401. package/test/integration/blocks.spec.ts +1 -1
  402. package/test/integration/cltv.spec.ts +18 -16
  403. package/test/integration/csv.spec.ts +37 -64
  404. package/test/integration/payments.spec.ts +5 -3
  405. package/test/integration/taproot.spec.ts +76 -83
  406. package/test/integration/transactions.spec.ts +38 -35
  407. package/test/payments.spec.ts +35 -13
  408. package/test/payments.utils.ts +17 -16
  409. package/test/psbt.spec.ts +111 -100
  410. package/test/script.spec.ts +11 -10
  411. package/test/script_signature.spec.ts +9 -11
  412. package/test/taproot-cache.spec.ts +694 -0
  413. package/test/transaction.spec.ts +32 -40
  414. package/test/types.spec.ts +74 -29
  415. package/test/workers-pool.spec.ts +963 -0
  416. package/test/workers-signing.spec.ts +635 -0
  417. package/test/workers.spec.ts +1390 -0
  418. package/tsconfig.base.json +34 -18
  419. package/tsconfig.browser.json +15 -0
  420. package/tsconfig.build.json +5 -0
  421. package/tsconfig.json +5 -14
  422. package/vite.config.browser.ts +3 -42
  423. package/vitest.config.integration.ts +11 -0
  424. package/browser/bufferutils.d.ts +0 -34
  425. package/browser/chunks/crypto-BhCpKpek.js +0 -2033
  426. package/browser/chunks/payments-yjA0Evsv.js +0 -1089
  427. package/browser/chunks/psbt-URK2hBFc.js +0 -4039
  428. package/browser/chunks/script-DyPItFEl.js +0 -318
  429. package/browser/chunks/transaction-C_UbhMGn.js +0 -432
  430. package/browser/chunks/utils-DNZi-T5W.js +0 -761
  431. package/browser/ecc_lib.d.ts +0 -3
  432. package/browser/hooks/AdvancedSignatureManager.d.ts +0 -16
  433. package/browser/hooks/HookedSigner.d.ts +0 -4
  434. package/browser/hooks/SignatureManager.d.ts +0 -13
  435. package/browser/payments/lazy.d.ts +0 -2
  436. package/browser/typeforce.d.ts +0 -38
  437. package/build/bufferutils.d.ts +0 -34
  438. package/build/bufferutils.js +0 -141
  439. package/build/ecc_lib.d.ts +0 -3
  440. package/build/ecc_lib.js +0 -61
  441. package/build/hooks/AdvancedSignatureManager.d.ts +0 -16
  442. package/build/hooks/AdvancedSignatureManager.js +0 -52
  443. package/build/hooks/HookedSigner.d.ts +0 -4
  444. package/build/hooks/HookedSigner.js +0 -64
  445. package/build/hooks/SignatureManager.d.ts +0 -13
  446. package/build/hooks/SignatureManager.js +0 -45
  447. package/build/payments/lazy.d.ts +0 -2
  448. package/build/payments/lazy.js +0 -28
  449. package/build/tsconfig.tsbuildinfo +0 -1
  450. package/src/bufferutils.ts +0 -188
  451. package/src/ecc_lib.ts +0 -94
  452. package/src/hooks/AdvancedSignatureManager.ts +0 -104
  453. package/src/hooks/HookedSigner.ts +0 -108
  454. package/src/hooks/SignatureManager.ts +0 -84
  455. package/src/payments/lazy.ts +0 -28
  456. package/src/typeforce.d.ts +0 -38
  457. package/tsconfig.webpack.json +0 -18
@@ -1,5 +1,5 @@
1
- import * as varuint from 'bip174/src/lib/converter/varint.js';
2
- import { PartialSig, PsbtInput } from 'bip174/src/lib/interfaces.js';
1
+ import type { PartialSig, PsbtInput } from 'bip174';
2
+ import { varuint, concat, alloc, equals } from '../io/index.js';
3
3
  import { hash160 } from '../crypto.js';
4
4
  import { p2ms } from '../payments/p2ms.js';
5
5
  import { p2pk } from '../payments/p2pk.js';
@@ -12,13 +12,14 @@ import { p2op } from '../payments/p2op.js';
12
12
  import { decompressPublicKey, pubkeysMatch, toXOnly } from '../pubkey.js';
13
13
  import * as bscript from '../script.js';
14
14
  import { Transaction } from '../transaction.js';
15
+ import type { PublicKey, Script } from '../types.js';
15
16
 
16
- type PaymentFunction = (opts: { output: Buffer }) => unknown;
17
+ type PaymentFunction = (opts: { output: Script }) => unknown;
17
18
 
18
- function isPaymentFactory(payment: PaymentFunction): (script: Buffer) => boolean {
19
- return (script: Buffer): boolean => {
19
+ function isPaymentFactory(payment: PaymentFunction): (script: Uint8Array) => boolean {
20
+ return (script: Uint8Array): boolean => {
20
21
  try {
21
- payment({ output: script });
22
+ payment({ output: script as Script });
22
23
  return true;
23
24
  } catch {
24
25
  return false;
@@ -34,7 +35,7 @@ export const isP2WSHScript = isPaymentFactory(p2wsh);
34
35
  export const isP2SHScript = isPaymentFactory(p2sh);
35
36
  export const isP2TR = isPaymentFactory(p2tr);
36
37
  export const isP2OP = isPaymentFactory(p2op);
37
- export const isP2A = (script: Buffer): boolean => {
38
+ export const isP2A = (script: Uint8Array): boolean => {
38
39
  return (
39
40
  script.length === 4 &&
40
41
  script[0] === 0x51 && // OP_1
@@ -47,41 +48,35 @@ export const isP2A = (script: Buffer): boolean => {
47
48
  /**
48
49
  * Converts a witness stack to a script witness.
49
50
  * @param witness The witness stack to convert.
50
- * @returns The script witness as a Buffer.
51
+ * @returns The script witness as a Uint8Array.
51
52
  */
52
- /**
53
- * Converts a witness stack to a script witness.
54
- * @param witness The witness stack to convert.
55
- * @returns The converted script witness.
56
- */
57
- export function witnessStackToScriptWitness(witness: Buffer[]): Buffer {
58
- let buffer = Buffer.allocUnsafe(0);
53
+ export function witnessStackToScriptWitness(witness: Uint8Array[]): Uint8Array {
54
+ const chunks: Uint8Array[] = [];
59
55
 
60
- function writeSlice(slice: Buffer): void {
61
- buffer = Buffer.concat([buffer, Buffer.from(slice)]);
56
+ function writeSlice(slice: Uint8Array): void {
57
+ chunks.push(slice);
62
58
  }
63
59
 
64
60
  function writeVarInt(i: number): void {
65
- const currentLen = buffer.length;
66
61
  const varintLen = varuint.encodingLength(i);
67
-
68
- buffer = Buffer.concat([buffer, Buffer.allocUnsafe(varintLen)]);
69
- varuint.encode(i, buffer, currentLen);
62
+ const buf = alloc(varintLen);
63
+ varuint.encode(i, buf, 0);
64
+ chunks.push(buf);
70
65
  }
71
66
 
72
- function writeVarSlice(slice: Buffer): void {
67
+ function writeVarSlice(slice: Uint8Array): void {
73
68
  writeVarInt(slice.length);
74
69
  writeSlice(slice);
75
70
  }
76
71
 
77
- function writeVector(vector: Buffer[]): void {
72
+ function writeVector(vector: Uint8Array[]): void {
78
73
  writeVarInt(vector.length);
79
74
  vector.forEach(writeVarSlice);
80
75
  }
81
76
 
82
77
  writeVector(witness);
83
78
 
84
- return buffer;
79
+ return concat(chunks);
85
80
  }
86
81
 
87
82
  /**
@@ -91,7 +86,7 @@ export function witnessStackToScriptWitness(witness: Buffer[]): Buffer {
91
86
  * @returns The index of the public key in the script, or -1 if not found.
92
87
  * @throws {Error} If there is an unknown script error.
93
88
  */
94
- export function pubkeyPositionInScript(pubkey: Buffer, script: Buffer): number {
89
+ export function pubkeyPositionInScript(pubkey: Uint8Array, script: Uint8Array): number {
95
90
  const decompiled = bscript.decompile(script);
96
91
  if (decompiled === null) throw new Error('Unknown script error');
97
92
 
@@ -99,8 +94,8 @@ export function pubkeyPositionInScript(pubkey: Buffer, script: Buffer): number {
99
94
  const pubkeyHash = hash160(pubkey);
100
95
 
101
96
  // For Taproot or some cases, we might also check the x-only
102
- const pubkeyXOnly = toXOnly(pubkey);
103
- const uncompressed = decompressPublicKey(pubkey);
97
+ const pubkeyXOnly = toXOnly(pubkey as PublicKey);
98
+ const uncompressed = decompressPublicKey(pubkey as PublicKey);
104
99
 
105
100
  const pubkeyHybridHash = uncompressed?.hybrid ? hash160(uncompressed.hybrid) : undefined;
106
101
  const pubkeyUncompressedHash = uncompressed?.uncompressed
@@ -114,7 +109,7 @@ export function pubkeyPositionInScript(pubkey: Buffer, script: Buffer): number {
114
109
 
115
110
  if (pubkeysMatch(element, pubkeyXOnly)) return true;
116
111
 
117
- if (element.equals(pubkeyHash)) {
112
+ if (equals(element, pubkeyHash)) {
118
113
  return true;
119
114
  }
120
115
 
@@ -124,12 +119,14 @@ export function pubkeyPositionInScript(pubkey: Buffer, script: Buffer): number {
124
119
  if (pubkeysMatch(element, uncompressed.hybrid)) return true;
125
120
 
126
121
  if (
127
- (pubkeyHybridHash && element.equals(pubkeyHybridHash)) ||
128
- (pubkeyUncompressedHash && element.equals(pubkeyUncompressedHash))
122
+ (pubkeyHybridHash && equals(element, pubkeyHybridHash)) ||
123
+ (pubkeyUncompressedHash && equals(element, pubkeyUncompressedHash))
129
124
  ) {
130
125
  return true;
131
126
  }
132
127
  }
128
+
129
+ return false;
133
130
  });
134
131
  }
135
132
 
@@ -139,7 +136,7 @@ export function pubkeyPositionInScript(pubkey: Buffer, script: Buffer): number {
139
136
  * @param script The script to search in.
140
137
  * @returns A boolean indicating whether the public key is present in the script.
141
138
  */
142
- export function pubkeyInScript(pubkey: Buffer, script: Buffer): boolean {
139
+ export function pubkeyInScript(pubkey: Uint8Array, script: Uint8Array): boolean {
143
140
  return pubkeyPositionInScript(pubkey, script) !== -1;
144
141
  }
145
142
 
@@ -154,8 +151,8 @@ export function checkInputForSig(input: PsbtInput, action: string): boolean {
154
151
  return pSigs.some((pSig) => signatureBlocksAction(pSig, bscript.signature.decode, action));
155
152
  }
156
153
 
157
- type SignatureDecodeFunc = (buffer: Buffer) => {
158
- signature: Buffer;
154
+ type SignatureDecodeFunc = (buffer: Uint8Array) => {
155
+ signature: Uint8Array;
159
156
  hashType: number;
160
157
  };
161
158
 
@@ -167,7 +164,7 @@ type SignatureDecodeFunc = (buffer: Buffer) => {
167
164
  * @returns True if the action is allowed, false otherwise.
168
165
  */
169
166
  export function signatureBlocksAction(
170
- signature: Buffer,
167
+ signature: Uint8Array,
171
168
  signatureDecodeFn: SignatureDecodeFunc,
172
169
  action: string,
173
170
  ): boolean {
@@ -198,7 +195,7 @@ export function signatureBlocksAction(
198
195
  * @param input - The PsbtInput object from which to extract the signatures.
199
196
  * @returns An array of signatures extracted from the PsbtInput object.
200
197
  */
201
- function extractPartialSigs(input: PsbtInput): Buffer[] {
198
+ function extractPartialSigs(input: PsbtInput): Uint8Array[] {
202
199
  const { partialSig } = input;
203
200
  let pSigs: PartialSig[];
204
201
  if (!partialSig || partialSig.length === 0) {
@@ -207,7 +204,7 @@ function extractPartialSigs(input: PsbtInput): Buffer[] {
207
204
  } else {
208
205
  pSigs = partialSig;
209
206
  }
210
- return pSigs.map((p) => p.signature);
207
+ return pSigs.map((p) => new Uint8Array(p.signature));
211
208
  }
212
209
 
213
210
  /**
@@ -219,14 +216,16 @@ function extractPartialSigs(input: PsbtInput): Buffer[] {
219
216
  * @returns An array of PartialSig objects containing the extracted Psigs.
220
217
  */
221
218
  export function getPsigsFromInputFinalScripts(input: PsbtInput): PartialSig[] {
222
- const scriptItems = !input.finalScriptSig ? [] : bscript.decompile(input.finalScriptSig) || [];
219
+ const scriptItems = !input.finalScriptSig
220
+ ? []
221
+ : bscript.decompile(new Uint8Array(input.finalScriptSig)) || [];
223
222
  const witnessItems = !input.finalScriptWitness
224
223
  ? []
225
- : bscript.decompile(input.finalScriptWitness) || [];
224
+ : bscript.decompile(new Uint8Array(input.finalScriptWitness)) || [];
226
225
  return scriptItems
227
226
  .concat(witnessItems)
228
227
  .filter((item) => {
229
- return Buffer.isBuffer(item) && bscript.isCanonicalScriptSignature(item);
228
+ return item instanceof Uint8Array && bscript.isCanonicalScriptSignature(item);
230
229
  })
231
- .map((sig) => ({ signature: sig })) as PartialSig[];
230
+ .map((sig) => ({ signature: sig as Uint8Array })) as PartialSig[];
232
231
  }
@@ -0,0 +1,331 @@
1
+ /**
2
+ * PSBT types and interfaces
3
+ * @packageDocumentation
4
+ */
5
+
6
+ import type { Psbt as PsbtBase, PsbtGlobal, PsbtInput, PsbtOutput } from 'bip174';
7
+ import type { Network } from '../networks.js';
8
+ import type { Transaction, TaprootHashCache } from '../transaction.js';
9
+ import type {
10
+ Bytes32,
11
+ PublicKey,
12
+ Satoshi,
13
+ Script,
14
+ Signature,
15
+ SchnorrSignature,
16
+ } from '../types.js';
17
+
18
+ /**
19
+ * Transaction input interface for PSBT.
20
+ */
21
+ export interface TransactionInput {
22
+ readonly hash: string | Bytes32;
23
+ readonly index: number;
24
+ readonly sequence?: number | undefined;
25
+ }
26
+
27
+ /**
28
+ * PSBT transaction input with Uint8Array hash.
29
+ */
30
+ export interface PsbtTxInput extends TransactionInput {
31
+ readonly hash: Bytes32;
32
+ }
33
+
34
+ /**
35
+ * Transaction output interface for PSBT.
36
+ */
37
+ export interface TransactionOutput {
38
+ readonly script: Script;
39
+ readonly value: Satoshi;
40
+ }
41
+
42
+ /**
43
+ * PSBT transaction output with optional address.
44
+ */
45
+ export interface PsbtTxOutput extends TransactionOutput {
46
+ readonly address: string | undefined;
47
+ }
48
+
49
+ /**
50
+ * Signature validation function type.
51
+ * msghash is 32 byte hash of preimage, signature is 64 byte compact signature (r,s 32 bytes each)
52
+ */
53
+ export type ValidateSigFunction = (
54
+ pubkey: PublicKey,
55
+ msghash: Bytes32,
56
+ signature: Uint8Array,
57
+ ) => boolean;
58
+
59
+ /**
60
+ * Extended PsbtBase interface with typed inputs and globalMap.
61
+ */
62
+ export interface PsbtBaseExtended extends Omit<PsbtBase, 'inputs'> {
63
+ readonly inputs: PsbtInput[];
64
+ readonly globalMap: PsbtGlobal;
65
+ }
66
+
67
+ /**
68
+ * Optional PSBT options.
69
+ */
70
+ export interface PsbtOptsOptional {
71
+ readonly network?: Network | undefined;
72
+ readonly maximumFeeRate?: number | undefined;
73
+ readonly version?: 1 | 2 | 3 | undefined;
74
+ }
75
+
76
+ /**
77
+ * Required PSBT options.
78
+ */
79
+ export interface PsbtOpts {
80
+ readonly network: Network;
81
+ maximumFeeRate: number;
82
+ }
83
+
84
+ /**
85
+ * Extended PSBT input with additional fields.
86
+ */
87
+ export interface PsbtInputExtended extends PsbtInput, TransactionInput {
88
+ readonly isPayToAnchor?: boolean | undefined;
89
+ }
90
+
91
+ /**
92
+ * Extended PSBT output - either address-based or script-based.
93
+ */
94
+ export type PsbtOutputExtended = PsbtOutputExtendedAddress | PsbtOutputExtendedScript;
95
+
96
+ /**
97
+ * PSBT output with address.
98
+ */
99
+ export interface PsbtOutputExtendedAddress extends PsbtOutput {
100
+ readonly address: string;
101
+ readonly value: Satoshi;
102
+ }
103
+
104
+ /**
105
+ * PSBT output with script.
106
+ */
107
+ export interface PsbtOutputExtendedScript extends PsbtOutput {
108
+ readonly script: Script;
109
+ readonly value: Satoshi;
110
+ }
111
+
112
+ /**
113
+ * Base interface for HD signers.
114
+ */
115
+ interface HDSignerBase {
116
+ /**
117
+ * DER format compressed publicKey Uint8Array
118
+ */
119
+ readonly publicKey: PublicKey;
120
+ /**
121
+ * The first 4 bytes of the sha256-ripemd160 of the publicKey
122
+ */
123
+ readonly fingerprint: Uint8Array;
124
+ }
125
+
126
+ /**
127
+ * HD signer interface for synchronous signing.
128
+ */
129
+ export interface HDSigner extends HDSignerBase {
130
+ /**
131
+ * The path string must match /^m(\/\d+'?)+$/
132
+ * ex. m/44'/0'/0'/1/23 levels with ' must be hard derivations
133
+ */
134
+ derivePath(path: string): HDSigner;
135
+
136
+ /**
137
+ * Input hash (the "message digest") for the signature algorithm
138
+ * Return a 64 byte signature (32 byte r and 32 byte s in that order)
139
+ */
140
+ sign(hash: Bytes32): Uint8Array;
141
+ }
142
+
143
+ /**
144
+ * HD signer interface for asynchronous signing.
145
+ */
146
+ export interface HDSignerAsync extends HDSignerBase {
147
+ derivePath(path: string): HDSignerAsync;
148
+
149
+ sign(hash: Bytes32): Promise<Uint8Array>;
150
+ }
151
+
152
+ /**
153
+ * Alternative signer interface with lowR support.
154
+ */
155
+ export interface SignerAlternative {
156
+ readonly publicKey: PublicKey;
157
+ readonly lowR: boolean;
158
+
159
+ sign(hash: Bytes32, lowR?: boolean): Signature;
160
+
161
+ verify(hash: Bytes32, signature: Signature): boolean;
162
+
163
+ signSchnorr(hash: Bytes32): SchnorrSignature;
164
+
165
+ verifySchnorr(hash: Bytes32, signature: SchnorrSignature): boolean;
166
+ }
167
+
168
+ /**
169
+ * Basic signer interface for synchronous signing.
170
+ */
171
+ export interface Signer {
172
+ readonly publicKey: PublicKey;
173
+ readonly network?: Network | undefined;
174
+
175
+ sign(hash: Bytes32, lowR?: boolean): Signature;
176
+
177
+ signSchnorr?(hash: Bytes32): SchnorrSignature;
178
+
179
+ getPublicKey?(): PublicKey;
180
+ }
181
+
182
+ /**
183
+ * Basic signer interface for asynchronous signing.
184
+ */
185
+ export interface SignerAsync {
186
+ readonly publicKey: PublicKey;
187
+ readonly network?: Network | undefined;
188
+
189
+ sign(hash: Bytes32, lowR?: boolean): Promise<Signature>;
190
+
191
+ signSchnorr?(hash: Bytes32): Promise<SchnorrSignature>;
192
+
193
+ getPublicKey?(): PublicKey;
194
+ }
195
+
196
+ /**
197
+ * Minimal key pair interface for checking Taproot hashes.
198
+ * Only requires publicKey and optional signSchnorr presence check.
199
+ * Used by checkTaprootHashesForSig to accept broader key pair types (e.g., worker key pairs).
200
+ */
201
+ export interface TaprootHashCheckSigner {
202
+ readonly publicKey: Uint8Array;
203
+ signSchnorr?(hash: Uint8Array): Uint8Array | Promise<Uint8Array>;
204
+ }
205
+
206
+ /**
207
+ * Internal PSBT cache for computed values.
208
+ */
209
+ export interface PsbtCache {
210
+ nonWitnessUtxoTxCache: Transaction[];
211
+ nonWitnessUtxoBufCache: Uint8Array[];
212
+ txInCache: TxInCacheMap;
213
+ tx: Transaction;
214
+ feeRate?: number | undefined;
215
+ fee?: number | undefined;
216
+ extractedTx?: Transaction | undefined;
217
+ unsafeSignNonSegwit: boolean;
218
+ /** Cached flag: true if any input has signatures (avoids O(n) check) */
219
+ hasSignatures: boolean;
220
+ /** Cached prevOuts for Taproot signing (computed once) */
221
+ prevOuts?: readonly PrevOut[] | undefined;
222
+ /** Cached signing scripts */
223
+ signingScripts?: readonly Script[] | undefined;
224
+ /** Cached values */
225
+ values?: readonly Satoshi[] | undefined;
226
+ /** Cached intermediate hashes for Taproot sighash (computed once per PSBT) */
227
+ taprootHashCache?: TaprootHashCache | undefined;
228
+ }
229
+
230
+ /**
231
+ * Keys for cached numeric values in the transaction cache.
232
+ */
233
+ export type TxCacheNumberKey = 'feeRate' | 'fee';
234
+
235
+ /**
236
+ * Script types for classification.
237
+ */
238
+ export type ScriptType = 'witnesspubkeyhash' | 'pubkeyhash' | 'multisig' | 'pubkey' | 'nonstandard';
239
+
240
+ /**
241
+ * All possible script types including witness types.
242
+ * Note: P2WPKH can't be wrapped in P2WSH (already a witness program)
243
+ */
244
+ export type AllScriptType =
245
+ | 'witnesspubkeyhash'
246
+ | 'pubkeyhash'
247
+ | 'multisig'
248
+ | 'pubkey'
249
+ | 'nonstandard'
250
+ | 'p2sh-witnesspubkeyhash'
251
+ | 'p2sh-pubkeyhash'
252
+ | 'p2sh-multisig'
253
+ | 'p2sh-pubkey'
254
+ | 'p2sh-nonstandard'
255
+ | 'p2wsh-pubkeyhash'
256
+ | 'p2wsh-multisig'
257
+ | 'p2wsh-pubkey'
258
+ | 'p2wsh-nonstandard'
259
+ | 'p2sh-p2wsh-pubkeyhash'
260
+ | 'p2sh-p2wsh-multisig'
261
+ | 'p2sh-p2wsh-pubkey'
262
+ | 'p2sh-p2wsh-nonstandard';
263
+
264
+ /**
265
+ * Return type for getScriptFromInput function.
266
+ */
267
+ export interface GetScriptReturn {
268
+ script: Script | null;
269
+ isSegwit: boolean;
270
+ isP2SH: boolean;
271
+ isP2WSH: boolean;
272
+ }
273
+
274
+ /**
275
+ * Index map for transaction input cache.
276
+ */
277
+ export interface TxInCacheMap {
278
+ readonly [index: string]: number;
279
+ }
280
+
281
+ /**
282
+ * Previous output data for signing.
283
+ */
284
+ export interface PrevOut {
285
+ readonly script: Script;
286
+ readonly value: Satoshi;
287
+ }
288
+
289
+ /**
290
+ * Result from getTaprootHashesForSig containing hash and optional leaf hash.
291
+ */
292
+ export interface TaprootHashResult {
293
+ readonly hash: Bytes32;
294
+ readonly leafHash?: Bytes32 | undefined;
295
+ }
296
+
297
+ /**
298
+ * Extended Taproot hash result with pubkey for validation.
299
+ */
300
+ export interface TaprootSigningHash {
301
+ readonly pubkey: PublicKey;
302
+ readonly hash: Bytes32;
303
+ readonly leafHash?: Bytes32 | undefined;
304
+ }
305
+
306
+ /**
307
+ * Function type for final scripts computation.
308
+ */
309
+ export type FinalScriptsFunc = (
310
+ inputIndex: number,
311
+ input: PsbtInput,
312
+ script: Script,
313
+ isSegwit: boolean,
314
+ isP2SH: boolean,
315
+ isP2WSH: boolean,
316
+ canRunChecks: boolean,
317
+ ) => {
318
+ finalScriptSig: Script | undefined;
319
+ finalScriptWitness: Uint8Array | undefined;
320
+ };
321
+
322
+ /**
323
+ * Function type for final Taproot scripts computation.
324
+ */
325
+ export type FinalTaprootScriptsFunc = (
326
+ inputIndex: number,
327
+ input: PsbtInput,
328
+ tapLeafHashToFinalize?: Bytes32,
329
+ ) => {
330
+ finalScriptWitness: Uint8Array | undefined;
331
+ };