@btc-vision/bitcoin 6.4.11 → 6.5.1
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/.babelrc +10 -1
- package/browser/chunks/crypto-C6FlKKmp.js +2006 -0
- package/browser/chunks/payments-BE4vwHhV.js +1045 -0
- package/browser/chunks/psbt-Dlosf9CT.js +3853 -0
- package/browser/chunks/script-COWGdiOo.js +318 -0
- package/browser/chunks/transaction-BiXwH2v4.js +421 -0
- package/browser/chunks/utils-BKmkTzNZ.js +759 -0
- package/browser/crypto/crypto.d.ts +1 -1
- package/browser/index.d.ts +7 -27
- package/browser/index.js +92 -2
- package/build/index.d.ts +7 -27
- package/build/index.js +2 -2
- package/package.json +12 -9
- package/src/index.ts +18 -40
- package/vite.config.browser.ts +93 -0
- package/browser/index.js.LICENSE.txt +0 -14
|
@@ -0,0 +1,3853 @@
|
|
|
1
|
+
import { s as _t, B as d, h as et, c as fr } from "./crypto-C6FlKKmp.js";
|
|
2
|
+
import { o as Ae, t as pr, c as hr, d as ce, i as _n, s as de, a as lr, b as dr } from "./script-COWGdiOo.js";
|
|
3
|
+
import { t as gr, a as yr, H as Sr, U as Er, i as wr, b as bn, c as bt, r as vn } from "./utils-BKmkTzNZ.js";
|
|
4
|
+
import { p as Te, a as _e, b as Ge, c as be, d as ve, e as In, t as Tr, f as qe, M as mn, L as _r, r as br, g as kn, h as De, i as vr } from "./payments-BE4vwHhV.js";
|
|
5
|
+
import { T as I, a as Ir } from "./transaction-BiXwH2v4.js";
|
|
6
|
+
const Ve = {
|
|
7
|
+
/**
|
|
8
|
+
* The message prefix used for signing Bitcoin messages.
|
|
9
|
+
*/
|
|
10
|
+
messagePrefix: `Bitcoin Signed Message:
|
|
11
|
+
`,
|
|
12
|
+
/**
|
|
13
|
+
* The Bech32 prefix used for Bitcoin addresses.
|
|
14
|
+
*/
|
|
15
|
+
bech32: "bc",
|
|
16
|
+
bech32Opnet: "op",
|
|
17
|
+
/**
|
|
18
|
+
* The BIP32 key prefixes for Bitcoin.
|
|
19
|
+
*/
|
|
20
|
+
bip32: {
|
|
21
|
+
/**
|
|
22
|
+
* The public key prefix for BIP32 extended public keys.
|
|
23
|
+
*/
|
|
24
|
+
public: 76067358,
|
|
25
|
+
/**
|
|
26
|
+
* The private key prefix for BIP32 extended private keys.
|
|
27
|
+
*/
|
|
28
|
+
private: 76066276
|
|
29
|
+
},
|
|
30
|
+
/**
|
|
31
|
+
* The prefix for Bitcoin public key hashes.
|
|
32
|
+
*/
|
|
33
|
+
pubKeyHash: 0,
|
|
34
|
+
/**
|
|
35
|
+
* The prefix for Bitcoin script hashes.
|
|
36
|
+
*/
|
|
37
|
+
scriptHash: 5,
|
|
38
|
+
/**
|
|
39
|
+
* The prefix for Bitcoin Wallet Import Format (WIF) private keys.
|
|
40
|
+
*/
|
|
41
|
+
wif: 128
|
|
42
|
+
}, mr = {
|
|
43
|
+
messagePrefix: `Bitcoin Signed Message:
|
|
44
|
+
`,
|
|
45
|
+
bech32: "bcrt",
|
|
46
|
+
bech32Opnet: "opr",
|
|
47
|
+
bip32: {
|
|
48
|
+
public: 70617039,
|
|
49
|
+
private: 70615956
|
|
50
|
+
},
|
|
51
|
+
pubKeyHash: 111,
|
|
52
|
+
scriptHash: 196,
|
|
53
|
+
wif: 239
|
|
54
|
+
}, kr = {
|
|
55
|
+
messagePrefix: `Bitcoin Signed Message:
|
|
56
|
+
`,
|
|
57
|
+
bech32: "tb",
|
|
58
|
+
bech32Opnet: "opt",
|
|
59
|
+
bip32: {
|
|
60
|
+
public: 70617039,
|
|
61
|
+
private: 70615956
|
|
62
|
+
},
|
|
63
|
+
pubKeyHash: 111,
|
|
64
|
+
scriptHash: 196,
|
|
65
|
+
wif: 239
|
|
66
|
+
}, Ar = {
|
|
67
|
+
messagePrefix: `Dogecoin Signed Message:
|
|
68
|
+
`,
|
|
69
|
+
bech32: "",
|
|
70
|
+
// Dogecoin does not currently use Bech32
|
|
71
|
+
bech32Opnet: "",
|
|
72
|
+
bip32: {
|
|
73
|
+
public: 49990397,
|
|
74
|
+
private: 49988504
|
|
75
|
+
},
|
|
76
|
+
pubKeyHash: 30,
|
|
77
|
+
scriptHash: 22,
|
|
78
|
+
wif: 158
|
|
79
|
+
}, Pr = {
|
|
80
|
+
messagePrefix: `Dogecoin Signed Message:
|
|
81
|
+
`,
|
|
82
|
+
bech32: "",
|
|
83
|
+
// Dogecoin testnet does not currently use Bech32
|
|
84
|
+
bech32Opnet: "",
|
|
85
|
+
bip32: {
|
|
86
|
+
public: 70429096,
|
|
87
|
+
private: 70427203
|
|
88
|
+
},
|
|
89
|
+
pubKeyHash: 113,
|
|
90
|
+
scriptHash: 196,
|
|
91
|
+
wif: 241
|
|
92
|
+
}, Or = {
|
|
93
|
+
messagePrefix: `Litecoin Signed Message:
|
|
94
|
+
`,
|
|
95
|
+
bech32: "ltc",
|
|
96
|
+
bech32Opnet: "opl",
|
|
97
|
+
bip32: {
|
|
98
|
+
public: 27108450,
|
|
99
|
+
private: 27106558
|
|
100
|
+
},
|
|
101
|
+
pubKeyHash: 48,
|
|
102
|
+
scriptHash: 50,
|
|
103
|
+
wif: 176
|
|
104
|
+
}, Cr = {
|
|
105
|
+
messagePrefix: `Litecoin Signed Message:
|
|
106
|
+
`,
|
|
107
|
+
bech32: "tltc",
|
|
108
|
+
bech32Opnet: "oplt",
|
|
109
|
+
bip32: {
|
|
110
|
+
public: 70709117,
|
|
111
|
+
private: 70711009
|
|
112
|
+
},
|
|
113
|
+
pubKeyHash: 111,
|
|
114
|
+
scriptHash: 58,
|
|
115
|
+
wif: 239
|
|
116
|
+
}, xr = {
|
|
117
|
+
messagePrefix: `Bitcoin Signed Message:
|
|
118
|
+
`,
|
|
119
|
+
// Cashaddr prefix differs from bech32 for general usage, but we can set it similarly.
|
|
120
|
+
// Actual cashaddr prefix is "bitcoincash", but this field is for bech32 which BCH doesn't fully use for segwit (it doesn't have segwit).
|
|
121
|
+
bech32: "bitcoincash",
|
|
122
|
+
bech32Opnet: "opbch",
|
|
123
|
+
bip32: {
|
|
124
|
+
public: 76067358,
|
|
125
|
+
private: 76066276
|
|
126
|
+
},
|
|
127
|
+
pubKeyHash: 0,
|
|
128
|
+
scriptHash: 5,
|
|
129
|
+
wif: 128
|
|
130
|
+
}, Nr = {
|
|
131
|
+
messagePrefix: `Bitcoin Signed Message:
|
|
132
|
+
`,
|
|
133
|
+
bech32: "bchtest",
|
|
134
|
+
bech32Opnet: "opbcht",
|
|
135
|
+
bip32: {
|
|
136
|
+
public: 70617039,
|
|
137
|
+
private: 70615956
|
|
138
|
+
},
|
|
139
|
+
pubKeyHash: 111,
|
|
140
|
+
scriptHash: 196,
|
|
141
|
+
wif: 239
|
|
142
|
+
}, Hr = {
|
|
143
|
+
// Historically Dash used DarkCoin message prefix, and most implementations use this:
|
|
144
|
+
// As of Dash Core 0.17, this has not changed in code.
|
|
145
|
+
messagePrefix: `DarkCoin Signed Message:
|
|
146
|
+
`,
|
|
147
|
+
bech32: "",
|
|
148
|
+
// Dash does not use Bech32
|
|
149
|
+
bech32Opnet: "",
|
|
150
|
+
bip32: {
|
|
151
|
+
public: 50221772,
|
|
152
|
+
private: 50221816
|
|
153
|
+
},
|
|
154
|
+
pubKeyHash: 76,
|
|
155
|
+
scriptHash: 16,
|
|
156
|
+
wif: 204
|
|
157
|
+
}, Ur = {
|
|
158
|
+
messagePrefix: `DarkCoin Signed Message:
|
|
159
|
+
`,
|
|
160
|
+
bech32: "",
|
|
161
|
+
// Dash testnet does not use Bech32
|
|
162
|
+
bech32Opnet: "",
|
|
163
|
+
bip32: {
|
|
164
|
+
public: 981492128,
|
|
165
|
+
private: 981489719
|
|
166
|
+
},
|
|
167
|
+
pubKeyHash: 140,
|
|
168
|
+
scriptHash: 19,
|
|
169
|
+
wif: 239
|
|
170
|
+
}, Rr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
171
|
+
__proto__: null,
|
|
172
|
+
bitcoin: Ve,
|
|
173
|
+
bitcoinCash: xr,
|
|
174
|
+
bitcoinCashTestnet: Nr,
|
|
175
|
+
dash: Hr,
|
|
176
|
+
dashTestnet: Ur,
|
|
177
|
+
dogecoin: Ar,
|
|
178
|
+
dogecoinTestnet: Pr,
|
|
179
|
+
litecoin: Or,
|
|
180
|
+
litecoinTestnet: Cr,
|
|
181
|
+
regtest: mr,
|
|
182
|
+
testnet: kr
|
|
183
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
184
|
+
var te = {}, vt;
|
|
185
|
+
function Fr() {
|
|
186
|
+
if (vt) return te;
|
|
187
|
+
vt = 1, Object.defineProperty(te, "__esModule", { value: !0 }), te.bech32m = te.bech32 = void 0;
|
|
188
|
+
const t = "qpzry9x8gf2tvdw0s3jn54khce6mua7l", e = {};
|
|
189
|
+
for (let u = 0; u < t.length; u++) {
|
|
190
|
+
const f = t.charAt(u);
|
|
191
|
+
e[f] = u;
|
|
192
|
+
}
|
|
193
|
+
function n(u) {
|
|
194
|
+
const f = u >> 25;
|
|
195
|
+
return (u & 33554431) << 5 ^ -(f >> 0 & 1) & 996825010 ^ -(f >> 1 & 1) & 642813549 ^ -(f >> 2 & 1) & 513874426 ^ -(f >> 3 & 1) & 1027748829 ^ -(f >> 4 & 1) & 705979059;
|
|
196
|
+
}
|
|
197
|
+
function r(u) {
|
|
198
|
+
let f = 1;
|
|
199
|
+
for (let p = 0; p < u.length; ++p) {
|
|
200
|
+
const y = u.charCodeAt(p);
|
|
201
|
+
if (y < 33 || y > 126)
|
|
202
|
+
return "Invalid prefix (" + u + ")";
|
|
203
|
+
f = n(f) ^ y >> 5;
|
|
204
|
+
}
|
|
205
|
+
f = n(f);
|
|
206
|
+
for (let p = 0; p < u.length; ++p) {
|
|
207
|
+
const y = u.charCodeAt(p);
|
|
208
|
+
f = n(f) ^ y & 31;
|
|
209
|
+
}
|
|
210
|
+
return f;
|
|
211
|
+
}
|
|
212
|
+
function a(u, f, p, y) {
|
|
213
|
+
let S = 0, h = 0;
|
|
214
|
+
const l = (1 << p) - 1, w = [];
|
|
215
|
+
for (let T = 0; T < u.length; ++T)
|
|
216
|
+
for (S = S << f | u[T], h += f; h >= p; )
|
|
217
|
+
h -= p, w.push(S >> h & l);
|
|
218
|
+
if (y)
|
|
219
|
+
h > 0 && w.push(S << p - h & l);
|
|
220
|
+
else {
|
|
221
|
+
if (h >= f)
|
|
222
|
+
return "Excess padding";
|
|
223
|
+
if (S << p - h & l)
|
|
224
|
+
return "Non-zero padding";
|
|
225
|
+
}
|
|
226
|
+
return w;
|
|
227
|
+
}
|
|
228
|
+
function o(u) {
|
|
229
|
+
return a(u, 8, 5, !0);
|
|
230
|
+
}
|
|
231
|
+
function i(u) {
|
|
232
|
+
const f = a(u, 5, 8, !1);
|
|
233
|
+
if (Array.isArray(f))
|
|
234
|
+
return f;
|
|
235
|
+
}
|
|
236
|
+
function s(u) {
|
|
237
|
+
const f = a(u, 5, 8, !1);
|
|
238
|
+
if (Array.isArray(f))
|
|
239
|
+
return f;
|
|
240
|
+
throw new Error(f);
|
|
241
|
+
}
|
|
242
|
+
function c(u) {
|
|
243
|
+
let f;
|
|
244
|
+
u === "bech32" ? f = 1 : f = 734539939;
|
|
245
|
+
function p(l, w, T) {
|
|
246
|
+
if (T = T || 90, l.length + 7 + w.length > T)
|
|
247
|
+
throw new TypeError("Exceeds length limit");
|
|
248
|
+
l = l.toLowerCase();
|
|
249
|
+
let g = r(l);
|
|
250
|
+
if (typeof g == "string")
|
|
251
|
+
throw new Error(g);
|
|
252
|
+
let E = l + "1";
|
|
253
|
+
for (let b = 0; b < w.length; ++b) {
|
|
254
|
+
const k = w[b];
|
|
255
|
+
if (k >> 5 !== 0)
|
|
256
|
+
throw new Error("Non 5-bit word");
|
|
257
|
+
g = n(g) ^ k, E += t.charAt(k);
|
|
258
|
+
}
|
|
259
|
+
for (let b = 0; b < 6; ++b)
|
|
260
|
+
g = n(g);
|
|
261
|
+
g ^= f;
|
|
262
|
+
for (let b = 0; b < 6; ++b) {
|
|
263
|
+
const k = g >> (5 - b) * 5 & 31;
|
|
264
|
+
E += t.charAt(k);
|
|
265
|
+
}
|
|
266
|
+
return E;
|
|
267
|
+
}
|
|
268
|
+
function y(l, w) {
|
|
269
|
+
if (w = w || 90, l.length < 8)
|
|
270
|
+
return l + " too short";
|
|
271
|
+
if (l.length > w)
|
|
272
|
+
return "Exceeds length limit";
|
|
273
|
+
const T = l.toLowerCase(), g = l.toUpperCase();
|
|
274
|
+
if (l !== T && l !== g)
|
|
275
|
+
return "Mixed-case string " + l;
|
|
276
|
+
l = T;
|
|
277
|
+
const E = l.lastIndexOf("1");
|
|
278
|
+
if (E === -1)
|
|
279
|
+
return "No separator character for " + l;
|
|
280
|
+
if (E === 0)
|
|
281
|
+
return "Missing prefix for " + l;
|
|
282
|
+
const b = l.slice(0, E), k = l.slice(E + 1);
|
|
283
|
+
if (k.length < 6)
|
|
284
|
+
return "Data too short";
|
|
285
|
+
let x = r(b);
|
|
286
|
+
if (typeof x == "string")
|
|
287
|
+
return x;
|
|
288
|
+
const v = [];
|
|
289
|
+
for (let m = 0; m < k.length; ++m) {
|
|
290
|
+
const U = k.charAt(m), R = e[U];
|
|
291
|
+
if (R === void 0)
|
|
292
|
+
return "Unknown character " + U;
|
|
293
|
+
x = n(x) ^ R, !(m + 6 >= k.length) && v.push(R);
|
|
294
|
+
}
|
|
295
|
+
return x !== f ? "Invalid checksum for " + l : { prefix: b, words: v };
|
|
296
|
+
}
|
|
297
|
+
function S(l, w) {
|
|
298
|
+
const T = y(l, w);
|
|
299
|
+
if (typeof T == "object")
|
|
300
|
+
return T;
|
|
301
|
+
}
|
|
302
|
+
function h(l, w) {
|
|
303
|
+
const T = y(l, w);
|
|
304
|
+
if (typeof T == "object")
|
|
305
|
+
return T;
|
|
306
|
+
throw new Error(T);
|
|
307
|
+
}
|
|
308
|
+
return {
|
|
309
|
+
decodeUnsafe: S,
|
|
310
|
+
decode: h,
|
|
311
|
+
encode: p,
|
|
312
|
+
toWords: o,
|
|
313
|
+
fromWordsUnsafe: i,
|
|
314
|
+
fromWords: s
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
return te.bech32 = c("bech32"), te.bech32m = c("bech32m"), te;
|
|
318
|
+
}
|
|
319
|
+
var L = Fr();
|
|
320
|
+
function Br(t) {
|
|
321
|
+
if (t.length >= 255)
|
|
322
|
+
throw new TypeError("Alphabet too long");
|
|
323
|
+
const e = new Uint8Array(256);
|
|
324
|
+
for (let u = 0; u < e.length; u++)
|
|
325
|
+
e[u] = 255;
|
|
326
|
+
for (let u = 0; u < t.length; u++) {
|
|
327
|
+
const f = t.charAt(u), p = f.charCodeAt(0);
|
|
328
|
+
if (e[p] !== 255)
|
|
329
|
+
throw new TypeError(f + " is ambiguous");
|
|
330
|
+
e[p] = u;
|
|
331
|
+
}
|
|
332
|
+
const n = t.length, r = t.charAt(0), a = Math.log(n) / Math.log(256), o = Math.log(256) / Math.log(n);
|
|
333
|
+
function i(u) {
|
|
334
|
+
if (u instanceof Uint8Array || (ArrayBuffer.isView(u) ? u = new Uint8Array(u.buffer, u.byteOffset, u.byteLength) : Array.isArray(u) && (u = Uint8Array.from(u))), !(u instanceof Uint8Array))
|
|
335
|
+
throw new TypeError("Expected Uint8Array");
|
|
336
|
+
if (u.length === 0)
|
|
337
|
+
return "";
|
|
338
|
+
let f = 0, p = 0, y = 0;
|
|
339
|
+
const S = u.length;
|
|
340
|
+
for (; y !== S && u[y] === 0; )
|
|
341
|
+
y++, f++;
|
|
342
|
+
const h = (S - y) * o + 1 >>> 0, l = new Uint8Array(h);
|
|
343
|
+
for (; y !== S; ) {
|
|
344
|
+
let g = u[y], E = 0;
|
|
345
|
+
for (let b = h - 1; (g !== 0 || E < p) && b !== -1; b--, E++)
|
|
346
|
+
g += 256 * l[b] >>> 0, l[b] = g % n >>> 0, g = g / n >>> 0;
|
|
347
|
+
if (g !== 0)
|
|
348
|
+
throw new Error("Non-zero carry");
|
|
349
|
+
p = E, y++;
|
|
350
|
+
}
|
|
351
|
+
let w = h - p;
|
|
352
|
+
for (; w !== h && l[w] === 0; )
|
|
353
|
+
w++;
|
|
354
|
+
let T = r.repeat(f);
|
|
355
|
+
for (; w < h; ++w)
|
|
356
|
+
T += t.charAt(l[w]);
|
|
357
|
+
return T;
|
|
358
|
+
}
|
|
359
|
+
function s(u) {
|
|
360
|
+
if (typeof u != "string")
|
|
361
|
+
throw new TypeError("Expected String");
|
|
362
|
+
if (u.length === 0)
|
|
363
|
+
return new Uint8Array();
|
|
364
|
+
let f = 0, p = 0, y = 0;
|
|
365
|
+
for (; u[f] === r; )
|
|
366
|
+
p++, f++;
|
|
367
|
+
const S = (u.length - f) * a + 1 >>> 0, h = new Uint8Array(S);
|
|
368
|
+
for (; u[f]; ) {
|
|
369
|
+
let g = e[u.charCodeAt(f)];
|
|
370
|
+
if (g === 255)
|
|
371
|
+
return;
|
|
372
|
+
let E = 0;
|
|
373
|
+
for (let b = S - 1; (g !== 0 || E < y) && b !== -1; b--, E++)
|
|
374
|
+
g += n * h[b] >>> 0, h[b] = g % 256 >>> 0, g = g / 256 >>> 0;
|
|
375
|
+
if (g !== 0)
|
|
376
|
+
throw new Error("Non-zero carry");
|
|
377
|
+
y = E, f++;
|
|
378
|
+
}
|
|
379
|
+
let l = S - y;
|
|
380
|
+
for (; l !== S && h[l] === 0; )
|
|
381
|
+
l++;
|
|
382
|
+
const w = new Uint8Array(p + (S - l));
|
|
383
|
+
let T = p;
|
|
384
|
+
for (; l !== S; )
|
|
385
|
+
w[T++] = h[l++];
|
|
386
|
+
return w;
|
|
387
|
+
}
|
|
388
|
+
function c(u) {
|
|
389
|
+
const f = s(u);
|
|
390
|
+
if (f)
|
|
391
|
+
return f;
|
|
392
|
+
throw new Error("Non-base" + n + " character");
|
|
393
|
+
}
|
|
394
|
+
return {
|
|
395
|
+
encode: i,
|
|
396
|
+
decodeUnsafe: s,
|
|
397
|
+
decode: c
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
var Kr = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
401
|
+
const tt = Br(Kr);
|
|
402
|
+
function Lr(t) {
|
|
403
|
+
function e(o) {
|
|
404
|
+
var i = Uint8Array.from(o), s = t(i), c = i.length + 4, u = new Uint8Array(c);
|
|
405
|
+
return u.set(i, 0), u.set(s.subarray(0, 4), i.length), tt.encode(u);
|
|
406
|
+
}
|
|
407
|
+
function n(o) {
|
|
408
|
+
var i = o.slice(0, -4), s = o.slice(-4), c = t(i);
|
|
409
|
+
if (!(s[0] ^ c[0] | s[1] ^ c[1] | s[2] ^ c[2] | s[3] ^ c[3]))
|
|
410
|
+
return i;
|
|
411
|
+
}
|
|
412
|
+
function r(o) {
|
|
413
|
+
var i = tt.decodeUnsafe(o);
|
|
414
|
+
if (i != null)
|
|
415
|
+
return n(i);
|
|
416
|
+
}
|
|
417
|
+
function a(o) {
|
|
418
|
+
var i = tt.decode(o), s = n(i);
|
|
419
|
+
if (s == null)
|
|
420
|
+
throw new Error("Invalid checksum");
|
|
421
|
+
return s;
|
|
422
|
+
}
|
|
423
|
+
return {
|
|
424
|
+
encode: e,
|
|
425
|
+
decode: a,
|
|
426
|
+
decodeUnsafe: r
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
function Mr(t) {
|
|
430
|
+
return _t(_t(t));
|
|
431
|
+
}
|
|
432
|
+
const An = Lr(Mr), Ie = 40, me = 2, ke = 15, Pn = 16, Me = 16, je = 2, ze = 80, Wr = "WARNING: Sending to a future segwit version address can lead to loss of funds. End users MUST be warned carefully in the GUI and asked if they wish to proceed with caution. Wallets should verify the segwit version from the output of fromBech32, then decide when it is safe to use which version of segwit.", On = (t) => {
|
|
433
|
+
try {
|
|
434
|
+
const e = d.from(t.subarray(2));
|
|
435
|
+
if (e.length < me || e.length > Ie)
|
|
436
|
+
throw new TypeError("Invalid program length for segwit address");
|
|
437
|
+
const n = t[0] - ze;
|
|
438
|
+
if (n < je || n > ke + 1)
|
|
439
|
+
throw new TypeError("Invalid version for segwit address");
|
|
440
|
+
if (n === 1) throw new TypeError("taproot");
|
|
441
|
+
return !0;
|
|
442
|
+
} catch {
|
|
443
|
+
}
|
|
444
|
+
return !1;
|
|
445
|
+
};
|
|
446
|
+
function Cn(t, e) {
|
|
447
|
+
if (!d.isBuffer(t)) throw new TypeError("output must be a Buffer");
|
|
448
|
+
if (!e.bech32Opnet) throw new Error("Network does not support opnet");
|
|
449
|
+
const n = t[0];
|
|
450
|
+
let r = 1, a;
|
|
451
|
+
if (t[1] < 76)
|
|
452
|
+
a = t[1], r = 2;
|
|
453
|
+
else if (t[1] === 76)
|
|
454
|
+
a = t[2], r = 3;
|
|
455
|
+
else
|
|
456
|
+
throw new TypeError("Unsupported push opcode in script");
|
|
457
|
+
const o = d.from(t.subarray(r, r + a));
|
|
458
|
+
if (o.length < me || o.length > Ie)
|
|
459
|
+
throw new TypeError("Invalid program length for segwit address");
|
|
460
|
+
const i = n === Ae.OP_0 ? 0 : n >= Ae.OP_1 && n <= Ae.OP_16 ? n - (Ae.OP_1 - 1) : -1;
|
|
461
|
+
if (i < ke || i > Pn)
|
|
462
|
+
throw new TypeError(`Invalid segwit version ${i}`);
|
|
463
|
+
const s = [i, ...L.bech32m.toWords(o)];
|
|
464
|
+
return L.bech32m.encode(e.bech32Opnet, s);
|
|
465
|
+
}
|
|
466
|
+
function xn(t, e) {
|
|
467
|
+
const n = d.from(t.subarray(2));
|
|
468
|
+
if (n.length < me || n.length > Ie)
|
|
469
|
+
throw new TypeError("Invalid program length for segwit address");
|
|
470
|
+
const r = t[0] - ze;
|
|
471
|
+
if (r < je || r > ke)
|
|
472
|
+
throw new TypeError("Invalid version for segwit address");
|
|
473
|
+
if (t[1] !== n.length)
|
|
474
|
+
throw new TypeError(`Invalid script for segwit address ${t[1]} !== ${n.length}`);
|
|
475
|
+
return Un(n, r, e.bech32, e.bech32Opnet);
|
|
476
|
+
}
|
|
477
|
+
function Nn(t) {
|
|
478
|
+
const e = d.from(An.decode(t));
|
|
479
|
+
if (e.length < 21) throw new TypeError(t + " is too short");
|
|
480
|
+
if (e.length > 21) throw new TypeError(t + " is too long");
|
|
481
|
+
const n = e.readUInt8(0), r = d.from(e.subarray(1));
|
|
482
|
+
return { version: n, hash: r };
|
|
483
|
+
}
|
|
484
|
+
function Hn(t) {
|
|
485
|
+
let e, n;
|
|
486
|
+
try {
|
|
487
|
+
e = L.bech32.decode(t);
|
|
488
|
+
} catch {
|
|
489
|
+
}
|
|
490
|
+
if (e) {
|
|
491
|
+
if (n = e.words[0], n !== 0) throw new TypeError(t + " uses wrong encoding");
|
|
492
|
+
} else if (e = L.bech32m.decode(t), n = e.words[0], n === 0) throw new TypeError(t + " uses wrong encoding");
|
|
493
|
+
const r = L.bech32.fromWords(e.words.slice(1));
|
|
494
|
+
return {
|
|
495
|
+
version: n,
|
|
496
|
+
prefix: e.prefix,
|
|
497
|
+
data: d.from(r)
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
function Xr(t, e) {
|
|
501
|
+
gr(yr(Sr, Er), arguments);
|
|
502
|
+
const n = d.allocUnsafe(21);
|
|
503
|
+
return n.writeUInt8(e, 0), t.copy(n, 1), An.encode(n);
|
|
504
|
+
}
|
|
505
|
+
function Un(t, e, n, r) {
|
|
506
|
+
const a = L.bech32.toWords(t);
|
|
507
|
+
return a.unshift(e), e === Me && r ? L.bech32m.encode(r, a) : e === 0 ? L.bech32.encode(n, a) : L.bech32m.encode(n, a);
|
|
508
|
+
}
|
|
509
|
+
function Rn(t, e) {
|
|
510
|
+
e = e || Ve;
|
|
511
|
+
try {
|
|
512
|
+
return Te({ output: t, network: e }).address;
|
|
513
|
+
} catch {
|
|
514
|
+
}
|
|
515
|
+
try {
|
|
516
|
+
return _e({ output: t, network: e }).address;
|
|
517
|
+
} catch {
|
|
518
|
+
}
|
|
519
|
+
try {
|
|
520
|
+
return Ge({ output: t, network: e }).address;
|
|
521
|
+
} catch {
|
|
522
|
+
}
|
|
523
|
+
try {
|
|
524
|
+
return be({ output: t, network: e }).address;
|
|
525
|
+
} catch {
|
|
526
|
+
}
|
|
527
|
+
try {
|
|
528
|
+
return ve({ output: t, network: e }).address;
|
|
529
|
+
} catch {
|
|
530
|
+
}
|
|
531
|
+
try {
|
|
532
|
+
return Cn(t, e);
|
|
533
|
+
} catch {
|
|
534
|
+
}
|
|
535
|
+
try {
|
|
536
|
+
return xn(t, e);
|
|
537
|
+
} catch {
|
|
538
|
+
}
|
|
539
|
+
throw new Error(pr(t) + " has no matching Address");
|
|
540
|
+
}
|
|
541
|
+
function Fn(t, e) {
|
|
542
|
+
e = e || Ve;
|
|
543
|
+
let n, r;
|
|
544
|
+
try {
|
|
545
|
+
n = Nn(t);
|
|
546
|
+
} catch {
|
|
547
|
+
}
|
|
548
|
+
if (n) {
|
|
549
|
+
if (n.version === e.pubKeyHash)
|
|
550
|
+
return Te({ hash: n.hash }).output;
|
|
551
|
+
if (n.version === e.scriptHash)
|
|
552
|
+
return _e({ hash: n.hash }).output;
|
|
553
|
+
} else {
|
|
554
|
+
try {
|
|
555
|
+
r = Hn(t);
|
|
556
|
+
} catch {
|
|
557
|
+
}
|
|
558
|
+
if (r) {
|
|
559
|
+
if (r.prefix !== e.bech32 && e.bech32Opnet && r.prefix !== e.bech32Opnet)
|
|
560
|
+
throw new Error(t + " has an invalid prefix");
|
|
561
|
+
if (r.version === 0) {
|
|
562
|
+
if (r.data.length === 20)
|
|
563
|
+
return Ge({ hash: r.data }).output;
|
|
564
|
+
if (r.data.length === 32)
|
|
565
|
+
return be({ hash: r.data }).output;
|
|
566
|
+
} else if (r.version === 1) {
|
|
567
|
+
if (r.data.length === 32)
|
|
568
|
+
return ve({ pubkey: r.data }).output;
|
|
569
|
+
} else if (r.version === Me) {
|
|
570
|
+
if (!e.bech32Opnet) throw new Error(t + " has an invalid prefix");
|
|
571
|
+
return In({
|
|
572
|
+
program: r.data,
|
|
573
|
+
network: e
|
|
574
|
+
}).output;
|
|
575
|
+
} else if (r.version >= je && r.version <= ke && r.data.length >= me && r.data.length <= Ie)
|
|
576
|
+
return r.version !== Me && console.warn(Wr), hr([
|
|
577
|
+
r.version + ze,
|
|
578
|
+
r.data
|
|
579
|
+
]);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
return d.from(t, "hex");
|
|
583
|
+
}
|
|
584
|
+
const Gr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
585
|
+
__proto__: null,
|
|
586
|
+
FUTURE_MAX_VERSION: Pn,
|
|
587
|
+
FUTURE_OPNET_VERSION: Me,
|
|
588
|
+
FUTURE_SEGWIT_MAX_SIZE: Ie,
|
|
589
|
+
FUTURE_SEGWIT_MAX_VERSION: ke,
|
|
590
|
+
FUTURE_SEGWIT_MIN_SIZE: me,
|
|
591
|
+
FUTURE_SEGWIT_MIN_VERSION: je,
|
|
592
|
+
FUTURE_SEGWIT_VERSION_DIFF: ze,
|
|
593
|
+
_toFutureSegwitAddress: xn,
|
|
594
|
+
fromBase58Check: Nn,
|
|
595
|
+
fromBech32: Hn,
|
|
596
|
+
fromOutputScript: Rn,
|
|
597
|
+
isUnknownSegwitVersion: On,
|
|
598
|
+
toBase58Check: Xr,
|
|
599
|
+
toBech32: Un,
|
|
600
|
+
toFutureOPNetAddress: Cn,
|
|
601
|
+
toOutputScript: Fn
|
|
602
|
+
}, Symbol.toStringTag, { value: "Module" })), ge = {};
|
|
603
|
+
function wi(t) {
|
|
604
|
+
t ? t !== ge.eccLib && (qr(t), ge.eccLib = t) : ge.eccLib = t;
|
|
605
|
+
}
|
|
606
|
+
function Ti() {
|
|
607
|
+
if (!ge.eccLib)
|
|
608
|
+
throw new Error(
|
|
609
|
+
"No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance"
|
|
610
|
+
);
|
|
611
|
+
return ge.eccLib;
|
|
612
|
+
}
|
|
613
|
+
const F = (t) => d.from(t, "hex");
|
|
614
|
+
function qr(t) {
|
|
615
|
+
N(typeof t.isXOnlyPoint == "function"), N(t.isXOnlyPoint(F("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))), N(t.isXOnlyPoint(F("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))), N(t.isXOnlyPoint(F("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))), N(t.isXOnlyPoint(F("0000000000000000000000000000000000000000000000000000000000000001"))), N(
|
|
616
|
+
!t.isXOnlyPoint(F("0000000000000000000000000000000000000000000000000000000000000000"))
|
|
617
|
+
), N(
|
|
618
|
+
!t.isXOnlyPoint(F("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))
|
|
619
|
+
), N(typeof t.xOnlyPointAddTweak == "function"), Dr.forEach((e) => {
|
|
620
|
+
const n = t.xOnlyPointAddTweak(F(e.pubkey), F(e.tweak));
|
|
621
|
+
e.result === null ? N(n === null) : (N(n !== null), N(n.parity === e.parity), N(d.from(n.xOnlyPubkey).equals(F(e.result))));
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
function N(t) {
|
|
625
|
+
if (!t) throw new Error("ecc library invalid");
|
|
626
|
+
}
|
|
627
|
+
const Dr = [
|
|
628
|
+
{
|
|
629
|
+
pubkey: "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
|
|
630
|
+
tweak: "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",
|
|
631
|
+
parity: -1,
|
|
632
|
+
result: null
|
|
633
|
+
},
|
|
634
|
+
{
|
|
635
|
+
pubkey: "1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b",
|
|
636
|
+
tweak: "a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac",
|
|
637
|
+
parity: 1,
|
|
638
|
+
result: "e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"
|
|
639
|
+
},
|
|
640
|
+
{
|
|
641
|
+
pubkey: "2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991",
|
|
642
|
+
tweak: "823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47",
|
|
643
|
+
parity: 0,
|
|
644
|
+
result: "9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"
|
|
645
|
+
}
|
|
646
|
+
];
|
|
647
|
+
const gt = 2n ** 256n, se = gt - 0x1000003d1n, Vr = gt - 0x14551231950b75fc4402da1732fc9bebfn, jr = 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n, zr = 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n, Bn = {
|
|
648
|
+
a: 0n,
|
|
649
|
+
b: 7n
|
|
650
|
+
}, ye = 32, It = (t) => _(_(t * t) * t + Bn.b), P = (t = "") => {
|
|
651
|
+
throw new Error(t);
|
|
652
|
+
}, Ye = (t) => typeof t == "bigint", Kn = (t) => typeof t == "string", nt = (t) => Ye(t) && 0n < t && t < se, Ln = (t) => Ye(t) && 0n < t && t < Vr, Yr = (t) => t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array", ut = (t, e) => (
|
|
653
|
+
// assert is Uint8Array (of specific length)
|
|
654
|
+
!Yr(t) || typeof e == "number" && e > 0 && t.length !== e ? P("Uint8Array expected") : t
|
|
655
|
+
), Mn = (t) => new Uint8Array(t), Wn = (t, e) => ut(Kn(t) ? yt(t) : Mn(ut(t)), e), _ = (t, e = se) => {
|
|
656
|
+
const n = t % e;
|
|
657
|
+
return n >= 0n ? n : e + n;
|
|
658
|
+
}, mt = (t) => t instanceof C ? t : P("Point expected");
|
|
659
|
+
class C {
|
|
660
|
+
constructor(e, n, r) {
|
|
661
|
+
this.px = e, this.py = n, this.pz = r, Object.freeze(this);
|
|
662
|
+
}
|
|
663
|
+
/** Create 3d xyz point from 2d xy. (0, 0) => (0, 1, 0), not (0, 0, 1) */
|
|
664
|
+
static fromAffine(e) {
|
|
665
|
+
return e.x === 0n && e.y === 0n ? le : new C(e.x, e.y, 1n);
|
|
666
|
+
}
|
|
667
|
+
/** Convert Uint8Array or hex string to Point. */
|
|
668
|
+
static fromHex(e) {
|
|
669
|
+
e = Wn(e);
|
|
670
|
+
let n;
|
|
671
|
+
const r = e[0], a = e.subarray(1), o = At(a, 0, ye), i = e.length;
|
|
672
|
+
if (i === 33 && [2, 3].includes(r)) {
|
|
673
|
+
nt(o) || P("Point hex invalid: x not FE");
|
|
674
|
+
let s = Jr(It(o));
|
|
675
|
+
const c = (s & 1n) === 1n;
|
|
676
|
+
(r & 1) === 1 !== c && (s = _(-s)), n = new C(o, s, 1n);
|
|
677
|
+
}
|
|
678
|
+
return i === 65 && r === 4 && (n = new C(o, At(a, ye, 2 * ye), 1n)), n ? n.ok() : P("Point invalid: not on curve");
|
|
679
|
+
}
|
|
680
|
+
/** Create point from a private key. */
|
|
681
|
+
static fromPrivateKey(e) {
|
|
682
|
+
return Se.mul(Qr(e));
|
|
683
|
+
}
|
|
684
|
+
get x() {
|
|
685
|
+
return this.aff().x;
|
|
686
|
+
}
|
|
687
|
+
// .x, .y will call expensive toAffine:
|
|
688
|
+
get y() {
|
|
689
|
+
return this.aff().y;
|
|
690
|
+
}
|
|
691
|
+
// should be used with care.
|
|
692
|
+
/** Equality check: compare points P&Q. */
|
|
693
|
+
equals(e) {
|
|
694
|
+
const { px: n, py: r, pz: a } = this, { px: o, py: i, pz: s } = mt(e), c = _(n * s), u = _(o * a), f = _(r * s), p = _(i * a);
|
|
695
|
+
return c === u && f === p;
|
|
696
|
+
}
|
|
697
|
+
/** Flip point over y coordinate. */
|
|
698
|
+
negate() {
|
|
699
|
+
return new C(this.px, _(-this.py), this.pz);
|
|
700
|
+
}
|
|
701
|
+
/** Point doubling: P+P, complete formula. */
|
|
702
|
+
double() {
|
|
703
|
+
return this.add(this);
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* Point addition: P+Q, complete, exception-free formula
|
|
707
|
+
* (Renes-Costello-Batina, algo 1 of [2015/1060](https://eprint.iacr.org/2015/1060)).
|
|
708
|
+
* Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
709
|
+
*/
|
|
710
|
+
add(e) {
|
|
711
|
+
const { px: n, py: r, pz: a } = this, { px: o, py: i, pz: s } = mt(e), { a: c, b: u } = Bn;
|
|
712
|
+
let f = 0n, p = 0n, y = 0n;
|
|
713
|
+
const S = _(u * 3n);
|
|
714
|
+
let h = _(n * o), l = _(r * i), w = _(a * s), T = _(n + r), g = _(o + i);
|
|
715
|
+
T = _(T * g), g = _(h + l), T = _(T - g), g = _(n + a);
|
|
716
|
+
let E = _(o + s);
|
|
717
|
+
return g = _(g * E), E = _(h + w), g = _(g - E), E = _(r + a), f = _(i + s), E = _(E * f), f = _(l + w), E = _(E - f), y = _(c * g), f = _(S * w), y = _(f + y), f = _(l - y), y = _(l + y), p = _(f * y), l = _(h + h), l = _(l + h), w = _(c * w), g = _(S * g), l = _(l + w), w = _(h - w), w = _(c * w), g = _(g + w), h = _(l * g), p = _(p + h), h = _(E * g), f = _(T * f), f = _(f - h), h = _(T * l), y = _(E * y), y = _(y + h), new C(f, p, y);
|
|
718
|
+
}
|
|
719
|
+
mul(e, n = !0) {
|
|
720
|
+
if (!n && e === 0n)
|
|
721
|
+
return le;
|
|
722
|
+
if (Ln(e) || P("scalar invalid"), this.equals(Se))
|
|
723
|
+
return to(e).p;
|
|
724
|
+
let r = le, a = Se;
|
|
725
|
+
for (let o = this; e > 0n; o = o.double(), e >>= 1n)
|
|
726
|
+
e & 1n ? r = r.add(o) : n && (a = a.add(o));
|
|
727
|
+
return r;
|
|
728
|
+
}
|
|
729
|
+
mulAddQUns(e, n, r) {
|
|
730
|
+
return this.mul(n, !1).add(e.mul(r, !1)).ok();
|
|
731
|
+
}
|
|
732
|
+
// to private keys. Doesn't use Shamir trick
|
|
733
|
+
/** Convert point to 2d xy affine point. (x, y, z) ∋ (x=x/z, y=y/z) */
|
|
734
|
+
toAffine() {
|
|
735
|
+
const { px: e, py: n, pz: r } = this;
|
|
736
|
+
if (this.equals(le))
|
|
737
|
+
return { x: 0n, y: 0n };
|
|
738
|
+
if (r === 1n)
|
|
739
|
+
return { x: e, y: n };
|
|
740
|
+
const a = Zr(r, se);
|
|
741
|
+
return _(r * a) !== 1n && P("inverse invalid"), { x: _(e * a), y: _(n * a) };
|
|
742
|
+
}
|
|
743
|
+
/** Checks if the point is valid and on-curve. */
|
|
744
|
+
assertValidity() {
|
|
745
|
+
const { x: e, y: n } = this.aff();
|
|
746
|
+
return (!nt(e) || !nt(n)) && P("Point invalid: x or y"), _(n * n) === It(e) ? (
|
|
747
|
+
// y² = x³ + ax + b, must be equal
|
|
748
|
+
this
|
|
749
|
+
) : P("Point invalid: not on curve");
|
|
750
|
+
}
|
|
751
|
+
multiply(e) {
|
|
752
|
+
return this.mul(e);
|
|
753
|
+
}
|
|
754
|
+
// Aliases to compress code
|
|
755
|
+
aff() {
|
|
756
|
+
return this.toAffine();
|
|
757
|
+
}
|
|
758
|
+
ok() {
|
|
759
|
+
return this.assertValidity();
|
|
760
|
+
}
|
|
761
|
+
toHex(e = !0) {
|
|
762
|
+
const { x: n, y: r } = this.aff();
|
|
763
|
+
return (e ? (r & 1n) === 0n ? "02" : "03" : "04") + Pt(n) + (e ? "" : Pt(r));
|
|
764
|
+
}
|
|
765
|
+
toRawBytes(e = !0) {
|
|
766
|
+
return yt(this.toHex(e));
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
C.BASE = new C(jr, zr, 1n);
|
|
770
|
+
C.ZERO = new C(0n, 1n, 0n);
|
|
771
|
+
const { BASE: Se, ZERO: le } = C, Xn = (t, e) => t.toString(16).padStart(e, "0"), Gn = (t) => Array.from(ut(t)).map((e) => Xn(e, 2)).join(""), B = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 }, kt = (t) => {
|
|
772
|
+
if (t >= B._0 && t <= B._9)
|
|
773
|
+
return t - B._0;
|
|
774
|
+
if (t >= B.A && t <= B.F)
|
|
775
|
+
return t - (B.A - 10);
|
|
776
|
+
if (t >= B.a && t <= B.f)
|
|
777
|
+
return t - (B.a - 10);
|
|
778
|
+
}, yt = (t) => {
|
|
779
|
+
const e = "hex invalid";
|
|
780
|
+
if (!Kn(t))
|
|
781
|
+
return P(e);
|
|
782
|
+
const n = t.length, r = n / 2;
|
|
783
|
+
if (n % 2)
|
|
784
|
+
return P(e);
|
|
785
|
+
const a = Mn(r);
|
|
786
|
+
for (let o = 0, i = 0; o < r; o++, i += 2) {
|
|
787
|
+
const s = kt(t.charCodeAt(i)), c = kt(t.charCodeAt(i + 1));
|
|
788
|
+
if (s === void 0 || c === void 0)
|
|
789
|
+
return P(e);
|
|
790
|
+
a[o] = s * 16 + c;
|
|
791
|
+
}
|
|
792
|
+
return a;
|
|
793
|
+
}, qn = (t) => BigInt("0x" + (Gn(t) || "0")), At = (t, e, n) => qn(t.slice(e, n)), $r = (t) => Ye(t) && t >= 0n && t < gt ? yt(Xn(t, 2 * ye)) : P("bigint expected"), Pt = (t) => Gn($r(t)), Zr = (t, e) => {
|
|
794
|
+
(t === 0n || e <= 0n) && P("no inverse n=" + t + " mod=" + e);
|
|
795
|
+
let n = _(t, e), r = e, a = 0n, o = 1n;
|
|
796
|
+
for (; n !== 0n; ) {
|
|
797
|
+
const i = r / n, s = r % n, c = a - o * i;
|
|
798
|
+
r = n, n = s, a = o, o = c;
|
|
799
|
+
}
|
|
800
|
+
return r === 1n ? _(a, e) : P("no inverse");
|
|
801
|
+
}, Jr = (t) => {
|
|
802
|
+
let e = 1n;
|
|
803
|
+
for (let n = t, r = (se + 1n) / 4n; r > 0n; r >>= 1n)
|
|
804
|
+
r & 1n && (e = e * n % se), n = n * n % se;
|
|
805
|
+
return _(e * e) === t ? e : P("sqrt invalid");
|
|
806
|
+
}, Qr = (t) => (Ye(t) || (t = qn(Wn(t, ye))), Ln(t) ? t : P("private key invalid 3")), ne = 8, eo = () => {
|
|
807
|
+
const t = [], e = 256 / ne + 1;
|
|
808
|
+
let n = Se, r = n;
|
|
809
|
+
for (let a = 0; a < e; a++) {
|
|
810
|
+
r = n, t.push(r);
|
|
811
|
+
for (let o = 1; o < 2 ** (ne - 1); o++)
|
|
812
|
+
r = r.add(n), t.push(r);
|
|
813
|
+
n = r.double();
|
|
814
|
+
}
|
|
815
|
+
return t;
|
|
816
|
+
};
|
|
817
|
+
let Ot;
|
|
818
|
+
const to = (t) => {
|
|
819
|
+
const e = Ot || (Ot = eo()), n = (f, p) => {
|
|
820
|
+
let y = p.negate();
|
|
821
|
+
return f ? y : p;
|
|
822
|
+
};
|
|
823
|
+
let r = le, a = Se;
|
|
824
|
+
const o = 1 + 256 / ne, i = 2 ** (ne - 1), s = BigInt(2 ** ne - 1), c = 2 ** ne, u = BigInt(ne);
|
|
825
|
+
for (let f = 0; f < o; f++) {
|
|
826
|
+
const p = f * i;
|
|
827
|
+
let y = Number(t & s);
|
|
828
|
+
t >>= u, y > i && (y -= c, t += 1n);
|
|
829
|
+
const S = p, h = p + Math.abs(y) - 1, l = f % 2 !== 0, w = y < 0;
|
|
830
|
+
y === 0 ? a = a.add(n(l, e[S])) : r = r.add(n(w, e[h]));
|
|
831
|
+
}
|
|
832
|
+
return { p: r, f: a };
|
|
833
|
+
};
|
|
834
|
+
var re = {}, Ct;
|
|
835
|
+
function ue() {
|
|
836
|
+
if (Ct) return re;
|
|
837
|
+
Ct = 1, Object.defineProperty(re, "__esModule", { value: !0 });
|
|
838
|
+
const t = 9007199254740991;
|
|
839
|
+
function e(o) {
|
|
840
|
+
if (o < 0 || o > t || o % 1 !== 0)
|
|
841
|
+
throw new RangeError("value out of range");
|
|
842
|
+
}
|
|
843
|
+
function n(o, i, s) {
|
|
844
|
+
if (e(o), i || (i = d.allocUnsafe(a(o))), !d.isBuffer(i))
|
|
845
|
+
throw new TypeError("buffer must be a Buffer instance");
|
|
846
|
+
return s || (s = 0), o < 253 ? (i.writeUInt8(o, s), Object.assign(n, { bytes: 1 })) : o <= 65535 ? (i.writeUInt8(253, s), i.writeUInt16LE(o, s + 1), Object.assign(n, { bytes: 3 })) : o <= 4294967295 ? (i.writeUInt8(254, s), i.writeUInt32LE(o, s + 1), Object.assign(n, { bytes: 5 })) : (i.writeUInt8(255, s), i.writeUInt32LE(o >>> 0, s + 1), i.writeUInt32LE(o / 4294967296 | 0, s + 5), Object.assign(n, { bytes: 9 })), i;
|
|
847
|
+
}
|
|
848
|
+
re.encode = n;
|
|
849
|
+
function r(o, i) {
|
|
850
|
+
if (!d.isBuffer(o))
|
|
851
|
+
throw new TypeError("buffer must be a Buffer instance");
|
|
852
|
+
i || (i = 0);
|
|
853
|
+
const s = o.readUInt8(i);
|
|
854
|
+
if (s < 253)
|
|
855
|
+
return Object.assign(r, { bytes: 1 }), s;
|
|
856
|
+
if (s === 253)
|
|
857
|
+
return Object.assign(r, { bytes: 3 }), o.readUInt16LE(i + 1);
|
|
858
|
+
if (s === 254)
|
|
859
|
+
return Object.assign(r, { bytes: 5 }), o.readUInt32LE(i + 1);
|
|
860
|
+
{
|
|
861
|
+
Object.assign(r, { bytes: 9 });
|
|
862
|
+
const c = o.readUInt32LE(i + 1), f = o.readUInt32LE(i + 5) * 4294967296 + c;
|
|
863
|
+
return e(f), f;
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
re.decode = r;
|
|
867
|
+
function a(o) {
|
|
868
|
+
return e(o), o < 253 ? 1 : o <= 65535 ? 3 : o <= 4294967295 ? 5 : 9;
|
|
869
|
+
}
|
|
870
|
+
return re.encodingLength = a, re;
|
|
871
|
+
}
|
|
872
|
+
var We = ue();
|
|
873
|
+
const Ee = (t) => {
|
|
874
|
+
const e = t.length === 32 ? t : t.slice(1, 33);
|
|
875
|
+
return d.isBuffer(e) ? e : d.from(e);
|
|
876
|
+
};
|
|
877
|
+
function xt(t, e, n) {
|
|
878
|
+
const r = yo(e, t, n);
|
|
879
|
+
try {
|
|
880
|
+
const o = lo(e, r).concat(r.script).concat(r.controlBlock);
|
|
881
|
+
return { finalScriptWitness: we(o) };
|
|
882
|
+
} catch (a) {
|
|
883
|
+
throw new Error(`Can not finalize taproot input #${t}: ${a}`);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
function Pe(t, e) {
|
|
887
|
+
const n = e ? d.from([e]) : d.from([]);
|
|
888
|
+
return d.concat([t, n]);
|
|
889
|
+
}
|
|
890
|
+
function H(t) {
|
|
891
|
+
return t && !!(t.tapInternalKey || t.tapMerkleRoot || t.tapLeafScript && t.tapLeafScript.length || t.tapBip32Derivation && t.tapBip32Derivation.length || t.witnessUtxo && St(t.witnessUtxo.script));
|
|
892
|
+
}
|
|
893
|
+
function rt(t, e) {
|
|
894
|
+
return t && !!(t.tapInternalKey || t.tapTree || t.tapBip32Derivation && t.tapBip32Derivation.length || e && St(e));
|
|
895
|
+
}
|
|
896
|
+
function Nt(t, e, n) {
|
|
897
|
+
fo(t, e, n), ho(t, e, n);
|
|
898
|
+
}
|
|
899
|
+
function Ht(t, e, n) {
|
|
900
|
+
po(t, e, n), no(t, e);
|
|
901
|
+
}
|
|
902
|
+
function no(t, e) {
|
|
903
|
+
if (!e.tapTree && !e.tapInternalKey) return;
|
|
904
|
+
const n = e.tapInternalKey || t.tapInternalKey, r = e.tapTree || t.tapTree;
|
|
905
|
+
if (n) {
|
|
906
|
+
const { script: a } = t, o = ro(n, r);
|
|
907
|
+
if (a && !a.equals(o))
|
|
908
|
+
throw new Error("Error adding output. Script or address missmatch.");
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
function ro(t, e) {
|
|
912
|
+
const n = e && oo(e.leaves), { output: r } = ve({
|
|
913
|
+
internalPubkey: t,
|
|
914
|
+
scriptTree: n
|
|
915
|
+
});
|
|
916
|
+
return r;
|
|
917
|
+
}
|
|
918
|
+
function _i(t, e) {
|
|
919
|
+
const n = e.tapInternalKey, r = n && Tr(n, e.tapMerkleRoot);
|
|
920
|
+
if (!r)
|
|
921
|
+
throw new Error(
|
|
922
|
+
`Cannot tweak tap internal key for input #${t}. Public key: ${n && n.toString("hex")}`
|
|
923
|
+
);
|
|
924
|
+
return r.x;
|
|
925
|
+
}
|
|
926
|
+
function bi(t) {
|
|
927
|
+
if (!wr(t))
|
|
928
|
+
throw new Error("Cannot convert taptree to tapleaf list. Expecting a tapree structure.");
|
|
929
|
+
return ft(t);
|
|
930
|
+
}
|
|
931
|
+
function oo(t = []) {
|
|
932
|
+
return t.length === 1 && t[0].depth === 0 ? {
|
|
933
|
+
output: t[0].script,
|
|
934
|
+
version: t[0].leafVersion
|
|
935
|
+
} : uo(t);
|
|
936
|
+
}
|
|
937
|
+
function io(t, e) {
|
|
938
|
+
return ao(t).some((r) => jn(r, so, e));
|
|
939
|
+
}
|
|
940
|
+
function so(t) {
|
|
941
|
+
return {
|
|
942
|
+
signature: t.slice(0, 64),
|
|
943
|
+
hashType: t.slice(64)[0] || I.SIGHASH_DEFAULT
|
|
944
|
+
};
|
|
945
|
+
}
|
|
946
|
+
function ao(t) {
|
|
947
|
+
const e = [];
|
|
948
|
+
if (t.tapKeySig && e.push(t.tapKeySig), t.tapScriptSig && e.push(...t.tapScriptSig.map((n) => n.signature)), !e.length) {
|
|
949
|
+
const n = co(t.finalScriptWitness);
|
|
950
|
+
n && e.push(n);
|
|
951
|
+
}
|
|
952
|
+
return e;
|
|
953
|
+
}
|
|
954
|
+
function co(t) {
|
|
955
|
+
if (!t) return;
|
|
956
|
+
const e = t.slice(2);
|
|
957
|
+
if (e.length === 64 || e.length === 65) return e;
|
|
958
|
+
}
|
|
959
|
+
function ft(t, e = [], n = 0) {
|
|
960
|
+
if (n > mn) throw new Error("Max taptree depth exceeded.");
|
|
961
|
+
return t ? bn(t) ? (e.push({
|
|
962
|
+
depth: n,
|
|
963
|
+
leafVersion: t.version || _r,
|
|
964
|
+
script: t.output
|
|
965
|
+
}), e) : (t[0] && ft(t[0], e, n + 1), t[1] && ft(t[1], e, n + 1), e) : [];
|
|
966
|
+
}
|
|
967
|
+
function uo(t) {
|
|
968
|
+
let e;
|
|
969
|
+
for (const n of t)
|
|
970
|
+
if (e = pt(n, e), !e) throw new Error("No room left to insert tapleaf in tree");
|
|
971
|
+
return e;
|
|
972
|
+
}
|
|
973
|
+
function pt(t, e, n = 0) {
|
|
974
|
+
if (n > mn) throw new Error("Max taptree depth exceeded.");
|
|
975
|
+
if (t.depth === n)
|
|
976
|
+
return e ? void 0 : {
|
|
977
|
+
output: t.script,
|
|
978
|
+
version: t.leafVersion
|
|
979
|
+
};
|
|
980
|
+
if (bn(e)) return;
|
|
981
|
+
const r = pt(t, e && e[0], n + 1);
|
|
982
|
+
if (r) return [r, e && e[1]];
|
|
983
|
+
const a = pt(t, e && e[1], n + 1);
|
|
984
|
+
if (a) return [e && e[0], a];
|
|
985
|
+
}
|
|
986
|
+
function fo(t, e, n) {
|
|
987
|
+
const r = H(t) && ae(e), a = ae(t) && H(e), o = t === e && H(e) && ae(e);
|
|
988
|
+
if (r || a || o)
|
|
989
|
+
throw new Error(
|
|
990
|
+
`Invalid arguments for Psbt.${n}. Cannot use both taproot and non-taproot fields.`
|
|
991
|
+
);
|
|
992
|
+
}
|
|
993
|
+
function po(t, e, n) {
|
|
994
|
+
const r = rt(t) && ae(e), a = ae(t) && rt(e), o = t === e && rt(e) && ae(e);
|
|
995
|
+
if (r || a || o)
|
|
996
|
+
throw new Error(
|
|
997
|
+
`Invalid arguments for Psbt.${n}. Cannot use both taproot and non-taproot fields.`
|
|
998
|
+
);
|
|
999
|
+
}
|
|
1000
|
+
function ho(t, e, n) {
|
|
1001
|
+
if (e.tapMerkleRoot) {
|
|
1002
|
+
const r = (e.tapLeafScript || []).every(
|
|
1003
|
+
(o) => ot(o, e.tapMerkleRoot)
|
|
1004
|
+
), a = (t.tapLeafScript || []).every(
|
|
1005
|
+
(o) => ot(o, e.tapMerkleRoot)
|
|
1006
|
+
);
|
|
1007
|
+
if (!r || !a)
|
|
1008
|
+
throw new Error(`Invalid arguments for Psbt.${n}. Tapleaf not part of taptree.`);
|
|
1009
|
+
} else if (t.tapMerkleRoot && !(e.tapLeafScript || []).every(
|
|
1010
|
+
(a) => ot(a, t.tapMerkleRoot)
|
|
1011
|
+
))
|
|
1012
|
+
throw new Error(`Invalid arguments for Psbt.${n}. Tapleaf not part of taptree.`);
|
|
1013
|
+
}
|
|
1014
|
+
function ot(t, e) {
|
|
1015
|
+
if (!e) return !0;
|
|
1016
|
+
const n = qe({
|
|
1017
|
+
output: t.script,
|
|
1018
|
+
version: t.leafVersion
|
|
1019
|
+
});
|
|
1020
|
+
return br(t.controlBlock, n).equals(e);
|
|
1021
|
+
}
|
|
1022
|
+
function lo(t, e) {
|
|
1023
|
+
const n = qe({
|
|
1024
|
+
output: e.script,
|
|
1025
|
+
version: e.leafVersion
|
|
1026
|
+
});
|
|
1027
|
+
return (t.tapScriptSig || []).filter((r) => r.leafHash.equals(n)).map((r) => go(e.script, r)).sort((r, a) => a.positionInScript - r.positionInScript).map((r) => r.signature);
|
|
1028
|
+
}
|
|
1029
|
+
function go(t, e) {
|
|
1030
|
+
return Object.assign(
|
|
1031
|
+
{
|
|
1032
|
+
positionInScript: Vn(e.pubkey, t)
|
|
1033
|
+
},
|
|
1034
|
+
e
|
|
1035
|
+
);
|
|
1036
|
+
}
|
|
1037
|
+
function yo(t, e, n) {
|
|
1038
|
+
if (!t.tapScriptSig || !t.tapScriptSig.length)
|
|
1039
|
+
throw new Error(
|
|
1040
|
+
`Can not finalize taproot input #${e}. No tapleaf script signature provided.`
|
|
1041
|
+
);
|
|
1042
|
+
const r = (t.tapLeafScript || []).sort((a, o) => a.controlBlock.length - o.controlBlock.length).find((a) => So(a, t.tapScriptSig, n));
|
|
1043
|
+
if (!r)
|
|
1044
|
+
throw new Error(
|
|
1045
|
+
`Can not finalize taproot input #${e}. Signature for tapleaf script not found.`
|
|
1046
|
+
);
|
|
1047
|
+
return r;
|
|
1048
|
+
}
|
|
1049
|
+
function So(t, e, n) {
|
|
1050
|
+
const r = qe({
|
|
1051
|
+
output: t.script,
|
|
1052
|
+
version: t.leafVersion
|
|
1053
|
+
});
|
|
1054
|
+
return (!n || n.equals(r)) && e.find((o) => o.leafHash.equals(r)) !== void 0;
|
|
1055
|
+
}
|
|
1056
|
+
function ae(t) {
|
|
1057
|
+
return t && !!(t.redeemScript || t.witnessScript || t.bip32Derivation && t.bip32Derivation.length);
|
|
1058
|
+
}
|
|
1059
|
+
function Q(t) {
|
|
1060
|
+
return (e) => {
|
|
1061
|
+
try {
|
|
1062
|
+
return t({ output: e }), !0;
|
|
1063
|
+
} catch {
|
|
1064
|
+
return !1;
|
|
1065
|
+
}
|
|
1066
|
+
};
|
|
1067
|
+
}
|
|
1068
|
+
const Eo = Q(De), wo = Q(kn), To = Q(Te), $e = Q(Ge), Ut = Q(be), Dn = Q(_e), St = Q(ve), vi = Q(In), Ii = (t) => t.length === 4 && t[0] === 81 && // OP_1
|
|
1069
|
+
t[1] === 2 && // push 2 bytes
|
|
1070
|
+
t[2] === 78 && t[3] === 115;
|
|
1071
|
+
function we(t) {
|
|
1072
|
+
let e = d.allocUnsafe(0);
|
|
1073
|
+
function n(i) {
|
|
1074
|
+
e = d.concat([e, d.from(i)]);
|
|
1075
|
+
}
|
|
1076
|
+
function r(i) {
|
|
1077
|
+
const s = e.length, c = We.encodingLength(i);
|
|
1078
|
+
e = d.concat([e, d.allocUnsafe(c)]), We.encode(i, e, s);
|
|
1079
|
+
}
|
|
1080
|
+
function a(i) {
|
|
1081
|
+
r(i.length), n(i);
|
|
1082
|
+
}
|
|
1083
|
+
function o(i) {
|
|
1084
|
+
r(i.length), i.forEach(a);
|
|
1085
|
+
}
|
|
1086
|
+
return o(t), e;
|
|
1087
|
+
}
|
|
1088
|
+
function _o(t) {
|
|
1089
|
+
if (t.length === 32)
|
|
1090
|
+
return;
|
|
1091
|
+
if (![33, 65].includes(t.length)) {
|
|
1092
|
+
console.warn(
|
|
1093
|
+
`Unsupported key length=${t.length}. Must be 33 (compressed) or 65 (uncompressed).`
|
|
1094
|
+
);
|
|
1095
|
+
return;
|
|
1096
|
+
}
|
|
1097
|
+
let e;
|
|
1098
|
+
try {
|
|
1099
|
+
e = C.fromHex(t);
|
|
1100
|
+
} catch {
|
|
1101
|
+
throw new Error("Invalid secp256k1 public key bytes. Cannot parse.");
|
|
1102
|
+
}
|
|
1103
|
+
const n = Rt(e.x), r = Rt(e.y), o = e.y % 2n === 0n ? 6 : 7, i = d.alloc(65);
|
|
1104
|
+
i[0] = o, n.copy(i, 1), r.copy(i, 33);
|
|
1105
|
+
const s = d.concat([d.from([4]), n, r]);
|
|
1106
|
+
return {
|
|
1107
|
+
hybrid: i,
|
|
1108
|
+
uncompressed: s
|
|
1109
|
+
};
|
|
1110
|
+
}
|
|
1111
|
+
function Rt(t) {
|
|
1112
|
+
let e = t.toString(16);
|
|
1113
|
+
return e = e.padStart(64, "0"), e.length > 64 && (e = e.slice(-64)), d.from(e, "hex");
|
|
1114
|
+
}
|
|
1115
|
+
function Oe(t, e) {
|
|
1116
|
+
if (t.equals(e)) return !0;
|
|
1117
|
+
if (t.length === 65 && e.length === 65) {
|
|
1118
|
+
const n = d.from(t), r = d.from(e);
|
|
1119
|
+
return (n[0] === 6 || n[0] === 7) && (n[0] = 4), (r[0] === 6 || r[0] === 7) && (r[0] = 4), n.equals(r);
|
|
1120
|
+
}
|
|
1121
|
+
return !1;
|
|
1122
|
+
}
|
|
1123
|
+
function Vn(t, e) {
|
|
1124
|
+
const n = ce(e);
|
|
1125
|
+
if (n === null) throw new Error("Unknown script error");
|
|
1126
|
+
const r = et(t), a = Ee(t), o = _o(t), i = o?.hybrid ? et(o.hybrid) : void 0, s = o?.uncompressed ? et(o.uncompressed) : void 0;
|
|
1127
|
+
return n.findIndex((c) => {
|
|
1128
|
+
if (typeof c == "number") return !1;
|
|
1129
|
+
if (Oe(c, t) || Oe(c, a) || c.equals(r) || o && (Oe(c, o.uncompressed) || Oe(c, o.hybrid) || i && c.equals(i) || s && c.equals(s)))
|
|
1130
|
+
return !0;
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
function Ze(t, e) {
|
|
1134
|
+
return Vn(t, e) !== -1;
|
|
1135
|
+
}
|
|
1136
|
+
function bo(t, e) {
|
|
1137
|
+
return vo(t).some((r) => jn(r, de.decode, e));
|
|
1138
|
+
}
|
|
1139
|
+
function jn(t, e, n) {
|
|
1140
|
+
const { hashType: r } = e(t), a = [];
|
|
1141
|
+
switch (r & I.SIGHASH_ANYONECANPAY && a.push("addInput"), r & 31) {
|
|
1142
|
+
case I.SIGHASH_ALL:
|
|
1143
|
+
break;
|
|
1144
|
+
case I.SIGHASH_SINGLE:
|
|
1145
|
+
case I.SIGHASH_NONE:
|
|
1146
|
+
a.push("addOutput"), a.push("setInputSequence");
|
|
1147
|
+
break;
|
|
1148
|
+
}
|
|
1149
|
+
return a.indexOf(n) === -1;
|
|
1150
|
+
}
|
|
1151
|
+
function vo(t) {
|
|
1152
|
+
let e = [];
|
|
1153
|
+
if ((t.partialSig || []).length === 0) {
|
|
1154
|
+
if (!t.finalScriptSig && !t.finalScriptWitness) return [];
|
|
1155
|
+
e = Io(t);
|
|
1156
|
+
} else
|
|
1157
|
+
e = t.partialSig;
|
|
1158
|
+
return e.map((n) => n.signature);
|
|
1159
|
+
}
|
|
1160
|
+
function Io(t) {
|
|
1161
|
+
const e = t.finalScriptSig ? ce(t.finalScriptSig) || [] : [], n = t.finalScriptWitness ? ce(t.finalScriptWitness) || [] : [];
|
|
1162
|
+
return e.concat(n).filter((r) => d.isBuffer(r) && _n(r)).map((r) => ({ signature: r }));
|
|
1163
|
+
}
|
|
1164
|
+
var Ce = {}, xe = {}, it = {}, oe = {}, ie = {}, st = {}, Ft;
|
|
1165
|
+
function A() {
|
|
1166
|
+
return Ft || (Ft = 1, (function(t) {
|
|
1167
|
+
Object.defineProperty(t, "__esModule", { value: !0 }), (function(e) {
|
|
1168
|
+
e[e.UNSIGNED_TX = 0] = "UNSIGNED_TX", e[e.GLOBAL_XPUB = 1] = "GLOBAL_XPUB";
|
|
1169
|
+
})(t.GlobalTypes || (t.GlobalTypes = {})), t.GLOBAL_TYPE_NAMES = ["unsignedTx", "globalXpub"], (function(e) {
|
|
1170
|
+
e[e.NON_WITNESS_UTXO = 0] = "NON_WITNESS_UTXO", e[e.WITNESS_UTXO = 1] = "WITNESS_UTXO", e[e.PARTIAL_SIG = 2] = "PARTIAL_SIG", e[e.SIGHASH_TYPE = 3] = "SIGHASH_TYPE", e[e.REDEEM_SCRIPT = 4] = "REDEEM_SCRIPT", e[e.WITNESS_SCRIPT = 5] = "WITNESS_SCRIPT", e[e.BIP32_DERIVATION = 6] = "BIP32_DERIVATION", e[e.FINAL_SCRIPTSIG = 7] = "FINAL_SCRIPTSIG", e[e.FINAL_SCRIPTWITNESS = 8] = "FINAL_SCRIPTWITNESS", e[e.POR_COMMITMENT = 9] = "POR_COMMITMENT", e[e.TAP_KEY_SIG = 19] = "TAP_KEY_SIG", e[e.TAP_SCRIPT_SIG = 20] = "TAP_SCRIPT_SIG", e[e.TAP_LEAF_SCRIPT = 21] = "TAP_LEAF_SCRIPT", e[e.TAP_BIP32_DERIVATION = 22] = "TAP_BIP32_DERIVATION", e[e.TAP_INTERNAL_KEY = 23] = "TAP_INTERNAL_KEY", e[e.TAP_MERKLE_ROOT = 24] = "TAP_MERKLE_ROOT";
|
|
1171
|
+
})(t.InputTypes || (t.InputTypes = {})), t.INPUT_TYPE_NAMES = [
|
|
1172
|
+
"nonWitnessUtxo",
|
|
1173
|
+
"witnessUtxo",
|
|
1174
|
+
"partialSig",
|
|
1175
|
+
"sighashType",
|
|
1176
|
+
"redeemScript",
|
|
1177
|
+
"witnessScript",
|
|
1178
|
+
"bip32Derivation",
|
|
1179
|
+
"finalScriptSig",
|
|
1180
|
+
"finalScriptWitness",
|
|
1181
|
+
"porCommitment",
|
|
1182
|
+
"tapKeySig",
|
|
1183
|
+
"tapScriptSig",
|
|
1184
|
+
"tapLeafScript",
|
|
1185
|
+
"tapBip32Derivation",
|
|
1186
|
+
"tapInternalKey",
|
|
1187
|
+
"tapMerkleRoot"
|
|
1188
|
+
], (function(e) {
|
|
1189
|
+
e[e.REDEEM_SCRIPT = 0] = "REDEEM_SCRIPT", e[e.WITNESS_SCRIPT = 1] = "WITNESS_SCRIPT", e[e.BIP32_DERIVATION = 2] = "BIP32_DERIVATION", e[e.TAP_INTERNAL_KEY = 5] = "TAP_INTERNAL_KEY", e[e.TAP_TREE = 6] = "TAP_TREE", e[e.TAP_BIP32_DERIVATION = 7] = "TAP_BIP32_DERIVATION";
|
|
1190
|
+
})(t.OutputTypes || (t.OutputTypes = {})), t.OUTPUT_TYPE_NAMES = [
|
|
1191
|
+
"redeemScript",
|
|
1192
|
+
"witnessScript",
|
|
1193
|
+
"bip32Derivation",
|
|
1194
|
+
"tapInternalKey",
|
|
1195
|
+
"tapTree",
|
|
1196
|
+
"tapBip32Derivation"
|
|
1197
|
+
];
|
|
1198
|
+
})(st)), st;
|
|
1199
|
+
}
|
|
1200
|
+
var M = {}, Bt;
|
|
1201
|
+
function mo() {
|
|
1202
|
+
if (Bt) return M;
|
|
1203
|
+
Bt = 1, Object.defineProperty(M, "__esModule", { value: !0 });
|
|
1204
|
+
const t = A(), e = (i) => [...Array(i).keys()];
|
|
1205
|
+
function n(i) {
|
|
1206
|
+
if (i.key[0] !== t.GlobalTypes.GLOBAL_XPUB)
|
|
1207
|
+
throw new Error(
|
|
1208
|
+
"Decode Error: could not decode globalXpub with key 0x" + i.key.toString("hex")
|
|
1209
|
+
);
|
|
1210
|
+
if (i.key.length !== 79 || ![2, 3].includes(i.key[46]))
|
|
1211
|
+
throw new Error(
|
|
1212
|
+
"Decode Error: globalXpub has invalid extended pubkey in key 0x" + i.key.toString("hex")
|
|
1213
|
+
);
|
|
1214
|
+
if (i.value.length / 4 % 1 !== 0)
|
|
1215
|
+
throw new Error(
|
|
1216
|
+
"Decode Error: Global GLOBAL_XPUB value length should be multiple of 4"
|
|
1217
|
+
);
|
|
1218
|
+
const s = i.key.slice(1), c = {
|
|
1219
|
+
masterFingerprint: i.value.slice(0, 4),
|
|
1220
|
+
extendedPubkey: s,
|
|
1221
|
+
path: "m"
|
|
1222
|
+
};
|
|
1223
|
+
for (const u of e(i.value.length / 4 - 1)) {
|
|
1224
|
+
const f = i.value.readUInt32LE(u * 4 + 4), p = !!(f & 2147483648), y = f & 2147483647;
|
|
1225
|
+
c.path += "/" + y.toString(10) + (p ? "'" : "");
|
|
1226
|
+
}
|
|
1227
|
+
return c;
|
|
1228
|
+
}
|
|
1229
|
+
M.decode = n;
|
|
1230
|
+
function r(i) {
|
|
1231
|
+
const s = d.from([t.GlobalTypes.GLOBAL_XPUB]), c = d.concat([s, i.extendedPubkey]), u = i.path.split("/"), f = d.allocUnsafe(u.length * 4);
|
|
1232
|
+
i.masterFingerprint.copy(f, 0);
|
|
1233
|
+
let p = 4;
|
|
1234
|
+
return u.slice(1).forEach((y) => {
|
|
1235
|
+
const S = y.slice(-1) === "'";
|
|
1236
|
+
let h = 2147483647 & parseInt(S ? y.slice(0, -1) : y, 10);
|
|
1237
|
+
S && (h += 2147483648), f.writeUInt32LE(h, p), p += 4;
|
|
1238
|
+
}), {
|
|
1239
|
+
key: c,
|
|
1240
|
+
value: f
|
|
1241
|
+
};
|
|
1242
|
+
}
|
|
1243
|
+
M.encode = r, M.expected = "{ masterFingerprint: Buffer; extendedPubkey: Buffer; path: string; }";
|
|
1244
|
+
function a(i) {
|
|
1245
|
+
const s = i.extendedPubkey, c = i.masterFingerprint, u = i.path;
|
|
1246
|
+
return d.isBuffer(s) && s.length === 78 && [2, 3].indexOf(s[45]) > -1 && d.isBuffer(c) && c.length === 4 && typeof u == "string" && !!u.match(/^m(\/\d+'?)*$/);
|
|
1247
|
+
}
|
|
1248
|
+
M.check = a;
|
|
1249
|
+
function o(i, s, c) {
|
|
1250
|
+
const u = s.extendedPubkey.toString("hex");
|
|
1251
|
+
return c.has(u) ? !1 : (c.add(u), i.filter((f) => f.extendedPubkey.equals(s.extendedPubkey)).length === 0);
|
|
1252
|
+
}
|
|
1253
|
+
return M.canAddToArray = o, M;
|
|
1254
|
+
}
|
|
1255
|
+
var Ne = {}, Kt;
|
|
1256
|
+
function ko() {
|
|
1257
|
+
if (Kt) return Ne;
|
|
1258
|
+
Kt = 1, Object.defineProperty(Ne, "__esModule", { value: !0 });
|
|
1259
|
+
const t = A();
|
|
1260
|
+
function e(n) {
|
|
1261
|
+
return {
|
|
1262
|
+
key: d.from([t.GlobalTypes.UNSIGNED_TX]),
|
|
1263
|
+
value: n.toBuffer()
|
|
1264
|
+
};
|
|
1265
|
+
}
|
|
1266
|
+
return Ne.encode = e, Ne;
|
|
1267
|
+
}
|
|
1268
|
+
var W = {}, Lt;
|
|
1269
|
+
function Ao() {
|
|
1270
|
+
if (Lt) return W;
|
|
1271
|
+
Lt = 1, Object.defineProperty(W, "__esModule", { value: !0 });
|
|
1272
|
+
const t = A();
|
|
1273
|
+
function e(o) {
|
|
1274
|
+
if (o.key[0] !== t.InputTypes.FINAL_SCRIPTSIG)
|
|
1275
|
+
throw new Error(
|
|
1276
|
+
"Decode Error: could not decode finalScriptSig with key 0x" + o.key.toString("hex")
|
|
1277
|
+
);
|
|
1278
|
+
return o.value;
|
|
1279
|
+
}
|
|
1280
|
+
W.decode = e;
|
|
1281
|
+
function n(o) {
|
|
1282
|
+
return {
|
|
1283
|
+
key: d.from([t.InputTypes.FINAL_SCRIPTSIG]),
|
|
1284
|
+
value: o
|
|
1285
|
+
};
|
|
1286
|
+
}
|
|
1287
|
+
W.encode = n, W.expected = "Buffer";
|
|
1288
|
+
function r(o) {
|
|
1289
|
+
return d.isBuffer(o);
|
|
1290
|
+
}
|
|
1291
|
+
W.check = r;
|
|
1292
|
+
function a(o, i) {
|
|
1293
|
+
return !!o && !!i && o.finalScriptSig === void 0;
|
|
1294
|
+
}
|
|
1295
|
+
return W.canAdd = a, W;
|
|
1296
|
+
}
|
|
1297
|
+
var X = {}, Mt;
|
|
1298
|
+
function Po() {
|
|
1299
|
+
if (Mt) return X;
|
|
1300
|
+
Mt = 1, Object.defineProperty(X, "__esModule", { value: !0 });
|
|
1301
|
+
const t = A();
|
|
1302
|
+
function e(o) {
|
|
1303
|
+
if (o.key[0] !== t.InputTypes.FINAL_SCRIPTWITNESS)
|
|
1304
|
+
throw new Error(
|
|
1305
|
+
"Decode Error: could not decode finalScriptWitness with key 0x" + o.key.toString("hex")
|
|
1306
|
+
);
|
|
1307
|
+
return o.value;
|
|
1308
|
+
}
|
|
1309
|
+
X.decode = e;
|
|
1310
|
+
function n(o) {
|
|
1311
|
+
return {
|
|
1312
|
+
key: d.from([t.InputTypes.FINAL_SCRIPTWITNESS]),
|
|
1313
|
+
value: o
|
|
1314
|
+
};
|
|
1315
|
+
}
|
|
1316
|
+
X.encode = n, X.expected = "Buffer";
|
|
1317
|
+
function r(o) {
|
|
1318
|
+
return d.isBuffer(o);
|
|
1319
|
+
}
|
|
1320
|
+
X.check = r;
|
|
1321
|
+
function a(o, i) {
|
|
1322
|
+
return !!o && !!i && o.finalScriptWitness === void 0;
|
|
1323
|
+
}
|
|
1324
|
+
return X.canAdd = a, X;
|
|
1325
|
+
}
|
|
1326
|
+
var G = {}, Wt;
|
|
1327
|
+
function Oo() {
|
|
1328
|
+
if (Wt) return G;
|
|
1329
|
+
Wt = 1, Object.defineProperty(G, "__esModule", { value: !0 });
|
|
1330
|
+
const t = A();
|
|
1331
|
+
function e(o) {
|
|
1332
|
+
if (o.key[0] !== t.InputTypes.NON_WITNESS_UTXO)
|
|
1333
|
+
throw new Error(
|
|
1334
|
+
"Decode Error: could not decode nonWitnessUtxo with key 0x" + o.key.toString("hex")
|
|
1335
|
+
);
|
|
1336
|
+
return o.value;
|
|
1337
|
+
}
|
|
1338
|
+
G.decode = e;
|
|
1339
|
+
function n(o) {
|
|
1340
|
+
return {
|
|
1341
|
+
key: d.from([t.InputTypes.NON_WITNESS_UTXO]),
|
|
1342
|
+
value: o
|
|
1343
|
+
};
|
|
1344
|
+
}
|
|
1345
|
+
G.encode = n, G.expected = "Buffer";
|
|
1346
|
+
function r(o) {
|
|
1347
|
+
return d.isBuffer(o);
|
|
1348
|
+
}
|
|
1349
|
+
G.check = r;
|
|
1350
|
+
function a(o, i) {
|
|
1351
|
+
return !!o && !!i && o.nonWitnessUtxo === void 0;
|
|
1352
|
+
}
|
|
1353
|
+
return G.canAdd = a, G;
|
|
1354
|
+
}
|
|
1355
|
+
var q = {}, Xt;
|
|
1356
|
+
function Co() {
|
|
1357
|
+
if (Xt) return q;
|
|
1358
|
+
Xt = 1, Object.defineProperty(q, "__esModule", { value: !0 });
|
|
1359
|
+
const t = A();
|
|
1360
|
+
function e(i) {
|
|
1361
|
+
if (i.key[0] !== t.InputTypes.PARTIAL_SIG)
|
|
1362
|
+
throw new Error(
|
|
1363
|
+
"Decode Error: could not decode partialSig with key 0x" + i.key.toString("hex")
|
|
1364
|
+
);
|
|
1365
|
+
if (!(i.key.length === 34 || i.key.length === 66) || ![2, 3, 4].includes(i.key[1]))
|
|
1366
|
+
throw new Error(
|
|
1367
|
+
"Decode Error: partialSig has invalid pubkey in key 0x" + i.key.toString("hex")
|
|
1368
|
+
);
|
|
1369
|
+
return {
|
|
1370
|
+
pubkey: i.key.slice(1),
|
|
1371
|
+
signature: i.value
|
|
1372
|
+
};
|
|
1373
|
+
}
|
|
1374
|
+
q.decode = e;
|
|
1375
|
+
function n(i) {
|
|
1376
|
+
const s = d.from([t.InputTypes.PARTIAL_SIG]);
|
|
1377
|
+
return {
|
|
1378
|
+
key: d.concat([s, i.pubkey]),
|
|
1379
|
+
value: i.signature
|
|
1380
|
+
};
|
|
1381
|
+
}
|
|
1382
|
+
q.encode = n, q.expected = "{ pubkey: Buffer; signature: Buffer; }";
|
|
1383
|
+
function r(i) {
|
|
1384
|
+
return d.isBuffer(i.pubkey) && d.isBuffer(i.signature) && [33, 65].includes(i.pubkey.length) && [2, 3, 4].includes(i.pubkey[0]) && a(i.signature);
|
|
1385
|
+
}
|
|
1386
|
+
q.check = r;
|
|
1387
|
+
function a(i) {
|
|
1388
|
+
if (!d.isBuffer(i) || i.length < 9 || i[0] !== 48 || i.length !== i[1] + 3 || i[2] !== 2) return !1;
|
|
1389
|
+
const s = i[3];
|
|
1390
|
+
if (s > 33 || s < 1 || i[3 + s + 1] !== 2) return !1;
|
|
1391
|
+
const c = i[3 + s + 2];
|
|
1392
|
+
return !(c > 33 || c < 1 || i.length !== 3 + s + 2 + c + 2);
|
|
1393
|
+
}
|
|
1394
|
+
function o(i, s, c) {
|
|
1395
|
+
const u = s.pubkey.toString("hex");
|
|
1396
|
+
return c.has(u) ? !1 : (c.add(u), i.filter((f) => f.pubkey.equals(s.pubkey)).length === 0);
|
|
1397
|
+
}
|
|
1398
|
+
return q.canAddToArray = o, q;
|
|
1399
|
+
}
|
|
1400
|
+
var D = {}, Gt;
|
|
1401
|
+
function xo() {
|
|
1402
|
+
if (Gt) return D;
|
|
1403
|
+
Gt = 1, Object.defineProperty(D, "__esModule", { value: !0 });
|
|
1404
|
+
const t = A();
|
|
1405
|
+
function e(o) {
|
|
1406
|
+
if (o.key[0] !== t.InputTypes.POR_COMMITMENT)
|
|
1407
|
+
throw new Error(
|
|
1408
|
+
"Decode Error: could not decode porCommitment with key 0x" + o.key.toString("hex")
|
|
1409
|
+
);
|
|
1410
|
+
return o.value.toString("utf8");
|
|
1411
|
+
}
|
|
1412
|
+
D.decode = e;
|
|
1413
|
+
function n(o) {
|
|
1414
|
+
return {
|
|
1415
|
+
key: d.from([t.InputTypes.POR_COMMITMENT]),
|
|
1416
|
+
value: d.from(o, "utf8")
|
|
1417
|
+
};
|
|
1418
|
+
}
|
|
1419
|
+
D.encode = n, D.expected = "string";
|
|
1420
|
+
function r(o) {
|
|
1421
|
+
return typeof o == "string";
|
|
1422
|
+
}
|
|
1423
|
+
D.check = r;
|
|
1424
|
+
function a(o, i) {
|
|
1425
|
+
return !!o && !!i && o.porCommitment === void 0;
|
|
1426
|
+
}
|
|
1427
|
+
return D.canAdd = a, D;
|
|
1428
|
+
}
|
|
1429
|
+
var V = {}, qt;
|
|
1430
|
+
function No() {
|
|
1431
|
+
if (qt) return V;
|
|
1432
|
+
qt = 1, Object.defineProperty(V, "__esModule", { value: !0 });
|
|
1433
|
+
const t = A();
|
|
1434
|
+
function e(o) {
|
|
1435
|
+
if (o.key[0] !== t.InputTypes.SIGHASH_TYPE)
|
|
1436
|
+
throw new Error(
|
|
1437
|
+
"Decode Error: could not decode sighashType with key 0x" + o.key.toString("hex")
|
|
1438
|
+
);
|
|
1439
|
+
return o.value.readUInt32LE(0);
|
|
1440
|
+
}
|
|
1441
|
+
V.decode = e;
|
|
1442
|
+
function n(o) {
|
|
1443
|
+
const i = d.from([t.InputTypes.SIGHASH_TYPE]), s = d.allocUnsafe(4);
|
|
1444
|
+
return s.writeUInt32LE(o, 0), {
|
|
1445
|
+
key: i,
|
|
1446
|
+
value: s
|
|
1447
|
+
};
|
|
1448
|
+
}
|
|
1449
|
+
V.encode = n, V.expected = "number";
|
|
1450
|
+
function r(o) {
|
|
1451
|
+
return typeof o == "number";
|
|
1452
|
+
}
|
|
1453
|
+
V.check = r;
|
|
1454
|
+
function a(o, i) {
|
|
1455
|
+
return !!o && !!i && o.sighashType === void 0;
|
|
1456
|
+
}
|
|
1457
|
+
return V.canAdd = a, V;
|
|
1458
|
+
}
|
|
1459
|
+
var j = {}, Dt;
|
|
1460
|
+
function Ho() {
|
|
1461
|
+
if (Dt) return j;
|
|
1462
|
+
Dt = 1, Object.defineProperty(j, "__esModule", { value: !0 });
|
|
1463
|
+
const t = A();
|
|
1464
|
+
function e(o) {
|
|
1465
|
+
if (o.key[0] !== t.InputTypes.TAP_KEY_SIG || o.key.length !== 1)
|
|
1466
|
+
throw new Error(
|
|
1467
|
+
"Decode Error: could not decode tapKeySig with key 0x" + o.key.toString("hex")
|
|
1468
|
+
);
|
|
1469
|
+
if (!r(o.value))
|
|
1470
|
+
throw new Error(
|
|
1471
|
+
"Decode Error: tapKeySig not a valid 64-65-byte BIP340 signature"
|
|
1472
|
+
);
|
|
1473
|
+
return o.value;
|
|
1474
|
+
}
|
|
1475
|
+
j.decode = e;
|
|
1476
|
+
function n(o) {
|
|
1477
|
+
return { key: d.from([t.InputTypes.TAP_KEY_SIG]), value: o };
|
|
1478
|
+
}
|
|
1479
|
+
j.encode = n, j.expected = "Buffer";
|
|
1480
|
+
function r(o) {
|
|
1481
|
+
return d.isBuffer(o) && (o.length === 64 || o.length === 65);
|
|
1482
|
+
}
|
|
1483
|
+
j.check = r;
|
|
1484
|
+
function a(o, i) {
|
|
1485
|
+
return !!o && !!i && o.tapKeySig === void 0;
|
|
1486
|
+
}
|
|
1487
|
+
return j.canAdd = a, j;
|
|
1488
|
+
}
|
|
1489
|
+
var z = {}, Vt;
|
|
1490
|
+
function Uo() {
|
|
1491
|
+
if (Vt) return z;
|
|
1492
|
+
Vt = 1, Object.defineProperty(z, "__esModule", { value: !0 });
|
|
1493
|
+
const t = A();
|
|
1494
|
+
function e(o) {
|
|
1495
|
+
if (o.key[0] !== t.InputTypes.TAP_LEAF_SCRIPT)
|
|
1496
|
+
throw new Error(
|
|
1497
|
+
"Decode Error: could not decode tapLeafScript with key 0x" + o.key.toString("hex")
|
|
1498
|
+
);
|
|
1499
|
+
if ((o.key.length - 2) % 32 !== 0)
|
|
1500
|
+
throw new Error(
|
|
1501
|
+
"Decode Error: tapLeafScript has invalid control block in key 0x" + o.key.toString("hex")
|
|
1502
|
+
);
|
|
1503
|
+
const i = o.value[o.value.length - 1];
|
|
1504
|
+
if ((o.key[1] & 254) !== i)
|
|
1505
|
+
throw new Error(
|
|
1506
|
+
"Decode Error: tapLeafScript bad leaf version in key 0x" + o.key.toString("hex")
|
|
1507
|
+
);
|
|
1508
|
+
const s = o.value.slice(0, -1);
|
|
1509
|
+
return { controlBlock: o.key.slice(1), script: s, leafVersion: i };
|
|
1510
|
+
}
|
|
1511
|
+
z.decode = e;
|
|
1512
|
+
function n(o) {
|
|
1513
|
+
const i = d.from([t.InputTypes.TAP_LEAF_SCRIPT]), s = d.from([o.leafVersion]);
|
|
1514
|
+
return {
|
|
1515
|
+
key: d.concat([i, o.controlBlock]),
|
|
1516
|
+
value: d.concat([o.script, s])
|
|
1517
|
+
};
|
|
1518
|
+
}
|
|
1519
|
+
z.encode = n, z.expected = "{ controlBlock: Buffer; leafVersion: number, script: Buffer; }";
|
|
1520
|
+
function r(o) {
|
|
1521
|
+
return d.isBuffer(o.controlBlock) && (o.controlBlock.length - 1) % 32 === 0 && (o.controlBlock[0] & 254) === o.leafVersion && d.isBuffer(o.script);
|
|
1522
|
+
}
|
|
1523
|
+
z.check = r;
|
|
1524
|
+
function a(o, i, s) {
|
|
1525
|
+
const c = i.controlBlock.toString("hex");
|
|
1526
|
+
return s.has(c) ? !1 : (s.add(c), o.filter((u) => u.controlBlock.equals(i.controlBlock)).length === 0);
|
|
1527
|
+
}
|
|
1528
|
+
return z.canAddToArray = a, z;
|
|
1529
|
+
}
|
|
1530
|
+
var Y = {}, jt;
|
|
1531
|
+
function Ro() {
|
|
1532
|
+
if (jt) return Y;
|
|
1533
|
+
jt = 1, Object.defineProperty(Y, "__esModule", { value: !0 });
|
|
1534
|
+
const t = A();
|
|
1535
|
+
function e(o) {
|
|
1536
|
+
if (o.key[0] !== t.InputTypes.TAP_MERKLE_ROOT || o.key.length !== 1)
|
|
1537
|
+
throw new Error(
|
|
1538
|
+
"Decode Error: could not decode tapMerkleRoot with key 0x" + o.key.toString("hex")
|
|
1539
|
+
);
|
|
1540
|
+
if (!r(o.value))
|
|
1541
|
+
throw new Error("Decode Error: tapMerkleRoot not a 32-byte hash");
|
|
1542
|
+
return o.value;
|
|
1543
|
+
}
|
|
1544
|
+
Y.decode = e;
|
|
1545
|
+
function n(o) {
|
|
1546
|
+
return { key: d.from([t.InputTypes.TAP_MERKLE_ROOT]), value: o };
|
|
1547
|
+
}
|
|
1548
|
+
Y.encode = n, Y.expected = "Buffer";
|
|
1549
|
+
function r(o) {
|
|
1550
|
+
return d.isBuffer(o) && o.length === 32;
|
|
1551
|
+
}
|
|
1552
|
+
Y.check = r;
|
|
1553
|
+
function a(o, i) {
|
|
1554
|
+
return !!o && !!i && o.tapMerkleRoot === void 0;
|
|
1555
|
+
}
|
|
1556
|
+
return Y.canAdd = a, Y;
|
|
1557
|
+
}
|
|
1558
|
+
var $ = {}, zt;
|
|
1559
|
+
function Fo() {
|
|
1560
|
+
if (zt) return $;
|
|
1561
|
+
zt = 1, Object.defineProperty($, "__esModule", { value: !0 });
|
|
1562
|
+
const t = A();
|
|
1563
|
+
function e(o) {
|
|
1564
|
+
if (o.key[0] !== t.InputTypes.TAP_SCRIPT_SIG)
|
|
1565
|
+
throw new Error(
|
|
1566
|
+
"Decode Error: could not decode tapScriptSig with key 0x" + o.key.toString("hex")
|
|
1567
|
+
);
|
|
1568
|
+
if (o.key.length !== 65)
|
|
1569
|
+
throw new Error(
|
|
1570
|
+
"Decode Error: tapScriptSig has invalid key 0x" + o.key.toString("hex")
|
|
1571
|
+
);
|
|
1572
|
+
if (o.value.length !== 64 && o.value.length !== 65)
|
|
1573
|
+
throw new Error(
|
|
1574
|
+
"Decode Error: tapScriptSig has invalid signature in key 0x" + o.key.toString("hex")
|
|
1575
|
+
);
|
|
1576
|
+
const i = o.key.slice(1, 33), s = o.key.slice(33);
|
|
1577
|
+
return {
|
|
1578
|
+
pubkey: i,
|
|
1579
|
+
leafHash: s,
|
|
1580
|
+
signature: o.value
|
|
1581
|
+
};
|
|
1582
|
+
}
|
|
1583
|
+
$.decode = e;
|
|
1584
|
+
function n(o) {
|
|
1585
|
+
const i = d.from([t.InputTypes.TAP_SCRIPT_SIG]);
|
|
1586
|
+
return {
|
|
1587
|
+
key: d.concat([i, o.pubkey, o.leafHash]),
|
|
1588
|
+
value: o.signature
|
|
1589
|
+
};
|
|
1590
|
+
}
|
|
1591
|
+
$.encode = n, $.expected = "{ pubkey: Buffer; leafHash: Buffer; signature: Buffer; }";
|
|
1592
|
+
function r(o) {
|
|
1593
|
+
return d.isBuffer(o.pubkey) && d.isBuffer(o.leafHash) && d.isBuffer(o.signature) && o.pubkey.length === 32 && o.leafHash.length === 32 && (o.signature.length === 64 || o.signature.length === 65);
|
|
1594
|
+
}
|
|
1595
|
+
$.check = r;
|
|
1596
|
+
function a(o, i, s) {
|
|
1597
|
+
const c = i.pubkey.toString("hex") + i.leafHash.toString("hex");
|
|
1598
|
+
return s.has(c) ? !1 : (s.add(c), o.filter(
|
|
1599
|
+
(u) => u.pubkey.equals(i.pubkey) && u.leafHash.equals(i.leafHash)
|
|
1600
|
+
).length === 0);
|
|
1601
|
+
}
|
|
1602
|
+
return $.canAddToArray = a, $;
|
|
1603
|
+
}
|
|
1604
|
+
var Z = {}, K = {}, Yt;
|
|
1605
|
+
function Et() {
|
|
1606
|
+
if (Yt) return K;
|
|
1607
|
+
Yt = 1, Object.defineProperty(K, "__esModule", { value: !0 });
|
|
1608
|
+
const t = ue();
|
|
1609
|
+
K.range = (s) => [...Array(s).keys()];
|
|
1610
|
+
function e(s) {
|
|
1611
|
+
if (s.length < 1) return s;
|
|
1612
|
+
let c = s.length - 1, u = 0;
|
|
1613
|
+
for (let f = 0; f < s.length / 2; f++)
|
|
1614
|
+
u = s[f], s[f] = s[c], s[c] = u, c--;
|
|
1615
|
+
return s;
|
|
1616
|
+
}
|
|
1617
|
+
K.reverseBuffer = e;
|
|
1618
|
+
function n(s) {
|
|
1619
|
+
const c = s.map(r);
|
|
1620
|
+
return c.push(d.from([0])), d.concat(c);
|
|
1621
|
+
}
|
|
1622
|
+
K.keyValsToBuffer = n;
|
|
1623
|
+
function r(s) {
|
|
1624
|
+
const c = s.key.length, u = s.value.length, f = t.encodingLength(c), p = t.encodingLength(u), y = d.allocUnsafe(
|
|
1625
|
+
f + c + p + u
|
|
1626
|
+
);
|
|
1627
|
+
return t.encode(c, y, 0), s.key.copy(y, f), t.encode(u, y, f + c), s.value.copy(y, f + c + p), y;
|
|
1628
|
+
}
|
|
1629
|
+
K.keyValToBuffer = r;
|
|
1630
|
+
function a(s, c) {
|
|
1631
|
+
if (typeof s != "number")
|
|
1632
|
+
throw new Error("cannot write a non-number as a number");
|
|
1633
|
+
if (s < 0)
|
|
1634
|
+
throw new Error("specified a negative value for writing an unsigned value");
|
|
1635
|
+
if (s > c) throw new Error("RangeError: value out of range");
|
|
1636
|
+
if (Math.floor(s) !== s)
|
|
1637
|
+
throw new Error("value has a fractional component");
|
|
1638
|
+
}
|
|
1639
|
+
function o(s, c) {
|
|
1640
|
+
const u = s.readUInt32LE(c);
|
|
1641
|
+
let f = s.readUInt32LE(c + 4);
|
|
1642
|
+
return f *= 4294967296, a(f + u, 9007199254740991), f + u;
|
|
1643
|
+
}
|
|
1644
|
+
K.readUInt64LE = o;
|
|
1645
|
+
function i(s, c, u) {
|
|
1646
|
+
return a(c, 9007199254740991), s.writeInt32LE(c & -1, u), s.writeUInt32LE(Math.floor(c / 4294967296), u + 4), u + 8;
|
|
1647
|
+
}
|
|
1648
|
+
return K.writeUInt64LE = i, K;
|
|
1649
|
+
}
|
|
1650
|
+
var $t;
|
|
1651
|
+
function Bo() {
|
|
1652
|
+
if ($t) return Z;
|
|
1653
|
+
$t = 1, Object.defineProperty(Z, "__esModule", { value: !0 });
|
|
1654
|
+
const t = A(), e = Et(), n = ue();
|
|
1655
|
+
function r(s) {
|
|
1656
|
+
if (s.key[0] !== t.InputTypes.WITNESS_UTXO)
|
|
1657
|
+
throw new Error(
|
|
1658
|
+
"Decode Error: could not decode witnessUtxo with key 0x" + s.key.toString("hex")
|
|
1659
|
+
);
|
|
1660
|
+
const c = e.readUInt64LE(s.value, 0);
|
|
1661
|
+
let u = 8;
|
|
1662
|
+
const f = n.decode(s.value, u);
|
|
1663
|
+
u += n.encodingLength(f);
|
|
1664
|
+
const p = s.value.slice(u);
|
|
1665
|
+
if (p.length !== f)
|
|
1666
|
+
throw new Error("Decode Error: WITNESS_UTXO script is not proper length");
|
|
1667
|
+
return {
|
|
1668
|
+
script: p,
|
|
1669
|
+
value: c
|
|
1670
|
+
};
|
|
1671
|
+
}
|
|
1672
|
+
Z.decode = r;
|
|
1673
|
+
function a(s) {
|
|
1674
|
+
const { script: c, value: u } = s, f = n.encodingLength(c.length), p = d.allocUnsafe(8 + f + c.length);
|
|
1675
|
+
return e.writeUInt64LE(p, u, 0), n.encode(c.length, p, 8), c.copy(p, 8 + f), {
|
|
1676
|
+
key: d.from([t.InputTypes.WITNESS_UTXO]),
|
|
1677
|
+
value: p
|
|
1678
|
+
};
|
|
1679
|
+
}
|
|
1680
|
+
Z.encode = a, Z.expected = "{ script: Buffer; value: number; }";
|
|
1681
|
+
function o(s) {
|
|
1682
|
+
return d.isBuffer(s.script) && typeof s.value == "number";
|
|
1683
|
+
}
|
|
1684
|
+
Z.check = o;
|
|
1685
|
+
function i(s, c) {
|
|
1686
|
+
return !!s && !!c && s.witnessUtxo === void 0;
|
|
1687
|
+
}
|
|
1688
|
+
return Z.canAdd = i, Z;
|
|
1689
|
+
}
|
|
1690
|
+
var J = {}, Zt;
|
|
1691
|
+
function Ko() {
|
|
1692
|
+
if (Zt) return J;
|
|
1693
|
+
Zt = 1, Object.defineProperty(J, "__esModule", { value: !0 });
|
|
1694
|
+
const t = A(), e = ue();
|
|
1695
|
+
function n(i) {
|
|
1696
|
+
if (i.key[0] !== t.OutputTypes.TAP_TREE || i.key.length !== 1)
|
|
1697
|
+
throw new Error(
|
|
1698
|
+
"Decode Error: could not decode tapTree with key 0x" + i.key.toString("hex")
|
|
1699
|
+
);
|
|
1700
|
+
let s = 0;
|
|
1701
|
+
const c = [];
|
|
1702
|
+
for (; s < i.value.length; ) {
|
|
1703
|
+
const u = i.value[s++], f = i.value[s++], p = e.decode(i.value, s);
|
|
1704
|
+
s += e.encodingLength(p), c.push({
|
|
1705
|
+
depth: u,
|
|
1706
|
+
leafVersion: f,
|
|
1707
|
+
script: i.value.slice(s, s + p)
|
|
1708
|
+
}), s += p;
|
|
1709
|
+
}
|
|
1710
|
+
return { leaves: c };
|
|
1711
|
+
}
|
|
1712
|
+
J.decode = n;
|
|
1713
|
+
function r(i) {
|
|
1714
|
+
const s = d.from([t.OutputTypes.TAP_TREE]), c = [].concat(
|
|
1715
|
+
...i.leaves.map((u) => [
|
|
1716
|
+
d.of(u.depth, u.leafVersion),
|
|
1717
|
+
e.encode(u.script.length),
|
|
1718
|
+
u.script
|
|
1719
|
+
])
|
|
1720
|
+
);
|
|
1721
|
+
return {
|
|
1722
|
+
key: s,
|
|
1723
|
+
value: d.concat(c)
|
|
1724
|
+
};
|
|
1725
|
+
}
|
|
1726
|
+
J.encode = r, J.expected = "{ leaves: [{ depth: number; leafVersion: number, script: Buffer; }] }";
|
|
1727
|
+
function a(i) {
|
|
1728
|
+
return Array.isArray(i.leaves) && i.leaves.every(
|
|
1729
|
+
(s) => s.depth >= 0 && s.depth <= 128 && (s.leafVersion & 254) === s.leafVersion && d.isBuffer(s.script)
|
|
1730
|
+
);
|
|
1731
|
+
}
|
|
1732
|
+
J.check = a;
|
|
1733
|
+
function o(i, s) {
|
|
1734
|
+
return !!i && !!s && i.tapTree === void 0;
|
|
1735
|
+
}
|
|
1736
|
+
return J.canAdd = o, J;
|
|
1737
|
+
}
|
|
1738
|
+
var He = {}, Jt;
|
|
1739
|
+
function zn() {
|
|
1740
|
+
if (Jt) return He;
|
|
1741
|
+
Jt = 1, Object.defineProperty(He, "__esModule", { value: !0 });
|
|
1742
|
+
const t = (r) => [...Array(r).keys()], e = (r) => r.length === 33 && [2, 3].includes(r[0]) || r.length === 65 && r[0] === 4;
|
|
1743
|
+
function n(r, a = e) {
|
|
1744
|
+
function o(f) {
|
|
1745
|
+
if (f.key[0] !== r)
|
|
1746
|
+
throw new Error(
|
|
1747
|
+
"Decode Error: could not decode bip32Derivation with key 0x" + f.key.toString("hex")
|
|
1748
|
+
);
|
|
1749
|
+
const p = f.key.slice(1);
|
|
1750
|
+
if (!a(p))
|
|
1751
|
+
throw new Error(
|
|
1752
|
+
"Decode Error: bip32Derivation has invalid pubkey in key 0x" + f.key.toString("hex")
|
|
1753
|
+
);
|
|
1754
|
+
if (f.value.length / 4 % 1 !== 0)
|
|
1755
|
+
throw new Error(
|
|
1756
|
+
"Decode Error: Input BIP32_DERIVATION value length should be multiple of 4"
|
|
1757
|
+
);
|
|
1758
|
+
const y = {
|
|
1759
|
+
masterFingerprint: f.value.slice(0, 4),
|
|
1760
|
+
pubkey: p,
|
|
1761
|
+
path: "m"
|
|
1762
|
+
};
|
|
1763
|
+
for (const S of t(f.value.length / 4 - 1)) {
|
|
1764
|
+
const h = f.value.readUInt32LE(S * 4 + 4), l = !!(h & 2147483648), w = h & 2147483647;
|
|
1765
|
+
y.path += "/" + w.toString(10) + (l ? "'" : "");
|
|
1766
|
+
}
|
|
1767
|
+
return y;
|
|
1768
|
+
}
|
|
1769
|
+
function i(f) {
|
|
1770
|
+
const p = d.from([r]), y = d.concat([p, f.pubkey]), S = f.path.split("/"), h = d.allocUnsafe(S.length * 4);
|
|
1771
|
+
f.masterFingerprint.copy(h, 0);
|
|
1772
|
+
let l = 4;
|
|
1773
|
+
return S.slice(1).forEach((w) => {
|
|
1774
|
+
const T = w.slice(-1) === "'";
|
|
1775
|
+
let g = 2147483647 & parseInt(T ? w.slice(0, -1) : w, 10);
|
|
1776
|
+
T && (g += 2147483648), h.writeUInt32LE(g, l), l += 4;
|
|
1777
|
+
}), {
|
|
1778
|
+
key: y,
|
|
1779
|
+
value: h
|
|
1780
|
+
};
|
|
1781
|
+
}
|
|
1782
|
+
const s = "{ masterFingerprint: Buffer; pubkey: Buffer; path: string; }";
|
|
1783
|
+
function c(f) {
|
|
1784
|
+
return d.isBuffer(f.pubkey) && d.isBuffer(f.masterFingerprint) && typeof f.path == "string" && a(f.pubkey) && f.masterFingerprint.length === 4;
|
|
1785
|
+
}
|
|
1786
|
+
function u(f, p, y) {
|
|
1787
|
+
const S = p.pubkey.toString("hex");
|
|
1788
|
+
return y.has(S) ? !1 : (y.add(S), f.filter((h) => h.pubkey.equals(p.pubkey)).length === 0);
|
|
1789
|
+
}
|
|
1790
|
+
return {
|
|
1791
|
+
decode: o,
|
|
1792
|
+
encode: i,
|
|
1793
|
+
check: c,
|
|
1794
|
+
expected: s,
|
|
1795
|
+
canAddToArray: u
|
|
1796
|
+
};
|
|
1797
|
+
}
|
|
1798
|
+
return He.makeConverter = n, He;
|
|
1799
|
+
}
|
|
1800
|
+
var Ue = {}, Qt;
|
|
1801
|
+
function Lo() {
|
|
1802
|
+
if (Qt) return Ue;
|
|
1803
|
+
Qt = 1, Object.defineProperty(Ue, "__esModule", { value: !0 });
|
|
1804
|
+
function t(e) {
|
|
1805
|
+
return n;
|
|
1806
|
+
function n(r) {
|
|
1807
|
+
let a;
|
|
1808
|
+
if (e.includes(r.key[0]) && (a = r.key.slice(1), !(a.length === 33 || a.length === 65) || ![2, 3, 4].includes(a[0])))
|
|
1809
|
+
throw new Error(
|
|
1810
|
+
"Format Error: invalid pubkey in key 0x" + r.key.toString("hex")
|
|
1811
|
+
);
|
|
1812
|
+
return a;
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
return Ue.makeChecker = t, Ue;
|
|
1816
|
+
}
|
|
1817
|
+
var Re = {}, en;
|
|
1818
|
+
function Mo() {
|
|
1819
|
+
if (en) return Re;
|
|
1820
|
+
en = 1, Object.defineProperty(Re, "__esModule", { value: !0 });
|
|
1821
|
+
function t(e) {
|
|
1822
|
+
function n(s) {
|
|
1823
|
+
if (s.key[0] !== e)
|
|
1824
|
+
throw new Error(
|
|
1825
|
+
"Decode Error: could not decode redeemScript with key 0x" + s.key.toString("hex")
|
|
1826
|
+
);
|
|
1827
|
+
return s.value;
|
|
1828
|
+
}
|
|
1829
|
+
function r(s) {
|
|
1830
|
+
return {
|
|
1831
|
+
key: d.from([e]),
|
|
1832
|
+
value: s
|
|
1833
|
+
};
|
|
1834
|
+
}
|
|
1835
|
+
const a = "Buffer";
|
|
1836
|
+
function o(s) {
|
|
1837
|
+
return d.isBuffer(s);
|
|
1838
|
+
}
|
|
1839
|
+
function i(s, c) {
|
|
1840
|
+
return !!s && !!c && s.redeemScript === void 0;
|
|
1841
|
+
}
|
|
1842
|
+
return {
|
|
1843
|
+
decode: n,
|
|
1844
|
+
encode: r,
|
|
1845
|
+
check: o,
|
|
1846
|
+
expected: a,
|
|
1847
|
+
canAdd: i
|
|
1848
|
+
};
|
|
1849
|
+
}
|
|
1850
|
+
return Re.makeConverter = t, Re;
|
|
1851
|
+
}
|
|
1852
|
+
var Fe = {}, tn;
|
|
1853
|
+
function Wo() {
|
|
1854
|
+
if (tn) return Fe;
|
|
1855
|
+
tn = 1, Object.defineProperty(Fe, "__esModule", { value: !0 });
|
|
1856
|
+
const t = ue(), e = zn(), n = (a) => a.length === 32;
|
|
1857
|
+
function r(a) {
|
|
1858
|
+
const o = e.makeConverter(a, n);
|
|
1859
|
+
function i(f) {
|
|
1860
|
+
const p = t.decode(f.value), y = t.encodingLength(p), S = o.decode({
|
|
1861
|
+
key: f.key,
|
|
1862
|
+
value: f.value.slice(y + p * 32)
|
|
1863
|
+
}), h = new Array(p);
|
|
1864
|
+
for (let l = 0, w = y; l < p; l++, w += 32)
|
|
1865
|
+
h[l] = f.value.slice(w, w + 32);
|
|
1866
|
+
return Object.assign({}, S, { leafHashes: h });
|
|
1867
|
+
}
|
|
1868
|
+
function s(f) {
|
|
1869
|
+
const p = o.encode(f), y = t.encodingLength(f.leafHashes.length), S = d.allocUnsafe(y);
|
|
1870
|
+
t.encode(f.leafHashes.length, S);
|
|
1871
|
+
const h = d.concat([S, ...f.leafHashes, p.value]);
|
|
1872
|
+
return Object.assign({}, p, { value: h });
|
|
1873
|
+
}
|
|
1874
|
+
const c = "{ masterFingerprint: Buffer; pubkey: Buffer; path: string; leafHashes: Buffer[]; }";
|
|
1875
|
+
function u(f) {
|
|
1876
|
+
return Array.isArray(f.leafHashes) && f.leafHashes.every(
|
|
1877
|
+
(p) => d.isBuffer(p) && p.length === 32
|
|
1878
|
+
) && o.check(f);
|
|
1879
|
+
}
|
|
1880
|
+
return {
|
|
1881
|
+
decode: i,
|
|
1882
|
+
encode: s,
|
|
1883
|
+
check: u,
|
|
1884
|
+
expected: c,
|
|
1885
|
+
canAddToArray: o.canAddToArray
|
|
1886
|
+
};
|
|
1887
|
+
}
|
|
1888
|
+
return Fe.makeConverter = r, Fe;
|
|
1889
|
+
}
|
|
1890
|
+
var Be = {}, nn;
|
|
1891
|
+
function Xo() {
|
|
1892
|
+
if (nn) return Be;
|
|
1893
|
+
nn = 1, Object.defineProperty(Be, "__esModule", { value: !0 });
|
|
1894
|
+
function t(e) {
|
|
1895
|
+
function n(s) {
|
|
1896
|
+
if (s.key[0] !== e || s.key.length !== 1)
|
|
1897
|
+
throw new Error(
|
|
1898
|
+
"Decode Error: could not decode tapInternalKey with key 0x" + s.key.toString("hex")
|
|
1899
|
+
);
|
|
1900
|
+
if (s.value.length !== 32)
|
|
1901
|
+
throw new Error(
|
|
1902
|
+
"Decode Error: tapInternalKey not a 32-byte x-only pubkey"
|
|
1903
|
+
);
|
|
1904
|
+
return s.value;
|
|
1905
|
+
}
|
|
1906
|
+
function r(s) {
|
|
1907
|
+
return { key: d.from([e]), value: s };
|
|
1908
|
+
}
|
|
1909
|
+
const a = "Buffer";
|
|
1910
|
+
function o(s) {
|
|
1911
|
+
return d.isBuffer(s) && s.length === 32;
|
|
1912
|
+
}
|
|
1913
|
+
function i(s, c) {
|
|
1914
|
+
return !!s && !!c && s.tapInternalKey === void 0;
|
|
1915
|
+
}
|
|
1916
|
+
return {
|
|
1917
|
+
decode: n,
|
|
1918
|
+
encode: r,
|
|
1919
|
+
check: o,
|
|
1920
|
+
expected: a,
|
|
1921
|
+
canAdd: i
|
|
1922
|
+
};
|
|
1923
|
+
}
|
|
1924
|
+
return Be.makeConverter = t, Be;
|
|
1925
|
+
}
|
|
1926
|
+
var Ke = {}, rn;
|
|
1927
|
+
function Go() {
|
|
1928
|
+
if (rn) return Ke;
|
|
1929
|
+
rn = 1, Object.defineProperty(Ke, "__esModule", { value: !0 });
|
|
1930
|
+
function t(e) {
|
|
1931
|
+
function n(s) {
|
|
1932
|
+
if (s.key[0] !== e)
|
|
1933
|
+
throw new Error(
|
|
1934
|
+
"Decode Error: could not decode witnessScript with key 0x" + s.key.toString("hex")
|
|
1935
|
+
);
|
|
1936
|
+
return s.value;
|
|
1937
|
+
}
|
|
1938
|
+
function r(s) {
|
|
1939
|
+
return {
|
|
1940
|
+
key: d.from([e]),
|
|
1941
|
+
value: s
|
|
1942
|
+
};
|
|
1943
|
+
}
|
|
1944
|
+
const a = "Buffer";
|
|
1945
|
+
function o(s) {
|
|
1946
|
+
return d.isBuffer(s);
|
|
1947
|
+
}
|
|
1948
|
+
function i(s, c) {
|
|
1949
|
+
return !!s && !!c && s.witnessScript === void 0;
|
|
1950
|
+
}
|
|
1951
|
+
return {
|
|
1952
|
+
decode: n,
|
|
1953
|
+
encode: r,
|
|
1954
|
+
check: o,
|
|
1955
|
+
expected: a,
|
|
1956
|
+
canAdd: i
|
|
1957
|
+
};
|
|
1958
|
+
}
|
|
1959
|
+
return Ke.makeConverter = t, Ke;
|
|
1960
|
+
}
|
|
1961
|
+
var on;
|
|
1962
|
+
function wt() {
|
|
1963
|
+
if (on) return ie;
|
|
1964
|
+
on = 1, Object.defineProperty(ie, "__esModule", { value: !0 });
|
|
1965
|
+
const t = A(), e = mo(), n = ko(), r = Ao(), a = Po(), o = Oo(), i = Co(), s = xo(), c = No(), u = Ho(), f = Uo(), p = Ro(), y = Fo(), S = Bo(), h = Ko(), l = zn(), w = Lo(), T = Mo(), g = Wo(), E = Xo(), b = Go(), k = {
|
|
1966
|
+
unsignedTx: n,
|
|
1967
|
+
globalXpub: e,
|
|
1968
|
+
// pass an Array of key bytes that require pubkey beside the key
|
|
1969
|
+
checkPubkey: w.makeChecker([])
|
|
1970
|
+
};
|
|
1971
|
+
ie.globals = k;
|
|
1972
|
+
const x = {
|
|
1973
|
+
nonWitnessUtxo: o,
|
|
1974
|
+
partialSig: i,
|
|
1975
|
+
sighashType: c,
|
|
1976
|
+
finalScriptSig: r,
|
|
1977
|
+
finalScriptWitness: a,
|
|
1978
|
+
porCommitment: s,
|
|
1979
|
+
witnessUtxo: S,
|
|
1980
|
+
bip32Derivation: l.makeConverter(
|
|
1981
|
+
t.InputTypes.BIP32_DERIVATION
|
|
1982
|
+
),
|
|
1983
|
+
redeemScript: T.makeConverter(
|
|
1984
|
+
t.InputTypes.REDEEM_SCRIPT
|
|
1985
|
+
),
|
|
1986
|
+
witnessScript: b.makeConverter(
|
|
1987
|
+
t.InputTypes.WITNESS_SCRIPT
|
|
1988
|
+
),
|
|
1989
|
+
checkPubkey: w.makeChecker([
|
|
1990
|
+
t.InputTypes.PARTIAL_SIG,
|
|
1991
|
+
t.InputTypes.BIP32_DERIVATION
|
|
1992
|
+
]),
|
|
1993
|
+
tapKeySig: u,
|
|
1994
|
+
tapScriptSig: y,
|
|
1995
|
+
tapLeafScript: f,
|
|
1996
|
+
tapBip32Derivation: g.makeConverter(
|
|
1997
|
+
t.InputTypes.TAP_BIP32_DERIVATION
|
|
1998
|
+
),
|
|
1999
|
+
tapInternalKey: E.makeConverter(
|
|
2000
|
+
t.InputTypes.TAP_INTERNAL_KEY
|
|
2001
|
+
),
|
|
2002
|
+
tapMerkleRoot: p
|
|
2003
|
+
};
|
|
2004
|
+
ie.inputs = x;
|
|
2005
|
+
const v = {
|
|
2006
|
+
bip32Derivation: l.makeConverter(
|
|
2007
|
+
t.OutputTypes.BIP32_DERIVATION
|
|
2008
|
+
),
|
|
2009
|
+
redeemScript: T.makeConverter(
|
|
2010
|
+
t.OutputTypes.REDEEM_SCRIPT
|
|
2011
|
+
),
|
|
2012
|
+
witnessScript: b.makeConverter(
|
|
2013
|
+
t.OutputTypes.WITNESS_SCRIPT
|
|
2014
|
+
),
|
|
2015
|
+
checkPubkey: w.makeChecker([
|
|
2016
|
+
t.OutputTypes.BIP32_DERIVATION
|
|
2017
|
+
]),
|
|
2018
|
+
tapBip32Derivation: g.makeConverter(
|
|
2019
|
+
t.OutputTypes.TAP_BIP32_DERIVATION
|
|
2020
|
+
),
|
|
2021
|
+
tapTree: h,
|
|
2022
|
+
tapInternalKey: E.makeConverter(
|
|
2023
|
+
t.OutputTypes.TAP_INTERNAL_KEY
|
|
2024
|
+
)
|
|
2025
|
+
};
|
|
2026
|
+
return ie.outputs = v, ie;
|
|
2027
|
+
}
|
|
2028
|
+
var sn;
|
|
2029
|
+
function qo() {
|
|
2030
|
+
if (sn) return oe;
|
|
2031
|
+
sn = 1, Object.defineProperty(oe, "__esModule", { value: !0 });
|
|
2032
|
+
const t = wt(), e = Et(), n = ue(), r = A();
|
|
2033
|
+
function a(s, c) {
|
|
2034
|
+
let u = 0;
|
|
2035
|
+
function f() {
|
|
2036
|
+
const v = n.decode(s, u);
|
|
2037
|
+
u += n.encodingLength(v);
|
|
2038
|
+
const m = s.slice(u, u + v);
|
|
2039
|
+
return u += v, m;
|
|
2040
|
+
}
|
|
2041
|
+
function p() {
|
|
2042
|
+
const v = s.readUInt32BE(u);
|
|
2043
|
+
return u += 4, v;
|
|
2044
|
+
}
|
|
2045
|
+
function y() {
|
|
2046
|
+
const v = s.readUInt8(u);
|
|
2047
|
+
return u += 1, v;
|
|
2048
|
+
}
|
|
2049
|
+
function S() {
|
|
2050
|
+
const v = f(), m = f();
|
|
2051
|
+
return {
|
|
2052
|
+
key: v,
|
|
2053
|
+
value: m
|
|
2054
|
+
};
|
|
2055
|
+
}
|
|
2056
|
+
function h() {
|
|
2057
|
+
if (u >= s.length)
|
|
2058
|
+
throw new Error("Format Error: Unexpected End of PSBT");
|
|
2059
|
+
const v = s.readUInt8(u) === 0;
|
|
2060
|
+
return v && u++, v;
|
|
2061
|
+
}
|
|
2062
|
+
if (p() !== 1886610036)
|
|
2063
|
+
throw new Error("Format Error: Invalid Magic Number");
|
|
2064
|
+
if (y() !== 255)
|
|
2065
|
+
throw new Error(
|
|
2066
|
+
"Format Error: Magic Number must be followed by 0xff separator"
|
|
2067
|
+
);
|
|
2068
|
+
const l = [], w = {};
|
|
2069
|
+
for (; !h(); ) {
|
|
2070
|
+
const v = S(), m = v.key.toString("hex");
|
|
2071
|
+
if (w[m])
|
|
2072
|
+
throw new Error(
|
|
2073
|
+
"Format Error: Keys must be unique for global keymap: key " + m
|
|
2074
|
+
);
|
|
2075
|
+
w[m] = 1, l.push(v);
|
|
2076
|
+
}
|
|
2077
|
+
const T = l.filter(
|
|
2078
|
+
(v) => v.key[0] === r.GlobalTypes.UNSIGNED_TX
|
|
2079
|
+
);
|
|
2080
|
+
if (T.length !== 1)
|
|
2081
|
+
throw new Error("Format Error: Only one UNSIGNED_TX allowed");
|
|
2082
|
+
const g = c(T[0].value), { inputCount: E, outputCount: b } = g.getInputOutputCounts(), k = [], x = [];
|
|
2083
|
+
for (const v of e.range(E)) {
|
|
2084
|
+
const m = {}, U = [];
|
|
2085
|
+
for (; !h(); ) {
|
|
2086
|
+
const R = S(), ee = R.key.toString("hex");
|
|
2087
|
+
if (m[ee])
|
|
2088
|
+
throw new Error(
|
|
2089
|
+
"Format Error: Keys must be unique for each input: input index " + v + " key " + ee
|
|
2090
|
+
);
|
|
2091
|
+
m[ee] = 1, U.push(R);
|
|
2092
|
+
}
|
|
2093
|
+
k.push(U);
|
|
2094
|
+
}
|
|
2095
|
+
for (const v of e.range(b)) {
|
|
2096
|
+
const m = {}, U = [];
|
|
2097
|
+
for (; !h(); ) {
|
|
2098
|
+
const R = S(), ee = R.key.toString("hex");
|
|
2099
|
+
if (m[ee])
|
|
2100
|
+
throw new Error(
|
|
2101
|
+
"Format Error: Keys must be unique for each output: output index " + v + " key " + ee
|
|
2102
|
+
);
|
|
2103
|
+
m[ee] = 1, U.push(R);
|
|
2104
|
+
}
|
|
2105
|
+
x.push(U);
|
|
2106
|
+
}
|
|
2107
|
+
return i(g, {
|
|
2108
|
+
globalMapKeyVals: l,
|
|
2109
|
+
inputKeyVals: k,
|
|
2110
|
+
outputKeyVals: x
|
|
2111
|
+
});
|
|
2112
|
+
}
|
|
2113
|
+
oe.psbtFromBuffer = a;
|
|
2114
|
+
function o(s, c, u) {
|
|
2115
|
+
if (!c.equals(d.from([u])))
|
|
2116
|
+
throw new Error(
|
|
2117
|
+
`Format Error: Invalid ${s} key: ${c.toString("hex")}`
|
|
2118
|
+
);
|
|
2119
|
+
}
|
|
2120
|
+
oe.checkKeyBuffer = o;
|
|
2121
|
+
function i(s, { globalMapKeyVals: c, inputKeyVals: u, outputKeyVals: f }) {
|
|
2122
|
+
const p = {
|
|
2123
|
+
unsignedTx: s
|
|
2124
|
+
};
|
|
2125
|
+
let y = 0;
|
|
2126
|
+
for (const T of c)
|
|
2127
|
+
switch (T.key[0]) {
|
|
2128
|
+
case r.GlobalTypes.UNSIGNED_TX:
|
|
2129
|
+
if (o(
|
|
2130
|
+
"global",
|
|
2131
|
+
T.key,
|
|
2132
|
+
r.GlobalTypes.UNSIGNED_TX
|
|
2133
|
+
), y > 0)
|
|
2134
|
+
throw new Error("Format Error: GlobalMap has multiple UNSIGNED_TX");
|
|
2135
|
+
y++;
|
|
2136
|
+
break;
|
|
2137
|
+
case r.GlobalTypes.GLOBAL_XPUB:
|
|
2138
|
+
p.globalXpub === void 0 && (p.globalXpub = []), p.globalXpub.push(t.globals.globalXpub.decode(T));
|
|
2139
|
+
break;
|
|
2140
|
+
default:
|
|
2141
|
+
p.unknownKeyVals || (p.unknownKeyVals = []), p.unknownKeyVals.push(T);
|
|
2142
|
+
}
|
|
2143
|
+
const S = u.length, h = f.length, l = [], w = [];
|
|
2144
|
+
for (const T of e.range(S)) {
|
|
2145
|
+
const g = {};
|
|
2146
|
+
for (const E of u[T])
|
|
2147
|
+
switch (t.inputs.checkPubkey(E), E.key[0]) {
|
|
2148
|
+
case r.InputTypes.NON_WITNESS_UTXO:
|
|
2149
|
+
if (o(
|
|
2150
|
+
"input",
|
|
2151
|
+
E.key,
|
|
2152
|
+
r.InputTypes.NON_WITNESS_UTXO
|
|
2153
|
+
), g.nonWitnessUtxo !== void 0)
|
|
2154
|
+
throw new Error(
|
|
2155
|
+
"Format Error: Input has multiple NON_WITNESS_UTXO"
|
|
2156
|
+
);
|
|
2157
|
+
g.nonWitnessUtxo = t.inputs.nonWitnessUtxo.decode(E);
|
|
2158
|
+
break;
|
|
2159
|
+
case r.InputTypes.WITNESS_UTXO:
|
|
2160
|
+
if (o(
|
|
2161
|
+
"input",
|
|
2162
|
+
E.key,
|
|
2163
|
+
r.InputTypes.WITNESS_UTXO
|
|
2164
|
+
), g.witnessUtxo !== void 0)
|
|
2165
|
+
throw new Error("Format Error: Input has multiple WITNESS_UTXO");
|
|
2166
|
+
g.witnessUtxo = t.inputs.witnessUtxo.decode(E);
|
|
2167
|
+
break;
|
|
2168
|
+
case r.InputTypes.PARTIAL_SIG:
|
|
2169
|
+
g.partialSig === void 0 && (g.partialSig = []), g.partialSig.push(t.inputs.partialSig.decode(E));
|
|
2170
|
+
break;
|
|
2171
|
+
case r.InputTypes.SIGHASH_TYPE:
|
|
2172
|
+
if (o(
|
|
2173
|
+
"input",
|
|
2174
|
+
E.key,
|
|
2175
|
+
r.InputTypes.SIGHASH_TYPE
|
|
2176
|
+
), g.sighashType !== void 0)
|
|
2177
|
+
throw new Error("Format Error: Input has multiple SIGHASH_TYPE");
|
|
2178
|
+
g.sighashType = t.inputs.sighashType.decode(E);
|
|
2179
|
+
break;
|
|
2180
|
+
case r.InputTypes.REDEEM_SCRIPT:
|
|
2181
|
+
if (o(
|
|
2182
|
+
"input",
|
|
2183
|
+
E.key,
|
|
2184
|
+
r.InputTypes.REDEEM_SCRIPT
|
|
2185
|
+
), g.redeemScript !== void 0)
|
|
2186
|
+
throw new Error("Format Error: Input has multiple REDEEM_SCRIPT");
|
|
2187
|
+
g.redeemScript = t.inputs.redeemScript.decode(E);
|
|
2188
|
+
break;
|
|
2189
|
+
case r.InputTypes.WITNESS_SCRIPT:
|
|
2190
|
+
if (o(
|
|
2191
|
+
"input",
|
|
2192
|
+
E.key,
|
|
2193
|
+
r.InputTypes.WITNESS_SCRIPT
|
|
2194
|
+
), g.witnessScript !== void 0)
|
|
2195
|
+
throw new Error("Format Error: Input has multiple WITNESS_SCRIPT");
|
|
2196
|
+
g.witnessScript = t.inputs.witnessScript.decode(E);
|
|
2197
|
+
break;
|
|
2198
|
+
case r.InputTypes.BIP32_DERIVATION:
|
|
2199
|
+
g.bip32Derivation === void 0 && (g.bip32Derivation = []), g.bip32Derivation.push(
|
|
2200
|
+
t.inputs.bip32Derivation.decode(E)
|
|
2201
|
+
);
|
|
2202
|
+
break;
|
|
2203
|
+
case r.InputTypes.FINAL_SCRIPTSIG:
|
|
2204
|
+
o(
|
|
2205
|
+
"input",
|
|
2206
|
+
E.key,
|
|
2207
|
+
r.InputTypes.FINAL_SCRIPTSIG
|
|
2208
|
+
), g.finalScriptSig = t.inputs.finalScriptSig.decode(E);
|
|
2209
|
+
break;
|
|
2210
|
+
case r.InputTypes.FINAL_SCRIPTWITNESS:
|
|
2211
|
+
o(
|
|
2212
|
+
"input",
|
|
2213
|
+
E.key,
|
|
2214
|
+
r.InputTypes.FINAL_SCRIPTWITNESS
|
|
2215
|
+
), g.finalScriptWitness = t.inputs.finalScriptWitness.decode(
|
|
2216
|
+
E
|
|
2217
|
+
);
|
|
2218
|
+
break;
|
|
2219
|
+
case r.InputTypes.POR_COMMITMENT:
|
|
2220
|
+
o(
|
|
2221
|
+
"input",
|
|
2222
|
+
E.key,
|
|
2223
|
+
r.InputTypes.POR_COMMITMENT
|
|
2224
|
+
), g.porCommitment = t.inputs.porCommitment.decode(E);
|
|
2225
|
+
break;
|
|
2226
|
+
case r.InputTypes.TAP_KEY_SIG:
|
|
2227
|
+
o(
|
|
2228
|
+
"input",
|
|
2229
|
+
E.key,
|
|
2230
|
+
r.InputTypes.TAP_KEY_SIG
|
|
2231
|
+
), g.tapKeySig = t.inputs.tapKeySig.decode(E);
|
|
2232
|
+
break;
|
|
2233
|
+
case r.InputTypes.TAP_SCRIPT_SIG:
|
|
2234
|
+
g.tapScriptSig === void 0 && (g.tapScriptSig = []), g.tapScriptSig.push(t.inputs.tapScriptSig.decode(E));
|
|
2235
|
+
break;
|
|
2236
|
+
case r.InputTypes.TAP_LEAF_SCRIPT:
|
|
2237
|
+
g.tapLeafScript === void 0 && (g.tapLeafScript = []), g.tapLeafScript.push(t.inputs.tapLeafScript.decode(E));
|
|
2238
|
+
break;
|
|
2239
|
+
case r.InputTypes.TAP_BIP32_DERIVATION:
|
|
2240
|
+
g.tapBip32Derivation === void 0 && (g.tapBip32Derivation = []), g.tapBip32Derivation.push(
|
|
2241
|
+
t.inputs.tapBip32Derivation.decode(E)
|
|
2242
|
+
);
|
|
2243
|
+
break;
|
|
2244
|
+
case r.InputTypes.TAP_INTERNAL_KEY:
|
|
2245
|
+
o(
|
|
2246
|
+
"input",
|
|
2247
|
+
E.key,
|
|
2248
|
+
r.InputTypes.TAP_INTERNAL_KEY
|
|
2249
|
+
), g.tapInternalKey = t.inputs.tapInternalKey.decode(E);
|
|
2250
|
+
break;
|
|
2251
|
+
case r.InputTypes.TAP_MERKLE_ROOT:
|
|
2252
|
+
o(
|
|
2253
|
+
"input",
|
|
2254
|
+
E.key,
|
|
2255
|
+
r.InputTypes.TAP_MERKLE_ROOT
|
|
2256
|
+
), g.tapMerkleRoot = t.inputs.tapMerkleRoot.decode(E);
|
|
2257
|
+
break;
|
|
2258
|
+
default:
|
|
2259
|
+
g.unknownKeyVals || (g.unknownKeyVals = []), g.unknownKeyVals.push(E);
|
|
2260
|
+
}
|
|
2261
|
+
l.push(g);
|
|
2262
|
+
}
|
|
2263
|
+
for (const T of e.range(h)) {
|
|
2264
|
+
const g = {};
|
|
2265
|
+
for (const E of f[T])
|
|
2266
|
+
switch (t.outputs.checkPubkey(E), E.key[0]) {
|
|
2267
|
+
case r.OutputTypes.REDEEM_SCRIPT:
|
|
2268
|
+
if (o(
|
|
2269
|
+
"output",
|
|
2270
|
+
E.key,
|
|
2271
|
+
r.OutputTypes.REDEEM_SCRIPT
|
|
2272
|
+
), g.redeemScript !== void 0)
|
|
2273
|
+
throw new Error("Format Error: Output has multiple REDEEM_SCRIPT");
|
|
2274
|
+
g.redeemScript = t.outputs.redeemScript.decode(E);
|
|
2275
|
+
break;
|
|
2276
|
+
case r.OutputTypes.WITNESS_SCRIPT:
|
|
2277
|
+
if (o(
|
|
2278
|
+
"output",
|
|
2279
|
+
E.key,
|
|
2280
|
+
r.OutputTypes.WITNESS_SCRIPT
|
|
2281
|
+
), g.witnessScript !== void 0)
|
|
2282
|
+
throw new Error("Format Error: Output has multiple WITNESS_SCRIPT");
|
|
2283
|
+
g.witnessScript = t.outputs.witnessScript.decode(E);
|
|
2284
|
+
break;
|
|
2285
|
+
case r.OutputTypes.BIP32_DERIVATION:
|
|
2286
|
+
g.bip32Derivation === void 0 && (g.bip32Derivation = []), g.bip32Derivation.push(
|
|
2287
|
+
t.outputs.bip32Derivation.decode(E)
|
|
2288
|
+
);
|
|
2289
|
+
break;
|
|
2290
|
+
case r.OutputTypes.TAP_INTERNAL_KEY:
|
|
2291
|
+
o(
|
|
2292
|
+
"output",
|
|
2293
|
+
E.key,
|
|
2294
|
+
r.OutputTypes.TAP_INTERNAL_KEY
|
|
2295
|
+
), g.tapInternalKey = t.outputs.tapInternalKey.decode(E);
|
|
2296
|
+
break;
|
|
2297
|
+
case r.OutputTypes.TAP_TREE:
|
|
2298
|
+
o(
|
|
2299
|
+
"output",
|
|
2300
|
+
E.key,
|
|
2301
|
+
r.OutputTypes.TAP_TREE
|
|
2302
|
+
), g.tapTree = t.outputs.tapTree.decode(E);
|
|
2303
|
+
break;
|
|
2304
|
+
case r.OutputTypes.TAP_BIP32_DERIVATION:
|
|
2305
|
+
g.tapBip32Derivation === void 0 && (g.tapBip32Derivation = []), g.tapBip32Derivation.push(
|
|
2306
|
+
t.outputs.tapBip32Derivation.decode(E)
|
|
2307
|
+
);
|
|
2308
|
+
break;
|
|
2309
|
+
default:
|
|
2310
|
+
g.unknownKeyVals || (g.unknownKeyVals = []), g.unknownKeyVals.push(E);
|
|
2311
|
+
}
|
|
2312
|
+
w.push(g);
|
|
2313
|
+
}
|
|
2314
|
+
return { globalMap: p, inputs: l, outputs: w };
|
|
2315
|
+
}
|
|
2316
|
+
return oe.psbtFromKeyVals = i, oe;
|
|
2317
|
+
}
|
|
2318
|
+
var fe = {}, an;
|
|
2319
|
+
function Do() {
|
|
2320
|
+
if (an) return fe;
|
|
2321
|
+
an = 1, Object.defineProperty(fe, "__esModule", { value: !0 });
|
|
2322
|
+
const t = wt(), e = Et();
|
|
2323
|
+
function n({ globalMap: i, inputs: s, outputs: c }) {
|
|
2324
|
+
const { globalKeyVals: u, inputKeyVals: f, outputKeyVals: p } = o({
|
|
2325
|
+
globalMap: i,
|
|
2326
|
+
inputs: s,
|
|
2327
|
+
outputs: c
|
|
2328
|
+
}), y = e.keyValsToBuffer(u), S = (T) => T.length === 0 ? [d.from([0])] : T.map(e.keyValsToBuffer), h = S(f), l = S(p), w = d.allocUnsafe(5);
|
|
2329
|
+
return w.writeUIntBE(482972169471, 0, 5), d.concat(
|
|
2330
|
+
[w, y].concat(h, l)
|
|
2331
|
+
);
|
|
2332
|
+
}
|
|
2333
|
+
fe.psbtToBuffer = n;
|
|
2334
|
+
const r = (i, s) => i.key.compare(s.key);
|
|
2335
|
+
function a(i, s) {
|
|
2336
|
+
const c = /* @__PURE__ */ new Set(), u = Object.entries(i).reduce((p, [y, S]) => {
|
|
2337
|
+
if (y === "unknownKeyVals") return p;
|
|
2338
|
+
const h = s[y];
|
|
2339
|
+
if (h === void 0) return p;
|
|
2340
|
+
const l = (Array.isArray(S) ? S : [S]).map(
|
|
2341
|
+
h.encode
|
|
2342
|
+
);
|
|
2343
|
+
return l.map((T) => T.key.toString("hex")).forEach((T) => {
|
|
2344
|
+
if (c.has(T))
|
|
2345
|
+
throw new Error("Serialize Error: Duplicate key: " + T);
|
|
2346
|
+
c.add(T);
|
|
2347
|
+
}), p.concat(l);
|
|
2348
|
+
}, []), f = i.unknownKeyVals ? i.unknownKeyVals.filter((p) => !c.has(p.key.toString("hex"))) : [];
|
|
2349
|
+
return u.concat(f).sort(r);
|
|
2350
|
+
}
|
|
2351
|
+
function o({ globalMap: i, inputs: s, outputs: c }) {
|
|
2352
|
+
return {
|
|
2353
|
+
globalKeyVals: a(i, t.globals),
|
|
2354
|
+
inputKeyVals: s.map((u) => a(u, t.inputs)),
|
|
2355
|
+
outputKeyVals: c.map((u) => a(u, t.outputs))
|
|
2356
|
+
};
|
|
2357
|
+
}
|
|
2358
|
+
return fe.psbtToKeyVals = o, fe;
|
|
2359
|
+
}
|
|
2360
|
+
var cn;
|
|
2361
|
+
function Yn() {
|
|
2362
|
+
return cn || (cn = 1, (function(t) {
|
|
2363
|
+
function e(n) {
|
|
2364
|
+
for (var r in n) t.hasOwnProperty(r) || (t[r] = n[r]);
|
|
2365
|
+
}
|
|
2366
|
+
Object.defineProperty(t, "__esModule", { value: !0 }), e(qo()), e(Do());
|
|
2367
|
+
})(it)), it;
|
|
2368
|
+
}
|
|
2369
|
+
var un;
|
|
2370
|
+
function Vo() {
|
|
2371
|
+
if (un) return xe;
|
|
2372
|
+
un = 1, Object.defineProperty(xe, "__esModule", { value: !0 });
|
|
2373
|
+
const t = Yn();
|
|
2374
|
+
function e(o) {
|
|
2375
|
+
const i = o[0], s = t.psbtToKeyVals(i), c = o.slice(1);
|
|
2376
|
+
if (c.length === 0) throw new Error("Combine: Nothing to combine");
|
|
2377
|
+
const u = r(i);
|
|
2378
|
+
if (u === void 0)
|
|
2379
|
+
throw new Error("Combine: Self missing transaction");
|
|
2380
|
+
const f = a(s.globalKeyVals), p = s.inputKeyVals.map(a), y = s.outputKeyVals.map(a);
|
|
2381
|
+
for (const S of c) {
|
|
2382
|
+
const h = r(S);
|
|
2383
|
+
if (h === void 0 || !h.toBuffer().equals(u.toBuffer()))
|
|
2384
|
+
throw new Error(
|
|
2385
|
+
"Combine: One of the Psbts does not have the same transaction."
|
|
2386
|
+
);
|
|
2387
|
+
const l = t.psbtToKeyVals(S);
|
|
2388
|
+
a(l.globalKeyVals).forEach(
|
|
2389
|
+
n(
|
|
2390
|
+
f,
|
|
2391
|
+
s.globalKeyVals,
|
|
2392
|
+
l.globalKeyVals
|
|
2393
|
+
)
|
|
2394
|
+
), l.inputKeyVals.map(a).forEach(
|
|
2395
|
+
(E, b) => E.forEach(
|
|
2396
|
+
n(
|
|
2397
|
+
p[b],
|
|
2398
|
+
s.inputKeyVals[b],
|
|
2399
|
+
l.inputKeyVals[b]
|
|
2400
|
+
)
|
|
2401
|
+
)
|
|
2402
|
+
), l.outputKeyVals.map(a).forEach(
|
|
2403
|
+
(E, b) => E.forEach(
|
|
2404
|
+
n(
|
|
2405
|
+
y[b],
|
|
2406
|
+
s.outputKeyVals[b],
|
|
2407
|
+
l.outputKeyVals[b]
|
|
2408
|
+
)
|
|
2409
|
+
)
|
|
2410
|
+
);
|
|
2411
|
+
}
|
|
2412
|
+
return t.psbtFromKeyVals(u, {
|
|
2413
|
+
globalMapKeyVals: s.globalKeyVals,
|
|
2414
|
+
inputKeyVals: s.inputKeyVals,
|
|
2415
|
+
outputKeyVals: s.outputKeyVals
|
|
2416
|
+
});
|
|
2417
|
+
}
|
|
2418
|
+
xe.combine = e;
|
|
2419
|
+
function n(o, i, s) {
|
|
2420
|
+
return (c) => {
|
|
2421
|
+
if (o.has(c)) return;
|
|
2422
|
+
const u = s.filter((f) => f.key.toString("hex") === c)[0];
|
|
2423
|
+
i.push(u), o.add(c);
|
|
2424
|
+
};
|
|
2425
|
+
}
|
|
2426
|
+
function r(o) {
|
|
2427
|
+
return o.globalMap.unsignedTx;
|
|
2428
|
+
}
|
|
2429
|
+
function a(o) {
|
|
2430
|
+
const i = /* @__PURE__ */ new Set();
|
|
2431
|
+
return o.forEach((s) => {
|
|
2432
|
+
const c = s.key.toString("hex");
|
|
2433
|
+
if (i.has(c))
|
|
2434
|
+
throw new Error("Combine: KeyValue Map keys should be unique");
|
|
2435
|
+
i.add(c);
|
|
2436
|
+
}), i;
|
|
2437
|
+
}
|
|
2438
|
+
return xe;
|
|
2439
|
+
}
|
|
2440
|
+
var at = {}, fn;
|
|
2441
|
+
function $n() {
|
|
2442
|
+
return fn || (fn = 1, (function(t) {
|
|
2443
|
+
Object.defineProperty(t, "__esModule", { value: !0 });
|
|
2444
|
+
const e = wt();
|
|
2445
|
+
function n(S, h) {
|
|
2446
|
+
const l = S[h];
|
|
2447
|
+
if (l === void 0) throw new Error(`No input #${h}`);
|
|
2448
|
+
return l;
|
|
2449
|
+
}
|
|
2450
|
+
t.checkForInput = n;
|
|
2451
|
+
function r(S, h) {
|
|
2452
|
+
const l = S[h];
|
|
2453
|
+
if (l === void 0) throw new Error(`No output #${h}`);
|
|
2454
|
+
return l;
|
|
2455
|
+
}
|
|
2456
|
+
t.checkForOutput = r;
|
|
2457
|
+
function a(S, h, l) {
|
|
2458
|
+
if (S.key[0] < l)
|
|
2459
|
+
throw new Error(
|
|
2460
|
+
"Use the method for your specific key instead of addUnknownKeyVal*"
|
|
2461
|
+
);
|
|
2462
|
+
if (h && h.filter((w) => w.key.equals(S.key)).length !== 0)
|
|
2463
|
+
throw new Error(`Duplicate Key: ${S.key.toString("hex")}`);
|
|
2464
|
+
}
|
|
2465
|
+
t.checkHasKey = a;
|
|
2466
|
+
function o(S) {
|
|
2467
|
+
let h = 0;
|
|
2468
|
+
return Object.keys(S).forEach((l) => {
|
|
2469
|
+
Number(isNaN(Number(l))) && h++;
|
|
2470
|
+
}), h;
|
|
2471
|
+
}
|
|
2472
|
+
t.getEnumLength = o;
|
|
2473
|
+
function i(S, h) {
|
|
2474
|
+
let l = !1;
|
|
2475
|
+
if (h.nonWitnessUtxo || h.witnessUtxo) {
|
|
2476
|
+
const w = !!h.redeemScript, T = !!h.witnessScript, g = !w || !!h.finalScriptSig, E = !T || !!h.finalScriptWitness, b = !!h.finalScriptSig || !!h.finalScriptWitness;
|
|
2477
|
+
l = g && E && b;
|
|
2478
|
+
}
|
|
2479
|
+
if (l === !1)
|
|
2480
|
+
throw new Error(
|
|
2481
|
+
`Input #${S} has too much or too little data to clean`
|
|
2482
|
+
);
|
|
2483
|
+
}
|
|
2484
|
+
t.inputCheckUncleanFinalized = i;
|
|
2485
|
+
function s(S, h, l, w) {
|
|
2486
|
+
throw new Error(
|
|
2487
|
+
`Data for ${S} key ${h} is incorrect: Expected ${l} and got ${JSON.stringify(w)}`
|
|
2488
|
+
);
|
|
2489
|
+
}
|
|
2490
|
+
function c(S) {
|
|
2491
|
+
return (h, l) => {
|
|
2492
|
+
for (const w of Object.keys(h)) {
|
|
2493
|
+
const T = h[w], { canAdd: g, canAddToArray: E, check: b, expected: k } = (
|
|
2494
|
+
// @ts-ignore
|
|
2495
|
+
e[S + "s"][w] || {}
|
|
2496
|
+
), x = !!E;
|
|
2497
|
+
if (b)
|
|
2498
|
+
if (x) {
|
|
2499
|
+
if (!Array.isArray(T) || // @ts-ignore
|
|
2500
|
+
l[w] && !Array.isArray(l[w]))
|
|
2501
|
+
throw new Error(`Key type ${w} must be an array`);
|
|
2502
|
+
T.every(b) || s(S, w, k, T);
|
|
2503
|
+
const v = l[w] || [], m = /* @__PURE__ */ new Set();
|
|
2504
|
+
if (!T.every((U) => E(v, U, m)))
|
|
2505
|
+
throw new Error("Can not add duplicate data to array");
|
|
2506
|
+
l[w] = v.concat(T);
|
|
2507
|
+
} else {
|
|
2508
|
+
if (b(T) || s(S, w, k, T), !g(l, T))
|
|
2509
|
+
throw new Error(`Can not add duplicate data to ${S}`);
|
|
2510
|
+
l[w] = T;
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2513
|
+
};
|
|
2514
|
+
}
|
|
2515
|
+
t.updateGlobal = c("global"), t.updateInput = c("input"), t.updateOutput = c("output");
|
|
2516
|
+
function u(S, h) {
|
|
2517
|
+
const l = S.length - 1, w = n(S, l);
|
|
2518
|
+
t.updateInput(h, w);
|
|
2519
|
+
}
|
|
2520
|
+
t.addInputAttributes = u;
|
|
2521
|
+
function f(S, h) {
|
|
2522
|
+
const l = S.length - 1, w = r(S, l);
|
|
2523
|
+
t.updateOutput(h, w);
|
|
2524
|
+
}
|
|
2525
|
+
t.addOutputAttributes = f;
|
|
2526
|
+
function p(S, h) {
|
|
2527
|
+
if (!d.isBuffer(h) || h.length < 4)
|
|
2528
|
+
throw new Error("Set Version: Invalid Transaction");
|
|
2529
|
+
return h.writeUInt32LE(S, 0), h;
|
|
2530
|
+
}
|
|
2531
|
+
t.defaultVersionSetter = p;
|
|
2532
|
+
function y(S, h) {
|
|
2533
|
+
if (!d.isBuffer(h) || h.length < 4)
|
|
2534
|
+
throw new Error("Set Locktime: Invalid Transaction");
|
|
2535
|
+
return h.writeUInt32LE(S, h.length - 4), h;
|
|
2536
|
+
}
|
|
2537
|
+
t.defaultLocktimeSetter = y;
|
|
2538
|
+
})(at)), at;
|
|
2539
|
+
}
|
|
2540
|
+
var pn;
|
|
2541
|
+
function jo() {
|
|
2542
|
+
if (pn) return Ce;
|
|
2543
|
+
pn = 1, Object.defineProperty(Ce, "__esModule", { value: !0 });
|
|
2544
|
+
const t = Vo(), e = Yn(), n = A(), r = $n();
|
|
2545
|
+
class a {
|
|
2546
|
+
constructor(i) {
|
|
2547
|
+
this.inputs = [], this.outputs = [], this.globalMap = {
|
|
2548
|
+
unsignedTx: i
|
|
2549
|
+
};
|
|
2550
|
+
}
|
|
2551
|
+
static fromBase64(i, s) {
|
|
2552
|
+
const c = d.from(i, "base64");
|
|
2553
|
+
return this.fromBuffer(c, s);
|
|
2554
|
+
}
|
|
2555
|
+
static fromHex(i, s) {
|
|
2556
|
+
const c = d.from(i, "hex");
|
|
2557
|
+
return this.fromBuffer(c, s);
|
|
2558
|
+
}
|
|
2559
|
+
static fromBuffer(i, s) {
|
|
2560
|
+
const c = e.psbtFromBuffer(i, s), u = new this(c.globalMap.unsignedTx);
|
|
2561
|
+
return Object.assign(u, c), u;
|
|
2562
|
+
}
|
|
2563
|
+
toBase64() {
|
|
2564
|
+
return this.toBuffer().toString("base64");
|
|
2565
|
+
}
|
|
2566
|
+
toHex() {
|
|
2567
|
+
return this.toBuffer().toString("hex");
|
|
2568
|
+
}
|
|
2569
|
+
toBuffer() {
|
|
2570
|
+
return e.psbtToBuffer(this);
|
|
2571
|
+
}
|
|
2572
|
+
updateGlobal(i) {
|
|
2573
|
+
return r.updateGlobal(i, this.globalMap), this;
|
|
2574
|
+
}
|
|
2575
|
+
updateInput(i, s) {
|
|
2576
|
+
const c = r.checkForInput(this.inputs, i);
|
|
2577
|
+
return r.updateInput(s, c), this;
|
|
2578
|
+
}
|
|
2579
|
+
updateOutput(i, s) {
|
|
2580
|
+
const c = r.checkForOutput(this.outputs, i);
|
|
2581
|
+
return r.updateOutput(s, c), this;
|
|
2582
|
+
}
|
|
2583
|
+
addUnknownKeyValToGlobal(i) {
|
|
2584
|
+
return r.checkHasKey(
|
|
2585
|
+
i,
|
|
2586
|
+
this.globalMap.unknownKeyVals,
|
|
2587
|
+
r.getEnumLength(n.GlobalTypes)
|
|
2588
|
+
), this.globalMap.unknownKeyVals || (this.globalMap.unknownKeyVals = []), this.globalMap.unknownKeyVals.push(i), this;
|
|
2589
|
+
}
|
|
2590
|
+
addUnknownKeyValToInput(i, s) {
|
|
2591
|
+
const c = r.checkForInput(this.inputs, i);
|
|
2592
|
+
return r.checkHasKey(
|
|
2593
|
+
s,
|
|
2594
|
+
c.unknownKeyVals,
|
|
2595
|
+
r.getEnumLength(n.InputTypes)
|
|
2596
|
+
), c.unknownKeyVals || (c.unknownKeyVals = []), c.unknownKeyVals.push(s), this;
|
|
2597
|
+
}
|
|
2598
|
+
addUnknownKeyValToOutput(i, s) {
|
|
2599
|
+
const c = r.checkForOutput(this.outputs, i);
|
|
2600
|
+
return r.checkHasKey(
|
|
2601
|
+
s,
|
|
2602
|
+
c.unknownKeyVals,
|
|
2603
|
+
r.getEnumLength(n.OutputTypes)
|
|
2604
|
+
), c.unknownKeyVals || (c.unknownKeyVals = []), c.unknownKeyVals.push(s), this;
|
|
2605
|
+
}
|
|
2606
|
+
addInput(i) {
|
|
2607
|
+
this.globalMap.unsignedTx.addInput(i), this.inputs.push({
|
|
2608
|
+
unknownKeyVals: []
|
|
2609
|
+
});
|
|
2610
|
+
const s = i.unknownKeyVals || [], c = this.inputs.length - 1;
|
|
2611
|
+
if (!Array.isArray(s))
|
|
2612
|
+
throw new Error("unknownKeyVals must be an Array");
|
|
2613
|
+
return s.forEach(
|
|
2614
|
+
(u) => this.addUnknownKeyValToInput(c, u)
|
|
2615
|
+
), r.addInputAttributes(this.inputs, i), this;
|
|
2616
|
+
}
|
|
2617
|
+
addOutput(i) {
|
|
2618
|
+
this.globalMap.unsignedTx.addOutput(i), this.outputs.push({
|
|
2619
|
+
unknownKeyVals: []
|
|
2620
|
+
});
|
|
2621
|
+
const s = i.unknownKeyVals || [], c = this.outputs.length - 1;
|
|
2622
|
+
if (!Array.isArray(s))
|
|
2623
|
+
throw new Error("unknownKeyVals must be an Array");
|
|
2624
|
+
return s.forEach(
|
|
2625
|
+
(u) => this.addUnknownKeyValToOutput(c, u)
|
|
2626
|
+
), r.addOutputAttributes(this.outputs, i), this;
|
|
2627
|
+
}
|
|
2628
|
+
clearFinalizedInput(i) {
|
|
2629
|
+
const s = r.checkForInput(this.inputs, i);
|
|
2630
|
+
r.inputCheckUncleanFinalized(i, s);
|
|
2631
|
+
for (const c of Object.keys(s))
|
|
2632
|
+
[
|
|
2633
|
+
"witnessUtxo",
|
|
2634
|
+
"nonWitnessUtxo",
|
|
2635
|
+
"finalScriptSig",
|
|
2636
|
+
"finalScriptWitness",
|
|
2637
|
+
"unknownKeyVals"
|
|
2638
|
+
].includes(c) || delete s[c];
|
|
2639
|
+
return this;
|
|
2640
|
+
}
|
|
2641
|
+
combine(...i) {
|
|
2642
|
+
const s = t.combine([this].concat(i));
|
|
2643
|
+
return Object.assign(this, s), this;
|
|
2644
|
+
}
|
|
2645
|
+
getTransaction() {
|
|
2646
|
+
return this.globalMap.unsignedTx.toBuffer();
|
|
2647
|
+
}
|
|
2648
|
+
}
|
|
2649
|
+
return Ce.Psbt = a, Ce;
|
|
2650
|
+
}
|
|
2651
|
+
var hn = jo(), O = $n();
|
|
2652
|
+
const zo = {
|
|
2653
|
+
/**
|
|
2654
|
+
* A bitcoinjs Network object. This is only used if you pass an `address`
|
|
2655
|
+
* parameter to addOutput. Otherwise it is not needed and can be left default.
|
|
2656
|
+
*/
|
|
2657
|
+
network: Ve,
|
|
2658
|
+
/**
|
|
2659
|
+
* When extractTransaction is called, the fee rate is checked.
|
|
2660
|
+
* THIS IS NOT TO BE RELIED ON.
|
|
2661
|
+
* It is only here as a last ditch effort to prevent sending a 500 BTC fee etc.
|
|
2662
|
+
*/
|
|
2663
|
+
maximumFeeRate: 5e3
|
|
2664
|
+
// satoshi per byte
|
|
2665
|
+
};
|
|
2666
|
+
class ht {
|
|
2667
|
+
constructor(e = {}, n = new hn.Psbt(new Zn())) {
|
|
2668
|
+
this.data = n, this.opts = Object.assign({}, zo, e), this.__CACHE = {
|
|
2669
|
+
__NON_WITNESS_UTXO_TX_CACHE: [],
|
|
2670
|
+
__NON_WITNESS_UTXO_BUF_CACHE: [],
|
|
2671
|
+
__TX_IN_CACHE: {},
|
|
2672
|
+
// @ts-expect-error no.
|
|
2673
|
+
__TX: this.data.globalMap.unsignedTx.tx,
|
|
2674
|
+
// Now TypeScript knows unsignedTx is a PsbtTransaction
|
|
2675
|
+
__UNSAFE_SIGN_NONSEGWIT: !1
|
|
2676
|
+
}, e.version === 3 ? this.setVersionTRUC() : this.data.inputs.length === 0 && this.setVersion(2);
|
|
2677
|
+
const r = (a, o, i, s) => {
|
|
2678
|
+
Object.defineProperty(a, o, {
|
|
2679
|
+
enumerable: i,
|
|
2680
|
+
writable: s
|
|
2681
|
+
});
|
|
2682
|
+
};
|
|
2683
|
+
r(this, "__CACHE", !1, !0), r(this, "opts", !1, !0);
|
|
2684
|
+
}
|
|
2685
|
+
get inputCount() {
|
|
2686
|
+
return this.data.inputs.length;
|
|
2687
|
+
}
|
|
2688
|
+
get version() {
|
|
2689
|
+
return this.__CACHE.__TX.version;
|
|
2690
|
+
}
|
|
2691
|
+
set version(e) {
|
|
2692
|
+
this.setVersion(e);
|
|
2693
|
+
}
|
|
2694
|
+
get locktime() {
|
|
2695
|
+
return this.__CACHE.__TX.locktime;
|
|
2696
|
+
}
|
|
2697
|
+
set locktime(e) {
|
|
2698
|
+
this.setLocktime(e);
|
|
2699
|
+
}
|
|
2700
|
+
get txInputs() {
|
|
2701
|
+
return this.__CACHE.__TX.ins.map((e) => ({
|
|
2702
|
+
hash: bt(e.hash),
|
|
2703
|
+
index: e.index,
|
|
2704
|
+
sequence: e.sequence
|
|
2705
|
+
}));
|
|
2706
|
+
}
|
|
2707
|
+
get txOutputs() {
|
|
2708
|
+
return this.__CACHE.__TX.outs.map((e) => {
|
|
2709
|
+
let n;
|
|
2710
|
+
try {
|
|
2711
|
+
n = Rn(e.script, this.opts.network);
|
|
2712
|
+
} catch {
|
|
2713
|
+
}
|
|
2714
|
+
return {
|
|
2715
|
+
script: bt(e.script),
|
|
2716
|
+
value: e.value,
|
|
2717
|
+
address: n
|
|
2718
|
+
};
|
|
2719
|
+
});
|
|
2720
|
+
}
|
|
2721
|
+
static fromBase64(e, n = {}) {
|
|
2722
|
+
const r = d.from(e, "base64");
|
|
2723
|
+
return this.fromBuffer(r, n);
|
|
2724
|
+
}
|
|
2725
|
+
static fromHex(e, n = {}) {
|
|
2726
|
+
const r = d.from(e, "hex");
|
|
2727
|
+
return this.fromBuffer(r, n);
|
|
2728
|
+
}
|
|
2729
|
+
static fromBuffer(e, n = {}) {
|
|
2730
|
+
const r = hn.Psbt.fromBuffer(e, Yo), a = new ht(n, r);
|
|
2731
|
+
return ei(a.__CACHE.__TX, a.__CACHE), a;
|
|
2732
|
+
}
|
|
2733
|
+
combine(...e) {
|
|
2734
|
+
return this.data.combine(...e.map((n) => n.data)), this;
|
|
2735
|
+
}
|
|
2736
|
+
clone() {
|
|
2737
|
+
return ht.fromBuffer(this.data.toBuffer(), JSON.parse(JSON.stringify(this.opts)));
|
|
2738
|
+
}
|
|
2739
|
+
setMaximumFeeRate(e) {
|
|
2740
|
+
Le(e), this.opts.maximumFeeRate = e;
|
|
2741
|
+
}
|
|
2742
|
+
setVersion(e) {
|
|
2743
|
+
Le(e), pe(this.data.inputs, "setVersion");
|
|
2744
|
+
const n = this.__CACHE;
|
|
2745
|
+
return n.__TX.version = e, n.__EXTRACTED_TX = void 0, this;
|
|
2746
|
+
}
|
|
2747
|
+
setVersionTRUC() {
|
|
2748
|
+
return this.setVersion(I.TRUC_VERSION);
|
|
2749
|
+
}
|
|
2750
|
+
setLocktime(e) {
|
|
2751
|
+
Le(e), pe(this.data.inputs, "setLocktime");
|
|
2752
|
+
const n = this.__CACHE;
|
|
2753
|
+
return n.__TX.locktime = e, n.__EXTRACTED_TX = void 0, this;
|
|
2754
|
+
}
|
|
2755
|
+
setInputSequence(e, n) {
|
|
2756
|
+
Le(n), pe(this.data.inputs, "setInputSequence");
|
|
2757
|
+
const r = this.__CACHE;
|
|
2758
|
+
if (r.__TX.ins.length <= e)
|
|
2759
|
+
throw new Error("Input index too high");
|
|
2760
|
+
return r.__TX.ins[e].sequence = n, r.__EXTRACTED_TX = void 0, this;
|
|
2761
|
+
}
|
|
2762
|
+
addInputs(e, n = !0) {
|
|
2763
|
+
return e.forEach((r) => this.addInput(r, n)), this;
|
|
2764
|
+
}
|
|
2765
|
+
addInput(e, n = !0) {
|
|
2766
|
+
if (!e || e.hash === void 0 || e.index === void 0)
|
|
2767
|
+
throw new Error(
|
|
2768
|
+
"Invalid arguments for Psbt.addInput. Requires single object with at least [hash] and [index]"
|
|
2769
|
+
);
|
|
2770
|
+
Nt(e, e, "addInput"), n && pe(this.data.inputs, "addInput"), e.witnessScript && Xe(e.witnessScript);
|
|
2771
|
+
const r = this.__CACHE;
|
|
2772
|
+
this.data.addInput(e);
|
|
2773
|
+
const a = r.__TX.ins[r.__TX.ins.length - 1];
|
|
2774
|
+
er(r, a);
|
|
2775
|
+
const o = this.data.inputs.length - 1, i = this.data.inputs[o];
|
|
2776
|
+
return i.nonWitnessUtxo && dt(this.__CACHE, i, o), r.__FEE = void 0, r.__FEE_RATE = void 0, r.__EXTRACTED_TX = void 0, this;
|
|
2777
|
+
}
|
|
2778
|
+
addOutputs(e) {
|
|
2779
|
+
return e.forEach((n) => this.addOutput(n)), this;
|
|
2780
|
+
}
|
|
2781
|
+
addOutput(e) {
|
|
2782
|
+
if (arguments.length > 1 || !e || e.value === void 0 || e.address === void 0 && e.script === void 0)
|
|
2783
|
+
throw new Error(
|
|
2784
|
+
"Invalid arguments for Psbt.addOutput. Requires single object with at least [script or address] and [value]"
|
|
2785
|
+
);
|
|
2786
|
+
pe(this.data.inputs, "addOutput");
|
|
2787
|
+
const { address: n } = e;
|
|
2788
|
+
if (typeof n == "string") {
|
|
2789
|
+
const { network: a } = this.opts, o = Fn(n, a);
|
|
2790
|
+
e = Object.assign({}, e, { script: o });
|
|
2791
|
+
}
|
|
2792
|
+
Ht(e, e, "addOutput");
|
|
2793
|
+
const r = this.__CACHE;
|
|
2794
|
+
return this.data.addOutput(e), r.__FEE = void 0, r.__FEE_RATE = void 0, r.__EXTRACTED_TX = void 0, this;
|
|
2795
|
+
}
|
|
2796
|
+
extractTransaction(e, n) {
|
|
2797
|
+
if (n && (this.data.inputs = this.data.inputs.filter((o) => !o.partialSig)), !this.data.inputs.every(Jn)) throw new Error("Not finalized");
|
|
2798
|
+
const r = this.__CACHE;
|
|
2799
|
+
if (e || Zo(this, r, this.opts), r.__EXTRACTED_TX) return r.__EXTRACTED_TX;
|
|
2800
|
+
const a = r.__TX.clone();
|
|
2801
|
+
return sr(this.data.inputs, a, r, !0, n), a;
|
|
2802
|
+
}
|
|
2803
|
+
getFeeRate(e = !1) {
|
|
2804
|
+
return Sn(
|
|
2805
|
+
"__FEE_RATE",
|
|
2806
|
+
"fee rate",
|
|
2807
|
+
this.data.inputs,
|
|
2808
|
+
this.__CACHE,
|
|
2809
|
+
e
|
|
2810
|
+
);
|
|
2811
|
+
}
|
|
2812
|
+
getFee(e = !1) {
|
|
2813
|
+
return Sn(
|
|
2814
|
+
"__FEE",
|
|
2815
|
+
"fee",
|
|
2816
|
+
this.data.inputs,
|
|
2817
|
+
this.__CACHE,
|
|
2818
|
+
e
|
|
2819
|
+
);
|
|
2820
|
+
}
|
|
2821
|
+
finalizeAllInputs() {
|
|
2822
|
+
return O.checkForInput(this.data.inputs, 0), he(this.data.inputs.length).forEach((e) => this.finalizeInput(e)), this;
|
|
2823
|
+
}
|
|
2824
|
+
finalizeInput(e, n, r) {
|
|
2825
|
+
const a = O.checkForInput(this.data.inputs, e);
|
|
2826
|
+
return H(a) ? this._finalizeTaprootInput(
|
|
2827
|
+
e,
|
|
2828
|
+
a,
|
|
2829
|
+
void 0,
|
|
2830
|
+
n
|
|
2831
|
+
) : this._finalizeInput(
|
|
2832
|
+
e,
|
|
2833
|
+
a,
|
|
2834
|
+
n,
|
|
2835
|
+
r ?? !0
|
|
2836
|
+
);
|
|
2837
|
+
}
|
|
2838
|
+
finalizeTaprootInput(e, n, r = xt) {
|
|
2839
|
+
const a = O.checkForInput(this.data.inputs, e);
|
|
2840
|
+
if (H(a))
|
|
2841
|
+
return this._finalizeTaprootInput(
|
|
2842
|
+
e,
|
|
2843
|
+
a,
|
|
2844
|
+
n,
|
|
2845
|
+
r
|
|
2846
|
+
);
|
|
2847
|
+
throw new Error(`Cannot finalize input #${e}. Not Taproot.`);
|
|
2848
|
+
}
|
|
2849
|
+
getInputType(e) {
|
|
2850
|
+
const n = O.checkForInput(this.data.inputs, e), r = ar(e, n, this.__CACHE), a = Qe(
|
|
2851
|
+
r,
|
|
2852
|
+
e,
|
|
2853
|
+
"input",
|
|
2854
|
+
n.redeemScript || fi(n.finalScriptSig),
|
|
2855
|
+
n.witnessScript || pi(n.finalScriptWitness)
|
|
2856
|
+
), o = a.type === "raw" ? "" : a.type + "-", i = ur(a.meaningfulScript);
|
|
2857
|
+
return o + i;
|
|
2858
|
+
}
|
|
2859
|
+
inputHasPubkey(e, n) {
|
|
2860
|
+
const r = O.checkForInput(this.data.inputs, e);
|
|
2861
|
+
return ci(n, r, e, this.__CACHE);
|
|
2862
|
+
}
|
|
2863
|
+
inputHasHDKey(e, n) {
|
|
2864
|
+
const r = O.checkForInput(this.data.inputs, e), a = dn(n);
|
|
2865
|
+
return !!r.bip32Derivation && r.bip32Derivation.some(a);
|
|
2866
|
+
}
|
|
2867
|
+
outputHasPubkey(e, n) {
|
|
2868
|
+
const r = O.checkForOutput(this.data.outputs, e);
|
|
2869
|
+
return ui(n, r, e, this.__CACHE);
|
|
2870
|
+
}
|
|
2871
|
+
outputHasHDKey(e, n) {
|
|
2872
|
+
const r = O.checkForOutput(this.data.outputs, e), a = dn(n);
|
|
2873
|
+
return !!r.bip32Derivation && r.bip32Derivation.some(a);
|
|
2874
|
+
}
|
|
2875
|
+
validateSignaturesOfAllInputs(e) {
|
|
2876
|
+
return O.checkForInput(this.data.inputs, 0), he(this.data.inputs.length).map(
|
|
2877
|
+
(r) => this.validateSignaturesOfInput(r, e)
|
|
2878
|
+
).reduce((r, a) => a === !0 && r, !0);
|
|
2879
|
+
}
|
|
2880
|
+
validateSignaturesOfInput(e, n, r) {
|
|
2881
|
+
const a = this.data.inputs[e];
|
|
2882
|
+
return H(a) ? this.validateSignaturesOfTaprootInput(e, n, r) : this._validateSignaturesOfInput(e, n, r);
|
|
2883
|
+
}
|
|
2884
|
+
signAllInputsHD(e, n = [I.SIGHASH_ALL]) {
|
|
2885
|
+
if (!e || !e.publicKey || !e.fingerprint)
|
|
2886
|
+
throw new Error("Need HDSigner to sign input");
|
|
2887
|
+
const r = [];
|
|
2888
|
+
for (const a of he(this.data.inputs.length))
|
|
2889
|
+
try {
|
|
2890
|
+
this.signInputHD(a, e, n), r.push(!0);
|
|
2891
|
+
} catch {
|
|
2892
|
+
r.push(!1);
|
|
2893
|
+
}
|
|
2894
|
+
if (r.every((a) => a === !1))
|
|
2895
|
+
throw new Error("No inputs were signed");
|
|
2896
|
+
return this;
|
|
2897
|
+
}
|
|
2898
|
+
signAllInputsHDAsync(e, n = [I.SIGHASH_ALL]) {
|
|
2899
|
+
return new Promise((r, a) => {
|
|
2900
|
+
if (!e || !e.publicKey || !e.fingerprint)
|
|
2901
|
+
return a(new Error("Need HDSigner to sign input"));
|
|
2902
|
+
const o = [], i = [];
|
|
2903
|
+
for (const s of he(this.data.inputs.length))
|
|
2904
|
+
i.push(
|
|
2905
|
+
this.signInputHDAsync(s, e, n).then(
|
|
2906
|
+
() => {
|
|
2907
|
+
o.push(!0);
|
|
2908
|
+
},
|
|
2909
|
+
() => {
|
|
2910
|
+
o.push(!1);
|
|
2911
|
+
}
|
|
2912
|
+
)
|
|
2913
|
+
);
|
|
2914
|
+
return Promise.all(i).then(() => {
|
|
2915
|
+
if (o.every((s) => s === !1))
|
|
2916
|
+
return a(new Error("No inputs were signed"));
|
|
2917
|
+
r();
|
|
2918
|
+
});
|
|
2919
|
+
});
|
|
2920
|
+
}
|
|
2921
|
+
signInputHD(e, n, r = [I.SIGHASH_ALL]) {
|
|
2922
|
+
if (!n || !n.publicKey || !n.fingerprint)
|
|
2923
|
+
throw new Error("Need HDSigner to sign input");
|
|
2924
|
+
return Tn(e, this.data.inputs, n).forEach((o) => this.signInput(e, o, r)), this;
|
|
2925
|
+
}
|
|
2926
|
+
signInputHDAsync(e, n, r = [I.SIGHASH_ALL]) {
|
|
2927
|
+
return new Promise((a, o) => {
|
|
2928
|
+
if (!n || !n.publicKey || !n.fingerprint)
|
|
2929
|
+
return o(new Error("Need HDSigner to sign input"));
|
|
2930
|
+
const s = Tn(e, this.data.inputs, n).map(
|
|
2931
|
+
(c) => this.signInputAsync(e, c, r)
|
|
2932
|
+
);
|
|
2933
|
+
return Promise.all(s).then(() => {
|
|
2934
|
+
a();
|
|
2935
|
+
}).catch(o);
|
|
2936
|
+
});
|
|
2937
|
+
}
|
|
2938
|
+
signAllInputs(e, n) {
|
|
2939
|
+
if (!e || !e.publicKey) throw new Error("Need Signer to sign input");
|
|
2940
|
+
const r = [];
|
|
2941
|
+
for (const a of he(this.data.inputs.length))
|
|
2942
|
+
try {
|
|
2943
|
+
this.signInput(a, e, n), r.push(!0);
|
|
2944
|
+
} catch {
|
|
2945
|
+
r.push(!1);
|
|
2946
|
+
}
|
|
2947
|
+
if (r.every((a) => a === !1))
|
|
2948
|
+
throw new Error("No inputs were signed");
|
|
2949
|
+
return this;
|
|
2950
|
+
}
|
|
2951
|
+
signAllInputsAsync(e, n) {
|
|
2952
|
+
return new Promise((r, a) => {
|
|
2953
|
+
if (!e || !e.publicKey)
|
|
2954
|
+
return a(new Error("Need Signer to sign input"));
|
|
2955
|
+
const o = [], i = [];
|
|
2956
|
+
for (const [s] of this.data.inputs.entries())
|
|
2957
|
+
i.push(
|
|
2958
|
+
this.signInputAsync(s, e, n).then(
|
|
2959
|
+
() => {
|
|
2960
|
+
o.push(!0);
|
|
2961
|
+
},
|
|
2962
|
+
() => {
|
|
2963
|
+
o.push(!1);
|
|
2964
|
+
}
|
|
2965
|
+
)
|
|
2966
|
+
);
|
|
2967
|
+
return Promise.all(i).then(() => {
|
|
2968
|
+
if (o.every((s) => s === !1))
|
|
2969
|
+
return a(new Error("No inputs were signed"));
|
|
2970
|
+
r();
|
|
2971
|
+
});
|
|
2972
|
+
});
|
|
2973
|
+
}
|
|
2974
|
+
signInput(e, n, r) {
|
|
2975
|
+
if (!n || !n.publicKey)
|
|
2976
|
+
throw new Error("Need Signer to sign input");
|
|
2977
|
+
const a = O.checkForInput(this.data.inputs, e);
|
|
2978
|
+
return H(a) ? this._signTaprootInput(e, a, n, void 0, r) : this._signInput(e, n, r);
|
|
2979
|
+
}
|
|
2980
|
+
signTaprootInput(e, n, r, a) {
|
|
2981
|
+
if (!n || !n.publicKey)
|
|
2982
|
+
throw new Error("Need Signer to sign input");
|
|
2983
|
+
const o = O.checkForInput(this.data.inputs, e);
|
|
2984
|
+
if (H(o))
|
|
2985
|
+
return this._signTaprootInput(
|
|
2986
|
+
e,
|
|
2987
|
+
o,
|
|
2988
|
+
n,
|
|
2989
|
+
r,
|
|
2990
|
+
a
|
|
2991
|
+
);
|
|
2992
|
+
throw new Error(`Input #${e} is not of type Taproot.`);
|
|
2993
|
+
}
|
|
2994
|
+
signInputAsync(e, n, r) {
|
|
2995
|
+
return Promise.resolve().then(() => {
|
|
2996
|
+
if (!n || !n.publicKey) throw new Error("Need Signer to sign input");
|
|
2997
|
+
const a = O.checkForInput(this.data.inputs, e);
|
|
2998
|
+
return H(a) ? this._signTaprootInputAsync(
|
|
2999
|
+
e,
|
|
3000
|
+
a,
|
|
3001
|
+
n,
|
|
3002
|
+
void 0,
|
|
3003
|
+
r
|
|
3004
|
+
) : this._signInputAsync(e, n, r);
|
|
3005
|
+
});
|
|
3006
|
+
}
|
|
3007
|
+
signTaprootInputAsync(e, n, r, a) {
|
|
3008
|
+
return Promise.resolve().then(() => {
|
|
3009
|
+
if (!n || !n.publicKey) throw new Error("Need Signer to sign input");
|
|
3010
|
+
const o = O.checkForInput(this.data.inputs, e);
|
|
3011
|
+
if (H(o))
|
|
3012
|
+
return this._signTaprootInputAsync(
|
|
3013
|
+
e,
|
|
3014
|
+
o,
|
|
3015
|
+
n,
|
|
3016
|
+
r,
|
|
3017
|
+
a
|
|
3018
|
+
);
|
|
3019
|
+
throw new Error(`Input #${e} is not of type Taproot.`);
|
|
3020
|
+
});
|
|
3021
|
+
}
|
|
3022
|
+
toBuffer() {
|
|
3023
|
+
return ct(this.__CACHE), this.data.toBuffer();
|
|
3024
|
+
}
|
|
3025
|
+
toHex() {
|
|
3026
|
+
return ct(this.__CACHE), this.data.toHex();
|
|
3027
|
+
}
|
|
3028
|
+
toBase64() {
|
|
3029
|
+
return ct(this.__CACHE), this.data.toBase64();
|
|
3030
|
+
}
|
|
3031
|
+
updateGlobal(e) {
|
|
3032
|
+
return this.data.updateGlobal(e), this;
|
|
3033
|
+
}
|
|
3034
|
+
updateInput(e, n) {
|
|
3035
|
+
return n.witnessScript && Xe(n.witnessScript), Nt(this.data.inputs[e], n, "updateInput"), this.data.updateInput(e, n), n.nonWitnessUtxo && dt(this.__CACHE, this.data.inputs[e], e), this;
|
|
3036
|
+
}
|
|
3037
|
+
updateOutput(e, n) {
|
|
3038
|
+
const r = this.data.outputs[e];
|
|
3039
|
+
return Ht(r, n, "updateOutput"), this.data.updateOutput(e, n), this;
|
|
3040
|
+
}
|
|
3041
|
+
addUnknownKeyValToGlobal(e) {
|
|
3042
|
+
return this.data.addUnknownKeyValToGlobal(e), this;
|
|
3043
|
+
}
|
|
3044
|
+
addUnknownKeyValToInput(e, n) {
|
|
3045
|
+
return this.data.addUnknownKeyValToInput(e, n), this;
|
|
3046
|
+
}
|
|
3047
|
+
addUnknownKeyValToOutput(e, n) {
|
|
3048
|
+
return this.data.addUnknownKeyValToOutput(e, n), this;
|
|
3049
|
+
}
|
|
3050
|
+
clearFinalizedInput(e) {
|
|
3051
|
+
return this.data.clearFinalizedInput(e), this;
|
|
3052
|
+
}
|
|
3053
|
+
checkTaprootHashesForSig(e, n, r, a, o) {
|
|
3054
|
+
if (typeof r.signSchnorr != "function")
|
|
3055
|
+
throw new Error(`Need Schnorr Signer to sign taproot input #${e}.`);
|
|
3056
|
+
const i = lt(
|
|
3057
|
+
e,
|
|
3058
|
+
n,
|
|
3059
|
+
this.data.inputs,
|
|
3060
|
+
r.publicKey,
|
|
3061
|
+
this.__CACHE,
|
|
3062
|
+
a,
|
|
3063
|
+
o
|
|
3064
|
+
);
|
|
3065
|
+
if (!i || !i.length)
|
|
3066
|
+
throw new Error(
|
|
3067
|
+
`Can not sign for input #${e} with the key ${r.publicKey.toString(
|
|
3068
|
+
"hex"
|
|
3069
|
+
)}`
|
|
3070
|
+
);
|
|
3071
|
+
return i;
|
|
3072
|
+
}
|
|
3073
|
+
_finalizeInput(e, n, r = ti, a = !0) {
|
|
3074
|
+
const { script: o, isP2SH: i, isP2WSH: s, isSegwit: c } = ii(
|
|
3075
|
+
e,
|
|
3076
|
+
n,
|
|
3077
|
+
this.__CACHE
|
|
3078
|
+
);
|
|
3079
|
+
if (!o) throw new Error(`No script found for input #${e}`);
|
|
3080
|
+
Jo(n);
|
|
3081
|
+
const { finalScriptSig: u, finalScriptWitness: f } = r(
|
|
3082
|
+
e,
|
|
3083
|
+
n,
|
|
3084
|
+
o,
|
|
3085
|
+
c,
|
|
3086
|
+
i,
|
|
3087
|
+
s,
|
|
3088
|
+
a
|
|
3089
|
+
);
|
|
3090
|
+
if (u && this.data.updateInput(e, { finalScriptSig: u }), f && this.data.updateInput(e, { finalScriptWitness: f }), !u && !f)
|
|
3091
|
+
throw new Error(`Unknown error finalizing input #${e}`);
|
|
3092
|
+
return this.data.clearFinalizedInput(e), this;
|
|
3093
|
+
}
|
|
3094
|
+
_finalizeTaprootInput(e, n, r, a = xt) {
|
|
3095
|
+
if (!n.witnessUtxo)
|
|
3096
|
+
throw new Error(`Cannot finalize input #${e}. Missing witness utxo.`);
|
|
3097
|
+
if (n.tapKeySig) {
|
|
3098
|
+
const o = ve({
|
|
3099
|
+
output: n.witnessUtxo.script,
|
|
3100
|
+
signature: n.tapKeySig
|
|
3101
|
+
}), i = we(o.witness);
|
|
3102
|
+
this.data.updateInput(e, { finalScriptWitness: i });
|
|
3103
|
+
} else {
|
|
3104
|
+
const { finalScriptWitness: o } = a(
|
|
3105
|
+
e,
|
|
3106
|
+
n,
|
|
3107
|
+
r
|
|
3108
|
+
);
|
|
3109
|
+
this.data.updateInput(e, { finalScriptWitness: o });
|
|
3110
|
+
}
|
|
3111
|
+
return this.data.clearFinalizedInput(e), this;
|
|
3112
|
+
}
|
|
3113
|
+
_validateSignaturesOfInput(e, n, r) {
|
|
3114
|
+
const a = this.data.inputs[e], o = (a || {}).partialSig;
|
|
3115
|
+
if (!a || !o || o.length < 1)
|
|
3116
|
+
throw new Error("No signatures to validate");
|
|
3117
|
+
if (typeof n != "function")
|
|
3118
|
+
throw new Error("Need validator function to validate signatures");
|
|
3119
|
+
const i = r ? o.filter((p) => p.pubkey.equals(r)) : o;
|
|
3120
|
+
if (i.length < 1) throw new Error("No signatures for this pubkey");
|
|
3121
|
+
const s = [];
|
|
3122
|
+
let c, u, f;
|
|
3123
|
+
for (const p of i) {
|
|
3124
|
+
const y = de.decode(p.signature), { hash: S, script: h } = f !== y.hashType ? nr(
|
|
3125
|
+
e,
|
|
3126
|
+
Object.assign({}, a, {
|
|
3127
|
+
sighashType: y.hashType
|
|
3128
|
+
}),
|
|
3129
|
+
this.__CACHE,
|
|
3130
|
+
!0
|
|
3131
|
+
) : { hash: c, script: u };
|
|
3132
|
+
f = y.hashType, c = S, u = h, Qn(p.pubkey, h, "verify"), s.push(n(p.pubkey, S, y.signature));
|
|
3133
|
+
}
|
|
3134
|
+
return s.every((p) => p === !0);
|
|
3135
|
+
}
|
|
3136
|
+
validateSignaturesOfTaprootInput(e, n, r) {
|
|
3137
|
+
const a = this.data.inputs[e], o = (a || {}).tapKeySig, i = (a || {}).tapScriptSig;
|
|
3138
|
+
if (!a && !o && !(i && !i.length))
|
|
3139
|
+
throw new Error("No signatures to validate");
|
|
3140
|
+
if (typeof n != "function")
|
|
3141
|
+
throw new Error("Need validator function to validate signatures");
|
|
3142
|
+
r = r && Ee(r);
|
|
3143
|
+
const s = r ? lt(e, a, this.data.inputs, r, this.__CACHE) : ri(e, a, this.data.inputs, this.__CACHE);
|
|
3144
|
+
if (!s.length) throw new Error("No signatures for this pubkey");
|
|
3145
|
+
const c = s.find((f) => !f.leafHash);
|
|
3146
|
+
let u = 0;
|
|
3147
|
+
if (o && c) {
|
|
3148
|
+
if (!n(
|
|
3149
|
+
c.pubkey,
|
|
3150
|
+
c.hash,
|
|
3151
|
+
wn(o)
|
|
3152
|
+
)) return !1;
|
|
3153
|
+
u++;
|
|
3154
|
+
}
|
|
3155
|
+
if (i)
|
|
3156
|
+
for (const f of i) {
|
|
3157
|
+
const p = s.find((y) => f.pubkey.equals(y.pubkey));
|
|
3158
|
+
if (p) {
|
|
3159
|
+
if (!n(
|
|
3160
|
+
f.pubkey,
|
|
3161
|
+
p.hash,
|
|
3162
|
+
wn(f.signature)
|
|
3163
|
+
)) return !1;
|
|
3164
|
+
u++;
|
|
3165
|
+
}
|
|
3166
|
+
}
|
|
3167
|
+
return u > 0;
|
|
3168
|
+
}
|
|
3169
|
+
_signInput(e, n, r = [I.SIGHASH_ALL]) {
|
|
3170
|
+
const { hash: a, sighashType: o } = En(
|
|
3171
|
+
this.data.inputs,
|
|
3172
|
+
e,
|
|
3173
|
+
n.publicKey,
|
|
3174
|
+
this.__CACHE,
|
|
3175
|
+
r
|
|
3176
|
+
), i = [
|
|
3177
|
+
{
|
|
3178
|
+
pubkey: n.publicKey,
|
|
3179
|
+
signature: de.encode(n.sign(a), o)
|
|
3180
|
+
}
|
|
3181
|
+
];
|
|
3182
|
+
return this.data.updateInput(e, { partialSig: i }), this;
|
|
3183
|
+
}
|
|
3184
|
+
_signTaprootInput(e, n, r, a, o = [I.SIGHASH_DEFAULT]) {
|
|
3185
|
+
const i = this.checkTaprootHashesForSig(
|
|
3186
|
+
e,
|
|
3187
|
+
n,
|
|
3188
|
+
r,
|
|
3189
|
+
a,
|
|
3190
|
+
o
|
|
3191
|
+
), s = i.filter((u) => !u.leafHash).map(
|
|
3192
|
+
(u) => Pe(r.signSchnorr(u.hash), n.sighashType)
|
|
3193
|
+
)[0], c = i.filter((u) => !!u.leafHash).map(
|
|
3194
|
+
(u) => ({
|
|
3195
|
+
pubkey: Ee(r.publicKey),
|
|
3196
|
+
signature: Pe(
|
|
3197
|
+
r.signSchnorr(u.hash),
|
|
3198
|
+
n.sighashType
|
|
3199
|
+
),
|
|
3200
|
+
leafHash: u.leafHash
|
|
3201
|
+
})
|
|
3202
|
+
);
|
|
3203
|
+
return s && this.data.updateInput(e, { tapKeySig: s }), c.length && this.data.updateInput(e, { tapScriptSig: c }), this;
|
|
3204
|
+
}
|
|
3205
|
+
_signInputAsync(e, n, r = [I.SIGHASH_ALL]) {
|
|
3206
|
+
const { hash: a, sighashType: o } = En(
|
|
3207
|
+
this.data.inputs,
|
|
3208
|
+
e,
|
|
3209
|
+
n.publicKey,
|
|
3210
|
+
this.__CACHE,
|
|
3211
|
+
r
|
|
3212
|
+
);
|
|
3213
|
+
return Promise.resolve(n.sign(a)).then((i) => {
|
|
3214
|
+
const s = [
|
|
3215
|
+
{
|
|
3216
|
+
pubkey: n.publicKey,
|
|
3217
|
+
signature: de.encode(i, o)
|
|
3218
|
+
}
|
|
3219
|
+
];
|
|
3220
|
+
this.data.updateInput(e, { partialSig: s });
|
|
3221
|
+
});
|
|
3222
|
+
}
|
|
3223
|
+
async _signTaprootInputAsync(e, n, r, a, o = [I.SIGHASH_DEFAULT]) {
|
|
3224
|
+
const i = this.checkTaprootHashesForSig(
|
|
3225
|
+
e,
|
|
3226
|
+
n,
|
|
3227
|
+
r,
|
|
3228
|
+
a,
|
|
3229
|
+
o
|
|
3230
|
+
), s = [], c = i.filter((p) => !p.leafHash)[0];
|
|
3231
|
+
if (c) {
|
|
3232
|
+
const p = Promise.resolve(r.signSchnorr(c.hash)).then(
|
|
3233
|
+
(y) => ({
|
|
3234
|
+
tapKeySig: Pe(y, n.sighashType)
|
|
3235
|
+
})
|
|
3236
|
+
);
|
|
3237
|
+
s.push(p);
|
|
3238
|
+
}
|
|
3239
|
+
const u = i.filter((p) => !!p.leafHash);
|
|
3240
|
+
if (u.length) {
|
|
3241
|
+
const p = u.map(async (y) => {
|
|
3242
|
+
const S = await r.signSchnorr(y.hash);
|
|
3243
|
+
return { tapScriptSig: [
|
|
3244
|
+
{
|
|
3245
|
+
pubkey: Ee(r.publicKey),
|
|
3246
|
+
signature: Pe(S, n.sighashType),
|
|
3247
|
+
leafHash: y.leafHash
|
|
3248
|
+
}
|
|
3249
|
+
] };
|
|
3250
|
+
});
|
|
3251
|
+
s.push(...p);
|
|
3252
|
+
}
|
|
3253
|
+
const f = await Promise.all(s);
|
|
3254
|
+
for (const p of f)
|
|
3255
|
+
this.data.updateInput(e, p);
|
|
3256
|
+
}
|
|
3257
|
+
}
|
|
3258
|
+
const Yo = (t) => new Zn(t);
|
|
3259
|
+
class Zn {
|
|
3260
|
+
constructor(e = d.from([2, 0, 0, 0, 0, 0, 0, 0, 0, 0])) {
|
|
3261
|
+
this.tx = I.fromBuffer(e), Qo(this.tx), Object.defineProperty(this, "tx", {
|
|
3262
|
+
enumerable: !1,
|
|
3263
|
+
writable: !0
|
|
3264
|
+
});
|
|
3265
|
+
}
|
|
3266
|
+
getInputOutputCounts() {
|
|
3267
|
+
return {
|
|
3268
|
+
inputCount: this.tx.ins.length,
|
|
3269
|
+
outputCount: this.tx.outs.length
|
|
3270
|
+
};
|
|
3271
|
+
}
|
|
3272
|
+
addInput(e) {
|
|
3273
|
+
if (e.hash === void 0 || e.index === void 0 || !d.isBuffer(e.hash) && typeof e.hash != "string" || typeof e.index != "number")
|
|
3274
|
+
throw new Error("Error adding input.");
|
|
3275
|
+
const n = typeof e.hash == "string" ? vn(d.from(e.hash, "hex")) : e.hash;
|
|
3276
|
+
this.tx.addInput(n, e.index, e.sequence);
|
|
3277
|
+
}
|
|
3278
|
+
addOutput(e) {
|
|
3279
|
+
if (e.script === void 0 || e.value === void 0 || !d.isBuffer(e.script) || typeof e.value != "number")
|
|
3280
|
+
throw new Error("Error adding output.");
|
|
3281
|
+
this.tx.addOutput(e.script, e.value);
|
|
3282
|
+
}
|
|
3283
|
+
toBuffer() {
|
|
3284
|
+
return this.tx.toBuffer();
|
|
3285
|
+
}
|
|
3286
|
+
}
|
|
3287
|
+
function $o(t, e, n) {
|
|
3288
|
+
switch (n) {
|
|
3289
|
+
case "pubkey":
|
|
3290
|
+
case "pubkeyhash":
|
|
3291
|
+
case "witnesspubkeyhash":
|
|
3292
|
+
return ln(1, t.partialSig);
|
|
3293
|
+
case "multisig":
|
|
3294
|
+
const r = De({
|
|
3295
|
+
output: e
|
|
3296
|
+
});
|
|
3297
|
+
return ln(r.m, t.partialSig, r.pubkeys);
|
|
3298
|
+
case "nonstandard":
|
|
3299
|
+
return !0;
|
|
3300
|
+
default:
|
|
3301
|
+
return !1;
|
|
3302
|
+
}
|
|
3303
|
+
}
|
|
3304
|
+
function ct(t) {
|
|
3305
|
+
if (t.__UNSAFE_SIGN_NONSEGWIT !== !1)
|
|
3306
|
+
throw new Error("Not BIP174 compliant, can not export");
|
|
3307
|
+
}
|
|
3308
|
+
function ln(t, e, n) {
|
|
3309
|
+
if (!e) return !1;
|
|
3310
|
+
let r;
|
|
3311
|
+
if (n ? r = n.map((a) => {
|
|
3312
|
+
const o = hi(a);
|
|
3313
|
+
return e.find((i) => i.pubkey.equals(o));
|
|
3314
|
+
}).filter((a) => !!a) : r = e, r.length > t) throw new Error("Too many signatures");
|
|
3315
|
+
return r.length === t;
|
|
3316
|
+
}
|
|
3317
|
+
function Jn(t) {
|
|
3318
|
+
return !!t.finalScriptSig || !!t.finalScriptWitness;
|
|
3319
|
+
}
|
|
3320
|
+
function dn(t) {
|
|
3321
|
+
return (e) => !(!e.masterFingerprint.equals(t.fingerprint) || !t.derivePath(e.path).publicKey.equals(e.pubkey));
|
|
3322
|
+
}
|
|
3323
|
+
function Le(t) {
|
|
3324
|
+
if (typeof t != "number" || t !== Math.floor(t) || t > 4294967295 || t < 0)
|
|
3325
|
+
throw new Error("Invalid 32 bit integer");
|
|
3326
|
+
}
|
|
3327
|
+
function Zo(t, e, n) {
|
|
3328
|
+
const r = e.__FEE_RATE || t.getFeeRate(), a = e.__EXTRACTED_TX.virtualSize(), o = r * a;
|
|
3329
|
+
if (r >= n.maximumFeeRate)
|
|
3330
|
+
throw new Error(
|
|
3331
|
+
`Warning: You are paying around ${(o / 1e8).toFixed(8)} in fees, which is ${r} satoshi per byte for a transaction with a VSize of ${a} bytes (segwit counted as 0.25 byte per byte). Use setMaximumFeeRate method to raise your threshold, or pass true to the first arg of extractTransaction.`
|
|
3332
|
+
);
|
|
3333
|
+
}
|
|
3334
|
+
function pe(t, e) {
|
|
3335
|
+
t.forEach((n) => {
|
|
3336
|
+
if (H(n) ? io(n, e) : bo(n, e)) throw new Error("Can not modify transaction, signatures exist.");
|
|
3337
|
+
});
|
|
3338
|
+
}
|
|
3339
|
+
function Jo(t) {
|
|
3340
|
+
if (!t.sighashType || !t.partialSig) return;
|
|
3341
|
+
const { partialSig: e, sighashType: n } = t;
|
|
3342
|
+
e.forEach((r) => {
|
|
3343
|
+
const { hashType: a } = de.decode(r.signature);
|
|
3344
|
+
if (n !== a)
|
|
3345
|
+
throw new Error("Signature sighash does not match input sighash type");
|
|
3346
|
+
});
|
|
3347
|
+
}
|
|
3348
|
+
function Qn(t, e, n) {
|
|
3349
|
+
if (!Ze(t, e))
|
|
3350
|
+
throw new Error(`Can not ${n} for this input with the key ${t.toString("hex")}`);
|
|
3351
|
+
}
|
|
3352
|
+
function Qo(t) {
|
|
3353
|
+
if (!t.ins.every(
|
|
3354
|
+
(n) => n.script && n.script.length === 0 && n.witness && n.witness.length === 0
|
|
3355
|
+
))
|
|
3356
|
+
throw new Error("Format Error: Transaction ScriptSigs are not empty");
|
|
3357
|
+
}
|
|
3358
|
+
function ei(t, e) {
|
|
3359
|
+
t.ins.forEach((n) => {
|
|
3360
|
+
er(e, n);
|
|
3361
|
+
});
|
|
3362
|
+
}
|
|
3363
|
+
function er(t, e) {
|
|
3364
|
+
const n = vn(d.from(e.hash)).toString("hex") + ":" + e.index;
|
|
3365
|
+
if (t.__TX_IN_CACHE[n]) throw new Error("Duplicate input detected.");
|
|
3366
|
+
t.__TX_IN_CACHE[n] = 1;
|
|
3367
|
+
}
|
|
3368
|
+
function tr(t, e) {
|
|
3369
|
+
return (n, r, a, o) => {
|
|
3370
|
+
const i = t({
|
|
3371
|
+
redeem: { output: a }
|
|
3372
|
+
}).output;
|
|
3373
|
+
if (!r.equals(i))
|
|
3374
|
+
throw new Error(
|
|
3375
|
+
`${e} for ${o} #${n} doesn't match the scriptPubKey in the prevout`
|
|
3376
|
+
);
|
|
3377
|
+
};
|
|
3378
|
+
}
|
|
3379
|
+
const gn = tr(_e, "Redeem script"), yn = tr(be, "Witness script");
|
|
3380
|
+
function Sn(t, e, n, r, a = !1) {
|
|
3381
|
+
if (!n.every(Jn)) throw new Error(`PSBT must be finalized to calculate ${e}`);
|
|
3382
|
+
if (t === "__FEE_RATE" && r.__FEE_RATE) return r.__FEE_RATE;
|
|
3383
|
+
if (t === "__FEE" && r.__FEE) return r.__FEE;
|
|
3384
|
+
let o, i = !0;
|
|
3385
|
+
if (r.__EXTRACTED_TX ? (o = r.__EXTRACTED_TX, i = !1) : o = r.__TX.clone(), sr(n, o, r, i, a), t === "__FEE_RATE") return r.__FEE_RATE;
|
|
3386
|
+
if (t === "__FEE") return r.__FEE;
|
|
3387
|
+
}
|
|
3388
|
+
function ti(t, e, n, r, a, o, i = !0, s) {
|
|
3389
|
+
const c = ur(n);
|
|
3390
|
+
if (!$o(e, n, c) && i)
|
|
3391
|
+
throw new Error(`Can not finalize input #${t}`);
|
|
3392
|
+
return ni(
|
|
3393
|
+
n,
|
|
3394
|
+
c,
|
|
3395
|
+
e.partialSig,
|
|
3396
|
+
r,
|
|
3397
|
+
a,
|
|
3398
|
+
o,
|
|
3399
|
+
s
|
|
3400
|
+
);
|
|
3401
|
+
}
|
|
3402
|
+
function ni(t, e, n, r, a, o, i) {
|
|
3403
|
+
let s, c;
|
|
3404
|
+
const u = oi(t, e, n), f = o ? be({ redeem: u }) : null, p = a ? _e({ redeem: f || u }) : null;
|
|
3405
|
+
return r ? (f ? c = we(f.witness) : u ? c = we(u.witness) : c = we(i ?? [d.from([0])]), p && (s = p?.input)) : p ? s = p?.input : u ? s = u.input : s = Array.isArray(i) && i[0] ? i[0] : d.from([1]), {
|
|
3406
|
+
finalScriptSig: s,
|
|
3407
|
+
finalScriptWitness: c
|
|
3408
|
+
};
|
|
3409
|
+
}
|
|
3410
|
+
function En(t, e, n, r, a) {
|
|
3411
|
+
const o = O.checkForInput(t, e), { hash: i, sighashType: s, script: c } = nr(
|
|
3412
|
+
e,
|
|
3413
|
+
o,
|
|
3414
|
+
r,
|
|
3415
|
+
!1,
|
|
3416
|
+
a
|
|
3417
|
+
);
|
|
3418
|
+
return Qn(n, c, "sign"), {
|
|
3419
|
+
hash: i,
|
|
3420
|
+
sighashType: s
|
|
3421
|
+
};
|
|
3422
|
+
}
|
|
3423
|
+
function nr(t, e, n, r, a) {
|
|
3424
|
+
const o = n.__TX, i = e.sighashType || I.SIGHASH_ALL;
|
|
3425
|
+
or(i, a);
|
|
3426
|
+
let s, c;
|
|
3427
|
+
if (e.nonWitnessUtxo) {
|
|
3428
|
+
const p = Je(n, e, t), y = o.ins[t].hash, S = p.getHash();
|
|
3429
|
+
if (!y.equals(S))
|
|
3430
|
+
throw new Error(
|
|
3431
|
+
`Non-witness UTXO hash for input #${t} doesn't match the hash specified in the prevout`
|
|
3432
|
+
);
|
|
3433
|
+
const h = o.ins[t].index;
|
|
3434
|
+
c = p.outs[h];
|
|
3435
|
+
} else if (e.witnessUtxo)
|
|
3436
|
+
c = e.witnessUtxo;
|
|
3437
|
+
else
|
|
3438
|
+
throw new Error("Need a Utxo input item for signing");
|
|
3439
|
+
const { meaningfulScript: u, type: f } = Qe(
|
|
3440
|
+
c.script,
|
|
3441
|
+
t,
|
|
3442
|
+
"input",
|
|
3443
|
+
e.redeemScript,
|
|
3444
|
+
e.witnessScript
|
|
3445
|
+
);
|
|
3446
|
+
if (["p2sh-p2wsh", "p2wsh"].indexOf(f) >= 0)
|
|
3447
|
+
s = o.hashForWitnessV0(
|
|
3448
|
+
t,
|
|
3449
|
+
u,
|
|
3450
|
+
c.value,
|
|
3451
|
+
i
|
|
3452
|
+
);
|
|
3453
|
+
else if ($e(u)) {
|
|
3454
|
+
const p = Te({
|
|
3455
|
+
hash: u.slice(2)
|
|
3456
|
+
}).output;
|
|
3457
|
+
s = o.hashForWitnessV0(t, p, c.value, i);
|
|
3458
|
+
} else {
|
|
3459
|
+
if (e.nonWitnessUtxo === void 0 && n.__UNSAFE_SIGN_NONSEGWIT === !1)
|
|
3460
|
+
throw new Error(
|
|
3461
|
+
`Input #${t} has witnessUtxo but non-segwit script: ${u.toString("hex")}`
|
|
3462
|
+
);
|
|
3463
|
+
!r && n.__UNSAFE_SIGN_NONSEGWIT !== !1 && console.warn(
|
|
3464
|
+
`Warning: Signing non-segwit inputs without the full parent transaction means there is a chance that a miner could feed you incorrect information to trick you into paying large fees. This behavior is the same as Psbt's predecessor (TransactionBuilder - now removed) when signing non-segwit scripts. You are not able to export this Psbt with toBuffer|toBase64|toHex since it is not BIP174 compliant.
|
|
3465
|
+
*********************
|
|
3466
|
+
PROCEED WITH CAUTION!
|
|
3467
|
+
*********************`
|
|
3468
|
+
), s = o.hashForSignature(t, u, i);
|
|
3469
|
+
}
|
|
3470
|
+
return {
|
|
3471
|
+
script: u,
|
|
3472
|
+
sighashType: i,
|
|
3473
|
+
hash: s
|
|
3474
|
+
};
|
|
3475
|
+
}
|
|
3476
|
+
function ri(t, e, n, r) {
|
|
3477
|
+
const a = [];
|
|
3478
|
+
if (e.tapInternalKey) {
|
|
3479
|
+
const i = rr(t, e, r);
|
|
3480
|
+
i && a.push(i);
|
|
3481
|
+
}
|
|
3482
|
+
if (e.tapScriptSig) {
|
|
3483
|
+
const i = e.tapScriptSig.map((s) => s.pubkey);
|
|
3484
|
+
a.push(...i);
|
|
3485
|
+
}
|
|
3486
|
+
return a.map(
|
|
3487
|
+
(i) => lt(t, e, n, i, r)
|
|
3488
|
+
).flat();
|
|
3489
|
+
}
|
|
3490
|
+
function rr(t, e, n) {
|
|
3491
|
+
const { script: r } = Tt(t, e, n);
|
|
3492
|
+
return St(r) ? d.from(r.subarray(2, 34)) : null;
|
|
3493
|
+
}
|
|
3494
|
+
function wn(t) {
|
|
3495
|
+
return t.length === 64 ? t : d.from(t.subarray(0, 64));
|
|
3496
|
+
}
|
|
3497
|
+
function lt(t, e, n, r, a, o, i) {
|
|
3498
|
+
const s = a.__TX, c = e.sighashType || I.SIGHASH_DEFAULT;
|
|
3499
|
+
or(c, i);
|
|
3500
|
+
const u = n.map(
|
|
3501
|
+
(h, l) => Tt(l, h, a)
|
|
3502
|
+
), f = u.map((h) => h.script), p = u.map((h) => h.value), y = [];
|
|
3503
|
+
if (e.tapInternalKey && !o) {
|
|
3504
|
+
const h = rr(t, e, a) || d.from([]);
|
|
3505
|
+
if (Ee(r).equals(h)) {
|
|
3506
|
+
const l = s.hashForWitnessV1(
|
|
3507
|
+
t,
|
|
3508
|
+
f,
|
|
3509
|
+
p,
|
|
3510
|
+
c
|
|
3511
|
+
);
|
|
3512
|
+
y.push({ pubkey: r, hash: l });
|
|
3513
|
+
}
|
|
3514
|
+
}
|
|
3515
|
+
const S = (e.tapLeafScript || []).filter((h) => Ze(r, h.script)).map((h) => {
|
|
3516
|
+
const l = qe({
|
|
3517
|
+
output: h.script,
|
|
3518
|
+
version: h.leafVersion
|
|
3519
|
+
});
|
|
3520
|
+
return Object.assign({ hash: l }, h);
|
|
3521
|
+
}).filter((h) => !o || o.equals(h.hash)).map((h) => {
|
|
3522
|
+
const l = s.hashForWitnessV1(
|
|
3523
|
+
t,
|
|
3524
|
+
f,
|
|
3525
|
+
p,
|
|
3526
|
+
c,
|
|
3527
|
+
h.hash
|
|
3528
|
+
);
|
|
3529
|
+
return {
|
|
3530
|
+
pubkey: r,
|
|
3531
|
+
hash: l,
|
|
3532
|
+
leafHash: h.hash
|
|
3533
|
+
};
|
|
3534
|
+
});
|
|
3535
|
+
return y.concat(S);
|
|
3536
|
+
}
|
|
3537
|
+
function or(t, e) {
|
|
3538
|
+
if (e && e.indexOf(t) < 0) {
|
|
3539
|
+
const n = ai(t);
|
|
3540
|
+
throw new Error(
|
|
3541
|
+
`Sighash type is not allowed. Retry the sign method passing the sighashTypes array of whitelisted types. Sighash type: ${n}`
|
|
3542
|
+
);
|
|
3543
|
+
}
|
|
3544
|
+
}
|
|
3545
|
+
function oi(t, e, n) {
|
|
3546
|
+
let r;
|
|
3547
|
+
switch (e) {
|
|
3548
|
+
case "multisig": {
|
|
3549
|
+
const a = si(t, n);
|
|
3550
|
+
r = De({
|
|
3551
|
+
output: t,
|
|
3552
|
+
signatures: a
|
|
3553
|
+
});
|
|
3554
|
+
break;
|
|
3555
|
+
}
|
|
3556
|
+
case "pubkey":
|
|
3557
|
+
r = kn({
|
|
3558
|
+
output: t,
|
|
3559
|
+
signature: n[0].signature
|
|
3560
|
+
});
|
|
3561
|
+
break;
|
|
3562
|
+
case "pubkeyhash":
|
|
3563
|
+
r = Te({
|
|
3564
|
+
output: t,
|
|
3565
|
+
pubkey: n[0].pubkey,
|
|
3566
|
+
signature: n[0].signature
|
|
3567
|
+
});
|
|
3568
|
+
break;
|
|
3569
|
+
case "witnesspubkeyhash":
|
|
3570
|
+
r = Ge({
|
|
3571
|
+
output: t,
|
|
3572
|
+
pubkey: n[0].pubkey,
|
|
3573
|
+
signature: n[0].signature
|
|
3574
|
+
});
|
|
3575
|
+
break;
|
|
3576
|
+
}
|
|
3577
|
+
return r;
|
|
3578
|
+
}
|
|
3579
|
+
function ii(t, e, n) {
|
|
3580
|
+
const r = n.__TX, a = {
|
|
3581
|
+
script: null,
|
|
3582
|
+
isSegwit: !1,
|
|
3583
|
+
isP2SH: !1,
|
|
3584
|
+
isP2WSH: !1
|
|
3585
|
+
};
|
|
3586
|
+
if (a.isP2SH = !!e.redeemScript, a.isP2WSH = !!e.witnessScript, e.witnessScript)
|
|
3587
|
+
a.script = e.witnessScript;
|
|
3588
|
+
else if (e.redeemScript)
|
|
3589
|
+
a.script = e.redeemScript;
|
|
3590
|
+
else if (e.nonWitnessUtxo) {
|
|
3591
|
+
const o = Je(n, e, t), i = r.ins[t].index;
|
|
3592
|
+
a.script = o.outs[i].script;
|
|
3593
|
+
} else e.witnessUtxo && (a.script = e.witnessUtxo.script);
|
|
3594
|
+
if (e.witnessScript || $e(a.script))
|
|
3595
|
+
a.isSegwit = !0;
|
|
3596
|
+
else
|
|
3597
|
+
try {
|
|
3598
|
+
const o = a.script;
|
|
3599
|
+
if (!o) throw new TypeError("Invalid script for segwit address");
|
|
3600
|
+
a.isSegwit = On(o);
|
|
3601
|
+
} catch {
|
|
3602
|
+
}
|
|
3603
|
+
return a;
|
|
3604
|
+
}
|
|
3605
|
+
function Tn(t, e, n) {
|
|
3606
|
+
const r = O.checkForInput(e, t);
|
|
3607
|
+
if (!r.bip32Derivation || r.bip32Derivation.length === 0)
|
|
3608
|
+
throw new Error("Need bip32Derivation to sign with HD");
|
|
3609
|
+
const a = r.bip32Derivation.map((o) => {
|
|
3610
|
+
if (o.masterFingerprint.equals(n.fingerprint))
|
|
3611
|
+
return o;
|
|
3612
|
+
}).filter((o) => !!o);
|
|
3613
|
+
if (a.length === 0)
|
|
3614
|
+
throw new Error(
|
|
3615
|
+
"Need one bip32Derivation masterFingerprint to match the HDSigner fingerprint"
|
|
3616
|
+
);
|
|
3617
|
+
return a.map((o) => {
|
|
3618
|
+
const i = n.derivePath(o.path);
|
|
3619
|
+
if (!o.pubkey.equals(i.publicKey))
|
|
3620
|
+
throw new Error("pubkey did not match bip32Derivation");
|
|
3621
|
+
return i;
|
|
3622
|
+
});
|
|
3623
|
+
}
|
|
3624
|
+
function si(t, e) {
|
|
3625
|
+
return De({ output: t }).pubkeys.map((r) => (e.filter((a) => a.pubkey.equals(r))[0] || {}).signature).filter((r) => !!r);
|
|
3626
|
+
}
|
|
3627
|
+
function ir(t) {
|
|
3628
|
+
let e = 0;
|
|
3629
|
+
function n(i) {
|
|
3630
|
+
return e += i, t.slice(e - i, e);
|
|
3631
|
+
}
|
|
3632
|
+
function r() {
|
|
3633
|
+
const i = We.decode(t, e);
|
|
3634
|
+
return e += We.decode.bytes, i;
|
|
3635
|
+
}
|
|
3636
|
+
function a() {
|
|
3637
|
+
return n(r());
|
|
3638
|
+
}
|
|
3639
|
+
function o() {
|
|
3640
|
+
const i = r(), s = [];
|
|
3641
|
+
for (let c = 0; c < i; c++) s.push(a());
|
|
3642
|
+
return s;
|
|
3643
|
+
}
|
|
3644
|
+
return o();
|
|
3645
|
+
}
|
|
3646
|
+
function ai(t) {
|
|
3647
|
+
let e = t & I.SIGHASH_ANYONECANPAY ? "SIGHASH_ANYONECANPAY | " : "";
|
|
3648
|
+
switch (t & 31) {
|
|
3649
|
+
case I.SIGHASH_ALL:
|
|
3650
|
+
e += "SIGHASH_ALL";
|
|
3651
|
+
break;
|
|
3652
|
+
case I.SIGHASH_SINGLE:
|
|
3653
|
+
e += "SIGHASH_SINGLE";
|
|
3654
|
+
break;
|
|
3655
|
+
case I.SIGHASH_NONE:
|
|
3656
|
+
e += "SIGHASH_NONE";
|
|
3657
|
+
break;
|
|
3658
|
+
}
|
|
3659
|
+
return e;
|
|
3660
|
+
}
|
|
3661
|
+
function dt(t, e, n) {
|
|
3662
|
+
t.__NON_WITNESS_UTXO_BUF_CACHE[n] = e.nonWitnessUtxo, t.__NON_WITNESS_UTXO_TX_CACHE[n] = I.fromBuffer(e.nonWitnessUtxo);
|
|
3663
|
+
const r = t, a = n;
|
|
3664
|
+
delete e.nonWitnessUtxo, Object.defineProperty(e, "nonWitnessUtxo", {
|
|
3665
|
+
enumerable: !0,
|
|
3666
|
+
get() {
|
|
3667
|
+
const o = r.__NON_WITNESS_UTXO_BUF_CACHE[a], i = r.__NON_WITNESS_UTXO_TX_CACHE[a];
|
|
3668
|
+
if (o !== void 0)
|
|
3669
|
+
return o;
|
|
3670
|
+
{
|
|
3671
|
+
const s = i.toBuffer();
|
|
3672
|
+
return r.__NON_WITNESS_UTXO_BUF_CACHE[a] = s, s;
|
|
3673
|
+
}
|
|
3674
|
+
},
|
|
3675
|
+
set(o) {
|
|
3676
|
+
r.__NON_WITNESS_UTXO_BUF_CACHE[a] = o;
|
|
3677
|
+
}
|
|
3678
|
+
});
|
|
3679
|
+
}
|
|
3680
|
+
function sr(t, e, n, r, a) {
|
|
3681
|
+
let o = 0;
|
|
3682
|
+
t.forEach((u, f) => {
|
|
3683
|
+
if (r && u.finalScriptSig && (e.ins[f].script = u.finalScriptSig), r && u.finalScriptWitness && (e.ins[f].witness = ir(u.finalScriptWitness)), u.witnessUtxo)
|
|
3684
|
+
o += u.witnessUtxo.value;
|
|
3685
|
+
else if (u.nonWitnessUtxo) {
|
|
3686
|
+
const p = Je(n, u, f), y = e.ins[f].index, S = p.outs[y];
|
|
3687
|
+
o += S.value;
|
|
3688
|
+
}
|
|
3689
|
+
});
|
|
3690
|
+
const i = e.outs.reduce((u, f) => u + f.value, 0), s = o - i;
|
|
3691
|
+
if (!a && s < 0)
|
|
3692
|
+
throw new Error(
|
|
3693
|
+
`Outputs are spending more than Inputs ${o} < ${i}`
|
|
3694
|
+
);
|
|
3695
|
+
const c = e.virtualSize();
|
|
3696
|
+
n.__FEE = s, n.__EXTRACTED_TX = e, n.__FEE_RATE = Math.floor(s / c);
|
|
3697
|
+
}
|
|
3698
|
+
function Je(t, e, n) {
|
|
3699
|
+
const r = t.__NON_WITNESS_UTXO_TX_CACHE;
|
|
3700
|
+
return r[n] || dt(t, e, n), r[n];
|
|
3701
|
+
}
|
|
3702
|
+
function ar(t, e, n) {
|
|
3703
|
+
const { script: r } = Tt(t, e, n);
|
|
3704
|
+
return r;
|
|
3705
|
+
}
|
|
3706
|
+
function Tt(t, e, n) {
|
|
3707
|
+
if (e.witnessUtxo !== void 0)
|
|
3708
|
+
return {
|
|
3709
|
+
script: e.witnessUtxo.script,
|
|
3710
|
+
value: e.witnessUtxo.value
|
|
3711
|
+
};
|
|
3712
|
+
if (e.nonWitnessUtxo !== void 0) {
|
|
3713
|
+
const a = Je(n, e, t).outs[n.__TX.ins[t].index];
|
|
3714
|
+
return { script: a.script, value: a.value };
|
|
3715
|
+
} else
|
|
3716
|
+
throw new Error("Can't find pubkey in input without Utxo data");
|
|
3717
|
+
}
|
|
3718
|
+
function ci(t, e, n, r) {
|
|
3719
|
+
const a = ar(n, e, r), { meaningfulScript: o } = Qe(
|
|
3720
|
+
a,
|
|
3721
|
+
n,
|
|
3722
|
+
"input",
|
|
3723
|
+
e.redeemScript,
|
|
3724
|
+
e.witnessScript
|
|
3725
|
+
);
|
|
3726
|
+
return Ze(t, o);
|
|
3727
|
+
}
|
|
3728
|
+
function ui(t, e, n, r) {
|
|
3729
|
+
const a = r.__TX.outs[n].script, { meaningfulScript: o } = Qe(
|
|
3730
|
+
a,
|
|
3731
|
+
n,
|
|
3732
|
+
"output",
|
|
3733
|
+
e.redeemScript,
|
|
3734
|
+
e.witnessScript
|
|
3735
|
+
);
|
|
3736
|
+
return Ze(t, o);
|
|
3737
|
+
}
|
|
3738
|
+
function fi(t) {
|
|
3739
|
+
if (!t) return;
|
|
3740
|
+
const e = ce(t);
|
|
3741
|
+
if (!e) return;
|
|
3742
|
+
const n = e[e.length - 1];
|
|
3743
|
+
if (!(!d.isBuffer(n) || cr(n) || li(n) || !ce(n)))
|
|
3744
|
+
return n;
|
|
3745
|
+
}
|
|
3746
|
+
function pi(t) {
|
|
3747
|
+
if (!t) return;
|
|
3748
|
+
const e = ir(t), n = e[e.length - 1];
|
|
3749
|
+
if (!(cr(n) || !ce(n)))
|
|
3750
|
+
return n;
|
|
3751
|
+
}
|
|
3752
|
+
function hi(t) {
|
|
3753
|
+
if (t.length === 65) {
|
|
3754
|
+
const e = t[64] & 1, n = t.slice(0, 33);
|
|
3755
|
+
return n[0] = 2 | e, n;
|
|
3756
|
+
}
|
|
3757
|
+
return t.slice();
|
|
3758
|
+
}
|
|
3759
|
+
function cr(t) {
|
|
3760
|
+
return t.length === 33 && lr(t);
|
|
3761
|
+
}
|
|
3762
|
+
function li(t) {
|
|
3763
|
+
return _n(t);
|
|
3764
|
+
}
|
|
3765
|
+
function Qe(t, e, n, r, a) {
|
|
3766
|
+
const o = Dn(t), i = o && r && Ut(r), s = Ut(t);
|
|
3767
|
+
if (o && r === void 0)
|
|
3768
|
+
throw new Error("scriptPubkey is P2SH but redeemScript missing");
|
|
3769
|
+
if ((s || i) && a === void 0)
|
|
3770
|
+
throw new Error("scriptPubkey or redeemScript is P2WSH but witnessScript missing");
|
|
3771
|
+
let c;
|
|
3772
|
+
return i ? (c = a, gn(e, t, r, n), yn(e, r, a, n), Xe(c)) : s ? (c = a, yn(e, t, a, n), Xe(c)) : o ? (c = r, gn(e, t, r, n)) : c = t, {
|
|
3773
|
+
meaningfulScript: c,
|
|
3774
|
+
type: i ? "p2sh-p2wsh" : o ? "p2sh" : s ? "p2wsh" : "raw"
|
|
3775
|
+
};
|
|
3776
|
+
}
|
|
3777
|
+
function Xe(t) {
|
|
3778
|
+
if ($e(t) || Dn(t))
|
|
3779
|
+
throw new Error("P2WPKH or P2SH can not be contained within P2WSH");
|
|
3780
|
+
}
|
|
3781
|
+
function ur(t) {
|
|
3782
|
+
return $e(t) ? "witnesspubkeyhash" : To(t) ? "pubkeyhash" : Eo(t) ? "multisig" : wo(t) ? "pubkey" : "nonstandard";
|
|
3783
|
+
}
|
|
3784
|
+
function he(t) {
|
|
3785
|
+
return [...Array(t).keys()];
|
|
3786
|
+
}
|
|
3787
|
+
const mi = {
|
|
3788
|
+
networks: Rr,
|
|
3789
|
+
address: Gr,
|
|
3790
|
+
payments: vr,
|
|
3791
|
+
script: dr,
|
|
3792
|
+
crypto: fr,
|
|
3793
|
+
Transaction: Ir
|
|
3794
|
+
};
|
|
3795
|
+
export {
|
|
3796
|
+
Ze as $,
|
|
3797
|
+
Pn as A,
|
|
3798
|
+
Me as B,
|
|
3799
|
+
je as C,
|
|
3800
|
+
ze as D,
|
|
3801
|
+
On as E,
|
|
3802
|
+
Ie as F,
|
|
3803
|
+
Cn as G,
|
|
3804
|
+
Nn as H,
|
|
3805
|
+
Xr as I,
|
|
3806
|
+
Un as J,
|
|
3807
|
+
Rn as K,
|
|
3808
|
+
Fn as L,
|
|
3809
|
+
Eo as M,
|
|
3810
|
+
wo as N,
|
|
3811
|
+
To as O,
|
|
3812
|
+
ht as P,
|
|
3813
|
+
$e as Q,
|
|
3814
|
+
Ut as R,
|
|
3815
|
+
Dn as S,
|
|
3816
|
+
St as T,
|
|
3817
|
+
vi as U,
|
|
3818
|
+
Ii as V,
|
|
3819
|
+
we as W,
|
|
3820
|
+
Rt as X,
|
|
3821
|
+
Oe as Y,
|
|
3822
|
+
Vn as Z,
|
|
3823
|
+
xn as _,
|
|
3824
|
+
_o as a,
|
|
3825
|
+
bo as a0,
|
|
3826
|
+
jn as a1,
|
|
3827
|
+
Io as a2,
|
|
3828
|
+
Ve as b,
|
|
3829
|
+
mi as c,
|
|
3830
|
+
L as d,
|
|
3831
|
+
Gr as e,
|
|
3832
|
+
Hn as f,
|
|
3833
|
+
Ti as g,
|
|
3834
|
+
wi as h,
|
|
3835
|
+
An as i,
|
|
3836
|
+
ti as j,
|
|
3837
|
+
xt as k,
|
|
3838
|
+
H as l,
|
|
3839
|
+
rt as m,
|
|
3840
|
+
Rr as n,
|
|
3841
|
+
Nt as o,
|
|
3842
|
+
ni as p,
|
|
3843
|
+
Ht as q,
|
|
3844
|
+
_i as r,
|
|
3845
|
+
Pe as s,
|
|
3846
|
+
Ee as t,
|
|
3847
|
+
bi as u,
|
|
3848
|
+
oo as v,
|
|
3849
|
+
io as w,
|
|
3850
|
+
co as x,
|
|
3851
|
+
me as y,
|
|
3852
|
+
ke as z
|
|
3853
|
+
};
|