@babylonlabs-io/ts-sdk 0.38.1 → 0.39.2
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-Cp2Tn5sH.js → PeginManager-DXrfY4d6.js} +388 -334
- package/dist/{PeginManager-Cp2Tn5sH.js.map → PeginManager-DXrfY4d6.js.map} +1 -1
- package/dist/PeginManager-zkTJOy_U.cjs +2 -0
- package/dist/{PeginManager-DaDs-bGr.cjs.map → PeginManager-zkTJOy_U.cjs.map} +1 -1
- package/dist/{buildAndBroadcastRefund-B5cOyUzj.js → buildAndBroadcastRefund-CjWAle7m.js} +278 -231
- package/dist/buildAndBroadcastRefund-CjWAle7m.js.map +1 -0
- package/dist/buildAndBroadcastRefund-CzKOUR75.cjs +2 -0
- package/dist/buildAndBroadcastRefund-CzKOUR75.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +152 -146
- package/dist/tbv/core/clients/eth/index.d.ts +1 -0
- package/dist/tbv/core/clients/eth/index.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/types.d.ts +20 -0
- package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts +5 -0
- package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts.map +1 -1
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +29 -27
- package/dist/tbv/core/clients/vault-provider/index.d.ts +1 -1
- package/dist/tbv/core/clients/vault-provider/index.d.ts.map +1 -1
- package/dist/tbv/core/clients/vault-provider/json-rpc-client.d.ts +11 -0
- package/dist/tbv/core/clients/vault-provider/json-rpc-client.d.ts.map +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +151 -145
- package/dist/tbv/core/managers/PeginManager.d.ts +25 -0
- 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.d.ts +2 -2
- package/dist/tbv/core/managers/index.d.ts.map +1 -1
- package/dist/tbv/core/managers/index.js +5 -4
- package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts.map +1 -1
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +26 -23
- package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts +3 -0
- package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts.map +1 -1
- package/dist/tbv/core/services/refund/index.d.ts +1 -1
- package/dist/tbv/core/services/refund/index.d.ts.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +151 -145
- package/dist/{vault-registry-reader-BrARgFre.js → types-0bvDGR4x.js} +88 -74
- package/dist/types-0bvDGR4x.js.map +1 -0
- package/dist/{vault-registry-reader-CbJHSxVe.cjs → types-Be3sAYzr.cjs} +2 -2
- package/dist/types-Be3sAYzr.cjs.map +1 -0
- package/dist/{types-TOmEvvRy.js → types-BqGAMOZM.js} +2 -1
- package/dist/types-BqGAMOZM.js.map +1 -0
- package/dist/{types-D2jcXfm7.cjs → types-eYlq0p1o.cjs} +2 -2
- package/dist/types-eYlq0p1o.cjs.map +1 -0
- package/package.json +1 -1
- package/dist/PeginManager-DaDs-bGr.cjs +0 -2
- package/dist/buildAndBroadcastRefund-B5cOyUzj.js.map +0 -1
- package/dist/buildAndBroadcastRefund-DVMT-pXQ.cjs +0 -2
- package/dist/buildAndBroadcastRefund-DVMT-pXQ.cjs.map +0 -1
- package/dist/types-D2jcXfm7.cjs.map +0 -1
- package/dist/types-TOmEvvRy.js.map +0 -1
- package/dist/vault-registry-reader-BrARgFre.js.map +0 -1
- package/dist/vault-registry-reader-CbJHSxVe.cjs.map +0 -1
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
var
|
|
2
|
-
var zt = (n, t, e) => t in n ?
|
|
1
|
+
var qt = Object.defineProperty;
|
|
2
|
+
var zt = (n, t, e) => t in n ? qt(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
|
|
3
3
|
var x = (n, t, e) => zt(n, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
-
import { s as
|
|
4
|
+
import { s as it, c as It, H as Yt, r as M, a as X, b as lt, u as jt, d as ut, e as ht, f as dt, g as Zt } from "./sha2-BYVxyZzX.js";
|
|
5
5
|
import * as Ct from "bitcoinjs-lib";
|
|
6
|
-
import { Transaction as
|
|
6
|
+
import { Transaction as Qt, Psbt as gt } from "bitcoinjs-lib";
|
|
7
7
|
import { Buffer as J } from "buffer";
|
|
8
|
-
import { isAddressEqual as
|
|
9
|
-
import { B as
|
|
8
|
+
import { isAddressEqual as ft, encodeFunctionData as tt, zeroAddress as Jt } from "viem";
|
|
9
|
+
import { B as I } from "./BTCVaultRegistry.abi-Cq9-JlqT.js";
|
|
10
10
|
import { h as H } from "./errors-CznAK5NB.js";
|
|
11
|
-
import { expandWotsSeed as
|
|
12
|
-
import { b as
|
|
13
|
-
import { b as
|
|
14
|
-
import { u as K, h as
|
|
15
|
-
import { c as
|
|
16
|
-
import { M as
|
|
17
|
-
import { c as
|
|
18
|
-
import { s as
|
|
19
|
-
import { p as
|
|
20
|
-
import { p as
|
|
21
|
-
const N = /* @__PURE__ */ BigInt(2 ** 32 - 1),
|
|
22
|
-
function me(n, t = !1) {
|
|
23
|
-
return t ? { h: Number(n & N), l: Number(n >> xt & N) } : { h: Number(n >> xt & N) | 0, l: Number(n & N) | 0 };
|
|
24
|
-
}
|
|
11
|
+
import { expandWotsSeed as te, expandHashlockSecret as ee, expandAuthAnchor as ne, deriveVaultId as pt } from "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
12
|
+
import { b as mt, a as se, f as bt } from "./assertPsbtUnsignedTxMatches-mTAnLhCz.js";
|
|
13
|
+
import { b as oe, e as re, f as ie } from "./peginInput-BPRB9tUi.js";
|
|
14
|
+
import { u as K, h as et, e as v, p as ae, i as wt, s as T, j as Pt, X as ce } from "./bitcoin-B5aNKtsk.js";
|
|
15
|
+
import { c as le } from "./signing-DaLvGwQe.js";
|
|
16
|
+
import { M as yt } from "./validation-CxqROCno.js";
|
|
17
|
+
import { c as ue, a as he } from "./PayoutManager-D29D-K-V.js";
|
|
18
|
+
import { s as de, f as z, i as ge, w as xt } from "./waitForTransactionReceiptSmartAware-CmgFXFza.js";
|
|
19
|
+
import { p as fe, f as pe } from "./fundPeginTransaction-t-6TsHAY.js";
|
|
20
|
+
import { p as me, f as be } from "./mempoolApi-CAIge7Nj.js";
|
|
21
|
+
const N = /* @__PURE__ */ BigInt(2 ** 32 - 1), kt = /* @__PURE__ */ BigInt(32);
|
|
25
22
|
function we(n, t = !1) {
|
|
23
|
+
return t ? { h: Number(n & N), l: Number(n >> kt & N) } : { h: Number(n >> kt & N) | 0, l: Number(n & N) | 0 };
|
|
24
|
+
}
|
|
25
|
+
function Pe(n, t = !1) {
|
|
26
26
|
const e = n.length;
|
|
27
27
|
let s = new Uint32Array(e), o = new Uint32Array(e);
|
|
28
28
|
for (let r = 0; r < e; r++) {
|
|
29
|
-
const { h: i, l: a } =
|
|
29
|
+
const { h: i, l: a } = we(n[r], t);
|
|
30
30
|
[s[r], o[r]] = [i, a];
|
|
31
31
|
}
|
|
32
32
|
return [s, o];
|
|
33
33
|
}
|
|
34
|
-
const
|
|
35
|
-
function
|
|
34
|
+
const ye = (n, t, e) => n << e | t >>> 32 - e, xe = (n, t, e) => t << e | n >>> 32 - e, ke = (n, t, e) => t << e - 32 | n >>> 64 - e, Ee = (n, t, e) => n << e - 32 | t >>> 64 - e, U = 32, Y = 32, nt = 36, Ht = 32, D = 4, Te = D + U + D + Ht;
|
|
35
|
+
function st(n, t, e) {
|
|
36
36
|
n[t] = e >>> 24 & 255, n[t + 1] = e >>> 16 & 255, n[t + 2] = e >>> 8 & 255, n[t + 3] = e & 255;
|
|
37
37
|
}
|
|
38
|
-
function
|
|
39
|
-
if (n.txid.length !==
|
|
38
|
+
function _e(n) {
|
|
39
|
+
if (n.txid.length !== Y)
|
|
40
40
|
throw new Error(
|
|
41
|
-
`outpoint.txid must be exactly ${
|
|
41
|
+
`outpoint.txid must be exactly ${Y} bytes, got ${n.txid.length}`
|
|
42
42
|
);
|
|
43
43
|
if (!Number.isInteger(n.vout) || n.vout < 0 || n.vout > 4294967295)
|
|
44
44
|
throw new Error(`outpoint.vout must be a u32, got ${n.vout}`);
|
|
45
|
-
const t = new Uint8Array(
|
|
46
|
-
return t.set(n.txid, 0),
|
|
45
|
+
const t = new Uint8Array(nt);
|
|
46
|
+
return t.set(n.txid, 0), st(t, Y, n.vout), t;
|
|
47
47
|
}
|
|
48
|
-
function
|
|
48
|
+
function Et(n, t) {
|
|
49
49
|
const e = Math.min(n.length, t.length);
|
|
50
50
|
for (let s = 0; s < e; s++)
|
|
51
51
|
if (n[s] !== t[s]) return n[s] - t[s];
|
|
52
52
|
return n.length - t.length;
|
|
53
53
|
}
|
|
54
|
-
function
|
|
54
|
+
function Be(n) {
|
|
55
55
|
if (n.length === 0)
|
|
56
56
|
throw new Error(
|
|
57
57
|
"buildFundingOutpointsCommitment: outpoints must be non-empty"
|
|
58
58
|
);
|
|
59
|
-
const t = n.map(
|
|
60
|
-
t.sort(
|
|
59
|
+
const t = n.map(_e);
|
|
60
|
+
t.sort(Et);
|
|
61
61
|
for (let s = 1; s < t.length; s++)
|
|
62
|
-
if (
|
|
62
|
+
if (Et(t[s - 1], t[s]) === 0)
|
|
63
63
|
throw new Error(
|
|
64
64
|
"buildFundingOutpointsCommitment: duplicate outpoint detected"
|
|
65
65
|
);
|
|
66
|
-
const e = new Uint8Array(t.length *
|
|
66
|
+
const e = new Uint8Array(t.length * nt);
|
|
67
67
|
for (let s = 0; s < t.length; s++)
|
|
68
|
-
e.set(t[s], s *
|
|
69
|
-
return
|
|
68
|
+
e.set(t[s], s * nt);
|
|
69
|
+
return it(e);
|
|
70
70
|
}
|
|
71
71
|
function ve(n) {
|
|
72
72
|
if (n.depositorBtcPubkey.length !== U)
|
|
73
73
|
throw new Error(
|
|
74
74
|
`vaultContext: depositorBtcPubkey must be exactly ${U} bytes, got ${n.depositorBtcPubkey.length}`
|
|
75
75
|
);
|
|
76
|
-
const t =
|
|
76
|
+
const t = Be(n.fundingOutpoints), e = new Uint8Array(Te);
|
|
77
77
|
let s = 0;
|
|
78
|
-
return
|
|
78
|
+
return st(e, s, U), s += D, e.set(n.depositorBtcPubkey, s), s += U, st(e, s, Ht), s += D, e.set(t, s), e;
|
|
79
79
|
}
|
|
80
|
-
const
|
|
81
|
-
async function
|
|
82
|
-
const e = ve(t), s = K(e), o = await n.deriveContextHash(
|
|
80
|
+
const Se = "babylon-btc-vault", Ot = 32, Tt = Ot * 2, Ae = /^[0-9a-f]+$/;
|
|
81
|
+
async function Ie(n, t) {
|
|
82
|
+
const e = ve(t), s = K(e), o = await n.deriveContextHash(Se, s);
|
|
83
83
|
if (typeof o != "string")
|
|
84
84
|
throw new Error(
|
|
85
85
|
`deriveVaultRoot: wallet must return a string, got ${typeof o}`
|
|
86
86
|
);
|
|
87
|
-
if (o.length !==
|
|
87
|
+
if (o.length !== Tt)
|
|
88
88
|
throw new Error(
|
|
89
|
-
`deriveVaultRoot: wallet must return a ${
|
|
89
|
+
`deriveVaultRoot: wallet must return a ${Tt}-character hex string (${Ot} bytes), got length ${o.length}`
|
|
90
90
|
);
|
|
91
|
-
if (!
|
|
91
|
+
if (!Ae.test(o))
|
|
92
92
|
throw new Error(
|
|
93
93
|
"deriveVaultRoot: wallet must return lowercase hex per derive-context-hash.md §2.1; got value with non-lowercase or non-hex characters"
|
|
94
94
|
);
|
|
95
|
-
return
|
|
95
|
+
return et(o);
|
|
96
96
|
}
|
|
97
|
-
const
|
|
97
|
+
const Ce = /* @__PURE__ */ Uint8Array.from([
|
|
98
98
|
7,
|
|
99
99
|
4,
|
|
100
100
|
13,
|
|
@@ -111,36 +111,36 @@ const Ie = /* @__PURE__ */ Uint8Array.from([
|
|
|
111
111
|
14,
|
|
112
112
|
11,
|
|
113
113
|
8
|
|
114
|
-
]), $t = Uint8Array.from(new Array(16).fill(0).map((n, t) => t)),
|
|
115
|
-
const e = [[$t], [
|
|
114
|
+
]), $t = Uint8Array.from(new Array(16).fill(0).map((n, t) => t)), He = $t.map((n) => (9 * n + 5) % 16), Rt = /* @__PURE__ */ (() => {
|
|
115
|
+
const e = [[$t], [He]];
|
|
116
116
|
for (let s = 0; s < 4; s++)
|
|
117
117
|
for (let o of e)
|
|
118
|
-
o.push(o[s].map((r) =>
|
|
118
|
+
o.push(o[s].map((r) => Ce[r]));
|
|
119
119
|
return e;
|
|
120
|
-
})(), Ut = Rt[0],
|
|
120
|
+
})(), Ut = Rt[0], Mt = Rt[1], Nt = /* @__PURE__ */ [
|
|
121
121
|
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
|
|
122
122
|
[12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
|
|
123
123
|
[13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
|
|
124
124
|
[14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
|
|
125
125
|
[15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
|
|
126
|
-
].map((n) => Uint8Array.from(n)),
|
|
126
|
+
].map((n) => Uint8Array.from(n)), Oe = /* @__PURE__ */ Ut.map((n, t) => n.map((e) => Nt[t][e])), $e = /* @__PURE__ */ Mt.map((n, t) => n.map((e) => Nt[t][e])), Re = /* @__PURE__ */ Uint32Array.from([
|
|
127
127
|
0,
|
|
128
128
|
1518500249,
|
|
129
129
|
1859775393,
|
|
130
130
|
2400959708,
|
|
131
131
|
2840853838
|
|
132
|
-
]),
|
|
132
|
+
]), Ue = /* @__PURE__ */ Uint32Array.from([
|
|
133
133
|
1352829926,
|
|
134
134
|
1548603684,
|
|
135
135
|
1836072691,
|
|
136
136
|
2053994217,
|
|
137
137
|
0
|
|
138
138
|
]);
|
|
139
|
-
function
|
|
139
|
+
function _t(n, t, e, s) {
|
|
140
140
|
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);
|
|
141
141
|
}
|
|
142
|
-
const
|
|
143
|
-
class
|
|
142
|
+
const V = /* @__PURE__ */ new Uint32Array(16);
|
|
143
|
+
class Me extends Yt {
|
|
144
144
|
constructor() {
|
|
145
145
|
super(64, 20, 8, !0);
|
|
146
146
|
x(this, "h0", 1732584193);
|
|
@@ -157,52 +157,52 @@ class Re extends qt {
|
|
|
157
157
|
this.h0 = e | 0, this.h1 = s | 0, this.h2 = o | 0, this.h3 = r | 0, this.h4 = i | 0;
|
|
158
158
|
}
|
|
159
159
|
process(e, s) {
|
|
160
|
-
for (let
|
|
161
|
-
|
|
162
|
-
let o = this.h0 | 0, r = o, i = this.h1 | 0, a = i, c = this.h2 | 0,
|
|
163
|
-
for (let
|
|
164
|
-
const
|
|
165
|
-
for (let
|
|
166
|
-
const
|
|
167
|
-
o =
|
|
160
|
+
for (let g = 0; g < 16; g++, s += 4)
|
|
161
|
+
V[g] = e.getUint32(s, !0);
|
|
162
|
+
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, b = this.h4 | 0, w = b;
|
|
163
|
+
for (let g = 0; g < 5; g++) {
|
|
164
|
+
const f = 4 - g, k = Re[g], S = Ue[g], E = Ut[g], p = Mt[g], P = Oe[g], y = $e[g];
|
|
165
|
+
for (let h = 0; h < 16; h++) {
|
|
166
|
+
const d = M(o + _t(g, i, c, l) + V[E[h]] + k, P[h]) + b | 0;
|
|
167
|
+
o = b, b = l, l = M(c, 10) | 0, c = i, i = d;
|
|
168
168
|
}
|
|
169
|
-
for (let
|
|
170
|
-
const
|
|
171
|
-
r =
|
|
169
|
+
for (let h = 0; h < 16; h++) {
|
|
170
|
+
const d = M(r + _t(f, a, u, m) + V[p[h]] + S, y[h]) + w | 0;
|
|
171
|
+
r = w, w = m, m = M(u, 10) | 0, u = a, a = d;
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
-
this.set(this.h1 + c + m | 0, this.h2 + l +
|
|
174
|
+
this.set(this.h1 + c + m | 0, this.h2 + l + w | 0, this.h3 + b + r | 0, this.h4 + o + a | 0, this.h0 + i + u | 0);
|
|
175
175
|
}
|
|
176
176
|
roundClean() {
|
|
177
|
-
|
|
177
|
+
X(V);
|
|
178
178
|
}
|
|
179
179
|
destroy() {
|
|
180
|
-
this.destroyed = !0,
|
|
180
|
+
this.destroyed = !0, X(this.buffer), this.set(0, 0, 0, 0, 0);
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
|
-
const
|
|
183
|
+
const Ne = /* @__PURE__ */ It(() => new Me()), Ve = BigInt(0), $ = BigInt(1), Le = BigInt(2), We = BigInt(7), Fe = BigInt(256), Xe = BigInt(113), Vt = [], Lt = [], Wt = [];
|
|
184
184
|
for (let n = 0, t = $, e = 1, s = 0; n < 24; n++) {
|
|
185
|
-
[e, s] = [s, (2 * e + 3 * s) % 5],
|
|
185
|
+
[e, s] = [s, (2 * e + 3 * s) % 5], Vt.push(2 * (5 * s + e)), Lt.push((n + 1) * (n + 2) / 2 % 64);
|
|
186
186
|
let o = Ve;
|
|
187
187
|
for (let r = 0; r < 7; r++)
|
|
188
|
-
t = (t << $ ^ (t >>
|
|
189
|
-
|
|
188
|
+
t = (t << $ ^ (t >> We) * Xe) % Fe, t & Le && (o ^= $ << ($ << BigInt(r)) - $);
|
|
189
|
+
Wt.push(o);
|
|
190
190
|
}
|
|
191
|
-
const
|
|
192
|
-
function
|
|
191
|
+
const Ft = Pe(Wt, !0), Ke = Ft[0], De = Ft[1], Bt = (n, t, e) => e > 32 ? ke(n, t, e) : ye(n, t, e), vt = (n, t, e) => e > 32 ? Ee(n, t, e) : xe(n, t, e);
|
|
192
|
+
function Ge(n, t = 24) {
|
|
193
193
|
const e = new Uint32Array(10);
|
|
194
194
|
for (let s = 24 - t; s < 24; s++) {
|
|
195
195
|
for (let i = 0; i < 10; i++)
|
|
196
196
|
e[i] = n[i] ^ n[i + 10] ^ n[i + 20] ^ n[i + 30] ^ n[i + 40];
|
|
197
197
|
for (let i = 0; i < 10; i += 2) {
|
|
198
|
-
const a = (i + 8) % 10, c = (i + 2) % 10,
|
|
199
|
-
for (let
|
|
200
|
-
n[i +
|
|
198
|
+
const a = (i + 8) % 10, c = (i + 2) % 10, u = e[c], l = e[c + 1], m = Bt(u, l, 1) ^ e[a], b = vt(u, l, 1) ^ e[a + 1];
|
|
199
|
+
for (let w = 0; w < 50; w += 10)
|
|
200
|
+
n[i + w] ^= m, n[i + w + 1] ^= b;
|
|
201
201
|
}
|
|
202
202
|
let o = n[2], r = n[3];
|
|
203
203
|
for (let i = 0; i < 24; i++) {
|
|
204
|
-
const a =
|
|
205
|
-
o = n[l], r = n[l + 1], n[l] = c, n[l + 1] =
|
|
204
|
+
const a = Lt[i], c = Bt(o, r, a), u = vt(o, r, a), l = Vt[i];
|
|
205
|
+
o = n[l], r = n[l + 1], n[l] = c, n[l + 1] = u;
|
|
206
206
|
}
|
|
207
207
|
for (let i = 0; i < 50; i += 10) {
|
|
208
208
|
for (let a = 0; a < 10; a++)
|
|
@@ -210,11 +210,11 @@ function Ke(n, t = 24) {
|
|
|
210
210
|
for (let a = 0; a < 10; a++)
|
|
211
211
|
n[i + a] ^= ~e[(a + 2) % 10] & e[(a + 4) % 10];
|
|
212
212
|
}
|
|
213
|
-
n[0] ^=
|
|
213
|
+
n[0] ^= Ke[s], n[1] ^= De[s];
|
|
214
214
|
}
|
|
215
|
-
|
|
215
|
+
X(e);
|
|
216
216
|
}
|
|
217
|
-
class
|
|
217
|
+
class at {
|
|
218
218
|
// NOTE: we accept arguments in bytes instead of bits here.
|
|
219
219
|
constructor(t, e, s, o = !1, r = 24) {
|
|
220
220
|
x(this, "state");
|
|
@@ -228,18 +228,18 @@ class rt {
|
|
|
228
228
|
x(this, "outputLen");
|
|
229
229
|
x(this, "enableXOF", !1);
|
|
230
230
|
x(this, "rounds");
|
|
231
|
-
if (this.blockLen = t, this.suffix = e, this.outputLen = s, this.enableXOF = o, this.rounds = r,
|
|
231
|
+
if (this.blockLen = t, this.suffix = e, this.outputLen = s, this.enableXOF = o, this.rounds = r, lt(s, "outputLen"), !(0 < t && t < 200))
|
|
232
232
|
throw new Error("only keccak-f1600 function is supported");
|
|
233
|
-
this.state = new Uint8Array(200), this.state32 =
|
|
233
|
+
this.state = new Uint8Array(200), this.state32 = jt(this.state);
|
|
234
234
|
}
|
|
235
235
|
clone() {
|
|
236
236
|
return this._cloneInto();
|
|
237
237
|
}
|
|
238
238
|
keccak() {
|
|
239
|
-
|
|
239
|
+
ut(this.state32), Ge(this.state32, this.rounds), ut(this.state32), this.posOut = 0, this.pos = 0;
|
|
240
240
|
}
|
|
241
241
|
update(t) {
|
|
242
|
-
|
|
242
|
+
ht(this), dt(t);
|
|
243
243
|
const { blockLen: e, state: s } = this, o = t.length;
|
|
244
244
|
for (let r = 0; r < o; ) {
|
|
245
245
|
const i = Math.min(e - this.pos, o - r);
|
|
@@ -257,7 +257,7 @@ class rt {
|
|
|
257
257
|
t[s] ^= e, (e & 128) !== 0 && s === o - 1 && this.keccak(), t[o - 1] ^= 128, this.keccak();
|
|
258
258
|
}
|
|
259
259
|
writeInto(t) {
|
|
260
|
-
|
|
260
|
+
ht(this, !1), dt(t), this.finish();
|
|
261
261
|
const e = this.state, { blockLen: s } = this;
|
|
262
262
|
for (let o = 0, r = t.length; o < r; ) {
|
|
263
263
|
this.posOut >= s && this.keccak();
|
|
@@ -272,10 +272,10 @@ class rt {
|
|
|
272
272
|
return this.writeInto(t);
|
|
273
273
|
}
|
|
274
274
|
xof(t) {
|
|
275
|
-
return
|
|
275
|
+
return lt(t), this.xofInto(new Uint8Array(t));
|
|
276
276
|
}
|
|
277
277
|
digestInto(t) {
|
|
278
|
-
if (
|
|
278
|
+
if (Zt(t, this), this.finished)
|
|
279
279
|
throw new Error("digest() was already called");
|
|
280
280
|
return this.writeInto(t), this.destroy(), t;
|
|
281
281
|
}
|
|
@@ -283,30 +283,30 @@ class rt {
|
|
|
283
283
|
return this.digestInto(new Uint8Array(this.outputLen));
|
|
284
284
|
}
|
|
285
285
|
destroy() {
|
|
286
|
-
this.destroyed = !0,
|
|
286
|
+
this.destroyed = !0, X(this.state);
|
|
287
287
|
}
|
|
288
288
|
_cloneInto(t) {
|
|
289
289
|
const { blockLen: e, suffix: s, outputLen: o, rounds: r, enableXOF: i } = this;
|
|
290
|
-
return t || (t = new
|
|
290
|
+
return t || (t = new at(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;
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
|
-
const
|
|
294
|
-
function
|
|
295
|
-
return
|
|
293
|
+
const qe = (n, t, e, s = {}) => It(() => new at(t, n, e), s), ze = /* @__PURE__ */ qe(1, 136, 32), St = 64, _ = 20, ot = 4, Xt = 2, Ye = 0, je = 1, L = [64, 64], Ze = (n) => Array.from(n).map((t) => t.toString(16).padStart(2, "0")).join("");
|
|
294
|
+
function ct(n) {
|
|
295
|
+
return Ne(it(n));
|
|
296
296
|
}
|
|
297
297
|
function Kt(n) {
|
|
298
298
|
return (1 << n) - 1;
|
|
299
299
|
}
|
|
300
|
-
function
|
|
300
|
+
function Qe(n) {
|
|
301
301
|
let t = 1;
|
|
302
302
|
for (; t * t < n + 1; ) t++;
|
|
303
303
|
return Math.max(t, 2);
|
|
304
304
|
}
|
|
305
|
-
function
|
|
306
|
-
const t =
|
|
307
|
-
return { d: t, n, checksum_radix:
|
|
305
|
+
function Je(n) {
|
|
306
|
+
const t = ot, e = n * Kt(t);
|
|
307
|
+
return { d: t, n, checksum_radix: Qe(e) };
|
|
308
308
|
}
|
|
309
|
-
function
|
|
309
|
+
function j(n, t) {
|
|
310
310
|
const e = [];
|
|
311
311
|
let s = t;
|
|
312
312
|
for (; s > 0; )
|
|
@@ -315,56 +315,56 @@ function Z(n, t) {
|
|
|
315
315
|
o.set(n);
|
|
316
316
|
for (let r = 0; r < e.length; r++)
|
|
317
317
|
o[n.length + r] = e[r];
|
|
318
|
-
return
|
|
318
|
+
return ct(o);
|
|
319
319
|
}
|
|
320
|
-
function
|
|
320
|
+
function Z(n, t) {
|
|
321
321
|
let e = n;
|
|
322
322
|
for (let s = 0; s < t; s++)
|
|
323
|
-
e =
|
|
323
|
+
e = ct(e);
|
|
324
324
|
return e;
|
|
325
325
|
}
|
|
326
|
-
function
|
|
326
|
+
function tn(n, t) {
|
|
327
327
|
const e = Kt(t.d), s = t.checksum_radix - 1, o = Math.floor(t.n * e / t.checksum_radix), r = [];
|
|
328
328
|
for (let l = 0; l < t.n; l++) {
|
|
329
|
-
const m =
|
|
330
|
-
r.push(Array.from(
|
|
329
|
+
const m = j(n, l + Xt), b = Z(m, e);
|
|
330
|
+
r.push(Array.from(b));
|
|
331
331
|
}
|
|
332
|
-
const i =
|
|
332
|
+
const i = j(
|
|
333
333
|
n,
|
|
334
|
-
|
|
335
|
-
), a =
|
|
334
|
+
Ye
|
|
335
|
+
), a = Z(
|
|
336
336
|
i,
|
|
337
337
|
s
|
|
338
|
-
), c =
|
|
338
|
+
), c = j(
|
|
339
339
|
n,
|
|
340
|
-
|
|
341
|
-
),
|
|
340
|
+
je
|
|
341
|
+
), u = Z(
|
|
342
342
|
c,
|
|
343
343
|
o
|
|
344
344
|
);
|
|
345
345
|
return {
|
|
346
346
|
config: t,
|
|
347
347
|
message_terminals: r,
|
|
348
|
-
checksum_major_terminal: Array.from(
|
|
348
|
+
checksum_major_terminal: Array.from(u),
|
|
349
349
|
checksum_minor_terminal: Array.from(a)
|
|
350
350
|
};
|
|
351
351
|
}
|
|
352
|
-
async function
|
|
352
|
+
async function en(n) {
|
|
353
353
|
try {
|
|
354
|
-
if (n.length !==
|
|
354
|
+
if (n.length !== St)
|
|
355
355
|
throw new Error(
|
|
356
|
-
`WOTS seed must be exactly ${
|
|
356
|
+
`WOTS seed must be exactly ${St} bytes, got ${n.length}`
|
|
357
357
|
);
|
|
358
358
|
const t = [];
|
|
359
|
-
for (let e = 0; e <
|
|
360
|
-
const s =
|
|
359
|
+
for (let e = 0; e < L.length; e++) {
|
|
360
|
+
const s = L[e], o = Je(s), r = new Uint8Array(n.length + 1);
|
|
361
361
|
r.set(n), r[n.length] = e;
|
|
362
|
-
const i =
|
|
362
|
+
const i = ct(r);
|
|
363
363
|
try {
|
|
364
|
-
const a =
|
|
365
|
-
if (a.config.d !==
|
|
364
|
+
const a = tn(i, o);
|
|
365
|
+
if (a.config.d !== ot)
|
|
366
366
|
throw new Error(
|
|
367
|
-
`Block ${e}: expected d=${
|
|
367
|
+
`Block ${e}: expected d=${ot}, got d=${a.config.d}`
|
|
368
368
|
);
|
|
369
369
|
if (a.config.n !== s)
|
|
370
370
|
throw new Error(
|
|
@@ -375,26 +375,26 @@ async function Je(n) {
|
|
|
375
375
|
`Block ${e}: expected ${s} message terminals, got ${a.message_terminals.length}`
|
|
376
376
|
);
|
|
377
377
|
for (let c = 0; c < a.message_terminals.length; c++)
|
|
378
|
-
if (a.message_terminals[c].length !==
|
|
378
|
+
if (a.message_terminals[c].length !== _)
|
|
379
379
|
throw new Error(
|
|
380
|
-
`Block ${e} terminal ${c}: expected ${
|
|
380
|
+
`Block ${e} terminal ${c}: expected ${_} bytes, got ${a.message_terminals[c].length}`
|
|
381
381
|
);
|
|
382
|
-
if (a.checksum_minor_terminal.length !==
|
|
382
|
+
if (a.checksum_minor_terminal.length !== _)
|
|
383
383
|
throw new Error(
|
|
384
|
-
`Block ${e} checksum_minor: expected ${
|
|
384
|
+
`Block ${e} checksum_minor: expected ${_} bytes`
|
|
385
385
|
);
|
|
386
|
-
if (a.checksum_major_terminal.length !==
|
|
386
|
+
if (a.checksum_major_terminal.length !== _)
|
|
387
387
|
throw new Error(
|
|
388
|
-
`Block ${e} checksum_major: expected ${
|
|
388
|
+
`Block ${e} checksum_major: expected ${_} bytes`
|
|
389
389
|
);
|
|
390
390
|
t.push(a);
|
|
391
391
|
} finally {
|
|
392
392
|
r.fill(0), i.fill(0);
|
|
393
393
|
}
|
|
394
394
|
}
|
|
395
|
-
if (t.length !==
|
|
395
|
+
if (t.length !== L.length)
|
|
396
396
|
throw new Error(
|
|
397
|
-
`Expected ${
|
|
397
|
+
`Expected ${L.length} blocks, got ${t.length}`
|
|
398
398
|
);
|
|
399
399
|
return t;
|
|
400
400
|
} finally {
|
|
@@ -402,9 +402,9 @@ async function Je(n) {
|
|
|
402
402
|
}
|
|
403
403
|
}
|
|
404
404
|
function Q(n, t, e) {
|
|
405
|
-
if (n.length !==
|
|
405
|
+
if (n.length !== _)
|
|
406
406
|
throw new Error(
|
|
407
|
-
`Block ${t} ${e}: expected ${
|
|
407
|
+
`Block ${t} ${e}: expected ${_} bytes, got ${n.length}`
|
|
408
408
|
);
|
|
409
409
|
for (let s = 0; s < n.length; s++) {
|
|
410
410
|
const o = n[s];
|
|
@@ -414,7 +414,7 @@ function Q(n, t, e) {
|
|
|
414
414
|
);
|
|
415
415
|
}
|
|
416
416
|
}
|
|
417
|
-
function
|
|
417
|
+
function nn(n) {
|
|
418
418
|
if (n.length === 0)
|
|
419
419
|
throw new Error("Public keys array must not be empty");
|
|
420
420
|
for (let r = 0; r < n.length; r++) {
|
|
@@ -425,32 +425,32 @@ function tn(n) {
|
|
|
425
425
|
}
|
|
426
426
|
let t = 0;
|
|
427
427
|
for (const r of n)
|
|
428
|
-
t +=
|
|
429
|
-
const e = new Uint8Array(t *
|
|
428
|
+
t += Xt + r.message_terminals.length;
|
|
429
|
+
const e = new Uint8Array(t * _);
|
|
430
430
|
let s = 0;
|
|
431
431
|
for (const r of n) {
|
|
432
|
-
e.set(r.checksum_minor_terminal, s), s +=
|
|
432
|
+
e.set(r.checksum_minor_terminal, s), s += _, e.set(r.checksum_major_terminal, s), s += _;
|
|
433
433
|
for (const i of r.message_terminals)
|
|
434
|
-
e.set(i, s), s +=
|
|
434
|
+
e.set(i, s), s += _;
|
|
435
435
|
}
|
|
436
436
|
const o = ze(e);
|
|
437
|
-
return `0x${
|
|
437
|
+
return `0x${Ze(o)}`;
|
|
438
438
|
}
|
|
439
|
-
async function
|
|
439
|
+
async function sn(n, t) {
|
|
440
440
|
const e = [], s = [], o = [], r = [];
|
|
441
441
|
try {
|
|
442
442
|
for (let i = 0; i < t; i++) {
|
|
443
|
-
const a = await
|
|
443
|
+
const a = await te(n, i);
|
|
444
444
|
try {
|
|
445
|
-
const
|
|
446
|
-
e.push(
|
|
445
|
+
const u = await en(a);
|
|
446
|
+
e.push(u), s.push(nn(u));
|
|
447
447
|
} finally {
|
|
448
448
|
a.fill(0);
|
|
449
449
|
}
|
|
450
|
-
const c = await
|
|
450
|
+
const c = await ee(n, i);
|
|
451
451
|
try {
|
|
452
|
-
const
|
|
453
|
-
o.push(
|
|
452
|
+
const u = K(c);
|
|
453
|
+
o.push(u), r.push(ue(v(u)).slice(2));
|
|
454
454
|
} finally {
|
|
455
455
|
c.fill(0);
|
|
456
456
|
}
|
|
@@ -460,33 +460,33 @@ async function en(n, t) {
|
|
|
460
460
|
}
|
|
461
461
|
return { perVaultWotsKeys: e, wotsPkHashes: s, htlcSecretHexes: o, hashlocks: r };
|
|
462
462
|
}
|
|
463
|
-
const
|
|
463
|
+
const on = /^0x[0-9a-f]+$/i, rn = /^[0-9a-f]+$/i, an = /^[A-Za-z0-9+/]+={0,2}$/;
|
|
464
464
|
function R(n) {
|
|
465
465
|
if (typeof n != "string" || n.length === 0)
|
|
466
466
|
throw new Error("BTC wallet returned empty public key");
|
|
467
|
-
return
|
|
467
|
+
return ae(n).toLowerCase();
|
|
468
468
|
}
|
|
469
|
-
function
|
|
469
|
+
function cn(n) {
|
|
470
470
|
if (typeof n != "string" || n.length === 0)
|
|
471
471
|
throw new Error("BTC wallet returned empty BIP-322 signature");
|
|
472
472
|
if (n.startsWith("0x") || n.startsWith("0X")) {
|
|
473
|
-
if (!
|
|
473
|
+
if (!on.test(n) || n.length < 4 || n.length % 2 !== 0)
|
|
474
474
|
throw new Error("BTC wallet returned malformed hex BIP-322 signature");
|
|
475
475
|
return n.toLowerCase();
|
|
476
476
|
}
|
|
477
|
-
if (
|
|
477
|
+
if (rn.test(n)) {
|
|
478
478
|
if (n.length % 2 !== 0)
|
|
479
479
|
throw new Error("BTC wallet returned malformed hex BIP-322 signature");
|
|
480
480
|
return `0x${n.toLowerCase()}`;
|
|
481
481
|
}
|
|
482
|
-
if (!
|
|
482
|
+
if (!an.test(n) || n.length % 4 !== 0)
|
|
483
483
|
throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
|
|
484
484
|
const t = J.from(n, "base64");
|
|
485
485
|
if (t.length === 0 || t.toString("base64") !== n)
|
|
486
486
|
throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
|
|
487
487
|
return `0x${t.toString("hex")}`;
|
|
488
488
|
}
|
|
489
|
-
async function
|
|
489
|
+
async function ln(n, t, e) {
|
|
490
490
|
if (typeof n.signPsbts == "function") {
|
|
491
491
|
const o = await n.signPsbts(t, e);
|
|
492
492
|
if (o.length !== t.length)
|
|
@@ -502,8 +502,8 @@ async function an(n, t, e) {
|
|
|
502
502
|
}
|
|
503
503
|
return s;
|
|
504
504
|
}
|
|
505
|
-
const
|
|
506
|
-
function
|
|
505
|
+
const Dt = 0, W = 25, rt = 9999, F = "00".repeat(32);
|
|
506
|
+
function un(n, t) {
|
|
507
507
|
const e = {
|
|
508
508
|
bitcoin: "bc",
|
|
509
509
|
testnet: "tb",
|
|
@@ -517,17 +517,17 @@ function ln(n, t) {
|
|
|
517
517
|
return !1;
|
|
518
518
|
}
|
|
519
519
|
}
|
|
520
|
-
function
|
|
520
|
+
function hn(n, t, e, s) {
|
|
521
521
|
const o = e == null ? void 0 : e[`${n}:${t}`];
|
|
522
522
|
return o ? Promise.resolve({
|
|
523
523
|
txid: n,
|
|
524
524
|
vout: t,
|
|
525
525
|
value: o.value,
|
|
526
526
|
scriptPubKey: o.scriptPubKey
|
|
527
|
-
}) :
|
|
527
|
+
}) : be(n, t, s);
|
|
528
528
|
}
|
|
529
|
-
const
|
|
530
|
-
class
|
|
529
|
+
const At = 12e4;
|
|
530
|
+
class Rn {
|
|
531
531
|
/**
|
|
532
532
|
* Creates a new PeginManager instance.
|
|
533
533
|
*
|
|
@@ -559,45 +559,45 @@ class An {
|
|
|
559
559
|
`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.`
|
|
560
560
|
);
|
|
561
561
|
const o = await this.prepareSizing(s, t), r = o.selectedUTXOs.map(
|
|
562
|
-
(
|
|
563
|
-
txid:
|
|
564
|
-
vout:
|
|
562
|
+
(f) => ({
|
|
563
|
+
txid: et(f.txid),
|
|
564
|
+
vout: f.vout
|
|
565
565
|
})
|
|
566
|
-
), i = await
|
|
567
|
-
depositorBtcPubkey:
|
|
566
|
+
), i = await Ie(this.config.btcWallet, {
|
|
567
|
+
depositorBtcPubkey: et(s),
|
|
568
568
|
fundingOutpoints: r
|
|
569
569
|
});
|
|
570
570
|
let a, c;
|
|
571
571
|
try {
|
|
572
|
-
const
|
|
572
|
+
const f = await ne(i);
|
|
573
573
|
try {
|
|
574
|
-
a = K(
|
|
574
|
+
a = K(f), c = K(it(f));
|
|
575
575
|
} finally {
|
|
576
|
-
|
|
576
|
+
f.fill(0);
|
|
577
577
|
}
|
|
578
|
-
} catch (
|
|
579
|
-
throw i.fill(0),
|
|
578
|
+
} catch (f) {
|
|
579
|
+
throw i.fill(0), f;
|
|
580
580
|
}
|
|
581
|
-
const
|
|
581
|
+
const u = await sn(i, t.amounts.length), { perVaultWotsKeys: l, wotsPkHashes: m, htlcSecretHexes: b, hashlocks: w } = u, g = await this.preparePeginCommit({
|
|
582
582
|
depositorBtcPubkeyRaw: e,
|
|
583
583
|
depositorBtcPubkey: s,
|
|
584
|
-
hashlocks:
|
|
584
|
+
hashlocks: w,
|
|
585
585
|
authAnchorHash: c,
|
|
586
586
|
sizing: o,
|
|
587
587
|
params: t
|
|
588
588
|
});
|
|
589
|
-
for (let
|
|
590
|
-
if (
|
|
589
|
+
for (let f = 0; f < g.perVault.length; f++)
|
|
590
|
+
if (g.perVault[f].htlcVout !== f)
|
|
591
591
|
throw new Error(
|
|
592
|
-
`Internal invariant violation: htlcVout/index mismatch at vault ${
|
|
592
|
+
`Internal invariant violation: htlcVout/index mismatch at vault ${f} (expected ${f}, got ${g.perVault[f].htlcVout})`
|
|
593
593
|
);
|
|
594
|
-
return
|
|
595
|
-
|
|
594
|
+
return he(
|
|
595
|
+
g.fundedPrePeginTxHex,
|
|
596
596
|
t.amounts.length,
|
|
597
597
|
c
|
|
598
598
|
), {
|
|
599
599
|
transaction: {
|
|
600
|
-
...
|
|
600
|
+
...g,
|
|
601
601
|
selectedUTXOs: o.selectedUTXOs,
|
|
602
602
|
fee: o.fee,
|
|
603
603
|
changeAmount: o.changeAmount
|
|
@@ -606,7 +606,7 @@ class An {
|
|
|
606
606
|
derivedSecrets: {
|
|
607
607
|
perVaultWotsKeys: l,
|
|
608
608
|
wotsPkHashes: m,
|
|
609
|
-
htlcSecretHexes:
|
|
609
|
+
htlcSecretHexes: b,
|
|
610
610
|
authAnchorHex: a
|
|
611
611
|
}
|
|
612
612
|
};
|
|
@@ -629,8 +629,8 @@ class An {
|
|
|
629
629
|
*/
|
|
630
630
|
async prepareSizing(t, e) {
|
|
631
631
|
const s = e.amounts.map(
|
|
632
|
-
() =>
|
|
633
|
-
), o = e.vaultKeeperBtcPubkeys.length, r = await
|
|
632
|
+
() => F
|
|
633
|
+
), o = e.vaultKeeperBtcPubkeys.length, r = await mt({
|
|
634
634
|
depositorPubkey: t,
|
|
635
635
|
vaultProviderPubkey: T(e.vaultProviderBtcPubkey),
|
|
636
636
|
vaultKeeperPubkeys: e.vaultKeeperBtcPubkeys.map(T),
|
|
@@ -643,14 +643,14 @@ class An {
|
|
|
643
643
|
councilQuorum: e.councilQuorum,
|
|
644
644
|
councilSize: e.councilSize,
|
|
645
645
|
network: this.config.btcNetwork,
|
|
646
|
-
authAnchorHash:
|
|
647
|
-
}), i =
|
|
646
|
+
authAnchorHash: F
|
|
647
|
+
}), i = de(
|
|
648
648
|
[...e.availableUTXOs],
|
|
649
649
|
r.totalOutputValue,
|
|
650
650
|
e.mempoolFeeRate,
|
|
651
|
-
|
|
651
|
+
fe(
|
|
652
652
|
r.htlcValues.length,
|
|
653
|
-
|
|
653
|
+
F
|
|
654
654
|
)
|
|
655
655
|
);
|
|
656
656
|
return {
|
|
@@ -668,85 +668,85 @@ class An {
|
|
|
668
668
|
authAnchorHash: r,
|
|
669
669
|
sizing: i,
|
|
670
670
|
params: a
|
|
671
|
-
} = t, c =
|
|
672
|
-
for (let
|
|
673
|
-
if (o[
|
|
671
|
+
} = t, c = F.toLowerCase();
|
|
672
|
+
for (let d = 0; d < o.length; d++)
|
|
673
|
+
if (o[d].toLowerCase() === c)
|
|
674
674
|
throw new Error(
|
|
675
|
-
`preparePeginCommit refusing to build with sizing-pass placeholder hashlock at vault ${
|
|
675
|
+
`preparePeginCommit refusing to build with sizing-pass placeholder hashlock at vault ${d} — internal substitution bug`
|
|
676
676
|
);
|
|
677
677
|
if (r.toLowerCase() === c)
|
|
678
678
|
throw new Error(
|
|
679
679
|
"preparePeginCommit refusing to build with sizing-pass placeholder auth-anchor hash — internal substitution bug"
|
|
680
680
|
);
|
|
681
|
-
const
|
|
681
|
+
const u = T(a.vaultProviderBtcPubkey), l = a.vaultKeeperBtcPubkeys.map(T), m = a.universalChallengerBtcPubkeys.map(T), b = l.length, w = {
|
|
682
682
|
depositorPubkey: s,
|
|
683
|
-
vaultProviderPubkey:
|
|
683
|
+
vaultProviderPubkey: u,
|
|
684
684
|
vaultKeeperPubkeys: l,
|
|
685
685
|
universalChallengerPubkeys: m,
|
|
686
686
|
hashlocks: o,
|
|
687
687
|
timelockRefund: a.timelockRefund,
|
|
688
688
|
pegInAmounts: a.amounts,
|
|
689
689
|
feeRate: a.protocolFeeRate,
|
|
690
|
-
numLocalChallengers:
|
|
690
|
+
numLocalChallengers: b,
|
|
691
691
|
councilQuorum: a.councilQuorum,
|
|
692
692
|
councilSize: a.councilSize,
|
|
693
693
|
network: this.config.btcNetwork,
|
|
694
694
|
authAnchorHash: r
|
|
695
|
-
},
|
|
696
|
-
unfundedTxHex:
|
|
695
|
+
}, g = await mt(w), f = Pt(this.config.btcNetwork), k = pe({
|
|
696
|
+
unfundedTxHex: g.psbtHex,
|
|
697
697
|
selectedUTXOs: i.selectedUTXOs,
|
|
698
698
|
changeAddress: a.changeAddress,
|
|
699
699
|
changeAmount: i.changeAmount,
|
|
700
|
-
network:
|
|
701
|
-
}),
|
|
702
|
-
for (let
|
|
703
|
-
const
|
|
704
|
-
prePeginParams:
|
|
700
|
+
network: f
|
|
701
|
+
}), S = T(z(k)), E = [], p = [], P = [];
|
|
702
|
+
for (let d = 0; d < o.length; d++) {
|
|
703
|
+
const B = await se({
|
|
704
|
+
prePeginParams: w,
|
|
705
705
|
timelockPegin: a.timelockPegin,
|
|
706
706
|
fundedPrePeginTxHex: k,
|
|
707
|
-
htlcVout:
|
|
708
|
-
}),
|
|
709
|
-
peginTxHex:
|
|
707
|
+
htlcVout: d
|
|
708
|
+
}), A = await oe({
|
|
709
|
+
peginTxHex: B.txHex,
|
|
710
710
|
fundedPrePeginTxHex: k,
|
|
711
711
|
depositorPubkey: s,
|
|
712
|
-
vaultProviderPubkey:
|
|
712
|
+
vaultProviderPubkey: u,
|
|
713
713
|
vaultKeeperPubkeys: l,
|
|
714
714
|
universalChallengerPubkeys: m,
|
|
715
|
-
hashlock: o[
|
|
715
|
+
hashlock: o[d],
|
|
716
716
|
timelockRefund: a.timelockRefund,
|
|
717
717
|
network: this.config.btcNetwork
|
|
718
718
|
});
|
|
719
|
-
E.push(
|
|
720
|
-
|
|
719
|
+
E.push(B), p.push(A.psbtHex), P.push(
|
|
720
|
+
le(e, 1)
|
|
721
721
|
);
|
|
722
722
|
}
|
|
723
|
-
const y = await
|
|
723
|
+
const y = await ln(
|
|
724
724
|
this.config.btcWallet,
|
|
725
725
|
p,
|
|
726
726
|
P
|
|
727
|
-
),
|
|
728
|
-
for (let
|
|
729
|
-
|
|
730
|
-
requestedPsbtHex: p[
|
|
731
|
-
returnedPsbtHex: y[
|
|
727
|
+
), h = [];
|
|
728
|
+
for (let d = 0; d < y.length; d++) {
|
|
729
|
+
bt({
|
|
730
|
+
requestedPsbtHex: p[d],
|
|
731
|
+
returnedPsbtHex: y[d]
|
|
732
732
|
});
|
|
733
|
-
const
|
|
734
|
-
y[
|
|
733
|
+
const B = re(
|
|
734
|
+
y[d],
|
|
735
735
|
s
|
|
736
|
-
),
|
|
737
|
-
|
|
738
|
-
htlcVout:
|
|
739
|
-
htlcValue:
|
|
740
|
-
peginTxHex:
|
|
741
|
-
peginTxid: E[
|
|
742
|
-
peginInputSignature:
|
|
743
|
-
vaultScriptPubKey: E[
|
|
736
|
+
), A = ie(y[d]);
|
|
737
|
+
h.push({
|
|
738
|
+
htlcVout: d,
|
|
739
|
+
htlcValue: g.htlcValues[d],
|
|
740
|
+
peginTxHex: A,
|
|
741
|
+
peginTxid: E[d].txid,
|
|
742
|
+
peginInputSignature: B,
|
|
743
|
+
vaultScriptPubKey: E[d].vaultScriptPubKey
|
|
744
744
|
});
|
|
745
745
|
}
|
|
746
746
|
return {
|
|
747
747
|
fundedPrePeginTxHex: k,
|
|
748
|
-
prePeginTxid:
|
|
749
|
-
perVault:
|
|
748
|
+
prePeginTxid: S,
|
|
749
|
+
perVault: h
|
|
750
750
|
};
|
|
751
751
|
}
|
|
752
752
|
/**
|
|
@@ -765,37 +765,37 @@ class An {
|
|
|
765
765
|
* @throws Error if signing or broadcasting fails
|
|
766
766
|
*/
|
|
767
767
|
async signAndBroadcast(t) {
|
|
768
|
-
const { fundedPrePeginTxHex: e, depositorBtcPubkey: s } = t, o = e.startsWith("0x") ? e.slice(2) : e, r =
|
|
768
|
+
const { fundedPrePeginTxHex: e, depositorBtcPubkey: s } = t, o = e.startsWith("0x") ? e.slice(2) : e, r = Qt.fromHex(o);
|
|
769
769
|
if (r.ins.length === 0)
|
|
770
770
|
throw new Error("Transaction has no inputs");
|
|
771
|
-
const i = new
|
|
771
|
+
const i = new gt();
|
|
772
772
|
i.setVersion(r.version), i.setLocktime(r.locktime);
|
|
773
773
|
const a = J.from(
|
|
774
774
|
R(s),
|
|
775
775
|
"hex"
|
|
776
|
-
), c = this.config.mempoolApiUrl,
|
|
776
|
+
), c = this.config.mempoolApiUrl, u = r.ins.map((p) => {
|
|
777
777
|
const P = J.from(p.hash).reverse().toString("hex"), y = p.index;
|
|
778
|
-
return
|
|
779
|
-
(
|
|
778
|
+
return hn(P, y, t.localPrevouts, c).then(
|
|
779
|
+
(h) => ({ input: p, utxoData: h, txid: P, vout: y })
|
|
780
780
|
);
|
|
781
|
-
}), l = await Promise.all(
|
|
781
|
+
}), l = await Promise.all(u), m = l.reduce(
|
|
782
782
|
(p, P) => p + BigInt(P.utxoData.value),
|
|
783
783
|
0n
|
|
784
|
-
),
|
|
784
|
+
), b = r.outs.reduce(
|
|
785
785
|
(p, P) => p + BigInt(P.value),
|
|
786
786
|
0n
|
|
787
787
|
);
|
|
788
|
-
if (m <
|
|
788
|
+
if (m < b)
|
|
789
789
|
throw new Error(
|
|
790
|
-
`UTXO value mismatch: total input value (${m} sat) is less than total output value (${
|
|
790
|
+
`UTXO value mismatch: total input value (${m} sat) is less than total output value (${b} sat). This may indicate the mempool API returned manipulated UTXO data.`
|
|
791
791
|
);
|
|
792
|
-
const
|
|
793
|
-
if (
|
|
792
|
+
const w = m - b;
|
|
793
|
+
if (w > yt)
|
|
794
794
|
throw new Error(
|
|
795
|
-
`Implied transaction fee (${
|
|
795
|
+
`Implied transaction fee (${w} sat) exceeds maximum reasonable fee (${yt} sat). This may indicate manipulated UTXO data.`
|
|
796
796
|
);
|
|
797
|
-
for (const { input: p, utxoData: P, txid: y, vout:
|
|
798
|
-
const
|
|
797
|
+
for (const { input: p, utxoData: P, txid: y, vout: h } of l) {
|
|
798
|
+
const d = ge(
|
|
799
799
|
{
|
|
800
800
|
value: P.value,
|
|
801
801
|
scriptPubKey: P.scriptPubKey
|
|
@@ -806,7 +806,7 @@ class An {
|
|
|
806
806
|
hash: p.hash,
|
|
807
807
|
index: p.index,
|
|
808
808
|
sequence: p.sequence,
|
|
809
|
-
...
|
|
809
|
+
...d
|
|
810
810
|
});
|
|
811
811
|
}
|
|
812
812
|
for (const p of r.outs)
|
|
@@ -814,12 +814,12 @@ class An {
|
|
|
814
814
|
script: p.script,
|
|
815
815
|
value: p.value
|
|
816
816
|
});
|
|
817
|
-
const
|
|
818
|
-
|
|
819
|
-
requestedPsbtHex:
|
|
820
|
-
returnedPsbtHex:
|
|
817
|
+
const g = i.toHex(), f = await this.config.btcWallet.signPsbt(g);
|
|
818
|
+
bt({
|
|
819
|
+
requestedPsbtHex: g,
|
|
820
|
+
returnedPsbtHex: f
|
|
821
821
|
});
|
|
822
|
-
const k =
|
|
822
|
+
const k = gt.fromHex(f);
|
|
823
823
|
try {
|
|
824
824
|
k.finalizeAllInputs();
|
|
825
825
|
} catch (p) {
|
|
@@ -830,8 +830,8 @@ class An {
|
|
|
830
830
|
`PSBT finalization failed and wallet did not auto-finalize: ${p}`
|
|
831
831
|
);
|
|
832
832
|
}
|
|
833
|
-
const
|
|
834
|
-
return await
|
|
833
|
+
const S = k.extractTransaction().toHex();
|
|
834
|
+
return await me(S, c);
|
|
835
835
|
}
|
|
836
836
|
/**
|
|
837
837
|
* Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
|
|
@@ -866,32 +866,32 @@ class An {
|
|
|
866
866
|
htlcVout: i,
|
|
867
867
|
depositorPayoutBtcAddress: a,
|
|
868
868
|
depositorWotsPkHash: c,
|
|
869
|
-
popSignature:
|
|
869
|
+
popSignature: u
|
|
870
870
|
} = t;
|
|
871
871
|
if (!this.config.ethWallet.account)
|
|
872
872
|
throw new Error("Ethereum wallet account not found");
|
|
873
873
|
const l = this.config.ethWallet.account.address;
|
|
874
|
-
if (!
|
|
874
|
+
if (!ft(u.depositorEthAddress, l))
|
|
875
875
|
throw new Error(
|
|
876
|
-
`Proof of possession was signed for ${
|
|
876
|
+
`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.`
|
|
877
877
|
);
|
|
878
|
-
const m = await this.assertPopMatchesBtcWallet(
|
|
878
|
+
const m = await this.assertPopMatchesBtcWallet(u), b = u.btcPopSignature, w = v(u.depositorBtcPubkey), g = v(e), f = v(s), k = a ?? await this.config.btcWallet.getAddress(), S = this.resolvePayoutScriptPubKey(
|
|
879
879
|
m,
|
|
880
880
|
k
|
|
881
|
-
), E =
|
|
881
|
+
), E = z(f), p = await pt(
|
|
882
882
|
T(E),
|
|
883
883
|
T(l)
|
|
884
|
-
), P =
|
|
884
|
+
), P = v(p);
|
|
885
885
|
if (await this.checkVaultExists(P))
|
|
886
886
|
throw new Error(
|
|
887
887
|
`Vault already exists (ID: ${P}, peginTxHash: ${E}). 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.`
|
|
888
888
|
);
|
|
889
|
-
const
|
|
890
|
-
let
|
|
889
|
+
const h = this.config.publicClient;
|
|
890
|
+
let d;
|
|
891
891
|
try {
|
|
892
|
-
|
|
892
|
+
d = await h.readContract({
|
|
893
893
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
894
|
-
abi:
|
|
894
|
+
abi: I,
|
|
895
895
|
functionName: "getPegInFee",
|
|
896
896
|
args: [o]
|
|
897
897
|
});
|
|
@@ -901,55 +901,55 @@ class An {
|
|
|
901
901
|
{ cause: O }
|
|
902
902
|
);
|
|
903
903
|
}
|
|
904
|
-
const
|
|
904
|
+
const B = await this.resolveMaxAcceptableCommissionBps(
|
|
905
905
|
o,
|
|
906
906
|
t.quotedCommissionBps
|
|
907
|
-
),
|
|
908
|
-
abi:
|
|
907
|
+
), A = tt({
|
|
908
|
+
abi: I,
|
|
909
909
|
functionName: "submitPeginRequest",
|
|
910
910
|
args: [
|
|
911
911
|
l,
|
|
912
|
-
b,
|
|
913
912
|
w,
|
|
914
|
-
|
|
913
|
+
b,
|
|
915
914
|
g,
|
|
915
|
+
f,
|
|
916
916
|
o,
|
|
917
|
-
|
|
917
|
+
B,
|
|
918
918
|
r,
|
|
919
919
|
i,
|
|
920
|
-
|
|
920
|
+
S,
|
|
921
921
|
c
|
|
922
922
|
]
|
|
923
923
|
});
|
|
924
|
-
let
|
|
924
|
+
let C;
|
|
925
925
|
try {
|
|
926
|
-
|
|
926
|
+
C = await h.estimateGas({
|
|
927
927
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
928
|
-
data:
|
|
929
|
-
value:
|
|
928
|
+
data: A,
|
|
929
|
+
value: d,
|
|
930
930
|
account: this.config.ethWallet.account.address
|
|
931
931
|
});
|
|
932
932
|
} catch (O) {
|
|
933
933
|
H(O);
|
|
934
934
|
}
|
|
935
|
-
let
|
|
935
|
+
let G;
|
|
936
936
|
try {
|
|
937
|
-
|
|
937
|
+
G = await this.config.ethWallet.sendTransaction({
|
|
938
938
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
939
|
-
data:
|
|
940
|
-
value:
|
|
939
|
+
data: A,
|
|
940
|
+
value: d,
|
|
941
941
|
account: this.config.ethWallet.account,
|
|
942
942
|
chain: this.config.ethChain,
|
|
943
|
-
gas:
|
|
943
|
+
gas: C
|
|
944
944
|
});
|
|
945
945
|
} catch (O) {
|
|
946
946
|
H(O);
|
|
947
947
|
}
|
|
948
|
-
const q = await
|
|
949
|
-
publicClient:
|
|
948
|
+
const q = await xt({
|
|
949
|
+
publicClient: h,
|
|
950
950
|
walletAddress: this.config.ethWallet.account.address,
|
|
951
|
-
hash:
|
|
952
|
-
timeout:
|
|
951
|
+
hash: G,
|
|
952
|
+
timeout: At
|
|
953
953
|
});
|
|
954
954
|
return q.status === "reverted" && H(
|
|
955
955
|
new Error(
|
|
@@ -978,69 +978,69 @@ class An {
|
|
|
978
978
|
if (!this.config.ethWallet.account)
|
|
979
979
|
throw new Error("Ethereum wallet account not found");
|
|
980
980
|
const i = this.config.ethWallet.account.address;
|
|
981
|
-
if (!
|
|
981
|
+
if (!ft(r.depositorEthAddress, i))
|
|
982
982
|
throw new Error(
|
|
983
983
|
`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.`
|
|
984
984
|
);
|
|
985
|
-
const a = await this.assertPopMatchesBtcWallet(r), c = r.btcPopSignature,
|
|
986
|
-
(
|
|
985
|
+
const a = await this.assertPopMatchesBtcWallet(r), c = r.btcPopSignature, u = o.map(
|
|
986
|
+
(h) => this.resolvePayoutScriptPubKey(
|
|
987
987
|
a,
|
|
988
|
-
|
|
988
|
+
h.depositorPayoutBtcAddress
|
|
989
989
|
)
|
|
990
990
|
), l = [];
|
|
991
|
-
for (const
|
|
992
|
-
const
|
|
993
|
-
|
|
994
|
-
),
|
|
995
|
-
T(
|
|
991
|
+
for (const h of o) {
|
|
992
|
+
const d = v(
|
|
993
|
+
h.depositorSignedPeginTx
|
|
994
|
+
), B = z(d), A = await pt(
|
|
995
|
+
T(B),
|
|
996
996
|
T(i)
|
|
997
|
-
),
|
|
998
|
-
if (await this.checkVaultExists(
|
|
997
|
+
), C = v(A);
|
|
998
|
+
if (await this.checkVaultExists(C))
|
|
999
999
|
throw new Error(
|
|
1000
|
-
`Vault already exists (ID: ${
|
|
1000
|
+
`Vault already exists (ID: ${C}, peginTxHash: ${B}). To create a new vault, use different UTXOs or a different amount.`
|
|
1001
1001
|
);
|
|
1002
|
-
l.push({ vaultId:
|
|
1002
|
+
l.push({ vaultId: C, peginTxHash: B });
|
|
1003
1003
|
}
|
|
1004
1004
|
const m = this.config.publicClient;
|
|
1005
|
-
let
|
|
1005
|
+
let b;
|
|
1006
1006
|
try {
|
|
1007
|
-
|
|
1007
|
+
b = await m.readContract({
|
|
1008
1008
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
1009
|
-
abi:
|
|
1009
|
+
abi: I,
|
|
1010
1010
|
functionName: "getPegInFee",
|
|
1011
1011
|
args: [e]
|
|
1012
1012
|
});
|
|
1013
|
-
} catch (
|
|
1013
|
+
} catch (h) {
|
|
1014
1014
|
throw new Error(
|
|
1015
1015
|
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct.",
|
|
1016
|
-
{ cause:
|
|
1016
|
+
{ cause: h }
|
|
1017
1017
|
);
|
|
1018
1018
|
}
|
|
1019
|
-
const
|
|
1019
|
+
const w = b * BigInt(o.length), g = await this.resolveMaxAcceptableCommissionBps(
|
|
1020
1020
|
e,
|
|
1021
1021
|
t.quotedCommissionBps
|
|
1022
|
-
),
|
|
1022
|
+
), f = v(
|
|
1023
1023
|
r.depositorBtcPubkey
|
|
1024
|
-
), k =
|
|
1025
|
-
depositorBtcPubKey:
|
|
1024
|
+
), k = v(s), S = o.map((h, d) => ({
|
|
1025
|
+
depositorBtcPubKey: f,
|
|
1026
1026
|
btcPopSignature: c,
|
|
1027
1027
|
unsignedPrePeginTx: k,
|
|
1028
|
-
depositorSignedPeginTx:
|
|
1029
|
-
|
|
1028
|
+
depositorSignedPeginTx: v(
|
|
1029
|
+
h.depositorSignedPeginTx
|
|
1030
1030
|
),
|
|
1031
|
-
hashlock:
|
|
1032
|
-
htlcVout:
|
|
1033
|
-
referralCode:
|
|
1034
|
-
depositorPayoutBtcAddress: d
|
|
1035
|
-
depositorWotsPkHash:
|
|
1036
|
-
})), E =
|
|
1037
|
-
abi:
|
|
1031
|
+
hashlock: h.hashlock,
|
|
1032
|
+
htlcVout: h.htlcVout,
|
|
1033
|
+
referralCode: Dt,
|
|
1034
|
+
depositorPayoutBtcAddress: u[d],
|
|
1035
|
+
depositorWotsPkHash: h.depositorWotsPkHash
|
|
1036
|
+
})), E = tt({
|
|
1037
|
+
abi: I,
|
|
1038
1038
|
functionName: "submitPeginRequestBatch",
|
|
1039
1039
|
args: [
|
|
1040
1040
|
i,
|
|
1041
1041
|
e,
|
|
1042
|
-
|
|
1043
|
-
|
|
1042
|
+
g,
|
|
1043
|
+
S
|
|
1044
1044
|
]
|
|
1045
1045
|
});
|
|
1046
1046
|
let p;
|
|
@@ -1048,30 +1048,30 @@ class An {
|
|
|
1048
1048
|
p = await m.estimateGas({
|
|
1049
1049
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1050
1050
|
data: E,
|
|
1051
|
-
value:
|
|
1051
|
+
value: w,
|
|
1052
1052
|
account: this.config.ethWallet.account.address
|
|
1053
1053
|
});
|
|
1054
|
-
} catch (
|
|
1055
|
-
H(
|
|
1054
|
+
} catch (h) {
|
|
1055
|
+
H(h);
|
|
1056
1056
|
}
|
|
1057
1057
|
let P;
|
|
1058
1058
|
try {
|
|
1059
1059
|
P = await this.config.ethWallet.sendTransaction({
|
|
1060
1060
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1061
1061
|
data: E,
|
|
1062
|
-
value:
|
|
1062
|
+
value: w,
|
|
1063
1063
|
account: this.config.ethWallet.account,
|
|
1064
1064
|
chain: this.config.ethChain,
|
|
1065
1065
|
gas: p
|
|
1066
1066
|
});
|
|
1067
|
-
} catch (
|
|
1068
|
-
H(
|
|
1067
|
+
} catch (h) {
|
|
1068
|
+
H(h);
|
|
1069
1069
|
}
|
|
1070
|
-
const y = await
|
|
1070
|
+
const y = await xt({
|
|
1071
1071
|
publicClient: m,
|
|
1072
1072
|
walletAddress: this.config.ethWallet.account.address,
|
|
1073
1073
|
hash: P,
|
|
1074
|
-
timeout:
|
|
1074
|
+
timeout: At
|
|
1075
1075
|
});
|
|
1076
1076
|
return y.status === "reverted" && H(
|
|
1077
1077
|
new Error(
|
|
@@ -1089,7 +1089,7 @@ class An {
|
|
|
1089
1089
|
try {
|
|
1090
1090
|
s = await this.config.publicClient.readContract({
|
|
1091
1091
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
1092
|
-
abi:
|
|
1092
|
+
abi: I,
|
|
1093
1093
|
functionName: "getVaultProviderCommission",
|
|
1094
1094
|
args: [t]
|
|
1095
1095
|
});
|
|
@@ -1100,18 +1100,18 @@ class An {
|
|
|
1100
1100
|
);
|
|
1101
1101
|
}
|
|
1102
1102
|
if (e !== void 0) {
|
|
1103
|
-
if (s > e +
|
|
1103
|
+
if (s > e + W)
|
|
1104
1104
|
throw new Error(
|
|
1105
|
-
`Vault provider commission changed since quote: quoted ${e} bps, chain currently reports ${s} bps (allowed drift ${
|
|
1105
|
+
`Vault provider commission changed since quote: quoted ${e} bps, chain currently reports ${s} bps (allowed drift ${W} bps). Please refresh to see the new commission and try again.`
|
|
1106
1106
|
);
|
|
1107
1107
|
return Math.min(
|
|
1108
|
-
e +
|
|
1109
|
-
|
|
1108
|
+
e + W,
|
|
1109
|
+
rt
|
|
1110
1110
|
);
|
|
1111
1111
|
}
|
|
1112
1112
|
return Math.min(
|
|
1113
|
-
s +
|
|
1114
|
-
|
|
1113
|
+
s + W,
|
|
1114
|
+
rt
|
|
1115
1115
|
);
|
|
1116
1116
|
}
|
|
1117
1117
|
/**
|
|
@@ -1130,10 +1130,10 @@ class An {
|
|
|
1130
1130
|
async checkVaultExists(t) {
|
|
1131
1131
|
return (await this.config.publicClient.readContract({
|
|
1132
1132
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
1133
|
-
abi:
|
|
1133
|
+
abi: I,
|
|
1134
1134
|
functionName: "getBtcVaultBasicInfo",
|
|
1135
1135
|
args: [t]
|
|
1136
|
-
})).depositor !==
|
|
1136
|
+
})).depositor !== Jt;
|
|
1137
1137
|
}
|
|
1138
1138
|
/**
|
|
1139
1139
|
* Resolve the BTC scriptPubKey to register as the depositor's payout sink.
|
|
@@ -1157,12 +1157,12 @@ class An {
|
|
|
1157
1157
|
t,
|
|
1158
1158
|
this.config.btcNetwork
|
|
1159
1159
|
))
|
|
1160
|
-
throw T(t).length ===
|
|
1160
|
+
throw T(t).length === ce && un(e, this.config.btcNetwork) ? new Error(
|
|
1161
1161
|
`BTC payout address "${e}" is a P2WPKH (Native SegWit) address, but the connected wallet only exposes an x-only public key. P2WPKH validation requires a compressed key with known y-parity. Use a P2TR (Taproot) payout address instead.`
|
|
1162
1162
|
) : new Error(
|
|
1163
1163
|
`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.`
|
|
1164
1164
|
);
|
|
1165
|
-
const s =
|
|
1165
|
+
const s = Pt(this.config.btcNetwork);
|
|
1166
1166
|
try {
|
|
1167
1167
|
return `0x${Ct.address.toOutputScript(e, s).toString("hex")}`;
|
|
1168
1168
|
} catch {
|
|
@@ -1187,7 +1187,7 @@ class An {
|
|
|
1187
1187
|
"bip322-simple"
|
|
1188
1188
|
);
|
|
1189
1189
|
return {
|
|
1190
|
-
btcPopSignature:
|
|
1190
|
+
btcPopSignature: cn(r),
|
|
1191
1191
|
depositorEthAddress: t,
|
|
1192
1192
|
depositorBtcPubkey: e
|
|
1193
1193
|
};
|
|
@@ -1225,13 +1225,67 @@ class An {
|
|
|
1225
1225
|
return this.config.vaultContracts.btcVaultRegistry;
|
|
1226
1226
|
}
|
|
1227
1227
|
}
|
|
1228
|
+
const dn = 80, gn = 250, fn = 300, pn = 22, Gt = "ab";
|
|
1229
|
+
function mn(n, t) {
|
|
1230
|
+
const e = Gt.repeat(fn), s = T(n).toLowerCase(), o = t.toString(16).padStart(8, "0"), r = `${s}${o}`, i = e.slice(r.length);
|
|
1231
|
+
return `0x${r}${i}`;
|
|
1232
|
+
}
|
|
1233
|
+
function bn(n, t) {
|
|
1234
|
+
const e = (s) => `0x${Gt.repeat(s)}`;
|
|
1235
|
+
return {
|
|
1236
|
+
depositorBtcPubKey: e(32),
|
|
1237
|
+
btcPopSignature: e(dn),
|
|
1238
|
+
unsignedPrePeginTx: e(gn),
|
|
1239
|
+
depositorSignedPeginTx: mn(
|
|
1240
|
+
n,
|
|
1241
|
+
t
|
|
1242
|
+
),
|
|
1243
|
+
hashlock: e(32),
|
|
1244
|
+
htlcVout: t,
|
|
1245
|
+
referralCode: Dt,
|
|
1246
|
+
depositorPayoutBtcAddress: e(pn),
|
|
1247
|
+
depositorWotsPkHash: e(32)
|
|
1248
|
+
};
|
|
1249
|
+
}
|
|
1250
|
+
async function Un(n) {
|
|
1251
|
+
const { publicClient: t, btcVaultRegistry: e, depositorEthAddress: s, vaultProvider: o, batchSize: r } = n;
|
|
1252
|
+
if (r <= 0)
|
|
1253
|
+
throw new Error(
|
|
1254
|
+
`estimateSubmitPeginRequestBatchGas requires batchSize >= 1 (received ${r})`
|
|
1255
|
+
);
|
|
1256
|
+
const a = await t.readContract({
|
|
1257
|
+
address: e,
|
|
1258
|
+
abi: I,
|
|
1259
|
+
functionName: "getPegInFee",
|
|
1260
|
+
args: [o]
|
|
1261
|
+
}) * BigInt(r), c = Array.from(
|
|
1262
|
+
{ length: r },
|
|
1263
|
+
(l, m) => bn(s, m)
|
|
1264
|
+
), u = tt({
|
|
1265
|
+
abi: I,
|
|
1266
|
+
functionName: "submitPeginRequestBatch",
|
|
1267
|
+
args: [
|
|
1268
|
+
s,
|
|
1269
|
+
o,
|
|
1270
|
+
rt,
|
|
1271
|
+
c
|
|
1272
|
+
]
|
|
1273
|
+
});
|
|
1274
|
+
return t.estimateGas({
|
|
1275
|
+
to: e,
|
|
1276
|
+
data: u,
|
|
1277
|
+
value: a,
|
|
1278
|
+
account: s
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1228
1281
|
export {
|
|
1229
|
-
|
|
1230
|
-
|
|
1282
|
+
Rn as P,
|
|
1283
|
+
Se as V,
|
|
1231
1284
|
ve as a,
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1285
|
+
Be as b,
|
|
1286
|
+
nn as c,
|
|
1287
|
+
en as d,
|
|
1288
|
+
Un as e,
|
|
1289
|
+
Ie as f
|
|
1236
1290
|
};
|
|
1237
|
-
//# sourceMappingURL=PeginManager-
|
|
1291
|
+
//# sourceMappingURL=PeginManager-DXrfY4d6.js.map
|