@btc-vision/bitcoin 6.5.4 → 6.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AUDIT/README.md +9 -0
- package/SECURITY.md +27 -0
- package/browser/chunks/{payments-Ngcm87h_.js → payments-B1wlSccx.js} +171 -173
- package/browser/chunks/{psbt-CcM4rw3q.js → psbt-BCNk7JUx.js} +807 -791
- package/browser/index.js +4 -4
- package/build/payments/p2tr.js +0 -4
- package/build/pubkey.js +2 -2
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -18
- package/src/payments/p2tr.ts +4 -3
- package/src/pubkey.ts +3 -3
- package/test/address.spec.ts +5 -5
- package/test/payments.spec.ts +4 -4
- package/vitest.config.integration.ts +9 -0
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { b as v, d as g, f as
|
|
2
|
-
import { o as _, c as l, i as H, d as m, b as
|
|
1
|
+
import { b as v, d as g, f as ie, i as L, a as D } from "./psbt-BCNk7JUx.js";
|
|
2
|
+
import { o as _, c as l, i as H, d as m, b as oe, e as fe, f as me } from "./script-DyPItFEl.js";
|
|
3
3
|
import { t as r, d as P, s as j, b as we, e as le, f as ye, i as be, T as $ } from "./utils-DNZi-T5W.js";
|
|
4
|
-
import { a as k, B as c, h as T, t as
|
|
4
|
+
import { a as k, B as c, h as T, t as X, s as Y } from "./crypto-BhCpKpek.js";
|
|
5
5
|
var E = /* @__PURE__ */ ((e) => (e.P2PK = "p2pk", e.P2PKH = "p2pkh", e.P2SH = "p2sh", e.P2MS = "p2ms", e.P2WPKH = "p2wpkh", e.P2WSH = "p2wsh", e.P2TR = "p2tr", e.P2OP = "p2op", e.Embed = "embed", e.ScriptRedeem = "scriptRedeem", e))(E || {});
|
|
6
6
|
function p(e, o, f) {
|
|
7
7
|
Object.defineProperty(e, o, {
|
|
8
8
|
configurable: !0,
|
|
9
9
|
enumerable: !0,
|
|
10
10
|
get() {
|
|
11
|
-
const
|
|
12
|
-
return this[o] =
|
|
11
|
+
const i = f.call(this);
|
|
12
|
+
return this[o] = i, i;
|
|
13
13
|
},
|
|
14
|
-
set(
|
|
14
|
+
set(i) {
|
|
15
15
|
Object.defineProperty(this, o, {
|
|
16
16
|
configurable: !0,
|
|
17
17
|
enumerable: !0,
|
|
18
|
-
value:
|
|
18
|
+
value: i,
|
|
19
19
|
writable: !0
|
|
20
20
|
});
|
|
21
21
|
}
|
|
@@ -25,7 +25,7 @@ function y(e) {
|
|
|
25
25
|
let o;
|
|
26
26
|
return () => (o !== void 0 || (o = e()), o);
|
|
27
27
|
}
|
|
28
|
-
const
|
|
28
|
+
const Q = _, z = 16, Z = 2, J = 40;
|
|
29
29
|
function ge(e, o) {
|
|
30
30
|
if (!e.address && !e.output && !e.program && (typeof e.deploymentVersion > "u" || !e.hash160))
|
|
31
31
|
throw new TypeError("At least one of address, output or program must be provided");
|
|
@@ -47,17 +47,17 @@ function ge(e, o) {
|
|
|
47
47
|
throw new TypeError("deploymentVersion must fit in one byte");
|
|
48
48
|
return c.concat([c.of(e.deploymentVersion), e.hash160]);
|
|
49
49
|
}
|
|
50
|
-
},
|
|
50
|
+
}, i = y(() => ie(e.address)), s = e.network || v, u = {
|
|
51
51
|
name: E.P2OP,
|
|
52
52
|
network: s,
|
|
53
53
|
deploymentVersion: 0
|
|
54
54
|
};
|
|
55
|
-
if (p(
|
|
55
|
+
if (p(u, "program", () => {
|
|
56
56
|
if (e.program) return e.program;
|
|
57
57
|
const n = f();
|
|
58
58
|
if (n) return n;
|
|
59
59
|
if (e.output) {
|
|
60
|
-
if (e.output[0] !==
|
|
60
|
+
if (e.output[0] !== Q.OP_16) throw new TypeError("Invalid P2OP script");
|
|
61
61
|
let t = 1, h;
|
|
62
62
|
if (e.output[1] < 76)
|
|
63
63
|
h = e.output[1], t = 2;
|
|
@@ -68,31 +68,31 @@ function ge(e, o) {
|
|
|
68
68
|
return e.output.subarray(t, t + h);
|
|
69
69
|
}
|
|
70
70
|
if (e.address)
|
|
71
|
-
return
|
|
72
|
-
}), p(
|
|
73
|
-
if (
|
|
74
|
-
return
|
|
75
|
-
}), p(
|
|
76
|
-
if (
|
|
77
|
-
return
|
|
78
|
-
}), p(
|
|
79
|
-
if (
|
|
80
|
-
return l([
|
|
81
|
-
}), p(
|
|
82
|
-
if (!
|
|
71
|
+
return i().data;
|
|
72
|
+
}), p(u, "deploymentVersion", () => {
|
|
73
|
+
if (u.program)
|
|
74
|
+
return u.program[0];
|
|
75
|
+
}), p(u, "hash160", () => {
|
|
76
|
+
if (u.program)
|
|
77
|
+
return u.program.subarray(1);
|
|
78
|
+
}), p(u, "output", () => {
|
|
79
|
+
if (u.program)
|
|
80
|
+
return l([Q.OP_16, u.program]);
|
|
81
|
+
}), p(u, "address", () => {
|
|
82
|
+
if (!u.program) return;
|
|
83
83
|
if (!s.bech32Opnet)
|
|
84
84
|
throw new TypeError("Network does not support opnet");
|
|
85
|
-
const n = g.bech32m.toWords(
|
|
86
|
-
return n.unshift(
|
|
85
|
+
const n = g.bech32m.toWords(u.program);
|
|
86
|
+
return n.unshift(z), g.bech32m.encode(s.bech32Opnet, n);
|
|
87
87
|
}), o.validate) {
|
|
88
88
|
let n = k.alloc(0);
|
|
89
89
|
if (e.address) {
|
|
90
|
-
const t =
|
|
90
|
+
const t = i();
|
|
91
91
|
if (s.bech32Opnet !== t.prefix)
|
|
92
92
|
throw new TypeError("Invalid prefix or network mismatch");
|
|
93
|
-
if (t.version !==
|
|
93
|
+
if (t.version !== z)
|
|
94
94
|
throw new TypeError("Invalid witness version for p2op");
|
|
95
|
-
if (t.data.length <
|
|
95
|
+
if (t.data.length < Z || t.data.length > J)
|
|
96
96
|
throw new TypeError("Invalid witness program length");
|
|
97
97
|
n = t.data;
|
|
98
98
|
}
|
|
@@ -101,19 +101,19 @@ function ge(e, o) {
|
|
|
101
101
|
n = e.program;
|
|
102
102
|
}
|
|
103
103
|
if (!n.length && e.deploymentVersion !== void 0 && e.hash160 && (n = f()), e.output) {
|
|
104
|
-
const t =
|
|
104
|
+
const t = u.program;
|
|
105
105
|
if (n.length && !n.equals(t))
|
|
106
106
|
throw new TypeError("Program mismatch (output vs other source)");
|
|
107
107
|
n = t;
|
|
108
108
|
}
|
|
109
|
-
if (n.length <
|
|
109
|
+
if (n.length < Z || n.length > J)
|
|
110
110
|
throw new TypeError(`Witness program must be 2–40 bytes. Was ${n.length} bytes`);
|
|
111
111
|
if (e.deploymentVersion !== void 0 && e.deploymentVersion !== n[0])
|
|
112
112
|
throw new TypeError("deploymentVersion mismatch");
|
|
113
113
|
if (e.hash160 && !e.hash160.equals(n.subarray(1)))
|
|
114
114
|
throw new TypeError("hash160 mismatch");
|
|
115
115
|
}
|
|
116
|
-
return Object.assign(
|
|
116
|
+
return Object.assign(u, e);
|
|
117
117
|
}
|
|
118
118
|
const S = _;
|
|
119
119
|
function ke(e, o) {
|
|
@@ -134,44 +134,44 @@ function ke(e, o) {
|
|
|
134
134
|
const f = y(() => {
|
|
135
135
|
const n = c.from(L.decode(e.address)), t = n.readUInt8(0), h = n.subarray(1);
|
|
136
136
|
return { version: t, hash: h };
|
|
137
|
-
}),
|
|
137
|
+
}), i = y(() => m(e.input)), s = e.network || v, u = {
|
|
138
138
|
name: E.P2PKH,
|
|
139
139
|
network: s,
|
|
140
140
|
hash: void 0
|
|
141
141
|
};
|
|
142
|
-
if (p(
|
|
143
|
-
if (!
|
|
142
|
+
if (p(u, "address", () => {
|
|
143
|
+
if (!u.hash) return;
|
|
144
144
|
const n = c.allocUnsafe(21);
|
|
145
|
-
return n.writeUInt8(s.pubKeyHash, 0),
|
|
146
|
-
}), p(
|
|
145
|
+
return n.writeUInt8(s.pubKeyHash, 0), u.hash.copy(n, 1), L.encode(n);
|
|
146
|
+
}), p(u, "hash", () => {
|
|
147
147
|
if (e.output) return e.output.subarray(3, 23);
|
|
148
148
|
if (e.address) return f().hash;
|
|
149
|
-
if (e.pubkey ||
|
|
150
|
-
}), p(
|
|
151
|
-
if (
|
|
149
|
+
if (e.pubkey || u.pubkey) return T(e.pubkey || u.pubkey);
|
|
150
|
+
}), p(u, "output", () => {
|
|
151
|
+
if (u.hash)
|
|
152
152
|
return l([
|
|
153
153
|
S.OP_DUP,
|
|
154
154
|
S.OP_HASH160,
|
|
155
|
-
|
|
155
|
+
u.hash,
|
|
156
156
|
S.OP_EQUALVERIFY,
|
|
157
157
|
S.OP_CHECKSIG
|
|
158
158
|
]);
|
|
159
|
-
}), p(
|
|
159
|
+
}), p(u, "pubkey", () => {
|
|
160
160
|
if (e.input)
|
|
161
|
-
return
|
|
162
|
-
}), p(
|
|
161
|
+
return i()[1];
|
|
162
|
+
}), p(u, "signature", () => {
|
|
163
163
|
if (e.input)
|
|
164
|
-
return
|
|
165
|
-
}), p(
|
|
164
|
+
return i()[0];
|
|
165
|
+
}), p(u, "input", () => {
|
|
166
166
|
if (!e.pubkey || !e.signature) return;
|
|
167
167
|
let n = e.pubkey;
|
|
168
168
|
if (e.useHybrid || e.useUncompressed) {
|
|
169
|
-
const t =
|
|
169
|
+
const t = D(e.pubkey);
|
|
170
170
|
t && (e.useUncompressed ? n = t.uncompressed : n = t.hybrid);
|
|
171
171
|
}
|
|
172
172
|
return l([e.signature, n]);
|
|
173
|
-
}), p(
|
|
174
|
-
if (
|
|
173
|
+
}), p(u, "witness", () => {
|
|
174
|
+
if (u.input)
|
|
175
175
|
return [];
|
|
176
176
|
}), o.validate) {
|
|
177
177
|
let n = c.from([]);
|
|
@@ -198,7 +198,7 @@ function ke(e, o) {
|
|
|
198
198
|
const t = T(e.pubkey);
|
|
199
199
|
let h = n.length > 0 && !n.equals(t);
|
|
200
200
|
if (h && (e.pubkey.length === 33 && (e.pubkey[0] === 2 || e.pubkey[0] === 3) || e.pubkey.length === 65 && e.pubkey[0] === 4)) {
|
|
201
|
-
const d =
|
|
201
|
+
const d = D(e.pubkey);
|
|
202
202
|
if (d) {
|
|
203
203
|
const a = T(d.uncompressed);
|
|
204
204
|
if (n.equals(a))
|
|
@@ -214,7 +214,7 @@ function ke(e, o) {
|
|
|
214
214
|
n = t;
|
|
215
215
|
}
|
|
216
216
|
if (e.input) {
|
|
217
|
-
const t =
|
|
217
|
+
const t = i();
|
|
218
218
|
if (t.length !== 2) throw new TypeError("Input is invalid");
|
|
219
219
|
if (!H(t[0]))
|
|
220
220
|
throw new TypeError("Input has invalid signature");
|
|
@@ -227,7 +227,7 @@ function ke(e, o) {
|
|
|
227
227
|
if (n.length > 0 && !n.equals(h)) throw new TypeError("Hash mismatch (input)");
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
|
-
return Object.assign(
|
|
230
|
+
return Object.assign(u, e);
|
|
231
231
|
}
|
|
232
232
|
const q = _;
|
|
233
233
|
function Ee(e, o) {
|
|
@@ -252,14 +252,14 @@ function Ee(e, o) {
|
|
|
252
252
|
);
|
|
253
253
|
let f = e.network;
|
|
254
254
|
f || (f = e.redeem && e.redeem.network || v);
|
|
255
|
-
const
|
|
255
|
+
const i = {
|
|
256
256
|
network: f,
|
|
257
257
|
name: E.P2SH
|
|
258
258
|
}, s = y(() => {
|
|
259
259
|
const t = c.from(L.decode(e.address)), h = t.readUInt8(0), d = t.subarray(1);
|
|
260
260
|
return { version: h, hash: d };
|
|
261
|
-
}),
|
|
262
|
-
const t =
|
|
261
|
+
}), u = y(() => m(e.input)), n = y(() => {
|
|
262
|
+
const t = u(), h = t[t.length - 1];
|
|
263
263
|
return {
|
|
264
264
|
network: f,
|
|
265
265
|
output: h === q.OP_FALSE ? c.from([]) : h,
|
|
@@ -267,31 +267,31 @@ function Ee(e, o) {
|
|
|
267
267
|
witness: e.witness || []
|
|
268
268
|
};
|
|
269
269
|
});
|
|
270
|
-
if (p(
|
|
271
|
-
if (!
|
|
270
|
+
if (p(i, "address", () => {
|
|
271
|
+
if (!i.hash) return;
|
|
272
272
|
const t = c.allocUnsafe(21);
|
|
273
|
-
return t.writeUInt8(
|
|
274
|
-
}), p(
|
|
273
|
+
return t.writeUInt8(i.network.scriptHash, 0), i.hash.copy(t, 1), L.encode(t);
|
|
274
|
+
}), p(i, "hash", () => {
|
|
275
275
|
if (e.output) return e.output.subarray(2, 22);
|
|
276
276
|
if (e.address) return s().hash;
|
|
277
|
-
if (
|
|
278
|
-
}), p(
|
|
279
|
-
if (
|
|
280
|
-
return l([q.OP_HASH160,
|
|
281
|
-
}), p(
|
|
277
|
+
if (i.redeem && i.redeem.output) return T(i.redeem.output);
|
|
278
|
+
}), p(i, "output", () => {
|
|
279
|
+
if (i.hash)
|
|
280
|
+
return l([q.OP_HASH160, i.hash, q.OP_EQUAL]);
|
|
281
|
+
}), p(i, "redeem", () => {
|
|
282
282
|
if (e.input)
|
|
283
283
|
return n();
|
|
284
|
-
}), p(
|
|
284
|
+
}), p(i, "input", () => {
|
|
285
285
|
if (!(!e.redeem || !e.redeem.input || !e.redeem.output))
|
|
286
286
|
return l(
|
|
287
287
|
[].concat(m(e.redeem.input), e.redeem.output)
|
|
288
288
|
);
|
|
289
|
-
}), p(
|
|
290
|
-
if (
|
|
291
|
-
if (
|
|
292
|
-
}), p(
|
|
289
|
+
}), p(i, "witness", () => {
|
|
290
|
+
if (i.redeem && i.redeem.witness) return i.redeem.witness;
|
|
291
|
+
if (i.input) return [];
|
|
292
|
+
}), p(i, "name", () => {
|
|
293
293
|
const t = ["p2sh"];
|
|
294
|
-
return
|
|
294
|
+
return i.redeem !== void 0 && i.redeem.name !== void 0 && t.push(i.redeem.name), t.join("-");
|
|
295
295
|
}), o.validate) {
|
|
296
296
|
let t = c.from([]);
|
|
297
297
|
if (e.address) {
|
|
@@ -318,7 +318,7 @@ function Ee(e, o) {
|
|
|
318
318
|
throw new TypeError("Redeem.output too short");
|
|
319
319
|
if (d.output.byteLength > 520)
|
|
320
320
|
throw new TypeError("Redeem.output unspendable if larger than 520 bytes");
|
|
321
|
-
if (
|
|
321
|
+
if (oe(a) > 201)
|
|
322
322
|
throw new TypeError(
|
|
323
323
|
"Redeem.output unspendable with more than 201 non-push ops"
|
|
324
324
|
);
|
|
@@ -332,13 +332,13 @@ function Ee(e, o) {
|
|
|
332
332
|
if (a && w) throw new TypeError("Input and witness provided");
|
|
333
333
|
if (a) {
|
|
334
334
|
const I = m(d.input);
|
|
335
|
-
if (!
|
|
335
|
+
if (!fe(I))
|
|
336
336
|
throw new TypeError("Non push-only scriptSig");
|
|
337
337
|
}
|
|
338
338
|
}
|
|
339
339
|
};
|
|
340
340
|
if (e.input) {
|
|
341
|
-
const d =
|
|
341
|
+
const d = u();
|
|
342
342
|
if (!d || d.length < 1) throw new TypeError("Input too short");
|
|
343
343
|
if (!c.isBuffer(n().output)) throw new TypeError("Input is invalid");
|
|
344
344
|
h(n());
|
|
@@ -358,13 +358,13 @@ function Ee(e, o) {
|
|
|
358
358
|
if (e.witness && e.redeem && e.redeem.witness && !j(e.redeem.witness, e.witness))
|
|
359
359
|
throw new TypeError("Witness and redeem.witness mismatch");
|
|
360
360
|
}
|
|
361
|
-
return Object.assign(
|
|
361
|
+
return Object.assign(i, e);
|
|
362
362
|
}
|
|
363
363
|
const R = {};
|
|
364
364
|
function We(e) {
|
|
365
365
|
e ? e !== R.eccLib && (Te(e), R.eccLib = e) : R.eccLib = e;
|
|
366
366
|
}
|
|
367
|
-
function
|
|
367
|
+
function pe() {
|
|
368
368
|
if (!R.eccLib)
|
|
369
369
|
throw new Error(
|
|
370
370
|
"No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance"
|
|
@@ -404,66 +404,66 @@ const Pe = [
|
|
|
404
404
|
parity: 0,
|
|
405
405
|
result: "9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"
|
|
406
406
|
}
|
|
407
|
-
],
|
|
407
|
+
], G = 192, Oe = 128, ve = (e) => "left" in e && "right" in e;
|
|
408
408
|
function F(e, o) {
|
|
409
409
|
if (e.length < 33)
|
|
410
410
|
throw new TypeError(
|
|
411
411
|
`The control-block length is too small. Got ${e.length}, expected min 33.`
|
|
412
412
|
);
|
|
413
413
|
const f = (e.length - 33) / 32;
|
|
414
|
-
let
|
|
414
|
+
let i = o;
|
|
415
415
|
for (let s = 0; s < f; s++) {
|
|
416
|
-
const
|
|
417
|
-
|
|
416
|
+
const u = e.subarray(33 + 32 * s, 65 + 32 * s);
|
|
417
|
+
i.compare(u) < 0 ? i = M(i, u) : i = M(u, i);
|
|
418
418
|
}
|
|
419
|
-
return
|
|
419
|
+
return i;
|
|
420
420
|
}
|
|
421
421
|
function W(e) {
|
|
422
422
|
if (we(e)) return { hash: B(e) };
|
|
423
423
|
const o = [W(e[0]), W(e[1])];
|
|
424
|
-
o.sort((s,
|
|
425
|
-
const [f,
|
|
424
|
+
o.sort((s, u) => s.hash.compare(u.hash));
|
|
425
|
+
const [f, i] = o;
|
|
426
426
|
return {
|
|
427
|
-
hash: M(f.hash,
|
|
427
|
+
hash: M(f.hash, i.hash),
|
|
428
428
|
left: f,
|
|
429
|
-
right:
|
|
429
|
+
right: i
|
|
430
430
|
};
|
|
431
431
|
}
|
|
432
432
|
function x(e, o) {
|
|
433
433
|
if (ve(e)) {
|
|
434
434
|
const f = x(e.left, o);
|
|
435
435
|
if (f !== void 0) return [...f, e.right.hash];
|
|
436
|
-
const
|
|
437
|
-
if (
|
|
436
|
+
const i = x(e.right, o);
|
|
437
|
+
if (i !== void 0) return [...i, e.left.hash];
|
|
438
438
|
} else if (e.hash.equals(o))
|
|
439
439
|
return [];
|
|
440
440
|
}
|
|
441
441
|
function B(e) {
|
|
442
|
-
const o = e.version ||
|
|
443
|
-
return
|
|
442
|
+
const o = e.version || G;
|
|
443
|
+
return X(
|
|
444
444
|
"TapLeaf",
|
|
445
445
|
k.concat([k.from([o]), Se(e.output)])
|
|
446
446
|
);
|
|
447
447
|
}
|
|
448
448
|
function _e(e, o) {
|
|
449
|
-
return
|
|
449
|
+
return X("TapTweak", k.concat(o ? [e, o] : [e]));
|
|
450
450
|
}
|
|
451
451
|
function V(e, o) {
|
|
452
452
|
if (!k.isBuffer(e) || e.length !== 32 || o && o.length !== 32) return null;
|
|
453
|
-
const f = _e(e, o),
|
|
454
|
-
return !
|
|
455
|
-
parity:
|
|
456
|
-
x: k.from(
|
|
453
|
+
const f = _e(e, o), i = pe().xOnlyPointAddTweak(e, f);
|
|
454
|
+
return !i || i.xOnlyPubkey === null ? null : {
|
|
455
|
+
parity: i.parity,
|
|
456
|
+
x: k.from(i.xOnlyPubkey)
|
|
457
457
|
};
|
|
458
458
|
}
|
|
459
459
|
function M(e, o) {
|
|
460
|
-
return
|
|
460
|
+
return X("TapBranch", k.concat([e, o]));
|
|
461
461
|
}
|
|
462
462
|
function Se(e) {
|
|
463
463
|
const o = le(e.length), f = k.allocUnsafe(o);
|
|
464
464
|
return ye(e.length, f), k.concat([f, e]);
|
|
465
465
|
}
|
|
466
|
-
const
|
|
466
|
+
const ee = _, re = 1, Ie = 80;
|
|
467
467
|
function He(e, o) {
|
|
468
468
|
if (!e.address && !e.output && !e.pubkey && !e.internalPubkey && !(e.witness && e.witness.length > 1))
|
|
469
469
|
throw new TypeError("Not enough data");
|
|
@@ -492,24 +492,24 @@ function He(e, o) {
|
|
|
492
492
|
},
|
|
493
493
|
e
|
|
494
494
|
);
|
|
495
|
-
const f = y(() =>
|
|
495
|
+
const f = y(() => ie(e.address)), i = y(() => {
|
|
496
496
|
if (!(!e.witness || !e.witness.length))
|
|
497
497
|
return e.witness.length >= 2 && e.witness[e.witness.length - 1][0] === Ie ? e.witness.slice(0, -1) : e.witness.slice();
|
|
498
498
|
}), s = y(() => {
|
|
499
499
|
if (e.scriptTree) return W(e.scriptTree);
|
|
500
500
|
if (e.hash) return { hash: e.hash };
|
|
501
|
-
}),
|
|
501
|
+
}), u = e.network || v, n = {
|
|
502
502
|
name: E.P2TR,
|
|
503
|
-
network:
|
|
503
|
+
network: u
|
|
504
504
|
};
|
|
505
505
|
if (p(n, "address", () => {
|
|
506
506
|
if (!n.pubkey) return;
|
|
507
507
|
const t = g.bech32m.toWords(n.pubkey);
|
|
508
|
-
return t.unshift(
|
|
508
|
+
return t.unshift(re), g.bech32m.encode(u.bech32, t);
|
|
509
509
|
}), p(n, "hash", () => {
|
|
510
510
|
const t = s();
|
|
511
511
|
if (t) return t.hash;
|
|
512
|
-
const h =
|
|
512
|
+
const h = i();
|
|
513
513
|
if (h && h.length > 1) {
|
|
514
514
|
const d = h[h.length - 1], a = d[0] & $, w = h[h.length - 2], I = B({
|
|
515
515
|
output: w,
|
|
@@ -519,9 +519,9 @@ function He(e, o) {
|
|
|
519
519
|
}
|
|
520
520
|
}), p(n, "output", () => {
|
|
521
521
|
if (n.pubkey)
|
|
522
|
-
return l([
|
|
523
|
-
}), p(n, "redeemVersion", () => e.redeemVersion ? e.redeemVersion : e.redeem && e.redeem.redeemVersion !== void 0 && e.redeem.redeemVersion !== null ? e.redeem.redeemVersion :
|
|
524
|
-
const t =
|
|
522
|
+
return l([ee.OP_1, n.pubkey]);
|
|
523
|
+
}), p(n, "redeemVersion", () => e.redeemVersion ? e.redeemVersion : e.redeem && e.redeem.redeemVersion !== void 0 && e.redeem.redeemVersion !== null ? e.redeem.redeemVersion : G), p(n, "redeem", () => {
|
|
524
|
+
const t = i();
|
|
525
525
|
if (!(!t || t.length < 2))
|
|
526
526
|
return {
|
|
527
527
|
output: t[t.length - 2],
|
|
@@ -538,11 +538,11 @@ function He(e, o) {
|
|
|
538
538
|
}
|
|
539
539
|
}), p(n, "internalPubkey", () => {
|
|
540
540
|
if (e.internalPubkey) return e.internalPubkey;
|
|
541
|
-
const t =
|
|
541
|
+
const t = i();
|
|
542
542
|
if (t && t.length > 1) return t[t.length - 1].subarray(1, 33);
|
|
543
543
|
}), p(n, "signature", () => {
|
|
544
544
|
if (e.signature) return e.signature;
|
|
545
|
-
const t =
|
|
545
|
+
const t = i();
|
|
546
546
|
if (!(!t || t.length !== 1))
|
|
547
547
|
return t[0];
|
|
548
548
|
}), p(n, "witness", () => {
|
|
@@ -567,9 +567,9 @@ function He(e, o) {
|
|
|
567
567
|
}), o.validate) {
|
|
568
568
|
let t = k.from([]);
|
|
569
569
|
if (e.address) {
|
|
570
|
-
if (
|
|
570
|
+
if (u && u.bech32 !== f().prefix)
|
|
571
571
|
throw new TypeError("Invalid prefix or Network mismatch");
|
|
572
|
-
if (f().version !==
|
|
572
|
+
if (f().version !== re)
|
|
573
573
|
throw new TypeError("Invalid address version");
|
|
574
574
|
if (f().data.length !== 32) throw new TypeError("Invalid address data");
|
|
575
575
|
t = f().data;
|
|
@@ -580,7 +580,7 @@ function He(e, o) {
|
|
|
580
580
|
t = e.pubkey;
|
|
581
581
|
}
|
|
582
582
|
if (e.output) {
|
|
583
|
-
if (e.output.length !== 34 || e.output[0] !==
|
|
583
|
+
if (e.output.length !== 34 || e.output[0] !== ee.OP_1 || e.output[1] !== 32)
|
|
584
584
|
throw new TypeError("Output is invalid");
|
|
585
585
|
if (t.length > 0 && !t.equals(e.output.subarray(2)))
|
|
586
586
|
throw new TypeError("Pubkey mismatch");
|
|
@@ -592,8 +592,6 @@ function He(e, o) {
|
|
|
592
592
|
throw new TypeError("Pubkey mismatch");
|
|
593
593
|
t = a.x;
|
|
594
594
|
}
|
|
595
|
-
if (t && t.length && !X().isXOnlyPoint(t))
|
|
596
|
-
throw new TypeError("Invalid pubkey for p2tr");
|
|
597
595
|
const h = s();
|
|
598
596
|
if (e.hash && h && !e.hash.equals(h.hash))
|
|
599
597
|
throw new TypeError("Hash mismatch");
|
|
@@ -605,7 +603,7 @@ function He(e, o) {
|
|
|
605
603
|
if (!x(h, a))
|
|
606
604
|
throw new TypeError("Redeem script not in tree");
|
|
607
605
|
}
|
|
608
|
-
const d =
|
|
606
|
+
const d = i();
|
|
609
607
|
if (e.redeem && n.redeem) {
|
|
610
608
|
if (e.redeem.redeemVersion && e.redeem.redeemVersion !== n.redeem.redeemVersion)
|
|
611
609
|
throw new TypeError("Redeem.redeemVersion and witness mismatch");
|
|
@@ -638,7 +636,7 @@ function He(e, o) {
|
|
|
638
636
|
const I = a.subarray(1, 33);
|
|
639
637
|
if (e.internalPubkey && !e.internalPubkey.equals(I))
|
|
640
638
|
throw new TypeError("Internal pubkey mismatch");
|
|
641
|
-
if (!
|
|
639
|
+
if (!pe().isXOnlyPoint(I))
|
|
642
640
|
throw new TypeError("Invalid internalPubkey for p2tr witness");
|
|
643
641
|
const he = a[0] & $, de = d[d.length - 2], ae = B({
|
|
644
642
|
output: de,
|
|
@@ -653,7 +651,7 @@ function He(e, o) {
|
|
|
653
651
|
}
|
|
654
652
|
return Object.assign(n, e);
|
|
655
653
|
}
|
|
656
|
-
const
|
|
654
|
+
const te = _, Ne = c.alloc(0);
|
|
657
655
|
function Be(e, o) {
|
|
658
656
|
if (!e.address && !e.hash && !e.output && !e.pubkey && !e.witness)
|
|
659
657
|
throw new TypeError("Not enough data");
|
|
@@ -671,27 +669,27 @@ function Be(e, o) {
|
|
|
671
669
|
e
|
|
672
670
|
);
|
|
673
671
|
const f = y(() => {
|
|
674
|
-
const
|
|
672
|
+
const u = g.bech32.decode(e.address), n = u.words.shift(), t = g.bech32.fromWords(u.words);
|
|
675
673
|
return {
|
|
676
674
|
version: n,
|
|
677
|
-
prefix:
|
|
675
|
+
prefix: u.prefix,
|
|
678
676
|
data: c.from(t)
|
|
679
677
|
};
|
|
680
|
-
}),
|
|
678
|
+
}), i = e.network || v, s = {
|
|
681
679
|
name: E.P2WPKH,
|
|
682
|
-
network:
|
|
680
|
+
network: i
|
|
683
681
|
};
|
|
684
682
|
if (p(s, "address", () => {
|
|
685
683
|
if (!s.hash) return;
|
|
686
|
-
const
|
|
687
|
-
return
|
|
684
|
+
const u = g.bech32.toWords(s.hash);
|
|
685
|
+
return u.unshift(0), g.bech32.encode(i.bech32, u);
|
|
688
686
|
}), p(s, "hash", () => {
|
|
689
687
|
if (e.output) return e.output.subarray(2, 22);
|
|
690
688
|
if (e.address) return f().data;
|
|
691
689
|
if (e.pubkey || s.pubkey) return T(e.pubkey || s.pubkey);
|
|
692
690
|
}), p(s, "output", () => {
|
|
693
691
|
if (s.hash)
|
|
694
|
-
return l([
|
|
692
|
+
return l([te.OP_0, s.hash]);
|
|
695
693
|
}), p(s, "pubkey", () => {
|
|
696
694
|
if (e.pubkey) return e.pubkey;
|
|
697
695
|
if (e.witness)
|
|
@@ -706,29 +704,29 @@ function Be(e, o) {
|
|
|
706
704
|
if (e.pubkey && e.signature)
|
|
707
705
|
return [e.signature, e.pubkey];
|
|
708
706
|
}), o.validate) {
|
|
709
|
-
let
|
|
707
|
+
let u = c.from([]);
|
|
710
708
|
if (e.address) {
|
|
711
|
-
if (
|
|
709
|
+
if (i && i.bech32 !== f().prefix)
|
|
712
710
|
throw new TypeError("Invalid prefix or Network mismatch");
|
|
713
711
|
if (f().version !== 0) throw new TypeError("Invalid address version");
|
|
714
712
|
if (f().data.length !== 20) throw new TypeError("Invalid address data");
|
|
715
|
-
|
|
713
|
+
u = f().data;
|
|
716
714
|
}
|
|
717
715
|
if (e.hash) {
|
|
718
|
-
if (
|
|
719
|
-
|
|
716
|
+
if (u.length > 0 && !u.equals(e.hash)) throw new TypeError("Hash mismatch");
|
|
717
|
+
u = e.hash;
|
|
720
718
|
}
|
|
721
719
|
if (e.output) {
|
|
722
|
-
if (e.output.length !== 22 || e.output[0] !==
|
|
720
|
+
if (e.output.length !== 22 || e.output[0] !== te.OP_0 || e.output[1] !== 20)
|
|
723
721
|
throw new TypeError("Output is invalid");
|
|
724
|
-
if (
|
|
722
|
+
if (u.length > 0 && !u.equals(e.output.subarray(2)))
|
|
725
723
|
throw new TypeError("Hash mismatch");
|
|
726
|
-
|
|
724
|
+
u = e.output.subarray(2);
|
|
727
725
|
}
|
|
728
726
|
if (e.pubkey) {
|
|
729
727
|
const n = T(e.pubkey);
|
|
730
|
-
if (
|
|
731
|
-
if (
|
|
728
|
+
if (u.length > 0 && !u.equals(n)) throw new TypeError("Hash mismatch");
|
|
729
|
+
if (u = n, !P(e.pubkey) || e.pubkey.length !== 33)
|
|
732
730
|
throw new TypeError("Invalid pubkey for p2wpkh");
|
|
733
731
|
}
|
|
734
732
|
if (e.witness) {
|
|
@@ -741,12 +739,12 @@ function Be(e, o) {
|
|
|
741
739
|
throw new TypeError("Signature mismatch");
|
|
742
740
|
if (e.pubkey && !e.pubkey.equals(e.witness[1])) throw new TypeError("Pubkey mismatch");
|
|
743
741
|
const n = T(e.witness[1]);
|
|
744
|
-
if (
|
|
742
|
+
if (u.length > 0 && !u.equals(n)) throw new TypeError("Hash mismatch");
|
|
745
743
|
}
|
|
746
744
|
}
|
|
747
745
|
return Object.assign(s, e);
|
|
748
746
|
}
|
|
749
|
-
const
|
|
747
|
+
const ne = _, K = c.alloc(0);
|
|
750
748
|
function A(e) {
|
|
751
749
|
return !!(c.isBuffer(e) && e.length === 65 && e[0] === 4 && P(e));
|
|
752
750
|
}
|
|
@@ -777,44 +775,44 @@ function je(e, o) {
|
|
|
777
775
|
prefix: n.prefix,
|
|
778
776
|
data: c.from(h)
|
|
779
777
|
};
|
|
780
|
-
}),
|
|
778
|
+
}), i = y(() => m(e.redeem.input));
|
|
781
779
|
let s = e.network;
|
|
782
780
|
s || (s = e.redeem && e.redeem.network || v);
|
|
783
|
-
const
|
|
781
|
+
const u = {
|
|
784
782
|
network: s,
|
|
785
783
|
name: E.P2WSH
|
|
786
784
|
};
|
|
787
|
-
if (p(
|
|
788
|
-
if (!
|
|
789
|
-
const n = g.bech32.toWords(
|
|
785
|
+
if (p(u, "address", () => {
|
|
786
|
+
if (!u.hash) return;
|
|
787
|
+
const n = g.bech32.toWords(u.hash);
|
|
790
788
|
return n.unshift(0), g.bech32.encode(s.bech32, n);
|
|
791
|
-
}), p(
|
|
789
|
+
}), p(u, "hash", () => {
|
|
792
790
|
if (e.output) return e.output.subarray(2);
|
|
793
791
|
if (e.address) return f().data;
|
|
794
|
-
if (
|
|
795
|
-
}), p(
|
|
796
|
-
if (
|
|
797
|
-
return l([
|
|
798
|
-
}), p(
|
|
792
|
+
if (u.redeem && u.redeem.output) return Y(u.redeem.output);
|
|
793
|
+
}), p(u, "output", () => {
|
|
794
|
+
if (u.hash)
|
|
795
|
+
return l([ne.OP_0, u.hash]);
|
|
796
|
+
}), p(u, "redeem", () => {
|
|
799
797
|
if (e.witness)
|
|
800
798
|
return {
|
|
801
799
|
output: e.witness[e.witness.length - 1],
|
|
802
800
|
input: K,
|
|
803
801
|
witness: e.witness.slice(0, -1)
|
|
804
802
|
};
|
|
805
|
-
}), p(
|
|
806
|
-
if (
|
|
803
|
+
}), p(u, "input", () => {
|
|
804
|
+
if (u.witness)
|
|
807
805
|
return K;
|
|
808
|
-
}), p(
|
|
806
|
+
}), p(u, "witness", () => {
|
|
809
807
|
if (e.redeem && e.redeem.input && e.redeem.input.length > 0 && e.redeem.output && e.redeem.output.length > 0) {
|
|
810
|
-
const n = me(
|
|
811
|
-
return
|
|
808
|
+
const n = me(i());
|
|
809
|
+
return u.redeem = Object.assign({ witness: n }, e.redeem), u.redeem.input = K, [].concat(n, e.redeem.output);
|
|
812
810
|
}
|
|
813
811
|
if (e.redeem && e.redeem.output && e.redeem.witness)
|
|
814
812
|
return [].concat(e.redeem.witness, e.redeem.output);
|
|
815
|
-
}), p(
|
|
813
|
+
}), p(u, "name", () => {
|
|
816
814
|
const n = ["p2wsh"];
|
|
817
|
-
return
|
|
815
|
+
return u.redeem !== void 0 && u.redeem.name !== void 0 && n.push(u.redeem.name), n.join("-");
|
|
818
816
|
}), o.validate) {
|
|
819
817
|
let n = c.from([]);
|
|
820
818
|
if (e.address) {
|
|
@@ -829,7 +827,7 @@ function je(e, o) {
|
|
|
829
827
|
n = e.hash;
|
|
830
828
|
}
|
|
831
829
|
if (e.output) {
|
|
832
|
-
if (e.output.length !== 34 || e.output[0] !==
|
|
830
|
+
if (e.output.length !== 34 || e.output[0] !== ne.OP_0 || e.output[1] !== 32)
|
|
833
831
|
throw new TypeError("Output is invalid");
|
|
834
832
|
const t = e.output.subarray(2);
|
|
835
833
|
if (n.length > 0 && !n.equals(t)) throw new TypeError("Hash mismatch");
|
|
@@ -846,19 +844,19 @@ function je(e, o) {
|
|
|
846
844
|
throw new TypeError("Redeem.output is invalid");
|
|
847
845
|
if (e.redeem.output.byteLength > 3600)
|
|
848
846
|
throw new TypeError("Redeem.output unspendable if larger than 3600 bytes");
|
|
849
|
-
if (
|
|
847
|
+
if (oe(t) > 201)
|
|
850
848
|
throw new TypeError(
|
|
851
849
|
"Redeem.output unspendable with more than 201 non-push ops"
|
|
852
850
|
);
|
|
853
|
-
const h =
|
|
851
|
+
const h = Y(e.redeem.output);
|
|
854
852
|
if (n.length > 0 && !n.equals(h)) throw new TypeError("Hash mismatch");
|
|
855
853
|
n = h;
|
|
856
854
|
}
|
|
857
|
-
if (e.redeem.input && !
|
|
855
|
+
if (e.redeem.input && !fe(i()))
|
|
858
856
|
throw new TypeError("Non push-only scriptSig");
|
|
859
857
|
if (e.witness && e.redeem.witness && !j(e.witness, e.redeem.witness))
|
|
860
858
|
throw new TypeError("Witness and redeem.witness mismatch");
|
|
861
|
-
if (e.redeem.input &&
|
|
859
|
+
if (e.redeem.input && i().some(A) || e.redeem.output && (m(e.redeem.output) || []).some(A))
|
|
862
860
|
throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey");
|
|
863
861
|
}
|
|
864
862
|
if (e.witness && e.witness.length > 0) {
|
|
@@ -869,9 +867,9 @@ function je(e, o) {
|
|
|
869
867
|
throw new TypeError("Witness contains uncompressed pubkey");
|
|
870
868
|
}
|
|
871
869
|
}
|
|
872
|
-
return Object.assign(
|
|
870
|
+
return Object.assign(u, e);
|
|
873
871
|
}
|
|
874
|
-
const
|
|
872
|
+
const se = _;
|
|
875
873
|
function qe(e, o) {
|
|
876
874
|
if (!e.data && !e.output) throw new TypeError("Not enough data");
|
|
877
875
|
o = Object.assign({ validate: !0 }, o || {}), r(
|
|
@@ -882,22 +880,22 @@ function qe(e, o) {
|
|
|
882
880
|
},
|
|
883
881
|
e
|
|
884
882
|
);
|
|
885
|
-
const f = e.network || v,
|
|
886
|
-
if (p(
|
|
883
|
+
const f = e.network || v, i = { name: E.Embed, network: f, data: [] };
|
|
884
|
+
if (p(i, "output", () => {
|
|
887
885
|
if (e.data)
|
|
888
|
-
return l([
|
|
889
|
-
}), p(
|
|
886
|
+
return l([se.OP_RETURN].concat(e.data));
|
|
887
|
+
}), p(i, "data", () => {
|
|
890
888
|
if (!e.output) return;
|
|
891
889
|
const s = m(e.output);
|
|
892
890
|
if (s != null)
|
|
893
891
|
return s.slice(1);
|
|
894
892
|
}), o.validate && e.output) {
|
|
895
893
|
const s = m(e.output);
|
|
896
|
-
if (s[0] !==
|
|
894
|
+
if (s[0] !== se.OP_RETURN) throw new TypeError("Output is invalid");
|
|
897
895
|
if (!s.slice(1).every(r.Buffer)) throw new TypeError("Output is invalid");
|
|
898
|
-
if (e.data && !j(e.data,
|
|
896
|
+
if (e.data && !j(e.data, i.data)) throw new TypeError("Data mismatch");
|
|
899
897
|
}
|
|
900
|
-
return Object.assign(
|
|
898
|
+
return Object.assign(i, e);
|
|
901
899
|
}
|
|
902
900
|
const N = _, U = N.OP_RESERVED;
|
|
903
901
|
function Ve(e, o) {
|
|
@@ -923,9 +921,9 @@ function Ve(e, o) {
|
|
|
923
921
|
network: e.network || v,
|
|
924
922
|
name: E.P2MS
|
|
925
923
|
};
|
|
926
|
-
let
|
|
924
|
+
let u = [], n = !1;
|
|
927
925
|
function t(h) {
|
|
928
|
-
n || (n = !0,
|
|
926
|
+
n || (n = !0, u = m(h), s.m = u[0] - U, s.n = u[u.length - 2] - U, s.pubkeys = u.slice(1, -2));
|
|
929
927
|
}
|
|
930
928
|
if (p(s, "output", () => {
|
|
931
929
|
if (e.m && s.n && e.pubkeys)
|
|
@@ -962,11 +960,11 @@ function Ve(e, o) {
|
|
|
962
960
|
return `p2ms(${s.m} of ${s.n})`;
|
|
963
961
|
}), o.validate) {
|
|
964
962
|
if (e.output) {
|
|
965
|
-
if (t(e.output), !r.Number(
|
|
966
|
-
if (!r.Number(
|
|
967
|
-
if (
|
|
963
|
+
if (t(e.output), !r.Number(u[0])) throw new TypeError("Output is invalid");
|
|
964
|
+
if (!r.Number(u[u.length - 2])) throw new TypeError("Output is invalid");
|
|
965
|
+
if (u[u.length - 1] !== N.OP_CHECKMULTISIG)
|
|
968
966
|
throw new TypeError("Output is invalid");
|
|
969
|
-
if (s.m <= 0 || s.n > 16 || s.m > s.n || s.n !==
|
|
967
|
+
if (s.m <= 0 || s.n > 16 || s.m > s.n || s.n !== u.length - 3)
|
|
970
968
|
throw new TypeError("Output is invalid");
|
|
971
969
|
if (!s.pubkeys.every((h) => P(h))) throw new TypeError("Output is invalid");
|
|
972
970
|
if (e.m !== void 0 && e.m !== s.m) throw new TypeError("m mismatch");
|
|
@@ -1009,9 +1007,9 @@ function Re(e, o) {
|
|
|
1009
1007
|
},
|
|
1010
1008
|
e
|
|
1011
1009
|
);
|
|
1012
|
-
const f = y(() => m(e.input)),
|
|
1010
|
+
const f = y(() => m(e.input)), i = e.network || v, s = {
|
|
1013
1011
|
name: E.P2PK,
|
|
1014
|
-
network:
|
|
1012
|
+
network: i,
|
|
1015
1013
|
pubkey: void 0
|
|
1016
1014
|
};
|
|
1017
1015
|
if (p(s, "output", () => {
|
|
@@ -1048,7 +1046,7 @@ function Re(e, o) {
|
|
|
1048
1046
|
}
|
|
1049
1047
|
const Ce = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1050
1048
|
__proto__: null,
|
|
1051
|
-
LEAF_VERSION_TAPSCRIPT:
|
|
1049
|
+
LEAF_VERSION_TAPSCRIPT: G,
|
|
1052
1050
|
MAX_TAPTREE_DEPTH: Oe,
|
|
1053
1051
|
PaymentType: E,
|
|
1054
1052
|
findScriptPath: x,
|
|
@@ -1069,7 +1067,7 @@ const Ce = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
1069
1067
|
value: y
|
|
1070
1068
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
1071
1069
|
export {
|
|
1072
|
-
|
|
1070
|
+
G as L,
|
|
1073
1071
|
Oe as M,
|
|
1074
1072
|
E as P,
|
|
1075
1073
|
Ee as a,
|