@btc-vision/bitcoin 6.3.1 → 6.3.3
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.
- package/.babelrc +4 -0
- package/.gitattributes +2 -0
- package/.nyc_output/6368a5b2-daa5-4821-8ed0-b742d6fc7eab.json +1 -0
- package/.nyc_output/processinfo/6368a5b2-daa5-4821-8ed0-b742d6fc7eab.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -0
- package/.prettierrc.json +12 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/.ready +0 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/.release-please-manifest.json +3 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/CHANGELOG.md +962 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/CONTRIBUTING.md +34 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/LICENSE +24 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/README.md +273 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/SECURITY.md +2 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/addon.gypi +204 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/bin/node-gyp.js +138 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/.release-please-manifest.json +3 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/LICENSE +28 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/data/ninja/build.ninja +4 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/data/win/large-pdb-shim.cc +12 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/GypVsCMake.md +116 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/Hacking.md +46 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/InputFormatReference.md +1080 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/LanguageSpecification.md +430 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/README.md +27 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/Testing.md +450 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/UserDocumentation.md +965 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/gyp +8 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/gyp.bat +5 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/gyp_main.py +45 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +365 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +206 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +1272 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +1547 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +59 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +153 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +271 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +574 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +692 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/common.py +711 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +171 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +169 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +113 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +55 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +804 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +1173 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +1318 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +127 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +103 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +461 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +89 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +57 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +2745 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +3976 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +44 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +2964 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +67 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +1391 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +25 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/input.py +3115 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +98 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +771 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +1260 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +174 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +61 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +373 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +1938 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation_test.py +53 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +302 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +3198 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +65 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/LICENSE +3 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/LICENSE.APACHE +177 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/LICENSE.BSD +23 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/__init__.py +15 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_elffile.py +108 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_manylinux.py +252 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_musllinux.py +83 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_parser.py +359 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_structures.py +61 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_tokenizer.py +192 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/markers.py +252 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/metadata.py +825 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/py.typed +0 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/requirements.py +90 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/specifiers.py +1030 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/tags.py +553 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/utils.py +172 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/version.py +563 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pyproject.toml +120 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/release-please-config.json +11 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/test_gyp.py +261 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/Find-VisualStudio.cs +250 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/build.js +227 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/clean.js +15 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/configure.js +328 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/create-config-gypi.js +150 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/download.js +39 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/find-node-directory.js +63 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/find-python.js +310 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/find-visualstudio.js +590 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/install.js +415 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/list.js +26 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/log.js +168 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/node-gyp.js +188 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/process-release.js +146 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/rebuild.js +12 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/remove.js +43 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/util.js +81 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/macOS_Catalina_acid_test.sh +21 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/package.json +51 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/release-please-config.json +40 -0
- package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/src/win_delay_load_hook.cc +39 -0
- package/CHANGELOG.md +403 -0
- package/CONTRIBUTING.md +83 -0
- package/browser/address.d.ts +16 -0
- package/{src → browser}/bip66.d.ts +6 -7
- package/{src → browser}/block.d.ts +29 -30
- package/{src → browser}/bufferutils.d.ts +34 -54
- package/browser/crypto/crypto.d.ts +1 -0
- package/{src → browser}/crypto.d.ts +13 -18
- package/browser/ecc_lib.d.ts +3 -0
- package/browser/hooks/AdvancedSignatureManager.d.ts +16 -0
- package/{src → browser}/hooks/HookedSigner.d.ts +4 -4
- package/browser/hooks/SignatureManager.d.ts +13 -0
- package/browser/index.d.ts +58 -0
- package/browser/index.js +2 -0
- package/browser/index.js.LICENSE.txt +14 -0
- package/browser/merkle.d.ts +1 -0
- package/browser/networks.d.ts +23 -0
- package/{src → browser}/ops.d.ts +126 -126
- package/browser/payments/bip341.d.ts +23 -0
- package/browser/payments/embed.d.ts +2 -0
- package/browser/payments/index.d.ts +43 -0
- package/{src → browser}/payments/lazy.d.ts +2 -2
- package/browser/payments/p2ms.d.ts +2 -0
- package/browser/payments/p2pk.d.ts +2 -0
- package/browser/payments/p2pkh.d.ts +2 -0
- package/browser/payments/p2sh.d.ts +2 -0
- package/browser/payments/p2tr.d.ts +2 -0
- package/browser/payments/p2wpkh.d.ts +2 -0
- package/browser/payments/p2wsh.d.ts +2 -0
- package/browser/psbt/bip371.d.ts +16 -0
- package/browser/psbt/psbtutils.d.ts +26 -0
- package/{src → browser}/psbt.d.ts +167 -238
- package/browser/push_data.d.ts +7 -0
- package/browser/script.d.ts +17 -0
- package/browser/script_number.d.ts +2 -0
- package/browser/script_signature.d.ts +7 -0
- package/{src → browser}/transaction.d.ts +48 -60
- package/{src → browser}/types.d.ts +37 -54
- package/build/address.d.ts +16 -0
- package/build/address.js +148 -0
- package/build/bip66.d.ts +6 -0
- package/build/bip66.js +99 -0
- package/build/block.d.ts +29 -0
- package/build/block.js +181 -0
- package/build/bufferutils.d.ts +34 -0
- package/build/bufferutils.js +141 -0
- package/build/crypto/crypto.d.ts +1 -0
- package/build/crypto/crypto.js +1 -0
- package/build/crypto.d.ts +13 -0
- package/build/crypto.js +87 -0
- package/build/ecc_lib.d.ts +3 -0
- package/build/ecc_lib.js +61 -0
- package/build/hooks/AdvancedSignatureManager.d.ts +16 -0
- package/build/hooks/AdvancedSignatureManager.js +52 -0
- package/build/hooks/HookedSigner.d.ts +4 -0
- package/build/hooks/HookedSigner.js +64 -0
- package/build/hooks/SignatureManager.d.ts +13 -0
- package/build/hooks/SignatureManager.js +45 -0
- package/build/index.d.ts +58 -0
- package/build/index.js +32 -0
- package/build/merkle.d.ts +1 -0
- package/build/merkle.js +19 -0
- package/build/networks.d.ts +23 -0
- package/build/networks.js +121 -0
- package/build/ops.d.ts +126 -0
- package/{src → build}/ops.js +127 -131
- package/build/payments/bip341.d.ts +23 -0
- package/build/payments/bip341.js +82 -0
- package/build/payments/embed.d.ts +2 -0
- package/build/payments/embed.js +39 -0
- package/build/payments/index.d.ts +43 -0
- package/build/payments/index.js +10 -0
- package/build/payments/lazy.d.ts +2 -0
- package/{src → build}/payments/lazy.js +28 -32
- package/build/payments/p2ms.d.ts +2 -0
- package/{src → build}/payments/p2ms.js +128 -158
- package/build/payments/p2pk.d.ts +2 -0
- package/build/payments/p2pk.js +68 -0
- package/build/payments/p2pkh.d.ts +2 -0
- package/build/payments/p2pkh.js +173 -0
- package/build/payments/p2sh.d.ts +2 -0
- package/build/payments/p2sh.js +176 -0
- package/build/payments/p2tr.d.ts +2 -0
- package/build/payments/p2tr.js +254 -0
- package/build/payments/p2wpkh.d.ts +2 -0
- package/build/payments/p2wpkh.js +130 -0
- package/build/payments/p2wsh.d.ts +2 -0
- package/build/payments/p2wsh.js +180 -0
- package/build/psbt/bip371.d.ts +16 -0
- package/build/psbt/bip371.js +246 -0
- package/build/psbt/psbtutils.d.ts +26 -0
- package/build/psbt/psbtutils.js +177 -0
- package/build/psbt.d.ts +167 -0
- package/build/psbt.js +1307 -0
- package/build/push_data.d.ts +7 -0
- package/build/push_data.js +57 -0
- package/build/script.d.ts +17 -0
- package/build/script.js +167 -0
- package/build/script_number.d.ts +2 -0
- package/build/script_number.js +49 -0
- package/build/script_signature.d.ts +7 -0
- package/build/script_signature.js +49 -0
- package/build/transaction.d.ts +48 -0
- package/build/transaction.js +445 -0
- package/build/types.d.ts +37 -0
- package/build/types.js +73 -0
- package/cjs/package.json +3 -0
- package/coverage/tmp/coverage-31752-1735543485354-0.json +1 -0
- package/coverage/tmp/coverage-59920-1735543484555-0.json +1 -0
- package/coverage/tmp/coverage-66252-1735543483919-0.json +1 -0
- package/coverage/tmp/coverage-68440-1735543485236-0.json +1 -0
- package/coverage/tmp/coverage-70588-1735543484426-0.json +1 -0
- package/coverage/tmp/coverage-79292-1735543485296-0.json +1 -0
- package/coverage/tmp/coverage-80212-1735543483980-0.json +1 -0
- package/eslint.config.js +56 -0
- package/gulpfile.js +42 -0
- package/package.json +105 -50
- package/src/{address.js → address.ts} +211 -191
- package/src/{bip66.js → bip66.ts} +23 -19
- package/src/{block.js → block.ts} +114 -105
- package/src/{bufferutils.js → bufferutils.ts} +65 -67
- package/src/crypto/crypto-browser.js +75 -0
- package/src/crypto/crypto.ts +1 -0
- package/src/crypto.ts +108 -0
- package/src/{ecc_lib.js → ecc_lib.ts} +25 -53
- package/src/hooks/{AdvancedSignatureManager.js → AdvancedSignatureManager.ts} +34 -18
- package/src/hooks/HookedSigner.ts +108 -0
- package/src/hooks/{SignatureManager.js → SignatureManager.ts} +26 -14
- package/src/index.ts +86 -0
- package/src/{merkle.js → merkle.ts} +8 -7
- package/src/{networks.js → networks.ts} +235 -220
- package/src/ops.ts +282 -0
- package/src/payments/bip341.ts +140 -0
- package/src/payments/embed.ts +55 -0
- package/src/payments/{index.d.ts → index.ts} +24 -10
- package/src/payments/lazy.ts +28 -0
- package/src/payments/p2ms.ts +150 -0
- package/src/payments/{p2pk.js → p2pk.ts} +85 -82
- package/src/payments/p2pkh.ts +206 -0
- package/src/payments/{p2sh.js → p2sh.ts} +206 -204
- package/src/payments/{p2tr.js → p2tr.ts} +114 -125
- package/src/payments/{p2wpkh.js → p2wpkh.ts} +51 -56
- package/src/payments/{p2wsh.js → p2wsh.ts} +69 -81
- package/src/psbt/{bip371.js → bip371.ts} +441 -424
- package/src/psbt/psbtutils.ts +301 -0
- package/src/{psbt.js → psbt.ts} +2187 -1828
- package/src/{push_data.js → push_data.ts} +35 -21
- package/src/{script.js → script.ts} +93 -77
- package/src/{script_number.js → script_number.ts} +15 -21
- package/src/{script_signature.js → script_signature.ts} +26 -14
- package/src/{transaction.js → transaction.ts} +247 -167
- package/src/types.ts +122 -0
- package/test/address.spec.js +124 -0
- package/test/address.spec.ts +177 -0
- package/test/bitcoin.core.spec.js +170 -0
- package/test/bitcoin.core.spec.ts +234 -0
- package/test/block.spec.js +141 -0
- package/test/block.spec.ts +194 -0
- package/test/bufferutils.spec.js +427 -0
- package/test/bufferutils.spec.ts +513 -0
- package/test/crypto.spec.js +41 -0
- package/test/crypto.spec.ts +55 -0
- package/test/fixtures/address.json +329 -0
- package/test/fixtures/block.json +148 -0
- package/test/fixtures/bufferutils.json +102 -0
- package/test/fixtures/core/README.md +26 -0
- package/test/fixtures/core/base58_encode_decode.json +50 -0
- package/test/fixtures/core/base58_keys_invalid.json +152 -0
- package/test/fixtures/core/base58_keys_valid.json +452 -0
- package/test/fixtures/core/blocks.json +27 -0
- package/test/fixtures/core/sig_canonical.json +7 -0
- package/test/fixtures/core/sig_noncanonical.json +33 -0
- package/test/fixtures/core/sighash.json +3505 -0
- package/test/fixtures/core/tx_valid.json +2023 -0
- package/test/fixtures/crypto.json +43 -0
- package/test/fixtures/ecdsa.json +217 -0
- package/test/fixtures/ecpair.json +141 -0
- package/test/fixtures/embed.json +108 -0
- package/test/fixtures/p2ms.json +434 -0
- package/test/fixtures/p2pk.json +179 -0
- package/test/fixtures/p2pkh.json +276 -0
- package/test/fixtures/p2sh.json +508 -0
- package/test/fixtures/p2tr.json +1198 -0
- package/test/fixtures/p2wpkh.json +290 -0
- package/test/fixtures/p2wsh.json +489 -0
- package/test/fixtures/psbt.json +924 -0
- package/test/fixtures/script.json +465 -0
- package/test/fixtures/script_number.json +225 -0
- package/test/fixtures/signature.json +140 -0
- package/test/fixtures/transaction.json +916 -0
- package/test/integration/_regtest.js +7 -0
- package/test/integration/_regtest.ts +6 -0
- package/test/integration/addresses.spec.js +116 -0
- package/test/integration/addresses.spec.ts +154 -0
- package/test/integration/bip32.spec.js +85 -0
- package/test/integration/bip32.spec.ts +151 -0
- package/test/integration/blocks.spec.js +26 -0
- package/test/integration/blocks.spec.ts +28 -0
- package/test/integration/cltv.spec.js +199 -0
- package/test/integration/cltv.spec.ts +283 -0
- package/test/integration/csv.spec.js +362 -0
- package/test/integration/csv.spec.ts +527 -0
- package/test/integration/payments.spec.js +98 -0
- package/test/integration/payments.spec.ts +135 -0
- package/test/integration/taproot.spec.js +532 -0
- package/test/integration/taproot.spec.ts +707 -0
- package/test/integration/transactions.spec.js +561 -0
- package/test/integration/transactions.spec.ts +769 -0
- package/test/payments.spec.js +97 -0
- package/test/payments.spec.ts +125 -0
- package/test/payments.utils.js +190 -0
- package/test/payments.utils.ts +208 -0
- package/test/psbt.spec.js +1044 -0
- package/test/psbt.spec.ts +1414 -0
- package/test/script.spec.js +151 -0
- package/test/script.spec.ts +210 -0
- package/test/script_number.spec.js +24 -0
- package/test/script_number.spec.ts +29 -0
- package/test/script_signature.spec.js +52 -0
- package/test/script_signature.spec.ts +66 -0
- package/test/transaction.spec.js +269 -0
- package/test/transaction.spec.ts +387 -0
- package/test/ts-node-register.js +5 -0
- package/test/tsconfig.json +45 -0
- package/test/types.spec.js +46 -0
- package/test/types.spec.ts +58 -0
- package/tsconfig.base.json +27 -0
- package/tsconfig.json +19 -0
- package/tsconfig.webpack.json +18 -0
- package/webpack.config.js +79 -0
- package/src/address.d.ts +0 -42
- package/src/crypto.js +0 -128
- package/src/ecc_lib.d.ts +0 -17
- package/src/hooks/AdvancedSignatureManager.d.ts +0 -44
- package/src/hooks/HookedSigner.js +0 -90
- package/src/hooks/SignatureManager.d.ts +0 -35
- package/src/index.d.ts +0 -42
- package/src/index.js +0 -87
- package/src/merkle.d.ts +0 -10
- package/src/networks.d.ts +0 -83
- package/src/payments/bip341.d.ts +0 -49
- package/src/payments/bip341.js +0 -124
- package/src/payments/embed.d.ts +0 -9
- package/src/payments/embed.js +0 -54
- package/src/payments/index.js +0 -69
- package/src/payments/p2ms.d.ts +0 -9
- package/src/payments/p2pk.d.ts +0 -10
- package/src/payments/p2pkh.d.ts +0 -10
- package/src/payments/p2pkh.js +0 -143
- package/src/payments/p2sh.d.ts +0 -10
- package/src/payments/p2tr.d.ts +0 -10
- package/src/payments/p2wpkh.d.ts +0 -10
- package/src/payments/p2wsh.d.ts +0 -10
- package/src/psbt/bip371.d.ts +0 -42
- package/src/psbt/psbtutils.d.ts +0 -64
- package/src/psbt/psbtutils.js +0 -191
- package/src/push_data.d.ts +0 -29
- package/src/script.d.ts +0 -42
- package/src/script_number.d.ts +0 -19
- package/src/script_signature.d.ts +0 -21
- package/src/types.js +0 -106
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import { BufferReader, BufferWriter, reverseBuffer, varuint } from './bufferutils.js';
|
|
2
|
+
import * as bcrypto from './crypto.js';
|
|
3
|
+
import * as bscript from './script.js';
|
|
4
|
+
import { OPS as opcodes } from './script.js';
|
|
5
|
+
import * as types from './types.js';
|
|
6
|
+
const { typeforce } = types;
|
|
7
|
+
function varSliceSize(someScript) {
|
|
8
|
+
const length = someScript.length;
|
|
9
|
+
return varuint.encodingLength(length) + length;
|
|
10
|
+
}
|
|
11
|
+
function vectorSize(someVector) {
|
|
12
|
+
const length = someVector.length;
|
|
13
|
+
return (varuint.encodingLength(length) +
|
|
14
|
+
someVector.reduce((sum, witness) => {
|
|
15
|
+
return sum + varSliceSize(witness);
|
|
16
|
+
}, 0));
|
|
17
|
+
}
|
|
18
|
+
const EMPTY_BUFFER = Buffer.allocUnsafe(0);
|
|
19
|
+
const EMPTY_WITNESS = [];
|
|
20
|
+
const ZERO = Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex');
|
|
21
|
+
const ONE = Buffer.from('0000000000000000000000000000000000000000000000000000000000000001', 'hex');
|
|
22
|
+
const VALUE_UINT64_MAX = Buffer.from('ffffffffffffffff', 'hex');
|
|
23
|
+
const BLANK_OUTPUT = {
|
|
24
|
+
script: EMPTY_BUFFER,
|
|
25
|
+
valueBuffer: VALUE_UINT64_MAX,
|
|
26
|
+
};
|
|
27
|
+
function isOutput(out) {
|
|
28
|
+
return out.value !== undefined;
|
|
29
|
+
}
|
|
30
|
+
export class Transaction {
|
|
31
|
+
constructor() {
|
|
32
|
+
this.version = 1;
|
|
33
|
+
this.locktime = 0;
|
|
34
|
+
this.ins = [];
|
|
35
|
+
this.outs = [];
|
|
36
|
+
}
|
|
37
|
+
static fromBuffer(buffer, _NO_STRICT) {
|
|
38
|
+
const bufferReader = new BufferReader(buffer);
|
|
39
|
+
const tx = new Transaction();
|
|
40
|
+
tx.version = bufferReader.readInt32();
|
|
41
|
+
const marker = bufferReader.readUInt8();
|
|
42
|
+
const flag = bufferReader.readUInt8();
|
|
43
|
+
let hasWitnesses = false;
|
|
44
|
+
if (marker === Transaction.ADVANCED_TRANSACTION_MARKER &&
|
|
45
|
+
flag === Transaction.ADVANCED_TRANSACTION_FLAG) {
|
|
46
|
+
hasWitnesses = true;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
bufferReader.offset -= 2;
|
|
50
|
+
}
|
|
51
|
+
const vinLen = bufferReader.readVarInt();
|
|
52
|
+
for (let i = 0; i < vinLen; ++i) {
|
|
53
|
+
const hash = bufferReader.readSlice(32);
|
|
54
|
+
const index = bufferReader.readUInt32();
|
|
55
|
+
const script = bufferReader.readVarSlice();
|
|
56
|
+
const sequence = bufferReader.readUInt32();
|
|
57
|
+
tx.ins.push({
|
|
58
|
+
hash: hash,
|
|
59
|
+
index: index,
|
|
60
|
+
script: script,
|
|
61
|
+
sequence: sequence,
|
|
62
|
+
witness: EMPTY_WITNESS,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
const voutLen = bufferReader.readVarInt();
|
|
66
|
+
for (let i = 0; i < voutLen; ++i) {
|
|
67
|
+
tx.outs.push({
|
|
68
|
+
value: bufferReader.readUInt64(),
|
|
69
|
+
script: bufferReader.readVarSlice(),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (hasWitnesses) {
|
|
73
|
+
for (let i = 0; i < vinLen; ++i) {
|
|
74
|
+
tx.ins[i].witness = bufferReader.readVector();
|
|
75
|
+
}
|
|
76
|
+
if (!tx.hasWitnesses())
|
|
77
|
+
throw new Error('Transaction has superfluous witness data');
|
|
78
|
+
}
|
|
79
|
+
tx.locktime = bufferReader.readUInt32();
|
|
80
|
+
if (_NO_STRICT)
|
|
81
|
+
return tx;
|
|
82
|
+
if (bufferReader.offset !== buffer.length)
|
|
83
|
+
throw new Error('Transaction has unexpected data');
|
|
84
|
+
return tx;
|
|
85
|
+
}
|
|
86
|
+
static fromHex(hex) {
|
|
87
|
+
return Transaction.fromBuffer(Buffer.from(hex, 'hex'), false);
|
|
88
|
+
}
|
|
89
|
+
static isCoinbaseHash(buffer) {
|
|
90
|
+
typeforce(types.Hash256bit, buffer);
|
|
91
|
+
for (let i = 0; i < 32; ++i) {
|
|
92
|
+
if (buffer[i] !== 0)
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
isCoinbase() {
|
|
98
|
+
return this.ins.length === 1 && Transaction.isCoinbaseHash(this.ins[0].hash);
|
|
99
|
+
}
|
|
100
|
+
addInput(hash, index, sequence, scriptSig) {
|
|
101
|
+
typeforce(types.tuple(types.Hash256bit, types.UInt32, types.maybe(types.UInt32), types.maybe(types.Buffer)), arguments);
|
|
102
|
+
if (types.Null(sequence)) {
|
|
103
|
+
sequence = Transaction.DEFAULT_SEQUENCE;
|
|
104
|
+
}
|
|
105
|
+
return (this.ins.push({
|
|
106
|
+
hash,
|
|
107
|
+
index,
|
|
108
|
+
script: scriptSig || EMPTY_BUFFER,
|
|
109
|
+
sequence: sequence,
|
|
110
|
+
witness: EMPTY_WITNESS,
|
|
111
|
+
}) - 1);
|
|
112
|
+
}
|
|
113
|
+
addOutput(scriptPubKey, value) {
|
|
114
|
+
typeforce(types.tuple(types.Buffer, types.Satoshi), arguments);
|
|
115
|
+
return (this.outs.push({
|
|
116
|
+
script: scriptPubKey,
|
|
117
|
+
value,
|
|
118
|
+
}) - 1);
|
|
119
|
+
}
|
|
120
|
+
hasWitnesses() {
|
|
121
|
+
return this.ins.some((x) => {
|
|
122
|
+
return x.witness.length !== 0;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
weight() {
|
|
126
|
+
const base = this.byteLength(false);
|
|
127
|
+
const total = this.byteLength(true);
|
|
128
|
+
return base * 3 + total;
|
|
129
|
+
}
|
|
130
|
+
virtualSize() {
|
|
131
|
+
return Math.ceil(this.weight() / 4);
|
|
132
|
+
}
|
|
133
|
+
byteLength(_ALLOW_WITNESS = true) {
|
|
134
|
+
const hasWitnesses = _ALLOW_WITNESS && this.hasWitnesses();
|
|
135
|
+
return ((hasWitnesses ? 10 : 8) +
|
|
136
|
+
varuint.encodingLength(this.ins.length) +
|
|
137
|
+
varuint.encodingLength(this.outs.length) +
|
|
138
|
+
this.ins.reduce((sum, input) => {
|
|
139
|
+
return sum + 40 + varSliceSize(input.script);
|
|
140
|
+
}, 0) +
|
|
141
|
+
this.outs.reduce((sum, output) => {
|
|
142
|
+
return sum + 8 + varSliceSize(output.script);
|
|
143
|
+
}, 0) +
|
|
144
|
+
(hasWitnesses
|
|
145
|
+
? this.ins.reduce((sum, input) => {
|
|
146
|
+
return sum + vectorSize(input.witness);
|
|
147
|
+
}, 0)
|
|
148
|
+
: 0));
|
|
149
|
+
}
|
|
150
|
+
clone() {
|
|
151
|
+
const newTx = new Transaction();
|
|
152
|
+
newTx.version = this.version;
|
|
153
|
+
newTx.locktime = this.locktime;
|
|
154
|
+
newTx.ins = this.ins.map((txIn) => {
|
|
155
|
+
return {
|
|
156
|
+
hash: txIn.hash,
|
|
157
|
+
index: txIn.index,
|
|
158
|
+
script: txIn.script,
|
|
159
|
+
sequence: txIn.sequence,
|
|
160
|
+
witness: txIn.witness,
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
newTx.outs = this.outs.map((txOut) => {
|
|
164
|
+
return {
|
|
165
|
+
script: txOut.script,
|
|
166
|
+
value: txOut.value,
|
|
167
|
+
};
|
|
168
|
+
});
|
|
169
|
+
return newTx;
|
|
170
|
+
}
|
|
171
|
+
hashForSignature(inIndex, prevOutScript, hashType) {
|
|
172
|
+
typeforce(types.tuple(types.UInt32, types.Buffer, types.Number), arguments);
|
|
173
|
+
if (inIndex >= this.ins.length)
|
|
174
|
+
return ONE;
|
|
175
|
+
const ourScript = bscript.compile(bscript.decompile(prevOutScript).filter((x) => {
|
|
176
|
+
return x !== opcodes.OP_CODESEPARATOR;
|
|
177
|
+
}));
|
|
178
|
+
const txTmp = this.clone();
|
|
179
|
+
if ((hashType & 0x1f) === Transaction.SIGHASH_NONE) {
|
|
180
|
+
txTmp.outs = [];
|
|
181
|
+
txTmp.ins.forEach((input, i) => {
|
|
182
|
+
if (i === inIndex)
|
|
183
|
+
return;
|
|
184
|
+
input.sequence = 0;
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
else if ((hashType & 0x1f) === Transaction.SIGHASH_SINGLE) {
|
|
188
|
+
if (inIndex >= this.outs.length)
|
|
189
|
+
return ONE;
|
|
190
|
+
txTmp.outs.length = inIndex + 1;
|
|
191
|
+
for (let i = 0; i < inIndex; i++) {
|
|
192
|
+
txTmp.outs[i] = BLANK_OUTPUT;
|
|
193
|
+
}
|
|
194
|
+
txTmp.ins.forEach((input, y) => {
|
|
195
|
+
if (y === inIndex)
|
|
196
|
+
return;
|
|
197
|
+
input.sequence = 0;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
if (hashType & Transaction.SIGHASH_ANYONECANPAY) {
|
|
201
|
+
txTmp.ins = [txTmp.ins[inIndex]];
|
|
202
|
+
txTmp.ins[0].script = ourScript;
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
txTmp.ins.forEach((input) => {
|
|
206
|
+
input.script = EMPTY_BUFFER;
|
|
207
|
+
});
|
|
208
|
+
txTmp.ins[inIndex].script = ourScript;
|
|
209
|
+
}
|
|
210
|
+
const buffer = Buffer.allocUnsafe(txTmp.byteLength(false) + 4);
|
|
211
|
+
buffer.writeInt32LE(hashType, buffer.length - 4);
|
|
212
|
+
txTmp.__toBuffer(buffer, 0, false);
|
|
213
|
+
return bcrypto.hash256(buffer);
|
|
214
|
+
}
|
|
215
|
+
hashForWitnessV1(inIndex, prevOutScripts, values, hashType, leafHash, annex) {
|
|
216
|
+
typeforce(types.tuple(types.UInt32, typeforce.arrayOf(types.Buffer), typeforce.arrayOf(types.Satoshi), types.UInt32), arguments);
|
|
217
|
+
if (values.length !== this.ins.length || prevOutScripts.length !== this.ins.length) {
|
|
218
|
+
throw new Error('Must supply prevout script and value for all inputs');
|
|
219
|
+
}
|
|
220
|
+
const outputType = hashType === Transaction.SIGHASH_DEFAULT
|
|
221
|
+
? Transaction.SIGHASH_ALL
|
|
222
|
+
: hashType & Transaction.SIGHASH_OUTPUT_MASK;
|
|
223
|
+
const inputType = hashType & Transaction.SIGHASH_INPUT_MASK;
|
|
224
|
+
const isAnyoneCanPay = inputType === Transaction.SIGHASH_ANYONECANPAY;
|
|
225
|
+
const isNone = outputType === Transaction.SIGHASH_NONE;
|
|
226
|
+
const isSingle = outputType === Transaction.SIGHASH_SINGLE;
|
|
227
|
+
let hashPrevouts = EMPTY_BUFFER;
|
|
228
|
+
let hashAmounts = EMPTY_BUFFER;
|
|
229
|
+
let hashScriptPubKeys = EMPTY_BUFFER;
|
|
230
|
+
let hashSequences = EMPTY_BUFFER;
|
|
231
|
+
let hashOutputs = EMPTY_BUFFER;
|
|
232
|
+
if (!isAnyoneCanPay) {
|
|
233
|
+
let bufferWriter = BufferWriter.withCapacity(36 * this.ins.length);
|
|
234
|
+
this.ins.forEach((txIn) => {
|
|
235
|
+
bufferWriter.writeSlice(txIn.hash);
|
|
236
|
+
bufferWriter.writeUInt32(txIn.index);
|
|
237
|
+
});
|
|
238
|
+
hashPrevouts = bcrypto.sha256(bufferWriter.end());
|
|
239
|
+
bufferWriter = BufferWriter.withCapacity(8 * this.ins.length);
|
|
240
|
+
values.forEach((value) => bufferWriter.writeUInt64(value));
|
|
241
|
+
hashAmounts = bcrypto.sha256(bufferWriter.end());
|
|
242
|
+
bufferWriter = BufferWriter.withCapacity(prevOutScripts.map(varSliceSize).reduce((a, b) => a + b));
|
|
243
|
+
prevOutScripts.forEach((prevOutScript) => bufferWriter.writeVarSlice(prevOutScript));
|
|
244
|
+
hashScriptPubKeys = bcrypto.sha256(bufferWriter.end());
|
|
245
|
+
bufferWriter = BufferWriter.withCapacity(4 * this.ins.length);
|
|
246
|
+
this.ins.forEach((txIn) => bufferWriter.writeUInt32(txIn.sequence));
|
|
247
|
+
hashSequences = bcrypto.sha256(bufferWriter.end());
|
|
248
|
+
}
|
|
249
|
+
if (!(isNone || isSingle)) {
|
|
250
|
+
if (!this.outs.length)
|
|
251
|
+
throw new Error('Add outputs to the transaction before signing.');
|
|
252
|
+
const txOutsSize = this.outs
|
|
253
|
+
.map((output) => 8 + varSliceSize(output.script))
|
|
254
|
+
.reduce((a, b) => a + b);
|
|
255
|
+
const bufferWriter = BufferWriter.withCapacity(txOutsSize);
|
|
256
|
+
this.outs.forEach((out) => {
|
|
257
|
+
bufferWriter.writeUInt64(out.value);
|
|
258
|
+
bufferWriter.writeVarSlice(out.script);
|
|
259
|
+
});
|
|
260
|
+
hashOutputs = bcrypto.sha256(bufferWriter.end());
|
|
261
|
+
}
|
|
262
|
+
else if (isSingle && inIndex < this.outs.length) {
|
|
263
|
+
const output = this.outs[inIndex];
|
|
264
|
+
const bufferWriter = BufferWriter.withCapacity(8 + varSliceSize(output.script));
|
|
265
|
+
bufferWriter.writeUInt64(output.value);
|
|
266
|
+
bufferWriter.writeVarSlice(output.script);
|
|
267
|
+
hashOutputs = bcrypto.sha256(bufferWriter.end());
|
|
268
|
+
}
|
|
269
|
+
const spendType = (leafHash ? 2 : 0) + (annex ? 1 : 0);
|
|
270
|
+
const sigMsgSize = 174 -
|
|
271
|
+
(isAnyoneCanPay ? 49 : 0) -
|
|
272
|
+
(isNone ? 32 : 0) +
|
|
273
|
+
(annex ? 32 : 0) +
|
|
274
|
+
(leafHash ? 37 : 0);
|
|
275
|
+
const sigMsgWriter = BufferWriter.withCapacity(sigMsgSize);
|
|
276
|
+
sigMsgWriter.writeUInt8(hashType);
|
|
277
|
+
sigMsgWriter.writeInt32(this.version);
|
|
278
|
+
sigMsgWriter.writeUInt32(this.locktime);
|
|
279
|
+
sigMsgWriter.writeSlice(hashPrevouts);
|
|
280
|
+
sigMsgWriter.writeSlice(hashAmounts);
|
|
281
|
+
sigMsgWriter.writeSlice(hashScriptPubKeys);
|
|
282
|
+
sigMsgWriter.writeSlice(hashSequences);
|
|
283
|
+
if (!(isNone || isSingle)) {
|
|
284
|
+
sigMsgWriter.writeSlice(hashOutputs);
|
|
285
|
+
}
|
|
286
|
+
sigMsgWriter.writeUInt8(spendType);
|
|
287
|
+
if (isAnyoneCanPay) {
|
|
288
|
+
const input = this.ins[inIndex];
|
|
289
|
+
sigMsgWriter.writeSlice(input.hash);
|
|
290
|
+
sigMsgWriter.writeUInt32(input.index);
|
|
291
|
+
sigMsgWriter.writeUInt64(values[inIndex]);
|
|
292
|
+
sigMsgWriter.writeVarSlice(prevOutScripts[inIndex]);
|
|
293
|
+
sigMsgWriter.writeUInt32(input.sequence);
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
sigMsgWriter.writeUInt32(inIndex);
|
|
297
|
+
}
|
|
298
|
+
if (annex) {
|
|
299
|
+
const bufferWriter = BufferWriter.withCapacity(varSliceSize(annex));
|
|
300
|
+
bufferWriter.writeVarSlice(annex);
|
|
301
|
+
sigMsgWriter.writeSlice(bcrypto.sha256(bufferWriter.end()));
|
|
302
|
+
}
|
|
303
|
+
if (isSingle) {
|
|
304
|
+
sigMsgWriter.writeSlice(hashOutputs);
|
|
305
|
+
}
|
|
306
|
+
if (leafHash) {
|
|
307
|
+
sigMsgWriter.writeSlice(leafHash);
|
|
308
|
+
sigMsgWriter.writeUInt8(0);
|
|
309
|
+
sigMsgWriter.writeUInt32(0xffffffff);
|
|
310
|
+
}
|
|
311
|
+
return bcrypto.taggedHash('TapSighash', Buffer.concat([Buffer.from([0x00]), sigMsgWriter.end()]));
|
|
312
|
+
}
|
|
313
|
+
hashForWitnessV0(inIndex, prevOutScript, value, hashType) {
|
|
314
|
+
typeforce(types.tuple(types.UInt32, types.Buffer, types.Satoshi, types.UInt32), arguments);
|
|
315
|
+
let tbuffer = Buffer.from([]);
|
|
316
|
+
let bufferWriter;
|
|
317
|
+
let hashOutputs = ZERO;
|
|
318
|
+
let hashPrevouts = ZERO;
|
|
319
|
+
let hashSequence = ZERO;
|
|
320
|
+
if (!(hashType & Transaction.SIGHASH_ANYONECANPAY)) {
|
|
321
|
+
tbuffer = Buffer.allocUnsafe(36 * this.ins.length);
|
|
322
|
+
bufferWriter = new BufferWriter(tbuffer, 0);
|
|
323
|
+
this.ins.forEach((txIn) => {
|
|
324
|
+
bufferWriter.writeSlice(txIn.hash);
|
|
325
|
+
bufferWriter.writeUInt32(txIn.index);
|
|
326
|
+
});
|
|
327
|
+
hashPrevouts = bcrypto.hash256(tbuffer);
|
|
328
|
+
}
|
|
329
|
+
if (!(hashType & Transaction.SIGHASH_ANYONECANPAY) &&
|
|
330
|
+
(hashType & 0x1f) !== Transaction.SIGHASH_SINGLE &&
|
|
331
|
+
(hashType & 0x1f) !== Transaction.SIGHASH_NONE) {
|
|
332
|
+
tbuffer = Buffer.allocUnsafe(4 * this.ins.length);
|
|
333
|
+
bufferWriter = new BufferWriter(tbuffer, 0);
|
|
334
|
+
this.ins.forEach((txIn) => {
|
|
335
|
+
bufferWriter.writeUInt32(txIn.sequence);
|
|
336
|
+
});
|
|
337
|
+
hashSequence = bcrypto.hash256(tbuffer);
|
|
338
|
+
}
|
|
339
|
+
if ((hashType & 0x1f) !== Transaction.SIGHASH_SINGLE &&
|
|
340
|
+
(hashType & 0x1f) !== Transaction.SIGHASH_NONE) {
|
|
341
|
+
const txOutsSize = this.outs.reduce((sum, output) => {
|
|
342
|
+
return sum + 8 + varSliceSize(output.script);
|
|
343
|
+
}, 0);
|
|
344
|
+
tbuffer = Buffer.allocUnsafe(txOutsSize);
|
|
345
|
+
bufferWriter = new BufferWriter(tbuffer, 0);
|
|
346
|
+
this.outs.forEach((out) => {
|
|
347
|
+
bufferWriter.writeUInt64(out.value);
|
|
348
|
+
bufferWriter.writeVarSlice(out.script);
|
|
349
|
+
});
|
|
350
|
+
hashOutputs = bcrypto.hash256(tbuffer);
|
|
351
|
+
}
|
|
352
|
+
else if ((hashType & 0x1f) === Transaction.SIGHASH_SINGLE && inIndex < this.outs.length) {
|
|
353
|
+
const output = this.outs[inIndex];
|
|
354
|
+
tbuffer = Buffer.allocUnsafe(8 + varSliceSize(output.script));
|
|
355
|
+
bufferWriter = new BufferWriter(tbuffer, 0);
|
|
356
|
+
bufferWriter.writeUInt64(output.value);
|
|
357
|
+
bufferWriter.writeVarSlice(output.script);
|
|
358
|
+
hashOutputs = bcrypto.hash256(tbuffer);
|
|
359
|
+
}
|
|
360
|
+
tbuffer = Buffer.allocUnsafe(156 + varSliceSize(prevOutScript));
|
|
361
|
+
bufferWriter = new BufferWriter(tbuffer, 0);
|
|
362
|
+
const input = this.ins[inIndex];
|
|
363
|
+
bufferWriter.writeInt32(this.version);
|
|
364
|
+
bufferWriter.writeSlice(hashPrevouts);
|
|
365
|
+
bufferWriter.writeSlice(hashSequence);
|
|
366
|
+
bufferWriter.writeSlice(input.hash);
|
|
367
|
+
bufferWriter.writeUInt32(input.index);
|
|
368
|
+
bufferWriter.writeVarSlice(prevOutScript);
|
|
369
|
+
bufferWriter.writeUInt64(value);
|
|
370
|
+
bufferWriter.writeUInt32(input.sequence);
|
|
371
|
+
bufferWriter.writeSlice(hashOutputs);
|
|
372
|
+
bufferWriter.writeUInt32(this.locktime);
|
|
373
|
+
bufferWriter.writeUInt32(hashType);
|
|
374
|
+
return bcrypto.hash256(tbuffer);
|
|
375
|
+
}
|
|
376
|
+
getHash(forWitness) {
|
|
377
|
+
if (forWitness && this.isCoinbase())
|
|
378
|
+
return Buffer.alloc(32, 0);
|
|
379
|
+
return bcrypto.hash256(this.__toBuffer(undefined, undefined, forWitness));
|
|
380
|
+
}
|
|
381
|
+
getId() {
|
|
382
|
+
return reverseBuffer(this.getHash(false)).toString('hex');
|
|
383
|
+
}
|
|
384
|
+
toBuffer(buffer, initialOffset) {
|
|
385
|
+
return this.__toBuffer(buffer, initialOffset, true);
|
|
386
|
+
}
|
|
387
|
+
toHex() {
|
|
388
|
+
return this.toBuffer(undefined, undefined).toString('hex');
|
|
389
|
+
}
|
|
390
|
+
setInputScript(index, scriptSig) {
|
|
391
|
+
typeforce(types.tuple(types.Number, types.Buffer), arguments);
|
|
392
|
+
this.ins[index].script = scriptSig;
|
|
393
|
+
}
|
|
394
|
+
setWitness(index, witness) {
|
|
395
|
+
typeforce(types.tuple(types.Number, [types.Buffer]), arguments);
|
|
396
|
+
this.ins[index].witness = witness;
|
|
397
|
+
}
|
|
398
|
+
__toBuffer(buffer, initialOffset, _ALLOW_WITNESS = false) {
|
|
399
|
+
if (!buffer)
|
|
400
|
+
buffer = Buffer.allocUnsafe(this.byteLength(_ALLOW_WITNESS));
|
|
401
|
+
const bufferWriter = new BufferWriter(buffer, initialOffset || 0);
|
|
402
|
+
bufferWriter.writeInt32(this.version);
|
|
403
|
+
const hasWitnesses = _ALLOW_WITNESS && this.hasWitnesses();
|
|
404
|
+
if (hasWitnesses) {
|
|
405
|
+
bufferWriter.writeUInt8(Transaction.ADVANCED_TRANSACTION_MARKER);
|
|
406
|
+
bufferWriter.writeUInt8(Transaction.ADVANCED_TRANSACTION_FLAG);
|
|
407
|
+
}
|
|
408
|
+
bufferWriter.writeVarInt(this.ins.length);
|
|
409
|
+
this.ins.forEach((txIn) => {
|
|
410
|
+
bufferWriter.writeSlice(txIn.hash);
|
|
411
|
+
bufferWriter.writeUInt32(txIn.index);
|
|
412
|
+
bufferWriter.writeVarSlice(txIn.script);
|
|
413
|
+
bufferWriter.writeUInt32(txIn.sequence);
|
|
414
|
+
});
|
|
415
|
+
bufferWriter.writeVarInt(this.outs.length);
|
|
416
|
+
this.outs.forEach((txOut) => {
|
|
417
|
+
if (isOutput(txOut)) {
|
|
418
|
+
bufferWriter.writeUInt64(txOut.value);
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
bufferWriter.writeSlice(txOut.valueBuffer);
|
|
422
|
+
}
|
|
423
|
+
bufferWriter.writeVarSlice(txOut.script);
|
|
424
|
+
});
|
|
425
|
+
if (hasWitnesses) {
|
|
426
|
+
this.ins.forEach((input) => {
|
|
427
|
+
bufferWriter.writeVector(input.witness);
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
bufferWriter.writeUInt32(this.locktime);
|
|
431
|
+
if (initialOffset !== undefined)
|
|
432
|
+
return buffer.slice(initialOffset, bufferWriter.offset);
|
|
433
|
+
return buffer;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
Transaction.DEFAULT_SEQUENCE = 0xffffffff;
|
|
437
|
+
Transaction.SIGHASH_DEFAULT = 0x00;
|
|
438
|
+
Transaction.SIGHASH_ALL = 0x01;
|
|
439
|
+
Transaction.SIGHASH_NONE = 0x02;
|
|
440
|
+
Transaction.SIGHASH_SINGLE = 0x03;
|
|
441
|
+
Transaction.SIGHASH_ANYONECANPAY = 0x80;
|
|
442
|
+
Transaction.SIGHASH_OUTPUT_MASK = 0x03;
|
|
443
|
+
Transaction.SIGHASH_INPUT_MASK = 0x80;
|
|
444
|
+
Transaction.ADVANCED_TRANSACTION_MARKER = 0x00;
|
|
445
|
+
Transaction.ADVANCED_TRANSACTION_FLAG = 0x01;
|
package/build/types.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export declare const typeforce: any;
|
|
2
|
+
export declare function stacksEqual(a: Buffer[], b: Buffer[]): boolean;
|
|
3
|
+
export declare function isPoint(p: Buffer | number | undefined | null): boolean;
|
|
4
|
+
export declare function Satoshi(value: number): boolean;
|
|
5
|
+
export interface XOnlyPointAddTweakResult {
|
|
6
|
+
parity: 1 | 0;
|
|
7
|
+
xOnlyPubkey: Uint8Array;
|
|
8
|
+
}
|
|
9
|
+
export interface Tapleaf {
|
|
10
|
+
output: Buffer;
|
|
11
|
+
version?: number;
|
|
12
|
+
}
|
|
13
|
+
export declare const TAPLEAF_VERSION_MASK = 254;
|
|
14
|
+
export declare function isTapleaf(o: any): o is Tapleaf;
|
|
15
|
+
export type Taptree = [Taptree | Tapleaf, Taptree | Tapleaf] | Tapleaf;
|
|
16
|
+
export declare function isTaptree(scriptTree: any): scriptTree is Taptree;
|
|
17
|
+
export interface TinySecp256k1Interface {
|
|
18
|
+
isXOnlyPoint(p: Uint8Array): boolean;
|
|
19
|
+
xOnlyPointAddTweak(p: Uint8Array, tweak: Uint8Array): XOnlyPointAddTweakResult | null;
|
|
20
|
+
}
|
|
21
|
+
export declare const Buffer256bit: any;
|
|
22
|
+
export declare const Hash160bit: any;
|
|
23
|
+
export declare const Hash256bit: any;
|
|
24
|
+
export declare const Number: any;
|
|
25
|
+
export declare const Array: any;
|
|
26
|
+
export declare const Boolean: any;
|
|
27
|
+
export declare const String: any;
|
|
28
|
+
export declare const Buffer: any;
|
|
29
|
+
export declare const Hex: any;
|
|
30
|
+
export declare const maybe: any;
|
|
31
|
+
export declare const tuple: any;
|
|
32
|
+
export declare const UInt8: any;
|
|
33
|
+
export declare const UInt32: any;
|
|
34
|
+
export declare const Function: any;
|
|
35
|
+
export declare const BufferN: any;
|
|
36
|
+
export declare const Null: any;
|
|
37
|
+
export declare const oneOf: any;
|
package/build/types.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Buffer as NBuffer } from 'buffer';
|
|
2
|
+
import * as _typeforce from 'typeforce';
|
|
3
|
+
export const typeforce = _typeforce.default;
|
|
4
|
+
const ZERO32 = NBuffer.alloc(32, 0);
|
|
5
|
+
const EC_P = NBuffer.from('fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f', 'hex');
|
|
6
|
+
export function stacksEqual(a, b) {
|
|
7
|
+
if (a.length !== b.length)
|
|
8
|
+
return false;
|
|
9
|
+
return a.every((x, i) => {
|
|
10
|
+
return x.equals(b[i]);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export function isPoint(p) {
|
|
14
|
+
if (!NBuffer.isBuffer(p))
|
|
15
|
+
return false;
|
|
16
|
+
if (p.length < 33)
|
|
17
|
+
return false;
|
|
18
|
+
const t = p[0];
|
|
19
|
+
const x = p.slice(1, 33);
|
|
20
|
+
if (x.compare(ZERO32) === 0)
|
|
21
|
+
return false;
|
|
22
|
+
if (x.compare(EC_P) >= 0)
|
|
23
|
+
return false;
|
|
24
|
+
if ((t === 0x02 || t === 0x03) && p.length === 33) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
if (p.length !== 65)
|
|
28
|
+
return false;
|
|
29
|
+
const y = p.slice(33);
|
|
30
|
+
if (y.compare(ZERO32) === 0)
|
|
31
|
+
return false;
|
|
32
|
+
if (y.compare(EC_P) >= 0)
|
|
33
|
+
return false;
|
|
34
|
+
return t === 0x04 || t === 0x06 || t === 0x07;
|
|
35
|
+
}
|
|
36
|
+
const SATOSHI_MAX = 21 * 1e14;
|
|
37
|
+
export function Satoshi(value) {
|
|
38
|
+
return typeforce.UInt53(value) && value <= SATOSHI_MAX;
|
|
39
|
+
}
|
|
40
|
+
export const TAPLEAF_VERSION_MASK = 0xfe;
|
|
41
|
+
export function isTapleaf(o) {
|
|
42
|
+
if (!o || !('output' in o))
|
|
43
|
+
return false;
|
|
44
|
+
if (!NBuffer.isBuffer(o.output))
|
|
45
|
+
return false;
|
|
46
|
+
if (o.version !== undefined)
|
|
47
|
+
return (o.version & TAPLEAF_VERSION_MASK) === o.version;
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
export function isTaptree(scriptTree) {
|
|
51
|
+
if (!Array(scriptTree))
|
|
52
|
+
return isTapleaf(scriptTree);
|
|
53
|
+
if (scriptTree.length !== 2)
|
|
54
|
+
return false;
|
|
55
|
+
return scriptTree.every((t) => isTaptree(t));
|
|
56
|
+
}
|
|
57
|
+
export const Buffer256bit = typeforce.BufferN(32);
|
|
58
|
+
export const Hash160bit = typeforce.BufferN(20);
|
|
59
|
+
export const Hash256bit = typeforce.BufferN(32);
|
|
60
|
+
export const Number = typeforce.Number;
|
|
61
|
+
export const Array = typeforce.Array;
|
|
62
|
+
export const Boolean = typeforce.Boolean;
|
|
63
|
+
export const String = typeforce.String;
|
|
64
|
+
export const Buffer = typeforce.Buffer;
|
|
65
|
+
export const Hex = typeforce.Hex;
|
|
66
|
+
export const maybe = typeforce.maybe;
|
|
67
|
+
export const tuple = typeforce.tuple;
|
|
68
|
+
export const UInt8 = typeforce.UInt8;
|
|
69
|
+
export const UInt32 = typeforce.UInt32;
|
|
70
|
+
export const Function = typeforce.Function;
|
|
71
|
+
export const BufferN = typeforce.BufferN;
|
|
72
|
+
export const Null = typeforce.Null;
|
|
73
|
+
export const oneOf = typeforce.oneOf;
|
package/cjs/package.json
ADDED