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