@pioneer-platform/pioneer-react 0.2.47 → 0.2.49
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/dist/index.js +198340 -146844
- package/dist/{index_0e37f5ff.js → index_0652205a.js} +6 -6
- package/dist/{index_f9d1a3bf.js → index_096371b1.js} +3 -1
- package/dist/{index_ae6c3b10.js → index_0a5ed442.js} +3 -3
- package/dist/{index_e233a036.js → index_0a6e5811.js} +1 -1
- package/dist/{index_547d2868.js → index_0b5f5f6a.js} +4 -4
- package/dist/index_10812439.js +25 -0
- package/dist/{index_4a548214.js → index_1093b1b4.js} +8 -8
- package/dist/{index_3a6b0cd3.js → index_169417bf.js} +3 -3
- package/dist/{index_e168f4c0.js → index_1d5f0f00.js} +7 -7
- package/dist/{index_e57ba5a5.js → index_278505c5.js} +3 -3
- package/dist/{index_a4f5a15a.js → index_2845411a.js} +19 -19
- package/dist/{index_003befba.js → index_29be6ff5.js} +1122 -1312
- package/dist/{index_a6b45215.js → index_2dc95f2a.js} +7 -3
- package/dist/{index_6d2a3e5c.js → index_3402bab8.js} +6 -2
- package/dist/{index_310b7772.js → index_3c54e5ec.js} +9 -9
- package/dist/{index_f9d461d1.js → index_423ea09e.js} +3 -3
- package/dist/{index_37894947.js → index_4425b278.js} +3 -3
- package/dist/{index_61a33920.js → index_514c608b.js} +6 -6
- package/dist/index_51b338c1.js +121 -0
- package/dist/{index_0364269a.js → index_5d8426fb.js} +3 -3
- package/dist/index_628b22bc.js +11003 -0
- package/dist/index_63a883f7.js +446 -0
- package/dist/{index_d8e757ba.js → index_654fef3a.js} +3 -3
- package/dist/index_691fd636.js +12913 -0
- package/dist/{index_674ffbfa.js → index_69b0f47b.js} +9 -9
- package/dist/{index_a682c1a8.js → index_6cd7bc1a.js} +3 -1
- package/dist/{index_c8ebd6e3.js → index_6ebe4744.js} +900 -900
- package/dist/{index_7382dec1.js → index_7f735685.js} +5 -5
- package/dist/{index_b3022c1a.js → index_82348f63.js} +5 -5
- package/dist/index_849386d3.js +1115 -0
- package/dist/{index_85b01410.js → index_8610c3c4.js} +6 -6
- package/dist/index_8d6422b9.js +112 -0
- package/dist/{index_167c5f7a.js → index_8fd2c24a.js} +3 -3
- package/dist/{index_1990afbf.js → index_942c3b80.js} +4 -4
- package/dist/index_94b7968d.js +22872 -0
- package/dist/index_94d38802.js +2856 -0
- package/dist/{index_bd7e0d56.js → index_a5ca5cc4.js} +2 -2
- package/dist/{index_f80541a0.js → index_aa71379e.js} +307 -267
- package/dist/{index_354cce52.js → index_aa773d39.js} +3 -3
- package/dist/{index_29e62962.js → index_b022faaa.js} +4 -4
- package/dist/index_b1028d5f.js +65 -0
- package/dist/index_c232ca43.js +25 -0
- package/dist/{index_f19b5fe5.js → index_c9105338.js} +3 -3
- package/dist/{index_7c12bb44.js → index_cebbd50e.js} +1 -1
- package/dist/{index_ca633a1c.js → index_d477606a.js} +7 -7
- package/dist/index_d8a5e2ef.js +116 -0
- package/dist/{index_542dbb9a.js → index_de4af619.js} +4 -4
- package/dist/{index_7a1bb0b1.js → index_df47a9c6.js} +8 -8
- package/dist/{index_8b9255eb.js → index_e0b32f2f.js} +10 -10
- package/dist/{index_b21f58b7.js → index_e2794130.js} +4 -4
- package/dist/{index_2cbf1530.js → index_ecce7b22.js} +6 -6
- package/dist/{index_3891b298.js → index_f2d68730.js} +1 -1
- package/dist/index_f66728ba.js +130 -0
- package/dist/{index_f3922fc1.js → index_f8bc80e1.js} +3 -3
- package/package.json +19 -18
- package/src/lib/context/Pioneer/sdk/connect.ts +11 -11
|
@@ -0,0 +1,2856 @@
|
|
|
1
|
+
import { f as requireBrowser$8, d as dist, h as requireSafeBuffer, i as requireBrowser$9, j as requireSha_js, g as getDefaultExportFromCjs, R as RIPEMD160 } from "./index_94b7968d.js";
|
|
2
|
+
import { c as crypto_1 } from "./index_29be6ff5.js";
|
|
3
|
+
import { S as Sg } from "./index_096371b1.js";
|
|
4
|
+
import { F as Fg } from "./index_6cd7bc1a.js";
|
|
5
|
+
import { s } from "./index_b1028d5f.js";
|
|
6
|
+
import { d } from "./index_10812439.js";
|
|
7
|
+
import { w } from "./index_c232ca43.js";
|
|
8
|
+
import { v as vn$1 } from "./index_849386d3.js";
|
|
9
|
+
import "./index_3402bab8.js";
|
|
10
|
+
import "./index_2dc95f2a.js";
|
|
11
|
+
import "./index_a5ca5cc4.js";
|
|
12
|
+
import "./index_f8bc80e1.js";
|
|
13
|
+
import "./index_0652205a.js";
|
|
14
|
+
import "./index_aa71379e.js";
|
|
15
|
+
import "react";
|
|
16
|
+
import "@chakra-ui/react";
|
|
17
|
+
import "react-dom";
|
|
18
|
+
import "./index_0a6e5811.js";
|
|
19
|
+
import "./index_aa773d39.js";
|
|
20
|
+
const X = requireBrowser$8(), rn = dist.Buffer.alloc(1, 1), gt = dist.Buffer.alloc(1, 0);
|
|
21
|
+
function sn(n, e, t, r, o) {
|
|
22
|
+
let i = dist.Buffer.alloc(32, 0), s2 = dist.Buffer.alloc(32, 1);
|
|
23
|
+
i = X("sha256", i).update(s2).update(gt).update(e).update(n).update(o || "").digest(), s2 = X("sha256", i).update(s2).digest(), i = X("sha256", i).update(s2).update(rn).update(e).update(n).update(o || "").digest(), s2 = X("sha256", i).update(s2).digest(), s2 = X("sha256", i).update(s2).digest();
|
|
24
|
+
let a = s2;
|
|
25
|
+
for (; !r(a) || !t(a); )
|
|
26
|
+
i = X("sha256", i).update(s2).update(gt).digest(), s2 = X("sha256", i).update(s2).digest(), s2 = X("sha256", i).update(s2).digest(), a = s2;
|
|
27
|
+
return a;
|
|
28
|
+
}
|
|
29
|
+
var on = sn;
|
|
30
|
+
const un = Sg, cn = Fg.ec, ot = new cn("secp256k1"), fn = on, Se = dist.Buffer.alloc(32, 0), _e = dist.Buffer.from("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141", "hex"), wt = dist.Buffer.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f", "hex"), G = ot.curve.n, Mt = G.shrn(1), Me = ot.curve.g, Ae = "Expected Private", ie = "Expected Point", Ne = "Expected Tweak", At = "Expected Hash", an = "Expected Signature", ln = "Expected Extra Data (32 bytes)";
|
|
31
|
+
function xe(n) {
|
|
32
|
+
return dist.Buffer.isBuffer(n) && n.length === 32;
|
|
33
|
+
}
|
|
34
|
+
function De(n) {
|
|
35
|
+
return xe(n) ? n.compare(_e) < 0 : false;
|
|
36
|
+
}
|
|
37
|
+
function z(n) {
|
|
38
|
+
if (!dist.Buffer.isBuffer(n) || n.length < 33)
|
|
39
|
+
return false;
|
|
40
|
+
const e = n[0], t = n.slice(1, 33);
|
|
41
|
+
if (t.compare(Se) === 0 || t.compare(wt) >= 0)
|
|
42
|
+
return false;
|
|
43
|
+
if ((e === 2 || e === 3) && n.length === 33) {
|
|
44
|
+
try {
|
|
45
|
+
se(n);
|
|
46
|
+
} catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
const r = n.slice(33);
|
|
52
|
+
return r.compare(Se) === 0 || r.compare(wt) >= 0 ? false : e === 4 && n.length === 65;
|
|
53
|
+
}
|
|
54
|
+
function Nt(n) {
|
|
55
|
+
return n[0] !== 4;
|
|
56
|
+
}
|
|
57
|
+
function hn(n) {
|
|
58
|
+
return z(n) ? Nt(n) : false;
|
|
59
|
+
}
|
|
60
|
+
function H(n) {
|
|
61
|
+
return xe(n) ? n.compare(Se) > 0 && // > 0
|
|
62
|
+
n.compare(_e) < 0 : false;
|
|
63
|
+
}
|
|
64
|
+
function pn(n) {
|
|
65
|
+
const e = n.slice(0, 32), t = n.slice(32, 64);
|
|
66
|
+
return dist.Buffer.isBuffer(n) && n.length === 64 && e.compare(_e) < 0 && t.compare(_e) < 0;
|
|
67
|
+
}
|
|
68
|
+
function Ee(n, e) {
|
|
69
|
+
return n === void 0 && e !== void 0 ? Nt(e) : n === void 0 ? true : n;
|
|
70
|
+
}
|
|
71
|
+
function k(n) {
|
|
72
|
+
return new un(n);
|
|
73
|
+
}
|
|
74
|
+
function ve(n) {
|
|
75
|
+
return n.toArrayLike(dist.Buffer, "be", 32);
|
|
76
|
+
}
|
|
77
|
+
function se(n) {
|
|
78
|
+
return ot.curve.decodePoint(n);
|
|
79
|
+
}
|
|
80
|
+
function le(n, e) {
|
|
81
|
+
return dist.Buffer.from(n._encode(e));
|
|
82
|
+
}
|
|
83
|
+
function dn(n, e, t) {
|
|
84
|
+
if (!z(n))
|
|
85
|
+
throw new TypeError(ie);
|
|
86
|
+
if (!z(e))
|
|
87
|
+
throw new TypeError(ie);
|
|
88
|
+
const r = se(n), o = se(e), i = r.add(o);
|
|
89
|
+
if (i.isInfinity())
|
|
90
|
+
return null;
|
|
91
|
+
const s2 = Ee(t, n);
|
|
92
|
+
return le(i, s2);
|
|
93
|
+
}
|
|
94
|
+
function gn(n, e, t) {
|
|
95
|
+
if (!z(n))
|
|
96
|
+
throw new TypeError(ie);
|
|
97
|
+
if (!De(e))
|
|
98
|
+
throw new TypeError(Ne);
|
|
99
|
+
const r = Ee(t, n), o = se(n);
|
|
100
|
+
if (e.compare(Se) === 0)
|
|
101
|
+
return le(o, r);
|
|
102
|
+
const i = k(e), s2 = Me.mul(i), a = o.add(s2);
|
|
103
|
+
return a.isInfinity() ? null : le(a, r);
|
|
104
|
+
}
|
|
105
|
+
function wn(n, e) {
|
|
106
|
+
if (!z(n))
|
|
107
|
+
throw new TypeError(ie);
|
|
108
|
+
const t = se(n);
|
|
109
|
+
if (t.isInfinity())
|
|
110
|
+
throw new TypeError(ie);
|
|
111
|
+
const r = Ee(e, n);
|
|
112
|
+
return le(t, r);
|
|
113
|
+
}
|
|
114
|
+
function mn(n, e) {
|
|
115
|
+
if (!H(n))
|
|
116
|
+
throw new TypeError(Ae);
|
|
117
|
+
const t = k(n), r = Me.mul(t);
|
|
118
|
+
if (r.isInfinity())
|
|
119
|
+
return null;
|
|
120
|
+
const o = Ee(e);
|
|
121
|
+
return le(r, o);
|
|
122
|
+
}
|
|
123
|
+
function In(n, e, t) {
|
|
124
|
+
if (!z(n))
|
|
125
|
+
throw new TypeError(ie);
|
|
126
|
+
if (!De(e))
|
|
127
|
+
throw new TypeError(Ne);
|
|
128
|
+
const r = Ee(t, n), o = se(n), i = k(e), s2 = o.mul(i);
|
|
129
|
+
return s2.isInfinity() ? null : le(s2, r);
|
|
130
|
+
}
|
|
131
|
+
function xn(n, e) {
|
|
132
|
+
if (!H(n))
|
|
133
|
+
throw new TypeError(Ae);
|
|
134
|
+
if (!De(e))
|
|
135
|
+
throw new TypeError(Ne);
|
|
136
|
+
const t = k(n), r = k(e), o = ve(t.add(r).umod(G));
|
|
137
|
+
return H(o) ? o : null;
|
|
138
|
+
}
|
|
139
|
+
function En(n, e) {
|
|
140
|
+
if (!H(n))
|
|
141
|
+
throw new TypeError(Ae);
|
|
142
|
+
if (!De(e))
|
|
143
|
+
throw new TypeError(Ne);
|
|
144
|
+
const t = k(n), r = k(e), o = ve(t.sub(r).umod(G));
|
|
145
|
+
return H(o) ? o : null;
|
|
146
|
+
}
|
|
147
|
+
function Bn(n, e) {
|
|
148
|
+
return Dt(n, e);
|
|
149
|
+
}
|
|
150
|
+
function Tn(n, e, t) {
|
|
151
|
+
return Dt(n, e, t);
|
|
152
|
+
}
|
|
153
|
+
function Dt(n, e, t) {
|
|
154
|
+
if (!xe(n))
|
|
155
|
+
throw new TypeError(At);
|
|
156
|
+
if (!H(e))
|
|
157
|
+
throw new TypeError(Ae);
|
|
158
|
+
if (t !== void 0 && !xe(t))
|
|
159
|
+
throw new TypeError(ln);
|
|
160
|
+
const r = k(e), o = k(n);
|
|
161
|
+
let i, s2;
|
|
162
|
+
fn(n, e, function(l) {
|
|
163
|
+
const f = k(l), h = Me.mul(f);
|
|
164
|
+
return !(h.isInfinity() || (i = h.x.umod(G), i.isZero() === 0) || (s2 = f.invm(G).mul(o.add(r.mul(i))).umod(G), s2.isZero() === 0));
|
|
165
|
+
}, H, t), s2.cmp(Mt) > 0 && (s2 = G.sub(s2));
|
|
166
|
+
const c = dist.Buffer.allocUnsafe(64);
|
|
167
|
+
return ve(i).copy(c, 0), ve(s2).copy(c, 32), c;
|
|
168
|
+
}
|
|
169
|
+
function yn(n, e, t, r) {
|
|
170
|
+
if (!xe(n))
|
|
171
|
+
throw new TypeError(At);
|
|
172
|
+
if (!z(e))
|
|
173
|
+
throw new TypeError(ie);
|
|
174
|
+
if (!pn(t))
|
|
175
|
+
throw new TypeError(an);
|
|
176
|
+
const o = se(e), i = k(t.slice(0, 32)), s2 = k(t.slice(32, 64));
|
|
177
|
+
if (r && s2.cmp(Mt) > 0 || i.gtn(0) <= 0 || s2.gtn(0) <= 0)
|
|
178
|
+
return false;
|
|
179
|
+
const a = k(n), c = s2.invm(G), l = a.mul(c).umod(G), f = i.mul(c).umod(G), h = Me.mulAdd(l, o, f);
|
|
180
|
+
return h.isInfinity() ? false : h.x.umod(G).eq(i);
|
|
181
|
+
}
|
|
182
|
+
var kt = {
|
|
183
|
+
isPoint: z,
|
|
184
|
+
isPointCompressed: hn,
|
|
185
|
+
isPrivate: H,
|
|
186
|
+
pointAdd: dn,
|
|
187
|
+
pointAddScalar: gn,
|
|
188
|
+
pointCompress: wn,
|
|
189
|
+
pointFromScalar: mn,
|
|
190
|
+
pointMultiply: In,
|
|
191
|
+
privateAdd: xn,
|
|
192
|
+
privateSub: En,
|
|
193
|
+
sign: Bn,
|
|
194
|
+
signWithEntropy: Tn,
|
|
195
|
+
verify: yn
|
|
196
|
+
}, ye = requireSafeBuffer().Buffer;
|
|
197
|
+
function Sn(n) {
|
|
198
|
+
if (n.length >= 255)
|
|
199
|
+
throw new TypeError("Alphabet too long");
|
|
200
|
+
for (var e = new Uint8Array(256), t = 0; t < e.length; t++)
|
|
201
|
+
e[t] = 255;
|
|
202
|
+
for (var r = 0; r < n.length; r++) {
|
|
203
|
+
var o = n.charAt(r), i = o.charCodeAt(0);
|
|
204
|
+
if (e[i] !== 255)
|
|
205
|
+
throw new TypeError(o + " is ambiguous");
|
|
206
|
+
e[i] = r;
|
|
207
|
+
}
|
|
208
|
+
var s2 = n.length, a = n.charAt(0), c = Math.log(s2) / Math.log(256), l = Math.log(256) / Math.log(s2);
|
|
209
|
+
function f(w2) {
|
|
210
|
+
if ((Array.isArray(w2) || w2 instanceof Uint8Array) && (w2 = ye.from(w2)), !ye.isBuffer(w2))
|
|
211
|
+
throw new TypeError("Expected Buffer");
|
|
212
|
+
if (w2.length === 0)
|
|
213
|
+
return "";
|
|
214
|
+
for (var T = 0, y = 0, B = 0, m = w2.length; B !== m && w2[B] === 0; )
|
|
215
|
+
B++, T++;
|
|
216
|
+
for (var p = (m - B) * l + 1 >>> 0, d2 = new Uint8Array(p); B !== m; ) {
|
|
217
|
+
for (var E = w2[B], _ = 0, I = p - 1; (E !== 0 || _ < y) && I !== -1; I--, _++)
|
|
218
|
+
E += 256 * d2[I] >>> 0, d2[I] = E % s2 >>> 0, E = E / s2 >>> 0;
|
|
219
|
+
if (E !== 0)
|
|
220
|
+
throw new Error("Non-zero carry");
|
|
221
|
+
y = _, B++;
|
|
222
|
+
}
|
|
223
|
+
for (var b = p - y; b !== p && d2[b] === 0; )
|
|
224
|
+
b++;
|
|
225
|
+
for (var U = a.repeat(T); b < p; ++b)
|
|
226
|
+
U += n.charAt(d2[b]);
|
|
227
|
+
return U;
|
|
228
|
+
}
|
|
229
|
+
function h(w2) {
|
|
230
|
+
if (typeof w2 != "string")
|
|
231
|
+
throw new TypeError("Expected String");
|
|
232
|
+
if (w2.length === 0)
|
|
233
|
+
return ye.alloc(0);
|
|
234
|
+
for (var T = 0, y = 0, B = 0; w2[T] === a; )
|
|
235
|
+
y++, T++;
|
|
236
|
+
for (var m = (w2.length - T) * c + 1 >>> 0, p = new Uint8Array(m); w2[T]; ) {
|
|
237
|
+
var d2 = e[w2.charCodeAt(T)];
|
|
238
|
+
if (d2 === 255)
|
|
239
|
+
return;
|
|
240
|
+
for (var E = 0, _ = m - 1; (d2 !== 0 || E < B) && _ !== -1; _--, E++)
|
|
241
|
+
d2 += s2 * p[_] >>> 0, p[_] = d2 % 256 >>> 0, d2 = d2 / 256 >>> 0;
|
|
242
|
+
if (d2 !== 0)
|
|
243
|
+
throw new Error("Non-zero carry");
|
|
244
|
+
B = E, T++;
|
|
245
|
+
}
|
|
246
|
+
for (var I = m - B; I !== m && p[I] === 0; )
|
|
247
|
+
I++;
|
|
248
|
+
var b = ye.allocUnsafe(y + (m - I));
|
|
249
|
+
b.fill(0, 0, y);
|
|
250
|
+
for (var U = y; I !== m; )
|
|
251
|
+
b[U++] = p[I++];
|
|
252
|
+
return b;
|
|
253
|
+
}
|
|
254
|
+
function x(w2) {
|
|
255
|
+
var T = h(w2);
|
|
256
|
+
if (T)
|
|
257
|
+
return T;
|
|
258
|
+
throw new Error("Non-base" + s2 + " character");
|
|
259
|
+
}
|
|
260
|
+
return {
|
|
261
|
+
encode: f,
|
|
262
|
+
decodeUnsafe: h,
|
|
263
|
+
decode: x
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
var _n = Sn, vn = _n, bn = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz", Ct = vn(bn);
|
|
267
|
+
const Pn = /* @__PURE__ */ getDefaultExportFromCjs(Ct);
|
|
268
|
+
var Ve = Ct, On = requireSafeBuffer().Buffer, Rn = function(n) {
|
|
269
|
+
function e(i) {
|
|
270
|
+
var s2 = n(i);
|
|
271
|
+
return Ve.encode(On.concat([
|
|
272
|
+
i,
|
|
273
|
+
s2
|
|
274
|
+
], i.length + 4));
|
|
275
|
+
}
|
|
276
|
+
function t(i) {
|
|
277
|
+
var s2 = i.slice(0, -4), a = i.slice(-4), c = n(s2);
|
|
278
|
+
if (!(a[0] ^ c[0] | a[1] ^ c[1] | a[2] ^ c[2] | a[3] ^ c[3]))
|
|
279
|
+
return s2;
|
|
280
|
+
}
|
|
281
|
+
function r(i) {
|
|
282
|
+
var s2 = Ve.decodeUnsafe(i);
|
|
283
|
+
if (s2)
|
|
284
|
+
return t(s2);
|
|
285
|
+
}
|
|
286
|
+
function o(i) {
|
|
287
|
+
var s2 = Ve.decode(i), a = t(s2);
|
|
288
|
+
if (!a)
|
|
289
|
+
throw new Error("Invalid checksum");
|
|
290
|
+
return a;
|
|
291
|
+
}
|
|
292
|
+
return {
|
|
293
|
+
encode: e,
|
|
294
|
+
decode: o,
|
|
295
|
+
decodeUnsafe: r
|
|
296
|
+
};
|
|
297
|
+
}, mt = requireBrowser$9(), Un = Rn;
|
|
298
|
+
function Mn(n) {
|
|
299
|
+
var e = mt("sha256").update(n).digest();
|
|
300
|
+
return mt("sha256").update(e).digest();
|
|
301
|
+
}
|
|
302
|
+
var An = Un(Mn);
|
|
303
|
+
const Lt = /* @__PURE__ */ getDefaultExportFromCjs(An);
|
|
304
|
+
function Ye(n) {
|
|
305
|
+
const e = dist.Buffer.alloc(1 + n.length * 4);
|
|
306
|
+
return e[0] = n.length, n.forEach((t, r) => {
|
|
307
|
+
e.writeUInt32BE(t, 1 + 4 * r);
|
|
308
|
+
}), e;
|
|
309
|
+
}
|
|
310
|
+
function ut(n) {
|
|
311
|
+
const e = n ? F(n) : [];
|
|
312
|
+
return Ye(e);
|
|
313
|
+
}
|
|
314
|
+
function ct(n) {
|
|
315
|
+
return s.fromPathArray(n).toString();
|
|
316
|
+
}
|
|
317
|
+
function F(n) {
|
|
318
|
+
return s.fromString(n).toPathArray();
|
|
319
|
+
}
|
|
320
|
+
function It(n) {
|
|
321
|
+
const e = Lt.decode(n);
|
|
322
|
+
return e.slice(e.length - 33);
|
|
323
|
+
}
|
|
324
|
+
function xt(n) {
|
|
325
|
+
const e = Lt.decode(n);
|
|
326
|
+
return {
|
|
327
|
+
chaincode: e.slice(13, 13 + 32),
|
|
328
|
+
pubkey: e.slice(e.length - 33),
|
|
329
|
+
version: e.readUInt32BE(0)
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
function Nn(n) {
|
|
333
|
+
for (let e = n.length - 1; e >= 0; e--)
|
|
334
|
+
if (n[e] >= 2147483648)
|
|
335
|
+
return n.slice(0, e + 1);
|
|
336
|
+
return [];
|
|
337
|
+
}
|
|
338
|
+
var je = requireSafeBuffer().Buffer, Dn = 9007199254740991;
|
|
339
|
+
function ft(n) {
|
|
340
|
+
if (n < 0 || n > Dn || n % 1 !== 0)
|
|
341
|
+
throw new RangeError("value out of range");
|
|
342
|
+
}
|
|
343
|
+
function we(n, e, t) {
|
|
344
|
+
if (ft(n), e || (e = je.allocUnsafe(Kt(n))), !je.isBuffer(e))
|
|
345
|
+
throw new TypeError("buffer must be a Buffer instance");
|
|
346
|
+
return t || (t = 0), n < 253 ? (e.writeUInt8(n, t), we.bytes = 1) : n <= 65535 ? (e.writeUInt8(253, t), e.writeUInt16LE(n, t + 1), we.bytes = 3) : n <= 4294967295 ? (e.writeUInt8(254, t), e.writeUInt32LE(n, t + 1), we.bytes = 5) : (e.writeUInt8(255, t), e.writeUInt32LE(n >>> 0, t + 1), e.writeUInt32LE(n / 4294967296 | 0, t + 5), we.bytes = 9), e;
|
|
347
|
+
}
|
|
348
|
+
function me(n, e) {
|
|
349
|
+
if (!je.isBuffer(n))
|
|
350
|
+
throw new TypeError("buffer must be a Buffer instance");
|
|
351
|
+
e || (e = 0);
|
|
352
|
+
var t = n.readUInt8(e);
|
|
353
|
+
if (t < 253)
|
|
354
|
+
return me.bytes = 1, t;
|
|
355
|
+
if (t === 253)
|
|
356
|
+
return me.bytes = 3, n.readUInt16LE(e + 1);
|
|
357
|
+
if (t === 254)
|
|
358
|
+
return me.bytes = 5, n.readUInt32LE(e + 1);
|
|
359
|
+
me.bytes = 9;
|
|
360
|
+
var r = n.readUInt32LE(e + 1), o = n.readUInt32LE(e + 5), i = o * 4294967296 + r;
|
|
361
|
+
return ft(i), i;
|
|
362
|
+
}
|
|
363
|
+
function Kt(n) {
|
|
364
|
+
return ft(n), n < 253 ? 1 : n <= 65535 ? 3 : n <= 4294967295 ? 5 : 9;
|
|
365
|
+
}
|
|
366
|
+
var kn = { encode: we, decode: me, encodingLength: Kt };
|
|
367
|
+
const Ze = /* @__PURE__ */ getDefaultExportFromCjs(kn);
|
|
368
|
+
function Gt(n) {
|
|
369
|
+
if (n > Number.MAX_SAFE_INTEGER)
|
|
370
|
+
throw new Error("Can't convert numbers > MAX_SAFE_INT");
|
|
371
|
+
const e = dist.Buffer.alloc(8, 0);
|
|
372
|
+
for (let t = 0; t < e.length; t++) {
|
|
373
|
+
const r = n & 255;
|
|
374
|
+
e[t] = r, n = (n - r) / 256;
|
|
375
|
+
}
|
|
376
|
+
return e;
|
|
377
|
+
}
|
|
378
|
+
function Vt(n) {
|
|
379
|
+
let e = 0;
|
|
380
|
+
if (n.length != 8)
|
|
381
|
+
throw new Error("Expected Bufffer of lenght 8");
|
|
382
|
+
if (n[7] != 0)
|
|
383
|
+
throw new Error("Can't encode numbers > MAX_SAFE_INT");
|
|
384
|
+
if (n[6] > 31)
|
|
385
|
+
throw new Error("Can't encode numbers > MAX_SAFE_INT");
|
|
386
|
+
for (let t = n.length - 1; t >= 0; t--)
|
|
387
|
+
e = e * 256 + n[t];
|
|
388
|
+
return e;
|
|
389
|
+
}
|
|
390
|
+
class A {
|
|
391
|
+
constructor() {
|
|
392
|
+
this.bufs = [];
|
|
393
|
+
}
|
|
394
|
+
write(e, t) {
|
|
395
|
+
const r = dist.Buffer.alloc(e);
|
|
396
|
+
t(r), this.bufs.push(r);
|
|
397
|
+
}
|
|
398
|
+
writeUInt8(e) {
|
|
399
|
+
this.write(1, (t) => t.writeUInt8(e, 0));
|
|
400
|
+
}
|
|
401
|
+
writeInt32(e) {
|
|
402
|
+
this.write(4, (t) => t.writeInt32LE(e, 0));
|
|
403
|
+
}
|
|
404
|
+
writeUInt32(e) {
|
|
405
|
+
this.write(4, (t) => t.writeUInt32LE(e, 0));
|
|
406
|
+
}
|
|
407
|
+
writeUInt64(e) {
|
|
408
|
+
const t = Gt(e);
|
|
409
|
+
this.writeSlice(t);
|
|
410
|
+
}
|
|
411
|
+
writeVarInt(e) {
|
|
412
|
+
this.bufs.push(Ze.encode(e));
|
|
413
|
+
}
|
|
414
|
+
writeSlice(e) {
|
|
415
|
+
this.bufs.push(dist.Buffer.from(e));
|
|
416
|
+
}
|
|
417
|
+
writeVarSlice(e) {
|
|
418
|
+
this.writeVarInt(e.length), this.writeSlice(e);
|
|
419
|
+
}
|
|
420
|
+
buffer() {
|
|
421
|
+
return dist.Buffer.concat(this.bufs);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
class ee {
|
|
425
|
+
constructor(e, t = 0) {
|
|
426
|
+
this.buffer = e, this.offset = t;
|
|
427
|
+
}
|
|
428
|
+
available() {
|
|
429
|
+
return this.buffer.length - this.offset;
|
|
430
|
+
}
|
|
431
|
+
readUInt8() {
|
|
432
|
+
const e = this.buffer.readUInt8(this.offset);
|
|
433
|
+
return this.offset++, e;
|
|
434
|
+
}
|
|
435
|
+
readInt32() {
|
|
436
|
+
const e = this.buffer.readInt32LE(this.offset);
|
|
437
|
+
return this.offset += 4, e;
|
|
438
|
+
}
|
|
439
|
+
readUInt32() {
|
|
440
|
+
const e = this.buffer.readUInt32LE(this.offset);
|
|
441
|
+
return this.offset += 4, e;
|
|
442
|
+
}
|
|
443
|
+
readUInt64() {
|
|
444
|
+
const e = this.readSlice(8);
|
|
445
|
+
return Vt(e);
|
|
446
|
+
}
|
|
447
|
+
readVarInt() {
|
|
448
|
+
const e = Ze.decode(this.buffer, this.offset);
|
|
449
|
+
return this.offset += Ze.decode.bytes, e;
|
|
450
|
+
}
|
|
451
|
+
readSlice(e) {
|
|
452
|
+
if (this.buffer.length < this.offset + e)
|
|
453
|
+
throw new Error("Cannot read slice out of bounds");
|
|
454
|
+
const t = this.buffer.slice(this.offset, this.offset + e);
|
|
455
|
+
return this.offset += e, t;
|
|
456
|
+
}
|
|
457
|
+
readVarSlice() {
|
|
458
|
+
return this.readSlice(this.readVarInt());
|
|
459
|
+
}
|
|
460
|
+
readVector() {
|
|
461
|
+
const e = this.readVarInt(), t = [];
|
|
462
|
+
for (let r = 0; r < e; r++)
|
|
463
|
+
t.push(this.readVarSlice());
|
|
464
|
+
return t;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
const Y = 50, Cn = 1, Ft = 0, be = 4294967295, at = 1, qt = 118, lt = 169, ke = 20, Ln = 135, Wt = 136, Xt = 172;
|
|
468
|
+
var Kn = requireSha_js();
|
|
469
|
+
const Pe = /* @__PURE__ */ getDefaultExportFromCjs(Kn);
|
|
470
|
+
function he(n) {
|
|
471
|
+
return new RIPEMD160().update(Pe("sha256").update(n).digest()).digest();
|
|
472
|
+
}
|
|
473
|
+
class Gn {
|
|
474
|
+
constructor(e, t) {
|
|
475
|
+
this.psbt = e, this.masterFp = t;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
class Ce extends Gn {
|
|
479
|
+
spendingCondition(e) {
|
|
480
|
+
if (e.length != 1)
|
|
481
|
+
throw new Error("Expected single key, got " + e.length);
|
|
482
|
+
return this.singleKeyCondition(e[0]);
|
|
483
|
+
}
|
|
484
|
+
setInput(e, t, r, o, i) {
|
|
485
|
+
if (o.length != 1)
|
|
486
|
+
throw new Error("Expected single key, got " + o.length);
|
|
487
|
+
if (i.length != 1)
|
|
488
|
+
throw new Error("Expected single path, got " + i.length);
|
|
489
|
+
this.setSingleKeyInput(e, t, r, o[0], i[0]);
|
|
490
|
+
}
|
|
491
|
+
setOwnOutput(e, t, r, o) {
|
|
492
|
+
if (r.length != 1)
|
|
493
|
+
throw new Error("Expected single key, got " + r.length);
|
|
494
|
+
if (o.length != 1)
|
|
495
|
+
throw new Error("Expected single path, got " + o.length);
|
|
496
|
+
this.setSingleKeyOutput(e, t, r[0], o[0]);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
class Vn extends Ce {
|
|
500
|
+
singleKeyCondition(e) {
|
|
501
|
+
const t = new A(), r = he(e);
|
|
502
|
+
return t.writeSlice(dist.Buffer.from([qt, lt, ke])), t.writeSlice(r), t.writeSlice(dist.Buffer.from([Wt, Xt])), { scriptPubKey: t.buffer() };
|
|
503
|
+
}
|
|
504
|
+
setSingleKeyInput(e, t, r, o, i) {
|
|
505
|
+
if (!t)
|
|
506
|
+
throw new Error("Full input base transaction required");
|
|
507
|
+
this.psbt.setInputNonWitnessUtxo(e, t), this.psbt.setInputBip32Derivation(e, o, this.masterFp, i);
|
|
508
|
+
}
|
|
509
|
+
setSingleKeyOutput(e, t, r, o) {
|
|
510
|
+
this.psbt.setOutputBip32Derivation(e, r, this.masterFp, o);
|
|
511
|
+
}
|
|
512
|
+
getDescriptorTemplate() {
|
|
513
|
+
return "pkh(@0)";
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
class Fn extends Ce {
|
|
517
|
+
singleKeyCondition(e) {
|
|
518
|
+
const t = e.slice(1), r = new A(), o = this.getTaprootOutputKey(t);
|
|
519
|
+
return r.writeSlice(dist.Buffer.from([81, 32])), r.writeSlice(o), { scriptPubKey: r.buffer() };
|
|
520
|
+
}
|
|
521
|
+
setSingleKeyInput(e, t, r, o, i) {
|
|
522
|
+
const s2 = o.slice(1);
|
|
523
|
+
this.psbt.setInputTapBip32Derivation(e, s2, [], this.masterFp, i), this.psbt.setInputWitnessUtxo(e, r.amount, r.cond.scriptPubKey);
|
|
524
|
+
}
|
|
525
|
+
setSingleKeyOutput(e, t, r, o) {
|
|
526
|
+
const i = r.slice(1);
|
|
527
|
+
this.psbt.setOutputTapBip32Derivation(e, i, [], this.masterFp, o);
|
|
528
|
+
}
|
|
529
|
+
getDescriptorTemplate() {
|
|
530
|
+
return "tr(@0)";
|
|
531
|
+
}
|
|
532
|
+
/*
|
|
533
|
+
The following two functions are copied from wallet-btc and adapted.
|
|
534
|
+
They should be moved to a library to avoid code reuse.
|
|
535
|
+
*/
|
|
536
|
+
hashTapTweak(e) {
|
|
537
|
+
const t = crypto_1.sha256(dist.Buffer.from("TapTweak", "utf-8"));
|
|
538
|
+
return crypto_1.sha256(dist.Buffer.concat([t, t, e]));
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Calculates a taproot output key from an internal key. This output key will be
|
|
542
|
+
* used as witness program in a taproot output. The internal key is tweaked
|
|
543
|
+
* according to recommendation in BIP341:
|
|
544
|
+
* https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#cite_ref-22-0
|
|
545
|
+
*
|
|
546
|
+
* @param internalPubkey A 32 byte x-only taproot internal key
|
|
547
|
+
* @returns The output key
|
|
548
|
+
*/
|
|
549
|
+
getTaprootOutputKey(e) {
|
|
550
|
+
if (e.length != 32)
|
|
551
|
+
throw new Error("Expected 32 byte pubkey. Got " + e.length);
|
|
552
|
+
const t = dist.Buffer.concat([dist.Buffer.from([2]), e]), r = this.hashTapTweak(e);
|
|
553
|
+
return dist.Buffer.from(kt.pointAddScalar(t, r)).slice(1);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
class qn extends Ce {
|
|
557
|
+
singleKeyCondition(e) {
|
|
558
|
+
const t = new A(), r = this.createRedeemScript(e), o = he(r);
|
|
559
|
+
return t.writeSlice(dist.Buffer.from([lt, ke])), t.writeSlice(o), t.writeUInt8(Ln), { scriptPubKey: t.buffer(), redeemScript: r };
|
|
560
|
+
}
|
|
561
|
+
setSingleKeyInput(e, t, r, o, i) {
|
|
562
|
+
if (!t)
|
|
563
|
+
throw new Error("Full input base transaction required");
|
|
564
|
+
this.psbt.setInputNonWitnessUtxo(e, t), this.psbt.setInputBip32Derivation(e, o, this.masterFp, i);
|
|
565
|
+
const s2 = r.cond.redeemScript, a = this.createRedeemScript(o);
|
|
566
|
+
if (s2 && !a.equals(s2))
|
|
567
|
+
throw new Error(`User-supplied redeemScript ${s2.toString("hex")} doesn't
|
|
568
|
+
match expected ${a.toString("hex")} for input ${e}`);
|
|
569
|
+
this.psbt.setInputRedeemScript(e, a), this.psbt.setInputWitnessUtxo(e, r.amount, r.cond.scriptPubKey);
|
|
570
|
+
}
|
|
571
|
+
setSingleKeyOutput(e, t, r, o) {
|
|
572
|
+
this.psbt.setOutputRedeemScript(e, t.redeemScript), this.psbt.setOutputBip32Derivation(e, r, this.masterFp, o);
|
|
573
|
+
}
|
|
574
|
+
getDescriptorTemplate() {
|
|
575
|
+
return "sh(wpkh(@0))";
|
|
576
|
+
}
|
|
577
|
+
createRedeemScript(e) {
|
|
578
|
+
const t = he(e);
|
|
579
|
+
return dist.Buffer.concat([dist.Buffer.from("0014", "hex"), t]);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
class Wn extends Ce {
|
|
583
|
+
singleKeyCondition(e) {
|
|
584
|
+
const t = new A(), r = he(e);
|
|
585
|
+
return t.writeSlice(dist.Buffer.from([0, ke])), t.writeSlice(r), { scriptPubKey: t.buffer() };
|
|
586
|
+
}
|
|
587
|
+
setSingleKeyInput(e, t, r, o, i) {
|
|
588
|
+
if (!t)
|
|
589
|
+
throw new Error("Full input base transaction required");
|
|
590
|
+
this.psbt.setInputNonWitnessUtxo(e, t), this.psbt.setInputBip32Derivation(e, o, this.masterFp, i), this.psbt.setInputWitnessUtxo(e, r.amount, r.cond.scriptPubKey);
|
|
591
|
+
}
|
|
592
|
+
setSingleKeyOutput(e, t, r, o) {
|
|
593
|
+
this.psbt.setOutputBip32Derivation(e, r, this.masterFp, o);
|
|
594
|
+
}
|
|
595
|
+
getDescriptorTemplate() {
|
|
596
|
+
return "wpkh(@0)";
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
class te {
|
|
600
|
+
constructor(e, t = crypto_1.sha256) {
|
|
601
|
+
this.leaves = e, this.h = t;
|
|
602
|
+
const r = this.calculateRoot(e);
|
|
603
|
+
this.rootNode = r.root, this.leafNodes = r.leaves;
|
|
604
|
+
}
|
|
605
|
+
getRoot() {
|
|
606
|
+
return this.rootNode.hash;
|
|
607
|
+
}
|
|
608
|
+
size() {
|
|
609
|
+
return this.leaves.length;
|
|
610
|
+
}
|
|
611
|
+
getLeaves() {
|
|
612
|
+
return this.leaves;
|
|
613
|
+
}
|
|
614
|
+
getLeafHash(e) {
|
|
615
|
+
return this.leafNodes[e].hash;
|
|
616
|
+
}
|
|
617
|
+
getProof(e) {
|
|
618
|
+
if (e >= this.leaves.length)
|
|
619
|
+
throw Error("Index out of bounds");
|
|
620
|
+
return Qe(this.leafNodes[e]);
|
|
621
|
+
}
|
|
622
|
+
calculateRoot(e) {
|
|
623
|
+
const t = e.length;
|
|
624
|
+
if (t == 0)
|
|
625
|
+
return {
|
|
626
|
+
root: new Fe(void 0, void 0, dist.Buffer.alloc(32, 0)),
|
|
627
|
+
leaves: []
|
|
628
|
+
};
|
|
629
|
+
if (t == 1) {
|
|
630
|
+
const f = new Fe(void 0, void 0, e[0]);
|
|
631
|
+
return { root: f, leaves: [f] };
|
|
632
|
+
}
|
|
633
|
+
const r = $n(t), o = this.calculateRoot(e.slice(0, r)), i = this.calculateRoot(e.slice(r)), s2 = o.root, a = i.root, c = this.hashNode(s2.hash, a.hash), l = new Fe(s2, a, c);
|
|
634
|
+
return s2.parent = l, a.parent = l, { root: l, leaves: o.leaves.concat(i.leaves) };
|
|
635
|
+
}
|
|
636
|
+
hashNode(e, t) {
|
|
637
|
+
return this.h(dist.Buffer.concat([dist.Buffer.from([1]), e, t]));
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
function ne(n, e = crypto_1.sha256) {
|
|
641
|
+
return Xn(dist.Buffer.from([0]), n, e);
|
|
642
|
+
}
|
|
643
|
+
function Xn(n, e, t) {
|
|
644
|
+
return t(dist.Buffer.concat([n, e]));
|
|
645
|
+
}
|
|
646
|
+
class Fe {
|
|
647
|
+
constructor(e, t, r) {
|
|
648
|
+
this.leftChild = e, this.rightChild = t, this.hash = r;
|
|
649
|
+
}
|
|
650
|
+
isLeaf() {
|
|
651
|
+
return this.leftChild == null;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
function Qe(n) {
|
|
655
|
+
if (!n.parent)
|
|
656
|
+
return [];
|
|
657
|
+
if (n.parent.leftChild == n) {
|
|
658
|
+
if (!n.parent.rightChild)
|
|
659
|
+
throw new Error("Expected right child to exist");
|
|
660
|
+
return [n.parent.rightChild.hash, ...Qe(n.parent)];
|
|
661
|
+
} else {
|
|
662
|
+
if (!n.parent.leftChild)
|
|
663
|
+
throw new Error("Expected left child to exist");
|
|
664
|
+
return [n.parent.leftChild.hash, ...Qe(n.parent)];
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
function $n(n) {
|
|
668
|
+
if (n < 2)
|
|
669
|
+
throw Error("Expected n >= 2");
|
|
670
|
+
return zn(n) ? n / 2 : 1 << Math.floor(Math.log2(n));
|
|
671
|
+
}
|
|
672
|
+
function zn(n) {
|
|
673
|
+
return (n & n - 1) == 0;
|
|
674
|
+
}
|
|
675
|
+
class Et {
|
|
676
|
+
/**
|
|
677
|
+
* For now, we only support default descriptor templates.
|
|
678
|
+
*/
|
|
679
|
+
constructor(e, t) {
|
|
680
|
+
this.descriptorTemplate = e, this.keys = [t];
|
|
681
|
+
}
|
|
682
|
+
getWalletId() {
|
|
683
|
+
return crypto_1.sha256(this.serialize());
|
|
684
|
+
}
|
|
685
|
+
serialize() {
|
|
686
|
+
const e = this.keys.map((o) => dist.Buffer.from(o, "ascii")), t = new te(e.map((o) => ne(o))), r = new A();
|
|
687
|
+
return r.writeUInt8(1), r.writeUInt8(0), r.writeVarSlice(dist.Buffer.from(this.descriptorTemplate, "ascii")), r.writeVarInt(this.keys.length), r.writeSlice(t.getRoot()), r.buffer();
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
function Bt(n, e, t) {
|
|
691
|
+
const r = ct(e);
|
|
692
|
+
return `[${n.toString("hex")}${r.substring(1)}]${t}/**`;
|
|
693
|
+
}
|
|
694
|
+
function Hn(n) {
|
|
695
|
+
var e, t;
|
|
696
|
+
const r = new A();
|
|
697
|
+
r.writeUInt32(n.getGlobalTxVersion());
|
|
698
|
+
const o = !!n.getInputWitnessUtxo(0);
|
|
699
|
+
o && r.writeSlice(dist.Buffer.from([0, 1]));
|
|
700
|
+
const i = n.getGlobalInputCount();
|
|
701
|
+
r.writeVarInt(i);
|
|
702
|
+
const s2 = new A();
|
|
703
|
+
for (let c = 0; c < i; c++)
|
|
704
|
+
r.writeSlice(n.getInputPreviousTxid(c)), r.writeUInt32(n.getInputOutputIndex(c)), r.writeVarSlice((e = n.getInputFinalScriptsig(c)) !== null && e !== void 0 ? e : dist.Buffer.from([])), r.writeUInt32(n.getInputSequence(c)), o && s2.writeSlice(n.getInputFinalScriptwitness(c));
|
|
705
|
+
const a = n.getGlobalOutputCount();
|
|
706
|
+
r.writeVarInt(a);
|
|
707
|
+
for (let c = 0; c < a; c++)
|
|
708
|
+
r.writeUInt64(n.getOutputAmount(c)), r.writeVarSlice(n.getOutputScript(c));
|
|
709
|
+
return r.writeSlice(s2.buffer()), r.writeUInt32((t = n.getGlobalFallbackLocktime()) !== null && t !== void 0 ? t : 0), r.buffer();
|
|
710
|
+
}
|
|
711
|
+
var N;
|
|
712
|
+
(function(n) {
|
|
713
|
+
n[n.TX_VERSION = 2] = "TX_VERSION", n[n.FALLBACK_LOCKTIME = 3] = "FALLBACK_LOCKTIME", n[n.INPUT_COUNT = 4] = "INPUT_COUNT", n[n.OUTPUT_COUNT = 5] = "OUTPUT_COUNT", n[n.TX_MODIFIABLE = 6] = "TX_MODIFIABLE", n[n.VERSION = 251] = "VERSION";
|
|
714
|
+
})(N || (N = {}));
|
|
715
|
+
var S;
|
|
716
|
+
(function(n) {
|
|
717
|
+
n[n.NON_WITNESS_UTXO = 0] = "NON_WITNESS_UTXO", n[n.WITNESS_UTXO = 1] = "WITNESS_UTXO", n[n.PARTIAL_SIG = 2] = "PARTIAL_SIG", n[n.SIGHASH_TYPE = 3] = "SIGHASH_TYPE", n[n.REDEEM_SCRIPT = 4] = "REDEEM_SCRIPT", n[n.BIP32_DERIVATION = 6] = "BIP32_DERIVATION", n[n.FINAL_SCRIPTSIG = 7] = "FINAL_SCRIPTSIG", n[n.FINAL_SCRIPTWITNESS = 8] = "FINAL_SCRIPTWITNESS", n[n.PREVIOUS_TXID = 14] = "PREVIOUS_TXID", n[n.OUTPUT_INDEX = 15] = "OUTPUT_INDEX", n[n.SEQUENCE = 16] = "SEQUENCE", n[n.TAP_KEY_SIG = 19] = "TAP_KEY_SIG", n[n.TAP_BIP32_DERIVATION = 22] = "TAP_BIP32_DERIVATION";
|
|
718
|
+
})(S || (S = {}));
|
|
719
|
+
var L;
|
|
720
|
+
(function(n) {
|
|
721
|
+
n[n.REDEEM_SCRIPT = 0] = "REDEEM_SCRIPT", n[n.BIP_32_DERIVATION = 2] = "BIP_32_DERIVATION", n[n.AMOUNT = 3] = "AMOUNT", n[n.SCRIPT = 4] = "SCRIPT", n[n.TAP_BIP32_DERIVATION = 7] = "TAP_BIP32_DERIVATION";
|
|
722
|
+
})(L || (L = {}));
|
|
723
|
+
const Yn = dist.Buffer.from([112, 115, 98, 116, 255]);
|
|
724
|
+
class jn extends Error {
|
|
725
|
+
}
|
|
726
|
+
class $t {
|
|
727
|
+
constructor() {
|
|
728
|
+
this.globalMap = /* @__PURE__ */ new Map(), this.inputMaps = [], this.outputMaps = [];
|
|
729
|
+
}
|
|
730
|
+
setGlobalTxVersion(e) {
|
|
731
|
+
this.setGlobal(N.TX_VERSION, ue(e));
|
|
732
|
+
}
|
|
733
|
+
getGlobalTxVersion() {
|
|
734
|
+
return this.getGlobal(N.TX_VERSION).readUInt32LE(0);
|
|
735
|
+
}
|
|
736
|
+
setGlobalFallbackLocktime(e) {
|
|
737
|
+
this.setGlobal(N.FALLBACK_LOCKTIME, ue(e));
|
|
738
|
+
}
|
|
739
|
+
getGlobalFallbackLocktime() {
|
|
740
|
+
var e;
|
|
741
|
+
return (e = this.getGlobalOptional(N.FALLBACK_LOCKTIME)) === null || e === void 0 ? void 0 : e.readUInt32LE(0);
|
|
742
|
+
}
|
|
743
|
+
setGlobalInputCount(e) {
|
|
744
|
+
this.setGlobal(N.INPUT_COUNT, Tt(e));
|
|
745
|
+
}
|
|
746
|
+
getGlobalInputCount() {
|
|
747
|
+
return yt(this.getGlobal(N.INPUT_COUNT));
|
|
748
|
+
}
|
|
749
|
+
setGlobalOutputCount(e) {
|
|
750
|
+
this.setGlobal(N.OUTPUT_COUNT, Tt(e));
|
|
751
|
+
}
|
|
752
|
+
getGlobalOutputCount() {
|
|
753
|
+
return yt(this.getGlobal(N.OUTPUT_COUNT));
|
|
754
|
+
}
|
|
755
|
+
setGlobalTxModifiable(e) {
|
|
756
|
+
this.setGlobal(N.TX_MODIFIABLE, e);
|
|
757
|
+
}
|
|
758
|
+
getGlobalTxModifiable() {
|
|
759
|
+
return this.getGlobalOptional(N.TX_MODIFIABLE);
|
|
760
|
+
}
|
|
761
|
+
setGlobalPsbtVersion(e) {
|
|
762
|
+
this.setGlobal(N.VERSION, ue(e));
|
|
763
|
+
}
|
|
764
|
+
getGlobalPsbtVersion() {
|
|
765
|
+
return this.getGlobal(N.VERSION).readUInt32LE(0);
|
|
766
|
+
}
|
|
767
|
+
setInputNonWitnessUtxo(e, t) {
|
|
768
|
+
this.setInput(e, S.NON_WITNESS_UTXO, P(), t);
|
|
769
|
+
}
|
|
770
|
+
getInputNonWitnessUtxo(e) {
|
|
771
|
+
return this.getInputOptional(e, S.NON_WITNESS_UTXO, P());
|
|
772
|
+
}
|
|
773
|
+
setInputWitnessUtxo(e, t, r) {
|
|
774
|
+
const o = new A();
|
|
775
|
+
o.writeSlice(t), o.writeVarSlice(r), this.setInput(e, S.WITNESS_UTXO, P(), o.buffer());
|
|
776
|
+
}
|
|
777
|
+
getInputWitnessUtxo(e) {
|
|
778
|
+
const t = this.getInputOptional(e, S.WITNESS_UTXO, P());
|
|
779
|
+
if (!t)
|
|
780
|
+
return;
|
|
781
|
+
const r = new ee(t);
|
|
782
|
+
return { amount: r.readSlice(8), scriptPubKey: r.readVarSlice() };
|
|
783
|
+
}
|
|
784
|
+
setInputPartialSig(e, t, r) {
|
|
785
|
+
this.setInput(e, S.PARTIAL_SIG, t, r);
|
|
786
|
+
}
|
|
787
|
+
getInputPartialSig(e, t) {
|
|
788
|
+
return this.getInputOptional(e, S.PARTIAL_SIG, t);
|
|
789
|
+
}
|
|
790
|
+
setInputSighashType(e, t) {
|
|
791
|
+
this.setInput(e, S.SIGHASH_TYPE, P(), ue(t));
|
|
792
|
+
}
|
|
793
|
+
getInputSighashType(e) {
|
|
794
|
+
const t = this.getInputOptional(e, S.SIGHASH_TYPE, P());
|
|
795
|
+
if (t)
|
|
796
|
+
return t.readUInt32LE(0);
|
|
797
|
+
}
|
|
798
|
+
setInputRedeemScript(e, t) {
|
|
799
|
+
this.setInput(e, S.REDEEM_SCRIPT, P(), t);
|
|
800
|
+
}
|
|
801
|
+
getInputRedeemScript(e) {
|
|
802
|
+
return this.getInputOptional(e, S.REDEEM_SCRIPT, P());
|
|
803
|
+
}
|
|
804
|
+
setInputBip32Derivation(e, t, r, o) {
|
|
805
|
+
if (t.length != 33)
|
|
806
|
+
throw new Error("Invalid pubkey length: " + t.length);
|
|
807
|
+
this.setInput(e, S.BIP32_DERIVATION, t, this.encodeBip32Derivation(r, o));
|
|
808
|
+
}
|
|
809
|
+
getInputBip32Derivation(e, t) {
|
|
810
|
+
const r = this.getInputOptional(e, S.BIP32_DERIVATION, t);
|
|
811
|
+
if (r)
|
|
812
|
+
return this.decodeBip32Derivation(r);
|
|
813
|
+
}
|
|
814
|
+
setInputFinalScriptsig(e, t) {
|
|
815
|
+
this.setInput(e, S.FINAL_SCRIPTSIG, P(), t);
|
|
816
|
+
}
|
|
817
|
+
getInputFinalScriptsig(e) {
|
|
818
|
+
return this.getInputOptional(e, S.FINAL_SCRIPTSIG, P());
|
|
819
|
+
}
|
|
820
|
+
setInputFinalScriptwitness(e, t) {
|
|
821
|
+
this.setInput(e, S.FINAL_SCRIPTWITNESS, P(), t);
|
|
822
|
+
}
|
|
823
|
+
getInputFinalScriptwitness(e) {
|
|
824
|
+
return this.getInput(e, S.FINAL_SCRIPTWITNESS, P());
|
|
825
|
+
}
|
|
826
|
+
setInputPreviousTxId(e, t) {
|
|
827
|
+
this.setInput(e, S.PREVIOUS_TXID, P(), t);
|
|
828
|
+
}
|
|
829
|
+
getInputPreviousTxid(e) {
|
|
830
|
+
return this.getInput(e, S.PREVIOUS_TXID, P());
|
|
831
|
+
}
|
|
832
|
+
setInputOutputIndex(e, t) {
|
|
833
|
+
this.setInput(e, S.OUTPUT_INDEX, P(), ue(t));
|
|
834
|
+
}
|
|
835
|
+
getInputOutputIndex(e) {
|
|
836
|
+
return this.getInput(e, S.OUTPUT_INDEX, P()).readUInt32LE(0);
|
|
837
|
+
}
|
|
838
|
+
setInputSequence(e, t) {
|
|
839
|
+
this.setInput(e, S.SEQUENCE, P(), ue(t));
|
|
840
|
+
}
|
|
841
|
+
getInputSequence(e) {
|
|
842
|
+
var t, r;
|
|
843
|
+
return (r = (t = this.getInputOptional(e, S.SEQUENCE, P())) === null || t === void 0 ? void 0 : t.readUInt32LE(0)) !== null && r !== void 0 ? r : 4294967295;
|
|
844
|
+
}
|
|
845
|
+
setInputTapKeySig(e, t) {
|
|
846
|
+
this.setInput(e, S.TAP_KEY_SIG, P(), t);
|
|
847
|
+
}
|
|
848
|
+
getInputTapKeySig(e) {
|
|
849
|
+
return this.getInputOptional(e, S.TAP_KEY_SIG, P());
|
|
850
|
+
}
|
|
851
|
+
setInputTapBip32Derivation(e, t, r, o, i) {
|
|
852
|
+
if (t.length != 32)
|
|
853
|
+
throw new Error("Invalid pubkey length: " + t.length);
|
|
854
|
+
const s2 = this.encodeTapBip32Derivation(r, o, i);
|
|
855
|
+
this.setInput(e, S.TAP_BIP32_DERIVATION, t, s2);
|
|
856
|
+
}
|
|
857
|
+
getInputTapBip32Derivation(e, t) {
|
|
858
|
+
const r = this.getInput(e, S.TAP_BIP32_DERIVATION, t);
|
|
859
|
+
return this.decodeTapBip32Derivation(r);
|
|
860
|
+
}
|
|
861
|
+
getInputKeyDatas(e, t) {
|
|
862
|
+
return this.getKeyDatas(this.inputMaps[e], t);
|
|
863
|
+
}
|
|
864
|
+
setOutputRedeemScript(e, t) {
|
|
865
|
+
this.setOutput(e, L.REDEEM_SCRIPT, P(), t);
|
|
866
|
+
}
|
|
867
|
+
getOutputRedeemScript(e) {
|
|
868
|
+
return this.getOutput(e, L.REDEEM_SCRIPT, P());
|
|
869
|
+
}
|
|
870
|
+
setOutputBip32Derivation(e, t, r, o) {
|
|
871
|
+
this.setOutput(e, L.BIP_32_DERIVATION, t, this.encodeBip32Derivation(r, o));
|
|
872
|
+
}
|
|
873
|
+
getOutputBip32Derivation(e, t) {
|
|
874
|
+
const r = this.getOutput(e, L.BIP_32_DERIVATION, t);
|
|
875
|
+
return this.decodeBip32Derivation(r);
|
|
876
|
+
}
|
|
877
|
+
setOutputAmount(e, t) {
|
|
878
|
+
this.setOutput(e, L.AMOUNT, P(), Jn(t));
|
|
879
|
+
}
|
|
880
|
+
getOutputAmount(e) {
|
|
881
|
+
const t = this.getOutput(e, L.AMOUNT, P());
|
|
882
|
+
return Vt(t);
|
|
883
|
+
}
|
|
884
|
+
setOutputScript(e, t) {
|
|
885
|
+
this.setOutput(e, L.SCRIPT, P(), t);
|
|
886
|
+
}
|
|
887
|
+
getOutputScript(e) {
|
|
888
|
+
return this.getOutput(e, L.SCRIPT, P());
|
|
889
|
+
}
|
|
890
|
+
setOutputTapBip32Derivation(e, t, r, o, i) {
|
|
891
|
+
const s2 = this.encodeTapBip32Derivation(r, o, i);
|
|
892
|
+
this.setOutput(e, L.TAP_BIP32_DERIVATION, t, s2);
|
|
893
|
+
}
|
|
894
|
+
getOutputTapBip32Derivation(e, t) {
|
|
895
|
+
const r = this.getOutput(e, L.TAP_BIP32_DERIVATION, t);
|
|
896
|
+
return this.decodeTapBip32Derivation(r);
|
|
897
|
+
}
|
|
898
|
+
deleteInputEntries(e, t) {
|
|
899
|
+
this.inputMaps[e].forEach((o, i, s2) => {
|
|
900
|
+
this.isKeyType(i, t) && s2.delete(i);
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
copy(e) {
|
|
904
|
+
this.copyMap(this.globalMap, e.globalMap), this.copyMaps(this.inputMaps, e.inputMaps), this.copyMaps(this.outputMaps, e.outputMaps);
|
|
905
|
+
}
|
|
906
|
+
copyMaps(e, t) {
|
|
907
|
+
e.forEach((r, o) => {
|
|
908
|
+
const i = /* @__PURE__ */ new Map();
|
|
909
|
+
this.copyMap(r, i), t[o] = i;
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
copyMap(e, t) {
|
|
913
|
+
e.forEach((r, o) => t.set(o, dist.Buffer.from(r)));
|
|
914
|
+
}
|
|
915
|
+
serialize() {
|
|
916
|
+
const e = new A();
|
|
917
|
+
return e.writeSlice(dist.Buffer.from([112, 115, 98, 116, 255])), qe(e, this.globalMap), this.inputMaps.forEach((t) => {
|
|
918
|
+
qe(e, t);
|
|
919
|
+
}), this.outputMaps.forEach((t) => {
|
|
920
|
+
qe(e, t);
|
|
921
|
+
}), e.buffer();
|
|
922
|
+
}
|
|
923
|
+
deserialize(e) {
|
|
924
|
+
const t = new ee(e);
|
|
925
|
+
if (!t.readSlice(5).equals(Yn))
|
|
926
|
+
throw new Error("Invalid magic bytes");
|
|
927
|
+
for (; this.readKeyPair(this.globalMap, t); )
|
|
928
|
+
;
|
|
929
|
+
for (let r = 0; r < this.getGlobalInputCount(); r++)
|
|
930
|
+
for (this.inputMaps[r] = /* @__PURE__ */ new Map(); this.readKeyPair(this.inputMaps[r], t); )
|
|
931
|
+
;
|
|
932
|
+
for (let r = 0; r < this.getGlobalOutputCount(); r++)
|
|
933
|
+
for (this.outputMaps[r] = /* @__PURE__ */ new Map(); this.readKeyPair(this.outputMaps[r], t); )
|
|
934
|
+
;
|
|
935
|
+
}
|
|
936
|
+
readKeyPair(e, t) {
|
|
937
|
+
const r = t.readVarInt();
|
|
938
|
+
if (r == 0)
|
|
939
|
+
return false;
|
|
940
|
+
const o = t.readUInt8(), i = t.readSlice(r - 1), s2 = t.readVarSlice();
|
|
941
|
+
return We(e, o, i, s2), true;
|
|
942
|
+
}
|
|
943
|
+
getKeyDatas(e, t) {
|
|
944
|
+
const r = [];
|
|
945
|
+
return e.forEach((o, i) => {
|
|
946
|
+
this.isKeyType(i, [t]) && r.push(dist.Buffer.from(i.substring(2), "hex"));
|
|
947
|
+
}), r;
|
|
948
|
+
}
|
|
949
|
+
isKeyType(e, t) {
|
|
950
|
+
const r = dist.Buffer.from(e.substring(0, 2), "hex").readUInt8(0);
|
|
951
|
+
return t.some((o) => o == r);
|
|
952
|
+
}
|
|
953
|
+
setGlobal(e, t) {
|
|
954
|
+
const r = new Le(e, dist.Buffer.from([]));
|
|
955
|
+
this.globalMap.set(r.toString(), t);
|
|
956
|
+
}
|
|
957
|
+
getGlobal(e) {
|
|
958
|
+
return ge(this.globalMap, e, P(), false);
|
|
959
|
+
}
|
|
960
|
+
getGlobalOptional(e) {
|
|
961
|
+
return ge(this.globalMap, e, P(), true);
|
|
962
|
+
}
|
|
963
|
+
setInput(e, t, r, o) {
|
|
964
|
+
We(this.getMap(e, this.inputMaps), t, r, o);
|
|
965
|
+
}
|
|
966
|
+
getInput(e, t, r) {
|
|
967
|
+
return ge(this.inputMaps[e], t, r, false);
|
|
968
|
+
}
|
|
969
|
+
getInputOptional(e, t, r) {
|
|
970
|
+
return ge(this.inputMaps[e], t, r, true);
|
|
971
|
+
}
|
|
972
|
+
setOutput(e, t, r, o) {
|
|
973
|
+
We(this.getMap(e, this.outputMaps), t, r, o);
|
|
974
|
+
}
|
|
975
|
+
getOutput(e, t, r) {
|
|
976
|
+
return ge(this.outputMaps[e], t, r, false);
|
|
977
|
+
}
|
|
978
|
+
getMap(e, t) {
|
|
979
|
+
return t[e] ? t[e] : t[e] = /* @__PURE__ */ new Map();
|
|
980
|
+
}
|
|
981
|
+
encodeBip32Derivation(e, t) {
|
|
982
|
+
const r = new A();
|
|
983
|
+
return this.writeBip32Derivation(r, e, t), r.buffer();
|
|
984
|
+
}
|
|
985
|
+
decodeBip32Derivation(e) {
|
|
986
|
+
const t = new ee(e);
|
|
987
|
+
return this.readBip32Derivation(t);
|
|
988
|
+
}
|
|
989
|
+
writeBip32Derivation(e, t, r) {
|
|
990
|
+
e.writeSlice(t), r.forEach((o) => {
|
|
991
|
+
e.writeUInt32(o);
|
|
992
|
+
});
|
|
993
|
+
}
|
|
994
|
+
readBip32Derivation(e) {
|
|
995
|
+
const t = e.readSlice(4), r = [];
|
|
996
|
+
for (; e.offset < e.buffer.length; )
|
|
997
|
+
r.push(e.readUInt32());
|
|
998
|
+
return { masterFingerprint: t, path: r };
|
|
999
|
+
}
|
|
1000
|
+
encodeTapBip32Derivation(e, t, r) {
|
|
1001
|
+
const o = new A();
|
|
1002
|
+
return o.writeVarInt(e.length), e.forEach((i) => {
|
|
1003
|
+
o.writeSlice(i);
|
|
1004
|
+
}), this.writeBip32Derivation(o, t, r), o.buffer();
|
|
1005
|
+
}
|
|
1006
|
+
decodeTapBip32Derivation(e) {
|
|
1007
|
+
const t = new ee(e), r = t.readVarInt(), o = [];
|
|
1008
|
+
for (let s2 = 0; s2 < r; s2++)
|
|
1009
|
+
o.push(t.readSlice(32));
|
|
1010
|
+
const i = this.readBip32Derivation(t);
|
|
1011
|
+
return Object.assign({ hashes: o }, i);
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
function ge(n, e, t, r) {
|
|
1015
|
+
if (!n)
|
|
1016
|
+
throw Error("No such map");
|
|
1017
|
+
const o = new Le(e, t), i = n.get(o.toString());
|
|
1018
|
+
if (!i) {
|
|
1019
|
+
if (r)
|
|
1020
|
+
return;
|
|
1021
|
+
throw new jn(o.toString());
|
|
1022
|
+
}
|
|
1023
|
+
return dist.Buffer.from(i);
|
|
1024
|
+
}
|
|
1025
|
+
class Le {
|
|
1026
|
+
constructor(e, t) {
|
|
1027
|
+
this.keyType = e, this.keyData = t;
|
|
1028
|
+
}
|
|
1029
|
+
toString() {
|
|
1030
|
+
const e = new A();
|
|
1031
|
+
return this.toBuffer(e), e.buffer().toString("hex");
|
|
1032
|
+
}
|
|
1033
|
+
serialize(e) {
|
|
1034
|
+
e.writeVarInt(1 + this.keyData.length), this.toBuffer(e);
|
|
1035
|
+
}
|
|
1036
|
+
toBuffer(e) {
|
|
1037
|
+
e.writeUInt8(this.keyType), e.writeSlice(this.keyData);
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
class Zn {
|
|
1041
|
+
constructor(e, t) {
|
|
1042
|
+
this.key = e, this.value = t;
|
|
1043
|
+
}
|
|
1044
|
+
serialize(e) {
|
|
1045
|
+
this.key.serialize(e), e.writeVarSlice(this.value);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
function Qn(n) {
|
|
1049
|
+
return new Le(n.readUInt8(0), n.slice(1));
|
|
1050
|
+
}
|
|
1051
|
+
function qe(n, e) {
|
|
1052
|
+
for (const t of e.keys()) {
|
|
1053
|
+
const r = e.get(t);
|
|
1054
|
+
new Zn(Qn(dist.Buffer.from(t, "hex")), r).serialize(n);
|
|
1055
|
+
}
|
|
1056
|
+
n.writeUInt8(0);
|
|
1057
|
+
}
|
|
1058
|
+
function P() {
|
|
1059
|
+
return dist.Buffer.from([]);
|
|
1060
|
+
}
|
|
1061
|
+
function We(n, e, t, r) {
|
|
1062
|
+
const o = new Le(e, t);
|
|
1063
|
+
n.set(o.toString(), r);
|
|
1064
|
+
}
|
|
1065
|
+
function ue(n) {
|
|
1066
|
+
const e = dist.Buffer.alloc(4);
|
|
1067
|
+
return e.writeUInt32LE(n, 0), e;
|
|
1068
|
+
}
|
|
1069
|
+
function Jn(n) {
|
|
1070
|
+
return Gt(n);
|
|
1071
|
+
}
|
|
1072
|
+
function Tt(n) {
|
|
1073
|
+
const e = new A();
|
|
1074
|
+
return e.writeVarInt(n), e.buffer();
|
|
1075
|
+
}
|
|
1076
|
+
function yt(n) {
|
|
1077
|
+
return new ee(n).readVarInt();
|
|
1078
|
+
}
|
|
1079
|
+
function er(n) {
|
|
1080
|
+
const e = n.getGlobalInputCount();
|
|
1081
|
+
for (let t = 0; t < e; t++) {
|
|
1082
|
+
const r = n.getInputKeyDatas(t, S.PARTIAL_SIG), o = n.getInputTapKeySig(t);
|
|
1083
|
+
if (r.length == 0 && !o)
|
|
1084
|
+
throw Error(`No signature for input ${t} present`);
|
|
1085
|
+
if (r.length > 0) {
|
|
1086
|
+
if (r.length > 1)
|
|
1087
|
+
throw Error(`Expected exactly one signature, got ${r.length}`);
|
|
1088
|
+
if (o)
|
|
1089
|
+
throw Error("Both taproot and non-taproot signatures present.");
|
|
1090
|
+
const i = !!n.getInputWitnessUtxo(t), s2 = n.getInputRedeemScript(t), a = !!s2, c = n.getInputPartialSig(t, r[0]);
|
|
1091
|
+
if (!c)
|
|
1092
|
+
throw new Error("Expected partial signature for input " + t);
|
|
1093
|
+
if (i) {
|
|
1094
|
+
const l = new A();
|
|
1095
|
+
if (l.writeVarInt(2), l.writeVarInt(c.length), l.writeSlice(c), l.writeVarInt(r[0].length), l.writeSlice(r[0]), n.setInputFinalScriptwitness(t, l.buffer()), a) {
|
|
1096
|
+
if (!s2 || s2.length == 0)
|
|
1097
|
+
throw new Error("Expected non-empty redeemscript. Can't finalize intput " + t);
|
|
1098
|
+
const f = new A();
|
|
1099
|
+
f.writeUInt8(s2.length), f.writeSlice(s2), n.setInputFinalScriptsig(t, f.buffer());
|
|
1100
|
+
}
|
|
1101
|
+
} else {
|
|
1102
|
+
const l = new A();
|
|
1103
|
+
St(l, c), St(l, r[0]), n.setInputFinalScriptsig(t, l.buffer());
|
|
1104
|
+
}
|
|
1105
|
+
} else {
|
|
1106
|
+
const i = n.getInputTapKeySig(t);
|
|
1107
|
+
if (!i)
|
|
1108
|
+
throw Error("No taproot signature found");
|
|
1109
|
+
if (i.length != 64 && i.length != 65)
|
|
1110
|
+
throw Error("Unexpected length of schnorr signature.");
|
|
1111
|
+
const s2 = new A();
|
|
1112
|
+
s2.writeVarInt(1), s2.writeVarSlice(i), n.setInputFinalScriptwitness(t, s2.buffer());
|
|
1113
|
+
}
|
|
1114
|
+
tr(n, t);
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
function tr(n, e) {
|
|
1118
|
+
const t = [
|
|
1119
|
+
S.BIP32_DERIVATION,
|
|
1120
|
+
S.PARTIAL_SIG,
|
|
1121
|
+
S.TAP_BIP32_DERIVATION,
|
|
1122
|
+
S.TAP_KEY_SIG
|
|
1123
|
+
], r = !!n.getInputWitnessUtxo(e), o = !!n.getInputNonWitnessUtxo(e);
|
|
1124
|
+
r && o && t.push(S.NON_WITNESS_UTXO), n.deleteInputEntries(e, t);
|
|
1125
|
+
}
|
|
1126
|
+
function St(n, e) {
|
|
1127
|
+
if (e.length <= 75)
|
|
1128
|
+
n.writeUInt8(e.length);
|
|
1129
|
+
else if (e.length <= 256)
|
|
1130
|
+
n.writeUInt8(76), n.writeUInt8(e.length);
|
|
1131
|
+
else if (e.length <= 256 * 256) {
|
|
1132
|
+
n.writeUInt8(77);
|
|
1133
|
+
const t = dist.Buffer.alloc(2);
|
|
1134
|
+
t.writeUInt16LE(e.length, 0), n.writeSlice(t);
|
|
1135
|
+
}
|
|
1136
|
+
n.writeSlice(e);
|
|
1137
|
+
}
|
|
1138
|
+
function ce(n, e) {
|
|
1139
|
+
if (n[e] < 253)
|
|
1140
|
+
return [n[e], 1];
|
|
1141
|
+
if (n[e] === 253)
|
|
1142
|
+
return [(n[e + 2] << 8) + n[e + 1], 3];
|
|
1143
|
+
if (n[e] === 254)
|
|
1144
|
+
return [
|
|
1145
|
+
(n[e + 4] << 24) + (n[e + 3] << 16) + (n[e + 2] << 8) + n[e + 1],
|
|
1146
|
+
5
|
|
1147
|
+
];
|
|
1148
|
+
throw new Error("getVarint called with unexpected parameters");
|
|
1149
|
+
}
|
|
1150
|
+
function M(n) {
|
|
1151
|
+
if (n < 253) {
|
|
1152
|
+
const t = dist.Buffer.alloc(1);
|
|
1153
|
+
return t[0] = n, t;
|
|
1154
|
+
}
|
|
1155
|
+
if (n <= 65535) {
|
|
1156
|
+
const t = dist.Buffer.alloc(3);
|
|
1157
|
+
return t[0] = 253, t[1] = n & 255, t[2] = n >> 8 & 255, t;
|
|
1158
|
+
}
|
|
1159
|
+
const e = dist.Buffer.alloc(5);
|
|
1160
|
+
return e[0] = 254, e[1] = n & 255, e[2] = n >> 8 & 255, e[3] = n >> 16 & 255, e[4] = n >> 24 & 255, e;
|
|
1161
|
+
}
|
|
1162
|
+
function zt({ outputs: n }) {
|
|
1163
|
+
let e = dist.Buffer.alloc(0);
|
|
1164
|
+
return typeof n < "u" && (e = dist.Buffer.concat([e, M(n.length)]), n.forEach((t) => {
|
|
1165
|
+
e = dist.Buffer.concat([
|
|
1166
|
+
e,
|
|
1167
|
+
t.amount,
|
|
1168
|
+
M(t.script.length),
|
|
1169
|
+
t.script
|
|
1170
|
+
]);
|
|
1171
|
+
})), e;
|
|
1172
|
+
}
|
|
1173
|
+
function ht(n, e, t, r = []) {
|
|
1174
|
+
const o = r.includes("decred"), i = r.includes("zcash"), s2 = r.includes("bech32");
|
|
1175
|
+
let a = dist.Buffer.alloc(0);
|
|
1176
|
+
const c = typeof n.witness < "u" && !e;
|
|
1177
|
+
n.inputs.forEach((f) => {
|
|
1178
|
+
a = o || s2 ? dist.Buffer.concat([
|
|
1179
|
+
a,
|
|
1180
|
+
f.prevout,
|
|
1181
|
+
dist.Buffer.from([0]),
|
|
1182
|
+
f.sequence
|
|
1183
|
+
]) : dist.Buffer.concat([
|
|
1184
|
+
a,
|
|
1185
|
+
f.prevout,
|
|
1186
|
+
M(f.script.length),
|
|
1187
|
+
f.script,
|
|
1188
|
+
f.sequence
|
|
1189
|
+
]);
|
|
1190
|
+
});
|
|
1191
|
+
let l = zt(n);
|
|
1192
|
+
return typeof n.outputs < "u" && typeof n.locktime < "u" && (l = dist.Buffer.concat([
|
|
1193
|
+
l,
|
|
1194
|
+
c && n.witness || dist.Buffer.alloc(0),
|
|
1195
|
+
n.locktime,
|
|
1196
|
+
n.nExpiryHeight || dist.Buffer.alloc(0),
|
|
1197
|
+
n.extraData || dist.Buffer.alloc(0)
|
|
1198
|
+
])), i ? dist.Buffer.concat([
|
|
1199
|
+
n.version,
|
|
1200
|
+
n.nVersionGroupId || dist.Buffer.alloc(0),
|
|
1201
|
+
dist.Buffer.from([180, 208, 214, 194]),
|
|
1202
|
+
n.locktime || dist.Buffer.from([0, 0, 0, 0]),
|
|
1203
|
+
n.nExpiryHeight || dist.Buffer.from([0, 0, 0, 0]),
|
|
1204
|
+
c ? dist.Buffer.from("0001", "hex") : dist.Buffer.alloc(0),
|
|
1205
|
+
M(n.inputs.length),
|
|
1206
|
+
a,
|
|
1207
|
+
l
|
|
1208
|
+
]) : dist.Buffer.concat([
|
|
1209
|
+
n.version,
|
|
1210
|
+
t || dist.Buffer.alloc(0),
|
|
1211
|
+
n.nVersionGroupId || dist.Buffer.alloc(0),
|
|
1212
|
+
c ? dist.Buffer.from("0001", "hex") : dist.Buffer.alloc(0),
|
|
1213
|
+
M(n.inputs.length),
|
|
1214
|
+
a,
|
|
1215
|
+
l
|
|
1216
|
+
]);
|
|
1217
|
+
}
|
|
1218
|
+
var $ = globalThis && globalThis.__awaiter || function(n, e, t, r) {
|
|
1219
|
+
function o(i) {
|
|
1220
|
+
return i instanceof t ? i : new t(function(s2) {
|
|
1221
|
+
s2(i);
|
|
1222
|
+
});
|
|
1223
|
+
}
|
|
1224
|
+
return new (t || (t = Promise))(function(i, s2) {
|
|
1225
|
+
function a(f) {
|
|
1226
|
+
try {
|
|
1227
|
+
l(r.next(f));
|
|
1228
|
+
} catch (h) {
|
|
1229
|
+
s2(h);
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
function c(f) {
|
|
1233
|
+
try {
|
|
1234
|
+
l(r.throw(f));
|
|
1235
|
+
} catch (h) {
|
|
1236
|
+
s2(h);
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
function l(f) {
|
|
1240
|
+
f.done ? i(f.value) : o(f.value).then(a, c);
|
|
1241
|
+
}
|
|
1242
|
+
l((r = r.apply(n, e || [])).next());
|
|
1243
|
+
});
|
|
1244
|
+
};
|
|
1245
|
+
class nr {
|
|
1246
|
+
constructor(e) {
|
|
1247
|
+
this.client = e;
|
|
1248
|
+
}
|
|
1249
|
+
/**
|
|
1250
|
+
* This is a new method that allow users to get an xpub at a standard path.
|
|
1251
|
+
* Standard paths are described at
|
|
1252
|
+
* https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md#description
|
|
1253
|
+
*
|
|
1254
|
+
* This boils down to paths (N=0 for Bitcoin, N=1 for Testnet):
|
|
1255
|
+
* M/44'/N'/x'/**
|
|
1256
|
+
* M/48'/N'/x'/y'/**
|
|
1257
|
+
* M/49'/N'/x'/**
|
|
1258
|
+
* M/84'/N'/x'/**
|
|
1259
|
+
* M/86'/N'/x'/**
|
|
1260
|
+
*
|
|
1261
|
+
* The method was added because of added security in the hardware app v2+. The
|
|
1262
|
+
* new hardware app will allow export of any xpub up to and including the
|
|
1263
|
+
* deepest hardened key of standard derivation paths, whereas the old app
|
|
1264
|
+
* would allow export of any key.
|
|
1265
|
+
*
|
|
1266
|
+
* This caused an issue for callers of this class, who only had
|
|
1267
|
+
* getWalletPublicKey() to call which means they have to constuct xpub
|
|
1268
|
+
* themselves:
|
|
1269
|
+
*
|
|
1270
|
+
* Suppose a user of this class wants to create an account xpub on a standard
|
|
1271
|
+
* path, M/44'/0'/Z'. The user must get the parent key fingerprint (see BIP32)
|
|
1272
|
+
* by requesting the parent key M/44'/0'. The new app won't allow that, because
|
|
1273
|
+
* it only allows exporting deepest level hardened path. So the options are to
|
|
1274
|
+
* allow requesting M/44'/0' from the app, or to add a new function
|
|
1275
|
+
* "getWalletXpub".
|
|
1276
|
+
*
|
|
1277
|
+
* We opted for adding a new function, which can greatly simplify client code.
|
|
1278
|
+
*/
|
|
1279
|
+
getWalletXpub({ path: e, xpubVersion: t }) {
|
|
1280
|
+
return $(this, void 0, void 0, function* () {
|
|
1281
|
+
const r = F(e), o = yield this.client.getExtendedPubkey(false, r), i = xt(o);
|
|
1282
|
+
if (i.version != t)
|
|
1283
|
+
throw new Error(`Expected xpub version ${t} doesn't match the xpub version from the device ${i.version}`);
|
|
1284
|
+
return o;
|
|
1285
|
+
});
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
* This method returns a public key, a bitcoin address, and and a chaincode
|
|
1289
|
+
* for a specific derivation path.
|
|
1290
|
+
*
|
|
1291
|
+
* Limitation: If the path is not a leaf node of a standard path, the address
|
|
1292
|
+
* will be the empty string "", see this.getWalletAddress() for details.
|
|
1293
|
+
*/
|
|
1294
|
+
getWalletPublicKey(e, t) {
|
|
1295
|
+
var r, o;
|
|
1296
|
+
return $(this, void 0, void 0, function* () {
|
|
1297
|
+
if (!sr(e))
|
|
1298
|
+
throw Error(`non-standard path: ${e}`);
|
|
1299
|
+
const i = F(e), s2 = yield this.client.getExtendedPubkey(false, i), a = (r = t == null ? void 0 : t.verify) !== null && r !== void 0 ? r : false, c = yield this.getWalletAddress(i, rr((o = t == null ? void 0 : t.format) !== null && o !== void 0 ? o : "legacy"), a), l = xt(s2);
|
|
1300
|
+
return {
|
|
1301
|
+
publicKey: dist.Buffer.from(kt.pointCompress(l.pubkey, false)).toString("hex"),
|
|
1302
|
+
bitcoinAddress: c,
|
|
1303
|
+
chainCode: l.chaincode.toString("hex")
|
|
1304
|
+
};
|
|
1305
|
+
});
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* Get an address for the specified path.
|
|
1309
|
+
*
|
|
1310
|
+
* If display is true, we must get the address from the device, which would require
|
|
1311
|
+
* us to determine WalletPolicy. This requires two *extra* queries to the device, one
|
|
1312
|
+
* for the account xpub and one for master key fingerprint.
|
|
1313
|
+
*
|
|
1314
|
+
* If display is false we *could* generate the address ourselves, but chose to
|
|
1315
|
+
* get it from the device to save development time. However, it shouldn't take
|
|
1316
|
+
* too much time to implement local address generation.
|
|
1317
|
+
*
|
|
1318
|
+
* Moreover, if the path is not for a leaf, ie accountPath+/X/Y, there is no
|
|
1319
|
+
* way to get the address from the device. In this case we have to create it
|
|
1320
|
+
* ourselves, but we don't at this time, and instead return an empty ("") address.
|
|
1321
|
+
*/
|
|
1322
|
+
getWalletAddress(e, t, r) {
|
|
1323
|
+
return $(this, void 0, void 0, function* () {
|
|
1324
|
+
const o = Nn(e);
|
|
1325
|
+
if (o.length + 2 != e.length)
|
|
1326
|
+
return "";
|
|
1327
|
+
const i = yield this.client.getExtendedPubkey(false, o), s2 = yield this.client.getMasterFingerprint(), a = new Et(t, Bt(s2, o, i)), c = e.slice(-2, e.length);
|
|
1328
|
+
return this.client.getWalletAddress(a, dist.Buffer.alloc(32, 0), c[0], c[1], r);
|
|
1329
|
+
});
|
|
1330
|
+
}
|
|
1331
|
+
/**
|
|
1332
|
+
* Build and sign a transaction. See Btc.createPaymentTransaction for
|
|
1333
|
+
* details on how to use this method.
|
|
1334
|
+
*
|
|
1335
|
+
* This method will convert the legacy arguments, CreateTransactionArg, into
|
|
1336
|
+
* a psbt which is finally signed and finalized, and the extracted fully signed
|
|
1337
|
+
* transaction is returned.
|
|
1338
|
+
*/
|
|
1339
|
+
createPaymentTransaction(e) {
|
|
1340
|
+
return $(this, void 0, void 0, function* () {
|
|
1341
|
+
const t = e.inputs.length;
|
|
1342
|
+
if (t == 0)
|
|
1343
|
+
throw Error("No inputs");
|
|
1344
|
+
const r = new $t(), o = yield this.client.getMasterFingerprint(), i = ir(e, r, o);
|
|
1345
|
+
e.lockTime != null && r.setGlobalFallbackLocktime(e.lockTime), r.setGlobalInputCount(t), r.setGlobalPsbtVersion(2), r.setGlobalTxVersion(2);
|
|
1346
|
+
let s2 = 0;
|
|
1347
|
+
const a = () => {
|
|
1348
|
+
e.onDeviceStreaming && e.onDeviceStreaming({
|
|
1349
|
+
total: 2 * t,
|
|
1350
|
+
index: s2,
|
|
1351
|
+
progress: ++s2 / (2 * t)
|
|
1352
|
+
});
|
|
1353
|
+
};
|
|
1354
|
+
let c = "", l = [];
|
|
1355
|
+
for (let E = 0; E < t; E++) {
|
|
1356
|
+
a();
|
|
1357
|
+
const _ = F(e.associatedKeysets[E]);
|
|
1358
|
+
c == "" && (l = _.slice(0, -2), c = yield this.client.getExtendedPubkey(false, l)), yield this.setInput(r, E, e.inputs[E], _, i, o, e.sigHashType);
|
|
1359
|
+
}
|
|
1360
|
+
const f = dist.Buffer.from(e.outputScriptHex, "hex"), h = new ee(f), x = h.readVarInt();
|
|
1361
|
+
r.setGlobalOutputCount(x);
|
|
1362
|
+
const w2 = yield this.outputScriptAt(l, i, e.changePath);
|
|
1363
|
+
let T = !w2;
|
|
1364
|
+
for (let E = 0; E < x; E++) {
|
|
1365
|
+
const _ = Number(h.readUInt64()), I = h.readVarSlice();
|
|
1366
|
+
if (r.setOutputAmount(E, _), r.setOutputScript(E, I), w2 && I.equals(w2 == null ? void 0 : w2.cond.scriptPubKey)) {
|
|
1367
|
+
T = true;
|
|
1368
|
+
const U = F(e.changePath), q = w2.pubkey;
|
|
1369
|
+
i.setOwnOutput(E, w2.cond, [q], [U]);
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
if (!T)
|
|
1373
|
+
throw new Error("Change script not found among outputs! " + (w2 == null ? void 0 : w2.cond.scriptPubKey.toString("hex")));
|
|
1374
|
+
const y = Bt(o, l, c), B = new Et(i.getDescriptorTemplate(), y);
|
|
1375
|
+
e.onDeviceSignatureRequested && e.onDeviceSignatureRequested();
|
|
1376
|
+
let m = false;
|
|
1377
|
+
const p = () => {
|
|
1378
|
+
m || (m = true, e.onDeviceSignatureGranted && e.onDeviceSignatureGranted()), a();
|
|
1379
|
+
};
|
|
1380
|
+
return yield this.signPsbt(r, B, p), er(r), Hn(r).toString("hex");
|
|
1381
|
+
});
|
|
1382
|
+
}
|
|
1383
|
+
/**
|
|
1384
|
+
* Signs an arbitrary hex-formatted message with the private key at
|
|
1385
|
+
* the provided derivation path according to the Bitcoin Signature format
|
|
1386
|
+
* and returns v, r, s.
|
|
1387
|
+
*/
|
|
1388
|
+
signMessage({ path: e, messageHex: t }) {
|
|
1389
|
+
return $(this, void 0, void 0, function* () {
|
|
1390
|
+
const r = F(e), o = dist.Buffer.from(t, "hex"), i = yield this.client.signMessage(o, r), s2 = dist.Buffer.from(i, "base64"), a = s2.readUInt8() - 27 - 4, c = s2.slice(1, 33).toString("hex"), l = s2.slice(33, 65).toString("hex");
|
|
1391
|
+
return {
|
|
1392
|
+
v: a,
|
|
1393
|
+
r: c,
|
|
1394
|
+
s: l
|
|
1395
|
+
};
|
|
1396
|
+
});
|
|
1397
|
+
}
|
|
1398
|
+
/**
|
|
1399
|
+
* Calculates an output script along with public key and possible redeemScript
|
|
1400
|
+
* from a path and accountType. The accountPath must be a prefix of path.
|
|
1401
|
+
*
|
|
1402
|
+
* @returns an object with output script (property "script"), redeemScript (if
|
|
1403
|
+
* wrapped p2wpkh), and pubkey at provided path. The values of these three
|
|
1404
|
+
* properties depend on the accountType used.
|
|
1405
|
+
*/
|
|
1406
|
+
outputScriptAt(e, t, r) {
|
|
1407
|
+
return $(this, void 0, void 0, function* () {
|
|
1408
|
+
if (!r)
|
|
1409
|
+
return;
|
|
1410
|
+
const o = F(r);
|
|
1411
|
+
for (let c = 0; c < e.length; c++)
|
|
1412
|
+
if (e[c] != o[c])
|
|
1413
|
+
throw new Error(`Path ${r} not in account ${ct(e)}`);
|
|
1414
|
+
const i = yield this.client.getExtendedPubkey(false, o), s2 = It(i);
|
|
1415
|
+
return { cond: t.spendingCondition([s2]), pubkey: s2 };
|
|
1416
|
+
});
|
|
1417
|
+
}
|
|
1418
|
+
/**
|
|
1419
|
+
* Adds relevant data about an input to the psbt. This includes sequence,
|
|
1420
|
+
* previous txid, output index, spent UTXO, redeem script for wrapped p2wpkh,
|
|
1421
|
+
* public key and its derivation path.
|
|
1422
|
+
*/
|
|
1423
|
+
setInput(e, t, r, o, i, s2, a) {
|
|
1424
|
+
return $(this, void 0, void 0, function* () {
|
|
1425
|
+
const c = r[0], l = r[1], f = r[2] ? dist.Buffer.from(r[2], "hex") : void 0, h = r[3];
|
|
1426
|
+
h != null && e.setInputSequence(t, h), a != null && e.setInputSighashType(t, a);
|
|
1427
|
+
const x = ht(c, true), w2 = crypto_1.hash256(x), T = yield this.client.getExtendedPubkey(false, o), y = It(T);
|
|
1428
|
+
if (!c.outputs)
|
|
1429
|
+
throw Error("Missing outputs array in transaction to sign");
|
|
1430
|
+
const B = c.outputs[l], p = { cond: {
|
|
1431
|
+
scriptPubKey: B.script,
|
|
1432
|
+
redeemScript: f
|
|
1433
|
+
}, amount: B.amount };
|
|
1434
|
+
i.setInput(t, x, p, [y], [o]), e.setInputPreviousTxId(t, w2), e.setInputOutputIndex(t, l);
|
|
1435
|
+
});
|
|
1436
|
+
}
|
|
1437
|
+
/**
|
|
1438
|
+
* This implements the "Signer" role of the BIP370 transaction signing
|
|
1439
|
+
* process.
|
|
1440
|
+
*
|
|
1441
|
+
* It ssks the hardware device to sign the a psbt using the specified wallet
|
|
1442
|
+
* policy. This method assumes BIP32 derived keys are used for all inputs, see
|
|
1443
|
+
* comment in-line. The signatures returned from the hardware device is added
|
|
1444
|
+
* to the appropriate input fields of the PSBT.
|
|
1445
|
+
*/
|
|
1446
|
+
signPsbt(e, t, r) {
|
|
1447
|
+
return $(this, void 0, void 0, function* () {
|
|
1448
|
+
(yield this.client.signPsbt(e, t, dist.Buffer.alloc(32, 0), r)).forEach((i, s2) => {
|
|
1449
|
+
const a = e.getInputKeyDatas(s2, S.BIP32_DERIVATION);
|
|
1450
|
+
let c;
|
|
1451
|
+
if (a.length != 1) {
|
|
1452
|
+
if (c = e.getInputKeyDatas(s2, S.TAP_BIP32_DERIVATION), c.length == 0)
|
|
1453
|
+
throw Error(`Missing pubkey derivation for input ${s2}`);
|
|
1454
|
+
e.setInputTapKeySig(s2, i);
|
|
1455
|
+
} else
|
|
1456
|
+
c = a[0], e.setInputPartialSig(s2, c, i);
|
|
1457
|
+
});
|
|
1458
|
+
});
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
function rr(n) {
|
|
1462
|
+
if (n == "legacy")
|
|
1463
|
+
return "pkh(@0)";
|
|
1464
|
+
if (n == "p2sh")
|
|
1465
|
+
return "sh(wpkh(@0))";
|
|
1466
|
+
if (n == "bech32")
|
|
1467
|
+
return "wpkh(@0)";
|
|
1468
|
+
if (n == "bech32m")
|
|
1469
|
+
return "tr(@0)";
|
|
1470
|
+
throw new Error("Unsupported address format " + n);
|
|
1471
|
+
}
|
|
1472
|
+
function ir(n, e, t) {
|
|
1473
|
+
return n.additionals.includes("bech32m") ? new Fn(e, t) : n.additionals.includes("bech32") ? new Wn(e, t) : n.segwit ? new qn(e, t) : new Vn(e, t);
|
|
1474
|
+
}
|
|
1475
|
+
function sr(n) {
|
|
1476
|
+
const t = F(n), r = (s2) => s2 >= 2147483648, o = (s2) => s2 === void 0 || s2 < 2147483648, i = (s2) => s2 === void 0 || s2 === 0 || s2 === 1;
|
|
1477
|
+
return !!(t.length >= 3 && t.length <= 5 && [44 + 2147483648, 49 + 2147483648, 84 + 2147483648, 86 + 2147483648].some((s2) => s2 == t[0]) && [0 + 2147483648, 1 + 2147483648].some((s2) => s2 == t[1]) && r(t[2]) && i(t[3]) && o(t[4]) || t.length >= 4 && t.length <= 6 && 48 + 2147483648 == t[0] && [0 + 2147483648, 1 + 2147483648].some((s2) => s2 == t[1]) && r(t[2]) && r(t[3]) && i(t[4]) && o(t[5]));
|
|
1478
|
+
}
|
|
1479
|
+
var or = globalThis && globalThis.__awaiter || function(n, e, t, r) {
|
|
1480
|
+
function o(i) {
|
|
1481
|
+
return i instanceof t ? i : new t(function(s2) {
|
|
1482
|
+
s2(i);
|
|
1483
|
+
});
|
|
1484
|
+
}
|
|
1485
|
+
return new (t || (t = Promise))(function(i, s2) {
|
|
1486
|
+
function a(f) {
|
|
1487
|
+
try {
|
|
1488
|
+
l(r.next(f));
|
|
1489
|
+
} catch (h) {
|
|
1490
|
+
s2(h);
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
function c(f) {
|
|
1494
|
+
try {
|
|
1495
|
+
l(r.throw(f));
|
|
1496
|
+
} catch (h) {
|
|
1497
|
+
s2(h);
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
function l(f) {
|
|
1501
|
+
f.done ? i(f.value) : o(f.value).then(a, c);
|
|
1502
|
+
}
|
|
1503
|
+
l((r = r.apply(n, e || [])).next());
|
|
1504
|
+
});
|
|
1505
|
+
};
|
|
1506
|
+
const _t = {
|
|
1507
|
+
legacy: 0,
|
|
1508
|
+
p2sh: 1,
|
|
1509
|
+
bech32: 2,
|
|
1510
|
+
cashaddr: 3
|
|
1511
|
+
};
|
|
1512
|
+
function Je(n, e) {
|
|
1513
|
+
return or(this, void 0, void 0, function* () {
|
|
1514
|
+
const { path: t, verify: r, format: o } = Object.assign({ verify: false, format: "legacy" }, e);
|
|
1515
|
+
if (!(o in _t))
|
|
1516
|
+
throw new Error("btc.getWalletPublicKey invalid format=" + o);
|
|
1517
|
+
const i = ut(t), s2 = r ? 1 : 0, a = _t[o], c = yield n.send(224, 64, s2, a, i), l = c[0], f = c[1 + l], h = c.slice(1, 1 + l).toString("hex"), x = c.slice(1 + l + 1, 1 + l + 1 + f).toString("ascii"), w2 = c.slice(1 + l + 1 + f, 1 + l + 1 + f + 32).toString("hex");
|
|
1518
|
+
return {
|
|
1519
|
+
publicKey: h,
|
|
1520
|
+
bitcoinAddress: x,
|
|
1521
|
+
chainCode: w2
|
|
1522
|
+
};
|
|
1523
|
+
});
|
|
1524
|
+
}
|
|
1525
|
+
var et = globalThis && globalThis.__awaiter || function(n, e, t, r) {
|
|
1526
|
+
function o(i) {
|
|
1527
|
+
return i instanceof t ? i : new t(function(s2) {
|
|
1528
|
+
s2(i);
|
|
1529
|
+
});
|
|
1530
|
+
}
|
|
1531
|
+
return new (t || (t = Promise))(function(i, s2) {
|
|
1532
|
+
function a(f) {
|
|
1533
|
+
try {
|
|
1534
|
+
l(r.next(f));
|
|
1535
|
+
} catch (h) {
|
|
1536
|
+
s2(h);
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
function c(f) {
|
|
1540
|
+
try {
|
|
1541
|
+
l(r.throw(f));
|
|
1542
|
+
} catch (h) {
|
|
1543
|
+
s2(h);
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
function l(f) {
|
|
1547
|
+
f.done ? i(f.value) : o(f.value).then(a, c);
|
|
1548
|
+
}
|
|
1549
|
+
l((r = r.apply(n, e || [])).next());
|
|
1550
|
+
});
|
|
1551
|
+
};
|
|
1552
|
+
function fe(n, e, t) {
|
|
1553
|
+
return et(this, void 0, void 0, function* () {
|
|
1554
|
+
let r, o = false;
|
|
1555
|
+
if (typeof t == "number") {
|
|
1556
|
+
o = true;
|
|
1557
|
+
const a = dist.Buffer.alloc(4);
|
|
1558
|
+
a.writeUInt32BE(t, 0), r = dist.Buffer.concat([a, e], e.length + 4);
|
|
1559
|
+
} else
|
|
1560
|
+
r = e;
|
|
1561
|
+
const i = yield n.send(224, 66, o ? 0 : 128, 0, r);
|
|
1562
|
+
return i.slice(0, i.length - 2).toString("hex");
|
|
1563
|
+
});
|
|
1564
|
+
}
|
|
1565
|
+
function pt(n, e, t, r = []) {
|
|
1566
|
+
return et(this, void 0, void 0, function* () {
|
|
1567
|
+
const { version: o, inputs: i, outputs: s2, locktime: a, nExpiryHeight: c, extraData: l } = t;
|
|
1568
|
+
if (!s2 || !a)
|
|
1569
|
+
throw new Error("getTrustedInput: locktime & outputs is expected");
|
|
1570
|
+
const f = r.includes("decred"), h = r.includes("stealthcoin"), x = (m, p) => et(this, void 0, void 0, function* () {
|
|
1571
|
+
const d2 = p || dist.Buffer.alloc(0), E = [];
|
|
1572
|
+
let _ = 0;
|
|
1573
|
+
for (; _ !== m.length; ) {
|
|
1574
|
+
const b = m.length - _ > Y ? Y : m.length - _;
|
|
1575
|
+
_ + b !== m.length ? E.push(m.slice(_, _ + b)) : E.push(dist.Buffer.concat([m.slice(_, _ + b), d2])), _ += b;
|
|
1576
|
+
}
|
|
1577
|
+
m.length === 0 && E.push(d2);
|
|
1578
|
+
let I;
|
|
1579
|
+
for (const b of E)
|
|
1580
|
+
I = yield fe(n, b);
|
|
1581
|
+
return I;
|
|
1582
|
+
}), w$1 = (m) => fe(n, m);
|
|
1583
|
+
yield fe(n, dist.Buffer.concat([
|
|
1584
|
+
t.version,
|
|
1585
|
+
t.timestamp || dist.Buffer.alloc(0),
|
|
1586
|
+
t.nVersionGroupId || dist.Buffer.alloc(0),
|
|
1587
|
+
M(i.length)
|
|
1588
|
+
]), e);
|
|
1589
|
+
for (const m of i) {
|
|
1590
|
+
const p = h && dist.Buffer.compare(o, dist.Buffer.from([2, 0, 0, 0])) === 0, d2 = f ? m.tree || dist.Buffer.from([0]) : dist.Buffer.alloc(0), E = dist.Buffer.concat([
|
|
1591
|
+
m.prevout,
|
|
1592
|
+
d2,
|
|
1593
|
+
p ? dist.Buffer.from([0]) : M(m.script.length)
|
|
1594
|
+
]);
|
|
1595
|
+
yield fe(n, E), yield f ? w$1(dist.Buffer.concat([m.script, m.sequence])) : p ? w$1(m.sequence) : x(m.script, m.sequence);
|
|
1596
|
+
}
|
|
1597
|
+
yield fe(n, M(s2.length));
|
|
1598
|
+
for (const m of s2) {
|
|
1599
|
+
const p = dist.Buffer.concat([
|
|
1600
|
+
m.amount,
|
|
1601
|
+
f ? dist.Buffer.from([0, 0]) : dist.Buffer.alloc(0),
|
|
1602
|
+
M(m.script.length),
|
|
1603
|
+
m.script
|
|
1604
|
+
]);
|
|
1605
|
+
yield fe(n, p);
|
|
1606
|
+
}
|
|
1607
|
+
const T = [];
|
|
1608
|
+
c && c.length > 0 && T.push(c), l && l.length > 0 && T.push(l);
|
|
1609
|
+
let y;
|
|
1610
|
+
if (T.length) {
|
|
1611
|
+
const m = dist.Buffer.concat(T);
|
|
1612
|
+
y = f ? m : dist.Buffer.concat([M(m.length), m]);
|
|
1613
|
+
}
|
|
1614
|
+
const B = yield x(dist.Buffer.concat([a, y || dist.Buffer.alloc(0)]));
|
|
1615
|
+
return w(B, "missing result in processScriptBlocks"), B;
|
|
1616
|
+
});
|
|
1617
|
+
}
|
|
1618
|
+
var ur = globalThis && globalThis.__awaiter || function(n, e, t, r) {
|
|
1619
|
+
function o(i) {
|
|
1620
|
+
return i instanceof t ? i : new t(function(s2) {
|
|
1621
|
+
s2(i);
|
|
1622
|
+
});
|
|
1623
|
+
}
|
|
1624
|
+
return new (t || (t = Promise))(function(i, s2) {
|
|
1625
|
+
function a(f) {
|
|
1626
|
+
try {
|
|
1627
|
+
l(r.next(f));
|
|
1628
|
+
} catch (h) {
|
|
1629
|
+
s2(h);
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
function c(f) {
|
|
1633
|
+
try {
|
|
1634
|
+
l(r.throw(f));
|
|
1635
|
+
} catch (h) {
|
|
1636
|
+
s2(h);
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
function l(f) {
|
|
1640
|
+
f.done ? i(f.value) : o(f.value).then(a, c);
|
|
1641
|
+
}
|
|
1642
|
+
l((r = r.apply(n, e || [])).next());
|
|
1643
|
+
});
|
|
1644
|
+
};
|
|
1645
|
+
function Xe(n, e, t, r, o = false, i = false, s2 = []) {
|
|
1646
|
+
const a = s2.includes("cashaddr") ? 3 : o ? s2.includes("sapling") ? 5 : i ? 4 : 2 : 0;
|
|
1647
|
+
return n.send(224, 68, t ? 0 : 128, e ? a : 128, r);
|
|
1648
|
+
}
|
|
1649
|
+
function Oe(n, e, t, r, o = false, i = false, s2 = [], a = false) {
|
|
1650
|
+
return ur(this, void 0, void 0, function* () {
|
|
1651
|
+
let c = dist.Buffer.concat([
|
|
1652
|
+
t.version,
|
|
1653
|
+
t.timestamp || dist.Buffer.alloc(0),
|
|
1654
|
+
t.nVersionGroupId || dist.Buffer.alloc(0),
|
|
1655
|
+
M(t.inputs.length)
|
|
1656
|
+
]);
|
|
1657
|
+
yield Xe(n, e, true, c, o, i, s2);
|
|
1658
|
+
let l = 0;
|
|
1659
|
+
const f = s2.includes("decred");
|
|
1660
|
+
for (const h of t.inputs) {
|
|
1661
|
+
let x;
|
|
1662
|
+
const w2 = r[l].value;
|
|
1663
|
+
o ? a && r[l].trustedInput ? x = dist.Buffer.from([1, w2.length]) : x = dist.Buffer.from([2]) : r[l].trustedInput ? x = dist.Buffer.from([1, r[l].value.length]) : x = dist.Buffer.from([0]), c = dist.Buffer.concat([
|
|
1664
|
+
x,
|
|
1665
|
+
w2,
|
|
1666
|
+
f ? dist.Buffer.from([0]) : dist.Buffer.alloc(0),
|
|
1667
|
+
M(h.script.length)
|
|
1668
|
+
]), yield Xe(n, e, false, c, o, i, s2);
|
|
1669
|
+
const T = [];
|
|
1670
|
+
let y = 0;
|
|
1671
|
+
if (h.script.length === 0)
|
|
1672
|
+
T.push(h.sequence);
|
|
1673
|
+
else
|
|
1674
|
+
for (; y !== h.script.length; ) {
|
|
1675
|
+
const B = h.script.length - y > Y ? Y : h.script.length - y;
|
|
1676
|
+
y + B !== h.script.length ? T.push(h.script.slice(y, y + B)) : T.push(dist.Buffer.concat([h.script.slice(y, y + B), h.sequence])), y += B;
|
|
1677
|
+
}
|
|
1678
|
+
for (const B of T)
|
|
1679
|
+
yield Xe(n, e, false, B, o, i, s2);
|
|
1680
|
+
l++;
|
|
1681
|
+
}
|
|
1682
|
+
});
|
|
1683
|
+
}
|
|
1684
|
+
function dt(n, e, t, r = []) {
|
|
1685
|
+
if (!t)
|
|
1686
|
+
throw new Error("getTrustedInputBIP143: missing tx");
|
|
1687
|
+
if (r.includes("decred"))
|
|
1688
|
+
throw new Error("Decred does not implement BIP143");
|
|
1689
|
+
let i = Pe("sha256").update(Pe("sha256").update(ht(t, true)).digest()).digest();
|
|
1690
|
+
const s2 = dist.Buffer.alloc(4);
|
|
1691
|
+
s2.writeUInt32LE(e, 0);
|
|
1692
|
+
const { outputs: a, locktime: c } = t;
|
|
1693
|
+
if (!a || !c)
|
|
1694
|
+
throw new Error("getTrustedInputBIP143: locktime & outputs is expected");
|
|
1695
|
+
if (!a[e])
|
|
1696
|
+
throw new Error("getTrustedInputBIP143: wrong index");
|
|
1697
|
+
return i = dist.Buffer.concat([i, s2, a[e].amount]), i.toString("hex");
|
|
1698
|
+
}
|
|
1699
|
+
function cr(n) {
|
|
1700
|
+
const e = n[64] & 1 ? 3 : 2, t = dist.Buffer.alloc(1);
|
|
1701
|
+
return t[0] = e, dist.Buffer.concat([t, n.slice(1, 1 + 32)]);
|
|
1702
|
+
}
|
|
1703
|
+
function tt(n, e, t, r, o, i = []) {
|
|
1704
|
+
const s2 = i.includes("decred"), a = ut(e), c = dist.Buffer.alloc(4);
|
|
1705
|
+
c.writeUInt32BE(t, 0);
|
|
1706
|
+
let l = s2 ? dist.Buffer.concat([
|
|
1707
|
+
a,
|
|
1708
|
+
c,
|
|
1709
|
+
o || dist.Buffer.from([0, 0, 0, 0]),
|
|
1710
|
+
dist.Buffer.from([r])
|
|
1711
|
+
]) : dist.Buffer.concat([a, dist.Buffer.from([0]), c, dist.Buffer.from([r])]);
|
|
1712
|
+
return o && !s2 && (l = dist.Buffer.concat([l, o])), n.send(224, 72, 0, 0, l).then((f) => f.length > 0 ? (f[0] = 48, f.slice(0, f.length - 2)) : f);
|
|
1713
|
+
}
|
|
1714
|
+
var fr = globalThis && globalThis.__awaiter || function(n, e, t, r) {
|
|
1715
|
+
function o(i) {
|
|
1716
|
+
return i instanceof t ? i : new t(function(s2) {
|
|
1717
|
+
s2(i);
|
|
1718
|
+
});
|
|
1719
|
+
}
|
|
1720
|
+
return new (t || (t = Promise))(function(i, s2) {
|
|
1721
|
+
function a(f) {
|
|
1722
|
+
try {
|
|
1723
|
+
l(r.next(f));
|
|
1724
|
+
} catch (h) {
|
|
1725
|
+
s2(h);
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
function c(f) {
|
|
1729
|
+
try {
|
|
1730
|
+
l(r.throw(f));
|
|
1731
|
+
} catch (h) {
|
|
1732
|
+
s2(h);
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
function l(f) {
|
|
1736
|
+
f.done ? i(f.value) : o(f.value).then(a, c);
|
|
1737
|
+
}
|
|
1738
|
+
l((r = r.apply(n, e || [])).next());
|
|
1739
|
+
});
|
|
1740
|
+
};
|
|
1741
|
+
function vt(n, e) {
|
|
1742
|
+
const t = ut(e);
|
|
1743
|
+
return n.send(224, 74, 255, 0, t);
|
|
1744
|
+
}
|
|
1745
|
+
function Re(n, e, t = []) {
|
|
1746
|
+
return fr(this, void 0, void 0, function* () {
|
|
1747
|
+
let r = 0;
|
|
1748
|
+
const o = 128;
|
|
1749
|
+
if (t.includes("decred"))
|
|
1750
|
+
return n.send(224, 74, o, 0, e);
|
|
1751
|
+
for (; r < e.length; ) {
|
|
1752
|
+
const s2 = r + Y >= e.length ? e.length - r : Y, a = r + s2 === e.length ? 128 : 0, c = e.slice(r, r + s2);
|
|
1753
|
+
yield n.send(224, 74, a, 0, c), r += s2;
|
|
1754
|
+
}
|
|
1755
|
+
});
|
|
1756
|
+
}
|
|
1757
|
+
var Ht = globalThis && globalThis.__awaiter || function(n, e, t, r) {
|
|
1758
|
+
function o(i) {
|
|
1759
|
+
return i instanceof t ? i : new t(function(s2) {
|
|
1760
|
+
s2(i);
|
|
1761
|
+
});
|
|
1762
|
+
}
|
|
1763
|
+
return new (t || (t = Promise))(function(i, s2) {
|
|
1764
|
+
function a(f) {
|
|
1765
|
+
try {
|
|
1766
|
+
l(r.next(f));
|
|
1767
|
+
} catch (h) {
|
|
1768
|
+
s2(h);
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
function c(f) {
|
|
1772
|
+
try {
|
|
1773
|
+
l(r.throw(f));
|
|
1774
|
+
} catch (h) {
|
|
1775
|
+
s2(h);
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
function l(f) {
|
|
1779
|
+
f.done ? i(f.value) : o(f.value).then(a, c);
|
|
1780
|
+
}
|
|
1781
|
+
l((r = r.apply(n, e || [])).next());
|
|
1782
|
+
});
|
|
1783
|
+
};
|
|
1784
|
+
const Yt = (n) => Ht(void 0, void 0, void 0, function* () {
|
|
1785
|
+
const e = yield n.send(176, 1, 0, 0);
|
|
1786
|
+
let t = 0;
|
|
1787
|
+
const r = e[t++];
|
|
1788
|
+
w(r === 1, "getAppAndVersion: format not supported");
|
|
1789
|
+
const o = e[t++], i = e.slice(t, t += o).toString("ascii"), s2 = e[t++], a = e.slice(t, t += s2).toString("ascii"), c = e[t++], l = e.slice(t, t += c);
|
|
1790
|
+
return {
|
|
1791
|
+
name: i,
|
|
1792
|
+
version: a,
|
|
1793
|
+
flags: l
|
|
1794
|
+
};
|
|
1795
|
+
}), ar = (n) => Ht(void 0, void 0, void 0, function* () {
|
|
1796
|
+
try {
|
|
1797
|
+
yield n.send(224, 196, 0, 0);
|
|
1798
|
+
} catch {
|
|
1799
|
+
return false;
|
|
1800
|
+
}
|
|
1801
|
+
return true;
|
|
1802
|
+
});
|
|
1803
|
+
function lr({ version: n, name: e }) {
|
|
1804
|
+
return e === "Decred" ? false : e === "Exchange" ? true : vn$1.gte(n, "1.4.0");
|
|
1805
|
+
}
|
|
1806
|
+
var hr = globalThis && globalThis.__awaiter || function(n, e, t, r) {
|
|
1807
|
+
function o(i) {
|
|
1808
|
+
return i instanceof t ? i : new t(function(s2) {
|
|
1809
|
+
s2(i);
|
|
1810
|
+
});
|
|
1811
|
+
}
|
|
1812
|
+
return new (t || (t = Promise))(function(i, s2) {
|
|
1813
|
+
function a(f) {
|
|
1814
|
+
try {
|
|
1815
|
+
l(r.next(f));
|
|
1816
|
+
} catch (h) {
|
|
1817
|
+
s2(h);
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
function c(f) {
|
|
1821
|
+
try {
|
|
1822
|
+
l(r.throw(f));
|
|
1823
|
+
} catch (h) {
|
|
1824
|
+
s2(h);
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
function l(f) {
|
|
1828
|
+
f.done ? i(f.value) : o(f.value).then(a, c);
|
|
1829
|
+
}
|
|
1830
|
+
l((r = r.apply(n, e || [])).next());
|
|
1831
|
+
});
|
|
1832
|
+
};
|
|
1833
|
+
const pr = {
|
|
1834
|
+
lockTime: Ft,
|
|
1835
|
+
sigHashType: at,
|
|
1836
|
+
segwit: false,
|
|
1837
|
+
additionals: [],
|
|
1838
|
+
onDeviceStreaming: (n) => {
|
|
1839
|
+
},
|
|
1840
|
+
onDeviceSignatureGranted: () => {
|
|
1841
|
+
},
|
|
1842
|
+
onDeviceSignatureRequested: () => {
|
|
1843
|
+
}
|
|
1844
|
+
};
|
|
1845
|
+
function dr(n, e) {
|
|
1846
|
+
return hr(this, void 0, void 0, function* () {
|
|
1847
|
+
const t = Object.assign(Object.assign({}, pr), e), { inputs: r, associatedKeysets: o, changePath: i, outputScriptHex: s2, lockTime: a, sigHashType: c, segwit: l, initialTimestamp: f, additionals: h, expiryHeight: x, onDeviceStreaming: w2, onDeviceSignatureGranted: T, onDeviceSignatureRequested: y } = t;
|
|
1848
|
+
let B = t.useTrustedInputForSegwit;
|
|
1849
|
+
if (B === void 0)
|
|
1850
|
+
try {
|
|
1851
|
+
const g = yield Yt(n);
|
|
1852
|
+
B = lr(g);
|
|
1853
|
+
} catch (g) {
|
|
1854
|
+
if (g.statusCode === 27904)
|
|
1855
|
+
B = false;
|
|
1856
|
+
else
|
|
1857
|
+
throw g;
|
|
1858
|
+
}
|
|
1859
|
+
const m = (g, v) => {
|
|
1860
|
+
const { length: R } = r;
|
|
1861
|
+
if (R < 3)
|
|
1862
|
+
return;
|
|
1863
|
+
const D = R * g + v, Q = 2 * R, Ge = D / Q;
|
|
1864
|
+
w2({
|
|
1865
|
+
progress: Ge,
|
|
1866
|
+
total: Q,
|
|
1867
|
+
index: D
|
|
1868
|
+
});
|
|
1869
|
+
}, p = h.includes("decred"), d$1 = h.includes("zcash"), E = h.includes("stealthcoin"), _ = Date.now(), I = h.includes("sapling"), b = l && h.includes("bech32"), U = l || !!h && (h.includes("abc") || h.includes("gold") || h.includes("bip143")) || !!x && !p, q = dist.Buffer.alloc(4);
|
|
1870
|
+
q.writeUInt32LE(a, 0);
|
|
1871
|
+
const C = dist.Buffer.alloc(0), j = dist.Buffer.alloc(0), V = dist.Buffer.alloc(4);
|
|
1872
|
+
x && !p ? V.writeUInt32LE(d$1 ? 2147483653 : I ? 2147483652 : 2147483651, 0) : E ? V.writeUInt32LE(2, 0) : V.writeUInt32LE(1, 0);
|
|
1873
|
+
const W = [], pe = [], de = [], Z = [];
|
|
1874
|
+
let Te = true;
|
|
1875
|
+
const O = {
|
|
1876
|
+
inputs: [],
|
|
1877
|
+
version: V,
|
|
1878
|
+
timestamp: dist.Buffer.alloc(0)
|
|
1879
|
+
}, jt = U && !B ? dt : pt, Ke = dist.Buffer.from(s2, "hex");
|
|
1880
|
+
m(0, 0);
|
|
1881
|
+
for (const g of r) {
|
|
1882
|
+
{
|
|
1883
|
+
const D = yield jt(n, g[1], g[0], h);
|
|
1884
|
+
d("hw", "got trustedInput=" + D);
|
|
1885
|
+
const Q = dist.Buffer.alloc(4);
|
|
1886
|
+
Q.writeUInt32LE(g.length >= 4 && typeof g[3] == "number" ? g[3] : be, 0), W.push({
|
|
1887
|
+
trustedInput: true,
|
|
1888
|
+
value: dist.Buffer.from(D, "hex"),
|
|
1889
|
+
sequence: Q
|
|
1890
|
+
});
|
|
1891
|
+
}
|
|
1892
|
+
const { outputs: v } = g[0], R = g[1];
|
|
1893
|
+
v && R <= v.length - 1 && pe.push(v[R]), x && !p ? (O.nVersionGroupId = dist.Buffer.from(
|
|
1894
|
+
// nVersionGroupId is 0x26A7270A for zcash from https://z.cash/upgrade/nu5/
|
|
1895
|
+
d$1 ? [10, 39, 167, 38] : I ? [133, 32, 47, 137] : [112, 130, 196, 3]
|
|
1896
|
+
), O.nExpiryHeight = x, O.extraData = dist.Buffer.from(I ? [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] : [0])) : p && (O.nExpiryHeight = x);
|
|
1897
|
+
}
|
|
1898
|
+
O.inputs = r.map((g, v) => {
|
|
1899
|
+
const R = dist.Buffer.alloc(4);
|
|
1900
|
+
return R.writeUInt32LE(g.length >= 4 && typeof g[3] == "number" ? g[3] : be, 0), {
|
|
1901
|
+
script: d$1 ? pe[v].script : C,
|
|
1902
|
+
prevout: j,
|
|
1903
|
+
sequence: R
|
|
1904
|
+
};
|
|
1905
|
+
});
|
|
1906
|
+
{
|
|
1907
|
+
const g = [];
|
|
1908
|
+
for (let v = 0; v < r.length; v++) {
|
|
1909
|
+
const R = yield Je(n, {
|
|
1910
|
+
path: o[v]
|
|
1911
|
+
});
|
|
1912
|
+
m(0, v + 1), g.push(R);
|
|
1913
|
+
}
|
|
1914
|
+
for (let v = 0; v < g.length; v++)
|
|
1915
|
+
Z.push(cr(dist.Buffer.from(g[v].publicKey, "hex")));
|
|
1916
|
+
}
|
|
1917
|
+
f !== void 0 && (O.timestamp = dist.Buffer.alloc(4), O.timestamp.writeUInt32LE(Math.floor(f + (Date.now() - _) / 1e3), 0)), y(), U && (yield Oe(n, true, O, W, true, !!x, h, B), i && (yield vt(n, i)), yield Re(n, Ke)), x && !p && (yield tt(n, "", a, at, x));
|
|
1918
|
+
for (let g = 0; g < r.length; g++) {
|
|
1919
|
+
const v = r[g], R = r[g].length >= 3 && typeof v[2] == "string" ? dist.Buffer.from(v[2], "hex") : l ? dist.Buffer.concat([
|
|
1920
|
+
dist.Buffer.from([qt, lt, ke]),
|
|
1921
|
+
he(Z[g]),
|
|
1922
|
+
dist.Buffer.from([Wt, Xt])
|
|
1923
|
+
]) : pe[g].script, D = Object.assign({}, O), Q = U ? [W[g]] : W;
|
|
1924
|
+
U ? D.inputs = [Object.assign(Object.assign({}, D.inputs[g]), { script: R })] : D.inputs[g].script = R, yield Oe(n, !U && Te, D, Q, U, !!x && !p, h, B), U || (i && (yield vt(n, i)), yield Re(n, Ke, h)), Te && (T(), m(1, 0));
|
|
1925
|
+
const Ge = yield tt(n, o[g], a, c, x, h);
|
|
1926
|
+
m(1, g + 1), de.push(Ge), O.inputs[g].script = C, Te && (Te = false);
|
|
1927
|
+
}
|
|
1928
|
+
for (let g = 0; g < r.length; g++) {
|
|
1929
|
+
if (l)
|
|
1930
|
+
O.witness = dist.Buffer.alloc(0), b || (O.inputs[g].script = dist.Buffer.concat([
|
|
1931
|
+
dist.Buffer.from("160014", "hex"),
|
|
1932
|
+
he(Z[g])
|
|
1933
|
+
]));
|
|
1934
|
+
else {
|
|
1935
|
+
const R = dist.Buffer.alloc(1), D = dist.Buffer.alloc(1);
|
|
1936
|
+
R[0] = de[g].length, D[0] = Z[g].length, O.inputs[g].script = dist.Buffer.concat([
|
|
1937
|
+
R,
|
|
1938
|
+
de[g],
|
|
1939
|
+
D,
|
|
1940
|
+
Z[g]
|
|
1941
|
+
]);
|
|
1942
|
+
}
|
|
1943
|
+
const v = U && !B ? 0 : 4;
|
|
1944
|
+
O.inputs[g].prevout = W[g].value.slice(v, v + 36);
|
|
1945
|
+
}
|
|
1946
|
+
O.locktime = q;
|
|
1947
|
+
let K = dist.Buffer.concat([
|
|
1948
|
+
ht(O, false, O.timestamp, h),
|
|
1949
|
+
Ke
|
|
1950
|
+
]);
|
|
1951
|
+
if (l && !p) {
|
|
1952
|
+
let g = dist.Buffer.alloc(0);
|
|
1953
|
+
for (let v = 0; v < r.length; v++) {
|
|
1954
|
+
const R = dist.Buffer.concat([
|
|
1955
|
+
dist.Buffer.from("02", "hex"),
|
|
1956
|
+
dist.Buffer.from([de[v].length]),
|
|
1957
|
+
de[v],
|
|
1958
|
+
dist.Buffer.from([Z[v].length]),
|
|
1959
|
+
Z[v]
|
|
1960
|
+
]);
|
|
1961
|
+
g = dist.Buffer.concat([g, R]);
|
|
1962
|
+
}
|
|
1963
|
+
K = dist.Buffer.concat([K, g]);
|
|
1964
|
+
}
|
|
1965
|
+
if (d$1 || (K = dist.Buffer.concat([K, q]), x && (K = dist.Buffer.concat([
|
|
1966
|
+
K,
|
|
1967
|
+
O.nExpiryHeight || dist.Buffer.alloc(0),
|
|
1968
|
+
O.extraData || dist.Buffer.alloc(0)
|
|
1969
|
+
]))), p) {
|
|
1970
|
+
let g = dist.Buffer.from([O.inputs.length]);
|
|
1971
|
+
r.forEach((v, R) => {
|
|
1972
|
+
g = dist.Buffer.concat([
|
|
1973
|
+
g,
|
|
1974
|
+
dist.Buffer.from([0, 0, 0, 0, 0, 0, 0, 0]),
|
|
1975
|
+
dist.Buffer.from([0, 0, 0, 0]),
|
|
1976
|
+
dist.Buffer.from([255, 255, 255, 255]),
|
|
1977
|
+
dist.Buffer.from([O.inputs[R].script.length]),
|
|
1978
|
+
O.inputs[R].script
|
|
1979
|
+
]);
|
|
1980
|
+
}), K = dist.Buffer.concat([K, g]);
|
|
1981
|
+
}
|
|
1982
|
+
return d$1 && (K = dist.Buffer.concat([K, dist.Buffer.from([0, 0, 0])])), K.toString("hex");
|
|
1983
|
+
});
|
|
1984
|
+
}
|
|
1985
|
+
var gr = globalThis && globalThis.__awaiter || function(n, e, t, r) {
|
|
1986
|
+
function o(i) {
|
|
1987
|
+
return i instanceof t ? i : new t(function(s2) {
|
|
1988
|
+
s2(i);
|
|
1989
|
+
});
|
|
1990
|
+
}
|
|
1991
|
+
return new (t || (t = Promise))(function(i, s2) {
|
|
1992
|
+
function a(f) {
|
|
1993
|
+
try {
|
|
1994
|
+
l(r.next(f));
|
|
1995
|
+
} catch (h) {
|
|
1996
|
+
s2(h);
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
function c(f) {
|
|
2000
|
+
try {
|
|
2001
|
+
l(r.throw(f));
|
|
2002
|
+
} catch (h) {
|
|
2003
|
+
s2(h);
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
function l(f) {
|
|
2007
|
+
f.done ? i(f.value) : o(f.value).then(a, c);
|
|
2008
|
+
}
|
|
2009
|
+
l((r = r.apply(n, e || [])).next());
|
|
2010
|
+
});
|
|
2011
|
+
};
|
|
2012
|
+
function wr(n, { path: e, messageHex: t }) {
|
|
2013
|
+
return gr(this, void 0, void 0, function* () {
|
|
2014
|
+
const r = s.fromString(e).toPathArray(), o = dist.Buffer.from(t, "hex");
|
|
2015
|
+
let i = 0;
|
|
2016
|
+
for (; i !== o.length; ) {
|
|
2017
|
+
const f = i === 0 ? Y - 1 - r.length * 4 - 4 : Y, h = i + f > o.length ? o.length - i : f, x = dist.Buffer.alloc(i === 0 ? 1 + r.length * 4 + 2 + h : h);
|
|
2018
|
+
i === 0 ? (x[0] = r.length, r.forEach((w2, T) => {
|
|
2019
|
+
x.writeUInt32BE(w2, 1 + 4 * T);
|
|
2020
|
+
}), x.writeUInt16BE(o.length, 1 + 4 * r.length), o.copy(x, 1 + 4 * r.length + 2, i, i + h)) : o.copy(x, 0, i, i + h), yield n.send(224, 78, 0, i === 0 ? 1 : 128, x), i += h;
|
|
2021
|
+
}
|
|
2022
|
+
const s$1 = yield n.send(224, 78, 128, 0, dist.Buffer.from([0])), a = s$1[0] - 48;
|
|
2023
|
+
let c = s$1.slice(4, 4 + s$1[3]);
|
|
2024
|
+
c[0] === 0 && (c = c.slice(1)), c = c.toString("hex"), i = 4 + s$1[3] + 2;
|
|
2025
|
+
let l = s$1.slice(i, i + s$1[i - 1]);
|
|
2026
|
+
return l[0] === 0 && (l = l.slice(1)), l = l.toString("hex"), {
|
|
2027
|
+
v: a,
|
|
2028
|
+
r: c,
|
|
2029
|
+
s: l
|
|
2030
|
+
};
|
|
2031
|
+
});
|
|
2032
|
+
}
|
|
2033
|
+
var $e = globalThis && globalThis.__awaiter || function(n, e, t, r) {
|
|
2034
|
+
function o(i) {
|
|
2035
|
+
return i instanceof t ? i : new t(function(s2) {
|
|
2036
|
+
s2(i);
|
|
2037
|
+
});
|
|
2038
|
+
}
|
|
2039
|
+
return new (t || (t = Promise))(function(i, s2) {
|
|
2040
|
+
function a(f) {
|
|
2041
|
+
try {
|
|
2042
|
+
l(r.next(f));
|
|
2043
|
+
} catch (h) {
|
|
2044
|
+
s2(h);
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
function c(f) {
|
|
2048
|
+
try {
|
|
2049
|
+
l(r.throw(f));
|
|
2050
|
+
} catch (h) {
|
|
2051
|
+
s2(h);
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
function l(f) {
|
|
2055
|
+
f.done ? i(f.value) : o(f.value).then(a, c);
|
|
2056
|
+
}
|
|
2057
|
+
l((r = r.apply(n, e || [])).next());
|
|
2058
|
+
});
|
|
2059
|
+
};
|
|
2060
|
+
class ze {
|
|
2061
|
+
constructor(e) {
|
|
2062
|
+
this.transport = e, this.derivationsCache = {};
|
|
2063
|
+
}
|
|
2064
|
+
derivatePath(e) {
|
|
2065
|
+
return $e(this, void 0, void 0, function* () {
|
|
2066
|
+
if (this.derivationsCache[e])
|
|
2067
|
+
return this.derivationsCache[e];
|
|
2068
|
+
const t = yield Je(this.transport, {
|
|
2069
|
+
path: e
|
|
2070
|
+
});
|
|
2071
|
+
return this.derivationsCache[e] = t, t;
|
|
2072
|
+
});
|
|
2073
|
+
}
|
|
2074
|
+
getWalletXpub({ path: e, xpubVersion: t }) {
|
|
2075
|
+
return $e(this, void 0, void 0, function* () {
|
|
2076
|
+
const r = F(e), o = r.slice(0, -1), i = yield this.derivatePath(ct(o)), s2 = yield this.derivatePath(e), a = mr(Pt(dist.Buffer.from(i.publicKey, "hex")));
|
|
2077
|
+
return Ir(t, r.length, a, r[r.length - 1], dist.Buffer.from(s2.chainCode, "hex"), Pt(dist.Buffer.from(s2.publicKey, "hex")));
|
|
2078
|
+
});
|
|
2079
|
+
}
|
|
2080
|
+
/**
|
|
2081
|
+
* @param path a BIP 32 path
|
|
2082
|
+
* @param options an object with optional these fields:
|
|
2083
|
+
*
|
|
2084
|
+
* - verify (boolean) will ask user to confirm the address on the device
|
|
2085
|
+
*
|
|
2086
|
+
* - format ("legacy" | "p2sh" | "bech32" | "cashaddr") to use different bitcoin address formatter.
|
|
2087
|
+
*
|
|
2088
|
+
* NB The normal usage is to use:
|
|
2089
|
+
*
|
|
2090
|
+
* - legacy format with 44' paths
|
|
2091
|
+
*
|
|
2092
|
+
* - p2sh format with 49' paths
|
|
2093
|
+
*
|
|
2094
|
+
* - bech32 format with 173' paths
|
|
2095
|
+
*
|
|
2096
|
+
* - cashaddr in case of Bitcoin Cash
|
|
2097
|
+
*
|
|
2098
|
+
* @example
|
|
2099
|
+
* btc.getWalletPublicKey("44'/0'/0'/0/0").then(o => o.bitcoinAddress)
|
|
2100
|
+
* btc.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress)
|
|
2101
|
+
*/
|
|
2102
|
+
getWalletPublicKey(e, t) {
|
|
2103
|
+
if ((t == null ? void 0 : t.format) === "bech32m")
|
|
2104
|
+
throw new Error("Unsupported address format bech32m");
|
|
2105
|
+
return Je(this.transport, Object.assign(Object.assign({}, t), { path: e }));
|
|
2106
|
+
}
|
|
2107
|
+
/**
|
|
2108
|
+
* To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters
|
|
2109
|
+
* @param inputs is an array of [ transaction, output_index, optional redeem script, optional sequence ] where
|
|
2110
|
+
*
|
|
2111
|
+
* * transaction is the previously computed transaction object for this UTXO
|
|
2112
|
+
* * output_index is the output in the transaction used as input for this UTXO (counting from 0)
|
|
2113
|
+
* * redeem script is the optional redeem script to use when consuming a Segregated Witness input
|
|
2114
|
+
* * sequence is the sequence number to use for this input (when using RBF), or non present
|
|
2115
|
+
* @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
|
|
2116
|
+
* @param changePath is an optional BIP 32 path pointing to the path to the public key used to compute the change address
|
|
2117
|
+
* @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign
|
|
2118
|
+
* @param lockTime is the optional lockTime of the transaction to sign, or default (0)
|
|
2119
|
+
* @param sigHashType is the hash type of the transaction to sign, or default (all)
|
|
2120
|
+
* @param segwit is an optional boolean indicating wether to use segwit or not
|
|
2121
|
+
* @param initialTimestamp is an optional timestamp of the function call to use for coins that necessitate timestamps only, (not the one that the tx will include)
|
|
2122
|
+
* @param additionals list of additionnal options
|
|
2123
|
+
*
|
|
2124
|
+
* - "bech32" for spending native segwit outputs
|
|
2125
|
+
* - "abc" for bch
|
|
2126
|
+
* - "gold" for btg
|
|
2127
|
+
* - "bipxxx" for using BIPxxx
|
|
2128
|
+
* - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200)
|
|
2129
|
+
* @param expiryHeight is an optional Buffer for zec overwinter / sapling Txs
|
|
2130
|
+
* @param useTrustedInputForSegwit trust inputs for segwit transactions
|
|
2131
|
+
* @return the signed transaction ready to be broadcast
|
|
2132
|
+
* @example
|
|
2133
|
+
btc.createTransaction({
|
|
2134
|
+
inputs: [ [tx1, 1] ],
|
|
2135
|
+
associatedKeysets: ["0'/0/0"],
|
|
2136
|
+
outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
|
|
2137
|
+
}).then(res => ...);
|
|
2138
|
+
*/
|
|
2139
|
+
createPaymentTransaction(e) {
|
|
2140
|
+
if (arguments.length > 1)
|
|
2141
|
+
throw new Error("@ledgerhq/hw-app-btc: createPaymentTransaction multi argument signature is deprecated. please switch to named parameters.");
|
|
2142
|
+
return dr(this.transport, e);
|
|
2143
|
+
}
|
|
2144
|
+
signMessage({ path: e, messageHex: t }) {
|
|
2145
|
+
return $e(this, void 0, void 0, function* () {
|
|
2146
|
+
return wr(this.transport, {
|
|
2147
|
+
path: e,
|
|
2148
|
+
messageHex: t
|
|
2149
|
+
});
|
|
2150
|
+
});
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
function mr(n) {
|
|
2154
|
+
return Br(n).slice(0, 4);
|
|
2155
|
+
}
|
|
2156
|
+
function bt(n) {
|
|
2157
|
+
const e = dist.Buffer.allocUnsafe(4);
|
|
2158
|
+
return e.writeUInt32BE(n, 0), e;
|
|
2159
|
+
}
|
|
2160
|
+
const Pt = (n) => dist.Buffer.concat([dist.Buffer.from([2 + (n[64] & 1)]), n.slice(1, 33)]);
|
|
2161
|
+
function Ir(n, e, t, r, o, i) {
|
|
2162
|
+
const s2 = bt(r);
|
|
2163
|
+
s2[0] |= 128;
|
|
2164
|
+
const a = dist.Buffer.concat([
|
|
2165
|
+
bt(n),
|
|
2166
|
+
dist.Buffer.from([e]),
|
|
2167
|
+
t,
|
|
2168
|
+
s2,
|
|
2169
|
+
o,
|
|
2170
|
+
i
|
|
2171
|
+
]), c = xr(a).slice(0, 4);
|
|
2172
|
+
return Pn.encode(dist.Buffer.concat([a, c]));
|
|
2173
|
+
}
|
|
2174
|
+
function nt(n) {
|
|
2175
|
+
return Pe("sha256").update(n).digest();
|
|
2176
|
+
}
|
|
2177
|
+
function xr(n) {
|
|
2178
|
+
return nt(nt(n));
|
|
2179
|
+
}
|
|
2180
|
+
function Er(n) {
|
|
2181
|
+
return new RIPEMD160().update(n).digest();
|
|
2182
|
+
}
|
|
2183
|
+
function Br(n) {
|
|
2184
|
+
return Er(nt(n));
|
|
2185
|
+
}
|
|
2186
|
+
class Tr {
|
|
2187
|
+
/**
|
|
2188
|
+
* @param keys Sorted list of (unhashed) keys
|
|
2189
|
+
* @param values values, in corresponding order as the keys, and of equal length
|
|
2190
|
+
*/
|
|
2191
|
+
constructor(e, t) {
|
|
2192
|
+
if (e.length != t.length)
|
|
2193
|
+
throw new Error("keys and values should have the same length");
|
|
2194
|
+
for (let r = 0; r < e.length - 1; r++)
|
|
2195
|
+
if (e[r].toString("hex") >= e[r + 1].toString("hex"))
|
|
2196
|
+
throw new Error("keys must be in strictly increasing order");
|
|
2197
|
+
this.keys = e, this.keysTree = new te(e.map((r) => ne(r))), this.values = t, this.valuesTree = new te(t.map((r) => ne(r)));
|
|
2198
|
+
}
|
|
2199
|
+
commitment() {
|
|
2200
|
+
return dist.Buffer.concat([
|
|
2201
|
+
M(this.keys.length),
|
|
2202
|
+
this.keysTree.getRoot(),
|
|
2203
|
+
this.valuesTree.getRoot()
|
|
2204
|
+
]);
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
class Ie extends $t {
|
|
2208
|
+
constructor(e) {
|
|
2209
|
+
super(), this.inputMerkleMaps = [], this.outputMerkleMaps = [], e.copy(this), this.globalMerkleMap = Ie.createMerkleMap(this.globalMap);
|
|
2210
|
+
for (let t = 0; t < this.getGlobalInputCount(); t++)
|
|
2211
|
+
this.inputMerkleMaps.push(Ie.createMerkleMap(this.inputMaps[t]));
|
|
2212
|
+
this.inputMapCommitments = [...this.inputMerkleMaps.values()].map((t) => t.commitment());
|
|
2213
|
+
for (let t = 0; t < this.getGlobalOutputCount(); t++)
|
|
2214
|
+
this.outputMerkleMaps.push(Ie.createMerkleMap(this.outputMaps[t]));
|
|
2215
|
+
this.outputMapCommitments = [...this.outputMerkleMaps.values()].map((t) => t.commitment());
|
|
2216
|
+
}
|
|
2217
|
+
// These public functions are for MerkelizedPsbt.
|
|
2218
|
+
getGlobalSize() {
|
|
2219
|
+
return this.globalMap.size;
|
|
2220
|
+
}
|
|
2221
|
+
getGlobalKeysValuesRoot() {
|
|
2222
|
+
return this.globalMerkleMap.commitment();
|
|
2223
|
+
}
|
|
2224
|
+
static createMerkleMap(e) {
|
|
2225
|
+
const t = [...e.keys()].sort(), r = t.map((s2) => {
|
|
2226
|
+
const a = e.get(s2);
|
|
2227
|
+
if (!a)
|
|
2228
|
+
throw new Error("No value for key " + s2);
|
|
2229
|
+
return a;
|
|
2230
|
+
}), o = t.map((s2) => dist.Buffer.from(s2, "hex"));
|
|
2231
|
+
return new Tr(o, r);
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
var oe;
|
|
2235
|
+
(function(n) {
|
|
2236
|
+
n[n.YIELD = 16] = "YIELD", n[n.GET_PREIMAGE = 64] = "GET_PREIMAGE", n[n.GET_MERKLE_LEAF_PROOF = 65] = "GET_MERKLE_LEAF_PROOF", n[n.GET_MERKLE_LEAF_INDEX = 66] = "GET_MERKLE_LEAF_INDEX", n[n.GET_MORE_ELEMENTS = 160] = "GET_MORE_ELEMENTS";
|
|
2237
|
+
})(oe || (oe = {}));
|
|
2238
|
+
class Be {
|
|
2239
|
+
}
|
|
2240
|
+
class yr extends Be {
|
|
2241
|
+
constructor(e, t) {
|
|
2242
|
+
super(), this.progressCallback = t, this.code = oe.YIELD, this.results = e;
|
|
2243
|
+
}
|
|
2244
|
+
execute(e) {
|
|
2245
|
+
return this.results.push(dist.Buffer.from(e.subarray(1))), this.progressCallback(), dist.Buffer.from("");
|
|
2246
|
+
}
|
|
2247
|
+
}
|
|
2248
|
+
class Sr extends Be {
|
|
2249
|
+
constructor(e, t) {
|
|
2250
|
+
super(), this.code = oe.GET_PREIMAGE, this.known_preimages = e, this.queue = t;
|
|
2251
|
+
}
|
|
2252
|
+
execute(e) {
|
|
2253
|
+
const t = dist.Buffer.from(e.subarray(1));
|
|
2254
|
+
if (t.length != 1 + 32)
|
|
2255
|
+
throw new Error("Invalid request, unexpected trailing data");
|
|
2256
|
+
if (t[0] != 0)
|
|
2257
|
+
throw new Error("Unsupported request, the first byte should be 0");
|
|
2258
|
+
const r = dist.Buffer.alloc(32);
|
|
2259
|
+
for (let s2 = 0; s2 < 32; s2++)
|
|
2260
|
+
r[s2] = t[1 + s2];
|
|
2261
|
+
const o = r.toString("hex"), i = this.known_preimages.get(o);
|
|
2262
|
+
if (i != null) {
|
|
2263
|
+
const s2 = M(i.length), a = 255 - s2.length - 1, c = Math.min(a, i.length);
|
|
2264
|
+
if (c < i.length)
|
|
2265
|
+
for (let l = c; l < i.length; l++)
|
|
2266
|
+
this.queue.push(dist.Buffer.from([i[l]]));
|
|
2267
|
+
return dist.Buffer.concat([
|
|
2268
|
+
s2,
|
|
2269
|
+
dist.Buffer.from([c]),
|
|
2270
|
+
dist.Buffer.from(i.subarray(0, c))
|
|
2271
|
+
]);
|
|
2272
|
+
}
|
|
2273
|
+
throw Error(`Requested unknown preimage for: ${o}`);
|
|
2274
|
+
}
|
|
2275
|
+
}
|
|
2276
|
+
class _r extends Be {
|
|
2277
|
+
constructor(e, t) {
|
|
2278
|
+
super(), this.code = oe.GET_MERKLE_LEAF_PROOF, this.known_trees = e, this.queue = t;
|
|
2279
|
+
}
|
|
2280
|
+
execute(e) {
|
|
2281
|
+
const t = dist.Buffer.from(e.subarray(1));
|
|
2282
|
+
if (t.length < 32 + 1 + 1)
|
|
2283
|
+
throw new Error("Invalid request, expected at least 34 bytes");
|
|
2284
|
+
const r = new ee(t), i = r.readSlice(32).toString("hex");
|
|
2285
|
+
let s2, a;
|
|
2286
|
+
try {
|
|
2287
|
+
s2 = r.readVarInt(), a = r.readVarInt();
|
|
2288
|
+
} catch {
|
|
2289
|
+
throw new Error("Invalid request, couldn't parse tree_size or leaf_index");
|
|
2290
|
+
}
|
|
2291
|
+
const c = this.known_trees.get(i);
|
|
2292
|
+
if (!c)
|
|
2293
|
+
throw Error(`Requested Merkle leaf proof for unknown tree: ${i}`);
|
|
2294
|
+
if (a >= s2 || c.size() != s2)
|
|
2295
|
+
throw Error("Invalid index or tree size.");
|
|
2296
|
+
if (this.queue.length != 0)
|
|
2297
|
+
throw Error("This command should not execute when the queue is not empty.");
|
|
2298
|
+
const l = c.getProof(a), f = Math.min(Math.floor((255 - 32 - 1 - 1) / 32), l.length), h = l.length - f;
|
|
2299
|
+
return h > 0 && this.queue.push(...l.slice(-h)), dist.Buffer.concat([
|
|
2300
|
+
c.getLeafHash(a),
|
|
2301
|
+
dist.Buffer.from([l.length]),
|
|
2302
|
+
dist.Buffer.from([f]),
|
|
2303
|
+
...l.slice(0, f)
|
|
2304
|
+
]);
|
|
2305
|
+
}
|
|
2306
|
+
}
|
|
2307
|
+
class vr extends Be {
|
|
2308
|
+
constructor(e) {
|
|
2309
|
+
super(), this.code = oe.GET_MERKLE_LEAF_INDEX, this.known_trees = e;
|
|
2310
|
+
}
|
|
2311
|
+
execute(e) {
|
|
2312
|
+
const t = dist.Buffer.from(e.subarray(1));
|
|
2313
|
+
if (t.length != 32 + 32)
|
|
2314
|
+
throw new Error("Invalid request, unexpected trailing data");
|
|
2315
|
+
const r = dist.Buffer.alloc(32);
|
|
2316
|
+
for (let f = 0; f < 32; f++)
|
|
2317
|
+
r[f] = t.readUInt8(f);
|
|
2318
|
+
const o = r.toString("hex"), i = dist.Buffer.alloc(32);
|
|
2319
|
+
for (let f = 0; f < 32; f++)
|
|
2320
|
+
i[f] = t.readUInt8(32 + f);
|
|
2321
|
+
const s2 = i.toString("hex"), a = this.known_trees.get(o);
|
|
2322
|
+
if (!a)
|
|
2323
|
+
throw Error(`Requested Merkle leaf index for unknown root: ${o}`);
|
|
2324
|
+
let c = 0, l = 0;
|
|
2325
|
+
for (let f = 0; f < a.size(); f++)
|
|
2326
|
+
if (a.getLeafHash(f).toString("hex") == s2) {
|
|
2327
|
+
l = 1, c = f;
|
|
2328
|
+
break;
|
|
2329
|
+
}
|
|
2330
|
+
return dist.Buffer.concat([dist.Buffer.from([l]), M(c)]);
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
class br extends Be {
|
|
2334
|
+
constructor(e) {
|
|
2335
|
+
super(), this.code = oe.GET_MORE_ELEMENTS, this.queue = e;
|
|
2336
|
+
}
|
|
2337
|
+
execute(e) {
|
|
2338
|
+
if (e.length != 1)
|
|
2339
|
+
throw new Error("Invalid request, unexpected trailing data");
|
|
2340
|
+
if (this.queue.length === 0)
|
|
2341
|
+
throw new Error("No elements to get");
|
|
2342
|
+
const t = this.queue[0].length;
|
|
2343
|
+
if (this.queue.some((s2) => s2.length != t))
|
|
2344
|
+
throw new Error("The queue contains elements with different byte length, which is not expected");
|
|
2345
|
+
const r = Math.floor(253 / t), o = Math.min(r, this.queue.length), i = this.queue.splice(0, o);
|
|
2346
|
+
return dist.Buffer.concat([
|
|
2347
|
+
dist.Buffer.from([o]),
|
|
2348
|
+
dist.Buffer.from([t]),
|
|
2349
|
+
...i
|
|
2350
|
+
]);
|
|
2351
|
+
}
|
|
2352
|
+
}
|
|
2353
|
+
class He {
|
|
2354
|
+
constructor(e) {
|
|
2355
|
+
this.roots = /* @__PURE__ */ new Map(), this.preimages = /* @__PURE__ */ new Map(), this.yielded = [], this.queue = [], this.commands = /* @__PURE__ */ new Map();
|
|
2356
|
+
const t = [
|
|
2357
|
+
new yr(this.yielded, e),
|
|
2358
|
+
new Sr(this.preimages, this.queue),
|
|
2359
|
+
new vr(this.roots),
|
|
2360
|
+
new _r(this.roots, this.queue),
|
|
2361
|
+
new br(this.queue)
|
|
2362
|
+
];
|
|
2363
|
+
for (const r of t) {
|
|
2364
|
+
if (this.commands.has(r.code))
|
|
2365
|
+
throw new Error(`Multiple commands with code ${r.code}`);
|
|
2366
|
+
this.commands.set(r.code, r);
|
|
2367
|
+
}
|
|
2368
|
+
}
|
|
2369
|
+
getYielded() {
|
|
2370
|
+
return this.yielded;
|
|
2371
|
+
}
|
|
2372
|
+
addKnownPreimage(e) {
|
|
2373
|
+
this.preimages.set(crypto_1.sha256(e).toString("hex"), e);
|
|
2374
|
+
}
|
|
2375
|
+
addKnownList(e) {
|
|
2376
|
+
for (const r of e) {
|
|
2377
|
+
const o = dist.Buffer.concat([dist.Buffer.from([0]), r]);
|
|
2378
|
+
this.addKnownPreimage(o);
|
|
2379
|
+
}
|
|
2380
|
+
const t = new te(e.map((r) => ne(r)));
|
|
2381
|
+
this.roots.set(t.getRoot().toString("hex"), t);
|
|
2382
|
+
}
|
|
2383
|
+
addKnownMapping(e) {
|
|
2384
|
+
this.addKnownList(e.keys), this.addKnownList(e.values);
|
|
2385
|
+
}
|
|
2386
|
+
execute(e) {
|
|
2387
|
+
if (e.length == 0)
|
|
2388
|
+
throw new Error("Unexpected empty command");
|
|
2389
|
+
const t = e[0], r = this.commands.get(t);
|
|
2390
|
+
if (!r)
|
|
2391
|
+
throw new Error(`Unexpected command code ${t}`);
|
|
2392
|
+
return r.execute(e);
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
var ae = globalThis && globalThis.__awaiter || function(n, e, t, r) {
|
|
2396
|
+
function o(i) {
|
|
2397
|
+
return i instanceof t ? i : new t(function(s2) {
|
|
2398
|
+
s2(i);
|
|
2399
|
+
});
|
|
2400
|
+
}
|
|
2401
|
+
return new (t || (t = Promise))(function(i, s2) {
|
|
2402
|
+
function a(f) {
|
|
2403
|
+
try {
|
|
2404
|
+
l(r.next(f));
|
|
2405
|
+
} catch (h) {
|
|
2406
|
+
s2(h);
|
|
2407
|
+
}
|
|
2408
|
+
}
|
|
2409
|
+
function c(f) {
|
|
2410
|
+
try {
|
|
2411
|
+
l(r.throw(f));
|
|
2412
|
+
} catch (h) {
|
|
2413
|
+
s2(h);
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
function l(f) {
|
|
2417
|
+
f.done ? i(f.value) : o(f.value).then(a, c);
|
|
2418
|
+
}
|
|
2419
|
+
l((r = r.apply(n, e || [])).next());
|
|
2420
|
+
});
|
|
2421
|
+
};
|
|
2422
|
+
const Pr = 225, Or = 248;
|
|
2423
|
+
var J;
|
|
2424
|
+
(function(n) {
|
|
2425
|
+
n[n.GET_PUBKEY = 0] = "GET_PUBKEY", n[n.REGISTER_WALLET = 2] = "REGISTER_WALLET", n[n.GET_WALLET_ADDRESS = 3] = "GET_WALLET_ADDRESS", n[n.SIGN_PSBT = 4] = "SIGN_PSBT", n[n.GET_MASTER_FINGERPRINT = 5] = "GET_MASTER_FINGERPRINT", n[n.SIGN_MESSAGE = 16] = "SIGN_MESSAGE";
|
|
2426
|
+
})(J || (J = {}));
|
|
2427
|
+
var rt;
|
|
2428
|
+
(function(n) {
|
|
2429
|
+
n[n.CONTINUE_INTERRUPTED = 1] = "CONTINUE_INTERRUPTED";
|
|
2430
|
+
})(rt || (rt = {}));
|
|
2431
|
+
class Rr {
|
|
2432
|
+
constructor(e) {
|
|
2433
|
+
this.transport = e;
|
|
2434
|
+
}
|
|
2435
|
+
makeRequest(e, t, r) {
|
|
2436
|
+
return ae(this, void 0, void 0, function* () {
|
|
2437
|
+
let o = yield this.transport.send(Pr, e, 0, 0, t, [36864, 57344]);
|
|
2438
|
+
for (; o.readUInt16BE(o.length - 2) === 57344; ) {
|
|
2439
|
+
if (!r)
|
|
2440
|
+
throw new Error("Unexpected SW_INTERRUPTED_EXECUTION");
|
|
2441
|
+
const i = o.slice(0, -2), s2 = r.execute(i);
|
|
2442
|
+
o = yield this.transport.send(Or, rt.CONTINUE_INTERRUPTED, 0, 0, s2, [36864, 57344]);
|
|
2443
|
+
}
|
|
2444
|
+
return o.slice(0, -2);
|
|
2445
|
+
});
|
|
2446
|
+
}
|
|
2447
|
+
getExtendedPubkey(e, t) {
|
|
2448
|
+
return ae(this, void 0, void 0, function* () {
|
|
2449
|
+
if (t.length > 6)
|
|
2450
|
+
throw new Error("Path too long. At most 6 levels allowed.");
|
|
2451
|
+
return (yield this.makeRequest(J.GET_PUBKEY, dist.Buffer.concat([dist.Buffer.from(e ? [1] : [0]), Ye(t)]))).toString("ascii");
|
|
2452
|
+
});
|
|
2453
|
+
}
|
|
2454
|
+
getWalletAddress(e, t, r, o, i) {
|
|
2455
|
+
return ae(this, void 0, void 0, function* () {
|
|
2456
|
+
if (r !== 0 && r !== 1)
|
|
2457
|
+
throw new Error("Change can only be 0 or 1");
|
|
2458
|
+
if (o < 0 || !Number.isInteger(o))
|
|
2459
|
+
throw new Error("Invalid address index");
|
|
2460
|
+
if (t != null && t.length != 32)
|
|
2461
|
+
throw new Error("Invalid HMAC length");
|
|
2462
|
+
const s2 = new He(() => {
|
|
2463
|
+
});
|
|
2464
|
+
s2.addKnownList(e.keys.map((l) => dist.Buffer.from(l, "ascii"))), s2.addKnownPreimage(e.serialize());
|
|
2465
|
+
const a = dist.Buffer.alloc(4);
|
|
2466
|
+
return a.writeUInt32BE(o, 0), (yield this.makeRequest(J.GET_WALLET_ADDRESS, dist.Buffer.concat([
|
|
2467
|
+
dist.Buffer.from(i ? [1] : [0]),
|
|
2468
|
+
e.getWalletId(),
|
|
2469
|
+
t || dist.Buffer.alloc(32, 0),
|
|
2470
|
+
dist.Buffer.from([r]),
|
|
2471
|
+
a
|
|
2472
|
+
]), s2)).toString("ascii");
|
|
2473
|
+
});
|
|
2474
|
+
}
|
|
2475
|
+
signPsbt(e, t, r, o) {
|
|
2476
|
+
return ae(this, void 0, void 0, function* () {
|
|
2477
|
+
const i = new Ie(e);
|
|
2478
|
+
if (r != null && r.length != 32)
|
|
2479
|
+
throw new Error("Invalid HMAC length");
|
|
2480
|
+
const s2 = new He(o);
|
|
2481
|
+
s2.addKnownList(t.keys.map((h) => dist.Buffer.from(h, "ascii"))), s2.addKnownPreimage(t.serialize()), s2.addKnownMapping(i.globalMerkleMap);
|
|
2482
|
+
for (const h of i.inputMerkleMaps)
|
|
2483
|
+
s2.addKnownMapping(h);
|
|
2484
|
+
for (const h of i.outputMerkleMaps)
|
|
2485
|
+
s2.addKnownMapping(h);
|
|
2486
|
+
s2.addKnownList(i.inputMapCommitments);
|
|
2487
|
+
const a = new te(i.inputMapCommitments.map((h) => ne(h))).getRoot();
|
|
2488
|
+
s2.addKnownList(i.outputMapCommitments);
|
|
2489
|
+
const c = new te(i.outputMapCommitments.map((h) => ne(h))).getRoot();
|
|
2490
|
+
yield this.makeRequest(J.SIGN_PSBT, dist.Buffer.concat([
|
|
2491
|
+
i.getGlobalKeysValuesRoot(),
|
|
2492
|
+
M(i.getGlobalInputCount()),
|
|
2493
|
+
a,
|
|
2494
|
+
M(i.getGlobalOutputCount()),
|
|
2495
|
+
c,
|
|
2496
|
+
t.getWalletId(),
|
|
2497
|
+
r || dist.Buffer.alloc(32, 0)
|
|
2498
|
+
]), s2);
|
|
2499
|
+
const l = s2.getYielded(), f = /* @__PURE__ */ new Map();
|
|
2500
|
+
for (const h of l)
|
|
2501
|
+
f.set(h[0], h.slice(1));
|
|
2502
|
+
return f;
|
|
2503
|
+
});
|
|
2504
|
+
}
|
|
2505
|
+
getMasterFingerprint() {
|
|
2506
|
+
return ae(this, void 0, void 0, function* () {
|
|
2507
|
+
return this.makeRequest(J.GET_MASTER_FINGERPRINT, dist.Buffer.from([]));
|
|
2508
|
+
});
|
|
2509
|
+
}
|
|
2510
|
+
signMessage(e, t) {
|
|
2511
|
+
return ae(this, void 0, void 0, function* () {
|
|
2512
|
+
if (t.length > 6)
|
|
2513
|
+
throw new Error("Path too long. At most 6 levels allowed.");
|
|
2514
|
+
const r = new He(() => {
|
|
2515
|
+
}), o = Math.ceil(e.length / 64), i = [];
|
|
2516
|
+
for (let c = 0; c < o; c++)
|
|
2517
|
+
i.push(e.subarray(64 * c, 64 * c + 64));
|
|
2518
|
+
r.addKnownList(i);
|
|
2519
|
+
const s2 = new te(i.map((c) => ne(c))).getRoot();
|
|
2520
|
+
return (yield this.makeRequest(J.SIGN_MESSAGE, dist.Buffer.concat([Ye(t), M(e.length), s2]), r)).toString("base64");
|
|
2521
|
+
});
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2524
|
+
function Ur(n) {
|
|
2525
|
+
let e = "TX";
|
|
2526
|
+
return e += " version " + n.version.toString("hex"), n.locktime && (e += " locktime " + n.locktime.toString("hex")), n.witness && (e += " witness " + n.witness.toString("hex")), n.timestamp && (e += " timestamp " + n.timestamp.toString("hex")), n.nVersionGroupId && (e += " nVersionGroupId " + n.nVersionGroupId.toString("hex")), n.nExpiryHeight && (e += " nExpiryHeight " + n.nExpiryHeight.toString("hex")), n.extraData && (e += " extraData " + n.extraData.toString("hex")), n.inputs.forEach(({ prevout: t, script: r, sequence: o }, i) => {
|
|
2527
|
+
e += `
|
|
2528
|
+
input ${i}:`, e += ` prevout ${t.toString("hex")}`, e += ` script ${r.toString("hex")}`, e += ` sequence ${o.toString("hex")}`;
|
|
2529
|
+
}), (n.outputs || []).forEach(({ amount: t, script: r }, o) => {
|
|
2530
|
+
e += `
|
|
2531
|
+
output ${o}:`, e += ` amount ${t.toString("hex")}`, e += ` script ${r.toString("hex")}`;
|
|
2532
|
+
}), e;
|
|
2533
|
+
}
|
|
2534
|
+
function Mr(n, e = false, t = false, r = false, o = []) {
|
|
2535
|
+
const i = [], s2 = [];
|
|
2536
|
+
let a = false, c = 0, l = dist.Buffer.alloc(0), f = dist.Buffer.alloc(0), h = dist.Buffer.alloc(0), x = dist.Buffer.alloc(0), w2, T;
|
|
2537
|
+
const y = o.includes("decred"), B = o.includes("zencash"), m = o.includes("zcash"), p = dist.Buffer.from(n, "hex"), d$1 = p.slice(c, c + 4), E = d$1.equals(dist.Buffer.from([3, 0, 0, 128])) || d$1.equals(dist.Buffer.from([4, 0, 0, 128])) || d$1.equals(dist.Buffer.from([5, 0, 0, 128])), _ = m && d$1.equals(dist.Buffer.from([5, 0, 0, 128]));
|
|
2538
|
+
c += 4, !t && e && p[c] === 0 && p[c + 1] !== 0 && !B && (c += 2, a = true), t && (l = p.slice(c, 4 + c), c += 4), E && (h = p.slice(c, 4 + c), c += 4), _ && (T = p.slice(c + 4, c + 8), f = p.slice(c + 8, c + 12), c += 12);
|
|
2539
|
+
let I = ce(p, c);
|
|
2540
|
+
const b = I[0];
|
|
2541
|
+
c += I[1];
|
|
2542
|
+
for (let C = 0; C < b; C++) {
|
|
2543
|
+
const j = p.slice(c, c + 36);
|
|
2544
|
+
c += 36;
|
|
2545
|
+
let V = dist.Buffer.alloc(0), W = dist.Buffer.alloc(0);
|
|
2546
|
+
y ? (W = p.slice(c, c + 1), c += 1) : (I = ce(p, c), c += I[1], V = p.slice(c, c + I[0]), c += I[0]);
|
|
2547
|
+
const pe = p.slice(c, c + 4);
|
|
2548
|
+
c += 4, i.push({
|
|
2549
|
+
prevout: j,
|
|
2550
|
+
script: V,
|
|
2551
|
+
sequence: pe,
|
|
2552
|
+
tree: W
|
|
2553
|
+
});
|
|
2554
|
+
}
|
|
2555
|
+
I = ce(p, c);
|
|
2556
|
+
const U = I[0];
|
|
2557
|
+
c += I[1];
|
|
2558
|
+
for (let C = 0; C < U; C++) {
|
|
2559
|
+
const j = p.slice(c, c + 8);
|
|
2560
|
+
c += 8, y && (c += 2), I = ce(p, c), c += I[1];
|
|
2561
|
+
const V = p.slice(c, c + I[0]);
|
|
2562
|
+
c += I[0], s2.push({
|
|
2563
|
+
amount: j,
|
|
2564
|
+
script: V
|
|
2565
|
+
});
|
|
2566
|
+
}
|
|
2567
|
+
if (a ? (w2 = p.slice(c, -4), T = p.slice(p.length - 4)) : _ || (T = p.slice(c, c + 4)), c += 4, (E || y) && !_ && (f = p.slice(c, c + 4), c += 4), r && (x = p.slice(c)), y) {
|
|
2568
|
+
if (I = ce(p, c), c += I[1], I[0] !== b)
|
|
2569
|
+
throw new Error("splitTransaction: incoherent number of witnesses");
|
|
2570
|
+
for (let C = 0; C < b; C++) {
|
|
2571
|
+
c += 8, c += 4, c += 4, I = ce(p, c), c += I[1];
|
|
2572
|
+
const j = p.slice(c, c + I[0]);
|
|
2573
|
+
c += I[0], i[C].script = j;
|
|
2574
|
+
}
|
|
2575
|
+
}
|
|
2576
|
+
const q = {
|
|
2577
|
+
version: d$1,
|
|
2578
|
+
inputs: i,
|
|
2579
|
+
outputs: s2,
|
|
2580
|
+
locktime: T,
|
|
2581
|
+
witness: w2,
|
|
2582
|
+
timestamp: l,
|
|
2583
|
+
nVersionGroupId: h,
|
|
2584
|
+
nExpiryHeight: f,
|
|
2585
|
+
extraData: x
|
|
2586
|
+
};
|
|
2587
|
+
return d("btc", `splitTransaction ${n}:
|
|
2588
|
+
${Ur(q)}`), q;
|
|
2589
|
+
}
|
|
2590
|
+
var Ar = globalThis && globalThis.__awaiter || function(n, e, t, r) {
|
|
2591
|
+
function o(i) {
|
|
2592
|
+
return i instanceof t ? i : new t(function(s2) {
|
|
2593
|
+
s2(i);
|
|
2594
|
+
});
|
|
2595
|
+
}
|
|
2596
|
+
return new (t || (t = Promise))(function(i, s2) {
|
|
2597
|
+
function a(f) {
|
|
2598
|
+
try {
|
|
2599
|
+
l(r.next(f));
|
|
2600
|
+
} catch (h) {
|
|
2601
|
+
s2(h);
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
function c(f) {
|
|
2605
|
+
try {
|
|
2606
|
+
l(r.throw(f));
|
|
2607
|
+
} catch (h) {
|
|
2608
|
+
s2(h);
|
|
2609
|
+
}
|
|
2610
|
+
}
|
|
2611
|
+
function l(f) {
|
|
2612
|
+
f.done ? i(f.value) : o(f.value).then(a, c);
|
|
2613
|
+
}
|
|
2614
|
+
l((r = r.apply(n, e || [])).next());
|
|
2615
|
+
});
|
|
2616
|
+
};
|
|
2617
|
+
const Nr = {
|
|
2618
|
+
lockTime: Ft,
|
|
2619
|
+
sigHashType: at,
|
|
2620
|
+
segwit: false,
|
|
2621
|
+
transactionVersion: Cn
|
|
2622
|
+
};
|
|
2623
|
+
function Dr(n, e) {
|
|
2624
|
+
return Ar(this, void 0, void 0, function* () {
|
|
2625
|
+
const { inputs: t, associatedKeysets: r, outputScriptHex: o, lockTime: i, sigHashType: s2, segwit: a, transactionVersion: c } = Object.assign(Object.assign({}, Nr), e), l = dist.Buffer.alloc(0), f = dist.Buffer.alloc(0), h = dist.Buffer.alloc(4);
|
|
2626
|
+
h.writeUInt32LE(c, 0);
|
|
2627
|
+
const x = [], w2 = [], T = [];
|
|
2628
|
+
let y = true;
|
|
2629
|
+
const B = {
|
|
2630
|
+
inputs: [],
|
|
2631
|
+
version: h
|
|
2632
|
+
}, m = a ? dt : pt, p = dist.Buffer.from(o, "hex");
|
|
2633
|
+
for (const d2 of t) {
|
|
2634
|
+
{
|
|
2635
|
+
const I = yield m(n, d2[1], d2[0]), b = dist.Buffer.alloc(4);
|
|
2636
|
+
b.writeUInt32LE(d2.length >= 4 && typeof d2[3] == "number" ? d2[3] : be, 0), x.push({
|
|
2637
|
+
trustedInput: false,
|
|
2638
|
+
value: a ? dist.Buffer.from(I, "hex") : dist.Buffer.from(I, "hex").slice(4, 4 + 36),
|
|
2639
|
+
sequence: b
|
|
2640
|
+
});
|
|
2641
|
+
}
|
|
2642
|
+
const { outputs: E } = d2[0], _ = d2[1];
|
|
2643
|
+
E && _ <= E.length - 1 && w2.push(E[_]);
|
|
2644
|
+
}
|
|
2645
|
+
for (let d2 = 0; d2 < t.length; d2++) {
|
|
2646
|
+
const E = dist.Buffer.alloc(4);
|
|
2647
|
+
E.writeUInt32LE(t[d2].length >= 4 && typeof t[d2][3] == "number" ? t[d2][3] : be, 0), B.inputs.push({
|
|
2648
|
+
script: l,
|
|
2649
|
+
prevout: f,
|
|
2650
|
+
sequence: E
|
|
2651
|
+
});
|
|
2652
|
+
}
|
|
2653
|
+
a && (yield Oe(n, true, B, x, true), yield Re(n, p));
|
|
2654
|
+
for (let d2 = 0; d2 < t.length; d2++) {
|
|
2655
|
+
const E = t[d2], _ = t[d2].length >= 3 && typeof E[2] == "string" ? dist.Buffer.from(E[2], "hex") : w2[d2].script, I = Object.assign({}, B), b = a ? [x[d2]] : x;
|
|
2656
|
+
a ? I.inputs = [Object.assign(Object.assign({}, I.inputs[d2]), { script: _ })] : I.inputs[d2].script = _, yield Oe(n, !a && y, I, b, a), a || (yield Re(n, p));
|
|
2657
|
+
const U = yield tt(n, r[d2], i, s2);
|
|
2658
|
+
T.push(a ? U.toString("hex") : U.slice(0, U.length - 1).toString("hex")), B.inputs[d2].script = l, y && (y = false);
|
|
2659
|
+
}
|
|
2660
|
+
return T;
|
|
2661
|
+
});
|
|
2662
|
+
}
|
|
2663
|
+
var kr = globalThis && globalThis.__awaiter || function(n, e, t, r) {
|
|
2664
|
+
function o(i) {
|
|
2665
|
+
return i instanceof t ? i : new t(function(s2) {
|
|
2666
|
+
s2(i);
|
|
2667
|
+
});
|
|
2668
|
+
}
|
|
2669
|
+
return new (t || (t = Promise))(function(i, s2) {
|
|
2670
|
+
function a(f) {
|
|
2671
|
+
try {
|
|
2672
|
+
l(r.next(f));
|
|
2673
|
+
} catch (h) {
|
|
2674
|
+
s2(h);
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2677
|
+
function c(f) {
|
|
2678
|
+
try {
|
|
2679
|
+
l(r.throw(f));
|
|
2680
|
+
} catch (h) {
|
|
2681
|
+
s2(h);
|
|
2682
|
+
}
|
|
2683
|
+
}
|
|
2684
|
+
function l(f) {
|
|
2685
|
+
f.done ? i(f.value) : o(f.value).then(a, c);
|
|
2686
|
+
}
|
|
2687
|
+
l((r = r.apply(n, e || [])).next());
|
|
2688
|
+
});
|
|
2689
|
+
};
|
|
2690
|
+
class ti {
|
|
2691
|
+
constructor({ transport: e, scrambleKey: t = "BTC", currency: r = "bitcoin" }) {
|
|
2692
|
+
this._transport = e, this._transport.decorateAppAPIMethods(this, [
|
|
2693
|
+
"getWalletXpub",
|
|
2694
|
+
"getWalletPublicKey",
|
|
2695
|
+
"signP2SHTransaction",
|
|
2696
|
+
"signMessage",
|
|
2697
|
+
"createPaymentTransaction",
|
|
2698
|
+
"getTrustedInput",
|
|
2699
|
+
"getTrustedInputBIP143"
|
|
2700
|
+
], t), r === "bitcoin" || r === "bitcoin_testnet" ? this._impl = new nr(new Rr(this._transport)) : this._impl = new ze(this._transport);
|
|
2701
|
+
}
|
|
2702
|
+
/**
|
|
2703
|
+
* Get an XPUB with a ledger device
|
|
2704
|
+
* @param arg derivation parameter
|
|
2705
|
+
* - path: a BIP 32 path of the account level. e.g. `84'/0'/0'`
|
|
2706
|
+
* - xpubVersion: the XPUBVersion of the coin used. (use @ledgerhq/currencies if needed)
|
|
2707
|
+
* @returns XPUB of the account
|
|
2708
|
+
*/
|
|
2709
|
+
getWalletXpub(e) {
|
|
2710
|
+
return this.changeImplIfNecessary().then((t) => t.getWalletXpub(e));
|
|
2711
|
+
}
|
|
2712
|
+
/**
|
|
2713
|
+
* @param path a BIP 32 path
|
|
2714
|
+
* @param options an object with optional these fields:
|
|
2715
|
+
*
|
|
2716
|
+
* - verify (boolean) will ask user to confirm the address on the device
|
|
2717
|
+
*
|
|
2718
|
+
* - format ("legacy" | "p2sh" | "bech32" | "bech32m" | "cashaddr") to use different bitcoin address formatter.
|
|
2719
|
+
*
|
|
2720
|
+
* NB The normal usage is to use:
|
|
2721
|
+
*
|
|
2722
|
+
* - legacy format with 44' paths
|
|
2723
|
+
*
|
|
2724
|
+
* - p2sh format with 49' paths
|
|
2725
|
+
*
|
|
2726
|
+
* - bech32 format with 84' paths
|
|
2727
|
+
*
|
|
2728
|
+
* - cashaddr in case of Bitcoin Cash
|
|
2729
|
+
*
|
|
2730
|
+
* @example
|
|
2731
|
+
* btc.getWalletPublicKey("44'/0'/0'/0/0").then(o => o.bitcoinAddress)
|
|
2732
|
+
* btc.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress)
|
|
2733
|
+
*/
|
|
2734
|
+
getWalletPublicKey(e, t) {
|
|
2735
|
+
let r;
|
|
2736
|
+
return arguments.length > 2 || typeof t == "boolean" ? (console.warn("btc.getWalletPublicKey deprecated signature used. Please switch to getWalletPublicKey(path, { format, verify })"), r = {
|
|
2737
|
+
verify: !!t,
|
|
2738
|
+
// eslint-disable-next-line prefer-rest-params
|
|
2739
|
+
format: arguments[2] ? "p2sh" : "legacy"
|
|
2740
|
+
}) : r = t || {}, this.changeImplIfNecessary().then((o) => o.getWalletPublicKey(e, r));
|
|
2741
|
+
}
|
|
2742
|
+
/**
|
|
2743
|
+
* You can sign a message according to the Bitcoin Signature format and retrieve v, r, s given the message and the BIP 32 path of the account to sign.
|
|
2744
|
+
* @example
|
|
2745
|
+
btc.signMessage("44'/60'/0'/0'/0", Buffer.from("test").toString("hex")).then(function(result) {
|
|
2746
|
+
var v = result['v'] + 27 + 4;
|
|
2747
|
+
var signature = Buffer.from(v.toString(16) + result['r'] + result['s'], 'hex').toString('base64');
|
|
2748
|
+
console.log("Signature : " + signature);
|
|
2749
|
+
}).catch(function(ex) {console.log(ex);});
|
|
2750
|
+
*/
|
|
2751
|
+
signMessage(e, t) {
|
|
2752
|
+
return this.changeImplIfNecessary().then((r) => r.signMessage({
|
|
2753
|
+
path: e,
|
|
2754
|
+
messageHex: t
|
|
2755
|
+
}));
|
|
2756
|
+
}
|
|
2757
|
+
/**
|
|
2758
|
+
* To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters
|
|
2759
|
+
* @param inputs is an array of [ transaction, output_index, optional redeem script, optional sequence ] where
|
|
2760
|
+
*
|
|
2761
|
+
* * transaction is the previously computed transaction object for this UTXO
|
|
2762
|
+
* * output_index is the output in the transaction used as input for this UTXO (counting from 0)
|
|
2763
|
+
* * redeem script is the optional redeem script to use when consuming a Segregated Witness input
|
|
2764
|
+
* * sequence is the sequence number to use for this input (when using RBF), or non present
|
|
2765
|
+
* @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
|
|
2766
|
+
* @param changePath is an optional BIP 32 path pointing to the path to the public key used to compute the change address
|
|
2767
|
+
* @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign, including leading vararg voutCount
|
|
2768
|
+
* @param lockTime is the optional lockTime of the transaction to sign, or default (0)
|
|
2769
|
+
* @param sigHashType is the hash type of the transaction to sign, or default (all)
|
|
2770
|
+
* @param segwit is an optional boolean indicating wether to use segwit or not. This includes wrapped segwit.
|
|
2771
|
+
* @param initialTimestamp is an optional timestamp of the function call to use for coins that necessitate timestamps only, (not the one that the tx will include)
|
|
2772
|
+
* @param additionals list of additionnal options
|
|
2773
|
+
*
|
|
2774
|
+
* - "bech32" for spending native segwit outputs
|
|
2775
|
+
* - "bech32m" for spending segwit v1+ outputs
|
|
2776
|
+
* - "abc" for bch
|
|
2777
|
+
* - "gold" for btg
|
|
2778
|
+
* - "bipxxx" for using BIPxxx
|
|
2779
|
+
* - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200)
|
|
2780
|
+
* @param expiryHeight is an optional Buffer for zec overwinter / sapling Txs
|
|
2781
|
+
* @param useTrustedInputForSegwit trust inputs for segwit transactions. If app version >= 1.4.0 this should be true.
|
|
2782
|
+
* @return the signed transaction ready to be broadcast
|
|
2783
|
+
* @example
|
|
2784
|
+
btc.createTransaction({
|
|
2785
|
+
inputs: [ [tx1, 1] ],
|
|
2786
|
+
associatedKeysets: ["0'/0/0"],
|
|
2787
|
+
outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
|
|
2788
|
+
}).then(res => ...);
|
|
2789
|
+
*/
|
|
2790
|
+
createPaymentTransaction(e) {
|
|
2791
|
+
if (arguments.length > 1)
|
|
2792
|
+
throw new Error("@ledgerhq/hw-app-btc: createPaymentTransaction multi argument signature is deprecated. please switch to named parameters.");
|
|
2793
|
+
return this.changeImplIfNecessary().then((t) => t.createPaymentTransaction(e));
|
|
2794
|
+
}
|
|
2795
|
+
/**
|
|
2796
|
+
* To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransaction_async with the folowing parameters
|
|
2797
|
+
* @param inputs is an array of [ transaction, output_index, redeem script, optional sequence ] where
|
|
2798
|
+
* * transaction is the previously computed transaction object for this UTXO
|
|
2799
|
+
* * output_index is the output in the transaction used as input for this UTXO (counting from 0)
|
|
2800
|
+
* * redeem script is the mandatory redeem script associated to the current P2SH input
|
|
2801
|
+
* * sequence is the sequence number to use for this input (when using RBF), or non present
|
|
2802
|
+
* @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
|
|
2803
|
+
* @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign
|
|
2804
|
+
* @param lockTime is the optional lockTime of the transaction to sign, or default (0)
|
|
2805
|
+
* @param sigHashType is the hash type of the transaction to sign, or default (all)
|
|
2806
|
+
* @return the signed transaction ready to be broadcast
|
|
2807
|
+
* @example
|
|
2808
|
+
btc.signP2SHTransaction({
|
|
2809
|
+
inputs: [ [tx, 1, "52210289b4a3ad52a919abd2bdd6920d8a6879b1e788c38aa76f0440a6f32a9f1996d02103a3393b1439d1693b063482c04bd40142db97bdf139eedd1b51ffb7070a37eac321030b9a409a1e476b0d5d17b804fcdb81cf30f9b99c6f3ae1178206e08bc500639853ae"] ],
|
|
2810
|
+
associatedKeysets: ["0'/0/0"],
|
|
2811
|
+
outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
|
|
2812
|
+
}).then(result => ...);
|
|
2813
|
+
*/
|
|
2814
|
+
signP2SHTransaction(e) {
|
|
2815
|
+
return Dr(this._transport, e);
|
|
2816
|
+
}
|
|
2817
|
+
/**
|
|
2818
|
+
* For each UTXO included in your transaction, create a transaction object from the raw serialized version of the transaction used in this UTXO.
|
|
2819
|
+
* @example
|
|
2820
|
+
const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000");
|
|
2821
|
+
*/
|
|
2822
|
+
splitTransaction(e, t = false, r = false, o = false, i = []) {
|
|
2823
|
+
return Mr(e, t, r, o, i);
|
|
2824
|
+
}
|
|
2825
|
+
/**
|
|
2826
|
+
@example
|
|
2827
|
+
const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000");
|
|
2828
|
+
const outputScript = btc.serializeTransactionOutputs(tx1).toString('hex');
|
|
2829
|
+
*/
|
|
2830
|
+
serializeTransactionOutputs(e) {
|
|
2831
|
+
return zt(e);
|
|
2832
|
+
}
|
|
2833
|
+
getTrustedInput(e, t, r = []) {
|
|
2834
|
+
return pt(this._transport, e, t, r);
|
|
2835
|
+
}
|
|
2836
|
+
getTrustedInputBIP143(e, t, r = []) {
|
|
2837
|
+
return dt(this._transport, e, t, r);
|
|
2838
|
+
}
|
|
2839
|
+
changeImplIfNecessary() {
|
|
2840
|
+
return kr(this, void 0, void 0, function* () {
|
|
2841
|
+
if (this._impl instanceof ze)
|
|
2842
|
+
return this._impl;
|
|
2843
|
+
const e = yield Yt(this._transport);
|
|
2844
|
+
let t = true;
|
|
2845
|
+
if (e.name === "Bitcoin" || e.name === "Bitcoin Test") {
|
|
2846
|
+
const [r, o] = e.version.split(".");
|
|
2847
|
+
t = parseInt(r) <= 1 || parseInt(r) == 2 && parseInt(o) == 0;
|
|
2848
|
+
} else
|
|
2849
|
+
e.name === "Bitcoin Legacy" || e.name === "Bitcoin Test Legacy" ? t = true : e.name === "Exchange" && (t = yield ar(this._transport));
|
|
2850
|
+
return t && (this._impl = new ze(this._transport)), this._impl;
|
|
2851
|
+
});
|
|
2852
|
+
}
|
|
2853
|
+
}
|
|
2854
|
+
export {
|
|
2855
|
+
ti as default
|
|
2856
|
+
};
|