@btc-vision/bitcoin 6.3.2 → 6.3.4
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/.gitattributes +2 -2
- 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/browser/index.js +1 -1
- package/browser/payments/index.d.ts +2 -0
- package/browser/psbt.d.ts +3 -3
- package/build/payments/index.d.ts +2 -0
- package/build/payments/p2pkh.js +52 -10
- package/build/payments/p2sh.js +2 -1
- package/build/psbt/psbtutils.d.ts +1 -1
- package/build/psbt/psbtutils.js +22 -7
- package/build/psbt.d.ts +3 -3
- package/build/psbt.js +9 -7
- 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 -56
- package/package.json +1 -1
- package/src/address.ts +211 -211
- package/src/crypto/crypto-browser.js +75 -75
- package/src/crypto/crypto.ts +1 -1
- package/src/hooks/HookedSigner.ts +108 -108
- package/src/index.ts +86 -86
- package/src/networks.ts +235 -235
- package/src/payments/embed.ts +55 -55
- package/src/payments/index.ts +4 -0
- package/src/payments/lazy.ts +28 -28
- package/src/payments/p2pk.ts +85 -85
- package/src/payments/p2pkh.ts +210 -149
- package/src/payments/p2sh.ts +206 -205
- package/src/psbt/bip371.ts +441 -441
- package/src/psbt/psbtutils.ts +315 -299
- package/src/psbt.ts +2187 -2174
- package/src/types.ts +122 -122
- package/webpack.config.js +79 -79
package/src/payments/p2sh.ts
CHANGED
|
@@ -1,205 +1,206 @@
|
|
|
1
|
-
import * as bs58check from 'bs58check';
|
|
2
|
-
import * as bcrypto from '../crypto.js';
|
|
3
|
-
import { bitcoin as BITCOIN_NETWORK } from '../networks.js';
|
|
4
|
-
import * as bscript from '../script.js';
|
|
5
|
-
import { stacksEqual, typeforce as typef } from '../types.js';
|
|
6
|
-
import { Payment, PaymentFunction, PaymentOpts, Stack, StackFunction } from './index.js';
|
|
7
|
-
import * as lazy from './lazy.js';
|
|
8
|
-
|
|
9
|
-
const OPS = bscript.OPS;
|
|
10
|
-
|
|
11
|
-
// input: [redeemScriptSig ...] {redeemScript}
|
|
12
|
-
// witness: <?>
|
|
13
|
-
// output: OP_HASH160 {hash160(redeemScript)} OP_EQUAL
|
|
14
|
-
/**
|
|
15
|
-
* Creates a Pay-to-Script-Hash (P2SH) payment object.
|
|
16
|
-
*
|
|
17
|
-
* @param a - The payment object containing the necessary data.
|
|
18
|
-
* @param opts - Optional payment options.
|
|
19
|
-
* @returns The P2SH payment object.
|
|
20
|
-
* @throws {TypeError} If the required data is not provided or if the data is invalid.
|
|
21
|
-
*/
|
|
22
|
-
export function p2sh(a: Payment, opts?: PaymentOpts): Payment {
|
|
23
|
-
if (!a.address && !a.hash && !a.output && !a.redeem && !a.input)
|
|
24
|
-
throw new TypeError('Not enough data');
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
payload.
|
|
80
|
-
o.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (a.
|
|
87
|
-
if (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (o.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
a.output
|
|
133
|
-
a.output[
|
|
134
|
-
a.output[
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
if (hasInput && hasWitness) throw new TypeError('
|
|
168
|
-
if (hasInput)
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (!
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
1
|
+
import * as bs58check from 'bs58check';
|
|
2
|
+
import * as bcrypto from '../crypto.js';
|
|
3
|
+
import { bitcoin as BITCOIN_NETWORK } from '../networks.js';
|
|
4
|
+
import * as bscript from '../script.js';
|
|
5
|
+
import { stacksEqual, typeforce as typef } from '../types.js';
|
|
6
|
+
import { Payment, PaymentFunction, PaymentOpts, Stack, StackFunction } from './index.js';
|
|
7
|
+
import * as lazy from './lazy.js';
|
|
8
|
+
|
|
9
|
+
const OPS = bscript.OPS;
|
|
10
|
+
|
|
11
|
+
// input: [redeemScriptSig ...] {redeemScript}
|
|
12
|
+
// witness: <?>
|
|
13
|
+
// output: OP_HASH160 {hash160(redeemScript)} OP_EQUAL
|
|
14
|
+
/**
|
|
15
|
+
* Creates a Pay-to-Script-Hash (P2SH) payment object.
|
|
16
|
+
*
|
|
17
|
+
* @param a - The payment object containing the necessary data.
|
|
18
|
+
* @param opts - Optional payment options.
|
|
19
|
+
* @returns The P2SH payment object.
|
|
20
|
+
* @throws {TypeError} If the required data is not provided or if the data is invalid.
|
|
21
|
+
*/
|
|
22
|
+
export function p2sh(a: Payment, opts?: PaymentOpts): Payment {
|
|
23
|
+
if (!a.address && !a.hash && !a.output && !a.redeem && !a.input) {
|
|
24
|
+
throw new TypeError('Not enough data');
|
|
25
|
+
}
|
|
26
|
+
opts = Object.assign({ validate: true }, opts || {});
|
|
27
|
+
|
|
28
|
+
typef(
|
|
29
|
+
{
|
|
30
|
+
network: typef.maybe(typef.Object),
|
|
31
|
+
|
|
32
|
+
address: typef.maybe(typef.String),
|
|
33
|
+
hash: typef.maybe(typef.BufferN(20)),
|
|
34
|
+
output: typef.maybe(typef.BufferN(23)),
|
|
35
|
+
|
|
36
|
+
redeem: typef.maybe({
|
|
37
|
+
network: typef.maybe(typef.Object),
|
|
38
|
+
output: typef.maybe(typef.Buffer),
|
|
39
|
+
input: typef.maybe(typef.Buffer),
|
|
40
|
+
witness: typef.maybe(typef.arrayOf(typef.Buffer)),
|
|
41
|
+
}),
|
|
42
|
+
input: typef.maybe(typef.Buffer),
|
|
43
|
+
witness: typef.maybe(typef.arrayOf(typef.Buffer)),
|
|
44
|
+
},
|
|
45
|
+
a,
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
let network = a.network;
|
|
49
|
+
if (!network) {
|
|
50
|
+
network = (a.redeem && a.redeem.network) || BITCOIN_NETWORK;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const o: Payment = { network };
|
|
54
|
+
|
|
55
|
+
const _address = lazy.value(() => {
|
|
56
|
+
const payload = Buffer.from(bs58check.default.decode(a.address!));
|
|
57
|
+
const version = payload.readUInt8(0);
|
|
58
|
+
const hash = payload.slice(1);
|
|
59
|
+
return { version, hash };
|
|
60
|
+
});
|
|
61
|
+
const _chunks = lazy.value(() => {
|
|
62
|
+
return bscript.decompile(a.input!);
|
|
63
|
+
}) as StackFunction;
|
|
64
|
+
const _redeem = lazy.value((): Payment => {
|
|
65
|
+
const chunks = _chunks();
|
|
66
|
+
const lastChunk = chunks[chunks.length - 1];
|
|
67
|
+
return {
|
|
68
|
+
network,
|
|
69
|
+
output: lastChunk === OPS.OP_FALSE ? Buffer.from([]) : (lastChunk as Buffer),
|
|
70
|
+
input: bscript.compile(chunks.slice(0, -1)),
|
|
71
|
+
witness: a.witness || [],
|
|
72
|
+
};
|
|
73
|
+
}) as PaymentFunction;
|
|
74
|
+
|
|
75
|
+
// output dependents
|
|
76
|
+
lazy.prop(o, 'address', () => {
|
|
77
|
+
if (!o.hash) return;
|
|
78
|
+
|
|
79
|
+
const payload = Buffer.allocUnsafe(21);
|
|
80
|
+
payload.writeUInt8(o.network!.scriptHash, 0);
|
|
81
|
+
o.hash.copy(payload, 1);
|
|
82
|
+
return bs58check.default.encode(payload);
|
|
83
|
+
});
|
|
84
|
+
lazy.prop(o, 'hash', () => {
|
|
85
|
+
// in order of least effort
|
|
86
|
+
if (a.output) return a.output.slice(2, 22);
|
|
87
|
+
if (a.address) return _address().hash;
|
|
88
|
+
if (o.redeem && o.redeem.output) return bcrypto.hash160(o.redeem.output);
|
|
89
|
+
});
|
|
90
|
+
lazy.prop(o, 'output', () => {
|
|
91
|
+
if (!o.hash) return;
|
|
92
|
+
return bscript.compile([OPS.OP_HASH160, o.hash, OPS.OP_EQUAL]);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// input dependents
|
|
96
|
+
lazy.prop(o, 'redeem', () => {
|
|
97
|
+
if (!a.input) return;
|
|
98
|
+
return _redeem();
|
|
99
|
+
});
|
|
100
|
+
lazy.prop(o, 'input', () => {
|
|
101
|
+
if (!a.redeem || !a.redeem.input || !a.redeem.output) return;
|
|
102
|
+
return bscript.compile(
|
|
103
|
+
([] as Stack).concat(bscript.decompile(a.redeem.input) as Stack, a.redeem.output),
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
lazy.prop(o, 'witness', () => {
|
|
107
|
+
if (o.redeem && o.redeem.witness) return o.redeem.witness;
|
|
108
|
+
if (o.input) return [];
|
|
109
|
+
});
|
|
110
|
+
lazy.prop(o, 'name', () => {
|
|
111
|
+
const nameParts = ['p2sh'];
|
|
112
|
+
if (o.redeem !== undefined && o.redeem.name !== undefined) nameParts.push(o.redeem.name!);
|
|
113
|
+
return nameParts.join('-');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
if (opts.validate) {
|
|
117
|
+
let hash: Buffer = Buffer.from([]);
|
|
118
|
+
if (a.address) {
|
|
119
|
+
if (_address().version !== network.scriptHash)
|
|
120
|
+
throw new TypeError('Invalid version or Network mismatch');
|
|
121
|
+
if (_address().hash.length !== 20) throw new TypeError('Invalid address');
|
|
122
|
+
hash = _address().hash;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (a.hash) {
|
|
126
|
+
if (hash.length > 0 && !hash.equals(a.hash)) throw new TypeError('Hash mismatch');
|
|
127
|
+
else hash = a.hash;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (a.output) {
|
|
131
|
+
if (
|
|
132
|
+
a.output.length !== 23 ||
|
|
133
|
+
a.output[0] !== OPS.OP_HASH160 ||
|
|
134
|
+
a.output[1] !== 0x14 ||
|
|
135
|
+
a.output[22] !== OPS.OP_EQUAL
|
|
136
|
+
)
|
|
137
|
+
throw new TypeError('Output is invalid');
|
|
138
|
+
|
|
139
|
+
const hash2 = a.output.slice(2, 22);
|
|
140
|
+
if (hash.length > 0 && !hash.equals(hash2)) throw new TypeError('Hash mismatch');
|
|
141
|
+
else hash = hash2;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// inlined to prevent 'no-inner-declarations' failing
|
|
145
|
+
const checkRedeem = (redeem: Payment): void => {
|
|
146
|
+
// is the redeem output empty/invalid?
|
|
147
|
+
if (redeem.output) {
|
|
148
|
+
const decompile = bscript.decompile(redeem.output);
|
|
149
|
+
if (!decompile || decompile.length < 1)
|
|
150
|
+
throw new TypeError('Redeem.output too short');
|
|
151
|
+
if (redeem.output.byteLength > 520)
|
|
152
|
+
throw new TypeError('Redeem.output unspendable if larger than 520 bytes');
|
|
153
|
+
if (bscript.countNonPushOnlyOPs(decompile) > 201)
|
|
154
|
+
throw new TypeError(
|
|
155
|
+
'Redeem.output unspendable with more than 201 non-push ops',
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
// match hash against other sources
|
|
159
|
+
const hash2 = bcrypto.hash160(redeem.output);
|
|
160
|
+
if (hash.length > 0 && !hash.equals(hash2)) throw new TypeError('Hash mismatch');
|
|
161
|
+
else hash = hash2;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (redeem.input) {
|
|
165
|
+
const hasInput = redeem.input.length > 0;
|
|
166
|
+
const hasWitness = redeem.witness && redeem.witness.length > 0;
|
|
167
|
+
if (!hasInput && !hasWitness) throw new TypeError('Empty input');
|
|
168
|
+
if (hasInput && hasWitness) throw new TypeError('Input and witness provided');
|
|
169
|
+
if (hasInput) {
|
|
170
|
+
const richunks = bscript.decompile(redeem.input) as Stack;
|
|
171
|
+
if (!bscript.isPushOnly(richunks))
|
|
172
|
+
throw new TypeError('Non push-only scriptSig');
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
if (a.input) {
|
|
178
|
+
const chunks = _chunks();
|
|
179
|
+
if (!chunks || chunks.length < 1) throw new TypeError('Input too short');
|
|
180
|
+
if (!Buffer.isBuffer(_redeem().output)) throw new TypeError('Input is invalid');
|
|
181
|
+
|
|
182
|
+
checkRedeem(_redeem());
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (a.redeem) {
|
|
186
|
+
if (a.redeem.network && a.redeem.network !== network)
|
|
187
|
+
throw new TypeError('Network mismatch');
|
|
188
|
+
if (a.input) {
|
|
189
|
+
const redeem = _redeem();
|
|
190
|
+
if (a.redeem.output && !a.redeem.output.equals(redeem.output!))
|
|
191
|
+
throw new TypeError('Redeem.output mismatch');
|
|
192
|
+
if (a.redeem.input && !a.redeem.input.equals(redeem.input!))
|
|
193
|
+
throw new TypeError('Redeem.input mismatch');
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
checkRedeem(a.redeem);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (a.witness) {
|
|
200
|
+
if (a.redeem && a.redeem.witness && !stacksEqual(a.redeem.witness, a.witness))
|
|
201
|
+
throw new TypeError('Witness and redeem.witness mismatch');
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return Object.assign(o, a);
|
|
206
|
+
}
|