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