@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
package/src/types.ts CHANGED
@@ -1,122 +1,122 @@
1
- import { Buffer as NBuffer } from 'buffer';
2
-
3
- // @ts-ignore
4
- import * as _typeforce from 'typeforce';
5
-
6
- export const typeforce = _typeforce.default;
7
-
8
- const ZERO32 = NBuffer.alloc(32, 0);
9
- const EC_P = NBuffer.from(
10
- 'fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f',
11
- 'hex',
12
- );
13
-
14
- /**
15
- * Checks if two arrays of Buffers are equal.
16
- * @param a - The first array of Buffers.
17
- * @param b - The second array of Buffers.
18
- * @returns True if the arrays are equal, false otherwise.
19
- */
20
- export function stacksEqual(a: Buffer[], b: Buffer[]): boolean {
21
- if (a.length !== b.length) return false;
22
-
23
- return a.every((x, i) => {
24
- return x.equals(b[i]);
25
- });
26
- }
27
-
28
- /**
29
- * Checks if the given value is a valid elliptic curve point.
30
- * @param p - The value to check.
31
- * @returns True if the value is a valid elliptic curve point, false otherwise.
32
- */
33
- export function isPoint(p: Buffer | number | undefined | null): boolean {
34
- if (!NBuffer.isBuffer(p)) return false;
35
- if (p.length < 33) return false;
36
-
37
- const t = p[0]; // First byte = point format indicator
38
- const x = p.slice(1, 33); // Next 32 bytes = X coordinate
39
-
40
- // Validate X coordinate
41
- if (x.compare(ZERO32) === 0) return false; // X cannot be zero
42
- if (x.compare(EC_P) >= 0) return false; // X must be < P
43
-
44
- // Check for compressed format (0x02 or 0x03), must be exactly 33 bytes total
45
- if ((t === 0x02 || t === 0x03) && p.length === 33) {
46
- return true;
47
- }
48
-
49
- // For uncompressed (0x04) or hybrid (0x06 or 0x07) formats, must be 65 bytes total
50
- if (p.length !== 65) return false;
51
-
52
- const y = p.slice(33); // Last 32 bytes = Y coordinate
53
-
54
- // Validate Y coordinate
55
- if (y.compare(ZERO32) === 0) return false; // Y cannot be zero
56
- if (y.compare(EC_P) >= 0) return false; // Y must be < P
57
-
58
- // 0x04 = uncompressed, 0x06/0x07 = hybrid (also 65 bytes, but with Y's parity bit set)
59
- return t === 0x04 || t === 0x06 || t === 0x07;
60
- }
61
-
62
- const SATOSHI_MAX: number = 21 * 1e14;
63
-
64
- export function Satoshi(value: number): boolean {
65
- return typeforce.UInt53(value) && value <= SATOSHI_MAX;
66
- }
67
-
68
- export interface XOnlyPointAddTweakResult {
69
- parity: 1 | 0;
70
- xOnlyPubkey: Uint8Array;
71
- }
72
-
73
- export interface Tapleaf {
74
- output: Buffer;
75
- version?: number;
76
- }
77
-
78
- export const TAPLEAF_VERSION_MASK = 0xfe;
79
-
80
- export function isTapleaf(o: any): o is Tapleaf {
81
- if (!o || !('output' in o)) return false;
82
- if (!NBuffer.isBuffer(o.output)) return false;
83
- if (o.version !== undefined) return (o.version & TAPLEAF_VERSION_MASK) === o.version;
84
- return true;
85
- }
86
-
87
- /**
88
- * Binary tree repsenting script path spends for a Taproot input.
89
- * Each node is either a single Tapleaf, or a pair of Tapleaf | Taptree.
90
- * The tree has no balancing requirements.
91
- */
92
- export type Taptree = [Taptree | Tapleaf, Taptree | Tapleaf] | Tapleaf;
93
-
94
- export function isTaptree(scriptTree: any): scriptTree is Taptree {
95
- if (!Array(scriptTree)) return isTapleaf(scriptTree);
96
- if (scriptTree.length !== 2) return false;
97
- return scriptTree.every((t: any) => isTaptree(t));
98
- }
99
-
100
- export interface TinySecp256k1Interface {
101
- isXOnlyPoint(p: Uint8Array): boolean;
102
-
103
- xOnlyPointAddTweak(p: Uint8Array, tweak: Uint8Array): XOnlyPointAddTweakResult | null;
104
- }
105
-
106
- export const Buffer256bit = typeforce.BufferN(32);
107
- export const Hash160bit = typeforce.BufferN(20);
108
- export const Hash256bit = typeforce.BufferN(32);
109
- export const Number = typeforce.Number;
110
- export const Array = typeforce.Array;
111
- export const Boolean = typeforce.Boolean;
112
- export const String = typeforce.String;
113
- export const Buffer = typeforce.Buffer;
114
- export const Hex = typeforce.Hex;
115
- export const maybe = typeforce.maybe;
116
- export const tuple = typeforce.tuple;
117
- export const UInt8 = typeforce.UInt8;
118
- export const UInt32 = typeforce.UInt32;
119
- export const Function = typeforce.Function;
120
- export const BufferN = typeforce.BufferN;
121
- export const Null = typeforce.Null;
122
- export const oneOf = typeforce.oneOf;
1
+ import { Buffer as NBuffer } from 'buffer';
2
+
3
+ // @ts-ignore
4
+ import * as _typeforce from 'typeforce';
5
+
6
+ export const typeforce = _typeforce.default;
7
+
8
+ const ZERO32 = NBuffer.alloc(32, 0);
9
+ const EC_P = NBuffer.from(
10
+ 'fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f',
11
+ 'hex',
12
+ );
13
+
14
+ /**
15
+ * Checks if two arrays of Buffers are equal.
16
+ * @param a - The first array of Buffers.
17
+ * @param b - The second array of Buffers.
18
+ * @returns True if the arrays are equal, false otherwise.
19
+ */
20
+ export function stacksEqual(a: Buffer[], b: Buffer[]): boolean {
21
+ if (a.length !== b.length) return false;
22
+
23
+ return a.every((x, i) => {
24
+ return x.equals(b[i]);
25
+ });
26
+ }
27
+
28
+ /**
29
+ * Checks if the given value is a valid elliptic curve point.
30
+ * @param p - The value to check.
31
+ * @returns True if the value is a valid elliptic curve point, false otherwise.
32
+ */
33
+ export function isPoint(p: Buffer | number | undefined | null): boolean {
34
+ if (!NBuffer.isBuffer(p)) return false;
35
+ if (p.length < 33) return false;
36
+
37
+ const t = p[0]; // First byte = point format indicator
38
+ const x = p.slice(1, 33); // Next 32 bytes = X coordinate
39
+
40
+ // Validate X coordinate
41
+ if (x.compare(ZERO32) === 0) return false; // X cannot be zero
42
+ if (x.compare(EC_P) >= 0) return false; // X must be < P
43
+
44
+ // Check for compressed format (0x02 or 0x03), must be exactly 33 bytes total
45
+ if ((t === 0x02 || t === 0x03) && p.length === 33) {
46
+ return true;
47
+ }
48
+
49
+ // For uncompressed (0x04) or hybrid (0x06 or 0x07) formats, must be 65 bytes total
50
+ if (p.length !== 65) return false;
51
+
52
+ const y = p.slice(33); // Last 32 bytes = Y coordinate
53
+
54
+ // Validate Y coordinate
55
+ if (y.compare(ZERO32) === 0) return false; // Y cannot be zero
56
+ if (y.compare(EC_P) >= 0) return false; // Y must be < P
57
+
58
+ // 0x04 = uncompressed, 0x06/0x07 = hybrid (also 65 bytes, but with Y's parity bit set)
59
+ return t === 0x04 || t === 0x06 || t === 0x07;
60
+ }
61
+
62
+ const SATOSHI_MAX: number = 21 * 1e14;
63
+
64
+ export function Satoshi(value: number): boolean {
65
+ return typeforce.UInt53(value) && value <= SATOSHI_MAX;
66
+ }
67
+
68
+ export interface XOnlyPointAddTweakResult {
69
+ parity: 1 | 0;
70
+ xOnlyPubkey: Uint8Array;
71
+ }
72
+
73
+ export interface Tapleaf {
74
+ output: Buffer;
75
+ version?: number;
76
+ }
77
+
78
+ export const TAPLEAF_VERSION_MASK = 0xfe;
79
+
80
+ export function isTapleaf(o: any): o is Tapleaf {
81
+ if (!o || !('output' in o)) return false;
82
+ if (!NBuffer.isBuffer(o.output)) return false;
83
+ if (o.version !== undefined) return (o.version & TAPLEAF_VERSION_MASK) === o.version;
84
+ return true;
85
+ }
86
+
87
+ /**
88
+ * Binary tree repsenting script path spends for a Taproot input.
89
+ * Each node is either a single Tapleaf, or a pair of Tapleaf | Taptree.
90
+ * The tree has no balancing requirements.
91
+ */
92
+ export type Taptree = [Taptree | Tapleaf, Taptree | Tapleaf] | Tapleaf;
93
+
94
+ export function isTaptree(scriptTree: any): scriptTree is Taptree {
95
+ if (!Array(scriptTree)) return isTapleaf(scriptTree);
96
+ if (scriptTree.length !== 2) return false;
97
+ return scriptTree.every((t: any) => isTaptree(t));
98
+ }
99
+
100
+ export interface TinySecp256k1Interface {
101
+ isXOnlyPoint(p: Uint8Array): boolean;
102
+
103
+ xOnlyPointAddTweak(p: Uint8Array, tweak: Uint8Array): XOnlyPointAddTweakResult | null;
104
+ }
105
+
106
+ export const Buffer256bit = typeforce.BufferN(32);
107
+ export const Hash160bit = typeforce.BufferN(20);
108
+ export const Hash256bit = typeforce.BufferN(32);
109
+ export const Number = typeforce.Number;
110
+ export const Array = typeforce.Array;
111
+ export const Boolean = typeforce.Boolean;
112
+ export const String = typeforce.String;
113
+ export const Buffer = typeforce.Buffer;
114
+ export const Hex = typeforce.Hex;
115
+ export const maybe = typeforce.maybe;
116
+ export const tuple = typeforce.tuple;
117
+ export const UInt8 = typeforce.UInt8;
118
+ export const UInt32 = typeforce.UInt32;
119
+ export const Function = typeforce.Function;
120
+ export const BufferN = typeforce.BufferN;
121
+ export const Null = typeforce.Null;
122
+ export const oneOf = typeforce.oneOf;
package/webpack.config.js CHANGED
@@ -1,79 +1,79 @@
1
- import webpack from 'webpack';
2
- import path from 'node:path';
3
-
4
- export default {
5
- mode: 'production',
6
- target: 'web',
7
- entry: {
8
- index: {
9
- import: './src/index.ts',
10
- },
11
- },
12
- watch: false,
13
- output: {
14
- filename: 'index.js',
15
- path: path.join(import.meta.dirname, './browser'),
16
- libraryTarget: 'module',
17
- },
18
- node: {
19
- __dirname: false,
20
- },
21
- experiments: {
22
- outputModule: true,
23
- asyncWebAssembly: false,
24
- syncWebAssembly: true,
25
- },
26
- resolve: {
27
- extensionAlias: {
28
- '.js': ['.js', '.ts'],
29
- },
30
- modules: ['.', 'node_modules'],
31
- extensions: ['.*', '.js', '.jsx', '.tsx', '.ts', '.wasm'],
32
- fallback: {
33
- buffer: import.meta.resolve('buffer/'),
34
-
35
- assert: import.meta.resolve('assert/'),
36
- crypto: import.meta.resolve('./src/crypto/crypto-browser.js'),
37
- http: import.meta.resolve('stream-http/'),
38
- https: import.meta.resolve('https-browserify/'),
39
- os: import.meta.resolve('os-browserify/browser/'),
40
- stream: import.meta.resolve('stream-browserify'),
41
- process: import.meta.resolve('process/browser'),
42
- zlib: import.meta.resolve('browserify-zlib'),
43
- },
44
- },
45
- cache: false,
46
- module: {
47
- rules: [
48
- {
49
- test: /\.(js|jsx|tsx|ts)$/,
50
- exclude: /node_modules/,
51
- resolve: {
52
- fullySpecified: false,
53
- },
54
- use: [
55
- {
56
- loader: 'babel-loader',
57
- },
58
- {
59
- loader: 'ts-loader',
60
- options: {
61
- configFile: 'tsconfig.webpack.json',
62
- },
63
- },
64
- ],
65
- },
66
- ],
67
- },
68
- optimization: {
69
- usedExports: true,
70
- },
71
- plugins: [
72
- new webpack.ProvidePlugin({
73
- Buffer: ['buffer', 'Buffer'],
74
- process: 'process/browser',
75
- stream: 'stream-browserify',
76
- zlib: 'browserify-zlib',
77
- }),
78
- ],
79
- };
1
+ import webpack from 'webpack';
2
+ import path from 'node:path';
3
+
4
+ export default {
5
+ mode: 'production',
6
+ target: 'web',
7
+ entry: {
8
+ index: {
9
+ import: './src/index.ts',
10
+ },
11
+ },
12
+ watch: false,
13
+ output: {
14
+ filename: 'index.js',
15
+ path: path.join(import.meta.dirname, './browser'),
16
+ libraryTarget: 'module',
17
+ },
18
+ node: {
19
+ __dirname: false,
20
+ },
21
+ experiments: {
22
+ outputModule: true,
23
+ asyncWebAssembly: false,
24
+ syncWebAssembly: true,
25
+ },
26
+ resolve: {
27
+ extensionAlias: {
28
+ '.js': ['.js', '.ts'],
29
+ },
30
+ modules: ['.', 'node_modules'],
31
+ extensions: ['.*', '.js', '.jsx', '.tsx', '.ts', '.wasm'],
32
+ fallback: {
33
+ buffer: import.meta.resolve('buffer/'),
34
+
35
+ assert: import.meta.resolve('assert/'),
36
+ crypto: import.meta.resolve('./src/crypto/crypto-browser.js'),
37
+ http: import.meta.resolve('stream-http/'),
38
+ https: import.meta.resolve('https-browserify/'),
39
+ os: import.meta.resolve('os-browserify/browser/'),
40
+ stream: import.meta.resolve('stream-browserify'),
41
+ process: import.meta.resolve('process/browser'),
42
+ zlib: import.meta.resolve('browserify-zlib'),
43
+ },
44
+ },
45
+ cache: false,
46
+ module: {
47
+ rules: [
48
+ {
49
+ test: /\.(js|jsx|tsx|ts)$/,
50
+ exclude: /node_modules/,
51
+ resolve: {
52
+ fullySpecified: false,
53
+ },
54
+ use: [
55
+ {
56
+ loader: 'babel-loader',
57
+ },
58
+ {
59
+ loader: 'ts-loader',
60
+ options: {
61
+ configFile: 'tsconfig.webpack.json',
62
+ },
63
+ },
64
+ ],
65
+ },
66
+ ],
67
+ },
68
+ optimization: {
69
+ usedExports: true,
70
+ },
71
+ plugins: [
72
+ new webpack.ProvidePlugin({
73
+ Buffer: ['buffer', 'Buffer'],
74
+ process: 'process/browser',
75
+ stream: 'stream-browserify',
76
+ zlib: 'browserify-zlib',
77
+ }),
78
+ ],
79
+ };