@babylonlabs-io/ts-sdk 0.39.0 → 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/{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 +110 -105
- 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 +18 -0
- package/dist/tbv/core/clients/eth/types.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 +115 -110
- 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 +115 -110
- package/dist/{vault-registry-reader-DXvw-1f6.js → types-0bvDGR4x.js} +82 -80
- package/dist/types-0bvDGR4x.js.map +1 -0
- package/dist/{vault-registry-reader-BM_993Lb.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/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-BM_993Lb.cjs.map +0 -1
- package/dist/vault-registry-reader-DXvw-1f6.js.map +0 -1
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { B as
|
|
5
|
-
import { e as
|
|
6
|
-
import { v as
|
|
7
|
-
import { D as
|
|
8
|
-
import { Transaction as _, Psbt as
|
|
9
|
-
import { c as
|
|
10
|
-
import { c as
|
|
11
|
-
import { c as
|
|
12
|
-
const
|
|
13
|
-
function
|
|
1
|
+
var W = Object.defineProperty;
|
|
2
|
+
var Y = (e, t, r) => t in e ? W(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var A = (e, t, r) => Y(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { B as J } from "./BTCVaultRegistry.abi-Cq9-JlqT.js";
|
|
5
|
+
import { e as Z, v as ee, s as p, u as M, p as C, d as te, f as w } from "./bitcoin-B5aNKtsk.js";
|
|
6
|
+
import { v as re, P as ne, f as oe } from "./PayoutManager-D29D-K-V.js";
|
|
7
|
+
import { D as m, c as se, a as ae, R as ie, d as L } from "./types-BqGAMOZM.js";
|
|
8
|
+
import { Transaction as _, Psbt as ue } from "bitcoinjs-lib";
|
|
9
|
+
import { c as le, d as ce, f as I, e as N } from "./assertPsbtUnsignedTxMatches-mTAnLhCz.js";
|
|
10
|
+
import { c as de, a as pe, b as he } from "./noPayout-qbaSEKGC.js";
|
|
11
|
+
import { c as V } from "./signing-DaLvGwQe.js";
|
|
12
|
+
const fe = /^0x[0-9a-fA-F]{64}$/, ge = /^0x[0-9a-fA-F]{40}$/, Pe = /^0x([0-9a-fA-F]{2})*$/;
|
|
13
|
+
function B(e, t) {
|
|
14
14
|
if (e.length !== 66)
|
|
15
15
|
throw new Error(
|
|
16
16
|
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
17
17
|
);
|
|
18
|
-
if (!
|
|
18
|
+
if (!fe.test(e))
|
|
19
19
|
throw new Error(
|
|
20
20
|
`${t} must contain only hex characters after the 0x prefix`
|
|
21
21
|
);
|
|
22
22
|
}
|
|
23
|
-
function
|
|
24
|
-
if (!
|
|
23
|
+
function ye(e, t) {
|
|
24
|
+
if (!ge.test(e))
|
|
25
25
|
throw new Error(
|
|
26
26
|
`${t} must be a 20-byte 0x-prefixed hex address (42 chars)`
|
|
27
27
|
);
|
|
28
28
|
}
|
|
29
|
-
function
|
|
30
|
-
if (!
|
|
29
|
+
function me(e, t) {
|
|
30
|
+
if (!Pe.test(e))
|
|
31
31
|
throw new Error(
|
|
32
32
|
`${t} must be a 0x-prefixed hex string with an even number of hex chars`
|
|
33
33
|
);
|
|
34
34
|
}
|
|
35
|
-
async function
|
|
35
|
+
async function at(e) {
|
|
36
36
|
const {
|
|
37
37
|
btcVaultRegistryAddress: t,
|
|
38
38
|
vaultId: r,
|
|
@@ -41,27 +41,27 @@ async function tt(e) {
|
|
|
41
41
|
writeContract: u,
|
|
42
42
|
signal: a
|
|
43
43
|
} = e;
|
|
44
|
-
a == null || a.throwIfAborted(),
|
|
45
|
-
const i =
|
|
46
|
-
if (
|
|
44
|
+
a == null || a.throwIfAborted(), ye(t, "btcVaultRegistryAddress"), B(r, "vaultId");
|
|
45
|
+
const i = Z(e.secret);
|
|
46
|
+
if (B(i, "secret"), n !== void 0 && (B(n, "hashlock"), !re(i, n)))
|
|
47
47
|
throw new Error(
|
|
48
48
|
"Invalid secret: SHA256(secret) does not match the provided hashlock"
|
|
49
49
|
);
|
|
50
|
-
return
|
|
50
|
+
return me(o, "activationMetadata"), u({
|
|
51
51
|
address: t,
|
|
52
|
-
abi:
|
|
52
|
+
abi: J,
|
|
53
53
|
functionName: "activateVaultWithSecret",
|
|
54
54
|
args: [r, i, o]
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
|
-
const
|
|
58
|
-
async function
|
|
57
|
+
const be = 1e4;
|
|
58
|
+
async function F(e) {
|
|
59
59
|
const {
|
|
60
60
|
statusReader: t,
|
|
61
61
|
peginTxid: r,
|
|
62
62
|
targetStatuses: n,
|
|
63
63
|
timeoutMs: o,
|
|
64
|
-
pollIntervalMs: u =
|
|
64
|
+
pollIntervalMs: u = be,
|
|
65
65
|
signal: a
|
|
66
66
|
} = e, i = Date.now();
|
|
67
67
|
for (; ; ) {
|
|
@@ -83,14 +83,14 @@ async function D(e) {
|
|
|
83
83
|
`getPeginStatus returned status for pegin ${s.pegin_txid.slice(0, 8)}…, requested ${r.slice(0, 8)}…`
|
|
84
84
|
);
|
|
85
85
|
const l = s.status;
|
|
86
|
-
if (n.has(l) || l ===
|
|
86
|
+
if (n.has(l) || l === m.ACTIVATED)
|
|
87
87
|
return l;
|
|
88
|
-
if (l ===
|
|
88
|
+
if (l === m.EXPIRED || se.has(l))
|
|
89
89
|
throw new Error(
|
|
90
90
|
`Pegin ${r.slice(0, 8)}… reached terminal status "${l}" while waiting for ${[...n].join(", ")}`
|
|
91
91
|
);
|
|
92
92
|
} catch (s) {
|
|
93
|
-
if (!(s instanceof
|
|
93
|
+
if (!(s instanceof ae && s.code === ie.PEGIN_NOT_FOUND))
|
|
94
94
|
throw s;
|
|
95
95
|
}
|
|
96
96
|
await new Promise((s, l) => {
|
|
@@ -107,29 +107,29 @@ async function D(e) {
|
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
...
|
|
110
|
+
const ve = 300 * 1e3, we = /* @__PURE__ */ new Set([
|
|
111
|
+
m.PENDING_DEPOSITOR_WOTS_PK,
|
|
112
|
+
...L
|
|
113
113
|
]);
|
|
114
|
-
async function
|
|
114
|
+
async function it(e) {
|
|
115
115
|
const {
|
|
116
116
|
statusReader: t,
|
|
117
117
|
wotsSubmitter: r,
|
|
118
118
|
peginTxid: n,
|
|
119
119
|
depositorPk: o,
|
|
120
120
|
wotsPublicKeys: u,
|
|
121
|
-
timeoutMs: a =
|
|
121
|
+
timeoutMs: a = ve,
|
|
122
122
|
signal: i
|
|
123
123
|
} = e;
|
|
124
124
|
i == null || i.throwIfAborted();
|
|
125
|
-
const s = await
|
|
125
|
+
const s = await F({
|
|
126
126
|
statusReader: t,
|
|
127
127
|
peginTxid: n,
|
|
128
|
-
targetStatuses:
|
|
128
|
+
targetStatuses: we,
|
|
129
129
|
timeoutMs: a,
|
|
130
130
|
signal: i
|
|
131
131
|
});
|
|
132
|
-
|
|
132
|
+
L.has(s) || (i == null || i.throwIfAborted(), await r.submitDepositorWotsKey(
|
|
133
133
|
{
|
|
134
134
|
pegin_txid: n,
|
|
135
135
|
depositor_pk: o,
|
|
@@ -139,8 +139,8 @@ async function rt(e) {
|
|
|
139
139
|
));
|
|
140
140
|
}
|
|
141
141
|
const H = 1;
|
|
142
|
-
function
|
|
143
|
-
const r =
|
|
142
|
+
function xe(e, t) {
|
|
143
|
+
const r = p(t).toLowerCase(), o = e.map((u) => p(u).toLowerCase()).filter((u) => u !== r);
|
|
144
144
|
if (o.length === 0)
|
|
145
145
|
throw new Error(
|
|
146
146
|
"Cannot derive localChallengers: vault keeper set is empty (or contains only the depositor)"
|
|
@@ -151,16 +151,16 @@ function be(e, t) {
|
|
|
151
151
|
);
|
|
152
152
|
return o;
|
|
153
153
|
}
|
|
154
|
-
function
|
|
154
|
+
function Ee(e, t, r) {
|
|
155
155
|
const n = r.map(
|
|
156
|
-
(c) =>
|
|
156
|
+
(c) => p(c).toLowerCase()
|
|
157
157
|
), o = t.filter((c) => n.includes(c));
|
|
158
158
|
if (o.length > 0)
|
|
159
159
|
throw new Error(
|
|
160
160
|
`Cannot validate challenger set: vault keepers and universal challengers overlap (${o.join(", ")})`
|
|
161
161
|
);
|
|
162
162
|
const u = [...t, ...n], a = e.map(
|
|
163
|
-
(c) =>
|
|
163
|
+
(c) => p(c.challenger_pubkey).toLowerCase()
|
|
164
164
|
), i = new Set(a);
|
|
165
165
|
if (i.size !== a.length)
|
|
166
166
|
throw new Error(
|
|
@@ -172,36 +172,36 @@ function me(e, t, r) {
|
|
|
172
172
|
"Depositor graph challenger set does not match expected (local ∪ universal)" + (l.length > 0 ? ` (missing: ${l.join(", ")})` : "") + (d.length > 0 ? ` (unexpected: ${d.join(", ")})` : "")
|
|
173
173
|
);
|
|
174
174
|
}
|
|
175
|
-
function
|
|
175
|
+
function Te(e, t) {
|
|
176
176
|
const r = e.ins[t];
|
|
177
|
-
return
|
|
177
|
+
return M(new Uint8Array(r.hash).slice().reverse());
|
|
178
178
|
}
|
|
179
|
-
function
|
|
179
|
+
function R(e, t, r, n, o) {
|
|
180
180
|
const u = e.ins[t];
|
|
181
181
|
if (u.index !== 0)
|
|
182
182
|
throw new Error(
|
|
183
183
|
`NoPayout (challenger ${o}) input ${t} expected to spend ${n} vout 0, got vout ${u.index}`
|
|
184
184
|
);
|
|
185
|
-
const a = r.getId(), i =
|
|
185
|
+
const a = r.getId(), i = Te(e, t);
|
|
186
186
|
if (i !== a)
|
|
187
187
|
throw new Error(
|
|
188
188
|
`NoPayout (challenger ${o}) input ${t} does not reference ${n} (expected txid ${a}, got ${i})`
|
|
189
189
|
);
|
|
190
190
|
}
|
|
191
|
-
async function
|
|
192
|
-
const n = [], o = [], u = [], a =
|
|
191
|
+
async function ke(e, t, r) {
|
|
192
|
+
const n = [], o = [], u = [], a = xe(
|
|
193
193
|
r.vaultKeeperBtcPubkeys,
|
|
194
194
|
r.depositorBtcPubkey
|
|
195
195
|
);
|
|
196
|
-
|
|
196
|
+
Ee(
|
|
197
197
|
e.challenger_presign_data,
|
|
198
198
|
a,
|
|
199
199
|
r.universalChallengerBtcPubkeys
|
|
200
|
-
),
|
|
200
|
+
), le(
|
|
201
201
|
e.payout_tx.tx_hex,
|
|
202
202
|
r.registeredPayoutScriptPubKey
|
|
203
203
|
);
|
|
204
|
-
const i = await
|
|
204
|
+
const i = await ce({
|
|
205
205
|
payoutTxHex: e.payout_tx.tx_hex,
|
|
206
206
|
peginTxHex: r.peginTxHex,
|
|
207
207
|
assertTxHex: e.assert_tx.tx_hex,
|
|
@@ -213,16 +213,16 @@ async function we(e, t, r) {
|
|
|
213
213
|
network: r.network
|
|
214
214
|
});
|
|
215
215
|
n.push(i.psbtHex), o.push(
|
|
216
|
-
|
|
216
|
+
V(
|
|
217
217
|
t,
|
|
218
218
|
H
|
|
219
219
|
)
|
|
220
220
|
);
|
|
221
|
-
const s =
|
|
222
|
-
|
|
221
|
+
const s = p(r.depositorBtcPubkey), l = _.fromHex(
|
|
222
|
+
p(e.assert_tx.tx_hex)
|
|
223
223
|
);
|
|
224
224
|
for (const d of e.challenger_presign_data) {
|
|
225
|
-
const c =
|
|
225
|
+
const c = p(d.challenger_pubkey), h = n.length, P = await _e({
|
|
226
226
|
challenger: d,
|
|
227
227
|
challengerPubkey: c,
|
|
228
228
|
claimerPubkey: s,
|
|
@@ -231,18 +231,18 @@ async function we(e, t, r) {
|
|
|
231
231
|
ctx: r
|
|
232
232
|
});
|
|
233
233
|
n.push(P), o.push(
|
|
234
|
-
|
|
234
|
+
V(
|
|
235
235
|
t,
|
|
236
236
|
H
|
|
237
237
|
)
|
|
238
238
|
), u.push({
|
|
239
239
|
challengerPubkey: c,
|
|
240
|
-
noPayoutIdx:
|
|
240
|
+
noPayoutIdx: h
|
|
241
241
|
});
|
|
242
242
|
}
|
|
243
243
|
return { psbtHexes: n, signOptions: o, challengerEntries: u };
|
|
244
244
|
}
|
|
245
|
-
async function
|
|
245
|
+
async function _e(e) {
|
|
246
246
|
const {
|
|
247
247
|
challenger: t,
|
|
248
248
|
challengerPubkey: r,
|
|
@@ -251,35 +251,35 @@ async function xe(e) {
|
|
|
251
251
|
assertTxParsed: u,
|
|
252
252
|
ctx: a
|
|
253
253
|
} = e;
|
|
254
|
-
|
|
254
|
+
de(
|
|
255
255
|
t.nopayout_tx.tx_hex,
|
|
256
256
|
r,
|
|
257
257
|
a.network
|
|
258
258
|
);
|
|
259
259
|
const i = _.fromHex(
|
|
260
|
-
|
|
260
|
+
p(t.nopayout_tx.tx_hex)
|
|
261
261
|
), s = _.fromHex(
|
|
262
|
-
|
|
262
|
+
p(t.challenge_assert_x_tx.tx_hex)
|
|
263
263
|
), l = _.fromHex(
|
|
264
|
-
|
|
264
|
+
p(t.challenge_assert_y_tx.tx_hex)
|
|
265
265
|
);
|
|
266
266
|
if (i.ins.length !== 3)
|
|
267
267
|
throw new Error(
|
|
268
268
|
`NoPayout (challenger ${r}) must have exactly 3 inputs, got ${i.ins.length}`
|
|
269
269
|
);
|
|
270
|
-
|
|
270
|
+
R(
|
|
271
271
|
i,
|
|
272
272
|
0,
|
|
273
273
|
u,
|
|
274
274
|
"Assert",
|
|
275
275
|
r
|
|
276
|
-
),
|
|
276
|
+
), R(
|
|
277
277
|
i,
|
|
278
278
|
1,
|
|
279
279
|
s,
|
|
280
280
|
"ChallengeAssertX",
|
|
281
281
|
r
|
|
282
|
-
),
|
|
282
|
+
), R(
|
|
283
283
|
i,
|
|
284
284
|
2,
|
|
285
285
|
l,
|
|
@@ -291,10 +291,10 @@ async function xe(e) {
|
|
|
291
291
|
s.outs[0],
|
|
292
292
|
l.outs[0]
|
|
293
293
|
].map((c) => ({
|
|
294
|
-
script_pubkey:
|
|
294
|
+
script_pubkey: M(new Uint8Array(c.script)),
|
|
295
295
|
value: c.value
|
|
296
296
|
}));
|
|
297
|
-
return
|
|
297
|
+
return pe({
|
|
298
298
|
noPayoutTxHex: t.nopayout_tx.tx_hex,
|
|
299
299
|
challengerPubkey: r,
|
|
300
300
|
prevouts: d,
|
|
@@ -308,15 +308,15 @@ async function xe(e) {
|
|
|
308
308
|
}
|
|
309
309
|
});
|
|
310
310
|
}
|
|
311
|
-
function
|
|
312
|
-
|
|
313
|
-
const n =
|
|
311
|
+
function Ce(e, t, r) {
|
|
312
|
+
I(e[0]);
|
|
313
|
+
const n = N(
|
|
314
314
|
e[0].returnedPsbtHex,
|
|
315
315
|
r
|
|
316
316
|
), o = {};
|
|
317
317
|
for (const u of t)
|
|
318
|
-
|
|
319
|
-
nopayout_signature:
|
|
318
|
+
I(e[u.noPayoutIdx]), o[u.challengerPubkey] = {
|
|
319
|
+
nopayout_signature: N(
|
|
320
320
|
e[u.noPayoutIdx].returnedPsbtHex,
|
|
321
321
|
r
|
|
322
322
|
)
|
|
@@ -328,7 +328,7 @@ function Te(e, t, r) {
|
|
|
328
328
|
per_challenger: o
|
|
329
329
|
};
|
|
330
330
|
}
|
|
331
|
-
async function
|
|
331
|
+
async function Se(e, t, r) {
|
|
332
332
|
if (typeof e.signPsbts == "function")
|
|
333
333
|
return e.signPsbts(t, r);
|
|
334
334
|
const n = [];
|
|
@@ -336,15 +336,15 @@ async function ke(e, t, r) {
|
|
|
336
336
|
n.push(await e.signPsbt(t[o], r == null ? void 0 : r[o]));
|
|
337
337
|
return n;
|
|
338
338
|
}
|
|
339
|
-
async function
|
|
340
|
-
const { depositorGraph: t, btcWallet: r, signingContext: n } = e, o = await r.getPublicKeyHex(), { depositorPubkey: u } =
|
|
339
|
+
async function Ae(e) {
|
|
340
|
+
const { depositorGraph: t, btcWallet: r, signingContext: n } = e, o = await r.getPublicKeyHex(), { depositorPubkey: u } = ee(
|
|
341
341
|
o,
|
|
342
|
-
|
|
343
|
-
), { psbtHexes: a, signOptions: i, challengerEntries: s } = await
|
|
342
|
+
p(n.depositorBtcPubkey)
|
|
343
|
+
), { psbtHexes: a, signOptions: i, challengerEntries: s } = await ke(
|
|
344
344
|
t,
|
|
345
345
|
o,
|
|
346
346
|
n
|
|
347
|
-
), l = await
|
|
347
|
+
), l = await Se(
|
|
348
348
|
r,
|
|
349
349
|
a,
|
|
350
350
|
i
|
|
@@ -353,49 +353,78 @@ async function Ee(e) {
|
|
|
353
353
|
throw new Error(
|
|
354
354
|
`Wallet returned ${l.length} signed PSBTs, expected ${a.length}`
|
|
355
355
|
);
|
|
356
|
-
const d = a.map((c,
|
|
356
|
+
const d = a.map((c, h) => ({
|
|
357
357
|
requestedPsbtHex: c,
|
|
358
|
-
returnedPsbtHex: l[
|
|
358
|
+
returnedPsbtHex: l[h]
|
|
359
359
|
}));
|
|
360
|
-
return
|
|
360
|
+
return Ce(
|
|
361
361
|
d,
|
|
362
362
|
s,
|
|
363
363
|
u
|
|
364
364
|
);
|
|
365
365
|
}
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
]),
|
|
372
|
-
|
|
373
|
-
...
|
|
366
|
+
const Be = 1200 * 1e3, X = /* @__PURE__ */ new Set([
|
|
367
|
+
m.PENDING_ACKS,
|
|
368
|
+
m.PENDING_ACTIVATION,
|
|
369
|
+
m.ACTIVATED_PENDING_BROADCAST,
|
|
370
|
+
m.ACTIVATED
|
|
371
|
+
]), Re = /* @__PURE__ */ new Set([
|
|
372
|
+
m.PENDING_DEPOSITOR_SIGNATURES,
|
|
373
|
+
...X
|
|
374
374
|
]);
|
|
375
|
-
function
|
|
375
|
+
function $e(e) {
|
|
376
376
|
return e.map((t) => ({
|
|
377
|
-
claimerPubkeyXOnly:
|
|
377
|
+
claimerPubkeyXOnly: C(t.claimer_pubkey),
|
|
378
378
|
payoutTxHex: t.payout_tx.tx_hex,
|
|
379
379
|
assertTxHex: t.assert_tx.tx_hex
|
|
380
380
|
}));
|
|
381
381
|
}
|
|
382
|
-
function
|
|
383
|
-
|
|
382
|
+
function x(e) {
|
|
383
|
+
return C(e).toLowerCase();
|
|
384
|
+
}
|
|
385
|
+
function Ie(e, t, r, n) {
|
|
386
|
+
const o = x(n), u = [
|
|
387
|
+
x(t),
|
|
388
|
+
...r.map(x)
|
|
389
|
+
], a = new Set(u);
|
|
390
|
+
if (a.size !== u.length)
|
|
391
|
+
throw new Error(
|
|
392
|
+
"Cannot validate claimer set: signing context contains duplicate vault provider or vault keeper key"
|
|
393
|
+
);
|
|
394
|
+
if (a.has(o))
|
|
395
|
+
throw new Error(
|
|
396
|
+
"Cannot validate claimer set: depositor key overlaps with vault provider or vault keeper set"
|
|
397
|
+
);
|
|
398
|
+
const i = e.map(
|
|
399
|
+
(h) => x(h.claimer_pubkey)
|
|
400
|
+
);
|
|
401
|
+
if (new Set(i).size !== i.length)
|
|
402
|
+
throw new Error(
|
|
403
|
+
"Presign response contains duplicate claimer entries"
|
|
404
|
+
);
|
|
405
|
+
const s = i.filter((h) => h !== o), l = new Set(s), d = u.filter((h) => !l.has(h)), c = s.filter((h) => !a.has(h));
|
|
406
|
+
if (d.length > 0 || c.length > 0)
|
|
407
|
+
throw new Error(
|
|
408
|
+
"Presign response claimer set does not match expected (vault provider ∪ vault keepers)" + (d.length > 0 ? ` (missing: ${d.join(", ")})` : "") + (c.length > 0 ? ` (unexpected: ${c.join(", ")})` : "")
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
function Ve(e, t) {
|
|
412
|
+
const r = p(e).toLowerCase(), n = p(
|
|
384
413
|
t.vaultProviderBtcPubkey
|
|
385
|
-
).toLowerCase(), o =
|
|
414
|
+
).toLowerCase(), o = p(
|
|
386
415
|
t.depositorBtcPubkey
|
|
387
416
|
).toLowerCase();
|
|
388
417
|
if (r === n || r === o)
|
|
389
418
|
return t.registeredPayoutScriptPubKey;
|
|
390
419
|
if (!t.vaultKeeperBtcPubkeys.some(
|
|
391
|
-
(a) =>
|
|
420
|
+
(a) => p(a).toLowerCase() === r
|
|
392
421
|
))
|
|
393
422
|
throw new Error(
|
|
394
423
|
`Unknown claimer pubkey ${r}: not VP, depositor, or a registered vault keeper`
|
|
395
424
|
);
|
|
396
|
-
return
|
|
425
|
+
return te(r);
|
|
397
426
|
}
|
|
398
|
-
function
|
|
427
|
+
function O(e, t) {
|
|
399
428
|
return {
|
|
400
429
|
payoutTxHex: e.payoutTxHex,
|
|
401
430
|
peginTxHex: t.peginTxHex,
|
|
@@ -405,14 +434,14 @@ function K(e, t) {
|
|
|
405
434
|
universalChallengerBtcPubkeys: t.universalChallengerBtcPubkeys,
|
|
406
435
|
depositorBtcPubkey: t.depositorBtcPubkey,
|
|
407
436
|
timelockPegin: t.timelockPegin,
|
|
408
|
-
registeredPayoutScriptPubKey:
|
|
437
|
+
registeredPayoutScriptPubKey: Ve(
|
|
409
438
|
e.claimerPubkeyXOnly,
|
|
410
439
|
t
|
|
411
440
|
)
|
|
412
441
|
};
|
|
413
442
|
}
|
|
414
|
-
async function
|
|
415
|
-
const o = new
|
|
443
|
+
async function Ne(e, t, r, n) {
|
|
444
|
+
const o = new ne({
|
|
416
445
|
network: t.network,
|
|
417
446
|
btcWallet: e
|
|
418
447
|
}), u = r.length;
|
|
@@ -420,14 +449,14 @@ async function Be(e, t, r, n) {
|
|
|
420
449
|
let a;
|
|
421
450
|
if (o.supportsBatchSigning())
|
|
422
451
|
a = (await o.signPayoutTransactionsBatch(
|
|
423
|
-
r.map((l) =>
|
|
452
|
+
r.map((l) => O(l, t))
|
|
424
453
|
)).map((l) => l.payoutSignature);
|
|
425
454
|
else {
|
|
426
455
|
a = [];
|
|
427
456
|
for (let s = 0; s < r.length; s++) {
|
|
428
457
|
n == null || n(s, u);
|
|
429
458
|
const l = await o.signPayoutTransaction(
|
|
430
|
-
|
|
459
|
+
O(r[s], t)
|
|
431
460
|
);
|
|
432
461
|
a.push(l.signature);
|
|
433
462
|
}
|
|
@@ -439,7 +468,7 @@ async function Be(e, t, r, n) {
|
|
|
439
468
|
};
|
|
440
469
|
return n == null || n(u, u), i;
|
|
441
470
|
}
|
|
442
|
-
async function
|
|
471
|
+
async function ut(e) {
|
|
443
472
|
const {
|
|
444
473
|
statusReader: t,
|
|
445
474
|
presignClient: r,
|
|
@@ -447,17 +476,17 @@ async function nt(e) {
|
|
|
447
476
|
peginTxid: o,
|
|
448
477
|
depositorPk: u,
|
|
449
478
|
signingContext: a,
|
|
450
|
-
timeoutMs: i =
|
|
479
|
+
timeoutMs: i = Be,
|
|
451
480
|
signal: s,
|
|
452
481
|
onProgress: l
|
|
453
|
-
} = e, d = await
|
|
482
|
+
} = e, d = await F({
|
|
454
483
|
statusReader: t,
|
|
455
484
|
peginTxid: o,
|
|
456
|
-
targetStatuses:
|
|
485
|
+
targetStatuses: Re,
|
|
457
486
|
timeoutMs: i,
|
|
458
487
|
signal: s
|
|
459
488
|
});
|
|
460
|
-
if (
|
|
489
|
+
if (X.has(d))
|
|
461
490
|
return;
|
|
462
491
|
s == null || s.throwIfAborted();
|
|
463
492
|
const c = await r.requestDepositorPresignTransactions(
|
|
@@ -468,16 +497,23 @@ async function nt(e) {
|
|
|
468
497
|
s
|
|
469
498
|
);
|
|
470
499
|
s == null || s.throwIfAborted();
|
|
471
|
-
const
|
|
472
|
-
|
|
473
|
-
|
|
500
|
+
const h = x(u);
|
|
501
|
+
Ie(
|
|
502
|
+
c.txs,
|
|
503
|
+
a.vaultProviderBtcPubkey,
|
|
504
|
+
a.vaultKeeperBtcPubkeys,
|
|
505
|
+
u
|
|
506
|
+
);
|
|
507
|
+
const P = c.txs.filter(
|
|
508
|
+
(v) => x(v.claimer_pubkey) !== h
|
|
509
|
+
), b = $e(P), g = await Ne(
|
|
474
510
|
n,
|
|
475
511
|
a,
|
|
476
|
-
|
|
512
|
+
b,
|
|
477
513
|
l
|
|
478
514
|
);
|
|
479
515
|
s == null || s.throwIfAborted();
|
|
480
|
-
const
|
|
516
|
+
const E = await Ae({
|
|
481
517
|
depositorGraph: c.depositor_graph,
|
|
482
518
|
btcWallet: n,
|
|
483
519
|
signingContext: {
|
|
@@ -495,21 +531,21 @@ async function nt(e) {
|
|
|
495
531
|
}
|
|
496
532
|
});
|
|
497
533
|
s == null || s.throwIfAborted();
|
|
498
|
-
const
|
|
499
|
-
|
|
534
|
+
const y = { ...g };
|
|
535
|
+
y[p(u)] = E.payout_signatures, await r.submitDepositorPresignatures(
|
|
500
536
|
{
|
|
501
537
|
pegin_txid: o,
|
|
502
538
|
depositor_pk: u,
|
|
503
|
-
signatures:
|
|
504
|
-
depositor_claimer_presignatures:
|
|
539
|
+
signatures: y,
|
|
540
|
+
depositor_claimer_presignatures: E
|
|
505
541
|
},
|
|
506
542
|
s
|
|
507
543
|
);
|
|
508
544
|
}
|
|
509
|
-
function
|
|
545
|
+
function He(e) {
|
|
510
546
|
return /^[0-9a-fA-F]{64}$/.test(e);
|
|
511
547
|
}
|
|
512
|
-
function
|
|
548
|
+
function lt(e) {
|
|
513
549
|
const {
|
|
514
550
|
amountSats: t,
|
|
515
551
|
minDeposit: r,
|
|
@@ -520,29 +556,29 @@ function ot(e) {
|
|
|
520
556
|
} = e;
|
|
521
557
|
return !(t <= 0n || t < r || n && n > 0n && t > n || u == null || a == null || t + u + a > o);
|
|
522
558
|
}
|
|
523
|
-
function
|
|
559
|
+
function ct(e, t, r) {
|
|
524
560
|
return e <= 0n ? {
|
|
525
561
|
valid: !1,
|
|
526
562
|
error: "Deposit amount must be greater than zero"
|
|
527
563
|
} : e < t ? {
|
|
528
564
|
valid: !1,
|
|
529
|
-
error: `Minimum deposit is ${
|
|
565
|
+
error: `Minimum deposit is ${w(t)} BTC`
|
|
530
566
|
} : r && r > 0n && e > r ? {
|
|
531
567
|
valid: !1,
|
|
532
|
-
error: `Maximum deposit is ${
|
|
568
|
+
error: `Maximum deposit is ${w(r)} BTC`
|
|
533
569
|
} : { valid: !0 };
|
|
534
570
|
}
|
|
535
|
-
function
|
|
571
|
+
function dt(e) {
|
|
536
572
|
const { amount: t, effectiveRemaining: r } = e;
|
|
537
573
|
return r === null ? { valid: !0 } : r === 0n ? {
|
|
538
574
|
valid: !1,
|
|
539
575
|
error: "Supply cap reached — deposits temporarily paused"
|
|
540
576
|
} : t > r ? {
|
|
541
577
|
valid: !1,
|
|
542
|
-
error: `Vault size exceeds remaining capacity (${
|
|
578
|
+
error: `Vault size exceeds remaining capacity (${w(r)} BTC)`
|
|
543
579
|
} : { valid: !0 };
|
|
544
580
|
}
|
|
545
|
-
function
|
|
581
|
+
function pt(e, t) {
|
|
546
582
|
if (!e || e.length === 0)
|
|
547
583
|
return {
|
|
548
584
|
valid: !1,
|
|
@@ -558,7 +594,7 @@ function it(e, t) {
|
|
|
558
594
|
error: "Invalid vault provider selected"
|
|
559
595
|
} : { valid: !0 };
|
|
560
596
|
}
|
|
561
|
-
function
|
|
597
|
+
function Oe(e, t, r) {
|
|
562
598
|
if (!e || e.length === 0)
|
|
563
599
|
return {
|
|
564
600
|
valid: !1,
|
|
@@ -574,40 +610,40 @@ function Ve(e, t, r) {
|
|
|
574
610
|
if (t && o < t)
|
|
575
611
|
return {
|
|
576
612
|
valid: !1,
|
|
577
|
-
error: `Vault ${n + 1} amount ${
|
|
613
|
+
error: `Vault ${n + 1} amount ${w(o)} BTC is below minimum deposit ${w(t)} BTC`
|
|
578
614
|
};
|
|
579
615
|
if (r && o > r)
|
|
580
616
|
return {
|
|
581
617
|
valid: !1,
|
|
582
|
-
error: `Vault ${n + 1} amount ${
|
|
618
|
+
error: `Vault ${n + 1} amount ${w(o)} BTC exceeds maximum deposit ${w(r)} BTC`
|
|
583
619
|
};
|
|
584
620
|
}
|
|
585
621
|
return { valid: !0 };
|
|
586
622
|
}
|
|
587
|
-
function
|
|
588
|
-
const t =
|
|
589
|
-
return
|
|
623
|
+
function Ke(e) {
|
|
624
|
+
const t = p(e);
|
|
625
|
+
return He(t) ? { valid: !0 } : {
|
|
590
626
|
valid: !1,
|
|
591
627
|
error: "Invalid pubkey format: must be 64 hex characters (32-byte x-only public key, no 0x prefix)"
|
|
592
628
|
};
|
|
593
629
|
}
|
|
594
|
-
function
|
|
630
|
+
function De(e) {
|
|
595
631
|
if (!e || e.length === 0)
|
|
596
632
|
throw new Error(
|
|
597
633
|
"No vault keepers available. The system requires at least one vault keeper to create a deposit."
|
|
598
634
|
);
|
|
599
635
|
}
|
|
600
|
-
function
|
|
636
|
+
function Ue(e) {
|
|
601
637
|
if (!e || e.length === 0)
|
|
602
638
|
throw new Error(
|
|
603
639
|
"No universal challengers available. The system requires at least one universal challenger to create a deposit."
|
|
604
640
|
);
|
|
605
641
|
}
|
|
606
|
-
function
|
|
642
|
+
function Me(e) {
|
|
607
643
|
if (e.length === 0)
|
|
608
644
|
throw new Error("No spendable UTXOs available");
|
|
609
645
|
}
|
|
610
|
-
function
|
|
646
|
+
function ht(e) {
|
|
611
647
|
const {
|
|
612
648
|
vaultAmounts: t,
|
|
613
649
|
confirmedUTXOs: r,
|
|
@@ -616,19 +652,19 @@ function ut(e) {
|
|
|
616
652
|
universalChallengerBtcPubkeys: u,
|
|
617
653
|
minDeposit: a,
|
|
618
654
|
maxDeposit: i
|
|
619
|
-
} = e, s =
|
|
655
|
+
} = e, s = Oe(
|
|
620
656
|
t,
|
|
621
657
|
a,
|
|
622
658
|
i
|
|
623
659
|
);
|
|
624
660
|
if (!s.valid)
|
|
625
661
|
throw new Error(s.error);
|
|
626
|
-
const l =
|
|
662
|
+
const l = Ke(n);
|
|
627
663
|
if (!l.valid)
|
|
628
664
|
throw new Error(l.error);
|
|
629
|
-
|
|
665
|
+
De(o), Ue(u), Me(r);
|
|
630
666
|
}
|
|
631
|
-
async function
|
|
667
|
+
async function ft(e) {
|
|
632
668
|
const {
|
|
633
669
|
vaultRegistryReader: t,
|
|
634
670
|
vaultKeeperReader: r,
|
|
@@ -646,7 +682,7 @@ async function lt(e) {
|
|
|
646
682
|
t.getVaultProviderBtcPubKey(o),
|
|
647
683
|
r.getCurrentVaultKeepersVersion(u),
|
|
648
684
|
n.getLatestUniversalChallengersVersion()
|
|
649
|
-
]), [
|
|
685
|
+
]), [h, P] = await Promise.all([
|
|
650
686
|
r.getVaultKeepersByVersion(
|
|
651
687
|
u,
|
|
652
688
|
d
|
|
@@ -654,42 +690,42 @@ async function lt(e) {
|
|
|
654
690
|
n.getUniversalChallengersByVersion(
|
|
655
691
|
c
|
|
656
692
|
)
|
|
657
|
-
]),
|
|
658
|
-
if (
|
|
693
|
+
]), b = (f) => C(f).toLowerCase(), g = (f) => f.map(b).sort();
|
|
694
|
+
if (b(a) !== l)
|
|
659
695
|
throw new Error(
|
|
660
696
|
`Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${o}. Refresh and try again.`
|
|
661
697
|
);
|
|
662
|
-
const
|
|
663
|
-
|
|
698
|
+
const y = g(i), v = g(
|
|
699
|
+
h.map((f) => f.btcPubKey)
|
|
664
700
|
);
|
|
665
|
-
if (
|
|
701
|
+
if (y.length !== v.length || y.some((f, S) => f !== v[S]))
|
|
666
702
|
throw new Error(
|
|
667
703
|
`Vault keeper BTC pubkeys (v${d}) indexer set does not match ApplicationRegistry on-chain set. Refresh and try again.`
|
|
668
704
|
);
|
|
669
|
-
const
|
|
705
|
+
const T = g(s), k = g(
|
|
670
706
|
P.map((f) => f.btcPubKey)
|
|
671
707
|
);
|
|
672
|
-
if (
|
|
708
|
+
if (T.length !== k.length || T.some((f, S) => f !== k[S]))
|
|
673
709
|
throw new Error(
|
|
674
710
|
`Universal challenger BTC pubkeys (v${c}) indexer set does not match ProtocolParams on-chain set. Refresh and try again.`
|
|
675
711
|
);
|
|
676
712
|
return {
|
|
677
713
|
vaultProviderBtcPubkeyXOnly: l,
|
|
678
|
-
vaultKeeperBtcPubkeysSorted:
|
|
679
|
-
universalChallengerBtcPubkeysSorted:
|
|
714
|
+
vaultKeeperBtcPubkeysSorted: v,
|
|
715
|
+
universalChallengerBtcPubkeysSorted: k,
|
|
680
716
|
expectedAppVaultKeepersVersion: d,
|
|
681
717
|
expectedUniversalChallengersVersion: c
|
|
682
718
|
};
|
|
683
719
|
}
|
|
684
|
-
class
|
|
720
|
+
class z extends Error {
|
|
685
721
|
constructor(t) {
|
|
686
722
|
super(t), this.name = "RegisteredVaultVersionMismatchError";
|
|
687
723
|
}
|
|
688
724
|
}
|
|
689
|
-
function
|
|
690
|
-
return e instanceof
|
|
725
|
+
function gt(e) {
|
|
726
|
+
return e instanceof z || e instanceof Error && e.name === "RegisteredVaultVersionMismatchError";
|
|
691
727
|
}
|
|
692
|
-
async function
|
|
728
|
+
async function Pt(e) {
|
|
693
729
|
const {
|
|
694
730
|
vaultRegistryReader: t,
|
|
695
731
|
vaultIds: r,
|
|
@@ -707,78 +743,78 @@ async function dt(e) {
|
|
|
707
743
|
`vault ${d}: universalChallengers expected v${u}, got v${s.universalChallengersVersion}`
|
|
708
744
|
);
|
|
709
745
|
}), i.length > 0)
|
|
710
|
-
throw new
|
|
746
|
+
throw new z(
|
|
711
747
|
`Aborting BTC broadcast: signer-set or offchain-params versions changed during registration (${i.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
|
|
712
748
|
);
|
|
713
749
|
}
|
|
714
|
-
var
|
|
715
|
-
const
|
|
750
|
+
var G = /* @__PURE__ */ ((e) => (e.CLAIM_EVENT_RECEIVED = "ClaimEventReceived", e.CLAIM_BROADCAST = "ClaimBroadcast", e.ASSERT_BROADCAST = "AssertBroadcast", e.PAYOUT_BROADCAST = "PayoutBroadcast", e.PAYOUT_BLOCKED = "PayoutBlocked", e))(G || {});
|
|
751
|
+
const Le = /* @__PURE__ */ new Set([
|
|
716
752
|
"PayoutBroadcast",
|
|
717
753
|
"PayoutBlocked"
|
|
718
754
|
/* PAYOUT_BLOCKED */
|
|
719
755
|
]);
|
|
720
|
-
function
|
|
721
|
-
return Object.values(
|
|
756
|
+
function yt(e) {
|
|
757
|
+
return Object.values(G).includes(
|
|
722
758
|
e
|
|
723
759
|
);
|
|
724
760
|
}
|
|
725
|
-
function
|
|
726
|
-
return !!e &&
|
|
761
|
+
function mt(e) {
|
|
762
|
+
return !!e && Le.has(e);
|
|
727
763
|
}
|
|
728
|
-
class
|
|
764
|
+
class Fe extends Error {
|
|
729
765
|
constructor(r, n) {
|
|
730
766
|
super(`Refund not yet mature (BIP68 not final): ${n.message}`);
|
|
731
|
-
|
|
732
|
-
|
|
767
|
+
A(this, "vaultId");
|
|
768
|
+
A(this, "cause");
|
|
733
769
|
this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = n;
|
|
734
770
|
}
|
|
735
771
|
}
|
|
736
|
-
const
|
|
737
|
-
function
|
|
772
|
+
const Xe = /^0x[0-9a-fA-F]{64}$/, ze = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, j = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, q = 160, K = 2e3, D = 10n, U = 100n;
|
|
773
|
+
function bt(e) {
|
|
738
774
|
if (!Number.isFinite(e) || e <= 0)
|
|
739
775
|
throw new Error(
|
|
740
776
|
`feeRateSatsVb must be a positive finite number, got ${e}`
|
|
741
777
|
);
|
|
742
|
-
return BigInt(Math.ceil(e *
|
|
778
|
+
return BigInt(Math.ceil(e * q));
|
|
743
779
|
}
|
|
744
|
-
const
|
|
745
|
-
function
|
|
780
|
+
const Ge = 1, je = /non-BIP68-final/i;
|
|
781
|
+
function Q(e, t) {
|
|
746
782
|
if (e.length !== 66)
|
|
747
783
|
throw new Error(
|
|
748
784
|
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
749
785
|
);
|
|
750
|
-
if (!
|
|
786
|
+
if (!Xe.test(e))
|
|
751
787
|
throw new Error(
|
|
752
788
|
`${t} must contain only hex characters after the 0x prefix`
|
|
753
789
|
);
|
|
754
790
|
}
|
|
755
|
-
function
|
|
791
|
+
function $(e, t) {
|
|
756
792
|
if (!Number.isInteger(e) || e < 0)
|
|
757
793
|
throw new Error(`${t} must be a non-negative integer, got ${e}`);
|
|
758
794
|
}
|
|
759
|
-
function
|
|
760
|
-
if (
|
|
795
|
+
function qe(e) {
|
|
796
|
+
if (Q(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout !== 0)
|
|
761
797
|
throw new Error(
|
|
762
798
|
`Multi-vault Pre-PegIn refund is not supported by this SDK call (htlcVout=${e.htlcVout}, expected 0). Refund of batched-deposit vaults requires reconstructing all sibling HTLCs.`
|
|
763
799
|
);
|
|
764
|
-
if (
|
|
800
|
+
if ($(e.offchainParamsVersion, "offchainParamsVersion"), $(e.appVaultKeepersVersion, "appVaultKeepersVersion"), $(
|
|
765
801
|
e.universalChallengersVersion,
|
|
766
802
|
"universalChallengersVersion"
|
|
767
803
|
), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
|
|
768
804
|
throw new Error("unsignedPrePeginTxHex must be a non-empty hex string");
|
|
769
|
-
if (!
|
|
805
|
+
if (!ze.test(e.unsignedPrePeginTxHex))
|
|
770
806
|
throw new Error(
|
|
771
807
|
"unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
|
|
772
808
|
);
|
|
773
|
-
if (!e.depositorBtcPubkey || !
|
|
809
|
+
if (!e.depositorBtcPubkey || !j.test(e.depositorBtcPubkey))
|
|
774
810
|
throw new Error(
|
|
775
811
|
"depositorBtcPubkey must be 32 or 33 bytes of hex (optional 0x prefix)"
|
|
776
812
|
);
|
|
777
813
|
if (typeof e.amount != "bigint" || e.amount <= 0n)
|
|
778
814
|
throw new Error(`amount must be a positive bigint, got ${e.amount}`);
|
|
779
815
|
}
|
|
780
|
-
function
|
|
781
|
-
if (!e.vaultProviderPubkey || !
|
|
816
|
+
function Qe(e) {
|
|
817
|
+
if (!e.vaultProviderPubkey || !j.test(e.vaultProviderPubkey))
|
|
782
818
|
throw new Error("vaultProviderPubkey must be 32 or 33 bytes of hex");
|
|
783
819
|
if (e.vaultKeeperPubkeys.length === 0)
|
|
784
820
|
throw new Error("vaultKeeperPubkeys must be non-empty");
|
|
@@ -799,8 +835,8 @@ function Xe(e) {
|
|
|
799
835
|
`councilQuorum (${e.councilQuorum}) must be in [1, councilSize=${e.councilSize}]`
|
|
800
836
|
);
|
|
801
837
|
}
|
|
802
|
-
function
|
|
803
|
-
const t =
|
|
838
|
+
function We(e) {
|
|
839
|
+
const t = ue.fromHex(e);
|
|
804
840
|
try {
|
|
805
841
|
t.finalizeAllInputs();
|
|
806
842
|
} catch (r) {
|
|
@@ -810,7 +846,7 @@ function ze(e) {
|
|
|
810
846
|
}
|
|
811
847
|
return t.extractTransaction().toHex();
|
|
812
848
|
}
|
|
813
|
-
async function
|
|
849
|
+
async function vt(e) {
|
|
814
850
|
const {
|
|
815
851
|
vaultId: t,
|
|
816
852
|
readVault: r,
|
|
@@ -820,28 +856,36 @@ async function gt(e) {
|
|
|
820
856
|
broadcastTx: a,
|
|
821
857
|
signal: i
|
|
822
858
|
} = e;
|
|
823
|
-
i == null || i.throwIfAborted(),
|
|
859
|
+
i == null || i.throwIfAborted(), Q(t, "vaultId");
|
|
824
860
|
const s = await r();
|
|
825
|
-
|
|
861
|
+
qe(s), i == null || i.throwIfAborted();
|
|
826
862
|
const l = await n(s);
|
|
827
|
-
if (
|
|
863
|
+
if (Qe(l), i == null || i.throwIfAborted(), !Number.isFinite(o) || o <= 0)
|
|
828
864
|
throw new Error(`feeRate must be a positive number, got ${o}`);
|
|
829
|
-
|
|
865
|
+
if (o > K)
|
|
866
|
+
throw new Error(
|
|
867
|
+
`feeRate ${o} sat/vB exceeds refund safety cap ${K} sat/vB; refusing to sign refund.`
|
|
868
|
+
);
|
|
869
|
+
const d = BigInt(Math.ceil(o * q)), c = s.amount * D / U;
|
|
870
|
+
if (d > c)
|
|
871
|
+
throw new Error(
|
|
872
|
+
`Refund fee ${d} sats exceeds the per-vault safety cap of ${c} sats (${D}/${U} of vault.amount=${s.amount}); refusing to sign refund.`
|
|
873
|
+
);
|
|
830
874
|
i == null || i.throwIfAborted();
|
|
831
|
-
const
|
|
875
|
+
const h = C(
|
|
832
876
|
s.depositorBtcPubkey
|
|
833
|
-
),
|
|
834
|
-
if (
|
|
877
|
+
), P = p(s.unsignedPrePeginTxHex), b = 1, g = oe(P);
|
|
878
|
+
if (g !== void 0 && g.vout !== b)
|
|
835
879
|
throw new Error(
|
|
836
|
-
`Multi-vault Pre-PegIn refund is not supported by this SDK call (auth-anchor OP_RETURN at vout ${
|
|
880
|
+
`Multi-vault Pre-PegIn refund is not supported by this SDK call (auth-anchor OP_RETURN at vout ${g.vout}; single-vault refund expects vout ${b}). Refund of batched-deposit vaults requires reconstructing all sibling HTLCs.`
|
|
837
881
|
);
|
|
838
|
-
const
|
|
882
|
+
const E = g == null ? void 0 : g.hash, { psbtHex: y } = await he({
|
|
839
883
|
prePeginParams: {
|
|
840
|
-
depositorPubkey:
|
|
841
|
-
vaultProviderPubkey:
|
|
842
|
-
vaultKeeperPubkeys: l.vaultKeeperPubkeys.map(
|
|
843
|
-
universalChallengerPubkeys: l.universalChallengerPubkeys.map(
|
|
844
|
-
hashlocks: [
|
|
884
|
+
depositorPubkey: h,
|
|
885
|
+
vaultProviderPubkey: p(l.vaultProviderPubkey),
|
|
886
|
+
vaultKeeperPubkeys: l.vaultKeeperPubkeys.map(p),
|
|
887
|
+
universalChallengerPubkeys: l.universalChallengerPubkeys.map(p),
|
|
888
|
+
hashlocks: [p(s.hashlock)],
|
|
845
889
|
timelockRefund: l.timelockRefund,
|
|
846
890
|
pegInAmounts: [s.amount],
|
|
847
891
|
feeRate: l.feeRate,
|
|
@@ -849,57 +893,60 @@ async function gt(e) {
|
|
|
849
893
|
councilQuorum: l.councilQuorum,
|
|
850
894
|
councilSize: l.councilSize,
|
|
851
895
|
network: l.network,
|
|
852
|
-
authAnchorHash:
|
|
896
|
+
authAnchorHash: E
|
|
853
897
|
},
|
|
854
|
-
fundedPrePeginTxHex:
|
|
898
|
+
fundedPrePeginTxHex: P,
|
|
855
899
|
htlcVout: s.htlcVout,
|
|
856
900
|
refundFee: d,
|
|
857
901
|
// buildRefundPsbt's top-level `hashlock` param is documented as "no 0x
|
|
858
902
|
// prefix" and flows into the WASM HTLC connector derivation; a prefixed
|
|
859
903
|
// value would derive the wrong refund script leaf and yield an
|
|
860
904
|
// unspendable PSBT. Match the `hashlocks` array handling above.
|
|
861
|
-
hashlock:
|
|
905
|
+
hashlock: p(s.hashlock)
|
|
862
906
|
});
|
|
863
907
|
i == null || i.throwIfAborted();
|
|
864
|
-
const
|
|
908
|
+
const v = V(
|
|
865
909
|
s.depositorBtcPubkey,
|
|
866
|
-
|
|
867
|
-
),
|
|
868
|
-
|
|
869
|
-
requestedPsbtHex:
|
|
870
|
-
returnedPsbtHex:
|
|
910
|
+
Ge
|
|
911
|
+
), T = await u(y, v);
|
|
912
|
+
I({
|
|
913
|
+
requestedPsbtHex: y,
|
|
914
|
+
returnedPsbtHex: T
|
|
871
915
|
});
|
|
872
|
-
const
|
|
916
|
+
const k = We(T);
|
|
873
917
|
i == null || i.throwIfAborted();
|
|
874
918
|
try {
|
|
875
|
-
return await a(
|
|
876
|
-
} catch (
|
|
877
|
-
throw
|
|
919
|
+
return await a(k);
|
|
920
|
+
} catch (f) {
|
|
921
|
+
throw f instanceof Error && je.test(f.message) ? new Fe(t, f) : f;
|
|
878
922
|
}
|
|
879
923
|
}
|
|
880
924
|
export {
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
925
|
+
Fe as B,
|
|
926
|
+
G as C,
|
|
927
|
+
z as R,
|
|
928
|
+
at as a,
|
|
929
|
+
Ae as b,
|
|
930
|
+
dt as c,
|
|
931
|
+
pt as d,
|
|
932
|
+
Oe as e,
|
|
933
|
+
Ke as f,
|
|
934
|
+
ht as g,
|
|
935
|
+
ft as h,
|
|
936
|
+
lt as i,
|
|
937
|
+
gt as j,
|
|
938
|
+
Pt as k,
|
|
939
|
+
yt as l,
|
|
940
|
+
mt as m,
|
|
941
|
+
vt as n,
|
|
942
|
+
bt as o,
|
|
943
|
+
U as p,
|
|
944
|
+
D as q,
|
|
945
|
+
ut as r,
|
|
946
|
+
it as s,
|
|
947
|
+
K as t,
|
|
948
|
+
q as u,
|
|
949
|
+
ct as v,
|
|
950
|
+
F as w
|
|
904
951
|
};
|
|
905
|
-
//# sourceMappingURL=buildAndBroadcastRefund-
|
|
952
|
+
//# sourceMappingURL=buildAndBroadcastRefund-CjWAle7m.js.map
|