@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.
Files changed (144) hide show
  1. package/.gitattributes +2 -2
  2. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/.ready +0 -0
  3. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/.release-please-manifest.json +3 -0
  4. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/CHANGELOG.md +962 -0
  5. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/CONTRIBUTING.md +34 -0
  6. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/LICENSE +24 -0
  7. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/README.md +273 -0
  8. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/SECURITY.md +2 -0
  9. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/addon.gypi +204 -0
  10. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/bin/node-gyp.js +138 -0
  11. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/.release-please-manifest.json +3 -0
  12. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/LICENSE +28 -0
  13. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/data/ninja/build.ninja +4 -0
  14. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/data/win/large-pdb-shim.cc +12 -0
  15. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/GypVsCMake.md +116 -0
  16. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/Hacking.md +46 -0
  17. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/InputFormatReference.md +1080 -0
  18. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/LanguageSpecification.md +430 -0
  19. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/README.md +27 -0
  20. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/Testing.md +450 -0
  21. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/docs/UserDocumentation.md +965 -0
  22. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/gyp +8 -0
  23. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/gyp.bat +5 -0
  24. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/gyp_main.py +45 -0
  25. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +365 -0
  26. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +206 -0
  27. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +1272 -0
  28. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +1547 -0
  29. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +59 -0
  30. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +153 -0
  31. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +271 -0
  32. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +574 -0
  33. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +692 -0
  34. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/common.py +711 -0
  35. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +171 -0
  36. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +169 -0
  37. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +113 -0
  38. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +55 -0
  39. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
  40. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +804 -0
  41. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +1173 -0
  42. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +1318 -0
  43. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +127 -0
  44. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +103 -0
  45. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +461 -0
  46. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +89 -0
  47. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +57 -0
  48. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +2745 -0
  49. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +3976 -0
  50. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +44 -0
  51. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +2964 -0
  52. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +67 -0
  53. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +1391 -0
  54. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +25 -0
  55. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/input.py +3115 -0
  56. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +98 -0
  57. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +771 -0
  58. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +1260 -0
  59. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +174 -0
  60. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +61 -0
  61. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +373 -0
  62. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +1938 -0
  63. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation_test.py +53 -0
  64. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +302 -0
  65. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +3198 -0
  66. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +65 -0
  67. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/LICENSE +3 -0
  68. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/LICENSE.APACHE +177 -0
  69. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/LICENSE.BSD +23 -0
  70. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/__init__.py +15 -0
  71. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_elffile.py +108 -0
  72. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_manylinux.py +252 -0
  73. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_musllinux.py +83 -0
  74. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_parser.py +359 -0
  75. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_structures.py +61 -0
  76. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/_tokenizer.py +192 -0
  77. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/markers.py +252 -0
  78. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/metadata.py +825 -0
  79. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/py.typed +0 -0
  80. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/requirements.py +90 -0
  81. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/specifiers.py +1030 -0
  82. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/tags.py +553 -0
  83. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/utils.py +172 -0
  84. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pylib/packaging/version.py +563 -0
  85. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/pyproject.toml +120 -0
  86. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/release-please-config.json +11 -0
  87. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/gyp/test_gyp.py +261 -0
  88. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/Find-VisualStudio.cs +250 -0
  89. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/build.js +227 -0
  90. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/clean.js +15 -0
  91. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/configure.js +328 -0
  92. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/create-config-gypi.js +150 -0
  93. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/download.js +39 -0
  94. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/find-node-directory.js +63 -0
  95. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/find-python.js +310 -0
  96. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/find-visualstudio.js +590 -0
  97. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/install.js +415 -0
  98. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/list.js +26 -0
  99. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/log.js +168 -0
  100. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/node-gyp.js +188 -0
  101. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/process-release.js +146 -0
  102. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/rebuild.js +12 -0
  103. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/remove.js +43 -0
  104. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/lib/util.js +81 -0
  105. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/macOS_Catalina_acid_test.sh +21 -0
  106. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/package.json +51 -0
  107. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/release-please-config.json +40 -0
  108. package/.yarn/unplugged/node-gyp-npm-10.2.0-cad1109948/node_modules/node-gyp/src/win_delay_load_hook.cc +39 -0
  109. package/browser/index.js +1 -1
  110. package/browser/payments/index.d.ts +2 -0
  111. package/browser/psbt.d.ts +3 -3
  112. package/build/payments/index.d.ts +2 -0
  113. package/build/payments/p2pkh.js +52 -10
  114. package/build/payments/p2sh.js +2 -1
  115. package/build/psbt/psbtutils.d.ts +1 -1
  116. package/build/psbt/psbtutils.js +22 -7
  117. package/build/psbt.d.ts +3 -3
  118. package/build/psbt.js +9 -7
  119. package/coverage/tmp/coverage-31752-1735543485354-0.json +1 -0
  120. package/coverage/tmp/coverage-59920-1735543484555-0.json +1 -0
  121. package/coverage/tmp/coverage-66252-1735543483919-0.json +1 -0
  122. package/coverage/tmp/coverage-68440-1735543485236-0.json +1 -0
  123. package/coverage/tmp/coverage-70588-1735543484426-0.json +1 -0
  124. package/coverage/tmp/coverage-79292-1735543485296-0.json +1 -0
  125. package/coverage/tmp/coverage-80212-1735543483980-0.json +1 -0
  126. package/eslint.config.js +56 -56
  127. package/package.json +1 -1
  128. package/src/address.ts +211 -211
  129. package/src/crypto/crypto-browser.js +75 -75
  130. package/src/crypto/crypto.ts +1 -1
  131. package/src/hooks/HookedSigner.ts +108 -108
  132. package/src/index.ts +86 -86
  133. package/src/networks.ts +235 -235
  134. package/src/payments/embed.ts +55 -55
  135. package/src/payments/index.ts +4 -0
  136. package/src/payments/lazy.ts +28 -28
  137. package/src/payments/p2pk.ts +85 -85
  138. package/src/payments/p2pkh.ts +210 -149
  139. package/src/payments/p2sh.ts +206 -205
  140. package/src/psbt/bip371.ts +441 -441
  141. package/src/psbt/psbtutils.ts +315 -299
  142. package/src/psbt.ts +2187 -2174
  143. package/src/types.ts +122 -122
  144. package/webpack.config.js +79 -79
@@ -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
+ }
@@ -1,149 +1,210 @@
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 { isPoint, typeforce as typef } from '../types.js';
6
- import { Payment, PaymentOpts, StackFunction } from './index.js';
7
- import * as lazy from './lazy.js';
8
-
9
- const OPS = bscript.OPS;
10
-
11
- // input: {signature} {pubkey}
12
- // output: OP_DUP OP_HASH160 {hash160(pubkey)} OP_EQUALVERIFY OP_CHECKSIG
13
- /**
14
- * Creates a Pay-to-Public-Key-Hash (P2PKH) payment object.
15
- *
16
- * @param a - The payment object containing the necessary data.
17
- * @param opts - Optional payment options.
18
- * @returns The P2PKH payment object.
19
- * @throws {TypeError} If the required data is not provided or if the data is invalid.
20
- */
21
- export function p2pkh(a: Payment, opts?: PaymentOpts): Payment {
22
- if (!a.address && !a.hash && !a.output && !a.pubkey && !a.input)
23
- throw new TypeError('Not enough data');
24
- opts = Object.assign({ validate: true }, opts || {});
25
-
26
- typef(
27
- {
28
- network: typef.maybe(typef.Object),
29
- address: typef.maybe(typef.String),
30
- hash: typef.maybe(typef.BufferN(20)),
31
- output: typef.maybe(typef.BufferN(25)),
32
-
33
- pubkey: typef.maybe(isPoint),
34
- signature: typef.maybe(bscript.isCanonicalScriptSignature),
35
- input: typef.maybe(typef.Buffer),
36
- },
37
- a,
38
- );
39
-
40
- const _address = lazy.value(() => {
41
- const payload = Buffer.from(bs58check.default.decode(a.address!));
42
- const version = payload.readUInt8(0);
43
- const hash = payload.slice(1);
44
- return { version, hash };
45
- });
46
- const _chunks = lazy.value(() => {
47
- return bscript.decompile(a.input!);
48
- }) as StackFunction;
49
-
50
- const network = a.network || BITCOIN_NETWORK;
51
- const o: Payment = { name: 'p2pkh', network };
52
-
53
- lazy.prop(o, 'address', () => {
54
- if (!o.hash) return;
55
-
56
- const payload = Buffer.allocUnsafe(21);
57
- payload.writeUInt8(network.pubKeyHash, 0);
58
- o.hash.copy(payload, 1);
59
- return bs58check.default.encode(payload);
60
- });
61
- lazy.prop(o, 'hash', () => {
62
- if (a.output) return a.output.slice(3, 23);
63
- if (a.address) return _address().hash;
64
- if (a.pubkey || o.pubkey) return bcrypto.hash160(a.pubkey! || o.pubkey!);
65
- });
66
- lazy.prop(o, 'output', () => {
67
- if (!o.hash) return;
68
- return bscript.compile([
69
- OPS.OP_DUP,
70
- OPS.OP_HASH160,
71
- o.hash,
72
- OPS.OP_EQUALVERIFY,
73
- OPS.OP_CHECKSIG,
74
- ]);
75
- });
76
- lazy.prop(o, 'pubkey', () => {
77
- if (!a.input) return;
78
- return _chunks()[1] as Buffer;
79
- });
80
- lazy.prop(o, 'signature', () => {
81
- if (!a.input) return;
82
- return _chunks()[0] as Buffer;
83
- });
84
- lazy.prop(o, 'input', () => {
85
- if (!a.pubkey) return;
86
- if (!a.signature) return;
87
- return bscript.compile([a.signature, a.pubkey]);
88
- });
89
- lazy.prop(o, 'witness', () => {
90
- if (!o.input) return;
91
- return [];
92
- });
93
-
94
- // extended validation
95
- if (opts.validate) {
96
- let hash: Buffer = Buffer.from([]);
97
- if (a.address) {
98
- if (_address().version !== network.pubKeyHash)
99
- throw new TypeError('Invalid version or Network mismatch');
100
- if (_address().hash.length !== 20) throw new TypeError('Invalid address');
101
- hash = _address().hash;
102
- }
103
-
104
- if (a.hash) {
105
- if (hash.length > 0 && !hash.equals(a.hash)) throw new TypeError('Hash mismatch');
106
- else hash = a.hash;
107
- }
108
-
109
- if (a.output) {
110
- if (
111
- a.output.length !== 25 ||
112
- a.output[0] !== OPS.OP_DUP ||
113
- a.output[1] !== OPS.OP_HASH160 ||
114
- a.output[2] !== 0x14 ||
115
- a.output[23] !== OPS.OP_EQUALVERIFY ||
116
- a.output[24] !== OPS.OP_CHECKSIG
117
- )
118
- throw new TypeError('Output is invalid');
119
-
120
- const hash2 = a.output.slice(3, 23);
121
- if (hash.length > 0 && !hash.equals(hash2)) throw new TypeError('Hash mismatch');
122
- else hash = hash2;
123
- }
124
-
125
- if (a.pubkey) {
126
- const pkh = bcrypto.hash160(a.pubkey);
127
- if (hash.length > 0 && !hash.equals(pkh)) throw new TypeError('Hash mismatch');
128
- else hash = pkh;
129
- }
130
-
131
- if (a.input) {
132
- const chunks = _chunks();
133
- if (chunks.length !== 2) throw new TypeError('Input is invalid');
134
- if (!bscript.isCanonicalScriptSignature(chunks[0] as Buffer))
135
- throw new TypeError('Input has invalid signature');
136
- if (!isPoint(chunks[1])) throw new TypeError('Input has invalid pubkey');
137
-
138
- if (a.signature && !a.signature.equals(chunks[0] as Buffer))
139
- throw new TypeError('Signature mismatch');
140
- if (a.pubkey && !a.pubkey.equals(chunks[1] as Buffer))
141
- throw new TypeError('Pubkey mismatch');
142
-
143
- const pkh = bcrypto.hash160(chunks[1] as Buffer);
144
- if (hash.length > 0 && !hash.equals(pkh)) throw new TypeError('Hash mismatch');
145
- }
146
- }
147
-
148
- return Object.assign(o, a);
149
- }
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 { isPoint, typeforce as typef } from '../types.js';
6
+ import { Payment, PaymentOpts, StackFunction } from './index.js';
7
+ import * as lazy from './lazy.js';
8
+ import { decompressPublicKey } from '../psbt/psbtutils.js';
9
+
10
+ const OPS = bscript.OPS;
11
+
12
+ // input: {signature} {pubkey}
13
+ // output: OP_DUP OP_HASH160 {hash160(pubkey)} OP_EQUALVERIFY OP_CHECKSIG
14
+ /**
15
+ * Creates a Pay-to-Public-Key-Hash (P2PKH) payment object.
16
+ *
17
+ * @param a - The payment object containing the necessary data.
18
+ * @param opts - Optional payment options.
19
+ * @returns The P2PKH payment object.
20
+ * @throws {TypeError} If the required data is not provided or if the data is invalid.
21
+ */
22
+ export function p2pkh(a: Payment, opts?: PaymentOpts): Payment {
23
+ if (!a.address && !a.hash && !a.output && !a.pubkey && !a.input) {
24
+ throw new TypeError('Not enough data');
25
+ }
26
+
27
+ opts = Object.assign({ validate: true }, opts || {});
28
+
29
+ typef(
30
+ {
31
+ network: typef.maybe(typef.Object),
32
+ address: typef.maybe(typef.String),
33
+ hash: typef.maybe(typef.BufferN(20)),
34
+ output: typef.maybe(typef.BufferN(25)),
35
+
36
+ pubkey: typef.maybe(isPoint),
37
+ signature: typef.maybe(bscript.isCanonicalScriptSignature),
38
+ input: typef.maybe(typef.Buffer),
39
+ },
40
+ a,
41
+ );
42
+
43
+ const _address = lazy.value(() => {
44
+ const payload = Buffer.from(bs58check.default.decode(a.address!));
45
+ const version = payload.readUInt8(0);
46
+ const hash = payload.slice(1);
47
+ return { version, hash };
48
+ });
49
+
50
+ const _chunks = lazy.value(() => {
51
+ return bscript.decompile(a.input!);
52
+ }) as StackFunction;
53
+
54
+ const network = a.network || BITCOIN_NETWORK;
55
+ const o: Payment = { name: 'p2pkh', network };
56
+
57
+ lazy.prop(o, 'address', () => {
58
+ if (!o.hash) return;
59
+
60
+ const payload = Buffer.allocUnsafe(21);
61
+ payload.writeUInt8(network.pubKeyHash, 0);
62
+ o.hash.copy(payload, 1);
63
+ return bs58check.default.encode(payload);
64
+ });
65
+
66
+ lazy.prop(o, 'hash', () => {
67
+ if (a.output) return a.output.slice(3, 23);
68
+ if (a.address) return _address().hash;
69
+ if (a.pubkey || o.pubkey) return bcrypto.hash160(a.pubkey! || o.pubkey!);
70
+ });
71
+
72
+ lazy.prop(o, 'output', () => {
73
+ if (!o.hash) return;
74
+ return bscript.compile([
75
+ OPS.OP_DUP,
76
+ OPS.OP_HASH160,
77
+ o.hash,
78
+ OPS.OP_EQUALVERIFY,
79
+ OPS.OP_CHECKSIG,
80
+ ]);
81
+ });
82
+
83
+ lazy.prop(o, 'pubkey', () => {
84
+ if (!a.input) return;
85
+ return _chunks()[1] as Buffer;
86
+ });
87
+
88
+ lazy.prop(o, 'signature', () => {
89
+ if (!a.input) return;
90
+ return _chunks()[0] as Buffer;
91
+ });
92
+
93
+ lazy.prop(o, 'input', () => {
94
+ if (!a.pubkey) return;
95
+ if (!a.signature) return;
96
+
97
+ let pubKey: Buffer = a.pubkey;
98
+ if (a.useHybrid || a.useUncompressed) {
99
+ const decompressed = decompressPublicKey(a.pubkey);
100
+ if (decompressed) {
101
+ if (a.useUncompressed) {
102
+ pubKey = decompressed.uncompressed;
103
+ } else {
104
+ pubKey = decompressed.hybrid;
105
+ }
106
+ }
107
+ }
108
+
109
+ return bscript.compile([a.signature, pubKey]);
110
+ });
111
+
112
+ lazy.prop(o, 'witness', () => {
113
+ if (!o.input) return;
114
+ return [];
115
+ });
116
+
117
+ // extended validation
118
+ if (opts.validate) {
119
+ let hash: Buffer = Buffer.from([]);
120
+ if (a.address) {
121
+ if (_address().version !== network.pubKeyHash) {
122
+ throw new TypeError('Invalid version or Network mismatch');
123
+ }
124
+
125
+ if (_address().hash.length !== 20) {
126
+ throw new TypeError('Invalid address');
127
+ }
128
+
129
+ hash = _address().hash;
130
+ }
131
+
132
+ if (a.hash) {
133
+ if (hash.length > 0 && !hash.equals(a.hash)) {
134
+ throw new TypeError('Hash mismatch');
135
+ } else {
136
+ hash = a.hash;
137
+ }
138
+ }
139
+
140
+ if (a.output) {
141
+ if (
142
+ a.output.length !== 25 ||
143
+ a.output[0] !== OPS.OP_DUP ||
144
+ a.output[1] !== OPS.OP_HASH160 ||
145
+ a.output[2] !== 0x14 ||
146
+ a.output[23] !== OPS.OP_EQUALVERIFY ||
147
+ a.output[24] !== OPS.OP_CHECKSIG
148
+ ) {
149
+ throw new TypeError('Output is invalid');
150
+ }
151
+
152
+ const hash2 = a.output.slice(3, 23);
153
+ if (hash.length > 0 && !hash.equals(hash2)) throw new TypeError('Hash mismatch');
154
+ else hash = hash2;
155
+ }
156
+
157
+ if (a.pubkey) {
158
+ const pkh = bcrypto.hash160(a.pubkey);
159
+
160
+ let badHash = hash.length > 0 && !hash.equals(pkh);
161
+ if (badHash) {
162
+ if (
163
+ (a.pubkey.length === 33 && (a.pubkey[0] === 0x02 || a.pubkey[0] === 0x03)) ||
164
+ (a.pubkey.length === 65 && a.pubkey[0] === 0x04)
165
+ ) {
166
+ const uncompressed = decompressPublicKey(a.pubkey);
167
+ if (uncompressed) {
168
+ const pkh2 = bcrypto.hash160(uncompressed.uncompressed);
169
+
170
+ if (!hash.equals(pkh2)) {
171
+ const pkh3 = bcrypto.hash160(uncompressed.hybrid);
172
+ badHash = !hash.equals(pkh3);
173
+
174
+ if (!badHash) {
175
+ a.useHybrid = true;
176
+ }
177
+ } else {
178
+ badHash = false;
179
+ a.useUncompressed = true;
180
+ }
181
+ }
182
+ }
183
+ }
184
+
185
+ if (badHash) {
186
+ throw new TypeError('Hash mismatch');
187
+ } else {
188
+ hash = pkh;
189
+ }
190
+ }
191
+
192
+ if (a.input) {
193
+ const chunks = _chunks();
194
+ if (chunks.length !== 2) throw new TypeError('Input is invalid');
195
+ if (!bscript.isCanonicalScriptSignature(chunks[0] as Buffer))
196
+ throw new TypeError('Input has invalid signature');
197
+ if (!isPoint(chunks[1])) throw new TypeError('Input has invalid pubkey');
198
+
199
+ if (a.signature && !a.signature.equals(chunks[0] as Buffer))
200
+ throw new TypeError('Signature mismatch');
201
+ if (a.pubkey && !a.pubkey.equals(chunks[1] as Buffer))
202
+ throw new TypeError('Pubkey mismatch');
203
+
204
+ const pkh = bcrypto.hash160(chunks[1] as Buffer);
205
+ if (hash.length > 0 && !hash.equals(pkh)) throw new TypeError('Hash mismatch (input)');
206
+ }
207
+ }
208
+
209
+ return Object.assign(o, a);
210
+ }