@babylonlabs-io/ts-sdk 0.71.2 → 0.72.1
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-Bn8FxM35.cjs → PeginManager-Bwjqb0_6.cjs} +2 -2
- package/dist/{PeginManager-Bn8FxM35.cjs.map → PeginManager-Bwjqb0_6.cjs.map} +1 -1
- package/dist/{PeginManager-C3ojNTlv.js → PeginManager-DjatPUPS.js} +2 -2
- package/dist/{PeginManager-C3ojNTlv.js.map → PeginManager-DjatPUPS.js.map} +1 -1
- package/dist/buildAndBroadcastReclaim-HX2xQlbM.cjs +2 -0
- package/dist/buildAndBroadcastReclaim-HX2xQlbM.cjs.map +1 -0
- package/dist/{buildAndBroadcastReclaim-YvWDRAN8.js → buildAndBroadcastReclaim-QIN8Mcwq.js} +366 -357
- package/dist/buildAndBroadcastReclaim-QIN8Mcwq.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +5 -5
- package/dist/mempoolApi-BJvC9nPF.cjs +2 -0
- package/dist/mempoolApi-BJvC9nPF.cjs.map +1 -0
- package/dist/{mempoolApi-CKD_IbrM.js → mempoolApi-_CoQH5vH.js} +6 -5
- package/dist/mempoolApi-_CoQH5vH.js.map +1 -0
- package/dist/noPayout-DpGRzidi.js.map +1 -1
- package/dist/noPayout-zEifyecV.cjs.map +1 -1
- package/dist/{primeVpAuth-tLRjdHwZ.js → primeVpAuth-BI63kgdd.js} +55 -43
- package/dist/primeVpAuth-BI63kgdd.js.map +1 -0
- package/dist/primeVpAuth-D3xbar3j.cjs +2 -0
- package/dist/primeVpAuth-D3xbar3j.cjs.map +1 -0
- package/dist/tbv/core/clients/eth/operation-key-reader.d.ts +1 -1
- package/dist/tbv/core/clients/eth/operation-key-reader.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/protocol-params-reader.d.ts +6 -1
- package/dist/tbv/core/clients/eth/protocol-params-reader.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/signer-set-reader.d.ts +4 -4
- package/dist/tbv/core/clients/eth/signer-set-reader.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/types.d.ts +29 -8
- package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts +1 -1
- package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts.map +1 -1
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +2 -2
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +5 -5
- package/dist/tbv/core/managers/index.cjs +1 -1
- package/dist/tbv/core/managers/index.js +1 -1
- package/dist/tbv/core/primitives/psbt/refund.d.ts +3 -1
- package/dist/tbv/core/primitives/psbt/refund.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/validateOnChainParticipantKeys.d.ts +20 -0
- package/dist/tbv/core/services/deposit/validateOnChainParticipantKeys.d.ts.map +1 -1
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +1 -1
- package/dist/tbv/core/services/participants/resolveParticipantKeys.d.ts +8 -0
- package/dist/tbv/core/services/participants/resolveParticipantKeys.d.ts.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +5 -5
- package/dist/{toRefundInputs-Df1vi23S.js → toRefundInputs-BG-qHCEu.js} +2 -2
- package/dist/{toRefundInputs-Df1vi23S.js.map → toRefundInputs-BG-qHCEu.js.map} +1 -1
- package/dist/{toRefundInputs-CY9u84U9.cjs → toRefundInputs-kVR-3EdD.cjs} +2 -2
- package/dist/{toRefundInputs-CY9u84U9.cjs.map → toRefundInputs-kVR-3EdD.cjs.map} +1 -1
- package/package.json +1 -1
- package/dist/buildAndBroadcastReclaim-YvWDRAN8.js.map +0 -1
- package/dist/buildAndBroadcastReclaim-zfjDI5__.cjs +0 -2
- package/dist/buildAndBroadcastReclaim-zfjDI5__.cjs.map +0 -1
- package/dist/mempoolApi-CKD_IbrM.js.map +0 -1
- package/dist/mempoolApi-DronQ5xn.cjs +0 -2
- package/dist/mempoolApi-DronQ5xn.cjs.map +0 -1
- package/dist/primeVpAuth-Cjq6qFHq.cjs +0 -2
- package/dist/primeVpAuth-Cjq6qFHq.cjs.map +0 -1
- package/dist/primeVpAuth-tLRjdHwZ.js.map +0 -1
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var S = (e, t, r) =>
|
|
4
|
-
import { B as
|
|
5
|
-
import { e as
|
|
6
|
-
import { v as
|
|
7
|
-
import { zeroAddress as
|
|
8
|
-
import { D as C, c as
|
|
1
|
+
var xe = Object.defineProperty;
|
|
2
|
+
var Te = (e, t, r) => t in e ? xe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var S = (e, t, r) => Te(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { B as ie } from "./BTCVaultRegistry.abi-CJwWI2EO.js";
|
|
5
|
+
import { e as ue, v as Re, s as P, u as le, p as O, c as R, f as _ } from "./bitcoin-C-TuHb-v.js";
|
|
6
|
+
import { v as Ce, d as Ae, s as _e, P as Se, a as $e } from "./signPsbtsWithFallback-CCFTzE0o.js";
|
|
7
|
+
import { zeroAddress as Be } from "viem";
|
|
8
|
+
import { D as C, c as Ie, b as Ve, R as Ke, d as ce } from "./json-rpc-client-DuUARJvV.js";
|
|
9
9
|
import { Transaction as $ } from "bitcoinjs-lib";
|
|
10
|
-
import { o as
|
|
11
|
-
import { D as
|
|
12
|
-
import { d as He, c as
|
|
13
|
-
import { a as K, c as
|
|
14
|
-
import { a as
|
|
15
|
-
import { a as
|
|
16
|
-
import { deriveVaultId as
|
|
17
|
-
const
|
|
18
|
-
function
|
|
10
|
+
import { o as Oe, f as Ne, i as B, g as I, j as V } from "./verifyScriptPathSchnorrSignature-Ciq_xZhw.js";
|
|
11
|
+
import { D as q } from "./constants-CPzppOdq.js";
|
|
12
|
+
import { d as He, c as De, b as Fe, f as he, e as Me, a as Le } from "./noPayout-DpGRzidi.js";
|
|
13
|
+
import { a as K, c as Ue } from "./signing-Cm-McVR2.js";
|
|
14
|
+
import { a as z } from "./onChainBtcPubkey-DATNfAAl.js";
|
|
15
|
+
import { a as Xe } from "./vaultCoreVersion-D_fP9P3C.js";
|
|
16
|
+
import { deriveVaultId as Ge } from "./tbv/core/wasm/index.js";
|
|
17
|
+
const qe = /^0x[0-9a-fA-F]{64}$/, ze = /^0x[0-9a-fA-F]{40}$/, je = /^0x([0-9a-fA-F]{2})*$/;
|
|
18
|
+
function N(e, t) {
|
|
19
19
|
if (e.length !== 66)
|
|
20
20
|
throw new Error(
|
|
21
21
|
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
22
22
|
);
|
|
23
|
-
if (!
|
|
23
|
+
if (!qe.test(e))
|
|
24
24
|
throw new Error(
|
|
25
25
|
`${t} must contain only hex characters after the 0x prefix`
|
|
26
26
|
);
|
|
27
27
|
}
|
|
28
|
-
function
|
|
29
|
-
if (!
|
|
28
|
+
function Qe(e, t) {
|
|
29
|
+
if (!ze.test(e))
|
|
30
30
|
throw new Error(
|
|
31
31
|
`${t} must be a 20-byte 0x-prefixed hex address (42 chars)`
|
|
32
32
|
);
|
|
33
33
|
}
|
|
34
|
-
function
|
|
35
|
-
if (!
|
|
34
|
+
function We(e, t) {
|
|
35
|
+
if (!je.test(e))
|
|
36
36
|
throw new Error(
|
|
37
37
|
`${t} must be a 0x-prefixed hex string with an even number of hex chars`
|
|
38
38
|
);
|
|
39
39
|
}
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
const t =
|
|
43
|
-
if (
|
|
40
|
+
function de(e) {
|
|
41
|
+
Qe(e.btcVaultRegistryAddress, "btcVaultRegistryAddress"), N(e.vaultId, "vaultId");
|
|
42
|
+
const t = ue(e.secret);
|
|
43
|
+
if (N(t, "secret"), e.hashlock !== void 0 && (N(e.hashlock, "hashlock"), !Ce(t, e.hashlock)))
|
|
44
44
|
throw new Error(
|
|
45
45
|
"Invalid secret: SHA256(secret) does not match the provided hashlock"
|
|
46
46
|
);
|
|
47
47
|
return t;
|
|
48
48
|
}
|
|
49
|
-
async function
|
|
49
|
+
async function Yt(e) {
|
|
50
50
|
const {
|
|
51
51
|
btcVaultRegistryAddress: t,
|
|
52
52
|
vaultId: r,
|
|
@@ -56,23 +56,23 @@ async function Wt(e) {
|
|
|
56
56
|
signal: s
|
|
57
57
|
} = e;
|
|
58
58
|
s == null || s.throwIfAborted();
|
|
59
|
-
const i =
|
|
59
|
+
const i = de({
|
|
60
60
|
btcVaultRegistryAddress: t,
|
|
61
61
|
vaultId: r,
|
|
62
62
|
secret: e.secret,
|
|
63
63
|
hashlock: o
|
|
64
64
|
});
|
|
65
|
-
return
|
|
65
|
+
return We(a, "activationMetadata"), l({
|
|
66
66
|
address: t,
|
|
67
|
-
abi:
|
|
67
|
+
abi: ie,
|
|
68
68
|
functionName: "activateVaultWithSecret",
|
|
69
69
|
args: [r, i, a]
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
|
-
async function
|
|
72
|
+
async function Jt(e) {
|
|
73
73
|
const { btcVaultRegistryAddress: t, vaultId: r, hashlock: o, writeContract: a, signal: l } = e;
|
|
74
74
|
l == null || l.throwIfAborted();
|
|
75
|
-
const s =
|
|
75
|
+
const s = de({
|
|
76
76
|
btcVaultRegistryAddress: t,
|
|
77
77
|
vaultId: r,
|
|
78
78
|
secret: e.secret,
|
|
@@ -80,40 +80,40 @@ async function Yt(e) {
|
|
|
80
80
|
});
|
|
81
81
|
return a({
|
|
82
82
|
address: t,
|
|
83
|
-
abi:
|
|
83
|
+
abi: ie,
|
|
84
84
|
functionName: "activateVaultWithSecretAndRedeem",
|
|
85
85
|
args: [r, s]
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
|
-
const
|
|
89
|
-
class
|
|
88
|
+
const Ye = 8, Je = 6e3, Ze = 10 * 6e4, et = 10;
|
|
89
|
+
class pe extends Error {
|
|
90
90
|
constructor(t) {
|
|
91
91
|
super(t), this.name = "PeginRegistrationMissingError";
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
|
-
class
|
|
94
|
+
class ge extends Error {
|
|
95
95
|
constructor(t) {
|
|
96
96
|
super(t), this.name = "PeginRegistrationNotFinalError";
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
function
|
|
100
|
-
return e instanceof
|
|
99
|
+
function tt(e) {
|
|
100
|
+
return e instanceof pe || e instanceof Error && e.name === "PeginRegistrationMissingError";
|
|
101
101
|
}
|
|
102
|
-
function
|
|
103
|
-
return e instanceof
|
|
102
|
+
function Zt(e) {
|
|
103
|
+
return e instanceof ge || e instanceof Error && e.name === "PeginRegistrationNotFinalError";
|
|
104
104
|
}
|
|
105
|
-
function
|
|
105
|
+
function j(e) {
|
|
106
106
|
const { currentBlock: t, createdAtBlock: r } = e, o = t - r + 1n;
|
|
107
107
|
return o < 0n ? 0 : Number(o);
|
|
108
108
|
}
|
|
109
|
-
async function
|
|
109
|
+
async function er(e) {
|
|
110
110
|
const {
|
|
111
111
|
vaultRegistryReader: t,
|
|
112
112
|
getBlockNumber: r,
|
|
113
113
|
vaultIds: o,
|
|
114
|
-
required: a =
|
|
115
|
-
pollIntervalMs: l =
|
|
116
|
-
timeoutMs: s =
|
|
114
|
+
required: a = Ye,
|
|
115
|
+
pollIntervalMs: l = Je,
|
|
116
|
+
timeoutMs: s = Ze,
|
|
117
117
|
signal: i,
|
|
118
118
|
onProgress: n
|
|
119
119
|
} = e;
|
|
@@ -129,71 +129,71 @@ async function Zt(e) {
|
|
|
129
129
|
`Aborted while waiting for peg-in registration depth (${o.length} vault(s))`
|
|
130
130
|
);
|
|
131
131
|
if (Date.now() - u >= s)
|
|
132
|
-
throw new
|
|
132
|
+
throw new ge(
|
|
133
133
|
`Peg-in registration did not reach ${a} Ethereum confirmations within ${s}ms. The registration transaction was submitted but is not yet final, so the Pre-PegIn Bitcoin transaction was never sent and no funds are at risk. Resume this deposit from the dashboard once the network settles.` + (d instanceof Error ? ` Last read error: ${d.message}` : "")
|
|
134
134
|
);
|
|
135
135
|
try {
|
|
136
136
|
const p = await r(), g = await Promise.all(
|
|
137
|
-
o.map((
|
|
138
|
-
),
|
|
139
|
-
(
|
|
137
|
+
o.map((f) => t.getVaultBasicInfo(f))
|
|
138
|
+
), m = g.findIndex(
|
|
139
|
+
(f) => f.depositor === Be || f.createdAt === 0n
|
|
140
140
|
);
|
|
141
|
-
if (
|
|
142
|
-
if (c += 1, !h && c >
|
|
143
|
-
throw new
|
|
144
|
-
`Vault ${o[
|
|
141
|
+
if (m !== -1) {
|
|
142
|
+
if (c += 1, !h && c > et)
|
|
143
|
+
throw new pe(
|
|
144
|
+
`Vault ${o[m]} is still not visible on-chain after ${c} reads — the registration does not exist.`
|
|
145
145
|
);
|
|
146
146
|
console.warn(
|
|
147
|
-
`Peg-in registration for vault ${o[
|
|
147
|
+
`Peg-in registration for vault ${o[m]} is not visible in chain state at block ${p} — a lagging RPC backend or an Ethereum reorg. Still polling.`
|
|
148
148
|
), n == null || n({ confirmations: 0, required: a });
|
|
149
149
|
} else {
|
|
150
150
|
h = !0, c = 0, d = void 0;
|
|
151
|
-
let
|
|
151
|
+
let f = g[0], v = j({
|
|
152
152
|
currentBlock: p,
|
|
153
153
|
createdAtBlock: g[0].createdAt
|
|
154
154
|
});
|
|
155
155
|
for (const w of g.slice(1)) {
|
|
156
|
-
const
|
|
156
|
+
const k = j({
|
|
157
157
|
currentBlock: p,
|
|
158
158
|
createdAtBlock: w.createdAt
|
|
159
159
|
});
|
|
160
|
-
|
|
160
|
+
k < v && (v = k, f = w);
|
|
161
161
|
}
|
|
162
|
-
if (n == null || n({ confirmations:
|
|
163
|
-
return { confirmations:
|
|
162
|
+
if (n == null || n({ confirmations: v, required: a }), v >= a)
|
|
163
|
+
return { confirmations: v, basicInfo: f };
|
|
164
164
|
}
|
|
165
165
|
} catch (p) {
|
|
166
|
-
if (
|
|
166
|
+
if (tt(p))
|
|
167
167
|
throw p;
|
|
168
168
|
console.warn(
|
|
169
169
|
`Registration-depth read failed (retrying in ${l}ms): ` + (p instanceof Error ? p.message : String(p))
|
|
170
170
|
), d = p;
|
|
171
171
|
}
|
|
172
172
|
await new Promise((p, g) => {
|
|
173
|
-
const
|
|
174
|
-
clearTimeout(
|
|
173
|
+
const m = () => {
|
|
174
|
+
clearTimeout(f), g(
|
|
175
175
|
new Error(
|
|
176
176
|
`Aborted while waiting for peg-in registration depth (${o.length} vault(s))`
|
|
177
177
|
)
|
|
178
178
|
);
|
|
179
|
-
},
|
|
180
|
-
i == null || i.removeEventListener("abort",
|
|
179
|
+
}, f = setTimeout(() => {
|
|
180
|
+
i == null || i.removeEventListener("abort", m), p();
|
|
181
181
|
}, l);
|
|
182
|
-
i == null || i.addEventListener("abort",
|
|
182
|
+
i == null || i.addEventListener("abort", m, { once: !0 });
|
|
183
183
|
});
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
|
-
const
|
|
187
|
-
function
|
|
186
|
+
const rt = 1;
|
|
187
|
+
function ot(e, t, r) {
|
|
188
188
|
const o = r.map(
|
|
189
|
-
(c) =>
|
|
189
|
+
(c) => P(c).toLowerCase()
|
|
190
190
|
), a = t.filter((c) => o.includes(c));
|
|
191
191
|
if (a.length > 0)
|
|
192
192
|
throw new Error(
|
|
193
193
|
`Cannot validate challenger set: vault keepers and universal challengers overlap (${a.join(", ")})`
|
|
194
194
|
);
|
|
195
195
|
const l = [...t, ...o], s = e.map(
|
|
196
|
-
(c) =>
|
|
196
|
+
(c) => P(c.challenger_pubkey).toLowerCase()
|
|
197
197
|
), i = new Set(s);
|
|
198
198
|
if (i.size !== s.length)
|
|
199
199
|
throw new Error(
|
|
@@ -205,35 +205,35 @@ function rt(e, t, r) {
|
|
|
205
205
|
"Depositor graph challenger set does not match expected (local ∪ universal)" + (u.length > 0 ? ` (missing: ${u.join(", ")})` : "") + (h.length > 0 ? ` (unexpected: ${h.join(", ")})` : "")
|
|
206
206
|
);
|
|
207
207
|
}
|
|
208
|
-
function
|
|
208
|
+
function nt(e, t) {
|
|
209
209
|
const r = e.ins[t];
|
|
210
|
-
return
|
|
210
|
+
return le(new Uint8Array(r.hash).slice().reverse());
|
|
211
211
|
}
|
|
212
|
-
function
|
|
212
|
+
function H(e, t, r, o, a) {
|
|
213
213
|
const l = e.ins[t];
|
|
214
214
|
if (l.index !== 0)
|
|
215
215
|
throw new Error(
|
|
216
216
|
`NoPayout (challenger ${a}) input ${t} expected to spend ${o} vout 0, got vout ${l.index}`
|
|
217
217
|
);
|
|
218
|
-
const s = r.getId(), i =
|
|
218
|
+
const s = r.getId(), i = nt(e, t);
|
|
219
219
|
if (i !== s)
|
|
220
220
|
throw new Error(
|
|
221
221
|
`NoPayout (challenger ${a}) input ${t} does not reference ${o} (expected txid ${s}, got ${i})`
|
|
222
222
|
);
|
|
223
223
|
}
|
|
224
|
-
async function
|
|
225
|
-
const o = [], a = [], l = [], s =
|
|
224
|
+
async function st(e, t, r) {
|
|
225
|
+
const o = [], a = [], l = [], s = Oe({
|
|
226
226
|
claimerBtcPubkey: r.depositorBtcPubkey,
|
|
227
227
|
depositorBtcPubkey: r.depositorBtcPubkey,
|
|
228
228
|
vaultProviderBtcPubkey: r.vaultProviderBtcPubkey,
|
|
229
229
|
vaultKeeperBtcPubkeys: r.vaultKeeperBtcPubkeys
|
|
230
230
|
});
|
|
231
|
-
|
|
231
|
+
ot(
|
|
232
232
|
e.challenger_presign_data,
|
|
233
233
|
s,
|
|
234
234
|
r.universalChallengerBtcPubkeys
|
|
235
235
|
);
|
|
236
|
-
const i = await
|
|
236
|
+
const i = await Ne({
|
|
237
237
|
vaultCoreVersion: r.vaultCoreVersion,
|
|
238
238
|
vkClaimerPayoutScriptPubKeys: r.vkClaimerPayoutScriptPubKeys,
|
|
239
239
|
vpCommissionScriptPubKey: r.vpCommissionScriptPubKey,
|
|
@@ -249,7 +249,7 @@ async function nt(e, t, r) {
|
|
|
249
249
|
network: r.network,
|
|
250
250
|
claimerBtcPubkey: r.depositorBtcPubkey,
|
|
251
251
|
registeredPayoutScriptPubKey: r.registeredPayoutScriptPubKey,
|
|
252
|
-
commissionBps:
|
|
252
|
+
commissionBps: rt,
|
|
253
253
|
protocolFeeRate: r.protocolFeeRate,
|
|
254
254
|
councilMembers: r.councilMembers,
|
|
255
255
|
councilQuorum: r.councilQuorum
|
|
@@ -257,14 +257,14 @@ async function nt(e, t, r) {
|
|
|
257
257
|
o.push(i.psbtHex), a.push(
|
|
258
258
|
K(
|
|
259
259
|
t,
|
|
260
|
-
|
|
260
|
+
q
|
|
261
261
|
)
|
|
262
262
|
);
|
|
263
|
-
const n =
|
|
264
|
-
|
|
263
|
+
const n = P(r.depositorBtcPubkey), u = $.fromHex(
|
|
264
|
+
P(e.assert_tx.tx_hex)
|
|
265
265
|
);
|
|
266
266
|
for (const h of e.challenger_presign_data) {
|
|
267
|
-
const c =
|
|
267
|
+
const c = P(h.challenger_pubkey), d = o.length, p = await at({
|
|
268
268
|
challenger: h,
|
|
269
269
|
challengerPubkey: c,
|
|
270
270
|
claimerPubkey: n,
|
|
@@ -275,7 +275,7 @@ async function nt(e, t, r) {
|
|
|
275
275
|
o.push(p), a.push(
|
|
276
276
|
K(
|
|
277
277
|
t,
|
|
278
|
-
|
|
278
|
+
q
|
|
279
279
|
)
|
|
280
280
|
), l.push({
|
|
281
281
|
challengerPubkey: c,
|
|
@@ -284,7 +284,7 @@ async function nt(e, t, r) {
|
|
|
284
284
|
}
|
|
285
285
|
return { psbtHexes: o, signOptions: a, challengerEntries: l };
|
|
286
286
|
}
|
|
287
|
-
async function
|
|
287
|
+
async function at(e) {
|
|
288
288
|
const {
|
|
289
289
|
challenger: t,
|
|
290
290
|
challengerPubkey: r,
|
|
@@ -299,29 +299,29 @@ async function st(e) {
|
|
|
299
299
|
s.network
|
|
300
300
|
);
|
|
301
301
|
const i = $.fromHex(
|
|
302
|
-
|
|
302
|
+
P(t.nopayout_tx.tx_hex)
|
|
303
303
|
), n = $.fromHex(
|
|
304
|
-
|
|
304
|
+
P(t.challenge_assert_x_tx.tx_hex)
|
|
305
305
|
), u = $.fromHex(
|
|
306
|
-
|
|
306
|
+
P(t.challenge_assert_y_tx.tx_hex)
|
|
307
307
|
);
|
|
308
308
|
if (i.ins.length !== 3)
|
|
309
309
|
throw new Error(
|
|
310
310
|
`NoPayout (challenger ${r}) must have exactly 3 inputs, got ${i.ins.length}`
|
|
311
311
|
);
|
|
312
|
-
|
|
312
|
+
H(
|
|
313
313
|
i,
|
|
314
314
|
0,
|
|
315
315
|
l,
|
|
316
316
|
"Assert",
|
|
317
317
|
r
|
|
318
|
-
),
|
|
318
|
+
), H(
|
|
319
319
|
i,
|
|
320
320
|
1,
|
|
321
321
|
n,
|
|
322
322
|
"ChallengeAssertX",
|
|
323
323
|
r
|
|
324
|
-
),
|
|
324
|
+
), H(
|
|
325
325
|
i,
|
|
326
326
|
2,
|
|
327
327
|
u,
|
|
@@ -333,10 +333,10 @@ async function st(e) {
|
|
|
333
333
|
n.outs[0],
|
|
334
334
|
u.outs[0]
|
|
335
335
|
].map((c) => ({
|
|
336
|
-
script_pubkey:
|
|
336
|
+
script_pubkey: le(new Uint8Array(c.script)),
|
|
337
337
|
value: c.value
|
|
338
338
|
}));
|
|
339
|
-
return
|
|
339
|
+
return De({
|
|
340
340
|
noPayoutTxHex: t.nopayout_tx.tx_hex,
|
|
341
341
|
challengerPubkey: r,
|
|
342
342
|
prevouts: h,
|
|
@@ -351,7 +351,7 @@ async function st(e) {
|
|
|
351
351
|
}
|
|
352
352
|
});
|
|
353
353
|
}
|
|
354
|
-
function
|
|
354
|
+
function it(e, t, r) {
|
|
355
355
|
B(e[0]);
|
|
356
356
|
const a = I(
|
|
357
357
|
e[0].returnedPsbtHex,
|
|
@@ -386,15 +386,15 @@ function at(e, t, r) {
|
|
|
386
386
|
per_challenger: l
|
|
387
387
|
};
|
|
388
388
|
}
|
|
389
|
-
async function
|
|
390
|
-
const { depositorGraph: t, btcWallet: r, signingContext: o } = e, a = await r.getPublicKeyHex(), { depositorPubkey: l } =
|
|
389
|
+
async function ut(e) {
|
|
390
|
+
const { depositorGraph: t, btcWallet: r, signingContext: o } = e, a = await r.getPublicKeyHex(), { depositorPubkey: l } = Re(
|
|
391
391
|
a,
|
|
392
|
-
|
|
393
|
-
), { psbtHexes: s, signOptions: i, challengerEntries: n } = await
|
|
392
|
+
P(o.depositorBtcPubkey)
|
|
393
|
+
), { psbtHexes: s, signOptions: i, challengerEntries: n } = await st(
|
|
394
394
|
t,
|
|
395
395
|
a,
|
|
396
396
|
o
|
|
397
|
-
), u = await
|
|
397
|
+
), u = await Ae(
|
|
398
398
|
r,
|
|
399
399
|
s,
|
|
400
400
|
i
|
|
@@ -402,20 +402,20 @@ async function it(e) {
|
|
|
402
402
|
requestedPsbtHex: c,
|
|
403
403
|
returnedPsbtHex: u[d]
|
|
404
404
|
}));
|
|
405
|
-
return
|
|
405
|
+
return it(
|
|
406
406
|
h,
|
|
407
407
|
n,
|
|
408
408
|
l
|
|
409
409
|
);
|
|
410
410
|
}
|
|
411
|
-
const
|
|
412
|
-
async function
|
|
411
|
+
const lt = 1e4;
|
|
412
|
+
async function fe(e) {
|
|
413
413
|
const {
|
|
414
414
|
statusReader: t,
|
|
415
415
|
peginTxid: r,
|
|
416
416
|
targetStatuses: o,
|
|
417
417
|
timeoutMs: a,
|
|
418
|
-
pollIntervalMs: l =
|
|
418
|
+
pollIntervalMs: l = lt,
|
|
419
419
|
signal: s
|
|
420
420
|
} = e, i = Date.now();
|
|
421
421
|
for (; ; ) {
|
|
@@ -439,12 +439,12 @@ async function ge(e) {
|
|
|
439
439
|
const u = n.status;
|
|
440
440
|
if (o.has(u) || u === C.ACTIVATED)
|
|
441
441
|
return u;
|
|
442
|
-
if (u === C.EXPIRED ||
|
|
442
|
+
if (u === C.EXPIRED || Ie.has(u))
|
|
443
443
|
throw new Error(
|
|
444
444
|
`Pegin ${r.slice(0, 8)}… reached terminal status "${u}" while waiting for ${[...o].join(", ")}`
|
|
445
445
|
);
|
|
446
446
|
} catch (n) {
|
|
447
|
-
if (!(n instanceof
|
|
447
|
+
if (!(n instanceof Ve && n.code === Ke.PEGIN_NOT_FOUND))
|
|
448
448
|
throw n;
|
|
449
449
|
}
|
|
450
450
|
await new Promise((n, u) => {
|
|
@@ -461,16 +461,16 @@ async function ge(e) {
|
|
|
461
461
|
});
|
|
462
462
|
}
|
|
463
463
|
}
|
|
464
|
-
const
|
|
464
|
+
const ct = 1200 * 1e3, me = /* @__PURE__ */ new Set([
|
|
465
465
|
C.PENDING_ACKS,
|
|
466
466
|
C.PENDING_ACTIVATION,
|
|
467
467
|
C.ACTIVATED_PENDING_BROADCAST,
|
|
468
468
|
C.ACTIVATED
|
|
469
|
-
]),
|
|
469
|
+
]), ht = /* @__PURE__ */ new Set([
|
|
470
470
|
C.PENDING_DEPOSITOR_SIGNATURES,
|
|
471
|
-
...
|
|
471
|
+
...me
|
|
472
472
|
]);
|
|
473
|
-
function
|
|
473
|
+
function dt(e) {
|
|
474
474
|
return e.map((t) => ({
|
|
475
475
|
claimerPubkeyXOnly: O(t.claimer_pubkey),
|
|
476
476
|
payoutTxHex: t.payout_tx.tx_hex,
|
|
@@ -480,7 +480,7 @@ function ht(e) {
|
|
|
480
480
|
function T(e) {
|
|
481
481
|
return O(e).toLowerCase();
|
|
482
482
|
}
|
|
483
|
-
function
|
|
483
|
+
function pt(e, t) {
|
|
484
484
|
const r = (n, u, h) => {
|
|
485
485
|
throw new Error(
|
|
486
486
|
`Deposit terms ${n} (${String(u)}) does not match the vault's version-locked signing context (${String(h)}); refusing to sign payouts against terms that describe a different graph.`
|
|
@@ -518,7 +518,7 @@ function dt(e, t) {
|
|
|
518
518
|
t.vaultProviderBtcPubkey
|
|
519
519
|
);
|
|
520
520
|
}
|
|
521
|
-
function
|
|
521
|
+
function gt(e, t, r, o) {
|
|
522
522
|
const a = T(o), l = [
|
|
523
523
|
T(t),
|
|
524
524
|
...r.map(T)
|
|
@@ -542,7 +542,7 @@ function pt(e, t, r, o) {
|
|
|
542
542
|
"Presign response claimer set does not match expected (vault provider ∪ vault keepers)" + (h.length > 0 ? ` (missing: ${h.join(", ")})` : "") + (c.length > 0 ? ` (unexpected: ${c.join(", ")})` : "")
|
|
543
543
|
);
|
|
544
544
|
}
|
|
545
|
-
function
|
|
545
|
+
function Q(e, t) {
|
|
546
546
|
return {
|
|
547
547
|
vaultCoreVersion: t.vaultCoreVersion,
|
|
548
548
|
payoutTxHex: e.payoutTxHex,
|
|
@@ -564,8 +564,8 @@ function j(e, t) {
|
|
|
564
564
|
vpCommissionScriptPubKey: t.vpCommissionScriptPubKey
|
|
565
565
|
};
|
|
566
566
|
}
|
|
567
|
-
async function
|
|
568
|
-
const a = new
|
|
567
|
+
async function ft(e, t, r, o) {
|
|
568
|
+
const a = new Se({
|
|
569
569
|
network: t.network,
|
|
570
570
|
btcWallet: e
|
|
571
571
|
}), l = r.length;
|
|
@@ -573,14 +573,14 @@ async function gt(e, t, r, o) {
|
|
|
573
573
|
let s;
|
|
574
574
|
if (a.supportsBatchSigning())
|
|
575
575
|
s = (await a.signPayoutTransactionsBatch(
|
|
576
|
-
r.map((u) =>
|
|
576
|
+
r.map((u) => Q(u, t))
|
|
577
577
|
)).map((u) => u.payoutSignature);
|
|
578
578
|
else {
|
|
579
579
|
s = [];
|
|
580
580
|
for (let n = 0; n < r.length; n++) {
|
|
581
581
|
o == null || o(n, l);
|
|
582
582
|
const u = await a.signPayoutTransaction(
|
|
583
|
-
|
|
583
|
+
Q(r[n], t)
|
|
584
584
|
);
|
|
585
585
|
s.push(u.signature);
|
|
586
586
|
}
|
|
@@ -592,7 +592,7 @@ async function gt(e, t, r, o) {
|
|
|
592
592
|
};
|
|
593
593
|
return o == null || o(l, l), i;
|
|
594
594
|
}
|
|
595
|
-
async function
|
|
595
|
+
async function tr(e) {
|
|
596
596
|
const {
|
|
597
597
|
statusReader: t,
|
|
598
598
|
presignClient: r,
|
|
@@ -601,19 +601,19 @@ async function er(e) {
|
|
|
601
601
|
depositorPk: l,
|
|
602
602
|
signingContext: s,
|
|
603
603
|
depositTerms: i,
|
|
604
|
-
timeoutMs: n =
|
|
604
|
+
timeoutMs: n = ct,
|
|
605
605
|
signal: u,
|
|
606
606
|
onProgress: h
|
|
607
|
-
} = e, c = await
|
|
607
|
+
} = e, c = await fe({
|
|
608
608
|
statusReader: t,
|
|
609
609
|
peginTxid: a,
|
|
610
|
-
targetStatuses:
|
|
610
|
+
targetStatuses: ht,
|
|
611
611
|
timeoutMs: n,
|
|
612
612
|
signal: u
|
|
613
613
|
});
|
|
614
|
-
if (
|
|
614
|
+
if (me.has(c))
|
|
615
615
|
return;
|
|
616
|
-
if (u == null || u.throwIfAborted(), i !== void 0 &&
|
|
616
|
+
if (u == null || u.throwIfAborted(), i !== void 0 && pt(i, s), _e(o)) {
|
|
617
617
|
if (!i)
|
|
618
618
|
throw new Error(
|
|
619
619
|
"runDepositorPresignFlow: this wallet requires approved deposit terms but none were provided. Fresh deposits must pass PreparePeginResult.depositTerms; resume flows must rebuild them from on-chain state (the vault app's rebuildDepositTerms)."
|
|
@@ -629,22 +629,22 @@ async function er(e) {
|
|
|
629
629
|
);
|
|
630
630
|
u == null || u.throwIfAborted();
|
|
631
631
|
const p = T(l);
|
|
632
|
-
|
|
632
|
+
gt(
|
|
633
633
|
d.txs,
|
|
634
634
|
s.vaultProviderBtcPubkey,
|
|
635
635
|
s.vaultKeeperBtcPubkeys,
|
|
636
636
|
l
|
|
637
637
|
);
|
|
638
638
|
const g = d.txs.filter(
|
|
639
|
-
(
|
|
640
|
-
),
|
|
639
|
+
(k) => T(k.claimer_pubkey) !== p
|
|
640
|
+
), m = dt(g), f = await ft(
|
|
641
641
|
o,
|
|
642
642
|
s,
|
|
643
|
-
|
|
643
|
+
m,
|
|
644
644
|
h
|
|
645
645
|
);
|
|
646
646
|
u == null || u.throwIfAborted();
|
|
647
|
-
const
|
|
647
|
+
const v = await ut({
|
|
648
648
|
depositorGraph: d.depositor_graph,
|
|
649
649
|
btcWallet: o,
|
|
650
650
|
signingContext: {
|
|
@@ -666,40 +666,40 @@ async function er(e) {
|
|
|
666
666
|
}
|
|
667
667
|
});
|
|
668
668
|
u == null || u.throwIfAborted();
|
|
669
|
-
const w = { ...
|
|
670
|
-
w[
|
|
669
|
+
const w = { ...f };
|
|
670
|
+
w[P(l)] = v.payout_signatures, await r.submitDepositorPresignatures(
|
|
671
671
|
{
|
|
672
672
|
pegin_txid: a,
|
|
673
673
|
depositor_pk: l,
|
|
674
674
|
signatures: w,
|
|
675
|
-
depositor_claimer_presignatures:
|
|
675
|
+
depositor_claimer_presignatures: v
|
|
676
676
|
},
|
|
677
677
|
u
|
|
678
678
|
);
|
|
679
679
|
}
|
|
680
|
-
const
|
|
680
|
+
const mt = 300 * 1e3, vt = /* @__PURE__ */ new Set([
|
|
681
681
|
C.PENDING_DEPOSITOR_WOTS_PK,
|
|
682
|
-
...
|
|
682
|
+
...ce
|
|
683
683
|
]);
|
|
684
|
-
async function
|
|
684
|
+
async function rr(e) {
|
|
685
685
|
const {
|
|
686
686
|
statusReader: t,
|
|
687
687
|
wotsSubmitter: r,
|
|
688
688
|
peginTxid: o,
|
|
689
689
|
depositorPk: a,
|
|
690
690
|
wotsPublicKeys: l,
|
|
691
|
-
timeoutMs: s =
|
|
691
|
+
timeoutMs: s = mt,
|
|
692
692
|
signal: i
|
|
693
693
|
} = e;
|
|
694
694
|
i == null || i.throwIfAborted();
|
|
695
|
-
const n = await
|
|
695
|
+
const n = await fe({
|
|
696
696
|
statusReader: t,
|
|
697
697
|
peginTxid: o,
|
|
698
|
-
targetStatuses:
|
|
698
|
+
targetStatuses: vt,
|
|
699
699
|
timeoutMs: s,
|
|
700
700
|
signal: i
|
|
701
701
|
});
|
|
702
|
-
|
|
702
|
+
ce.has(n) || (i == null || i.throwIfAborted(), await r.submitDepositorWotsKey(
|
|
703
703
|
{
|
|
704
704
|
pegin_txid: o,
|
|
705
705
|
depositor_pk: a,
|
|
@@ -711,27 +711,27 @@ async function tr(e) {
|
|
|
711
711
|
function D(e) {
|
|
712
712
|
return e.registration || e.operation;
|
|
713
713
|
}
|
|
714
|
-
function
|
|
714
|
+
function Pt(e, t, r) {
|
|
715
715
|
const o = R(e);
|
|
716
716
|
return {
|
|
717
717
|
registration: o === R(t),
|
|
718
718
|
operation: o === R(r)
|
|
719
719
|
};
|
|
720
720
|
}
|
|
721
|
-
function
|
|
721
|
+
function W(e, t, r) {
|
|
722
722
|
const o = F(e);
|
|
723
723
|
return {
|
|
724
|
-
registration:
|
|
725
|
-
operation:
|
|
724
|
+
registration: Y(o, F(t)),
|
|
725
|
+
operation: Y(o, F(r))
|
|
726
726
|
};
|
|
727
727
|
}
|
|
728
728
|
function F(e) {
|
|
729
729
|
return e.map(R).sort();
|
|
730
730
|
}
|
|
731
|
-
function
|
|
731
|
+
function Y(e, t) {
|
|
732
732
|
return e.length === t.length && e.every((r, o) => r === t[o]);
|
|
733
733
|
}
|
|
734
|
-
async function
|
|
734
|
+
async function or(e) {
|
|
735
735
|
const {
|
|
736
736
|
vaultProviderEthAddress: t,
|
|
737
737
|
hintBtcPubkey: r,
|
|
@@ -751,10 +751,10 @@ async function rr(e) {
|
|
|
751
751
|
);
|
|
752
752
|
}
|
|
753
753
|
function M(e, t, r) {
|
|
754
|
-
const o = `${e} operation key (admin=${t.ethAddress})`, a =
|
|
754
|
+
const o = `${e} operation key (admin=${t.ethAddress})`, a = z(
|
|
755
755
|
t.btcPubKey,
|
|
756
756
|
`${e} roster key (admin=${t.ethAddress})`
|
|
757
|
-
), l =
|
|
757
|
+
), l = z(r, o);
|
|
758
758
|
return {
|
|
759
759
|
adminAddress: t.ethAddress,
|
|
760
760
|
genesisBtcPubkey: a,
|
|
@@ -762,7 +762,7 @@ function M(e, t, r) {
|
|
|
762
762
|
rotated: l !== a
|
|
763
763
|
};
|
|
764
764
|
}
|
|
765
|
-
function
|
|
765
|
+
function bt(e) {
|
|
766
766
|
const t = /* @__PURE__ */ new Map();
|
|
767
767
|
for (const r of e) {
|
|
768
768
|
const o = t.get(r.operationBtcPubkey);
|
|
@@ -773,7 +773,7 @@ function Pt(e) {
|
|
|
773
773
|
t.set(r.operationBtcPubkey, r.adminAddress);
|
|
774
774
|
}
|
|
775
775
|
}
|
|
776
|
-
function
|
|
776
|
+
function ve(e, t, r) {
|
|
777
777
|
if (t.vaultKeepers.length !== e.vaultKeepers.length || t.universalChallengers.length !== e.universalChallengers.length)
|
|
778
778
|
throw new Error(
|
|
779
779
|
`Operation-key resolution returned ${t.vaultKeepers.length} keeper and ${t.universalChallengers.length} challenger keys for a roster of ${e.vaultKeepers.length} keepers and ${e.universalChallengers.length} challengers`
|
|
@@ -790,7 +790,7 @@ function me(e, t, r) {
|
|
|
790
790
|
), l = e.universalChallengers.map(
|
|
791
791
|
(s, i) => M("universal challenger", s, t.universalChallengers[i])
|
|
792
792
|
);
|
|
793
|
-
return
|
|
793
|
+
return bt([
|
|
794
794
|
o,
|
|
795
795
|
...a,
|
|
796
796
|
...l
|
|
@@ -807,22 +807,23 @@ function me(e, t, r) {
|
|
|
807
807
|
}
|
|
808
808
|
async function yt(e) {
|
|
809
809
|
const t = await e.operationKeyReader.getCurrentOperationKeys(
|
|
810
|
-
e.query
|
|
810
|
+
e.query,
|
|
811
|
+
e.blockNumber
|
|
811
812
|
);
|
|
812
|
-
return
|
|
813
|
+
return ve(e.query, t, { mode: "current" });
|
|
813
814
|
}
|
|
814
|
-
async function
|
|
815
|
+
async function wt(e) {
|
|
815
816
|
const t = await e.operationKeyReader.getOperationKeysAtEpochs(
|
|
816
817
|
e.query,
|
|
817
818
|
e.epochs
|
|
818
819
|
);
|
|
819
|
-
return
|
|
820
|
+
return ve(e.query, t, {
|
|
820
821
|
mode: "epochs",
|
|
821
822
|
epochs: e.epochs
|
|
822
823
|
});
|
|
823
824
|
}
|
|
824
|
-
const
|
|
825
|
-
async function
|
|
825
|
+
const J = (e) => e.map(R).sort();
|
|
826
|
+
async function nr(e) {
|
|
826
827
|
const {
|
|
827
828
|
vaultRegistryReader: t,
|
|
828
829
|
vaultKeeperReader: r,
|
|
@@ -834,90 +835,98 @@ async function or(e) {
|
|
|
834
835
|
expectedUniversalChallengerBtcPubkeys: n,
|
|
835
836
|
operationKeyReader: u,
|
|
836
837
|
onIndexerServingOperationKeys: h,
|
|
837
|
-
onIndexerHintsInconsistent: c
|
|
838
|
+
onIndexerHintsInconsistent: c,
|
|
839
|
+
blockNumber: d
|
|
838
840
|
} = e, [
|
|
839
|
-
d,
|
|
840
841
|
p,
|
|
841
|
-
g
|
|
842
|
+
g,
|
|
843
|
+
m
|
|
842
844
|
] = await Promise.all([
|
|
843
845
|
t.getVaultProviderGenesisBtcPubKey(
|
|
844
|
-
a
|
|
846
|
+
a,
|
|
847
|
+
d
|
|
848
|
+
),
|
|
849
|
+
r.getCurrentVaultKeepersVersion(
|
|
850
|
+
l,
|
|
851
|
+
d
|
|
845
852
|
),
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
]), [P, m] = await Promise.all([
|
|
853
|
+
o.getLatestUniversalChallengersVersion(d)
|
|
854
|
+
]), [f, v] = await Promise.all([
|
|
849
855
|
r.getVaultKeepersByVersion(
|
|
850
856
|
l,
|
|
851
|
-
|
|
857
|
+
g,
|
|
858
|
+
d
|
|
852
859
|
),
|
|
853
860
|
o.getUniversalChallengersByVersion(
|
|
854
|
-
|
|
861
|
+
m,
|
|
862
|
+
d
|
|
855
863
|
)
|
|
856
|
-
]),
|
|
857
|
-
vaultProvider: R(
|
|
858
|
-
vaultKeepers:
|
|
859
|
-
universalChallengers:
|
|
860
|
-
},
|
|
864
|
+
]), w = {
|
|
865
|
+
vaultProvider: R(p),
|
|
866
|
+
vaultKeepers: J(f.map((E) => E.btcPubKey)),
|
|
867
|
+
universalChallengers: J(v.map((E) => E.btcPubKey))
|
|
868
|
+
}, k = await yt({
|
|
861
869
|
operationKeyReader: u,
|
|
862
870
|
query: {
|
|
863
871
|
vaultProviderEthAddress: a,
|
|
864
|
-
vaultProviderGenesisBtcPubkey: `0x${
|
|
872
|
+
vaultProviderGenesisBtcPubkey: `0x${p}`,
|
|
865
873
|
applicationEntryPoint: l,
|
|
866
|
-
vaultKeepers:
|
|
867
|
-
universalChallengers:
|
|
868
|
-
}
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
874
|
+
vaultKeepers: f,
|
|
875
|
+
universalChallengers: v
|
|
876
|
+
},
|
|
877
|
+
blockNumber: d
|
|
878
|
+
}), b = {
|
|
879
|
+
vaultProvider: k.vaultProvider.operationBtcPubkey,
|
|
880
|
+
vaultKeepers: [...k.vaultKeeperOperationKeysSorted],
|
|
872
881
|
universalChallengers: [
|
|
873
|
-
...
|
|
882
|
+
...k.universalChallengerOperationKeysSorted
|
|
874
883
|
]
|
|
875
|
-
},
|
|
884
|
+
}, x = Pt(
|
|
876
885
|
s,
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
),
|
|
886
|
+
w.vaultProvider,
|
|
887
|
+
b.vaultProvider
|
|
888
|
+
), A = W(
|
|
880
889
|
i,
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
),
|
|
890
|
+
w.vaultKeepers,
|
|
891
|
+
b.vaultKeepers
|
|
892
|
+
), y = W(
|
|
884
893
|
n,
|
|
885
|
-
|
|
886
|
-
|
|
894
|
+
w.universalChallengers,
|
|
895
|
+
b.universalChallengers
|
|
887
896
|
);
|
|
888
|
-
if (!D(
|
|
897
|
+
if (!D(x))
|
|
889
898
|
throw new Error(
|
|
890
899
|
`Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${a}. Refresh and try again.`
|
|
891
900
|
);
|
|
892
|
-
if (!D(
|
|
901
|
+
if (!D(A))
|
|
893
902
|
throw new Error(
|
|
894
|
-
`Vault keeper BTC pubkeys (v${
|
|
903
|
+
`Vault keeper BTC pubkeys (v${g}) indexer set does not match ApplicationRegistry on-chain set. Refresh and try again.`
|
|
895
904
|
);
|
|
896
|
-
if (!D(
|
|
905
|
+
if (!D(y))
|
|
897
906
|
throw new Error(
|
|
898
|
-
`Universal challenger BTC pubkeys (v${
|
|
907
|
+
`Universal challenger BTC pubkeys (v${m}) indexer set does not match ProtocolParams on-chain set. Refresh and try again.`
|
|
899
908
|
);
|
|
900
|
-
const
|
|
901
|
-
if (
|
|
909
|
+
const X = [x, A, y], Ee = X.some((E) => E.registration && !E.operation), G = X.some((E) => E.operation && !E.registration);
|
|
910
|
+
if (Ee && G) {
|
|
902
911
|
const E = `Indexer participant hints are internally inconsistent for vault provider ${a}: some roles match the registration keys while others match the rotated operation keys.`;
|
|
903
912
|
throw c == null || c(E), new Error(`${E} Refresh and try again.`);
|
|
904
913
|
}
|
|
905
|
-
return
|
|
914
|
+
return G && (h == null || h(
|
|
906
915
|
`Indexer is serving rotated operation keys for vault provider ${a}`
|
|
907
916
|
)), {
|
|
908
|
-
vaultProviderBtcPubkeyXOnly:
|
|
909
|
-
vaultKeeperBtcPubkeysSorted:
|
|
910
|
-
universalChallengerBtcPubkeysSorted:
|
|
911
|
-
expectedAppVaultKeepersVersion:
|
|
912
|
-
expectedUniversalChallengersVersion:
|
|
913
|
-
registrationKeys:
|
|
914
|
-
participantKeys:
|
|
917
|
+
vaultProviderBtcPubkeyXOnly: b.vaultProvider,
|
|
918
|
+
vaultKeeperBtcPubkeysSorted: b.vaultKeepers,
|
|
919
|
+
universalChallengerBtcPubkeysSorted: b.universalChallengers,
|
|
920
|
+
expectedAppVaultKeepersVersion: g,
|
|
921
|
+
expectedUniversalChallengersVersion: m,
|
|
922
|
+
registrationKeys: w,
|
|
923
|
+
participantKeys: k
|
|
915
924
|
};
|
|
916
925
|
}
|
|
917
|
-
function
|
|
926
|
+
function kt(e) {
|
|
918
927
|
return /^[0-9a-fA-F]{64}$/.test(e);
|
|
919
928
|
}
|
|
920
|
-
function
|
|
929
|
+
function sr(e) {
|
|
921
930
|
const {
|
|
922
931
|
amountSats: t,
|
|
923
932
|
minDeposit: r,
|
|
@@ -928,7 +937,7 @@ function nr(e) {
|
|
|
928
937
|
} = e;
|
|
929
938
|
return !(t <= 0n || t < r || o && o > 0n && t > o || l == null || s == null || t + l + s > a);
|
|
930
939
|
}
|
|
931
|
-
function
|
|
940
|
+
function ar(e, t, r) {
|
|
932
941
|
return e <= 0n ? {
|
|
933
942
|
valid: !1,
|
|
934
943
|
error: "Deposit amount must be greater than zero"
|
|
@@ -940,7 +949,7 @@ function sr(e, t, r) {
|
|
|
940
949
|
error: `Maximum deposit is ${_(r)} BTC`
|
|
941
950
|
} : { valid: !0 };
|
|
942
951
|
}
|
|
943
|
-
function
|
|
952
|
+
function ir(e) {
|
|
944
953
|
const { amount: t, effectiveRemaining: r } = e;
|
|
945
954
|
return r === null ? { valid: !0 } : r === 0n ? {
|
|
946
955
|
valid: !1,
|
|
@@ -950,7 +959,7 @@ function ar(e) {
|
|
|
950
959
|
error: `Vault size exceeds remaining capacity (${_(r)} BTC)`
|
|
951
960
|
} : { valid: !0 };
|
|
952
961
|
}
|
|
953
|
-
function
|
|
962
|
+
function ur(e, t) {
|
|
954
963
|
if (!e || e.length === 0)
|
|
955
964
|
return {
|
|
956
965
|
valid: !1,
|
|
@@ -966,7 +975,7 @@ function ir(e, t) {
|
|
|
966
975
|
error: "Invalid vault provider selected"
|
|
967
976
|
} : { valid: !0 };
|
|
968
977
|
}
|
|
969
|
-
function
|
|
978
|
+
function Et(e, t, r) {
|
|
970
979
|
if (!e || e.length === 0)
|
|
971
980
|
return {
|
|
972
981
|
valid: !1,
|
|
@@ -992,30 +1001,30 @@ function kt(e, t, r) {
|
|
|
992
1001
|
}
|
|
993
1002
|
return { valid: !0 };
|
|
994
1003
|
}
|
|
995
|
-
function
|
|
996
|
-
const t =
|
|
997
|
-
return
|
|
1004
|
+
function xt(e) {
|
|
1005
|
+
const t = P(e);
|
|
1006
|
+
return kt(t) ? { valid: !0 } : {
|
|
998
1007
|
valid: !1,
|
|
999
1008
|
error: "Invalid pubkey format: must be 64 hex characters (32-byte x-only public key, no 0x prefix)"
|
|
1000
1009
|
};
|
|
1001
1010
|
}
|
|
1002
|
-
function
|
|
1011
|
+
function Tt(e) {
|
|
1003
1012
|
if (!e || e.length === 0)
|
|
1004
1013
|
throw new Error(
|
|
1005
1014
|
"No vault keepers available. The system requires at least one vault keeper to create a deposit."
|
|
1006
1015
|
);
|
|
1007
1016
|
}
|
|
1008
|
-
function
|
|
1017
|
+
function Rt(e) {
|
|
1009
1018
|
if (!e || e.length === 0)
|
|
1010
1019
|
throw new Error(
|
|
1011
1020
|
"No universal challengers available. The system requires at least one universal challenger to create a deposit."
|
|
1012
1021
|
);
|
|
1013
1022
|
}
|
|
1014
|
-
function
|
|
1023
|
+
function Ct(e) {
|
|
1015
1024
|
if (e.length === 0)
|
|
1016
1025
|
throw new Error("No spendable UTXOs available");
|
|
1017
1026
|
}
|
|
1018
|
-
function
|
|
1027
|
+
function lr(e) {
|
|
1019
1028
|
const {
|
|
1020
1029
|
vaultAmounts: t,
|
|
1021
1030
|
confirmedUTXOs: r,
|
|
@@ -1024,30 +1033,30 @@ function ur(e) {
|
|
|
1024
1033
|
universalChallengerBtcPubkeys: l,
|
|
1025
1034
|
minDeposit: s,
|
|
1026
1035
|
maxDeposit: i
|
|
1027
|
-
} = e, n =
|
|
1036
|
+
} = e, n = Et(
|
|
1028
1037
|
t,
|
|
1029
1038
|
s,
|
|
1030
1039
|
i
|
|
1031
1040
|
);
|
|
1032
1041
|
if (!n.valid)
|
|
1033
1042
|
throw new Error(n.error);
|
|
1034
|
-
const u =
|
|
1043
|
+
const u = xt(o);
|
|
1035
1044
|
if (!u.valid)
|
|
1036
1045
|
throw new Error(u.error);
|
|
1037
|
-
|
|
1046
|
+
Tt(a), Rt(l), Ct(r);
|
|
1038
1047
|
}
|
|
1039
|
-
class
|
|
1048
|
+
class Pe extends Error {
|
|
1040
1049
|
constructor(t) {
|
|
1041
1050
|
super(t), this.name = "ParticipantKeyDriftError";
|
|
1042
1051
|
}
|
|
1043
1052
|
}
|
|
1044
|
-
function
|
|
1045
|
-
return e instanceof
|
|
1053
|
+
function cr(e) {
|
|
1054
|
+
return e instanceof Pe || e instanceof Error && e.name === "ParticipantKeyDriftError";
|
|
1046
1055
|
}
|
|
1047
|
-
function
|
|
1056
|
+
function Z(e, t, r) {
|
|
1048
1057
|
return t.length === r.length && t.every((o, a) => o === r[a]) ? null : `${e} expected [${t.join(", ")}], got [${r.join(", ")}]`;
|
|
1049
1058
|
}
|
|
1050
|
-
async function
|
|
1059
|
+
async function hr(e) {
|
|
1051
1060
|
const { vaultRegistryReader: t, operationKeyReader: r, vaultIds: o, expected: a } = e, l = a.query;
|
|
1052
1061
|
if (o.length === 0) return;
|
|
1053
1062
|
const s = await t.getVaultKeyEpochsBatch(o), i = [];
|
|
@@ -1055,7 +1064,7 @@ async function cr(e) {
|
|
|
1055
1064
|
const h = o[n];
|
|
1056
1065
|
let c;
|
|
1057
1066
|
try {
|
|
1058
|
-
c = await
|
|
1067
|
+
c = await wt({
|
|
1059
1068
|
operationKeyReader: r,
|
|
1060
1069
|
query: l,
|
|
1061
1070
|
epochs: u
|
|
@@ -1069,13 +1078,13 @@ async function cr(e) {
|
|
|
1069
1078
|
c.vaultProvider.operationBtcPubkey !== a.vaultProvider.operationBtcPubkey && i.push(
|
|
1070
1079
|
`vault ${h}: vault provider key expected ${a.vaultProvider.operationBtcPubkey}, got ${c.vaultProvider.operationBtcPubkey}`
|
|
1071
1080
|
);
|
|
1072
|
-
const d =
|
|
1081
|
+
const d = Z(
|
|
1073
1082
|
`vault ${h}: vault keeper keys`,
|
|
1074
1083
|
a.vaultKeeperOperationKeysSorted,
|
|
1075
1084
|
c.vaultKeeperOperationKeysSorted
|
|
1076
1085
|
);
|
|
1077
1086
|
d && i.push(d);
|
|
1078
|
-
const p =
|
|
1087
|
+
const p = Z(
|
|
1079
1088
|
`vault ${h}: universal challenger keys`,
|
|
1080
1089
|
a.universalChallengerOperationKeysSorted,
|
|
1081
1090
|
c.universalChallengerOperationKeysSorted
|
|
@@ -1083,19 +1092,19 @@ async function cr(e) {
|
|
|
1083
1092
|
p && i.push(p);
|
|
1084
1093
|
}
|
|
1085
1094
|
if (i.length > 0)
|
|
1086
|
-
throw new
|
|
1095
|
+
throw new Pe(
|
|
1087
1096
|
`Aborting BTC broadcast: participant operation keys changed during registration (${i.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
|
|
1088
1097
|
);
|
|
1089
1098
|
}
|
|
1090
|
-
class
|
|
1099
|
+
class be extends Error {
|
|
1091
1100
|
constructor(t) {
|
|
1092
1101
|
super(t), this.name = "RegisteredVaultVersionMismatchError";
|
|
1093
1102
|
}
|
|
1094
1103
|
}
|
|
1095
|
-
function
|
|
1096
|
-
return e instanceof
|
|
1104
|
+
function dr(e) {
|
|
1105
|
+
return e instanceof be || e instanceof Error && e.name === "RegisteredVaultVersionMismatchError";
|
|
1097
1106
|
}
|
|
1098
|
-
async function
|
|
1107
|
+
async function pr(e) {
|
|
1099
1108
|
const {
|
|
1100
1109
|
vaultRegistryReader: t,
|
|
1101
1110
|
vaultIds: r,
|
|
@@ -1116,25 +1125,25 @@ async function dr(e) {
|
|
|
1116
1125
|
`vault ${c}: vaultCoreVersion expected v${s} (build-time active), got v${u.vaultCoreVersion}`
|
|
1117
1126
|
);
|
|
1118
1127
|
}), n.length > 0)
|
|
1119
|
-
throw new
|
|
1128
|
+
throw new be(
|
|
1120
1129
|
`Aborting BTC broadcast: signer-set or offchain-params versions changed during registration (${n.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
|
|
1121
1130
|
);
|
|
1122
1131
|
}
|
|
1123
1132
|
var ye = /* @__PURE__ */ ((e) => (e.CLAIM_EVENT_RECEIVED = "ClaimEventReceived", e.CLAIM_BROADCAST = "ClaimBroadcast", e.ASSERT_BROADCAST = "AssertBroadcast", e.PAYOUT_BROADCAST = "PayoutBroadcast", e.PAYOUT_BLOCKED = "PayoutBlocked", e))(ye || {});
|
|
1124
|
-
const
|
|
1133
|
+
const At = /* @__PURE__ */ new Set([
|
|
1125
1134
|
"PayoutBroadcast",
|
|
1126
1135
|
"PayoutBlocked"
|
|
1127
1136
|
/* PAYOUT_BLOCKED */
|
|
1128
1137
|
]);
|
|
1129
|
-
function
|
|
1138
|
+
function gr(e) {
|
|
1130
1139
|
return Object.values(ye).includes(
|
|
1131
1140
|
e
|
|
1132
1141
|
);
|
|
1133
1142
|
}
|
|
1134
|
-
function
|
|
1135
|
-
return !!e &&
|
|
1143
|
+
function fr(e) {
|
|
1144
|
+
return !!e && At.has(e);
|
|
1136
1145
|
}
|
|
1137
|
-
class
|
|
1146
|
+
class _t extends Error {
|
|
1138
1147
|
constructor(r, o) {
|
|
1139
1148
|
super(`Refund not yet mature (BIP68 not final): ${o.message}`);
|
|
1140
1149
|
S(this, "vaultId");
|
|
@@ -1142,21 +1151,21 @@ class At extends Error {
|
|
|
1142
1151
|
this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = o;
|
|
1143
1152
|
}
|
|
1144
1153
|
}
|
|
1145
|
-
const
|
|
1146
|
-
function
|
|
1154
|
+
const St = /^0x[0-9a-fA-F]{64}$/, $t = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, we = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, ke = 160, ee = 2e3, te = 10n, re = 100n;
|
|
1155
|
+
function mr(e) {
|
|
1147
1156
|
if (!Number.isFinite(e) || e <= 0)
|
|
1148
1157
|
throw new Error(
|
|
1149
1158
|
`feeRateSatsVb must be a positive finite number, got ${e}`
|
|
1150
1159
|
);
|
|
1151
|
-
return BigInt(Math.ceil(e *
|
|
1160
|
+
return BigInt(Math.ceil(e * ke));
|
|
1152
1161
|
}
|
|
1153
|
-
const
|
|
1162
|
+
const Bt = 1, It = /non-BIP68-final/i;
|
|
1154
1163
|
function U(e, t) {
|
|
1155
1164
|
if (e.length !== 66)
|
|
1156
1165
|
throw new Error(
|
|
1157
1166
|
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
1158
1167
|
);
|
|
1159
|
-
if (!
|
|
1168
|
+
if (!St.test(e))
|
|
1160
1169
|
throw new Error(
|
|
1161
1170
|
`${t} must contain only hex characters after the 0x prefix`
|
|
1162
1171
|
);
|
|
@@ -1165,7 +1174,7 @@ function L(e, t) {
|
|
|
1165
1174
|
if (!Number.isInteger(e) || e < 0)
|
|
1166
1175
|
throw new Error(`${t} must be a non-negative integer, got ${e}`);
|
|
1167
1176
|
}
|
|
1168
|
-
function
|
|
1177
|
+
function Vt(e) {
|
|
1169
1178
|
if (U(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0)
|
|
1170
1179
|
throw new Error(
|
|
1171
1180
|
`htlcVout must be a non-negative integer, got ${e.htlcVout}`
|
|
@@ -1199,24 +1208,24 @@ function It(e) {
|
|
|
1199
1208
|
if (L(e.offchainParamsVersion, "offchainParamsVersion"), L(e.appVaultKeepersVersion, "appVaultKeepersVersion"), L(
|
|
1200
1209
|
e.universalChallengersVersion,
|
|
1201
1210
|
"universalChallengersVersion"
|
|
1202
|
-
),
|
|
1211
|
+
), Xe(
|
|
1203
1212
|
e.vaultCoreVersion,
|
|
1204
1213
|
"VaultRefundData.vaultCoreVersion"
|
|
1205
1214
|
), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
|
|
1206
1215
|
throw new Error("unsignedPrePeginTxHex must be a non-empty hex string");
|
|
1207
|
-
if (
|
|
1216
|
+
if (!$t.test(e.unsignedPrePeginTxHex))
|
|
1208
1217
|
throw new Error(
|
|
1209
1218
|
"unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
|
|
1210
1219
|
);
|
|
1211
|
-
if (!e.depositorBtcPubkey || !
|
|
1220
|
+
if (!e.depositorBtcPubkey || !we.test(e.depositorBtcPubkey))
|
|
1212
1221
|
throw new Error(
|
|
1213
1222
|
"depositorBtcPubkey must be 32 or 33 bytes of hex (optional 0x prefix)"
|
|
1214
1223
|
);
|
|
1215
1224
|
if (typeof e.amount != "bigint" || e.amount <= 0n)
|
|
1216
1225
|
throw new Error(`amount must be a positive bigint, got ${e.amount}`);
|
|
1217
1226
|
}
|
|
1218
|
-
function
|
|
1219
|
-
if (!e.vaultProviderPubkey || !
|
|
1227
|
+
function Kt(e) {
|
|
1228
|
+
if (!e.vaultProviderPubkey || !we.test(e.vaultProviderPubkey))
|
|
1220
1229
|
throw new Error("vaultProviderPubkey must be 32 or 33 bytes of hex");
|
|
1221
1230
|
if (e.vaultKeeperPubkeys.length === 0)
|
|
1222
1231
|
throw new Error("vaultKeeperPubkeys must be non-empty");
|
|
@@ -1241,7 +1250,7 @@ function Vt(e) {
|
|
|
1241
1250
|
`councilQuorum (${e.councilQuorum}) must be in [1, councilSize=${e.councilSize}]`
|
|
1242
1251
|
);
|
|
1243
1252
|
}
|
|
1244
|
-
async function
|
|
1253
|
+
async function vr(e) {
|
|
1245
1254
|
const {
|
|
1246
1255
|
vaultId: t,
|
|
1247
1256
|
readVault: r,
|
|
@@ -1253,48 +1262,48 @@ async function mr(e) {
|
|
|
1253
1262
|
} = e;
|
|
1254
1263
|
i == null || i.throwIfAborted(), U(t, "vaultId");
|
|
1255
1264
|
const n = await r();
|
|
1256
|
-
|
|
1265
|
+
Vt(n), i == null || i.throwIfAborted();
|
|
1257
1266
|
const u = await o(n);
|
|
1258
|
-
if (
|
|
1267
|
+
if (Kt(u), i == null || i.throwIfAborted(), !Number.isFinite(a) || a <= 0)
|
|
1259
1268
|
throw new Error(`feeRate must be a positive number, got ${a}`);
|
|
1260
|
-
if (a >
|
|
1269
|
+
if (a > ee)
|
|
1261
1270
|
throw new Error(
|
|
1262
|
-
`feeRate ${a} sat/vB exceeds refund safety cap ${
|
|
1271
|
+
`feeRate ${a} sat/vB exceeds refund safety cap ${ee} sat/vB; refusing to sign refund.`
|
|
1263
1272
|
);
|
|
1264
|
-
const h = BigInt(Math.ceil(a *
|
|
1273
|
+
const h = BigInt(Math.ceil(a * ke)), c = n.amount * te / re;
|
|
1265
1274
|
if (h > c)
|
|
1266
1275
|
throw new Error(
|
|
1267
|
-
`Refund fee ${h} sats exceeds the per-vault safety cap of ${c} sats (${
|
|
1276
|
+
`Refund fee ${h} sats exceeds the per-vault safety cap of ${c} sats (${te}/${re} of vault.amount=${n.amount}); refusing to sign refund.`
|
|
1268
1277
|
);
|
|
1269
1278
|
i == null || i.throwIfAborted();
|
|
1270
1279
|
const d = O(
|
|
1271
1280
|
n.depositorBtcPubkey
|
|
1272
|
-
), p =
|
|
1281
|
+
), p = P(n.unsignedPrePeginTxHex), g = $e(p);
|
|
1273
1282
|
if (g !== void 0 && g.vout !== n.batch.length)
|
|
1274
1283
|
throw new Error(
|
|
1275
1284
|
`Auth-anchor OP_RETURN at vout ${g.vout} does not match batch size (${n.batch.length} HTLC outputs expect the anchor at vout ${n.batch.length}). Refund refused — sibling HTLC vector is incomplete.`
|
|
1276
1285
|
);
|
|
1277
|
-
const
|
|
1278
|
-
let
|
|
1286
|
+
const m = g == null ? void 0 : g.hash;
|
|
1287
|
+
let f;
|
|
1279
1288
|
try {
|
|
1280
|
-
|
|
1281
|
-
} catch (
|
|
1289
|
+
f = $.fromHex(p);
|
|
1290
|
+
} catch (y) {
|
|
1282
1291
|
throw new Error(
|
|
1283
|
-
`Failed to parse funded Pre-PegIn transaction hex: ${
|
|
1292
|
+
`Failed to parse funded Pre-PegIn transaction hex: ${y instanceof Error ? y.message : String(y)}`
|
|
1284
1293
|
);
|
|
1285
1294
|
}
|
|
1286
|
-
if (
|
|
1295
|
+
if (f.outs.length < n.batch.length)
|
|
1287
1296
|
throw new Error(
|
|
1288
|
-
`Funded Pre-PegIn tx has ${
|
|
1297
|
+
`Funded Pre-PegIn tx has ${f.outs.length} outputs but batch requires at least ${n.batch.length} HTLC outputs. Refund refused — funded tx shape disagrees with sibling vector.`
|
|
1289
1298
|
);
|
|
1290
|
-
const { psbtHex:
|
|
1299
|
+
const { psbtHex: v } = await Fe({
|
|
1291
1300
|
prePeginParams: {
|
|
1292
1301
|
vaultCoreVersion: n.vaultCoreVersion,
|
|
1293
1302
|
depositorPubkey: d,
|
|
1294
|
-
vaultProviderPubkey:
|
|
1295
|
-
vaultKeeperPubkeys: u.vaultKeeperPubkeys.map(
|
|
1296
|
-
universalChallengerPubkeys: u.universalChallengerPubkeys.map(
|
|
1297
|
-
hashlocks: n.batch.map((
|
|
1303
|
+
vaultProviderPubkey: P(u.vaultProviderPubkey),
|
|
1304
|
+
vaultKeeperPubkeys: u.vaultKeeperPubkeys.map(P),
|
|
1305
|
+
universalChallengerPubkeys: u.universalChallengerPubkeys.map(P),
|
|
1306
|
+
hashlocks: n.batch.map((y) => P(y.hashlock)),
|
|
1298
1307
|
timelockRefund: u.timelockRefund,
|
|
1299
1308
|
// `batch[i].amount` is the on-chain vault deposit (peg-in) amount, which
|
|
1300
1309
|
// is exactly what WASM's `pegInAmounts` expects — it re-adds the protocol
|
|
@@ -1302,14 +1311,14 @@ async function mr(e) {
|
|
|
1302
1311
|
// HTLC output. `buildRefundPsbt`'s value cross-check then binds the result
|
|
1303
1312
|
// to the funded tx bytes, refusing the refund if the template's HTLC value
|
|
1304
1313
|
// disagrees with the on-chain commitment.
|
|
1305
|
-
pegInAmounts: n.batch.map((
|
|
1314
|
+
pegInAmounts: n.batch.map((y) => y.amount),
|
|
1306
1315
|
feeRate: u.feeRate,
|
|
1307
1316
|
minPeginFeeRate: u.minPeginFeeRate,
|
|
1308
1317
|
numLocalChallengers: u.numLocalChallengers,
|
|
1309
1318
|
councilQuorum: u.councilQuorum,
|
|
1310
1319
|
councilSize: u.councilSize,
|
|
1311
1320
|
network: u.network,
|
|
1312
|
-
authAnchorHash:
|
|
1321
|
+
authAnchorHash: m
|
|
1313
1322
|
},
|
|
1314
1323
|
fundedPrePeginTxHex: p,
|
|
1315
1324
|
htlcVout: n.htlcVout,
|
|
@@ -1318,41 +1327,41 @@ async function mr(e) {
|
|
|
1318
1327
|
// prefix" and flows into the WASM HTLC connector derivation; a prefixed
|
|
1319
1328
|
// value would derive the wrong refund script leaf and yield an
|
|
1320
1329
|
// unspendable PSBT. Match the `hashlocks` array handling above.
|
|
1321
|
-
hashlock:
|
|
1330
|
+
hashlock: P(n.hashlock)
|
|
1322
1331
|
});
|
|
1323
1332
|
i == null || i.throwIfAborted();
|
|
1324
1333
|
const w = K(
|
|
1325
1334
|
n.depositorBtcPubkey,
|
|
1326
|
-
|
|
1327
|
-
),
|
|
1335
|
+
Bt
|
|
1336
|
+
), k = await l(v, w);
|
|
1328
1337
|
B({
|
|
1329
|
-
requestedPsbtHex:
|
|
1330
|
-
returnedPsbtHex:
|
|
1338
|
+
requestedPsbtHex: v,
|
|
1339
|
+
returnedPsbtHex: k
|
|
1331
1340
|
});
|
|
1332
|
-
const
|
|
1333
|
-
|
|
1341
|
+
const b = 0, x = I(
|
|
1342
|
+
k,
|
|
1334
1343
|
d,
|
|
1335
|
-
|
|
1344
|
+
b
|
|
1336
1345
|
);
|
|
1337
1346
|
V({
|
|
1338
|
-
requestedPsbtHex:
|
|
1347
|
+
requestedPsbtHex: v,
|
|
1339
1348
|
signatureHex: x,
|
|
1340
1349
|
signerXOnlyPubkeyHex: d,
|
|
1341
|
-
inputIndex:
|
|
1350
|
+
inputIndex: b
|
|
1342
1351
|
});
|
|
1343
|
-
const A =
|
|
1344
|
-
requestedPsbtHex:
|
|
1352
|
+
const A = he({
|
|
1353
|
+
requestedPsbtHex: v,
|
|
1345
1354
|
signaturesHex: [x],
|
|
1346
1355
|
signerXOnlyPubkeyHex: d
|
|
1347
1356
|
});
|
|
1348
1357
|
i == null || i.throwIfAborted();
|
|
1349
1358
|
try {
|
|
1350
1359
|
return await s(A);
|
|
1351
|
-
} catch (
|
|
1352
|
-
throw
|
|
1360
|
+
} catch (y) {
|
|
1361
|
+
throw y instanceof Error && It.test(y.message) ? new _t(t, y) : y;
|
|
1353
1362
|
}
|
|
1354
1363
|
}
|
|
1355
|
-
class
|
|
1364
|
+
class oe extends Error {
|
|
1356
1365
|
constructor(r, o, a) {
|
|
1357
1366
|
super(r);
|
|
1358
1367
|
/** Fee the reclaim would have paid, in satoshis. */
|
|
@@ -1362,13 +1371,13 @@ class re extends Error {
|
|
|
1362
1371
|
this.name = "ReclaimUneconomicalError", this.feeSats = o, this.sweptTotalSats = a;
|
|
1363
1372
|
}
|
|
1364
1373
|
}
|
|
1365
|
-
const
|
|
1366
|
-
async function
|
|
1374
|
+
const ne = 2e3, se = 25n, ae = 100n, Pr = 10n;
|
|
1375
|
+
async function Ot(e, t, r) {
|
|
1367
1376
|
for (let o = 0; o < e.length; o++) {
|
|
1368
|
-
const a =
|
|
1369
|
-
await
|
|
1370
|
-
|
|
1371
|
-
|
|
1377
|
+
const a = Ue(e[o].depositorSignedPeginTxHex), l = ue(
|
|
1378
|
+
await Ge(
|
|
1379
|
+
P(a),
|
|
1380
|
+
P(r)
|
|
1372
1381
|
)
|
|
1373
1382
|
).toLowerCase();
|
|
1374
1383
|
if (l !== t[o].toLowerCase())
|
|
@@ -1377,7 +1386,7 @@ async function Kt(e, t, r) {
|
|
|
1377
1386
|
);
|
|
1378
1387
|
}
|
|
1379
1388
|
}
|
|
1380
|
-
async function
|
|
1389
|
+
async function br(e) {
|
|
1381
1390
|
const {
|
|
1382
1391
|
vaultIds: t,
|
|
1383
1392
|
depositorEthAddress: r,
|
|
@@ -1392,9 +1401,9 @@ async function Pr(e) {
|
|
|
1392
1401
|
throw new Error("Reclaim requires at least one vault id; got none.");
|
|
1393
1402
|
if (!Number.isFinite(l) || l <= 0)
|
|
1394
1403
|
throw new Error(`feeRate must be a positive number, got ${l}`);
|
|
1395
|
-
if (l >
|
|
1396
|
-
throw new
|
|
1397
|
-
`Fee rate ${l} sat/vB exceeds the reclaim safety cap of ${
|
|
1404
|
+
if (l > ne)
|
|
1405
|
+
throw new oe(
|
|
1406
|
+
`Fee rate ${l} sat/vB exceeds the reclaim safety cap of ${ne} sat/vB; refusing to sign.`,
|
|
1398
1407
|
0n,
|
|
1399
1408
|
0n
|
|
1400
1409
|
);
|
|
@@ -1403,100 +1412,100 @@ async function Pr(e) {
|
|
|
1403
1412
|
throw new Error(
|
|
1404
1413
|
`readVaults returned ${u.length} reserves for ${t.length} vault id(s); refusing to sweep a set that does not match the request.`
|
|
1405
1414
|
);
|
|
1406
|
-
await
|
|
1407
|
-
const h = O(o), c = u.map((
|
|
1408
|
-
depositorSignedPeginTxHex:
|
|
1409
|
-
observed:
|
|
1410
|
-
expectedValue:
|
|
1411
|
-
})), d =
|
|
1415
|
+
await Ot(u, t, r), n == null || n.throwIfAborted();
|
|
1416
|
+
const h = O(o), c = u.map((b) => ({
|
|
1417
|
+
depositorSignedPeginTxHex: b.depositorSignedPeginTxHex,
|
|
1418
|
+
observed: b.observed,
|
|
1419
|
+
expectedValue: b.expectedClaimValue
|
|
1420
|
+
})), d = Me(l, c.length), p = c.reduce((b, x) => b + x.expectedValue, 0n), g = p * se / ae;
|
|
1412
1421
|
if (d > g)
|
|
1413
|
-
throw new
|
|
1414
|
-
`Reclaim fee ${d} sats exceeds ${
|
|
1422
|
+
throw new oe(
|
|
1423
|
+
`Reclaim fee ${d} sats exceeds ${se}/${ae} of the swept total (${p} sats, cap ${g} sats). The reserve is not at risk — it stays where it is until fee rates fall.`,
|
|
1415
1424
|
d,
|
|
1416
1425
|
p
|
|
1417
1426
|
);
|
|
1418
1427
|
n == null || n.throwIfAborted();
|
|
1419
|
-
const { psbtHex:
|
|
1428
|
+
const { psbtHex: m } = Le({
|
|
1420
1429
|
depositorPubkey: h,
|
|
1421
1430
|
inputs: c,
|
|
1422
1431
|
feeSats: d
|
|
1423
1432
|
});
|
|
1424
1433
|
n == null || n.throwIfAborted();
|
|
1425
|
-
const
|
|
1434
|
+
const f = K(
|
|
1426
1435
|
o,
|
|
1427
1436
|
c.length
|
|
1428
|
-
),
|
|
1437
|
+
), v = await s(m, f);
|
|
1429
1438
|
B({
|
|
1430
|
-
requestedPsbtHex:
|
|
1431
|
-
returnedPsbtHex:
|
|
1439
|
+
requestedPsbtHex: m,
|
|
1440
|
+
returnedPsbtHex: v
|
|
1432
1441
|
});
|
|
1433
|
-
const w = c.map((
|
|
1442
|
+
const w = c.map((b, x) => {
|
|
1434
1443
|
const A = I(
|
|
1435
|
-
|
|
1444
|
+
v,
|
|
1436
1445
|
h,
|
|
1437
1446
|
x
|
|
1438
1447
|
);
|
|
1439
1448
|
return V({
|
|
1440
|
-
requestedPsbtHex:
|
|
1449
|
+
requestedPsbtHex: m,
|
|
1441
1450
|
signatureHex: A,
|
|
1442
1451
|
signerXOnlyPubkeyHex: h,
|
|
1443
1452
|
inputIndex: x
|
|
1444
1453
|
}), A;
|
|
1445
|
-
}),
|
|
1446
|
-
requestedPsbtHex:
|
|
1454
|
+
}), k = he({
|
|
1455
|
+
requestedPsbtHex: m,
|
|
1447
1456
|
signaturesHex: w,
|
|
1448
1457
|
signerXOnlyPubkeyHex: h
|
|
1449
1458
|
});
|
|
1450
|
-
return n == null || n.throwIfAborted(), i(
|
|
1459
|
+
return n == null || n.throwIfAborted(), i(k);
|
|
1451
1460
|
}
|
|
1452
1461
|
export {
|
|
1453
|
-
|
|
1454
|
-
|
|
1462
|
+
Pt as A,
|
|
1463
|
+
W as B,
|
|
1455
1464
|
yt as C,
|
|
1456
|
-
|
|
1465
|
+
wt as D,
|
|
1457
1466
|
ye as E,
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1467
|
+
gr as F,
|
|
1468
|
+
fr as G,
|
|
1469
|
+
_t as H,
|
|
1470
|
+
vr as I,
|
|
1471
|
+
mr as J,
|
|
1472
|
+
re as K,
|
|
1473
|
+
te as L,
|
|
1474
|
+
ee as M,
|
|
1475
|
+
ke as N,
|
|
1476
|
+
oe as O,
|
|
1477
|
+
Ye as P,
|
|
1478
|
+
br as Q,
|
|
1479
|
+
be as R,
|
|
1480
|
+
ae as S,
|
|
1481
|
+
se as T,
|
|
1482
|
+
ne as U,
|
|
1483
|
+
Pr as V,
|
|
1484
|
+
Yt as a,
|
|
1485
|
+
Jt as b,
|
|
1486
|
+
pe as c,
|
|
1487
|
+
ge as d,
|
|
1488
|
+
Zt as e,
|
|
1489
|
+
rr as f,
|
|
1490
|
+
sr as g,
|
|
1491
|
+
ar as h,
|
|
1492
|
+
tt as i,
|
|
1493
|
+
lr as j,
|
|
1494
|
+
ur as k,
|
|
1495
|
+
ir as l,
|
|
1496
|
+
Et as m,
|
|
1497
|
+
xt as n,
|
|
1498
|
+
Pe as o,
|
|
1499
|
+
cr as p,
|
|
1500
|
+
hr as q,
|
|
1501
|
+
tr as r,
|
|
1502
|
+
ut as s,
|
|
1503
|
+
dr as t,
|
|
1504
|
+
pr as u,
|
|
1505
|
+
nr as v,
|
|
1506
|
+
er as w,
|
|
1507
|
+
fe as x,
|
|
1508
|
+
or as y,
|
|
1500
1509
|
D as z
|
|
1501
1510
|
};
|
|
1502
|
-
//# sourceMappingURL=buildAndBroadcastReclaim-
|
|
1511
|
+
//# sourceMappingURL=buildAndBroadcastReclaim-QIN8Mcwq.js.map
|