@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,156 +1,528 @@
1
- import { bitcoin as BITCOIN_NETWORK } from '../networks.js';
1
+ /**
2
+ * Pay-to-Multisig (P2MS) payment class.
3
+ *
4
+ * P2MS is a bare multisig script where M-of-N signatures are required
5
+ * to spend the output. The public keys are embedded directly in the script.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+
10
+ import { bitcoin as BITCOIN_NETWORK, type Network } from '../networks.js';
2
11
  import * as bscript from '../script.js';
3
- import { isPoint, stacksEqual, typeforce as typef, type Stack } from '../types.js';
4
- import { P2MSPayment, PaymentOpts, PaymentType } from './types.js';
5
- import * as lazy from './lazy.js';
12
+ import { isPoint, stacksEqual, type PublicKey, type Script, type Signature, type Stack } from '../types.js';
13
+ import { PaymentType, type P2MSPayment, type PaymentOpts } from './types.js';
6
14
 
7
15
  const OPS = bscript.opcodes;
8
-
9
16
  const OP_INT_BASE = OPS.OP_RESERVED; // OP_1 - 1
10
17
 
11
- // input: OP_0 [signatures ...]
12
- // output: m [pubKeys ...] n OP_CHECKMULTISIG
13
18
  /**
14
- * Represents a function that creates a Pay-to-Multisig (P2MS) payment object.
15
- * @param a - The payment object.
16
- * @param opts - Optional payment options.
17
- * @returns The created payment object.
18
- * @throws {TypeError} If the provided data is not valid.
19
+ * Pay-to-Multisig (P2MS) payment class.
20
+ *
21
+ * Creates locking scripts of the form:
22
+ * `m {pubKey1} {pubKey2} ... {pubKeyN} n OP_CHECKMULTISIG`
23
+ *
24
+ * Spending requires: `OP_0 {sig1} {sig2} ... {sigM}`
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * import { P2MS } from '@btc-vision/bitcoin';
29
+ *
30
+ * // Create a 2-of-3 multisig
31
+ * const payment = P2MS.fromPubkeys(2, [pubkey1, pubkey2, pubkey3]);
32
+ * console.log(payment.output); // scriptPubKey
33
+ * console.log(payment.m); // 2
34
+ * console.log(payment.n); // 3
35
+ *
36
+ * // Decode an existing output
37
+ * const decoded = P2MS.fromOutput(scriptPubKey);
38
+ * console.log(decoded.pubkeys); // array of public keys
39
+ * ```
19
40
  */
20
- export function p2ms(a: Omit<P2MSPayment, 'name'>, opts?: PaymentOpts): P2MSPayment {
21
- if (!a.input && !a.output && !(a.pubkeys && a.m !== undefined) && !a.signatures)
22
- throw new TypeError('Not enough data');
23
- opts = Object.assign({ validate: true }, opts || {});
41
+ export class P2MS {
42
+ // Static public fields
43
+ static readonly NAME = PaymentType.P2MS;
24
44
 
25
- function isAcceptableSignature(x: Buffer | number): boolean {
26
- return (
27
- bscript.isCanonicalScriptSignature(x as Buffer) ||
28
- (opts!.allowIncomplete && (x as number) === OPS.OP_0) !== undefined
29
- );
30
- }
45
+ // Private instance fields
46
+ readonly #network: Network;
47
+ readonly #opts: Required<PaymentOpts>;
31
48
 
32
- typef(
33
- {
34
- network: typef.maybe(typef.Object),
35
- m: typef.maybe(typef.Number),
36
- n: typef.maybe(typef.Number),
37
- output: typef.maybe(typef.Buffer),
38
- pubkeys: typef.maybe(typef.arrayOf(isPoint)),
39
-
40
- signatures: typef.maybe(typef.arrayOf(isAcceptableSignature)),
41
- input: typef.maybe(typef.Buffer),
49
+ // Input data (provided by user)
50
+ #inputM?: number | undefined;
51
+ #inputN?: number | undefined;
52
+ #inputPubkeys?: Uint8Array[] | undefined;
53
+ #inputSignatures?: Uint8Array[] | undefined;
54
+ #inputOutput?: Uint8Array | undefined;
55
+ #inputInput?: Uint8Array | undefined;
56
+
57
+ // Cached computed values
58
+ #m?: number | undefined;
59
+ #n?: number | undefined;
60
+ #pubkeys?: Uint8Array[] | undefined;
61
+ #signatures?: Uint8Array[] | undefined;
62
+ #output?: Uint8Array | undefined;
63
+ #input?: Uint8Array | undefined;
64
+ #witness?: Uint8Array[] | undefined;
65
+
66
+ // Cache flags
67
+ #mComputed = false;
68
+ #nComputed = false;
69
+ #pubkeysComputed = false;
70
+ #signaturesComputed = false;
71
+ #outputComputed = false;
72
+ #inputComputed = false;
73
+ #witnessComputed = false;
74
+
75
+ // Decoded chunks cache
76
+ #decodedChunks?: Stack | undefined;
77
+ #decoded = false;
78
+
79
+ /**
80
+ * Creates a new P2MS payment instance.
81
+ *
82
+ * @param params - Payment parameters
83
+ * @param params.m - Required number of signatures
84
+ * @param params.n - Total number of public keys (optional, derived from pubkeys)
85
+ * @param params.pubkeys - Array of public keys
86
+ * @param params.signatures - Array of signatures
87
+ * @param params.output - The scriptPubKey
88
+ * @param params.input - The scriptSig
89
+ * @param params.network - Network parameters (defaults to mainnet)
90
+ * @param opts - Payment options
91
+ * @param opts.validate - Whether to validate inputs (default: true)
92
+ * @param opts.allowIncomplete - Allow incomplete signatures (default: false)
93
+ *
94
+ * @throws {TypeError} If validation is enabled and data is invalid
95
+ */
96
+ constructor(
97
+ params: {
98
+ m?: number | undefined;
99
+ n?: number | undefined;
100
+ pubkeys?: Uint8Array[] | undefined;
101
+ signatures?: Uint8Array[] | undefined;
102
+ output?: Uint8Array | undefined;
103
+ input?: Uint8Array | undefined;
104
+ network?: Network | undefined;
42
105
  },
43
- a,
44
- );
106
+ opts?: PaymentOpts,
107
+ ) {
108
+ this.#network = params.network ?? BITCOIN_NETWORK;
109
+ this.#opts = {
110
+ validate: opts?.validate ?? true,
111
+ allowIncomplete: opts?.allowIncomplete ?? false,
112
+ };
113
+
114
+ // Store input data
115
+ this.#inputM = params.m;
116
+ this.#inputN = params.n;
117
+ this.#inputPubkeys = params.pubkeys;
118
+ this.#inputSignatures = params.signatures;
119
+ this.#inputOutput = params.output;
120
+ this.#inputInput = params.input;
45
121
 
46
- const network = a.network || BITCOIN_NETWORK;
47
- const o: P2MSPayment = {
48
- network,
49
- name: PaymentType.P2MS,
50
- };
122
+ // Validate if requested
123
+ if (this.#opts.validate) {
124
+ this.#validate();
125
+ }
126
+ }
51
127
 
52
- let chunks: Stack = [];
53
- let decoded = false;
128
+ // Public getters
129
+
130
+ /**
131
+ * Payment type discriminant.
132
+ */
133
+ get name(): string {
134
+ const m = this.m;
135
+ const n = this.n;
136
+ if (m !== undefined && n !== undefined) {
137
+ return `p2ms(${m} of ${n})`;
138
+ }
139
+ return PaymentType.P2MS;
140
+ }
54
141
 
55
- function decode(output: Buffer | Stack): void {
56
- if (decoded) return;
57
- decoded = true;
58
- chunks = bscript.decompile(output) as Stack;
59
- o.m = (chunks[0] as number) - OP_INT_BASE;
60
- o.n = (chunks[chunks.length - 2] as number) - OP_INT_BASE;
61
- o.pubkeys = chunks.slice(1, -2) as Buffer[];
142
+ /**
143
+ * Network parameters.
144
+ */
145
+ get network(): Network {
146
+ return this.#network;
147
+ }
148
+
149
+ /**
150
+ * Required number of signatures (M in M-of-N).
151
+ */
152
+ get m(): number | undefined {
153
+ if (!this.#mComputed) {
154
+ this.#m = this.#computeM();
155
+ this.#mComputed = true;
156
+ }
157
+ return this.#m;
158
+ }
159
+
160
+ /**
161
+ * Total number of public keys (N in M-of-N).
162
+ */
163
+ get n(): number | undefined {
164
+ if (!this.#nComputed) {
165
+ this.#n = this.#computeN();
166
+ this.#nComputed = true;
167
+ }
168
+ return this.#n;
62
169
  }
63
170
 
64
- lazy.prop(o, 'output', () => {
65
- if (!a.m) return;
66
- if (!o.n) return;
67
- if (!a.pubkeys) return;
171
+ /**
172
+ * Array of public keys.
173
+ */
174
+ get pubkeys(): PublicKey[] | undefined {
175
+ if (!this.#pubkeysComputed) {
176
+ this.#pubkeys = this.#computePubkeys();
177
+ this.#pubkeysComputed = true;
178
+ }
179
+ return this.#pubkeys as PublicKey[] | undefined;
180
+ }
181
+
182
+ /**
183
+ * Array of signatures.
184
+ */
185
+ get signatures(): Signature[] | undefined {
186
+ if (!this.#signaturesComputed) {
187
+ this.#signatures = this.#computeSignatures();
188
+ this.#signaturesComputed = true;
189
+ }
190
+ return this.#signatures as Signature[] | undefined;
191
+ }
192
+
193
+ /**
194
+ * The scriptPubKey: `m {pubkeys} n OP_CHECKMULTISIG`
195
+ */
196
+ get output(): Script | undefined {
197
+ if (!this.#outputComputed) {
198
+ this.#output = this.#computeOutput();
199
+ this.#outputComputed = true;
200
+ }
201
+ return this.#output as Script | undefined;
202
+ }
203
+
204
+ /**
205
+ * The scriptSig: `OP_0 {signatures}`
206
+ */
207
+ get input(): Script | undefined {
208
+ if (!this.#inputComputed) {
209
+ this.#input = this.#computeInput();
210
+ this.#inputComputed = true;
211
+ }
212
+ return this.#input as Script | undefined;
213
+ }
214
+
215
+ /**
216
+ * Witness stack (empty for P2MS as it's not a SegWit type).
217
+ */
218
+ get witness(): Uint8Array[] | undefined {
219
+ if (!this.#witnessComputed) {
220
+ this.#witness = this.#computeWitness();
221
+ this.#witnessComputed = true;
222
+ }
223
+ return this.#witness;
224
+ }
225
+
226
+ // Static factory methods
227
+
228
+ /**
229
+ * Creates a P2MS payment from public keys.
230
+ *
231
+ * @param m - Required number of signatures
232
+ * @param pubkeys - Array of public keys
233
+ * @param network - Network parameters (defaults to mainnet)
234
+ * @returns A new P2MS payment instance
235
+ *
236
+ * @example
237
+ * ```typescript
238
+ * // Create a 2-of-3 multisig
239
+ * const payment = P2MS.fromPubkeys(2, [pubkey1, pubkey2, pubkey3]);
240
+ * ```
241
+ */
242
+ static fromPubkeys(m: number, pubkeys: PublicKey[], network?: Network): P2MS {
243
+ return new P2MS({ m, pubkeys, network });
244
+ }
245
+
246
+ /**
247
+ * Creates a P2MS payment from a scriptPubKey.
248
+ *
249
+ * @param output - The scriptPubKey
250
+ * @param network - Network parameters (defaults to mainnet)
251
+ * @returns A new P2MS payment instance
252
+ */
253
+ static fromOutput(output: Uint8Array, network?: Network): P2MS {
254
+ return new P2MS({ output, network });
255
+ }
256
+
257
+ /**
258
+ * Creates a P2MS payment from signatures (for spending).
259
+ *
260
+ * @param signatures - Array of signatures
261
+ * @param m - Required number of signatures (optional)
262
+ * @param pubkeys - Array of public keys (optional, for validation)
263
+ * @param network - Network parameters (defaults to mainnet)
264
+ * @returns A new P2MS payment instance
265
+ */
266
+ static fromSignatures(
267
+ signatures: Signature[],
268
+ m?: number,
269
+ pubkeys?: PublicKey[],
270
+ network?: Network,
271
+ ): P2MS {
272
+ return new P2MS({ signatures, m, pubkeys, network });
273
+ }
274
+
275
+ // Private helper methods
276
+
277
+ #decode(output: Uint8Array | Stack): void {
278
+ if (this.#decoded) return;
279
+ this.#decoded = true;
280
+ this.#decodedChunks = (bscript.decompile(output) ?? []) as Stack;
281
+ this.#m = (this.#decodedChunks[0] as number) - OP_INT_BASE;
282
+ this.#n = (this.#decodedChunks[this.#decodedChunks.length - 2] as number) - OP_INT_BASE;
283
+ this.#pubkeys = this.#decodedChunks.slice(1, -2) as Uint8Array[];
284
+ this.#mComputed = true;
285
+ this.#nComputed = true;
286
+ this.#pubkeysComputed = true;
287
+ }
288
+
289
+ // Private computation methods
290
+
291
+ #computeM(): number | undefined {
292
+ if (this.#inputM !== undefined) {
293
+ return this.#inputM;
294
+ }
295
+ const output = this.#inputOutput ?? this.output;
296
+ if (output) {
297
+ this.#decode(output);
298
+ return this.#m;
299
+ }
300
+ return undefined;
301
+ }
302
+
303
+ #computeN(): number | undefined {
304
+ if (this.#inputN !== undefined) {
305
+ return this.#inputN;
306
+ }
307
+ if (this.#inputPubkeys) {
308
+ return this.#inputPubkeys.length;
309
+ }
310
+ if (this.#inputOutput) {
311
+ this.#decode(this.#inputOutput);
312
+ return this.#n;
313
+ }
314
+ return undefined;
315
+ }
316
+
317
+ #computePubkeys(): PublicKey[] | undefined {
318
+ if (this.#inputPubkeys) {
319
+ return this.#inputPubkeys as PublicKey[];
320
+ }
321
+ if (this.#inputOutput) {
322
+ this.#decode(this.#inputOutput);
323
+ return this.#pubkeys as PublicKey[] | undefined;
324
+ }
325
+ return undefined;
326
+ }
327
+
328
+ #computeSignatures(): Signature[] | undefined {
329
+ if (this.#inputSignatures) {
330
+ return this.#inputSignatures as Signature[];
331
+ }
332
+ if (this.#inputInput) {
333
+ const decompiled = bscript.decompile(this.#inputInput);
334
+ if (decompiled === null || decompiled === undefined) {
335
+ return undefined;
336
+ }
337
+ return decompiled.slice(1) as Signature[];
338
+ }
339
+ return undefined;
340
+ }
341
+
342
+ #computeOutput(): Script | undefined {
343
+ if (this.#inputOutput) {
344
+ return this.#inputOutput as Script;
345
+ }
346
+ const m = this.#inputM;
347
+ const n = this.n;
348
+ const pubkeys = this.#inputPubkeys;
349
+ if (m === undefined || n === undefined || !pubkeys) {
350
+ return undefined;
351
+ }
68
352
  return bscript.compile(
69
- ([] as Stack).concat(
70
- OP_INT_BASE + a.m,
71
- a.pubkeys,
72
- OP_INT_BASE + o.n,
73
- OPS.OP_CHECKMULTISIG,
74
- ),
353
+ ([] as Stack).concat(OP_INT_BASE + m, pubkeys, OP_INT_BASE + n, OPS.OP_CHECKMULTISIG),
354
+ ) as Script;
355
+ }
356
+
357
+ #computeInput(): Script | undefined {
358
+ if (this.#inputInput) {
359
+ return this.#inputInput as Script;
360
+ }
361
+ if (!this.#inputSignatures) {
362
+ return undefined;
363
+ }
364
+ return bscript.compile(([OPS.OP_0] as Stack).concat(this.#inputSignatures)) as Script;
365
+ }
366
+
367
+ #computeWitness(): Uint8Array[] | undefined {
368
+ if (this.input) {
369
+ return [];
370
+ }
371
+ return undefined;
372
+ }
373
+
374
+ // Validation
375
+
376
+ #isAcceptableSignature(x: Uint8Array | number): boolean {
377
+ return (
378
+ bscript.isCanonicalScriptSignature(x as Uint8Array) ||
379
+ (this.#opts.allowIncomplete && (x as number) === OPS.OP_0)
75
380
  );
76
- });
77
- lazy.prop(o, 'm', () => {
78
- if (!o.output) return;
79
- decode(o.output);
80
- return o.m;
81
- });
82
- lazy.prop(o, 'n', () => {
83
- if (!o.pubkeys) return;
84
- return o.pubkeys.length;
85
- });
86
- lazy.prop(o, 'pubkeys', () => {
87
- if (!a.output) return;
88
- decode(a.output);
89
- return o.pubkeys;
90
- });
91
- lazy.prop<P2MSPayment>(o, 'signatures', () => {
92
- if (!a.input) return;
93
- const decompiled = bscript.decompile(a.input);
94
- if (decompiled === null || decompiled === undefined) return;
95
-
96
- return decompiled.slice(1) as Buffer[];
97
- });
98
- lazy.prop(o, 'input', () => {
99
- if (!a.signatures) return;
100
- return bscript.compile(([OPS.OP_0] as Stack).concat(a.signatures));
101
- });
102
- lazy.prop(o, 'witness', () => {
103
- if (!o.input) return;
104
- return [];
105
- });
106
- lazy.prop(o, 'name', () => {
107
- if (!o.m || !o.n) return;
108
- return `p2ms(${o.m} of ${o.n})`;
109
- });
110
-
111
- // extended validation
112
- if (opts.validate) {
113
- if (a.output) {
114
- decode(a.output);
115
- if (!typef.Number(chunks[0])) throw new TypeError('Output is invalid');
116
- if (!typef.Number(chunks[chunks.length - 2])) throw new TypeError('Output is invalid');
117
- if (chunks[chunks.length - 1] !== OPS.OP_CHECKMULTISIG)
381
+ }
382
+
383
+ #validate(): void {
384
+ if (this.#inputOutput) {
385
+ this.#decode(this.#inputOutput);
386
+ const chunks = this.#decodedChunks;
387
+ if (!chunks) {
118
388
  throw new TypeError('Output is invalid');
389
+ }
119
390
 
120
- if (o.m! <= 0 || o.n! > 16 || o.m! > o.n! || o.n !== chunks.length - 3)
391
+ if (typeof chunks[0] !== 'number') {
392
+ throw new TypeError('Output is invalid');
393
+ }
394
+ if (typeof chunks[chunks.length - 2] !== 'number') {
395
+ throw new TypeError('Output is invalid');
396
+ }
397
+ if (chunks[chunks.length - 1] !== OPS.OP_CHECKMULTISIG) {
398
+ throw new TypeError('Output is invalid');
399
+ }
400
+
401
+ const m = this.#m;
402
+ const n = this.#n;
403
+ const pubkeys = this.#pubkeys;
404
+ if (m === undefined || n === undefined || !pubkeys) {
405
+ throw new TypeError('Output is invalid');
406
+ }
407
+
408
+ if (m <= 0 || n > 16 || m > n || n !== chunks.length - 3) {
409
+ throw new TypeError('Output is invalid');
410
+ }
411
+ if (!pubkeys.every((x) => isPoint(x))) {
121
412
  throw new TypeError('Output is invalid');
122
- if (!o.pubkeys!.every((x) => isPoint(x))) throw new TypeError('Output is invalid');
413
+ }
123
414
 
124
- if (a.m !== undefined && a.m !== o.m) throw new TypeError('m mismatch');
125
- if (a.n !== undefined && a.n !== o.n) throw new TypeError('n mismatch');
126
- if (a.pubkeys && !stacksEqual(a.pubkeys, o.pubkeys!))
415
+ if (this.#inputM !== undefined && this.#inputM !== m) {
416
+ throw new TypeError('m mismatch');
417
+ }
418
+ if (this.#inputN !== undefined && this.#inputN !== n) {
419
+ throw new TypeError('n mismatch');
420
+ }
421
+ if (this.#inputPubkeys && !stacksEqual(this.#inputPubkeys, pubkeys)) {
127
422
  throw new TypeError('Pubkeys mismatch');
423
+ }
128
424
  }
129
425
 
130
- if (a.pubkeys) {
131
- if (a.n !== undefined && a.n !== a.pubkeys.length)
426
+ if (this.#inputPubkeys) {
427
+ if (this.#inputN !== undefined && this.#inputN !== this.#inputPubkeys.length) {
132
428
  throw new TypeError('Pubkey count mismatch');
133
- o.n = a.pubkeys.length;
429
+ }
430
+ this.#n = this.#inputPubkeys.length;
431
+ this.#nComputed = true;
134
432
 
135
- if (o.n < o.m!) throw new TypeError('Pubkey count cannot be less than m');
433
+ if (this.#m !== undefined && this.#n < this.#m) {
434
+ throw new TypeError('Pubkey count cannot be less than m');
435
+ }
136
436
  }
137
437
 
138
- if (a.signatures) {
139
- if (a.signatures.length < o.m!) throw new TypeError('Not enough signatures provided');
140
- if (a.signatures.length > o.m!) throw new TypeError('Too many signatures provided');
438
+ if (this.#inputSignatures) {
439
+ if (this.#m !== undefined && this.#inputSignatures.length < this.#m) {
440
+ throw new TypeError('Not enough signatures provided');
441
+ }
442
+ if (this.#m !== undefined && this.#inputSignatures.length > this.#m) {
443
+ throw new TypeError('Too many signatures provided');
444
+ }
141
445
  }
142
446
 
143
- if (a.input) {
144
- if (a.input[0] !== OPS.OP_0) throw new TypeError('Input is invalid');
145
- if (o.signatures!.length === 0 || !o.signatures!.every(isAcceptableSignature))
447
+ if (this.#inputInput) {
448
+ if (this.#inputInput[0] !== OPS.OP_0) {
449
+ throw new TypeError('Input is invalid');
450
+ }
451
+ const sigs = this.signatures;
452
+ if (!sigs || sigs.length === 0 || !sigs.every((s) => this.#isAcceptableSignature(s))) {
146
453
  throw new TypeError('Input has invalid signature(s)');
454
+ }
147
455
 
148
- if (a.signatures && !stacksEqual(a.signatures, o.signatures!))
456
+ if (this.#inputSignatures && !stacksEqual(this.#inputSignatures, sigs)) {
149
457
  throw new TypeError('Signature mismatch');
150
- if (a.m !== undefined && a.m !== a.signatures!.length)
458
+ }
459
+ if (
460
+ this.#inputM !== undefined &&
461
+ this.#inputSignatures &&
462
+ this.#inputM !== this.#inputSignatures.length
463
+ ) {
151
464
  throw new TypeError('Signature count mismatch');
465
+ }
152
466
  }
153
467
  }
154
468
 
155
- return Object.assign(o, a);
469
+ /**
470
+ * Converts to a plain P2MSPayment object for backwards compatibility.
471
+ *
472
+ * @returns A P2MSPayment object
473
+ */
474
+ toPayment(): P2MSPayment {
475
+ return {
476
+ name: this.name,
477
+ network: this.network,
478
+ m: this.m,
479
+ n: this.n,
480
+ pubkeys: this.pubkeys,
481
+ signatures: this.signatures,
482
+ output: this.output,
483
+ input: this.input,
484
+ witness: this.witness,
485
+ };
486
+ }
487
+ }
488
+
489
+ /**
490
+ * Creates a Pay-to-Multisig (P2MS) payment object.
491
+ *
492
+ * This is the legacy factory function for backwards compatibility.
493
+ * For new code, prefer using the P2MS class directly.
494
+ *
495
+ * @param a - The payment object containing the necessary data
496
+ * @param opts - Optional payment options
497
+ * @returns The P2MS payment object
498
+ * @throws {TypeError} If the required data is not provided or if the data is invalid
499
+ *
500
+ * @example
501
+ * ```typescript
502
+ * import { p2ms } from '@btc-vision/bitcoin';
503
+ *
504
+ * // Create a 2-of-3 multisig
505
+ * const payment = p2ms({ m: 2, pubkeys: [pubkey1, pubkey2, pubkey3] });
506
+ * ```
507
+ */
508
+ export function p2ms(a: Omit<P2MSPayment, 'name'>, opts?: PaymentOpts): P2MSPayment {
509
+ if (!a.input && !a.output && !(a.pubkeys && a.m !== undefined) && !a.signatures) {
510
+ throw new TypeError('Not enough data');
511
+ }
512
+
513
+ const instance = new P2MS(
514
+ {
515
+ m: a.m,
516
+ n: a.n,
517
+ pubkeys: a.pubkeys,
518
+ signatures: a.signatures,
519
+ output: a.output,
520
+ input: a.input,
521
+ network: a.network,
522
+ },
523
+ opts,
524
+ );
525
+
526
+ // Return a merged object for backwards compatibility
527
+ return Object.assign(instance.toPayment(), a);
156
528
  }