@babylonlabs-io/ts-sdk 0.30.0 → 0.32.0
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-Zrv-ncJi.cjs → PeginManager-CTRPJo8m.cjs} +2 -2
- package/dist/{PeginManager-Zrv-ncJi.cjs.map → PeginManager-CTRPJo8m.cjs.map} +1 -1
- package/dist/{PeginManager-_pamUKlS.js → PeginManager-DUR1BTKM.js} +6 -6
- package/dist/{PeginManager-_pamUKlS.js.map → PeginManager-DUR1BTKM.js.map} +1 -1
- package/dist/{bitcoin-B-Y0DlqR.js → bitcoin-0_T6KJON.js} +32 -28
- package/dist/bitcoin-0_T6KJON.js.map +1 -0
- package/dist/bitcoin-EYBKDtEW.cjs +2 -0
- package/dist/bitcoin-EYBKDtEW.cjs.map +1 -0
- package/dist/buildAndBroadcastRefund-CIHhUmRv.cjs +2 -0
- package/dist/{buildAndBroadcastRefund-CO60ReNf.cjs.map → buildAndBroadcastRefund-CIHhUmRv.cjs.map} +1 -1
- package/dist/{buildAndBroadcastRefund-BY6mYmFl.js → buildAndBroadcastRefund-DwrX_IBf.js} +173 -163
- package/dist/{buildAndBroadcastRefund-BY6mYmFl.js.map → buildAndBroadcastRefund-DwrX_IBf.js.map} +1 -1
- package/dist/challengeAssert-DSlCIBoT.js +304 -0
- package/dist/challengeAssert-DSlCIBoT.js.map +1 -0
- package/dist/challengeAssert-DuhkzZG-.cjs +2 -0
- package/dist/challengeAssert-DuhkzZG-.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +112 -110
- package/dist/{noPayout-CwgYkZYs.cjs → noPayout-CDhbGn_B.cjs} +2 -2
- package/dist/{noPayout-CwgYkZYs.cjs.map → noPayout-CDhbGn_B.cjs.map} +1 -1
- package/dist/{noPayout-B8JiTaYt.js → noPayout-DohtepqZ.js} +2 -2
- package/dist/{noPayout-B8JiTaYt.js.map → noPayout-DohtepqZ.js.map} +1 -1
- package/dist/{psbtInputFields-CB8hqjQ5.cjs → psbtInputFields-BLi7Ta-T.cjs} +2 -2
- package/dist/{psbtInputFields-CB8hqjQ5.cjs.map → psbtInputFields-BLi7Ta-T.cjs.map} +1 -1
- package/dist/{psbtInputFields-DeTFSJOq.js → psbtInputFields-DPCFHgGd.js} +2 -2
- package/dist/{psbtInputFields-DeTFSJOq.js.map → psbtInputFields-DPCFHgGd.js.map} +1 -1
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +112 -110
- package/dist/tbv/core/primitives/index.cjs +1 -1
- package/dist/tbv/core/primitives/index.js +3 -3
- package/dist/tbv/core/primitives/psbt/challengeAssert.d.ts +10 -7
- package/dist/tbv/core/primitives/psbt/challengeAssert.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/constants.d.ts +26 -0
- package/dist/tbv/core/primitives/psbt/constants.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/depositorPayout.d.ts +13 -6
- package/dist/tbv/core/primitives/psbt/depositorPayout.d.ts.map +1 -1
- package/dist/tbv/core/primitives/utils/bitcoin.d.ts +13 -0
- package/dist/tbv/core/primitives/utils/bitcoin.d.ts.map +1 -1
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +21 -19
- package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts +8 -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/core/utils/index.cjs +1 -1
- package/dist/tbv/core/utils/index.js +2 -2
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +112 -110
- package/dist/testing/index.cjs +1 -1
- package/dist/testing/index.js +1 -1
- package/dist/{vault-registry-reader-DdruADqa.cjs → vault-registry-reader-BBS1_AON.cjs} +2 -2
- package/dist/{vault-registry-reader-DdruADqa.cjs.map → vault-registry-reader-BBS1_AON.cjs.map} +1 -1
- package/dist/{vault-registry-reader-BywZhqJL.js → vault-registry-reader-CG6bea1S.js} +2 -2
- package/dist/{vault-registry-reader-BywZhqJL.js.map → vault-registry-reader-CG6bea1S.js.map} +1 -1
- package/package.json +1 -1
- package/dist/bitcoin-B-Y0DlqR.js.map +0 -1
- package/dist/bitcoin-DIN0OupO.cjs +0 -2
- package/dist/bitcoin-DIN0OupO.cjs.map +0 -1
- package/dist/buildAndBroadcastRefund-CO60ReNf.cjs +0 -2
- package/dist/challengeAssert-mYikGC34.js +0 -269
- package/dist/challengeAssert-mYikGC34.js.map +0 -1
- package/dist/challengeAssert-yYFflBOx.cjs +0 -2
- package/dist/challengeAssert-yYFflBOx.cjs.map +0 -1
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var x = (e, t, r) =>
|
|
4
|
-
import { B as
|
|
5
|
-
import { e as
|
|
6
|
-
import { s as
|
|
7
|
-
import * as
|
|
8
|
-
import { Transaction as
|
|
9
|
-
import { Buffer as
|
|
1
|
+
var G = Object.defineProperty;
|
|
2
|
+
var Q = (e, t, r) => t in e ? G(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var x = (e, t, r) => Q(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { B as Y, c as j, a as q, R as J, d as O, D as y } from "./types-CnG3JsRs.js";
|
|
5
|
+
import { e as Z, s as l, u as K, v as H, p as w, f } from "./bitcoin-0_T6KJON.js";
|
|
6
|
+
import { s as ee } from "./sha2-6wN58S6R.js";
|
|
7
|
+
import * as te from "bitcoinjs-lib";
|
|
8
|
+
import { Transaction as m, Psbt as re } from "bitcoinjs-lib";
|
|
9
|
+
import { Buffer as oe } from "buffer";
|
|
10
10
|
import { c as b } from "./signing-BZigafm0.js";
|
|
11
11
|
import "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
12
|
-
import { a as V, c as S, e as v, g as
|
|
12
|
+
import { a as V, c as S, e as v, g as ne, d as se, b as ie } from "./noPayout-DohtepqZ.js";
|
|
13
13
|
const $ = 66;
|
|
14
14
|
function L(e) {
|
|
15
15
|
if (!e.startsWith("0x") && !e.startsWith("0X"))
|
|
@@ -24,7 +24,7 @@ function L(e) {
|
|
|
24
24
|
r[o] = parseInt(t.slice(o * 2, o * 2 + 2), 16);
|
|
25
25
|
return r;
|
|
26
26
|
}
|
|
27
|
-
function
|
|
27
|
+
function ae(e) {
|
|
28
28
|
return `0x${Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("")}`;
|
|
29
29
|
}
|
|
30
30
|
function A(e, t) {
|
|
@@ -33,15 +33,15 @@ function A(e, t) {
|
|
|
33
33
|
`${t} must be exactly 32 bytes (${$} hex chars with 0x prefix), got ${e.length}`
|
|
34
34
|
);
|
|
35
35
|
}
|
|
36
|
-
function
|
|
36
|
+
function ue(e) {
|
|
37
37
|
A(e, "Secret");
|
|
38
|
-
const t = L(e), r =
|
|
39
|
-
return
|
|
38
|
+
const t = L(e), r = ee(t);
|
|
39
|
+
return ae(r);
|
|
40
40
|
}
|
|
41
|
-
function
|
|
42
|
-
return A(e, "Secret"), A(t, "Hashlock"), L(t),
|
|
41
|
+
function ce(e, t) {
|
|
42
|
+
return A(e, "Secret"), A(t, "Hashlock"), L(t), ue(e).toLowerCase() === t.toLowerCase();
|
|
43
43
|
}
|
|
44
|
-
const le = /^0x[0-9a-fA-F]{64}$/,
|
|
44
|
+
const le = /^0x[0-9a-fA-F]{64}$/, de = /^0x[0-9a-fA-F]{40}$/, he = /^0x([0-9a-fA-F]{2})*$/;
|
|
45
45
|
function E(e, t) {
|
|
46
46
|
if (e.length !== 66)
|
|
47
47
|
throw new Error(
|
|
@@ -52,14 +52,14 @@ function E(e, t) {
|
|
|
52
52
|
`${t} must contain only hex characters after the 0x prefix`
|
|
53
53
|
);
|
|
54
54
|
}
|
|
55
|
-
function
|
|
56
|
-
if (!
|
|
55
|
+
function pe(e, t) {
|
|
56
|
+
if (!de.test(e))
|
|
57
57
|
throw new Error(
|
|
58
58
|
`${t} must be a 20-byte 0x-prefixed hex address (42 chars)`
|
|
59
59
|
);
|
|
60
60
|
}
|
|
61
|
-
function
|
|
62
|
-
if (!
|
|
61
|
+
function fe(e, t) {
|
|
62
|
+
if (!he.test(e))
|
|
63
63
|
throw new Error(
|
|
64
64
|
`${t} must be a 0x-prefixed hex string with an even number of hex chars`
|
|
65
65
|
);
|
|
@@ -73,27 +73,27 @@ async function rt(e) {
|
|
|
73
73
|
writeContract: u,
|
|
74
74
|
signal: s
|
|
75
75
|
} = e;
|
|
76
|
-
s == null || s.throwIfAborted(),
|
|
77
|
-
const a =
|
|
78
|
-
if (E(a, "secret"), o !== void 0 && (E(o, "hashlock"), !
|
|
76
|
+
s == null || s.throwIfAborted(), pe(t, "btcVaultRegistryAddress"), E(r, "vaultId");
|
|
77
|
+
const a = Z(e.secret);
|
|
78
|
+
if (E(a, "secret"), o !== void 0 && (E(o, "hashlock"), !ce(a, o)))
|
|
79
79
|
throw new Error(
|
|
80
80
|
"Invalid secret: SHA256(secret) does not match the provided hashlock"
|
|
81
81
|
);
|
|
82
|
-
return
|
|
82
|
+
return fe(i, "activationMetadata"), u({
|
|
83
83
|
address: t,
|
|
84
|
-
abi:
|
|
84
|
+
abi: Y,
|
|
85
85
|
functionName: "activateVaultWithSecret",
|
|
86
86
|
args: [r, a, i]
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
|
-
const
|
|
89
|
+
const ge = 1e4;
|
|
90
90
|
async function D(e) {
|
|
91
91
|
const {
|
|
92
92
|
statusReader: t,
|
|
93
93
|
peginTxid: r,
|
|
94
94
|
targetStatuses: o,
|
|
95
95
|
timeoutMs: i,
|
|
96
|
-
pollIntervalMs: u =
|
|
96
|
+
pollIntervalMs: u = ge,
|
|
97
97
|
signal: s
|
|
98
98
|
} = e, a = Date.now();
|
|
99
99
|
for (; ; ) {
|
|
@@ -106,23 +106,23 @@ async function D(e) {
|
|
|
106
106
|
`Polling timeout after ${i}ms for pegin ${r.slice(0, 8)}… (target: ${[...o].join(", ")})`
|
|
107
107
|
);
|
|
108
108
|
try {
|
|
109
|
-
const
|
|
109
|
+
const c = (await t.getPeginStatus(
|
|
110
110
|
{ pegin_txid: r },
|
|
111
111
|
s
|
|
112
112
|
)).status;
|
|
113
|
-
if (o.has(
|
|
114
|
-
return
|
|
115
|
-
if (
|
|
113
|
+
if (o.has(c))
|
|
114
|
+
return c;
|
|
115
|
+
if (j.has(c) && !o.has(c))
|
|
116
116
|
throw new Error(
|
|
117
|
-
`Pegin ${r.slice(0, 8)}… reached terminal status "${
|
|
117
|
+
`Pegin ${r.slice(0, 8)}… reached terminal status "${c}" while waiting for ${[...o].join(", ")}`
|
|
118
118
|
);
|
|
119
119
|
} catch (n) {
|
|
120
|
-
if (!(n instanceof
|
|
120
|
+
if (!(n instanceof q && n.code === J.NOT_FOUND || n instanceof Error && n.message.includes("PegIn not found")))
|
|
121
121
|
throw n;
|
|
122
122
|
}
|
|
123
|
-
await new Promise((n,
|
|
123
|
+
await new Promise((n, c) => {
|
|
124
124
|
const d = () => {
|
|
125
|
-
clearTimeout(h),
|
|
125
|
+
clearTimeout(h), c(
|
|
126
126
|
new Error(
|
|
127
127
|
`Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...o].join(", ")})`
|
|
128
128
|
)
|
|
@@ -134,7 +134,7 @@ async function D(e) {
|
|
|
134
134
|
});
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
|
-
const
|
|
137
|
+
const Pe = 300 * 1e3, ye = /* @__PURE__ */ new Set([
|
|
138
138
|
y.PENDING_DEPOSITOR_WOTS_PK,
|
|
139
139
|
...O
|
|
140
140
|
]);
|
|
@@ -145,14 +145,14 @@ async function ot(e) {
|
|
|
145
145
|
peginTxid: o,
|
|
146
146
|
depositorPk: i,
|
|
147
147
|
wotsPublicKeys: u,
|
|
148
|
-
timeoutMs: s =
|
|
148
|
+
timeoutMs: s = Pe,
|
|
149
149
|
signal: a
|
|
150
150
|
} = e;
|
|
151
151
|
a == null || a.throwIfAborted();
|
|
152
152
|
const n = await D({
|
|
153
153
|
statusReader: t,
|
|
154
154
|
peginTxid: o,
|
|
155
|
-
targetStatuses:
|
|
155
|
+
targetStatuses: ye,
|
|
156
156
|
timeoutMs: s,
|
|
157
157
|
signal: a
|
|
158
158
|
});
|
|
@@ -166,9 +166,9 @@ async function ot(e) {
|
|
|
166
166
|
));
|
|
167
167
|
}
|
|
168
168
|
const I = 1;
|
|
169
|
-
function
|
|
170
|
-
const o =
|
|
171
|
-
(s) =>
|
|
169
|
+
function be(e, t, r) {
|
|
170
|
+
const o = l(r).toLowerCase(), u = [e, ...t].map(
|
|
171
|
+
(s) => l(s).toLowerCase()
|
|
172
172
|
).filter((s) => s !== o);
|
|
173
173
|
if (u.length === 0)
|
|
174
174
|
throw new Error(
|
|
@@ -176,23 +176,23 @@ function ye(e, t, r) {
|
|
|
176
176
|
);
|
|
177
177
|
return u;
|
|
178
178
|
}
|
|
179
|
-
function
|
|
179
|
+
function xe(e, t) {
|
|
180
180
|
const r = e.ins[t];
|
|
181
181
|
return K(new Uint8Array(r.hash).slice().reverse());
|
|
182
182
|
}
|
|
183
|
-
function
|
|
183
|
+
function B(e, t, r, o, i) {
|
|
184
184
|
const u = e.ins[t];
|
|
185
185
|
if (u.index !== 0)
|
|
186
186
|
throw new Error(
|
|
187
187
|
`NoPayout (challenger ${i}) input ${t} expected to spend ${o} vout 0, got vout ${u.index}`
|
|
188
188
|
);
|
|
189
|
-
const s = r.getId(), a =
|
|
189
|
+
const s = r.getId(), a = xe(e, t);
|
|
190
190
|
if (a !== s)
|
|
191
191
|
throw new Error(
|
|
192
192
|
`NoPayout (challenger ${i}) input ${t} does not reference ${o} (expected txid ${s}, got ${a})`
|
|
193
193
|
);
|
|
194
194
|
}
|
|
195
|
-
async function
|
|
195
|
+
async function me(e, t, r) {
|
|
196
196
|
const o = [], i = [], u = [];
|
|
197
197
|
V(
|
|
198
198
|
e.payout_tx.tx_hex,
|
|
@@ -215,20 +215,20 @@ async function xe(e, t, r) {
|
|
|
215
215
|
I
|
|
216
216
|
)
|
|
217
217
|
);
|
|
218
|
-
const a =
|
|
218
|
+
const a = be(
|
|
219
219
|
r.vaultProviderBtcPubkey,
|
|
220
220
|
r.vaultKeeperBtcPubkeys,
|
|
221
221
|
r.depositorBtcPubkey
|
|
222
|
-
), n =
|
|
223
|
-
|
|
222
|
+
), n = l(r.depositorBtcPubkey), c = m.fromHex(
|
|
223
|
+
l(e.assert_tx.tx_hex)
|
|
224
224
|
);
|
|
225
225
|
for (const d of e.challenger_presign_data) {
|
|
226
|
-
const h =
|
|
226
|
+
const h = l(d.challenger_pubkey), g = o.length, P = await we({
|
|
227
227
|
challenger: d,
|
|
228
228
|
challengerPubkey: h,
|
|
229
229
|
claimerPubkey: n,
|
|
230
230
|
localChallengers: a,
|
|
231
|
-
assertTxParsed:
|
|
231
|
+
assertTxParsed: c,
|
|
232
232
|
ctx: r
|
|
233
233
|
});
|
|
234
234
|
o.push(P), i.push(
|
|
@@ -252,50 +252,50 @@ async function we(e) {
|
|
|
252
252
|
assertTxParsed: u,
|
|
253
253
|
ctx: s
|
|
254
254
|
} = e;
|
|
255
|
-
|
|
255
|
+
ne(
|
|
256
256
|
t.nopayout_tx.tx_hex,
|
|
257
257
|
r,
|
|
258
258
|
s.network
|
|
259
259
|
);
|
|
260
|
-
const a =
|
|
261
|
-
|
|
262
|
-
), n =
|
|
263
|
-
|
|
264
|
-
),
|
|
265
|
-
|
|
260
|
+
const a = m.fromHex(
|
|
261
|
+
l(t.nopayout_tx.tx_hex)
|
|
262
|
+
), n = m.fromHex(
|
|
263
|
+
l(t.challenge_assert_x_tx.tx_hex)
|
|
264
|
+
), c = m.fromHex(
|
|
265
|
+
l(t.challenge_assert_y_tx.tx_hex)
|
|
266
266
|
);
|
|
267
267
|
if (a.ins.length !== 3)
|
|
268
268
|
throw new Error(
|
|
269
269
|
`NoPayout (challenger ${r}) must have exactly 3 inputs, got ${a.ins.length}`
|
|
270
270
|
);
|
|
271
|
-
|
|
271
|
+
B(
|
|
272
272
|
a,
|
|
273
273
|
0,
|
|
274
274
|
u,
|
|
275
275
|
"Assert",
|
|
276
276
|
r
|
|
277
|
-
),
|
|
277
|
+
), B(
|
|
278
278
|
a,
|
|
279
279
|
1,
|
|
280
280
|
n,
|
|
281
281
|
"ChallengeAssertX",
|
|
282
282
|
r
|
|
283
|
-
),
|
|
283
|
+
), B(
|
|
284
284
|
a,
|
|
285
285
|
2,
|
|
286
|
-
|
|
286
|
+
c,
|
|
287
287
|
"ChallengeAssertY",
|
|
288
288
|
r
|
|
289
289
|
);
|
|
290
290
|
const d = [
|
|
291
291
|
u.outs[0],
|
|
292
292
|
n.outs[0],
|
|
293
|
-
|
|
293
|
+
c.outs[0]
|
|
294
294
|
].map((h) => ({
|
|
295
295
|
script_pubkey: K(new Uint8Array(h.script)),
|
|
296
296
|
value: h.value
|
|
297
297
|
}));
|
|
298
|
-
return
|
|
298
|
+
return se({
|
|
299
299
|
noPayoutTxHex: t.nopayout_tx.tx_hex,
|
|
300
300
|
challengerPubkey: r,
|
|
301
301
|
prevouts: d,
|
|
@@ -309,7 +309,7 @@ async function we(e) {
|
|
|
309
309
|
}
|
|
310
310
|
});
|
|
311
311
|
}
|
|
312
|
-
function
|
|
312
|
+
function ve(e, t, r) {
|
|
313
313
|
const o = v(
|
|
314
314
|
e[0],
|
|
315
315
|
r
|
|
@@ -328,7 +328,7 @@ function me(e, t, r) {
|
|
|
328
328
|
per_challenger: i
|
|
329
329
|
};
|
|
330
330
|
}
|
|
331
|
-
async function
|
|
331
|
+
async function ke(e, t, r) {
|
|
332
332
|
if (typeof e.signPsbts == "function")
|
|
333
333
|
return e.signPsbts(t, r);
|
|
334
334
|
const o = [];
|
|
@@ -336,27 +336,27 @@ async function ve(e, t, r) {
|
|
|
336
336
|
o.push(await e.signPsbt(t[i], r == null ? void 0 : r[i]));
|
|
337
337
|
return o;
|
|
338
338
|
}
|
|
339
|
-
async function
|
|
340
|
-
const { depositorGraph: t, btcWallet: r, signingContext: o } = e, i =
|
|
339
|
+
async function Te(e) {
|
|
340
|
+
const { depositorGraph: t, btcWallet: r, signingContext: o } = e, i = l(o.depositorBtcPubkey), u = await r.getPublicKeyHex(), { psbtHexes: s, signOptions: a, challengerEntries: n } = await me(
|
|
341
341
|
t,
|
|
342
342
|
u,
|
|
343
343
|
o
|
|
344
|
-
),
|
|
344
|
+
), c = await ke(
|
|
345
345
|
r,
|
|
346
346
|
s,
|
|
347
347
|
a
|
|
348
348
|
);
|
|
349
|
-
if (
|
|
349
|
+
if (c.length !== s.length)
|
|
350
350
|
throw new Error(
|
|
351
|
-
`Wallet returned ${
|
|
351
|
+
`Wallet returned ${c.length} signed PSBTs, expected ${s.length}`
|
|
352
352
|
);
|
|
353
|
-
return
|
|
354
|
-
|
|
353
|
+
return ve(
|
|
354
|
+
c,
|
|
355
355
|
n,
|
|
356
356
|
i
|
|
357
357
|
);
|
|
358
358
|
}
|
|
359
|
-
class
|
|
359
|
+
class Ee {
|
|
360
360
|
/**
|
|
361
361
|
* Creates a new PayoutManager instance.
|
|
362
362
|
*
|
|
@@ -451,16 +451,16 @@ class Te {
|
|
|
451
451
|
n.payoutTxHex,
|
|
452
452
|
n.registeredPayoutScriptPubKey
|
|
453
453
|
);
|
|
454
|
-
const { depositorPubkey:
|
|
454
|
+
const { depositorPubkey: c } = H(
|
|
455
455
|
r,
|
|
456
456
|
n.depositorBtcPubkey
|
|
457
457
|
);
|
|
458
|
-
u.push(
|
|
458
|
+
u.push(c);
|
|
459
459
|
const d = await S({
|
|
460
460
|
payoutTxHex: n.payoutTxHex,
|
|
461
461
|
peginTxHex: n.peginTxHex,
|
|
462
462
|
assertTxHex: n.assertTxHex,
|
|
463
|
-
depositorBtcPubkey:
|
|
463
|
+
depositorBtcPubkey: c,
|
|
464
464
|
vaultProviderBtcPubkey: n.vaultProviderBtcPubkey,
|
|
465
465
|
vaultKeeperBtcPubkeys: n.vaultKeeperBtcPubkeys,
|
|
466
466
|
universalChallengerBtcPubkeys: n.universalChallengerBtcPubkeys,
|
|
@@ -479,13 +479,13 @@ class Te {
|
|
|
479
479
|
);
|
|
480
480
|
const a = [];
|
|
481
481
|
for (let n = 0; n < t.length; n++) {
|
|
482
|
-
const
|
|
482
|
+
const c = u[n], d = v(
|
|
483
483
|
s[n],
|
|
484
|
-
|
|
484
|
+
c
|
|
485
485
|
);
|
|
486
486
|
a.push({
|
|
487
487
|
payoutSignature: d,
|
|
488
|
-
depositorBtcPubkey:
|
|
488
|
+
depositorBtcPubkey: c
|
|
489
489
|
});
|
|
490
490
|
}
|
|
491
491
|
return a;
|
|
@@ -511,7 +511,7 @@ class Te {
|
|
|
511
511
|
);
|
|
512
512
|
}
|
|
513
513
|
}
|
|
514
|
-
const
|
|
514
|
+
const Be = 1200 * 1e3, M = /* @__PURE__ */ new Set([
|
|
515
515
|
y.PENDING_ACKS,
|
|
516
516
|
y.PENDING_ACTIVATION,
|
|
517
517
|
y.ACTIVATED
|
|
@@ -519,36 +519,36 @@ const Ee = 1200 * 1e3, M = /* @__PURE__ */ new Set([
|
|
|
519
519
|
y.PENDING_DEPOSITOR_SIGNATURES,
|
|
520
520
|
...M
|
|
521
521
|
]);
|
|
522
|
-
function
|
|
522
|
+
function Se(e) {
|
|
523
523
|
return e.map((t) => ({
|
|
524
|
-
claimerPubkeyXOnly:
|
|
524
|
+
claimerPubkeyXOnly: w(t.claimer_pubkey),
|
|
525
525
|
payoutTxHex: t.payout_tx.tx_hex,
|
|
526
526
|
assertTxHex: t.assert_tx.tx_hex
|
|
527
527
|
}));
|
|
528
528
|
}
|
|
529
|
-
function
|
|
530
|
-
const { output: t } =
|
|
531
|
-
internalPubkey:
|
|
529
|
+
function Ae(e) {
|
|
530
|
+
const { output: t } = te.payments.p2tr({
|
|
531
|
+
internalPubkey: oe.from(e, "hex")
|
|
532
532
|
});
|
|
533
533
|
if (!t)
|
|
534
534
|
throw new Error("Failed to derive BIP-86 P2TR scriptPubKey");
|
|
535
535
|
return t.toString("hex");
|
|
536
536
|
}
|
|
537
|
-
function
|
|
538
|
-
const r =
|
|
537
|
+
function Ce(e, t) {
|
|
538
|
+
const r = l(e).toLowerCase(), o = l(
|
|
539
539
|
t.vaultProviderBtcPubkey
|
|
540
|
-
).toLowerCase(), i =
|
|
540
|
+
).toLowerCase(), i = l(
|
|
541
541
|
t.depositorBtcPubkey
|
|
542
542
|
).toLowerCase();
|
|
543
543
|
if (r === o || r === i)
|
|
544
544
|
return t.registeredPayoutScriptPubKey;
|
|
545
545
|
if (!t.vaultKeeperBtcPubkeys.some(
|
|
546
|
-
(a) =>
|
|
546
|
+
(a) => l(a).toLowerCase() === r
|
|
547
547
|
))
|
|
548
548
|
throw new Error(
|
|
549
549
|
`Unknown claimer pubkey ${r}: not VP, depositor, or a registered vault keeper`
|
|
550
550
|
);
|
|
551
|
-
return `0x${
|
|
551
|
+
return `0x${Ae(r)}`;
|
|
552
552
|
}
|
|
553
553
|
function R(e, t) {
|
|
554
554
|
return {
|
|
@@ -560,14 +560,14 @@ function R(e, t) {
|
|
|
560
560
|
universalChallengerBtcPubkeys: t.universalChallengerBtcPubkeys,
|
|
561
561
|
depositorBtcPubkey: t.depositorBtcPubkey,
|
|
562
562
|
timelockPegin: t.timelockPegin,
|
|
563
|
-
registeredPayoutScriptPubKey:
|
|
563
|
+
registeredPayoutScriptPubKey: Ce(
|
|
564
564
|
e.claimerPubkeyXOnly,
|
|
565
565
|
t
|
|
566
566
|
)
|
|
567
567
|
};
|
|
568
568
|
}
|
|
569
|
-
async function
|
|
570
|
-
const i = new
|
|
569
|
+
async function He(e, t, r, o) {
|
|
570
|
+
const i = new Ee({
|
|
571
571
|
network: t.network,
|
|
572
572
|
btcWallet: e
|
|
573
573
|
}), u = r.length;
|
|
@@ -575,16 +575,16 @@ async function Ce(e, t, r, o) {
|
|
|
575
575
|
let s;
|
|
576
576
|
if (i.supportsBatchSigning())
|
|
577
577
|
s = (await i.signPayoutTransactionsBatch(
|
|
578
|
-
r.map((
|
|
579
|
-
)).map((
|
|
578
|
+
r.map((c) => R(c, t))
|
|
579
|
+
)).map((c) => c.payoutSignature);
|
|
580
580
|
else {
|
|
581
581
|
s = [];
|
|
582
582
|
for (let n = 0; n < r.length; n++) {
|
|
583
583
|
o == null || o(n, u);
|
|
584
|
-
const
|
|
584
|
+
const c = await i.signPayoutTransaction(
|
|
585
585
|
R(r[n], t)
|
|
586
586
|
);
|
|
587
|
-
s.push(
|
|
587
|
+
s.push(c.signature);
|
|
588
588
|
}
|
|
589
589
|
}
|
|
590
590
|
const a = {};
|
|
@@ -602,9 +602,9 @@ async function nt(e) {
|
|
|
602
602
|
peginTxid: i,
|
|
603
603
|
depositorPk: u,
|
|
604
604
|
signingContext: s,
|
|
605
|
-
timeoutMs: a =
|
|
605
|
+
timeoutMs: a = Be,
|
|
606
606
|
signal: n,
|
|
607
|
-
onProgress:
|
|
607
|
+
onProgress: c
|
|
608
608
|
} = e, d = await D({
|
|
609
609
|
statusReader: t,
|
|
610
610
|
peginTxid: i,
|
|
@@ -623,16 +623,16 @@ async function nt(e) {
|
|
|
623
623
|
n
|
|
624
624
|
);
|
|
625
625
|
n == null || n.throwIfAborted();
|
|
626
|
-
const g =
|
|
627
|
-
(
|
|
628
|
-
), k =
|
|
626
|
+
const g = w(u), P = h.txs.filter(
|
|
627
|
+
(z) => w(z.claimer_pubkey) !== g
|
|
628
|
+
), k = Se(P), T = await He(
|
|
629
629
|
o,
|
|
630
630
|
s,
|
|
631
631
|
k,
|
|
632
|
-
|
|
632
|
+
c
|
|
633
633
|
);
|
|
634
634
|
n == null || n.throwIfAborted();
|
|
635
|
-
const p = await
|
|
635
|
+
const p = await Te({
|
|
636
636
|
depositorGraph: h.depositor_graph,
|
|
637
637
|
btcWallet: o,
|
|
638
638
|
signingContext: {
|
|
@@ -651,7 +651,7 @@ async function nt(e) {
|
|
|
651
651
|
});
|
|
652
652
|
n == null || n.throwIfAborted();
|
|
653
653
|
const C = { ...T };
|
|
654
|
-
C[
|
|
654
|
+
C[l(u)] = p.payout_signatures, await r.submitDepositorPresignatures(
|
|
655
655
|
{
|
|
656
656
|
pegin_txid: i,
|
|
657
657
|
depositor_pk: u,
|
|
@@ -661,7 +661,7 @@ async function nt(e) {
|
|
|
661
661
|
n
|
|
662
662
|
);
|
|
663
663
|
}
|
|
664
|
-
function
|
|
664
|
+
function $e(e) {
|
|
665
665
|
return /^[0-9a-fA-F]{64}$/.test(e);
|
|
666
666
|
}
|
|
667
667
|
function st(e) {
|
|
@@ -713,7 +713,7 @@ function ut(e, t) {
|
|
|
713
713
|
error: "Invalid vault provider selected"
|
|
714
714
|
} : { valid: !0 };
|
|
715
715
|
}
|
|
716
|
-
function
|
|
716
|
+
function Ie(e, t, r) {
|
|
717
717
|
if (!e || e.length === 0)
|
|
718
718
|
return {
|
|
719
719
|
valid: !1,
|
|
@@ -739,30 +739,30 @@ function $e(e, t, r) {
|
|
|
739
739
|
}
|
|
740
740
|
return { valid: !0 };
|
|
741
741
|
}
|
|
742
|
-
function
|
|
743
|
-
const t =
|
|
744
|
-
return
|
|
742
|
+
function Re(e) {
|
|
743
|
+
const t = l(e);
|
|
744
|
+
return $e(t) ? { valid: !0 } : {
|
|
745
745
|
valid: !1,
|
|
746
746
|
error: "Invalid pubkey format: must be 64 hex characters (32-byte x-only public key, no 0x prefix)"
|
|
747
747
|
};
|
|
748
748
|
}
|
|
749
|
-
function
|
|
749
|
+
function Ne(e) {
|
|
750
750
|
if (!e || e.length === 0)
|
|
751
751
|
throw new Error(
|
|
752
752
|
"No vault keepers available. The system requires at least one vault keeper to create a deposit."
|
|
753
753
|
);
|
|
754
754
|
}
|
|
755
|
-
function
|
|
755
|
+
function Oe(e) {
|
|
756
756
|
if (!e || e.length === 0)
|
|
757
757
|
throw new Error(
|
|
758
758
|
"No universal challengers available. The system requires at least one universal challenger to create a deposit."
|
|
759
759
|
);
|
|
760
760
|
}
|
|
761
|
-
function
|
|
761
|
+
function Ke(e) {
|
|
762
762
|
if (e.length === 0)
|
|
763
763
|
throw new Error("No spendable UTXOs available");
|
|
764
764
|
}
|
|
765
|
-
function
|
|
765
|
+
function ct(e) {
|
|
766
766
|
const {
|
|
767
767
|
vaultAmounts: t,
|
|
768
768
|
confirmedUTXOs: r,
|
|
@@ -771,33 +771,33 @@ function lt(e) {
|
|
|
771
771
|
universalChallengerBtcPubkeys: u,
|
|
772
772
|
minDeposit: s,
|
|
773
773
|
maxDeposit: a
|
|
774
|
-
} = e, n =
|
|
774
|
+
} = e, n = Ie(
|
|
775
775
|
t,
|
|
776
776
|
s,
|
|
777
777
|
a
|
|
778
778
|
);
|
|
779
779
|
if (!n.valid)
|
|
780
780
|
throw new Error(n.error);
|
|
781
|
-
const
|
|
782
|
-
if (!
|
|
783
|
-
throw new Error(
|
|
784
|
-
|
|
781
|
+
const c = Re(o);
|
|
782
|
+
if (!c.valid)
|
|
783
|
+
throw new Error(c.error);
|
|
784
|
+
Ne(i), Oe(u), Ke(r);
|
|
785
785
|
}
|
|
786
786
|
var U = /* @__PURE__ */ ((e) => (e.CLAIM_EVENT_RECEIVED = "ClaimEventReceived", e.CLAIM_BROADCAST = "ClaimBroadcast", e.ASSERT_BROADCAST = "AssertBroadcast", e.CHALLENGE_ASSERT_OBSERVED = "ChallengeAssertObserved", e.WRONGLY_CHALLENGED_BROADCAST = "WronglyChallengedBroadcast", e.PAYOUT_BROADCAST = "PayoutBroadcast", e.FAILED = "Failed", e))(U || {});
|
|
787
|
-
const
|
|
787
|
+
const Ve = /* @__PURE__ */ new Set([
|
|
788
788
|
"PayoutBroadcast",
|
|
789
789
|
"Failed"
|
|
790
790
|
/* FAILED */
|
|
791
791
|
]);
|
|
792
|
-
function
|
|
792
|
+
function lt(e) {
|
|
793
793
|
return Object.values(U).includes(
|
|
794
794
|
e
|
|
795
795
|
);
|
|
796
796
|
}
|
|
797
797
|
function dt(e) {
|
|
798
|
-
return !!e &&
|
|
798
|
+
return !!e && Ve.has(e);
|
|
799
799
|
}
|
|
800
|
-
class
|
|
800
|
+
class Le extends Error {
|
|
801
801
|
constructor(r, o) {
|
|
802
802
|
super(`Refund not yet mature (BIP68 not final): ${o.message}`);
|
|
803
803
|
x(this, "vaultId");
|
|
@@ -805,32 +805,40 @@ class Ve extends Error {
|
|
|
805
805
|
this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = o;
|
|
806
806
|
}
|
|
807
807
|
}
|
|
808
|
-
const
|
|
809
|
-
function
|
|
808
|
+
const De = /^0x[0-9a-fA-F]{64}$/, Me = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, F = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, W = 160;
|
|
809
|
+
function ht(e) {
|
|
810
|
+
if (!Number.isFinite(e) || e <= 0)
|
|
811
|
+
throw new Error(
|
|
812
|
+
`feeRateSatsVb must be a positive finite number, got ${e}`
|
|
813
|
+
);
|
|
814
|
+
return BigInt(Math.ceil(e * W));
|
|
815
|
+
}
|
|
816
|
+
const Ue = 1, N = 65535, Fe = /non-BIP68-final/i;
|
|
817
|
+
function X(e, t) {
|
|
810
818
|
if (e.length !== 66)
|
|
811
819
|
throw new Error(
|
|
812
820
|
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
813
821
|
);
|
|
814
|
-
if (!
|
|
822
|
+
if (!De.test(e))
|
|
815
823
|
throw new Error(
|
|
816
824
|
`${t} must contain only hex characters after the 0x prefix`
|
|
817
825
|
);
|
|
818
826
|
}
|
|
819
|
-
function
|
|
827
|
+
function _(e, t) {
|
|
820
828
|
if (!Number.isInteger(e) || e < 0)
|
|
821
829
|
throw new Error(`${t} must be a non-negative integer, got ${e}`);
|
|
822
830
|
}
|
|
823
831
|
function We(e) {
|
|
824
|
-
if (
|
|
832
|
+
if (X(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0 || e.htlcVout > N)
|
|
825
833
|
throw new Error(
|
|
826
834
|
`htlcVout must be an integer 0-${N}, got ${e.htlcVout}`
|
|
827
835
|
);
|
|
828
|
-
if (
|
|
836
|
+
if (_(e.offchainParamsVersion, "offchainParamsVersion"), _(e.appVaultKeepersVersion, "appVaultKeepersVersion"), _(
|
|
829
837
|
e.universalChallengersVersion,
|
|
830
838
|
"universalChallengersVersion"
|
|
831
839
|
), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
|
|
832
840
|
throw new Error("unsignedPrePeginTxHex must be a non-empty hex string");
|
|
833
|
-
if (!
|
|
841
|
+
if (!Me.test(e.unsignedPrePeginTxHex))
|
|
834
842
|
throw new Error(
|
|
835
843
|
"unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
|
|
836
844
|
);
|
|
@@ -864,7 +872,7 @@ function Xe(e) {
|
|
|
864
872
|
);
|
|
865
873
|
}
|
|
866
874
|
function ze(e) {
|
|
867
|
-
const t =
|
|
875
|
+
const t = re.fromHex(e);
|
|
868
876
|
try {
|
|
869
877
|
t.finalizeAllInputs();
|
|
870
878
|
} catch (r) {
|
|
@@ -874,7 +882,7 @@ function ze(e) {
|
|
|
874
882
|
}
|
|
875
883
|
return t.extractTransaction().toHex();
|
|
876
884
|
}
|
|
877
|
-
async function
|
|
885
|
+
async function pt(e) {
|
|
878
886
|
const {
|
|
879
887
|
vaultId: t,
|
|
880
888
|
readVault: r,
|
|
@@ -884,39 +892,39 @@ async function ht(e) {
|
|
|
884
892
|
broadcastTx: s,
|
|
885
893
|
signal: a
|
|
886
894
|
} = e;
|
|
887
|
-
a == null || a.throwIfAborted(),
|
|
895
|
+
a == null || a.throwIfAborted(), X(t, "vaultId");
|
|
888
896
|
const n = await r();
|
|
889
897
|
We(n), a == null || a.throwIfAborted();
|
|
890
|
-
const
|
|
891
|
-
if (Xe(
|
|
898
|
+
const c = await o(n);
|
|
899
|
+
if (Xe(c), a == null || a.throwIfAborted(), !Number.isFinite(i) || i <= 0)
|
|
892
900
|
throw new Error(`feeRate must be a positive number, got ${i}`);
|
|
893
|
-
const d = BigInt(Math.ceil(i *
|
|
901
|
+
const d = BigInt(Math.ceil(i * W));
|
|
894
902
|
a == null || a.throwIfAborted();
|
|
895
|
-
const h =
|
|
903
|
+
const h = w(
|
|
896
904
|
n.depositorBtcPubkey
|
|
897
|
-
), { psbtHex: g } = await
|
|
905
|
+
), { psbtHex: g } = await ie({
|
|
898
906
|
prePeginParams: {
|
|
899
907
|
depositorPubkey: h,
|
|
900
|
-
vaultProviderPubkey: c
|
|
901
|
-
vaultKeeperPubkeys:
|
|
902
|
-
universalChallengerPubkeys:
|
|
903
|
-
hashlocks: [
|
|
904
|
-
timelockRefund:
|
|
908
|
+
vaultProviderPubkey: l(c.vaultProviderPubkey),
|
|
909
|
+
vaultKeeperPubkeys: c.vaultKeeperPubkeys.map(l),
|
|
910
|
+
universalChallengerPubkeys: c.universalChallengerPubkeys.map(l),
|
|
911
|
+
hashlocks: [l(n.hashlock)],
|
|
912
|
+
timelockRefund: c.timelockRefund,
|
|
905
913
|
pegInAmounts: [n.amount],
|
|
906
|
-
feeRate:
|
|
907
|
-
numLocalChallengers:
|
|
908
|
-
councilQuorum:
|
|
909
|
-
councilSize:
|
|
910
|
-
network:
|
|
914
|
+
feeRate: c.feeRate,
|
|
915
|
+
numLocalChallengers: c.numLocalChallengers,
|
|
916
|
+
councilQuorum: c.councilQuorum,
|
|
917
|
+
councilSize: c.councilSize,
|
|
918
|
+
network: c.network
|
|
911
919
|
},
|
|
912
|
-
fundedPrePeginTxHex:
|
|
920
|
+
fundedPrePeginTxHex: l(n.unsignedPrePeginTxHex),
|
|
913
921
|
htlcVout: n.htlcVout,
|
|
914
922
|
refundFee: d,
|
|
915
923
|
// buildRefundPsbt's top-level `hashlock` param is documented as "no 0x
|
|
916
924
|
// prefix" and flows into the WASM HTLC connector derivation; a prefixed
|
|
917
925
|
// value would derive the wrong refund script leaf and yield an
|
|
918
926
|
// unspendable PSBT. Match the `hashlocks` array handling above.
|
|
919
|
-
hashlock:
|
|
927
|
+
hashlock: l(n.hashlock)
|
|
920
928
|
});
|
|
921
929
|
a == null || a.throwIfAborted();
|
|
922
930
|
const P = b(
|
|
@@ -927,29 +935,31 @@ async function ht(e) {
|
|
|
927
935
|
try {
|
|
928
936
|
return await s(T);
|
|
929
937
|
} catch (p) {
|
|
930
|
-
throw p instanceof Error && Fe.test(p.message) ? new
|
|
938
|
+
throw p instanceof Error && Fe.test(p.message) ? new Le(t, p) : p;
|
|
931
939
|
}
|
|
932
940
|
}
|
|
933
941
|
export {
|
|
934
|
-
|
|
942
|
+
Le as B,
|
|
935
943
|
U as C,
|
|
936
|
-
|
|
944
|
+
Ee as P,
|
|
945
|
+
W as R,
|
|
937
946
|
rt as a,
|
|
938
|
-
|
|
947
|
+
Te as b,
|
|
939
948
|
at as c,
|
|
940
949
|
ut as d,
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
950
|
+
Ie as e,
|
|
951
|
+
Re as f,
|
|
952
|
+
ct as g,
|
|
953
|
+
ue as h,
|
|
945
954
|
st as i,
|
|
946
|
-
|
|
947
|
-
|
|
955
|
+
ce as j,
|
|
956
|
+
lt as k,
|
|
948
957
|
dt as l,
|
|
949
|
-
|
|
958
|
+
pt as m,
|
|
959
|
+
ht as n,
|
|
950
960
|
nt as p,
|
|
951
961
|
ot as s,
|
|
952
962
|
it as v,
|
|
953
963
|
D as w
|
|
954
964
|
};
|
|
955
|
-
//# sourceMappingURL=buildAndBroadcastRefund-
|
|
965
|
+
//# sourceMappingURL=buildAndBroadcastRefund-DwrX_IBf.js.map
|