@babylonlabs-io/ts-sdk 0.55.0 → 0.55.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-D22MLWfM.js → PeginManager-CW03-M3T.js} +489 -555
- package/dist/PeginManager-CW03-M3T.js.map +1 -0
- package/dist/PeginManager-C_akOB1E.cjs +2 -0
- package/dist/PeginManager-C_akOB1E.cjs.map +1 -0
- package/dist/deriveVaultRoot-B_gEOTD6.js +72 -0
- package/dist/deriveVaultRoot-B_gEOTD6.js.map +1 -0
- package/dist/deriveVaultRoot-CebLadyJ.cjs +2 -0
- package/dist/deriveVaultRoot-CebLadyJ.cjs.map +1 -0
- package/dist/errors-B-H0seUG.js +8 -0
- package/dist/errors-B-H0seUG.js.map +1 -0
- package/dist/errors-Bfjxg_iJ.cjs +2 -0
- package/dist/errors-Bfjxg_iJ.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +145 -143
- package/dist/index.js.map +1 -1
- package/dist/parseFundingOutpoints-C_-PT9BT.cjs +2 -0
- package/dist/parseFundingOutpoints-C_-PT9BT.cjs.map +1 -0
- package/dist/parseFundingOutpoints-GSM-IaaK.js +17 -0
- package/dist/parseFundingOutpoints-GSM-IaaK.js.map +1 -0
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +143 -141
- package/dist/tbv/core/index.js.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/vault-secrets/index.cjs +2 -0
- package/dist/tbv/core/vault-secrets/index.cjs.map +1 -0
- package/dist/tbv/core/vault-secrets/index.js +14 -0
- package/dist/tbv/core/vault-secrets/index.js.map +1 -0
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +143 -141
- package/dist/tbv/index.js.map +1 -1
- package/dist/tbv/integrations/aave/clients/abis/AaveAdapterPositionProxy.abi.json.d.ts +16 -0
- package/dist/tbv/integrations/aave/clients/abis/AaveIntegrationAdapter.abi.json.d.ts +2 -2
- package/dist/tbv/integrations/aave/clients/index.d.ts +1 -0
- package/dist/tbv/integrations/aave/clients/index.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/clients/positionProxy.d.ts +8 -0
- package/dist/tbv/integrations/aave/clients/positionProxy.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/clients/spoke.d.ts +11 -10
- package/dist/tbv/integrations/aave/clients/spoke.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/clients/transaction.d.ts +6 -1
- package/dist/tbv/integrations/aave/clients/transaction.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/constants.d.ts +6 -14
- package/dist/tbv/integrations/aave/constants.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/index.cjs +1 -1
- package/dist/tbv/integrations/aave/index.cjs.map +1 -1
- package/dist/tbv/integrations/aave/index.d.ts +2 -2
- package/dist/tbv/integrations/aave/index.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/index.js +119 -85
- package/dist/tbv/integrations/aave/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/PeginManager-D22MLWfM.js.map +0 -1
- package/dist/PeginManager-vUUfZCzj.cjs +0 -2
- package/dist/PeginManager-vUUfZCzj.cjs.map +0 -1
- package/dist/errors-9AkghWyk.js +0 -22
- package/dist/errors-9AkghWyk.js.map +0 -1
- package/dist/errors-Bu0H-dZD.cjs +0 -2
- package/dist/errors-Bu0H-dZD.cjs.map +0 -1
|
@@ -1,100 +1,38 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var x = (
|
|
4
|
-
import {
|
|
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 Nt = (s, e, t) => e in s ? Mt(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
|
|
3
|
+
var x = (s, e, t) => Nt(s, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { c as kt, H as Wt, r as U, a as F, b as st, u as Ft, d as nt, e as ot, f as rt, g as Lt, s as Tt } from "./sha2-BYVxyZzX.js";
|
|
5
|
+
import * as Et from "bitcoinjs-lib";
|
|
6
|
+
import { Transaction as Xt, Psbt as it } from "bitcoinjs-lib";
|
|
7
|
+
import { Buffer as Y } from "buffer";
|
|
8
|
+
import { isAddressEqual as at, encodeFunctionData as j, zeroAddress as Kt } from "viem";
|
|
9
|
+
import { B as I } from "./BTCVaultRegistry.abi-Chs4AFBj.js";
|
|
10
10
|
import { h as H } from "./errors-Blc-JWnI.js";
|
|
11
|
-
import { expandWotsSeed as
|
|
12
|
-
import { a as
|
|
13
|
-
import { b as
|
|
14
|
-
import { u as
|
|
15
|
-
import { c as
|
|
16
|
-
import { M as
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import { p as
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
11
|
+
import { expandWotsSeed as Dt, expandHashlockSecret as Gt, expandAuthAnchor as qt, deriveVaultId as ct } from "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
12
|
+
import { a as lt, b as zt, d as ut, f as Yt } from "./verifyScriptPathSchnorrSignature-DA4Z4yZ3.js";
|
|
13
|
+
import { b as jt, e as Qt, f as Zt } from "./peginInput-BKD_b3gq.js";
|
|
14
|
+
import { u as Q, e as v, p as Jt, i as ht, h as dt, s as E, j as ft, X as te } from "./bitcoin-B5aNKtsk.js";
|
|
15
|
+
import { c as ee } from "./signing-DaLvGwQe.js";
|
|
16
|
+
import { M as gt } from "./validation-CxqROCno.js";
|
|
17
|
+
import { d as se } from "./deriveVaultRoot-B_gEOTD6.js";
|
|
18
|
+
import { c as ne, a as oe, s as re } from "./PayoutManager-BJmPnyRP.js";
|
|
19
|
+
import { s as ie, f as K, i as ae, w as pt } from "./waitForTransactionReceiptSmartAware-lobLm0q0.js";
|
|
20
|
+
import { p as ce, f as le } from "./fundPeginTransaction-B2wyjqp0.js";
|
|
21
|
+
import { p as ue, V as he, i as de } from "./mempoolApi-CB7bHuwi.js";
|
|
22
|
+
const V = /* @__PURE__ */ BigInt(2 ** 32 - 1), mt = /* @__PURE__ */ BigInt(32);
|
|
23
|
+
function fe(s, e = !1) {
|
|
24
|
+
return e ? { h: Number(s & V), l: Number(s >> mt & V) } : { h: Number(s >> mt & V) | 0, l: Number(s & V) | 0 };
|
|
24
25
|
}
|
|
25
|
-
function
|
|
26
|
-
const
|
|
27
|
-
let
|
|
28
|
-
for (let r = 0; r <
|
|
29
|
-
const { h: i, l: a } =
|
|
30
|
-
[
|
|
26
|
+
function ge(s, e = !1) {
|
|
27
|
+
const t = s.length;
|
|
28
|
+
let n = new Uint32Array(t), o = new Uint32Array(t);
|
|
29
|
+
for (let r = 0; r < t; r++) {
|
|
30
|
+
const { h: i, l: a } = fe(s[r], e);
|
|
31
|
+
[n[r], o[r]] = [i, a];
|
|
31
32
|
}
|
|
32
|
-
return [
|
|
33
|
+
return [n, o];
|
|
33
34
|
}
|
|
34
|
-
const
|
|
35
|
-
function st(n, t, e) {
|
|
36
|
-
n[t] = e >>> 24 & 255, n[t + 1] = e >>> 16 & 255, n[t + 2] = e >>> 8 & 255, n[t + 3] = e & 255;
|
|
37
|
-
}
|
|
38
|
-
function Se(n) {
|
|
39
|
-
if (n.txid.length !== z)
|
|
40
|
-
throw new Error(
|
|
41
|
-
`outpoint.txid must be exactly ${z} bytes, got ${n.txid.length}`
|
|
42
|
-
);
|
|
43
|
-
if (!Number.isInteger(n.vout) || n.vout < 0 || n.vout > 4294967295)
|
|
44
|
-
throw new Error(`outpoint.vout must be a u32, got ${n.vout}`);
|
|
45
|
-
const t = new Uint8Array(nt);
|
|
46
|
-
return t.set(n.txid, 0), st(t, z, n.vout), t;
|
|
47
|
-
}
|
|
48
|
-
function Et(n, t) {
|
|
49
|
-
const e = Math.min(n.length, t.length);
|
|
50
|
-
for (let s = 0; s < e; s++)
|
|
51
|
-
if (n[s] !== t[s]) return n[s] - t[s];
|
|
52
|
-
return n.length - t.length;
|
|
53
|
-
}
|
|
54
|
-
function Ie(n) {
|
|
55
|
-
if (n.length === 0)
|
|
56
|
-
throw new Error(
|
|
57
|
-
"buildFundingOutpointsCommitment: outpoints must be non-empty"
|
|
58
|
-
);
|
|
59
|
-
const t = n.map(Se);
|
|
60
|
-
t.sort(Et);
|
|
61
|
-
for (let s = 1; s < t.length; s++)
|
|
62
|
-
if (Et(t[s - 1], t[s]) === 0)
|
|
63
|
-
throw new Error(
|
|
64
|
-
"buildFundingOutpointsCommitment: duplicate outpoint detected"
|
|
65
|
-
);
|
|
66
|
-
const e = new Uint8Array(t.length * nt);
|
|
67
|
-
for (let s = 0; s < t.length; s++)
|
|
68
|
-
e.set(t[s], s * nt);
|
|
69
|
-
return it(e);
|
|
70
|
-
}
|
|
71
|
-
function Ae(n) {
|
|
72
|
-
if (n.depositorBtcPubkey.length !== U)
|
|
73
|
-
throw new Error(
|
|
74
|
-
`vaultContext: depositorBtcPubkey must be exactly ${U} bytes, got ${n.depositorBtcPubkey.length}`
|
|
75
|
-
);
|
|
76
|
-
const t = Ie(n.fundingOutpoints), e = new Uint8Array(ve);
|
|
77
|
-
let s = 0;
|
|
78
|
-
return st(e, s, U), s += K, e.set(n.depositorBtcPubkey, s), s += U, st(e, s, Ht), s += K, e.set(t, s), e;
|
|
79
|
-
}
|
|
80
|
-
const Ce = "babylon-btc-vault", Ot = 32, Tt = Ot * 2, He = /^[0-9a-f]+$/;
|
|
81
|
-
async function Oe(n, t) {
|
|
82
|
-
const e = Ae(t), s = X(e), o = await n.deriveContextHash(Ce, s);
|
|
83
|
-
if (typeof o != "string")
|
|
84
|
-
throw new Error(
|
|
85
|
-
`deriveVaultRoot: wallet must return a string, got ${typeof o}`
|
|
86
|
-
);
|
|
87
|
-
if (o.length !== Tt)
|
|
88
|
-
throw new Error(
|
|
89
|
-
`deriveVaultRoot: wallet must return a ${Tt}-character hex string (${Ot} bytes), got length ${o.length}`
|
|
90
|
-
);
|
|
91
|
-
if (!He.test(o))
|
|
92
|
-
throw new Error(
|
|
93
|
-
"deriveVaultRoot: wallet must return lowercase hex per derive-context-hash.md §2.1; got value with non-lowercase or non-hex characters"
|
|
94
|
-
);
|
|
95
|
-
return et(o);
|
|
96
|
-
}
|
|
97
|
-
const Re = /* @__PURE__ */ Uint8Array.from([
|
|
35
|
+
const pe = (s, e, t) => s << t | e >>> 32 - t, me = (s, e, t) => e << t | s >>> 32 - t, Pe = (s, e, t) => e << t - 32 | s >>> 64 - t, be = (s, e, t) => s << t - 32 | e >>> 64 - t, we = /* @__PURE__ */ Uint8Array.from([
|
|
98
36
|
7,
|
|
99
37
|
4,
|
|
100
38
|
13,
|
|
@@ -111,36 +49,36 @@ const Re = /* @__PURE__ */ Uint8Array.from([
|
|
|
111
49
|
14,
|
|
112
50
|
11,
|
|
113
51
|
8
|
|
114
|
-
]),
|
|
115
|
-
const
|
|
116
|
-
for (let
|
|
117
|
-
for (let o of
|
|
118
|
-
o.push(o[
|
|
119
|
-
return
|
|
120
|
-
})(),
|
|
52
|
+
]), Bt = Uint8Array.from(new Array(16).fill(0).map((s, e) => e)), ye = Bt.map((s) => (9 * s + 5) % 16), _t = /* @__PURE__ */ (() => {
|
|
53
|
+
const t = [[Bt], [ye]];
|
|
54
|
+
for (let n = 0; n < 4; n++)
|
|
55
|
+
for (let o of t)
|
|
56
|
+
o.push(o[n].map((r) => we[r]));
|
|
57
|
+
return t;
|
|
58
|
+
})(), vt = _t[0], St = _t[1], At = /* @__PURE__ */ [
|
|
121
59
|
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
|
|
122
60
|
[12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
|
|
123
61
|
[13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
|
|
124
62
|
[14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
|
|
125
63
|
[15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5]
|
|
126
|
-
].map((
|
|
64
|
+
].map((s) => Uint8Array.from(s)), xe = /* @__PURE__ */ vt.map((s, e) => s.map((t) => At[e][t])), ke = /* @__PURE__ */ St.map((s, e) => s.map((t) => At[e][t])), Te = /* @__PURE__ */ Uint32Array.from([
|
|
127
65
|
0,
|
|
128
66
|
1518500249,
|
|
129
67
|
1859775393,
|
|
130
68
|
2400959708,
|
|
131
69
|
2840853838
|
|
132
|
-
]),
|
|
70
|
+
]), Ee = /* @__PURE__ */ Uint32Array.from([
|
|
133
71
|
1352829926,
|
|
134
72
|
1548603684,
|
|
135
73
|
1836072691,
|
|
136
74
|
2053994217,
|
|
137
75
|
0
|
|
138
76
|
]);
|
|
139
|
-
function
|
|
140
|
-
return
|
|
77
|
+
function Pt(s, e, t, n) {
|
|
78
|
+
return s === 0 ? e ^ t ^ n : s === 1 ? e & t | ~e & n : s === 2 ? (e | ~t) ^ n : s === 3 ? e & n | t & ~n : e ^ (t | ~n);
|
|
141
79
|
}
|
|
142
|
-
const
|
|
143
|
-
class
|
|
80
|
+
const M = /* @__PURE__ */ new Uint32Array(16);
|
|
81
|
+
class Be extends Wt {
|
|
144
82
|
constructor() {
|
|
145
83
|
super(64, 20, 8, !0);
|
|
146
84
|
x(this, "h0", 1732584193);
|
|
@@ -150,73 +88,73 @@ class Fe extends Yt {
|
|
|
150
88
|
x(this, "h4", -1009589776);
|
|
151
89
|
}
|
|
152
90
|
get() {
|
|
153
|
-
const { h0:
|
|
154
|
-
return [
|
|
91
|
+
const { h0: t, h1: n, h2: o, h3: r, h4: i } = this;
|
|
92
|
+
return [t, n, o, r, i];
|
|
155
93
|
}
|
|
156
|
-
set(
|
|
157
|
-
this.h0 =
|
|
94
|
+
set(t, n, o, r, i) {
|
|
95
|
+
this.h0 = t | 0, this.h1 = n | 0, this.h2 = o | 0, this.h3 = r | 0, this.h4 = i | 0;
|
|
158
96
|
}
|
|
159
|
-
process(
|
|
160
|
-
for (let
|
|
161
|
-
|
|
162
|
-
let o = this.h0 | 0, r = o, i = this.h1 | 0, a = i, c = this.h2 | 0, h = c, l = this.h3 | 0, m = l,
|
|
163
|
-
for (let
|
|
164
|
-
const
|
|
97
|
+
process(t, n) {
|
|
98
|
+
for (let f = 0; f < 16; f++, n += 4)
|
|
99
|
+
M[f] = t.getUint32(n, !0);
|
|
100
|
+
let o = this.h0 | 0, r = o, i = this.h1 | 0, a = i, c = this.h2 | 0, h = c, l = this.h3 | 0, m = l, P = this.h4 | 0, b = P;
|
|
101
|
+
for (let f = 0; f < 5; f++) {
|
|
102
|
+
const g = 4 - f, k = Te[f], S = Ee[f], T = vt[f], p = St[f], w = xe[f], y = ke[f];
|
|
165
103
|
for (let d = 0; d < 16; d++) {
|
|
166
|
-
const u =
|
|
167
|
-
o =
|
|
104
|
+
const u = U(o + Pt(f, i, c, l) + M[T[d]] + k, w[d]) + P | 0;
|
|
105
|
+
o = P, P = l, l = U(c, 10) | 0, c = i, i = u;
|
|
168
106
|
}
|
|
169
107
|
for (let d = 0; d < 16; d++) {
|
|
170
|
-
const u =
|
|
171
|
-
r =
|
|
108
|
+
const u = U(r + Pt(g, a, h, m) + M[p[d]] + S, y[d]) + b | 0;
|
|
109
|
+
r = b, b = m, m = U(h, 10) | 0, h = a, a = u;
|
|
172
110
|
}
|
|
173
111
|
}
|
|
174
|
-
this.set(this.h1 + c + m | 0, this.h2 + l +
|
|
112
|
+
this.set(this.h1 + c + m | 0, this.h2 + l + b | 0, this.h3 + P + r | 0, this.h4 + o + a | 0, this.h0 + i + h | 0);
|
|
175
113
|
}
|
|
176
114
|
roundClean() {
|
|
177
|
-
|
|
115
|
+
F(M);
|
|
178
116
|
}
|
|
179
117
|
destroy() {
|
|
180
|
-
this.destroyed = !0,
|
|
118
|
+
this.destroyed = !0, F(this.buffer), this.set(0, 0, 0, 0, 0);
|
|
181
119
|
}
|
|
182
120
|
}
|
|
183
|
-
const
|
|
184
|
-
for (let
|
|
185
|
-
[
|
|
186
|
-
let o =
|
|
121
|
+
const _e = /* @__PURE__ */ kt(() => new Be()), ve = BigInt(0), O = BigInt(1), Se = BigInt(2), Ae = BigInt(7), Ie = BigInt(256), Ce = BigInt(113), It = [], Ct = [], Ht = [];
|
|
122
|
+
for (let s = 0, e = O, t = 1, n = 0; s < 24; s++) {
|
|
123
|
+
[t, n] = [n, (2 * t + 3 * n) % 5], It.push(2 * (5 * n + t)), Ct.push((s + 1) * (s + 2) / 2 % 64);
|
|
124
|
+
let o = ve;
|
|
187
125
|
for (let r = 0; r < 7; r++)
|
|
188
|
-
|
|
189
|
-
|
|
126
|
+
e = (e << O ^ (e >> Ae) * Ce) % Ie, e & Se && (o ^= O << (O << BigInt(r)) - O);
|
|
127
|
+
Ht.push(o);
|
|
190
128
|
}
|
|
191
|
-
const
|
|
192
|
-
function
|
|
193
|
-
const
|
|
194
|
-
for (let
|
|
129
|
+
const Rt = ge(Ht, !0), He = Rt[0], Re = Rt[1], bt = (s, e, t) => t > 32 ? Pe(s, e, t) : pe(s, e, t), wt = (s, e, t) => t > 32 ? be(s, e, t) : me(s, e, t);
|
|
130
|
+
function Oe(s, e = 24) {
|
|
131
|
+
const t = new Uint32Array(10);
|
|
132
|
+
for (let n = 24 - e; n < 24; n++) {
|
|
195
133
|
for (let i = 0; i < 10; i++)
|
|
196
|
-
|
|
134
|
+
t[i] = s[i] ^ s[i + 10] ^ s[i + 20] ^ s[i + 30] ^ s[i + 40];
|
|
197
135
|
for (let i = 0; i < 10; i += 2) {
|
|
198
|
-
const a = (i + 8) % 10, c = (i + 2) % 10, h =
|
|
199
|
-
for (let
|
|
200
|
-
|
|
136
|
+
const a = (i + 8) % 10, c = (i + 2) % 10, h = t[c], l = t[c + 1], m = bt(h, l, 1) ^ t[a], P = wt(h, l, 1) ^ t[a + 1];
|
|
137
|
+
for (let b = 0; b < 50; b += 10)
|
|
138
|
+
s[i + b] ^= m, s[i + b + 1] ^= P;
|
|
201
139
|
}
|
|
202
|
-
let o =
|
|
140
|
+
let o = s[2], r = s[3];
|
|
203
141
|
for (let i = 0; i < 24; i++) {
|
|
204
|
-
const a =
|
|
205
|
-
o =
|
|
142
|
+
const a = Ct[i], c = bt(o, r, a), h = wt(o, r, a), l = It[i];
|
|
143
|
+
o = s[l], r = s[l + 1], s[l] = c, s[l + 1] = h;
|
|
206
144
|
}
|
|
207
145
|
for (let i = 0; i < 50; i += 10) {
|
|
208
146
|
for (let a = 0; a < 10; a++)
|
|
209
|
-
|
|
147
|
+
t[a] = s[i + a];
|
|
210
148
|
for (let a = 0; a < 10; a++)
|
|
211
|
-
|
|
149
|
+
s[i + a] ^= ~t[(a + 2) % 10] & t[(a + 4) % 10];
|
|
212
150
|
}
|
|
213
|
-
|
|
151
|
+
s[0] ^= He[n], s[1] ^= Re[n];
|
|
214
152
|
}
|
|
215
|
-
|
|
153
|
+
F(t);
|
|
216
154
|
}
|
|
217
|
-
class
|
|
155
|
+
class tt {
|
|
218
156
|
// NOTE: we accept arguments in bytes instead of bits here.
|
|
219
|
-
constructor(
|
|
157
|
+
constructor(e, t, n, o = !1, r = 24) {
|
|
220
158
|
x(this, "state");
|
|
221
159
|
x(this, "pos", 0);
|
|
222
160
|
x(this, "posOut", 0);
|
|
@@ -228,24 +166,24 @@ class at {
|
|
|
228
166
|
x(this, "outputLen");
|
|
229
167
|
x(this, "enableXOF", !1);
|
|
230
168
|
x(this, "rounds");
|
|
231
|
-
if (this.blockLen =
|
|
169
|
+
if (this.blockLen = e, this.suffix = t, this.outputLen = n, this.enableXOF = o, this.rounds = r, st(n, "outputLen"), !(0 < e && e < 200))
|
|
232
170
|
throw new Error("only keccak-f1600 function is supported");
|
|
233
|
-
this.state = new Uint8Array(200), this.state32 =
|
|
171
|
+
this.state = new Uint8Array(200), this.state32 = Ft(this.state);
|
|
234
172
|
}
|
|
235
173
|
clone() {
|
|
236
174
|
return this._cloneInto();
|
|
237
175
|
}
|
|
238
176
|
keccak() {
|
|
239
|
-
|
|
177
|
+
nt(this.state32), Oe(this.state32, this.rounds), nt(this.state32), this.posOut = 0, this.pos = 0;
|
|
240
178
|
}
|
|
241
|
-
update(
|
|
242
|
-
|
|
243
|
-
const { blockLen:
|
|
179
|
+
update(e) {
|
|
180
|
+
ot(this), rt(e);
|
|
181
|
+
const { blockLen: t, state: n } = this, o = e.length;
|
|
244
182
|
for (let r = 0; r < o; ) {
|
|
245
|
-
const i = Math.min(
|
|
183
|
+
const i = Math.min(t - this.pos, o - r);
|
|
246
184
|
for (let a = 0; a < i; a++)
|
|
247
|
-
|
|
248
|
-
this.pos ===
|
|
185
|
+
n[this.pos++] ^= e[r++];
|
|
186
|
+
this.pos === t && this.keccak();
|
|
249
187
|
}
|
|
250
188
|
return this;
|
|
251
189
|
}
|
|
@@ -253,273 +191,273 @@ class at {
|
|
|
253
191
|
if (this.finished)
|
|
254
192
|
return;
|
|
255
193
|
this.finished = !0;
|
|
256
|
-
const { state:
|
|
257
|
-
|
|
194
|
+
const { state: e, suffix: t, pos: n, blockLen: o } = this;
|
|
195
|
+
e[n] ^= t, (t & 128) !== 0 && n === o - 1 && this.keccak(), e[o - 1] ^= 128, this.keccak();
|
|
258
196
|
}
|
|
259
|
-
writeInto(
|
|
260
|
-
|
|
261
|
-
const
|
|
262
|
-
for (let o = 0, r =
|
|
263
|
-
this.posOut >=
|
|
264
|
-
const i = Math.min(
|
|
265
|
-
|
|
197
|
+
writeInto(e) {
|
|
198
|
+
ot(this, !1), rt(e), this.finish();
|
|
199
|
+
const t = this.state, { blockLen: n } = this;
|
|
200
|
+
for (let o = 0, r = e.length; o < r; ) {
|
|
201
|
+
this.posOut >= n && this.keccak();
|
|
202
|
+
const i = Math.min(n - this.posOut, r - o);
|
|
203
|
+
e.set(t.subarray(this.posOut, this.posOut + i), o), this.posOut += i, o += i;
|
|
266
204
|
}
|
|
267
|
-
return
|
|
205
|
+
return e;
|
|
268
206
|
}
|
|
269
|
-
xofInto(
|
|
207
|
+
xofInto(e) {
|
|
270
208
|
if (!this.enableXOF)
|
|
271
209
|
throw new Error("XOF is not possible for this instance");
|
|
272
|
-
return this.writeInto(
|
|
210
|
+
return this.writeInto(e);
|
|
273
211
|
}
|
|
274
|
-
xof(
|
|
275
|
-
return
|
|
212
|
+
xof(e) {
|
|
213
|
+
return st(e), this.xofInto(new Uint8Array(e));
|
|
276
214
|
}
|
|
277
|
-
digestInto(
|
|
278
|
-
if (
|
|
215
|
+
digestInto(e) {
|
|
216
|
+
if (Lt(e, this), this.finished)
|
|
279
217
|
throw new Error("digest() was already called");
|
|
280
|
-
return this.writeInto(
|
|
218
|
+
return this.writeInto(e), this.destroy(), e;
|
|
281
219
|
}
|
|
282
220
|
digest() {
|
|
283
221
|
return this.digestInto(new Uint8Array(this.outputLen));
|
|
284
222
|
}
|
|
285
223
|
destroy() {
|
|
286
|
-
this.destroyed = !0,
|
|
224
|
+
this.destroyed = !0, F(this.state);
|
|
287
225
|
}
|
|
288
|
-
_cloneInto(
|
|
289
|
-
const { blockLen:
|
|
290
|
-
return
|
|
226
|
+
_cloneInto(e) {
|
|
227
|
+
const { blockLen: t, suffix: n, outputLen: o, rounds: r, enableXOF: i } = this;
|
|
228
|
+
return e || (e = new tt(t, n, o, i, r)), e.state32.set(this.state32), e.pos = this.pos, e.posOut = this.posOut, e.finished = this.finished, e.rounds = r, e.suffix = n, e.outputLen = o, e.enableXOF = i, e.destroyed = this.destroyed, e;
|
|
291
229
|
}
|
|
292
230
|
}
|
|
293
|
-
const
|
|
294
|
-
function
|
|
295
|
-
return
|
|
231
|
+
const $e = (s, e, t, n = {}) => kt(() => new tt(e, s, t), n), Ue = /* @__PURE__ */ $e(1, 136, 32), yt = 64, B = 20, Z = 4, Ot = 2, Ve = 0, Me = 1, N = [64, 64], Ne = (s) => Array.from(s).map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
232
|
+
function et(s) {
|
|
233
|
+
return _e(Tt(s));
|
|
296
234
|
}
|
|
297
|
-
function
|
|
298
|
-
return (1 <<
|
|
235
|
+
function $t(s) {
|
|
236
|
+
return (1 << s) - 1;
|
|
299
237
|
}
|
|
300
|
-
function
|
|
301
|
-
let
|
|
302
|
-
for (;
|
|
303
|
-
return Math.max(
|
|
238
|
+
function We(s) {
|
|
239
|
+
let e = 1;
|
|
240
|
+
for (; e * e < s + 1; ) e++;
|
|
241
|
+
return Math.max(e, 2);
|
|
304
242
|
}
|
|
305
|
-
function
|
|
306
|
-
const
|
|
307
|
-
return { d:
|
|
243
|
+
function Fe(s) {
|
|
244
|
+
const e = Z, t = s * $t(e);
|
|
245
|
+
return { d: e, n: s, checksum_radix: We(t) };
|
|
308
246
|
}
|
|
309
|
-
function
|
|
310
|
-
const
|
|
311
|
-
let
|
|
312
|
-
for (;
|
|
313
|
-
|
|
314
|
-
const o = new Uint8Array(
|
|
315
|
-
o.set(
|
|
316
|
-
for (let r = 0; r <
|
|
317
|
-
o[
|
|
318
|
-
return
|
|
247
|
+
function D(s, e) {
|
|
248
|
+
const t = [];
|
|
249
|
+
let n = e;
|
|
250
|
+
for (; n > 0; )
|
|
251
|
+
t.push(n & 255), n >>>= 8;
|
|
252
|
+
const o = new Uint8Array(s.length + t.length);
|
|
253
|
+
o.set(s);
|
|
254
|
+
for (let r = 0; r < t.length; r++)
|
|
255
|
+
o[s.length + r] = t[r];
|
|
256
|
+
return et(o);
|
|
319
257
|
}
|
|
320
|
-
function
|
|
321
|
-
let
|
|
322
|
-
for (let
|
|
323
|
-
|
|
324
|
-
return
|
|
258
|
+
function G(s, e) {
|
|
259
|
+
let t = s;
|
|
260
|
+
for (let n = 0; n < e; n++)
|
|
261
|
+
t = et(t);
|
|
262
|
+
return t;
|
|
325
263
|
}
|
|
326
|
-
function
|
|
327
|
-
const
|
|
328
|
-
for (let l = 0; l <
|
|
329
|
-
const m =
|
|
330
|
-
r.push(Array.from(
|
|
264
|
+
function Le(s, e) {
|
|
265
|
+
const t = $t(e.d), n = e.checksum_radix - 1, o = Math.floor(e.n * t / e.checksum_radix), r = [];
|
|
266
|
+
for (let l = 0; l < e.n; l++) {
|
|
267
|
+
const m = D(s, l + Ot), P = G(m, t);
|
|
268
|
+
r.push(Array.from(P));
|
|
331
269
|
}
|
|
332
|
-
const i =
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
), a =
|
|
270
|
+
const i = D(
|
|
271
|
+
s,
|
|
272
|
+
Ve
|
|
273
|
+
), a = G(
|
|
336
274
|
i,
|
|
337
|
-
|
|
338
|
-
), c =
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
), h =
|
|
275
|
+
n
|
|
276
|
+
), c = D(
|
|
277
|
+
s,
|
|
278
|
+
Me
|
|
279
|
+
), h = G(
|
|
342
280
|
c,
|
|
343
281
|
o
|
|
344
282
|
);
|
|
345
283
|
return {
|
|
346
|
-
config:
|
|
284
|
+
config: e,
|
|
347
285
|
message_terminals: r,
|
|
348
286
|
checksum_major_terminal: Array.from(h),
|
|
349
287
|
checksum_minor_terminal: Array.from(a)
|
|
350
288
|
};
|
|
351
289
|
}
|
|
352
|
-
async function
|
|
290
|
+
async function Xe(s) {
|
|
353
291
|
try {
|
|
354
|
-
if (
|
|
292
|
+
if (s.length !== yt)
|
|
355
293
|
throw new Error(
|
|
356
|
-
`WOTS seed must be exactly ${
|
|
294
|
+
`WOTS seed must be exactly ${yt} bytes, got ${s.length}`
|
|
357
295
|
);
|
|
358
|
-
const
|
|
359
|
-
for (let
|
|
360
|
-
const
|
|
361
|
-
r.set(
|
|
362
|
-
const i =
|
|
296
|
+
const e = [];
|
|
297
|
+
for (let t = 0; t < N.length; t++) {
|
|
298
|
+
const n = N[t], o = Fe(n), r = new Uint8Array(s.length + 1);
|
|
299
|
+
r.set(s), r[s.length] = t;
|
|
300
|
+
const i = et(r);
|
|
363
301
|
try {
|
|
364
|
-
const a =
|
|
365
|
-
if (a.config.d !==
|
|
302
|
+
const a = Le(i, o);
|
|
303
|
+
if (a.config.d !== Z)
|
|
366
304
|
throw new Error(
|
|
367
|
-
`Block ${
|
|
305
|
+
`Block ${t}: expected d=${Z}, got d=${a.config.d}`
|
|
368
306
|
);
|
|
369
|
-
if (a.config.n !==
|
|
307
|
+
if (a.config.n !== n)
|
|
370
308
|
throw new Error(
|
|
371
|
-
`Block ${
|
|
309
|
+
`Block ${t}: expected n=${n}, got n=${a.config.n}`
|
|
372
310
|
);
|
|
373
|
-
if (a.message_terminals.length !==
|
|
311
|
+
if (a.message_terminals.length !== n)
|
|
374
312
|
throw new Error(
|
|
375
|
-
`Block ${
|
|
313
|
+
`Block ${t}: expected ${n} message terminals, got ${a.message_terminals.length}`
|
|
376
314
|
);
|
|
377
315
|
for (let c = 0; c < a.message_terminals.length; c++)
|
|
378
|
-
if (a.message_terminals[c].length !==
|
|
316
|
+
if (a.message_terminals[c].length !== B)
|
|
379
317
|
throw new Error(
|
|
380
|
-
`Block ${
|
|
318
|
+
`Block ${t} terminal ${c}: expected ${B} bytes, got ${a.message_terminals[c].length}`
|
|
381
319
|
);
|
|
382
|
-
if (a.checksum_minor_terminal.length !==
|
|
320
|
+
if (a.checksum_minor_terminal.length !== B)
|
|
383
321
|
throw new Error(
|
|
384
|
-
`Block ${
|
|
322
|
+
`Block ${t} checksum_minor: expected ${B} bytes`
|
|
385
323
|
);
|
|
386
|
-
if (a.checksum_major_terminal.length !==
|
|
324
|
+
if (a.checksum_major_terminal.length !== B)
|
|
387
325
|
throw new Error(
|
|
388
|
-
`Block ${
|
|
326
|
+
`Block ${t} checksum_major: expected ${B} bytes`
|
|
389
327
|
);
|
|
390
|
-
|
|
328
|
+
e.push(a);
|
|
391
329
|
} finally {
|
|
392
330
|
r.fill(0), i.fill(0);
|
|
393
331
|
}
|
|
394
332
|
}
|
|
395
|
-
if (
|
|
333
|
+
if (e.length !== N.length)
|
|
396
334
|
throw new Error(
|
|
397
|
-
`Expected ${
|
|
335
|
+
`Expected ${N.length} blocks, got ${e.length}`
|
|
398
336
|
);
|
|
399
|
-
return
|
|
337
|
+
return e;
|
|
400
338
|
} finally {
|
|
401
|
-
|
|
339
|
+
s.fill(0);
|
|
402
340
|
}
|
|
403
341
|
}
|
|
404
|
-
function
|
|
405
|
-
if (
|
|
342
|
+
function q(s, e, t) {
|
|
343
|
+
if (s.length !== B)
|
|
406
344
|
throw new Error(
|
|
407
|
-
`Block ${
|
|
345
|
+
`Block ${e} ${t}: expected ${B} bytes, got ${s.length}`
|
|
408
346
|
);
|
|
409
|
-
for (let
|
|
410
|
-
const o = n
|
|
347
|
+
for (let n = 0; n < s.length; n++) {
|
|
348
|
+
const o = s[n];
|
|
411
349
|
if (!Number.isInteger(o) || o < 0 || o > 255)
|
|
412
350
|
throw new Error(
|
|
413
|
-
`Block ${
|
|
351
|
+
`Block ${e} ${t}[${n}]: invalid byte value ${o}`
|
|
414
352
|
);
|
|
415
353
|
}
|
|
416
354
|
}
|
|
417
|
-
function
|
|
418
|
-
if (
|
|
355
|
+
function Ke(s) {
|
|
356
|
+
if (s.length === 0)
|
|
419
357
|
throw new Error("Public keys array must not be empty");
|
|
420
|
-
for (let r = 0; r <
|
|
421
|
-
const i =
|
|
422
|
-
|
|
358
|
+
for (let r = 0; r < s.length; r++) {
|
|
359
|
+
const i = s[r];
|
|
360
|
+
q(i.checksum_minor_terminal, r, "checksum_minor_terminal"), q(i.checksum_major_terminal, r, "checksum_major_terminal");
|
|
423
361
|
for (let a = 0; a < i.message_terminals.length; a++)
|
|
424
|
-
|
|
362
|
+
q(i.message_terminals[a], r, `message_terminal[${a}]`);
|
|
425
363
|
}
|
|
426
|
-
let
|
|
427
|
-
for (const r of
|
|
428
|
-
|
|
429
|
-
const
|
|
430
|
-
let
|
|
431
|
-
for (const r of
|
|
432
|
-
|
|
364
|
+
let e = 0;
|
|
365
|
+
for (const r of s)
|
|
366
|
+
e += Ot + r.message_terminals.length;
|
|
367
|
+
const t = new Uint8Array(e * B);
|
|
368
|
+
let n = 0;
|
|
369
|
+
for (const r of s) {
|
|
370
|
+
t.set(r.checksum_minor_terminal, n), n += B, t.set(r.checksum_major_terminal, n), n += B;
|
|
433
371
|
for (const i of r.message_terminals)
|
|
434
|
-
|
|
372
|
+
t.set(i, n), n += B;
|
|
435
373
|
}
|
|
436
|
-
const o =
|
|
437
|
-
return `0x${
|
|
374
|
+
const o = Ue(t);
|
|
375
|
+
return `0x${Ne(o)}`;
|
|
438
376
|
}
|
|
439
|
-
async function
|
|
440
|
-
const
|
|
377
|
+
async function De(s, e) {
|
|
378
|
+
const t = [], n = [], o = [], r = [];
|
|
441
379
|
try {
|
|
442
|
-
for (let i = 0; i <
|
|
443
|
-
const a = await
|
|
380
|
+
for (let i = 0; i < e; i++) {
|
|
381
|
+
const a = await Dt(s, i);
|
|
444
382
|
try {
|
|
445
|
-
const h = await
|
|
446
|
-
|
|
383
|
+
const h = await Xe(a);
|
|
384
|
+
t.push(h), n.push(Ke(h));
|
|
447
385
|
} finally {
|
|
448
386
|
a.fill(0);
|
|
449
387
|
}
|
|
450
|
-
const c = await
|
|
388
|
+
const c = await Gt(s, i);
|
|
451
389
|
try {
|
|
452
|
-
const h =
|
|
453
|
-
o.push(h), r.push(
|
|
390
|
+
const h = Q(c);
|
|
391
|
+
o.push(h), r.push(ne(v(h)).slice(2));
|
|
454
392
|
} finally {
|
|
455
393
|
c.fill(0);
|
|
456
394
|
}
|
|
457
395
|
}
|
|
458
396
|
} finally {
|
|
459
|
-
|
|
397
|
+
s.fill(0);
|
|
460
398
|
}
|
|
461
|
-
return { perVaultWotsKeys:
|
|
399
|
+
return { perVaultWotsKeys: t, wotsPkHashes: n, htlcSecretHexes: o, hashlocks: r };
|
|
462
400
|
}
|
|
463
|
-
const
|
|
464
|
-
function $(
|
|
465
|
-
if (typeof
|
|
401
|
+
const Ge = /^0x[0-9a-f]+$/i, qe = /^[0-9a-f]+$/i, ze = /^[A-Za-z0-9+/]+={0,2}$/;
|
|
402
|
+
function $(s) {
|
|
403
|
+
if (typeof s != "string" || s.length === 0)
|
|
466
404
|
throw new Error("BTC wallet returned empty public key");
|
|
467
|
-
return
|
|
405
|
+
return Jt(s).toLowerCase();
|
|
468
406
|
}
|
|
469
|
-
function
|
|
470
|
-
if (typeof
|
|
407
|
+
function Ye(s) {
|
|
408
|
+
if (typeof s != "string" || s.length === 0)
|
|
471
409
|
throw new Error("BTC wallet returned empty BIP-322 signature");
|
|
472
|
-
if (
|
|
473
|
-
if (!
|
|
410
|
+
if (s.startsWith("0x") || s.startsWith("0X")) {
|
|
411
|
+
if (!Ge.test(s) || s.length < 4 || s.length % 2 !== 0)
|
|
474
412
|
throw new Error("BTC wallet returned malformed hex BIP-322 signature");
|
|
475
|
-
return
|
|
413
|
+
return s.toLowerCase();
|
|
476
414
|
}
|
|
477
|
-
if (
|
|
478
|
-
if (
|
|
415
|
+
if (qe.test(s)) {
|
|
416
|
+
if (s.length % 2 !== 0)
|
|
479
417
|
throw new Error("BTC wallet returned malformed hex BIP-322 signature");
|
|
480
|
-
return `0x${
|
|
418
|
+
return `0x${s.toLowerCase()}`;
|
|
481
419
|
}
|
|
482
|
-
if (!
|
|
420
|
+
if (!ze.test(s) || s.length % 4 !== 0)
|
|
483
421
|
throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
|
|
484
|
-
const
|
|
485
|
-
if (
|
|
422
|
+
const e = Y.from(s, "base64");
|
|
423
|
+
if (e.length === 0 || e.toString("base64") !== s)
|
|
486
424
|
throw new Error("BTC wallet returned malformed base64 BIP-322 signature");
|
|
487
|
-
return `0x${
|
|
425
|
+
return `0x${e.toString("hex")}`;
|
|
488
426
|
}
|
|
489
|
-
const
|
|
490
|
-
function
|
|
491
|
-
const
|
|
427
|
+
const Ut = 0, W = 25, J = 9999, z = "00".repeat(32);
|
|
428
|
+
function je(s, e) {
|
|
429
|
+
const t = {
|
|
492
430
|
bitcoin: "bc",
|
|
493
431
|
testnet: "tb",
|
|
494
432
|
signet: "tb",
|
|
495
433
|
regtest: "bcrt"
|
|
496
434
|
};
|
|
497
435
|
try {
|
|
498
|
-
const
|
|
499
|
-
return
|
|
436
|
+
const n = Et.address.fromBech32(s);
|
|
437
|
+
return n.prefix === t[e] && n.version === 0 && n.data.length === 20;
|
|
500
438
|
} catch {
|
|
501
439
|
return !1;
|
|
502
440
|
}
|
|
503
441
|
}
|
|
504
|
-
function
|
|
505
|
-
const o =
|
|
442
|
+
function Qe(s, e, t, n) {
|
|
443
|
+
const o = t == null ? void 0 : t[`${s}:${e}`];
|
|
506
444
|
return o ? Promise.resolve({
|
|
507
|
-
txid:
|
|
508
|
-
vout:
|
|
445
|
+
txid: s,
|
|
446
|
+
vout: e,
|
|
509
447
|
value: o.value,
|
|
510
448
|
scriptPubKey: o.scriptPubKey
|
|
511
|
-
}) :
|
|
449
|
+
}) : de(s, e, n);
|
|
512
450
|
}
|
|
513
|
-
const
|
|
514
|
-
class
|
|
451
|
+
const xt = 12e4;
|
|
452
|
+
class ks {
|
|
515
453
|
/**
|
|
516
454
|
* Creates a new PeginManager instance.
|
|
517
455
|
*
|
|
518
456
|
* @param config - Manager configuration including wallets and contract addresses
|
|
519
457
|
*/
|
|
520
|
-
constructor(
|
|
458
|
+
constructor(e) {
|
|
521
459
|
x(this, "config");
|
|
522
|
-
this.config =
|
|
460
|
+
this.config = e;
|
|
523
461
|
}
|
|
524
462
|
/**
|
|
525
463
|
* Prepare a peg-in: sizing pass → vault-root derivation (one wallet
|
|
@@ -531,67 +469,67 @@ class Vn {
|
|
|
531
469
|
* @throws If the wallet rejects, insufficient funds, or an internal
|
|
532
470
|
* invariant violation.
|
|
533
471
|
*/
|
|
534
|
-
async preparePegin(
|
|
535
|
-
if (
|
|
472
|
+
async preparePegin(e) {
|
|
473
|
+
if (e.amounts.length === 0)
|
|
536
474
|
throw new Error("amounts must contain at least one entry");
|
|
537
|
-
const
|
|
538
|
-
if (!
|
|
539
|
-
|
|
540
|
-
|
|
475
|
+
const t = await this.config.btcWallet.getPublicKeyHex(), n = $(t);
|
|
476
|
+
if (!ht(
|
|
477
|
+
e.changeAddress,
|
|
478
|
+
t,
|
|
541
479
|
this.config.btcNetwork
|
|
542
480
|
))
|
|
543
481
|
throw new Error(
|
|
544
|
-
`Pre-PegIn changeAddress "${
|
|
482
|
+
`Pre-PegIn changeAddress "${e.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.`
|
|
545
483
|
);
|
|
546
|
-
const o = await this.prepareSizing(
|
|
547
|
-
(
|
|
548
|
-
txid:
|
|
549
|
-
vout:
|
|
484
|
+
const o = await this.prepareSizing(n, e), r = o.selectedUTXOs.map(
|
|
485
|
+
(g) => ({
|
|
486
|
+
txid: dt(g.txid),
|
|
487
|
+
vout: g.vout
|
|
550
488
|
})
|
|
551
|
-
), i = await
|
|
552
|
-
depositorBtcPubkey:
|
|
489
|
+
), i = await se(this.config.btcWallet, {
|
|
490
|
+
depositorBtcPubkey: dt(n),
|
|
553
491
|
fundingOutpoints: r
|
|
554
492
|
});
|
|
555
493
|
let a, c;
|
|
556
494
|
try {
|
|
557
|
-
const
|
|
495
|
+
const g = await qt(i);
|
|
558
496
|
try {
|
|
559
|
-
a =
|
|
497
|
+
a = Q(g), c = Q(Tt(g));
|
|
560
498
|
} finally {
|
|
561
|
-
|
|
499
|
+
g.fill(0);
|
|
562
500
|
}
|
|
563
|
-
} catch (
|
|
564
|
-
throw i.fill(0),
|
|
501
|
+
} catch (g) {
|
|
502
|
+
throw i.fill(0), g;
|
|
565
503
|
}
|
|
566
|
-
const h = await
|
|
567
|
-
depositorBtcPubkeyRaw:
|
|
568
|
-
depositorBtcPubkey:
|
|
569
|
-
hashlocks:
|
|
504
|
+
const h = await De(i, e.amounts.length), { perVaultWotsKeys: l, wotsPkHashes: m, htlcSecretHexes: P, hashlocks: b } = h, f = await this.preparePeginCommit({
|
|
505
|
+
depositorBtcPubkeyRaw: t,
|
|
506
|
+
depositorBtcPubkey: n,
|
|
507
|
+
hashlocks: b,
|
|
570
508
|
authAnchorHash: c,
|
|
571
509
|
sizing: o,
|
|
572
|
-
params:
|
|
510
|
+
params: e
|
|
573
511
|
});
|
|
574
|
-
for (let
|
|
575
|
-
if (
|
|
512
|
+
for (let g = 0; g < f.perVault.length; g++)
|
|
513
|
+
if (f.perVault[g].htlcVout !== g)
|
|
576
514
|
throw new Error(
|
|
577
|
-
`Internal invariant violation: htlcVout/index mismatch at vault ${
|
|
515
|
+
`Internal invariant violation: htlcVout/index mismatch at vault ${g} (expected ${g}, got ${f.perVault[g].htlcVout})`
|
|
578
516
|
);
|
|
579
|
-
return
|
|
580
|
-
|
|
581
|
-
|
|
517
|
+
return oe(
|
|
518
|
+
f.fundedPrePeginTxHex,
|
|
519
|
+
e.amounts.length,
|
|
582
520
|
c
|
|
583
521
|
), {
|
|
584
522
|
transaction: {
|
|
585
|
-
...
|
|
523
|
+
...f,
|
|
586
524
|
selectedUTXOs: o.selectedUTXOs,
|
|
587
525
|
fee: o.fee,
|
|
588
526
|
changeAmount: o.changeAmount
|
|
589
527
|
},
|
|
590
|
-
depositorBtcPubkey:
|
|
528
|
+
depositorBtcPubkey: n,
|
|
591
529
|
derivedSecrets: {
|
|
592
530
|
perVaultWotsKeys: l,
|
|
593
531
|
wotsPkHashes: m,
|
|
594
|
-
htlcSecretHexes:
|
|
532
|
+
htlcSecretHexes: P,
|
|
595
533
|
authAnchorHex: a
|
|
596
534
|
}
|
|
597
535
|
};
|
|
@@ -612,30 +550,30 @@ class Vn {
|
|
|
612
550
|
* real values. Output budget is identical (32-byte push regardless of
|
|
613
551
|
* content), so UTXO selection is invariant under substitution.
|
|
614
552
|
*/
|
|
615
|
-
async prepareSizing(
|
|
616
|
-
const
|
|
617
|
-
() =>
|
|
618
|
-
), o =
|
|
619
|
-
vaultCoreVersion:
|
|
620
|
-
depositorPubkey:
|
|
621
|
-
vaultProviderPubkey:
|
|
622
|
-
vaultKeeperPubkeys:
|
|
623
|
-
universalChallengerPubkeys:
|
|
624
|
-
hashlocks:
|
|
625
|
-
timelockRefund:
|
|
626
|
-
pegInAmounts:
|
|
627
|
-
feeRate:
|
|
628
|
-
minPeginFeeRate:
|
|
553
|
+
async prepareSizing(e, t) {
|
|
554
|
+
const n = t.amounts.map(
|
|
555
|
+
() => z
|
|
556
|
+
), o = t.vaultKeeperBtcPubkeys.length, r = await lt({
|
|
557
|
+
vaultCoreVersion: t.vaultCoreVersion,
|
|
558
|
+
depositorPubkey: e,
|
|
559
|
+
vaultProviderPubkey: E(t.vaultProviderBtcPubkey),
|
|
560
|
+
vaultKeeperPubkeys: t.vaultKeeperBtcPubkeys.map(E),
|
|
561
|
+
universalChallengerPubkeys: t.universalChallengerBtcPubkeys.map(E),
|
|
562
|
+
hashlocks: n,
|
|
563
|
+
timelockRefund: t.timelockRefund,
|
|
564
|
+
pegInAmounts: t.amounts,
|
|
565
|
+
feeRate: t.protocolFeeRate,
|
|
566
|
+
minPeginFeeRate: t.minPeginFeeRate,
|
|
629
567
|
numLocalChallengers: o,
|
|
630
|
-
councilQuorum:
|
|
631
|
-
councilSize:
|
|
568
|
+
councilQuorum: t.councilQuorum,
|
|
569
|
+
councilSize: t.councilSize,
|
|
632
570
|
network: this.config.btcNetwork,
|
|
633
|
-
authAnchorHash:
|
|
634
|
-
}), i =
|
|
635
|
-
[...
|
|
571
|
+
authAnchorHash: z
|
|
572
|
+
}), i = ie(
|
|
573
|
+
[...t.availableUTXOs],
|
|
636
574
|
r.totalOutputValue,
|
|
637
|
-
|
|
638
|
-
|
|
575
|
+
t.mempoolFeeRate,
|
|
576
|
+
ce(r.htlcValues.length, !0)
|
|
639
577
|
);
|
|
640
578
|
return {
|
|
641
579
|
selectedUTXOs: i.selectedUTXOs,
|
|
@@ -644,15 +582,15 @@ class Vn {
|
|
|
644
582
|
};
|
|
645
583
|
}
|
|
646
584
|
/** Build PegIn txs and batch-sign their inputs with real hashlocks. */
|
|
647
|
-
async preparePeginCommit(
|
|
585
|
+
async preparePeginCommit(e) {
|
|
648
586
|
const {
|
|
649
|
-
depositorBtcPubkeyRaw:
|
|
650
|
-
depositorBtcPubkey:
|
|
587
|
+
depositorBtcPubkeyRaw: t,
|
|
588
|
+
depositorBtcPubkey: n,
|
|
651
589
|
hashlocks: o,
|
|
652
590
|
authAnchorHash: r,
|
|
653
591
|
sizing: i,
|
|
654
592
|
params: a
|
|
655
|
-
} =
|
|
593
|
+
} = e, c = z.toLowerCase();
|
|
656
594
|
for (let u = 0; u < o.length; u++)
|
|
657
595
|
if (o[u].toLowerCase() === c)
|
|
658
596
|
throw new Error(
|
|
@@ -662,11 +600,11 @@ class Vn {
|
|
|
662
600
|
throw new Error(
|
|
663
601
|
"preparePeginCommit refusing to build with sizing-pass placeholder auth-anchor hash — internal substitution bug"
|
|
664
602
|
);
|
|
665
|
-
const h =
|
|
603
|
+
const h = E(
|
|
666
604
|
a.vaultProviderBtcPubkey
|
|
667
|
-
), l = a.vaultKeeperBtcPubkeys.map(
|
|
605
|
+
), l = a.vaultKeeperBtcPubkeys.map(E), m = a.universalChallengerBtcPubkeys.map(E), P = l.length, b = {
|
|
668
606
|
vaultCoreVersion: a.vaultCoreVersion,
|
|
669
|
-
depositorPubkey:
|
|
607
|
+
depositorPubkey: n,
|
|
670
608
|
vaultProviderPubkey: h,
|
|
671
609
|
vaultKeeperPubkeys: l,
|
|
672
610
|
universalChallengerPubkeys: m,
|
|
@@ -675,31 +613,31 @@ class Vn {
|
|
|
675
613
|
pegInAmounts: a.amounts,
|
|
676
614
|
feeRate: a.protocolFeeRate,
|
|
677
615
|
minPeginFeeRate: a.minPeginFeeRate,
|
|
678
|
-
numLocalChallengers:
|
|
616
|
+
numLocalChallengers: P,
|
|
679
617
|
councilQuorum: a.councilQuorum,
|
|
680
618
|
councilSize: a.councilSize,
|
|
681
619
|
network: this.config.btcNetwork,
|
|
682
620
|
authAnchorHash: r
|
|
683
|
-
},
|
|
684
|
-
unfundedTxHex:
|
|
621
|
+
}, f = await lt(b), g = ft(this.config.btcNetwork), k = le({
|
|
622
|
+
unfundedTxHex: f.psbtHex,
|
|
685
623
|
selectedUTXOs: i.selectedUTXOs,
|
|
686
624
|
changeAddress: a.changeAddress,
|
|
687
625
|
changeAmount: i.changeAmount,
|
|
688
|
-
network:
|
|
689
|
-
}), S =
|
|
690
|
-
|
|
691
|
-
),
|
|
626
|
+
network: g
|
|
627
|
+
}), S = E(
|
|
628
|
+
K(k)
|
|
629
|
+
), T = [], p = [], w = [];
|
|
692
630
|
for (let u = 0; u < o.length; u++) {
|
|
693
|
-
const
|
|
694
|
-
prePeginParams:
|
|
631
|
+
const _ = await zt({
|
|
632
|
+
prePeginParams: b,
|
|
695
633
|
timelockPegin: a.timelockPegin,
|
|
696
634
|
fundedPrePeginTxHex: k,
|
|
697
635
|
htlcVout: u
|
|
698
|
-
}),
|
|
636
|
+
}), A = await jt({
|
|
699
637
|
vaultCoreVersion: a.vaultCoreVersion,
|
|
700
|
-
peginTxHex:
|
|
638
|
+
peginTxHex: _.txHex,
|
|
701
639
|
fundedPrePeginTxHex: k,
|
|
702
|
-
depositorPubkey:
|
|
640
|
+
depositorPubkey: n,
|
|
703
641
|
vaultProviderPubkey: h,
|
|
704
642
|
vaultKeeperPubkeys: l,
|
|
705
643
|
universalChallengerPubkeys: m,
|
|
@@ -707,38 +645,38 @@ class Vn {
|
|
|
707
645
|
timelockRefund: a.timelockRefund,
|
|
708
646
|
network: this.config.btcNetwork
|
|
709
647
|
});
|
|
710
|
-
|
|
711
|
-
|
|
648
|
+
T.push(_), p.push(A.psbtHex), w.push(
|
|
649
|
+
ee(t, 1)
|
|
712
650
|
);
|
|
713
651
|
}
|
|
714
|
-
const y = await
|
|
652
|
+
const y = await re(
|
|
715
653
|
this.config.btcWallet,
|
|
716
654
|
p,
|
|
717
655
|
w
|
|
718
656
|
), d = [];
|
|
719
657
|
for (let u = 0; u < y.length; u++) {
|
|
720
|
-
|
|
658
|
+
ut({
|
|
721
659
|
requestedPsbtHex: p[u],
|
|
722
660
|
returnedPsbtHex: y[u]
|
|
723
661
|
});
|
|
724
|
-
const
|
|
662
|
+
const _ = Qt(
|
|
725
663
|
y[u],
|
|
726
|
-
|
|
664
|
+
n
|
|
727
665
|
);
|
|
728
|
-
|
|
666
|
+
Yt({
|
|
729
667
|
requestedPsbtHex: p[u],
|
|
730
|
-
signatureHex:
|
|
731
|
-
signerXOnlyPubkeyHex:
|
|
668
|
+
signatureHex: _,
|
|
669
|
+
signerXOnlyPubkeyHex: n,
|
|
732
670
|
inputIndex: 0
|
|
733
671
|
});
|
|
734
|
-
const
|
|
672
|
+
const A = Zt(y[u]);
|
|
735
673
|
d.push({
|
|
736
674
|
htlcVout: u,
|
|
737
|
-
htlcValue:
|
|
738
|
-
peginTxHex:
|
|
739
|
-
peginTxid:
|
|
740
|
-
peginInputSignature:
|
|
741
|
-
vaultScriptPubKey:
|
|
675
|
+
htlcValue: f.htlcValues[u],
|
|
676
|
+
peginTxHex: A,
|
|
677
|
+
peginTxid: T[u].txid,
|
|
678
|
+
peginInputSignature: _,
|
|
679
|
+
vaultScriptPubKey: T[u].vaultScriptPubKey
|
|
742
680
|
});
|
|
743
681
|
}
|
|
744
682
|
return {
|
|
@@ -762,38 +700,38 @@ class Vn {
|
|
|
762
700
|
* @returns The broadcasted Bitcoin transaction ID
|
|
763
701
|
* @throws Error if signing or broadcasting fails
|
|
764
702
|
*/
|
|
765
|
-
async signAndBroadcast(
|
|
766
|
-
const { fundedPrePeginTxHex:
|
|
703
|
+
async signAndBroadcast(e) {
|
|
704
|
+
const { fundedPrePeginTxHex: t, depositorBtcPubkey: n } = e, o = t.startsWith("0x") ? t.slice(2) : t, r = Xt.fromHex(o);
|
|
767
705
|
if (r.ins.length === 0)
|
|
768
706
|
throw new Error("Transaction has no inputs");
|
|
769
|
-
const i = new
|
|
707
|
+
const i = new it();
|
|
770
708
|
i.setVersion(r.version), i.setLocktime(r.locktime);
|
|
771
|
-
const a =
|
|
772
|
-
$(
|
|
709
|
+
const a = Y.from(
|
|
710
|
+
$(n),
|
|
773
711
|
"hex"
|
|
774
712
|
), c = this.config.mempoolApiUrl, h = r.ins.map((p) => {
|
|
775
|
-
const w =
|
|
776
|
-
return
|
|
713
|
+
const w = Y.from(p.hash).reverse().toString("hex"), y = p.index;
|
|
714
|
+
return Qe(w, y, e.localPrevouts, c).then(
|
|
777
715
|
(d) => ({ input: p, utxoData: d, txid: w, vout: y })
|
|
778
716
|
);
|
|
779
717
|
}), l = await Promise.all(h), m = l.reduce(
|
|
780
718
|
(p, w) => p + BigInt(w.utxoData.value),
|
|
781
719
|
0n
|
|
782
|
-
),
|
|
720
|
+
), P = r.outs.reduce(
|
|
783
721
|
(p, w) => p + BigInt(w.value),
|
|
784
722
|
0n
|
|
785
723
|
);
|
|
786
|
-
if (m <
|
|
724
|
+
if (m < P)
|
|
787
725
|
throw new Error(
|
|
788
|
-
`UTXO value mismatch: total input value (${m} sat) is less than total output value (${
|
|
726
|
+
`UTXO value mismatch: total input value (${m} sat) is less than total output value (${P} sat). This may indicate the mempool API returned manipulated UTXO data.`
|
|
789
727
|
);
|
|
790
|
-
const
|
|
791
|
-
if (
|
|
728
|
+
const b = m - P;
|
|
729
|
+
if (b > gt)
|
|
792
730
|
throw new Error(
|
|
793
|
-
`Implied transaction fee (${
|
|
731
|
+
`Implied transaction fee (${b} sat) exceeds maximum reasonable fee (${gt} sat). This may indicate manipulated UTXO data.`
|
|
794
732
|
);
|
|
795
733
|
for (const { input: p, utxoData: w, txid: y, vout: d } of l) {
|
|
796
|
-
const u =
|
|
734
|
+
const u = ae(
|
|
797
735
|
{
|
|
798
736
|
value: w.value,
|
|
799
737
|
scriptPubKey: w.scriptPubKey
|
|
@@ -812,12 +750,12 @@ class Vn {
|
|
|
812
750
|
script: p.script,
|
|
813
751
|
value: p.value
|
|
814
752
|
});
|
|
815
|
-
const
|
|
816
|
-
|
|
817
|
-
requestedPsbtHex:
|
|
818
|
-
returnedPsbtHex:
|
|
753
|
+
const f = i.toHex(), g = await this.config.btcWallet.signPsbt(f);
|
|
754
|
+
ut({
|
|
755
|
+
requestedPsbtHex: f,
|
|
756
|
+
returnedPsbtHex: g
|
|
819
757
|
});
|
|
820
|
-
const k =
|
|
758
|
+
const k = it.fromHex(g);
|
|
821
759
|
try {
|
|
822
760
|
k.finalizeAllInputs();
|
|
823
761
|
} catch (p) {
|
|
@@ -829,7 +767,7 @@ class Vn {
|
|
|
829
767
|
);
|
|
830
768
|
}
|
|
831
769
|
const S = k.extractTransaction().toHex();
|
|
832
|
-
return await
|
|
770
|
+
return await ue(S, c);
|
|
833
771
|
}
|
|
834
772
|
/**
|
|
835
773
|
* Registers a peg-in on Ethereum by calling the BTCVaultRegistry contract.
|
|
@@ -855,66 +793,66 @@ class Vn {
|
|
|
855
793
|
* @throws Error if contract simulation fails (e.g., invalid signature,
|
|
856
794
|
* unauthorized)
|
|
857
795
|
*/
|
|
858
|
-
async registerPeginOnChain(
|
|
796
|
+
async registerPeginOnChain(e) {
|
|
859
797
|
const {
|
|
860
|
-
unsignedPrePeginTx:
|
|
861
|
-
depositorSignedPeginTx:
|
|
798
|
+
unsignedPrePeginTx: t,
|
|
799
|
+
depositorSignedPeginTx: n,
|
|
862
800
|
vaultProvider: o,
|
|
863
801
|
hashlock: r,
|
|
864
802
|
htlcVout: i,
|
|
865
803
|
depositorPayoutBtcAddress: a,
|
|
866
804
|
depositorWotsPkHash: c,
|
|
867
805
|
popSignature: h
|
|
868
|
-
} =
|
|
806
|
+
} = e;
|
|
869
807
|
if (!this.config.ethWallet.account)
|
|
870
808
|
throw new Error("Ethereum wallet account not found");
|
|
871
809
|
const l = this.config.ethWallet.account.address;
|
|
872
|
-
if (!
|
|
810
|
+
if (!at(h.depositorEthAddress, l))
|
|
873
811
|
throw new Error(
|
|
874
812
|
`Proof of possession was signed for ${h.depositorEthAddress} but the Ethereum wallet is currently connected to ${l}. Reconnect the original account or call signProofOfPossession() again.`
|
|
875
813
|
);
|
|
876
|
-
const m = await this.assertPopMatchesBtcWallet(h),
|
|
814
|
+
const m = await this.assertPopMatchesBtcWallet(h), P = h.btcPopSignature, b = v(
|
|
877
815
|
h.depositorBtcPubkey
|
|
878
|
-
),
|
|
816
|
+
), f = v(t), g = v(n), k = a ?? await this.config.btcWallet.getAddress(), S = this.resolvePayoutScriptPubKey(
|
|
879
817
|
m,
|
|
880
818
|
k
|
|
881
|
-
),
|
|
882
|
-
T
|
|
883
|
-
|
|
819
|
+
), T = K(g), p = await ct(
|
|
820
|
+
E(T),
|
|
821
|
+
E(l)
|
|
884
822
|
), w = v(p);
|
|
885
823
|
if (await this.checkVaultExists(w))
|
|
886
824
|
throw new Error(
|
|
887
|
-
`Vault already exists (ID: ${w}, peginTxHash: ${
|
|
825
|
+
`Vault already exists (ID: ${w}, peginTxHash: ${T}). 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
826
|
);
|
|
889
827
|
const d = this.config.publicClient;
|
|
890
828
|
let u;
|
|
891
829
|
try {
|
|
892
830
|
u = await d.readContract({
|
|
893
831
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
894
|
-
abi:
|
|
832
|
+
abi: I,
|
|
895
833
|
functionName: "getPegInFee",
|
|
896
834
|
args: [o]
|
|
897
835
|
});
|
|
898
|
-
} catch (
|
|
836
|
+
} catch (R) {
|
|
899
837
|
throw new Error(
|
|
900
838
|
"Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct.",
|
|
901
|
-
{ cause:
|
|
839
|
+
{ cause: R }
|
|
902
840
|
);
|
|
903
841
|
}
|
|
904
|
-
const
|
|
842
|
+
const _ = await this.resolveMaxAcceptableCommissionBps(
|
|
905
843
|
o,
|
|
906
|
-
|
|
907
|
-
),
|
|
908
|
-
abi:
|
|
844
|
+
e.quotedCommissionBps
|
|
845
|
+
), A = j({
|
|
846
|
+
abi: I,
|
|
909
847
|
functionName: "submitPeginRequest",
|
|
910
848
|
args: [
|
|
911
849
|
l,
|
|
912
|
-
P,
|
|
913
850
|
b,
|
|
914
|
-
|
|
851
|
+
P,
|
|
915
852
|
f,
|
|
853
|
+
g,
|
|
916
854
|
o,
|
|
917
|
-
|
|
855
|
+
_,
|
|
918
856
|
r,
|
|
919
857
|
i,
|
|
920
858
|
S,
|
|
@@ -925,40 +863,40 @@ class Vn {
|
|
|
925
863
|
try {
|
|
926
864
|
C = await d.estimateGas({
|
|
927
865
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
928
|
-
data:
|
|
866
|
+
data: A,
|
|
929
867
|
value: u,
|
|
930
868
|
account: this.config.ethWallet.account.address
|
|
931
869
|
});
|
|
932
|
-
} catch (
|
|
933
|
-
H(
|
|
870
|
+
} catch (R) {
|
|
871
|
+
H(R);
|
|
934
872
|
}
|
|
935
|
-
let
|
|
873
|
+
let L;
|
|
936
874
|
try {
|
|
937
|
-
|
|
875
|
+
L = await this.config.ethWallet.sendTransaction({
|
|
938
876
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
939
|
-
data:
|
|
877
|
+
data: A,
|
|
940
878
|
value: u,
|
|
941
879
|
account: this.config.ethWallet.account,
|
|
942
880
|
chain: this.config.ethChain,
|
|
943
881
|
gas: C
|
|
944
882
|
});
|
|
945
|
-
} catch (
|
|
946
|
-
H(
|
|
883
|
+
} catch (R) {
|
|
884
|
+
H(R);
|
|
947
885
|
}
|
|
948
|
-
const
|
|
886
|
+
const X = await pt({
|
|
949
887
|
publicClient: d,
|
|
950
888
|
walletAddress: this.config.ethWallet.account.address,
|
|
951
|
-
hash:
|
|
952
|
-
timeout:
|
|
889
|
+
hash: L,
|
|
890
|
+
timeout: xt
|
|
953
891
|
});
|
|
954
|
-
return
|
|
892
|
+
return X.status === "reverted" && H(
|
|
955
893
|
new Error(
|
|
956
|
-
`Transaction reverted. Hash: ${
|
|
894
|
+
`Transaction reverted. Hash: ${X.transactionHash}. Check the transaction on block explorer for details.`
|
|
957
895
|
)
|
|
958
896
|
), {
|
|
959
|
-
ethTxHash:
|
|
897
|
+
ethTxHash: X.transactionHash,
|
|
960
898
|
vaultId: w,
|
|
961
|
-
peginTxHash:
|
|
899
|
+
peginTxHash: T
|
|
962
900
|
};
|
|
963
901
|
}
|
|
964
902
|
/**
|
|
@@ -971,14 +909,14 @@ class Vn {
|
|
|
971
909
|
* @param params - Batch registration parameters
|
|
972
910
|
* @returns Batch result with per-vault IDs and single ETH tx hash
|
|
973
911
|
*/
|
|
974
|
-
async registerPeginBatchOnChain(
|
|
975
|
-
const { vaultProvider:
|
|
912
|
+
async registerPeginBatchOnChain(e) {
|
|
913
|
+
const { vaultProvider: t, unsignedPrePeginTx: n, requests: o, popSignature: r } = e;
|
|
976
914
|
if (o.length === 0)
|
|
977
915
|
throw new Error("Batch pegin requires at least one request");
|
|
978
916
|
if (!this.config.ethWallet.account)
|
|
979
917
|
throw new Error("Ethereum wallet account not found");
|
|
980
918
|
const i = this.config.ethWallet.account.address;
|
|
981
|
-
if (!
|
|
919
|
+
if (!at(r.depositorEthAddress, i))
|
|
982
920
|
throw new Error(
|
|
983
921
|
`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
922
|
);
|
|
@@ -991,24 +929,24 @@ class Vn {
|
|
|
991
929
|
for (const d of o) {
|
|
992
930
|
const u = v(
|
|
993
931
|
d.depositorSignedPeginTx
|
|
994
|
-
),
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
), C = v(
|
|
932
|
+
), _ = K(u), A = await ct(
|
|
933
|
+
E(_),
|
|
934
|
+
E(i)
|
|
935
|
+
), C = v(A);
|
|
998
936
|
if (await this.checkVaultExists(C))
|
|
999
937
|
throw new Error(
|
|
1000
|
-
`Vault already exists (ID: ${C}, peginTxHash: ${
|
|
938
|
+
`Vault already exists (ID: ${C}, peginTxHash: ${_}). To create a new vault, use different UTXOs or a different amount.`
|
|
1001
939
|
);
|
|
1002
|
-
l.push({ vaultId: C, peginTxHash:
|
|
940
|
+
l.push({ vaultId: C, peginTxHash: _ });
|
|
1003
941
|
}
|
|
1004
942
|
const m = this.config.publicClient;
|
|
1005
|
-
let
|
|
943
|
+
let P;
|
|
1006
944
|
try {
|
|
1007
|
-
|
|
945
|
+
P = await m.readContract({
|
|
1008
946
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
1009
|
-
abi:
|
|
947
|
+
abi: I,
|
|
1010
948
|
functionName: "getPegInFee",
|
|
1011
|
-
args: [
|
|
949
|
+
args: [t]
|
|
1012
950
|
});
|
|
1013
951
|
} catch (d) {
|
|
1014
952
|
throw new Error(
|
|
@@ -1016,13 +954,13 @@ class Vn {
|
|
|
1016
954
|
{ cause: d }
|
|
1017
955
|
);
|
|
1018
956
|
}
|
|
1019
|
-
const
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
),
|
|
957
|
+
const b = P * BigInt(o.length), f = await this.resolveMaxAcceptableCommissionBps(
|
|
958
|
+
t,
|
|
959
|
+
e.quotedCommissionBps
|
|
960
|
+
), g = v(
|
|
1023
961
|
r.depositorBtcPubkey
|
|
1024
|
-
), k = v(
|
|
1025
|
-
depositorBtcPubKey:
|
|
962
|
+
), k = v(n), S = o.map((d, u) => ({
|
|
963
|
+
depositorBtcPubKey: g,
|
|
1026
964
|
btcPopSignature: c,
|
|
1027
965
|
unsignedPrePeginTx: k,
|
|
1028
966
|
depositorSignedPeginTx: v(
|
|
@@ -1030,16 +968,16 @@ class Vn {
|
|
|
1030
968
|
),
|
|
1031
969
|
hashlock: d.hashlock,
|
|
1032
970
|
htlcVout: d.htlcVout,
|
|
1033
|
-
referralCode:
|
|
971
|
+
referralCode: Ut,
|
|
1034
972
|
depositorPayoutBtcAddress: h[u],
|
|
1035
973
|
depositorWotsPkHash: d.depositorWotsPkHash
|
|
1036
|
-
})),
|
|
1037
|
-
abi:
|
|
974
|
+
})), T = j({
|
|
975
|
+
abi: I,
|
|
1038
976
|
functionName: "submitPeginRequestBatch",
|
|
1039
977
|
args: [
|
|
1040
978
|
i,
|
|
1041
|
-
|
|
1042
|
-
|
|
979
|
+
t,
|
|
980
|
+
f,
|
|
1043
981
|
S
|
|
1044
982
|
]
|
|
1045
983
|
});
|
|
@@ -1047,8 +985,8 @@ class Vn {
|
|
|
1047
985
|
try {
|
|
1048
986
|
p = await m.estimateGas({
|
|
1049
987
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1050
|
-
data:
|
|
1051
|
-
value:
|
|
988
|
+
data: T,
|
|
989
|
+
value: b,
|
|
1052
990
|
account: this.config.ethWallet.account.address
|
|
1053
991
|
});
|
|
1054
992
|
} catch (d) {
|
|
@@ -1058,8 +996,8 @@ class Vn {
|
|
|
1058
996
|
try {
|
|
1059
997
|
w = await this.config.ethWallet.sendTransaction({
|
|
1060
998
|
to: this.config.vaultContracts.btcVaultRegistry,
|
|
1061
|
-
data:
|
|
1062
|
-
value:
|
|
999
|
+
data: T,
|
|
1000
|
+
value: b,
|
|
1063
1001
|
account: this.config.ethWallet.account,
|
|
1064
1002
|
chain: this.config.ethChain,
|
|
1065
1003
|
gas: p
|
|
@@ -1067,11 +1005,11 @@ class Vn {
|
|
|
1067
1005
|
} catch (d) {
|
|
1068
1006
|
H(d);
|
|
1069
1007
|
}
|
|
1070
|
-
const y = await
|
|
1008
|
+
const y = await pt({
|
|
1071
1009
|
publicClient: m,
|
|
1072
1010
|
walletAddress: this.config.ethWallet.account.address,
|
|
1073
1011
|
hash: w,
|
|
1074
|
-
timeout:
|
|
1012
|
+
timeout: xt
|
|
1075
1013
|
});
|
|
1076
1014
|
return y.status === "reverted" && H(
|
|
1077
1015
|
new Error(
|
|
@@ -1084,32 +1022,32 @@ class Vn {
|
|
|
1084
1022
|
}
|
|
1085
1023
|
// Anchor to quoted+headroom when supplied (refuse if chain drifted past it);
|
|
1086
1024
|
// otherwise fall back to chain-current+headroom — see #1691.
|
|
1087
|
-
async resolveMaxAcceptableCommissionBps(
|
|
1088
|
-
let
|
|
1025
|
+
async resolveMaxAcceptableCommissionBps(e, t) {
|
|
1026
|
+
let n;
|
|
1089
1027
|
try {
|
|
1090
|
-
|
|
1028
|
+
n = await new he(
|
|
1091
1029
|
this.config.publicClient,
|
|
1092
1030
|
this.config.vaultContracts.btcVaultRegistry
|
|
1093
|
-
).getVaultProviderCommission(
|
|
1031
|
+
).getVaultProviderCommission(e);
|
|
1094
1032
|
} catch (o) {
|
|
1095
1033
|
throw new Error(
|
|
1096
1034
|
"Failed to query vault provider commission from the contract. Please check your network connection and that the contract address is correct.",
|
|
1097
1035
|
{ cause: o }
|
|
1098
1036
|
);
|
|
1099
1037
|
}
|
|
1100
|
-
if (
|
|
1101
|
-
if (
|
|
1038
|
+
if (t !== void 0) {
|
|
1039
|
+
if (n > t + W)
|
|
1102
1040
|
throw new Error(
|
|
1103
|
-
`Vault provider commission changed since quote: quoted ${
|
|
1041
|
+
`Vault provider commission changed since quote: quoted ${t} bps, chain currently reports ${n} bps (allowed drift ${W} bps). Please refresh to see the new commission and try again.`
|
|
1104
1042
|
);
|
|
1105
1043
|
return Math.min(
|
|
1106
|
-
|
|
1107
|
-
|
|
1044
|
+
t + W,
|
|
1045
|
+
J
|
|
1108
1046
|
);
|
|
1109
1047
|
}
|
|
1110
1048
|
return Math.min(
|
|
1111
|
-
|
|
1112
|
-
|
|
1049
|
+
n + W,
|
|
1050
|
+
J
|
|
1113
1051
|
);
|
|
1114
1052
|
}
|
|
1115
1053
|
/**
|
|
@@ -1125,13 +1063,13 @@ class Vn {
|
|
|
1125
1063
|
* @returns True if vault exists, false otherwise
|
|
1126
1064
|
* @throws If the underlying RPC read fails
|
|
1127
1065
|
*/
|
|
1128
|
-
async checkVaultExists(
|
|
1066
|
+
async checkVaultExists(e) {
|
|
1129
1067
|
return (await this.config.publicClient.readContract({
|
|
1130
1068
|
address: this.config.vaultContracts.btcVaultRegistry,
|
|
1131
|
-
abi:
|
|
1069
|
+
abi: I,
|
|
1132
1070
|
functionName: "getBtcVaultBasicInfo",
|
|
1133
|
-
args: [
|
|
1134
|
-
})).depositor !==
|
|
1071
|
+
args: [e]
|
|
1072
|
+
})).depositor !== Kt;
|
|
1135
1073
|
}
|
|
1136
1074
|
/**
|
|
1137
1075
|
* Resolve the BTC scriptPubKey to register as the depositor's payout sink.
|
|
@@ -1149,23 +1087,23 @@ class Vn {
|
|
|
1149
1087
|
* state-race or stale FE state that lets a non-wallet address reach the
|
|
1150
1088
|
* on-chain payout-script registration.
|
|
1151
1089
|
*/
|
|
1152
|
-
resolvePayoutScriptPubKey(
|
|
1153
|
-
if (!
|
|
1154
|
-
e,
|
|
1090
|
+
resolvePayoutScriptPubKey(e, t) {
|
|
1091
|
+
if (!ht(
|
|
1155
1092
|
t,
|
|
1093
|
+
e,
|
|
1156
1094
|
this.config.btcNetwork
|
|
1157
1095
|
))
|
|
1158
|
-
throw
|
|
1159
|
-
`BTC payout address "${
|
|
1096
|
+
throw E(e).length === te && je(t, this.config.btcNetwork) ? new Error(
|
|
1097
|
+
`BTC payout address "${t}" 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.`
|
|
1160
1098
|
) : new Error(
|
|
1161
|
-
`BTC payout address "${
|
|
1099
|
+
`BTC payout address "${t}" 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.`
|
|
1162
1100
|
);
|
|
1163
|
-
const
|
|
1101
|
+
const n = ft(this.config.btcNetwork);
|
|
1164
1102
|
try {
|
|
1165
|
-
return `0x${
|
|
1103
|
+
return `0x${Et.address.toOutputScript(t, n).toString("hex")}`;
|
|
1166
1104
|
} catch {
|
|
1167
1105
|
throw new Error(
|
|
1168
|
-
`Invalid BTC payout address: "${
|
|
1106
|
+
`Invalid BTC payout address: "${t}". Please provide a valid Bitcoin address for the ${this.config.btcNetwork} network.`
|
|
1169
1107
|
);
|
|
1170
1108
|
}
|
|
1171
1109
|
}
|
|
@@ -1178,16 +1116,16 @@ class Vn {
|
|
|
1178
1116
|
async signProofOfPossession() {
|
|
1179
1117
|
if (!this.config.ethWallet.account)
|
|
1180
1118
|
throw new Error("Ethereum wallet account not found");
|
|
1181
|
-
const
|
|
1119
|
+
const e = this.config.ethWallet.account.address, t = $(
|
|
1182
1120
|
await this.config.btcWallet.getPublicKeyHex()
|
|
1183
|
-
),
|
|
1121
|
+
), n = this.config.vaultContracts.btcVaultRegistry, o = `${e.toLowerCase()}:${this.config.ethChain.id}:pegin:${n.toLowerCase()}`, r = await this.config.btcWallet.signMessage(
|
|
1184
1122
|
o,
|
|
1185
1123
|
"bip322-simple"
|
|
1186
1124
|
);
|
|
1187
1125
|
return {
|
|
1188
|
-
btcPopSignature:
|
|
1189
|
-
depositorEthAddress:
|
|
1190
|
-
depositorBtcPubkey:
|
|
1126
|
+
btcPopSignature: Ye(r),
|
|
1127
|
+
depositorEthAddress: e,
|
|
1128
|
+
depositorBtcPubkey: t
|
|
1191
1129
|
};
|
|
1192
1130
|
}
|
|
1193
1131
|
/**
|
|
@@ -1198,13 +1136,13 @@ class Vn {
|
|
|
1198
1136
|
* a parity-bearing compressed key — an x-only form would let an attacker
|
|
1199
1137
|
* substitute the opposite-parity P2WPKH address.
|
|
1200
1138
|
*/
|
|
1201
|
-
async assertPopMatchesBtcWallet(
|
|
1202
|
-
const
|
|
1203
|
-
if (
|
|
1139
|
+
async assertPopMatchesBtcWallet(e) {
|
|
1140
|
+
const t = await this.config.btcWallet.getPublicKeyHex(), n = $(t), o = $(e.depositorBtcPubkey);
|
|
1141
|
+
if (n !== o)
|
|
1204
1142
|
throw new Error(
|
|
1205
|
-
`Proof of possession was signed with BTC pubkey ${o} but the BTC wallet is currently connected to ${
|
|
1143
|
+
`Proof of possession was signed with BTC pubkey ${o} but the BTC wallet is currently connected to ${n}. Reconnect the original wallet or call signProofOfPossession() again.`
|
|
1206
1144
|
);
|
|
1207
|
-
return
|
|
1145
|
+
return t;
|
|
1208
1146
|
}
|
|
1209
1147
|
/**
|
|
1210
1148
|
* Gets the configured Bitcoin network.
|
|
@@ -1223,73 +1161,69 @@ class Vn {
|
|
|
1223
1161
|
return this.config.vaultContracts.btcVaultRegistry;
|
|
1224
1162
|
}
|
|
1225
1163
|
}
|
|
1226
|
-
const
|
|
1227
|
-
function
|
|
1228
|
-
const
|
|
1164
|
+
const Ze = 80, Je = 250, ts = 300, es = 22, Vt = "ab";
|
|
1165
|
+
function ss(s, e) {
|
|
1166
|
+
const t = Vt.repeat(ts), n = E(s).toLowerCase(), o = e.toString(16).padStart(8, "0"), r = `${n}${o}`, i = t.slice(r.length);
|
|
1229
1167
|
return `0x${r}${i}`;
|
|
1230
1168
|
}
|
|
1231
|
-
function
|
|
1232
|
-
const
|
|
1169
|
+
function ns(s, e) {
|
|
1170
|
+
const t = (n) => `0x${Vt.repeat(n)}`;
|
|
1233
1171
|
return {
|
|
1234
|
-
depositorBtcPubKey:
|
|
1235
|
-
btcPopSignature:
|
|
1236
|
-
unsignedPrePeginTx:
|
|
1237
|
-
depositorSignedPeginTx:
|
|
1238
|
-
|
|
1239
|
-
|
|
1172
|
+
depositorBtcPubKey: t(32),
|
|
1173
|
+
btcPopSignature: t(Ze),
|
|
1174
|
+
unsignedPrePeginTx: t(Je),
|
|
1175
|
+
depositorSignedPeginTx: ss(
|
|
1176
|
+
s,
|
|
1177
|
+
e
|
|
1240
1178
|
),
|
|
1241
|
-
hashlock:
|
|
1242
|
-
htlcVout:
|
|
1243
|
-
referralCode:
|
|
1244
|
-
depositorPayoutBtcAddress:
|
|
1245
|
-
depositorWotsPkHash:
|
|
1179
|
+
hashlock: t(32),
|
|
1180
|
+
htlcVout: e,
|
|
1181
|
+
referralCode: Ut,
|
|
1182
|
+
depositorPayoutBtcAddress: t(es),
|
|
1183
|
+
depositorWotsPkHash: t(32)
|
|
1246
1184
|
};
|
|
1247
1185
|
}
|
|
1248
|
-
async function
|
|
1186
|
+
async function Ts(s) {
|
|
1249
1187
|
const {
|
|
1250
|
-
publicClient:
|
|
1251
|
-
btcVaultRegistry:
|
|
1252
|
-
depositorEthAddress:
|
|
1188
|
+
publicClient: e,
|
|
1189
|
+
btcVaultRegistry: t,
|
|
1190
|
+
depositorEthAddress: n,
|
|
1253
1191
|
vaultProvider: o,
|
|
1254
1192
|
batchSize: r
|
|
1255
|
-
} =
|
|
1193
|
+
} = s;
|
|
1256
1194
|
if (r <= 0)
|
|
1257
1195
|
throw new Error(
|
|
1258
1196
|
`estimateSubmitPeginRequestBatchGas requires batchSize >= 1 (received ${r})`
|
|
1259
1197
|
);
|
|
1260
|
-
const a = await
|
|
1261
|
-
address:
|
|
1262
|
-
abi:
|
|
1198
|
+
const a = await e.readContract({
|
|
1199
|
+
address: t,
|
|
1200
|
+
abi: I,
|
|
1263
1201
|
functionName: "getPegInFee",
|
|
1264
1202
|
args: [o]
|
|
1265
1203
|
}) * BigInt(r), c = Array.from(
|
|
1266
1204
|
{ length: r },
|
|
1267
|
-
(l, m) =>
|
|
1268
|
-
), h =
|
|
1269
|
-
abi:
|
|
1205
|
+
(l, m) => ns(n, m)
|
|
1206
|
+
), h = j({
|
|
1207
|
+
abi: I,
|
|
1270
1208
|
functionName: "submitPeginRequestBatch",
|
|
1271
1209
|
args: [
|
|
1272
|
-
|
|
1210
|
+
n,
|
|
1273
1211
|
o,
|
|
1274
|
-
|
|
1212
|
+
J,
|
|
1275
1213
|
c
|
|
1276
1214
|
]
|
|
1277
1215
|
});
|
|
1278
|
-
return
|
|
1279
|
-
to:
|
|
1216
|
+
return e.estimateGas({
|
|
1217
|
+
to: t,
|
|
1280
1218
|
data: h,
|
|
1281
1219
|
value: a,
|
|
1282
|
-
account:
|
|
1220
|
+
account: n
|
|
1283
1221
|
});
|
|
1284
1222
|
}
|
|
1285
1223
|
export {
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
rn as c,
|
|
1291
|
-
on as d,
|
|
1292
|
-
Mn as e,
|
|
1293
|
-
Oe as f
|
|
1224
|
+
ks as P,
|
|
1225
|
+
Ke as c,
|
|
1226
|
+
Xe as d,
|
|
1227
|
+
Ts as e
|
|
1294
1228
|
};
|
|
1295
|
-
//# sourceMappingURL=PeginManager-
|
|
1229
|
+
//# sourceMappingURL=PeginManager-CW03-M3T.js.map
|