@btc-vision/bitcoin 6.5.1 → 6.5.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.
- package/browser/chunks/crypto-0PweVewC.js +2033 -0
- package/browser/chunks/{payments-BE4vwHhV.js → payments-CgasufRS.js} +410 -408
- package/browser/chunks/psbt-BIwOrKer.js +4096 -0
- package/browser/chunks/{script-COWGdiOo.js → script-CROJPzz_.js} +96 -96
- package/browser/chunks/{transaction-BiXwH2v4.js → transaction-DchBu35N.js} +158 -147
- package/browser/chunks/{utils-BKmkTzNZ.js → utils-CO5kmxe9.js} +225 -223
- package/browser/crypto.d.ts +1 -1
- package/browser/hooks/HookedSigner.d.ts +1 -1
- package/browser/index.d.ts +23 -1
- package/browser/index.js +6 -6
- package/browser/payments/index.d.ts +2 -2
- package/browser/payments/lazy.d.ts +1 -1
- package/browser/psbt/bip371.d.ts +5 -1
- package/browser/psbt.d.ts +1 -1
- package/browser/typeforce.d.ts +38 -0
- package/browser/types.d.ts +22 -20
- package/build/address.js +2 -2
- package/build/bip66.js +2 -2
- package/build/block.js +2 -2
- package/build/crypto.d.ts +1 -1
- package/build/crypto.js +2 -3
- package/build/hooks/HookedSigner.d.ts +1 -1
- package/build/index.d.ts +23 -1
- package/build/payments/bip341.js +1 -1
- package/build/payments/index.d.ts +2 -2
- package/build/payments/lazy.d.ts +1 -1
- package/build/payments/p2op.js +3 -3
- package/build/payments/p2pk.js +1 -1
- package/build/payments/p2pkh.js +3 -3
- package/build/payments/p2sh.js +3 -3
- package/build/payments/p2tr.js +9 -5
- package/build/payments/p2wpkh.js +3 -3
- package/build/payments/p2wsh.js +2 -2
- package/build/psbt/bip371.d.ts +5 -1
- package/build/psbt/bip371.js +10 -7
- package/build/psbt/psbtutils.js +5 -4
- package/build/psbt.d.ts +1 -1
- package/build/psbt.js +78 -45
- package/build/script.js +2 -2
- package/build/script_signature.js +7 -7
- package/build/transaction.js +22 -10
- package/build/tsconfig.tsbuildinfo +1 -0
- package/build/types.d.ts +22 -20
- package/build/types.js +10 -9
- package/package.json +32 -57
- package/src/address.ts +2 -2
- package/src/bip66.ts +2 -2
- package/src/block.ts +8 -5
- package/src/crypto.ts +3 -4
- package/src/ecc_lib.ts +1 -1
- package/src/hooks/HookedSigner.ts +1 -1
- package/src/index.ts +34 -12
- package/src/payments/bip341.ts +1 -1
- package/src/payments/embed.ts +1 -2
- package/src/payments/index.ts +4 -4
- package/src/payments/lazy.ts +3 -3
- package/src/payments/p2op.ts +4 -3
- package/src/payments/p2pk.ts +1 -1
- package/src/payments/p2pkh.ts +3 -3
- package/src/payments/p2sh.ts +13 -5
- package/src/payments/p2tr.ts +8 -9
- package/src/payments/p2wpkh.ts +3 -3
- package/src/payments/p2wsh.ts +4 -4
- package/src/psbt/bip371.ts +22 -13
- package/src/psbt/psbtutils.ts +8 -5
- package/src/psbt.ts +127 -80
- package/src/script.ts +4 -4
- package/src/script_signature.ts +7 -7
- package/src/transaction.ts +31 -18
- package/src/typeforce.d.ts +38 -0
- package/src/types.ts +34 -29
- package/test/address.spec.ts +12 -4
- package/test/bitcoin.core.spec.ts +1 -1
- package/test/block.spec.ts +1 -1
- package/test/bufferutils.spec.ts +1 -1
- package/test/crypto.spec.ts +3 -2
- package/test/fixtures/address.json +1 -1
- package/test/integration/addresses.spec.ts +1 -1
- package/test/integration/bip32.spec.ts +2 -2
- package/test/integration/blocks.spec.ts +1 -1
- package/test/integration/cltv.spec.ts +3 -3
- package/test/integration/csv.spec.ts +3 -3
- package/test/integration/payments.spec.ts +1 -1
- package/test/integration/taproot.spec.ts +8 -7
- package/test/integration/transactions.spec.ts +2 -2
- package/test/payments.spec.ts +4 -3
- package/test/psbt.spec.ts +106 -74
- package/test/script.spec.ts +73 -7
- package/test/script_number.spec.ts +1 -1
- package/test/script_signature.spec.ts +1 -1
- package/test/transaction.spec.ts +1 -1
- package/test/tsconfig.json +1 -1
- package/test/types.spec.ts +1 -1
- package/vitest.config.ts +16 -0
- package/.babelrc +0 -13
- package/.mocharc.json +0 -13
- package/browser/chunks/crypto-C6FlKKmp.js +0 -2006
- package/browser/chunks/psbt-Dlosf9CT.js +0 -3853
- package/cjs/package.json +0 -3
- package/gulpfile.js +0 -42
- package/src/crypto/crypto-browser.js +0 -75
- package/test/ts-node-register.js +0 -7
- package/webpack.config.js +0 -79
|
@@ -1,116 +1,115 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import { g as
|
|
3
|
-
import { b as
|
|
4
|
-
import { d as
|
|
5
|
-
const
|
|
6
|
-
function
|
|
1
|
+
import { t as F, e as g, B as m, h as E, a as G } from "./crypto-0PweVewC.js";
|
|
2
|
+
import { g as K, b as P, i as x, d as b, f as se, a as X } from "./psbt-BIwOrKer.js";
|
|
3
|
+
import { b as ae, g as me, h as we, t as r, s as N, j as T, i as ce, T as W } from "./utils-CO5kmxe9.js";
|
|
4
|
+
import { d as w, o as v, c as y, i as S, e as ue, f as ie, g as ye } from "./script-CROJPzz_.js";
|
|
5
|
+
const M = 192, le = 128, be = (e) => "left" in e && "right" in e;
|
|
6
|
+
function L(e, o) {
|
|
7
7
|
if (e.length < 33)
|
|
8
8
|
throw new TypeError(
|
|
9
9
|
`The control-block length is too small. Got ${e.length}, expected min 33.`
|
|
10
10
|
);
|
|
11
11
|
const p = (e.length - 33) / 32;
|
|
12
|
-
let
|
|
12
|
+
let i = o;
|
|
13
13
|
for (let s = 0; s < p; s++) {
|
|
14
|
-
const
|
|
15
|
-
|
|
14
|
+
const u = e.subarray(33 + 32 * s, 65 + 32 * s);
|
|
15
|
+
i.compare(u) < 0 ? i = C(i, u) : i = C(u, i);
|
|
16
16
|
}
|
|
17
|
-
return
|
|
17
|
+
return i;
|
|
18
18
|
}
|
|
19
19
|
function A(e) {
|
|
20
|
-
if (
|
|
20
|
+
if (ae(e)) return { hash: H(e) };
|
|
21
21
|
const o = [A(e[0]), A(e[1])];
|
|
22
|
-
o.sort((s,
|
|
23
|
-
const [p,
|
|
22
|
+
o.sort((s, u) => s.hash.compare(u.hash));
|
|
23
|
+
const [p, i] = o;
|
|
24
24
|
return {
|
|
25
|
-
hash:
|
|
25
|
+
hash: C(p.hash, i.hash),
|
|
26
26
|
left: p,
|
|
27
|
-
right:
|
|
27
|
+
right: i
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
function q(e, o) {
|
|
31
31
|
if (be(e)) {
|
|
32
32
|
const p = q(e.left, o);
|
|
33
33
|
if (p !== void 0) return [...p, e.right.hash];
|
|
34
|
-
const
|
|
35
|
-
if (
|
|
34
|
+
const i = q(e.right, o);
|
|
35
|
+
if (i !== void 0) return [...i, e.left.hash];
|
|
36
36
|
} else if (e.hash.equals(o))
|
|
37
37
|
return [];
|
|
38
38
|
}
|
|
39
39
|
function H(e) {
|
|
40
|
-
const o = e.version ||
|
|
41
|
-
return
|
|
40
|
+
const o = e.version || M;
|
|
41
|
+
return F(
|
|
42
42
|
"TapLeaf",
|
|
43
43
|
g.concat([g.from([o]), ge(e.output)])
|
|
44
44
|
);
|
|
45
45
|
}
|
|
46
46
|
function oe(e, o) {
|
|
47
|
-
return
|
|
47
|
+
return F("TapTweak", g.concat(o ? [e, o] : [e]));
|
|
48
48
|
}
|
|
49
49
|
function j(e, o) {
|
|
50
50
|
if (!g.isBuffer(e) || e.length !== 32 || o && o.length !== 32) return null;
|
|
51
|
-
const p = oe(e, o),
|
|
52
|
-
return !
|
|
53
|
-
parity:
|
|
54
|
-
x: g.from(
|
|
51
|
+
const p = oe(e, o), i = K().xOnlyPointAddTweak(e, p);
|
|
52
|
+
return !i || i.xOnlyPubkey === null ? null : {
|
|
53
|
+
parity: i.parity,
|
|
54
|
+
x: g.from(i.xOnlyPubkey)
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
|
-
function
|
|
58
|
-
return
|
|
57
|
+
function C(e, o) {
|
|
58
|
+
return F("TapBranch", g.concat([e, o]));
|
|
59
59
|
}
|
|
60
60
|
function ge(e) {
|
|
61
|
-
const o =
|
|
62
|
-
return
|
|
61
|
+
const o = me(e.length), p = g.allocUnsafe(o);
|
|
62
|
+
return we(e.length, p), g.concat([p, e]);
|
|
63
63
|
}
|
|
64
64
|
function h(e, o, p) {
|
|
65
65
|
Object.defineProperty(e, o, {
|
|
66
66
|
configurable: !0,
|
|
67
67
|
enumerable: !0,
|
|
68
68
|
get() {
|
|
69
|
-
const
|
|
70
|
-
return this[o] =
|
|
69
|
+
const i = p.call(this);
|
|
70
|
+
return this[o] = i, i;
|
|
71
71
|
},
|
|
72
|
-
set(
|
|
72
|
+
set(i) {
|
|
73
73
|
Object.defineProperty(this, o, {
|
|
74
74
|
configurable: !0,
|
|
75
75
|
enumerable: !0,
|
|
76
|
-
value:
|
|
76
|
+
value: i,
|
|
77
77
|
writable: !0
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
|
-
function
|
|
82
|
+
function l(e) {
|
|
83
83
|
let o;
|
|
84
84
|
return () => (o !== void 0 || (o = e()), o);
|
|
85
85
|
}
|
|
86
86
|
const D = v;
|
|
87
87
|
function ke(e, o) {
|
|
88
88
|
if (!e.data && !e.output) throw new TypeError("Not enough data");
|
|
89
|
-
o = Object.assign({ validate: !0 }, o || {}),
|
|
89
|
+
o = Object.assign({ validate: !0 }, o || {}), r(
|
|
90
90
|
{
|
|
91
|
-
network:
|
|
92
|
-
output:
|
|
93
|
-
data:
|
|
91
|
+
network: r.maybe(r.Object),
|
|
92
|
+
output: r.maybe(r.Buffer),
|
|
93
|
+
data: r.maybe(r.arrayOf(r.Buffer))
|
|
94
94
|
},
|
|
95
95
|
e
|
|
96
96
|
);
|
|
97
|
-
const p = e.network || P,
|
|
98
|
-
if (h(
|
|
97
|
+
const p = e.network || P, i = { name: k.Embed, network: p, data: [] };
|
|
98
|
+
if (h(i, "output", () => {
|
|
99
99
|
if (e.data)
|
|
100
|
-
return
|
|
101
|
-
}), h(
|
|
100
|
+
return y([D.OP_RETURN].concat(e.data));
|
|
101
|
+
}), h(i, "data", () => {
|
|
102
102
|
if (!e.output) return;
|
|
103
|
-
const s =
|
|
103
|
+
const s = w(e.output);
|
|
104
104
|
if (s != null)
|
|
105
105
|
return s.slice(1);
|
|
106
106
|
}), o.validate && e.output) {
|
|
107
|
-
const s =
|
|
107
|
+
const s = w(e.output);
|
|
108
108
|
if (s[0] !== D.OP_RETURN) throw new TypeError("Output is invalid");
|
|
109
|
-
if (!s.slice(1).every(
|
|
110
|
-
if (e.data && !N(e.data,
|
|
111
|
-
throw new TypeError("Data mismatch");
|
|
109
|
+
if (!s.slice(1).every(r.Buffer)) throw new TypeError("Output is invalid");
|
|
110
|
+
if (e.data && !N(e.data, i.data)) throw new TypeError("Data mismatch");
|
|
112
111
|
}
|
|
113
|
-
return Object.assign(
|
|
112
|
+
return Object.assign(i, e);
|
|
114
113
|
}
|
|
115
114
|
const I = v, V = I.OP_RESERVED;
|
|
116
115
|
function Ee(e, o) {
|
|
@@ -120,15 +119,15 @@ function Ee(e, o) {
|
|
|
120
119
|
function p(f) {
|
|
121
120
|
return S(f) || (o.allowIncomplete && f === I.OP_0) !== void 0;
|
|
122
121
|
}
|
|
123
|
-
|
|
122
|
+
r(
|
|
124
123
|
{
|
|
125
|
-
network:
|
|
126
|
-
m:
|
|
127
|
-
n:
|
|
128
|
-
output:
|
|
129
|
-
pubkeys:
|
|
130
|
-
signatures:
|
|
131
|
-
input:
|
|
124
|
+
network: r.maybe(r.Object),
|
|
125
|
+
m: r.maybe(r.Number),
|
|
126
|
+
n: r.maybe(r.Number),
|
|
127
|
+
output: r.maybe(r.Buffer),
|
|
128
|
+
pubkeys: r.maybe(r.arrayOf(T)),
|
|
129
|
+
signatures: r.maybe(r.arrayOf(p)),
|
|
130
|
+
input: r.maybe(r.Buffer)
|
|
132
131
|
},
|
|
133
132
|
e
|
|
134
133
|
);
|
|
@@ -136,13 +135,13 @@ function Ee(e, o) {
|
|
|
136
135
|
network: e.network || P,
|
|
137
136
|
name: k.P2MS
|
|
138
137
|
};
|
|
139
|
-
let
|
|
140
|
-
function
|
|
141
|
-
n || (n = !0,
|
|
138
|
+
let u = [], n = !1;
|
|
139
|
+
function t(f) {
|
|
140
|
+
n || (n = !0, u = w(f), s.m = u[0] - V, s.n = u[u.length - 2] - V, s.pubkeys = u.slice(1, -2));
|
|
142
141
|
}
|
|
143
142
|
if (h(s, "output", () => {
|
|
144
143
|
if (e.m && s.n && e.pubkeys)
|
|
145
|
-
return
|
|
144
|
+
return y(
|
|
146
145
|
[].concat(
|
|
147
146
|
V + e.m,
|
|
148
147
|
e.pubkeys,
|
|
@@ -152,21 +151,21 @@ function Ee(e, o) {
|
|
|
152
151
|
);
|
|
153
152
|
}), h(s, "m", () => {
|
|
154
153
|
if (s.output)
|
|
155
|
-
return
|
|
154
|
+
return t(s.output), s.m;
|
|
156
155
|
}), h(s, "n", () => {
|
|
157
156
|
if (s.pubkeys)
|
|
158
157
|
return s.pubkeys.length;
|
|
159
158
|
}), h(s, "pubkeys", () => {
|
|
160
159
|
if (e.output)
|
|
161
|
-
return
|
|
160
|
+
return t(e.output), s.pubkeys;
|
|
162
161
|
}), h(s, "signatures", () => {
|
|
163
162
|
if (!e.input) return;
|
|
164
|
-
const f =
|
|
163
|
+
const f = w(e.input);
|
|
165
164
|
if (f != null)
|
|
166
165
|
return f.slice(1);
|
|
167
166
|
}), h(s, "input", () => {
|
|
168
167
|
if (e.signatures)
|
|
169
|
-
return
|
|
168
|
+
return y([I.OP_0].concat(e.signatures));
|
|
170
169
|
}), h(s, "witness", () => {
|
|
171
170
|
if (s.input)
|
|
172
171
|
return [];
|
|
@@ -175,11 +174,11 @@ function Ee(e, o) {
|
|
|
175
174
|
return `p2ms(${s.m} of ${s.n})`;
|
|
176
175
|
}), o.validate) {
|
|
177
176
|
if (e.output) {
|
|
178
|
-
if (
|
|
179
|
-
if (!
|
|
180
|
-
if (
|
|
177
|
+
if (t(e.output), !r.Number(u[0])) throw new TypeError("Output is invalid");
|
|
178
|
+
if (!r.Number(u[u.length - 2])) throw new TypeError("Output is invalid");
|
|
179
|
+
if (u[u.length - 1] !== I.OP_CHECKMULTISIG)
|
|
181
180
|
throw new TypeError("Output is invalid");
|
|
182
|
-
if (s.m <= 0 || s.n > 16 || s.m > s.n || s.n !==
|
|
181
|
+
if (s.m <= 0 || s.n > 16 || s.m > s.n || s.n !== u.length - 3)
|
|
183
182
|
throw new TypeError("Output is invalid");
|
|
184
183
|
if (!s.pubkeys.every((f) => T(f))) throw new TypeError("Output is invalid");
|
|
185
184
|
if (e.m !== void 0 && e.m !== s.m) throw new TypeError("m mismatch");
|
|
@@ -208,43 +207,43 @@ function Ee(e, o) {
|
|
|
208
207
|
}
|
|
209
208
|
return Object.assign(s, e);
|
|
210
209
|
}
|
|
211
|
-
const
|
|
210
|
+
const Q = v;
|
|
212
211
|
function Te(e, o) {
|
|
213
212
|
if (!e.input && !e.output && !e.pubkey && !e.input && !e.signature)
|
|
214
213
|
throw new TypeError("Not enough data");
|
|
215
|
-
o = Object.assign({ validate: !0 }, o || {}),
|
|
214
|
+
o = Object.assign({ validate: !0 }, o || {}), r(
|
|
216
215
|
{
|
|
217
|
-
network:
|
|
218
|
-
output:
|
|
219
|
-
pubkey:
|
|
220
|
-
signature:
|
|
221
|
-
input:
|
|
216
|
+
network: r.maybe(r.Object),
|
|
217
|
+
output: r.maybe(r.Buffer),
|
|
218
|
+
pubkey: r.maybe(T),
|
|
219
|
+
signature: r.maybe(S),
|
|
220
|
+
input: r.maybe(r.Buffer)
|
|
222
221
|
},
|
|
223
222
|
e
|
|
224
223
|
);
|
|
225
|
-
const p =
|
|
224
|
+
const p = l(() => w(e.input)), i = e.network || P, s = {
|
|
226
225
|
name: k.P2PK,
|
|
227
|
-
network:
|
|
226
|
+
network: i,
|
|
228
227
|
pubkey: void 0
|
|
229
228
|
};
|
|
230
229
|
if (h(s, "output", () => {
|
|
231
230
|
if (e.pubkey)
|
|
232
|
-
return
|
|
231
|
+
return y([e.pubkey, Q.OP_CHECKSIG]);
|
|
233
232
|
}), h(s, "pubkey", () => {
|
|
234
233
|
if (e.output)
|
|
235
|
-
return e.output.
|
|
234
|
+
return e.output.subarray(1, -1);
|
|
236
235
|
}), h(s, "signature", () => {
|
|
237
236
|
if (e.input)
|
|
238
237
|
return p()[0];
|
|
239
238
|
}), h(s, "input", () => {
|
|
240
239
|
if (e.signature)
|
|
241
|
-
return
|
|
240
|
+
return y([e.signature]);
|
|
242
241
|
}), h(s, "witness", () => {
|
|
243
242
|
if (s.input)
|
|
244
243
|
return [];
|
|
245
244
|
}), o.validate) {
|
|
246
245
|
if (e.output) {
|
|
247
|
-
if (e.output[e.output.length - 1] !==
|
|
246
|
+
if (e.output[e.output.length - 1] !== Q.OP_CHECKSIG)
|
|
248
247
|
throw new TypeError("Output is invalid");
|
|
249
248
|
if (!T(s.pubkey)) throw new TypeError("Output pubkey is invalid");
|
|
250
249
|
if (e.pubkey && !e.pubkey.equals(s.pubkey)) throw new TypeError("Pubkey mismatch");
|
|
@@ -263,114 +262,114 @@ const B = v;
|
|
|
263
262
|
function Pe(e, o) {
|
|
264
263
|
if (!e.address && !e.hash && !e.output && !e.redeem && !e.input)
|
|
265
264
|
throw new TypeError("Not enough data");
|
|
266
|
-
o = Object.assign({ validate: !0 }, o || {}),
|
|
265
|
+
o = Object.assign({ validate: !0 }, o || {}), r(
|
|
267
266
|
{
|
|
268
|
-
network:
|
|
269
|
-
address:
|
|
270
|
-
hash:
|
|
271
|
-
output:
|
|
272
|
-
redeem:
|
|
273
|
-
network:
|
|
274
|
-
output:
|
|
275
|
-
input:
|
|
276
|
-
witness:
|
|
267
|
+
network: r.maybe(r.Object),
|
|
268
|
+
address: r.maybe(r.String),
|
|
269
|
+
hash: r.maybe(r.BufferN(20)),
|
|
270
|
+
output: r.maybe(r.BufferN(23)),
|
|
271
|
+
redeem: r.maybe({
|
|
272
|
+
network: r.maybe(r.Object),
|
|
273
|
+
output: r.maybe(r.Buffer),
|
|
274
|
+
input: r.maybe(r.Buffer),
|
|
275
|
+
witness: r.maybe(r.arrayOf(r.Buffer))
|
|
277
276
|
}),
|
|
278
|
-
input:
|
|
279
|
-
witness:
|
|
277
|
+
input: r.maybe(r.Buffer),
|
|
278
|
+
witness: r.maybe(r.arrayOf(r.Buffer))
|
|
280
279
|
},
|
|
281
280
|
e
|
|
282
281
|
);
|
|
283
282
|
let p = e.network;
|
|
284
283
|
p || (p = e.redeem && e.redeem.network || P);
|
|
285
|
-
const
|
|
284
|
+
const i = {
|
|
286
285
|
network: p,
|
|
287
286
|
name: k.P2SH
|
|
288
|
-
}, s =
|
|
289
|
-
const
|
|
287
|
+
}, s = l(() => {
|
|
288
|
+
const t = m.from(x.decode(e.address)), f = t.readUInt8(0), d = t.subarray(1);
|
|
290
289
|
return { version: f, hash: d };
|
|
291
|
-
}),
|
|
292
|
-
const
|
|
290
|
+
}), u = l(() => w(e.input)), n = l(() => {
|
|
291
|
+
const t = u(), f = t[t.length - 1];
|
|
293
292
|
return {
|
|
294
293
|
network: p,
|
|
295
|
-
output: f === B.OP_FALSE ?
|
|
296
|
-
input:
|
|
294
|
+
output: f === B.OP_FALSE ? m.from([]) : f,
|
|
295
|
+
input: y(t.slice(0, -1)),
|
|
297
296
|
witness: e.witness || []
|
|
298
297
|
};
|
|
299
298
|
});
|
|
300
|
-
if (h(
|
|
301
|
-
if (!
|
|
302
|
-
const
|
|
303
|
-
return
|
|
304
|
-
}), h(
|
|
305
|
-
if (e.output) return e.output.
|
|
299
|
+
if (h(i, "address", () => {
|
|
300
|
+
if (!i.hash) return;
|
|
301
|
+
const t = m.allocUnsafe(21);
|
|
302
|
+
return t.writeUInt8(i.network.scriptHash, 0), i.hash.copy(t, 1), x.encode(t);
|
|
303
|
+
}), h(i, "hash", () => {
|
|
304
|
+
if (e.output) return e.output.subarray(2, 22);
|
|
306
305
|
if (e.address) return s().hash;
|
|
307
|
-
if (
|
|
308
|
-
}), h(
|
|
309
|
-
if (
|
|
310
|
-
return
|
|
311
|
-
}), h(
|
|
306
|
+
if (i.redeem && i.redeem.output) return E(i.redeem.output);
|
|
307
|
+
}), h(i, "output", () => {
|
|
308
|
+
if (i.hash)
|
|
309
|
+
return y([B.OP_HASH160, i.hash, B.OP_EQUAL]);
|
|
310
|
+
}), h(i, "redeem", () => {
|
|
312
311
|
if (e.input)
|
|
313
312
|
return n();
|
|
314
|
-
}), h(
|
|
313
|
+
}), h(i, "input", () => {
|
|
315
314
|
if (!(!e.redeem || !e.redeem.input || !e.redeem.output))
|
|
316
|
-
return
|
|
317
|
-
[].concat(
|
|
315
|
+
return y(
|
|
316
|
+
[].concat(w(e.redeem.input), e.redeem.output)
|
|
318
317
|
);
|
|
319
|
-
}), h(
|
|
320
|
-
if (
|
|
321
|
-
if (
|
|
322
|
-
}), h(
|
|
323
|
-
const
|
|
324
|
-
return
|
|
318
|
+
}), h(i, "witness", () => {
|
|
319
|
+
if (i.redeem && i.redeem.witness) return i.redeem.witness;
|
|
320
|
+
if (i.input) return [];
|
|
321
|
+
}), h(i, "name", () => {
|
|
322
|
+
const t = ["p2sh"];
|
|
323
|
+
return i.redeem !== void 0 && i.redeem.name !== void 0 && t.push(i.redeem.name), t.join("-");
|
|
325
324
|
}), o.validate) {
|
|
326
|
-
let
|
|
325
|
+
let t = m.from([]);
|
|
327
326
|
if (e.address) {
|
|
328
327
|
if (s().version !== p.scriptHash)
|
|
329
328
|
throw new TypeError("Invalid version or Network mismatch");
|
|
330
329
|
if (s().hash.length !== 20) throw new TypeError("Invalid address");
|
|
331
|
-
|
|
330
|
+
t = s().hash;
|
|
332
331
|
}
|
|
333
332
|
if (e.hash) {
|
|
334
|
-
if (
|
|
335
|
-
|
|
333
|
+
if (t.length > 0 && !t.equals(e.hash)) throw new TypeError("Hash mismatch");
|
|
334
|
+
t = e.hash;
|
|
336
335
|
}
|
|
337
336
|
if (e.output) {
|
|
338
337
|
if (e.output.length !== 23 || e.output[0] !== B.OP_HASH160 || e.output[1] !== 20 || e.output[22] !== B.OP_EQUAL)
|
|
339
338
|
throw new TypeError("Output is invalid");
|
|
340
|
-
const d = e.output.
|
|
341
|
-
if (
|
|
342
|
-
|
|
339
|
+
const d = e.output.subarray(2, 22);
|
|
340
|
+
if (t.length > 0 && !t.equals(d)) throw new TypeError("Hash mismatch");
|
|
341
|
+
t = d;
|
|
343
342
|
}
|
|
344
343
|
const f = (d) => {
|
|
345
344
|
if (d.output) {
|
|
346
|
-
const
|
|
347
|
-
if (!
|
|
345
|
+
const a = w(d.output);
|
|
346
|
+
if (!a || a.length < 1)
|
|
348
347
|
throw new TypeError("Redeem.output too short");
|
|
349
348
|
if (d.output.byteLength > 520)
|
|
350
349
|
throw new TypeError("Redeem.output unspendable if larger than 520 bytes");
|
|
351
|
-
if (
|
|
350
|
+
if (ue(a) > 201)
|
|
352
351
|
throw new TypeError(
|
|
353
352
|
"Redeem.output unspendable with more than 201 non-push ops"
|
|
354
353
|
);
|
|
355
|
-
const
|
|
356
|
-
if (
|
|
357
|
-
|
|
354
|
+
const c = E(d.output);
|
|
355
|
+
if (t.length > 0 && !t.equals(c)) throw new TypeError("Hash mismatch");
|
|
356
|
+
t = c;
|
|
358
357
|
}
|
|
359
358
|
if (d.input) {
|
|
360
|
-
const
|
|
361
|
-
if (!
|
|
362
|
-
if (
|
|
363
|
-
if (
|
|
364
|
-
const _ =
|
|
365
|
-
if (!
|
|
359
|
+
const a = d.input.length > 0, c = d.witness && d.witness.length > 0;
|
|
360
|
+
if (!a && !c) throw new TypeError("Empty input");
|
|
361
|
+
if (a && c) throw new TypeError("Input and witness provided");
|
|
362
|
+
if (a) {
|
|
363
|
+
const _ = w(d.input);
|
|
364
|
+
if (!ie(_))
|
|
366
365
|
throw new TypeError("Non push-only scriptSig");
|
|
367
366
|
}
|
|
368
367
|
}
|
|
369
368
|
};
|
|
370
369
|
if (e.input) {
|
|
371
|
-
const d =
|
|
370
|
+
const d = u();
|
|
372
371
|
if (!d || d.length < 1) throw new TypeError("Input too short");
|
|
373
|
-
if (!
|
|
372
|
+
if (!m.isBuffer(n().output)) throw new TypeError("Input is invalid");
|
|
374
373
|
f(n());
|
|
375
374
|
}
|
|
376
375
|
if (e.redeem) {
|
|
@@ -388,154 +387,156 @@ function Pe(e, o) {
|
|
|
388
387
|
if (e.witness && e.redeem && e.redeem.witness && !N(e.redeem.witness, e.witness))
|
|
389
388
|
throw new TypeError("Witness and redeem.witness mismatch");
|
|
390
389
|
}
|
|
391
|
-
return Object.assign(
|
|
390
|
+
return Object.assign(i, e);
|
|
392
391
|
}
|
|
393
|
-
const
|
|
392
|
+
const Y = v, z = 1, ve = 80;
|
|
394
393
|
function Oe(e, o) {
|
|
395
394
|
if (!e.address && !e.output && !e.pubkey && !e.internalPubkey && !(e.witness && e.witness.length > 1))
|
|
396
395
|
throw new TypeError("Not enough data");
|
|
397
|
-
o = Object.assign({ validate: !0 }, o || {}),
|
|
396
|
+
o = Object.assign({ validate: !0 }, o || {}), r(
|
|
398
397
|
{
|
|
399
|
-
address:
|
|
400
|
-
input:
|
|
401
|
-
network:
|
|
402
|
-
output:
|
|
403
|
-
internalPubkey:
|
|
404
|
-
hash:
|
|
398
|
+
address: r.maybe(r.String),
|
|
399
|
+
input: r.maybe(r.BufferN(0)),
|
|
400
|
+
network: r.maybe(r.Object),
|
|
401
|
+
output: r.maybe(r.BufferN(34)),
|
|
402
|
+
internalPubkey: r.maybe(r.BufferN(32)),
|
|
403
|
+
hash: r.maybe(r.BufferN(32)),
|
|
405
404
|
// merkle root hash, the tweak
|
|
406
|
-
pubkey:
|
|
405
|
+
pubkey: r.maybe(r.BufferN(32)),
|
|
407
406
|
// tweaked with `hash` from `internalPubkey`
|
|
408
|
-
signature:
|
|
409
|
-
witness:
|
|
410
|
-
scriptTree:
|
|
411
|
-
redeem:
|
|
412
|
-
output:
|
|
407
|
+
signature: r.maybe(r.anyOf(r.BufferN(64), r.BufferN(65))),
|
|
408
|
+
witness: r.maybe(r.arrayOf(r.Buffer)),
|
|
409
|
+
scriptTree: r.maybe(ce),
|
|
410
|
+
redeem: r.maybe({
|
|
411
|
+
output: r.maybe(r.Buffer),
|
|
413
412
|
// tapleaf script
|
|
414
|
-
redeemVersion:
|
|
413
|
+
redeemVersion: r.maybe(r.Number),
|
|
415
414
|
// tapleaf version
|
|
416
|
-
witness:
|
|
415
|
+
witness: r.maybe(r.arrayOf(r.Buffer))
|
|
417
416
|
}),
|
|
418
|
-
redeemVersion:
|
|
417
|
+
redeemVersion: r.maybe(r.Number)
|
|
419
418
|
},
|
|
420
419
|
e
|
|
421
420
|
);
|
|
422
|
-
const p =
|
|
421
|
+
const p = l(() => se(e.address)), i = l(() => {
|
|
423
422
|
if (!(!e.witness || !e.witness.length))
|
|
424
423
|
return e.witness.length >= 2 && e.witness[e.witness.length - 1][0] === ve ? e.witness.slice(0, -1) : e.witness.slice();
|
|
425
|
-
}), s =
|
|
424
|
+
}), s = l(() => {
|
|
426
425
|
if (e.scriptTree) return A(e.scriptTree);
|
|
427
426
|
if (e.hash) return { hash: e.hash };
|
|
428
|
-
}),
|
|
427
|
+
}), u = e.network || P, n = {
|
|
429
428
|
name: k.P2TR,
|
|
430
|
-
network:
|
|
429
|
+
network: u
|
|
431
430
|
};
|
|
432
431
|
if (h(n, "address", () => {
|
|
433
432
|
if (!n.pubkey) return;
|
|
434
|
-
const
|
|
435
|
-
return
|
|
433
|
+
const t = b.bech32m.toWords(n.pubkey);
|
|
434
|
+
return t.unshift(z), b.bech32m.encode(u.bech32, t);
|
|
436
435
|
}), h(n, "hash", () => {
|
|
437
|
-
const
|
|
438
|
-
if (
|
|
439
|
-
const f =
|
|
436
|
+
const t = s();
|
|
437
|
+
if (t) return t.hash;
|
|
438
|
+
const f = i();
|
|
440
439
|
if (f && f.length > 1) {
|
|
441
|
-
const d = f[f.length - 1],
|
|
442
|
-
output:
|
|
443
|
-
version:
|
|
440
|
+
const d = f[f.length - 1], a = d[0] & W, c = f[f.length - 2], _ = H({
|
|
441
|
+
output: c,
|
|
442
|
+
version: a
|
|
444
443
|
});
|
|
445
|
-
return
|
|
444
|
+
return L(d, _);
|
|
446
445
|
}
|
|
447
446
|
}), h(n, "output", () => {
|
|
448
447
|
if (n.pubkey)
|
|
449
|
-
return
|
|
450
|
-
}), h(n, "redeemVersion", () => e.redeemVersion ? e.redeemVersion : e.redeem && e.redeem.redeemVersion !== void 0 && e.redeem.redeemVersion !== null ? e.redeem.redeemVersion :
|
|
451
|
-
const
|
|
452
|
-
if (!(!
|
|
448
|
+
return y([Y.OP_1, n.pubkey]);
|
|
449
|
+
}), h(n, "redeemVersion", () => e.redeemVersion ? e.redeemVersion : e.redeem && e.redeem.redeemVersion !== void 0 && e.redeem.redeemVersion !== null ? e.redeem.redeemVersion : M), h(n, "redeem", () => {
|
|
450
|
+
const t = i();
|
|
451
|
+
if (!(!t || t.length < 2))
|
|
453
452
|
return {
|
|
454
|
-
output:
|
|
455
|
-
witness:
|
|
456
|
-
redeemVersion:
|
|
453
|
+
output: t[t.length - 2],
|
|
454
|
+
witness: t.slice(0, -2),
|
|
455
|
+
redeemVersion: t[t.length - 1][0] & W
|
|
457
456
|
};
|
|
458
457
|
}), h(n, "pubkey", () => {
|
|
459
458
|
if (e.pubkey) return e.pubkey;
|
|
460
|
-
if (e.output) return e.output.
|
|
459
|
+
if (e.output) return e.output.subarray(2);
|
|
461
460
|
if (e.address) return p().data;
|
|
462
461
|
if (n.internalPubkey) {
|
|
463
|
-
const
|
|
464
|
-
if (
|
|
462
|
+
const t = j(n.internalPubkey, n.hash);
|
|
463
|
+
if (t) return t.x;
|
|
465
464
|
}
|
|
466
465
|
}), h(n, "internalPubkey", () => {
|
|
467
466
|
if (e.internalPubkey) return e.internalPubkey;
|
|
468
|
-
const
|
|
469
|
-
if (
|
|
467
|
+
const t = i();
|
|
468
|
+
if (t && t.length > 1) return t[t.length - 1].subarray(1, 33);
|
|
470
469
|
}), h(n, "signature", () => {
|
|
471
470
|
if (e.signature) return e.signature;
|
|
472
|
-
const
|
|
473
|
-
if (!(!
|
|
474
|
-
return
|
|
471
|
+
const t = i();
|
|
472
|
+
if (!(!t || t.length !== 1))
|
|
473
|
+
return t[0];
|
|
475
474
|
}), h(n, "witness", () => {
|
|
476
475
|
if (e.witness) return e.witness;
|
|
477
|
-
const
|
|
478
|
-
if (
|
|
476
|
+
const t = s();
|
|
477
|
+
if (t && e.redeem && e.redeem.output && e.internalPubkey) {
|
|
479
478
|
const f = H({
|
|
480
479
|
output: e.redeem.output,
|
|
481
480
|
version: n.redeemVersion
|
|
482
|
-
}), d = q(
|
|
481
|
+
}), d = q(t, f);
|
|
483
482
|
if (!d) return;
|
|
484
|
-
const
|
|
485
|
-
if (!
|
|
486
|
-
const
|
|
487
|
-
[g.from([n.redeemVersion |
|
|
483
|
+
const a = j(e.internalPubkey, t.hash);
|
|
484
|
+
if (!a) return;
|
|
485
|
+
const c = g.concat(
|
|
486
|
+
[g.from([n.redeemVersion | a.parity]), e.internalPubkey].concat(
|
|
488
487
|
d
|
|
489
488
|
)
|
|
490
489
|
);
|
|
491
|
-
return [e.redeem.output,
|
|
490
|
+
return [e.redeem.output, c];
|
|
492
491
|
}
|
|
493
492
|
if (e.signature) return [e.signature];
|
|
494
493
|
}), o.validate) {
|
|
495
|
-
let
|
|
494
|
+
let t = g.from([]);
|
|
496
495
|
if (e.address) {
|
|
497
|
-
if (
|
|
496
|
+
if (u && u.bech32 !== p().prefix)
|
|
498
497
|
throw new TypeError("Invalid prefix or Network mismatch");
|
|
499
|
-
if (p().version !==
|
|
498
|
+
if (p().version !== z)
|
|
500
499
|
throw new TypeError("Invalid address version");
|
|
501
500
|
if (p().data.length !== 32) throw new TypeError("Invalid address data");
|
|
502
|
-
|
|
501
|
+
t = p().data;
|
|
503
502
|
}
|
|
504
503
|
if (e.pubkey) {
|
|
505
|
-
if (
|
|
504
|
+
if (t.length > 0 && !t.equals(e.pubkey))
|
|
506
505
|
throw new TypeError("Pubkey mismatch");
|
|
507
|
-
|
|
506
|
+
t = e.pubkey;
|
|
508
507
|
}
|
|
509
508
|
if (e.output) {
|
|
510
|
-
if (e.output.length !== 34 || e.output[0] !==
|
|
509
|
+
if (e.output.length !== 34 || e.output[0] !== Y.OP_1 || e.output[1] !== 32)
|
|
511
510
|
throw new TypeError("Output is invalid");
|
|
512
|
-
if (
|
|
511
|
+
if (t.length > 0 && !t.equals(e.output.subarray(2)))
|
|
513
512
|
throw new TypeError("Pubkey mismatch");
|
|
514
|
-
|
|
513
|
+
t = e.output.subarray(2);
|
|
515
514
|
}
|
|
516
515
|
if (e.internalPubkey) {
|
|
517
|
-
const
|
|
518
|
-
if (
|
|
516
|
+
const a = j(e.internalPubkey, n.hash);
|
|
517
|
+
if (t.length > 0 && !t.equals(a.x))
|
|
519
518
|
throw new TypeError("Pubkey mismatch");
|
|
520
|
-
|
|
519
|
+
t = a.x;
|
|
521
520
|
}
|
|
521
|
+
if (t && t.length && !K().isXOnlyPoint(t))
|
|
522
|
+
throw new TypeError("Invalid pubkey for p2tr");
|
|
522
523
|
const f = s();
|
|
523
524
|
if (e.hash && f && !e.hash.equals(f.hash))
|
|
524
525
|
throw new TypeError("Hash mismatch");
|
|
525
526
|
if (e.redeem && e.redeem.output && f) {
|
|
526
|
-
const
|
|
527
|
+
const a = H({
|
|
527
528
|
output: e.redeem.output,
|
|
528
529
|
version: n.redeemVersion
|
|
529
530
|
});
|
|
530
|
-
if (!q(f,
|
|
531
|
+
if (!q(f, a))
|
|
531
532
|
throw new TypeError("Redeem script not in tree");
|
|
532
533
|
}
|
|
533
|
-
const d =
|
|
534
|
+
const d = i();
|
|
534
535
|
if (e.redeem && n.redeem) {
|
|
535
536
|
if (e.redeem.redeemVersion && e.redeem.redeemVersion !== n.redeem.redeemVersion)
|
|
536
537
|
throw new TypeError("Redeem.redeemVersion and witness mismatch");
|
|
537
538
|
if (e.redeem.output) {
|
|
538
|
-
if (
|
|
539
|
+
if (w(e.redeem.output).length === 0)
|
|
539
540
|
throw new TypeError("Redeem.output is invalid");
|
|
540
541
|
if (n.redeem.output && !e.redeem.output.equals(n.redeem.output))
|
|
541
542
|
throw new TypeError("Redeem.output and witness mismatch");
|
|
@@ -548,75 +549,75 @@ function Oe(e, o) {
|
|
|
548
549
|
if (e.signature && !e.signature.equals(d[0]))
|
|
549
550
|
throw new TypeError("Signature mismatch");
|
|
550
551
|
} else {
|
|
551
|
-
const
|
|
552
|
-
if (
|
|
552
|
+
const a = d[d.length - 1];
|
|
553
|
+
if (a.length < 33)
|
|
553
554
|
throw new TypeError(
|
|
554
|
-
`The control-block length is too small. Got ${
|
|
555
|
+
`The control-block length is too small. Got ${a.length}, expected min 33.`
|
|
555
556
|
);
|
|
556
|
-
if ((
|
|
557
|
+
if ((a.length - 33) % 32 !== 0)
|
|
557
558
|
throw new TypeError(
|
|
558
|
-
`The control-block length of ${
|
|
559
|
+
`The control-block length of ${a.length} is incorrect!`
|
|
559
560
|
);
|
|
560
|
-
const
|
|
561
|
-
if (
|
|
562
|
-
throw new TypeError(`The script path is too long. Got ${
|
|
563
|
-
const _ =
|
|
561
|
+
const c = (a.length - 33) / 32;
|
|
562
|
+
if (c > 128)
|
|
563
|
+
throw new TypeError(`The script path is too long. Got ${c}, expected max 128.`);
|
|
564
|
+
const _ = a.subarray(1, 33);
|
|
564
565
|
if (e.internalPubkey && !e.internalPubkey.equals(_))
|
|
565
566
|
throw new TypeError("Internal pubkey mismatch");
|
|
566
|
-
if (!
|
|
567
|
+
if (!K().isXOnlyPoint(_))
|
|
567
568
|
throw new TypeError("Invalid internalPubkey for p2tr witness");
|
|
568
|
-
const he =
|
|
569
|
+
const he = a[0] & W, pe = d[d.length - 2], fe = H({
|
|
569
570
|
output: pe,
|
|
570
571
|
version: he
|
|
571
|
-
}), de =
|
|
572
|
+
}), de = L(a, fe), U = j(_, de);
|
|
572
573
|
if (!U)
|
|
573
574
|
throw new TypeError("Invalid outputKey for p2tr witness");
|
|
574
|
-
if (
|
|
575
|
+
if (t.length && !t.equals(U.x))
|
|
575
576
|
throw new TypeError("Pubkey mismatch for p2tr witness");
|
|
576
|
-
if (U.parity !== (
|
|
577
|
+
if (U.parity !== (a[0] & 1)) throw new Error("Incorrect parity");
|
|
577
578
|
}
|
|
578
579
|
}
|
|
579
580
|
return Object.assign(n, e);
|
|
580
581
|
}
|
|
581
|
-
const
|
|
582
|
+
const Z = v, _e = m.alloc(0);
|
|
582
583
|
function Se(e, o) {
|
|
583
584
|
if (!e.address && !e.hash && !e.output && !e.pubkey && !e.witness)
|
|
584
585
|
throw new TypeError("Not enough data");
|
|
585
|
-
o = Object.assign({ validate: !0 }, o || {}),
|
|
586
|
+
o = Object.assign({ validate: !0 }, o || {}), r(
|
|
586
587
|
{
|
|
587
|
-
address:
|
|
588
|
-
hash:
|
|
589
|
-
input:
|
|
590
|
-
network:
|
|
591
|
-
output:
|
|
592
|
-
pubkey:
|
|
593
|
-
signature:
|
|
594
|
-
witness:
|
|
588
|
+
address: r.maybe(r.String),
|
|
589
|
+
hash: r.maybe(r.BufferN(20)),
|
|
590
|
+
input: r.maybe(r.BufferN(0)),
|
|
591
|
+
network: r.maybe(r.Object),
|
|
592
|
+
output: r.maybe(r.BufferN(22)),
|
|
593
|
+
pubkey: r.maybe(T),
|
|
594
|
+
signature: r.maybe(S),
|
|
595
|
+
witness: r.maybe(r.arrayOf(r.Buffer))
|
|
595
596
|
},
|
|
596
597
|
e
|
|
597
598
|
);
|
|
598
|
-
const p =
|
|
599
|
-
const
|
|
599
|
+
const p = l(() => {
|
|
600
|
+
const u = b.bech32.decode(e.address), n = u.words.shift(), t = b.bech32.fromWords(u.words);
|
|
600
601
|
return {
|
|
601
602
|
version: n,
|
|
602
|
-
prefix:
|
|
603
|
-
data:
|
|
603
|
+
prefix: u.prefix,
|
|
604
|
+
data: m.from(t)
|
|
604
605
|
};
|
|
605
|
-
}),
|
|
606
|
+
}), i = e.network || P, s = {
|
|
606
607
|
name: k.P2WPKH,
|
|
607
|
-
network:
|
|
608
|
+
network: i
|
|
608
609
|
};
|
|
609
610
|
if (h(s, "address", () => {
|
|
610
611
|
if (!s.hash) return;
|
|
611
|
-
const
|
|
612
|
-
return
|
|
612
|
+
const u = b.bech32.toWords(s.hash);
|
|
613
|
+
return u.unshift(0), b.bech32.encode(i.bech32, u);
|
|
613
614
|
}), h(s, "hash", () => {
|
|
614
|
-
if (e.output) return e.output.
|
|
615
|
+
if (e.output) return e.output.subarray(2, 22);
|
|
615
616
|
if (e.address) return p().data;
|
|
616
617
|
if (e.pubkey || s.pubkey) return E(e.pubkey || s.pubkey);
|
|
617
618
|
}), h(s, "output", () => {
|
|
618
619
|
if (s.hash)
|
|
619
|
-
return
|
|
620
|
+
return y([Z.OP_0, s.hash]);
|
|
620
621
|
}), h(s, "pubkey", () => {
|
|
621
622
|
if (e.pubkey) return e.pubkey;
|
|
622
623
|
if (e.witness)
|
|
@@ -631,29 +632,29 @@ function Se(e, o) {
|
|
|
631
632
|
if (e.pubkey && e.signature)
|
|
632
633
|
return [e.signature, e.pubkey];
|
|
633
634
|
}), o.validate) {
|
|
634
|
-
let
|
|
635
|
+
let u = m.from([]);
|
|
635
636
|
if (e.address) {
|
|
636
|
-
if (
|
|
637
|
+
if (i && i.bech32 !== p().prefix)
|
|
637
638
|
throw new TypeError("Invalid prefix or Network mismatch");
|
|
638
639
|
if (p().version !== 0) throw new TypeError("Invalid address version");
|
|
639
640
|
if (p().data.length !== 20) throw new TypeError("Invalid address data");
|
|
640
|
-
|
|
641
|
+
u = p().data;
|
|
641
642
|
}
|
|
642
643
|
if (e.hash) {
|
|
643
|
-
if (
|
|
644
|
-
|
|
644
|
+
if (u.length > 0 && !u.equals(e.hash)) throw new TypeError("Hash mismatch");
|
|
645
|
+
u = e.hash;
|
|
645
646
|
}
|
|
646
647
|
if (e.output) {
|
|
647
|
-
if (e.output.length !== 22 || e.output[0] !==
|
|
648
|
+
if (e.output.length !== 22 || e.output[0] !== Z.OP_0 || e.output[1] !== 20)
|
|
648
649
|
throw new TypeError("Output is invalid");
|
|
649
|
-
if (
|
|
650
|
+
if (u.length > 0 && !u.equals(e.output.subarray(2)))
|
|
650
651
|
throw new TypeError("Hash mismatch");
|
|
651
|
-
|
|
652
|
+
u = e.output.subarray(2);
|
|
652
653
|
}
|
|
653
654
|
if (e.pubkey) {
|
|
654
655
|
const n = E(e.pubkey);
|
|
655
|
-
if (
|
|
656
|
-
if (
|
|
656
|
+
if (u.length > 0 && !u.equals(n)) throw new TypeError("Hash mismatch");
|
|
657
|
+
if (u = n, !T(e.pubkey) || e.pubkey.length !== 33)
|
|
657
658
|
throw new TypeError("Invalid pubkey for p2wpkh");
|
|
658
659
|
}
|
|
659
660
|
if (e.witness) {
|
|
@@ -666,82 +667,82 @@ function Se(e, o) {
|
|
|
666
667
|
throw new TypeError("Signature mismatch");
|
|
667
668
|
if (e.pubkey && !e.pubkey.equals(e.witness[1])) throw new TypeError("Pubkey mismatch");
|
|
668
669
|
const n = E(e.witness[1]);
|
|
669
|
-
if (
|
|
670
|
+
if (u.length > 0 && !u.equals(n)) throw new TypeError("Hash mismatch");
|
|
670
671
|
}
|
|
671
672
|
}
|
|
672
673
|
return Object.assign(s, e);
|
|
673
674
|
}
|
|
674
|
-
const
|
|
675
|
+
const J = v, $ = m.alloc(0);
|
|
675
676
|
function R(e) {
|
|
676
|
-
return !!(
|
|
677
|
+
return !!(m.isBuffer(e) && e.length === 65 && e[0] === 4 && T(e));
|
|
677
678
|
}
|
|
678
679
|
function Ie(e, o) {
|
|
679
680
|
if (!e.address && !e.hash && !e.output && !e.redeem && !e.witness)
|
|
680
681
|
throw new TypeError("Not enough data");
|
|
681
|
-
o = Object.assign({ validate: !0 }, o || {}),
|
|
682
|
+
o = Object.assign({ validate: !0 }, o || {}), r(
|
|
682
683
|
{
|
|
683
|
-
network:
|
|
684
|
-
address:
|
|
685
|
-
hash:
|
|
686
|
-
output:
|
|
687
|
-
redeem:
|
|
688
|
-
input:
|
|
689
|
-
network:
|
|
690
|
-
output:
|
|
691
|
-
witness:
|
|
684
|
+
network: r.maybe(r.Object),
|
|
685
|
+
address: r.maybe(r.String),
|
|
686
|
+
hash: r.maybe(r.BufferN(32)),
|
|
687
|
+
output: r.maybe(r.BufferN(34)),
|
|
688
|
+
redeem: r.maybe({
|
|
689
|
+
input: r.maybe(r.Buffer),
|
|
690
|
+
network: r.maybe(r.Object),
|
|
691
|
+
output: r.maybe(r.Buffer),
|
|
692
|
+
witness: r.maybe(r.arrayOf(r.Buffer))
|
|
692
693
|
}),
|
|
693
|
-
input:
|
|
694
|
-
witness:
|
|
694
|
+
input: r.maybe(r.BufferN(0)),
|
|
695
|
+
witness: r.maybe(r.arrayOf(r.Buffer))
|
|
695
696
|
},
|
|
696
697
|
e
|
|
697
698
|
);
|
|
698
|
-
const p =
|
|
699
|
-
const n = b.bech32.decode(e.address),
|
|
699
|
+
const p = l(() => {
|
|
700
|
+
const n = b.bech32.decode(e.address), t = n.words.shift(), f = b.bech32.fromWords(n.words);
|
|
700
701
|
return {
|
|
701
|
-
version:
|
|
702
|
+
version: t,
|
|
702
703
|
prefix: n.prefix,
|
|
703
|
-
data:
|
|
704
|
+
data: m.from(f)
|
|
704
705
|
};
|
|
705
|
-
}),
|
|
706
|
+
}), i = l(() => w(e.redeem.input));
|
|
706
707
|
let s = e.network;
|
|
707
708
|
s || (s = e.redeem && e.redeem.network || P);
|
|
708
|
-
const
|
|
709
|
+
const u = {
|
|
709
710
|
network: s,
|
|
710
711
|
name: k.P2WSH
|
|
711
712
|
};
|
|
712
|
-
if (h(
|
|
713
|
-
if (!
|
|
714
|
-
const n = b.bech32.toWords(
|
|
713
|
+
if (h(u, "address", () => {
|
|
714
|
+
if (!u.hash) return;
|
|
715
|
+
const n = b.bech32.toWords(u.hash);
|
|
715
716
|
return n.unshift(0), b.bech32.encode(s.bech32, n);
|
|
716
|
-
}), h(
|
|
717
|
-
if (e.output) return e.output.
|
|
717
|
+
}), h(u, "hash", () => {
|
|
718
|
+
if (e.output) return e.output.subarray(2);
|
|
718
719
|
if (e.address) return p().data;
|
|
719
|
-
if (
|
|
720
|
-
}), h(
|
|
721
|
-
if (
|
|
722
|
-
return
|
|
723
|
-
}), h(
|
|
720
|
+
if (u.redeem && u.redeem.output) return G(u.redeem.output);
|
|
721
|
+
}), h(u, "output", () => {
|
|
722
|
+
if (u.hash)
|
|
723
|
+
return y([J.OP_0, u.hash]);
|
|
724
|
+
}), h(u, "redeem", () => {
|
|
724
725
|
if (e.witness)
|
|
725
726
|
return {
|
|
726
727
|
output: e.witness[e.witness.length - 1],
|
|
727
728
|
input: $,
|
|
728
729
|
witness: e.witness.slice(0, -1)
|
|
729
730
|
};
|
|
730
|
-
}), h(
|
|
731
|
-
if (
|
|
731
|
+
}), h(u, "input", () => {
|
|
732
|
+
if (u.witness)
|
|
732
733
|
return $;
|
|
733
|
-
}), h(
|
|
734
|
+
}), h(u, "witness", () => {
|
|
734
735
|
if (e.redeem && e.redeem.input && e.redeem.input.length > 0 && e.redeem.output && e.redeem.output.length > 0) {
|
|
735
|
-
const n =
|
|
736
|
-
return
|
|
736
|
+
const n = ye(i());
|
|
737
|
+
return u.redeem = Object.assign({ witness: n }, e.redeem), u.redeem.input = $, [].concat(n, e.redeem.output);
|
|
737
738
|
}
|
|
738
739
|
if (e.redeem && e.redeem.output && e.redeem.witness)
|
|
739
740
|
return [].concat(e.redeem.witness, e.redeem.output);
|
|
740
|
-
}), h(
|
|
741
|
+
}), h(u, "name", () => {
|
|
741
742
|
const n = ["p2wsh"];
|
|
742
|
-
return
|
|
743
|
+
return u.redeem !== void 0 && u.redeem.name !== void 0 && n.push(u.redeem.name), n.join("-");
|
|
743
744
|
}), o.validate) {
|
|
744
|
-
let n =
|
|
745
|
+
let n = m.from([]);
|
|
745
746
|
if (e.address) {
|
|
746
747
|
if (p().prefix !== s.bech32)
|
|
747
748
|
throw new TypeError("Invalid prefix or Network mismatch");
|
|
@@ -754,11 +755,11 @@ function Ie(e, o) {
|
|
|
754
755
|
n = e.hash;
|
|
755
756
|
}
|
|
756
757
|
if (e.output) {
|
|
757
|
-
if (e.output.length !== 34 || e.output[0] !==
|
|
758
|
+
if (e.output.length !== 34 || e.output[0] !== J.OP_0 || e.output[1] !== 32)
|
|
758
759
|
throw new TypeError("Output is invalid");
|
|
759
|
-
const
|
|
760
|
-
if (n.length > 0 && !n.equals(
|
|
761
|
-
n =
|
|
760
|
+
const t = e.output.subarray(2);
|
|
761
|
+
if (n.length > 0 && !n.equals(t)) throw new TypeError("Hash mismatch");
|
|
762
|
+
n = t;
|
|
762
763
|
}
|
|
763
764
|
if (e.redeem) {
|
|
764
765
|
if (e.redeem.network && e.redeem.network !== s)
|
|
@@ -766,48 +767,48 @@ function Ie(e, o) {
|
|
|
766
767
|
if (e.redeem.input && e.redeem.input.length > 0 && e.redeem.witness && e.redeem.witness.length > 0)
|
|
767
768
|
throw new TypeError("Ambiguous witness source");
|
|
768
769
|
if (e.redeem.output) {
|
|
769
|
-
const
|
|
770
|
-
if (!
|
|
770
|
+
const t = w(e.redeem.output);
|
|
771
|
+
if (!t || t.length < 1)
|
|
771
772
|
throw new TypeError("Redeem.output is invalid");
|
|
772
773
|
if (e.redeem.output.byteLength > 3600)
|
|
773
774
|
throw new TypeError("Redeem.output unspendable if larger than 3600 bytes");
|
|
774
|
-
if (
|
|
775
|
+
if (ue(t) > 201)
|
|
775
776
|
throw new TypeError(
|
|
776
777
|
"Redeem.output unspendable with more than 201 non-push ops"
|
|
777
778
|
);
|
|
778
|
-
const f =
|
|
779
|
+
const f = G(e.redeem.output);
|
|
779
780
|
if (n.length > 0 && !n.equals(f)) throw new TypeError("Hash mismatch");
|
|
780
781
|
n = f;
|
|
781
782
|
}
|
|
782
|
-
if (e.redeem.input && !
|
|
783
|
+
if (e.redeem.input && !ie(i()))
|
|
783
784
|
throw new TypeError("Non push-only scriptSig");
|
|
784
785
|
if (e.witness && e.redeem.witness && !N(e.witness, e.redeem.witness))
|
|
785
786
|
throw new TypeError("Witness and redeem.witness mismatch");
|
|
786
|
-
if (e.redeem.input &&
|
|
787
|
+
if (e.redeem.input && i().some(R) || e.redeem.output && (w(e.redeem.output) || []).some(R))
|
|
787
788
|
throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey");
|
|
788
789
|
}
|
|
789
790
|
if (e.witness && e.witness.length > 0) {
|
|
790
|
-
const
|
|
791
|
-
if (e.redeem && e.redeem.output && !e.redeem.output.equals(
|
|
791
|
+
const t = e.witness[e.witness.length - 1];
|
|
792
|
+
if (e.redeem && e.redeem.output && !e.redeem.output.equals(t))
|
|
792
793
|
throw new TypeError("Witness and redeem.output mismatch");
|
|
793
|
-
if (e.witness.some(R) || (
|
|
794
|
+
if (e.witness.some(R) || (w(t) || []).some(R))
|
|
794
795
|
throw new TypeError("Witness contains uncompressed pubkey");
|
|
795
796
|
}
|
|
796
797
|
}
|
|
797
|
-
return Object.assign(
|
|
798
|
+
return Object.assign(u, e);
|
|
798
799
|
}
|
|
799
|
-
const
|
|
800
|
+
const ee = v, re = 16, te = 2, ne = 40;
|
|
800
801
|
function He(e, o) {
|
|
801
802
|
if (!e.address && !e.output && !e.program && (typeof e.deploymentVersion > "u" || !e.hash160))
|
|
802
803
|
throw new TypeError("At least one of address, output or program must be provided");
|
|
803
|
-
o = Object.assign({ validate: !0 }, o || {}),
|
|
804
|
+
o = Object.assign({ validate: !0 }, o || {}), r(
|
|
804
805
|
{
|
|
805
|
-
address:
|
|
806
|
-
output:
|
|
807
|
-
program:
|
|
808
|
-
network:
|
|
809
|
-
deploymentVersion:
|
|
810
|
-
hash160:
|
|
806
|
+
address: r.maybe(r.String),
|
|
807
|
+
output: r.maybe(r.Buffer),
|
|
808
|
+
program: r.maybe(r.Buffer),
|
|
809
|
+
network: r.maybe(r.Object),
|
|
810
|
+
deploymentVersion: r.maybe(r.Number),
|
|
811
|
+
hash160: r.maybe(r.BufferN(20))
|
|
811
812
|
},
|
|
812
813
|
e
|
|
813
814
|
);
|
|
@@ -816,135 +817,136 @@ function He(e, o) {
|
|
|
816
817
|
if (e.hash160.length !== 20) throw new TypeError("hash160 must be exactly 20 bytes");
|
|
817
818
|
if (e.deploymentVersion < 0 || e.deploymentVersion > 255)
|
|
818
819
|
throw new TypeError("deploymentVersion must fit in one byte");
|
|
819
|
-
return
|
|
820
|
+
return m.concat([m.of(e.deploymentVersion), e.hash160]);
|
|
820
821
|
}
|
|
821
|
-
},
|
|
822
|
+
}, i = l(() => se(e.address)), s = e.network || P, u = {
|
|
822
823
|
name: k.P2OP,
|
|
823
824
|
network: s,
|
|
824
825
|
deploymentVersion: 0
|
|
825
826
|
};
|
|
826
|
-
if (h(
|
|
827
|
+
if (h(u, "program", () => {
|
|
827
828
|
if (e.program) return e.program;
|
|
828
829
|
const n = p();
|
|
829
830
|
if (n) return n;
|
|
830
831
|
if (e.output) {
|
|
831
|
-
if (e.output[0] !==
|
|
832
|
-
let
|
|
832
|
+
if (e.output[0] !== ee.OP_16) throw new TypeError("Invalid P2OP script");
|
|
833
|
+
let t = 1, f;
|
|
833
834
|
if (e.output[1] < 76)
|
|
834
|
-
f = e.output[1],
|
|
835
|
+
f = e.output[1], t = 2;
|
|
835
836
|
else if (e.output[1] === 76)
|
|
836
|
-
f = e.output[2],
|
|
837
|
+
f = e.output[2], t = 3;
|
|
837
838
|
else
|
|
838
839
|
throw new TypeError("Unsupported push opcode in P2OP script");
|
|
839
|
-
return e.output.
|
|
840
|
+
return e.output.subarray(t, t + f);
|
|
840
841
|
}
|
|
841
842
|
if (e.address)
|
|
842
|
-
return
|
|
843
|
-
}), h(
|
|
844
|
-
if (
|
|
845
|
-
return
|
|
846
|
-
}), h(
|
|
847
|
-
if (
|
|
848
|
-
return
|
|
849
|
-
}), h(
|
|
850
|
-
if (
|
|
851
|
-
return
|
|
852
|
-
}), h(
|
|
853
|
-
if (!
|
|
843
|
+
return i().data;
|
|
844
|
+
}), h(u, "deploymentVersion", () => {
|
|
845
|
+
if (u.program)
|
|
846
|
+
return u.program[0];
|
|
847
|
+
}), h(u, "hash160", () => {
|
|
848
|
+
if (u.program)
|
|
849
|
+
return u.program.subarray(1);
|
|
850
|
+
}), h(u, "output", () => {
|
|
851
|
+
if (u.program)
|
|
852
|
+
return y([ee.OP_16, u.program]);
|
|
853
|
+
}), h(u, "address", () => {
|
|
854
|
+
if (!u.program) return;
|
|
854
855
|
if (!s.bech32Opnet)
|
|
855
856
|
throw new TypeError("Network does not support opnet");
|
|
856
|
-
const n = b.bech32m.toWords(
|
|
857
|
-
return n.unshift(
|
|
857
|
+
const n = b.bech32m.toWords(u.program);
|
|
858
|
+
return n.unshift(re), b.bech32m.encode(s.bech32Opnet, n);
|
|
858
859
|
}), o.validate) {
|
|
859
860
|
let n = g.alloc(0);
|
|
860
861
|
if (e.address) {
|
|
861
|
-
const
|
|
862
|
-
if (s.bech32Opnet !==
|
|
862
|
+
const t = i();
|
|
863
|
+
if (s.bech32Opnet !== t.prefix)
|
|
863
864
|
throw new TypeError("Invalid prefix or network mismatch");
|
|
864
|
-
if (
|
|
865
|
+
if (t.version !== re)
|
|
865
866
|
throw new TypeError("Invalid witness version for p2op");
|
|
866
|
-
if (
|
|
867
|
+
if (t.data.length < te || t.data.length > ne)
|
|
867
868
|
throw new TypeError("Invalid witness program length");
|
|
868
|
-
n =
|
|
869
|
+
n = t.data;
|
|
869
870
|
}
|
|
870
871
|
if (e.program) {
|
|
871
872
|
if (n.length && !n.equals(e.program)) throw new TypeError("Program mismatch");
|
|
872
873
|
n = e.program;
|
|
873
874
|
}
|
|
874
875
|
if (!n.length && e.deploymentVersion !== void 0 && e.hash160 && (n = p()), e.output) {
|
|
875
|
-
const
|
|
876
|
-
if (n.length && !n.equals(
|
|
876
|
+
const t = u.program;
|
|
877
|
+
if (n.length && !n.equals(t))
|
|
877
878
|
throw new TypeError("Program mismatch (output vs other source)");
|
|
878
|
-
n =
|
|
879
|
+
n = t;
|
|
879
880
|
}
|
|
880
|
-
if (n.length < te || n.length >
|
|
881
|
+
if (n.length < te || n.length > ne)
|
|
881
882
|
throw new TypeError(`Witness program must be 2–40 bytes. Was ${n.length} bytes`);
|
|
882
883
|
if (e.deploymentVersion !== void 0 && e.deploymentVersion !== n[0])
|
|
883
884
|
throw new TypeError("deploymentVersion mismatch");
|
|
884
|
-
if (e.hash160 && !e.hash160.equals(n.
|
|
885
|
+
if (e.hash160 && !e.hash160.equals(n.subarray(1)))
|
|
886
|
+
throw new TypeError("hash160 mismatch");
|
|
885
887
|
}
|
|
886
|
-
return Object.assign(
|
|
888
|
+
return Object.assign(u, e);
|
|
887
889
|
}
|
|
888
890
|
const O = v;
|
|
889
891
|
function Ne(e, o) {
|
|
890
892
|
if (!e.address && !e.hash && !e.output && !e.pubkey && !e.input)
|
|
891
893
|
throw new TypeError("Not enough data");
|
|
892
|
-
o = Object.assign({ validate: !0 }, o || {}),
|
|
894
|
+
o = Object.assign({ validate: !0 }, o || {}), r(
|
|
893
895
|
{
|
|
894
|
-
network:
|
|
895
|
-
address:
|
|
896
|
-
hash:
|
|
897
|
-
output:
|
|
898
|
-
pubkey:
|
|
899
|
-
signature:
|
|
900
|
-
input:
|
|
896
|
+
network: r.maybe(r.Object),
|
|
897
|
+
address: r.maybe(r.String),
|
|
898
|
+
hash: r.maybe(r.BufferN(20)),
|
|
899
|
+
output: r.maybe(r.BufferN(25)),
|
|
900
|
+
pubkey: r.maybe(T),
|
|
901
|
+
signature: r.maybe(S),
|
|
902
|
+
input: r.maybe(r.Buffer)
|
|
901
903
|
},
|
|
902
904
|
e
|
|
903
905
|
);
|
|
904
|
-
const p =
|
|
905
|
-
const n =
|
|
906
|
-
return { version:
|
|
907
|
-
}),
|
|
906
|
+
const p = l(() => {
|
|
907
|
+
const n = m.from(x.decode(e.address)), t = n.readUInt8(0), f = n.subarray(1);
|
|
908
|
+
return { version: t, hash: f };
|
|
909
|
+
}), i = l(() => w(e.input)), s = e.network || P, u = {
|
|
908
910
|
name: k.P2PKH,
|
|
909
911
|
network: s,
|
|
910
912
|
hash: void 0
|
|
911
913
|
};
|
|
912
|
-
if (h(
|
|
913
|
-
if (!
|
|
914
|
-
const n =
|
|
915
|
-
return n.writeUInt8(s.pubKeyHash, 0),
|
|
916
|
-
}), h(
|
|
917
|
-
if (e.output) return e.output.
|
|
914
|
+
if (h(u, "address", () => {
|
|
915
|
+
if (!u.hash) return;
|
|
916
|
+
const n = m.allocUnsafe(21);
|
|
917
|
+
return n.writeUInt8(s.pubKeyHash, 0), u.hash.copy(n, 1), x.encode(n);
|
|
918
|
+
}), h(u, "hash", () => {
|
|
919
|
+
if (e.output) return e.output.subarray(3, 23);
|
|
918
920
|
if (e.address) return p().hash;
|
|
919
|
-
if (e.pubkey ||
|
|
920
|
-
}), h(
|
|
921
|
-
if (
|
|
922
|
-
return
|
|
921
|
+
if (e.pubkey || u.pubkey) return E(e.pubkey || u.pubkey);
|
|
922
|
+
}), h(u, "output", () => {
|
|
923
|
+
if (u.hash)
|
|
924
|
+
return y([
|
|
923
925
|
O.OP_DUP,
|
|
924
926
|
O.OP_HASH160,
|
|
925
|
-
|
|
927
|
+
u.hash,
|
|
926
928
|
O.OP_EQUALVERIFY,
|
|
927
929
|
O.OP_CHECKSIG
|
|
928
930
|
]);
|
|
929
|
-
}), h(
|
|
931
|
+
}), h(u, "pubkey", () => {
|
|
930
932
|
if (e.input)
|
|
931
|
-
return
|
|
932
|
-
}), h(
|
|
933
|
+
return i()[1];
|
|
934
|
+
}), h(u, "signature", () => {
|
|
933
935
|
if (e.input)
|
|
934
|
-
return
|
|
935
|
-
}), h(
|
|
936
|
+
return i()[0];
|
|
937
|
+
}), h(u, "input", () => {
|
|
936
938
|
if (!e.pubkey || !e.signature) return;
|
|
937
939
|
let n = e.pubkey;
|
|
938
940
|
if (e.useHybrid || e.useUncompressed) {
|
|
939
|
-
const
|
|
940
|
-
|
|
941
|
+
const t = X(e.pubkey);
|
|
942
|
+
t && (e.useUncompressed ? n = t.uncompressed : n = t.hybrid);
|
|
941
943
|
}
|
|
942
|
-
return
|
|
943
|
-
}), h(
|
|
944
|
-
if (
|
|
944
|
+
return y([e.signature, n]);
|
|
945
|
+
}), h(u, "witness", () => {
|
|
946
|
+
if (u.input)
|
|
945
947
|
return [];
|
|
946
948
|
}), o.validate) {
|
|
947
|
-
let n =
|
|
949
|
+
let n = m.from([]);
|
|
948
950
|
if (e.address) {
|
|
949
951
|
if (p().version !== s.pubKeyHash)
|
|
950
952
|
throw new TypeError("Invalid version or Network mismatch");
|
|
@@ -960,50 +962,50 @@ function Ne(e, o) {
|
|
|
960
962
|
if (e.output) {
|
|
961
963
|
if (e.output.length !== 25 || e.output[0] !== O.OP_DUP || e.output[1] !== O.OP_HASH160 || e.output[2] !== 20 || e.output[23] !== O.OP_EQUALVERIFY || e.output[24] !== O.OP_CHECKSIG)
|
|
962
964
|
throw new TypeError("Output is invalid");
|
|
963
|
-
const
|
|
964
|
-
if (n.length > 0 && !n.equals(
|
|
965
|
-
n =
|
|
965
|
+
const t = e.output.subarray(3, 23);
|
|
966
|
+
if (n.length > 0 && !n.equals(t)) throw new TypeError("Hash mismatch");
|
|
967
|
+
n = t;
|
|
966
968
|
}
|
|
967
969
|
if (e.pubkey) {
|
|
968
|
-
const
|
|
969
|
-
let f = n.length > 0 && !n.equals(
|
|
970
|
+
const t = E(e.pubkey);
|
|
971
|
+
let f = n.length > 0 && !n.equals(t);
|
|
970
972
|
if (f && (e.pubkey.length === 33 && (e.pubkey[0] === 2 || e.pubkey[0] === 3) || e.pubkey.length === 65 && e.pubkey[0] === 4)) {
|
|
971
|
-
const d =
|
|
973
|
+
const d = X(e.pubkey);
|
|
972
974
|
if (d) {
|
|
973
|
-
const
|
|
974
|
-
if (n.equals(
|
|
975
|
+
const a = E(d.uncompressed);
|
|
976
|
+
if (n.equals(a))
|
|
975
977
|
f = !1, e.useUncompressed = !0;
|
|
976
978
|
else {
|
|
977
|
-
const
|
|
978
|
-
f = !n.equals(
|
|
979
|
+
const c = E(d.hybrid);
|
|
980
|
+
f = !n.equals(c), f || (e.useHybrid = !0);
|
|
979
981
|
}
|
|
980
982
|
}
|
|
981
983
|
}
|
|
982
984
|
if (f)
|
|
983
985
|
throw new TypeError("Hash mismatch");
|
|
984
|
-
n =
|
|
986
|
+
n = t;
|
|
985
987
|
}
|
|
986
988
|
if (e.input) {
|
|
987
|
-
const
|
|
988
|
-
if (
|
|
989
|
-
if (!S(
|
|
989
|
+
const t = i();
|
|
990
|
+
if (t.length !== 2) throw new TypeError("Input is invalid");
|
|
991
|
+
if (!S(t[0]))
|
|
990
992
|
throw new TypeError("Input has invalid signature");
|
|
991
|
-
if (!T(
|
|
992
|
-
if (e.signature && !e.signature.equals(
|
|
993
|
+
if (!T(t[1])) throw new TypeError("Input has invalid pubkey");
|
|
994
|
+
if (e.signature && !e.signature.equals(t[0]))
|
|
993
995
|
throw new TypeError("Signature mismatch");
|
|
994
|
-
if (e.pubkey && !e.pubkey.equals(
|
|
996
|
+
if (e.pubkey && !e.pubkey.equals(t[1]))
|
|
995
997
|
throw new TypeError("Pubkey mismatch");
|
|
996
|
-
const f = E(
|
|
998
|
+
const f = E(t[1]);
|
|
997
999
|
if (n.length > 0 && !n.equals(f)) throw new TypeError("Hash mismatch (input)");
|
|
998
1000
|
}
|
|
999
1001
|
}
|
|
1000
|
-
return Object.assign(
|
|
1002
|
+
return Object.assign(u, e);
|
|
1001
1003
|
}
|
|
1002
1004
|
var k = /* @__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))(k || {});
|
|
1003
1005
|
const Re = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1004
1006
|
__proto__: null,
|
|
1005
|
-
LEAF_VERSION_TAPSCRIPT:
|
|
1006
|
-
MAX_TAPTREE_DEPTH:
|
|
1007
|
+
LEAF_VERSION_TAPSCRIPT: M,
|
|
1008
|
+
MAX_TAPTREE_DEPTH: le,
|
|
1007
1009
|
PaymentType: k,
|
|
1008
1010
|
findScriptPath: q,
|
|
1009
1011
|
p2data: ke,
|
|
@@ -1016,16 +1018,16 @@ const Re = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
1016
1018
|
p2wpkh: Se,
|
|
1017
1019
|
p2wsh: Ie,
|
|
1018
1020
|
prop: h,
|
|
1019
|
-
rootHashFromPath:
|
|
1021
|
+
rootHashFromPath: L,
|
|
1020
1022
|
tapTweakHash: oe,
|
|
1021
1023
|
tapleafHash: H,
|
|
1022
1024
|
toHashTree: A,
|
|
1023
1025
|
tweakKey: j,
|
|
1024
|
-
value:
|
|
1026
|
+
value: l
|
|
1025
1027
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
1026
1028
|
export {
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
+
M as L,
|
|
1030
|
+
le as M,
|
|
1029
1031
|
k as P,
|
|
1030
1032
|
Pe as a,
|
|
1031
1033
|
Se as b,
|
|
@@ -1040,6 +1042,6 @@ export {
|
|
|
1040
1042
|
q as k,
|
|
1041
1043
|
oe as l,
|
|
1042
1044
|
Ne as p,
|
|
1043
|
-
|
|
1045
|
+
L as r,
|
|
1044
1046
|
j as t
|
|
1045
1047
|
};
|