@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/build/merkle.js CHANGED
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Calculates the Merkle root of an array of Uint8Arrays using a specified digest function.
3
+ *
4
+ * @param values - The array of Uint8Arrays.
5
+ * @param digestFn - The digest function used to calculate the hash of the concatenated arrays.
6
+ * @returns The Merkle root as a Uint8Array.
7
+ * @throws {TypeError} If the values parameter is not an array or the digestFn parameter is not a function.
8
+ */
1
9
  export function fastMerkleRoot(values, digestFn) {
2
10
  if (!Array.isArray(values))
3
11
  throw TypeError('Expected values Array');
@@ -10,10 +18,13 @@ export function fastMerkleRoot(values, digestFn) {
10
18
  for (let i = 0; i < length; i += 2, ++j) {
11
19
  const left = results[i];
12
20
  const right = i + 1 === length ? left : results[i + 1];
13
- const data = Buffer.concat([left, right]);
21
+ const data = new Uint8Array(left.length + right.length);
22
+ data.set(left);
23
+ data.set(right, left.length);
14
24
  results[j] = digestFn(data);
15
25
  }
16
26
  length = j;
17
27
  }
18
28
  return results[0];
19
29
  }
30
+ //# sourceMappingURL=merkle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merkle.js","sourceRoot":"","sources":["../src/merkle.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAC1B,MAAoB,EACpB,QAAuC;IAEvC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,MAAM,SAAS,CAAC,uBAAuB,CAAC,CAAC;IACrE,IAAI,OAAO,QAAQ,KAAK,UAAU;QAAE,MAAM,SAAS,CAAC,0BAA0B,CAAC,CAAC;IAEhF,IAAI,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC3B,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;IAEhC,OAAO,MAAM,GAAG,CAAC,EAAE,CAAC;QAChB,IAAI,CAAC,GAAG,CAAC,CAAC;QAEV,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;YACtC,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAE,CAAC;YACzB,MAAM,KAAK,GAAG,CAAC,GAAG,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAE,CAAC;YACxD,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;YACxD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACf,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YAE7B,OAAO,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;QAChC,CAAC;QAED,MAAM,GAAG,CAAC,CAAC;IACf,CAAC;IAED,OAAO,OAAO,CAAC,CAAC,CAAE,CAAC;AACvB,CAAC"}
@@ -1,24 +1,85 @@
1
+ /**
2
+ * Represents a Bitcoin network configuration,including messagePrefix, bech32, bip32, pubKeyHash, scriptHash, wif.
3
+ * Support bitcoin、bitcoin testnet and bitcoin regtest.
4
+ * @packageDocumentation
5
+ */
1
6
  export interface Bip32 {
2
- public: number;
3
- private: number;
7
+ readonly public: number;
8
+ readonly private: number;
4
9
  }
5
10
  export interface Network {
6
- wif: number;
7
- bip32: Bip32;
8
- messagePrefix: string;
9
- bech32: string;
10
- bech32Opnet?: string;
11
- pubKeyHash: number;
12
- scriptHash: number;
11
+ readonly wif: number;
12
+ readonly bip32: Bip32;
13
+ readonly messagePrefix: string;
14
+ readonly bech32: string;
15
+ readonly bech32Opnet?: string;
16
+ readonly pubKeyHash: number;
17
+ readonly scriptHash: number;
13
18
  }
19
+ /**
20
+ * Represents the Bitcoin network configuration.
21
+ */
14
22
  export declare const bitcoin: Network;
23
+ /**
24
+ * Represents the regtest network configuration.
25
+ */
15
26
  export declare const regtest: Network;
27
+ /**
28
+ * Represents the testnet network configuration.
29
+ */
16
30
  export declare const testnet: Network;
31
+ /**
32
+ * Represents the Dogecoin mainnet configuration.
33
+ *
34
+ * Prefixes from:
35
+ * - P2PKH: 0x1e (30 decimal) - addresses start with 'D'
36
+ * - P2SH: 0x16 (22 decimal) - addresses often start with '9' or 'A'
37
+ * - WIF: 0x9e (158 decimal)
38
+ * - BIP32:
39
+ * - public: 0x02facafd
40
+ * - private: 0x02fac398
41
+ * Message prefix:
42
+ * - Dogecoin uses "\x19Dogecoin Signed Message:\n"
43
+ */
17
44
  export declare const dogecoin: Network;
45
+ /**
46
+ * Represents the Dogecoin testnet configuration.
47
+ *
48
+ * Prefixes from Dogecoin testnet chainparams:
49
+ * - P2PKH: 0x71 (113 decimal)
50
+ * - P2SH: 0xc4 (196 decimal)
51
+ * - WIF: 0xf1 (241 decimal)
52
+ * - BIP32:
53
+ * - public: 0x0432a9a8
54
+ * - private: 0x0432a243
55
+ * Message prefix:
56
+ * - Same as mainnet: "\x19Dogecoin Signed Message:\n"
57
+ */
18
58
  export declare const dogecoinTestnet: Network;
59
+ /**
60
+ * Litecoin mainnet configuration.
61
+ */
19
62
  export declare const litecoin: Network;
63
+ /**
64
+ * Litecoin testnet configuration.
65
+ */
20
66
  export declare const litecoinTestnet: Network;
67
+ /**
68
+ * Bitcoin Cash mainnet configuration (legacy).
69
+ * Note: Bitcoin Cash uses Cashaddr starting with 'q' or 'p',
70
+ * but we retain the legacy prefixes for compatibility.
71
+ */
21
72
  export declare const bitcoinCash: Network;
73
+ /**
74
+ * Bitcoin Cash testnet configuration (legacy).
75
+ */
22
76
  export declare const bitcoinCashTestnet: Network;
77
+ /**
78
+ * Dash mainnet configuration.
79
+ */
23
80
  export declare const dash: Network;
81
+ /**
82
+ * Dash testnet configuration.
83
+ */
24
84
  export declare const dashTestnet: Network;
85
+ //# sourceMappingURL=networks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"networks.d.ts","sourceRoot":"","sources":["../src/networks.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AAEH,MAAM,WAAW,KAAK;IAClB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,OAAO;IACpB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC/B;AAED;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,OAmCrB,CAAC;AACF;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,OAWrB,CAAC;AACF;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,OAWrB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,QAAQ,EAAE,OAWtB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,eAAe,EAAE,OAW7B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,OAWtB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,OAW7B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,OAazB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,OAWhC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,IAAI,EAAE,OAalB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,OAWzB,CAAC"}
package/build/networks.js CHANGED
@@ -1,15 +1,47 @@
1
+ // https://en.bitcoin.it/wiki/List_of_address_prefixes
2
+ // Dogecoin BIP32 is a proposed standard: https://bitcointalk.org/index.php?topic=409731
3
+ /**
4
+ * Represents the Bitcoin network configuration.
5
+ */
1
6
  export const bitcoin = {
7
+ /**
8
+ * The message prefix used for signing Bitcoin messages.
9
+ */
2
10
  messagePrefix: '\x18Bitcoin Signed Message:\n',
11
+ /**
12
+ * The Bech32 prefix used for Bitcoin addresses.
13
+ */
3
14
  bech32: 'bc',
4
15
  bech32Opnet: 'op',
16
+ /**
17
+ * The BIP32 key prefixes for Bitcoin.
18
+ */
5
19
  bip32: {
20
+ /**
21
+ * The public key prefix for BIP32 extended public keys.
22
+ */
6
23
  public: 0x0488b21e,
24
+ /**
25
+ * The private key prefix for BIP32 extended private keys.
26
+ */
7
27
  private: 0x0488ade4,
8
28
  },
29
+ /**
30
+ * The prefix for Bitcoin public key hashes.
31
+ */
9
32
  pubKeyHash: 0x00,
33
+ /**
34
+ * The prefix for Bitcoin script hashes.
35
+ */
10
36
  scriptHash: 0x05,
37
+ /**
38
+ * The prefix for Bitcoin Wallet Import Format (WIF) private keys.
39
+ */
11
40
  wif: 0x80,
12
41
  };
42
+ /**
43
+ * Represents the regtest network configuration.
44
+ */
13
45
  export const regtest = {
14
46
  messagePrefix: '\x18Bitcoin Signed Message:\n',
15
47
  bech32: 'bcrt',
@@ -22,6 +54,9 @@ export const regtest = {
22
54
  scriptHash: 0xc4,
23
55
  wif: 0xef,
24
56
  };
57
+ /**
58
+ * Represents the testnet network configuration.
59
+ */
25
60
  export const testnet = {
26
61
  messagePrefix: '\x18Bitcoin Signed Message:\n',
27
62
  bech32: 'tb',
@@ -34,9 +69,22 @@ export const testnet = {
34
69
  scriptHash: 0xc4,
35
70
  wif: 0xef,
36
71
  };
72
+ /**
73
+ * Represents the Dogecoin mainnet configuration.
74
+ *
75
+ * Prefixes from:
76
+ * - P2PKH: 0x1e (30 decimal) - addresses start with 'D'
77
+ * - P2SH: 0x16 (22 decimal) - addresses often start with '9' or 'A'
78
+ * - WIF: 0x9e (158 decimal)
79
+ * - BIP32:
80
+ * - public: 0x02facafd
81
+ * - private: 0x02fac398
82
+ * Message prefix:
83
+ * - Dogecoin uses "\x19Dogecoin Signed Message:\n"
84
+ */
37
85
  export const dogecoin = {
38
86
  messagePrefix: '\x19Dogecoin Signed Message:\n',
39
- bech32: '',
87
+ bech32: '', // Dogecoin does not currently use Bech32
40
88
  bech32Opnet: '',
41
89
  bip32: {
42
90
  public: 0x02facafd,
@@ -46,9 +94,22 @@ export const dogecoin = {
46
94
  scriptHash: 0x16,
47
95
  wif: 0x9e,
48
96
  };
97
+ /**
98
+ * Represents the Dogecoin testnet configuration.
99
+ *
100
+ * Prefixes from Dogecoin testnet chainparams:
101
+ * - P2PKH: 0x71 (113 decimal)
102
+ * - P2SH: 0xc4 (196 decimal)
103
+ * - WIF: 0xf1 (241 decimal)
104
+ * - BIP32:
105
+ * - public: 0x0432a9a8
106
+ * - private: 0x0432a243
107
+ * Message prefix:
108
+ * - Same as mainnet: "\x19Dogecoin Signed Message:\n"
109
+ */
49
110
  export const dogecoinTestnet = {
50
111
  messagePrefix: '\x19Dogecoin Signed Message:\n',
51
- bech32: '',
112
+ bech32: '', // Dogecoin testnet does not currently use Bech32
52
113
  bech32Opnet: '',
53
114
  bip32: {
54
115
  public: 0x0432a9a8,
@@ -58,6 +119,9 @@ export const dogecoinTestnet = {
58
119
  scriptHash: 0xc4,
59
120
  wif: 0xf1,
60
121
  };
122
+ /**
123
+ * Litecoin mainnet configuration.
124
+ */
61
125
  export const litecoin = {
62
126
  messagePrefix: '\x19Litecoin Signed Message:\n',
63
127
  bech32: 'ltc',
@@ -70,6 +134,9 @@ export const litecoin = {
70
134
  scriptHash: 0x32,
71
135
  wif: 0xb0,
72
136
  };
137
+ /**
138
+ * Litecoin testnet configuration.
139
+ */
73
140
  export const litecoinTestnet = {
74
141
  messagePrefix: '\x19Litecoin Signed Message:\n',
75
142
  bech32: 'tltc',
@@ -82,8 +149,15 @@ export const litecoinTestnet = {
82
149
  scriptHash: 0x3a,
83
150
  wif: 0xef,
84
151
  };
152
+ /**
153
+ * Bitcoin Cash mainnet configuration (legacy).
154
+ * Note: Bitcoin Cash uses Cashaddr starting with 'q' or 'p',
155
+ * but we retain the legacy prefixes for compatibility.
156
+ */
85
157
  export const bitcoinCash = {
86
158
  messagePrefix: '\x18Bitcoin Signed Message:\n',
159
+ // Cashaddr prefix differs from bech32 for general usage, but we can set it similarly.
160
+ // Actual cashaddr prefix is "bitcoincash", but this field is for bech32 which BCH doesn't fully use for segwit (it doesn't have segwit).
87
161
  bech32: 'bitcoincash',
88
162
  bech32Opnet: 'opbch',
89
163
  bip32: {
@@ -94,6 +168,9 @@ export const bitcoinCash = {
94
168
  scriptHash: 0x05,
95
169
  wif: 0x80,
96
170
  };
171
+ /**
172
+ * Bitcoin Cash testnet configuration (legacy).
173
+ */
97
174
  export const bitcoinCashTestnet = {
98
175
  messagePrefix: '\x18Bitcoin Signed Message:\n',
99
176
  bech32: 'bchtest',
@@ -106,9 +183,14 @@ export const bitcoinCashTestnet = {
106
183
  scriptHash: 0xc4,
107
184
  wif: 0xef,
108
185
  };
186
+ /**
187
+ * Dash mainnet configuration.
188
+ */
109
189
  export const dash = {
190
+ // Historically Dash used DarkCoin message prefix, and most implementations use this:
191
+ // As of Dash Core 0.17, this has not changed in code.
110
192
  messagePrefix: '\x19DarkCoin Signed Message:\n',
111
- bech32: '',
193
+ bech32: '', // Dash does not use Bech32
112
194
  bech32Opnet: '',
113
195
  bip32: {
114
196
  public: 0x02fe52cc,
@@ -118,9 +200,12 @@ export const dash = {
118
200
  scriptHash: 0x10,
119
201
  wif: 0xcc,
120
202
  };
203
+ /**
204
+ * Dash testnet configuration.
205
+ */
121
206
  export const dashTestnet = {
122
207
  messagePrefix: '\x19DarkCoin Signed Message:\n',
123
- bech32: '',
208
+ bech32: '', // Dash testnet does not use Bech32
124
209
  bech32Opnet: '',
125
210
  bip32: {
126
211
  public: 0x3a8061a0,
@@ -130,3 +215,4 @@ export const dashTestnet = {
130
215
  scriptHash: 0x13,
131
216
  wif: 0xef,
132
217
  };
218
+ //# sourceMappingURL=networks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"networks.js","sourceRoot":"","sources":["../src/networks.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,wFAAwF;AAuBxF;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAY;IAC5B;;OAEG;IACH,aAAa,EAAE,+BAA+B;IAC9C;;OAEG;IACH,MAAM,EAAE,IAAI;IACZ,WAAW,EAAE,IAAI;IACjB;;OAEG;IACH,KAAK,EAAE;QACH;;WAEG;QACH,MAAM,EAAE,UAAU;QAClB;;WAEG;QACH,OAAO,EAAE,UAAU;KACtB;IACD;;OAEG;IACH,UAAU,EAAE,IAAI;IAChB;;OAEG;IACH,UAAU,EAAE,IAAI;IAChB;;OAEG;IACH,GAAG,EAAE,IAAI;CACZ,CAAC;AACF;;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E,EAAE;IACf,KAAK,EAAE;QACH,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE,UAAU;KACtB;IACD,UAAU,EAAE,IAAI;IAChB,UAAU,EAAE,IAAI;IAChB,GAAG,EAAE,IAAI;CACZ,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAY;IAChC,aAAa,EAAE,gCAAgC;IAC/C,MAAM,EAAE,EAAE,EAAE,mCAAmC;IAC/C,WAAW,EAAE,EAAE;IACf,KAAK,EAAE;QACH,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE,UAAU;KACtB;IACD,UAAU,EAAE,IAAI;IAChB,UAAU,EAAE,IAAI;IAChB,GAAG,EAAE,IAAI;CACZ,CAAC"}
@@ -123,3 +123,4 @@ export declare const opcodes: Opcodes;
123
123
  export declare const REVERSE_OPS: {
124
124
  [key: number]: string;
125
125
  };
126
+ //# sourceMappingURL=opcodes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opcodes.d.ts","sourceRoot":"","sources":["../src/opcodes.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,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BAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,MAAM,CAAC;IACzB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,sBAAsB,EAAE,MAAM,CAAC;IAC/B,sBAAsB,EAAE,MAAM,CAAC;IAE/B,cAAc,EAAE,MAAM,CAAC;IAGvB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IAGjB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;CAC5B;AAED,eAAO,MAAM,OAAO,EAAE,OAsIrB,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAO,CAAC"}
package/build/opcodes.js CHANGED
@@ -124,3 +124,4 @@ for (const op of Object.keys(opcodes)) {
124
124
  const code = opcodes[op];
125
125
  REVERSE_OPS[code] = op;
126
126
  }
127
+ //# sourceMappingURL=opcodes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opcodes.js","sourceRoot":"","sources":["../src/opcodes.ts"],"names":[],"mappings":"AA2IA,MAAM,CAAC,MAAM,OAAO,GAAY;IAC5B,QAAQ,EAAE,CAAC;IACX,IAAI,EAAE,CAAC;IACP,YAAY,EAAE,EAAE;IAChB,YAAY,EAAE,EAAE;IAChB,YAAY,EAAE,EAAE;IAChB,UAAU,EAAE,EAAE;IACd,WAAW,EAAE,EAAE;IACf,OAAO,EAAE,EAAE;IACX,IAAI,EAAE,EAAE;IACR,IAAI,EAAE,EAAE;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OAAO,EAAE,GAAG;IACZ,QAAQ,EAAE,GAAG;IAEb,cAAc,EAAE,GAAG;IAEnB,aAAa,EAAE,GAAG;IAClB,SAAS,EAAE,GAAG;IACd,gBAAgB,EAAE,GAAG;CACxB,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAA8B,EAAE,CAAC;AACzD,KAAK,MAAM,EAAE,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;IACpC,MAAM,IAAI,GAAG,OAAO,CAAC,EAAmB,CAAC,CAAC;IAC1C,WAAW,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;AAC3B,CAAC"}
@@ -1,23 +1,50 @@
1
- import { Tapleaf, Taptree } from '../types.js';
1
+ import type { Tapleaf, Taptree } from '../types.js';
2
+ import type { Bytes32, XOnlyPublicKey } from '../types.js';
2
3
  export declare const LEAF_VERSION_TAPSCRIPT = 192;
3
4
  export declare const MAX_TAPTREE_DEPTH = 128;
4
5
  interface HashLeaf {
5
- hash: Buffer;
6
+ hash: Bytes32;
6
7
  }
7
8
  interface HashBranch {
8
- hash: Buffer;
9
+ hash: Bytes32;
9
10
  left: HashTree;
10
11
  right: HashTree;
11
12
  }
12
13
  interface TweakedPublicKey {
13
14
  parity: number;
14
- x: Buffer;
15
+ x: XOnlyPublicKey;
15
16
  }
17
+ /**
18
+ * Binary tree representing leaf, branch, and root node hashes of a Taptree.
19
+ * Each node contains a hash, and potentially left and right branch hashes.
20
+ * This tree is used for 2 purposes: Providing the root hash for tweaking,
21
+ * and calculating merkle inclusion proofs when constructing a control block.
22
+ */
16
23
  export type HashTree = HashLeaf | HashBranch;
17
- export declare function rootHashFromPath(controlBlock: Buffer, leafHash: Buffer): Buffer;
24
+ /**
25
+ * Calculates the root hash from a given control block and leaf hash.
26
+ * @param controlBlock - The control block.
27
+ * @param leafHash - The leaf hash.
28
+ * @returns The root hash.
29
+ * @throws {TypeError} If the control block length is less than 33.
30
+ */
31
+ export declare function rootHashFromPath(controlBlock: Uint8Array, leafHash: Uint8Array): Bytes32;
32
+ /**
33
+ * Build a hash tree of merkle nodes from the scripts binary tree.
34
+ * @param scriptTree - the tree of scripts to pairwise hash.
35
+ */
18
36
  export declare function toHashTree(scriptTree: Taptree): HashTree;
19
- export declare function findScriptPath(node: HashTree, hash: Buffer): Buffer[] | undefined;
20
- export declare function tapleafHash(leaf: Tapleaf): Buffer;
21
- export declare function tapTweakHash(pubKey: Buffer, h: Buffer | undefined): Buffer;
22
- export declare function tweakKey(pubKey: Buffer, h: Buffer | undefined): TweakedPublicKey | null;
37
+ /**
38
+ * Given a HashTree, finds the path from a particular hash to the root.
39
+ * @param node - the root of the tree
40
+ * @param hash - the hash to search for
41
+ * @returns - array of sibling hashes, from leaf (inclusive) to root
42
+ * (exclusive) needed to prove inclusion of the specified hash. undefined if no
43
+ * path is found
44
+ */
45
+ export declare function findScriptPath(node: HashTree, hash: Bytes32): Bytes32[] | undefined;
46
+ export declare function tapleafHash(leaf: Tapleaf): Bytes32;
47
+ export declare function tapTweakHash(pubKey: XOnlyPublicKey, h: Bytes32 | undefined): Bytes32;
48
+ export declare function tweakKey(pubKey: XOnlyPublicKey, h: Bytes32 | undefined): TweakedPublicKey | null;
23
49
  export {};
50
+ //# sourceMappingURL=bip341.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bip341.d.ts","sourceRoot":"","sources":["../../src/payments/bip341.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE3D,eAAO,MAAM,sBAAsB,MAAO,CAAC;AAC3C,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAErC,UAAU,QAAQ;IACd,IAAI,EAAE,OAAO,CAAC;CACjB;AAED,UAAU,UAAU;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,QAAQ,CAAC;CACnB;AAED,UAAU,gBAAgB;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,CAAC,EAAE,cAAc,CAAC;CACrB;AAID;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,UAAU,CAAC;AAE7C;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,GAAG,OAAO,CAkBxF;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,OAAO,GAAG,QAAQ,CAYxD;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,EAAE,GAAG,SAAS,CAYnF;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAMlD;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,OAAO,CAEpF;AAED,wBAAgB,QAAQ,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,gBAAgB,GAAG,IAAI,CAchG"}
@@ -1,11 +1,18 @@
1
- import { Buffer as NBuffer } from 'buffer';
2
1
  import * as bcrypto from '../crypto.js';
3
- import { getEccLib } from '../ecc_lib.js';
4
- import { varuint } from '../bufferutils.js';
2
+ import { getEccLib } from '../ecc/context.js';
3
+ import { concat, compare, equals, alloc } from '../io/index.js';
4
+ import { varuint } from '../io/index.js';
5
5
  import { isTapleaf } from '../types.js';
6
6
  export const LEAF_VERSION_TAPSCRIPT = 0xc0;
7
7
  export const MAX_TAPTREE_DEPTH = 128;
8
8
  const isHashBranch = (ht) => 'left' in ht && 'right' in ht;
9
+ /**
10
+ * Calculates the root hash from a given control block and leaf hash.
11
+ * @param controlBlock - The control block.
12
+ * @param leafHash - The leaf hash.
13
+ * @returns The root hash.
14
+ * @throws {TypeError} If the control block length is less than 33.
15
+ */
9
16
  export function rootHashFromPath(controlBlock, leafHash) {
10
17
  if (controlBlock.length < 33)
11
18
  throw new TypeError(`The control-block length is too small. Got ${controlBlock.length}, expected min 33.`);
@@ -13,7 +20,7 @@ export function rootHashFromPath(controlBlock, leafHash) {
13
20
  let kj = leafHash;
14
21
  for (let j = 0; j < m; j++) {
15
22
  const ej = controlBlock.subarray(33 + 32 * j, 65 + 32 * j);
16
- if (kj.compare(ej) < 0) {
23
+ if (compare(kj, ej) < 0) {
17
24
  kj = tapBranchHash(kj, ej);
18
25
  }
19
26
  else {
@@ -22,18 +29,30 @@ export function rootHashFromPath(controlBlock, leafHash) {
22
29
  }
23
30
  return kj;
24
31
  }
32
+ /**
33
+ * Build a hash tree of merkle nodes from the scripts binary tree.
34
+ * @param scriptTree - the tree of scripts to pairwise hash.
35
+ */
25
36
  export function toHashTree(scriptTree) {
26
37
  if (isTapleaf(scriptTree))
27
38
  return { hash: tapleafHash(scriptTree) };
28
39
  const hashes = [toHashTree(scriptTree[0]), toHashTree(scriptTree[1])];
29
- hashes.sort((a, b) => a.hash.compare(b.hash));
40
+ hashes.sort((a, b) => compare(a.hash, b.hash));
30
41
  const [left, right] = hashes;
31
42
  return {
32
43
  hash: tapBranchHash(left.hash, right.hash),
33
- left,
34
- right,
44
+ left: left,
45
+ right: right,
35
46
  };
36
47
  }
48
+ /**
49
+ * Given a HashTree, finds the path from a particular hash to the root.
50
+ * @param node - the root of the tree
51
+ * @param hash - the hash to search for
52
+ * @returns - array of sibling hashes, from leaf (inclusive) to root
53
+ * (exclusive) needed to prove inclusion of the specified hash. undefined if no
54
+ * path is found
55
+ */
37
56
  export function findScriptPath(node, hash) {
38
57
  if (isHashBranch(node)) {
39
58
  const leftPath = findScriptPath(node.left, hash);
@@ -43,20 +62,20 @@ export function findScriptPath(node, hash) {
43
62
  if (rightPath !== undefined)
44
63
  return [...rightPath, node.left.hash];
45
64
  }
46
- else if (node.hash.equals(hash)) {
65
+ else if (equals(node.hash, hash)) {
47
66
  return [];
48
67
  }
49
68
  return undefined;
50
69
  }
51
70
  export function tapleafHash(leaf) {
52
71
  const version = leaf.version || LEAF_VERSION_TAPSCRIPT;
53
- return bcrypto.taggedHash('TapLeaf', NBuffer.concat([NBuffer.from([version]), serializeScript(leaf.output)]));
72
+ return bcrypto.taggedHash('TapLeaf', concat([new Uint8Array([version]), serializeScript(leaf.output)]));
54
73
  }
55
74
  export function tapTweakHash(pubKey, h) {
56
- return bcrypto.taggedHash('TapTweak', NBuffer.concat(h ? [pubKey, h] : [pubKey]));
75
+ return bcrypto.taggedHash('TapTweak', h ? concat([pubKey, h]) : pubKey);
57
76
  }
58
77
  export function tweakKey(pubKey, h) {
59
- if (!NBuffer.isBuffer(pubKey))
78
+ if (!(pubKey instanceof Uint8Array))
60
79
  return null;
61
80
  if (pubKey.length !== 32)
62
81
  return null;
@@ -68,15 +87,16 @@ export function tweakKey(pubKey, h) {
68
87
  return null;
69
88
  return {
70
89
  parity: res.parity,
71
- x: NBuffer.from(res.xOnlyPubkey),
90
+ x: new Uint8Array(res.xOnlyPubkey),
72
91
  };
73
92
  }
74
93
  function tapBranchHash(a, b) {
75
- return bcrypto.taggedHash('TapBranch', NBuffer.concat([a, b]));
94
+ return bcrypto.taggedHash('TapBranch', concat([a, b]));
76
95
  }
77
96
  function serializeScript(s) {
78
97
  const varintLen = varuint.encodingLength(s.length);
79
- const buffer = NBuffer.allocUnsafe(varintLen);
98
+ const buffer = alloc(varintLen);
80
99
  varuint.encode(s.length, buffer);
81
- return NBuffer.concat([buffer, s]);
100
+ return concat([buffer, s]);
82
101
  }
102
+ //# sourceMappingURL=bip341.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bip341.js","sourceRoot":"","sources":["../../src/payments/bip341.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,C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O,OAAO,CAAC,UAAU,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAY,CAAC;AACtE,CAAC;AAED,SAAS,eAAe,CAAC,CAAa;IAClC,MAAM,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IACnD,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,OAAO,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;AAC/B,CAAC"}
@@ -1,2 +1,121 @@
1
- import { EmbedPayment, PaymentOpts } from './types.js';
1
+ /**
2
+ * OP_RETURN Embed payment class.
3
+ *
4
+ * Embed payments use OP_RETURN to store arbitrary data in the blockchain.
5
+ * These outputs are provably unspendable.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ import { type Network } from '../networks.js';
10
+ import type { Script } from '../types.js';
11
+ import { PaymentType, type EmbedPayment, type PaymentOpts } from './types.js';
12
+ /**
13
+ * OP_RETURN Embed payment class.
14
+ *
15
+ * Creates outputs of the form: `OP_RETURN {data1} {data2} ...`
16
+ * These outputs are provably unspendable and used for data storage.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * import { Embed } from '@btc-vision/bitcoin';
21
+ *
22
+ * // Create from data
23
+ * const payment = Embed.fromData([Buffer.from('Hello, Bitcoin!')]);
24
+ * console.log(payment.output); // scriptPubKey with OP_RETURN
25
+ *
26
+ * // Decode an existing output
27
+ * const decoded = Embed.fromOutput(scriptPubKey);
28
+ * console.log(decoded.data); // array of data chunks
29
+ * ```
30
+ */
31
+ export declare class Embed {
32
+ #private;
33
+ static readonly NAME: "embed";
34
+ /**
35
+ * Creates a new Embed payment instance.
36
+ *
37
+ * @param params - Payment parameters
38
+ * @param params.data - Array of data chunks to embed
39
+ * @param params.output - The scriptPubKey
40
+ * @param params.network - Network parameters (defaults to mainnet)
41
+ * @param opts - Payment options
42
+ * @param opts.validate - Whether to validate inputs (default: true)
43
+ *
44
+ * @throws {TypeError} If validation is enabled and data is invalid
45
+ */
46
+ constructor(params: {
47
+ data?: Uint8Array[] | undefined;
48
+ output?: Uint8Array | undefined;
49
+ network?: Network | undefined;
50
+ }, opts?: PaymentOpts);
51
+ /**
52
+ * Payment type discriminant.
53
+ */
54
+ get name(): typeof PaymentType.Embed;
55
+ /**
56
+ * Network parameters.
57
+ */
58
+ get network(): Network;
59
+ /**
60
+ * The embedded data chunks.
61
+ */
62
+ get data(): Uint8Array[];
63
+ /**
64
+ * The scriptPubKey: `OP_RETURN {data...}`
65
+ */
66
+ get output(): Script | undefined;
67
+ /**
68
+ * Creates an Embed payment from data chunks.
69
+ *
70
+ * @param data - Array of data chunks to embed
71
+ * @param network - Network parameters (defaults to mainnet)
72
+ * @returns A new Embed payment instance
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * const payment = Embed.fromData([
77
+ * new TextEncoder().encode('Hello'),
78
+ * new TextEncoder().encode('Bitcoin')
79
+ * ]);
80
+ * ```
81
+ */
82
+ static fromData(data: Uint8Array[], network?: Network): Embed;
83
+ /**
84
+ * Creates an Embed payment from a scriptPubKey.
85
+ *
86
+ * @param output - The scriptPubKey
87
+ * @param network - Network parameters (defaults to mainnet)
88
+ * @returns A new Embed payment instance
89
+ */
90
+ static fromOutput(output: Uint8Array, network?: Network): Embed;
91
+ /**
92
+ * Converts to a plain EmbedPayment object for backwards compatibility.
93
+ *
94
+ * @returns An EmbedPayment object
95
+ */
96
+ toPayment(): EmbedPayment;
97
+ }
98
+ /**
99
+ * Creates an OP_RETURN Embed payment object.
100
+ *
101
+ * This is the legacy factory function for backwards compatibility.
102
+ * For new code, prefer using the Embed class directly.
103
+ *
104
+ * @param a - The payment object containing the necessary data
105
+ * @param opts - Optional payment options
106
+ * @returns The Embed payment object
107
+ * @throws {TypeError} If the required data is not provided or if the data is invalid
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * import { p2data } from '@btc-vision/bitcoin';
112
+ *
113
+ * // Create from data
114
+ * const payment = p2data({ data: [Buffer.from('Hello')] });
115
+ *
116
+ * // Decode from output
117
+ * const decoded = p2data({ output: scriptPubKey });
118
+ * ```
119
+ */
2
120
  export declare function p2data(a: Omit<EmbedPayment, 'name'>, opts?: PaymentOpts): EmbedPayment;
121
+ //# sourceMappingURL=embed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"embed.d.ts","sourceRoot":"","sources":["../../src/payments/embed.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAA8B,KAAK,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAG1E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAI9E;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,KAAK;;IAEd,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAqB;IAkBzC;;;;;;;;;;;OAWG;gBAEC,MAAM,EAAE;QACJ,IAAI,CAAC,EAAE,UAAU,EAAE,GAAG,SAAS,CAAC;QAChC,MAAM,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;QAChC,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;KACjC,EACD,IAAI,CAAC,EAAE,WAAW;IAoBtB;;OAEG;IACH,IAAI,IAAI,IAAI,OAAO,WAAW,CAAC,KAAK,CAEnC;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,OAAO,CAErB;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,UAAU,EAAE,CAMvB;IAED;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,GAAG,SAAS,CAM/B;IAID;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,UAA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