@babylonlabs-io/ts-sdk 0.36.1 → 0.36.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/PeginManager-BPXVXu8t.cjs +2 -0
- package/dist/{PeginManager-cPQuJTB9.cjs.map → PeginManager-BPXVXu8t.cjs.map} +1 -1
- package/dist/{PeginManager-DF1oinIQ.js → PeginManager-CB-dVkT2.js} +387 -369
- package/dist/{PeginManager-DF1oinIQ.js.map → PeginManager-CB-dVkT2.js.map} +1 -1
- package/dist/{buildAndBroadcastRefund-D4YqqClN.js → buildAndBroadcastRefund-C2VqXiOx.js} +241 -220
- package/dist/buildAndBroadcastRefund-C2VqXiOx.js.map +1 -0
- package/dist/buildAndBroadcastRefund-CBIfcF47.cjs +2 -0
- package/dist/buildAndBroadcastRefund-CBIfcF47.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +4 -4
- package/dist/reservation-DF0uiCUC.cjs +2 -0
- package/dist/reservation-DF0uiCUC.cjs.map +1 -0
- package/dist/{reservation-CHUGW0F_.js → reservation-fZUvejYK.js} +36 -35
- package/dist/reservation-fZUvejYK.js.map +1 -0
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +1 -1
- package/dist/tbv/core/clients/vault-provider/validators.d.ts.map +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +4 -4
- package/dist/tbv/core/managers/PeginManager.d.ts +22 -4
- package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
- package/dist/tbv/core/managers/index.cjs +1 -1
- package/dist/tbv/core/managers/index.js +1 -1
- package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts.map +1 -1
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +1 -1
- package/dist/tbv/core/utils/index.cjs +1 -1
- package/dist/tbv/core/utils/index.js +1 -1
- package/dist/tbv/core/utils/utxo/reservation.d.ts +4 -1
- package/dist/tbv/core/utils/utxo/reservation.d.ts.map +1 -1
- package/dist/tbv/core/vault-secrets/index.d.ts +1 -0
- package/dist/tbv/core/vault-secrets/index.d.ts.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +4 -4
- package/dist/vault-registry-reader-Br9m8bHF.cjs +2 -0
- package/dist/vault-registry-reader-Br9m8bHF.cjs.map +1 -0
- package/dist/{vault-registry-reader-CrLodprY.js → vault-registry-reader-CohvzvoH.js} +129 -124
- package/dist/vault-registry-reader-CohvzvoH.js.map +1 -0
- package/package.json +1 -1
- package/dist/PeginManager-cPQuJTB9.cjs +0 -2
- package/dist/buildAndBroadcastRefund-D4YqqClN.js.map +0 -1
- package/dist/buildAndBroadcastRefund-DSELaUiR.cjs +0 -2
- package/dist/buildAndBroadcastRefund-DSELaUiR.cjs.map +0 -1
- package/dist/reservation-CHUGW0F_.js.map +0 -1
- package/dist/reservation-ho7mjW3X.cjs +0 -2
- package/dist/reservation-ho7mjW3X.cjs.map +0 -1
- package/dist/vault-registry-reader-CLnhAUN4.cjs +0 -2
- package/dist/vault-registry-reader-CLnhAUN4.cjs.map +0 -1
- package/dist/vault-registry-reader-CrLodprY.js.map +0 -1
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { s as
|
|
5
|
-
import * as
|
|
6
|
-
import { Transaction as
|
|
7
|
-
import { Buffer as
|
|
8
|
-
import { isAddressEqual as
|
|
9
|
-
import { B as
|
|
1
|
+
var Mt = Object.defineProperty;
|
|
2
|
+
var Xt = (n, t, e) => t in n ? Mt(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
|
|
3
|
+
var k = (n, t, e) => Xt(n, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { s as nt, c as Bt, H as Kt, r as U, a as F, b as rt, u as Dt, d as it, e as at, f as ct, g as zt } from "./sha2-BYVxyZzX.js";
|
|
5
|
+
import * as It from "bitcoinjs-lib";
|
|
6
|
+
import { Transaction as Gt, Psbt as lt } from "bitcoinjs-lib";
|
|
7
|
+
import { Buffer as Q } from "buffer";
|
|
8
|
+
import { isAddressEqual as ut, encodeFunctionData as ht, zeroAddress as jt } from "viem";
|
|
9
|
+
import { B as O } from "./BTCVaultRegistry.abi-DbJ5lsFJ.js";
|
|
10
10
|
import { h as A } from "./errors-CznAK5NB.js";
|
|
11
|
-
import { expandWotsSeed as
|
|
12
|
-
import { b as
|
|
13
|
-
import { s as T, u as M, h as
|
|
14
|
-
import { c as
|
|
15
|
-
import { M as
|
|
16
|
-
import { c as
|
|
17
|
-
import { s as
|
|
18
|
-
import { p as
|
|
19
|
-
import { p as
|
|
20
|
-
const N = /* @__PURE__ */ BigInt(2 ** 32 - 1),
|
|
21
|
-
function
|
|
22
|
-
return t ? { h: Number(n & N), l: Number(n >>
|
|
11
|
+
import { expandWotsSeed as qt, expandHashlockSecret as Zt, expandAuthAnchor as Qt, deriveVaultId as dt } from "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
12
|
+
import { b as gt, a as Yt, c as Jt, e as te, f as ee } from "./peginInput-C2QPvuhR.js";
|
|
13
|
+
import { s as T, u as M, h as Y, e as B, p as ne, i as ft, g as pt } from "./bitcoin-B0S8SHCX.js";
|
|
14
|
+
import { c as se } from "./signing-DaLvGwQe.js";
|
|
15
|
+
import { M as mt } from "./validation-CxqROCno.js";
|
|
16
|
+
import { c as oe } from "./PayoutManager-s_uH8Uuj.js";
|
|
17
|
+
import { s as re, c as z, d as ie, w as wt } from "./waitForTransactionReceiptSmartAware-Cj_DKm0G.js";
|
|
18
|
+
import { p as ae, f as ce } from "./fundPeginTransaction-oV-dNJOU.js";
|
|
19
|
+
import { p as le, f as ue } from "./mempoolApi-CAIge7Nj.js";
|
|
20
|
+
const N = /* @__PURE__ */ BigInt(2 ** 32 - 1), Pt = /* @__PURE__ */ BigInt(32);
|
|
21
|
+
function he(n, t = !1) {
|
|
22
|
+
return t ? { h: Number(n & N), l: Number(n >> Pt & N) } : { h: Number(n >> Pt & N) | 0, l: Number(n & N) | 0 };
|
|
23
23
|
}
|
|
24
|
-
function
|
|
24
|
+
function de(n, t = !1) {
|
|
25
25
|
const e = n.length;
|
|
26
26
|
let s = new Uint32Array(e), o = new Uint32Array(e);
|
|
27
27
|
for (let r = 0; r < e; r++) {
|
|
28
|
-
const { h: i, l: a } =
|
|
28
|
+
const { h: i, l: a } = he(n[r], t);
|
|
29
29
|
[s[r], o[r]] = [i, a];
|
|
30
30
|
}
|
|
31
31
|
return [s, o];
|
|
32
32
|
}
|
|
33
|
-
const
|
|
34
|
-
function
|
|
35
|
-
const s = T(n), o =
|
|
33
|
+
const ge = (n, t, e) => n << e | t >>> 32 - e, fe = (n, t, e) => t << e | n >>> 32 - e, pe = (n, t, e) => t << e - 32 | n >>> 64 - e, me = (n, t, e) => n << e - 32 | t >>> 64 - e, we = 106, Pe = 32, bt = 34;
|
|
34
|
+
function be(n, t, e) {
|
|
35
|
+
const s = T(n), o = It.Transaction.fromHex(s);
|
|
36
36
|
if (o.outs.length <= t)
|
|
37
37
|
throw new Error(
|
|
38
38
|
`Pre-PegIn auth-anchor OP_RETURN missing: tx has ${o.outs.length} outputs, expected at least ${t + 1} (vault outputs + OP_RETURN)`
|
|
39
39
|
);
|
|
40
40
|
const r = o.outs[t], i = r.script;
|
|
41
|
-
if (i.length !==
|
|
41
|
+
if (i.length !== bt || i[0] !== we || i[1] !== Pe)
|
|
42
42
|
throw new Error(
|
|
43
|
-
`Pre-PegIn auth-anchor OP_RETURN at vout ${t} has unexpected script encoding (got ${i.length}-byte script with prefix 0x${i.slice(0, Math.min(2, i.length)).toString("hex")}; expected ${
|
|
43
|
+
`Pre-PegIn auth-anchor OP_RETURN at vout ${t} has unexpected script encoding (got ${i.length}-byte script with prefix 0x${i.slice(0, Math.min(2, i.length)).toString("hex")}; expected ${bt}-byte OP_RETURN + PUSH32 layout)`
|
|
44
44
|
);
|
|
45
45
|
const a = i.slice(2).toString("hex").toLowerCase();
|
|
46
46
|
if (a !== e.toLowerCase())
|
|
@@ -52,70 +52,70 @@ function we(n, t, e) {
|
|
|
52
52
|
`Pre-PegIn auth-anchor OP_RETURN at vout ${t} has non-zero value ${r.value}; OP_RETURN outputs must be 0-value`
|
|
53
53
|
);
|
|
54
54
|
}
|
|
55
|
-
const C = 32,
|
|
56
|
-
function
|
|
55
|
+
const C = 32, G = 32, J = 36, St = 32, X = 4, ye = X + C + X + St;
|
|
56
|
+
function tt(n, t, e) {
|
|
57
57
|
n[t] = e >>> 24 & 255, n[t + 1] = e >>> 16 & 255, n[t + 2] = e >>> 8 & 255, n[t + 3] = e & 255;
|
|
58
58
|
}
|
|
59
|
-
function
|
|
60
|
-
if (n.txid.length !==
|
|
59
|
+
function xe(n) {
|
|
60
|
+
if (n.txid.length !== G)
|
|
61
61
|
throw new Error(
|
|
62
|
-
`outpoint.txid must be exactly ${
|
|
62
|
+
`outpoint.txid must be exactly ${G} bytes, got ${n.txid.length}`
|
|
63
63
|
);
|
|
64
64
|
if (!Number.isInteger(n.vout) || n.vout < 0 || n.vout > 4294967295)
|
|
65
65
|
throw new Error(`outpoint.vout must be a u32, got ${n.vout}`);
|
|
66
|
-
const t = new Uint8Array(
|
|
67
|
-
return t.set(n.txid, 0),
|
|
66
|
+
const t = new Uint8Array(J);
|
|
67
|
+
return t.set(n.txid, 0), tt(t, G, n.vout), t;
|
|
68
68
|
}
|
|
69
|
-
function
|
|
69
|
+
function yt(n, t) {
|
|
70
70
|
const e = Math.min(n.length, t.length);
|
|
71
71
|
for (let s = 0; s < e; s++)
|
|
72
72
|
if (n[s] !== t[s]) return n[s] - t[s];
|
|
73
73
|
return n.length - t.length;
|
|
74
74
|
}
|
|
75
|
-
function
|
|
75
|
+
function ke(n) {
|
|
76
76
|
if (n.length === 0)
|
|
77
77
|
throw new Error(
|
|
78
78
|
"buildFundingOutpointsCommitment: outpoints must be non-empty"
|
|
79
79
|
);
|
|
80
|
-
const t = n.map(
|
|
81
|
-
t.sort(
|
|
80
|
+
const t = n.map(xe);
|
|
81
|
+
t.sort(yt);
|
|
82
82
|
for (let s = 1; s < t.length; s++)
|
|
83
|
-
if (
|
|
83
|
+
if (yt(t[s - 1], t[s]) === 0)
|
|
84
84
|
throw new Error(
|
|
85
85
|
"buildFundingOutpointsCommitment: duplicate outpoint detected"
|
|
86
86
|
);
|
|
87
|
-
const e = new Uint8Array(t.length *
|
|
87
|
+
const e = new Uint8Array(t.length * J);
|
|
88
88
|
for (let s = 0; s < t.length; s++)
|
|
89
|
-
e.set(t[s], s *
|
|
90
|
-
return
|
|
89
|
+
e.set(t[s], s * J);
|
|
90
|
+
return nt(e);
|
|
91
91
|
}
|
|
92
|
-
function
|
|
92
|
+
function Ee(n) {
|
|
93
93
|
if (n.depositorBtcPubkey.length !== C)
|
|
94
94
|
throw new Error(
|
|
95
95
|
`vaultContext: depositorBtcPubkey must be exactly ${C} bytes, got ${n.depositorBtcPubkey.length}`
|
|
96
96
|
);
|
|
97
|
-
const t =
|
|
97
|
+
const t = ke(n.fundingOutpoints), e = new Uint8Array(ye);
|
|
98
98
|
let s = 0;
|
|
99
|
-
return
|
|
99
|
+
return tt(e, s, C), s += X, e.set(n.depositorBtcPubkey, s), s += C, tt(e, s, St), s += X, e.set(t, s), e;
|
|
100
100
|
}
|
|
101
|
-
const
|
|
102
|
-
async function
|
|
103
|
-
const e =
|
|
101
|
+
const Te = "babylon-btc-vault", At = 32, xt = At * 2, _e = /^[0-9a-f]+$/;
|
|
102
|
+
async function ve(n, t) {
|
|
103
|
+
const e = Ee(t), s = M(e), o = await n.deriveContextHash(Te, s);
|
|
104
104
|
if (typeof o != "string")
|
|
105
105
|
throw new Error(
|
|
106
106
|
`deriveVaultRoot: wallet must return a string, got ${typeof o}`
|
|
107
107
|
);
|
|
108
|
-
if (o.length !==
|
|
108
|
+
if (o.length !== xt)
|
|
109
109
|
throw new Error(
|
|
110
|
-
`deriveVaultRoot: wallet must return a ${
|
|
110
|
+
`deriveVaultRoot: wallet must return a ${xt}-character hex string (${At} bytes), got length ${o.length}`
|
|
111
111
|
);
|
|
112
|
-
if (!
|
|
112
|
+
if (!_e.test(o))
|
|
113
113
|
throw new Error(
|
|
114
114
|
"deriveVaultRoot: wallet must return lowercase hex per derive-context-hash.md §2.1; got value with non-lowercase or non-hex characters"
|
|
115
115
|
);
|
|
116
|
-
return
|
|
116
|
+
return Y(o);
|
|
117
117
|
}
|
|
118
|
-
const
|
|
118
|
+
const Be = /* @__PURE__ */ Uint8Array.from([
|
|
119
119
|
7,
|
|
120
120
|
4,
|
|
121
121
|
13,
|
|
@@ -132,43 +132,43 @@ const _e = /* @__PURE__ */ Uint8Array.from([
|
|
|
132
132
|
14,
|
|
133
133
|
11,
|
|
134
134
|
8
|
|
135
|
-
]),
|
|
136
|
-
const e = [[
|
|
135
|
+
]), Rt = Uint8Array.from(new Array(16).fill(0).map((n, t) => t)), Ie = Rt.map((n) => (9 * n + 5) % 16), Ot = /* @__PURE__ */ (() => {
|
|
136
|
+
const e = [[Rt], [Ie]];
|
|
137
137
|
for (let s = 0; s < 4; s++)
|
|
138
138
|
for (let o of e)
|
|
139
|
-
o.push(o[s].map((r) =>
|
|
139
|
+
o.push(o[s].map((r) => Be[r]));
|
|
140
140
|
return e;
|
|
141
|
-
})(),
|
|
141
|
+
})(), $t = Ot[0], Ht = Ot[1], Ct = /* @__PURE__ */ [
|
|
142
142
|
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
|
|
143
143
|
[12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
|
|
144
144
|
[13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
|
|
145
145
|
[14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
|
|
146
146
|
[15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
|
|
147
|
-
].map((n) => Uint8Array.from(n)),
|
|
147
|
+
].map((n) => Uint8Array.from(n)), Se = /* @__PURE__ */ $t.map((n, t) => n.map((e) => Ct[t][e])), Ae = /* @__PURE__ */ Ht.map((n, t) => n.map((e) => Ct[t][e])), Re = /* @__PURE__ */ Uint32Array.from([
|
|
148
148
|
0,
|
|
149
149
|
1518500249,
|
|
150
150
|
1859775393,
|
|
151
151
|
2400959708,
|
|
152
152
|
2840853838
|
|
153
|
-
]),
|
|
153
|
+
]), Oe = /* @__PURE__ */ Uint32Array.from([
|
|
154
154
|
1352829926,
|
|
155
155
|
1548603684,
|
|
156
156
|
1836072691,
|
|
157
157
|
2053994217,
|
|
158
158
|
0
|
|
159
159
|
]);
|
|
160
|
-
function
|
|
160
|
+
function kt(n, t, e, s) {
|
|
161
161
|
return n === 0 ? t ^ e ^ s : n === 1 ? t & e | ~t & s : n === 2 ? (t | ~e) ^ s : n === 3 ? t & s | e & ~s : t ^ (e | ~s);
|
|
162
162
|
}
|
|
163
163
|
const V = /* @__PURE__ */ new Uint32Array(16);
|
|
164
|
-
class
|
|
164
|
+
class $e extends Kt {
|
|
165
165
|
constructor() {
|
|
166
166
|
super(64, 20, 8, !0);
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
167
|
+
k(this, "h0", 1732584193);
|
|
168
|
+
k(this, "h1", -271733879);
|
|
169
|
+
k(this, "h2", -1732584194);
|
|
170
|
+
k(this, "h3", 271733878);
|
|
171
|
+
k(this, "h4", -1009589776);
|
|
172
172
|
}
|
|
173
173
|
get() {
|
|
174
174
|
const { h0: e, h1: s, h2: o, h3: r, h4: i } = this;
|
|
@@ -178,18 +178,18 @@ class Oe extends Ft {
|
|
|
178
178
|
this.h0 = e | 0, this.h1 = s | 0, this.h2 = o | 0, this.h3 = r | 0, this.h4 = i | 0;
|
|
179
179
|
}
|
|
180
180
|
process(e, s) {
|
|
181
|
-
for (let
|
|
182
|
-
V[
|
|
181
|
+
for (let d = 0; d < 16; d++, s += 4)
|
|
182
|
+
V[d] = e.getUint32(s, !0);
|
|
183
183
|
let o = this.h0 | 0, r = o, i = this.h1 | 0, a = i, c = this.h2 | 0, u = c, l = this.h3 | 0, m = l, w = this.h4 | 0, P = w;
|
|
184
|
-
for (let
|
|
185
|
-
const g = 4 -
|
|
184
|
+
for (let d = 0; d < 5; d++) {
|
|
185
|
+
const g = 4 - d, E = Re[d], I = Oe[d], f = $t[d], y = Ht[d], x = Se[d], p = Ae[d];
|
|
186
186
|
for (let b = 0; b < 16; b++) {
|
|
187
|
-
const
|
|
188
|
-
o = w, w = l, l = U(c, 10) | 0, c = i, i =
|
|
187
|
+
const h = U(o + kt(d, i, c, l) + V[f[b]] + E, x[b]) + w | 0;
|
|
188
|
+
o = w, w = l, l = U(c, 10) | 0, c = i, i = h;
|
|
189
189
|
}
|
|
190
190
|
for (let b = 0; b < 16; b++) {
|
|
191
|
-
const
|
|
192
|
-
r = P, P = m, m = U(u, 10) | 0, u = a, a =
|
|
191
|
+
const h = U(r + kt(g, a, u, m) + V[y[b]] + I, p[b]) + P | 0;
|
|
192
|
+
r = P, P = m, m = U(u, 10) | 0, u = a, a = h;
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
this.set(this.h1 + c + m | 0, this.h2 + l + P | 0, this.h3 + w + r | 0, this.h4 + o + a | 0, this.h0 + i + u | 0);
|
|
@@ -201,28 +201,28 @@ class Oe extends Ft {
|
|
|
201
201
|
this.destroyed = !0, F(this.buffer), this.set(0, 0, 0, 0, 0);
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
|
-
const
|
|
205
|
-
for (let n = 0, t =
|
|
206
|
-
[e, s] = [s, (2 * e + 3 * s) % 5],
|
|
207
|
-
let o =
|
|
204
|
+
const He = /* @__PURE__ */ Bt(() => new $e()), Ce = BigInt(0), $ = BigInt(1), Ue = BigInt(2), Ne = BigInt(7), Ve = BigInt(256), Le = BigInt(113), Ut = [], Nt = [], Vt = [];
|
|
205
|
+
for (let n = 0, t = $, e = 1, s = 0; n < 24; n++) {
|
|
206
|
+
[e, s] = [s, (2 * e + 3 * s) % 5], Ut.push(2 * (5 * s + e)), Nt.push((n + 1) * (n + 2) / 2 % 64);
|
|
207
|
+
let o = Ce;
|
|
208
208
|
for (let r = 0; r < 7; r++)
|
|
209
|
-
t = (t <<
|
|
210
|
-
|
|
209
|
+
t = (t << $ ^ (t >> Ne) * Le) % Ve, t & Ue && (o ^= $ << ($ << BigInt(r)) - $);
|
|
210
|
+
Vt.push(o);
|
|
211
211
|
}
|
|
212
|
-
const
|
|
213
|
-
function
|
|
212
|
+
const Lt = de(Vt, !0), We = Lt[0], Fe = Lt[1], Et = (n, t, e) => e > 32 ? pe(n, t, e) : ge(n, t, e), Tt = (n, t, e) => e > 32 ? me(n, t, e) : fe(n, t, e);
|
|
213
|
+
function Me(n, t = 24) {
|
|
214
214
|
const e = new Uint32Array(10);
|
|
215
215
|
for (let s = 24 - t; s < 24; s++) {
|
|
216
216
|
for (let i = 0; i < 10; i++)
|
|
217
217
|
e[i] = n[i] ^ n[i + 10] ^ n[i + 20] ^ n[i + 30] ^ n[i + 40];
|
|
218
218
|
for (let i = 0; i < 10; i += 2) {
|
|
219
|
-
const a = (i + 8) % 10, c = (i + 2) % 10, u = e[c], l = e[c + 1], m =
|
|
219
|
+
const a = (i + 8) % 10, c = (i + 2) % 10, u = e[c], l = e[c + 1], m = Et(u, l, 1) ^ e[a], w = Tt(u, l, 1) ^ e[a + 1];
|
|
220
220
|
for (let P = 0; P < 50; P += 10)
|
|
221
221
|
n[i + P] ^= m, n[i + P + 1] ^= w;
|
|
222
222
|
}
|
|
223
223
|
let o = n[2], r = n[3];
|
|
224
224
|
for (let i = 0; i < 24; i++) {
|
|
225
|
-
const a =
|
|
225
|
+
const a = Nt[i], c = Et(o, r, a), u = Tt(o, r, a), l = Ut[i];
|
|
226
226
|
o = n[l], r = n[l + 1], n[l] = c, n[l + 1] = u;
|
|
227
227
|
}
|
|
228
228
|
for (let i = 0; i < 50; i += 10) {
|
|
@@ -231,36 +231,36 @@ function Le(n, t = 24) {
|
|
|
231
231
|
for (let a = 0; a < 10; a++)
|
|
232
232
|
n[i + a] ^= ~e[(a + 2) % 10] & e[(a + 4) % 10];
|
|
233
233
|
}
|
|
234
|
-
n[0] ^=
|
|
234
|
+
n[0] ^= We[s], n[1] ^= Fe[s];
|
|
235
235
|
}
|
|
236
236
|
F(e);
|
|
237
237
|
}
|
|
238
|
-
class
|
|
238
|
+
class st {
|
|
239
239
|
// NOTE: we accept arguments in bytes instead of bits here.
|
|
240
240
|
constructor(t, e, s, o = !1, r = 24) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
if (this.blockLen = t, this.suffix = e, this.outputLen = s, this.enableXOF = o, this.rounds = r,
|
|
241
|
+
k(this, "state");
|
|
242
|
+
k(this, "pos", 0);
|
|
243
|
+
k(this, "posOut", 0);
|
|
244
|
+
k(this, "finished", !1);
|
|
245
|
+
k(this, "state32");
|
|
246
|
+
k(this, "destroyed", !1);
|
|
247
|
+
k(this, "blockLen");
|
|
248
|
+
k(this, "suffix");
|
|
249
|
+
k(this, "outputLen");
|
|
250
|
+
k(this, "enableXOF", !1);
|
|
251
|
+
k(this, "rounds");
|
|
252
|
+
if (this.blockLen = t, this.suffix = e, this.outputLen = s, this.enableXOF = o, this.rounds = r, rt(s, "outputLen"), !(0 < t && t < 200))
|
|
253
253
|
throw new Error("only keccak-f1600 function is supported");
|
|
254
|
-
this.state = new Uint8Array(200), this.state32 =
|
|
254
|
+
this.state = new Uint8Array(200), this.state32 = Dt(this.state);
|
|
255
255
|
}
|
|
256
256
|
clone() {
|
|
257
257
|
return this._cloneInto();
|
|
258
258
|
}
|
|
259
259
|
keccak() {
|
|
260
|
-
|
|
260
|
+
it(this.state32), Me(this.state32, this.rounds), it(this.state32), this.posOut = 0, this.pos = 0;
|
|
261
261
|
}
|
|
262
262
|
update(t) {
|
|
263
|
-
|
|
263
|
+
at(this), ct(t);
|
|
264
264
|
const { blockLen: e, state: s } = this, o = t.length;
|
|
265
265
|
for (let r = 0; r < o; ) {
|
|
266
266
|
const i = Math.min(e - this.pos, o - r);
|
|
@@ -278,7 +278,7 @@ class et {
|
|
|
278
278
|
t[s] ^= e, (e & 128) !== 0 && s === o - 1 && this.keccak(), t[o - 1] ^= 128, this.keccak();
|
|
279
279
|
}
|
|
280
280
|
writeInto(t) {
|
|
281
|
-
|
|
281
|
+
at(this, !1), ct(t), this.finish();
|
|
282
282
|
const e = this.state, { blockLen: s } = this;
|
|
283
283
|
for (let o = 0, r = t.length; o < r; ) {
|
|
284
284
|
this.posOut >= s && this.keccak();
|
|
@@ -293,10 +293,10 @@ class et {
|
|
|
293
293
|
return this.writeInto(t);
|
|
294
294
|
}
|
|
295
295
|
xof(t) {
|
|
296
|
-
return
|
|
296
|
+
return rt(t), this.xofInto(new Uint8Array(t));
|
|
297
297
|
}
|
|
298
298
|
digestInto(t) {
|
|
299
|
-
if (
|
|
299
|
+
if (zt(t, this), this.finished)
|
|
300
300
|
throw new Error("digest() was already called");
|
|
301
301
|
return this.writeInto(t), this.destroy(), t;
|
|
302
302
|
}
|
|
@@ -308,26 +308,26 @@ class et {
|
|
|
308
308
|
}
|
|
309
309
|
_cloneInto(t) {
|
|
310
310
|
const { blockLen: e, suffix: s, outputLen: o, rounds: r, enableXOF: i } = this;
|
|
311
|
-
return t || (t = new
|
|
311
|
+
return t || (t = new st(e, s, o, i, r)), t.state32.set(this.state32), t.pos = this.pos, t.posOut = this.posOut, t.finished = this.finished, t.rounds = r, t.suffix = s, t.outputLen = o, t.enableXOF = i, t.destroyed = this.destroyed, t;
|
|
312
312
|
}
|
|
313
313
|
}
|
|
314
|
-
const
|
|
315
|
-
function
|
|
316
|
-
return
|
|
314
|
+
const Xe = (n, t, e, s = {}) => Bt(() => new st(t, n, e), s), Ke = /* @__PURE__ */ Xe(1, 136, 32), _t = 64, _ = 20, et = 4, Wt = 2, De = 0, ze = 1, L = [64, 64], Ge = (n) => Array.from(n).map((t) => t.toString(16).padStart(2, "0")).join("");
|
|
315
|
+
function ot(n) {
|
|
316
|
+
return He(nt(n));
|
|
317
317
|
}
|
|
318
|
-
function
|
|
318
|
+
function Ft(n) {
|
|
319
319
|
return (1 << n) - 1;
|
|
320
320
|
}
|
|
321
|
-
function
|
|
321
|
+
function je(n) {
|
|
322
322
|
let t = 1;
|
|
323
323
|
for (; t * t < n + 1; ) t++;
|
|
324
324
|
return Math.max(t, 2);
|
|
325
325
|
}
|
|
326
|
-
function
|
|
327
|
-
const t =
|
|
328
|
-
return { d: t, n, checksum_radix:
|
|
326
|
+
function qe(n) {
|
|
327
|
+
const t = et, e = n * Ft(t);
|
|
328
|
+
return { d: t, n, checksum_radix: je(e) };
|
|
329
329
|
}
|
|
330
|
-
function
|
|
330
|
+
function j(n, t) {
|
|
331
331
|
const e = [];
|
|
332
332
|
let s = t;
|
|
333
333
|
for (; s > 0; )
|
|
@@ -336,30 +336,30 @@ function z(n, t) {
|
|
|
336
336
|
o.set(n);
|
|
337
337
|
for (let r = 0; r < e.length; r++)
|
|
338
338
|
o[n.length + r] = e[r];
|
|
339
|
-
return
|
|
339
|
+
return ot(o);
|
|
340
340
|
}
|
|
341
|
-
function
|
|
341
|
+
function q(n, t) {
|
|
342
342
|
let e = n;
|
|
343
343
|
for (let s = 0; s < t; s++)
|
|
344
|
-
e =
|
|
344
|
+
e = ot(e);
|
|
345
345
|
return e;
|
|
346
346
|
}
|
|
347
|
-
function
|
|
348
|
-
const e =
|
|
347
|
+
function Ze(n, t) {
|
|
348
|
+
const e = Ft(t.d), s = t.checksum_radix - 1, o = Math.floor(t.n * e / t.checksum_radix), r = [];
|
|
349
349
|
for (let l = 0; l < t.n; l++) {
|
|
350
|
-
const m =
|
|
350
|
+
const m = j(n, l + Wt), w = q(m, e);
|
|
351
351
|
r.push(Array.from(w));
|
|
352
352
|
}
|
|
353
|
-
const i =
|
|
353
|
+
const i = j(
|
|
354
354
|
n,
|
|
355
|
-
|
|
356
|
-
), a =
|
|
355
|
+
De
|
|
356
|
+
), a = q(
|
|
357
357
|
i,
|
|
358
358
|
s
|
|
359
|
-
), c =
|
|
359
|
+
), c = j(
|
|
360
360
|
n,
|
|
361
|
-
|
|
362
|
-
), u =
|
|
361
|
+
ze
|
|
362
|
+
), u = q(
|
|
363
363
|
c,
|
|
364
364
|
o
|
|
365
365
|
);
|
|
@@ -370,22 +370,22 @@ function je(n, t) {
|
|
|
370
370
|
checksum_minor_terminal: Array.from(a)
|
|
371
371
|
};
|
|
372
372
|
}
|
|
373
|
-
async function
|
|
373
|
+
async function Qe(n) {
|
|
374
374
|
try {
|
|
375
|
-
if (n.length !==
|
|
375
|
+
if (n.length !== _t)
|
|
376
376
|
throw new Error(
|
|
377
|
-
`WOTS seed must be exactly ${
|
|
377
|
+
`WOTS seed must be exactly ${_t} bytes, got ${n.length}`
|
|
378
378
|
);
|
|
379
379
|
const t = [];
|
|
380
|
-
for (let e = 0; e <
|
|
381
|
-
const s =
|
|
380
|
+
for (let e = 0; e < L.length; e++) {
|
|
381
|
+
const s = L[e], o = qe(s), r = new Uint8Array(n.length + 1);
|
|
382
382
|
r.set(n), r[n.length] = e;
|
|
383
|
-
const i =
|
|
383
|
+
const i = ot(r);
|
|
384
384
|
try {
|
|
385
|
-
const a =
|
|
386
|
-
if (a.config.d !==
|
|
385
|
+
const a = Ze(i, o);
|
|
386
|
+
if (a.config.d !== et)
|
|
387
387
|
throw new Error(
|
|
388
|
-
`Block ${e}: expected d=${
|
|
388
|
+
`Block ${e}: expected d=${et}, got d=${a.config.d}`
|
|
389
389
|
);
|
|
390
390
|
if (a.config.n !== s)
|
|
391
391
|
throw new Error(
|
|
@@ -413,16 +413,16 @@ async function qe(n) {
|
|
|
413
413
|
r.fill(0), i.fill(0);
|
|
414
414
|
}
|
|
415
415
|
}
|
|
416
|
-
if (t.length !==
|
|
416
|
+
if (t.length !== L.length)
|
|
417
417
|
throw new Error(
|
|
418
|
-
`Expected ${
|
|
418
|
+
`Expected ${L.length} blocks, got ${t.length}`
|
|
419
419
|
);
|
|
420
420
|
return t;
|
|
421
421
|
} finally {
|
|
422
422
|
n.fill(0);
|
|
423
423
|
}
|
|
424
424
|
}
|
|
425
|
-
function
|
|
425
|
+
function Z(n, t, e) {
|
|
426
426
|
if (n.length !== _)
|
|
427
427
|
throw new Error(
|
|
428
428
|
`Block ${t} ${e}: expected ${_} bytes, got ${n.length}`
|
|
@@ -435,18 +435,18 @@ function j(n, t, e) {
|
|
|
435
435
|
);
|
|
436
436
|
}
|
|
437
437
|
}
|
|
438
|
-
function
|
|
438
|
+
function Ye(n) {
|
|
439
439
|
if (n.length === 0)
|
|
440
440
|
throw new Error("Public keys array must not be empty");
|
|
441
441
|
for (let r = 0; r < n.length; r++) {
|
|
442
442
|
const i = n[r];
|
|
443
|
-
|
|
443
|
+
Z(i.checksum_minor_terminal, r, "checksum_minor_terminal"), Z(i.checksum_major_terminal, r, "checksum_major_terminal");
|
|
444
444
|
for (let a = 0; a < i.message_terminals.length; a++)
|
|
445
|
-
|
|
445
|
+
Z(i.message_terminals[a], r, `message_terminal[${a}]`);
|
|
446
446
|
}
|
|
447
447
|
let t = 0;
|
|
448
448
|
for (const r of n)
|
|
449
|
-
t +=
|
|
449
|
+
t += Wt + r.message_terminals.length;
|
|
450
450
|
const e = new Uint8Array(t * _);
|
|
451
451
|
let s = 0;
|
|
452
452
|
for (const r of n) {
|
|
@@ -454,24 +454,24 @@ function Ze(n) {
|
|
|
454
454
|
for (const i of r.message_terminals)
|
|
455
455
|
e.set(i, s), s += _;
|
|
456
456
|
}
|
|
457
|
-
const o =
|
|
458
|
-
return `0x${
|
|
457
|
+
const o = Ke(e);
|
|
458
|
+
return `0x${Ge(o)}`;
|
|
459
459
|
}
|
|
460
|
-
async function
|
|
460
|
+
async function Je(n, t) {
|
|
461
461
|
const e = [], s = [], o = [], r = [];
|
|
462
462
|
try {
|
|
463
463
|
for (let i = 0; i < t; i++) {
|
|
464
|
-
const a = await
|
|
464
|
+
const a = await qt(n, i);
|
|
465
465
|
try {
|
|
466
|
-
const u = await
|
|
467
|
-
e.push(u), s.push(
|
|
466
|
+
const u = await Qe(a);
|
|
467
|
+
e.push(u), s.push(Ye(u));
|
|
468
468
|
} finally {
|
|
469
469
|
a.fill(0);
|
|
470
470
|
}
|
|
471
|
-
const c = await
|
|
471
|
+
const c = await Zt(n, i);
|
|
472
472
|
try {
|
|
473
473
|
const u = M(c);
|
|
474
|
-
o.push(u), r.push(
|
|
474
|
+
o.push(u), r.push(oe(B(u)).slice(2));
|
|
475
475
|
} finally {
|
|
476
476
|
c.fill(0);
|
|
477
477
|
}
|
|
@@ -481,33 +481,33 @@ async function Qe(n, t) {
|
|
|
481
481
|
}
|
|
482
482
|
return { perVaultWotsKeys: e, wotsPkHashes: s, htlcSecretHexes: o, hashlocks: r };
|
|
483
483
|
}
|
|
484
|
-
const
|
|
485
|
-
function
|
|
484
|
+
const tn = /^0x[0-9a-f]+$/i, en = /^[0-9a-f]+$/i, nn = /^[A-Za-z0-9+/]+={0,2}$/;
|
|
485
|
+
function H(n) {
|
|
486
486
|
if (typeof n != "string" || n.length === 0)
|
|
487
487
|
throw new Error("BTC wallet returned empty public key");
|
|
488
|
-
return
|
|
488
|
+
return ne(n).toLowerCase();
|
|
489
489
|
}
|
|
490
|
-
function
|
|
490
|
+
function sn(n) {
|
|
491
491
|
if (typeof n != "string" || n.length === 0)
|
|
492
492
|
throw new Error("BTC wallet returned empty BIP-322 signature");
|
|
493
493
|
if (n.startsWith("0x") || n.startsWith("0X")) {
|
|
494
|
-
if (!
|
|
494
|
+
if (!tn.test(n) || n.length < 4 || n.length % 2 !== 0)
|
|
495
495
|
throw new Error("BTC wallet returned malformed hex BIP-322 signature");
|
|
496
496
|
return n.toLowerCase();
|
|
497
497
|
}
|
|
498
|
-
if (
|
|
498
|
+
if (en.test(n)) {
|
|
499
499
|
if (n.length % 2 !== 0)
|
|
500
500
|
throw new Error("BTC wallet returned malformed hex BIP-322 signature");
|
|
501
501
|
return `0x${n.toLowerCase()}`;
|
|
502
502
|
}
|
|
503
|
-
if (!
|
|
503
|
+
if (!nn.test(n) || n.length % 4 !== 0)
|
|
504
504
|
throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
|
|
505
|
-
const t =
|
|
505
|
+
const t = Q.from(n, "base64");
|
|
506
506
|
if (t.length === 0 || t.toString("base64") !== n)
|
|
507
507
|
throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
|
|
508
508
|
return `0x${t.toString("hex")}`;
|
|
509
509
|
}
|
|
510
|
-
async function
|
|
510
|
+
async function on(n, t, e) {
|
|
511
511
|
if (typeof n.signPsbts == "function") {
|
|
512
512
|
const o = await n.signPsbts(t, e);
|
|
513
513
|
if (o.length !== t.length)
|
|
@@ -523,25 +523,25 @@ async function nn(n, t, e) {
|
|
|
523
523
|
}
|
|
524
524
|
return s;
|
|
525
525
|
}
|
|
526
|
-
const
|
|
527
|
-
function
|
|
526
|
+
const rn = 0, W = "00".repeat(32);
|
|
527
|
+
function an(n, t, e, s) {
|
|
528
528
|
const o = e == null ? void 0 : e[`${n}:${t}`];
|
|
529
529
|
return o ? Promise.resolve({
|
|
530
530
|
txid: n,
|
|
531
531
|
vout: t,
|
|
532
532
|
value: o.value,
|
|
533
533
|
scriptPubKey: o.scriptPubKey
|
|
534
|
-
}) :
|
|
534
|
+
}) : ue(n, t, s);
|
|
535
535
|
}
|
|
536
|
-
const
|
|
537
|
-
class
|
|
536
|
+
const vt = 12e4;
|
|
537
|
+
class Tn {
|
|
538
538
|
/**
|
|
539
539
|
* Creates a new PeginManager instance.
|
|
540
540
|
*
|
|
541
541
|
* @param config - Manager configuration including wallets and contract addresses
|
|
542
542
|
*/
|
|
543
543
|
constructor(t) {
|
|
544
|
-
|
|
544
|
+
k(this, "config");
|
|
545
545
|
this.config = t;
|
|
546
546
|
}
|
|
547
547
|
/**
|
|
@@ -556,27 +556,36 @@ class kn {
|
|
|
556
556
|
async preparePegin(t) {
|
|
557
557
|
if (t.amounts.length === 0)
|
|
558
558
|
throw new Error("amounts must contain at least one entry");
|
|
559
|
-
const e = await this.config.btcWallet.getPublicKeyHex(), s =
|
|
559
|
+
const e = await this.config.btcWallet.getPublicKeyHex(), s = H(e);
|
|
560
|
+
if (!ft(
|
|
561
|
+
t.changeAddress,
|
|
562
|
+
e,
|
|
563
|
+
this.config.btcNetwork
|
|
564
|
+
))
|
|
565
|
+
throw new Error(
|
|
566
|
+
`Pre-PegIn changeAddress "${t.changeAddress}" is not derived from the connected wallet's public key. Refusing to build a tx that would send change to an address the signing key doesn't control.`
|
|
567
|
+
);
|
|
568
|
+
const o = await this.prepareSizing(s, t), r = o.selectedUTXOs.map(
|
|
560
569
|
(g) => ({
|
|
561
|
-
txid:
|
|
570
|
+
txid: Y(g.txid),
|
|
562
571
|
vout: g.vout
|
|
563
572
|
})
|
|
564
|
-
), i = await
|
|
565
|
-
depositorBtcPubkey:
|
|
573
|
+
), i = await ve(this.config.btcWallet, {
|
|
574
|
+
depositorBtcPubkey: Y(s),
|
|
566
575
|
fundingOutpoints: r
|
|
567
576
|
});
|
|
568
577
|
let a, c;
|
|
569
578
|
try {
|
|
570
|
-
const g = await
|
|
579
|
+
const g = await Qt(i);
|
|
571
580
|
try {
|
|
572
|
-
a = M(g), c = M(
|
|
581
|
+
a = M(g), c = M(nt(g));
|
|
573
582
|
} finally {
|
|
574
583
|
g.fill(0);
|
|
575
584
|
}
|
|
576
585
|
} catch (g) {
|
|
577
586
|
throw i.fill(0), g;
|
|
578
587
|
}
|
|
579
|
-
const u = await
|
|
588
|
+
const u = await Je(i, t.amounts.length), { perVaultWotsKeys: l, wotsPkHashes: m, htlcSecretHexes: w, hashlocks: P } = u, d = await this.preparePeginCommit({
|
|
580
589
|
depositorBtcPubkeyRaw: e,
|
|
581
590
|
depositorBtcPubkey: s,
|
|
582
591
|
hashlocks: P,
|
|
@@ -584,18 +593,18 @@ class kn {
|
|
|
584
593
|
sizing: o,
|
|
585
594
|
params: t
|
|
586
595
|
});
|
|
587
|
-
for (let g = 0; g <
|
|
588
|
-
if (
|
|
596
|
+
for (let g = 0; g < d.perVault.length; g++)
|
|
597
|
+
if (d.perVault[g].htlcVout !== g)
|
|
589
598
|
throw new Error(
|
|
590
|
-
`Internal invariant violation: htlcVout/index mismatch at vault ${g} (expected ${g}, got ${
|
|
599
|
+
`Internal invariant violation: htlcVout/index mismatch at vault ${g} (expected ${g}, got ${d.perVault[g].htlcVout})`
|
|
591
600
|
);
|
|
592
|
-
return
|
|
593
|
-
|
|
601
|
+
return be(
|
|
602
|
+
d.fundedPrePeginTxHex,
|
|
594
603
|
t.amounts.length,
|
|
595
604
|
c
|
|
596
605
|
), {
|
|
597
606
|
transaction: {
|
|
598
|
-
...
|
|
607
|
+
...d,
|
|
599
608
|
selectedUTXOs: o.selectedUTXOs,
|
|
600
609
|
fee: o.fee,
|
|
601
610
|
changeAmount: o.changeAmount
|
|
@@ -627,8 +636,8 @@ class kn {
|
|
|
627
636
|
*/
|
|
628
637
|
async prepareSizing(t, e) {
|
|
629
638
|
const s = e.amounts.map(
|
|
630
|
-
() =>
|
|
631
|
-
), o = e.vaultKeeperBtcPubkeys.length, r = await
|
|
639
|
+
() => W
|
|
640
|
+
), o = e.vaultKeeperBtcPubkeys.length, r = await gt({
|
|
632
641
|
depositorPubkey: t,
|
|
633
642
|
vaultProviderPubkey: T(e.vaultProviderBtcPubkey),
|
|
634
643
|
vaultKeeperPubkeys: e.vaultKeeperBtcPubkeys.map(T),
|
|
@@ -641,14 +650,14 @@ class kn {
|
|
|
641
650
|
councilQuorum: e.councilQuorum,
|
|
642
651
|
councilSize: e.councilSize,
|
|
643
652
|
network: this.config.btcNetwork,
|
|
644
|
-
authAnchorHash:
|
|
645
|
-
}), i =
|
|
653
|
+
authAnchorHash: W
|
|
654
|
+
}), i = re(
|
|
646
655
|
[...e.availableUTXOs],
|
|
647
656
|
r.totalOutputValue,
|
|
648
657
|
e.mempoolFeeRate,
|
|
649
|
-
|
|
658
|
+
ae(
|
|
650
659
|
r.htlcValues.length,
|
|
651
|
-
|
|
660
|
+
W
|
|
652
661
|
)
|
|
653
662
|
);
|
|
654
663
|
return {
|
|
@@ -666,11 +675,11 @@ class kn {
|
|
|
666
675
|
authAnchorHash: r,
|
|
667
676
|
sizing: i,
|
|
668
677
|
params: a
|
|
669
|
-
} = t, c =
|
|
670
|
-
for (let
|
|
671
|
-
if (o[
|
|
678
|
+
} = t, c = W.toLowerCase();
|
|
679
|
+
for (let h = 0; h < o.length; h++)
|
|
680
|
+
if (o[h].toLowerCase() === c)
|
|
672
681
|
throw new Error(
|
|
673
|
-
`preparePeginCommit refusing to build with sizing-pass placeholder hashlock at vault ${
|
|
682
|
+
`preparePeginCommit refusing to build with sizing-pass placeholder hashlock at vault ${h} — internal substitution bug`
|
|
674
683
|
);
|
|
675
684
|
if (r.toLowerCase() === c)
|
|
676
685
|
throw new Error(
|
|
@@ -690,56 +699,56 @@ class kn {
|
|
|
690
699
|
councilSize: a.councilSize,
|
|
691
700
|
network: this.config.btcNetwork,
|
|
692
701
|
authAnchorHash: r
|
|
693
|
-
},
|
|
694
|
-
unfundedTxHex:
|
|
702
|
+
}, d = await gt(P), g = pt(this.config.btcNetwork), E = ce({
|
|
703
|
+
unfundedTxHex: d.psbtHex,
|
|
695
704
|
selectedUTXOs: i.selectedUTXOs,
|
|
696
705
|
changeAddress: a.changeAddress,
|
|
697
706
|
changeAmount: i.changeAmount,
|
|
698
707
|
network: g
|
|
699
|
-
}),
|
|
700
|
-
for (let
|
|
701
|
-
const
|
|
708
|
+
}), I = T(z(E)), f = [], y = [], x = [];
|
|
709
|
+
for (let h = 0; h < o.length; h++) {
|
|
710
|
+
const S = await Yt({
|
|
702
711
|
prePeginParams: P,
|
|
703
712
|
timelockPegin: a.timelockPegin,
|
|
704
713
|
fundedPrePeginTxHex: E,
|
|
705
|
-
htlcVout:
|
|
706
|
-
}),
|
|
707
|
-
peginTxHex:
|
|
714
|
+
htlcVout: h
|
|
715
|
+
}), v = await Jt({
|
|
716
|
+
peginTxHex: S.txHex,
|
|
708
717
|
fundedPrePeginTxHex: E,
|
|
709
718
|
depositorPubkey: s,
|
|
710
719
|
vaultProviderPubkey: u,
|
|
711
720
|
vaultKeeperPubkeys: l,
|
|
712
721
|
universalChallengerPubkeys: m,
|
|
713
|
-
hashlock: o[
|
|
722
|
+
hashlock: o[h],
|
|
714
723
|
timelockRefund: a.timelockRefund,
|
|
715
724
|
network: this.config.btcNetwork
|
|
716
725
|
});
|
|
717
|
-
f.push(
|
|
718
|
-
|
|
726
|
+
f.push(S), y.push(v.psbtHex), x.push(
|
|
727
|
+
se(e, 1)
|
|
719
728
|
);
|
|
720
729
|
}
|
|
721
|
-
const
|
|
730
|
+
const p = await on(
|
|
722
731
|
this.config.btcWallet,
|
|
723
|
-
|
|
724
|
-
|
|
732
|
+
y,
|
|
733
|
+
x
|
|
725
734
|
), b = [];
|
|
726
|
-
for (let
|
|
727
|
-
const
|
|
728
|
-
|
|
735
|
+
for (let h = 0; h < p.length; h++) {
|
|
736
|
+
const S = te(
|
|
737
|
+
p[h],
|
|
729
738
|
s
|
|
730
|
-
),
|
|
739
|
+
), v = ee(p[h]);
|
|
731
740
|
b.push({
|
|
732
|
-
htlcVout:
|
|
733
|
-
htlcValue:
|
|
734
|
-
peginTxHex:
|
|
735
|
-
peginTxid: f[
|
|
736
|
-
peginInputSignature:
|
|
737
|
-
vaultScriptPubKey: f[
|
|
741
|
+
htlcVout: h,
|
|
742
|
+
htlcValue: d.htlcValues[h],
|
|
743
|
+
peginTxHex: v,
|
|
744
|
+
peginTxid: f[h].txid,
|
|
745
|
+
peginInputSignature: S,
|
|
746
|
+
vaultScriptPubKey: f[h].vaultScriptPubKey
|
|
738
747
|
});
|
|
739
748
|
}
|
|
740
749
|
return {
|
|
741
750
|
fundedPrePeginTxHex: E,
|
|
742
|
-
prePeginTxid:
|
|
751
|
+
prePeginTxid: I,
|
|
743
752
|
perVault: b
|
|
744
753
|
};
|
|
745
754
|
}
|
|
@@ -759,24 +768,24 @@ class kn {
|
|
|
759
768
|
* @throws Error if signing or broadcasting fails
|
|
760
769
|
*/
|
|
761
770
|
async signAndBroadcast(t) {
|
|
762
|
-
const { fundedPrePeginTxHex: e, depositorBtcPubkey: s } = t, o = e.startsWith("0x") ? e.slice(2) : e, r =
|
|
771
|
+
const { fundedPrePeginTxHex: e, depositorBtcPubkey: s } = t, o = e.startsWith("0x") ? e.slice(2) : e, r = Gt.fromHex(o);
|
|
763
772
|
if (r.ins.length === 0)
|
|
764
773
|
throw new Error("Transaction has no inputs");
|
|
765
|
-
const i = new
|
|
774
|
+
const i = new lt();
|
|
766
775
|
i.setVersion(r.version), i.setLocktime(r.locktime);
|
|
767
|
-
const a =
|
|
768
|
-
|
|
776
|
+
const a = Q.from(
|
|
777
|
+
H(s),
|
|
769
778
|
"hex"
|
|
770
779
|
), c = this.config.mempoolApiUrl, u = r.ins.map((f) => {
|
|
771
|
-
const
|
|
772
|
-
return
|
|
773
|
-
(
|
|
780
|
+
const y = Q.from(f.hash).reverse().toString("hex"), x = f.index;
|
|
781
|
+
return an(y, x, t.localPrevouts, c).then(
|
|
782
|
+
(p) => ({ input: f, utxoData: p, txid: y, vout: x })
|
|
774
783
|
);
|
|
775
784
|
}), l = await Promise.all(u), m = l.reduce(
|
|
776
|
-
(f,
|
|
785
|
+
(f, y) => f + BigInt(y.utxoData.value),
|
|
777
786
|
0n
|
|
778
787
|
), w = r.outs.reduce(
|
|
779
|
-
(f,
|
|
788
|
+
(f, y) => f + BigInt(y.value),
|
|
780
789
|
0n
|
|
781
790
|
);
|
|
782
791
|
if (m < w)
|
|
@@ -784,15 +793,15 @@ class kn {
|
|
|
784
793
|
`UTXO value mismatch: total input value (${m} sat) is less than total output value (${w} sat). This may indicate the mempool API returned manipulated UTXO data.`
|
|
785
794
|
);
|
|
786
795
|
const P = m - w;
|
|
787
|
-
if (P >
|
|
796
|
+
if (P > mt)
|
|
788
797
|
throw new Error(
|
|
789
|
-
`Implied transaction fee (${P} sat) exceeds maximum reasonable fee (${
|
|
798
|
+
`Implied transaction fee (${P} sat) exceeds maximum reasonable fee (${mt} sat). This may indicate manipulated UTXO data.`
|
|
790
799
|
);
|
|
791
|
-
for (const { input: f, utxoData:
|
|
792
|
-
const b =
|
|
800
|
+
for (const { input: f, utxoData: y, txid: x, vout: p } of l) {
|
|
801
|
+
const b = ie(
|
|
793
802
|
{
|
|
794
|
-
value:
|
|
795
|
-
scriptPubKey:
|
|
803
|
+
value: y.value,
|
|
804
|
+
scriptPubKey: y.scriptPubKey
|
|
796
805
|
},
|
|
797
806
|
a
|
|
798
807
|
);
|
|
@@ -808,19 +817,19 @@ class kn {
|
|
|
808
817
|
script: f.script,
|
|
809
818
|
value: f.value
|
|
810
819
|
});
|
|
811
|
-
const
|
|
820
|
+
const d = await this.config.btcWallet.signPsbt(i.toHex()), g = lt.fromHex(d);
|
|
812
821
|
try {
|
|
813
822
|
g.finalizeAllInputs();
|
|
814
823
|
} catch (f) {
|
|
815
824
|
if (!g.data.inputs.every(
|
|
816
|
-
(
|
|
825
|
+
(x) => x.finalScriptWitness || x.finalScriptSig
|
|
817
826
|
))
|
|
818
827
|
throw new Error(
|
|
819
828
|
`PSBT finalization failed and wallet did not auto-finalize: ${f}`
|
|
820
829
|
);
|
|
821
830
|
}
|
|
822
831
|
const E = g.extractTransaction().toHex();
|
|
823
|
-
return await
|
|
832
|
+
return await le(E, c);
|
|
824
833
|
}
|
|
825
834
|
/**
|
|
826
835
|
* Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
|
|
@@ -860,90 +869,90 @@ class kn {
|
|
|
860
869
|
if (!this.config.ethWallet.account)
|
|
861
870
|
throw new Error("Ethereum wallet account not found");
|
|
862
871
|
const l = this.config.ethWallet.account.address;
|
|
863
|
-
if (!
|
|
872
|
+
if (!ut(u.depositorEthAddress, l))
|
|
864
873
|
throw new Error(
|
|
865
874
|
`Proof of possession was signed for ${u.depositorEthAddress} but the Ethereum wallet is currently connected to ${l}. Reconnect the original account or call signProofOfPossession() again.`
|
|
866
875
|
);
|
|
867
|
-
await this.assertPopMatchesBtcWallet(u)
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
),
|
|
871
|
-
T(
|
|
876
|
+
const m = await this.assertPopMatchesBtcWallet(u), w = u.btcPopSignature, P = B(u.depositorBtcPubkey), d = B(e), g = B(s), E = a ?? await this.config.btcWallet.getAddress(), I = this.resolvePayoutScriptPubKey(
|
|
877
|
+
m,
|
|
878
|
+
E
|
|
879
|
+
), f = z(g), y = await dt(
|
|
880
|
+
T(f),
|
|
872
881
|
T(l)
|
|
873
|
-
),
|
|
874
|
-
if (await this.checkVaultExists(
|
|
882
|
+
), x = B(y);
|
|
883
|
+
if (await this.checkVaultExists(x))
|
|
875
884
|
throw new Error(
|
|
876
|
-
`Vault already exists (ID: ${
|
|
885
|
+
`Vault already exists (ID: ${x}, peginTxHash: ${f}). Vault IDs are derived from the pegin transaction hash and depositor address. To create a new vault, use different UTXOs or a different amount to generate a unique transaction.`
|
|
877
886
|
);
|
|
878
|
-
const
|
|
879
|
-
let
|
|
887
|
+
const b = this.config.publicClient;
|
|
888
|
+
let h;
|
|
880
889
|
try {
|
|
881
|
-
|
|
890
|
+
h = await b.readContract({
|
|
882
891
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
883
|
-
abi:
|
|
892
|
+
abi: O,
|
|
884
893
|
functionName: "getPegInFee",
|
|
885
894
|
args: [o]
|
|
886
895
|
});
|
|
887
|
-
} catch (
|
|
896
|
+
} catch (R) {
|
|
888
897
|
throw new Error(
|
|
889
898
|
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct.",
|
|
890
|
-
{ cause:
|
|
899
|
+
{ cause: R }
|
|
891
900
|
);
|
|
892
901
|
}
|
|
893
|
-
const
|
|
894
|
-
abi:
|
|
902
|
+
const S = ht({
|
|
903
|
+
abi: O,
|
|
895
904
|
functionName: "submitPeginRequest",
|
|
896
905
|
args: [
|
|
897
906
|
l,
|
|
898
|
-
w,
|
|
899
|
-
m,
|
|
900
907
|
P,
|
|
901
|
-
|
|
908
|
+
w,
|
|
909
|
+
d,
|
|
910
|
+
g,
|
|
902
911
|
o,
|
|
903
912
|
r,
|
|
904
913
|
i,
|
|
905
|
-
|
|
914
|
+
I,
|
|
906
915
|
c
|
|
907
916
|
]
|
|
908
917
|
});
|
|
909
|
-
let
|
|
918
|
+
let v;
|
|
910
919
|
try {
|
|
911
|
-
|
|
920
|
+
v = await b.estimateGas({
|
|
912
921
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
913
|
-
data:
|
|
914
|
-
value:
|
|
922
|
+
data: S,
|
|
923
|
+
value: h,
|
|
915
924
|
account: this.config.ethWallet.account.address
|
|
916
925
|
});
|
|
917
|
-
} catch (
|
|
918
|
-
A(
|
|
926
|
+
} catch (R) {
|
|
927
|
+
A(R);
|
|
919
928
|
}
|
|
920
|
-
let
|
|
929
|
+
let K;
|
|
921
930
|
try {
|
|
922
|
-
|
|
931
|
+
K = await this.config.ethWallet.sendTransaction({
|
|
923
932
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
924
|
-
data:
|
|
925
|
-
value:
|
|
933
|
+
data: S,
|
|
934
|
+
value: h,
|
|
926
935
|
account: this.config.ethWallet.account,
|
|
927
936
|
chain: this.config.ethChain,
|
|
928
|
-
gas:
|
|
937
|
+
gas: v
|
|
929
938
|
});
|
|
930
|
-
} catch (
|
|
931
|
-
A(
|
|
939
|
+
} catch (R) {
|
|
940
|
+
A(R);
|
|
932
941
|
}
|
|
933
|
-
const
|
|
934
|
-
publicClient:
|
|
942
|
+
const D = await wt({
|
|
943
|
+
publicClient: b,
|
|
935
944
|
walletAddress: this.config.ethWallet.account.address,
|
|
936
|
-
hash:
|
|
937
|
-
timeout:
|
|
945
|
+
hash: K,
|
|
946
|
+
timeout: vt
|
|
938
947
|
});
|
|
939
|
-
return
|
|
948
|
+
return D.status === "reverted" && A(
|
|
940
949
|
new Error(
|
|
941
|
-
`Transaction reverted. Hash: ${
|
|
950
|
+
`Transaction reverted. Hash: ${D.transactionHash}. Check the transaction on block explorer for details.`
|
|
942
951
|
)
|
|
943
952
|
), {
|
|
944
|
-
ethTxHash:
|
|
945
|
-
vaultId:
|
|
946
|
-
peginTxHash:
|
|
953
|
+
ethTxHash: D.transactionHash,
|
|
954
|
+
vaultId: x,
|
|
955
|
+
peginTxHash: f
|
|
947
956
|
};
|
|
948
957
|
}
|
|
949
958
|
/**
|
|
@@ -963,93 +972,92 @@ class kn {
|
|
|
963
972
|
if (!this.config.ethWallet.account)
|
|
964
973
|
throw new Error("Ethereum wallet account not found");
|
|
965
974
|
const i = this.config.ethWallet.account.address;
|
|
966
|
-
if (!
|
|
975
|
+
if (!ut(r.depositorEthAddress, i))
|
|
967
976
|
throw new Error(
|
|
968
977
|
`Proof of possession was signed for ${r.depositorEthAddress} but the Ethereum wallet is currently connected to ${i}. Reconnect the original account or call signProofOfPossession() again.`
|
|
969
978
|
);
|
|
970
|
-
await this.assertPopMatchesBtcWallet(r)
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
const
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
T(b),
|
|
979
|
+
const a = await this.assertPopMatchesBtcWallet(r), c = r.btcPopSignature, u = o.map(
|
|
980
|
+
(p) => this.resolvePayoutScriptPubKey(
|
|
981
|
+
a,
|
|
982
|
+
p.depositorPayoutBtcAddress
|
|
983
|
+
)
|
|
984
|
+
), l = [];
|
|
985
|
+
for (const p of o) {
|
|
986
|
+
const b = B(
|
|
987
|
+
p.depositorSignedPeginTx
|
|
988
|
+
), h = z(b), S = await dt(
|
|
989
|
+
T(h),
|
|
982
990
|
T(i)
|
|
983
|
-
), v =
|
|
991
|
+
), v = B(S);
|
|
984
992
|
if (await this.checkVaultExists(v))
|
|
985
993
|
throw new Error(
|
|
986
|
-
`Vault already exists (ID: ${v}, peginTxHash: ${
|
|
994
|
+
`Vault already exists (ID: ${v}, peginTxHash: ${h}). To create a new vault, use different UTXOs or a different amount.`
|
|
987
995
|
);
|
|
988
|
-
|
|
996
|
+
l.push({ vaultId: v, peginTxHash: h });
|
|
989
997
|
}
|
|
990
|
-
const
|
|
991
|
-
let
|
|
998
|
+
const m = this.config.publicClient;
|
|
999
|
+
let w;
|
|
992
1000
|
try {
|
|
993
|
-
|
|
1001
|
+
w = await m.readContract({
|
|
994
1002
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
995
|
-
abi:
|
|
1003
|
+
abi: O,
|
|
996
1004
|
functionName: "getPegInFee",
|
|
997
1005
|
args: [e]
|
|
998
1006
|
});
|
|
999
|
-
} catch (
|
|
1007
|
+
} catch (p) {
|
|
1000
1008
|
throw new Error(
|
|
1001
1009
|
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct.",
|
|
1002
|
-
{ cause:
|
|
1010
|
+
{ cause: p }
|
|
1003
1011
|
);
|
|
1004
1012
|
}
|
|
1005
|
-
const
|
|
1013
|
+
const P = w * BigInt(o.length), d = B(
|
|
1006
1014
|
r.depositorBtcPubkey
|
|
1007
|
-
),
|
|
1008
|
-
depositorBtcPubKey:
|
|
1009
|
-
btcPopSignature:
|
|
1010
|
-
unsignedPrePeginTx:
|
|
1011
|
-
depositorSignedPeginTx:
|
|
1012
|
-
|
|
1015
|
+
), g = B(s), E = o.map((p, b) => ({
|
|
1016
|
+
depositorBtcPubKey: d,
|
|
1017
|
+
btcPopSignature: c,
|
|
1018
|
+
unsignedPrePeginTx: g,
|
|
1019
|
+
depositorSignedPeginTx: B(
|
|
1020
|
+
p.depositorSignedPeginTx
|
|
1013
1021
|
),
|
|
1014
|
-
hashlock:
|
|
1015
|
-
htlcVout:
|
|
1016
|
-
referralCode:
|
|
1017
|
-
depositorPayoutBtcAddress:
|
|
1018
|
-
depositorWotsPkHash:
|
|
1019
|
-
})),
|
|
1020
|
-
abi:
|
|
1022
|
+
hashlock: p.hashlock,
|
|
1023
|
+
htlcVout: p.htlcVout,
|
|
1024
|
+
referralCode: rn,
|
|
1025
|
+
depositorPayoutBtcAddress: u[b],
|
|
1026
|
+
depositorWotsPkHash: p.depositorWotsPkHash
|
|
1027
|
+
})), I = ht({
|
|
1028
|
+
abi: O,
|
|
1021
1029
|
functionName: "submitPeginRequestBatch",
|
|
1022
|
-
args: [i, e,
|
|
1030
|
+
args: [i, e, E]
|
|
1023
1031
|
});
|
|
1024
|
-
let
|
|
1032
|
+
let f;
|
|
1025
1033
|
try {
|
|
1026
|
-
|
|
1034
|
+
f = await m.estimateGas({
|
|
1027
1035
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1028
|
-
data:
|
|
1029
|
-
value:
|
|
1036
|
+
data: I,
|
|
1037
|
+
value: P,
|
|
1030
1038
|
account: this.config.ethWallet.account.address
|
|
1031
1039
|
});
|
|
1032
|
-
} catch (
|
|
1033
|
-
A(
|
|
1040
|
+
} catch (p) {
|
|
1041
|
+
A(p);
|
|
1034
1042
|
}
|
|
1035
|
-
let
|
|
1043
|
+
let y;
|
|
1036
1044
|
try {
|
|
1037
|
-
|
|
1045
|
+
y = await this.config.ethWallet.sendTransaction({
|
|
1038
1046
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1039
|
-
data:
|
|
1040
|
-
value:
|
|
1047
|
+
data: I,
|
|
1048
|
+
value: P,
|
|
1041
1049
|
account: this.config.ethWallet.account,
|
|
1042
1050
|
chain: this.config.ethChain,
|
|
1043
|
-
gas:
|
|
1051
|
+
gas: f
|
|
1044
1052
|
});
|
|
1045
|
-
} catch (
|
|
1046
|
-
A(
|
|
1053
|
+
} catch (p) {
|
|
1054
|
+
A(p);
|
|
1047
1055
|
}
|
|
1048
|
-
const x = await
|
|
1049
|
-
publicClient:
|
|
1056
|
+
const x = await wt({
|
|
1057
|
+
publicClient: m,
|
|
1050
1058
|
walletAddress: this.config.ethWallet.account.address,
|
|
1051
|
-
hash:
|
|
1052
|
-
timeout:
|
|
1059
|
+
hash: y,
|
|
1060
|
+
timeout: vt
|
|
1053
1061
|
});
|
|
1054
1062
|
return x.status === "reverted" && A(
|
|
1055
1063
|
new Error(
|
|
@@ -1057,7 +1065,7 @@ class kn {
|
|
|
1057
1065
|
)
|
|
1058
1066
|
), {
|
|
1059
1067
|
ethTxHash: x.transactionHash,
|
|
1060
|
-
vaults:
|
|
1068
|
+
vaults: l
|
|
1061
1069
|
};
|
|
1062
1070
|
}
|
|
1063
1071
|
/**
|
|
@@ -1076,37 +1084,40 @@ class kn {
|
|
|
1076
1084
|
async checkVaultExists(t) {
|
|
1077
1085
|
return (await this.config.publicClient.readContract({
|
|
1078
1086
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
1079
|
-
abi:
|
|
1087
|
+
abi: O,
|
|
1080
1088
|
functionName: "getBtcVaultBasicInfo",
|
|
1081
1089
|
args: [t]
|
|
1082
|
-
})).depositor !==
|
|
1090
|
+
})).depositor !== jt;
|
|
1083
1091
|
}
|
|
1084
1092
|
/**
|
|
1085
|
-
* Resolve the BTC
|
|
1093
|
+
* Resolve the BTC scriptPubKey to register as the depositor's payout sink.
|
|
1094
|
+
*
|
|
1095
|
+
* `address` is validated against the verified depositor pubkey, which MUST
|
|
1096
|
+
* be the *raw* (parity-preserving) form returned by the wallet adapter —
|
|
1097
|
+
* the caller should source it from `assertPopMatchesBtcWallet`'s return
|
|
1098
|
+
* value, not from `popSignature.depositorBtcPubkey` (x-only, parity
|
|
1099
|
+
* stripped). P2WPKH addresses are derived from a parity-bearing compressed
|
|
1100
|
+
* key; passing the x-only form here would let `isAddressFromPublicKey`
|
|
1101
|
+
* try both `02|x` and `03|x` and accept an opposite-parity P2WPKH
|
|
1102
|
+
* address the wallet does not actually control.
|
|
1086
1103
|
*
|
|
1087
|
-
*
|
|
1088
|
-
*
|
|
1089
|
-
*
|
|
1104
|
+
* The helper does not call into the wallet so the batch path can resolve
|
|
1105
|
+
* many requests without any extra adapter reads. Threat closed: a
|
|
1106
|
+
* state-race or stale FE state that lets a non-wallet address reach the
|
|
1107
|
+
* on-chain payout-script registration.
|
|
1090
1108
|
*/
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
this.config.btcNetwork
|
|
1102
|
-
))
|
|
1103
|
-
throw new Error(
|
|
1104
|
-
"The BTC address from your wallet does not match the wallet's public key. Please ensure your wallet is using a supported address type (Taproot or Native SegWit)."
|
|
1105
|
-
);
|
|
1106
|
-
}
|
|
1107
|
-
const s = dt(this.config.btcNetwork);
|
|
1109
|
+
resolvePayoutScriptPubKey(t, e) {
|
|
1110
|
+
if (!ft(
|
|
1111
|
+
e,
|
|
1112
|
+
t,
|
|
1113
|
+
this.config.btcNetwork
|
|
1114
|
+
))
|
|
1115
|
+
throw new Error(
|
|
1116
|
+
`BTC payout address "${e}" is not derived from the connected wallet's public key. The payout sink must be controlled by the same key that signs the pegin; refusing to register a mismatched address.`
|
|
1117
|
+
);
|
|
1118
|
+
const s = pt(this.config.btcNetwork);
|
|
1108
1119
|
try {
|
|
1109
|
-
return `0x${
|
|
1120
|
+
return `0x${It.address.toOutputScript(e, s).toString("hex")}`;
|
|
1110
1121
|
} catch {
|
|
1111
1122
|
throw new Error(
|
|
1112
1123
|
`Invalid BTC payout address: "${e}". Please provide a valid Bitcoin address for the ${this.config.btcNetwork} network.`
|
|
@@ -1122,26 +1133,33 @@ class kn {
|
|
|
1122
1133
|
async signProofOfPossession() {
|
|
1123
1134
|
if (!this.config.ethWallet.account)
|
|
1124
1135
|
throw new Error("Ethereum wallet account not found");
|
|
1125
|
-
const t = this.config.ethWallet.account.address, e =
|
|
1136
|
+
const t = this.config.ethWallet.account.address, e = H(
|
|
1126
1137
|
await this.config.btcWallet.getPublicKeyHex()
|
|
1127
1138
|
), s = this.config.vaultContracts.btcVaultRegistry, o = `${t.toLowerCase()}:${this.config.ethChain.id}:pegin:${s.toLowerCase()}`, r = await this.config.btcWallet.signMessage(
|
|
1128
1139
|
o,
|
|
1129
1140
|
"bip322-simple"
|
|
1130
1141
|
);
|
|
1131
1142
|
return {
|
|
1132
|
-
btcPopSignature:
|
|
1143
|
+
btcPopSignature: sn(r),
|
|
1133
1144
|
depositorEthAddress: t,
|
|
1134
1145
|
depositorBtcPubkey: e
|
|
1135
1146
|
};
|
|
1136
1147
|
}
|
|
1148
|
+
/**
|
|
1149
|
+
* Confirm the connected BTC wallet still matches the PoP it produced, and
|
|
1150
|
+
* return the wallet's *raw* pubkey hex (parity-preserving form, as the
|
|
1151
|
+
* wallet adapter returns it). The raw form is required by callers that
|
|
1152
|
+
* validate Native SegWit / P2WPKH addresses, since P2WPKH is derived from
|
|
1153
|
+
* a parity-bearing compressed key — an x-only form would let an attacker
|
|
1154
|
+
* substitute the opposite-parity P2WPKH address.
|
|
1155
|
+
*/
|
|
1137
1156
|
async assertPopMatchesBtcWallet(t) {
|
|
1138
|
-
const e =
|
|
1139
|
-
|
|
1140
|
-
), s = $(t.depositorBtcPubkey);
|
|
1141
|
-
if (e !== s)
|
|
1157
|
+
const e = await this.config.btcWallet.getPublicKeyHex(), s = H(e), o = H(t.depositorBtcPubkey);
|
|
1158
|
+
if (s !== o)
|
|
1142
1159
|
throw new Error(
|
|
1143
|
-
`Proof of possession was signed with BTC pubkey ${
|
|
1160
|
+
`Proof of possession was signed with BTC pubkey ${o} but the BTC wallet is currently connected to ${s}. Reconnect the original wallet or call signProofOfPossession() again.`
|
|
1144
1161
|
);
|
|
1162
|
+
return e;
|
|
1145
1163
|
}
|
|
1146
1164
|
/**
|
|
1147
1165
|
* Gets the configured Bitcoin network.
|
|
@@ -1161,12 +1179,12 @@ class kn {
|
|
|
1161
1179
|
}
|
|
1162
1180
|
}
|
|
1163
1181
|
export {
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1182
|
+
Tn as P,
|
|
1183
|
+
Te as V,
|
|
1184
|
+
Ee as a,
|
|
1185
|
+
ke as b,
|
|
1186
|
+
Ye as c,
|
|
1187
|
+
Qe as d,
|
|
1188
|
+
ve as e
|
|
1171
1189
|
};
|
|
1172
|
-
//# sourceMappingURL=PeginManager-
|
|
1190
|
+
//# sourceMappingURL=PeginManager-CB-dVkT2.js.map
|