@babylonlabs-io/ts-sdk 0.58.1 → 0.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BTCVaultRegistry.abi-COxUdCTR.cjs +2 -0
- package/dist/BTCVaultRegistry.abi-COxUdCTR.cjs.map +1 -0
- package/dist/{BTCVaultRegistry.abi-CixOlp3B.js → BTCVaultRegistry.abi-Ch0IiqNK.js} +19 -1
- package/dist/BTCVaultRegistry.abi-Ch0IiqNK.js.map +1 -0
- package/dist/{PeginManager-CogqZaa2.cjs → PeginManager-792nHwLl.cjs} +2 -2
- package/dist/{PeginManager-CogqZaa2.cjs.map → PeginManager-792nHwLl.cjs.map} +1 -1
- package/dist/{PeginManager-C8ixWlUM.js → PeginManager-Ddn6NDm3.js} +3 -3
- package/dist/{PeginManager-C8ixWlUM.js.map → PeginManager-Ddn6NDm3.js.map} +1 -1
- package/dist/{batchPoll-B0VxT62K.js → batchPoll-qXRNTvnR.js} +3 -3
- package/dist/{batchPoll-B0VxT62K.js.map → batchPoll-qXRNTvnR.js.map} +1 -1
- package/dist/{batchPoll-D5IDDOa8.cjs → batchPoll-xvVjiJXJ.cjs} +2 -2
- package/dist/{batchPoll-D5IDDOa8.cjs.map → batchPoll-xvVjiJXJ.cjs.map} +1 -1
- package/dist/{buildAndBroadcastRefund-DBA-Mp4I.js → buildAndBroadcastRefund-C-rbYMy6.js} +455 -428
- package/dist/buildAndBroadcastRefund-C-rbYMy6.js.map +1 -0
- package/dist/buildAndBroadcastRefund-HBOCjeUh.cjs +2 -0
- package/dist/buildAndBroadcastRefund-HBOCjeUh.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +52 -51
- package/dist/{mempoolApi-CMHEz4ez.js → mempoolApi-BTkbTDSY.js} +2 -2
- package/dist/{mempoolApi-CMHEz4ez.js.map → mempoolApi-BTkbTDSY.js.map} +1 -1
- package/dist/{mempoolApi-DfD3_Y6v.cjs → mempoolApi-DjwZ130O.cjs} +2 -2
- package/dist/{mempoolApi-DfD3_Y6v.cjs.map → mempoolApi-DjwZ130O.cjs.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/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +2 -2
- package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts +14 -0
- 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/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/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/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-Ch0IiqNK.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]
|
|
67
|
+
});
|
|
68
|
+
}
|
|
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]
|
|
57
83
|
});
|
|
58
84
|
}
|
|
59
|
-
const G = 1,
|
|
60
|
-
function
|
|
61
|
-
const r = d(t).toLowerCase(),
|
|
62
|
-
if (
|
|
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,148 @@ 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.getVaultProviderBtcPubKey(
|
|
719
|
-
r.getCurrentVaultKeepersVersion(
|
|
744
|
+
t.getVaultProviderBtcPubKey(a),
|
|
745
|
+
r.getCurrentVaultKeepersVersion(u),
|
|
720
746
|
n.getLatestUniversalChallengersVersion()
|
|
721
747
|
]), [T, x] = await Promise.all([
|
|
722
748
|
r.getVaultKeepersByVersion(
|
|
723
|
-
|
|
749
|
+
u,
|
|
724
750
|
f
|
|
725
751
|
),
|
|
726
752
|
n.getUniversalChallengersByVersion(
|
|
727
|
-
|
|
753
|
+
v
|
|
728
754
|
)
|
|
729
755
|
]), m = {
|
|
730
756
|
vaultProvider: k(h),
|
|
731
|
-
vaultKeepers:
|
|
732
|
-
universalChallengers:
|
|
733
|
-
}, b = await
|
|
757
|
+
vaultKeepers: W(T.map((P) => P.btcPubKey)),
|
|
758
|
+
universalChallengers: W(x.map((P) => P.btcPubKey))
|
|
759
|
+
}, b = await rt({
|
|
734
760
|
operationKeyReader: i,
|
|
735
761
|
query: {
|
|
736
|
-
vaultProviderEthAddress:
|
|
762
|
+
vaultProviderEthAddress: a,
|
|
737
763
|
vaultProviderGenesisBtcPubkey: `0x${h}`,
|
|
738
|
-
applicationEntryPoint:
|
|
764
|
+
applicationEntryPoint: u,
|
|
739
765
|
vaultKeepers: T,
|
|
740
766
|
universalChallengers: x
|
|
741
767
|
}
|
|
742
|
-
}),
|
|
768
|
+
}), y = {
|
|
743
769
|
vaultProvider: b.vaultProvider.operationBtcPubkey,
|
|
744
770
|
vaultKeepers: [...b.vaultKeeperOperationKeysSorted],
|
|
745
771
|
universalChallengers: [
|
|
746
772
|
...b.universalChallengerOperationKeysSorted
|
|
747
773
|
]
|
|
748
|
-
}, S =
|
|
774
|
+
}, S = et(
|
|
749
775
|
o,
|
|
750
776
|
m.vaultProvider,
|
|
751
|
-
|
|
777
|
+
y.vaultProvider
|
|
752
778
|
), _ = q(
|
|
753
|
-
|
|
779
|
+
s,
|
|
754
780
|
m.vaultKeepers,
|
|
755
|
-
|
|
781
|
+
y.vaultKeepers
|
|
756
782
|
), B = q(
|
|
757
|
-
|
|
783
|
+
l,
|
|
758
784
|
m.universalChallengers,
|
|
759
|
-
|
|
785
|
+
y.universalChallengers
|
|
760
786
|
);
|
|
761
|
-
if (!
|
|
787
|
+
if (!K(S))
|
|
762
788
|
throw new Error(
|
|
763
|
-
`Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${
|
|
789
|
+
`Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${a}. Refresh and try again.`
|
|
764
790
|
);
|
|
765
|
-
if (!
|
|
791
|
+
if (!K(_))
|
|
766
792
|
throw new Error(
|
|
767
793
|
`Vault keeper BTC pubkeys (v${f}) indexer set does not match ApplicationRegistry on-chain set. Refresh and try again.`
|
|
768
794
|
);
|
|
769
|
-
if (!
|
|
795
|
+
if (!K(B))
|
|
770
796
|
throw new Error(
|
|
771
|
-
`Universal challenger BTC pubkeys (v${
|
|
797
|
+
`Universal challenger BTC pubkeys (v${v}) indexer set does not match ProtocolParams on-chain set. Refresh and try again.`
|
|
772
798
|
);
|
|
773
|
-
const g = [S, _, B],
|
|
774
|
-
if (
|
|
775
|
-
const P = `Indexer participant hints are internally inconsistent for vault provider ${
|
|
799
|
+
const g = [S, _, B], de = g.some((P) => P.registration && !P.operation), z = g.some((P) => P.operation && !P.registration);
|
|
800
|
+
if (de && z) {
|
|
801
|
+
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
802
|
throw c == null || c(P), new Error(`${P} Refresh and try again.`);
|
|
777
803
|
}
|
|
778
804
|
return z && (p == null || p(
|
|
779
|
-
`Indexer is serving rotated operation keys for vault provider ${
|
|
805
|
+
`Indexer is serving rotated operation keys for vault provider ${a}`
|
|
780
806
|
)), {
|
|
781
|
-
vaultProviderBtcPubkeyXOnly:
|
|
782
|
-
vaultKeeperBtcPubkeysSorted:
|
|
783
|
-
universalChallengerBtcPubkeysSorted:
|
|
807
|
+
vaultProviderBtcPubkeyXOnly: y.vaultProvider,
|
|
808
|
+
vaultKeeperBtcPubkeysSorted: y.vaultKeepers,
|
|
809
|
+
universalChallengerBtcPubkeysSorted: y.universalChallengers,
|
|
784
810
|
expectedAppVaultKeepersVersion: f,
|
|
785
|
-
expectedUniversalChallengersVersion:
|
|
811
|
+
expectedUniversalChallengersVersion: v,
|
|
786
812
|
registrationKeys: m,
|
|
787
813
|
participantKeys: b
|
|
788
814
|
};
|
|
789
815
|
}
|
|
790
|
-
function
|
|
816
|
+
function ot(e) {
|
|
791
817
|
return /^[0-9a-fA-F]{64}$/.test(e);
|
|
792
818
|
}
|
|
793
|
-
function
|
|
819
|
+
function Ot(e) {
|
|
794
820
|
const {
|
|
795
821
|
amountSats: t,
|
|
796
822
|
minDeposit: r,
|
|
797
823
|
maxDeposit: n,
|
|
798
|
-
btcBalance:
|
|
799
|
-
estimatedFeeSats:
|
|
824
|
+
btcBalance: a,
|
|
825
|
+
estimatedFeeSats: u,
|
|
800
826
|
depositorClaimValue: o
|
|
801
827
|
} = e;
|
|
802
|
-
return !(t <= 0n || t < r || n && n > 0n && t > n ||
|
|
828
|
+
return !(t <= 0n || t < r || n && n > 0n && t > n || u == null || o == null || t + u + o > a);
|
|
803
829
|
}
|
|
804
|
-
function
|
|
830
|
+
function Ht(e, t, r) {
|
|
805
831
|
return e <= 0n ? {
|
|
806
832
|
valid: !1,
|
|
807
833
|
error: "Deposit amount must be greater than zero"
|
|
@@ -813,7 +839,7 @@ function It(e, t, r) {
|
|
|
813
839
|
error: `Maximum deposit is ${C(r)} BTC`
|
|
814
840
|
} : { valid: !0 };
|
|
815
841
|
}
|
|
816
|
-
function
|
|
842
|
+
function Nt(e) {
|
|
817
843
|
const { amount: t, effectiveRemaining: r } = e;
|
|
818
844
|
return r === null ? { valid: !0 } : r === 0n ? {
|
|
819
845
|
valid: !1,
|
|
@@ -823,191 +849,191 @@ function Ot(e) {
|
|
|
823
849
|
error: `Vault size exceeds remaining capacity (${C(r)} BTC)`
|
|
824
850
|
} : { valid: !0 };
|
|
825
851
|
}
|
|
826
|
-
function
|
|
852
|
+
function Dt(e, t) {
|
|
827
853
|
if (!e || e.length === 0)
|
|
828
854
|
return {
|
|
829
855
|
valid: !1,
|
|
830
856
|
error: "At least one vault provider must be selected"
|
|
831
857
|
};
|
|
832
858
|
const r = t.map(
|
|
833
|
-
(
|
|
859
|
+
(a) => a.toLowerCase()
|
|
834
860
|
);
|
|
835
861
|
return e.filter(
|
|
836
|
-
(
|
|
862
|
+
(a) => !r.includes(a.toLowerCase())
|
|
837
863
|
).length > 0 ? {
|
|
838
864
|
valid: !1,
|
|
839
865
|
error: "Invalid vault provider selected"
|
|
840
866
|
} : { valid: !0 };
|
|
841
867
|
}
|
|
842
|
-
function
|
|
868
|
+
function at(e, t, r) {
|
|
843
869
|
if (!e || e.length === 0)
|
|
844
870
|
return {
|
|
845
871
|
valid: !1,
|
|
846
872
|
error: "At least one vault amount required"
|
|
847
873
|
};
|
|
848
874
|
for (let n = 0; n < e.length; n++) {
|
|
849
|
-
const
|
|
850
|
-
if (
|
|
875
|
+
const a = e[n];
|
|
876
|
+
if (a <= 0n)
|
|
851
877
|
return {
|
|
852
878
|
valid: !1,
|
|
853
879
|
error: `Vault ${n + 1} amount must be positive`
|
|
854
880
|
};
|
|
855
|
-
if (t &&
|
|
881
|
+
if (t && a < t)
|
|
856
882
|
return {
|
|
857
883
|
valid: !1,
|
|
858
|
-
error: `Vault ${n + 1} amount ${C(
|
|
884
|
+
error: `Vault ${n + 1} amount ${C(a)} BTC is below minimum deposit ${C(t)} BTC`
|
|
859
885
|
};
|
|
860
|
-
if (r &&
|
|
886
|
+
if (r && a > r)
|
|
861
887
|
return {
|
|
862
888
|
valid: !1,
|
|
863
|
-
error: `Vault ${n + 1} amount ${C(
|
|
889
|
+
error: `Vault ${n + 1} amount ${C(a)} BTC exceeds maximum deposit ${C(r)} BTC`
|
|
864
890
|
};
|
|
865
891
|
}
|
|
866
892
|
return { valid: !0 };
|
|
867
893
|
}
|
|
868
|
-
function
|
|
894
|
+
function st(e) {
|
|
869
895
|
const t = d(e);
|
|
870
|
-
return
|
|
896
|
+
return ot(t) ? { valid: !0 } : {
|
|
871
897
|
valid: !1,
|
|
872
898
|
error: "Invalid pubkey format: must be 64 hex characters (32-byte x-only public key, no 0x prefix)"
|
|
873
899
|
};
|
|
874
900
|
}
|
|
875
|
-
function
|
|
901
|
+
function it(e) {
|
|
876
902
|
if (!e || e.length === 0)
|
|
877
903
|
throw new Error(
|
|
878
904
|
"No vault keepers available. The system requires at least one vault keeper to create a deposit."
|
|
879
905
|
);
|
|
880
906
|
}
|
|
881
|
-
function
|
|
907
|
+
function ut(e) {
|
|
882
908
|
if (!e || e.length === 0)
|
|
883
909
|
throw new Error(
|
|
884
910
|
"No universal challengers available. The system requires at least one universal challenger to create a deposit."
|
|
885
911
|
);
|
|
886
912
|
}
|
|
887
|
-
function
|
|
913
|
+
function lt(e) {
|
|
888
914
|
if (e.length === 0)
|
|
889
915
|
throw new Error("No spendable UTXOs available");
|
|
890
916
|
}
|
|
891
|
-
function
|
|
917
|
+
function Ft(e) {
|
|
892
918
|
const {
|
|
893
919
|
vaultAmounts: t,
|
|
894
920
|
confirmedUTXOs: r,
|
|
895
921
|
vaultProviderBtcPubkey: n,
|
|
896
|
-
vaultKeeperBtcPubkeys:
|
|
897
|
-
universalChallengerBtcPubkeys:
|
|
922
|
+
vaultKeeperBtcPubkeys: a,
|
|
923
|
+
universalChallengerBtcPubkeys: u,
|
|
898
924
|
minDeposit: o,
|
|
899
|
-
maxDeposit:
|
|
900
|
-
} = e,
|
|
925
|
+
maxDeposit: s
|
|
926
|
+
} = e, l = at(
|
|
901
927
|
t,
|
|
902
928
|
o,
|
|
903
|
-
|
|
929
|
+
s
|
|
904
930
|
);
|
|
905
|
-
if (!
|
|
906
|
-
throw new Error(
|
|
907
|
-
const i =
|
|
931
|
+
if (!l.valid)
|
|
932
|
+
throw new Error(l.error);
|
|
933
|
+
const i = st(n);
|
|
908
934
|
if (!i.valid)
|
|
909
935
|
throw new Error(i.error);
|
|
910
|
-
|
|
936
|
+
it(a), ut(u), lt(r);
|
|
911
937
|
}
|
|
912
|
-
class
|
|
938
|
+
class ue extends Error {
|
|
913
939
|
constructor(t) {
|
|
914
940
|
super(t), this.name = "ParticipantKeyDriftError";
|
|
915
941
|
}
|
|
916
942
|
}
|
|
917
|
-
function
|
|
918
|
-
return e instanceof
|
|
943
|
+
function Mt(e) {
|
|
944
|
+
return e instanceof ue || e instanceof Error && e.name === "ParticipantKeyDriftError";
|
|
919
945
|
}
|
|
920
|
-
function
|
|
921
|
-
return t.length === r.length && t.every((n,
|
|
946
|
+
function Y(e, t, r) {
|
|
947
|
+
return t.length === r.length && t.every((n, a) => n === r[a]) ? null : `${e} expected [${t.join(", ")}], got [${r.join(", ")}]`;
|
|
922
948
|
}
|
|
923
|
-
async function
|
|
924
|
-
const { vaultRegistryReader: t, operationKeyReader: r, vaultIds: n, expected:
|
|
949
|
+
async function Ut(e) {
|
|
950
|
+
const { vaultRegistryReader: t, operationKeyReader: r, vaultIds: n, expected: a } = e, u = a.query;
|
|
925
951
|
if (n.length === 0) return;
|
|
926
|
-
const o = await t.getVaultKeyEpochsBatch(n),
|
|
927
|
-
for (const [
|
|
928
|
-
const p = n[
|
|
952
|
+
const o = await t.getVaultKeyEpochsBatch(n), s = [];
|
|
953
|
+
for (const [l, i] of o.entries()) {
|
|
954
|
+
const p = n[l];
|
|
929
955
|
let c;
|
|
930
956
|
try {
|
|
931
|
-
c = await
|
|
957
|
+
c = await nt({
|
|
932
958
|
operationKeyReader: r,
|
|
933
|
-
query:
|
|
959
|
+
query: u,
|
|
934
960
|
epochs: i
|
|
935
961
|
});
|
|
936
|
-
} catch (
|
|
937
|
-
|
|
938
|
-
`vault ${p}: could not resolve participants at frozen epochs (vp=${i.vpKeyEpoch}, keeper=${i.appKeeperKeyEpoch}, uc=${i.ucKeyEpoch}): ${
|
|
962
|
+
} catch (v) {
|
|
963
|
+
s.push(
|
|
964
|
+
`vault ${p}: could not resolve participants at frozen epochs (vp=${i.vpKeyEpoch}, keeper=${i.appKeeperKeyEpoch}, uc=${i.ucKeyEpoch}): ${v.message}`
|
|
939
965
|
);
|
|
940
966
|
continue;
|
|
941
967
|
}
|
|
942
|
-
c.vaultProvider.operationBtcPubkey !==
|
|
943
|
-
`vault ${p}: vault provider key expected ${
|
|
968
|
+
c.vaultProvider.operationBtcPubkey !== a.vaultProvider.operationBtcPubkey && s.push(
|
|
969
|
+
`vault ${p}: vault provider key expected ${a.vaultProvider.operationBtcPubkey}, got ${c.vaultProvider.operationBtcPubkey}`
|
|
944
970
|
);
|
|
945
|
-
const h =
|
|
971
|
+
const h = Y(
|
|
946
972
|
`vault ${p}: vault keeper keys`,
|
|
947
|
-
|
|
973
|
+
a.vaultKeeperOperationKeysSorted,
|
|
948
974
|
c.vaultKeeperOperationKeysSorted
|
|
949
975
|
);
|
|
950
|
-
h &&
|
|
951
|
-
const f =
|
|
976
|
+
h && s.push(h);
|
|
977
|
+
const f = Y(
|
|
952
978
|
`vault ${p}: universal challenger keys`,
|
|
953
|
-
|
|
979
|
+
a.universalChallengerOperationKeysSorted,
|
|
954
980
|
c.universalChallengerOperationKeysSorted
|
|
955
981
|
);
|
|
956
|
-
f &&
|
|
982
|
+
f && s.push(f);
|
|
957
983
|
}
|
|
958
|
-
if (
|
|
959
|
-
throw new
|
|
960
|
-
`Aborting BTC broadcast: participant operation keys changed during registration (${
|
|
984
|
+
if (s.length > 0)
|
|
985
|
+
throw new ue(
|
|
986
|
+
`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
987
|
);
|
|
962
988
|
}
|
|
963
|
-
class
|
|
989
|
+
class le extends Error {
|
|
964
990
|
constructor(t) {
|
|
965
991
|
super(t), this.name = "RegisteredVaultVersionMismatchError";
|
|
966
992
|
}
|
|
967
993
|
}
|
|
968
|
-
function
|
|
969
|
-
return e instanceof
|
|
994
|
+
function Lt(e) {
|
|
995
|
+
return e instanceof le || e instanceof Error && e.name === "RegisteredVaultVersionMismatchError";
|
|
970
996
|
}
|
|
971
|
-
async function
|
|
997
|
+
async function zt(e) {
|
|
972
998
|
const {
|
|
973
999
|
vaultRegistryReader: t,
|
|
974
1000
|
vaultIds: r,
|
|
975
1001
|
expectedOffchainParamsVersion: n,
|
|
976
|
-
expectedAppVaultKeepersVersion:
|
|
977
|
-
expectedUniversalChallengersVersion:
|
|
1002
|
+
expectedAppVaultKeepersVersion: a,
|
|
1003
|
+
expectedUniversalChallengersVersion: u,
|
|
978
1004
|
expectedVaultCoreVersion: o
|
|
979
|
-
} = e,
|
|
980
|
-
if (
|
|
1005
|
+
} = e, s = await t.getProtocolInfoBatch(r), l = [];
|
|
1006
|
+
if (s.forEach((i, p) => {
|
|
981
1007
|
const c = r[p];
|
|
982
|
-
i.offchainParamsVersion !== n &&
|
|
1008
|
+
i.offchainParamsVersion !== n && l.push(
|
|
983
1009
|
`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 &&
|
|
1010
|
+
), i.appVaultKeepersVersion !== a && l.push(
|
|
1011
|
+
`vault ${c}: appVaultKeepers expected v${a}, got v${i.appVaultKeepersVersion}`
|
|
1012
|
+
), i.universalChallengersVersion !== u && l.push(
|
|
1013
|
+
`vault ${c}: universalChallengers expected v${u}, got v${i.universalChallengersVersion}`
|
|
1014
|
+
), i.vaultCoreVersion !== o && l.push(
|
|
989
1015
|
`vault ${c}: vaultCoreVersion expected v${o} (build-time active), got v${i.vaultCoreVersion}`
|
|
990
1016
|
);
|
|
991
|
-
}),
|
|
992
|
-
throw new
|
|
993
|
-
`Aborting BTC broadcast: signer-set or offchain-params versions changed during registration (${
|
|
1017
|
+
}), l.length > 0)
|
|
1018
|
+
throw new le(
|
|
1019
|
+
`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
1020
|
);
|
|
995
1021
|
}
|
|
996
|
-
var
|
|
997
|
-
const
|
|
1022
|
+
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 || {});
|
|
1023
|
+
const ct = /* @__PURE__ */ new Set([
|
|
998
1024
|
"PayoutBroadcast",
|
|
999
1025
|
"PayoutBlocked"
|
|
1000
1026
|
/* PAYOUT_BLOCKED */
|
|
1001
1027
|
]);
|
|
1002
|
-
function
|
|
1003
|
-
return Object.values(
|
|
1028
|
+
function Xt(e) {
|
|
1029
|
+
return Object.values(ce).includes(
|
|
1004
1030
|
e
|
|
1005
1031
|
);
|
|
1006
1032
|
}
|
|
1007
|
-
function
|
|
1008
|
-
return !!e &&
|
|
1033
|
+
function Gt(e) {
|
|
1034
|
+
return !!e && ct.has(e);
|
|
1009
1035
|
}
|
|
1010
|
-
class
|
|
1036
|
+
class pt extends Error {
|
|
1011
1037
|
constructor(r, n) {
|
|
1012
1038
|
super(`Refund not yet mature (BIP68 not final): ${n.message}`);
|
|
1013
1039
|
A(this, "vaultId");
|
|
@@ -1015,21 +1041,21 @@ class ct extends Error {
|
|
|
1015
1041
|
this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = n;
|
|
1016
1042
|
}
|
|
1017
1043
|
}
|
|
1018
|
-
const
|
|
1019
|
-
function
|
|
1044
|
+
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;
|
|
1045
|
+
function jt(e) {
|
|
1020
1046
|
if (!Number.isFinite(e) || e <= 0)
|
|
1021
1047
|
throw new Error(
|
|
1022
1048
|
`feeRateSatsVb must be a positive finite number, got ${e}`
|
|
1023
1049
|
);
|
|
1024
|
-
return BigInt(Math.ceil(e *
|
|
1050
|
+
return BigInt(Math.ceil(e * he));
|
|
1025
1051
|
}
|
|
1026
|
-
const
|
|
1052
|
+
const gt = 1, ft = /non-BIP68-final/i;
|
|
1027
1053
|
function U(e, t) {
|
|
1028
1054
|
if (e.length !== 66)
|
|
1029
1055
|
throw new Error(
|
|
1030
1056
|
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
1031
1057
|
);
|
|
1032
|
-
if (!
|
|
1058
|
+
if (!ht.test(e))
|
|
1033
1059
|
throw new Error(
|
|
1034
1060
|
`${t} must contain only hex characters after the 0x prefix`
|
|
1035
1061
|
);
|
|
@@ -1038,7 +1064,7 @@ function H(e, t) {
|
|
|
1038
1064
|
if (!Number.isInteger(e) || e < 0)
|
|
1039
1065
|
throw new Error(`${t} must be a non-negative integer, got ${e}`);
|
|
1040
1066
|
}
|
|
1041
|
-
function
|
|
1067
|
+
function vt(e) {
|
|
1042
1068
|
if (U(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0)
|
|
1043
1069
|
throw new Error(
|
|
1044
1070
|
`htlcVout must be a non-negative integer, got ${e.htlcVout}`
|
|
@@ -1072,16 +1098,16 @@ function ft(e) {
|
|
|
1072
1098
|
if (H(e.offchainParamsVersion, "offchainParamsVersion"), H(e.appVaultKeepersVersion, "appVaultKeepersVersion"), H(
|
|
1073
1099
|
e.universalChallengersVersion,
|
|
1074
1100
|
"universalChallengersVersion"
|
|
1075
|
-
),
|
|
1101
|
+
), Ae(
|
|
1076
1102
|
e.vaultCoreVersion,
|
|
1077
1103
|
"VaultRefundData.vaultCoreVersion"
|
|
1078
1104
|
), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
|
|
1079
1105
|
throw new Error("unsignedPrePeginTxHex must be a non-empty hex string");
|
|
1080
|
-
if (!
|
|
1106
|
+
if (!dt.test(e.unsignedPrePeginTxHex))
|
|
1081
1107
|
throw new Error(
|
|
1082
1108
|
"unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
|
|
1083
1109
|
);
|
|
1084
|
-
if (!e.depositorBtcPubkey || !
|
|
1110
|
+
if (!e.depositorBtcPubkey || !pe.test(e.depositorBtcPubkey))
|
|
1085
1111
|
throw new Error(
|
|
1086
1112
|
"depositorBtcPubkey must be 32 or 33 bytes of hex (optional 0x prefix)"
|
|
1087
1113
|
);
|
|
@@ -1089,7 +1115,7 @@ function ft(e) {
|
|
|
1089
1115
|
throw new Error(`amount must be a positive bigint, got ${e.amount}`);
|
|
1090
1116
|
}
|
|
1091
1117
|
function yt(e) {
|
|
1092
|
-
if (!e.vaultProviderPubkey || !
|
|
1118
|
+
if (!e.vaultProviderPubkey || !pe.test(e.vaultProviderPubkey))
|
|
1093
1119
|
throw new Error("vaultProviderPubkey must be 32 or 33 bytes of hex");
|
|
1094
1120
|
if (e.vaultKeeperPubkeys.length === 0)
|
|
1095
1121
|
throw new Error("vaultKeeperPubkeys must be non-empty");
|
|
@@ -1114,8 +1140,8 @@ function yt(e) {
|
|
|
1114
1140
|
`councilQuorum (${e.councilQuorum}) must be in [1, councilSize=${e.councilSize}]`
|
|
1115
1141
|
);
|
|
1116
1142
|
}
|
|
1117
|
-
function
|
|
1118
|
-
const t =
|
|
1143
|
+
function Pt(e) {
|
|
1144
|
+
const t = Te.fromHex(e);
|
|
1119
1145
|
try {
|
|
1120
1146
|
t.finalizeAllInputs();
|
|
1121
1147
|
} catch (r) {
|
|
@@ -1125,40 +1151,40 @@ function vt(e) {
|
|
|
1125
1151
|
}
|
|
1126
1152
|
return t.extractTransaction().toHex();
|
|
1127
1153
|
}
|
|
1128
|
-
async function
|
|
1154
|
+
async function qt(e) {
|
|
1129
1155
|
const {
|
|
1130
1156
|
vaultId: t,
|
|
1131
1157
|
readVault: r,
|
|
1132
1158
|
readPrePeginContext: n,
|
|
1133
|
-
feeRate:
|
|
1134
|
-
signPsbt:
|
|
1159
|
+
feeRate: a,
|
|
1160
|
+
signPsbt: u,
|
|
1135
1161
|
broadcastTx: o,
|
|
1136
|
-
signal:
|
|
1162
|
+
signal: s
|
|
1137
1163
|
} = 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 (
|
|
1164
|
+
s == null || s.throwIfAborted(), U(t, "vaultId");
|
|
1165
|
+
const l = await r();
|
|
1166
|
+
vt(l), s == null || s.throwIfAborted();
|
|
1167
|
+
const i = await n(l);
|
|
1168
|
+
if (yt(i), s == null || s.throwIfAborted(), !Number.isFinite(a) || a <= 0)
|
|
1169
|
+
throw new Error(`feeRate must be a positive number, got ${a}`);
|
|
1170
|
+
if (a > J)
|
|
1145
1171
|
throw new Error(
|
|
1146
|
-
`feeRate ${
|
|
1172
|
+
`feeRate ${a} sat/vB exceeds refund safety cap ${J} sat/vB; refusing to sign refund.`
|
|
1147
1173
|
);
|
|
1148
|
-
const p = BigInt(Math.ceil(
|
|
1174
|
+
const p = BigInt(Math.ceil(a * he)), c = l.amount * Z / ee;
|
|
1149
1175
|
if (p > c)
|
|
1150
1176
|
throw new Error(
|
|
1151
|
-
`Refund fee ${p} sats exceeds the per-vault safety cap of ${c} sats (${Z}/${ee} of vault.amount=${
|
|
1177
|
+
`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
1178
|
);
|
|
1153
|
-
|
|
1179
|
+
s == null || s.throwIfAborted();
|
|
1154
1180
|
const h = L(
|
|
1155
|
-
|
|
1156
|
-
), f = d(
|
|
1157
|
-
if (
|
|
1181
|
+
l.depositorBtcPubkey
|
|
1182
|
+
), f = d(l.unsignedPrePeginTxHex), v = ke(f);
|
|
1183
|
+
if (v !== void 0 && v.vout !== l.batch.length)
|
|
1158
1184
|
throw new Error(
|
|
1159
|
-
`Auth-anchor OP_RETURN at vout ${
|
|
1185
|
+
`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
1186
|
);
|
|
1161
|
-
const T =
|
|
1187
|
+
const T = v == null ? void 0 : v.hash;
|
|
1162
1188
|
let x;
|
|
1163
1189
|
try {
|
|
1164
1190
|
x = $.fromHex(f);
|
|
@@ -1167,18 +1193,18 @@ async function Gt(e) {
|
|
|
1167
1193
|
`Failed to parse funded Pre-PegIn transaction hex: ${g instanceof Error ? g.message : String(g)}`
|
|
1168
1194
|
);
|
|
1169
1195
|
}
|
|
1170
|
-
if (x.outs.length <
|
|
1196
|
+
if (x.outs.length < l.batch.length)
|
|
1171
1197
|
throw new Error(
|
|
1172
|
-
`Funded Pre-PegIn tx has ${x.outs.length} outputs but batch requires at least ${
|
|
1198
|
+
`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
1199
|
);
|
|
1174
|
-
const { psbtHex: m } = await
|
|
1200
|
+
const { psbtHex: m } = await Be({
|
|
1175
1201
|
prePeginParams: {
|
|
1176
|
-
vaultCoreVersion:
|
|
1202
|
+
vaultCoreVersion: l.vaultCoreVersion,
|
|
1177
1203
|
depositorPubkey: h,
|
|
1178
1204
|
vaultProviderPubkey: d(i.vaultProviderPubkey),
|
|
1179
1205
|
vaultKeeperPubkeys: i.vaultKeeperPubkeys.map(d),
|
|
1180
1206
|
universalChallengerPubkeys: i.universalChallengerPubkeys.map(d),
|
|
1181
|
-
hashlocks:
|
|
1207
|
+
hashlocks: l.batch.map((g) => d(g.hashlock)),
|
|
1182
1208
|
timelockRefund: i.timelockRefund,
|
|
1183
1209
|
// `batch[i].amount` is the on-chain vault deposit (peg-in) amount, which
|
|
1184
1210
|
// is exactly what WASM's `pegInAmounts` expects — it re-adds the protocol
|
|
@@ -1186,7 +1212,7 @@ async function Gt(e) {
|
|
|
1186
1212
|
// HTLC output. `buildRefundPsbt`'s value cross-check then binds the result
|
|
1187
1213
|
// to the funded tx bytes, refusing the refund if the template's HTLC value
|
|
1188
1214
|
// disagrees with the on-chain commitment.
|
|
1189
|
-
pegInAmounts:
|
|
1215
|
+
pegInAmounts: l.batch.map((g) => g.amount),
|
|
1190
1216
|
feeRate: i.feeRate,
|
|
1191
1217
|
minPeginFeeRate: i.minPeginFeeRate,
|
|
1192
1218
|
numLocalChallengers: i.numLocalChallengers,
|
|
@@ -1196,25 +1222,25 @@ async function Gt(e) {
|
|
|
1196
1222
|
authAnchorHash: T
|
|
1197
1223
|
},
|
|
1198
1224
|
fundedPrePeginTxHex: f,
|
|
1199
|
-
htlcVout:
|
|
1225
|
+
htlcVout: l.htlcVout,
|
|
1200
1226
|
refundFee: p,
|
|
1201
1227
|
// buildRefundPsbt's top-level `hashlock` param is documented as "no 0x
|
|
1202
1228
|
// prefix" and flows into the WASM HTLC connector derivation; a prefixed
|
|
1203
1229
|
// value would derive the wrong refund script leaf and yield an
|
|
1204
1230
|
// unspendable PSBT. Match the `hashlocks` array handling above.
|
|
1205
|
-
hashlock: d(
|
|
1231
|
+
hashlock: d(l.hashlock)
|
|
1206
1232
|
});
|
|
1207
|
-
|
|
1233
|
+
s == null || s.throwIfAborted();
|
|
1208
1234
|
const b = M(
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
),
|
|
1235
|
+
l.depositorBtcPubkey,
|
|
1236
|
+
gt
|
|
1237
|
+
), y = await u(m, b);
|
|
1212
1238
|
N({
|
|
1213
1239
|
requestedPsbtHex: m,
|
|
1214
|
-
returnedPsbtHex:
|
|
1240
|
+
returnedPsbtHex: y
|
|
1215
1241
|
});
|
|
1216
1242
|
const S = 0, _ = D(
|
|
1217
|
-
|
|
1243
|
+
y,
|
|
1218
1244
|
h,
|
|
1219
1245
|
S
|
|
1220
1246
|
);
|
|
@@ -1224,49 +1250,50 @@ async function Gt(e) {
|
|
|
1224
1250
|
signerXOnlyPubkeyHex: h,
|
|
1225
1251
|
inputIndex: S
|
|
1226
1252
|
});
|
|
1227
|
-
const B =
|
|
1228
|
-
|
|
1253
|
+
const B = Pt(y);
|
|
1254
|
+
s == null || s.throwIfAborted();
|
|
1229
1255
|
try {
|
|
1230
1256
|
return await o(B);
|
|
1231
1257
|
} catch (g) {
|
|
1232
|
-
throw g instanceof Error &&
|
|
1258
|
+
throw g instanceof Error && ft.test(g.message) ? new pt(t, g) : g;
|
|
1233
1259
|
}
|
|
1234
1260
|
}
|
|
1235
1261
|
export {
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1262
|
+
qt as A,
|
|
1263
|
+
pt as B,
|
|
1264
|
+
ce as C,
|
|
1265
|
+
jt as D,
|
|
1266
|
+
ee as E,
|
|
1267
|
+
Z as F,
|
|
1268
|
+
J as G,
|
|
1269
|
+
he as H,
|
|
1270
|
+
ue as P,
|
|
1271
|
+
le as R,
|
|
1272
|
+
Bt as a,
|
|
1246
1273
|
At as b,
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1274
|
+
Vt as c,
|
|
1275
|
+
Ht as d,
|
|
1276
|
+
Ft as e,
|
|
1277
|
+
Dt as f,
|
|
1278
|
+
Nt as g,
|
|
1252
1279
|
at as h,
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
q,
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1280
|
+
Ot as i,
|
|
1281
|
+
st as j,
|
|
1282
|
+
Mt as k,
|
|
1283
|
+
Ut as l,
|
|
1284
|
+
Lt as m,
|
|
1285
|
+
zt as n,
|
|
1286
|
+
Kt as o,
|
|
1287
|
+
K as p,
|
|
1288
|
+
et as q,
|
|
1289
|
+
Rt as r,
|
|
1290
|
+
ze as s,
|
|
1291
|
+
q as t,
|
|
1265
1292
|
rt as u,
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1293
|
+
It as v,
|
|
1294
|
+
ae as w,
|
|
1295
|
+
nt as x,
|
|
1296
|
+
Xt as y,
|
|
1270
1297
|
Gt as z
|
|
1271
1298
|
};
|
|
1272
|
-
//# sourceMappingURL=buildAndBroadcastRefund-
|
|
1299
|
+
//# sourceMappingURL=buildAndBroadcastRefund-C-rbYMy6.js.map
|