@babylonlabs-io/ts-sdk 0.58.1 → 0.59.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/BTCVaultRegistry.abi-3VLWva2x.cjs +2 -0
- package/dist/BTCVaultRegistry.abi-3VLWva2x.cjs.map +1 -0
- package/dist/{BTCVaultRegistry.abi-CixOlp3B.js → BTCVaultRegistry.abi-B3BLhpJ4.js} +30 -13
- package/dist/BTCVaultRegistry.abi-B3BLhpJ4.js.map +1 -0
- package/dist/{PeginManager-C8ixWlUM.js → PeginManager-1R9dMB1G.js} +3 -3
- package/dist/{PeginManager-C8ixWlUM.js.map → PeginManager-1R9dMB1G.js.map} +1 -1
- package/dist/{PeginManager-CogqZaa2.cjs → PeginManager-OXUOsgz2.cjs} +2 -2
- package/dist/{PeginManager-CogqZaa2.cjs.map → PeginManager-OXUOsgz2.cjs.map} +1 -1
- package/dist/{batchPoll-D5IDDOa8.cjs → batchPoll-C4hwVFa8.cjs} +2 -2
- package/dist/batchPoll-C4hwVFa8.cjs.map +1 -0
- package/dist/{batchPoll-B0VxT62K.js → batchPoll-L9LzMl1E.js} +3 -3
- package/dist/batchPoll-L9LzMl1E.js.map +1 -0
- package/dist/{buildAndBroadcastRefund-DBA-Mp4I.js → buildAndBroadcastRefund-DpF_b3d9.js} +457 -428
- package/dist/buildAndBroadcastRefund-DpF_b3d9.js.map +1 -0
- package/dist/buildAndBroadcastRefund-rSxXMwFd.cjs +2 -0
- package/dist/buildAndBroadcastRefund-rSxXMwFd.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +52 -51
- package/dist/{mempoolApi-CMHEz4ez.js → mempoolApi-BQKF5MTr.js} +96 -79
- package/dist/mempoolApi-BQKF5MTr.js.map +1 -0
- package/dist/mempoolApi-BxhMqJ4f.cjs +2 -0
- package/dist/mempoolApi-BxhMqJ4f.cjs.map +1 -0
- package/dist/onChainBtcPubkey-C_a2L3kL.cjs.map +1 -1
- package/dist/onChainBtcPubkey-DeF4cKoO.js.map +1 -1
- package/dist/{peginState-BB81JI6I.js → peginState-CxDiaKuk.js} +26 -19
- package/dist/peginState-CxDiaKuk.js.map +1 -0
- package/dist/peginState-eaQ4IO_R.cjs +2 -0
- package/dist/peginState-eaQ4IO_R.cjs.map +1 -0
- package/dist/{reservation-CbAXa7VG.js → reservation-B4i_PQhY.js} +2 -2
- package/dist/{reservation-CbAXa7VG.js.map → reservation-B4i_PQhY.js.map} +1 -1
- package/dist/{reservation-RGKvg2x6.cjs → reservation-CDbInVw0.cjs} +2 -2
- package/dist/{reservation-RGKvg2x6.cjs.map → reservation-CDbInVw0.cjs.map} +1 -1
- package/dist/tbv/core/clients/eth/onChainBtcPubkey.d.ts +2 -2
- package/dist/tbv/core/clients/eth/types.d.ts +15 -3
- package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts +24 -7
- 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/contracts/abis/BTCVaultRegistry.abi.d.ts +14 -14
- package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts.map +1 -1
- package/dist/tbv/core/contracts/index.cjs +1 -1
- package/dist/tbv/core/contracts/index.js +1 -1
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +58 -57
- package/dist/tbv/core/managers/index.cjs +1 -1
- package/dist/tbv/core/managers/index.js +1 -1
- package/dist/tbv/core/services/activation/activateVault.d.ts +45 -0
- package/dist/tbv/core/services/activation/activateVault.d.ts.map +1 -1
- package/dist/tbv/core/services/activation/index.d.ts +1 -1
- package/dist/tbv/core/services/activation/index.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/peginState.d.ts +24 -0
- package/dist/tbv/core/services/deposit/peginState.d.ts.map +1 -1
- 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 +34 -33
- package/dist/tbv/core/utils/index.cjs +1 -1
- package/dist/tbv/core/utils/index.js +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +58 -57
- package/package.json +1 -1
- package/dist/BTCVaultRegistry.abi-AUAyCHal.cjs +0 -2
- package/dist/BTCVaultRegistry.abi-AUAyCHal.cjs.map +0 -1
- package/dist/BTCVaultRegistry.abi-CixOlp3B.js.map +0 -1
- package/dist/batchPoll-B0VxT62K.js.map +0 -1
- package/dist/batchPoll-D5IDDOa8.cjs.map +0 -1
- package/dist/buildAndBroadcastRefund-BL8u-Ti4.cjs +0 -2
- package/dist/buildAndBroadcastRefund-BL8u-Ti4.cjs.map +0 -1
- package/dist/buildAndBroadcastRefund-DBA-Mp4I.js.map +0 -1
- package/dist/mempoolApi-CMHEz4ez.js.map +0 -1
- package/dist/mempoolApi-DfD3_Y6v.cjs +0 -2
- package/dist/mempoolApi-DfD3_Y6v.cjs.map +0 -1
- package/dist/peginState-BB81JI6I.js.map +0 -1
- package/dist/peginState-CBBJw4Za.cjs +0 -2
- package/dist/peginState-CBBJw4Za.cjs.map +0 -1
|
@@ -1,122 +1,148 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var A = (e, t, r) =>
|
|
4
|
-
import { B as
|
|
5
|
-
import { e as
|
|
6
|
-
import { v as
|
|
7
|
-
import { D as E, c as
|
|
8
|
-
import { Transaction as $, Psbt as
|
|
9
|
-
import { c as
|
|
10
|
-
import { c as
|
|
1
|
+
var ge = Object.defineProperty;
|
|
2
|
+
var fe = (e, t, r) => t in e ? ge(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var A = (e, t, r) => fe(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { B as te } from "./BTCVaultRegistry.abi-B3BLhpJ4.js";
|
|
5
|
+
import { e as ve, v as ye, s as d, u as re, p as L, c as k, f as C } from "./bitcoin-d9eaaZB_.js";
|
|
6
|
+
import { v as Pe, b as me, s as be, P as we, d as ke } from "./signPsbtsWithFallback-eY1YgV13.js";
|
|
7
|
+
import { D as E, c as xe, b as Ee, R as Ce, d as ne } from "./json-rpc-client-DuUARJvV.js";
|
|
8
|
+
import { Transaction as $, Psbt as Te } from "bitcoinjs-lib";
|
|
9
|
+
import { c as Se, d as N, e as D, f as F } from "./verifyScriptPathSchnorrSignature-Bav08_7R.js";
|
|
10
|
+
import { c as $e, a as _e, b as Be } from "./noPayout-DuE-UyhQ.js";
|
|
11
11
|
import { c as M } from "./signing-DaLvGwQe.js";
|
|
12
12
|
import { a as X } from "./onChainBtcPubkey-DeF4cKoO.js";
|
|
13
|
-
import { a as
|
|
14
|
-
const
|
|
13
|
+
import { a as Ae } from "./constants-GjWXdaqV.js";
|
|
14
|
+
const Re = /^0x[0-9a-fA-F]{64}$/, Ve = /^0x[0-9a-fA-F]{40}$/, Ke = /^0x([0-9a-fA-F]{2})*$/;
|
|
15
15
|
function R(e, t) {
|
|
16
16
|
if (e.length !== 66)
|
|
17
17
|
throw new Error(
|
|
18
18
|
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
19
19
|
);
|
|
20
|
-
if (!
|
|
20
|
+
if (!Re.test(e))
|
|
21
21
|
throw new Error(
|
|
22
22
|
`${t} must contain only hex characters after the 0x prefix`
|
|
23
23
|
);
|
|
24
24
|
}
|
|
25
|
-
function
|
|
26
|
-
if (!
|
|
25
|
+
function Ie(e, t) {
|
|
26
|
+
if (!Ve.test(e))
|
|
27
27
|
throw new Error(
|
|
28
28
|
`${t} must be a 20-byte 0x-prefixed hex address (42 chars)`
|
|
29
29
|
);
|
|
30
30
|
}
|
|
31
|
-
function
|
|
31
|
+
function Oe(e, t) {
|
|
32
32
|
if (!Ke.test(e))
|
|
33
33
|
throw new Error(
|
|
34
34
|
`${t} must be a 0x-prefixed hex string with an even number of hex chars`
|
|
35
35
|
);
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
function oe(e) {
|
|
38
|
+
Ie(e.btcVaultRegistryAddress, "btcVaultRegistryAddress"), R(e.vaultId, "vaultId");
|
|
39
|
+
const t = ve(e.secret);
|
|
40
|
+
if (R(t, "secret"), e.hashlock !== void 0 && (R(e.hashlock, "hashlock"), !Pe(t, e.hashlock)))
|
|
41
|
+
throw new Error(
|
|
42
|
+
"Invalid secret: SHA256(secret) does not match the provided hashlock"
|
|
43
|
+
);
|
|
44
|
+
return t;
|
|
45
|
+
}
|
|
46
|
+
async function Bt(e) {
|
|
38
47
|
const {
|
|
39
48
|
btcVaultRegistryAddress: t,
|
|
40
49
|
vaultId: r,
|
|
41
50
|
hashlock: n,
|
|
42
|
-
activationMetadata:
|
|
43
|
-
writeContract:
|
|
51
|
+
activationMetadata: a,
|
|
52
|
+
writeContract: u,
|
|
44
53
|
signal: o
|
|
45
54
|
} = e;
|
|
46
|
-
o == null || o.throwIfAborted()
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
55
|
+
o == null || o.throwIfAborted();
|
|
56
|
+
const s = oe({
|
|
57
|
+
btcVaultRegistryAddress: t,
|
|
58
|
+
vaultId: r,
|
|
59
|
+
secret: e.secret,
|
|
60
|
+
hashlock: n
|
|
61
|
+
});
|
|
62
|
+
return Oe(a, "activationMetadata"), u({
|
|
53
63
|
address: t,
|
|
54
|
-
abi:
|
|
64
|
+
abi: te,
|
|
55
65
|
functionName: "activateVaultWithSecret",
|
|
56
|
-
args: [r,
|
|
66
|
+
args: [r, s, a]
|
|
57
67
|
});
|
|
58
68
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
69
|
+
async function At(e) {
|
|
70
|
+
const { btcVaultRegistryAddress: t, vaultId: r, hashlock: n, writeContract: a, signal: u } = e;
|
|
71
|
+
u == null || u.throwIfAborted();
|
|
72
|
+
const o = oe({
|
|
73
|
+
btcVaultRegistryAddress: t,
|
|
74
|
+
vaultId: r,
|
|
75
|
+
secret: e.secret,
|
|
76
|
+
hashlock: n
|
|
77
|
+
});
|
|
78
|
+
return a({
|
|
79
|
+
address: t,
|
|
80
|
+
abi: te,
|
|
81
|
+
functionName: "activateVaultWithSecretAndRedeem",
|
|
82
|
+
args: [r, o]
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
const G = 1, He = 1;
|
|
86
|
+
function Ne(e, t) {
|
|
87
|
+
const r = d(t).toLowerCase(), a = e.map((u) => d(u).toLowerCase()).filter((u) => u !== r);
|
|
88
|
+
if (a.length === 0)
|
|
63
89
|
throw new Error(
|
|
64
90
|
"Cannot derive localChallengers: vault keeper set is empty (or contains only the depositor)"
|
|
65
91
|
);
|
|
66
|
-
if (new Set(
|
|
92
|
+
if (new Set(a).size !== a.length)
|
|
67
93
|
throw new Error(
|
|
68
94
|
"Cannot derive localChallengers: duplicate vaultKeeper key — signing context is misconfigured"
|
|
69
95
|
);
|
|
70
|
-
return
|
|
96
|
+
return a;
|
|
71
97
|
}
|
|
72
|
-
function
|
|
98
|
+
function De(e, t, r) {
|
|
73
99
|
const n = r.map(
|
|
74
100
|
(c) => d(c).toLowerCase()
|
|
75
|
-
),
|
|
76
|
-
if (
|
|
101
|
+
), a = t.filter((c) => n.includes(c));
|
|
102
|
+
if (a.length > 0)
|
|
77
103
|
throw new Error(
|
|
78
|
-
`Cannot validate challenger set: vault keepers and universal challengers overlap (${
|
|
104
|
+
`Cannot validate challenger set: vault keepers and universal challengers overlap (${a.join(", ")})`
|
|
79
105
|
);
|
|
80
|
-
const
|
|
106
|
+
const u = [...t, ...n], o = e.map(
|
|
81
107
|
(c) => d(c.challenger_pubkey).toLowerCase()
|
|
82
|
-
),
|
|
83
|
-
if (
|
|
108
|
+
), s = new Set(o);
|
|
109
|
+
if (s.size !== o.length)
|
|
84
110
|
throw new Error(
|
|
85
111
|
"Depositor graph contains duplicate challenger entries in challenger_presign_data"
|
|
86
112
|
);
|
|
87
|
-
const
|
|
113
|
+
const l = new Set(u), i = u.filter((c) => !s.has(c)), p = o.filter((c) => !l.has(c));
|
|
88
114
|
if (i.length > 0 || p.length > 0)
|
|
89
115
|
throw new Error(
|
|
90
116
|
"Depositor graph challenger set does not match expected (local ∪ universal)" + (i.length > 0 ? ` (missing: ${i.join(", ")})` : "") + (p.length > 0 ? ` (unexpected: ${p.join(", ")})` : "")
|
|
91
117
|
);
|
|
92
118
|
}
|
|
93
|
-
function
|
|
119
|
+
function Fe(e, t) {
|
|
94
120
|
const r = e.ins[t];
|
|
95
|
-
return
|
|
121
|
+
return re(new Uint8Array(r.hash).slice().reverse());
|
|
96
122
|
}
|
|
97
|
-
function
|
|
98
|
-
const
|
|
99
|
-
if (
|
|
123
|
+
function V(e, t, r, n, a) {
|
|
124
|
+
const u = e.ins[t];
|
|
125
|
+
if (u.index !== 0)
|
|
100
126
|
throw new Error(
|
|
101
|
-
`NoPayout (challenger ${
|
|
127
|
+
`NoPayout (challenger ${a}) input ${t} expected to spend ${n} vout 0, got vout ${u.index}`
|
|
102
128
|
);
|
|
103
|
-
const o = r.getId(),
|
|
104
|
-
if (
|
|
129
|
+
const o = r.getId(), s = Fe(e, t);
|
|
130
|
+
if (s !== o)
|
|
105
131
|
throw new Error(
|
|
106
|
-
`NoPayout (challenger ${
|
|
132
|
+
`NoPayout (challenger ${a}) input ${t} does not reference ${n} (expected txid ${o}, got ${s})`
|
|
107
133
|
);
|
|
108
134
|
}
|
|
109
|
-
async function
|
|
110
|
-
const n = [],
|
|
135
|
+
async function Me(e, t, r) {
|
|
136
|
+
const n = [], a = [], u = [], o = Ne(
|
|
111
137
|
r.vaultKeeperBtcPubkeys,
|
|
112
138
|
r.depositorBtcPubkey
|
|
113
139
|
);
|
|
114
|
-
|
|
140
|
+
De(
|
|
115
141
|
e.challenger_presign_data,
|
|
116
142
|
o,
|
|
117
143
|
r.universalChallengerBtcPubkeys
|
|
118
144
|
);
|
|
119
|
-
const
|
|
145
|
+
const s = await Se({
|
|
120
146
|
vaultCoreVersion: r.vaultCoreVersion,
|
|
121
147
|
vkClaimerPayoutScriptPubKeys: r.vkClaimerPayoutScriptPubKeys,
|
|
122
148
|
vpCommissionScriptPubKey: r.vpCommissionScriptPubKey,
|
|
@@ -132,100 +158,100 @@ async function Fe(e, t, r) {
|
|
|
132
158
|
network: r.network,
|
|
133
159
|
claimerBtcPubkey: r.depositorBtcPubkey,
|
|
134
160
|
registeredPayoutScriptPubKey: r.registeredPayoutScriptPubKey,
|
|
135
|
-
commissionBps:
|
|
161
|
+
commissionBps: He,
|
|
136
162
|
protocolFeeRate: r.protocolFeeRate,
|
|
137
163
|
councilSize: r.councilMembers.length
|
|
138
164
|
});
|
|
139
|
-
n.push(
|
|
165
|
+
n.push(s.psbtHex), a.push(
|
|
140
166
|
M(
|
|
141
167
|
t,
|
|
142
168
|
G
|
|
143
169
|
)
|
|
144
170
|
);
|
|
145
|
-
const
|
|
171
|
+
const l = d(r.depositorBtcPubkey), i = $.fromHex(
|
|
146
172
|
d(e.assert_tx.tx_hex)
|
|
147
173
|
);
|
|
148
174
|
for (const p of e.challenger_presign_data) {
|
|
149
|
-
const c = d(p.challenger_pubkey), h = n.length, f = await
|
|
175
|
+
const c = d(p.challenger_pubkey), h = n.length, f = await Ue({
|
|
150
176
|
challenger: p,
|
|
151
177
|
challengerPubkey: c,
|
|
152
|
-
claimerPubkey:
|
|
178
|
+
claimerPubkey: l,
|
|
153
179
|
localChallengers: o,
|
|
154
180
|
assertTxParsed: i,
|
|
155
181
|
ctx: r
|
|
156
182
|
});
|
|
157
|
-
n.push(f),
|
|
183
|
+
n.push(f), a.push(
|
|
158
184
|
M(
|
|
159
185
|
t,
|
|
160
186
|
G
|
|
161
187
|
)
|
|
162
|
-
),
|
|
188
|
+
), u.push({
|
|
163
189
|
challengerPubkey: c,
|
|
164
190
|
noPayoutIdx: h
|
|
165
191
|
});
|
|
166
192
|
}
|
|
167
|
-
return { psbtHexes: n, signOptions:
|
|
193
|
+
return { psbtHexes: n, signOptions: a, challengerEntries: u };
|
|
168
194
|
}
|
|
169
|
-
async function
|
|
195
|
+
async function Ue(e) {
|
|
170
196
|
const {
|
|
171
197
|
challenger: t,
|
|
172
198
|
challengerPubkey: r,
|
|
173
199
|
claimerPubkey: n,
|
|
174
|
-
localChallengers:
|
|
175
|
-
assertTxParsed:
|
|
200
|
+
localChallengers: a,
|
|
201
|
+
assertTxParsed: u,
|
|
176
202
|
ctx: o
|
|
177
203
|
} = e;
|
|
178
|
-
|
|
204
|
+
$e(
|
|
179
205
|
t.nopayout_tx.tx_hex,
|
|
180
206
|
r,
|
|
181
207
|
o.network
|
|
182
208
|
);
|
|
183
|
-
const
|
|
209
|
+
const s = $.fromHex(
|
|
184
210
|
d(t.nopayout_tx.tx_hex)
|
|
185
|
-
),
|
|
211
|
+
), l = $.fromHex(
|
|
186
212
|
d(t.challenge_assert_x_tx.tx_hex)
|
|
187
213
|
), i = $.fromHex(
|
|
188
214
|
d(t.challenge_assert_y_tx.tx_hex)
|
|
189
215
|
);
|
|
190
|
-
if (
|
|
216
|
+
if (s.ins.length !== 3)
|
|
191
217
|
throw new Error(
|
|
192
|
-
`NoPayout (challenger ${r}) must have exactly 3 inputs, got ${
|
|
218
|
+
`NoPayout (challenger ${r}) must have exactly 3 inputs, got ${s.ins.length}`
|
|
193
219
|
);
|
|
194
|
-
|
|
195
|
-
|
|
220
|
+
V(
|
|
221
|
+
s,
|
|
196
222
|
0,
|
|
197
|
-
|
|
223
|
+
u,
|
|
198
224
|
"Assert",
|
|
199
225
|
r
|
|
200
|
-
),
|
|
201
|
-
|
|
226
|
+
), V(
|
|
227
|
+
s,
|
|
202
228
|
1,
|
|
203
|
-
|
|
229
|
+
l,
|
|
204
230
|
"ChallengeAssertX",
|
|
205
231
|
r
|
|
206
|
-
),
|
|
207
|
-
|
|
232
|
+
), V(
|
|
233
|
+
s,
|
|
208
234
|
2,
|
|
209
235
|
i,
|
|
210
236
|
"ChallengeAssertY",
|
|
211
237
|
r
|
|
212
238
|
);
|
|
213
239
|
const p = [
|
|
214
|
-
l.outs[0],
|
|
215
240
|
u.outs[0],
|
|
241
|
+
l.outs[0],
|
|
216
242
|
i.outs[0]
|
|
217
243
|
].map((c) => ({
|
|
218
|
-
script_pubkey:
|
|
244
|
+
script_pubkey: re(new Uint8Array(c.script)),
|
|
219
245
|
value: c.value
|
|
220
246
|
}));
|
|
221
|
-
return
|
|
247
|
+
return _e({
|
|
222
248
|
noPayoutTxHex: t.nopayout_tx.tx_hex,
|
|
223
249
|
challengerPubkey: r,
|
|
224
250
|
prevouts: p,
|
|
225
251
|
connectorParams: {
|
|
226
252
|
txGraphVersion: o.vaultCoreVersion,
|
|
227
253
|
claimer: n,
|
|
228
|
-
localChallengers:
|
|
254
|
+
localChallengers: a,
|
|
229
255
|
universalChallengers: o.universalChallengerBtcPubkeys,
|
|
230
256
|
timelockAssert: o.timelockAssert,
|
|
231
257
|
councilMembers: o.councilMembers,
|
|
@@ -233,103 +259,103 @@ async function Me(e) {
|
|
|
233
259
|
}
|
|
234
260
|
});
|
|
235
261
|
}
|
|
236
|
-
function
|
|
262
|
+
function Le(e, t, r) {
|
|
237
263
|
N(e[0]);
|
|
238
|
-
const
|
|
264
|
+
const a = D(
|
|
239
265
|
e[0].returnedPsbtHex,
|
|
240
266
|
r
|
|
241
267
|
);
|
|
242
268
|
F({
|
|
243
269
|
requestedPsbtHex: e[0].requestedPsbtHex,
|
|
244
|
-
signatureHex:
|
|
270
|
+
signatureHex: a,
|
|
245
271
|
signerXOnlyPubkeyHex: r,
|
|
246
272
|
inputIndex: 0
|
|
247
273
|
});
|
|
248
|
-
const
|
|
274
|
+
const u = {};
|
|
249
275
|
for (const o of t) {
|
|
250
276
|
N(e[o.noPayoutIdx]);
|
|
251
|
-
const
|
|
277
|
+
const s = D(
|
|
252
278
|
e[o.noPayoutIdx].returnedPsbtHex,
|
|
253
279
|
r
|
|
254
280
|
);
|
|
255
281
|
F({
|
|
256
282
|
requestedPsbtHex: e[o.noPayoutIdx].requestedPsbtHex,
|
|
257
|
-
signatureHex:
|
|
283
|
+
signatureHex: s,
|
|
258
284
|
signerXOnlyPubkeyHex: r,
|
|
259
285
|
inputIndex: 0
|
|
260
|
-
}),
|
|
261
|
-
nopayout_signature:
|
|
286
|
+
}), u[o.challengerPubkey] = {
|
|
287
|
+
nopayout_signature: s
|
|
262
288
|
};
|
|
263
289
|
}
|
|
264
290
|
return {
|
|
265
291
|
payout_signatures: {
|
|
266
|
-
payout_signature:
|
|
292
|
+
payout_signature: a
|
|
267
293
|
},
|
|
268
|
-
per_challenger:
|
|
294
|
+
per_challenger: u
|
|
269
295
|
};
|
|
270
296
|
}
|
|
271
|
-
async function
|
|
272
|
-
const { depositorGraph: t, btcWallet: r, signingContext: n } = e,
|
|
273
|
-
|
|
297
|
+
async function ze(e) {
|
|
298
|
+
const { depositorGraph: t, btcWallet: r, signingContext: n } = e, a = await r.getPublicKeyHex(), { depositorPubkey: u } = ye(
|
|
299
|
+
a,
|
|
274
300
|
d(n.depositorBtcPubkey)
|
|
275
|
-
), { psbtHexes: o, signOptions:
|
|
301
|
+
), { psbtHexes: o, signOptions: s, challengerEntries: l } = await Me(
|
|
276
302
|
t,
|
|
277
|
-
|
|
303
|
+
a,
|
|
278
304
|
n
|
|
279
|
-
), i = await
|
|
305
|
+
), i = await me(
|
|
280
306
|
r,
|
|
281
307
|
o,
|
|
282
|
-
|
|
308
|
+
s
|
|
283
309
|
), p = o.map((c, h) => ({
|
|
284
310
|
requestedPsbtHex: c,
|
|
285
311
|
returnedPsbtHex: i[h]
|
|
286
312
|
}));
|
|
287
|
-
return
|
|
313
|
+
return Le(
|
|
288
314
|
p,
|
|
289
|
-
|
|
290
|
-
|
|
315
|
+
l,
|
|
316
|
+
u
|
|
291
317
|
);
|
|
292
318
|
}
|
|
293
|
-
const
|
|
294
|
-
async function
|
|
319
|
+
const Xe = 1e4;
|
|
320
|
+
async function ae(e) {
|
|
295
321
|
const {
|
|
296
322
|
statusReader: t,
|
|
297
323
|
peginTxid: r,
|
|
298
324
|
targetStatuses: n,
|
|
299
|
-
timeoutMs:
|
|
300
|
-
pollIntervalMs:
|
|
325
|
+
timeoutMs: a,
|
|
326
|
+
pollIntervalMs: u = Xe,
|
|
301
327
|
signal: o
|
|
302
|
-
} = e,
|
|
328
|
+
} = e, s = Date.now();
|
|
303
329
|
for (; ; ) {
|
|
304
330
|
if (o != null && o.aborted)
|
|
305
331
|
throw new Error(
|
|
306
332
|
`Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...n].join(", ")})`
|
|
307
333
|
);
|
|
308
|
-
if (Date.now() -
|
|
334
|
+
if (Date.now() - s >= a)
|
|
309
335
|
throw new Error(
|
|
310
|
-
`Polling timeout after ${
|
|
336
|
+
`Polling timeout after ${a}ms for pegin ${r.slice(0, 8)}… (target: ${[...n].join(", ")})`
|
|
311
337
|
);
|
|
312
338
|
try {
|
|
313
|
-
const
|
|
339
|
+
const l = await t.getPeginStatus(
|
|
314
340
|
{ pegin_txid: r },
|
|
315
341
|
o
|
|
316
342
|
);
|
|
317
|
-
if (
|
|
343
|
+
if (l.pegin_txid.toLowerCase() !== r.toLowerCase())
|
|
318
344
|
throw new Error(
|
|
319
|
-
`getPeginStatus returned status for pegin ${
|
|
345
|
+
`getPeginStatus returned status for pegin ${l.pegin_txid.slice(0, 8)}…, requested ${r.slice(0, 8)}…`
|
|
320
346
|
);
|
|
321
|
-
const i =
|
|
347
|
+
const i = l.status;
|
|
322
348
|
if (n.has(i) || i === E.ACTIVATED)
|
|
323
349
|
return i;
|
|
324
|
-
if (i === E.EXPIRED ||
|
|
350
|
+
if (i === E.EXPIRED || xe.has(i))
|
|
325
351
|
throw new Error(
|
|
326
352
|
`Pegin ${r.slice(0, 8)}… reached terminal status "${i}" while waiting for ${[...n].join(", ")}`
|
|
327
353
|
);
|
|
328
|
-
} catch (
|
|
329
|
-
if (!(
|
|
330
|
-
throw
|
|
354
|
+
} catch (l) {
|
|
355
|
+
if (!(l instanceof Ee && l.code === Ce.PEGIN_NOT_FOUND))
|
|
356
|
+
throw l;
|
|
331
357
|
}
|
|
332
|
-
await new Promise((
|
|
358
|
+
await new Promise((l, i) => {
|
|
333
359
|
const p = () => {
|
|
334
360
|
clearTimeout(c), i(
|
|
335
361
|
new Error(
|
|
@@ -337,22 +363,22 @@ async function ne(e) {
|
|
|
337
363
|
)
|
|
338
364
|
);
|
|
339
365
|
}, c = setTimeout(() => {
|
|
340
|
-
o == null || o.removeEventListener("abort", p),
|
|
341
|
-
},
|
|
366
|
+
o == null || o.removeEventListener("abort", p), l();
|
|
367
|
+
}, u);
|
|
342
368
|
o == null || o.addEventListener("abort", p, { once: !0 });
|
|
343
369
|
});
|
|
344
370
|
}
|
|
345
371
|
}
|
|
346
|
-
const
|
|
372
|
+
const Ge = 1200 * 1e3, se = /* @__PURE__ */ new Set([
|
|
347
373
|
E.PENDING_ACKS,
|
|
348
374
|
E.PENDING_ACTIVATION,
|
|
349
375
|
E.ACTIVATED_PENDING_BROADCAST,
|
|
350
376
|
E.ACTIVATED
|
|
351
|
-
]),
|
|
377
|
+
]), je = /* @__PURE__ */ new Set([
|
|
352
378
|
E.PENDING_DEPOSITOR_SIGNATURES,
|
|
353
|
-
...
|
|
379
|
+
...se
|
|
354
380
|
]);
|
|
355
|
-
function
|
|
381
|
+
function qe(e) {
|
|
356
382
|
return e.map((t) => ({
|
|
357
383
|
claimerPubkeyXOnly: L(t.claimer_pubkey),
|
|
358
384
|
payoutTxHex: t.payout_tx.tx_hex,
|
|
@@ -362,22 +388,22 @@ function je(e) {
|
|
|
362
388
|
function w(e) {
|
|
363
389
|
return L(e).toLowerCase();
|
|
364
390
|
}
|
|
365
|
-
function
|
|
366
|
-
const r = (
|
|
391
|
+
function Qe(e, t) {
|
|
392
|
+
const r = (s, l, i) => {
|
|
367
393
|
throw new Error(
|
|
368
|
-
`Deposit terms ${
|
|
394
|
+
`Deposit terms ${s} (${String(l)}) does not match the vault's version-locked signing context (${String(i)}); refusing to sign payouts against terms that describe a different graph.`
|
|
369
395
|
);
|
|
370
396
|
};
|
|
371
397
|
e.protocolFeeRate !== t.protocolFeeRate && r("protocolFeeRate", e.protocolFeeRate, t.protocolFeeRate);
|
|
372
|
-
const n = (
|
|
373
|
-
const i = n(
|
|
398
|
+
const n = (s) => s.map(w).sort(), a = (s, l) => {
|
|
399
|
+
const i = n(s), p = n(l);
|
|
374
400
|
return i.length === p.length && i.every((c, h) => c === p[h]);
|
|
375
401
|
};
|
|
376
|
-
|
|
402
|
+
a(e.vaultKeeperBtcPubkeys, t.vaultKeeperBtcPubkeys) || r(
|
|
377
403
|
"vaultKeeperBtcPubkeys",
|
|
378
404
|
e.vaultKeeperBtcPubkeys.join(","),
|
|
379
405
|
t.vaultKeeperBtcPubkeys.join(",")
|
|
380
|
-
),
|
|
406
|
+
), a(
|
|
381
407
|
e.universalChallengerBtcPubkeys,
|
|
382
408
|
t.universalChallengerBtcPubkeys
|
|
383
409
|
) || r(
|
|
@@ -385,34 +411,34 @@ function qe(e, t) {
|
|
|
385
411
|
e.universalChallengerBtcPubkeys.join(","),
|
|
386
412
|
t.universalChallengerBtcPubkeys.join(",")
|
|
387
413
|
);
|
|
388
|
-
const
|
|
389
|
-
(
|
|
414
|
+
const u = w(t.vaultProviderBtcPubkey), o = e.vaults.map(
|
|
415
|
+
(s) => w(s.vaultProviderBtcPubkey)
|
|
390
416
|
);
|
|
391
|
-
o.includes(
|
|
417
|
+
o.includes(u) || r(
|
|
392
418
|
"vaults[].vaultProviderBtcPubkey",
|
|
393
419
|
o.join(",") || "<no vaults>",
|
|
394
420
|
t.vaultProviderBtcPubkey
|
|
395
421
|
);
|
|
396
422
|
}
|
|
397
|
-
function
|
|
398
|
-
const
|
|
423
|
+
function We(e, t, r, n) {
|
|
424
|
+
const a = w(n), u = [
|
|
399
425
|
w(t),
|
|
400
426
|
...r.map(w)
|
|
401
|
-
], o = new Set(
|
|
402
|
-
if (o.size !==
|
|
427
|
+
], o = new Set(u);
|
|
428
|
+
if (o.size !== u.length)
|
|
403
429
|
throw new Error(
|
|
404
430
|
"Cannot validate claimer set: signing context contains duplicate vault provider or vault keeper key"
|
|
405
431
|
);
|
|
406
|
-
if (o.has(
|
|
432
|
+
if (o.has(a))
|
|
407
433
|
throw new Error(
|
|
408
434
|
"Cannot validate claimer set: depositor key overlaps with vault provider or vault keeper set"
|
|
409
435
|
);
|
|
410
|
-
const
|
|
436
|
+
const s = e.map(
|
|
411
437
|
(h) => w(h.claimer_pubkey)
|
|
412
438
|
);
|
|
413
|
-
if (new Set(
|
|
439
|
+
if (new Set(s).size !== s.length)
|
|
414
440
|
throw new Error("Presign response contains duplicate claimer entries");
|
|
415
|
-
const
|
|
441
|
+
const l = s.filter((h) => h !== a), i = new Set(l), p = u.filter((h) => !i.has(h)), c = l.filter((h) => !o.has(h));
|
|
416
442
|
if (p.length > 0 || c.length > 0)
|
|
417
443
|
throw new Error(
|
|
418
444
|
"Presign response claimer set does not match expected (vault provider ∪ vault keepers)" + (p.length > 0 ? ` (missing: ${p.join(", ")})` : "") + (c.length > 0 ? ` (unexpected: ${c.join(", ")})` : "")
|
|
@@ -440,92 +466,92 @@ function j(e, t) {
|
|
|
440
466
|
};
|
|
441
467
|
}
|
|
442
468
|
async function Ye(e, t, r, n) {
|
|
443
|
-
const
|
|
469
|
+
const a = new we({
|
|
444
470
|
network: t.network,
|
|
445
471
|
btcWallet: e
|
|
446
|
-
}),
|
|
447
|
-
n == null || n(0,
|
|
472
|
+
}), u = r.length;
|
|
473
|
+
n == null || n(0, u);
|
|
448
474
|
let o;
|
|
449
|
-
if (
|
|
450
|
-
o = (await
|
|
475
|
+
if (a.supportsBatchSigning())
|
|
476
|
+
o = (await a.signPayoutTransactionsBatch(
|
|
451
477
|
r.map((i) => j(i, t))
|
|
452
478
|
)).map((i) => i.payoutSignature);
|
|
453
479
|
else {
|
|
454
480
|
o = [];
|
|
455
|
-
for (let
|
|
456
|
-
n == null || n(
|
|
457
|
-
const i = await
|
|
458
|
-
j(r[
|
|
481
|
+
for (let l = 0; l < r.length; l++) {
|
|
482
|
+
n == null || n(l, u);
|
|
483
|
+
const i = await a.signPayoutTransaction(
|
|
484
|
+
j(r[l], t)
|
|
459
485
|
);
|
|
460
486
|
o.push(i.signature);
|
|
461
487
|
}
|
|
462
488
|
}
|
|
463
|
-
const
|
|
464
|
-
for (let
|
|
465
|
-
|
|
466
|
-
payout_signature: o[
|
|
489
|
+
const s = {};
|
|
490
|
+
for (let l = 0; l < r.length; l++)
|
|
491
|
+
s[r[l].claimerPubkeyXOnly] = {
|
|
492
|
+
payout_signature: o[l]
|
|
467
493
|
};
|
|
468
|
-
return n == null || n(
|
|
494
|
+
return n == null || n(u, u), s;
|
|
469
495
|
}
|
|
470
|
-
async function
|
|
496
|
+
async function Rt(e) {
|
|
471
497
|
const {
|
|
472
498
|
statusReader: t,
|
|
473
499
|
presignClient: r,
|
|
474
500
|
btcWallet: n,
|
|
475
|
-
peginTxid:
|
|
476
|
-
depositorPk:
|
|
501
|
+
peginTxid: a,
|
|
502
|
+
depositorPk: u,
|
|
477
503
|
signingContext: o,
|
|
478
|
-
depositTerms:
|
|
479
|
-
timeoutMs:
|
|
504
|
+
depositTerms: s,
|
|
505
|
+
timeoutMs: l = Ge,
|
|
480
506
|
signal: i,
|
|
481
507
|
onProgress: p
|
|
482
|
-
} = e, c = await
|
|
508
|
+
} = e, c = await ae({
|
|
483
509
|
statusReader: t,
|
|
484
|
-
peginTxid:
|
|
485
|
-
targetStatuses:
|
|
486
|
-
timeoutMs:
|
|
510
|
+
peginTxid: a,
|
|
511
|
+
targetStatuses: je,
|
|
512
|
+
timeoutMs: l,
|
|
487
513
|
signal: i
|
|
488
514
|
});
|
|
489
|
-
if (
|
|
515
|
+
if (se.has(c))
|
|
490
516
|
return;
|
|
491
|
-
if (i == null || i.throwIfAborted(),
|
|
492
|
-
if (!
|
|
517
|
+
if (i == null || i.throwIfAborted(), s !== void 0 && Qe(s, o), be(n)) {
|
|
518
|
+
if (!s)
|
|
493
519
|
throw new Error(
|
|
494
520
|
"runDepositorPresignFlow: this wallet requires approved deposit terms but none were provided. Fresh deposits must pass PreparePeginResult.depositTerms; resume-path rebuild is not wired yet."
|
|
495
521
|
);
|
|
496
|
-
await n.approveDepositTerms(
|
|
522
|
+
await n.approveDepositTerms(s);
|
|
497
523
|
}
|
|
498
524
|
const h = await r.requestDepositorPresignTransactions(
|
|
499
525
|
{
|
|
500
|
-
pegin_txid:
|
|
501
|
-
depositor_pk:
|
|
526
|
+
pegin_txid: a,
|
|
527
|
+
depositor_pk: u
|
|
502
528
|
},
|
|
503
529
|
i
|
|
504
530
|
);
|
|
505
531
|
i == null || i.throwIfAborted();
|
|
506
|
-
const f = w(
|
|
507
|
-
|
|
532
|
+
const f = w(u);
|
|
533
|
+
We(
|
|
508
534
|
h.txs,
|
|
509
535
|
o.vaultProviderBtcPubkey,
|
|
510
536
|
o.vaultKeeperBtcPubkeys,
|
|
511
|
-
|
|
537
|
+
u
|
|
512
538
|
);
|
|
513
|
-
const
|
|
514
|
-
(
|
|
515
|
-
), T =
|
|
539
|
+
const v = h.txs.filter(
|
|
540
|
+
(y) => w(y.claimer_pubkey) !== f
|
|
541
|
+
), T = qe(v), x = await Ye(
|
|
516
542
|
n,
|
|
517
543
|
o,
|
|
518
544
|
T,
|
|
519
545
|
p
|
|
520
546
|
);
|
|
521
547
|
i == null || i.throwIfAborted();
|
|
522
|
-
const m = await
|
|
548
|
+
const m = await ze({
|
|
523
549
|
depositorGraph: h.depositor_graph,
|
|
524
550
|
btcWallet: n,
|
|
525
551
|
signingContext: {
|
|
526
552
|
vaultCoreVersion: o.vaultCoreVersion,
|
|
527
553
|
peginTxHex: o.peginTxHex,
|
|
528
|
-
depositorBtcPubkey:
|
|
554
|
+
depositorBtcPubkey: u,
|
|
529
555
|
vaultProviderBtcPubkey: o.vaultProviderBtcPubkey,
|
|
530
556
|
vaultKeeperBtcPubkeys: o.vaultKeeperBtcPubkeys,
|
|
531
557
|
universalChallengerBtcPubkeys: o.universalChallengerBtcPubkeys,
|
|
@@ -542,51 +568,51 @@ async function Bt(e) {
|
|
|
542
568
|
});
|
|
543
569
|
i == null || i.throwIfAborted();
|
|
544
570
|
const b = { ...x };
|
|
545
|
-
b[d(
|
|
571
|
+
b[d(u)] = m.payout_signatures, await r.submitDepositorPresignatures(
|
|
546
572
|
{
|
|
547
|
-
pegin_txid:
|
|
548
|
-
depositor_pk:
|
|
573
|
+
pegin_txid: a,
|
|
574
|
+
depositor_pk: u,
|
|
549
575
|
signatures: b,
|
|
550
576
|
depositor_claimer_presignatures: m
|
|
551
577
|
},
|
|
552
578
|
i
|
|
553
579
|
);
|
|
554
580
|
}
|
|
555
|
-
const
|
|
581
|
+
const Je = 300 * 1e3, Ze = /* @__PURE__ */ new Set([
|
|
556
582
|
E.PENDING_DEPOSITOR_WOTS_PK,
|
|
557
|
-
...
|
|
583
|
+
...ne
|
|
558
584
|
]);
|
|
559
|
-
async function
|
|
585
|
+
async function Vt(e) {
|
|
560
586
|
const {
|
|
561
587
|
statusReader: t,
|
|
562
588
|
wotsSubmitter: r,
|
|
563
589
|
peginTxid: n,
|
|
564
|
-
depositorPk:
|
|
565
|
-
wotsPublicKeys:
|
|
566
|
-
timeoutMs: o =
|
|
567
|
-
signal:
|
|
590
|
+
depositorPk: a,
|
|
591
|
+
wotsPublicKeys: u,
|
|
592
|
+
timeoutMs: o = Je,
|
|
593
|
+
signal: s
|
|
568
594
|
} = e;
|
|
569
|
-
|
|
570
|
-
const
|
|
595
|
+
s == null || s.throwIfAborted();
|
|
596
|
+
const l = await ae({
|
|
571
597
|
statusReader: t,
|
|
572
598
|
peginTxid: n,
|
|
573
|
-
targetStatuses:
|
|
599
|
+
targetStatuses: Ze,
|
|
574
600
|
timeoutMs: o,
|
|
575
|
-
signal:
|
|
601
|
+
signal: s
|
|
576
602
|
});
|
|
577
|
-
|
|
603
|
+
ne.has(l) || (s == null || s.throwIfAborted(), await r.submitDepositorWotsKey(
|
|
578
604
|
{
|
|
579
605
|
pegin_txid: n,
|
|
580
|
-
depositor_pk:
|
|
581
|
-
wots_public_keys:
|
|
606
|
+
depositor_pk: a,
|
|
607
|
+
wots_public_keys: u
|
|
582
608
|
},
|
|
583
|
-
|
|
609
|
+
s
|
|
584
610
|
));
|
|
585
611
|
}
|
|
586
|
-
function
|
|
612
|
+
function K(e) {
|
|
587
613
|
return e.registration || e.operation;
|
|
588
614
|
}
|
|
589
|
-
function
|
|
615
|
+
function et(e, t, r) {
|
|
590
616
|
const n = k(e);
|
|
591
617
|
return {
|
|
592
618
|
registration: n === k(t),
|
|
@@ -606,38 +632,38 @@ function I(e) {
|
|
|
606
632
|
function Q(e, t) {
|
|
607
633
|
return e.length === t.length && e.every((r, n) => r === t[n]);
|
|
608
634
|
}
|
|
609
|
-
async function
|
|
635
|
+
async function Kt(e) {
|
|
610
636
|
const {
|
|
611
637
|
vaultProviderEthAddress: t,
|
|
612
638
|
hintBtcPubkey: r,
|
|
613
639
|
registrationBtcPubkey: n,
|
|
614
|
-
readCurrentOperationBtcPubkey:
|
|
615
|
-
context:
|
|
640
|
+
readCurrentOperationBtcPubkey: a,
|
|
641
|
+
context: u
|
|
616
642
|
} = e;
|
|
617
643
|
if (!r) return;
|
|
618
644
|
const o = k(r);
|
|
619
645
|
if (o === k(n)) return;
|
|
620
|
-
const
|
|
621
|
-
await
|
|
646
|
+
const s = k(
|
|
647
|
+
await a()
|
|
622
648
|
);
|
|
623
|
-
if (o !==
|
|
649
|
+
if (o !== s)
|
|
624
650
|
throw new Error(
|
|
625
|
-
`Vault provider BTC pubkey mismatch for ${t}: indexer hint matches neither the registration key nor the current operation key on-chain.${
|
|
651
|
+
`Vault provider BTC pubkey mismatch for ${t}: indexer hint matches neither the registration key nor the current operation key on-chain.${u ? ` ${u}` : ""}`
|
|
626
652
|
);
|
|
627
653
|
}
|
|
628
654
|
function O(e, t, r) {
|
|
629
|
-
const n = `${e} operation key (admin=${t.ethAddress})`,
|
|
655
|
+
const n = `${e} operation key (admin=${t.ethAddress})`, a = X(
|
|
630
656
|
t.btcPubKey,
|
|
631
657
|
`${e} roster key (admin=${t.ethAddress})`
|
|
632
|
-
),
|
|
658
|
+
), u = X(r, n);
|
|
633
659
|
return {
|
|
634
660
|
adminAddress: t.ethAddress,
|
|
635
|
-
genesisBtcPubkey:
|
|
636
|
-
operationBtcPubkey:
|
|
637
|
-
rotated:
|
|
661
|
+
genesisBtcPubkey: a,
|
|
662
|
+
operationBtcPubkey: u,
|
|
663
|
+
rotated: u !== a
|
|
638
664
|
};
|
|
639
665
|
}
|
|
640
|
-
function
|
|
666
|
+
function tt(e) {
|
|
641
667
|
const t = /* @__PURE__ */ new Map();
|
|
642
668
|
for (const r of e) {
|
|
643
669
|
const n = t.get(r.operationBtcPubkey);
|
|
@@ -648,7 +674,7 @@ function et(e) {
|
|
|
648
674
|
t.set(r.operationBtcPubkey, r.adminAddress);
|
|
649
675
|
}
|
|
650
676
|
}
|
|
651
|
-
function
|
|
677
|
+
function ie(e, t, r) {
|
|
652
678
|
if (t.vaultKeepers.length !== e.vaultKeepers.length || t.universalChallengers.length !== e.universalChallengers.length)
|
|
653
679
|
throw new Error(
|
|
654
680
|
`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`
|
|
@@ -660,148 +686,150 @@ function ae(e, t, r) {
|
|
|
660
686
|
btcPubKey: e.vaultProviderGenesisBtcPubkey
|
|
661
687
|
},
|
|
662
688
|
t.vaultProvider
|
|
663
|
-
),
|
|
664
|
-
(o,
|
|
665
|
-
),
|
|
666
|
-
(o,
|
|
689
|
+
), a = e.vaultKeepers.map(
|
|
690
|
+
(o, s) => O("vault keeper", o, t.vaultKeepers[s])
|
|
691
|
+
), u = e.universalChallengers.map(
|
|
692
|
+
(o, s) => O("universal challenger", o, t.universalChallengers[s])
|
|
667
693
|
);
|
|
668
|
-
return
|
|
694
|
+
return tt([
|
|
669
695
|
n,
|
|
670
|
-
...
|
|
671
|
-
...
|
|
696
|
+
...a,
|
|
697
|
+
...u
|
|
672
698
|
]), {
|
|
673
699
|
vaultProvider: n,
|
|
674
|
-
vaultKeepers:
|
|
675
|
-
universalChallengers:
|
|
700
|
+
vaultKeepers: a,
|
|
701
|
+
universalChallengers: u,
|
|
676
702
|
// Derived from the pairs, never the reverse — see ParticipantKeySet.
|
|
677
|
-
vaultKeeperOperationKeysSorted:
|
|
678
|
-
universalChallengerOperationKeysSorted:
|
|
703
|
+
vaultKeeperOperationKeysSorted: a.map((o) => o.operationBtcPubkey).sort(),
|
|
704
|
+
universalChallengerOperationKeysSorted: u.map((o) => o.operationBtcPubkey).sort(),
|
|
679
705
|
resolvedAt: r,
|
|
680
706
|
query: e
|
|
681
707
|
};
|
|
682
708
|
}
|
|
683
|
-
async function
|
|
709
|
+
async function rt(e) {
|
|
684
710
|
const t = await e.operationKeyReader.getCurrentOperationKeys(
|
|
685
711
|
e.query
|
|
686
712
|
);
|
|
687
|
-
return
|
|
713
|
+
return ie(e.query, t, { mode: "current" });
|
|
688
714
|
}
|
|
689
|
-
async function
|
|
715
|
+
async function nt(e) {
|
|
690
716
|
const t = await e.operationKeyReader.getOperationKeysAtEpochs(
|
|
691
717
|
e.query,
|
|
692
718
|
e.epochs
|
|
693
719
|
);
|
|
694
|
-
return
|
|
720
|
+
return ie(e.query, t, {
|
|
695
721
|
mode: "epochs",
|
|
696
722
|
epochs: e.epochs
|
|
697
723
|
});
|
|
698
724
|
}
|
|
699
|
-
const
|
|
700
|
-
async function
|
|
725
|
+
const W = (e) => e.map(k).sort();
|
|
726
|
+
async function It(e) {
|
|
701
727
|
const {
|
|
702
728
|
vaultRegistryReader: t,
|
|
703
729
|
vaultKeeperReader: r,
|
|
704
730
|
universalChallengerReader: n,
|
|
705
|
-
vaultProviderEthAddress:
|
|
706
|
-
applicationEntryPoint:
|
|
731
|
+
vaultProviderEthAddress: a,
|
|
732
|
+
applicationEntryPoint: u,
|
|
707
733
|
expectedVaultProviderBtcPubkey: o,
|
|
708
|
-
expectedVaultKeeperBtcPubkeys:
|
|
709
|
-
expectedUniversalChallengerBtcPubkeys:
|
|
734
|
+
expectedVaultKeeperBtcPubkeys: s,
|
|
735
|
+
expectedUniversalChallengerBtcPubkeys: l,
|
|
710
736
|
operationKeyReader: i,
|
|
711
737
|
onIndexerServingOperationKeys: p,
|
|
712
738
|
onIndexerHintsInconsistent: c
|
|
713
739
|
} = e, [
|
|
714
740
|
h,
|
|
715
741
|
f,
|
|
716
|
-
|
|
742
|
+
v
|
|
717
743
|
] = await Promise.all([
|
|
718
|
-
t.
|
|
719
|
-
|
|
744
|
+
t.getVaultProviderGenesisBtcPubKey(
|
|
745
|
+
a
|
|
746
|
+
),
|
|
747
|
+
r.getCurrentVaultKeepersVersion(u),
|
|
720
748
|
n.getLatestUniversalChallengersVersion()
|
|
721
749
|
]), [T, x] = await Promise.all([
|
|
722
750
|
r.getVaultKeepersByVersion(
|
|
723
|
-
|
|
751
|
+
u,
|
|
724
752
|
f
|
|
725
753
|
),
|
|
726
754
|
n.getUniversalChallengersByVersion(
|
|
727
|
-
|
|
755
|
+
v
|
|
728
756
|
)
|
|
729
757
|
]), m = {
|
|
730
758
|
vaultProvider: k(h),
|
|
731
|
-
vaultKeepers:
|
|
732
|
-
universalChallengers:
|
|
733
|
-
}, b = await
|
|
759
|
+
vaultKeepers: W(T.map((P) => P.btcPubKey)),
|
|
760
|
+
universalChallengers: W(x.map((P) => P.btcPubKey))
|
|
761
|
+
}, b = await rt({
|
|
734
762
|
operationKeyReader: i,
|
|
735
763
|
query: {
|
|
736
|
-
vaultProviderEthAddress:
|
|
764
|
+
vaultProviderEthAddress: a,
|
|
737
765
|
vaultProviderGenesisBtcPubkey: `0x${h}`,
|
|
738
|
-
applicationEntryPoint:
|
|
766
|
+
applicationEntryPoint: u,
|
|
739
767
|
vaultKeepers: T,
|
|
740
768
|
universalChallengers: x
|
|
741
769
|
}
|
|
742
|
-
}),
|
|
770
|
+
}), y = {
|
|
743
771
|
vaultProvider: b.vaultProvider.operationBtcPubkey,
|
|
744
772
|
vaultKeepers: [...b.vaultKeeperOperationKeysSorted],
|
|
745
773
|
universalChallengers: [
|
|
746
774
|
...b.universalChallengerOperationKeysSorted
|
|
747
775
|
]
|
|
748
|
-
}, S =
|
|
776
|
+
}, S = et(
|
|
749
777
|
o,
|
|
750
778
|
m.vaultProvider,
|
|
751
|
-
|
|
779
|
+
y.vaultProvider
|
|
752
780
|
), _ = q(
|
|
753
|
-
|
|
781
|
+
s,
|
|
754
782
|
m.vaultKeepers,
|
|
755
|
-
|
|
783
|
+
y.vaultKeepers
|
|
756
784
|
), B = q(
|
|
757
|
-
|
|
785
|
+
l,
|
|
758
786
|
m.universalChallengers,
|
|
759
|
-
|
|
787
|
+
y.universalChallengers
|
|
760
788
|
);
|
|
761
|
-
if (!
|
|
789
|
+
if (!K(S))
|
|
762
790
|
throw new Error(
|
|
763
|
-
`Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${
|
|
791
|
+
`Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${a}. Refresh and try again.`
|
|
764
792
|
);
|
|
765
|
-
if (!
|
|
793
|
+
if (!K(_))
|
|
766
794
|
throw new Error(
|
|
767
795
|
`Vault keeper BTC pubkeys (v${f}) indexer set does not match ApplicationRegistry on-chain set. Refresh and try again.`
|
|
768
796
|
);
|
|
769
|
-
if (!
|
|
797
|
+
if (!K(B))
|
|
770
798
|
throw new Error(
|
|
771
|
-
`Universal challenger BTC pubkeys (v${
|
|
799
|
+
`Universal challenger BTC pubkeys (v${v}) indexer set does not match ProtocolParams on-chain set. Refresh and try again.`
|
|
772
800
|
);
|
|
773
|
-
const g = [S, _, B],
|
|
774
|
-
if (
|
|
775
|
-
const P = `Indexer participant hints are internally inconsistent for vault provider ${
|
|
801
|
+
const g = [S, _, B], de = g.some((P) => P.registration && !P.operation), z = g.some((P) => P.operation && !P.registration);
|
|
802
|
+
if (de && z) {
|
|
803
|
+
const P = `Indexer participant hints are internally inconsistent for vault provider ${a}: some roles match the registration keys while others match the rotated operation keys.`;
|
|
776
804
|
throw c == null || c(P), new Error(`${P} Refresh and try again.`);
|
|
777
805
|
}
|
|
778
806
|
return z && (p == null || p(
|
|
779
|
-
`Indexer is serving rotated operation keys for vault provider ${
|
|
807
|
+
`Indexer is serving rotated operation keys for vault provider ${a}`
|
|
780
808
|
)), {
|
|
781
|
-
vaultProviderBtcPubkeyXOnly:
|
|
782
|
-
vaultKeeperBtcPubkeysSorted:
|
|
783
|
-
universalChallengerBtcPubkeysSorted:
|
|
809
|
+
vaultProviderBtcPubkeyXOnly: y.vaultProvider,
|
|
810
|
+
vaultKeeperBtcPubkeysSorted: y.vaultKeepers,
|
|
811
|
+
universalChallengerBtcPubkeysSorted: y.universalChallengers,
|
|
784
812
|
expectedAppVaultKeepersVersion: f,
|
|
785
|
-
expectedUniversalChallengersVersion:
|
|
813
|
+
expectedUniversalChallengersVersion: v,
|
|
786
814
|
registrationKeys: m,
|
|
787
815
|
participantKeys: b
|
|
788
816
|
};
|
|
789
817
|
}
|
|
790
|
-
function
|
|
818
|
+
function ot(e) {
|
|
791
819
|
return /^[0-9a-fA-F]{64}$/.test(e);
|
|
792
820
|
}
|
|
793
|
-
function
|
|
821
|
+
function Ot(e) {
|
|
794
822
|
const {
|
|
795
823
|
amountSats: t,
|
|
796
824
|
minDeposit: r,
|
|
797
825
|
maxDeposit: n,
|
|
798
|
-
btcBalance:
|
|
799
|
-
estimatedFeeSats:
|
|
826
|
+
btcBalance: a,
|
|
827
|
+
estimatedFeeSats: u,
|
|
800
828
|
depositorClaimValue: o
|
|
801
829
|
} = e;
|
|
802
|
-
return !(t <= 0n || t < r || n && n > 0n && t > n ||
|
|
830
|
+
return !(t <= 0n || t < r || n && n > 0n && t > n || u == null || o == null || t + u + o > a);
|
|
803
831
|
}
|
|
804
|
-
function
|
|
832
|
+
function Ht(e, t, r) {
|
|
805
833
|
return e <= 0n ? {
|
|
806
834
|
valid: !1,
|
|
807
835
|
error: "Deposit amount must be greater than zero"
|
|
@@ -813,7 +841,7 @@ function It(e, t, r) {
|
|
|
813
841
|
error: `Maximum deposit is ${C(r)} BTC`
|
|
814
842
|
} : { valid: !0 };
|
|
815
843
|
}
|
|
816
|
-
function
|
|
844
|
+
function Nt(e) {
|
|
817
845
|
const { amount: t, effectiveRemaining: r } = e;
|
|
818
846
|
return r === null ? { valid: !0 } : r === 0n ? {
|
|
819
847
|
valid: !1,
|
|
@@ -823,191 +851,191 @@ function Ot(e) {
|
|
|
823
851
|
error: `Vault size exceeds remaining capacity (${C(r)} BTC)`
|
|
824
852
|
} : { valid: !0 };
|
|
825
853
|
}
|
|
826
|
-
function
|
|
854
|
+
function Dt(e, t) {
|
|
827
855
|
if (!e || e.length === 0)
|
|
828
856
|
return {
|
|
829
857
|
valid: !1,
|
|
830
858
|
error: "At least one vault provider must be selected"
|
|
831
859
|
};
|
|
832
860
|
const r = t.map(
|
|
833
|
-
(
|
|
861
|
+
(a) => a.toLowerCase()
|
|
834
862
|
);
|
|
835
863
|
return e.filter(
|
|
836
|
-
(
|
|
864
|
+
(a) => !r.includes(a.toLowerCase())
|
|
837
865
|
).length > 0 ? {
|
|
838
866
|
valid: !1,
|
|
839
867
|
error: "Invalid vault provider selected"
|
|
840
868
|
} : { valid: !0 };
|
|
841
869
|
}
|
|
842
|
-
function
|
|
870
|
+
function at(e, t, r) {
|
|
843
871
|
if (!e || e.length === 0)
|
|
844
872
|
return {
|
|
845
873
|
valid: !1,
|
|
846
874
|
error: "At least one vault amount required"
|
|
847
875
|
};
|
|
848
876
|
for (let n = 0; n < e.length; n++) {
|
|
849
|
-
const
|
|
850
|
-
if (
|
|
877
|
+
const a = e[n];
|
|
878
|
+
if (a <= 0n)
|
|
851
879
|
return {
|
|
852
880
|
valid: !1,
|
|
853
881
|
error: `Vault ${n + 1} amount must be positive`
|
|
854
882
|
};
|
|
855
|
-
if (t &&
|
|
883
|
+
if (t && a < t)
|
|
856
884
|
return {
|
|
857
885
|
valid: !1,
|
|
858
|
-
error: `Vault ${n + 1} amount ${C(
|
|
886
|
+
error: `Vault ${n + 1} amount ${C(a)} BTC is below minimum deposit ${C(t)} BTC`
|
|
859
887
|
};
|
|
860
|
-
if (r &&
|
|
888
|
+
if (r && a > r)
|
|
861
889
|
return {
|
|
862
890
|
valid: !1,
|
|
863
|
-
error: `Vault ${n + 1} amount ${C(
|
|
891
|
+
error: `Vault ${n + 1} amount ${C(a)} BTC exceeds maximum deposit ${C(r)} BTC`
|
|
864
892
|
};
|
|
865
893
|
}
|
|
866
894
|
return { valid: !0 };
|
|
867
895
|
}
|
|
868
|
-
function
|
|
896
|
+
function st(e) {
|
|
869
897
|
const t = d(e);
|
|
870
|
-
return
|
|
898
|
+
return ot(t) ? { valid: !0 } : {
|
|
871
899
|
valid: !1,
|
|
872
900
|
error: "Invalid pubkey format: must be 64 hex characters (32-byte x-only public key, no 0x prefix)"
|
|
873
901
|
};
|
|
874
902
|
}
|
|
875
|
-
function
|
|
903
|
+
function it(e) {
|
|
876
904
|
if (!e || e.length === 0)
|
|
877
905
|
throw new Error(
|
|
878
906
|
"No vault keepers available. The system requires at least one vault keeper to create a deposit."
|
|
879
907
|
);
|
|
880
908
|
}
|
|
881
|
-
function
|
|
909
|
+
function ut(e) {
|
|
882
910
|
if (!e || e.length === 0)
|
|
883
911
|
throw new Error(
|
|
884
912
|
"No universal challengers available. The system requires at least one universal challenger to create a deposit."
|
|
885
913
|
);
|
|
886
914
|
}
|
|
887
|
-
function
|
|
915
|
+
function lt(e) {
|
|
888
916
|
if (e.length === 0)
|
|
889
917
|
throw new Error("No spendable UTXOs available");
|
|
890
918
|
}
|
|
891
|
-
function
|
|
919
|
+
function Ft(e) {
|
|
892
920
|
const {
|
|
893
921
|
vaultAmounts: t,
|
|
894
922
|
confirmedUTXOs: r,
|
|
895
923
|
vaultProviderBtcPubkey: n,
|
|
896
|
-
vaultKeeperBtcPubkeys:
|
|
897
|
-
universalChallengerBtcPubkeys:
|
|
924
|
+
vaultKeeperBtcPubkeys: a,
|
|
925
|
+
universalChallengerBtcPubkeys: u,
|
|
898
926
|
minDeposit: o,
|
|
899
|
-
maxDeposit:
|
|
900
|
-
} = e,
|
|
927
|
+
maxDeposit: s
|
|
928
|
+
} = e, l = at(
|
|
901
929
|
t,
|
|
902
930
|
o,
|
|
903
|
-
|
|
931
|
+
s
|
|
904
932
|
);
|
|
905
|
-
if (!
|
|
906
|
-
throw new Error(
|
|
907
|
-
const i =
|
|
933
|
+
if (!l.valid)
|
|
934
|
+
throw new Error(l.error);
|
|
935
|
+
const i = st(n);
|
|
908
936
|
if (!i.valid)
|
|
909
937
|
throw new Error(i.error);
|
|
910
|
-
|
|
938
|
+
it(a), ut(u), lt(r);
|
|
911
939
|
}
|
|
912
|
-
class
|
|
940
|
+
class ue extends Error {
|
|
913
941
|
constructor(t) {
|
|
914
942
|
super(t), this.name = "ParticipantKeyDriftError";
|
|
915
943
|
}
|
|
916
944
|
}
|
|
917
|
-
function
|
|
918
|
-
return e instanceof
|
|
945
|
+
function Mt(e) {
|
|
946
|
+
return e instanceof ue || e instanceof Error && e.name === "ParticipantKeyDriftError";
|
|
919
947
|
}
|
|
920
|
-
function
|
|
921
|
-
return t.length === r.length && t.every((n,
|
|
948
|
+
function Y(e, t, r) {
|
|
949
|
+
return t.length === r.length && t.every((n, a) => n === r[a]) ? null : `${e} expected [${t.join(", ")}], got [${r.join(", ")}]`;
|
|
922
950
|
}
|
|
923
|
-
async function
|
|
924
|
-
const { vaultRegistryReader: t, operationKeyReader: r, vaultIds: n, expected:
|
|
951
|
+
async function Ut(e) {
|
|
952
|
+
const { vaultRegistryReader: t, operationKeyReader: r, vaultIds: n, expected: a } = e, u = a.query;
|
|
925
953
|
if (n.length === 0) return;
|
|
926
|
-
const o = await t.getVaultKeyEpochsBatch(n),
|
|
927
|
-
for (const [
|
|
928
|
-
const p = n[
|
|
954
|
+
const o = await t.getVaultKeyEpochsBatch(n), s = [];
|
|
955
|
+
for (const [l, i] of o.entries()) {
|
|
956
|
+
const p = n[l];
|
|
929
957
|
let c;
|
|
930
958
|
try {
|
|
931
|
-
c = await
|
|
959
|
+
c = await nt({
|
|
932
960
|
operationKeyReader: r,
|
|
933
|
-
query:
|
|
961
|
+
query: u,
|
|
934
962
|
epochs: i
|
|
935
963
|
});
|
|
936
|
-
} catch (
|
|
937
|
-
|
|
938
|
-
`vault ${p}: could not resolve participants at frozen epochs (vp=${i.vpKeyEpoch}, keeper=${i.appKeeperKeyEpoch}, uc=${i.ucKeyEpoch}): ${
|
|
964
|
+
} catch (v) {
|
|
965
|
+
s.push(
|
|
966
|
+
`vault ${p}: could not resolve participants at frozen epochs (vp=${i.vpKeyEpoch}, keeper=${i.appKeeperKeyEpoch}, uc=${i.ucKeyEpoch}): ${v.message}`
|
|
939
967
|
);
|
|
940
968
|
continue;
|
|
941
969
|
}
|
|
942
|
-
c.vaultProvider.operationBtcPubkey !==
|
|
943
|
-
`vault ${p}: vault provider key expected ${
|
|
970
|
+
c.vaultProvider.operationBtcPubkey !== a.vaultProvider.operationBtcPubkey && s.push(
|
|
971
|
+
`vault ${p}: vault provider key expected ${a.vaultProvider.operationBtcPubkey}, got ${c.vaultProvider.operationBtcPubkey}`
|
|
944
972
|
);
|
|
945
|
-
const h =
|
|
973
|
+
const h = Y(
|
|
946
974
|
`vault ${p}: vault keeper keys`,
|
|
947
|
-
|
|
975
|
+
a.vaultKeeperOperationKeysSorted,
|
|
948
976
|
c.vaultKeeperOperationKeysSorted
|
|
949
977
|
);
|
|
950
|
-
h &&
|
|
951
|
-
const f =
|
|
978
|
+
h && s.push(h);
|
|
979
|
+
const f = Y(
|
|
952
980
|
`vault ${p}: universal challenger keys`,
|
|
953
|
-
|
|
981
|
+
a.universalChallengerOperationKeysSorted,
|
|
954
982
|
c.universalChallengerOperationKeysSorted
|
|
955
983
|
);
|
|
956
|
-
f &&
|
|
984
|
+
f && s.push(f);
|
|
957
985
|
}
|
|
958
|
-
if (
|
|
959
|
-
throw new
|
|
960
|
-
`Aborting BTC broadcast: participant operation keys changed during registration (${
|
|
986
|
+
if (s.length > 0)
|
|
987
|
+
throw new ue(
|
|
988
|
+
`Aborting BTC broadcast: participant operation keys changed during registration (${s.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
|
|
961
989
|
);
|
|
962
990
|
}
|
|
963
|
-
class
|
|
991
|
+
class le extends Error {
|
|
964
992
|
constructor(t) {
|
|
965
993
|
super(t), this.name = "RegisteredVaultVersionMismatchError";
|
|
966
994
|
}
|
|
967
995
|
}
|
|
968
|
-
function
|
|
969
|
-
return e instanceof
|
|
996
|
+
function Lt(e) {
|
|
997
|
+
return e instanceof le || e instanceof Error && e.name === "RegisteredVaultVersionMismatchError";
|
|
970
998
|
}
|
|
971
|
-
async function
|
|
999
|
+
async function zt(e) {
|
|
972
1000
|
const {
|
|
973
1001
|
vaultRegistryReader: t,
|
|
974
1002
|
vaultIds: r,
|
|
975
1003
|
expectedOffchainParamsVersion: n,
|
|
976
|
-
expectedAppVaultKeepersVersion:
|
|
977
|
-
expectedUniversalChallengersVersion:
|
|
1004
|
+
expectedAppVaultKeepersVersion: a,
|
|
1005
|
+
expectedUniversalChallengersVersion: u,
|
|
978
1006
|
expectedVaultCoreVersion: o
|
|
979
|
-
} = e,
|
|
980
|
-
if (
|
|
1007
|
+
} = e, s = await t.getProtocolInfoBatch(r), l = [];
|
|
1008
|
+
if (s.forEach((i, p) => {
|
|
981
1009
|
const c = r[p];
|
|
982
|
-
i.offchainParamsVersion !== n &&
|
|
1010
|
+
i.offchainParamsVersion !== n && l.push(
|
|
983
1011
|
`vault ${c}: offchainParams expected v${n}, got v${i.offchainParamsVersion}`
|
|
984
|
-
), i.appVaultKeepersVersion !==
|
|
985
|
-
`vault ${c}: appVaultKeepers expected v${
|
|
986
|
-
), i.universalChallengersVersion !==
|
|
987
|
-
`vault ${c}: universalChallengers expected v${
|
|
988
|
-
), i.vaultCoreVersion !== o &&
|
|
1012
|
+
), i.appVaultKeepersVersion !== a && l.push(
|
|
1013
|
+
`vault ${c}: appVaultKeepers expected v${a}, got v${i.appVaultKeepersVersion}`
|
|
1014
|
+
), i.universalChallengersVersion !== u && l.push(
|
|
1015
|
+
`vault ${c}: universalChallengers expected v${u}, got v${i.universalChallengersVersion}`
|
|
1016
|
+
), i.vaultCoreVersion !== o && l.push(
|
|
989
1017
|
`vault ${c}: vaultCoreVersion expected v${o} (build-time active), got v${i.vaultCoreVersion}`
|
|
990
1018
|
);
|
|
991
|
-
}),
|
|
992
|
-
throw new
|
|
993
|
-
`Aborting BTC broadcast: signer-set or offchain-params versions changed during registration (${
|
|
1019
|
+
}), l.length > 0)
|
|
1020
|
+
throw new le(
|
|
1021
|
+
`Aborting BTC broadcast: signer-set or offchain-params versions changed during registration (${l.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
|
|
994
1022
|
);
|
|
995
1023
|
}
|
|
996
|
-
var
|
|
997
|
-
const
|
|
1024
|
+
var ce = /* @__PURE__ */ ((e) => (e.CLAIM_EVENT_RECEIVED = "ClaimEventReceived", e.CLAIM_BROADCAST = "ClaimBroadcast", e.ASSERT_BROADCAST = "AssertBroadcast", e.PAYOUT_BROADCAST = "PayoutBroadcast", e.PAYOUT_BLOCKED = "PayoutBlocked", e))(ce || {});
|
|
1025
|
+
const ct = /* @__PURE__ */ new Set([
|
|
998
1026
|
"PayoutBroadcast",
|
|
999
1027
|
"PayoutBlocked"
|
|
1000
1028
|
/* PAYOUT_BLOCKED */
|
|
1001
1029
|
]);
|
|
1002
|
-
function
|
|
1003
|
-
return Object.values(
|
|
1030
|
+
function Xt(e) {
|
|
1031
|
+
return Object.values(ce).includes(
|
|
1004
1032
|
e
|
|
1005
1033
|
);
|
|
1006
1034
|
}
|
|
1007
|
-
function
|
|
1008
|
-
return !!e &&
|
|
1035
|
+
function Gt(e) {
|
|
1036
|
+
return !!e && ct.has(e);
|
|
1009
1037
|
}
|
|
1010
|
-
class
|
|
1038
|
+
class pt extends Error {
|
|
1011
1039
|
constructor(r, n) {
|
|
1012
1040
|
super(`Refund not yet mature (BIP68 not final): ${n.message}`);
|
|
1013
1041
|
A(this, "vaultId");
|
|
@@ -1015,21 +1043,21 @@ class ct extends Error {
|
|
|
1015
1043
|
this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = n;
|
|
1016
1044
|
}
|
|
1017
1045
|
}
|
|
1018
|
-
const
|
|
1019
|
-
function
|
|
1046
|
+
const ht = /^0x[0-9a-fA-F]{64}$/, dt = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, pe = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, he = 160, J = 2e3, Z = 10n, ee = 100n;
|
|
1047
|
+
function jt(e) {
|
|
1020
1048
|
if (!Number.isFinite(e) || e <= 0)
|
|
1021
1049
|
throw new Error(
|
|
1022
1050
|
`feeRateSatsVb must be a positive finite number, got ${e}`
|
|
1023
1051
|
);
|
|
1024
|
-
return BigInt(Math.ceil(e *
|
|
1052
|
+
return BigInt(Math.ceil(e * he));
|
|
1025
1053
|
}
|
|
1026
|
-
const
|
|
1054
|
+
const gt = 1, ft = /non-BIP68-final/i;
|
|
1027
1055
|
function U(e, t) {
|
|
1028
1056
|
if (e.length !== 66)
|
|
1029
1057
|
throw new Error(
|
|
1030
1058
|
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
1031
1059
|
);
|
|
1032
|
-
if (!
|
|
1060
|
+
if (!ht.test(e))
|
|
1033
1061
|
throw new Error(
|
|
1034
1062
|
`${t} must contain only hex characters after the 0x prefix`
|
|
1035
1063
|
);
|
|
@@ -1038,7 +1066,7 @@ function H(e, t) {
|
|
|
1038
1066
|
if (!Number.isInteger(e) || e < 0)
|
|
1039
1067
|
throw new Error(`${t} must be a non-negative integer, got ${e}`);
|
|
1040
1068
|
}
|
|
1041
|
-
function
|
|
1069
|
+
function vt(e) {
|
|
1042
1070
|
if (U(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0)
|
|
1043
1071
|
throw new Error(
|
|
1044
1072
|
`htlcVout must be a non-negative integer, got ${e.htlcVout}`
|
|
@@ -1072,16 +1100,16 @@ function ft(e) {
|
|
|
1072
1100
|
if (H(e.offchainParamsVersion, "offchainParamsVersion"), H(e.appVaultKeepersVersion, "appVaultKeepersVersion"), H(
|
|
1073
1101
|
e.universalChallengersVersion,
|
|
1074
1102
|
"universalChallengersVersion"
|
|
1075
|
-
),
|
|
1103
|
+
), Ae(
|
|
1076
1104
|
e.vaultCoreVersion,
|
|
1077
1105
|
"VaultRefundData.vaultCoreVersion"
|
|
1078
1106
|
), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
|
|
1079
1107
|
throw new Error("unsignedPrePeginTxHex must be a non-empty hex string");
|
|
1080
|
-
if (!
|
|
1108
|
+
if (!dt.test(e.unsignedPrePeginTxHex))
|
|
1081
1109
|
throw new Error(
|
|
1082
1110
|
"unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
|
|
1083
1111
|
);
|
|
1084
|
-
if (!e.depositorBtcPubkey || !
|
|
1112
|
+
if (!e.depositorBtcPubkey || !pe.test(e.depositorBtcPubkey))
|
|
1085
1113
|
throw new Error(
|
|
1086
1114
|
"depositorBtcPubkey must be 32 or 33 bytes of hex (optional 0x prefix)"
|
|
1087
1115
|
);
|
|
@@ -1089,7 +1117,7 @@ function ft(e) {
|
|
|
1089
1117
|
throw new Error(`amount must be a positive bigint, got ${e.amount}`);
|
|
1090
1118
|
}
|
|
1091
1119
|
function yt(e) {
|
|
1092
|
-
if (!e.vaultProviderPubkey || !
|
|
1120
|
+
if (!e.vaultProviderPubkey || !pe.test(e.vaultProviderPubkey))
|
|
1093
1121
|
throw new Error("vaultProviderPubkey must be 32 or 33 bytes of hex");
|
|
1094
1122
|
if (e.vaultKeeperPubkeys.length === 0)
|
|
1095
1123
|
throw new Error("vaultKeeperPubkeys must be non-empty");
|
|
@@ -1114,8 +1142,8 @@ function yt(e) {
|
|
|
1114
1142
|
`councilQuorum (${e.councilQuorum}) must be in [1, councilSize=${e.councilSize}]`
|
|
1115
1143
|
);
|
|
1116
1144
|
}
|
|
1117
|
-
function
|
|
1118
|
-
const t =
|
|
1145
|
+
function Pt(e) {
|
|
1146
|
+
const t = Te.fromHex(e);
|
|
1119
1147
|
try {
|
|
1120
1148
|
t.finalizeAllInputs();
|
|
1121
1149
|
} catch (r) {
|
|
@@ -1125,40 +1153,40 @@ function vt(e) {
|
|
|
1125
1153
|
}
|
|
1126
1154
|
return t.extractTransaction().toHex();
|
|
1127
1155
|
}
|
|
1128
|
-
async function
|
|
1156
|
+
async function qt(e) {
|
|
1129
1157
|
const {
|
|
1130
1158
|
vaultId: t,
|
|
1131
1159
|
readVault: r,
|
|
1132
1160
|
readPrePeginContext: n,
|
|
1133
|
-
feeRate:
|
|
1134
|
-
signPsbt:
|
|
1161
|
+
feeRate: a,
|
|
1162
|
+
signPsbt: u,
|
|
1135
1163
|
broadcastTx: o,
|
|
1136
|
-
signal:
|
|
1164
|
+
signal: s
|
|
1137
1165
|
} = e;
|
|
1138
|
-
|
|
1139
|
-
const
|
|
1140
|
-
|
|
1141
|
-
const i = await n(
|
|
1142
|
-
if (yt(i),
|
|
1143
|
-
throw new Error(`feeRate must be a positive number, got ${
|
|
1144
|
-
if (
|
|
1166
|
+
s == null || s.throwIfAborted(), U(t, "vaultId");
|
|
1167
|
+
const l = await r();
|
|
1168
|
+
vt(l), s == null || s.throwIfAborted();
|
|
1169
|
+
const i = await n(l);
|
|
1170
|
+
if (yt(i), s == null || s.throwIfAborted(), !Number.isFinite(a) || a <= 0)
|
|
1171
|
+
throw new Error(`feeRate must be a positive number, got ${a}`);
|
|
1172
|
+
if (a > J)
|
|
1145
1173
|
throw new Error(
|
|
1146
|
-
`feeRate ${
|
|
1174
|
+
`feeRate ${a} sat/vB exceeds refund safety cap ${J} sat/vB; refusing to sign refund.`
|
|
1147
1175
|
);
|
|
1148
|
-
const p = BigInt(Math.ceil(
|
|
1176
|
+
const p = BigInt(Math.ceil(a * he)), c = l.amount * Z / ee;
|
|
1149
1177
|
if (p > c)
|
|
1150
1178
|
throw new Error(
|
|
1151
|
-
`Refund fee ${p} sats exceeds the per-vault safety cap of ${c} sats (${Z}/${ee} of vault.amount=${
|
|
1179
|
+
`Refund fee ${p} sats exceeds the per-vault safety cap of ${c} sats (${Z}/${ee} of vault.amount=${l.amount}); refusing to sign refund.`
|
|
1152
1180
|
);
|
|
1153
|
-
|
|
1181
|
+
s == null || s.throwIfAborted();
|
|
1154
1182
|
const h = L(
|
|
1155
|
-
|
|
1156
|
-
), f = d(
|
|
1157
|
-
if (
|
|
1183
|
+
l.depositorBtcPubkey
|
|
1184
|
+
), f = d(l.unsignedPrePeginTxHex), v = ke(f);
|
|
1185
|
+
if (v !== void 0 && v.vout !== l.batch.length)
|
|
1158
1186
|
throw new Error(
|
|
1159
|
-
`Auth-anchor OP_RETURN at vout ${
|
|
1187
|
+
`Auth-anchor OP_RETURN at vout ${v.vout} does not match batch size (${l.batch.length} HTLC outputs expect the anchor at vout ${l.batch.length}). Refund refused — sibling HTLC vector is incomplete.`
|
|
1160
1188
|
);
|
|
1161
|
-
const T =
|
|
1189
|
+
const T = v == null ? void 0 : v.hash;
|
|
1162
1190
|
let x;
|
|
1163
1191
|
try {
|
|
1164
1192
|
x = $.fromHex(f);
|
|
@@ -1167,18 +1195,18 @@ async function Gt(e) {
|
|
|
1167
1195
|
`Failed to parse funded Pre-PegIn transaction hex: ${g instanceof Error ? g.message : String(g)}`
|
|
1168
1196
|
);
|
|
1169
1197
|
}
|
|
1170
|
-
if (x.outs.length <
|
|
1198
|
+
if (x.outs.length < l.batch.length)
|
|
1171
1199
|
throw new Error(
|
|
1172
|
-
`Funded Pre-PegIn tx has ${x.outs.length} outputs but batch requires at least ${
|
|
1200
|
+
`Funded Pre-PegIn tx has ${x.outs.length} outputs but batch requires at least ${l.batch.length} HTLC outputs. Refund refused — funded tx shape disagrees with sibling vector.`
|
|
1173
1201
|
);
|
|
1174
|
-
const { psbtHex: m } = await
|
|
1202
|
+
const { psbtHex: m } = await Be({
|
|
1175
1203
|
prePeginParams: {
|
|
1176
|
-
vaultCoreVersion:
|
|
1204
|
+
vaultCoreVersion: l.vaultCoreVersion,
|
|
1177
1205
|
depositorPubkey: h,
|
|
1178
1206
|
vaultProviderPubkey: d(i.vaultProviderPubkey),
|
|
1179
1207
|
vaultKeeperPubkeys: i.vaultKeeperPubkeys.map(d),
|
|
1180
1208
|
universalChallengerPubkeys: i.universalChallengerPubkeys.map(d),
|
|
1181
|
-
hashlocks:
|
|
1209
|
+
hashlocks: l.batch.map((g) => d(g.hashlock)),
|
|
1182
1210
|
timelockRefund: i.timelockRefund,
|
|
1183
1211
|
// `batch[i].amount` is the on-chain vault deposit (peg-in) amount, which
|
|
1184
1212
|
// is exactly what WASM's `pegInAmounts` expects — it re-adds the protocol
|
|
@@ -1186,7 +1214,7 @@ async function Gt(e) {
|
|
|
1186
1214
|
// HTLC output. `buildRefundPsbt`'s value cross-check then binds the result
|
|
1187
1215
|
// to the funded tx bytes, refusing the refund if the template's HTLC value
|
|
1188
1216
|
// disagrees with the on-chain commitment.
|
|
1189
|
-
pegInAmounts:
|
|
1217
|
+
pegInAmounts: l.batch.map((g) => g.amount),
|
|
1190
1218
|
feeRate: i.feeRate,
|
|
1191
1219
|
minPeginFeeRate: i.minPeginFeeRate,
|
|
1192
1220
|
numLocalChallengers: i.numLocalChallengers,
|
|
@@ -1196,25 +1224,25 @@ async function Gt(e) {
|
|
|
1196
1224
|
authAnchorHash: T
|
|
1197
1225
|
},
|
|
1198
1226
|
fundedPrePeginTxHex: f,
|
|
1199
|
-
htlcVout:
|
|
1227
|
+
htlcVout: l.htlcVout,
|
|
1200
1228
|
refundFee: p,
|
|
1201
1229
|
// buildRefundPsbt's top-level `hashlock` param is documented as "no 0x
|
|
1202
1230
|
// prefix" and flows into the WASM HTLC connector derivation; a prefixed
|
|
1203
1231
|
// value would derive the wrong refund script leaf and yield an
|
|
1204
1232
|
// unspendable PSBT. Match the `hashlocks` array handling above.
|
|
1205
|
-
hashlock: d(
|
|
1233
|
+
hashlock: d(l.hashlock)
|
|
1206
1234
|
});
|
|
1207
|
-
|
|
1235
|
+
s == null || s.throwIfAborted();
|
|
1208
1236
|
const b = M(
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
),
|
|
1237
|
+
l.depositorBtcPubkey,
|
|
1238
|
+
gt
|
|
1239
|
+
), y = await u(m, b);
|
|
1212
1240
|
N({
|
|
1213
1241
|
requestedPsbtHex: m,
|
|
1214
|
-
returnedPsbtHex:
|
|
1242
|
+
returnedPsbtHex: y
|
|
1215
1243
|
});
|
|
1216
1244
|
const S = 0, _ = D(
|
|
1217
|
-
|
|
1245
|
+
y,
|
|
1218
1246
|
h,
|
|
1219
1247
|
S
|
|
1220
1248
|
);
|
|
@@ -1224,49 +1252,50 @@ async function Gt(e) {
|
|
|
1224
1252
|
signerXOnlyPubkeyHex: h,
|
|
1225
1253
|
inputIndex: S
|
|
1226
1254
|
});
|
|
1227
|
-
const B =
|
|
1228
|
-
|
|
1255
|
+
const B = Pt(y);
|
|
1256
|
+
s == null || s.throwIfAborted();
|
|
1229
1257
|
try {
|
|
1230
1258
|
return await o(B);
|
|
1231
1259
|
} catch (g) {
|
|
1232
|
-
throw g instanceof Error &&
|
|
1260
|
+
throw g instanceof Error && ft.test(g.message) ? new pt(t, g) : g;
|
|
1233
1261
|
}
|
|
1234
1262
|
}
|
|
1235
1263
|
export {
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1264
|
+
qt as A,
|
|
1265
|
+
pt as B,
|
|
1266
|
+
ce as C,
|
|
1267
|
+
jt as D,
|
|
1268
|
+
ee as E,
|
|
1269
|
+
Z as F,
|
|
1270
|
+
J as G,
|
|
1271
|
+
he as H,
|
|
1272
|
+
ue as P,
|
|
1273
|
+
le as R,
|
|
1274
|
+
Bt as a,
|
|
1246
1275
|
At as b,
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1276
|
+
Vt as c,
|
|
1277
|
+
Ht as d,
|
|
1278
|
+
Ft as e,
|
|
1279
|
+
Dt as f,
|
|
1280
|
+
Nt as g,
|
|
1252
1281
|
at as h,
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
q,
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1282
|
+
Ot as i,
|
|
1283
|
+
st as j,
|
|
1284
|
+
Mt as k,
|
|
1285
|
+
Ut as l,
|
|
1286
|
+
Lt as m,
|
|
1287
|
+
zt as n,
|
|
1288
|
+
Kt as o,
|
|
1289
|
+
K as p,
|
|
1290
|
+
et as q,
|
|
1291
|
+
Rt as r,
|
|
1292
|
+
ze as s,
|
|
1293
|
+
q as t,
|
|
1265
1294
|
rt as u,
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1295
|
+
It as v,
|
|
1296
|
+
ae as w,
|
|
1297
|
+
nt as x,
|
|
1298
|
+
Xt as y,
|
|
1270
1299
|
Gt as z
|
|
1271
1300
|
};
|
|
1272
|
-
//# sourceMappingURL=buildAndBroadcastRefund-
|
|
1301
|
+
//# sourceMappingURL=buildAndBroadcastRefund-DpF_b3d9.js.map
|