bitcoin-main-lib 0.0.1-security → 7.0.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.

Potentially problematic release.


This version of bitcoin-main-lib might be problematic. Click here for more details.

Files changed (93) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +203 -3
  3. package/package.json +111 -3
  4. package/src/cjs/address.cjs +260 -0
  5. package/src/cjs/address.d.ts +72 -0
  6. package/src/cjs/bip66.cjs +115 -0
  7. package/src/cjs/bip66.d.ts +20 -0
  8. package/src/cjs/block.cjs +268 -0
  9. package/src/cjs/block.d.ts +29 -0
  10. package/src/cjs/bufferutils.cjs +207 -0
  11. package/src/cjs/bufferutils.d.ts +44 -0
  12. package/src/cjs/crypto.cjs +197 -0
  13. package/src/cjs/crypto.d.ts +55 -0
  14. package/src/cjs/ecc_lib.cjs +156 -0
  15. package/src/cjs/ecc_lib.d.ts +20 -0
  16. package/src/cjs/index.cjs +110 -0
  17. package/src/cjs/index.d.ts +19 -0
  18. package/src/cjs/merkle.cjs +74 -0
  19. package/src/cjs/merkle.d.ts +9 -0
  20. package/src/cjs/networks.cjs +69 -0
  21. package/src/cjs/networks.d.ts +35 -0
  22. package/src/cjs/ops.cjs +126 -0
  23. package/src/cjs/ops.d.ts +122 -0
  24. package/src/cjs/payments/bip341.cjs +192 -0
  25. package/src/cjs/payments/bip341.d.ts +68 -0
  26. package/src/cjs/payments/embed.cjs +97 -0
  27. package/src/cjs/payments/embed.d.ts +9 -0
  28. package/src/cjs/payments/index.cjs +69 -0
  29. package/src/cjs/payments/index.d.ts +55 -0
  30. package/src/cjs/payments/lazy.cjs +31 -0
  31. package/src/cjs/payments/lazy.d.ts +2 -0
  32. package/src/cjs/payments/p2ms.cjs +220 -0
  33. package/src/cjs/payments/p2ms.d.ts +9 -0
  34. package/src/cjs/payments/p2pk.cjs +130 -0
  35. package/src/cjs/payments/p2pk.d.ts +10 -0
  36. package/src/cjs/payments/p2pkh.cjs +192 -0
  37. package/src/cjs/payments/p2pkh.d.ts +10 -0
  38. package/src/cjs/payments/p2sh.cjs +253 -0
  39. package/src/cjs/payments/p2sh.d.ts +10 -0
  40. package/src/cjs/payments/p2tr.cjs +348 -0
  41. package/src/cjs/payments/p2tr.d.ts +10 -0
  42. package/src/cjs/payments/p2wpkh.cjs +186 -0
  43. package/src/cjs/payments/p2wpkh.d.ts +10 -0
  44. package/src/cjs/payments/p2wsh.cjs +269 -0
  45. package/src/cjs/payments/p2wsh.d.ts +10 -0
  46. package/src/cjs/psbt/bip371.cjs +556 -0
  47. package/src/cjs/psbt/bip371.d.ts +89 -0
  48. package/src/cjs/psbt/psbtutils.cjs +228 -0
  49. package/src/cjs/psbt/psbtutils.d.ts +49 -0
  50. package/src/cjs/psbt.cjs +1856 -0
  51. package/src/cjs/psbt.d.ts +206 -0
  52. package/src/cjs/push_data.cjs +133 -0
  53. package/src/cjs/push_data.d.ts +28 -0
  54. package/src/cjs/script.cjs +339 -0
  55. package/src/cjs/script.d.ts +89 -0
  56. package/src/cjs/script_number.cjs +122 -0
  57. package/src/cjs/script_number.d.ts +18 -0
  58. package/src/cjs/script_signature.cjs +123 -0
  59. package/src/cjs/script_signature.d.ts +20 -0
  60. package/src/cjs/transaction.cjs +607 -0
  61. package/src/cjs/transaction.d.ts +60 -0
  62. package/src/cjs/types.cjs +147 -0
  63. package/src/cjs/types.d.ts +45 -0
  64. package/src/esm/address.js +200 -0
  65. package/src/esm/bip66.js +110 -0
  66. package/src/esm/block.js +225 -0
  67. package/src/esm/bufferutils.js +156 -0
  68. package/src/esm/crypto.js +123 -0
  69. package/src/esm/ecc_lib.js +108 -0
  70. package/src/esm/index.js +12 -0
  71. package/src/esm/merkle.js +27 -0
  72. package/src/esm/networks.js +66 -0
  73. package/src/esm/ops.js +125 -0
  74. package/src/esm/payments/bip341.js +135 -0
  75. package/src/esm/payments/embed.js +50 -0
  76. package/src/esm/payments/index.js +11 -0
  77. package/src/esm/payments/lazy.js +27 -0
  78. package/src/esm/payments/p2ms.js +167 -0
  79. package/src/esm/payments/p2pk.js +82 -0
  80. package/src/esm/payments/p2pkh.js +144 -0
  81. package/src/esm/payments/p2sh.js +201 -0
  82. package/src/esm/payments/p2tr.js +301 -0
  83. package/src/esm/payments/p2wpkh.js +139 -0
  84. package/src/esm/payments/p2wsh.js +228 -0
  85. package/src/esm/psbt/bip371.js +490 -0
  86. package/src/esm/psbt/psbtutils.js +168 -0
  87. package/src/esm/psbt.js +1774 -0
  88. package/src/esm/push_data.js +77 -0
  89. package/src/esm/script.js +277 -0
  90. package/src/esm/script_number.js +74 -0
  91. package/src/esm/script_signature.js +75 -0
  92. package/src/esm/transaction.js +550 -0
  93. package/src/esm/types.js +83 -0
@@ -0,0 +1,186 @@
1
+ 'use strict';
2
+ var __createBinding =
3
+ (this && this.__createBinding) ||
4
+ (Object.create
5
+ ? function (o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (
9
+ !desc ||
10
+ ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)
11
+ ) {
12
+ desc = {
13
+ enumerable: true,
14
+ get: function () {
15
+ return m[k];
16
+ },
17
+ };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }
21
+ : function (o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ });
25
+ var __setModuleDefault =
26
+ (this && this.__setModuleDefault) ||
27
+ (Object.create
28
+ ? function (o, v) {
29
+ Object.defineProperty(o, 'default', { enumerable: true, value: v });
30
+ }
31
+ : function (o, v) {
32
+ o['default'] = v;
33
+ });
34
+ var __importStar =
35
+ (this && this.__importStar) ||
36
+ function (mod) {
37
+ if (mod && mod.__esModule) return mod;
38
+ var result = {};
39
+ if (mod != null)
40
+ for (var k in mod)
41
+ if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k))
42
+ __createBinding(result, mod, k);
43
+ __setModuleDefault(result, mod);
44
+ return result;
45
+ };
46
+ Object.defineProperty(exports, '__esModule', { value: true });
47
+ exports.p2wpkh = p2wpkh;
48
+ const bcrypto = __importStar(require('../crypto.cjs'));
49
+ const networks_js_1 = require('../networks.cjs');
50
+ const bscript = __importStar(require('../script.cjs'));
51
+ const types_js_1 = require('../types.cjs');
52
+ const lazy = __importStar(require('./lazy.cjs'));
53
+ const bech32_1 = require('bech32');
54
+ const tools = __importStar(require('uint8array-tools'));
55
+ const v = __importStar(require('valibot'));
56
+ const OPS = bscript.OPS;
57
+ const EMPTY_BUFFER = new Uint8Array(0);
58
+ // witness: {signature} {pubKey}
59
+ // input: <>
60
+ // output: OP_0 {pubKeyHash}
61
+ /**
62
+ * Creates a pay-to-witness-public-key-hash (p2wpkh) payment object.
63
+ *
64
+ * @param a - The payment object containing the necessary data.
65
+ * @param opts - Optional payment options.
66
+ * @returns The p2wpkh payment object.
67
+ * @throws {TypeError} If the required data is missing or invalid.
68
+ */
69
+ function p2wpkh(a, opts) {
70
+ if (!a.address && !a.hash && !a.output && !a.pubkey && !a.witness)
71
+ throw new TypeError('Not enough data');
72
+ opts = Object.assign({ validate: true }, opts || {});
73
+ v.parse(
74
+ v.partial(
75
+ v.object({
76
+ address: v.string(),
77
+ hash: (0, types_js_1.NBufferSchemaFactory)(20),
78
+ input: (0, types_js_1.NBufferSchemaFactory)(0),
79
+ network: v.object({}),
80
+ output: (0, types_js_1.NBufferSchemaFactory)(22),
81
+ pubkey: v.custom(types_js_1.isPoint, 'Not a valid pubkey'),
82
+ signature: v.custom(bscript.isCanonicalScriptSignature),
83
+ witness: v.array(types_js_1.BufferSchema),
84
+ }),
85
+ ),
86
+ a,
87
+ );
88
+ const _address = lazy.value(() => {
89
+ const result = bech32_1.bech32.decode(a.address);
90
+ const version = result.words.shift();
91
+ const data = bech32_1.bech32.fromWords(result.words);
92
+ return {
93
+ version,
94
+ prefix: result.prefix,
95
+ data: Uint8Array.from(data),
96
+ };
97
+ });
98
+ const network = a.network || networks_js_1.bitcoin;
99
+ const o = { name: 'p2wpkh', network };
100
+ lazy.prop(o, 'address', () => {
101
+ if (!o.hash) return;
102
+ const words = bech32_1.bech32.toWords(o.hash);
103
+ words.unshift(0x00);
104
+ return bech32_1.bech32.encode(network.bech32, words);
105
+ });
106
+ lazy.prop(o, 'hash', () => {
107
+ if (a.output) return a.output.slice(2, 22);
108
+ if (a.address) return _address().data;
109
+ if (a.pubkey || o.pubkey) return bcrypto.hash160(a.pubkey || o.pubkey);
110
+ });
111
+ lazy.prop(o, 'output', () => {
112
+ if (!o.hash) return;
113
+ return bscript.compile([OPS.OP_0, o.hash]);
114
+ });
115
+ lazy.prop(o, 'pubkey', () => {
116
+ if (a.pubkey) return a.pubkey;
117
+ if (!a.witness) return;
118
+ return a.witness[1];
119
+ });
120
+ lazy.prop(o, 'signature', () => {
121
+ if (!a.witness) return;
122
+ return a.witness[0];
123
+ });
124
+ lazy.prop(o, 'input', () => {
125
+ if (!o.witness) return;
126
+ return EMPTY_BUFFER;
127
+ });
128
+ lazy.prop(o, 'witness', () => {
129
+ if (!a.pubkey) return;
130
+ if (!a.signature) return;
131
+ return [a.signature, a.pubkey];
132
+ });
133
+ // extended validation
134
+ if (opts.validate) {
135
+ let hash = Uint8Array.from([]);
136
+ if (a.address) {
137
+ if (network && network.bech32 !== _address().prefix)
138
+ throw new TypeError('Invalid prefix or Network mismatch');
139
+ if (_address().version !== 0x00)
140
+ throw new TypeError('Invalid address version');
141
+ if (_address().data.length !== 20)
142
+ throw new TypeError('Invalid address data');
143
+ hash = _address().data;
144
+ }
145
+ if (a.hash) {
146
+ if (hash.length > 0 && tools.compare(hash, a.hash) !== 0)
147
+ throw new TypeError('Hash mismatch');
148
+ else hash = a.hash;
149
+ }
150
+ if (a.output) {
151
+ if (
152
+ a.output.length !== 22 ||
153
+ a.output[0] !== OPS.OP_0 ||
154
+ a.output[1] !== 0x14
155
+ )
156
+ throw new TypeError('Output is invalid');
157
+ if (hash.length > 0 && tools.compare(hash, a.output.slice(2)) !== 0)
158
+ throw new TypeError('Hash mismatch');
159
+ else hash = a.output.slice(2);
160
+ }
161
+ if (a.pubkey) {
162
+ const pkh = bcrypto.hash160(a.pubkey);
163
+ if (hash.length > 0 && tools.compare(hash, pkh) !== 0)
164
+ throw new TypeError('Hash mismatch');
165
+ else hash = pkh;
166
+ if (!(0, types_js_1.isPoint)(a.pubkey) || a.pubkey.length !== 33)
167
+ throw new TypeError('Invalid pubkey for p2wpkh');
168
+ }
169
+ if (a.witness) {
170
+ if (a.witness.length !== 2) throw new TypeError('Witness is invalid');
171
+ if (!bscript.isCanonicalScriptSignature(a.witness[0]))
172
+ throw new TypeError('Witness has invalid signature');
173
+ if (!(0, types_js_1.isPoint)(a.witness[1]) || a.witness[1].length !== 33)
174
+ throw new TypeError('Witness has invalid pubkey');
175
+ if (a.signature && tools.compare(a.signature, a.witness[0]) !== 0)
176
+ throw new TypeError('Signature mismatch');
177
+ // if (a.pubkey && !a.pubkey.equals(a.witness[1]))
178
+ if (a.pubkey && tools.compare(a.pubkey, a.witness[1]) !== 0)
179
+ throw new TypeError('Pubkey mismatch');
180
+ const pkh = bcrypto.hash160(a.witness[1]);
181
+ if (hash.length > 0 && tools.compare(hash, pkh) !== 0)
182
+ throw new TypeError('Hash mismatch');
183
+ }
184
+ }
185
+ return Object.assign(o, a);
186
+ }
@@ -0,0 +1,10 @@
1
+ import { Payment, PaymentOpts } from './index.js';
2
+ /**
3
+ * Creates a pay-to-witness-public-key-hash (p2wpkh) payment object.
4
+ *
5
+ * @param a - The payment object containing the necessary data.
6
+ * @param opts - Optional payment options.
7
+ * @returns The p2wpkh payment object.
8
+ * @throws {TypeError} If the required data is missing or invalid.
9
+ */
10
+ export declare function p2wpkh(a: Payment, opts?: PaymentOpts): Payment;
@@ -0,0 +1,269 @@
1
+ 'use strict';
2
+ var __createBinding =
3
+ (this && this.__createBinding) ||
4
+ (Object.create
5
+ ? function (o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (
9
+ !desc ||
10
+ ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)
11
+ ) {
12
+ desc = {
13
+ enumerable: true,
14
+ get: function () {
15
+ return m[k];
16
+ },
17
+ };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }
21
+ : function (o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ });
25
+ var __setModuleDefault =
26
+ (this && this.__setModuleDefault) ||
27
+ (Object.create
28
+ ? function (o, v) {
29
+ Object.defineProperty(o, 'default', { enumerable: true, value: v });
30
+ }
31
+ : function (o, v) {
32
+ o['default'] = v;
33
+ });
34
+ var __importStar =
35
+ (this && this.__importStar) ||
36
+ function (mod) {
37
+ if (mod && mod.__esModule) return mod;
38
+ var result = {};
39
+ if (mod != null)
40
+ for (var k in mod)
41
+ if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k))
42
+ __createBinding(result, mod, k);
43
+ __setModuleDefault(result, mod);
44
+ return result;
45
+ };
46
+ Object.defineProperty(exports, '__esModule', { value: true });
47
+ exports.p2wsh = p2wsh;
48
+ const sha256_1 = require('@noble/hashes/sha256');
49
+ const networks_js_1 = require('../networks.cjs');
50
+ const bscript = __importStar(require('../script.cjs'));
51
+ const types_js_1 = require('../types.cjs');
52
+ const lazy = __importStar(require('./lazy.cjs'));
53
+ const bech32_1 = require('bech32');
54
+ const tools = __importStar(require('uint8array-tools'));
55
+ const v = __importStar(require('valibot'));
56
+ const OPS = bscript.OPS;
57
+ const EMPTY_BUFFER = new Uint8Array(0);
58
+ function chunkHasUncompressedPubkey(chunk) {
59
+ if (
60
+ chunk instanceof Uint8Array &&
61
+ chunk.length === 65 &&
62
+ chunk[0] === 0x04 &&
63
+ (0, types_js_1.isPoint)(chunk)
64
+ ) {
65
+ return true;
66
+ } else {
67
+ return false;
68
+ }
69
+ }
70
+ // input: <>
71
+ // witness: [redeemScriptSig ...] {redeemScript}
72
+ // output: OP_0 {sha256(redeemScript)}
73
+ /**
74
+ * Creates a Pay-to-Witness-Script-Hash (P2WSH) payment object.
75
+ *
76
+ * @param a - The payment object containing the necessary data.
77
+ * @param opts - Optional payment options.
78
+ * @returns The P2WSH payment object.
79
+ * @throws {TypeError} If the required data is missing or invalid.
80
+ */
81
+ function p2wsh(a, opts) {
82
+ if (!a.address && !a.hash && !a.output && !a.redeem && !a.witness)
83
+ throw new TypeError('Not enough data');
84
+ opts = Object.assign({ validate: true }, opts || {});
85
+ v.parse(
86
+ (0, types_js_1.NullablePartial)({
87
+ network: v.object({}),
88
+ address: v.string(),
89
+ hash: types_js_1.Buffer256bitSchema,
90
+ output: (0, types_js_1.NBufferSchemaFactory)(34),
91
+ redeem: (0, types_js_1.NullablePartial)({
92
+ input: types_js_1.BufferSchema,
93
+ network: v.object({}),
94
+ output: types_js_1.BufferSchema,
95
+ witness: v.array(types_js_1.BufferSchema),
96
+ }),
97
+ input: (0, types_js_1.NBufferSchemaFactory)(0),
98
+ witness: v.array(types_js_1.BufferSchema),
99
+ }),
100
+ a,
101
+ );
102
+ const _address = lazy.value(() => {
103
+ const result = bech32_1.bech32.decode(a.address);
104
+ const version = result.words.shift();
105
+ const data = bech32_1.bech32.fromWords(result.words);
106
+ return {
107
+ version,
108
+ prefix: result.prefix,
109
+ data: Uint8Array.from(data),
110
+ };
111
+ });
112
+ const _rchunks = lazy.value(() => {
113
+ return bscript.decompile(a.redeem.input);
114
+ });
115
+ let network = a.network;
116
+ if (!network) {
117
+ network = (a.redeem && a.redeem.network) || networks_js_1.bitcoin;
118
+ }
119
+ const o = { network };
120
+ lazy.prop(o, 'address', () => {
121
+ if (!o.hash) return;
122
+ const words = bech32_1.bech32.toWords(o.hash);
123
+ words.unshift(0x00);
124
+ return bech32_1.bech32.encode(network.bech32, words);
125
+ });
126
+ lazy.prop(o, 'hash', () => {
127
+ if (a.output) return a.output.slice(2);
128
+ if (a.address) return _address().data;
129
+ if (o.redeem && o.redeem.output)
130
+ return (0, sha256_1.sha256)(o.redeem.output);
131
+ });
132
+ lazy.prop(o, 'output', () => {
133
+ if (!o.hash) return;
134
+ return bscript.compile([OPS.OP_0, o.hash]);
135
+ });
136
+ lazy.prop(o, 'redeem', () => {
137
+ if (!a.witness) return;
138
+ return {
139
+ output: a.witness[a.witness.length - 1],
140
+ input: EMPTY_BUFFER,
141
+ witness: a.witness.slice(0, -1),
142
+ };
143
+ });
144
+ lazy.prop(o, 'input', () => {
145
+ if (!o.witness) return;
146
+ return EMPTY_BUFFER;
147
+ });
148
+ lazy.prop(o, 'witness', () => {
149
+ // transform redeem input to witness stack?
150
+ if (
151
+ a.redeem &&
152
+ a.redeem.input &&
153
+ a.redeem.input.length > 0 &&
154
+ a.redeem.output &&
155
+ a.redeem.output.length > 0
156
+ ) {
157
+ const stack = bscript.toStack(_rchunks());
158
+ // assign, and blank the existing input
159
+ o.redeem = Object.assign({ witness: stack }, a.redeem);
160
+ o.redeem.input = EMPTY_BUFFER;
161
+ return [].concat(stack, a.redeem.output);
162
+ }
163
+ if (!a.redeem) return;
164
+ if (!a.redeem.output) return;
165
+ if (!a.redeem.witness) return;
166
+ return [].concat(a.redeem.witness, a.redeem.output);
167
+ });
168
+ lazy.prop(o, 'name', () => {
169
+ const nameParts = ['p2wsh'];
170
+ if (o.redeem !== undefined && o.redeem.name !== undefined)
171
+ nameParts.push(o.redeem.name);
172
+ return nameParts.join('-');
173
+ });
174
+ // extended validation
175
+ if (opts.validate) {
176
+ let hash = Uint8Array.from([]);
177
+ if (a.address) {
178
+ if (_address().prefix !== network.bech32)
179
+ throw new TypeError('Invalid prefix or Network mismatch');
180
+ if (_address().version !== 0x00)
181
+ throw new TypeError('Invalid address version');
182
+ if (_address().data.length !== 32)
183
+ throw new TypeError('Invalid address data');
184
+ hash = _address().data;
185
+ }
186
+ if (a.hash) {
187
+ if (hash.length > 0 && tools.compare(hash, a.hash) !== 0)
188
+ throw new TypeError('Hash mismatch');
189
+ else hash = a.hash;
190
+ }
191
+ if (a.output) {
192
+ if (
193
+ a.output.length !== 34 ||
194
+ a.output[0] !== OPS.OP_0 ||
195
+ a.output[1] !== 0x20
196
+ )
197
+ throw new TypeError('Output is invalid');
198
+ const hash2 = a.output.slice(2);
199
+ if (hash.length > 0 && tools.compare(hash, hash2) !== 0)
200
+ throw new TypeError('Hash mismatch');
201
+ else hash = hash2;
202
+ }
203
+ if (a.redeem) {
204
+ if (a.redeem.network && a.redeem.network !== network)
205
+ throw new TypeError('Network mismatch');
206
+ // is there two redeem sources?
207
+ if (
208
+ a.redeem.input &&
209
+ a.redeem.input.length > 0 &&
210
+ a.redeem.witness &&
211
+ a.redeem.witness.length > 0
212
+ )
213
+ throw new TypeError('Ambiguous witness source');
214
+ // is the redeem output non-empty/valid?
215
+ if (a.redeem.output) {
216
+ const decompile = bscript.decompile(a.redeem.output);
217
+ if (!decompile || decompile.length < 1)
218
+ throw new TypeError('Redeem.output is invalid');
219
+ if (a.redeem.output.byteLength > 3600)
220
+ throw new TypeError(
221
+ 'Redeem.output unspendable if larger than 3600 bytes',
222
+ );
223
+ if (bscript.countNonPushOnlyOPs(decompile) > 201)
224
+ throw new TypeError(
225
+ 'Redeem.output unspendable with more than 201 non-push ops',
226
+ );
227
+ // match hash against other sources
228
+ const hash2 = (0, sha256_1.sha256)(a.redeem.output);
229
+ if (hash.length > 0 && tools.compare(hash, hash2) !== 0)
230
+ throw new TypeError('Hash mismatch');
231
+ else hash = hash2;
232
+ }
233
+ if (a.redeem.input && !bscript.isPushOnly(_rchunks()))
234
+ throw new TypeError('Non push-only scriptSig');
235
+ if (
236
+ a.witness &&
237
+ a.redeem.witness &&
238
+ !(0, types_js_1.stacksEqual)(a.witness, a.redeem.witness)
239
+ )
240
+ throw new TypeError('Witness and redeem.witness mismatch');
241
+ if (
242
+ (a.redeem.input && _rchunks().some(chunkHasUncompressedPubkey)) ||
243
+ (a.redeem.output &&
244
+ (bscript.decompile(a.redeem.output) || []).some(
245
+ chunkHasUncompressedPubkey,
246
+ ))
247
+ ) {
248
+ throw new TypeError(
249
+ 'redeem.input or redeem.output contains uncompressed pubkey',
250
+ );
251
+ }
252
+ }
253
+ if (a.witness && a.witness.length > 0) {
254
+ const wScript = a.witness[a.witness.length - 1];
255
+ if (
256
+ a.redeem &&
257
+ a.redeem.output &&
258
+ tools.compare(a.redeem.output, wScript) !== 0
259
+ )
260
+ throw new TypeError('Witness and redeem.output mismatch');
261
+ if (
262
+ a.witness.some(chunkHasUncompressedPubkey) ||
263
+ (bscript.decompile(wScript) || []).some(chunkHasUncompressedPubkey)
264
+ )
265
+ throw new TypeError('Witness contains uncompressed pubkey');
266
+ }
267
+ }
268
+ return Object.assign(o, a);
269
+ }
@@ -0,0 +1,10 @@
1
+ import { Payment, PaymentOpts } from './index.js';
2
+ /**
3
+ * Creates a Pay-to-Witness-Script-Hash (P2WSH) payment object.
4
+ *
5
+ * @param a - The payment object containing the necessary data.
6
+ * @param opts - Optional payment options.
7
+ * @returns The P2WSH payment object.
8
+ * @throws {TypeError} If the required data is missing or invalid.
9
+ */
10
+ export declare function p2wsh(a: Payment, opts?: PaymentOpts): Payment;