@btc-vision/bitcoin 6.3.2 → 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/.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 +48 -10
- package/build/payments/p2sh.js +2 -1
- package/build/psbt/psbtutils.js +11 -4
- 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 +67 -10
- package/src/payments/p2sh.ts +206 -205
- package/src/psbt/bip371.ts +441 -441
- package/src/psbt/psbtutils.ts +13 -11
- package/src/psbt.ts +2187 -2174
- package/src/types.ts +122 -122
- package/webpack.config.js +79 -79
package/src/payments/p2pk.ts
CHANGED
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
import { bitcoin as BITCOIN_NETWORK } from '../networks.js';
|
|
2
|
-
import * as bscript from '../script.js';
|
|
3
|
-
import { isPoint, typeforce as typef } from '../types.js';
|
|
4
|
-
import { Payment, PaymentOpts, StackFunction } from './index.js';
|
|
5
|
-
import * as lazy from './lazy.js';
|
|
6
|
-
|
|
7
|
-
const OPS = bscript.OPS;
|
|
8
|
-
|
|
9
|
-
// input: {signature}
|
|
10
|
-
// output: {pubKey} OP_CHECKSIG
|
|
11
|
-
/**
|
|
12
|
-
* Creates a pay-to-public-key (P2PK) payment object.
|
|
13
|
-
*
|
|
14
|
-
* @param a - The payment object containing the necessary data.
|
|
15
|
-
* @param opts - Optional payment options.
|
|
16
|
-
* @returns The P2PK payment object.
|
|
17
|
-
* @throws {TypeError} If the required data is not provided or if the data is invalid.
|
|
18
|
-
*/
|
|
19
|
-
export function p2pk(a: Payment, opts?: PaymentOpts): Payment {
|
|
20
|
-
if (!a.input && !a.output && !a.pubkey && !a.input && !a.signature)
|
|
21
|
-
throw new TypeError('Not enough data');
|
|
22
|
-
opts = Object.assign({ validate: true }, opts || {});
|
|
23
|
-
|
|
24
|
-
typef(
|
|
25
|
-
{
|
|
26
|
-
network: typef.maybe(typef.Object),
|
|
27
|
-
output: typef.maybe(typef.Buffer),
|
|
28
|
-
pubkey: typef.maybe(isPoint),
|
|
29
|
-
|
|
30
|
-
signature: typef.maybe(bscript.isCanonicalScriptSignature),
|
|
31
|
-
input: typef.maybe(typef.Buffer),
|
|
32
|
-
},
|
|
33
|
-
a,
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
const _chunks = lazy.value(() => {
|
|
37
|
-
return bscript.decompile(a.input!);
|
|
38
|
-
}) as StackFunction;
|
|
39
|
-
|
|
40
|
-
const network = a.network || BITCOIN_NETWORK;
|
|
41
|
-
const o: Payment = { name: 'p2pk', network };
|
|
42
|
-
|
|
43
|
-
lazy.prop(o, 'output', () => {
|
|
44
|
-
if (!a.pubkey) return;
|
|
45
|
-
return bscript.compile([a.pubkey, OPS.OP_CHECKSIG]);
|
|
46
|
-
});
|
|
47
|
-
lazy.prop(o, 'pubkey', () => {
|
|
48
|
-
if (!a.output) return;
|
|
49
|
-
return a.output.slice(1, -1);
|
|
50
|
-
});
|
|
51
|
-
lazy.prop(o, 'signature', () => {
|
|
52
|
-
if (!a.input) return;
|
|
53
|
-
return _chunks()[0] as Buffer;
|
|
54
|
-
});
|
|
55
|
-
lazy.prop(o, 'input', () => {
|
|
56
|
-
if (!a.signature) return;
|
|
57
|
-
return bscript.compile([a.signature]);
|
|
58
|
-
});
|
|
59
|
-
lazy.prop(o, 'witness', () => {
|
|
60
|
-
if (!o.input) return;
|
|
61
|
-
return [];
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// extended validation
|
|
65
|
-
if (opts.validate) {
|
|
66
|
-
if (a.output) {
|
|
67
|
-
if (a.output[a.output.length - 1] !== OPS.OP_CHECKSIG)
|
|
68
|
-
throw new TypeError('Output is invalid');
|
|
69
|
-
if (!isPoint(o.pubkey)) throw new TypeError('Output pubkey is invalid');
|
|
70
|
-
if (a.pubkey && !a.pubkey.equals(o.pubkey!)) throw new TypeError('Pubkey mismatch');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (a.signature) {
|
|
74
|
-
if (a.input && !a.input.equals(o.input!)) throw new TypeError('Signature mismatch');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (a.input) {
|
|
78
|
-
if (_chunks().length !== 1) throw new TypeError('Input is invalid');
|
|
79
|
-
if (!bscript.isCanonicalScriptSignature(o.signature!))
|
|
80
|
-
throw new TypeError('Input has invalid signature');
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return Object.assign(o, a);
|
|
85
|
-
}
|
|
1
|
+
import { bitcoin as BITCOIN_NETWORK } from '../networks.js';
|
|
2
|
+
import * as bscript from '../script.js';
|
|
3
|
+
import { isPoint, typeforce as typef } from '../types.js';
|
|
4
|
+
import { Payment, PaymentOpts, StackFunction } from './index.js';
|
|
5
|
+
import * as lazy from './lazy.js';
|
|
6
|
+
|
|
7
|
+
const OPS = bscript.OPS;
|
|
8
|
+
|
|
9
|
+
// input: {signature}
|
|
10
|
+
// output: {pubKey} OP_CHECKSIG
|
|
11
|
+
/**
|
|
12
|
+
* Creates a pay-to-public-key (P2PK) payment object.
|
|
13
|
+
*
|
|
14
|
+
* @param a - The payment object containing the necessary data.
|
|
15
|
+
* @param opts - Optional payment options.
|
|
16
|
+
* @returns The P2PK payment object.
|
|
17
|
+
* @throws {TypeError} If the required data is not provided or if the data is invalid.
|
|
18
|
+
*/
|
|
19
|
+
export function p2pk(a: Payment, opts?: PaymentOpts): Payment {
|
|
20
|
+
if (!a.input && !a.output && !a.pubkey && !a.input && !a.signature)
|
|
21
|
+
throw new TypeError('Not enough data');
|
|
22
|
+
opts = Object.assign({ validate: true }, opts || {});
|
|
23
|
+
|
|
24
|
+
typef(
|
|
25
|
+
{
|
|
26
|
+
network: typef.maybe(typef.Object),
|
|
27
|
+
output: typef.maybe(typef.Buffer),
|
|
28
|
+
pubkey: typef.maybe(isPoint),
|
|
29
|
+
|
|
30
|
+
signature: typef.maybe(bscript.isCanonicalScriptSignature),
|
|
31
|
+
input: typef.maybe(typef.Buffer),
|
|
32
|
+
},
|
|
33
|
+
a,
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const _chunks = lazy.value(() => {
|
|
37
|
+
return bscript.decompile(a.input!);
|
|
38
|
+
}) as StackFunction;
|
|
39
|
+
|
|
40
|
+
const network = a.network || BITCOIN_NETWORK;
|
|
41
|
+
const o: Payment = { name: 'p2pk', network };
|
|
42
|
+
|
|
43
|
+
lazy.prop(o, 'output', () => {
|
|
44
|
+
if (!a.pubkey) return;
|
|
45
|
+
return bscript.compile([a.pubkey, OPS.OP_CHECKSIG]);
|
|
46
|
+
});
|
|
47
|
+
lazy.prop(o, 'pubkey', () => {
|
|
48
|
+
if (!a.output) return;
|
|
49
|
+
return a.output.slice(1, -1);
|
|
50
|
+
});
|
|
51
|
+
lazy.prop(o, 'signature', () => {
|
|
52
|
+
if (!a.input) return;
|
|
53
|
+
return _chunks()[0] as Buffer;
|
|
54
|
+
});
|
|
55
|
+
lazy.prop(o, 'input', () => {
|
|
56
|
+
if (!a.signature) return;
|
|
57
|
+
return bscript.compile([a.signature]);
|
|
58
|
+
});
|
|
59
|
+
lazy.prop(o, 'witness', () => {
|
|
60
|
+
if (!o.input) return;
|
|
61
|
+
return [];
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// extended validation
|
|
65
|
+
if (opts.validate) {
|
|
66
|
+
if (a.output) {
|
|
67
|
+
if (a.output[a.output.length - 1] !== OPS.OP_CHECKSIG)
|
|
68
|
+
throw new TypeError('Output is invalid');
|
|
69
|
+
if (!isPoint(o.pubkey)) throw new TypeError('Output pubkey is invalid');
|
|
70
|
+
if (a.pubkey && !a.pubkey.equals(o.pubkey!)) throw new TypeError('Pubkey mismatch');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (a.signature) {
|
|
74
|
+
if (a.input && !a.input.equals(o.input!)) throw new TypeError('Signature mismatch');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (a.input) {
|
|
78
|
+
if (_chunks().length !== 1) throw new TypeError('Input is invalid');
|
|
79
|
+
if (!bscript.isCanonicalScriptSignature(o.signature!))
|
|
80
|
+
throw new TypeError('Input has invalid signature');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return Object.assign(o, a);
|
|
85
|
+
}
|
package/src/payments/p2pkh.ts
CHANGED
|
@@ -5,6 +5,7 @@ import * as bscript from '../script.js';
|
|
|
5
5
|
import { isPoint, typeforce as typef } from '../types.js';
|
|
6
6
|
import { Payment, PaymentOpts, StackFunction } from './index.js';
|
|
7
7
|
import * as lazy from './lazy.js';
|
|
8
|
+
import { decompressPublicKey } from '../psbt/psbtutils.js';
|
|
8
9
|
|
|
9
10
|
const OPS = bscript.OPS;
|
|
10
11
|
|
|
@@ -19,8 +20,10 @@ const OPS = bscript.OPS;
|
|
|
19
20
|
* @throws {TypeError} If the required data is not provided or if the data is invalid.
|
|
20
21
|
*/
|
|
21
22
|
export function p2pkh(a: Payment, opts?: PaymentOpts): Payment {
|
|
22
|
-
if (!a.address && !a.hash && !a.output && !a.pubkey && !a.input)
|
|
23
|
+
if (!a.address && !a.hash && !a.output && !a.pubkey && !a.input) {
|
|
23
24
|
throw new TypeError('Not enough data');
|
|
25
|
+
}
|
|
26
|
+
|
|
24
27
|
opts = Object.assign({ validate: true }, opts || {});
|
|
25
28
|
|
|
26
29
|
typef(
|
|
@@ -43,6 +46,7 @@ export function p2pkh(a: Payment, opts?: PaymentOpts): Payment {
|
|
|
43
46
|
const hash = payload.slice(1);
|
|
44
47
|
return { version, hash };
|
|
45
48
|
});
|
|
49
|
+
|
|
46
50
|
const _chunks = lazy.value(() => {
|
|
47
51
|
return bscript.decompile(a.input!);
|
|
48
52
|
}) as StackFunction;
|
|
@@ -58,11 +62,13 @@ export function p2pkh(a: Payment, opts?: PaymentOpts): Payment {
|
|
|
58
62
|
o.hash.copy(payload, 1);
|
|
59
63
|
return bs58check.default.encode(payload);
|
|
60
64
|
});
|
|
65
|
+
|
|
61
66
|
lazy.prop(o, 'hash', () => {
|
|
62
67
|
if (a.output) return a.output.slice(3, 23);
|
|
63
68
|
if (a.address) return _address().hash;
|
|
64
69
|
if (a.pubkey || o.pubkey) return bcrypto.hash160(a.pubkey! || o.pubkey!);
|
|
65
70
|
});
|
|
71
|
+
|
|
66
72
|
lazy.prop(o, 'output', () => {
|
|
67
73
|
if (!o.hash) return;
|
|
68
74
|
return bscript.compile([
|
|
@@ -73,19 +79,34 @@ export function p2pkh(a: Payment, opts?: PaymentOpts): Payment {
|
|
|
73
79
|
OPS.OP_CHECKSIG,
|
|
74
80
|
]);
|
|
75
81
|
});
|
|
82
|
+
|
|
76
83
|
lazy.prop(o, 'pubkey', () => {
|
|
77
84
|
if (!a.input) return;
|
|
78
85
|
return _chunks()[1] as Buffer;
|
|
79
86
|
});
|
|
87
|
+
|
|
80
88
|
lazy.prop(o, 'signature', () => {
|
|
81
89
|
if (!a.input) return;
|
|
82
90
|
return _chunks()[0] as Buffer;
|
|
83
91
|
});
|
|
92
|
+
|
|
84
93
|
lazy.prop(o, 'input', () => {
|
|
85
94
|
if (!a.pubkey) return;
|
|
86
95
|
if (!a.signature) return;
|
|
87
|
-
|
|
96
|
+
|
|
97
|
+
let pubKey: Buffer = a.pubkey;
|
|
98
|
+
if (a.useHybrid || a.useUncompressed) {
|
|
99
|
+
const decompressed = decompressPublicKey(a.pubkey);
|
|
100
|
+
if (a.useUncompressed) {
|
|
101
|
+
pubKey = decompressed.uncompressed;
|
|
102
|
+
} else {
|
|
103
|
+
pubKey = decompressed.hybrid;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return bscript.compile([a.signature, pubKey]);
|
|
88
108
|
});
|
|
109
|
+
|
|
89
110
|
lazy.prop(o, 'witness', () => {
|
|
90
111
|
if (!o.input) return;
|
|
91
112
|
return [];
|
|
@@ -95,15 +116,23 @@ export function p2pkh(a: Payment, opts?: PaymentOpts): Payment {
|
|
|
95
116
|
if (opts.validate) {
|
|
96
117
|
let hash: Buffer = Buffer.from([]);
|
|
97
118
|
if (a.address) {
|
|
98
|
-
if (_address().version !== network.pubKeyHash)
|
|
119
|
+
if (_address().version !== network.pubKeyHash) {
|
|
99
120
|
throw new TypeError('Invalid version or Network mismatch');
|
|
100
|
-
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (_address().hash.length !== 20) {
|
|
124
|
+
throw new TypeError('Invalid address');
|
|
125
|
+
}
|
|
126
|
+
|
|
101
127
|
hash = _address().hash;
|
|
102
128
|
}
|
|
103
129
|
|
|
104
130
|
if (a.hash) {
|
|
105
|
-
if (hash.length > 0 && !hash.equals(a.hash))
|
|
106
|
-
|
|
131
|
+
if (hash.length > 0 && !hash.equals(a.hash)) {
|
|
132
|
+
throw new TypeError('Hash mismatch');
|
|
133
|
+
} else {
|
|
134
|
+
hash = a.hash;
|
|
135
|
+
}
|
|
107
136
|
}
|
|
108
137
|
|
|
109
138
|
if (a.output) {
|
|
@@ -114,8 +143,9 @@ export function p2pkh(a: Payment, opts?: PaymentOpts): Payment {
|
|
|
114
143
|
a.output[2] !== 0x14 ||
|
|
115
144
|
a.output[23] !== OPS.OP_EQUALVERIFY ||
|
|
116
145
|
a.output[24] !== OPS.OP_CHECKSIG
|
|
117
|
-
)
|
|
146
|
+
) {
|
|
118
147
|
throw new TypeError('Output is invalid');
|
|
148
|
+
}
|
|
119
149
|
|
|
120
150
|
const hash2 = a.output.slice(3, 23);
|
|
121
151
|
if (hash.length > 0 && !hash.equals(hash2)) throw new TypeError('Hash mismatch');
|
|
@@ -124,8 +154,35 @@ export function p2pkh(a: Payment, opts?: PaymentOpts): Payment {
|
|
|
124
154
|
|
|
125
155
|
if (a.pubkey) {
|
|
126
156
|
const pkh = bcrypto.hash160(a.pubkey);
|
|
127
|
-
|
|
128
|
-
|
|
157
|
+
|
|
158
|
+
let badHash = hash.length > 0 && !hash.equals(pkh);
|
|
159
|
+
if (badHash) {
|
|
160
|
+
if (
|
|
161
|
+
(a.pubkey.length === 33 && (a.pubkey[0] === 0x02 || a.pubkey[0] === 0x03)) ||
|
|
162
|
+
(a.pubkey.length === 65 && a.pubkey[0] === 0x04)
|
|
163
|
+
) {
|
|
164
|
+
const uncompressed = decompressPublicKey(a.pubkey);
|
|
165
|
+
const pkh2 = bcrypto.hash160(uncompressed.uncompressed);
|
|
166
|
+
|
|
167
|
+
if (!hash.equals(pkh2)) {
|
|
168
|
+
const pkh3 = bcrypto.hash160(uncompressed.hybrid);
|
|
169
|
+
badHash = !hash.equals(pkh3);
|
|
170
|
+
|
|
171
|
+
if (!badHash) {
|
|
172
|
+
a.useHybrid = true;
|
|
173
|
+
}
|
|
174
|
+
} else {
|
|
175
|
+
badHash = false;
|
|
176
|
+
a.useUncompressed = true;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (badHash) {
|
|
182
|
+
throw new TypeError('Hash mismatch');
|
|
183
|
+
} else {
|
|
184
|
+
hash = pkh;
|
|
185
|
+
}
|
|
129
186
|
}
|
|
130
187
|
|
|
131
188
|
if (a.input) {
|
|
@@ -141,7 +198,7 @@ export function p2pkh(a: Payment, opts?: PaymentOpts): Payment {
|
|
|
141
198
|
throw new TypeError('Pubkey mismatch');
|
|
142
199
|
|
|
143
200
|
const pkh = bcrypto.hash160(chunks[1] as Buffer);
|
|
144
|
-
if (hash.length > 0 && !hash.equals(pkh)) throw new TypeError('Hash mismatch');
|
|
201
|
+
if (hash.length > 0 && !hash.equals(pkh)) throw new TypeError('Hash mismatch (input)');
|
|
145
202
|
}
|
|
146
203
|
}
|
|
147
204
|
|