@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
@@ -29,6 +29,8 @@ export interface Payment {
29
29
  redeemVersion?: number;
30
30
  scriptTree?: Taptree;
31
31
  witness?: Buffer[];
32
+ useHybrid?: boolean;
33
+ useUncompressed?: boolean;
32
34
  }
33
35
  export type PaymentCreator = (a: Payment, opts?: PaymentOpts) => Payment;
34
36
  export type PaymentFunction = () => Payment;
package/browser/psbt.d.ts CHANGED
@@ -53,7 +53,7 @@ export declare class Psbt {
53
53
  getFeeRate(disableOutputChecks?: boolean): number;
54
54
  getFee(disableOutputChecks?: boolean): number;
55
55
  finalizeAllInputs(): this;
56
- finalizeInput(inputIndex: number, finalScriptsFunc?: FinalScriptsFunc | FinalTaprootScriptsFunc): this;
56
+ finalizeInput(inputIndex: number, finalScriptsFunc?: FinalScriptsFunc | FinalTaprootScriptsFunc, canRunChecks?: boolean): this;
57
57
  finalizeTaprootInput(inputIndex: number, tapLeafHashToFinalize?: Buffer, finalScriptsFunc?: FinalTaprootScriptsFunc): this;
58
58
  getInputType(inputIndex: number): AllScriptType;
59
59
  inputHasPubkey(inputIndex: number, pubkey: Buffer): boolean;
@@ -148,14 +148,14 @@ export interface SignerAsync {
148
148
  signSchnorr?(hash: Buffer): Promise<Buffer>;
149
149
  getPublicKey?(): Buffer;
150
150
  }
151
- type FinalScriptsFunc = (inputIndex: number, input: PsbtInput, script: Buffer, isSegwit: boolean, isP2SH: boolean, isP2WSH: boolean) => {
151
+ type FinalScriptsFunc = (inputIndex: number, input: PsbtInput, script: Buffer, isSegwit: boolean, isP2SH: boolean, isP2WSH: boolean, canRunChecks: boolean) => {
152
152
  finalScriptSig: Buffer | undefined;
153
153
  finalScriptWitness: Buffer | undefined;
154
154
  };
155
155
  type FinalTaprootScriptsFunc = (inputIndex: number, input: PsbtInput, tapLeafHashToFinalize?: Buffer) => {
156
156
  finalScriptWitness: Buffer | undefined;
157
157
  };
158
- export declare function getFinalScripts(inputIndex: number, input: PsbtInput, script: Buffer, isSegwit: boolean, isP2SH: boolean, isP2WSH: boolean): {
158
+ export declare function getFinalScripts(inputIndex: number, input: PsbtInput, script: Buffer, isSegwit: boolean, isP2SH: boolean, isP2WSH: boolean, canRunChecks?: boolean): {
159
159
  finalScriptSig: Buffer | undefined;
160
160
  finalScriptWitness: Buffer | undefined;
161
161
  };
@@ -29,6 +29,8 @@ export interface Payment {
29
29
  redeemVersion?: number;
30
30
  scriptTree?: Taptree;
31
31
  witness?: Buffer[];
32
+ useHybrid?: boolean;
33
+ useUncompressed?: boolean;
32
34
  }
33
35
  export type PaymentCreator = (a: Payment, opts?: PaymentOpts) => Payment;
34
36
  export type PaymentFunction = () => Payment;
@@ -4,10 +4,12 @@ import { bitcoin as BITCOIN_NETWORK } from '../networks.js';
4
4
  import * as bscript from '../script.js';
5
5
  import { isPoint, typeforce as typef } from '../types.js';
6
6
  import * as lazy from './lazy.js';
7
+ import { decompressPublicKey } from '../psbt/psbtutils.js';
7
8
  const OPS = bscript.OPS;
8
9
  export function p2pkh(a, opts) {
9
- if (!a.address && !a.hash && !a.output && !a.pubkey && !a.input)
10
+ if (!a.address && !a.hash && !a.output && !a.pubkey && !a.input) {
10
11
  throw new TypeError('Not enough data');
12
+ }
11
13
  opts = Object.assign({ validate: true }, opts || {});
12
14
  typef({
13
15
  network: typef.maybe(typef.Object),
@@ -71,7 +73,19 @@ export function p2pkh(a, opts) {
71
73
  return;
72
74
  if (!a.signature)
73
75
  return;
74
- return bscript.compile([a.signature, a.pubkey]);
76
+ let pubKey = a.pubkey;
77
+ if (a.useHybrid || a.useUncompressed) {
78
+ const decompressed = decompressPublicKey(a.pubkey);
79
+ if (decompressed) {
80
+ if (a.useUncompressed) {
81
+ pubKey = decompressed.uncompressed;
82
+ }
83
+ else {
84
+ pubKey = decompressed.hybrid;
85
+ }
86
+ }
87
+ }
88
+ return bscript.compile([a.signature, pubKey]);
75
89
  });
76
90
  lazy.prop(o, 'witness', () => {
77
91
  if (!o.input)
@@ -81,17 +95,21 @@ export function p2pkh(a, opts) {
81
95
  if (opts.validate) {
82
96
  let hash = Buffer.from([]);
83
97
  if (a.address) {
84
- if (_address().version !== network.pubKeyHash)
98
+ if (_address().version !== network.pubKeyHash) {
85
99
  throw new TypeError('Invalid version or Network mismatch');
86
- if (_address().hash.length !== 20)
100
+ }
101
+ if (_address().hash.length !== 20) {
87
102
  throw new TypeError('Invalid address');
103
+ }
88
104
  hash = _address().hash;
89
105
  }
90
106
  if (a.hash) {
91
- if (hash.length > 0 && !hash.equals(a.hash))
107
+ if (hash.length > 0 && !hash.equals(a.hash)) {
92
108
  throw new TypeError('Hash mismatch');
93
- else
109
+ }
110
+ else {
94
111
  hash = a.hash;
112
+ }
95
113
  }
96
114
  if (a.output) {
97
115
  if (a.output.length !== 25 ||
@@ -99,8 +117,9 @@ export function p2pkh(a, opts) {
99
117
  a.output[1] !== OPS.OP_HASH160 ||
100
118
  a.output[2] !== 0x14 ||
101
119
  a.output[23] !== OPS.OP_EQUALVERIFY ||
102
- a.output[24] !== OPS.OP_CHECKSIG)
120
+ a.output[24] !== OPS.OP_CHECKSIG) {
103
121
  throw new TypeError('Output is invalid');
122
+ }
104
123
  const hash2 = a.output.slice(3, 23);
105
124
  if (hash.length > 0 && !hash.equals(hash2))
106
125
  throw new TypeError('Hash mismatch');
@@ -109,10 +128,33 @@ export function p2pkh(a, opts) {
109
128
  }
110
129
  if (a.pubkey) {
111
130
  const pkh = bcrypto.hash160(a.pubkey);
112
- if (hash.length > 0 && !hash.equals(pkh))
131
+ let badHash = hash.length > 0 && !hash.equals(pkh);
132
+ if (badHash) {
133
+ if ((a.pubkey.length === 33 && (a.pubkey[0] === 0x02 || a.pubkey[0] === 0x03)) ||
134
+ (a.pubkey.length === 65 && a.pubkey[0] === 0x04)) {
135
+ const uncompressed = decompressPublicKey(a.pubkey);
136
+ if (uncompressed) {
137
+ const pkh2 = bcrypto.hash160(uncompressed.uncompressed);
138
+ if (!hash.equals(pkh2)) {
139
+ const pkh3 = bcrypto.hash160(uncompressed.hybrid);
140
+ badHash = !hash.equals(pkh3);
141
+ if (!badHash) {
142
+ a.useHybrid = true;
143
+ }
144
+ }
145
+ else {
146
+ badHash = false;
147
+ a.useUncompressed = true;
148
+ }
149
+ }
150
+ }
151
+ }
152
+ if (badHash) {
113
153
  throw new TypeError('Hash mismatch');
114
- else
154
+ }
155
+ else {
115
156
  hash = pkh;
157
+ }
116
158
  }
117
159
  if (a.input) {
118
160
  const chunks = _chunks();
@@ -128,7 +170,7 @@ export function p2pkh(a, opts) {
128
170
  throw new TypeError('Pubkey mismatch');
129
171
  const pkh = bcrypto.hash160(chunks[1]);
130
172
  if (hash.length > 0 && !hash.equals(pkh))
131
- throw new TypeError('Hash mismatch');
173
+ throw new TypeError('Hash mismatch (input)');
132
174
  }
133
175
  }
134
176
  return Object.assign(o, a);
@@ -6,8 +6,9 @@ import { stacksEqual, typeforce as typef } from '../types.js';
6
6
  import * as lazy from './lazy.js';
7
7
  const OPS = bscript.OPS;
8
8
  export function p2sh(a, opts) {
9
- if (!a.address && !a.hash && !a.output && !a.redeem && !a.input)
9
+ if (!a.address && !a.hash && !a.output && !a.redeem && !a.input) {
10
10
  throw new TypeError('Not enough data');
11
+ }
11
12
  opts = Object.assign({ validate: true }, opts || {});
12
13
  typef({
13
14
  network: typef.maybe(typef.Object),
@@ -11,7 +11,7 @@ export interface UncompressedPublicKey {
11
11
  hybrid: Buffer;
12
12
  uncompressed: Buffer;
13
13
  }
14
- export declare function decompressPublicKey(realPubKey: Uint8Array | Buffer): UncompressedPublicKey;
14
+ export declare function decompressPublicKey(realPubKey: Uint8Array | Buffer): UncompressedPublicKey | undefined;
15
15
  export declare function bigIntTo32Bytes(num: bigint): Buffer;
16
16
  export declare function pubkeysMatch(a: Buffer, b: Buffer): boolean;
17
17
  export declare function pubkeyPositionInScript(pubkey: Buffer, script: Buffer): number;
@@ -52,6 +52,9 @@ export function witnessStackToScriptWitness(witness) {
52
52
  return buffer;
53
53
  }
54
54
  export function decompressPublicKey(realPubKey) {
55
+ if (realPubKey.length === 32) {
56
+ return;
57
+ }
55
58
  if (![33, 65].includes(realPubKey.length)) {
56
59
  throw new Error(`Unsupported key length=${realPubKey.length}. Must be 33 (compressed) or 65 (uncompressed).`);
57
60
  }
@@ -99,12 +102,16 @@ export function pubkeysMatch(a, b) {
99
102
  return false;
100
103
  }
101
104
  export function pubkeyPositionInScript(pubkey, script) {
102
- const pubkeyHash = hash160(pubkey);
103
- const pubkeyXOnly = toXOnly(pubkey);
104
- const uncompressed = decompressPublicKey(pubkey);
105
105
  const decompiled = bscript.decompile(script);
106
106
  if (decompiled === null)
107
107
  throw new Error('Unknown script error');
108
+ const pubkeyHash = hash160(pubkey);
109
+ const pubkeyXOnly = toXOnly(pubkey);
110
+ const uncompressed = decompressPublicKey(pubkey);
111
+ const pubkeyHybridHash = uncompressed?.hybrid ? hash160(uncompressed.hybrid) : undefined;
112
+ const pubkeyUncompressedHash = uncompressed?.uncompressed
113
+ ? hash160(uncompressed.uncompressed)
114
+ : undefined;
108
115
  return decompiled.findIndex((element) => {
109
116
  if (typeof element === 'number')
110
117
  return false;
@@ -112,11 +119,19 @@ export function pubkeyPositionInScript(pubkey, script) {
112
119
  return true;
113
120
  if (pubkeysMatch(element, pubkeyXOnly))
114
121
  return true;
115
- if (pubkeysMatch(element, uncompressed.uncompressed))
116
- return true;
117
- if (pubkeysMatch(element, uncompressed.hybrid))
122
+ if (element.equals(pubkeyHash)) {
118
123
  return true;
119
- return element.equals(pubkeyHash);
124
+ }
125
+ if (uncompressed) {
126
+ if (pubkeysMatch(element, uncompressed.uncompressed))
127
+ return true;
128
+ if (pubkeysMatch(element, uncompressed.hybrid))
129
+ return true;
130
+ if ((pubkeyHybridHash && element.equals(pubkeyHybridHash)) ||
131
+ (pubkeyUncompressedHash && element.equals(pubkeyUncompressedHash))) {
132
+ return true;
133
+ }
134
+ }
120
135
  });
121
136
  }
122
137
  export function pubkeyInScript(pubkey, script) {
package/build/psbt.d.ts CHANGED
@@ -53,7 +53,7 @@ export declare class Psbt {
53
53
  getFeeRate(disableOutputChecks?: boolean): number;
54
54
  getFee(disableOutputChecks?: boolean): number;
55
55
  finalizeAllInputs(): this;
56
- finalizeInput(inputIndex: number, finalScriptsFunc?: FinalScriptsFunc | FinalTaprootScriptsFunc): this;
56
+ finalizeInput(inputIndex: number, finalScriptsFunc?: FinalScriptsFunc | FinalTaprootScriptsFunc, canRunChecks?: boolean): this;
57
57
  finalizeTaprootInput(inputIndex: number, tapLeafHashToFinalize?: Buffer, finalScriptsFunc?: FinalTaprootScriptsFunc): this;
58
58
  getInputType(inputIndex: number): AllScriptType;
59
59
  inputHasPubkey(inputIndex: number, pubkey: Buffer): boolean;
@@ -148,14 +148,14 @@ export interface SignerAsync {
148
148
  signSchnorr?(hash: Buffer): Promise<Buffer>;
149
149
  getPublicKey?(): Buffer;
150
150
  }
151
- type FinalScriptsFunc = (inputIndex: number, input: PsbtInput, script: Buffer, isSegwit: boolean, isP2SH: boolean, isP2WSH: boolean) => {
151
+ type FinalScriptsFunc = (inputIndex: number, input: PsbtInput, script: Buffer, isSegwit: boolean, isP2SH: boolean, isP2WSH: boolean, canRunChecks: boolean) => {
152
152
  finalScriptSig: Buffer | undefined;
153
153
  finalScriptWitness: Buffer | undefined;
154
154
  };
155
155
  type FinalTaprootScriptsFunc = (inputIndex: number, input: PsbtInput, tapLeafHashToFinalize?: Buffer) => {
156
156
  finalScriptWitness: Buffer | undefined;
157
157
  };
158
- export declare function getFinalScripts(inputIndex: number, input: PsbtInput, script: Buffer, isSegwit: boolean, isP2SH: boolean, isP2WSH: boolean): {
158
+ export declare function getFinalScripts(inputIndex: number, input: PsbtInput, script: Buffer, isSegwit: boolean, isP2SH: boolean, isP2WSH: boolean, canRunChecks?: boolean): {
159
159
  finalScriptSig: Buffer | undefined;
160
160
  finalScriptWitness: Buffer | undefined;
161
161
  };
package/build/psbt.js CHANGED
@@ -209,11 +209,12 @@ export class Psbt {
209
209
  range(this.data.inputs.length).forEach((idx) => this.finalizeInput(idx));
210
210
  return this;
211
211
  }
212
- finalizeInput(inputIndex, finalScriptsFunc) {
212
+ finalizeInput(inputIndex, finalScriptsFunc, canRunChecks) {
213
213
  const input = checkForInput(this.data.inputs, inputIndex);
214
- if (isTaprootInput(input))
214
+ if (isTaprootInput(input)) {
215
215
  return this._finalizeTaprootInput(inputIndex, input, undefined, finalScriptsFunc);
216
- return this._finalizeInput(inputIndex, input, finalScriptsFunc);
216
+ }
217
+ return this._finalizeInput(inputIndex, input, finalScriptsFunc, canRunChecks ?? true);
217
218
  }
218
219
  finalizeTaprootInput(inputIndex, tapLeafHashToFinalize, finalScriptsFunc = tapScriptFinalizer) {
219
220
  const input = checkForInput(this.data.inputs, inputIndex);
@@ -456,12 +457,12 @@ export class Psbt {
456
457
  throw new Error(`Can not sign for input #${inputIndex} with the key ${keyPair.publicKey.toString('hex')}`);
457
458
  return hashesForSig;
458
459
  }
459
- _finalizeInput(inputIndex, input, finalScriptsFunc = getFinalScripts) {
460
+ _finalizeInput(inputIndex, input, finalScriptsFunc = getFinalScripts, canRunChecks = true) {
460
461
  const { script, isP2SH, isP2WSH, isSegwit } = getScriptFromInput(inputIndex, input, this.__CACHE);
461
462
  if (!script)
462
463
  throw new Error(`No script found for input #${inputIndex}`);
463
464
  checkPartialSigSighashes(input);
464
- const { finalScriptSig, finalScriptWitness } = finalScriptsFunc(inputIndex, input, script, isSegwit, isP2SH, isP2WSH);
465
+ const { finalScriptSig, finalScriptWitness } = finalScriptsFunc(inputIndex, input, script, isSegwit, isP2SH, isP2WSH, canRunChecks);
465
466
  if (finalScriptSig)
466
467
  this.data.updateInput(inputIndex, { finalScriptSig });
467
468
  if (finalScriptWitness)
@@ -819,10 +820,11 @@ function getTxCacheValue(key, name, inputs, c, disableOutputChecks = false) {
819
820
  else if (key === '__FEE')
820
821
  return c.__FEE;
821
822
  }
822
- export function getFinalScripts(inputIndex, input, script, isSegwit, isP2SH, isP2WSH) {
823
+ export function getFinalScripts(inputIndex, input, script, isSegwit, isP2SH, isP2WSH, canRunChecks = true) {
823
824
  const scriptType = classifyScript(script);
824
- if (!canFinalize(input, script, scriptType))
825
+ if (!canFinalize(input, script, scriptType) && canRunChecks) {
825
826
  throw new Error(`Can not finalize input #${inputIndex}`);
827
+ }
826
828
  return prepareFinalScripts(script, scriptType, input.partialSig, isSegwit, isP2SH, isP2WSH);
827
829
  }
828
830
  export function prepareFinalScripts(script, scriptType, partialSig, isSegwit, isP2SH, isP2WSH) {