@btc-vision/bitcoin 6.5.4 → 6.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AUDIT/README.md +9 -0
- package/SECURITY.md +27 -0
- package/browser/chunks/{payments-Ngcm87h_.js → payments-B1wlSccx.js} +171 -173
- package/browser/chunks/{psbt-CcM4rw3q.js → psbt-BCNk7JUx.js} +807 -791
- package/browser/index.js +4 -4
- package/build/payments/p2tr.js +0 -4
- package/build/pubkey.js +2 -2
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -18
- package/src/payments/p2tr.ts +4 -3
- package/src/pubkey.ts +3 -3
- package/test/address.spec.ts +5 -5
- package/test/payments.spec.ts +4 -4
- package/vitest.config.integration.ts +9 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { B as l, h as
|
|
2
|
-
import { p as
|
|
3
|
-
import { o as
|
|
4
|
-
import { t as
|
|
1
|
+
import { B as l, h as et } from "./crypto-BhCpKpek.js";
|
|
2
|
+
import { p as we, a as Ee, b as Xe, c as be, d as Te, e as On, f as Pn, g as De, t as Tr, h as qe, M as Nn, L as _r, r as mr } from "./payments-B1wlSccx.js";
|
|
3
|
+
import { o as ve, t as Ir, c as vr, d as ue, i as Un, s as de, a as kr } from "./script-DyPItFEl.js";
|
|
4
|
+
import { t as Ar, a as xr, H as Cr, U as Or, i as Pr, b as Hn, c as At, r as Bn } from "./utils-DNZi-T5W.js";
|
|
5
5
|
import { T as v } from "./transaction-C_UbhMGn.js";
|
|
6
|
-
const
|
|
6
|
+
const Ve = {
|
|
7
7
|
/**
|
|
8
8
|
* The message prefix used for signing Bitcoin messages.
|
|
9
9
|
*/
|
|
@@ -39,7 +39,7 @@ const Ye = {
|
|
|
39
39
|
* The prefix for Bitcoin Wallet Import Format (WIF) private keys.
|
|
40
40
|
*/
|
|
41
41
|
wif: 128
|
|
42
|
-
},
|
|
42
|
+
}, Nr = {
|
|
43
43
|
messagePrefix: `Bitcoin Signed Message:
|
|
44
44
|
`,
|
|
45
45
|
bech32: "bcrt",
|
|
@@ -51,7 +51,7 @@ const Ye = {
|
|
|
51
51
|
pubKeyHash: 111,
|
|
52
52
|
scriptHash: 196,
|
|
53
53
|
wif: 239
|
|
54
|
-
},
|
|
54
|
+
}, Ur = {
|
|
55
55
|
messagePrefix: `Bitcoin Signed Message:
|
|
56
56
|
`,
|
|
57
57
|
bech32: "tb",
|
|
@@ -63,7 +63,7 @@ const Ye = {
|
|
|
63
63
|
pubKeyHash: 111,
|
|
64
64
|
scriptHash: 196,
|
|
65
65
|
wif: 239
|
|
66
|
-
},
|
|
66
|
+
}, Hr = {
|
|
67
67
|
messagePrefix: `Dogecoin Signed Message:
|
|
68
68
|
`,
|
|
69
69
|
bech32: "",
|
|
@@ -76,7 +76,7 @@ const Ye = {
|
|
|
76
76
|
pubKeyHash: 30,
|
|
77
77
|
scriptHash: 22,
|
|
78
78
|
wif: 158
|
|
79
|
-
},
|
|
79
|
+
}, Br = {
|
|
80
80
|
messagePrefix: `Dogecoin Signed Message:
|
|
81
81
|
`,
|
|
82
82
|
bech32: "",
|
|
@@ -89,7 +89,7 @@ const Ye = {
|
|
|
89
89
|
pubKeyHash: 113,
|
|
90
90
|
scriptHash: 196,
|
|
91
91
|
wif: 241
|
|
92
|
-
},
|
|
92
|
+
}, Rr = {
|
|
93
93
|
messagePrefix: `Litecoin Signed Message:
|
|
94
94
|
`,
|
|
95
95
|
bech32: "ltc",
|
|
@@ -101,7 +101,7 @@ const Ye = {
|
|
|
101
101
|
pubKeyHash: 48,
|
|
102
102
|
scriptHash: 50,
|
|
103
103
|
wif: 176
|
|
104
|
-
},
|
|
104
|
+
}, Fr = {
|
|
105
105
|
messagePrefix: `Litecoin Signed Message:
|
|
106
106
|
`,
|
|
107
107
|
bech32: "tltc",
|
|
@@ -113,7 +113,7 @@ const Ye = {
|
|
|
113
113
|
pubKeyHash: 111,
|
|
114
114
|
scriptHash: 58,
|
|
115
115
|
wif: 239
|
|
116
|
-
},
|
|
116
|
+
}, Kr = {
|
|
117
117
|
messagePrefix: `Bitcoin Signed Message:
|
|
118
118
|
`,
|
|
119
119
|
// Cashaddr prefix differs from bech32 for general usage, but we can set it similarly.
|
|
@@ -127,7 +127,7 @@ const Ye = {
|
|
|
127
127
|
pubKeyHash: 0,
|
|
128
128
|
scriptHash: 5,
|
|
129
129
|
wif: 128
|
|
130
|
-
},
|
|
130
|
+
}, Lr = {
|
|
131
131
|
messagePrefix: `Bitcoin Signed Message:
|
|
132
132
|
`,
|
|
133
133
|
bech32: "bchtest",
|
|
@@ -139,7 +139,7 @@ const Ye = {
|
|
|
139
139
|
pubKeyHash: 111,
|
|
140
140
|
scriptHash: 196,
|
|
141
141
|
wif: 239
|
|
142
|
-
},
|
|
142
|
+
}, Mr = {
|
|
143
143
|
// Historically Dash used DarkCoin message prefix, and most implementations use this:
|
|
144
144
|
// As of Dash Core 0.17, this has not changed in code.
|
|
145
145
|
messagePrefix: `DarkCoin Signed Message:
|
|
@@ -154,7 +154,7 @@ const Ye = {
|
|
|
154
154
|
pubKeyHash: 76,
|
|
155
155
|
scriptHash: 16,
|
|
156
156
|
wif: 204
|
|
157
|
-
},
|
|
157
|
+
}, Wr = {
|
|
158
158
|
messagePrefix: `DarkCoin Signed Message:
|
|
159
159
|
`,
|
|
160
160
|
bech32: "",
|
|
@@ -167,24 +167,24 @@ const Ye = {
|
|
|
167
167
|
pubKeyHash: 140,
|
|
168
168
|
scriptHash: 19,
|
|
169
169
|
wif: 239
|
|
170
|
-
},
|
|
170
|
+
}, Wo = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
171
171
|
__proto__: null,
|
|
172
|
-
bitcoin:
|
|
173
|
-
bitcoinCash:
|
|
174
|
-
bitcoinCashTestnet:
|
|
175
|
-
dash:
|
|
176
|
-
dashTestnet:
|
|
177
|
-
dogecoin:
|
|
178
|
-
dogecoinTestnet:
|
|
179
|
-
litecoin:
|
|
180
|
-
litecoinTestnet:
|
|
181
|
-
regtest:
|
|
182
|
-
testnet:
|
|
172
|
+
bitcoin: Ve,
|
|
173
|
+
bitcoinCash: Kr,
|
|
174
|
+
bitcoinCashTestnet: Lr,
|
|
175
|
+
dash: Mr,
|
|
176
|
+
dashTestnet: Wr,
|
|
177
|
+
dogecoin: Hr,
|
|
178
|
+
dogecoinTestnet: Br,
|
|
179
|
+
litecoin: Rr,
|
|
180
|
+
litecoinTestnet: Fr,
|
|
181
|
+
regtest: Nr,
|
|
182
|
+
testnet: Ur
|
|
183
183
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
184
|
-
var ne = {},
|
|
185
|
-
function
|
|
186
|
-
if (
|
|
187
|
-
|
|
184
|
+
var ne = {}, xt;
|
|
185
|
+
function Gr() {
|
|
186
|
+
if (xt) return ne;
|
|
187
|
+
xt = 1, Object.defineProperty(ne, "__esModule", { value: !0 }), ne.bech32m = ne.bech32 = void 0;
|
|
188
188
|
const t = "qpzry9x8gf2tvdw0s3jn54khce6mua7l", e = {};
|
|
189
189
|
for (let u = 0; u < t.length; u++) {
|
|
190
190
|
const f = t.charAt(u);
|
|
@@ -196,31 +196,31 @@ function Vr() {
|
|
|
196
196
|
}
|
|
197
197
|
function r(u) {
|
|
198
198
|
let f = 1;
|
|
199
|
-
for (let
|
|
200
|
-
const g = u.charCodeAt(
|
|
199
|
+
for (let h = 0; h < u.length; ++h) {
|
|
200
|
+
const g = u.charCodeAt(h);
|
|
201
201
|
if (g < 33 || g > 126)
|
|
202
202
|
return "Invalid prefix (" + u + ")";
|
|
203
203
|
f = n(f) ^ g >> 5;
|
|
204
204
|
}
|
|
205
205
|
f = n(f);
|
|
206
|
-
for (let
|
|
207
|
-
const g = u.charCodeAt(
|
|
206
|
+
for (let h = 0; h < u.length; ++h) {
|
|
207
|
+
const g = u.charCodeAt(h);
|
|
208
208
|
f = n(f) ^ g & 31;
|
|
209
209
|
}
|
|
210
210
|
return f;
|
|
211
211
|
}
|
|
212
|
-
function c(u, f,
|
|
213
|
-
let y = 0,
|
|
214
|
-
const d = (1 <<
|
|
212
|
+
function c(u, f, h, g) {
|
|
213
|
+
let y = 0, p = 0;
|
|
214
|
+
const d = (1 << h) - 1, E = [];
|
|
215
215
|
for (let b = 0; b < u.length; ++b)
|
|
216
|
-
for (y = y << f | u[b],
|
|
217
|
-
|
|
216
|
+
for (y = y << f | u[b], p += f; p >= h; )
|
|
217
|
+
p -= h, E.push(y >> p & d);
|
|
218
218
|
if (g)
|
|
219
|
-
|
|
219
|
+
p > 0 && E.push(y << h - p & d);
|
|
220
220
|
else {
|
|
221
|
-
if (
|
|
221
|
+
if (p >= f)
|
|
222
222
|
return "Excess padding";
|
|
223
|
-
if (y <<
|
|
223
|
+
if (y << h - p & d)
|
|
224
224
|
return "Non-zero padding";
|
|
225
225
|
}
|
|
226
226
|
return E;
|
|
@@ -242,7 +242,7 @@ function Vr() {
|
|
|
242
242
|
function a(u) {
|
|
243
243
|
let f;
|
|
244
244
|
u === "bech32" ? f = 1 : f = 734539939;
|
|
245
|
-
function
|
|
245
|
+
function h(d, E, b) {
|
|
246
246
|
if (b = b || 90, d.length + 7 + E.length > b)
|
|
247
247
|
throw new TypeError("Exceeds length limit");
|
|
248
248
|
d = d.toLowerCase();
|
|
@@ -282,24 +282,24 @@ function Vr() {
|
|
|
282
282
|
const _ = d.slice(0, w), I = d.slice(w + 1);
|
|
283
283
|
if (I.length < 6)
|
|
284
284
|
return "Data too short";
|
|
285
|
-
let
|
|
286
|
-
if (typeof
|
|
287
|
-
return
|
|
285
|
+
let P = r(_);
|
|
286
|
+
if (typeof P == "string")
|
|
287
|
+
return P;
|
|
288
288
|
const m = [];
|
|
289
289
|
for (let k = 0; k < I.length; ++k) {
|
|
290
|
-
const
|
|
290
|
+
const U = I.charAt(k), B = e[U];
|
|
291
291
|
if (B === void 0)
|
|
292
|
-
return "Unknown character " +
|
|
293
|
-
|
|
292
|
+
return "Unknown character " + U;
|
|
293
|
+
P = n(P) ^ B, !(k + 6 >= I.length) && m.push(B);
|
|
294
294
|
}
|
|
295
|
-
return
|
|
295
|
+
return P !== f ? "Invalid checksum for " + d : { prefix: _, words: m };
|
|
296
296
|
}
|
|
297
297
|
function y(d, E) {
|
|
298
298
|
const b = g(d, E);
|
|
299
299
|
if (typeof b == "object")
|
|
300
300
|
return b;
|
|
301
301
|
}
|
|
302
|
-
function
|
|
302
|
+
function p(d, E) {
|
|
303
303
|
const b = g(d, E);
|
|
304
304
|
if (typeof b == "object")
|
|
305
305
|
return b;
|
|
@@ -307,8 +307,8 @@ function Vr() {
|
|
|
307
307
|
}
|
|
308
308
|
return {
|
|
309
309
|
decodeUnsafe: y,
|
|
310
|
-
decode:
|
|
311
|
-
encode:
|
|
310
|
+
decode: p,
|
|
311
|
+
encode: h,
|
|
312
312
|
toWords: s,
|
|
313
313
|
fromWordsUnsafe: o,
|
|
314
314
|
fromWords: i
|
|
@@ -316,75 +316,75 @@ function Vr() {
|
|
|
316
316
|
}
|
|
317
317
|
return ne.bech32 = a("bech32"), ne.bech32m = a("bech32m"), ne;
|
|
318
318
|
}
|
|
319
|
-
var K =
|
|
320
|
-
function
|
|
319
|
+
var K = Gr();
|
|
320
|
+
function Xr(t) {
|
|
321
321
|
return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array";
|
|
322
322
|
}
|
|
323
|
-
function
|
|
324
|
-
if (!
|
|
323
|
+
function bt(t, ...e) {
|
|
324
|
+
if (!Xr(t))
|
|
325
325
|
throw new Error("Uint8Array expected");
|
|
326
326
|
if (e.length > 0 && !e.includes(t.length))
|
|
327
327
|
throw new Error("Uint8Array expected of length " + e + ", got length=" + t.length);
|
|
328
328
|
}
|
|
329
|
-
function
|
|
329
|
+
function Ct(t, e = !0) {
|
|
330
330
|
if (t.destroyed)
|
|
331
331
|
throw new Error("Hash instance has been destroyed");
|
|
332
332
|
if (e && t.finished)
|
|
333
333
|
throw new Error("Hash#digest() has already been called");
|
|
334
334
|
}
|
|
335
|
-
function
|
|
336
|
-
|
|
335
|
+
function Dr(t, e) {
|
|
336
|
+
bt(t);
|
|
337
337
|
const n = e.outputLen;
|
|
338
338
|
if (t.length < n)
|
|
339
339
|
throw new Error("digestInto() expects output buffer of length at least " + n);
|
|
340
340
|
}
|
|
341
|
-
function
|
|
341
|
+
function ft(...t) {
|
|
342
342
|
for (let e = 0; e < t.length; e++)
|
|
343
343
|
t[e].fill(0);
|
|
344
344
|
}
|
|
345
|
-
function
|
|
345
|
+
function tt(t) {
|
|
346
346
|
return new DataView(t.buffer, t.byteOffset, t.byteLength);
|
|
347
347
|
}
|
|
348
|
-
function
|
|
348
|
+
function H(t, e) {
|
|
349
349
|
return t << 32 - e | t >>> e;
|
|
350
350
|
}
|
|
351
|
-
function
|
|
351
|
+
function qr(t) {
|
|
352
352
|
if (typeof t != "string")
|
|
353
353
|
throw new Error("string expected");
|
|
354
354
|
return new Uint8Array(new TextEncoder().encode(t));
|
|
355
355
|
}
|
|
356
356
|
function Rn(t) {
|
|
357
|
-
return typeof t == "string" && (t =
|
|
357
|
+
return typeof t == "string" && (t = qr(t)), bt(t), t;
|
|
358
358
|
}
|
|
359
|
-
class
|
|
359
|
+
class Vr {
|
|
360
360
|
}
|
|
361
|
-
function
|
|
361
|
+
function jr(t) {
|
|
362
362
|
const e = (r) => t().update(Rn(r)).digest(), n = t();
|
|
363
363
|
return e.outputLen = n.outputLen, e.blockLen = n.blockLen, e.create = () => t(), e;
|
|
364
364
|
}
|
|
365
|
-
function
|
|
365
|
+
function zr(t, e, n, r) {
|
|
366
366
|
if (typeof t.setBigUint64 == "function")
|
|
367
367
|
return t.setBigUint64(e, n, r);
|
|
368
368
|
const c = BigInt(32), s = BigInt(4294967295), o = Number(n >> c & s), i = Number(n & s), a = r ? 4 : 0, u = r ? 0 : 4;
|
|
369
369
|
t.setUint32(e + a, o, r), t.setUint32(e + u, i, r);
|
|
370
370
|
}
|
|
371
|
-
function
|
|
371
|
+
function Yr(t, e, n) {
|
|
372
372
|
return t & e ^ ~t & n;
|
|
373
373
|
}
|
|
374
|
-
function
|
|
374
|
+
function $r(t, e, n) {
|
|
375
375
|
return t & e ^ t & n ^ e & n;
|
|
376
376
|
}
|
|
377
|
-
class
|
|
377
|
+
class Zr extends Vr {
|
|
378
378
|
constructor(e, n, r, c) {
|
|
379
|
-
super(), this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.blockLen = e, this.outputLen = n, this.padOffset = r, this.isLE = c, this.buffer = new Uint8Array(e), this.view =
|
|
379
|
+
super(), this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.blockLen = e, this.outputLen = n, this.padOffset = r, this.isLE = c, this.buffer = new Uint8Array(e), this.view = tt(this.buffer);
|
|
380
380
|
}
|
|
381
381
|
update(e) {
|
|
382
|
-
|
|
382
|
+
Ct(this), e = Rn(e), bt(e);
|
|
383
383
|
const { view: n, buffer: r, blockLen: c } = this, s = e.length;
|
|
384
384
|
for (let o = 0; o < s; ) {
|
|
385
385
|
const i = Math.min(c - this.pos, s - o);
|
|
386
386
|
if (i === c) {
|
|
387
|
-
const a =
|
|
387
|
+
const a = tt(e);
|
|
388
388
|
for (; c <= s - o; o += c)
|
|
389
389
|
this.process(a, o);
|
|
390
390
|
continue;
|
|
@@ -394,21 +394,21 @@ class ts extends $r {
|
|
|
394
394
|
return this.length += e.length, this.roundClean(), this;
|
|
395
395
|
}
|
|
396
396
|
digestInto(e) {
|
|
397
|
-
|
|
397
|
+
Ct(this), Dr(e, this), this.finished = !0;
|
|
398
398
|
const { buffer: n, view: r, blockLen: c, isLE: s } = this;
|
|
399
399
|
let { pos: o } = this;
|
|
400
|
-
n[o++] = 128,
|
|
401
|
-
for (let
|
|
402
|
-
n[
|
|
403
|
-
|
|
404
|
-
const i =
|
|
400
|
+
n[o++] = 128, ft(this.buffer.subarray(o)), this.padOffset > c - o && (this.process(r, 0), o = 0);
|
|
401
|
+
for (let h = o; h < c; h++)
|
|
402
|
+
n[h] = 0;
|
|
403
|
+
zr(r, c - 8, BigInt(this.length * 8), s), this.process(r, 0);
|
|
404
|
+
const i = tt(e), a = this.outputLen;
|
|
405
405
|
if (a % 4)
|
|
406
406
|
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
407
407
|
const u = a / 4, f = this.get();
|
|
408
408
|
if (u > f.length)
|
|
409
409
|
throw new Error("_sha2: outputLen bigger than state");
|
|
410
|
-
for (let
|
|
411
|
-
i.setUint32(4 *
|
|
410
|
+
for (let h = 0; h < u; h++)
|
|
411
|
+
i.setUint32(4 * h, f[h], s);
|
|
412
412
|
}
|
|
413
413
|
digest() {
|
|
414
414
|
const { buffer: e, outputLen: n } = this;
|
|
@@ -434,7 +434,7 @@ const L = /* @__PURE__ */ Uint32Array.from([
|
|
|
434
434
|
2600822924,
|
|
435
435
|
528734635,
|
|
436
436
|
1541459225
|
|
437
|
-
]),
|
|
437
|
+
]), Jr = /* @__PURE__ */ Uint32Array.from([
|
|
438
438
|
1116352408,
|
|
439
439
|
1899447441,
|
|
440
440
|
3049323471,
|
|
@@ -500,7 +500,7 @@ const L = /* @__PURE__ */ Uint32Array.from([
|
|
|
500
500
|
3204031479,
|
|
501
501
|
3329325298
|
|
502
502
|
]), M = /* @__PURE__ */ new Uint32Array(64);
|
|
503
|
-
class
|
|
503
|
+
class Qr extends Zr {
|
|
504
504
|
constructor(e = 32) {
|
|
505
505
|
super(64, e, 8, !1), this.A = L[0] | 0, this.B = L[1] | 0, this.C = L[2] | 0, this.D = L[3] | 0, this.E = L[4] | 0, this.F = L[5] | 0, this.G = L[6] | 0, this.H = L[7] | 0;
|
|
506
506
|
}
|
|
@@ -513,38 +513,38 @@ class rs extends ts {
|
|
|
513
513
|
this.A = e | 0, this.B = n | 0, this.C = r | 0, this.D = c | 0, this.E = s | 0, this.F = o | 0, this.G = i | 0, this.H = a | 0;
|
|
514
514
|
}
|
|
515
515
|
process(e, n) {
|
|
516
|
-
for (let
|
|
517
|
-
M[
|
|
518
|
-
for (let
|
|
519
|
-
const g = M[
|
|
520
|
-
M[
|
|
516
|
+
for (let h = 0; h < 16; h++, n += 4)
|
|
517
|
+
M[h] = e.getUint32(n, !1);
|
|
518
|
+
for (let h = 16; h < 64; h++) {
|
|
519
|
+
const g = M[h - 15], y = M[h - 2], p = H(g, 7) ^ H(g, 18) ^ g >>> 3, d = H(y, 17) ^ H(y, 19) ^ y >>> 10;
|
|
520
|
+
M[h] = d + M[h - 7] + p + M[h - 16] | 0;
|
|
521
521
|
}
|
|
522
522
|
let { A: r, B: c, C: s, D: o, E: i, F: a, G: u, H: f } = this;
|
|
523
|
-
for (let
|
|
524
|
-
const g =
|
|
523
|
+
for (let h = 0; h < 64; h++) {
|
|
524
|
+
const g = H(i, 6) ^ H(i, 11) ^ H(i, 25), y = f + g + Yr(i, a, u) + Jr[h] + M[h] | 0, d = (H(r, 2) ^ H(r, 13) ^ H(r, 22)) + $r(r, c, s) | 0;
|
|
525
525
|
f = u, u = a, a = i, i = o + y | 0, o = s, s = c, c = r, r = y + d | 0;
|
|
526
526
|
}
|
|
527
527
|
r = r + this.A | 0, c = c + this.B | 0, s = s + this.C | 0, o = o + this.D | 0, i = i + this.E | 0, a = a + this.F | 0, u = u + this.G | 0, f = f + this.H | 0, this.set(r, c, s, o, i, a, u, f);
|
|
528
528
|
}
|
|
529
529
|
roundClean() {
|
|
530
|
-
|
|
530
|
+
ft(M);
|
|
531
531
|
}
|
|
532
532
|
destroy() {
|
|
533
|
-
this.set(0, 0, 0, 0, 0, 0, 0, 0),
|
|
533
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0), ft(this.buffer);
|
|
534
534
|
}
|
|
535
535
|
}
|
|
536
|
-
const
|
|
537
|
-
function
|
|
536
|
+
const es = /* @__PURE__ */ jr(() => new Qr()), Ot = es;
|
|
537
|
+
function ts(t) {
|
|
538
538
|
if (t.length >= 255)
|
|
539
539
|
throw new TypeError("Alphabet too long");
|
|
540
540
|
const e = new Uint8Array(256);
|
|
541
541
|
for (let u = 0; u < e.length; u++)
|
|
542
542
|
e[u] = 255;
|
|
543
543
|
for (let u = 0; u < t.length; u++) {
|
|
544
|
-
const f = t.charAt(u),
|
|
545
|
-
if (e[
|
|
544
|
+
const f = t.charAt(u), h = f.charCodeAt(0);
|
|
545
|
+
if (e[h] !== 255)
|
|
546
546
|
throw new TypeError(f + " is ambiguous");
|
|
547
|
-
e[
|
|
547
|
+
e[h] = u;
|
|
548
548
|
}
|
|
549
549
|
const n = t.length, r = t.charAt(0), c = Math.log(n) / Math.log(256), s = Math.log(256) / Math.log(n);
|
|
550
550
|
function o(u) {
|
|
@@ -552,24 +552,24 @@ function os(t) {
|
|
|
552
552
|
throw new TypeError("Expected Uint8Array");
|
|
553
553
|
if (u.length === 0)
|
|
554
554
|
return "";
|
|
555
|
-
let f = 0,
|
|
555
|
+
let f = 0, h = 0, g = 0;
|
|
556
556
|
const y = u.length;
|
|
557
557
|
for (; g !== y && u[g] === 0; )
|
|
558
558
|
g++, f++;
|
|
559
|
-
const
|
|
559
|
+
const p = (y - g) * s + 1 >>> 0, d = new Uint8Array(p);
|
|
560
560
|
for (; g !== y; ) {
|
|
561
561
|
let S = u[g], w = 0;
|
|
562
|
-
for (let _ =
|
|
562
|
+
for (let _ = p - 1; (S !== 0 || w < h) && _ !== -1; _--, w++)
|
|
563
563
|
S += 256 * d[_] >>> 0, d[_] = S % n >>> 0, S = S / n >>> 0;
|
|
564
564
|
if (S !== 0)
|
|
565
565
|
throw new Error("Non-zero carry");
|
|
566
|
-
|
|
566
|
+
h = w, g++;
|
|
567
567
|
}
|
|
568
|
-
let E =
|
|
569
|
-
for (; E !==
|
|
568
|
+
let E = p - h;
|
|
569
|
+
for (; E !== p && d[E] === 0; )
|
|
570
570
|
E++;
|
|
571
571
|
let b = r.repeat(f);
|
|
572
|
-
for (; E <
|
|
572
|
+
for (; E < p; ++E)
|
|
573
573
|
b += t.charAt(d[E]);
|
|
574
574
|
return b;
|
|
575
575
|
}
|
|
@@ -578,10 +578,10 @@ function os(t) {
|
|
|
578
578
|
throw new TypeError("Expected String");
|
|
579
579
|
if (u.length === 0)
|
|
580
580
|
return new Uint8Array();
|
|
581
|
-
let f = 0,
|
|
581
|
+
let f = 0, h = 0, g = 0;
|
|
582
582
|
for (; u[f] === r; )
|
|
583
|
-
|
|
584
|
-
const y = (u.length - f) * c + 1 >>> 0,
|
|
583
|
+
h++, f++;
|
|
584
|
+
const y = (u.length - f) * c + 1 >>> 0, p = new Uint8Array(y);
|
|
585
585
|
for (; f < u.length; ) {
|
|
586
586
|
const S = u.charCodeAt(f);
|
|
587
587
|
if (S > 255)
|
|
@@ -591,18 +591,18 @@ function os(t) {
|
|
|
591
591
|
return;
|
|
592
592
|
let _ = 0;
|
|
593
593
|
for (let I = y - 1; (w !== 0 || _ < g) && I !== -1; I--, _++)
|
|
594
|
-
w += n *
|
|
594
|
+
w += n * p[I] >>> 0, p[I] = w % 256 >>> 0, w = w / 256 >>> 0;
|
|
595
595
|
if (w !== 0)
|
|
596
596
|
throw new Error("Non-zero carry");
|
|
597
597
|
g = _, f++;
|
|
598
598
|
}
|
|
599
599
|
let d = y - g;
|
|
600
|
-
for (; d !== y &&
|
|
600
|
+
for (; d !== y && p[d] === 0; )
|
|
601
601
|
d++;
|
|
602
|
-
const E = new Uint8Array(
|
|
603
|
-
let b =
|
|
602
|
+
const E = new Uint8Array(h + (y - d));
|
|
603
|
+
let b = h;
|
|
604
604
|
for (; d !== y; )
|
|
605
|
-
E[b++] =
|
|
605
|
+
E[b++] = p[d++];
|
|
606
606
|
return E;
|
|
607
607
|
}
|
|
608
608
|
function a(u) {
|
|
@@ -617,12 +617,12 @@ function os(t) {
|
|
|
617
617
|
decode: a
|
|
618
618
|
};
|
|
619
619
|
}
|
|
620
|
-
var
|
|
621
|
-
const
|
|
622
|
-
function
|
|
620
|
+
var ns = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
621
|
+
const nt = ts(ns);
|
|
622
|
+
function rs(t) {
|
|
623
623
|
function e(s) {
|
|
624
624
|
var o = Uint8Array.from(s), i = t(o), a = o.length + 4, u = new Uint8Array(a);
|
|
625
|
-
return u.set(o, 0), u.set(i.subarray(0, 4), o.length),
|
|
625
|
+
return u.set(o, 0), u.set(i.subarray(0, 4), o.length), nt.encode(u);
|
|
626
626
|
}
|
|
627
627
|
function n(s) {
|
|
628
628
|
var o = s.slice(0, -4), i = s.slice(-4), a = t(o);
|
|
@@ -630,12 +630,12 @@ function cs(t) {
|
|
|
630
630
|
return o;
|
|
631
631
|
}
|
|
632
632
|
function r(s) {
|
|
633
|
-
var o =
|
|
633
|
+
var o = nt.decodeUnsafe(s);
|
|
634
634
|
if (o != null)
|
|
635
635
|
return n(o);
|
|
636
636
|
}
|
|
637
637
|
function c(s) {
|
|
638
|
-
var o =
|
|
638
|
+
var o = nt.decode(s), i = n(o);
|
|
639
639
|
if (i == null)
|
|
640
640
|
throw new Error("Invalid checksum");
|
|
641
641
|
return i;
|
|
@@ -646,10 +646,10 @@ function cs(t) {
|
|
|
646
646
|
decodeUnsafe: r
|
|
647
647
|
};
|
|
648
648
|
}
|
|
649
|
-
function
|
|
650
|
-
return
|
|
649
|
+
function ss(t) {
|
|
650
|
+
return Ot(Ot(t));
|
|
651
651
|
}
|
|
652
|
-
const Fn =
|
|
652
|
+
const Fn = rs(ss);
|
|
653
653
|
function Kn(t) {
|
|
654
654
|
let e, n;
|
|
655
655
|
try {
|
|
@@ -666,92 +666,125 @@ function Kn(t) {
|
|
|
666
666
|
data: l.from(r)
|
|
667
667
|
};
|
|
668
668
|
}
|
|
669
|
-
const
|
|
669
|
+
const Ln = {
|
|
670
670
|
p: 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,
|
|
671
671
|
n: 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n,
|
|
672
|
+
h: 1n,
|
|
673
|
+
a: 0n,
|
|
672
674
|
b: 7n,
|
|
673
675
|
Gx: 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,
|
|
674
676
|
Gy: 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n
|
|
675
|
-
}, { p: se, n:
|
|
676
|
-
|
|
677
|
-
|
|
677
|
+
}, { p: se, n: os, Gx: is, Gy: cs, b: Mn } = Ln, ht = 32, Tt = 64, as = {
|
|
678
|
+
publicKey: ht + 1,
|
|
679
|
+
publicKeyUncompressed: Tt + 1
|
|
680
|
+
}, us = (...t) => {
|
|
681
|
+
"captureStackTrace" in Error && typeof Error.captureStackTrace == "function" && Error.captureStackTrace(...t);
|
|
682
|
+
}, C = (t = "") => {
|
|
683
|
+
const e = new Error(t);
|
|
684
|
+
throw us(e, C), e;
|
|
685
|
+
}, fs = (t) => typeof t == "bigint", hs = (t) => typeof t == "string", ps = (t) => t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array", _t = (t, e, n = "") => {
|
|
686
|
+
const r = ps(t), c = t?.length, s = e !== void 0;
|
|
687
|
+
if (!r || s && c !== e) {
|
|
688
|
+
const o = n && `"${n}" `, i = s ? ` of length ${e}` : "", a = r ? `length=${c}` : `type=${typeof t}`;
|
|
689
|
+
C(o + "expected Uint8Array" + i + ", got " + a);
|
|
690
|
+
}
|
|
691
|
+
return t;
|
|
692
|
+
}, Wn = (t) => new Uint8Array(t), Gn = (t, e) => t.toString(16).padStart(e, "0"), Xn = (t) => Array.from(_t(t)).map((e) => Gn(e, 2)).join(""), R = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 }, Pt = (t) => {
|
|
678
693
|
if (t >= R._0 && t <= R._9)
|
|
679
694
|
return t - R._0;
|
|
680
695
|
if (t >= R.A && t <= R.F)
|
|
681
696
|
return t - (R.A - 10);
|
|
682
697
|
if (t >= R.a && t <= R.f)
|
|
683
698
|
return t - (R.a - 10);
|
|
684
|
-
},
|
|
699
|
+
}, Dn = (t) => {
|
|
685
700
|
const e = "hex invalid";
|
|
686
|
-
if (!
|
|
687
|
-
return
|
|
701
|
+
if (!hs(t))
|
|
702
|
+
return C(e);
|
|
688
703
|
const n = t.length, r = n / 2;
|
|
689
704
|
if (n % 2)
|
|
690
|
-
return
|
|
691
|
-
const c =
|
|
705
|
+
return C(e);
|
|
706
|
+
const c = Wn(r);
|
|
692
707
|
for (let s = 0, o = 0; s < r; s++, o += 2) {
|
|
693
|
-
const i =
|
|
708
|
+
const i = Pt(t.charCodeAt(o)), a = Pt(t.charCodeAt(o + 1));
|
|
694
709
|
if (i === void 0 || a === void 0)
|
|
695
|
-
return
|
|
710
|
+
return C(e);
|
|
696
711
|
c[s] = i * 16 + a;
|
|
697
712
|
}
|
|
698
713
|
return c;
|
|
699
|
-
},
|
|
700
|
-
const e =
|
|
714
|
+
}, Nt = (...t) => {
|
|
715
|
+
const e = Wn(t.reduce((r, c) => r + _t(c).length, 0));
|
|
701
716
|
let n = 0;
|
|
702
717
|
return t.forEach((r) => {
|
|
703
718
|
e.set(r, n), n += r.length;
|
|
704
719
|
}), e;
|
|
705
|
-
},
|
|
720
|
+
}, Le = BigInt, je = (t, e, n, r = "bad number: out of range") => fs(t) && e <= t && t < n ? t : C(r), T = (t, e = se) => {
|
|
706
721
|
const n = t % e;
|
|
707
722
|
return n >= 0n ? n : e + n;
|
|
708
|
-
},
|
|
709
|
-
(t === 0n || e <= 0n) &&
|
|
723
|
+
}, ls = (t, e) => {
|
|
724
|
+
(t === 0n || e <= 0n) && C("no inverse n=" + t + " mod=" + e);
|
|
710
725
|
let n = T(t, e), r = e, c = 0n, s = 1n;
|
|
711
726
|
for (; n !== 0n; ) {
|
|
712
727
|
const o = r / n, i = r % n, a = c - s * o;
|
|
713
728
|
r = n, n = i, c = s, s = a;
|
|
714
729
|
}
|
|
715
|
-
return r === 1n ? T(c, e) :
|
|
716
|
-
},
|
|
717
|
-
const e =
|
|
730
|
+
return r === 1n ? T(c, e) : C("no inverse");
|
|
731
|
+
}, rt = (t) => t instanceof O ? t : C("Point expected"), qn = (t) => T(T(t * t) * t + Mn), Ut = (t) => je(t, 0n, se), Ke = (t) => je(t, 1n, se), ds = (t) => je(t, 1n, os), pt = (t) => (t & 1n) === 0n, Vn = (t) => Uint8Array.of(t), gs = (t) => Vn(pt(t) ? 2 : 3), ys = (t) => {
|
|
732
|
+
const e = qn(Ke(t));
|
|
718
733
|
let n = 1n;
|
|
719
734
|
for (let r = e, c = (se + 1n) / 4n; c > 0n; c >>= 1n)
|
|
720
735
|
c & 1n && (n = n * r % se), r = r * r % se;
|
|
721
|
-
return T(n * n) === e ? n :
|
|
736
|
+
return T(n * n) === e ? n : C("sqrt invalid");
|
|
722
737
|
};
|
|
723
|
-
class
|
|
738
|
+
class O {
|
|
724
739
|
static BASE;
|
|
725
740
|
static ZERO;
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
741
|
+
X;
|
|
742
|
+
Y;
|
|
743
|
+
Z;
|
|
729
744
|
constructor(e, n, r) {
|
|
730
|
-
this.
|
|
745
|
+
this.X = Ut(e), this.Y = Ke(n), this.Z = Ut(r), Object.freeze(this);
|
|
746
|
+
}
|
|
747
|
+
static CURVE() {
|
|
748
|
+
return Ln;
|
|
749
|
+
}
|
|
750
|
+
/** Create 3d xyz point from 2d xy. (0, 0) => (0, 1, 0), not (0, 0, 1) */
|
|
751
|
+
static fromAffine(e) {
|
|
752
|
+
const { x: n, y: r } = e;
|
|
753
|
+
return n === 0n && r === 0n ? re : new O(n, r, 1n);
|
|
731
754
|
}
|
|
732
755
|
/** Convert Uint8Array or hex string to Point. */
|
|
733
756
|
static fromBytes(e) {
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
757
|
+
_t(e);
|
|
758
|
+
const { publicKey: n, publicKeyUncompressed: r } = as;
|
|
759
|
+
let c;
|
|
760
|
+
const s = e.length, o = e[0], i = e.subarray(1), a = Ht(i, 0, ht);
|
|
761
|
+
if (s === n && (o === 2 || o === 3)) {
|
|
762
|
+
let u = ys(a);
|
|
763
|
+
const f = pt(u);
|
|
764
|
+
pt(Le(o)) !== f && (u = T(-u)), c = new O(a, u, 1n);
|
|
741
765
|
}
|
|
742
|
-
return
|
|
766
|
+
return s === r && o === 4 && (c = new O(a, Ht(i, ht, Tt), 1n)), c ? c.assertValidity() : C("bad point: not on curve");
|
|
767
|
+
}
|
|
768
|
+
static fromHex(e) {
|
|
769
|
+
return O.fromBytes(Dn(e));
|
|
770
|
+
}
|
|
771
|
+
get x() {
|
|
772
|
+
return this.toAffine().x;
|
|
773
|
+
}
|
|
774
|
+
get y() {
|
|
775
|
+
return this.toAffine().y;
|
|
743
776
|
}
|
|
744
777
|
/** Equality check: compare points P&Q. */
|
|
745
778
|
equals(e) {
|
|
746
|
-
const {
|
|
747
|
-
return a === u && f ===
|
|
779
|
+
const { X: n, Y: r, Z: c } = this, { X: s, Y: o, Z: i } = rt(e), a = T(n * i), u = T(s * c), f = T(r * i), h = T(o * c);
|
|
780
|
+
return a === u && f === h;
|
|
748
781
|
}
|
|
749
782
|
is0() {
|
|
750
783
|
return this.equals(re);
|
|
751
784
|
}
|
|
752
785
|
/** Flip point over y coordinate. */
|
|
753
786
|
negate() {
|
|
754
|
-
return new
|
|
787
|
+
return new O(this.X, T(-this.Y), this.Z);
|
|
755
788
|
}
|
|
756
789
|
/** Point doubling: P+P, complete formula. */
|
|
757
790
|
double() {
|
|
@@ -764,13 +797,16 @@ class C {
|
|
|
764
797
|
*/
|
|
765
798
|
// prettier-ignore
|
|
766
799
|
add(e) {
|
|
767
|
-
const {
|
|
768
|
-
let f = 0n,
|
|
800
|
+
const { X: n, Y: r, Z: c } = this, { X: s, Y: o, Z: i } = rt(e), a = 0n, u = Mn;
|
|
801
|
+
let f = 0n, h = 0n, g = 0n;
|
|
769
802
|
const y = T(u * 3n);
|
|
770
|
-
let
|
|
771
|
-
b = T(b * S), S = T(
|
|
803
|
+
let p = T(n * s), d = T(r * o), E = T(c * i), b = T(n + r), S = T(s + o);
|
|
804
|
+
b = T(b * S), S = T(p + d), b = T(b - S), S = T(n + c);
|
|
772
805
|
let w = T(s + i);
|
|
773
|
-
return S = T(S * w), w = T(
|
|
806
|
+
return S = T(S * w), w = T(p + E), S = T(S - w), w = T(r + c), f = T(o + i), w = T(w * f), f = T(d + E), w = T(w - f), g = T(a * S), f = T(y * E), g = T(f + g), f = T(d - g), g = T(d + g), h = T(f * g), d = T(p + p), d = T(d + p), E = T(a * E), S = T(y * S), d = T(d + E), E = T(p - E), E = T(a * E), S = T(S + E), p = T(d * S), h = T(h + p), p = T(w * S), f = T(b * f), f = T(f - p), p = T(b * d), g = T(w * g), g = T(g + p), new O(f, h, g);
|
|
807
|
+
}
|
|
808
|
+
subtract(e) {
|
|
809
|
+
return this.add(rt(e).negate());
|
|
774
810
|
}
|
|
775
811
|
/**
|
|
776
812
|
* Point-by-scalar multiplication. Scalar must be in range 1 <= n < CURVE.n.
|
|
@@ -782,71 +818,51 @@ class C {
|
|
|
782
818
|
multiply(e, n = !0) {
|
|
783
819
|
if (!n && e === 0n)
|
|
784
820
|
return re;
|
|
785
|
-
if (
|
|
821
|
+
if (ds(e), e === 1n)
|
|
786
822
|
return this;
|
|
787
|
-
if (this.equals(
|
|
788
|
-
return
|
|
789
|
-
let r = re, c =
|
|
823
|
+
if (this.equals(Se))
|
|
824
|
+
return Ts(e).p;
|
|
825
|
+
let r = re, c = Se;
|
|
790
826
|
for (let s = this; e > 0n; s = s.double(), e >>= 1n)
|
|
791
827
|
e & 1n ? r = r.add(s) : n && (c = c.add(s));
|
|
792
828
|
return r;
|
|
793
829
|
}
|
|
830
|
+
multiplyUnsafe(e) {
|
|
831
|
+
return this.multiply(e, !1);
|
|
832
|
+
}
|
|
794
833
|
/** Convert point to 2d xy affine point. (X, Y, Z) ∋ (x=X/Z, y=Y/Z) */
|
|
795
834
|
toAffine() {
|
|
796
|
-
const {
|
|
835
|
+
const { X: e, Y: n, Z: r } = this;
|
|
797
836
|
if (this.equals(re))
|
|
798
837
|
return { x: 0n, y: 0n };
|
|
799
838
|
if (r === 1n)
|
|
800
839
|
return { x: e, y: n };
|
|
801
|
-
const c =
|
|
802
|
-
return T(r * c) !== 1n &&
|
|
840
|
+
const c = ls(r, se);
|
|
841
|
+
return T(r * c) !== 1n && C("inverse invalid"), { x: T(e * c), y: T(n * c) };
|
|
803
842
|
}
|
|
804
843
|
/** Checks if the point is valid and on-curve. */
|
|
805
844
|
assertValidity() {
|
|
806
845
|
const { x: e, y: n } = this.toAffine();
|
|
807
|
-
return
|
|
846
|
+
return Ke(e), Ke(n), T(n * n) === qn(e) ? this : C("bad point: not on curve");
|
|
808
847
|
}
|
|
809
848
|
/** Converts point to 33/65-byte Uint8Array. */
|
|
810
849
|
toBytes(e = !0) {
|
|
811
850
|
const { x: n, y: r } = this.assertValidity().toAffine(), c = Bt(n);
|
|
812
|
-
return e ?
|
|
813
|
-
}
|
|
814
|
-
/** Create 3d xyz point from 2d xy. (0, 0) => (0, 1, 0), not (0, 0, 1) */
|
|
815
|
-
static fromAffine(e) {
|
|
816
|
-
const { x: n, y: r } = e;
|
|
817
|
-
return n === 0n && r === 0n ? re : new C(n, r, 1n);
|
|
851
|
+
return e ? Nt(gs(r), c) : Nt(Vn(4), c, Bt(r));
|
|
818
852
|
}
|
|
819
853
|
toHex(e) {
|
|
820
854
|
return Xn(this.toBytes(e));
|
|
821
855
|
}
|
|
822
|
-
static fromPrivateKey(e) {
|
|
823
|
-
return ae.multiply(Es(e));
|
|
824
|
-
}
|
|
825
|
-
static fromHex(e) {
|
|
826
|
-
return C.fromBytes(jn(e));
|
|
827
|
-
}
|
|
828
|
-
get x() {
|
|
829
|
-
return this.toAffine().x;
|
|
830
|
-
}
|
|
831
|
-
get y() {
|
|
832
|
-
return this.toAffine().y;
|
|
833
|
-
}
|
|
834
|
-
toRawBytes(e) {
|
|
835
|
-
return this.toBytes(e);
|
|
836
|
-
}
|
|
837
856
|
}
|
|
838
|
-
const
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
const
|
|
842
|
-
const e = Wn(t) ? t : $n(jn(t, Me));
|
|
843
|
-
return me(e, 1n, Ln, "private key invalid 3");
|
|
844
|
-
}, De = 8, bs = 256, Zn = Math.ceil(bs / De) + 1, dt = 2 ** (De - 1), Ts = () => {
|
|
857
|
+
const Se = new O(is, cs, 1n), re = new O(0n, 1n, 0n);
|
|
858
|
+
O.BASE = Se;
|
|
859
|
+
O.ZERO = re;
|
|
860
|
+
const Ss = (t) => Le("0x" + (Xn(t) || "0")), Ht = (t, e, n) => Ss(t.subarray(e, n)), ws = 2n ** 256n, Bt = (t) => Dn(Gn(je(t, 0n, ws), Tt)), Me = 8, Es = 256, jn = Math.ceil(Es / Me) + 1, lt = 2 ** (Me - 1), bs = () => {
|
|
845
861
|
const t = [];
|
|
846
|
-
let e =
|
|
847
|
-
for (let r = 0; r <
|
|
862
|
+
let e = Se, n = e;
|
|
863
|
+
for (let r = 0; r < jn; r++) {
|
|
848
864
|
n = e, t.push(n);
|
|
849
|
-
for (let c = 1; c <
|
|
865
|
+
for (let c = 1; c < lt; c++)
|
|
850
866
|
n = n.add(e), t.push(n);
|
|
851
867
|
e = n.double();
|
|
852
868
|
}
|
|
@@ -856,18 +872,18 @@ let Rt;
|
|
|
856
872
|
const Ft = (t, e) => {
|
|
857
873
|
const n = e.negate();
|
|
858
874
|
return t ? n : e;
|
|
859
|
-
},
|
|
860
|
-
const e = Rt || (Rt =
|
|
861
|
-
let n = re, r =
|
|
862
|
-
const c = 2 **
|
|
863
|
-
for (let a = 0; a <
|
|
875
|
+
}, Ts = (t) => {
|
|
876
|
+
const e = Rt || (Rt = bs());
|
|
877
|
+
let n = re, r = Se;
|
|
878
|
+
const c = 2 ** Me, s = c, o = Le(c - 1), i = Le(Me);
|
|
879
|
+
for (let a = 0; a < jn; a++) {
|
|
864
880
|
let u = Number(t & o);
|
|
865
|
-
t >>= i, u >
|
|
866
|
-
const f = a *
|
|
867
|
-
u === 0 ? r = r.add(Ft(y, e[
|
|
881
|
+
t >>= i, u > lt && (u -= s, t += 1n);
|
|
882
|
+
const f = a * lt, h = f, g = f + Math.abs(u) - 1, y = a % 2 !== 0, p = u < 0;
|
|
883
|
+
u === 0 ? r = r.add(Ft(y, e[h])) : n = n.add(Ft(p, e[g]));
|
|
868
884
|
}
|
|
869
|
-
return { p: n, f: r };
|
|
870
|
-
},
|
|
885
|
+
return t !== 0n && C("invalid wnaf"), { p: n, f: r };
|
|
886
|
+
}, ge = (t) => {
|
|
871
887
|
const e = t.length === 32 ? t : t.subarray(1, 33);
|
|
872
888
|
return l.isBuffer(e) ? e : l.from(e);
|
|
873
889
|
};
|
|
@@ -875,7 +891,7 @@ function Kt(t) {
|
|
|
875
891
|
let e = t.toString(16);
|
|
876
892
|
return e = e.padStart(64, "0"), e.length > 64 && (e = e.slice(-64)), l.from(e, "hex");
|
|
877
893
|
}
|
|
878
|
-
function
|
|
894
|
+
function _s(t) {
|
|
879
895
|
if (t.length === 32)
|
|
880
896
|
return;
|
|
881
897
|
if (![33, 65].includes(t.length)) {
|
|
@@ -886,7 +902,7 @@ function ms(t) {
|
|
|
886
902
|
}
|
|
887
903
|
let e;
|
|
888
904
|
try {
|
|
889
|
-
e =
|
|
905
|
+
e = O.fromHex(l.from(t).toString("hex"));
|
|
890
906
|
} catch {
|
|
891
907
|
throw new Error("Invalid secp256k1 public key bytes. Cannot parse.");
|
|
892
908
|
}
|
|
@@ -898,7 +914,7 @@ function ms(t) {
|
|
|
898
914
|
uncompressed: i
|
|
899
915
|
};
|
|
900
916
|
}
|
|
901
|
-
function
|
|
917
|
+
function ke(t, e) {
|
|
902
918
|
if (t.equals(e)) return !0;
|
|
903
919
|
if (t.length === 65 && e.length === 65) {
|
|
904
920
|
const n = l.from(t), r = l.from(e);
|
|
@@ -906,13 +922,13 @@ function xe(t, e) {
|
|
|
906
922
|
}
|
|
907
923
|
return !1;
|
|
908
924
|
}
|
|
909
|
-
const
|
|
925
|
+
const _e = 40, me = 2, Ie = 15, zn = 16, We = 16, ze = 2, Ye = 80, ms = "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.", Yn = (t) => {
|
|
910
926
|
try {
|
|
911
927
|
const e = l.from(t.subarray(2));
|
|
912
|
-
if (e.length <
|
|
928
|
+
if (e.length < me || e.length > _e)
|
|
913
929
|
throw new TypeError("Invalid program length for segwit address");
|
|
914
|
-
const n = t[0] -
|
|
915
|
-
if (n <
|
|
930
|
+
const n = t[0] - Ye;
|
|
931
|
+
if (n < ze || n > Ie + 1)
|
|
916
932
|
throw new TypeError("Invalid version for segwit address");
|
|
917
933
|
if (n === 1) throw new TypeError("taproot");
|
|
918
934
|
return !0;
|
|
@@ -920,7 +936,7 @@ const Ie = 40, ve = 2, ke = 15, Jn = 16, qe = 16, $e = 2, Ze = 80, Is = "WARNING
|
|
|
920
936
|
}
|
|
921
937
|
return !1;
|
|
922
938
|
};
|
|
923
|
-
function
|
|
939
|
+
function $n(t, e) {
|
|
924
940
|
if (!l.isBuffer(t)) throw new TypeError("output must be a Buffer");
|
|
925
941
|
if (!e.bech32Opnet) throw new Error("Network does not support opnet");
|
|
926
942
|
const n = t[0];
|
|
@@ -932,85 +948,85 @@ function er(t, e) {
|
|
|
932
948
|
else
|
|
933
949
|
throw new TypeError("Unsupported push opcode in script");
|
|
934
950
|
const s = l.from(t.subarray(r, r + c));
|
|
935
|
-
if (s.length <
|
|
951
|
+
if (s.length < me || s.length > _e)
|
|
936
952
|
throw new TypeError("Invalid program length for segwit address");
|
|
937
|
-
const o = n ===
|
|
938
|
-
if (o <
|
|
953
|
+
const o = n === ve.OP_0 ? 0 : n >= ve.OP_1 && n <= ve.OP_16 ? n - (ve.OP_1 - 1) : -1;
|
|
954
|
+
if (o < Ie || o > zn)
|
|
939
955
|
throw new TypeError(`Invalid segwit version ${o}`);
|
|
940
956
|
const i = [o, ...K.bech32m.toWords(s)];
|
|
941
957
|
return K.bech32m.encode(e.bech32Opnet, i);
|
|
942
958
|
}
|
|
943
|
-
function
|
|
959
|
+
function Zn(t, e) {
|
|
944
960
|
const n = l.from(t.subarray(2));
|
|
945
|
-
if (n.length <
|
|
961
|
+
if (n.length < me || n.length > _e)
|
|
946
962
|
throw new TypeError("Invalid program length for segwit address");
|
|
947
|
-
const r = t[0] -
|
|
948
|
-
if (r <
|
|
963
|
+
const r = t[0] - Ye;
|
|
964
|
+
if (r < ze || r > Ie)
|
|
949
965
|
throw new TypeError("Invalid version for segwit address");
|
|
950
966
|
if (t[1] !== n.length)
|
|
951
967
|
throw new TypeError(`Invalid script for segwit address ${t[1]} !== ${n.length}`);
|
|
952
|
-
return
|
|
968
|
+
return Qn(n, r, e.bech32, e.bech32Opnet);
|
|
953
969
|
}
|
|
954
|
-
function
|
|
970
|
+
function Jn(t) {
|
|
955
971
|
const e = l.from(Fn.decode(t));
|
|
956
972
|
if (e.length < 21) throw new TypeError(t + " is too short");
|
|
957
973
|
if (e.length > 21) throw new TypeError(t + " is too long");
|
|
958
974
|
const n = e.readUInt8(0), r = l.from(e.subarray(1));
|
|
959
975
|
return { version: n, hash: r };
|
|
960
976
|
}
|
|
961
|
-
function
|
|
962
|
-
|
|
977
|
+
function Is(t, e) {
|
|
978
|
+
Ar(xr(Cr, Or), [t, e]);
|
|
963
979
|
const n = l.allocUnsafe(21);
|
|
964
980
|
return n.writeUInt8(e, 0), t.copy(n, 1), Fn.encode(n);
|
|
965
981
|
}
|
|
966
|
-
function
|
|
982
|
+
function Qn(t, e, n, r) {
|
|
967
983
|
const c = K.bech32.toWords(t);
|
|
968
|
-
return c.unshift(e), e ===
|
|
984
|
+
return c.unshift(e), e === We && r ? K.bech32m.encode(r, c) : e === 0 ? K.bech32.encode(n, c) : K.bech32m.encode(n, c);
|
|
969
985
|
}
|
|
970
|
-
function
|
|
971
|
-
e = e ||
|
|
986
|
+
function er(t, e) {
|
|
987
|
+
e = e || Ve;
|
|
972
988
|
try {
|
|
973
|
-
return
|
|
989
|
+
return we({ output: t, network: e }).address;
|
|
974
990
|
} catch {
|
|
975
991
|
}
|
|
976
992
|
try {
|
|
977
|
-
return
|
|
993
|
+
return Ee({ output: t, network: e }).address;
|
|
978
994
|
} catch {
|
|
979
995
|
}
|
|
980
996
|
try {
|
|
981
|
-
return
|
|
997
|
+
return Xe({ output: t, network: e }).address;
|
|
982
998
|
} catch {
|
|
983
999
|
}
|
|
984
1000
|
try {
|
|
985
|
-
return
|
|
1001
|
+
return be({ output: t, network: e }).address;
|
|
986
1002
|
} catch {
|
|
987
1003
|
}
|
|
988
1004
|
try {
|
|
989
|
-
return
|
|
1005
|
+
return Te({ output: t, network: e }).address;
|
|
990
1006
|
} catch {
|
|
991
1007
|
}
|
|
992
1008
|
try {
|
|
993
|
-
return
|
|
1009
|
+
return $n(t, e);
|
|
994
1010
|
} catch {
|
|
995
1011
|
}
|
|
996
1012
|
try {
|
|
997
|
-
return
|
|
1013
|
+
return Zn(t, e);
|
|
998
1014
|
} catch {
|
|
999
1015
|
}
|
|
1000
|
-
throw new Error(
|
|
1016
|
+
throw new Error(Ir(t) + " has no matching Address");
|
|
1001
1017
|
}
|
|
1002
|
-
function
|
|
1003
|
-
e = e ||
|
|
1018
|
+
function tr(t, e) {
|
|
1019
|
+
e = e || Ve;
|
|
1004
1020
|
let n, r;
|
|
1005
1021
|
try {
|
|
1006
|
-
n =
|
|
1022
|
+
n = Jn(t);
|
|
1007
1023
|
} catch {
|
|
1008
1024
|
}
|
|
1009
1025
|
if (n) {
|
|
1010
1026
|
if (n.version === e.pubKeyHash)
|
|
1011
|
-
return
|
|
1027
|
+
return we({ hash: n.hash }).output;
|
|
1012
1028
|
if (n.version === e.scriptHash)
|
|
1013
|
-
return
|
|
1029
|
+
return Ee({ hash: n.hash }).output;
|
|
1014
1030
|
} else {
|
|
1015
1031
|
try {
|
|
1016
1032
|
r = Kn(t);
|
|
@@ -1021,47 +1037,47 @@ function or(t, e) {
|
|
|
1021
1037
|
throw new Error(t + " has an invalid prefix");
|
|
1022
1038
|
if (r.version === 0) {
|
|
1023
1039
|
if (r.data.length === 20)
|
|
1024
|
-
return
|
|
1040
|
+
return Xe({ hash: r.data }).output;
|
|
1025
1041
|
if (r.data.length === 32)
|
|
1026
|
-
return
|
|
1042
|
+
return be({ hash: r.data }).output;
|
|
1027
1043
|
} else if (r.version === 1) {
|
|
1028
1044
|
if (r.data.length === 32)
|
|
1029
|
-
return
|
|
1030
|
-
} else if (r.version ===
|
|
1045
|
+
return Te({ pubkey: r.data }).output;
|
|
1046
|
+
} else if (r.version === We) {
|
|
1031
1047
|
if (!e.bech32Opnet) throw new Error(t + " has an invalid prefix");
|
|
1032
1048
|
return On({
|
|
1033
1049
|
program: r.data,
|
|
1034
1050
|
network: e
|
|
1035
1051
|
}).output;
|
|
1036
|
-
} else if (r.version >=
|
|
1037
|
-
return r.version !==
|
|
1038
|
-
r.version +
|
|
1052
|
+
} else if (r.version >= ze && r.version <= Ie && r.data.length >= me && r.data.length <= _e)
|
|
1053
|
+
return r.version !== We && console.warn(ms), vr([
|
|
1054
|
+
r.version + Ye,
|
|
1039
1055
|
r.data
|
|
1040
1056
|
]);
|
|
1041
1057
|
}
|
|
1042
1058
|
}
|
|
1043
1059
|
throw new TypeError(t + " has no matching Script");
|
|
1044
1060
|
}
|
|
1045
|
-
const
|
|
1061
|
+
const Go = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1046
1062
|
__proto__: null,
|
|
1047
|
-
FUTURE_MAX_VERSION:
|
|
1048
|
-
FUTURE_OPNET_VERSION:
|
|
1049
|
-
FUTURE_SEGWIT_MAX_SIZE:
|
|
1050
|
-
FUTURE_SEGWIT_MAX_VERSION:
|
|
1051
|
-
FUTURE_SEGWIT_MIN_SIZE:
|
|
1052
|
-
FUTURE_SEGWIT_MIN_VERSION:
|
|
1053
|
-
FUTURE_SEGWIT_VERSION_DIFF:
|
|
1054
|
-
_toFutureSegwitAddress:
|
|
1055
|
-
fromBase58Check:
|
|
1063
|
+
FUTURE_MAX_VERSION: zn,
|
|
1064
|
+
FUTURE_OPNET_VERSION: We,
|
|
1065
|
+
FUTURE_SEGWIT_MAX_SIZE: _e,
|
|
1066
|
+
FUTURE_SEGWIT_MAX_VERSION: Ie,
|
|
1067
|
+
FUTURE_SEGWIT_MIN_SIZE: me,
|
|
1068
|
+
FUTURE_SEGWIT_MIN_VERSION: ze,
|
|
1069
|
+
FUTURE_SEGWIT_VERSION_DIFF: Ye,
|
|
1070
|
+
_toFutureSegwitAddress: Zn,
|
|
1071
|
+
fromBase58Check: Jn,
|
|
1056
1072
|
fromBech32: Kn,
|
|
1057
|
-
fromOutputScript:
|
|
1058
|
-
isUnknownSegwitVersion:
|
|
1059
|
-
toBase58Check:
|
|
1060
|
-
toBech32:
|
|
1061
|
-
toFutureOPNetAddress:
|
|
1062
|
-
toOutputScript:
|
|
1073
|
+
fromOutputScript: er,
|
|
1074
|
+
isUnknownSegwitVersion: Yn,
|
|
1075
|
+
toBase58Check: Is,
|
|
1076
|
+
toBech32: Qn,
|
|
1077
|
+
toFutureOPNetAddress: $n,
|
|
1078
|
+
toOutputScript: tr
|
|
1063
1079
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
1064
|
-
var
|
|
1080
|
+
var Ae = {}, xe = {}, st = {}, oe = {}, ie = {}, ot = {}, Lt;
|
|
1065
1081
|
function A() {
|
|
1066
1082
|
return Lt || (Lt = 1, (function(t) {
|
|
1067
1083
|
Object.defineProperty(t, "__esModule", { value: !0 }), (function(e) {
|
|
@@ -1095,10 +1111,10 @@ function A() {
|
|
|
1095
1111
|
"tapTree",
|
|
1096
1112
|
"tapBip32Derivation"
|
|
1097
1113
|
];
|
|
1098
|
-
})(
|
|
1114
|
+
})(ot)), ot;
|
|
1099
1115
|
}
|
|
1100
1116
|
var W = {}, Mt;
|
|
1101
|
-
function
|
|
1117
|
+
function vs() {
|
|
1102
1118
|
if (Mt) return W;
|
|
1103
1119
|
Mt = 1, Object.defineProperty(W, "__esModule", { value: !0 });
|
|
1104
1120
|
const t = A(), e = (o) => [...Array(o).keys()];
|
|
@@ -1121,8 +1137,8 @@ function ks() {
|
|
|
1121
1137
|
path: "m"
|
|
1122
1138
|
};
|
|
1123
1139
|
for (const u of e(o.value.length / 4 - 1)) {
|
|
1124
|
-
const f = o.value.readUInt32LE(u * 4 + 4),
|
|
1125
|
-
a.path += "/" + g.toString(10) + (
|
|
1140
|
+
const f = o.value.readUInt32LE(u * 4 + 4), h = !!(f & 2147483648), g = f & 2147483647;
|
|
1141
|
+
a.path += "/" + g.toString(10) + (h ? "'" : "");
|
|
1126
1142
|
}
|
|
1127
1143
|
return a;
|
|
1128
1144
|
}
|
|
@@ -1130,11 +1146,11 @@ function ks() {
|
|
|
1130
1146
|
function r(o) {
|
|
1131
1147
|
const i = l.from([t.GlobalTypes.GLOBAL_XPUB]), a = l.concat([i, o.extendedPubkey]), u = o.path.split("/"), f = l.allocUnsafe(u.length * 4);
|
|
1132
1148
|
o.masterFingerprint.copy(f, 0);
|
|
1133
|
-
let
|
|
1149
|
+
let h = 4;
|
|
1134
1150
|
return u.slice(1).forEach((g) => {
|
|
1135
1151
|
const y = g.slice(-1) === "'";
|
|
1136
|
-
let
|
|
1137
|
-
y && (
|
|
1152
|
+
let p = 2147483647 & parseInt(y ? g.slice(0, -1) : g, 10);
|
|
1153
|
+
y && (p += 2147483648), f.writeUInt32LE(p, h), h += 4;
|
|
1138
1154
|
}), {
|
|
1139
1155
|
key: a,
|
|
1140
1156
|
value: f
|
|
@@ -1152,10 +1168,10 @@ function ks() {
|
|
|
1152
1168
|
}
|
|
1153
1169
|
return W.canAddToArray = s, W;
|
|
1154
1170
|
}
|
|
1155
|
-
var
|
|
1156
|
-
function
|
|
1157
|
-
if (Wt) return
|
|
1158
|
-
Wt = 1, Object.defineProperty(
|
|
1171
|
+
var Ce = {}, Wt;
|
|
1172
|
+
function ks() {
|
|
1173
|
+
if (Wt) return Ce;
|
|
1174
|
+
Wt = 1, Object.defineProperty(Ce, "__esModule", { value: !0 });
|
|
1159
1175
|
const t = A();
|
|
1160
1176
|
function e(n) {
|
|
1161
1177
|
return {
|
|
@@ -1163,10 +1179,10 @@ function As() {
|
|
|
1163
1179
|
value: n.toBuffer()
|
|
1164
1180
|
};
|
|
1165
1181
|
}
|
|
1166
|
-
return
|
|
1182
|
+
return Ce.encode = e, Ce;
|
|
1167
1183
|
}
|
|
1168
1184
|
var G = {}, Gt;
|
|
1169
|
-
function
|
|
1185
|
+
function As() {
|
|
1170
1186
|
if (Gt) return G;
|
|
1171
1187
|
Gt = 1, Object.defineProperty(G, "__esModule", { value: !0 });
|
|
1172
1188
|
const t = A();
|
|
@@ -1194,10 +1210,10 @@ function xs() {
|
|
|
1194
1210
|
}
|
|
1195
1211
|
return G.canAdd = c, G;
|
|
1196
1212
|
}
|
|
1197
|
-
var
|
|
1198
|
-
function
|
|
1199
|
-
if (
|
|
1200
|
-
|
|
1213
|
+
var X = {}, Xt;
|
|
1214
|
+
function xs() {
|
|
1215
|
+
if (Xt) return X;
|
|
1216
|
+
Xt = 1, Object.defineProperty(X, "__esModule", { value: !0 });
|
|
1201
1217
|
const t = A();
|
|
1202
1218
|
function e(s) {
|
|
1203
1219
|
if (s.key[0] !== t.InputTypes.FINAL_SCRIPTWITNESS)
|
|
@@ -1206,27 +1222,27 @@ function Cs() {
|
|
|
1206
1222
|
);
|
|
1207
1223
|
return s.value;
|
|
1208
1224
|
}
|
|
1209
|
-
|
|
1225
|
+
X.decode = e;
|
|
1210
1226
|
function n(s) {
|
|
1211
1227
|
return {
|
|
1212
1228
|
key: l.from([t.InputTypes.FINAL_SCRIPTWITNESS]),
|
|
1213
1229
|
value: s
|
|
1214
1230
|
};
|
|
1215
1231
|
}
|
|
1216
|
-
|
|
1232
|
+
X.encode = n, X.expected = "Buffer";
|
|
1217
1233
|
function r(s) {
|
|
1218
1234
|
return l.isBuffer(s);
|
|
1219
1235
|
}
|
|
1220
|
-
|
|
1236
|
+
X.check = r;
|
|
1221
1237
|
function c(s, o) {
|
|
1222
1238
|
return !!s && !!o && s.finalScriptWitness === void 0;
|
|
1223
1239
|
}
|
|
1224
|
-
return
|
|
1240
|
+
return X.canAdd = c, X;
|
|
1225
1241
|
}
|
|
1226
|
-
var
|
|
1227
|
-
function
|
|
1228
|
-
if (
|
|
1229
|
-
|
|
1242
|
+
var D = {}, Dt;
|
|
1243
|
+
function Cs() {
|
|
1244
|
+
if (Dt) return D;
|
|
1245
|
+
Dt = 1, Object.defineProperty(D, "__esModule", { value: !0 });
|
|
1230
1246
|
const t = A();
|
|
1231
1247
|
function e(s) {
|
|
1232
1248
|
if (s.key[0] !== t.InputTypes.NON_WITNESS_UTXO)
|
|
@@ -1235,27 +1251,27 @@ function Os() {
|
|
|
1235
1251
|
);
|
|
1236
1252
|
return s.value;
|
|
1237
1253
|
}
|
|
1238
|
-
|
|
1254
|
+
D.decode = e;
|
|
1239
1255
|
function n(s) {
|
|
1240
1256
|
return {
|
|
1241
1257
|
key: l.from([t.InputTypes.NON_WITNESS_UTXO]),
|
|
1242
1258
|
value: s
|
|
1243
1259
|
};
|
|
1244
1260
|
}
|
|
1245
|
-
|
|
1261
|
+
D.encode = n, D.expected = "Buffer";
|
|
1246
1262
|
function r(s) {
|
|
1247
1263
|
return l.isBuffer(s);
|
|
1248
1264
|
}
|
|
1249
|
-
|
|
1265
|
+
D.check = r;
|
|
1250
1266
|
function c(s, o) {
|
|
1251
1267
|
return !!s && !!o && s.nonWitnessUtxo === void 0;
|
|
1252
1268
|
}
|
|
1253
|
-
return
|
|
1269
|
+
return D.canAdd = c, D;
|
|
1254
1270
|
}
|
|
1255
|
-
var
|
|
1256
|
-
function
|
|
1257
|
-
if (
|
|
1258
|
-
|
|
1271
|
+
var q = {}, qt;
|
|
1272
|
+
function Os() {
|
|
1273
|
+
if (qt) return q;
|
|
1274
|
+
qt = 1, Object.defineProperty(q, "__esModule", { value: !0 });
|
|
1259
1275
|
const t = A();
|
|
1260
1276
|
function e(o) {
|
|
1261
1277
|
if (o.key[0] !== t.InputTypes.PARTIAL_SIG)
|
|
@@ -1271,7 +1287,7 @@ function Ps() {
|
|
|
1271
1287
|
signature: o.value
|
|
1272
1288
|
};
|
|
1273
1289
|
}
|
|
1274
|
-
|
|
1290
|
+
q.decode = e;
|
|
1275
1291
|
function n(o) {
|
|
1276
1292
|
const i = l.from([t.InputTypes.PARTIAL_SIG]);
|
|
1277
1293
|
return {
|
|
@@ -1279,11 +1295,11 @@ function Ps() {
|
|
|
1279
1295
|
value: o.signature
|
|
1280
1296
|
};
|
|
1281
1297
|
}
|
|
1282
|
-
|
|
1298
|
+
q.encode = n, q.expected = "{ pubkey: Buffer; signature: Buffer; }";
|
|
1283
1299
|
function r(o) {
|
|
1284
1300
|
return l.isBuffer(o.pubkey) && l.isBuffer(o.signature) && [33, 65].includes(o.pubkey.length) && [2, 3, 4].includes(o.pubkey[0]) && c(o.signature);
|
|
1285
1301
|
}
|
|
1286
|
-
|
|
1302
|
+
q.check = r;
|
|
1287
1303
|
function c(o) {
|
|
1288
1304
|
if (!l.isBuffer(o) || o.length < 9 || o[0] !== 48 || o.length !== o[1] + 3 || o[2] !== 2) return !1;
|
|
1289
1305
|
const i = o[3];
|
|
@@ -1295,10 +1311,10 @@ function Ps() {
|
|
|
1295
1311
|
const u = i.pubkey.toString("hex");
|
|
1296
1312
|
return a.has(u) ? !1 : (a.add(u), o.filter((f) => f.pubkey.equals(i.pubkey)).length === 0);
|
|
1297
1313
|
}
|
|
1298
|
-
return
|
|
1314
|
+
return q.canAddToArray = s, q;
|
|
1299
1315
|
}
|
|
1300
1316
|
var V = {}, Vt;
|
|
1301
|
-
function
|
|
1317
|
+
function Ps() {
|
|
1302
1318
|
if (Vt) return V;
|
|
1303
1319
|
Vt = 1, Object.defineProperty(V, "__esModule", { value: !0 });
|
|
1304
1320
|
const t = A();
|
|
@@ -1327,7 +1343,7 @@ function Ns() {
|
|
|
1327
1343
|
return V.canAdd = c, V;
|
|
1328
1344
|
}
|
|
1329
1345
|
var j = {}, jt;
|
|
1330
|
-
function
|
|
1346
|
+
function Ns() {
|
|
1331
1347
|
if (jt) return j;
|
|
1332
1348
|
jt = 1, Object.defineProperty(j, "__esModule", { value: !0 });
|
|
1333
1349
|
const t = A();
|
|
@@ -1387,7 +1403,7 @@ function Us() {
|
|
|
1387
1403
|
return z.canAdd = c, z;
|
|
1388
1404
|
}
|
|
1389
1405
|
var Y = {}, Yt;
|
|
1390
|
-
function
|
|
1406
|
+
function Hs() {
|
|
1391
1407
|
if (Yt) return Y;
|
|
1392
1408
|
Yt = 1, Object.defineProperty(Y, "__esModule", { value: !0 });
|
|
1393
1409
|
const t = A();
|
|
@@ -1428,7 +1444,7 @@ function Bs() {
|
|
|
1428
1444
|
return Y.canAddToArray = c, Y;
|
|
1429
1445
|
}
|
|
1430
1446
|
var $ = {}, $t;
|
|
1431
|
-
function
|
|
1447
|
+
function Bs() {
|
|
1432
1448
|
if ($t) return $;
|
|
1433
1449
|
$t = 1, Object.defineProperty($, "__esModule", { value: !0 });
|
|
1434
1450
|
const t = A();
|
|
@@ -1456,7 +1472,7 @@ function Rs() {
|
|
|
1456
1472
|
return $.canAdd = c, $;
|
|
1457
1473
|
}
|
|
1458
1474
|
var Z = {}, Zt;
|
|
1459
|
-
function
|
|
1475
|
+
function Rs() {
|
|
1460
1476
|
if (Zt) return Z;
|
|
1461
1477
|
Zt = 1, Object.defineProperty(Z, "__esModule", { value: !0 });
|
|
1462
1478
|
const t = A();
|
|
@@ -1502,7 +1518,7 @@ function Fs() {
|
|
|
1502
1518
|
return Z.canAddToArray = c, Z;
|
|
1503
1519
|
}
|
|
1504
1520
|
var J = {}, F = {}, ce = {}, Jt;
|
|
1505
|
-
function
|
|
1521
|
+
function fe() {
|
|
1506
1522
|
if (Jt) return ce;
|
|
1507
1523
|
Jt = 1, Object.defineProperty(ce, "__esModule", { value: !0 });
|
|
1508
1524
|
const t = 9007199254740991;
|
|
@@ -1540,10 +1556,10 @@ function pe() {
|
|
|
1540
1556
|
return ce.encodingLength = c, ce;
|
|
1541
1557
|
}
|
|
1542
1558
|
var Qt;
|
|
1543
|
-
function
|
|
1559
|
+
function mt() {
|
|
1544
1560
|
if (Qt) return F;
|
|
1545
1561
|
Qt = 1, Object.defineProperty(F, "__esModule", { value: !0 });
|
|
1546
|
-
const t =
|
|
1562
|
+
const t = fe();
|
|
1547
1563
|
F.range = (i) => [...Array(i).keys()];
|
|
1548
1564
|
function e(i) {
|
|
1549
1565
|
if (i.length < 1) return i;
|
|
@@ -1559,10 +1575,10 @@ function _t() {
|
|
|
1559
1575
|
}
|
|
1560
1576
|
F.keyValsToBuffer = n;
|
|
1561
1577
|
function r(i) {
|
|
1562
|
-
const a = i.key.length, u = i.value.length, f = t.encodingLength(a),
|
|
1563
|
-
f + a +
|
|
1578
|
+
const a = i.key.length, u = i.value.length, f = t.encodingLength(a), h = t.encodingLength(u), g = l.allocUnsafe(
|
|
1579
|
+
f + a + h + u
|
|
1564
1580
|
);
|
|
1565
|
-
return t.encode(a, g, 0), i.key.copy(g, f), t.encode(u, g, f + a), i.value.copy(g, f + a +
|
|
1581
|
+
return t.encode(a, g, 0), i.key.copy(g, f), t.encode(u, g, f + a), i.value.copy(g, f + a + h), g;
|
|
1566
1582
|
}
|
|
1567
1583
|
F.keyValToBuffer = r;
|
|
1568
1584
|
function c(i, a) {
|
|
@@ -1586,10 +1602,10 @@ function _t() {
|
|
|
1586
1602
|
return F.writeUInt64LE = o, F;
|
|
1587
1603
|
}
|
|
1588
1604
|
var en;
|
|
1589
|
-
function
|
|
1605
|
+
function Fs() {
|
|
1590
1606
|
if (en) return J;
|
|
1591
1607
|
en = 1, Object.defineProperty(J, "__esModule", { value: !0 });
|
|
1592
|
-
const t = A(), e =
|
|
1608
|
+
const t = A(), e = mt(), n = fe();
|
|
1593
1609
|
function r(i) {
|
|
1594
1610
|
if (i.key[0] !== t.InputTypes.WITNESS_UTXO)
|
|
1595
1611
|
throw new Error(
|
|
@@ -1599,20 +1615,20 @@ function Ks() {
|
|
|
1599
1615
|
let u = 8;
|
|
1600
1616
|
const f = n.decode(i.value, u);
|
|
1601
1617
|
u += n.encodingLength(f);
|
|
1602
|
-
const
|
|
1603
|
-
if (
|
|
1618
|
+
const h = i.value.slice(u);
|
|
1619
|
+
if (h.length !== f)
|
|
1604
1620
|
throw new Error("Decode Error: WITNESS_UTXO script is not proper length");
|
|
1605
1621
|
return {
|
|
1606
|
-
script:
|
|
1622
|
+
script: h,
|
|
1607
1623
|
value: a
|
|
1608
1624
|
};
|
|
1609
1625
|
}
|
|
1610
1626
|
J.decode = r;
|
|
1611
1627
|
function c(i) {
|
|
1612
|
-
const { script: a, value: u } = i, f = n.encodingLength(a.length),
|
|
1613
|
-
return e.writeUInt64LE(
|
|
1628
|
+
const { script: a, value: u } = i, f = n.encodingLength(a.length), h = l.allocUnsafe(8 + f + a.length);
|
|
1629
|
+
return e.writeUInt64LE(h, u, 0), n.encode(a.length, h, 8), a.copy(h, 8 + f), {
|
|
1614
1630
|
key: l.from([t.InputTypes.WITNESS_UTXO]),
|
|
1615
|
-
value:
|
|
1631
|
+
value: h
|
|
1616
1632
|
};
|
|
1617
1633
|
}
|
|
1618
1634
|
J.encode = c, J.expected = "{ script: Buffer; value: number; }";
|
|
@@ -1626,10 +1642,10 @@ function Ks() {
|
|
|
1626
1642
|
return J.canAdd = o, J;
|
|
1627
1643
|
}
|
|
1628
1644
|
var Q = {}, tn;
|
|
1629
|
-
function
|
|
1645
|
+
function Ks() {
|
|
1630
1646
|
if (tn) return Q;
|
|
1631
1647
|
tn = 1, Object.defineProperty(Q, "__esModule", { value: !0 });
|
|
1632
|
-
const t = A(), e =
|
|
1648
|
+
const t = A(), e = fe();
|
|
1633
1649
|
function n(o) {
|
|
1634
1650
|
if (o.key[0] !== t.OutputTypes.TAP_TREE || o.key.length !== 1)
|
|
1635
1651
|
throw new Error(
|
|
@@ -1638,12 +1654,12 @@ function Ls() {
|
|
|
1638
1654
|
let i = 0;
|
|
1639
1655
|
const a = [];
|
|
1640
1656
|
for (; i < o.value.length; ) {
|
|
1641
|
-
const u = o.value[i++], f = o.value[i++],
|
|
1642
|
-
i += e.encodingLength(
|
|
1657
|
+
const u = o.value[i++], f = o.value[i++], h = e.decode(o.value, i);
|
|
1658
|
+
i += e.encodingLength(h), a.push({
|
|
1643
1659
|
depth: u,
|
|
1644
1660
|
leafVersion: f,
|
|
1645
|
-
script: o.value.slice(i, i +
|
|
1646
|
-
}), i +=
|
|
1661
|
+
script: o.value.slice(i, i + h)
|
|
1662
|
+
}), i += h;
|
|
1647
1663
|
}
|
|
1648
1664
|
return { leaves: a };
|
|
1649
1665
|
}
|
|
@@ -1673,10 +1689,10 @@ function Ls() {
|
|
|
1673
1689
|
}
|
|
1674
1690
|
return Q.canAdd = s, Q;
|
|
1675
1691
|
}
|
|
1676
|
-
var
|
|
1677
|
-
function
|
|
1678
|
-
if (nn) return
|
|
1679
|
-
nn = 1, Object.defineProperty(
|
|
1692
|
+
var Oe = {}, nn;
|
|
1693
|
+
function nr() {
|
|
1694
|
+
if (nn) return Oe;
|
|
1695
|
+
nn = 1, Object.defineProperty(Oe, "__esModule", { value: !0 });
|
|
1680
1696
|
const t = (r) => [...Array(r).keys()], e = (r) => r.length === 33 && [2, 3].includes(r[0]) || r.length === 65 && r[0] === 4;
|
|
1681
1697
|
function n(r, c = e) {
|
|
1682
1698
|
function s(f) {
|
|
@@ -1684,8 +1700,8 @@ function ir() {
|
|
|
1684
1700
|
throw new Error(
|
|
1685
1701
|
"Decode Error: could not decode bip32Derivation with key 0x" + f.key.toString("hex")
|
|
1686
1702
|
);
|
|
1687
|
-
const
|
|
1688
|
-
if (!c(
|
|
1703
|
+
const h = f.key.slice(1);
|
|
1704
|
+
if (!c(h))
|
|
1689
1705
|
throw new Error(
|
|
1690
1706
|
"Decode Error: bip32Derivation has invalid pubkey in key 0x" + f.key.toString("hex")
|
|
1691
1707
|
);
|
|
@@ -1695,35 +1711,35 @@ function ir() {
|
|
|
1695
1711
|
);
|
|
1696
1712
|
const g = {
|
|
1697
1713
|
masterFingerprint: f.value.slice(0, 4),
|
|
1698
|
-
pubkey:
|
|
1714
|
+
pubkey: h,
|
|
1699
1715
|
path: "m"
|
|
1700
1716
|
};
|
|
1701
1717
|
for (const y of t(f.value.length / 4 - 1)) {
|
|
1702
|
-
const
|
|
1718
|
+
const p = f.value.readUInt32LE(y * 4 + 4), d = !!(p & 2147483648), E = p & 2147483647;
|
|
1703
1719
|
g.path += "/" + E.toString(10) + (d ? "'" : "");
|
|
1704
1720
|
}
|
|
1705
1721
|
return g;
|
|
1706
1722
|
}
|
|
1707
1723
|
function o(f) {
|
|
1708
|
-
const
|
|
1709
|
-
f.masterFingerprint.copy(
|
|
1724
|
+
const h = l.from([r]), g = l.concat([h, f.pubkey]), y = f.path.split("/"), p = l.allocUnsafe(y.length * 4);
|
|
1725
|
+
f.masterFingerprint.copy(p, 0);
|
|
1710
1726
|
let d = 4;
|
|
1711
1727
|
return y.slice(1).forEach((E) => {
|
|
1712
1728
|
const b = E.slice(-1) === "'";
|
|
1713
1729
|
let S = 2147483647 & parseInt(b ? E.slice(0, -1) : E, 10);
|
|
1714
|
-
b && (S += 2147483648),
|
|
1730
|
+
b && (S += 2147483648), p.writeUInt32LE(S, d), d += 4;
|
|
1715
1731
|
}), {
|
|
1716
1732
|
key: g,
|
|
1717
|
-
value:
|
|
1733
|
+
value: p
|
|
1718
1734
|
};
|
|
1719
1735
|
}
|
|
1720
1736
|
const i = "{ masterFingerprint: Buffer; pubkey: Buffer; path: string; }";
|
|
1721
1737
|
function a(f) {
|
|
1722
1738
|
return l.isBuffer(f.pubkey) && l.isBuffer(f.masterFingerprint) && typeof f.path == "string" && c(f.pubkey) && f.masterFingerprint.length === 4;
|
|
1723
1739
|
}
|
|
1724
|
-
function u(f,
|
|
1725
|
-
const y =
|
|
1726
|
-
return g.has(y) ? !1 : (g.add(y), f.filter((
|
|
1740
|
+
function u(f, h, g) {
|
|
1741
|
+
const y = h.pubkey.toString("hex");
|
|
1742
|
+
return g.has(y) ? !1 : (g.add(y), f.filter((p) => p.pubkey.equals(h.pubkey)).length === 0);
|
|
1727
1743
|
}
|
|
1728
1744
|
return {
|
|
1729
1745
|
decode: s,
|
|
@@ -1733,12 +1749,12 @@ function ir() {
|
|
|
1733
1749
|
canAddToArray: u
|
|
1734
1750
|
};
|
|
1735
1751
|
}
|
|
1736
|
-
return
|
|
1752
|
+
return Oe.makeConverter = n, Oe;
|
|
1737
1753
|
}
|
|
1738
|
-
var
|
|
1739
|
-
function
|
|
1740
|
-
if (rn) return
|
|
1741
|
-
rn = 1, Object.defineProperty(
|
|
1754
|
+
var Pe = {}, rn;
|
|
1755
|
+
function Ls() {
|
|
1756
|
+
if (rn) return Pe;
|
|
1757
|
+
rn = 1, Object.defineProperty(Pe, "__esModule", { value: !0 });
|
|
1742
1758
|
function t(e) {
|
|
1743
1759
|
return n;
|
|
1744
1760
|
function n(r) {
|
|
@@ -1750,12 +1766,12 @@ function Ms() {
|
|
|
1750
1766
|
return c;
|
|
1751
1767
|
}
|
|
1752
1768
|
}
|
|
1753
|
-
return
|
|
1769
|
+
return Pe.makeChecker = t, Pe;
|
|
1754
1770
|
}
|
|
1755
|
-
var
|
|
1756
|
-
function
|
|
1757
|
-
if (sn) return
|
|
1758
|
-
sn = 1, Object.defineProperty(
|
|
1771
|
+
var Ne = {}, sn;
|
|
1772
|
+
function Ms() {
|
|
1773
|
+
if (sn) return Ne;
|
|
1774
|
+
sn = 1, Object.defineProperty(Ne, "__esModule", { value: !0 });
|
|
1759
1775
|
function t(e) {
|
|
1760
1776
|
function n(i) {
|
|
1761
1777
|
if (i.key[0] !== e)
|
|
@@ -1785,34 +1801,34 @@ function Ws() {
|
|
|
1785
1801
|
canAdd: o
|
|
1786
1802
|
};
|
|
1787
1803
|
}
|
|
1788
|
-
return
|
|
1804
|
+
return Ne.makeConverter = t, Ne;
|
|
1789
1805
|
}
|
|
1790
|
-
var
|
|
1791
|
-
function
|
|
1792
|
-
if (on) return
|
|
1793
|
-
on = 1, Object.defineProperty(
|
|
1794
|
-
const t =
|
|
1806
|
+
var Ue = {}, on;
|
|
1807
|
+
function Ws() {
|
|
1808
|
+
if (on) return Ue;
|
|
1809
|
+
on = 1, Object.defineProperty(Ue, "__esModule", { value: !0 });
|
|
1810
|
+
const t = fe(), e = nr(), n = (c) => c.length === 32;
|
|
1795
1811
|
function r(c) {
|
|
1796
1812
|
const s = e.makeConverter(c, n);
|
|
1797
1813
|
function o(f) {
|
|
1798
|
-
const
|
|
1814
|
+
const h = t.decode(f.value), g = t.encodingLength(h), y = s.decode({
|
|
1799
1815
|
key: f.key,
|
|
1800
|
-
value: f.value.slice(g +
|
|
1801
|
-
}),
|
|
1802
|
-
for (let d = 0, E = g; d <
|
|
1803
|
-
|
|
1804
|
-
return Object.assign({}, y, { leafHashes:
|
|
1816
|
+
value: f.value.slice(g + h * 32)
|
|
1817
|
+
}), p = new Array(h);
|
|
1818
|
+
for (let d = 0, E = g; d < h; d++, E += 32)
|
|
1819
|
+
p[d] = f.value.slice(E, E + 32);
|
|
1820
|
+
return Object.assign({}, y, { leafHashes: p });
|
|
1805
1821
|
}
|
|
1806
1822
|
function i(f) {
|
|
1807
|
-
const
|
|
1823
|
+
const h = s.encode(f), g = t.encodingLength(f.leafHashes.length), y = l.allocUnsafe(g);
|
|
1808
1824
|
t.encode(f.leafHashes.length, y);
|
|
1809
|
-
const
|
|
1810
|
-
return Object.assign({},
|
|
1825
|
+
const p = l.concat([y, ...f.leafHashes, h.value]);
|
|
1826
|
+
return Object.assign({}, h, { value: p });
|
|
1811
1827
|
}
|
|
1812
1828
|
const a = "{ masterFingerprint: Buffer; pubkey: Buffer; path: string; leafHashes: Buffer[]; }";
|
|
1813
1829
|
function u(f) {
|
|
1814
1830
|
return Array.isArray(f.leafHashes) && f.leafHashes.every(
|
|
1815
|
-
(
|
|
1831
|
+
(h) => l.isBuffer(h) && h.length === 32
|
|
1816
1832
|
) && s.check(f);
|
|
1817
1833
|
}
|
|
1818
1834
|
return {
|
|
@@ -1823,12 +1839,12 @@ function Gs() {
|
|
|
1823
1839
|
canAddToArray: s.canAddToArray
|
|
1824
1840
|
};
|
|
1825
1841
|
}
|
|
1826
|
-
return
|
|
1842
|
+
return Ue.makeConverter = r, Ue;
|
|
1827
1843
|
}
|
|
1828
|
-
var
|
|
1829
|
-
function
|
|
1830
|
-
if (cn) return
|
|
1831
|
-
cn = 1, Object.defineProperty(
|
|
1844
|
+
var He = {}, cn;
|
|
1845
|
+
function Gs() {
|
|
1846
|
+
if (cn) return He;
|
|
1847
|
+
cn = 1, Object.defineProperty(He, "__esModule", { value: !0 });
|
|
1832
1848
|
function t(e) {
|
|
1833
1849
|
function n(i) {
|
|
1834
1850
|
if (i.key[0] !== e || i.key.length !== 1)
|
|
@@ -1859,12 +1875,12 @@ function Ds() {
|
|
|
1859
1875
|
canAdd: o
|
|
1860
1876
|
};
|
|
1861
1877
|
}
|
|
1862
|
-
return
|
|
1878
|
+
return He.makeConverter = t, He;
|
|
1863
1879
|
}
|
|
1864
|
-
var
|
|
1865
|
-
function
|
|
1866
|
-
if (an) return
|
|
1867
|
-
an = 1, Object.defineProperty(
|
|
1880
|
+
var Be = {}, an;
|
|
1881
|
+
function Xs() {
|
|
1882
|
+
if (an) return Be;
|
|
1883
|
+
an = 1, Object.defineProperty(Be, "__esModule", { value: !0 });
|
|
1868
1884
|
function t(e) {
|
|
1869
1885
|
function n(i) {
|
|
1870
1886
|
if (i.key[0] !== e)
|
|
@@ -1894,20 +1910,20 @@ function qs() {
|
|
|
1894
1910
|
canAdd: o
|
|
1895
1911
|
};
|
|
1896
1912
|
}
|
|
1897
|
-
return
|
|
1913
|
+
return Be.makeConverter = t, Be;
|
|
1898
1914
|
}
|
|
1899
1915
|
var un;
|
|
1900
|
-
function
|
|
1916
|
+
function It() {
|
|
1901
1917
|
if (un) return ie;
|
|
1902
1918
|
un = 1, Object.defineProperty(ie, "__esModule", { value: !0 });
|
|
1903
|
-
const t = A(), e =
|
|
1919
|
+
const t = A(), e = vs(), n = ks(), r = As(), c = xs(), s = Cs(), o = Os(), i = Ps(), a = Ns(), u = Us(), f = Hs(), h = Bs(), g = Rs(), y = Fs(), p = Ks(), d = nr(), E = Ls(), b = Ms(), S = Ws(), w = Gs(), _ = Xs(), I = {
|
|
1904
1920
|
unsignedTx: n,
|
|
1905
1921
|
globalXpub: e,
|
|
1906
1922
|
// pass an Array of key bytes that require pubkey beside the key
|
|
1907
1923
|
checkPubkey: E.makeChecker([])
|
|
1908
1924
|
};
|
|
1909
1925
|
ie.globals = I;
|
|
1910
|
-
const
|
|
1926
|
+
const P = {
|
|
1911
1927
|
nonWitnessUtxo: s,
|
|
1912
1928
|
partialSig: o,
|
|
1913
1929
|
sighashType: a,
|
|
@@ -1937,9 +1953,9 @@ function mt() {
|
|
|
1937
1953
|
tapInternalKey: w.makeConverter(
|
|
1938
1954
|
t.InputTypes.TAP_INTERNAL_KEY
|
|
1939
1955
|
),
|
|
1940
|
-
tapMerkleRoot:
|
|
1956
|
+
tapMerkleRoot: h
|
|
1941
1957
|
};
|
|
1942
|
-
ie.inputs =
|
|
1958
|
+
ie.inputs = P;
|
|
1943
1959
|
const m = {
|
|
1944
1960
|
bip32Derivation: d.makeConverter(
|
|
1945
1961
|
t.OutputTypes.BIP32_DERIVATION
|
|
@@ -1956,7 +1972,7 @@ function mt() {
|
|
|
1956
1972
|
tapBip32Derivation: S.makeConverter(
|
|
1957
1973
|
t.OutputTypes.TAP_BIP32_DERIVATION
|
|
1958
1974
|
),
|
|
1959
|
-
tapTree:
|
|
1975
|
+
tapTree: p,
|
|
1960
1976
|
tapInternalKey: w.makeConverter(
|
|
1961
1977
|
t.OutputTypes.TAP_INTERNAL_KEY
|
|
1962
1978
|
)
|
|
@@ -1964,10 +1980,10 @@ function mt() {
|
|
|
1964
1980
|
return ie.outputs = m, ie;
|
|
1965
1981
|
}
|
|
1966
1982
|
var fn;
|
|
1967
|
-
function
|
|
1983
|
+
function Ds() {
|
|
1968
1984
|
if (fn) return oe;
|
|
1969
1985
|
fn = 1, Object.defineProperty(oe, "__esModule", { value: !0 });
|
|
1970
|
-
const t =
|
|
1986
|
+
const t = It(), e = mt(), n = fe(), r = A();
|
|
1971
1987
|
function c(i, a) {
|
|
1972
1988
|
let u = 0;
|
|
1973
1989
|
function f() {
|
|
@@ -1976,7 +1992,7 @@ function Xs() {
|
|
|
1976
1992
|
const k = i.slice(u, u + m);
|
|
1977
1993
|
return u += m, k;
|
|
1978
1994
|
}
|
|
1979
|
-
function
|
|
1995
|
+
function h() {
|
|
1980
1996
|
const m = i.readUInt32BE(u);
|
|
1981
1997
|
return u += 4, m;
|
|
1982
1998
|
}
|
|
@@ -1991,20 +2007,20 @@ function Xs() {
|
|
|
1991
2007
|
value: k
|
|
1992
2008
|
};
|
|
1993
2009
|
}
|
|
1994
|
-
function
|
|
2010
|
+
function p() {
|
|
1995
2011
|
if (u >= i.length)
|
|
1996
2012
|
throw new Error("Format Error: Unexpected End of PSBT");
|
|
1997
2013
|
const m = i.readUInt8(u) === 0;
|
|
1998
2014
|
return m && u++, m;
|
|
1999
2015
|
}
|
|
2000
|
-
if (
|
|
2016
|
+
if (h() !== 1886610036)
|
|
2001
2017
|
throw new Error("Format Error: Invalid Magic Number");
|
|
2002
2018
|
if (g() !== 255)
|
|
2003
2019
|
throw new Error(
|
|
2004
2020
|
"Format Error: Magic Number must be followed by 0xff separator"
|
|
2005
2021
|
);
|
|
2006
2022
|
const d = [], E = {};
|
|
2007
|
-
for (; !
|
|
2023
|
+
for (; !p(); ) {
|
|
2008
2024
|
const m = y(), k = m.key.toString("hex");
|
|
2009
2025
|
if (E[k])
|
|
2010
2026
|
throw new Error(
|
|
@@ -2017,35 +2033,35 @@ function Xs() {
|
|
|
2017
2033
|
);
|
|
2018
2034
|
if (b.length !== 1)
|
|
2019
2035
|
throw new Error("Format Error: Only one UNSIGNED_TX allowed");
|
|
2020
|
-
const S = a(b[0].value), { inputCount: w, outputCount: _ } = S.getInputOutputCounts(), I = [],
|
|
2036
|
+
const S = a(b[0].value), { inputCount: w, outputCount: _ } = S.getInputOutputCounts(), I = [], P = [];
|
|
2021
2037
|
for (const m of e.range(w)) {
|
|
2022
|
-
const k = {},
|
|
2023
|
-
for (; !
|
|
2038
|
+
const k = {}, U = [];
|
|
2039
|
+
for (; !p(); ) {
|
|
2024
2040
|
const B = y(), te = B.key.toString("hex");
|
|
2025
2041
|
if (k[te])
|
|
2026
2042
|
throw new Error(
|
|
2027
2043
|
"Format Error: Keys must be unique for each input: input index " + m + " key " + te
|
|
2028
2044
|
);
|
|
2029
|
-
k[te] = 1,
|
|
2045
|
+
k[te] = 1, U.push(B);
|
|
2030
2046
|
}
|
|
2031
|
-
I.push(
|
|
2047
|
+
I.push(U);
|
|
2032
2048
|
}
|
|
2033
2049
|
for (const m of e.range(_)) {
|
|
2034
|
-
const k = {},
|
|
2035
|
-
for (; !
|
|
2050
|
+
const k = {}, U = [];
|
|
2051
|
+
for (; !p(); ) {
|
|
2036
2052
|
const B = y(), te = B.key.toString("hex");
|
|
2037
2053
|
if (k[te])
|
|
2038
2054
|
throw new Error(
|
|
2039
2055
|
"Format Error: Keys must be unique for each output: output index " + m + " key " + te
|
|
2040
2056
|
);
|
|
2041
|
-
k[te] = 1,
|
|
2057
|
+
k[te] = 1, U.push(B);
|
|
2042
2058
|
}
|
|
2043
|
-
|
|
2059
|
+
P.push(U);
|
|
2044
2060
|
}
|
|
2045
2061
|
return o(S, {
|
|
2046
2062
|
globalMapKeyVals: d,
|
|
2047
2063
|
inputKeyVals: I,
|
|
2048
|
-
outputKeyVals:
|
|
2064
|
+
outputKeyVals: P
|
|
2049
2065
|
});
|
|
2050
2066
|
}
|
|
2051
2067
|
oe.psbtFromBuffer = c;
|
|
@@ -2057,7 +2073,7 @@ function Xs() {
|
|
|
2057
2073
|
}
|
|
2058
2074
|
oe.checkKeyBuffer = s;
|
|
2059
2075
|
function o(i, { globalMapKeyVals: a, inputKeyVals: u, outputKeyVals: f }) {
|
|
2060
|
-
const
|
|
2076
|
+
const h = {
|
|
2061
2077
|
unsignedTx: i
|
|
2062
2078
|
};
|
|
2063
2079
|
let g = 0;
|
|
@@ -2073,12 +2089,12 @@ function Xs() {
|
|
|
2073
2089
|
g++;
|
|
2074
2090
|
break;
|
|
2075
2091
|
case r.GlobalTypes.GLOBAL_XPUB:
|
|
2076
|
-
|
|
2092
|
+
h.globalXpub === void 0 && (h.globalXpub = []), h.globalXpub.push(t.globals.globalXpub.decode(b));
|
|
2077
2093
|
break;
|
|
2078
2094
|
default:
|
|
2079
|
-
|
|
2095
|
+
h.unknownKeyVals || (h.unknownKeyVals = []), h.unknownKeyVals.push(b);
|
|
2080
2096
|
}
|
|
2081
|
-
const y = u.length,
|
|
2097
|
+
const y = u.length, p = f.length, d = [], E = [];
|
|
2082
2098
|
for (const b of e.range(y)) {
|
|
2083
2099
|
const S = {};
|
|
2084
2100
|
for (const w of u[b])
|
|
@@ -2198,7 +2214,7 @@ function Xs() {
|
|
|
2198
2214
|
}
|
|
2199
2215
|
d.push(S);
|
|
2200
2216
|
}
|
|
2201
|
-
for (const b of e.range(
|
|
2217
|
+
for (const b of e.range(p)) {
|
|
2202
2218
|
const S = {};
|
|
2203
2219
|
for (const w of f[b])
|
|
2204
2220
|
switch (t.outputs.checkPubkey(w), w.key[0]) {
|
|
@@ -2249,41 +2265,41 @@ function Xs() {
|
|
|
2249
2265
|
}
|
|
2250
2266
|
E.push(S);
|
|
2251
2267
|
}
|
|
2252
|
-
return { globalMap:
|
|
2268
|
+
return { globalMap: h, inputs: d, outputs: E };
|
|
2253
2269
|
}
|
|
2254
2270
|
return oe.psbtFromKeyVals = o, oe;
|
|
2255
2271
|
}
|
|
2256
|
-
var he = {},
|
|
2257
|
-
function
|
|
2258
|
-
if (
|
|
2259
|
-
|
|
2260
|
-
const t =
|
|
2272
|
+
var he = {}, hn;
|
|
2273
|
+
function qs() {
|
|
2274
|
+
if (hn) return he;
|
|
2275
|
+
hn = 1, Object.defineProperty(he, "__esModule", { value: !0 });
|
|
2276
|
+
const t = It(), e = mt();
|
|
2261
2277
|
function n({ globalMap: o, inputs: i, outputs: a }) {
|
|
2262
|
-
const { globalKeyVals: u, inputKeyVals: f, outputKeyVals:
|
|
2278
|
+
const { globalKeyVals: u, inputKeyVals: f, outputKeyVals: h } = s({
|
|
2263
2279
|
globalMap: o,
|
|
2264
2280
|
inputs: i,
|
|
2265
2281
|
outputs: a
|
|
2266
|
-
}), g = e.keyValsToBuffer(u), y = (b) => b.length === 0 ? [l.from([0])] : b.map(e.keyValsToBuffer),
|
|
2282
|
+
}), g = e.keyValsToBuffer(u), y = (b) => b.length === 0 ? [l.from([0])] : b.map(e.keyValsToBuffer), p = y(f), d = y(h), E = l.allocUnsafe(5);
|
|
2267
2283
|
return E.writeUIntBE(482972169471, 0, 5), l.concat(
|
|
2268
|
-
[E, g].concat(
|
|
2284
|
+
[E, g].concat(p, d)
|
|
2269
2285
|
);
|
|
2270
2286
|
}
|
|
2271
2287
|
he.psbtToBuffer = n;
|
|
2272
2288
|
const r = (o, i) => o.key.compare(i.key);
|
|
2273
2289
|
function c(o, i) {
|
|
2274
|
-
const a = /* @__PURE__ */ new Set(), u = Object.entries(o).reduce((
|
|
2275
|
-
if (g === "unknownKeyVals") return
|
|
2276
|
-
const
|
|
2277
|
-
if (
|
|
2290
|
+
const a = /* @__PURE__ */ new Set(), u = Object.entries(o).reduce((h, [g, y]) => {
|
|
2291
|
+
if (g === "unknownKeyVals") return h;
|
|
2292
|
+
const p = i[g];
|
|
2293
|
+
if (p === void 0) return h;
|
|
2278
2294
|
const d = (Array.isArray(y) ? y : [y]).map(
|
|
2279
|
-
|
|
2295
|
+
p.encode
|
|
2280
2296
|
);
|
|
2281
2297
|
return d.map((b) => b.key.toString("hex")).forEach((b) => {
|
|
2282
2298
|
if (a.has(b))
|
|
2283
2299
|
throw new Error("Serialize Error: Duplicate key: " + b);
|
|
2284
2300
|
a.add(b);
|
|
2285
|
-
}),
|
|
2286
|
-
}, []), f = o.unknownKeyVals ? o.unknownKeyVals.filter((
|
|
2301
|
+
}), h.concat(d);
|
|
2302
|
+
}, []), f = o.unknownKeyVals ? o.unknownKeyVals.filter((h) => !a.has(h.key.toString("hex"))) : [];
|
|
2287
2303
|
return u.concat(f).sort(r);
|
|
2288
2304
|
}
|
|
2289
2305
|
function s({ globalMap: o, inputs: i, outputs: a }) {
|
|
@@ -2295,30 +2311,30 @@ function Vs() {
|
|
|
2295
2311
|
}
|
|
2296
2312
|
return he.psbtToKeyVals = s, he;
|
|
2297
2313
|
}
|
|
2298
|
-
var
|
|
2299
|
-
function
|
|
2300
|
-
return
|
|
2314
|
+
var pn;
|
|
2315
|
+
function rr() {
|
|
2316
|
+
return pn || (pn = 1, (function(t) {
|
|
2301
2317
|
function e(n) {
|
|
2302
2318
|
for (var r in n) t.hasOwnProperty(r) || (t[r] = n[r]);
|
|
2303
2319
|
}
|
|
2304
|
-
Object.defineProperty(t, "__esModule", { value: !0 }), e(
|
|
2305
|
-
})(
|
|
2320
|
+
Object.defineProperty(t, "__esModule", { value: !0 }), e(Ds()), e(qs());
|
|
2321
|
+
})(st)), st;
|
|
2306
2322
|
}
|
|
2307
2323
|
var ln;
|
|
2308
|
-
function
|
|
2309
|
-
if (ln) return
|
|
2310
|
-
ln = 1, Object.defineProperty(
|
|
2311
|
-
const t =
|
|
2324
|
+
function Vs() {
|
|
2325
|
+
if (ln) return xe;
|
|
2326
|
+
ln = 1, Object.defineProperty(xe, "__esModule", { value: !0 });
|
|
2327
|
+
const t = rr();
|
|
2312
2328
|
function e(s) {
|
|
2313
2329
|
const o = s[0], i = t.psbtToKeyVals(o), a = s.slice(1);
|
|
2314
2330
|
if (a.length === 0) throw new Error("Combine: Nothing to combine");
|
|
2315
2331
|
const u = r(o);
|
|
2316
2332
|
if (u === void 0)
|
|
2317
2333
|
throw new Error("Combine: Self missing transaction");
|
|
2318
|
-
const f = c(i.globalKeyVals),
|
|
2334
|
+
const f = c(i.globalKeyVals), h = i.inputKeyVals.map(c), g = i.outputKeyVals.map(c);
|
|
2319
2335
|
for (const y of a) {
|
|
2320
|
-
const
|
|
2321
|
-
if (
|
|
2336
|
+
const p = r(y);
|
|
2337
|
+
if (p === void 0 || !p.toBuffer().equals(u.toBuffer()))
|
|
2322
2338
|
throw new Error(
|
|
2323
2339
|
"Combine: One of the Psbts does not have the same transaction."
|
|
2324
2340
|
);
|
|
@@ -2332,7 +2348,7 @@ function js() {
|
|
|
2332
2348
|
), d.inputKeyVals.map(c).forEach(
|
|
2333
2349
|
(w, _) => w.forEach(
|
|
2334
2350
|
n(
|
|
2335
|
-
|
|
2351
|
+
h[_],
|
|
2336
2352
|
i.inputKeyVals[_],
|
|
2337
2353
|
d.inputKeyVals[_]
|
|
2338
2354
|
)
|
|
@@ -2353,7 +2369,7 @@ function js() {
|
|
|
2353
2369
|
outputKeyVals: i.outputKeyVals
|
|
2354
2370
|
});
|
|
2355
2371
|
}
|
|
2356
|
-
|
|
2372
|
+
xe.combine = e;
|
|
2357
2373
|
function n(s, o, i) {
|
|
2358
2374
|
return (a) => {
|
|
2359
2375
|
if (s.has(a)) return;
|
|
@@ -2373,45 +2389,45 @@ function js() {
|
|
|
2373
2389
|
o.add(a);
|
|
2374
2390
|
}), o;
|
|
2375
2391
|
}
|
|
2376
|
-
return
|
|
2392
|
+
return xe;
|
|
2377
2393
|
}
|
|
2378
|
-
var
|
|
2379
|
-
function
|
|
2394
|
+
var it = {}, dn;
|
|
2395
|
+
function sr() {
|
|
2380
2396
|
return dn || (dn = 1, (function(t) {
|
|
2381
2397
|
Object.defineProperty(t, "__esModule", { value: !0 });
|
|
2382
|
-
const e =
|
|
2383
|
-
function n(y,
|
|
2384
|
-
const d = y[
|
|
2385
|
-
if (d === void 0) throw new Error(`No input #${
|
|
2398
|
+
const e = It();
|
|
2399
|
+
function n(y, p) {
|
|
2400
|
+
const d = y[p];
|
|
2401
|
+
if (d === void 0) throw new Error(`No input #${p}`);
|
|
2386
2402
|
return d;
|
|
2387
2403
|
}
|
|
2388
2404
|
t.checkForInput = n;
|
|
2389
|
-
function r(y,
|
|
2390
|
-
const d = y[
|
|
2391
|
-
if (d === void 0) throw new Error(`No output #${
|
|
2405
|
+
function r(y, p) {
|
|
2406
|
+
const d = y[p];
|
|
2407
|
+
if (d === void 0) throw new Error(`No output #${p}`);
|
|
2392
2408
|
return d;
|
|
2393
2409
|
}
|
|
2394
2410
|
t.checkForOutput = r;
|
|
2395
|
-
function c(y,
|
|
2411
|
+
function c(y, p, d) {
|
|
2396
2412
|
if (y.key[0] < d)
|
|
2397
2413
|
throw new Error(
|
|
2398
2414
|
"Use the method for your specific key instead of addUnknownKeyVal*"
|
|
2399
2415
|
);
|
|
2400
|
-
if (
|
|
2416
|
+
if (p && p.filter((E) => E.key.equals(y.key)).length !== 0)
|
|
2401
2417
|
throw new Error(`Duplicate Key: ${y.key.toString("hex")}`);
|
|
2402
2418
|
}
|
|
2403
2419
|
t.checkHasKey = c;
|
|
2404
2420
|
function s(y) {
|
|
2405
|
-
let
|
|
2421
|
+
let p = 0;
|
|
2406
2422
|
return Object.keys(y).forEach((d) => {
|
|
2407
|
-
Number(isNaN(Number(d))) &&
|
|
2408
|
-
}),
|
|
2423
|
+
Number(isNaN(Number(d))) && p++;
|
|
2424
|
+
}), p;
|
|
2409
2425
|
}
|
|
2410
2426
|
t.getEnumLength = s;
|
|
2411
|
-
function o(y,
|
|
2427
|
+
function o(y, p) {
|
|
2412
2428
|
let d = !1;
|
|
2413
|
-
if (
|
|
2414
|
-
const E = !!
|
|
2429
|
+
if (p.nonWitnessUtxo || p.witnessUtxo) {
|
|
2430
|
+
const E = !!p.redeemScript, b = !!p.witnessScript, S = !E || !!p.finalScriptSig, w = !b || !!p.finalScriptWitness, _ = !!p.finalScriptSig || !!p.finalScriptWitness;
|
|
2415
2431
|
d = S && w && _;
|
|
2416
2432
|
}
|
|
2417
2433
|
if (d === !1)
|
|
@@ -2420,26 +2436,26 @@ function ar() {
|
|
|
2420
2436
|
);
|
|
2421
2437
|
}
|
|
2422
2438
|
t.inputCheckUncleanFinalized = o;
|
|
2423
|
-
function i(y,
|
|
2439
|
+
function i(y, p, d, E) {
|
|
2424
2440
|
throw new Error(
|
|
2425
|
-
`Data for ${y} key ${
|
|
2441
|
+
`Data for ${y} key ${p} is incorrect: Expected ${d} and got ${JSON.stringify(E)}`
|
|
2426
2442
|
);
|
|
2427
2443
|
}
|
|
2428
2444
|
function a(y) {
|
|
2429
|
-
return (
|
|
2430
|
-
for (const E of Object.keys(
|
|
2431
|
-
const b =
|
|
2445
|
+
return (p, d) => {
|
|
2446
|
+
for (const E of Object.keys(p)) {
|
|
2447
|
+
const b = p[E], { canAdd: S, canAddToArray: w, check: _, expected: I } = (
|
|
2432
2448
|
// @ts-ignore
|
|
2433
2449
|
e[y + "s"][E] || {}
|
|
2434
|
-
),
|
|
2450
|
+
), P = !!w;
|
|
2435
2451
|
if (_)
|
|
2436
|
-
if (
|
|
2452
|
+
if (P) {
|
|
2437
2453
|
if (!Array.isArray(b) || // @ts-ignore
|
|
2438
2454
|
d[E] && !Array.isArray(d[E]))
|
|
2439
2455
|
throw new Error(`Key type ${E} must be an array`);
|
|
2440
2456
|
b.every(_) || i(y, E, I, b);
|
|
2441
2457
|
const m = d[E] || [], k = /* @__PURE__ */ new Set();
|
|
2442
|
-
if (!b.every((
|
|
2458
|
+
if (!b.every((U) => w(m, U, k)))
|
|
2443
2459
|
throw new Error("Can not add duplicate data to array");
|
|
2444
2460
|
d[E] = m.concat(b);
|
|
2445
2461
|
} else {
|
|
@@ -2451,35 +2467,35 @@ function ar() {
|
|
|
2451
2467
|
};
|
|
2452
2468
|
}
|
|
2453
2469
|
t.updateGlobal = a("global"), t.updateInput = a("input"), t.updateOutput = a("output");
|
|
2454
|
-
function u(y,
|
|
2470
|
+
function u(y, p) {
|
|
2455
2471
|
const d = y.length - 1, E = n(y, d);
|
|
2456
|
-
t.updateInput(
|
|
2472
|
+
t.updateInput(p, E);
|
|
2457
2473
|
}
|
|
2458
2474
|
t.addInputAttributes = u;
|
|
2459
|
-
function f(y,
|
|
2475
|
+
function f(y, p) {
|
|
2460
2476
|
const d = y.length - 1, E = r(y, d);
|
|
2461
|
-
t.updateOutput(
|
|
2477
|
+
t.updateOutput(p, E);
|
|
2462
2478
|
}
|
|
2463
2479
|
t.addOutputAttributes = f;
|
|
2464
|
-
function
|
|
2465
|
-
if (!l.isBuffer(
|
|
2480
|
+
function h(y, p) {
|
|
2481
|
+
if (!l.isBuffer(p) || p.length < 4)
|
|
2466
2482
|
throw new Error("Set Version: Invalid Transaction");
|
|
2467
|
-
return
|
|
2483
|
+
return p.writeUInt32LE(y, 0), p;
|
|
2468
2484
|
}
|
|
2469
|
-
t.defaultVersionSetter =
|
|
2470
|
-
function g(y,
|
|
2471
|
-
if (!l.isBuffer(
|
|
2485
|
+
t.defaultVersionSetter = h;
|
|
2486
|
+
function g(y, p) {
|
|
2487
|
+
if (!l.isBuffer(p) || p.length < 4)
|
|
2472
2488
|
throw new Error("Set Locktime: Invalid Transaction");
|
|
2473
|
-
return
|
|
2489
|
+
return p.writeUInt32LE(y, p.length - 4), p;
|
|
2474
2490
|
}
|
|
2475
2491
|
t.defaultLocktimeSetter = g;
|
|
2476
|
-
})(
|
|
2492
|
+
})(it)), it;
|
|
2477
2493
|
}
|
|
2478
2494
|
var gn;
|
|
2479
|
-
function
|
|
2480
|
-
if (gn) return
|
|
2481
|
-
gn = 1, Object.defineProperty(
|
|
2482
|
-
const t =
|
|
2495
|
+
function js() {
|
|
2496
|
+
if (gn) return Ae;
|
|
2497
|
+
gn = 1, Object.defineProperty(Ae, "__esModule", { value: !0 });
|
|
2498
|
+
const t = Vs(), e = rr(), n = A(), r = sr();
|
|
2483
2499
|
class c {
|
|
2484
2500
|
constructor(o) {
|
|
2485
2501
|
this.inputs = [], this.outputs = [], this.globalMap = {
|
|
@@ -2584,9 +2600,9 @@ function zs() {
|
|
|
2584
2600
|
return this.globalMap.unsignedTx.toBuffer();
|
|
2585
2601
|
}
|
|
2586
2602
|
}
|
|
2587
|
-
return
|
|
2603
|
+
return Ae.Psbt = c, Ae;
|
|
2588
2604
|
}
|
|
2589
|
-
var yn =
|
|
2605
|
+
var yn = js(), dt = fe(), x = sr();
|
|
2590
2606
|
function ee(t) {
|
|
2591
2607
|
return (e) => {
|
|
2592
2608
|
try {
|
|
@@ -2596,17 +2612,17 @@ function ee(t) {
|
|
|
2596
2612
|
}
|
|
2597
2613
|
};
|
|
2598
2614
|
}
|
|
2599
|
-
const
|
|
2615
|
+
const zs = ee(De), Ys = ee(Pn), $s = ee(we), $e = ee(Xe), Sn = ee(be), or = ee(Ee), vt = ee(Te), Xo = ee(On), Do = (t) => t.length === 4 && t[0] === 81 && // OP_1
|
|
2600
2616
|
t[1] === 2 && // push 2 bytes
|
|
2601
2617
|
t[2] === 78 && t[3] === 115;
|
|
2602
|
-
function
|
|
2618
|
+
function ye(t) {
|
|
2603
2619
|
let e = l.allocUnsafe(0);
|
|
2604
2620
|
function n(o) {
|
|
2605
2621
|
e = l.concat([e, l.from(o)]);
|
|
2606
2622
|
}
|
|
2607
2623
|
function r(o) {
|
|
2608
|
-
const i = e.length, a =
|
|
2609
|
-
e = l.concat([e, l.allocUnsafe(a)]),
|
|
2624
|
+
const i = e.length, a = dt.encodingLength(o);
|
|
2625
|
+
e = l.concat([e, l.allocUnsafe(a)]), dt.encode(o, e, i);
|
|
2610
2626
|
}
|
|
2611
2627
|
function c(o) {
|
|
2612
2628
|
r(o.length), n(o);
|
|
@@ -2616,23 +2632,23 @@ function Se(t) {
|
|
|
2616
2632
|
}
|
|
2617
2633
|
return s(t), e;
|
|
2618
2634
|
}
|
|
2619
|
-
function
|
|
2620
|
-
const n =
|
|
2635
|
+
function ir(t, e) {
|
|
2636
|
+
const n = ue(e);
|
|
2621
2637
|
if (n === null) throw new Error("Unknown script error");
|
|
2622
|
-
const r =
|
|
2638
|
+
const r = et(t), c = ge(t), s = _s(t), o = s?.hybrid ? et(s.hybrid) : void 0, i = s?.uncompressed ? et(s.uncompressed) : void 0;
|
|
2623
2639
|
return n.findIndex((a) => {
|
|
2624
2640
|
if (typeof a == "number") return !1;
|
|
2625
|
-
if (
|
|
2641
|
+
if (ke(a, t) || ke(a, c) || a.equals(r) || s && (ke(a, s.uncompressed) || ke(a, s.hybrid) || o && a.equals(o) || i && a.equals(i)))
|
|
2626
2642
|
return !0;
|
|
2627
2643
|
});
|
|
2628
2644
|
}
|
|
2629
|
-
function
|
|
2630
|
-
return
|
|
2645
|
+
function Ze(t, e) {
|
|
2646
|
+
return ir(t, e) !== -1;
|
|
2631
2647
|
}
|
|
2632
|
-
function
|
|
2633
|
-
return
|
|
2648
|
+
function Zs(t, e) {
|
|
2649
|
+
return Js(t).some((r) => cr(r, de.decode, e));
|
|
2634
2650
|
}
|
|
2635
|
-
function
|
|
2651
|
+
function cr(t, e, n) {
|
|
2636
2652
|
const { hashType: r } = e(t), c = [];
|
|
2637
2653
|
switch (r & v.SIGHASH_ANYONECANPAY && c.push("addInput"), r & 31) {
|
|
2638
2654
|
case v.SIGHASH_ALL:
|
|
@@ -2644,210 +2660,210 @@ function pr(t, e, n) {
|
|
|
2644
2660
|
}
|
|
2645
2661
|
return c.indexOf(n) === -1;
|
|
2646
2662
|
}
|
|
2647
|
-
function
|
|
2663
|
+
function Js(t) {
|
|
2648
2664
|
const { partialSig: e } = t;
|
|
2649
2665
|
let n;
|
|
2650
2666
|
if (!e || e.length === 0) {
|
|
2651
2667
|
if (!t.finalScriptSig && !t.finalScriptWitness) return [];
|
|
2652
|
-
n =
|
|
2668
|
+
n = Qs(t);
|
|
2653
2669
|
} else
|
|
2654
2670
|
n = e;
|
|
2655
2671
|
return n.map((r) => r.signature);
|
|
2656
2672
|
}
|
|
2657
|
-
function
|
|
2658
|
-
const e = t.finalScriptSig ?
|
|
2659
|
-
return e.concat(n).filter((r) => l.isBuffer(r) &&
|
|
2673
|
+
function Qs(t) {
|
|
2674
|
+
const e = t.finalScriptSig ? ue(t.finalScriptSig) || [] : [], n = t.finalScriptWitness ? ue(t.finalScriptWitness) || [] : [];
|
|
2675
|
+
return e.concat(n).filter((r) => l.isBuffer(r) && Un(r)).map((r) => ({ signature: r }));
|
|
2660
2676
|
}
|
|
2661
2677
|
function wn(t, e, n) {
|
|
2662
|
-
const r =
|
|
2678
|
+
const r = lo(e, t, n);
|
|
2663
2679
|
try {
|
|
2664
2680
|
const s = ho(e, r).concat(r.script).concat(r.controlBlock);
|
|
2665
|
-
return { finalScriptWitness:
|
|
2681
|
+
return { finalScriptWitness: ye(s) };
|
|
2666
2682
|
} catch (c) {
|
|
2667
2683
|
throw new Error(`Can not finalize taproot input #${t}: ${c}`);
|
|
2668
2684
|
}
|
|
2669
2685
|
}
|
|
2670
|
-
function
|
|
2686
|
+
function Re(t, e) {
|
|
2671
2687
|
const n = e ? l.from([e]) : l.from([]);
|
|
2672
2688
|
return l.concat([t, n]);
|
|
2673
2689
|
}
|
|
2674
2690
|
function N(t) {
|
|
2675
|
-
return t && !!(t.tapInternalKey || t.tapMerkleRoot || t.tapLeafScript && t.tapLeafScript.length || t.tapBip32Derivation && t.tapBip32Derivation.length || t.witnessUtxo &&
|
|
2691
|
+
return t && !!(t.tapInternalKey || t.tapMerkleRoot || t.tapLeafScript && t.tapLeafScript.length || t.tapBip32Derivation && t.tapBip32Derivation.length || t.witnessUtxo && vt(t.witnessUtxo.script));
|
|
2676
2692
|
}
|
|
2677
|
-
function
|
|
2678
|
-
return t && !!(t.tapInternalKey || t.tapTree || t.tapBip32Derivation && t.tapBip32Derivation.length || e &&
|
|
2693
|
+
function ct(t, e) {
|
|
2694
|
+
return t && !!(t.tapInternalKey || t.tapTree || t.tapBip32Derivation && t.tapBip32Derivation.length || e && vt(e));
|
|
2679
2695
|
}
|
|
2680
2696
|
function En(t, e, n) {
|
|
2681
|
-
|
|
2697
|
+
ao(t, e, n), fo(t, e, n);
|
|
2682
2698
|
}
|
|
2683
2699
|
function bn(t, e, n) {
|
|
2684
|
-
|
|
2700
|
+
uo(t, e, n), eo(t, e);
|
|
2685
2701
|
}
|
|
2686
|
-
function
|
|
2702
|
+
function eo(t, e) {
|
|
2687
2703
|
if (!e.tapTree && !e.tapInternalKey) return;
|
|
2688
2704
|
const n = e.tapInternalKey || t.tapInternalKey, r = e.tapTree || t.tapTree;
|
|
2689
2705
|
if (n) {
|
|
2690
|
-
const c = t.script, s =
|
|
2706
|
+
const c = t.script, s = to(n, r);
|
|
2691
2707
|
if (c && !c.equals(s))
|
|
2692
2708
|
throw new Error("Error adding output. Script or address missmatch.");
|
|
2693
2709
|
}
|
|
2694
2710
|
}
|
|
2695
|
-
function
|
|
2696
|
-
const n = e &&
|
|
2711
|
+
function to(t, e) {
|
|
2712
|
+
const n = e && no(e.leaves), { output: r } = Te({
|
|
2697
2713
|
internalPubkey: t,
|
|
2698
2714
|
scriptTree: n
|
|
2699
2715
|
});
|
|
2700
2716
|
if (!r) throw new Error("Failed to generate taproot script pubkey");
|
|
2701
2717
|
return r;
|
|
2702
2718
|
}
|
|
2703
|
-
function
|
|
2704
|
-
const n = e.tapInternalKey, r = n &&
|
|
2719
|
+
function qo(t, e) {
|
|
2720
|
+
const n = e.tapInternalKey, r = n && Tr(n, e.tapMerkleRoot);
|
|
2705
2721
|
if (!r)
|
|
2706
2722
|
throw new Error(
|
|
2707
2723
|
`Cannot tweak tap internal key for input #${t}. Public key: ${n && n.toString("hex")}`
|
|
2708
2724
|
);
|
|
2709
2725
|
return r.x;
|
|
2710
2726
|
}
|
|
2711
|
-
function
|
|
2712
|
-
if (!
|
|
2727
|
+
function Vo(t) {
|
|
2728
|
+
if (!Pr(t))
|
|
2713
2729
|
throw new Error("Cannot convert taptree to tapleaf list. Expecting a tapree structure.");
|
|
2714
|
-
return
|
|
2730
|
+
return gt(t);
|
|
2715
2731
|
}
|
|
2716
|
-
function
|
|
2732
|
+
function no(t = []) {
|
|
2717
2733
|
return t.length === 1 && t[0].depth === 0 ? {
|
|
2718
2734
|
output: t[0].script,
|
|
2719
2735
|
version: t[0].leafVersion
|
|
2720
|
-
} :
|
|
2736
|
+
} : co(t);
|
|
2721
2737
|
}
|
|
2722
|
-
function
|
|
2723
|
-
return
|
|
2738
|
+
function ro(t, e) {
|
|
2739
|
+
return oo(t).some((r) => cr(r, so, e));
|
|
2724
2740
|
}
|
|
2725
|
-
function
|
|
2741
|
+
function so(t) {
|
|
2726
2742
|
return {
|
|
2727
2743
|
signature: t.subarray(0, 64),
|
|
2728
2744
|
hashType: t.subarray(64)[0] || v.SIGHASH_DEFAULT
|
|
2729
2745
|
};
|
|
2730
2746
|
}
|
|
2731
|
-
function
|
|
2747
|
+
function oo(t) {
|
|
2732
2748
|
const e = [];
|
|
2733
2749
|
if (t.tapKeySig && e.push(t.tapKeySig), t.tapScriptSig && e.push(...t.tapScriptSig.map((n) => n.signature)), !e.length) {
|
|
2734
|
-
const n =
|
|
2750
|
+
const n = io(t.finalScriptWitness);
|
|
2735
2751
|
n && e.push(n);
|
|
2736
2752
|
}
|
|
2737
2753
|
return e;
|
|
2738
2754
|
}
|
|
2739
|
-
function
|
|
2755
|
+
function io(t) {
|
|
2740
2756
|
if (!t) return;
|
|
2741
2757
|
const e = t.subarray(2);
|
|
2742
2758
|
if (e.length === 64 || e.length === 65) return e;
|
|
2743
2759
|
}
|
|
2744
|
-
function
|
|
2760
|
+
function gt(t, e = [], n = 0) {
|
|
2745
2761
|
if (n > Nn) throw new Error("Max taptree depth exceeded.");
|
|
2746
|
-
return t ?
|
|
2762
|
+
return t ? Hn(t) ? (e.push({
|
|
2747
2763
|
depth: n,
|
|
2748
|
-
leafVersion: t.version ||
|
|
2764
|
+
leafVersion: t.version || _r,
|
|
2749
2765
|
script: t.output
|
|
2750
|
-
}), e) : (t[0] &&
|
|
2766
|
+
}), e) : (t[0] && gt(t[0], e, n + 1), t[1] && gt(t[1], e, n + 1), e) : [];
|
|
2751
2767
|
}
|
|
2752
|
-
function
|
|
2768
|
+
function co(t) {
|
|
2753
2769
|
let e;
|
|
2754
2770
|
for (const n of t)
|
|
2755
|
-
if (e =
|
|
2771
|
+
if (e = yt(n, e), !e) throw new Error("No room left to insert tapleaf in tree");
|
|
2756
2772
|
return e;
|
|
2757
2773
|
}
|
|
2758
|
-
function
|
|
2774
|
+
function yt(t, e, n = 0) {
|
|
2759
2775
|
if (n > Nn) throw new Error("Max taptree depth exceeded.");
|
|
2760
2776
|
if (t.depth === n)
|
|
2761
2777
|
return e ? void 0 : {
|
|
2762
2778
|
output: t.script,
|
|
2763
2779
|
version: t.leafVersion
|
|
2764
2780
|
};
|
|
2765
|
-
if (
|
|
2766
|
-
const r =
|
|
2781
|
+
if (Hn(e)) return;
|
|
2782
|
+
const r = yt(t, e && e[0], n + 1);
|
|
2767
2783
|
if (r) return [r, e && e[1]];
|
|
2768
|
-
const c =
|
|
2784
|
+
const c = yt(t, e && e[1], n + 1);
|
|
2769
2785
|
if (c) return [e && e[0], c];
|
|
2770
2786
|
}
|
|
2771
|
-
function
|
|
2772
|
-
const r = N(t) &&
|
|
2787
|
+
function ao(t, e, n) {
|
|
2788
|
+
const r = N(t) && ae(e), c = ae(t) && N(e), s = t === e && N(e) && ae(e);
|
|
2773
2789
|
if (r || c || s)
|
|
2774
2790
|
throw new Error(
|
|
2775
2791
|
`Invalid arguments for Psbt.${n}. Cannot use both taproot and non-taproot fields.`
|
|
2776
2792
|
);
|
|
2777
2793
|
}
|
|
2778
|
-
function
|
|
2779
|
-
const r =
|
|
2794
|
+
function uo(t, e, n) {
|
|
2795
|
+
const r = ct(t) && ae(e), c = ae(t) && ct(e), s = t === e && ct(e) && ae(e);
|
|
2780
2796
|
if (r || c || s)
|
|
2781
2797
|
throw new Error(
|
|
2782
2798
|
`Invalid arguments for Psbt.${n}. Cannot use both taproot and non-taproot fields.`
|
|
2783
2799
|
);
|
|
2784
2800
|
}
|
|
2785
|
-
function
|
|
2801
|
+
function fo(t, e, n) {
|
|
2786
2802
|
if (e.tapMerkleRoot) {
|
|
2787
2803
|
const r = (e.tapLeafScript || []).every(
|
|
2788
|
-
(s) =>
|
|
2804
|
+
(s) => at(s, e.tapMerkleRoot)
|
|
2789
2805
|
), c = (t.tapLeafScript || []).every(
|
|
2790
|
-
(s) =>
|
|
2806
|
+
(s) => at(s, e.tapMerkleRoot)
|
|
2791
2807
|
);
|
|
2792
2808
|
if (!r || !c)
|
|
2793
2809
|
throw new Error(`Invalid arguments for Psbt.${n}. Tapleaf not part of taptree.`);
|
|
2794
2810
|
} else if (t.tapMerkleRoot && !(e.tapLeafScript || []).every(
|
|
2795
|
-
(c) =>
|
|
2811
|
+
(c) => at(c, t.tapMerkleRoot)
|
|
2796
2812
|
))
|
|
2797
2813
|
throw new Error(`Invalid arguments for Psbt.${n}. Tapleaf not part of taptree.`);
|
|
2798
2814
|
}
|
|
2799
|
-
function
|
|
2815
|
+
function at(t, e) {
|
|
2800
2816
|
if (!e) return !0;
|
|
2801
|
-
const n =
|
|
2817
|
+
const n = qe({
|
|
2802
2818
|
output: t.script,
|
|
2803
2819
|
version: t.leafVersion
|
|
2804
2820
|
});
|
|
2805
|
-
return
|
|
2821
|
+
return mr(t.controlBlock, n).equals(e);
|
|
2806
2822
|
}
|
|
2807
2823
|
function ho(t, e) {
|
|
2808
|
-
const n =
|
|
2824
|
+
const n = qe({
|
|
2809
2825
|
output: e.script,
|
|
2810
2826
|
version: e.leafVersion
|
|
2811
2827
|
});
|
|
2812
|
-
return (t.tapScriptSig || []).filter((r) => r.leafHash.equals(n)).map((r) =>
|
|
2828
|
+
return (t.tapScriptSig || []).filter((r) => r.leafHash.equals(n)).map((r) => po(e.script, r)).sort((r, c) => c.positionInScript - r.positionInScript).map((r) => r.signature);
|
|
2813
2829
|
}
|
|
2814
|
-
function
|
|
2830
|
+
function po(t, e) {
|
|
2815
2831
|
return Object.assign(
|
|
2816
2832
|
{
|
|
2817
|
-
positionInScript:
|
|
2833
|
+
positionInScript: ir(e.pubkey, t)
|
|
2818
2834
|
},
|
|
2819
2835
|
e
|
|
2820
2836
|
);
|
|
2821
2837
|
}
|
|
2822
|
-
function
|
|
2838
|
+
function lo(t, e, n) {
|
|
2823
2839
|
const { tapScriptSig: r } = t;
|
|
2824
2840
|
if (!r || !r.length)
|
|
2825
2841
|
throw new Error(
|
|
2826
2842
|
`Can not finalize taproot input #${e}. No tapleaf script signature provided.`
|
|
2827
2843
|
);
|
|
2828
|
-
const c = (t.tapLeafScript || []).sort((s, o) => s.controlBlock.length - o.controlBlock.length).find((s) =>
|
|
2844
|
+
const c = (t.tapLeafScript || []).sort((s, o) => s.controlBlock.length - o.controlBlock.length).find((s) => go(s, r, n));
|
|
2829
2845
|
if (!c)
|
|
2830
2846
|
throw new Error(
|
|
2831
2847
|
`Can not finalize taproot input #${e}. Signature for tapleaf script not found.`
|
|
2832
2848
|
);
|
|
2833
2849
|
return c;
|
|
2834
2850
|
}
|
|
2835
|
-
function
|
|
2836
|
-
const r =
|
|
2851
|
+
function go(t, e, n) {
|
|
2852
|
+
const r = qe({
|
|
2837
2853
|
output: t.script,
|
|
2838
2854
|
version: t.leafVersion
|
|
2839
2855
|
});
|
|
2840
2856
|
return (!n || n.equals(r)) && e.find((s) => s.leafHash.equals(r)) !== void 0;
|
|
2841
2857
|
}
|
|
2842
|
-
function
|
|
2858
|
+
function ae(t) {
|
|
2843
2859
|
return t && !!(t.redeemScript || t.witnessScript || t.bip32Derivation && t.bip32Derivation.length);
|
|
2844
2860
|
}
|
|
2845
|
-
const Tn =
|
|
2861
|
+
const Tn = dt.decode, yo = {
|
|
2846
2862
|
/**
|
|
2847
2863
|
* A bitcoinjs Network object. This is only used if you pass an `address`
|
|
2848
2864
|
* parameter to addOutput. Otherwise it is not needed and can be left default.
|
|
2849
2865
|
*/
|
|
2850
|
-
network:
|
|
2866
|
+
network: Ve,
|
|
2851
2867
|
/**
|
|
2852
2868
|
* When extractTransaction is called, the fee rate is checked.
|
|
2853
2869
|
* THIS IS NOT TO BE RELIED ON.
|
|
@@ -2856,9 +2872,9 @@ const Tn = gt.decode, So = {
|
|
|
2856
2872
|
maximumFeeRate: 5e3
|
|
2857
2873
|
// satoshi per byte
|
|
2858
2874
|
};
|
|
2859
|
-
class
|
|
2860
|
-
constructor(e = {}, n = new yn.Psbt(new
|
|
2861
|
-
this.data = n, this.opts = Object.assign({},
|
|
2875
|
+
class St {
|
|
2876
|
+
constructor(e = {}, n = new yn.Psbt(new ar())) {
|
|
2877
|
+
this.data = n, this.opts = Object.assign({}, yo, e), this.__CACHE = {
|
|
2862
2878
|
__NON_WITNESS_UTXO_TX_CACHE: [],
|
|
2863
2879
|
__NON_WITNESS_UTXO_BUF_CACHE: [],
|
|
2864
2880
|
__TX_IN_CACHE: {},
|
|
@@ -2891,7 +2907,7 @@ class wt {
|
|
|
2891
2907
|
}
|
|
2892
2908
|
get txInputs() {
|
|
2893
2909
|
return this.__CACHE.__TX.ins.map((e) => ({
|
|
2894
|
-
hash:
|
|
2910
|
+
hash: At(e.hash),
|
|
2895
2911
|
index: e.index,
|
|
2896
2912
|
sequence: e.sequence
|
|
2897
2913
|
}));
|
|
@@ -2900,11 +2916,11 @@ class wt {
|
|
|
2900
2916
|
return this.__CACHE.__TX.outs.map((e) => {
|
|
2901
2917
|
let n;
|
|
2902
2918
|
try {
|
|
2903
|
-
n =
|
|
2919
|
+
n = er(e.script, this.opts.network);
|
|
2904
2920
|
} catch {
|
|
2905
2921
|
}
|
|
2906
2922
|
return {
|
|
2907
|
-
script:
|
|
2923
|
+
script: At(e.script),
|
|
2908
2924
|
value: e.value,
|
|
2909
2925
|
address: n
|
|
2910
2926
|
};
|
|
@@ -2919,21 +2935,21 @@ class wt {
|
|
|
2919
2935
|
return this.fromBuffer(r, n);
|
|
2920
2936
|
}
|
|
2921
2937
|
static fromBuffer(e, n = {}) {
|
|
2922
|
-
const r = yn.Psbt.fromBuffer(e,
|
|
2923
|
-
return
|
|
2938
|
+
const r = yn.Psbt.fromBuffer(e, So), c = new St(n, r);
|
|
2939
|
+
return _o(c.__CACHE.__TX, c.__CACHE), c;
|
|
2924
2940
|
}
|
|
2925
2941
|
combine(...e) {
|
|
2926
2942
|
return this.data.combine(...e.map((n) => n.data)), this;
|
|
2927
2943
|
}
|
|
2928
2944
|
clone() {
|
|
2929
2945
|
const e = JSON.parse(JSON.stringify(this.opts));
|
|
2930
|
-
return
|
|
2946
|
+
return St.fromBuffer(this.data.toBuffer(), e);
|
|
2931
2947
|
}
|
|
2932
2948
|
setMaximumFeeRate(e) {
|
|
2933
|
-
|
|
2949
|
+
Fe(e), this.opts.maximumFeeRate = e;
|
|
2934
2950
|
}
|
|
2935
2951
|
setVersion(e) {
|
|
2936
|
-
|
|
2952
|
+
Fe(e), pe(this.data.inputs, "setVersion");
|
|
2937
2953
|
const n = this.__CACHE;
|
|
2938
2954
|
return n.__TX.version = e, n.__EXTRACTED_TX = void 0, this;
|
|
2939
2955
|
}
|
|
@@ -2941,12 +2957,12 @@ class wt {
|
|
|
2941
2957
|
return this.setVersion(v.TRUC_VERSION);
|
|
2942
2958
|
}
|
|
2943
2959
|
setLocktime(e) {
|
|
2944
|
-
|
|
2960
|
+
Fe(e), pe(this.data.inputs, "setLocktime");
|
|
2945
2961
|
const n = this.__CACHE;
|
|
2946
2962
|
return n.__TX.locktime = e, n.__EXTRACTED_TX = void 0, this;
|
|
2947
2963
|
}
|
|
2948
2964
|
setInputSequence(e, n) {
|
|
2949
|
-
|
|
2965
|
+
Fe(n), pe(this.data.inputs, "setInputSequence");
|
|
2950
2966
|
const r = this.__CACHE;
|
|
2951
2967
|
if (r.__TX.ins.length <= e)
|
|
2952
2968
|
throw new Error("Input index too high");
|
|
@@ -2960,13 +2976,13 @@ class wt {
|
|
|
2960
2976
|
throw new Error(
|
|
2961
2977
|
"Invalid arguments for Psbt.addInput. Requires single object with at least [hash] and [index]"
|
|
2962
2978
|
);
|
|
2963
|
-
En(e, e, "addInput"), n &&
|
|
2979
|
+
En(e, e, "addInput"), n && pe(this.data.inputs, "addInput"), e.witnessScript && Ge(e.witnessScript);
|
|
2964
2980
|
const r = this.__CACHE;
|
|
2965
2981
|
this.data.addInput(e);
|
|
2966
2982
|
const c = r.__TX.ins[r.__TX.ins.length - 1];
|
|
2967
|
-
|
|
2983
|
+
hr(r, c);
|
|
2968
2984
|
const s = this.data.inputs.length - 1, o = this.data.inputs[s];
|
|
2969
|
-
return o.nonWitnessUtxo &&
|
|
2985
|
+
return o.nonWitnessUtxo && Et(this.__CACHE, o, s), r.__FEE = void 0, r.__FEE_RATE = void 0, r.__EXTRACTED_TX = void 0, this;
|
|
2970
2986
|
}
|
|
2971
2987
|
addOutputs(e) {
|
|
2972
2988
|
return e.forEach((n) => this.addOutput(n)), this;
|
|
@@ -2977,8 +2993,8 @@ class wt {
|
|
|
2977
2993
|
throw new Error(
|
|
2978
2994
|
"Invalid arguments for Psbt.addOutput. Requires single object with at least [script or address] and [value]"
|
|
2979
2995
|
);
|
|
2980
|
-
if (
|
|
2981
|
-
const { address: s } = e, { network: o } = this.opts, i =
|
|
2996
|
+
if (pe(this.data.inputs, "addOutput"), n) {
|
|
2997
|
+
const { address: s } = e, { network: o } = this.opts, i = tr(s, o);
|
|
2982
2998
|
e = Object.assign({}, e, { script: i });
|
|
2983
2999
|
}
|
|
2984
3000
|
bn(e, e, "addOutput");
|
|
@@ -2986,11 +3002,11 @@ class wt {
|
|
|
2986
3002
|
return this.data.addOutput(e), c.__FEE = void 0, c.__FEE_RATE = void 0, c.__EXTRACTED_TX = void 0, this;
|
|
2987
3003
|
}
|
|
2988
3004
|
extractTransaction(e, n) {
|
|
2989
|
-
if (n && (this.data.inputs = this.data.inputs.filter((s) => !s.partialSig)), !this.data.inputs.every(
|
|
3005
|
+
if (n && (this.data.inputs = this.data.inputs.filter((s) => !s.partialSig)), !this.data.inputs.every(ur)) throw new Error("Not finalized");
|
|
2990
3006
|
const r = this.__CACHE;
|
|
2991
|
-
if (e ||
|
|
3007
|
+
if (e || Eo(this, r, this.opts), r.__EXTRACTED_TX) return r.__EXTRACTED_TX;
|
|
2992
3008
|
const c = r.__TX.clone();
|
|
2993
|
-
return
|
|
3009
|
+
return Sr(this.data.inputs, c, r, !0, n), c;
|
|
2994
3010
|
}
|
|
2995
3011
|
getFeeRate(e = !1) {
|
|
2996
3012
|
return kn(
|
|
@@ -3005,7 +3021,7 @@ class wt {
|
|
|
3005
3021
|
return kn("__FEE", "fee", this.data.inputs, this.__CACHE, e);
|
|
3006
3022
|
}
|
|
3007
3023
|
finalizeAllInputs() {
|
|
3008
|
-
return x.checkForInput(this.data.inputs, 0),
|
|
3024
|
+
return x.checkForInput(this.data.inputs, 0), le(this.data.inputs.length).forEach((e) => this.finalizeInput(e)), this;
|
|
3009
3025
|
}
|
|
3010
3026
|
finalizeInput(e, n, r) {
|
|
3011
3027
|
const c = x.checkForInput(this.data.inputs, e);
|
|
@@ -3033,18 +3049,18 @@ class wt {
|
|
|
3033
3049
|
throw new Error(`Cannot finalize input #${e}. Not Taproot.`);
|
|
3034
3050
|
}
|
|
3035
3051
|
getInputType(e) {
|
|
3036
|
-
const n = x.checkForInput(this.data.inputs, e), r =
|
|
3052
|
+
const n = x.checkForInput(this.data.inputs, e), r = wr(e, n, this.__CACHE), c = Qe(
|
|
3037
3053
|
r,
|
|
3038
3054
|
e,
|
|
3039
3055
|
"input",
|
|
3040
|
-
n.redeemScript ||
|
|
3056
|
+
n.redeemScript || No(n.finalScriptSig),
|
|
3041
3057
|
n.witnessScript || Uo(n.finalScriptWitness)
|
|
3042
|
-
), s = c.type === "raw" ? "" : c.type + "-", o =
|
|
3058
|
+
), s = c.type === "raw" ? "" : c.type + "-", o = br(c.meaningfulScript);
|
|
3043
3059
|
return s + o;
|
|
3044
3060
|
}
|
|
3045
3061
|
inputHasPubkey(e, n) {
|
|
3046
3062
|
const r = x.checkForInput(this.data.inputs, e);
|
|
3047
|
-
return
|
|
3063
|
+
return Oo(n, r, e, this.__CACHE);
|
|
3048
3064
|
}
|
|
3049
3065
|
inputHasHDKey(e, n) {
|
|
3050
3066
|
const r = x.checkForInput(this.data.inputs, e), c = mn(n);
|
|
@@ -3052,14 +3068,14 @@ class wt {
|
|
|
3052
3068
|
}
|
|
3053
3069
|
outputHasPubkey(e, n) {
|
|
3054
3070
|
const r = x.checkForOutput(this.data.outputs, e);
|
|
3055
|
-
return
|
|
3071
|
+
return Po(n, r, e, this.__CACHE);
|
|
3056
3072
|
}
|
|
3057
3073
|
outputHasHDKey(e, n) {
|
|
3058
3074
|
const r = x.checkForOutput(this.data.outputs, e), c = mn(n);
|
|
3059
3075
|
return !!r.bip32Derivation && r.bip32Derivation.some(c);
|
|
3060
3076
|
}
|
|
3061
3077
|
validateSignaturesOfAllInputs(e) {
|
|
3062
|
-
return x.checkForInput(this.data.inputs, 0),
|
|
3078
|
+
return x.checkForInput(this.data.inputs, 0), le(this.data.inputs.length).map(
|
|
3063
3079
|
(r) => this.validateSignaturesOfInput(r, e)
|
|
3064
3080
|
).reduce((r, c) => c && r, !0);
|
|
3065
3081
|
}
|
|
@@ -3071,7 +3087,7 @@ class wt {
|
|
|
3071
3087
|
if (!e || !e.publicKey || !e.fingerprint)
|
|
3072
3088
|
throw new Error("Need HDSigner to sign input");
|
|
3073
3089
|
const r = [];
|
|
3074
|
-
for (const c of
|
|
3090
|
+
for (const c of le(this.data.inputs.length))
|
|
3075
3091
|
try {
|
|
3076
3092
|
this.signInputHD(c, e, n), r.push(!0);
|
|
3077
3093
|
} catch {
|
|
@@ -3086,7 +3102,7 @@ class wt {
|
|
|
3086
3102
|
if (!e || !e.publicKey || !e.fingerprint)
|
|
3087
3103
|
return c(new Error("Need HDSigner to sign input"));
|
|
3088
3104
|
const s = [], o = [];
|
|
3089
|
-
for (const i of
|
|
3105
|
+
for (const i of le(this.data.inputs.length))
|
|
3090
3106
|
o.push(
|
|
3091
3107
|
this.signInputHDAsync(i, e, n).then(
|
|
3092
3108
|
() => {
|
|
@@ -3124,7 +3140,7 @@ class wt {
|
|
|
3124
3140
|
signAllInputs(e, n) {
|
|
3125
3141
|
if (!e || !e.publicKey) throw new Error("Need Signer to sign input");
|
|
3126
3142
|
const r = [];
|
|
3127
|
-
for (const c of
|
|
3143
|
+
for (const c of le(this.data.inputs.length))
|
|
3128
3144
|
try {
|
|
3129
3145
|
this.signInput(c, e, n), r.push(!0);
|
|
3130
3146
|
} catch {
|
|
@@ -3206,19 +3222,19 @@ class wt {
|
|
|
3206
3222
|
});
|
|
3207
3223
|
}
|
|
3208
3224
|
toBuffer() {
|
|
3209
|
-
return
|
|
3225
|
+
return ut(this.__CACHE), this.data.toBuffer();
|
|
3210
3226
|
}
|
|
3211
3227
|
toHex() {
|
|
3212
|
-
return
|
|
3228
|
+
return ut(this.__CACHE), this.data.toHex();
|
|
3213
3229
|
}
|
|
3214
3230
|
toBase64() {
|
|
3215
|
-
return
|
|
3231
|
+
return ut(this.__CACHE), this.data.toBase64();
|
|
3216
3232
|
}
|
|
3217
3233
|
updateGlobal(e) {
|
|
3218
3234
|
return this.data.updateGlobal(e), this;
|
|
3219
3235
|
}
|
|
3220
3236
|
updateInput(e, n) {
|
|
3221
|
-
return n.witnessScript &&
|
|
3237
|
+
return n.witnessScript && Ge(n.witnessScript), En(this.data.inputs[e], n, "updateInput"), this.data.updateInput(e, n), n.nonWitnessUtxo && Et(this.__CACHE, this.data.inputs[e], e), this;
|
|
3222
3238
|
}
|
|
3223
3239
|
updateOutput(e, n) {
|
|
3224
3240
|
const r = this.data.outputs[e];
|
|
@@ -3239,7 +3255,7 @@ class wt {
|
|
|
3239
3255
|
checkTaprootHashesForSig(e, n, r, c, s) {
|
|
3240
3256
|
if (typeof r.signSchnorr != "function")
|
|
3241
3257
|
throw new Error(`Need Schnorr Signer to sign taproot input #${e}.`);
|
|
3242
|
-
const o = l.isBuffer(r.publicKey) ? r.publicKey : l.from(r.publicKey), i =
|
|
3258
|
+
const o = l.isBuffer(r.publicKey) ? r.publicKey : l.from(r.publicKey), i = wt(
|
|
3243
3259
|
e,
|
|
3244
3260
|
n,
|
|
3245
3261
|
this.data.inputs,
|
|
@@ -3254,14 +3270,14 @@ class wt {
|
|
|
3254
3270
|
);
|
|
3255
3271
|
return i;
|
|
3256
3272
|
}
|
|
3257
|
-
_finalizeInput(e, n, r =
|
|
3258
|
-
const { script: s, isP2SH: o, isP2WSH: i, isSegwit: a } =
|
|
3273
|
+
_finalizeInput(e, n, r = mo, c = !0) {
|
|
3274
|
+
const { script: s, isP2SH: o, isP2WSH: i, isSegwit: a } = Ao(
|
|
3259
3275
|
e,
|
|
3260
3276
|
n,
|
|
3261
3277
|
this.__CACHE
|
|
3262
3278
|
);
|
|
3263
3279
|
if (!s) throw new Error(`No script found for input #${e}`);
|
|
3264
|
-
|
|
3280
|
+
bo(n);
|
|
3265
3281
|
const { finalScriptSig: u, finalScriptWitness: f } = r(
|
|
3266
3282
|
e,
|
|
3267
3283
|
n,
|
|
@@ -3279,12 +3295,12 @@ class wt {
|
|
|
3279
3295
|
if (!n.witnessUtxo)
|
|
3280
3296
|
throw new Error(`Cannot finalize input #${e}. Missing witness utxo.`);
|
|
3281
3297
|
if (n.tapKeySig) {
|
|
3282
|
-
const s =
|
|
3298
|
+
const s = Te({
|
|
3283
3299
|
output: n.witnessUtxo.script,
|
|
3284
3300
|
signature: n.tapKeySig
|
|
3285
3301
|
});
|
|
3286
3302
|
if (!s.witness) throw new Error("Cannot finalize taproot key spend");
|
|
3287
|
-
const o =
|
|
3303
|
+
const o = ye(s.witness);
|
|
3288
3304
|
this.data.updateInput(e, { finalScriptWitness: o });
|
|
3289
3305
|
} else {
|
|
3290
3306
|
const { finalScriptWitness: s } = c(
|
|
@@ -3302,12 +3318,12 @@ class wt {
|
|
|
3302
3318
|
throw new Error("No signatures to validate");
|
|
3303
3319
|
if (typeof n != "function")
|
|
3304
3320
|
throw new Error("Need validator function to validate signatures");
|
|
3305
|
-
const o = r ? s.filter((
|
|
3321
|
+
const o = r ? s.filter((h) => h.pubkey.equals(r)) : s;
|
|
3306
3322
|
if (o.length < 1) throw new Error("No signatures for this pubkey");
|
|
3307
3323
|
const i = [];
|
|
3308
3324
|
let a, u, f;
|
|
3309
|
-
for (const
|
|
3310
|
-
const g =
|
|
3325
|
+
for (const h of o) {
|
|
3326
|
+
const g = de.decode(h.signature), { hash: y, script: p } = f !== g.hashType || !a || !u ? lr(
|
|
3311
3327
|
e,
|
|
3312
3328
|
Object.assign({}, c, {
|
|
3313
3329
|
sighashType: g.hashType
|
|
@@ -3315,9 +3331,9 @@ class wt {
|
|
|
3315
3331
|
this.__CACHE,
|
|
3316
3332
|
!0
|
|
3317
3333
|
) : { hash: a, script: u };
|
|
3318
|
-
f = g.hashType, a = y, u =
|
|
3334
|
+
f = g.hashType, a = y, u = p, fr(h.pubkey, p, "verify"), i.push(n(h.pubkey, y, g.signature));
|
|
3319
3335
|
}
|
|
3320
|
-
return i.every((
|
|
3336
|
+
return i.every((h) => h);
|
|
3321
3337
|
}
|
|
3322
3338
|
validateSignaturesOfTaprootInput(e, n, r) {
|
|
3323
3339
|
const c = this.data.inputs[e], s = (c || {}).tapKeySig, o = (c || {}).tapScriptSig;
|
|
@@ -3325,8 +3341,8 @@ class wt {
|
|
|
3325
3341
|
throw new Error("No signatures to validate");
|
|
3326
3342
|
if (typeof n != "function")
|
|
3327
3343
|
throw new Error("Need validator function to validate signatures");
|
|
3328
|
-
r = r &&
|
|
3329
|
-
const i = r ?
|
|
3344
|
+
r = r && ge(r);
|
|
3345
|
+
const i = r ? wt(e, c, this.data.inputs, r, this.__CACHE) : vo(e, c, this.data.inputs, this.__CACHE);
|
|
3330
3346
|
if (!i.length) throw new Error("No signatures for this pubkey");
|
|
3331
3347
|
const a = i.find((f) => !f.leafHash);
|
|
3332
3348
|
let u = 0;
|
|
@@ -3340,11 +3356,11 @@ class wt {
|
|
|
3340
3356
|
}
|
|
3341
3357
|
if (o)
|
|
3342
3358
|
for (const f of o) {
|
|
3343
|
-
const
|
|
3344
|
-
if (
|
|
3359
|
+
const h = i.find((g) => f.pubkey.equals(g.pubkey));
|
|
3360
|
+
if (h) {
|
|
3345
3361
|
if (!n(
|
|
3346
3362
|
f.pubkey,
|
|
3347
|
-
|
|
3363
|
+
h.hash,
|
|
3348
3364
|
xn(f.signature)
|
|
3349
3365
|
)) return !1;
|
|
3350
3366
|
u++;
|
|
@@ -3362,7 +3378,7 @@ class wt {
|
|
|
3362
3378
|
), i = n.sign(s), a = [
|
|
3363
3379
|
{
|
|
3364
3380
|
pubkey: c,
|
|
3365
|
-
signature:
|
|
3381
|
+
signature: de.encode(
|
|
3366
3382
|
l.isBuffer(i) ? i : l.from(i),
|
|
3367
3383
|
o
|
|
3368
3384
|
)
|
|
@@ -3378,18 +3394,18 @@ class wt {
|
|
|
3378
3394
|
c,
|
|
3379
3395
|
s
|
|
3380
3396
|
), a = r.signSchnorr.bind(r), u = (g) => l.isBuffer(g) ? g : l.from(g), f = i.filter((g) => !g.leafHash).map(
|
|
3381
|
-
(g) =>
|
|
3382
|
-
)[0],
|
|
3397
|
+
(g) => Re(u(a(g.hash)), n.sighashType)
|
|
3398
|
+
)[0], h = i.filter((g) => !!g.leafHash).map(
|
|
3383
3399
|
(g) => ({
|
|
3384
|
-
pubkey:
|
|
3385
|
-
signature:
|
|
3400
|
+
pubkey: ge(o),
|
|
3401
|
+
signature: Re(
|
|
3386
3402
|
u(a(g.hash)),
|
|
3387
3403
|
n.sighashType
|
|
3388
3404
|
),
|
|
3389
3405
|
leafHash: g.leafHash
|
|
3390
3406
|
})
|
|
3391
3407
|
);
|
|
3392
|
-
return f && this.data.updateInput(e, { tapKeySig: f }),
|
|
3408
|
+
return f && this.data.updateInput(e, { tapKeySig: f }), h.length && this.data.updateInput(e, { tapScriptSig: h }), this;
|
|
3393
3409
|
}
|
|
3394
3410
|
_signInputAsync(e, n, r = [v.SIGHASH_ALL]) {
|
|
3395
3411
|
const c = l.isBuffer(n.publicKey) ? n.publicKey : l.from(n.publicKey), { hash: s, sighashType: o } = An(
|
|
@@ -3403,7 +3419,7 @@ class wt {
|
|
|
3403
3419
|
const a = l.isBuffer(i) ? i : l.from(i), u = [
|
|
3404
3420
|
{
|
|
3405
3421
|
pubkey: c,
|
|
3406
|
-
signature:
|
|
3422
|
+
signature: de.encode(a, o)
|
|
3407
3423
|
}
|
|
3408
3424
|
];
|
|
3409
3425
|
this.data.updateInput(e, { partialSig: u });
|
|
@@ -3416,21 +3432,21 @@ class wt {
|
|
|
3416
3432
|
r,
|
|
3417
3433
|
c,
|
|
3418
3434
|
s
|
|
3419
|
-
), a = r.signSchnorr.bind(r), u = (
|
|
3420
|
-
if (
|
|
3421
|
-
const
|
|
3422
|
-
tapKeySig:
|
|
3435
|
+
), a = r.signSchnorr.bind(r), u = (p) => l.isBuffer(p) ? p : l.from(p), f = [], h = i.filter((p) => !p.leafHash)[0];
|
|
3436
|
+
if (h) {
|
|
3437
|
+
const p = Promise.resolve(a(h.hash)).then((d) => ({
|
|
3438
|
+
tapKeySig: Re(u(d), n.sighashType)
|
|
3423
3439
|
}));
|
|
3424
|
-
f.push(
|
|
3440
|
+
f.push(p);
|
|
3425
3441
|
}
|
|
3426
|
-
const g = i.filter((
|
|
3442
|
+
const g = i.filter((p) => !!p.leafHash);
|
|
3427
3443
|
if (g.length) {
|
|
3428
|
-
const
|
|
3444
|
+
const p = g.map(async (d) => {
|
|
3429
3445
|
const E = await a(d.hash);
|
|
3430
3446
|
return { tapScriptSig: [
|
|
3431
3447
|
{
|
|
3432
|
-
pubkey:
|
|
3433
|
-
signature:
|
|
3448
|
+
pubkey: ge(o),
|
|
3449
|
+
signature: Re(
|
|
3434
3450
|
u(E),
|
|
3435
3451
|
n.sighashType
|
|
3436
3452
|
),
|
|
@@ -3438,17 +3454,17 @@ class wt {
|
|
|
3438
3454
|
}
|
|
3439
3455
|
] };
|
|
3440
3456
|
});
|
|
3441
|
-
f.push(...
|
|
3457
|
+
f.push(...p);
|
|
3442
3458
|
}
|
|
3443
3459
|
const y = await Promise.all(f);
|
|
3444
|
-
for (const
|
|
3445
|
-
this.data.updateInput(e,
|
|
3460
|
+
for (const p of y)
|
|
3461
|
+
this.data.updateInput(e, p);
|
|
3446
3462
|
}
|
|
3447
3463
|
}
|
|
3448
|
-
const
|
|
3449
|
-
class
|
|
3464
|
+
const So = (t) => new ar(t);
|
|
3465
|
+
class ar {
|
|
3450
3466
|
constructor(e = l.from([2, 0, 0, 0, 0, 0, 0, 0, 0, 0])) {
|
|
3451
|
-
this.tx = v.fromBuffer(e),
|
|
3467
|
+
this.tx = v.fromBuffer(e), To(this.tx), Object.defineProperty(this, "tx", {
|
|
3452
3468
|
enumerable: !1,
|
|
3453
3469
|
writable: !0
|
|
3454
3470
|
});
|
|
@@ -3474,14 +3490,14 @@ class hr {
|
|
|
3474
3490
|
return this.tx.toBuffer();
|
|
3475
3491
|
}
|
|
3476
3492
|
}
|
|
3477
|
-
function
|
|
3493
|
+
function wo(t, e, n) {
|
|
3478
3494
|
switch (n) {
|
|
3479
3495
|
case "pubkey":
|
|
3480
3496
|
case "pubkeyhash":
|
|
3481
3497
|
case "witnesspubkeyhash":
|
|
3482
3498
|
return _n(1, t.partialSig);
|
|
3483
3499
|
case "multisig": {
|
|
3484
|
-
const r =
|
|
3500
|
+
const r = De({
|
|
3485
3501
|
output: e
|
|
3486
3502
|
});
|
|
3487
3503
|
return _n(r.m, t.partialSig, r.pubkeys);
|
|
@@ -3492,7 +3508,7 @@ function Eo(t, e, n) {
|
|
|
3492
3508
|
return !1;
|
|
3493
3509
|
}
|
|
3494
3510
|
}
|
|
3495
|
-
function
|
|
3511
|
+
function ut(t) {
|
|
3496
3512
|
if (t.__UNSAFE_SIGN_NONSEGWIT)
|
|
3497
3513
|
throw new Error("Not BIP174 compliant, can not export");
|
|
3498
3514
|
}
|
|
@@ -3500,12 +3516,12 @@ function _n(t, e, n) {
|
|
|
3500
3516
|
if (!e) return !1;
|
|
3501
3517
|
let r;
|
|
3502
3518
|
if (n ? r = n.map((c) => {
|
|
3503
|
-
const s =
|
|
3519
|
+
const s = Ho(c);
|
|
3504
3520
|
return e.find((o) => o.pubkey.equals(s));
|
|
3505
3521
|
}).filter((c) => !!c) : r = e, r.length > t) throw new Error("Too many signatures");
|
|
3506
3522
|
return r.length === t;
|
|
3507
3523
|
}
|
|
3508
|
-
function
|
|
3524
|
+
function ur(t) {
|
|
3509
3525
|
return !!t.finalScriptSig || !!t.finalScriptWitness;
|
|
3510
3526
|
}
|
|
3511
3527
|
function mn(t) {
|
|
@@ -3516,52 +3532,52 @@ function mn(t) {
|
|
|
3516
3532
|
return !!(l.isBuffer(r) ? r : l.from(r)).equals(e.pubkey);
|
|
3517
3533
|
};
|
|
3518
3534
|
}
|
|
3519
|
-
function
|
|
3535
|
+
function Fe(t) {
|
|
3520
3536
|
if (typeof t != "number" || t !== Math.floor(t) || t > 4294967295 || t < 0)
|
|
3521
3537
|
throw new Error("Invalid 32 bit integer");
|
|
3522
3538
|
}
|
|
3523
|
-
function
|
|
3539
|
+
function Eo(t, e, n) {
|
|
3524
3540
|
const r = e.__FEE_RATE || t.getFeeRate(), c = e.__EXTRACTED_TX.virtualSize(), s = r * c;
|
|
3525
3541
|
if (r >= n.maximumFeeRate)
|
|
3526
3542
|
throw new Error(
|
|
3527
3543
|
`Warning: You are paying around ${(s / 1e8).toFixed(8)} in fees, which is ${r} satoshi per byte for a transaction with a VSize of ${c} 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.`
|
|
3528
3544
|
);
|
|
3529
3545
|
}
|
|
3530
|
-
function
|
|
3546
|
+
function pe(t, e) {
|
|
3531
3547
|
t.forEach((n) => {
|
|
3532
|
-
if (N(n) ?
|
|
3548
|
+
if (N(n) ? ro(n, e) : Zs(n, e)) throw new Error("Can not modify transaction, signatures exist.");
|
|
3533
3549
|
});
|
|
3534
3550
|
}
|
|
3535
|
-
function
|
|
3551
|
+
function bo(t) {
|
|
3536
3552
|
if (!t.sighashType || !t.partialSig) return;
|
|
3537
3553
|
const { partialSig: e, sighashType: n } = t;
|
|
3538
3554
|
e.forEach((r) => {
|
|
3539
|
-
const { hashType: c } =
|
|
3555
|
+
const { hashType: c } = de.decode(r.signature);
|
|
3540
3556
|
if (n !== c)
|
|
3541
3557
|
throw new Error("Signature sighash does not match input sighash type");
|
|
3542
3558
|
});
|
|
3543
3559
|
}
|
|
3544
|
-
function
|
|
3545
|
-
if (!
|
|
3560
|
+
function fr(t, e, n) {
|
|
3561
|
+
if (!Ze(t, e))
|
|
3546
3562
|
throw new Error(`Can not ${n} for this input with the key ${t.toString("hex")}`);
|
|
3547
3563
|
}
|
|
3548
|
-
function
|
|
3564
|
+
function To(t) {
|
|
3549
3565
|
if (!t.ins.every(
|
|
3550
3566
|
(n) => n.script && n.script.length === 0 && n.witness && n.witness.length === 0
|
|
3551
3567
|
))
|
|
3552
3568
|
throw new Error("Format Error: Transaction ScriptSigs are not empty");
|
|
3553
3569
|
}
|
|
3554
|
-
function
|
|
3570
|
+
function _o(t, e) {
|
|
3555
3571
|
t.ins.forEach((n) => {
|
|
3556
|
-
|
|
3572
|
+
hr(e, n);
|
|
3557
3573
|
});
|
|
3558
3574
|
}
|
|
3559
|
-
function
|
|
3575
|
+
function hr(t, e) {
|
|
3560
3576
|
const n = `${Bn(l.from(e.hash)).toString("hex")}:${e.index}`;
|
|
3561
3577
|
if (t.__TX_IN_CACHE[n]) throw new Error("Duplicate input detected.");
|
|
3562
3578
|
t.__TX_IN_CACHE[n] = 1;
|
|
3563
3579
|
}
|
|
3564
|
-
function
|
|
3580
|
+
function pr(t, e) {
|
|
3565
3581
|
return (n, r, c, s) => {
|
|
3566
3582
|
const o = t({
|
|
3567
3583
|
redeem: { output: c }
|
|
@@ -3572,22 +3588,22 @@ function yr(t, e) {
|
|
|
3572
3588
|
);
|
|
3573
3589
|
};
|
|
3574
3590
|
}
|
|
3575
|
-
const In =
|
|
3591
|
+
const In = pr(Ee, "Redeem script"), vn = pr(be, "Witness script");
|
|
3576
3592
|
function kn(t, e, n, r, c = !1) {
|
|
3577
|
-
if (!n.every(
|
|
3593
|
+
if (!n.every(ur)) throw new Error(`PSBT must be finalized to calculate ${e}`);
|
|
3578
3594
|
if (t === "__FEE_RATE" && r.__FEE_RATE) return r.__FEE_RATE;
|
|
3579
3595
|
if (t === "__FEE" && r.__FEE) return r.__FEE;
|
|
3580
3596
|
let s, o = !0;
|
|
3581
|
-
r.__EXTRACTED_TX ? (s = r.__EXTRACTED_TX, o = !1) : s = r.__TX.clone(),
|
|
3597
|
+
r.__EXTRACTED_TX ? (s = r.__EXTRACTED_TX, o = !1) : s = r.__TX.clone(), Sr(n, s, r, o, c);
|
|
3582
3598
|
const i = t === "__FEE_RATE" ? r.__FEE_RATE : r.__FEE;
|
|
3583
3599
|
if (i === void 0) throw new Error(`Failed to calculate ${e}`);
|
|
3584
3600
|
return i;
|
|
3585
3601
|
}
|
|
3586
|
-
function
|
|
3587
|
-
const a =
|
|
3588
|
-
if (!
|
|
3602
|
+
function mo(t, e, n, r, c, s, o = !0, i) {
|
|
3603
|
+
const a = br(n);
|
|
3604
|
+
if (!wo(e, n, a) && o)
|
|
3589
3605
|
throw new Error(`Can not finalize input #${t}`);
|
|
3590
|
-
return
|
|
3606
|
+
return Io(
|
|
3591
3607
|
n,
|
|
3592
3608
|
a,
|
|
3593
3609
|
e.partialSig,
|
|
@@ -3597,44 +3613,44 @@ function Io(t, e, n, r, c, s, o = !0, i) {
|
|
|
3597
3613
|
i
|
|
3598
3614
|
);
|
|
3599
3615
|
}
|
|
3600
|
-
function
|
|
3616
|
+
function Io(t, e, n, r, c, s, o) {
|
|
3601
3617
|
let i, a;
|
|
3602
|
-
const u =
|
|
3603
|
-
return r ? (f ? a =
|
|
3618
|
+
const u = ko(t, e, n), f = s ? be({ redeem: u }) : null, h = c ? Ee({ redeem: f || u }) : null;
|
|
3619
|
+
return r ? (f ? a = ye(f.witness) : u ? a = ye(u.witness) : a = ye(o ?? [l.from([0])]), h && (i = h?.input)) : h ? i = h?.input : u ? i = u.input : i = Array.isArray(o) && o[0] ? o[0] : l.from([1]), {
|
|
3604
3620
|
finalScriptSig: i,
|
|
3605
3621
|
finalScriptWitness: a
|
|
3606
3622
|
};
|
|
3607
3623
|
}
|
|
3608
3624
|
function An(t, e, n, r, c) {
|
|
3609
|
-
const s = x.checkForInput(t, e), { hash: o, sighashType: i, script: a } =
|
|
3625
|
+
const s = x.checkForInput(t, e), { hash: o, sighashType: i, script: a } = lr(
|
|
3610
3626
|
e,
|
|
3611
3627
|
s,
|
|
3612
3628
|
r,
|
|
3613
3629
|
!1,
|
|
3614
3630
|
c
|
|
3615
3631
|
);
|
|
3616
|
-
return
|
|
3632
|
+
return fr(n, a, "sign"), {
|
|
3617
3633
|
hash: o,
|
|
3618
3634
|
sighashType: i
|
|
3619
3635
|
};
|
|
3620
3636
|
}
|
|
3621
|
-
function
|
|
3637
|
+
function lr(t, e, n, r, c) {
|
|
3622
3638
|
const s = n.__TX, o = e.sighashType || v.SIGHASH_ALL;
|
|
3623
|
-
|
|
3639
|
+
gr(o, c);
|
|
3624
3640
|
let i, a;
|
|
3625
3641
|
if (e.nonWitnessUtxo) {
|
|
3626
|
-
const
|
|
3642
|
+
const h = Je(n, e, t), g = s.ins[t].hash, y = h.getHash();
|
|
3627
3643
|
if (!g.equals(y))
|
|
3628
3644
|
throw new Error(
|
|
3629
3645
|
`Non-witness UTXO hash for input #${t} doesn't match the hash specified in the prevout`
|
|
3630
3646
|
);
|
|
3631
|
-
const
|
|
3632
|
-
a =
|
|
3647
|
+
const p = s.ins[t].index;
|
|
3648
|
+
a = h.outs[p];
|
|
3633
3649
|
} else if (e.witnessUtxo)
|
|
3634
3650
|
a = e.witnessUtxo;
|
|
3635
3651
|
else
|
|
3636
3652
|
throw new Error("Need a Utxo input item for signing");
|
|
3637
|
-
const { meaningfulScript: u, type: f } =
|
|
3653
|
+
const { meaningfulScript: u, type: f } = Qe(
|
|
3638
3654
|
a.script,
|
|
3639
3655
|
t,
|
|
3640
3656
|
"input",
|
|
@@ -3648,11 +3664,11 @@ function Sr(t, e, n, r, c) {
|
|
|
3648
3664
|
a.value,
|
|
3649
3665
|
o
|
|
3650
3666
|
);
|
|
3651
|
-
else if (
|
|
3652
|
-
const
|
|
3667
|
+
else if ($e(u)) {
|
|
3668
|
+
const h = we({
|
|
3653
3669
|
hash: u.subarray(2)
|
|
3654
3670
|
}).output;
|
|
3655
|
-
i = s.hashForWitnessV0(t,
|
|
3671
|
+
i = s.hashForWitnessV0(t, h, a.value, o);
|
|
3656
3672
|
} else {
|
|
3657
3673
|
if (e.nonWitnessUtxo === void 0 && !n.__UNSAFE_SIGN_NONSEGWIT)
|
|
3658
3674
|
throw new Error(
|
|
@@ -3671,10 +3687,10 @@ PROCEED WITH CAUTION!
|
|
|
3671
3687
|
hash: i
|
|
3672
3688
|
};
|
|
3673
3689
|
}
|
|
3674
|
-
function
|
|
3690
|
+
function vo(t, e, n, r) {
|
|
3675
3691
|
const c = [];
|
|
3676
3692
|
if (e.tapInternalKey) {
|
|
3677
|
-
const o =
|
|
3693
|
+
const o = dr(t, e, r);
|
|
3678
3694
|
o && c.push(o);
|
|
3679
3695
|
}
|
|
3680
3696
|
if (e.tapScriptSig) {
|
|
@@ -3682,70 +3698,70 @@ function ko(t, e, n, r) {
|
|
|
3682
3698
|
c.push(...o);
|
|
3683
3699
|
}
|
|
3684
3700
|
return c.map(
|
|
3685
|
-
(o) =>
|
|
3701
|
+
(o) => wt(t, e, n, o, r)
|
|
3686
3702
|
).flat();
|
|
3687
3703
|
}
|
|
3688
|
-
function
|
|
3689
|
-
const { script: r } =
|
|
3690
|
-
return
|
|
3704
|
+
function dr(t, e, n) {
|
|
3705
|
+
const { script: r } = kt(t, e, n);
|
|
3706
|
+
return vt(r) ? l.from(r.subarray(2, 34)) : null;
|
|
3691
3707
|
}
|
|
3692
3708
|
function xn(t) {
|
|
3693
3709
|
return t.length === 64 ? t : l.from(t.subarray(0, 64));
|
|
3694
3710
|
}
|
|
3695
|
-
function
|
|
3711
|
+
function wt(t, e, n, r, c, s, o) {
|
|
3696
3712
|
const i = c.__TX, a = e.sighashType || v.SIGHASH_DEFAULT;
|
|
3697
|
-
|
|
3713
|
+
gr(a, o);
|
|
3698
3714
|
const u = n.map(
|
|
3699
|
-
(
|
|
3700
|
-
), f = u.map((
|
|
3715
|
+
(p, d) => kt(d, p, c)
|
|
3716
|
+
), f = u.map((p) => p.script), h = u.map((p) => p.value), g = [];
|
|
3701
3717
|
if (e.tapInternalKey && !s) {
|
|
3702
|
-
const
|
|
3703
|
-
if (
|
|
3718
|
+
const p = dr(t, e, c) || l.from([]);
|
|
3719
|
+
if (ge(r).equals(p)) {
|
|
3704
3720
|
const d = i.hashForWitnessV1(
|
|
3705
3721
|
t,
|
|
3706
3722
|
f,
|
|
3707
|
-
|
|
3723
|
+
h,
|
|
3708
3724
|
a
|
|
3709
3725
|
);
|
|
3710
3726
|
g.push({ pubkey: r, hash: d });
|
|
3711
3727
|
}
|
|
3712
3728
|
}
|
|
3713
|
-
const y = (e.tapLeafScript || []).filter((
|
|
3714
|
-
const d =
|
|
3715
|
-
output:
|
|
3716
|
-
version:
|
|
3729
|
+
const y = (e.tapLeafScript || []).filter((p) => Ze(r, p.script)).map((p) => {
|
|
3730
|
+
const d = qe({
|
|
3731
|
+
output: p.script,
|
|
3732
|
+
version: p.leafVersion
|
|
3717
3733
|
});
|
|
3718
|
-
return Object.assign({ hash: d },
|
|
3719
|
-
}).filter((
|
|
3734
|
+
return Object.assign({ hash: d }, p);
|
|
3735
|
+
}).filter((p) => !s || s.equals(p.hash)).map((p) => {
|
|
3720
3736
|
const d = i.hashForWitnessV1(
|
|
3721
3737
|
t,
|
|
3722
3738
|
f,
|
|
3723
|
-
|
|
3739
|
+
h,
|
|
3724
3740
|
a,
|
|
3725
|
-
|
|
3741
|
+
p.hash
|
|
3726
3742
|
);
|
|
3727
3743
|
return {
|
|
3728
3744
|
pubkey: r,
|
|
3729
3745
|
hash: d,
|
|
3730
|
-
leafHash:
|
|
3746
|
+
leafHash: p.hash
|
|
3731
3747
|
};
|
|
3732
3748
|
});
|
|
3733
3749
|
return g.concat(y);
|
|
3734
3750
|
}
|
|
3735
|
-
function
|
|
3751
|
+
function gr(t, e) {
|
|
3736
3752
|
if (e && e.indexOf(t) < 0) {
|
|
3737
|
-
const n =
|
|
3753
|
+
const n = Co(t);
|
|
3738
3754
|
throw new Error(
|
|
3739
3755
|
`Sighash type is not allowed. Retry the sign method passing the sighashTypes array of whitelisted types. Sighash type: ${n}`
|
|
3740
3756
|
);
|
|
3741
3757
|
}
|
|
3742
3758
|
}
|
|
3743
|
-
function
|
|
3759
|
+
function ko(t, e, n) {
|
|
3744
3760
|
let r;
|
|
3745
3761
|
switch (e) {
|
|
3746
3762
|
case "multisig": {
|
|
3747
|
-
const c =
|
|
3748
|
-
r =
|
|
3763
|
+
const c = xo(t, n);
|
|
3764
|
+
r = De({
|
|
3749
3765
|
output: t,
|
|
3750
3766
|
signatures: c
|
|
3751
3767
|
});
|
|
@@ -3758,14 +3774,14 @@ function Ao(t, e, n) {
|
|
|
3758
3774
|
});
|
|
3759
3775
|
break;
|
|
3760
3776
|
case "pubkeyhash":
|
|
3761
|
-
r =
|
|
3777
|
+
r = we({
|
|
3762
3778
|
output: t,
|
|
3763
3779
|
pubkey: n[0].pubkey,
|
|
3764
3780
|
signature: n[0].signature
|
|
3765
3781
|
});
|
|
3766
3782
|
break;
|
|
3767
3783
|
case "witnesspubkeyhash":
|
|
3768
|
-
r =
|
|
3784
|
+
r = Xe({
|
|
3769
3785
|
output: t,
|
|
3770
3786
|
pubkey: n[0].pubkey,
|
|
3771
3787
|
signature: n[0].signature
|
|
@@ -3774,7 +3790,7 @@ function Ao(t, e, n) {
|
|
|
3774
3790
|
}
|
|
3775
3791
|
return r;
|
|
3776
3792
|
}
|
|
3777
|
-
function
|
|
3793
|
+
function Ao(t, e, n) {
|
|
3778
3794
|
const r = n.__TX, c = {
|
|
3779
3795
|
script: null,
|
|
3780
3796
|
isSegwit: !1,
|
|
@@ -3786,16 +3802,16 @@ function xo(t, e, n) {
|
|
|
3786
3802
|
else if (e.redeemScript)
|
|
3787
3803
|
c.script = e.redeemScript;
|
|
3788
3804
|
else if (e.nonWitnessUtxo) {
|
|
3789
|
-
const s =
|
|
3805
|
+
const s = Je(n, e, t), o = r.ins[t].index;
|
|
3790
3806
|
c.script = s.outs[o].script;
|
|
3791
3807
|
} else e.witnessUtxo && (c.script = e.witnessUtxo.script);
|
|
3792
|
-
if (e.witnessScript ||
|
|
3808
|
+
if (e.witnessScript || $e(c.script))
|
|
3793
3809
|
c.isSegwit = !0;
|
|
3794
3810
|
else
|
|
3795
3811
|
try {
|
|
3796
3812
|
const s = c.script;
|
|
3797
3813
|
if (!s) throw new TypeError("Invalid script for segwit address");
|
|
3798
|
-
c.isSegwit =
|
|
3814
|
+
c.isSegwit = Yn(s);
|
|
3799
3815
|
} catch {
|
|
3800
3816
|
}
|
|
3801
3817
|
return c;
|
|
@@ -3819,10 +3835,10 @@ function Cn(t, e, n) {
|
|
|
3819
3835
|
return o;
|
|
3820
3836
|
});
|
|
3821
3837
|
}
|
|
3822
|
-
function
|
|
3823
|
-
return
|
|
3838
|
+
function xo(t, e) {
|
|
3839
|
+
return De({ output: t }).pubkeys.map((r) => (e.filter((c) => c.pubkey.equals(r))[0] || {}).signature).filter((r) => !!r);
|
|
3824
3840
|
}
|
|
3825
|
-
function
|
|
3841
|
+
function yr(t) {
|
|
3826
3842
|
let e = 0;
|
|
3827
3843
|
function n(o) {
|
|
3828
3844
|
return e += o, t.subarray(e - o, e);
|
|
@@ -3841,7 +3857,7 @@ function br(t) {
|
|
|
3841
3857
|
}
|
|
3842
3858
|
return s();
|
|
3843
3859
|
}
|
|
3844
|
-
function
|
|
3860
|
+
function Co(t) {
|
|
3845
3861
|
let e = t & v.SIGHASH_ANYONECANPAY ? "SIGHASH_ANYONECANPAY | " : "";
|
|
3846
3862
|
switch (t & 31) {
|
|
3847
3863
|
case v.SIGHASH_ALL:
|
|
@@ -3856,7 +3872,7 @@ function Oo(t) {
|
|
|
3856
3872
|
}
|
|
3857
3873
|
return e;
|
|
3858
3874
|
}
|
|
3859
|
-
function
|
|
3875
|
+
function Et(t, e, n) {
|
|
3860
3876
|
t.__NON_WITNESS_UTXO_BUF_CACHE[n] = e.nonWitnessUtxo, t.__NON_WITNESS_UTXO_TX_CACHE[n] = v.fromBuffer(e.nonWitnessUtxo);
|
|
3861
3877
|
const r = t, c = n;
|
|
3862
3878
|
delete e.nonWitnessUtxo, Object.defineProperty(e, "nonWitnessUtxo", {
|
|
@@ -3875,13 +3891,13 @@ function bt(t, e, n) {
|
|
|
3875
3891
|
}
|
|
3876
3892
|
});
|
|
3877
3893
|
}
|
|
3878
|
-
function
|
|
3894
|
+
function Sr(t, e, n, r, c) {
|
|
3879
3895
|
let s = 0;
|
|
3880
3896
|
t.forEach((u, f) => {
|
|
3881
|
-
if (r && u.finalScriptSig && (e.ins[f].script = u.finalScriptSig), r && u.finalScriptWitness && (e.ins[f].witness =
|
|
3897
|
+
if (r && u.finalScriptSig && (e.ins[f].script = u.finalScriptSig), r && u.finalScriptWitness && (e.ins[f].witness = yr(u.finalScriptWitness)), u.witnessUtxo)
|
|
3882
3898
|
s += u.witnessUtxo.value;
|
|
3883
3899
|
else if (u.nonWitnessUtxo) {
|
|
3884
|
-
const
|
|
3900
|
+
const h = Je(n, u, f), g = e.ins[f].index, y = h.outs[g];
|
|
3885
3901
|
s += y.value;
|
|
3886
3902
|
}
|
|
3887
3903
|
});
|
|
@@ -3893,147 +3909,147 @@ function Tr(t, e, n, r, c) {
|
|
|
3893
3909
|
const a = e.virtualSize();
|
|
3894
3910
|
n.__FEE = i, n.__EXTRACTED_TX = e, n.__FEE_RATE = Math.floor(i / a);
|
|
3895
3911
|
}
|
|
3896
|
-
function
|
|
3912
|
+
function Je(t, e, n) {
|
|
3897
3913
|
const r = t.__NON_WITNESS_UTXO_TX_CACHE;
|
|
3898
|
-
return r[n] ||
|
|
3914
|
+
return r[n] || Et(t, e, n), r[n];
|
|
3899
3915
|
}
|
|
3900
|
-
function
|
|
3901
|
-
const { script: r } =
|
|
3916
|
+
function wr(t, e, n) {
|
|
3917
|
+
const { script: r } = kt(t, e, n);
|
|
3902
3918
|
return r;
|
|
3903
3919
|
}
|
|
3904
|
-
function
|
|
3920
|
+
function kt(t, e, n) {
|
|
3905
3921
|
if (e.witnessUtxo !== void 0)
|
|
3906
3922
|
return {
|
|
3907
3923
|
script: e.witnessUtxo.script,
|
|
3908
3924
|
value: e.witnessUtxo.value
|
|
3909
3925
|
};
|
|
3910
3926
|
if (e.nonWitnessUtxo !== void 0) {
|
|
3911
|
-
const c =
|
|
3927
|
+
const c = Je(n, e, t).outs[n.__TX.ins[t].index];
|
|
3912
3928
|
return { script: c.script, value: c.value };
|
|
3913
3929
|
} else
|
|
3914
3930
|
throw new Error("Can't find pubkey in input without Utxo data");
|
|
3915
3931
|
}
|
|
3916
|
-
function
|
|
3917
|
-
const c =
|
|
3932
|
+
function Oo(t, e, n, r) {
|
|
3933
|
+
const c = wr(n, e, r), { meaningfulScript: s } = Qe(
|
|
3918
3934
|
c,
|
|
3919
3935
|
n,
|
|
3920
3936
|
"input",
|
|
3921
3937
|
e.redeemScript,
|
|
3922
3938
|
e.witnessScript
|
|
3923
3939
|
);
|
|
3924
|
-
return
|
|
3940
|
+
return Ze(t, s);
|
|
3925
3941
|
}
|
|
3926
|
-
function
|
|
3927
|
-
const c = r.__TX.outs[n].script, { meaningfulScript: s } =
|
|
3942
|
+
function Po(t, e, n, r) {
|
|
3943
|
+
const c = r.__TX.outs[n].script, { meaningfulScript: s } = Qe(
|
|
3928
3944
|
c,
|
|
3929
3945
|
n,
|
|
3930
3946
|
"output",
|
|
3931
3947
|
e.redeemScript,
|
|
3932
3948
|
e.witnessScript
|
|
3933
3949
|
);
|
|
3934
|
-
return
|
|
3950
|
+
return Ze(t, s);
|
|
3935
3951
|
}
|
|
3936
|
-
function
|
|
3952
|
+
function No(t) {
|
|
3937
3953
|
if (!t) return;
|
|
3938
|
-
const e =
|
|
3954
|
+
const e = ue(t);
|
|
3939
3955
|
if (!e) return;
|
|
3940
3956
|
const n = e[e.length - 1];
|
|
3941
|
-
if (!(!l.isBuffer(n) ||
|
|
3957
|
+
if (!(!l.isBuffer(n) || Er(n) || Bo(n) || !ue(n)))
|
|
3942
3958
|
return n;
|
|
3943
3959
|
}
|
|
3944
3960
|
function Uo(t) {
|
|
3945
3961
|
if (!t) return;
|
|
3946
|
-
const e =
|
|
3947
|
-
if (!(
|
|
3962
|
+
const e = yr(t), n = e[e.length - 1];
|
|
3963
|
+
if (!(Er(n) || !ue(n)))
|
|
3948
3964
|
return n;
|
|
3949
3965
|
}
|
|
3950
|
-
function
|
|
3966
|
+
function Ho(t) {
|
|
3951
3967
|
if (t.length === 65) {
|
|
3952
3968
|
const e = t[64] & 1, n = l.from(t.subarray(0, 33));
|
|
3953
3969
|
return n[0] = 2 | e, n;
|
|
3954
3970
|
}
|
|
3955
3971
|
return l.from(t);
|
|
3956
3972
|
}
|
|
3957
|
-
function
|
|
3958
|
-
return t.length === 33 &&
|
|
3973
|
+
function Er(t) {
|
|
3974
|
+
return t.length === 33 && kr(t);
|
|
3959
3975
|
}
|
|
3960
|
-
function
|
|
3961
|
-
return
|
|
3976
|
+
function Bo(t) {
|
|
3977
|
+
return Un(t);
|
|
3962
3978
|
}
|
|
3963
|
-
function
|
|
3964
|
-
const s =
|
|
3979
|
+
function Qe(t, e, n, r, c) {
|
|
3980
|
+
const s = or(t), o = s && r && Sn(r), i = Sn(t);
|
|
3965
3981
|
if (s && r === void 0)
|
|
3966
3982
|
throw new Error("scriptPubkey is P2SH but redeemScript missing");
|
|
3967
3983
|
if ((i || o) && c === void 0)
|
|
3968
3984
|
throw new Error("scriptPubkey or redeemScript is P2WSH but witnessScript missing");
|
|
3969
3985
|
let a;
|
|
3970
|
-
return o ? (a = c, In(e, t, r, n), vn(e, r, c, n),
|
|
3986
|
+
return o ? (a = c, In(e, t, r, n), vn(e, r, c, n), Ge(a)) : i ? (a = c, vn(e, t, c, n), Ge(a)) : s ? (a = r, In(e, t, r, n)) : a = t, {
|
|
3971
3987
|
meaningfulScript: a,
|
|
3972
3988
|
type: o ? "p2sh-p2wsh" : s ? "p2sh" : i ? "p2wsh" : "raw"
|
|
3973
3989
|
};
|
|
3974
3990
|
}
|
|
3975
|
-
function
|
|
3976
|
-
if (
|
|
3991
|
+
function Ge(t) {
|
|
3992
|
+
if ($e(t) || or(t))
|
|
3977
3993
|
throw new Error("P2WPKH or P2SH can not be contained within P2WSH");
|
|
3978
3994
|
}
|
|
3979
|
-
function
|
|
3980
|
-
return
|
|
3995
|
+
function br(t) {
|
|
3996
|
+
return $e(t) ? "witnesspubkeyhash" : $s(t) ? "pubkeyhash" : zs(t) ? "multisig" : Ys(t) ? "pubkey" : "nonstandard";
|
|
3981
3997
|
}
|
|
3982
|
-
function
|
|
3998
|
+
function le(t) {
|
|
3983
3999
|
return [...Array(t).keys()];
|
|
3984
4000
|
}
|
|
3985
4001
|
export {
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4002
|
+
ze as A,
|
|
4003
|
+
Ye as B,
|
|
4004
|
+
Yn as C,
|
|
4005
|
+
$n as D,
|
|
4006
|
+
Jn as E,
|
|
4007
|
+
_e as F,
|
|
4008
|
+
Is as G,
|
|
4009
|
+
Qn as H,
|
|
4010
|
+
er as I,
|
|
4011
|
+
tr as J,
|
|
4012
|
+
zs as K,
|
|
4013
|
+
Ys as L,
|
|
4014
|
+
$s as M,
|
|
4015
|
+
$e as N,
|
|
4000
4016
|
Sn as O,
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4017
|
+
St as P,
|
|
4018
|
+
or as Q,
|
|
4019
|
+
vt as R,
|
|
4020
|
+
Xo as S,
|
|
4021
|
+
Do as T,
|
|
4022
|
+
ye as U,
|
|
4023
|
+
ir as V,
|
|
4024
|
+
Ze as W,
|
|
4025
|
+
Zs as X,
|
|
4026
|
+
cr as Y,
|
|
4027
|
+
Qs as Z,
|
|
4028
|
+
Zn as _,
|
|
4029
|
+
_s as a,
|
|
4030
|
+
Ve as b,
|
|
4031
|
+
Go as c,
|
|
4016
4032
|
K as d,
|
|
4017
|
-
|
|
4033
|
+
Io as e,
|
|
4018
4034
|
Kn as f,
|
|
4019
|
-
|
|
4035
|
+
mo as g,
|
|
4020
4036
|
wn as h,
|
|
4021
4037
|
Fn as i,
|
|
4022
4038
|
N as j,
|
|
4023
|
-
|
|
4039
|
+
ct as k,
|
|
4024
4040
|
En as l,
|
|
4025
4041
|
bn as m,
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4042
|
+
Wo as n,
|
|
4043
|
+
qo as o,
|
|
4044
|
+
ke as p,
|
|
4045
|
+
Vo as q,
|
|
4046
|
+
no as r,
|
|
4047
|
+
Re as s,
|
|
4048
|
+
ge as t,
|
|
4049
|
+
ro as u,
|
|
4050
|
+
io as v,
|
|
4051
|
+
me as w,
|
|
4052
|
+
Ie as x,
|
|
4053
|
+
zn as y,
|
|
4054
|
+
We as z
|
|
4039
4055
|
};
|