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