@btc-vision/bitcoin 6.4.10 → 6.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. package/.babelrc +13 -4
  2. package/.mocharc.json +13 -13
  3. package/.prettierrc.json +12 -12
  4. package/CHANGELOG.md +403 -403
  5. package/CONTRIBUTING.md +83 -83
  6. package/LICENSE +21 -21
  7. package/README.md +201 -201
  8. package/browser/chunks/crypto-C6FlKKmp.js +2006 -0
  9. package/browser/chunks/payments-BE4vwHhV.js +1045 -0
  10. package/browser/chunks/psbt-Dlosf9CT.js +3853 -0
  11. package/browser/chunks/script-COWGdiOo.js +318 -0
  12. package/browser/chunks/transaction-BiXwH2v4.js +421 -0
  13. package/browser/chunks/utils-BKmkTzNZ.js +759 -0
  14. package/browser/crypto/crypto.d.ts +1 -1
  15. package/browser/index.d.ts +7 -27
  16. package/browser/index.js +92 -2
  17. package/build/index.d.ts +7 -27
  18. package/build/index.js +2 -2
  19. package/cjs/package.json +3 -3
  20. package/gulpfile.js +42 -42
  21. package/package.json +153 -150
  22. package/src/bip66.ts +107 -107
  23. package/src/block.ts +233 -233
  24. package/src/bufferutils.ts +188 -188
  25. package/src/crypto.ts +108 -108
  26. package/src/ecc_lib.ts +94 -94
  27. package/src/hooks/AdvancedSignatureManager.ts +104 -104
  28. package/src/hooks/SignatureManager.ts +84 -84
  29. package/src/index.ts +83 -105
  30. package/src/merkle.ts +31 -31
  31. package/src/opcodes.ts +280 -280
  32. package/src/payments/bip341.ts +140 -140
  33. package/src/payments/embed.ts +61 -61
  34. package/src/payments/index.ts +172 -172
  35. package/src/payments/lazy.ts +28 -28
  36. package/src/payments/p2ms.ts +156 -156
  37. package/src/payments/p2op.ts +195 -195
  38. package/src/payments/p2pk.ts +93 -93
  39. package/src/payments/p2pkh.ts +214 -214
  40. package/src/payments/p2tr.ts +309 -309
  41. package/src/psbt/bip371.ts +441 -441
  42. package/src/push_data.ts +97 -97
  43. package/src/script.ts +247 -247
  44. package/src/script_number.ts +72 -72
  45. package/src/script_signature.ts +91 -91
  46. package/src/transaction.ts +656 -656
  47. package/test/address.spec.ts +155 -155
  48. package/test/bitcoin.core.spec.ts +212 -212
  49. package/test/block.spec.ts +171 -171
  50. package/test/bufferutils.spec.ts +450 -450
  51. package/test/crypto.spec.ts +49 -49
  52. package/test/fixtures/address.json +329 -329
  53. package/test/fixtures/block.json +148 -148
  54. package/test/fixtures/bufferutils.json +102 -102
  55. package/test/fixtures/core/README.md +26 -26
  56. package/test/fixtures/core/base58_encode_decode.json +50 -50
  57. package/test/fixtures/core/base58_keys_invalid.json +152 -152
  58. package/test/fixtures/core/base58_keys_valid.json +452 -452
  59. package/test/fixtures/core/blocks.json +27 -27
  60. package/test/fixtures/core/sig_canonical.json +7 -7
  61. package/test/fixtures/core/sig_noncanonical.json +33 -33
  62. package/test/fixtures/core/sighash.json +3505 -3505
  63. package/test/fixtures/core/tx_valid.json +2023 -2023
  64. package/test/fixtures/crypto.json +43 -43
  65. package/test/fixtures/ecdsa.json +217 -217
  66. package/test/fixtures/ecpair.json +141 -141
  67. package/test/fixtures/embed.json +108 -108
  68. package/test/fixtures/p2ms.json +434 -434
  69. package/test/fixtures/p2pk.json +179 -179
  70. package/test/fixtures/p2pkh.json +276 -276
  71. package/test/fixtures/p2sh.json +508 -508
  72. package/test/fixtures/p2tr.json +1198 -1198
  73. package/test/fixtures/p2wpkh.json +290 -290
  74. package/test/fixtures/p2wsh.json +489 -489
  75. package/test/fixtures/psbt.json +924 -924
  76. package/test/fixtures/script.json +465 -465
  77. package/test/fixtures/script_number.json +225 -225
  78. package/test/fixtures/signature.json +140 -140
  79. package/test/fixtures/transaction.json +916 -916
  80. package/test/integration/_regtest.ts +6 -6
  81. package/test/integration/addresses.spec.ts +142 -142
  82. package/test/integration/bip32.spec.ts +130 -130
  83. package/test/integration/blocks.spec.ts +28 -28
  84. package/test/integration/cltv.spec.ts +241 -241
  85. package/test/integration/csv.spec.ts +452 -452
  86. package/test/integration/payments.spec.ts +110 -110
  87. package/test/integration/taproot.spec.ts +663 -663
  88. package/test/integration/transactions.spec.ts +668 -668
  89. package/test/payments.spec.ts +114 -114
  90. package/test/payments.utils.ts +165 -165
  91. package/test/psbt.spec.ts +1285 -1285
  92. package/test/script.spec.ts +186 -186
  93. package/test/script_number.spec.ts +26 -26
  94. package/test/script_signature.spec.ts +66 -66
  95. package/test/transaction.spec.ts +337 -337
  96. package/test/ts-node-register.js +7 -7
  97. package/test/tsconfig.json +48 -48
  98. package/test/types.spec.ts +53 -53
  99. package/tsconfig.base.json +27 -27
  100. package/tsconfig.json +19 -19
  101. package/tsconfig.webpack.json +18 -18
  102. package/vite.config.browser.ts +93 -0
  103. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/.ready +0 -0
  104. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/.release-please-manifest.json +0 -3
  105. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/CHANGELOG.md +0 -962
  106. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/CONTRIBUTING.md +0 -34
  107. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/LICENSE +0 -24
  108. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/README.md +0 -273
  109. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/SECURITY.md +0 -2
  110. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/addon.gypi +0 -204
  111. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/bin/node-gyp.js +0 -138
  112. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/.release-please-manifest.json +0 -3
  113. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/LICENSE +0 -28
  114. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/data/ninja/build.ninja +0 -4
  115. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/data/win/large-pdb-shim.cc +0 -12
  116. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/GypVsCMake.md +0 -116
  117. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/Hacking.md +0 -46
  118. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/InputFormatReference.md +0 -1080
  119. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/LanguageSpecification.md +0 -430
  120. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/README.md +0 -27
  121. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/Testing.md +0 -450
  122. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/UserDocumentation.md +0 -965
  123. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/gyp +0 -8
  124. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/gyp.bat +0 -5
  125. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/gyp_main.py +0 -45
  126. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +0 -365
  127. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +0 -206
  128. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +0 -1272
  129. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +0 -1547
  130. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +0 -59
  131. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +0 -153
  132. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +0 -271
  133. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +0 -574
  134. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +0 -692
  135. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/common.py +0 -711
  136. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +0 -171
  137. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +0 -169
  138. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +0 -113
  139. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +0 -55
  140. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
  141. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +0 -804
  142. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +0 -1173
  143. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +0 -1318
  144. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +0 -127
  145. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +0 -103
  146. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +0 -461
  147. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +0 -89
  148. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +0 -57
  149. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +0 -2745
  150. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +0 -3976
  151. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +0 -44
  152. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +0 -2964
  153. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +0 -67
  154. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +0 -1391
  155. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +0 -25
  156. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/input.py +0 -3115
  157. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +0 -98
  158. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +0 -771
  159. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +0 -1260
  160. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +0 -174
  161. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +0 -61
  162. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +0 -373
  163. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +0 -1938
  164. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation_test.py +0 -53
  165. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +0 -302
  166. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +0 -3198
  167. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +0 -65
  168. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/LICENSE +0 -3
  169. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/LICENSE.APACHE +0 -177
  170. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/LICENSE.BSD +0 -23
  171. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/__init__.py +0 -15
  172. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_elffile.py +0 -108
  173. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_manylinux.py +0 -252
  174. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_musllinux.py +0 -83
  175. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_parser.py +0 -359
  176. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_structures.py +0 -61
  177. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_tokenizer.py +0 -192
  178. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/markers.py +0 -252
  179. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/metadata.py +0 -825
  180. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/py.typed +0 -0
  181. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/requirements.py +0 -90
  182. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/specifiers.py +0 -1030
  183. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/tags.py +0 -553
  184. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/utils.py +0 -172
  185. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/version.py +0 -563
  186. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pyproject.toml +0 -120
  187. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/release-please-config.json +0 -11
  188. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/test_gyp.py +0 -261
  189. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/Find-VisualStudio.cs +0 -250
  190. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/build.js +0 -227
  191. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/clean.js +0 -15
  192. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/configure.js +0 -328
  193. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/create-config-gypi.js +0 -150
  194. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/download.js +0 -39
  195. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/find-node-directory.js +0 -63
  196. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/find-python.js +0 -310
  197. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/find-visualstudio.js +0 -590
  198. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/install.js +0 -415
  199. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/list.js +0 -26
  200. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/log.js +0 -168
  201. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/node-gyp.js +0 -188
  202. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/process-release.js +0 -146
  203. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/rebuild.js +0 -12
  204. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/remove.js +0 -43
  205. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/util.js +0 -81
  206. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/macOS_Catalina_acid_test.sh +0 -21
  207. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/package.json +0 -51
  208. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/release-please-config.json +0 -40
  209. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/src/win_delay_load_hook.cc +0 -39
  210. package/browser/index.js.LICENSE.txt +0 -14
  211. package/browser/ops.d.ts +0 -126
  212. package/build/ops.d.ts +0 -126
  213. package/build/ops.js +0 -127
  214. package/coverage/tmp/coverage-31752-1735543485354-0.json +0 -1
  215. package/coverage/tmp/coverage-59920-1735543484555-0.json +0 -1
  216. package/coverage/tmp/coverage-66252-1735543483919-0.json +0 -1
  217. package/coverage/tmp/coverage-68440-1735543485236-0.json +0 -1
  218. package/coverage/tmp/coverage-70588-1735543484426-0.json +0 -1
  219. package/coverage/tmp/coverage-79292-1735543485296-0.json +0 -1
  220. package/coverage/tmp/coverage-80212-1735543483980-0.json +0 -1
@@ -0,0 +1,1045 @@
1
+ import { t as C, f as g, B as c, h as E, b as M } from "./crypto-C6FlKKmp.js";
2
+ import { g as ne, b as P, i as x, d as b, f as se, a as G } from "./psbt-Dlosf9CT.js";
3
+ import { b as me, g as ce, h as ae, t, s as N, j as T, i as we, T as W } from "./utils-BKmkTzNZ.js";
4
+ import { d as a, o as v, c as l, i as S, e as ie, f as ue, g as le } from "./script-COWGdiOo.js";
5
+ const F = 192, ye = 128, be = (e) => "left" in e && "right" in e;
6
+ function K(e, o) {
7
+ if (e.length < 33)
8
+ throw new TypeError(
9
+ `The control-block length is too small. Got ${e.length}, expected min 33.`
10
+ );
11
+ const p = (e.length - 33) / 32;
12
+ let u = o;
13
+ for (let s = 0; s < p; s++) {
14
+ const i = e.slice(33 + 32 * s, 65 + 32 * s);
15
+ u.compare(i) < 0 ? u = L(u, i) : u = L(i, u);
16
+ }
17
+ return u;
18
+ }
19
+ function A(e) {
20
+ if (me(e)) return { hash: H(e) };
21
+ const o = [A(e[0]), A(e[1])];
22
+ o.sort((s, i) => s.hash.compare(i.hash));
23
+ const [p, u] = o;
24
+ return {
25
+ hash: L(p.hash, u.hash),
26
+ left: p,
27
+ right: u
28
+ };
29
+ }
30
+ function q(e, o) {
31
+ if (be(e)) {
32
+ const p = q(e.left, o);
33
+ if (p !== void 0) return [...p, e.right.hash];
34
+ const u = q(e.right, o);
35
+ if (u !== void 0) return [...u, e.left.hash];
36
+ } else if (e.hash.equals(o))
37
+ return [];
38
+ }
39
+ function H(e) {
40
+ const o = e.version || F;
41
+ return C(
42
+ "TapLeaf",
43
+ g.concat([g.from([o]), ge(e.output)])
44
+ );
45
+ }
46
+ function oe(e, o) {
47
+ return C("TapTweak", g.concat(o ? [e, o] : [e]));
48
+ }
49
+ function j(e, o) {
50
+ if (!g.isBuffer(e) || e.length !== 32 || o && o.length !== 32) return null;
51
+ const p = oe(e, o), u = ne().xOnlyPointAddTweak(e, p);
52
+ return !u || u.xOnlyPubkey === null ? null : {
53
+ parity: u.parity,
54
+ x: g.from(u.xOnlyPubkey)
55
+ };
56
+ }
57
+ function L(e, o) {
58
+ return C("TapBranch", g.concat([e, o]));
59
+ }
60
+ function ge(e) {
61
+ const o = ce(e.length), p = g.allocUnsafe(o);
62
+ return ae(e.length, p), g.concat([p, e]);
63
+ }
64
+ function h(e, o, p) {
65
+ Object.defineProperty(e, o, {
66
+ configurable: !0,
67
+ enumerable: !0,
68
+ get() {
69
+ const u = p.call(this);
70
+ return this[o] = u, u;
71
+ },
72
+ set(u) {
73
+ Object.defineProperty(this, o, {
74
+ configurable: !0,
75
+ enumerable: !0,
76
+ value: u,
77
+ writable: !0
78
+ });
79
+ }
80
+ });
81
+ }
82
+ function y(e) {
83
+ let o;
84
+ return () => (o !== void 0 || (o = e()), o);
85
+ }
86
+ const D = v;
87
+ function ke(e, o) {
88
+ if (!e.data && !e.output) throw new TypeError("Not enough data");
89
+ o = Object.assign({ validate: !0 }, o || {}), t(
90
+ {
91
+ network: t.maybe(t.Object),
92
+ output: t.maybe(t.Buffer),
93
+ data: t.maybe(t.arrayOf(t.Buffer))
94
+ },
95
+ e
96
+ );
97
+ const p = e.network || P, u = { name: k.Embed, network: p, data: [] };
98
+ if (h(u, "output", () => {
99
+ if (e.data)
100
+ return l([D.OP_RETURN].concat(e.data));
101
+ }), h(u, "data", () => {
102
+ if (!e.output) return;
103
+ const s = a(e.output);
104
+ if (s != null)
105
+ return s.slice(1);
106
+ }), o.validate && e.output) {
107
+ const s = a(e.output);
108
+ if (s[0] !== D.OP_RETURN) throw new TypeError("Output is invalid");
109
+ if (!s.slice(1).every(t.Buffer)) throw new TypeError("Output is invalid");
110
+ if (e.data && !N(e.data, u.data))
111
+ throw new TypeError("Data mismatch");
112
+ }
113
+ return Object.assign(u, e);
114
+ }
115
+ const I = v, V = I.OP_RESERVED;
116
+ function Ee(e, o) {
117
+ if (!e.input && !e.output && !(e.pubkeys && e.m !== void 0) && !e.signatures)
118
+ throw new TypeError("Not enough data");
119
+ o = Object.assign({ validate: !0 }, o || {});
120
+ function p(f) {
121
+ return S(f) || (o.allowIncomplete && f === I.OP_0) !== void 0;
122
+ }
123
+ t(
124
+ {
125
+ network: t.maybe(t.Object),
126
+ m: t.maybe(t.Number),
127
+ n: t.maybe(t.Number),
128
+ output: t.maybe(t.Buffer),
129
+ pubkeys: t.maybe(t.arrayOf(T)),
130
+ signatures: t.maybe(t.arrayOf(p)),
131
+ input: t.maybe(t.Buffer)
132
+ },
133
+ e
134
+ );
135
+ const s = {
136
+ network: e.network || P,
137
+ name: k.P2MS
138
+ };
139
+ let i = [], n = !1;
140
+ function r(f) {
141
+ n || (n = !0, i = a(f), s.m = i[0] - V, s.n = i[i.length - 2] - V, s.pubkeys = i.slice(1, -2));
142
+ }
143
+ if (h(s, "output", () => {
144
+ if (e.m && s.n && e.pubkeys)
145
+ return l(
146
+ [].concat(
147
+ V + e.m,
148
+ e.pubkeys,
149
+ V + s.n,
150
+ I.OP_CHECKMULTISIG
151
+ )
152
+ );
153
+ }), h(s, "m", () => {
154
+ if (s.output)
155
+ return r(s.output), s.m;
156
+ }), h(s, "n", () => {
157
+ if (s.pubkeys)
158
+ return s.pubkeys.length;
159
+ }), h(s, "pubkeys", () => {
160
+ if (e.output)
161
+ return r(e.output), s.pubkeys;
162
+ }), h(s, "signatures", () => {
163
+ if (!e.input) return;
164
+ const f = a(e.input);
165
+ if (f != null)
166
+ return f.slice(1);
167
+ }), h(s, "input", () => {
168
+ if (e.signatures)
169
+ return l([I.OP_0].concat(e.signatures));
170
+ }), h(s, "witness", () => {
171
+ if (s.input)
172
+ return [];
173
+ }), h(s, "name", () => {
174
+ if (!(!s.m || !s.n))
175
+ return `p2ms(${s.m} of ${s.n})`;
176
+ }), o.validate) {
177
+ if (e.output) {
178
+ if (r(e.output), !t.Number(i[0])) throw new TypeError("Output is invalid");
179
+ if (!t.Number(i[i.length - 2])) throw new TypeError("Output is invalid");
180
+ if (i[i.length - 1] !== I.OP_CHECKMULTISIG)
181
+ throw new TypeError("Output is invalid");
182
+ if (s.m <= 0 || s.n > 16 || s.m > s.n || s.n !== i.length - 3)
183
+ throw new TypeError("Output is invalid");
184
+ if (!s.pubkeys.every((f) => T(f))) throw new TypeError("Output is invalid");
185
+ if (e.m !== void 0 && e.m !== s.m) throw new TypeError("m mismatch");
186
+ if (e.n !== void 0 && e.n !== s.n) throw new TypeError("n mismatch");
187
+ if (e.pubkeys && !N(e.pubkeys, s.pubkeys))
188
+ throw new TypeError("Pubkeys mismatch");
189
+ }
190
+ if (e.pubkeys) {
191
+ if (e.n !== void 0 && e.n !== e.pubkeys.length)
192
+ throw new TypeError("Pubkey count mismatch");
193
+ if (s.n = e.pubkeys.length, s.n < s.m) throw new TypeError("Pubkey count cannot be less than m");
194
+ }
195
+ if (e.signatures) {
196
+ if (e.signatures.length < s.m) throw new TypeError("Not enough signatures provided");
197
+ if (e.signatures.length > s.m) throw new TypeError("Too many signatures provided");
198
+ }
199
+ if (e.input) {
200
+ if (e.input[0] !== I.OP_0) throw new TypeError("Input is invalid");
201
+ if (s.signatures.length === 0 || !s.signatures.every(p))
202
+ throw new TypeError("Input has invalid signature(s)");
203
+ if (e.signatures && !N(e.signatures, s.signatures))
204
+ throw new TypeError("Signature mismatch");
205
+ if (e.m !== void 0 && e.m !== e.signatures.length)
206
+ throw new TypeError("Signature count mismatch");
207
+ }
208
+ }
209
+ return Object.assign(s, e);
210
+ }
211
+ const X = v;
212
+ function Te(e, o) {
213
+ if (!e.input && !e.output && !e.pubkey && !e.input && !e.signature)
214
+ throw new TypeError("Not enough data");
215
+ o = Object.assign({ validate: !0 }, o || {}), t(
216
+ {
217
+ network: t.maybe(t.Object),
218
+ output: t.maybe(t.Buffer),
219
+ pubkey: t.maybe(T),
220
+ signature: t.maybe(S),
221
+ input: t.maybe(t.Buffer)
222
+ },
223
+ e
224
+ );
225
+ const p = y(() => a(e.input)), u = e.network || P, s = {
226
+ name: k.P2PK,
227
+ network: u,
228
+ pubkey: void 0
229
+ };
230
+ if (h(s, "output", () => {
231
+ if (e.pubkey)
232
+ return l([e.pubkey, X.OP_CHECKSIG]);
233
+ }), h(s, "pubkey", () => {
234
+ if (e.output)
235
+ return e.output.slice(1, -1);
236
+ }), h(s, "signature", () => {
237
+ if (e.input)
238
+ return p()[0];
239
+ }), h(s, "input", () => {
240
+ if (e.signature)
241
+ return l([e.signature]);
242
+ }), h(s, "witness", () => {
243
+ if (s.input)
244
+ return [];
245
+ }), o.validate) {
246
+ if (e.output) {
247
+ if (e.output[e.output.length - 1] !== X.OP_CHECKSIG)
248
+ throw new TypeError("Output is invalid");
249
+ if (!T(s.pubkey)) throw new TypeError("Output pubkey is invalid");
250
+ if (e.pubkey && !e.pubkey.equals(s.pubkey)) throw new TypeError("Pubkey mismatch");
251
+ }
252
+ if (e.signature && e.input && !e.input.equals(s.input))
253
+ throw new TypeError("Signature mismatch");
254
+ if (e.input) {
255
+ if (p().length !== 1) throw new TypeError("Input is invalid");
256
+ if (!S(s.signature))
257
+ throw new TypeError("Input has invalid signature");
258
+ }
259
+ }
260
+ return Object.assign(s, e);
261
+ }
262
+ const B = v;
263
+ function Pe(e, o) {
264
+ if (!e.address && !e.hash && !e.output && !e.redeem && !e.input)
265
+ throw new TypeError("Not enough data");
266
+ o = Object.assign({ validate: !0 }, o || {}), t(
267
+ {
268
+ network: t.maybe(t.Object),
269
+ address: t.maybe(t.String),
270
+ hash: t.maybe(t.BufferN(20)),
271
+ output: t.maybe(t.BufferN(23)),
272
+ redeem: t.maybe({
273
+ network: t.maybe(t.Object),
274
+ output: t.maybe(t.Buffer),
275
+ input: t.maybe(t.Buffer),
276
+ witness: t.maybe(t.arrayOf(t.Buffer))
277
+ }),
278
+ input: t.maybe(t.Buffer),
279
+ witness: t.maybe(t.arrayOf(t.Buffer))
280
+ },
281
+ e
282
+ );
283
+ let p = e.network;
284
+ p || (p = e.redeem && e.redeem.network || P);
285
+ const u = {
286
+ network: p,
287
+ name: k.P2SH
288
+ }, s = y(() => {
289
+ const r = c.from(x.decode(e.address)), f = r.readUInt8(0), d = r.slice(1);
290
+ return { version: f, hash: d };
291
+ }), i = y(() => a(e.input)), n = y(() => {
292
+ const r = i(), f = r[r.length - 1];
293
+ return {
294
+ network: p,
295
+ output: f === B.OP_FALSE ? c.from([]) : f,
296
+ input: l(r.slice(0, -1)),
297
+ witness: e.witness || []
298
+ };
299
+ });
300
+ if (h(u, "address", () => {
301
+ if (!u.hash) return;
302
+ const r = c.allocUnsafe(21);
303
+ return r.writeUInt8(u.network.scriptHash, 0), u.hash.copy(r, 1), x.encode(r);
304
+ }), h(u, "hash", () => {
305
+ if (e.output) return e.output.slice(2, 22);
306
+ if (e.address) return s().hash;
307
+ if (u.redeem && u.redeem.output) return E(u.redeem.output);
308
+ }), h(u, "output", () => {
309
+ if (u.hash)
310
+ return l([B.OP_HASH160, u.hash, B.OP_EQUAL]);
311
+ }), h(u, "redeem", () => {
312
+ if (e.input)
313
+ return n();
314
+ }), h(u, "input", () => {
315
+ if (!(!e.redeem || !e.redeem.input || !e.redeem.output))
316
+ return l(
317
+ [].concat(a(e.redeem.input), e.redeem.output)
318
+ );
319
+ }), h(u, "witness", () => {
320
+ if (u.redeem && u.redeem.witness) return u.redeem.witness;
321
+ if (u.input) return [];
322
+ }), h(u, "name", () => {
323
+ const r = ["p2sh"];
324
+ return u.redeem !== void 0 && u.redeem.name !== void 0 && r.push(u.redeem.name), r.join("-");
325
+ }), o.validate) {
326
+ let r = c.from([]);
327
+ if (e.address) {
328
+ if (s().version !== p.scriptHash)
329
+ throw new TypeError("Invalid version or Network mismatch");
330
+ if (s().hash.length !== 20) throw new TypeError("Invalid address");
331
+ r = s().hash;
332
+ }
333
+ if (e.hash) {
334
+ if (r.length > 0 && !r.equals(e.hash)) throw new TypeError("Hash mismatch");
335
+ r = e.hash;
336
+ }
337
+ if (e.output) {
338
+ if (e.output.length !== 23 || e.output[0] !== B.OP_HASH160 || e.output[1] !== 20 || e.output[22] !== B.OP_EQUAL)
339
+ throw new TypeError("Output is invalid");
340
+ const d = e.output.slice(2, 22);
341
+ if (r.length > 0 && !r.equals(d)) throw new TypeError("Hash mismatch");
342
+ r = d;
343
+ }
344
+ const f = (d) => {
345
+ if (d.output) {
346
+ const m = a(d.output);
347
+ if (!m || m.length < 1)
348
+ throw new TypeError("Redeem.output too short");
349
+ if (d.output.byteLength > 520)
350
+ throw new TypeError("Redeem.output unspendable if larger than 520 bytes");
351
+ if (ie(m) > 201)
352
+ throw new TypeError(
353
+ "Redeem.output unspendable with more than 201 non-push ops"
354
+ );
355
+ const w = E(d.output);
356
+ if (r.length > 0 && !r.equals(w)) throw new TypeError("Hash mismatch");
357
+ r = w;
358
+ }
359
+ if (d.input) {
360
+ const m = d.input.length > 0, w = d.witness && d.witness.length > 0;
361
+ if (!m && !w) throw new TypeError("Empty input");
362
+ if (m && w) throw new TypeError("Input and witness provided");
363
+ if (m) {
364
+ const _ = a(d.input);
365
+ if (!ue(_))
366
+ throw new TypeError("Non push-only scriptSig");
367
+ }
368
+ }
369
+ };
370
+ if (e.input) {
371
+ const d = i();
372
+ if (!d || d.length < 1) throw new TypeError("Input too short");
373
+ if (!c.isBuffer(n().output)) throw new TypeError("Input is invalid");
374
+ f(n());
375
+ }
376
+ if (e.redeem) {
377
+ if (e.redeem.network && e.redeem.network !== p)
378
+ throw new TypeError("Network mismatch");
379
+ if (e.input) {
380
+ const d = n();
381
+ if (e.redeem.output && !e.redeem.output.equals(d.output))
382
+ throw new TypeError("Redeem.output mismatch");
383
+ if (e.redeem.input && !e.redeem.input.equals(d.input))
384
+ throw new TypeError("Redeem.input mismatch");
385
+ }
386
+ f(e.redeem);
387
+ }
388
+ if (e.witness && e.redeem && e.redeem.witness && !N(e.redeem.witness, e.witness))
389
+ throw new TypeError("Witness and redeem.witness mismatch");
390
+ }
391
+ return Object.assign(u, e);
392
+ }
393
+ const Q = v, Y = 1, ve = 80;
394
+ function Oe(e, o) {
395
+ if (!e.address && !e.output && !e.pubkey && !e.internalPubkey && !(e.witness && e.witness.length > 1))
396
+ throw new TypeError("Not enough data");
397
+ o = Object.assign({ validate: !0 }, o || {}), t(
398
+ {
399
+ address: t.maybe(t.String),
400
+ input: t.maybe(t.BufferN(0)),
401
+ network: t.maybe(t.Object),
402
+ output: t.maybe(t.BufferN(34)),
403
+ internalPubkey: t.maybe(t.BufferN(32)),
404
+ hash: t.maybe(t.BufferN(32)),
405
+ // merkle root hash, the tweak
406
+ pubkey: t.maybe(t.BufferN(32)),
407
+ // tweaked with `hash` from `internalPubkey`
408
+ signature: t.maybe(t.anyOf(t.BufferN(64), t.BufferN(65))),
409
+ witness: t.maybe(t.arrayOf(t.Buffer)),
410
+ scriptTree: t.maybe(we),
411
+ redeem: t.maybe({
412
+ output: t.maybe(t.Buffer),
413
+ // tapleaf script
414
+ redeemVersion: t.maybe(t.Number),
415
+ // tapleaf version
416
+ witness: t.maybe(t.arrayOf(t.Buffer))
417
+ }),
418
+ redeemVersion: t.maybe(t.Number)
419
+ },
420
+ e
421
+ );
422
+ const p = y(() => se(e.address)), u = y(() => {
423
+ if (!(!e.witness || !e.witness.length))
424
+ return e.witness.length >= 2 && e.witness[e.witness.length - 1][0] === ve ? e.witness.slice(0, -1) : e.witness.slice();
425
+ }), s = y(() => {
426
+ if (e.scriptTree) return A(e.scriptTree);
427
+ if (e.hash) return { hash: e.hash };
428
+ }), i = e.network || P, n = {
429
+ name: k.P2TR,
430
+ network: i
431
+ };
432
+ if (h(n, "address", () => {
433
+ if (!n.pubkey) return;
434
+ const r = b.bech32m.toWords(n.pubkey);
435
+ return r.unshift(Y), b.bech32m.encode(i.bech32, r);
436
+ }), h(n, "hash", () => {
437
+ const r = s();
438
+ if (r) return r.hash;
439
+ const f = u();
440
+ if (f && f.length > 1) {
441
+ const d = f[f.length - 1], m = d[0] & W, w = f[f.length - 2], _ = H({
442
+ output: w,
443
+ version: m
444
+ });
445
+ return K(d, _);
446
+ }
447
+ }), h(n, "output", () => {
448
+ if (n.pubkey)
449
+ return l([Q.OP_1, n.pubkey]);
450
+ }), h(n, "redeemVersion", () => e.redeemVersion ? e.redeemVersion : e.redeem && e.redeem.redeemVersion !== void 0 && e.redeem.redeemVersion !== null ? e.redeem.redeemVersion : F), h(n, "redeem", () => {
451
+ const r = u();
452
+ if (!(!r || r.length < 2))
453
+ return {
454
+ output: r[r.length - 2],
455
+ witness: r.slice(0, -2),
456
+ redeemVersion: r[r.length - 1][0] & W
457
+ };
458
+ }), h(n, "pubkey", () => {
459
+ if (e.pubkey) return e.pubkey;
460
+ if (e.output) return e.output.slice(2);
461
+ if (e.address) return p().data;
462
+ if (n.internalPubkey) {
463
+ const r = j(n.internalPubkey, n.hash);
464
+ if (r) return r.x;
465
+ }
466
+ }), h(n, "internalPubkey", () => {
467
+ if (e.internalPubkey) return e.internalPubkey;
468
+ const r = u();
469
+ if (r && r.length > 1) return r[r.length - 1].slice(1, 33);
470
+ }), h(n, "signature", () => {
471
+ if (e.signature) return e.signature;
472
+ const r = u();
473
+ if (!(!r || r.length !== 1))
474
+ return r[0];
475
+ }), h(n, "witness", () => {
476
+ if (e.witness) return e.witness;
477
+ const r = s();
478
+ if (r && e.redeem && e.redeem.output && e.internalPubkey) {
479
+ const f = H({
480
+ output: e.redeem.output,
481
+ version: n.redeemVersion
482
+ }), d = q(r, f);
483
+ if (!d) return;
484
+ const m = j(e.internalPubkey, r.hash);
485
+ if (!m) return;
486
+ const w = g.concat(
487
+ [g.from([n.redeemVersion | m.parity]), e.internalPubkey].concat(
488
+ d
489
+ )
490
+ );
491
+ return [e.redeem.output, w];
492
+ }
493
+ if (e.signature) return [e.signature];
494
+ }), o.validate) {
495
+ let r = g.from([]);
496
+ if (e.address) {
497
+ if (i && i.bech32 !== p().prefix)
498
+ throw new TypeError("Invalid prefix or Network mismatch");
499
+ if (p().version !== Y)
500
+ throw new TypeError("Invalid address version");
501
+ if (p().data.length !== 32) throw new TypeError("Invalid address data");
502
+ r = p().data;
503
+ }
504
+ if (e.pubkey) {
505
+ if (r.length > 0 && !r.equals(e.pubkey))
506
+ throw new TypeError("Pubkey mismatch");
507
+ r = e.pubkey;
508
+ }
509
+ if (e.output) {
510
+ if (e.output.length !== 34 || e.output[0] !== Q.OP_1 || e.output[1] !== 32)
511
+ throw new TypeError("Output is invalid");
512
+ if (r.length > 0 && !r.equals(e.output.slice(2)))
513
+ throw new TypeError("Pubkey mismatch");
514
+ r = e.output.slice(2);
515
+ }
516
+ if (e.internalPubkey) {
517
+ const m = j(e.internalPubkey, n.hash);
518
+ if (r.length > 0 && !r.equals(m.x))
519
+ throw new TypeError("Pubkey mismatch");
520
+ r = m.x;
521
+ }
522
+ const f = s();
523
+ if (e.hash && f && !e.hash.equals(f.hash))
524
+ throw new TypeError("Hash mismatch");
525
+ if (e.redeem && e.redeem.output && f) {
526
+ const m = H({
527
+ output: e.redeem.output,
528
+ version: n.redeemVersion
529
+ });
530
+ if (!q(f, m))
531
+ throw new TypeError("Redeem script not in tree");
532
+ }
533
+ const d = u();
534
+ if (e.redeem && n.redeem) {
535
+ if (e.redeem.redeemVersion && e.redeem.redeemVersion !== n.redeem.redeemVersion)
536
+ throw new TypeError("Redeem.redeemVersion and witness mismatch");
537
+ if (e.redeem.output) {
538
+ if (a(e.redeem.output).length === 0)
539
+ throw new TypeError("Redeem.output is invalid");
540
+ if (n.redeem.output && !e.redeem.output.equals(n.redeem.output))
541
+ throw new TypeError("Redeem.output and witness mismatch");
542
+ }
543
+ if (e.redeem.witness && n.redeem.witness && !N(e.redeem.witness, n.redeem.witness))
544
+ throw new TypeError("Redeem.witness and witness mismatch");
545
+ }
546
+ if (d && d.length)
547
+ if (d.length === 1) {
548
+ if (e.signature && !e.signature.equals(d[0]))
549
+ throw new TypeError("Signature mismatch");
550
+ } else {
551
+ const m = d[d.length - 1];
552
+ if (m.length < 33)
553
+ throw new TypeError(
554
+ `The control-block length is too small. Got ${m.length}, expected min 33.`
555
+ );
556
+ if ((m.length - 33) % 32 !== 0)
557
+ throw new TypeError(
558
+ `The control-block length of ${m.length} is incorrect!`
559
+ );
560
+ const w = (m.length - 33) / 32;
561
+ if (w > 128)
562
+ throw new TypeError(`The script path is too long. Got ${w}, expected max 128.`);
563
+ const _ = m.slice(1, 33);
564
+ if (e.internalPubkey && !e.internalPubkey.equals(_))
565
+ throw new TypeError("Internal pubkey mismatch");
566
+ if (!ne().isXOnlyPoint(_))
567
+ throw new TypeError("Invalid internalPubkey for p2tr witness");
568
+ const he = m[0] & W, pe = d[d.length - 2], fe = H({
569
+ output: pe,
570
+ version: he
571
+ }), de = K(m, fe), U = j(_, de);
572
+ if (!U)
573
+ throw new TypeError("Invalid outputKey for p2tr witness");
574
+ if (r.length && !r.equals(U.x))
575
+ throw new TypeError("Pubkey mismatch for p2tr witness");
576
+ if (U.parity !== (m[0] & 1)) throw new Error("Incorrect parity");
577
+ }
578
+ }
579
+ return Object.assign(n, e);
580
+ }
581
+ const z = v, _e = c.alloc(0);
582
+ function Se(e, o) {
583
+ if (!e.address && !e.hash && !e.output && !e.pubkey && !e.witness)
584
+ throw new TypeError("Not enough data");
585
+ o = Object.assign({ validate: !0 }, o || {}), t(
586
+ {
587
+ address: t.maybe(t.String),
588
+ hash: t.maybe(t.BufferN(20)),
589
+ input: t.maybe(t.BufferN(0)),
590
+ network: t.maybe(t.Object),
591
+ output: t.maybe(t.BufferN(22)),
592
+ pubkey: t.maybe(T),
593
+ signature: t.maybe(S),
594
+ witness: t.maybe(t.arrayOf(t.Buffer))
595
+ },
596
+ e
597
+ );
598
+ const p = y(() => {
599
+ const i = b.bech32.decode(e.address), n = i.words.shift(), r = b.bech32.fromWords(i.words);
600
+ return {
601
+ version: n,
602
+ prefix: i.prefix,
603
+ data: c.from(r)
604
+ };
605
+ }), u = e.network || P, s = {
606
+ name: k.P2WPKH,
607
+ network: u
608
+ };
609
+ if (h(s, "address", () => {
610
+ if (!s.hash) return;
611
+ const i = b.bech32.toWords(s.hash);
612
+ return i.unshift(0), b.bech32.encode(u.bech32, i);
613
+ }), h(s, "hash", () => {
614
+ if (e.output) return e.output.slice(2, 22);
615
+ if (e.address) return p().data;
616
+ if (e.pubkey || s.pubkey) return E(e.pubkey || s.pubkey);
617
+ }), h(s, "output", () => {
618
+ if (s.hash)
619
+ return l([z.OP_0, s.hash]);
620
+ }), h(s, "pubkey", () => {
621
+ if (e.pubkey) return e.pubkey;
622
+ if (e.witness)
623
+ return e.witness[1];
624
+ }), h(s, "signature", () => {
625
+ if (e.witness)
626
+ return e.witness[0];
627
+ }), h(s, "input", () => {
628
+ if (s.witness)
629
+ return _e;
630
+ }), h(s, "witness", () => {
631
+ if (e.pubkey && e.signature)
632
+ return [e.signature, e.pubkey];
633
+ }), o.validate) {
634
+ let i = c.from([]);
635
+ if (e.address) {
636
+ if (u && u.bech32 !== p().prefix)
637
+ throw new TypeError("Invalid prefix or Network mismatch");
638
+ if (p().version !== 0) throw new TypeError("Invalid address version");
639
+ if (p().data.length !== 20) throw new TypeError("Invalid address data");
640
+ i = p().data;
641
+ }
642
+ if (e.hash) {
643
+ if (i.length > 0 && !i.equals(e.hash)) throw new TypeError("Hash mismatch");
644
+ i = e.hash;
645
+ }
646
+ if (e.output) {
647
+ if (e.output.length !== 22 || e.output[0] !== z.OP_0 || e.output[1] !== 20)
648
+ throw new TypeError("Output is invalid");
649
+ if (i.length > 0 && !i.equals(e.output.slice(2)))
650
+ throw new TypeError("Hash mismatch");
651
+ i = e.output.slice(2);
652
+ }
653
+ if (e.pubkey) {
654
+ const n = E(e.pubkey);
655
+ if (i.length > 0 && !i.equals(n)) throw new TypeError("Hash mismatch");
656
+ if (i = n, !T(e.pubkey) || e.pubkey.length !== 33)
657
+ throw new TypeError("Invalid pubkey for p2wpkh");
658
+ }
659
+ if (e.witness) {
660
+ if (e.witness.length !== 2) throw new TypeError("Witness is invalid");
661
+ if (!S(e.witness[0]))
662
+ throw new TypeError("Witness has invalid signature");
663
+ if (!T(e.witness[1]) || e.witness[1].length !== 33)
664
+ throw new TypeError("Witness has invalid pubkey");
665
+ if (e.signature && !e.signature.equals(e.witness[0]))
666
+ throw new TypeError("Signature mismatch");
667
+ if (e.pubkey && !e.pubkey.equals(e.witness[1])) throw new TypeError("Pubkey mismatch");
668
+ const n = E(e.witness[1]);
669
+ if (i.length > 0 && !i.equals(n)) throw new TypeError("Hash mismatch");
670
+ }
671
+ }
672
+ return Object.assign(s, e);
673
+ }
674
+ const Z = v, $ = c.alloc(0);
675
+ function R(e) {
676
+ return !!(c.isBuffer(e) && e.length === 65 && e[0] === 4 && T(e));
677
+ }
678
+ function Ie(e, o) {
679
+ if (!e.address && !e.hash && !e.output && !e.redeem && !e.witness)
680
+ throw new TypeError("Not enough data");
681
+ o = Object.assign({ validate: !0 }, o || {}), t(
682
+ {
683
+ network: t.maybe(t.Object),
684
+ address: t.maybe(t.String),
685
+ hash: t.maybe(t.BufferN(32)),
686
+ output: t.maybe(t.BufferN(34)),
687
+ redeem: t.maybe({
688
+ input: t.maybe(t.Buffer),
689
+ network: t.maybe(t.Object),
690
+ output: t.maybe(t.Buffer),
691
+ witness: t.maybe(t.arrayOf(t.Buffer))
692
+ }),
693
+ input: t.maybe(t.BufferN(0)),
694
+ witness: t.maybe(t.arrayOf(t.Buffer))
695
+ },
696
+ e
697
+ );
698
+ const p = y(() => {
699
+ const n = b.bech32.decode(e.address), r = n.words.shift(), f = b.bech32.fromWords(n.words);
700
+ return {
701
+ version: r,
702
+ prefix: n.prefix,
703
+ data: c.from(f)
704
+ };
705
+ }), u = y(() => a(e.redeem.input));
706
+ let s = e.network;
707
+ s || (s = e.redeem && e.redeem.network || P);
708
+ const i = {
709
+ network: s,
710
+ name: k.P2WSH
711
+ };
712
+ if (h(i, "address", () => {
713
+ if (!i.hash) return;
714
+ const n = b.bech32.toWords(i.hash);
715
+ return n.unshift(0), b.bech32.encode(s.bech32, n);
716
+ }), h(i, "hash", () => {
717
+ if (e.output) return e.output.slice(2);
718
+ if (e.address) return p().data;
719
+ if (i.redeem && i.redeem.output) return M(i.redeem.output);
720
+ }), h(i, "output", () => {
721
+ if (i.hash)
722
+ return l([Z.OP_0, i.hash]);
723
+ }), h(i, "redeem", () => {
724
+ if (e.witness)
725
+ return {
726
+ output: e.witness[e.witness.length - 1],
727
+ input: $,
728
+ witness: e.witness.slice(0, -1)
729
+ };
730
+ }), h(i, "input", () => {
731
+ if (i.witness)
732
+ return $;
733
+ }), h(i, "witness", () => {
734
+ if (e.redeem && e.redeem.input && e.redeem.input.length > 0 && e.redeem.output && e.redeem.output.length > 0) {
735
+ const n = le(u());
736
+ return i.redeem = Object.assign({ witness: n }, e.redeem), i.redeem.input = $, [].concat(n, e.redeem.output);
737
+ }
738
+ if (e.redeem && e.redeem.output && e.redeem.witness)
739
+ return [].concat(e.redeem.witness, e.redeem.output);
740
+ }), h(i, "name", () => {
741
+ const n = ["p2wsh"];
742
+ return i.redeem !== void 0 && i.redeem.name !== void 0 && n.push(i.redeem.name), n.join("-");
743
+ }), o.validate) {
744
+ let n = c.from([]);
745
+ if (e.address) {
746
+ if (p().prefix !== s.bech32)
747
+ throw new TypeError("Invalid prefix or Network mismatch");
748
+ if (p().version !== 0) throw new TypeError("Invalid address version");
749
+ if (p().data.length !== 32) throw new TypeError("Invalid address data");
750
+ n = p().data;
751
+ }
752
+ if (e.hash) {
753
+ if (n.length > 0 && !n.equals(e.hash)) throw new TypeError("Hash mismatch");
754
+ n = e.hash;
755
+ }
756
+ if (e.output) {
757
+ if (e.output.length !== 34 || e.output[0] !== Z.OP_0 || e.output[1] !== 32)
758
+ throw new TypeError("Output is invalid");
759
+ const r = e.output.slice(2);
760
+ if (n.length > 0 && !n.equals(r)) throw new TypeError("Hash mismatch");
761
+ n = r;
762
+ }
763
+ if (e.redeem) {
764
+ if (e.redeem.network && e.redeem.network !== s)
765
+ throw new TypeError("Network mismatch");
766
+ if (e.redeem.input && e.redeem.input.length > 0 && e.redeem.witness && e.redeem.witness.length > 0)
767
+ throw new TypeError("Ambiguous witness source");
768
+ if (e.redeem.output) {
769
+ const r = a(e.redeem.output);
770
+ if (!r || r.length < 1)
771
+ throw new TypeError("Redeem.output is invalid");
772
+ if (e.redeem.output.byteLength > 3600)
773
+ throw new TypeError("Redeem.output unspendable if larger than 3600 bytes");
774
+ if (ie(r) > 201)
775
+ throw new TypeError(
776
+ "Redeem.output unspendable with more than 201 non-push ops"
777
+ );
778
+ const f = M(e.redeem.output);
779
+ if (n.length > 0 && !n.equals(f)) throw new TypeError("Hash mismatch");
780
+ n = f;
781
+ }
782
+ if (e.redeem.input && !ue(u()))
783
+ throw new TypeError("Non push-only scriptSig");
784
+ if (e.witness && e.redeem.witness && !N(e.witness, e.redeem.witness))
785
+ throw new TypeError("Witness and redeem.witness mismatch");
786
+ if (e.redeem.input && u().some(R) || e.redeem.output && (a(e.redeem.output) || []).some(R))
787
+ throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey");
788
+ }
789
+ if (e.witness && e.witness.length > 0) {
790
+ const r = e.witness[e.witness.length - 1];
791
+ if (e.redeem && e.redeem.output && !e.redeem.output.equals(r))
792
+ throw new TypeError("Witness and redeem.output mismatch");
793
+ if (e.witness.some(R) || (a(r) || []).some(R))
794
+ throw new TypeError("Witness contains uncompressed pubkey");
795
+ }
796
+ }
797
+ return Object.assign(i, e);
798
+ }
799
+ const J = v, ee = 16, te = 2, re = 40;
800
+ function He(e, o) {
801
+ if (!e.address && !e.output && !e.program && (typeof e.deploymentVersion > "u" || !e.hash160))
802
+ throw new TypeError("At least one of address, output or program must be provided");
803
+ o = Object.assign({ validate: !0 }, o || {}), t(
804
+ {
805
+ address: t.maybe(t.String),
806
+ output: t.maybe(t.Buffer),
807
+ program: t.maybe(t.Buffer),
808
+ network: t.maybe(t.Object),
809
+ deploymentVersion: t.maybe(t.Number),
810
+ hash160: t.maybe(t.BufferN(20))
811
+ },
812
+ e
813
+ );
814
+ const p = () => {
815
+ if (typeof e.deploymentVersion < "u" && typeof e.hash160 < "u") {
816
+ if (e.hash160.length !== 20) throw new TypeError("hash160 must be exactly 20 bytes");
817
+ if (e.deploymentVersion < 0 || e.deploymentVersion > 255)
818
+ throw new TypeError("deploymentVersion must fit in one byte");
819
+ return c.concat([c.of(e.deploymentVersion), e.hash160]);
820
+ }
821
+ }, u = y(() => se(e.address)), s = e.network || P, i = {
822
+ name: k.P2OP,
823
+ network: s,
824
+ deploymentVersion: 0
825
+ };
826
+ if (h(i, "program", () => {
827
+ if (e.program) return e.program;
828
+ const n = p();
829
+ if (n) return n;
830
+ if (e.output) {
831
+ if (e.output[0] !== J.OP_16) throw new TypeError("Invalid P2OP script");
832
+ let r = 1, f;
833
+ if (e.output[1] < 76)
834
+ f = e.output[1], r = 2;
835
+ else if (e.output[1] === 76)
836
+ f = e.output[2], r = 3;
837
+ else
838
+ throw new TypeError("Unsupported push opcode in P2OP script");
839
+ return e.output.slice(r, r + f);
840
+ }
841
+ if (e.address)
842
+ return u().data;
843
+ }), h(i, "deploymentVersion", () => {
844
+ if (i.program)
845
+ return i.program[0];
846
+ }), h(i, "hash160", () => {
847
+ if (i.program)
848
+ return i.program.slice(1);
849
+ }), h(i, "output", () => {
850
+ if (i.program)
851
+ return l([J.OP_16, i.program]);
852
+ }), h(i, "address", () => {
853
+ if (!i.program) return;
854
+ if (!s.bech32Opnet)
855
+ throw new TypeError("Network does not support opnet");
856
+ const n = b.bech32m.toWords(i.program);
857
+ return n.unshift(ee), b.bech32m.encode(s.bech32Opnet, n);
858
+ }), o.validate) {
859
+ let n = g.alloc(0);
860
+ if (e.address) {
861
+ const r = u();
862
+ if (s.bech32Opnet !== r.prefix)
863
+ throw new TypeError("Invalid prefix or network mismatch");
864
+ if (r.version !== ee)
865
+ throw new TypeError("Invalid witness version for p2op");
866
+ if (r.data.length < te || r.data.length > re)
867
+ throw new TypeError("Invalid witness program length");
868
+ n = r.data;
869
+ }
870
+ if (e.program) {
871
+ if (n.length && !n.equals(e.program)) throw new TypeError("Program mismatch");
872
+ n = e.program;
873
+ }
874
+ if (!n.length && e.deploymentVersion !== void 0 && e.hash160 && (n = p()), e.output) {
875
+ const r = i.program;
876
+ if (n.length && !n.equals(r))
877
+ throw new TypeError("Program mismatch (output vs other source)");
878
+ n = r;
879
+ }
880
+ if (n.length < te || n.length > re)
881
+ throw new TypeError(`Witness program must be 2–40 bytes. Was ${n.length} bytes`);
882
+ if (e.deploymentVersion !== void 0 && e.deploymentVersion !== n[0])
883
+ throw new TypeError("deploymentVersion mismatch");
884
+ if (e.hash160 && !e.hash160.equals(n.slice(1))) throw new TypeError("hash160 mismatch");
885
+ }
886
+ return Object.assign(i, e);
887
+ }
888
+ const O = v;
889
+ function Ne(e, o) {
890
+ if (!e.address && !e.hash && !e.output && !e.pubkey && !e.input)
891
+ throw new TypeError("Not enough data");
892
+ o = Object.assign({ validate: !0 }, o || {}), t(
893
+ {
894
+ network: t.maybe(t.Object),
895
+ address: t.maybe(t.String),
896
+ hash: t.maybe(t.BufferN(20)),
897
+ output: t.maybe(t.BufferN(25)),
898
+ pubkey: t.maybe(T),
899
+ signature: t.maybe(S),
900
+ input: t.maybe(t.Buffer)
901
+ },
902
+ e
903
+ );
904
+ const p = y(() => {
905
+ const n = c.from(x.decode(e.address)), r = n.readUInt8(0), f = n.slice(1);
906
+ return { version: r, hash: f };
907
+ }), u = y(() => a(e.input)), s = e.network || P, i = {
908
+ name: k.P2PKH,
909
+ network: s,
910
+ hash: void 0
911
+ };
912
+ if (h(i, "address", () => {
913
+ if (!i.hash) return;
914
+ const n = c.allocUnsafe(21);
915
+ return n.writeUInt8(s.pubKeyHash, 0), i.hash.copy(n, 1), x.encode(n);
916
+ }), h(i, "hash", () => {
917
+ if (e.output) return e.output.slice(3, 23);
918
+ if (e.address) return p().hash;
919
+ if (e.pubkey || i.pubkey) return E(e.pubkey || i.pubkey);
920
+ }), h(i, "output", () => {
921
+ if (i.hash)
922
+ return l([
923
+ O.OP_DUP,
924
+ O.OP_HASH160,
925
+ i.hash,
926
+ O.OP_EQUALVERIFY,
927
+ O.OP_CHECKSIG
928
+ ]);
929
+ }), h(i, "pubkey", () => {
930
+ if (e.input)
931
+ return u()[1];
932
+ }), h(i, "signature", () => {
933
+ if (e.input)
934
+ return u()[0];
935
+ }), h(i, "input", () => {
936
+ if (!e.pubkey || !e.signature) return;
937
+ let n = e.pubkey;
938
+ if (e.useHybrid || e.useUncompressed) {
939
+ const r = G(e.pubkey);
940
+ r && (e.useUncompressed ? n = r.uncompressed : n = r.hybrid);
941
+ }
942
+ return l([e.signature, n]);
943
+ }), h(i, "witness", () => {
944
+ if (i.input)
945
+ return [];
946
+ }), o.validate) {
947
+ let n = c.from([]);
948
+ if (e.address) {
949
+ if (p().version !== s.pubKeyHash)
950
+ throw new TypeError("Invalid version or Network mismatch");
951
+ if (p().hash.length !== 20)
952
+ throw new TypeError("Invalid address");
953
+ n = p().hash;
954
+ }
955
+ if (e.hash) {
956
+ if (n.length > 0 && !n.equals(e.hash))
957
+ throw new TypeError("Hash mismatch");
958
+ n = e.hash;
959
+ }
960
+ if (e.output) {
961
+ if (e.output.length !== 25 || e.output[0] !== O.OP_DUP || e.output[1] !== O.OP_HASH160 || e.output[2] !== 20 || e.output[23] !== O.OP_EQUALVERIFY || e.output[24] !== O.OP_CHECKSIG)
962
+ throw new TypeError("Output is invalid");
963
+ const r = e.output.slice(3, 23);
964
+ if (n.length > 0 && !n.equals(r)) throw new TypeError("Hash mismatch");
965
+ n = r;
966
+ }
967
+ if (e.pubkey) {
968
+ const r = E(e.pubkey);
969
+ let f = n.length > 0 && !n.equals(r);
970
+ if (f && (e.pubkey.length === 33 && (e.pubkey[0] === 2 || e.pubkey[0] === 3) || e.pubkey.length === 65 && e.pubkey[0] === 4)) {
971
+ const d = G(e.pubkey);
972
+ if (d) {
973
+ const m = E(d.uncompressed);
974
+ if (n.equals(m))
975
+ f = !1, e.useUncompressed = !0;
976
+ else {
977
+ const w = E(d.hybrid);
978
+ f = !n.equals(w), f || (e.useHybrid = !0);
979
+ }
980
+ }
981
+ }
982
+ if (f)
983
+ throw new TypeError("Hash mismatch");
984
+ n = r;
985
+ }
986
+ if (e.input) {
987
+ const r = u();
988
+ if (r.length !== 2) throw new TypeError("Input is invalid");
989
+ if (!S(r[0]))
990
+ throw new TypeError("Input has invalid signature");
991
+ if (!T(r[1])) throw new TypeError("Input has invalid pubkey");
992
+ if (e.signature && !e.signature.equals(r[0]))
993
+ throw new TypeError("Signature mismatch");
994
+ if (e.pubkey && !e.pubkey.equals(r[1]))
995
+ throw new TypeError("Pubkey mismatch");
996
+ const f = E(r[1]);
997
+ if (n.length > 0 && !n.equals(f)) throw new TypeError("Hash mismatch (input)");
998
+ }
999
+ }
1000
+ return Object.assign(i, e);
1001
+ }
1002
+ var k = /* @__PURE__ */ ((e) => (e.P2PK = "p2pk", e.P2PKH = "p2pkh", e.P2SH = "p2sh", e.P2MS = "p2ms", e.P2WPKH = "p2wpkh", e.P2WSH = "p2wsh", e.P2TR = "p2tr", e.P2OP = "p2op", e.Embed = "embed", e.ScriptRedeem = "scriptRedeem", e))(k || {});
1003
+ const Re = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1004
+ __proto__: null,
1005
+ LEAF_VERSION_TAPSCRIPT: F,
1006
+ MAX_TAPTREE_DEPTH: ye,
1007
+ PaymentType: k,
1008
+ findScriptPath: q,
1009
+ p2data: ke,
1010
+ p2ms: Ee,
1011
+ p2op: He,
1012
+ p2pk: Te,
1013
+ p2pkh: Ne,
1014
+ p2sh: Pe,
1015
+ p2tr: Oe,
1016
+ p2wpkh: Se,
1017
+ p2wsh: Ie,
1018
+ prop: h,
1019
+ rootHashFromPath: K,
1020
+ tapTweakHash: oe,
1021
+ tapleafHash: H,
1022
+ toHashTree: A,
1023
+ tweakKey: j,
1024
+ value: y
1025
+ }, Symbol.toStringTag, { value: "Module" }));
1026
+ export {
1027
+ F as L,
1028
+ ye as M,
1029
+ k as P,
1030
+ Pe as a,
1031
+ Se as b,
1032
+ Ie as c,
1033
+ Oe as d,
1034
+ He as e,
1035
+ H as f,
1036
+ Te as g,
1037
+ Ee as h,
1038
+ Re as i,
1039
+ A as j,
1040
+ q as k,
1041
+ oe as l,
1042
+ Ne as p,
1043
+ K as r,
1044
+ j as t
1045
+ };