@babylonlabs-io/ts-sdk 0.55.2 → 0.56.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -2
- package/dist/{PayoutManager-BJmPnyRP.js → PayoutManager-BVgmuKuK.js} +117 -105
- package/dist/PayoutManager-BVgmuKuK.js.map +1 -0
- package/dist/PayoutManager-Cu4_l-_Y.cjs +2 -0
- package/dist/PayoutManager-Cu4_l-_Y.cjs.map +1 -0
- package/dist/{PeginManager-CW03-M3T.js → PeginManager-Ba7Cr51Z.js} +520 -460
- package/dist/PeginManager-Ba7Cr51Z.js.map +1 -0
- package/dist/PeginManager-CcjGRo4O.cjs +2 -0
- package/dist/PeginManager-CcjGRo4O.cjs.map +1 -0
- package/dist/{buildAndBroadcastRefund-BiSO4zg2.js → buildAndBroadcastRefund-BtXUqBkb.js} +444 -430
- package/dist/buildAndBroadcastRefund-BtXUqBkb.js.map +1 -0
- package/dist/buildAndBroadcastRefund-Cq01wyZX.cjs +2 -0
- package/dist/buildAndBroadcastRefund-Cq01wyZX.cjs.map +1 -0
- package/dist/challengeAssert-BVQq50su.js +75 -0
- package/dist/challengeAssert-BVQq50su.js.map +1 -0
- package/dist/challengeAssert-Cu-PtJ1g.cjs +2 -0
- package/dist/challengeAssert-Cu-PtJ1g.cjs.map +1 -0
- package/dist/constants-BqU1Uz15.cjs +2 -0
- package/dist/{constants-CvbARMl-.cjs.map → constants-BqU1Uz15.cjs.map} +1 -1
- package/dist/{constants-BhclpREj.js → constants-CDQE812z.js} +8 -6
- package/dist/{constants-BhclpREj.js.map → constants-CDQE812z.js.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +195 -192
- package/dist/{mempoolApi-DqJByvqR.cjs → mempoolApi-DkyKmmgI.cjs} +2 -2
- package/dist/mempoolApi-DkyKmmgI.cjs.map +1 -0
- package/dist/{mempoolApi-CB7bHuwi.js → mempoolApi-lpJdvPkK.js} +66 -66
- package/dist/mempoolApi-lpJdvPkK.js.map +1 -0
- package/dist/{noPayout-CNMqNNpc.cjs → noPayout-Cb8vFrkY.cjs} +2 -2
- package/dist/{noPayout-CNMqNNpc.cjs.map → noPayout-Cb8vFrkY.cjs.map} +1 -1
- package/dist/{noPayout-CfBg3HzC.js → noPayout-CihCk1HE.js} +2 -2
- package/dist/{noPayout-CfBg3HzC.js.map → noPayout-CihCk1HE.js.map} +1 -1
- package/dist/{primeVpAuth-l-5x_2UV.js → primeVpAuth-Caa5J_uv.js} +4 -4
- package/dist/{primeVpAuth-l-5x_2UV.js.map → primeVpAuth-Caa5J_uv.js.map} +1 -1
- package/dist/{primeVpAuth-CF4cH5_e.cjs → primeVpAuth-y-4A88ah.cjs} +2 -2
- package/dist/{primeVpAuth-CF4cH5_e.cjs.map → primeVpAuth-y-4A88ah.cjs.map} +1 -1
- package/dist/tbv/core/clients/index.cjs +1 -1
- package/dist/tbv/core/clients/index.js +2 -2
- package/dist/tbv/core/clients/mempool/mempoolApi.d.ts.map +1 -1
- package/dist/tbv/core/deposit-terms/__tests__/buildDepositTerms.test.d.ts +2 -0
- package/dist/tbv/core/deposit-terms/__tests__/buildDepositTerms.test.d.ts.map +1 -0
- package/dist/tbv/core/deposit-terms/buildDepositTerms.d.ts +8 -0
- package/dist/tbv/core/deposit-terms/buildDepositTerms.d.ts.map +1 -0
- package/dist/tbv/core/deposit-terms/depositTerms.d.ts +92 -0
- package/dist/tbv/core/deposit-terms/depositTerms.d.ts.map +1 -0
- package/dist/tbv/core/deposit-terms/index.d.ts +12 -0
- package/dist/tbv/core/deposit-terms/index.d.ts.map +1 -0
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.d.ts +1 -0
- package/dist/tbv/core/index.d.ts.map +1 -1
- package/dist/tbv/core/index.js +194 -191
- package/dist/tbv/core/managers/PayoutManager.d.ts +7 -0
- package/dist/tbv/core/managers/PayoutManager.d.ts.map +1 -1
- package/dist/tbv/core/managers/PeginManager.d.ts +13 -0
- package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -1
- 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 +0 -3
- package/dist/tbv/core/primitives/index.d.ts.map +1 -1
- package/dist/tbv/core/primitives/index.js +37 -38
- package/dist/tbv/core/primitives/psbt/__tests__/assertPayoutFeeBand.test.d.ts +7 -0
- package/dist/tbv/core/primitives/psbt/__tests__/assertPayoutFeeBand.test.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/assertPayoutFeeBand.d.ts +63 -0
- package/dist/tbv/core/primitives/psbt/assertPayoutFeeBand.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/assertWasmPeginSizing.d.ts +4 -1
- package/dist/tbv/core/primitives/psbt/assertWasmPeginSizing.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/constants.d.ts +18 -4
- package/dist/tbv/core/primitives/psbt/constants.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/payout.d.ts +21 -2
- package/dist/tbv/core/primitives/psbt/payout.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/pegin.d.ts +6 -0
- package/dist/tbv/core/primitives/psbt/pegin.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts +12 -0
- package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts +5 -0
- package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts.map +1 -1
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +2 -2
- package/dist/tbv/core/utils/__tests__/abortSignals.test.d.ts +11 -0
- package/dist/tbv/core/utils/__tests__/abortSignals.test.d.ts.map +1 -0
- package/dist/tbv/core/utils/abortSignals.d.ts +23 -0
- package/dist/tbv/core/utils/abortSignals.d.ts.map +1 -0
- package/dist/tbv/core/utils/index.cjs +1 -1
- package/dist/tbv/core/utils/index.d.ts +1 -0
- package/dist/tbv/core/utils/index.d.ts.map +1 -1
- package/dist/tbv/core/utils/index.js +44 -43
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +194 -191
- package/dist/tbv/integrations/aave/clients/index.d.ts +1 -1
- package/dist/tbv/integrations/aave/clients/index.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/clients/spoke.d.ts +0 -20
- package/dist/tbv/integrations/aave/clients/spoke.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/constants.d.ts +0 -22
- package/dist/tbv/integrations/aave/constants.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/index.cjs +1 -1
- package/dist/tbv/integrations/aave/index.cjs.map +1 -1
- package/dist/tbv/integrations/aave/index.d.ts +5 -6
- package/dist/tbv/integrations/aave/index.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/index.js +236 -339
- package/dist/tbv/integrations/aave/index.js.map +1 -1
- package/dist/tbv/integrations/aave/types.d.ts +0 -7
- package/dist/tbv/integrations/aave/types.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/utils/healthFactor.d.ts +0 -7
- package/dist/tbv/integrations/aave/utils/healthFactor.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/utils/index.d.ts +3 -8
- package/dist/tbv/integrations/aave/utils/index.d.ts.map +1 -1
- package/dist/tbv/integrations/aave/utils/vaultSplit.d.ts +0 -65
- package/dist/tbv/integrations/aave/utils/vaultSplit.d.ts.map +1 -1
- package/dist/validation-CDbOaDj7.cjs +2 -0
- package/dist/validation-CDbOaDj7.cjs.map +1 -0
- package/dist/validation-Dj3dqYtl.js +30 -0
- package/dist/validation-Dj3dqYtl.js.map +1 -0
- package/dist/verifyScriptPathSchnorrSignature-BZhX-SOd.cjs +2 -0
- package/dist/verifyScriptPathSchnorrSignature-BZhX-SOd.cjs.map +1 -0
- package/dist/verifyScriptPathSchnorrSignature-CgrnAjMW.js +724 -0
- package/dist/verifyScriptPathSchnorrSignature-CgrnAjMW.js.map +1 -0
- package/package.json +2 -2
- package/dist/PayoutManager-BJmPnyRP.js.map +0 -1
- package/dist/PayoutManager-aqtsj60t.cjs +0 -2
- package/dist/PayoutManager-aqtsj60t.cjs.map +0 -1
- package/dist/PeginManager-CW03-M3T.js.map +0 -1
- package/dist/PeginManager-C_akOB1E.cjs +0 -2
- package/dist/PeginManager-C_akOB1E.cjs.map +0 -1
- package/dist/buildAndBroadcastRefund-BiSO4zg2.js.map +0 -1
- package/dist/buildAndBroadcastRefund-Bwi1I5we.cjs +0 -2
- package/dist/buildAndBroadcastRefund-Bwi1I5we.cjs.map +0 -1
- package/dist/challengeAssert-DLQfNcfU.cjs +0 -2
- package/dist/challengeAssert-DLQfNcfU.cjs.map +0 -1
- package/dist/challengeAssert-DvdbpEDY.js +0 -128
- package/dist/challengeAssert-DvdbpEDY.js.map +0 -1
- package/dist/constants-CvbARMl-.cjs +0 -2
- package/dist/mempoolApi-CB7bHuwi.js.map +0 -1
- package/dist/mempoolApi-DqJByvqR.cjs.map +0 -1
- package/dist/tbv/core/primitives/psbt/depositorPayout.d.ts +0 -34
- package/dist/tbv/core/primitives/psbt/depositorPayout.d.ts.map +0 -1
- package/dist/tbv/integrations/aave/utils/__tests__/borrowRatio.test.d.ts +0 -5
- package/dist/tbv/integrations/aave/utils/__tests__/borrowRatio.test.d.ts.map +0 -1
- package/dist/tbv/integrations/aave/utils/__tests__/seizureSimulation.test.d.ts +0 -5
- package/dist/tbv/integrations/aave/utils/__tests__/seizureSimulation.test.d.ts.map +0 -1
- package/dist/tbv/integrations/aave/utils/__tests__/vaultSelection.test.d.ts +0 -2
- package/dist/tbv/integrations/aave/utils/__tests__/vaultSelection.test.d.ts.map +0 -1
- package/dist/tbv/integrations/aave/utils/borrowRatio.d.ts +0 -15
- package/dist/tbv/integrations/aave/utils/borrowRatio.d.ts.map +0 -1
- package/dist/tbv/integrations/aave/utils/seizureSimulation.d.ts +0 -109
- package/dist/tbv/integrations/aave/utils/seizureSimulation.d.ts.map +0 -1
- package/dist/tbv/integrations/aave/utils/vaultSelection.d.ts +0 -33
- package/dist/tbv/integrations/aave/utils/vaultSelection.d.ts.map +0 -1
- package/dist/validation-CxqROCno.js +0 -15
- package/dist/validation-CxqROCno.js.map +0 -1
- package/dist/validation-u8W7Lp2x.cjs +0 -2
- package/dist/validation-u8W7Lp2x.cjs.map +0 -1
- package/dist/verifyScriptPathSchnorrSignature-BDznSCOR.cjs +0 -2
- package/dist/verifyScriptPathSchnorrSignature-BDznSCOR.cjs.map +0 -1
- package/dist/verifyScriptPathSchnorrSignature-DA4Z4yZ3.js +0 -658
- package/dist/verifyScriptPathSchnorrSignature-DA4Z4yZ3.js.map +0 -1
|
@@ -1,58 +1,58 @@
|
|
|
1
1
|
var J = Object.defineProperty;
|
|
2
2
|
var Z = (e, t, r) => t in e ? J(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
-
var
|
|
3
|
+
var A = (e, t, r) => Z(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
4
|
import { B as ee } from "./BTCVaultRegistry.abi-Chs4AFBj.js";
|
|
5
|
-
import { e as te, v as re, s as
|
|
6
|
-
import { v as ne, s as
|
|
7
|
-
import { D as
|
|
8
|
-
import { Transaction as S, Psbt as
|
|
9
|
-
import { c as
|
|
10
|
-
import { c as de, a as
|
|
5
|
+
import { e as te, v as re, s as d, u as X, p as R, f as E } from "./bitcoin-B5aNKtsk.js";
|
|
6
|
+
import { v as oe, b as ne, s as se, P as ae, d as ie } from "./PayoutManager-BVgmuKuK.js";
|
|
7
|
+
import { D as x, c as ue, a as le, R as ce, d as z } from "./types-CQDRQvV-.js";
|
|
8
|
+
import { Transaction as S, Psbt as he } from "bitcoinjs-lib";
|
|
9
|
+
import { c as pe, d as I, e as N, f as H } from "./verifyScriptPathSchnorrSignature-CgrnAjMW.js";
|
|
10
|
+
import { c as de, a as ge, b as fe } from "./noPayout-CihCk1HE.js";
|
|
11
11
|
import { c as O } from "./signing-DaLvGwQe.js";
|
|
12
|
-
import { a as
|
|
13
|
-
const
|
|
14
|
-
function
|
|
12
|
+
import { a as me } from "./constants-CDQE812z.js";
|
|
13
|
+
const be = /^0x[0-9a-fA-F]{64}$/, Pe = /^0x[0-9a-fA-F]{40}$/, ye = /^0x([0-9a-fA-F]{2})*$/;
|
|
14
|
+
function $(e, t) {
|
|
15
15
|
if (e.length !== 66)
|
|
16
16
|
throw new Error(
|
|
17
17
|
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
18
18
|
);
|
|
19
|
-
if (!
|
|
19
|
+
if (!be.test(e))
|
|
20
20
|
throw new Error(
|
|
21
21
|
`${t} must contain only hex characters after the 0x prefix`
|
|
22
22
|
);
|
|
23
23
|
}
|
|
24
|
-
function
|
|
24
|
+
function we(e, t) {
|
|
25
25
|
if (!Pe.test(e))
|
|
26
26
|
throw new Error(
|
|
27
27
|
`${t} must be a 20-byte 0x-prefixed hex address (42 chars)`
|
|
28
28
|
);
|
|
29
29
|
}
|
|
30
|
-
function
|
|
31
|
-
if (!
|
|
30
|
+
function ve(e, t) {
|
|
31
|
+
if (!ye.test(e))
|
|
32
32
|
throw new Error(
|
|
33
33
|
`${t} must be a 0x-prefixed hex string with an even number of hex chars`
|
|
34
34
|
);
|
|
35
35
|
}
|
|
36
|
-
async function
|
|
36
|
+
async function lt(e) {
|
|
37
37
|
const {
|
|
38
38
|
btcVaultRegistryAddress: t,
|
|
39
39
|
vaultId: r,
|
|
40
|
-
hashlock:
|
|
41
|
-
activationMetadata:
|
|
40
|
+
hashlock: o,
|
|
41
|
+
activationMetadata: i,
|
|
42
42
|
writeContract: l,
|
|
43
|
-
signal:
|
|
43
|
+
signal: n
|
|
44
44
|
} = e;
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
45
|
+
n == null || n.throwIfAborted(), we(t, "btcVaultRegistryAddress"), $(r, "vaultId");
|
|
46
|
+
const s = te(e.secret);
|
|
47
|
+
if ($(s, "secret"), o !== void 0 && ($(o, "hashlock"), !oe(s, o)))
|
|
48
48
|
throw new Error(
|
|
49
49
|
"Invalid secret: SHA256(secret) does not match the provided hashlock"
|
|
50
50
|
);
|
|
51
|
-
return
|
|
51
|
+
return ve(i, "activationMetadata"), l({
|
|
52
52
|
address: t,
|
|
53
53
|
abi: ee,
|
|
54
54
|
functionName: "activateVaultWithSecret",
|
|
55
|
-
args: [r,
|
|
55
|
+
args: [r, s, i]
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
const xe = 1e4;
|
|
@@ -60,146 +60,146 @@ async function G(e) {
|
|
|
60
60
|
const {
|
|
61
61
|
statusReader: t,
|
|
62
62
|
peginTxid: r,
|
|
63
|
-
targetStatuses:
|
|
64
|
-
timeoutMs:
|
|
63
|
+
targetStatuses: o,
|
|
64
|
+
timeoutMs: i,
|
|
65
65
|
pollIntervalMs: l = xe,
|
|
66
|
-
signal:
|
|
67
|
-
} = e,
|
|
66
|
+
signal: n
|
|
67
|
+
} = e, s = Date.now();
|
|
68
68
|
for (; ; ) {
|
|
69
|
-
if (
|
|
69
|
+
if (n != null && n.aborted)
|
|
70
70
|
throw new Error(
|
|
71
|
-
`Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...
|
|
71
|
+
`Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...o].join(", ")})`
|
|
72
72
|
);
|
|
73
|
-
if (Date.now() -
|
|
73
|
+
if (Date.now() - s >= i)
|
|
74
74
|
throw new Error(
|
|
75
|
-
`Polling timeout after ${
|
|
75
|
+
`Polling timeout after ${i}ms for pegin ${r.slice(0, 8)}… (target: ${[...o].join(", ")})`
|
|
76
76
|
);
|
|
77
77
|
try {
|
|
78
|
-
const
|
|
78
|
+
const u = await t.getPeginStatus(
|
|
79
79
|
{ pegin_txid: r },
|
|
80
|
-
|
|
80
|
+
n
|
|
81
81
|
);
|
|
82
|
-
if (
|
|
82
|
+
if (u.pegin_txid.toLowerCase() !== r.toLowerCase())
|
|
83
83
|
throw new Error(
|
|
84
|
-
`getPeginStatus returned status for pegin ${
|
|
84
|
+
`getPeginStatus returned status for pegin ${u.pegin_txid.slice(0, 8)}…, requested ${r.slice(0, 8)}…`
|
|
85
85
|
);
|
|
86
|
-
const
|
|
87
|
-
if (
|
|
88
|
-
return
|
|
89
|
-
if (
|
|
86
|
+
const a = u.status;
|
|
87
|
+
if (o.has(a) || a === x.ACTIVATED)
|
|
88
|
+
return a;
|
|
89
|
+
if (a === x.EXPIRED || ue.has(a))
|
|
90
90
|
throw new Error(
|
|
91
|
-
`Pegin ${r.slice(0, 8)}… reached terminal status "${
|
|
91
|
+
`Pegin ${r.slice(0, 8)}… reached terminal status "${a}" while waiting for ${[...o].join(", ")}`
|
|
92
92
|
);
|
|
93
|
-
} catch (
|
|
94
|
-
if (!(
|
|
95
|
-
throw
|
|
93
|
+
} catch (u) {
|
|
94
|
+
if (!(u instanceof le && u.code === ce.PEGIN_NOT_FOUND))
|
|
95
|
+
throw u;
|
|
96
96
|
}
|
|
97
|
-
await new Promise((
|
|
97
|
+
await new Promise((u, a) => {
|
|
98
98
|
const h = () => {
|
|
99
|
-
clearTimeout(c),
|
|
99
|
+
clearTimeout(c), a(
|
|
100
100
|
new Error(
|
|
101
|
-
`Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...
|
|
101
|
+
`Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...o].join(", ")})`
|
|
102
102
|
)
|
|
103
103
|
);
|
|
104
104
|
}, c = setTimeout(() => {
|
|
105
|
-
|
|
105
|
+
n == null || n.removeEventListener("abort", h), u();
|
|
106
106
|
}, l);
|
|
107
|
-
|
|
107
|
+
n == null || n.addEventListener("abort", h, { once: !0 });
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
-
const
|
|
112
|
-
|
|
111
|
+
const Ee = 300 * 1e3, Te = /* @__PURE__ */ new Set([
|
|
112
|
+
x.PENDING_DEPOSITOR_WOTS_PK,
|
|
113
113
|
...z
|
|
114
114
|
]);
|
|
115
|
-
async function
|
|
115
|
+
async function ct(e) {
|
|
116
116
|
const {
|
|
117
117
|
statusReader: t,
|
|
118
118
|
wotsSubmitter: r,
|
|
119
|
-
peginTxid:
|
|
120
|
-
depositorPk:
|
|
119
|
+
peginTxid: o,
|
|
120
|
+
depositorPk: i,
|
|
121
121
|
wotsPublicKeys: l,
|
|
122
|
-
timeoutMs:
|
|
123
|
-
signal:
|
|
122
|
+
timeoutMs: n = Ee,
|
|
123
|
+
signal: s
|
|
124
124
|
} = e;
|
|
125
|
-
|
|
126
|
-
const
|
|
125
|
+
s == null || s.throwIfAborted();
|
|
126
|
+
const u = await G({
|
|
127
127
|
statusReader: t,
|
|
128
|
-
peginTxid:
|
|
129
|
-
targetStatuses:
|
|
130
|
-
timeoutMs:
|
|
131
|
-
signal:
|
|
128
|
+
peginTxid: o,
|
|
129
|
+
targetStatuses: Te,
|
|
130
|
+
timeoutMs: n,
|
|
131
|
+
signal: s
|
|
132
132
|
});
|
|
133
|
-
z.has(
|
|
133
|
+
z.has(u) || (s == null || s.throwIfAborted(), await r.submitDepositorWotsKey(
|
|
134
134
|
{
|
|
135
|
-
pegin_txid:
|
|
136
|
-
depositor_pk:
|
|
135
|
+
pegin_txid: o,
|
|
136
|
+
depositor_pk: i,
|
|
137
137
|
wots_public_keys: l
|
|
138
138
|
},
|
|
139
|
-
|
|
139
|
+
s
|
|
140
140
|
));
|
|
141
141
|
}
|
|
142
|
-
const
|
|
143
|
-
function
|
|
144
|
-
const r =
|
|
145
|
-
if (
|
|
142
|
+
const F = 1, ke = 1;
|
|
143
|
+
function _e(e, t) {
|
|
144
|
+
const r = d(t).toLowerCase(), i = e.map((l) => d(l).toLowerCase()).filter((l) => l !== r);
|
|
145
|
+
if (i.length === 0)
|
|
146
146
|
throw new Error(
|
|
147
147
|
"Cannot derive localChallengers: vault keeper set is empty (or contains only the depositor)"
|
|
148
148
|
);
|
|
149
|
-
if (new Set(
|
|
149
|
+
if (new Set(i).size !== i.length)
|
|
150
150
|
throw new Error(
|
|
151
151
|
"Cannot derive localChallengers: duplicate vaultKeeper key — signing context is misconfigured"
|
|
152
152
|
);
|
|
153
|
-
return
|
|
153
|
+
return i;
|
|
154
154
|
}
|
|
155
|
-
function
|
|
156
|
-
const
|
|
157
|
-
(c) =>
|
|
158
|
-
),
|
|
159
|
-
if (
|
|
155
|
+
function Ce(e, t, r) {
|
|
156
|
+
const o = r.map(
|
|
157
|
+
(c) => d(c).toLowerCase()
|
|
158
|
+
), i = t.filter((c) => o.includes(c));
|
|
159
|
+
if (i.length > 0)
|
|
160
160
|
throw new Error(
|
|
161
|
-
`Cannot validate challenger set: vault keepers and universal challengers overlap (${
|
|
161
|
+
`Cannot validate challenger set: vault keepers and universal challengers overlap (${i.join(", ")})`
|
|
162
162
|
);
|
|
163
|
-
const l = [...t, ...
|
|
164
|
-
(c) =>
|
|
165
|
-
),
|
|
166
|
-
if (
|
|
163
|
+
const l = [...t, ...o], n = e.map(
|
|
164
|
+
(c) => d(c.challenger_pubkey).toLowerCase()
|
|
165
|
+
), s = new Set(n);
|
|
166
|
+
if (s.size !== n.length)
|
|
167
167
|
throw new Error(
|
|
168
168
|
"Depositor graph contains duplicate challenger entries in challenger_presign_data"
|
|
169
169
|
);
|
|
170
|
-
const
|
|
171
|
-
if (
|
|
170
|
+
const u = new Set(l), a = l.filter((c) => !s.has(c)), h = n.filter((c) => !u.has(c));
|
|
171
|
+
if (a.length > 0 || h.length > 0)
|
|
172
172
|
throw new Error(
|
|
173
|
-
"Depositor graph challenger set does not match expected (local ∪ universal)" + (
|
|
173
|
+
"Depositor graph challenger set does not match expected (local ∪ universal)" + (a.length > 0 ? ` (missing: ${a.join(", ")})` : "") + (h.length > 0 ? ` (unexpected: ${h.join(", ")})` : "")
|
|
174
174
|
);
|
|
175
175
|
}
|
|
176
|
-
function
|
|
176
|
+
function Se(e, t) {
|
|
177
177
|
const r = e.ins[t];
|
|
178
178
|
return X(new Uint8Array(r.hash).slice().reverse());
|
|
179
179
|
}
|
|
180
|
-
function
|
|
180
|
+
function V(e, t, r, o, i) {
|
|
181
181
|
const l = e.ins[t];
|
|
182
182
|
if (l.index !== 0)
|
|
183
183
|
throw new Error(
|
|
184
|
-
`NoPayout (challenger ${
|
|
184
|
+
`NoPayout (challenger ${i}) input ${t} expected to spend ${o} vout 0, got vout ${l.index}`
|
|
185
185
|
);
|
|
186
|
-
const
|
|
187
|
-
if (
|
|
186
|
+
const n = r.getId(), s = Se(e, t);
|
|
187
|
+
if (s !== n)
|
|
188
188
|
throw new Error(
|
|
189
|
-
`NoPayout (challenger ${
|
|
189
|
+
`NoPayout (challenger ${i}) input ${t} does not reference ${o} (expected txid ${n}, got ${s})`
|
|
190
190
|
);
|
|
191
191
|
}
|
|
192
|
-
async function
|
|
193
|
-
const
|
|
192
|
+
async function Re(e, t, r) {
|
|
193
|
+
const o = [], i = [], l = [], n = _e(
|
|
194
194
|
r.vaultKeeperBtcPubkeys,
|
|
195
195
|
r.depositorBtcPubkey
|
|
196
196
|
);
|
|
197
|
-
|
|
197
|
+
Ce(
|
|
198
198
|
e.challenger_presign_data,
|
|
199
|
-
|
|
199
|
+
n,
|
|
200
200
|
r.universalChallengerBtcPubkeys
|
|
201
201
|
);
|
|
202
|
-
const
|
|
202
|
+
const s = await pe({
|
|
203
203
|
vaultCoreVersion: r.vaultCoreVersion,
|
|
204
204
|
payoutTxHex: e.payout_tx.tx_hex,
|
|
205
205
|
peginTxHex: r.peginTxHex,
|
|
@@ -212,208 +212,208 @@ async function Se(e, t, r) {
|
|
|
212
212
|
network: r.network,
|
|
213
213
|
claimerBtcPubkey: r.depositorBtcPubkey,
|
|
214
214
|
registeredPayoutScriptPubKey: r.registeredPayoutScriptPubKey,
|
|
215
|
-
commissionBps:
|
|
215
|
+
commissionBps: ke,
|
|
216
|
+
protocolFeeRate: r.protocolFeeRate,
|
|
217
|
+
councilSize: r.councilMembers.length
|
|
216
218
|
});
|
|
217
|
-
|
|
219
|
+
o.push(s.psbtHex), i.push(
|
|
218
220
|
O(
|
|
219
221
|
t,
|
|
220
|
-
|
|
222
|
+
F
|
|
221
223
|
)
|
|
222
224
|
);
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
+
const u = d(r.depositorBtcPubkey), a = S.fromHex(
|
|
226
|
+
d(e.assert_tx.tx_hex)
|
|
225
227
|
);
|
|
226
228
|
for (const h of e.challenger_presign_data) {
|
|
227
|
-
const c =
|
|
229
|
+
const c = d(h.challenger_pubkey), p = o.length, b = await Ae({
|
|
228
230
|
challenger: h,
|
|
229
231
|
challengerPubkey: c,
|
|
230
|
-
claimerPubkey:
|
|
231
|
-
localChallengers:
|
|
232
|
-
assertTxParsed:
|
|
232
|
+
claimerPubkey: u,
|
|
233
|
+
localChallengers: n,
|
|
234
|
+
assertTxParsed: a,
|
|
233
235
|
ctx: r
|
|
234
236
|
});
|
|
235
|
-
|
|
237
|
+
o.push(b), i.push(
|
|
236
238
|
O(
|
|
237
239
|
t,
|
|
238
|
-
|
|
240
|
+
F
|
|
239
241
|
)
|
|
240
242
|
), l.push({
|
|
241
243
|
challengerPubkey: c,
|
|
242
|
-
noPayoutIdx:
|
|
244
|
+
noPayoutIdx: p
|
|
243
245
|
});
|
|
244
246
|
}
|
|
245
|
-
return { psbtHexes:
|
|
247
|
+
return { psbtHexes: o, signOptions: i, challengerEntries: l };
|
|
246
248
|
}
|
|
247
249
|
async function Ae(e) {
|
|
248
250
|
const {
|
|
249
251
|
challenger: t,
|
|
250
252
|
challengerPubkey: r,
|
|
251
|
-
claimerPubkey:
|
|
252
|
-
localChallengers:
|
|
253
|
+
claimerPubkey: o,
|
|
254
|
+
localChallengers: i,
|
|
253
255
|
assertTxParsed: l,
|
|
254
|
-
ctx:
|
|
256
|
+
ctx: n
|
|
255
257
|
} = e;
|
|
256
258
|
de(
|
|
257
259
|
t.nopayout_tx.tx_hex,
|
|
258
260
|
r,
|
|
259
|
-
|
|
261
|
+
n.network
|
|
260
262
|
);
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
), o = S.fromHex(
|
|
264
|
-
p(t.challenge_assert_x_tx.tx_hex)
|
|
263
|
+
const s = S.fromHex(
|
|
264
|
+
d(t.nopayout_tx.tx_hex)
|
|
265
265
|
), u = S.fromHex(
|
|
266
|
-
|
|
266
|
+
d(t.challenge_assert_x_tx.tx_hex)
|
|
267
|
+
), a = S.fromHex(
|
|
268
|
+
d(t.challenge_assert_y_tx.tx_hex)
|
|
267
269
|
);
|
|
268
|
-
if (
|
|
270
|
+
if (s.ins.length !== 3)
|
|
269
271
|
throw new Error(
|
|
270
|
-
`NoPayout (challenger ${r}) must have exactly 3 inputs, got ${
|
|
272
|
+
`NoPayout (challenger ${r}) must have exactly 3 inputs, got ${s.ins.length}`
|
|
271
273
|
);
|
|
272
|
-
|
|
273
|
-
|
|
274
|
+
V(
|
|
275
|
+
s,
|
|
274
276
|
0,
|
|
275
277
|
l,
|
|
276
278
|
"Assert",
|
|
277
279
|
r
|
|
278
|
-
),
|
|
279
|
-
|
|
280
|
+
), V(
|
|
281
|
+
s,
|
|
280
282
|
1,
|
|
281
|
-
|
|
283
|
+
u,
|
|
282
284
|
"ChallengeAssertX",
|
|
283
285
|
r
|
|
284
|
-
),
|
|
285
|
-
|
|
286
|
+
), V(
|
|
287
|
+
s,
|
|
286
288
|
2,
|
|
287
|
-
|
|
289
|
+
a,
|
|
288
290
|
"ChallengeAssertY",
|
|
289
291
|
r
|
|
290
292
|
);
|
|
291
293
|
const h = [
|
|
292
294
|
l.outs[0],
|
|
293
|
-
|
|
294
|
-
|
|
295
|
+
u.outs[0],
|
|
296
|
+
a.outs[0]
|
|
295
297
|
].map((c) => ({
|
|
296
298
|
script_pubkey: X(new Uint8Array(c.script)),
|
|
297
299
|
value: c.value
|
|
298
300
|
}));
|
|
299
|
-
return
|
|
301
|
+
return ge({
|
|
300
302
|
noPayoutTxHex: t.nopayout_tx.tx_hex,
|
|
301
303
|
challengerPubkey: r,
|
|
302
304
|
prevouts: h,
|
|
303
305
|
connectorParams: {
|
|
304
|
-
txGraphVersion:
|
|
305
|
-
claimer:
|
|
306
|
-
localChallengers:
|
|
307
|
-
universalChallengers:
|
|
308
|
-
timelockAssert:
|
|
309
|
-
councilMembers:
|
|
310
|
-
councilQuorum:
|
|
306
|
+
txGraphVersion: n.vaultCoreVersion,
|
|
307
|
+
claimer: o,
|
|
308
|
+
localChallengers: i,
|
|
309
|
+
universalChallengers: n.universalChallengerBtcPubkeys,
|
|
310
|
+
timelockAssert: n.timelockAssert,
|
|
311
|
+
councilMembers: n.councilMembers,
|
|
312
|
+
councilQuorum: n.councilQuorum
|
|
311
313
|
}
|
|
312
314
|
});
|
|
313
315
|
}
|
|
314
316
|
function $e(e, t, r) {
|
|
315
317
|
I(e[0]);
|
|
316
|
-
const
|
|
318
|
+
const i = N(
|
|
317
319
|
e[0].returnedPsbtHex,
|
|
318
320
|
r
|
|
319
321
|
);
|
|
320
322
|
H({
|
|
321
323
|
requestedPsbtHex: e[0].requestedPsbtHex,
|
|
322
|
-
signatureHex:
|
|
324
|
+
signatureHex: i,
|
|
323
325
|
signerXOnlyPubkeyHex: r,
|
|
324
326
|
inputIndex: 0
|
|
325
327
|
});
|
|
326
328
|
const l = {};
|
|
327
|
-
for (const
|
|
328
|
-
I(e[
|
|
329
|
-
const
|
|
330
|
-
e[
|
|
329
|
+
for (const n of t) {
|
|
330
|
+
I(e[n.noPayoutIdx]);
|
|
331
|
+
const s = N(
|
|
332
|
+
e[n.noPayoutIdx].returnedPsbtHex,
|
|
331
333
|
r
|
|
332
334
|
);
|
|
333
335
|
H({
|
|
334
|
-
requestedPsbtHex: e[
|
|
335
|
-
signatureHex:
|
|
336
|
+
requestedPsbtHex: e[n.noPayoutIdx].requestedPsbtHex,
|
|
337
|
+
signatureHex: s,
|
|
336
338
|
signerXOnlyPubkeyHex: r,
|
|
337
339
|
inputIndex: 0
|
|
338
|
-
}), l[
|
|
339
|
-
nopayout_signature:
|
|
340
|
+
}), l[n.challengerPubkey] = {
|
|
341
|
+
nopayout_signature: s
|
|
340
342
|
};
|
|
341
343
|
}
|
|
342
344
|
return {
|
|
343
345
|
payout_signatures: {
|
|
344
|
-
payout_signature:
|
|
346
|
+
payout_signature: i
|
|
345
347
|
},
|
|
346
348
|
per_challenger: l
|
|
347
349
|
};
|
|
348
350
|
}
|
|
349
351
|
async function Ve(e) {
|
|
350
|
-
const { depositorGraph: t, btcWallet: r, signingContext:
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
), { psbtHexes:
|
|
352
|
+
const { depositorGraph: t, btcWallet: r, signingContext: o } = e, i = await r.getPublicKeyHex(), { depositorPubkey: l } = re(
|
|
353
|
+
i,
|
|
354
|
+
d(o.depositorBtcPubkey)
|
|
355
|
+
), { psbtHexes: n, signOptions: s, challengerEntries: u } = await Re(
|
|
354
356
|
t,
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
),
|
|
357
|
+
i,
|
|
358
|
+
o
|
|
359
|
+
), a = await ne(
|
|
358
360
|
r,
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
), h =
|
|
361
|
+
n,
|
|
362
|
+
s
|
|
363
|
+
), h = n.map((c, p) => ({
|
|
362
364
|
requestedPsbtHex: c,
|
|
363
|
-
returnedPsbtHex:
|
|
365
|
+
returnedPsbtHex: a[p]
|
|
364
366
|
}));
|
|
365
367
|
return $e(
|
|
366
368
|
h,
|
|
367
|
-
|
|
369
|
+
u,
|
|
368
370
|
l
|
|
369
371
|
);
|
|
370
372
|
}
|
|
371
|
-
const
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
]),
|
|
377
|
-
|
|
373
|
+
const Be = 1200 * 1e3, q = /* @__PURE__ */ new Set([
|
|
374
|
+
x.PENDING_ACKS,
|
|
375
|
+
x.PENDING_ACTIVATION,
|
|
376
|
+
x.ACTIVATED_PENDING_BROADCAST,
|
|
377
|
+
x.ACTIVATED
|
|
378
|
+
]), Ie = /* @__PURE__ */ new Set([
|
|
379
|
+
x.PENDING_DEPOSITOR_SIGNATURES,
|
|
378
380
|
...q
|
|
379
381
|
]);
|
|
380
|
-
function
|
|
382
|
+
function Ne(e) {
|
|
381
383
|
return e.map((t) => ({
|
|
382
|
-
claimerPubkeyXOnly:
|
|
384
|
+
claimerPubkeyXOnly: R(t.claimer_pubkey),
|
|
383
385
|
payoutTxHex: t.payout_tx.tx_hex,
|
|
384
386
|
assertTxHex: t.assert_tx.tx_hex
|
|
385
387
|
}));
|
|
386
388
|
}
|
|
387
389
|
function _(e) {
|
|
388
|
-
return
|
|
390
|
+
return R(e).toLowerCase();
|
|
389
391
|
}
|
|
390
|
-
function
|
|
391
|
-
const
|
|
392
|
+
function He(e, t, r, o) {
|
|
393
|
+
const i = _(o), l = [
|
|
392
394
|
_(t),
|
|
393
395
|
...r.map(_)
|
|
394
|
-
],
|
|
395
|
-
if (
|
|
396
|
+
], n = new Set(l);
|
|
397
|
+
if (n.size !== l.length)
|
|
396
398
|
throw new Error(
|
|
397
399
|
"Cannot validate claimer set: signing context contains duplicate vault provider or vault keeper key"
|
|
398
400
|
);
|
|
399
|
-
if (
|
|
401
|
+
if (n.has(i))
|
|
400
402
|
throw new Error(
|
|
401
403
|
"Cannot validate claimer set: depositor key overlaps with vault provider or vault keeper set"
|
|
402
404
|
);
|
|
403
|
-
const
|
|
404
|
-
(
|
|
405
|
+
const s = e.map(
|
|
406
|
+
(p) => _(p.claimer_pubkey)
|
|
405
407
|
);
|
|
406
|
-
if (new Set(
|
|
407
|
-
throw new Error(
|
|
408
|
-
|
|
409
|
-
);
|
|
410
|
-
const o = i.filter((d) => d !== s), u = new Set(o), h = l.filter((d) => !u.has(d)), c = o.filter((d) => !a.has(d));
|
|
408
|
+
if (new Set(s).size !== s.length)
|
|
409
|
+
throw new Error("Presign response contains duplicate claimer entries");
|
|
410
|
+
const u = s.filter((p) => p !== i), a = new Set(u), h = l.filter((p) => !a.has(p)), c = u.filter((p) => !n.has(p));
|
|
411
411
|
if (h.length > 0 || c.length > 0)
|
|
412
412
|
throw new Error(
|
|
413
413
|
"Presign response claimer set does not match expected (vault provider ∪ vault keepers)" + (h.length > 0 ? ` (missing: ${h.join(", ")})` : "") + (c.length > 0 ? ` (unexpected: ${c.join(", ")})` : "")
|
|
414
414
|
);
|
|
415
415
|
}
|
|
416
|
-
function
|
|
416
|
+
function K(e, t) {
|
|
417
417
|
return {
|
|
418
418
|
vaultCoreVersion: t.vaultCoreVersion,
|
|
419
419
|
payoutTxHex: e.payoutTxHex,
|
|
@@ -426,125 +426,139 @@ function U(e, t) {
|
|
|
426
426
|
timelockPegin: t.timelockPegin,
|
|
427
427
|
registeredPayoutScriptPubKey: t.registeredPayoutScriptPubKey,
|
|
428
428
|
claimerBtcPubkey: e.claimerPubkeyXOnly,
|
|
429
|
-
commissionBps: t.commissionBps
|
|
429
|
+
commissionBps: t.commissionBps,
|
|
430
|
+
protocolFeeRate: t.protocolFeeRate,
|
|
431
|
+
councilSize: t.councilMembers.length
|
|
430
432
|
};
|
|
431
433
|
}
|
|
432
|
-
async function
|
|
433
|
-
const
|
|
434
|
+
async function Oe(e, t, r, o) {
|
|
435
|
+
const i = new ae({
|
|
434
436
|
network: t.network,
|
|
435
437
|
btcWallet: e
|
|
436
438
|
}), l = r.length;
|
|
437
|
-
|
|
438
|
-
let
|
|
439
|
-
if (
|
|
440
|
-
|
|
441
|
-
r.map((
|
|
442
|
-
)).map((
|
|
439
|
+
o == null || o(0, l);
|
|
440
|
+
let n;
|
|
441
|
+
if (i.supportsBatchSigning())
|
|
442
|
+
n = (await i.signPayoutTransactionsBatch(
|
|
443
|
+
r.map((a) => K(a, t))
|
|
444
|
+
)).map((a) => a.payoutSignature);
|
|
443
445
|
else {
|
|
444
|
-
|
|
445
|
-
for (let
|
|
446
|
-
|
|
447
|
-
const
|
|
448
|
-
|
|
446
|
+
n = [];
|
|
447
|
+
for (let u = 0; u < r.length; u++) {
|
|
448
|
+
o == null || o(u, l);
|
|
449
|
+
const a = await i.signPayoutTransaction(
|
|
450
|
+
K(r[u], t)
|
|
449
451
|
);
|
|
450
|
-
|
|
452
|
+
n.push(a.signature);
|
|
451
453
|
}
|
|
452
454
|
}
|
|
453
|
-
const
|
|
454
|
-
for (let
|
|
455
|
-
|
|
456
|
-
payout_signature:
|
|
455
|
+
const s = {};
|
|
456
|
+
for (let u = 0; u < r.length; u++)
|
|
457
|
+
s[r[u].claimerPubkeyXOnly] = {
|
|
458
|
+
payout_signature: n[u]
|
|
457
459
|
};
|
|
458
|
-
return
|
|
460
|
+
return o == null || o(l, l), s;
|
|
459
461
|
}
|
|
460
|
-
async function
|
|
462
|
+
async function ht(e) {
|
|
461
463
|
const {
|
|
462
464
|
statusReader: t,
|
|
463
465
|
presignClient: r,
|
|
464
|
-
btcWallet:
|
|
465
|
-
peginTxid:
|
|
466
|
+
btcWallet: o,
|
|
467
|
+
peginTxid: i,
|
|
466
468
|
depositorPk: l,
|
|
467
|
-
signingContext:
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
469
|
+
signingContext: n,
|
|
470
|
+
depositTerms: s,
|
|
471
|
+
timeoutMs: u = Be,
|
|
472
|
+
signal: a,
|
|
473
|
+
onProgress: h
|
|
474
|
+
} = e, c = await G({
|
|
472
475
|
statusReader: t,
|
|
473
|
-
peginTxid:
|
|
474
|
-
targetStatuses:
|
|
475
|
-
timeoutMs:
|
|
476
|
-
signal:
|
|
476
|
+
peginTxid: i,
|
|
477
|
+
targetStatuses: Ie,
|
|
478
|
+
timeoutMs: u,
|
|
479
|
+
signal: a
|
|
477
480
|
});
|
|
478
|
-
if (q.has(
|
|
481
|
+
if (q.has(c))
|
|
479
482
|
return;
|
|
480
|
-
|
|
481
|
-
|
|
483
|
+
if (a == null || a.throwIfAborted(), s !== void 0 && s.baseFeeRate !== n.protocolFeeRate)
|
|
484
|
+
throw new Error(
|
|
485
|
+
`Deposit terms baseFeeRate (${s.baseFeeRate} sat/vB) does not match the vault's version-locked protocolFeeRate (${n.protocolFeeRate} sat/vB); refusing to sign payouts against terms built from a different params version.`
|
|
486
|
+
);
|
|
487
|
+
if (se(o)) {
|
|
488
|
+
if (!s)
|
|
489
|
+
throw new Error(
|
|
490
|
+
"runDepositorPresignFlow: this wallet requires approved deposit terms but none were provided. Fresh deposits must pass PreparePeginResult.depositTerms; resume-path rebuild is not wired yet."
|
|
491
|
+
);
|
|
492
|
+
await o.approveDepositTerms(s);
|
|
493
|
+
}
|
|
494
|
+
const p = await r.requestDepositorPresignTransactions(
|
|
482
495
|
{
|
|
483
|
-
pegin_txid:
|
|
496
|
+
pegin_txid: i,
|
|
484
497
|
depositor_pk: l
|
|
485
498
|
},
|
|
486
|
-
|
|
499
|
+
a
|
|
487
500
|
);
|
|
488
|
-
|
|
489
|
-
const
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
501
|
+
a == null || a.throwIfAborted();
|
|
502
|
+
const b = _(l);
|
|
503
|
+
He(
|
|
504
|
+
p.txs,
|
|
505
|
+
n.vaultProviderBtcPubkey,
|
|
506
|
+
n.vaultKeeperBtcPubkeys,
|
|
494
507
|
l
|
|
495
508
|
);
|
|
496
|
-
const
|
|
497
|
-
(v) => _(v.claimer_pubkey) !==
|
|
498
|
-
),
|
|
509
|
+
const m = p.txs.filter(
|
|
510
|
+
(v) => _(v.claimer_pubkey) !== b
|
|
511
|
+
), y = Ne(m), T = await Oe(
|
|
512
|
+
o,
|
|
499
513
|
n,
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
u
|
|
514
|
+
y,
|
|
515
|
+
h
|
|
503
516
|
);
|
|
504
|
-
|
|
505
|
-
const
|
|
506
|
-
depositorGraph:
|
|
507
|
-
btcWallet:
|
|
517
|
+
a == null || a.throwIfAborted();
|
|
518
|
+
const P = await Ve({
|
|
519
|
+
depositorGraph: p.depositor_graph,
|
|
520
|
+
btcWallet: o,
|
|
508
521
|
signingContext: {
|
|
509
|
-
vaultCoreVersion:
|
|
510
|
-
peginTxHex:
|
|
522
|
+
vaultCoreVersion: n.vaultCoreVersion,
|
|
523
|
+
peginTxHex: n.peginTxHex,
|
|
511
524
|
depositorBtcPubkey: l,
|
|
512
|
-
vaultProviderBtcPubkey:
|
|
513
|
-
vaultKeeperBtcPubkeys:
|
|
514
|
-
universalChallengerBtcPubkeys:
|
|
515
|
-
timelockPegin:
|
|
516
|
-
timelockAssert:
|
|
517
|
-
councilMembers:
|
|
518
|
-
councilQuorum:
|
|
519
|
-
network:
|
|
520
|
-
registeredPayoutScriptPubKey:
|
|
525
|
+
vaultProviderBtcPubkey: n.vaultProviderBtcPubkey,
|
|
526
|
+
vaultKeeperBtcPubkeys: n.vaultKeeperBtcPubkeys,
|
|
527
|
+
universalChallengerBtcPubkeys: n.universalChallengerBtcPubkeys,
|
|
528
|
+
timelockPegin: n.timelockPegin,
|
|
529
|
+
timelockAssert: n.timelockAssert,
|
|
530
|
+
councilMembers: n.councilMembers,
|
|
531
|
+
councilQuorum: n.councilQuorum,
|
|
532
|
+
network: n.network,
|
|
533
|
+
registeredPayoutScriptPubKey: n.registeredPayoutScriptPubKey,
|
|
534
|
+
protocolFeeRate: n.protocolFeeRate
|
|
521
535
|
}
|
|
522
536
|
});
|
|
523
|
-
|
|
524
|
-
const
|
|
525
|
-
|
|
537
|
+
a == null || a.throwIfAborted();
|
|
538
|
+
const w = { ...T };
|
|
539
|
+
w[d(l)] = P.payout_signatures, await r.submitDepositorPresignatures(
|
|
526
540
|
{
|
|
527
|
-
pegin_txid:
|
|
541
|
+
pegin_txid: i,
|
|
528
542
|
depositor_pk: l,
|
|
529
|
-
signatures:
|
|
530
|
-
depositor_claimer_presignatures:
|
|
543
|
+
signatures: w,
|
|
544
|
+
depositor_claimer_presignatures: P
|
|
531
545
|
},
|
|
532
|
-
|
|
546
|
+
a
|
|
533
547
|
);
|
|
534
548
|
}
|
|
535
|
-
function
|
|
549
|
+
function De(e) {
|
|
536
550
|
return /^[0-9a-fA-F]{64}$/.test(e);
|
|
537
551
|
}
|
|
538
|
-
function
|
|
552
|
+
function pt(e) {
|
|
539
553
|
const {
|
|
540
554
|
amountSats: t,
|
|
541
555
|
minDeposit: r,
|
|
542
|
-
maxDeposit:
|
|
543
|
-
btcBalance:
|
|
556
|
+
maxDeposit: o,
|
|
557
|
+
btcBalance: i,
|
|
544
558
|
estimatedFeeSats: l,
|
|
545
|
-
depositorClaimValue:
|
|
559
|
+
depositorClaimValue: n
|
|
546
560
|
} = e;
|
|
547
|
-
return !(t <= 0n || t < r ||
|
|
561
|
+
return !(t <= 0n || t < r || o && o > 0n && t > o || l == null || n == null || t + l + n > i);
|
|
548
562
|
}
|
|
549
563
|
function dt(e, t, r) {
|
|
550
564
|
return e <= 0n ? {
|
|
@@ -558,7 +572,7 @@ function dt(e, t, r) {
|
|
|
558
572
|
error: `Maximum deposit is ${E(r)} BTC`
|
|
559
573
|
} : { valid: !0 };
|
|
560
574
|
}
|
|
561
|
-
function
|
|
575
|
+
function gt(e) {
|
|
562
576
|
const { amount: t, effectiveRemaining: r } = e;
|
|
563
577
|
return r === null ? { valid: !0 } : r === 0n ? {
|
|
564
578
|
valid: !1,
|
|
@@ -568,51 +582,51 @@ function pt(e) {
|
|
|
568
582
|
error: `Vault size exceeds remaining capacity (${E(r)} BTC)`
|
|
569
583
|
} : { valid: !0 };
|
|
570
584
|
}
|
|
571
|
-
function
|
|
585
|
+
function ft(e, t) {
|
|
572
586
|
if (!e || e.length === 0)
|
|
573
587
|
return {
|
|
574
588
|
valid: !1,
|
|
575
589
|
error: "At least one vault provider must be selected"
|
|
576
590
|
};
|
|
577
591
|
const r = t.map(
|
|
578
|
-
(
|
|
592
|
+
(i) => i.toLowerCase()
|
|
579
593
|
);
|
|
580
594
|
return e.filter(
|
|
581
|
-
(
|
|
595
|
+
(i) => !r.includes(i.toLowerCase())
|
|
582
596
|
).length > 0 ? {
|
|
583
597
|
valid: !1,
|
|
584
598
|
error: "Invalid vault provider selected"
|
|
585
599
|
} : { valid: !0 };
|
|
586
600
|
}
|
|
587
|
-
function
|
|
601
|
+
function Fe(e, t, r) {
|
|
588
602
|
if (!e || e.length === 0)
|
|
589
603
|
return {
|
|
590
604
|
valid: !1,
|
|
591
605
|
error: "At least one vault amount required"
|
|
592
606
|
};
|
|
593
|
-
for (let
|
|
594
|
-
const
|
|
595
|
-
if (
|
|
607
|
+
for (let o = 0; o < e.length; o++) {
|
|
608
|
+
const i = e[o];
|
|
609
|
+
if (i <= 0n)
|
|
596
610
|
return {
|
|
597
611
|
valid: !1,
|
|
598
|
-
error: `Vault ${
|
|
612
|
+
error: `Vault ${o + 1} amount must be positive`
|
|
599
613
|
};
|
|
600
|
-
if (t &&
|
|
614
|
+
if (t && i < t)
|
|
601
615
|
return {
|
|
602
616
|
valid: !1,
|
|
603
|
-
error: `Vault ${
|
|
617
|
+
error: `Vault ${o + 1} amount ${E(i)} BTC is below minimum deposit ${E(t)} BTC`
|
|
604
618
|
};
|
|
605
|
-
if (r &&
|
|
619
|
+
if (r && i > r)
|
|
606
620
|
return {
|
|
607
621
|
valid: !1,
|
|
608
|
-
error: `Vault ${
|
|
622
|
+
error: `Vault ${o + 1} amount ${E(i)} BTC exceeds maximum deposit ${E(r)} BTC`
|
|
609
623
|
};
|
|
610
624
|
}
|
|
611
625
|
return { valid: !0 };
|
|
612
626
|
}
|
|
613
627
|
function Ke(e) {
|
|
614
|
-
const t =
|
|
615
|
-
return
|
|
628
|
+
const t = d(e);
|
|
629
|
+
return De(t) ? { valid: !0 } : {
|
|
616
630
|
valid: !1,
|
|
617
631
|
error: "Invalid pubkey format: must be 64 hex characters (32-byte x-only public key, no 0x prefix)"
|
|
618
632
|
};
|
|
@@ -623,85 +637,85 @@ function Ue(e) {
|
|
|
623
637
|
"No vault keepers available. The system requires at least one vault keeper to create a deposit."
|
|
624
638
|
);
|
|
625
639
|
}
|
|
626
|
-
function
|
|
640
|
+
function Me(e) {
|
|
627
641
|
if (!e || e.length === 0)
|
|
628
642
|
throw new Error(
|
|
629
643
|
"No universal challengers available. The system requires at least one universal challenger to create a deposit."
|
|
630
644
|
);
|
|
631
645
|
}
|
|
632
|
-
function
|
|
646
|
+
function Le(e) {
|
|
633
647
|
if (e.length === 0)
|
|
634
648
|
throw new Error("No spendable UTXOs available");
|
|
635
649
|
}
|
|
636
|
-
function
|
|
650
|
+
function mt(e) {
|
|
637
651
|
const {
|
|
638
652
|
vaultAmounts: t,
|
|
639
653
|
confirmedUTXOs: r,
|
|
640
|
-
vaultProviderBtcPubkey:
|
|
641
|
-
vaultKeeperBtcPubkeys:
|
|
654
|
+
vaultProviderBtcPubkey: o,
|
|
655
|
+
vaultKeeperBtcPubkeys: i,
|
|
642
656
|
universalChallengerBtcPubkeys: l,
|
|
643
|
-
minDeposit:
|
|
644
|
-
maxDeposit:
|
|
645
|
-
} = e,
|
|
657
|
+
minDeposit: n,
|
|
658
|
+
maxDeposit: s
|
|
659
|
+
} = e, u = Fe(
|
|
646
660
|
t,
|
|
647
|
-
|
|
648
|
-
|
|
661
|
+
n,
|
|
662
|
+
s
|
|
649
663
|
);
|
|
650
|
-
if (!o.valid)
|
|
651
|
-
throw new Error(o.error);
|
|
652
|
-
const u = Ke(n);
|
|
653
664
|
if (!u.valid)
|
|
654
665
|
throw new Error(u.error);
|
|
655
|
-
|
|
666
|
+
const a = Ke(o);
|
|
667
|
+
if (!a.valid)
|
|
668
|
+
throw new Error(a.error);
|
|
669
|
+
Ue(i), Me(l), Le(r);
|
|
656
670
|
}
|
|
657
|
-
async function
|
|
671
|
+
async function bt(e) {
|
|
658
672
|
const {
|
|
659
673
|
vaultRegistryReader: t,
|
|
660
674
|
vaultKeeperReader: r,
|
|
661
|
-
universalChallengerReader:
|
|
662
|
-
vaultProviderEthAddress:
|
|
675
|
+
universalChallengerReader: o,
|
|
676
|
+
vaultProviderEthAddress: i,
|
|
663
677
|
applicationEntryPoint: l,
|
|
664
|
-
expectedVaultProviderBtcPubkey:
|
|
665
|
-
expectedVaultKeeperBtcPubkeys:
|
|
666
|
-
expectedUniversalChallengerBtcPubkeys:
|
|
678
|
+
expectedVaultProviderBtcPubkey: n,
|
|
679
|
+
expectedVaultKeeperBtcPubkeys: s,
|
|
680
|
+
expectedUniversalChallengerBtcPubkeys: u
|
|
667
681
|
} = e, [
|
|
668
|
-
|
|
682
|
+
a,
|
|
669
683
|
h,
|
|
670
684
|
c
|
|
671
685
|
] = await Promise.all([
|
|
672
|
-
t.getVaultProviderBtcPubKey(
|
|
686
|
+
t.getVaultProviderBtcPubKey(i),
|
|
673
687
|
r.getCurrentVaultKeepersVersion(l),
|
|
674
|
-
|
|
675
|
-
]), [
|
|
688
|
+
o.getLatestUniversalChallengersVersion()
|
|
689
|
+
]), [p, b] = await Promise.all([
|
|
676
690
|
r.getVaultKeepersByVersion(
|
|
677
691
|
l,
|
|
678
692
|
h
|
|
679
693
|
),
|
|
680
|
-
|
|
694
|
+
o.getUniversalChallengersByVersion(
|
|
681
695
|
c
|
|
682
696
|
)
|
|
683
|
-
]), m = (g) =>
|
|
684
|
-
if (m(
|
|
697
|
+
]), m = (g) => R(g).toLowerCase(), y = (g) => g.map(m).sort();
|
|
698
|
+
if (m(n) !== a)
|
|
685
699
|
throw new Error(
|
|
686
|
-
`Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${
|
|
700
|
+
`Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${i}. Refresh and try again.`
|
|
687
701
|
);
|
|
688
|
-
const
|
|
689
|
-
|
|
702
|
+
const P = y(s), w = y(
|
|
703
|
+
p.map((g) => g.btcPubKey)
|
|
690
704
|
);
|
|
691
|
-
if (
|
|
705
|
+
if (P.length !== w.length || P.some((g, C) => g !== w[C]))
|
|
692
706
|
throw new Error(
|
|
693
707
|
`Vault keeper BTC pubkeys (v${h}) indexer set does not match ApplicationRegistry on-chain set. Refresh and try again.`
|
|
694
708
|
);
|
|
695
|
-
const
|
|
696
|
-
|
|
709
|
+
const v = y(u), k = y(
|
|
710
|
+
b.map((g) => g.btcPubKey)
|
|
697
711
|
);
|
|
698
|
-
if (
|
|
712
|
+
if (v.length !== k.length || v.some((g, C) => g !== k[C]))
|
|
699
713
|
throw new Error(
|
|
700
714
|
`Universal challenger BTC pubkeys (v${c}) indexer set does not match ProtocolParams on-chain set. Refresh and try again.`
|
|
701
715
|
);
|
|
702
716
|
return {
|
|
703
|
-
vaultProviderBtcPubkeyXOnly:
|
|
704
|
-
vaultKeeperBtcPubkeysSorted:
|
|
717
|
+
vaultProviderBtcPubkeyXOnly: a,
|
|
718
|
+
vaultKeeperBtcPubkeysSorted: w,
|
|
705
719
|
universalChallengerBtcPubkeysSorted: k,
|
|
706
720
|
expectedAppVaultKeepersVersion: h,
|
|
707
721
|
expectedUniversalChallengersVersion: c
|
|
@@ -715,54 +729,54 @@ class j extends Error {
|
|
|
715
729
|
function Pt(e) {
|
|
716
730
|
return e instanceof j || e instanceof Error && e.name === "RegisteredVaultVersionMismatchError";
|
|
717
731
|
}
|
|
718
|
-
async function
|
|
732
|
+
async function yt(e) {
|
|
719
733
|
const {
|
|
720
734
|
vaultRegistryReader: t,
|
|
721
735
|
vaultIds: r,
|
|
722
|
-
expectedOffchainParamsVersion:
|
|
723
|
-
expectedAppVaultKeepersVersion:
|
|
736
|
+
expectedOffchainParamsVersion: o,
|
|
737
|
+
expectedAppVaultKeepersVersion: i,
|
|
724
738
|
expectedUniversalChallengersVersion: l,
|
|
725
|
-
expectedVaultCoreVersion:
|
|
726
|
-
} = e,
|
|
727
|
-
if (
|
|
739
|
+
expectedVaultCoreVersion: n
|
|
740
|
+
} = e, s = await t.getProtocolInfoBatch(r), u = [];
|
|
741
|
+
if (s.forEach((a, h) => {
|
|
728
742
|
const c = r[h];
|
|
729
|
-
|
|
730
|
-
`vault ${c}: offchainParams expected v${
|
|
731
|
-
),
|
|
732
|
-
`vault ${c}: appVaultKeepers expected v${
|
|
733
|
-
),
|
|
734
|
-
`vault ${c}: universalChallengers expected v${l}, got v${
|
|
735
|
-
),
|
|
736
|
-
`vault ${c}: vaultCoreVersion expected v${
|
|
737
|
-
);
|
|
738
|
-
}),
|
|
743
|
+
a.offchainParamsVersion !== o && u.push(
|
|
744
|
+
`vault ${c}: offchainParams expected v${o}, got v${a.offchainParamsVersion}`
|
|
745
|
+
), a.appVaultKeepersVersion !== i && u.push(
|
|
746
|
+
`vault ${c}: appVaultKeepers expected v${i}, got v${a.appVaultKeepersVersion}`
|
|
747
|
+
), a.universalChallengersVersion !== l && u.push(
|
|
748
|
+
`vault ${c}: universalChallengers expected v${l}, got v${a.universalChallengersVersion}`
|
|
749
|
+
), a.vaultCoreVersion !== n && u.push(
|
|
750
|
+
`vault ${c}: vaultCoreVersion expected v${n} (build-time active), got v${a.vaultCoreVersion}`
|
|
751
|
+
);
|
|
752
|
+
}), u.length > 0)
|
|
739
753
|
throw new j(
|
|
740
|
-
`Aborting BTC broadcast: signer-set or offchain-params versions changed during registration (${
|
|
754
|
+
`Aborting BTC broadcast: signer-set or offchain-params versions changed during registration (${u.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
|
|
741
755
|
);
|
|
742
756
|
}
|
|
743
757
|
var Q = /* @__PURE__ */ ((e) => (e.CLAIM_EVENT_RECEIVED = "ClaimEventReceived", e.CLAIM_BROADCAST = "ClaimBroadcast", e.ASSERT_BROADCAST = "AssertBroadcast", e.PAYOUT_BROADCAST = "PayoutBroadcast", e.PAYOUT_BLOCKED = "PayoutBlocked", e))(Q || {});
|
|
744
|
-
const
|
|
758
|
+
const Xe = /* @__PURE__ */ new Set([
|
|
745
759
|
"PayoutBroadcast",
|
|
746
760
|
"PayoutBlocked"
|
|
747
761
|
/* PAYOUT_BLOCKED */
|
|
748
762
|
]);
|
|
749
|
-
function
|
|
763
|
+
function wt(e) {
|
|
750
764
|
return Object.values(Q).includes(
|
|
751
765
|
e
|
|
752
766
|
);
|
|
753
767
|
}
|
|
754
|
-
function
|
|
755
|
-
return !!e &&
|
|
756
|
-
}
|
|
757
|
-
class
|
|
758
|
-
constructor(r,
|
|
759
|
-
super(`Refund not yet mature (BIP68 not final): ${
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
this.name = "BIP68NotMatureError", this.vaultId = r, this.cause =
|
|
768
|
+
function vt(e) {
|
|
769
|
+
return !!e && Xe.has(e);
|
|
770
|
+
}
|
|
771
|
+
class ze extends Error {
|
|
772
|
+
constructor(r, o) {
|
|
773
|
+
super(`Refund not yet mature (BIP68 not final): ${o.message}`);
|
|
774
|
+
A(this, "vaultId");
|
|
775
|
+
A(this, "cause");
|
|
776
|
+
this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = o;
|
|
763
777
|
}
|
|
764
778
|
}
|
|
765
|
-
const
|
|
779
|
+
const Ge = /^0x[0-9a-fA-F]{64}$/, qe = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, Y = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, W = 160, U = 2e3, M = 10n, L = 100n;
|
|
766
780
|
function xt(e) {
|
|
767
781
|
if (!Number.isFinite(e) || e <= 0)
|
|
768
782
|
throw new Error(
|
|
@@ -770,13 +784,13 @@ function xt(e) {
|
|
|
770
784
|
);
|
|
771
785
|
return BigInt(Math.ceil(e * W));
|
|
772
786
|
}
|
|
773
|
-
const
|
|
787
|
+
const je = 1, Qe = /non-BIP68-final/i;
|
|
774
788
|
function D(e, t) {
|
|
775
789
|
if (e.length !== 66)
|
|
776
790
|
throw new Error(
|
|
777
791
|
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
778
792
|
);
|
|
779
|
-
if (!
|
|
793
|
+
if (!Ge.test(e))
|
|
780
794
|
throw new Error(
|
|
781
795
|
`${t} must contain only hex characters after the 0x prefix`
|
|
782
796
|
);
|
|
@@ -785,7 +799,7 @@ function B(e, t) {
|
|
|
785
799
|
if (!Number.isInteger(e) || e < 0)
|
|
786
800
|
throw new Error(`${t} must be a non-negative integer, got ${e}`);
|
|
787
801
|
}
|
|
788
|
-
function
|
|
802
|
+
function Ye(e) {
|
|
789
803
|
if (D(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0)
|
|
790
804
|
throw new Error(
|
|
791
805
|
`htlcVout must be a non-negative integer, got ${e.htlcVout}`
|
|
@@ -797,14 +811,14 @@ function Qe(e) {
|
|
|
797
811
|
`htlcVout ${e.htlcVout} is out of range for batch of size ${e.batch.length}`
|
|
798
812
|
);
|
|
799
813
|
for (let r = 0; r < e.batch.length; r++) {
|
|
800
|
-
const
|
|
801
|
-
if (D(
|
|
814
|
+
const o = e.batch[r];
|
|
815
|
+
if (D(o.hashlock, `batch[${r}].hashlock`), !Number.isInteger(o.htlcVout) || o.htlcVout !== r)
|
|
802
816
|
throw new Error(
|
|
803
|
-
`batch[${r}].htlcVout must equal ${r} (contiguous vout-ordered vector), got ${
|
|
817
|
+
`batch[${r}].htlcVout must equal ${r} (contiguous vout-ordered vector), got ${o.htlcVout}`
|
|
804
818
|
);
|
|
805
|
-
if (typeof
|
|
819
|
+
if (typeof o.amount != "bigint" || o.amount <= 0n)
|
|
806
820
|
throw new Error(
|
|
807
|
-
`batch[${r}].amount must be a positive bigint, got ${
|
|
821
|
+
`batch[${r}].amount must be a positive bigint, got ${o.amount}`
|
|
808
822
|
);
|
|
809
823
|
}
|
|
810
824
|
const t = e.batch[e.htlcVout];
|
|
@@ -819,12 +833,12 @@ function Qe(e) {
|
|
|
819
833
|
if (B(e.offchainParamsVersion, "offchainParamsVersion"), B(e.appVaultKeepersVersion, "appVaultKeepersVersion"), B(
|
|
820
834
|
e.universalChallengersVersion,
|
|
821
835
|
"universalChallengersVersion"
|
|
822
|
-
),
|
|
836
|
+
), me(
|
|
823
837
|
e.vaultCoreVersion,
|
|
824
838
|
"VaultRefundData.vaultCoreVersion"
|
|
825
839
|
), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
|
|
826
840
|
throw new Error("unsignedPrePeginTxHex must be a non-empty hex string");
|
|
827
|
-
if (!
|
|
841
|
+
if (!qe.test(e.unsignedPrePeginTxHex))
|
|
828
842
|
throw new Error(
|
|
829
843
|
"unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
|
|
830
844
|
);
|
|
@@ -835,7 +849,7 @@ function Qe(e) {
|
|
|
835
849
|
if (typeof e.amount != "bigint" || e.amount <= 0n)
|
|
836
850
|
throw new Error(`amount must be a positive bigint, got ${e.amount}`);
|
|
837
851
|
}
|
|
838
|
-
function
|
|
852
|
+
function We(e) {
|
|
839
853
|
if (!e.vaultProviderPubkey || !Y.test(e.vaultProviderPubkey))
|
|
840
854
|
throw new Error("vaultProviderPubkey must be 32 or 33 bytes of hex");
|
|
841
855
|
if (e.vaultKeeperPubkeys.length === 0)
|
|
@@ -861,150 +875,150 @@ function Ye(e) {
|
|
|
861
875
|
`councilQuorum (${e.councilQuorum}) must be in [1, councilSize=${e.councilSize}]`
|
|
862
876
|
);
|
|
863
877
|
}
|
|
864
|
-
function
|
|
865
|
-
const t =
|
|
878
|
+
function Je(e) {
|
|
879
|
+
const t = he.fromHex(e);
|
|
866
880
|
try {
|
|
867
881
|
t.finalizeAllInputs();
|
|
868
882
|
} catch (r) {
|
|
869
|
-
const
|
|
870
|
-
if (!
|
|
871
|
-
throw new Error(`Failed to finalize refund PSBT: ${
|
|
883
|
+
const o = r instanceof Error ? r.message : String(r);
|
|
884
|
+
if (!o.includes("already finalized"))
|
|
885
|
+
throw new Error(`Failed to finalize refund PSBT: ${o}`);
|
|
872
886
|
}
|
|
873
887
|
return t.extractTransaction().toHex();
|
|
874
888
|
}
|
|
875
|
-
async function
|
|
889
|
+
async function Et(e) {
|
|
876
890
|
const {
|
|
877
891
|
vaultId: t,
|
|
878
892
|
readVault: r,
|
|
879
|
-
readPrePeginContext:
|
|
880
|
-
feeRate:
|
|
893
|
+
readPrePeginContext: o,
|
|
894
|
+
feeRate: i,
|
|
881
895
|
signPsbt: l,
|
|
882
|
-
broadcastTx:
|
|
883
|
-
signal:
|
|
896
|
+
broadcastTx: n,
|
|
897
|
+
signal: s
|
|
884
898
|
} = e;
|
|
885
|
-
|
|
886
|
-
const
|
|
887
|
-
|
|
888
|
-
const
|
|
889
|
-
if (
|
|
890
|
-
throw new Error(`feeRate must be a positive number, got ${
|
|
891
|
-
if (
|
|
899
|
+
s == null || s.throwIfAborted(), D(t, "vaultId");
|
|
900
|
+
const u = await r();
|
|
901
|
+
Ye(u), s == null || s.throwIfAborted();
|
|
902
|
+
const a = await o(u);
|
|
903
|
+
if (We(a), s == null || s.throwIfAborted(), !Number.isFinite(i) || i <= 0)
|
|
904
|
+
throw new Error(`feeRate must be a positive number, got ${i}`);
|
|
905
|
+
if (i > U)
|
|
892
906
|
throw new Error(
|
|
893
|
-
`feeRate ${
|
|
907
|
+
`feeRate ${i} sat/vB exceeds refund safety cap ${U} sat/vB; refusing to sign refund.`
|
|
894
908
|
);
|
|
895
|
-
const h = BigInt(Math.ceil(
|
|
909
|
+
const h = BigInt(Math.ceil(i * W)), c = u.amount * M / L;
|
|
896
910
|
if (h > c)
|
|
897
911
|
throw new Error(
|
|
898
|
-
`Refund fee ${h} sats exceeds the per-vault safety cap of ${c} sats (${M}/${L} of vault.amount=${
|
|
912
|
+
`Refund fee ${h} sats exceeds the per-vault safety cap of ${c} sats (${M}/${L} of vault.amount=${u.amount}); refusing to sign refund.`
|
|
899
913
|
);
|
|
900
|
-
|
|
901
|
-
const
|
|
902
|
-
|
|
903
|
-
),
|
|
904
|
-
if (m !== void 0 && m.vout !==
|
|
914
|
+
s == null || s.throwIfAborted();
|
|
915
|
+
const p = R(
|
|
916
|
+
u.depositorBtcPubkey
|
|
917
|
+
), b = d(u.unsignedPrePeginTxHex), m = ie(b);
|
|
918
|
+
if (m !== void 0 && m.vout !== u.batch.length)
|
|
905
919
|
throw new Error(
|
|
906
|
-
`Auth-anchor OP_RETURN at vout ${m.vout} does not match batch size (${
|
|
920
|
+
`Auth-anchor OP_RETURN at vout ${m.vout} does not match batch size (${u.batch.length} HTLC outputs expect the anchor at vout ${u.batch.length}). Refund refused — sibling HTLC vector is incomplete.`
|
|
907
921
|
);
|
|
908
922
|
const y = m == null ? void 0 : m.hash;
|
|
909
|
-
let
|
|
923
|
+
let T;
|
|
910
924
|
try {
|
|
911
|
-
|
|
925
|
+
T = S.fromHex(b);
|
|
912
926
|
} catch (f) {
|
|
913
927
|
throw new Error(
|
|
914
928
|
`Failed to parse funded Pre-PegIn transaction hex: ${f instanceof Error ? f.message : String(f)}`
|
|
915
929
|
);
|
|
916
930
|
}
|
|
917
|
-
if (
|
|
931
|
+
if (T.outs.length < u.batch.length)
|
|
918
932
|
throw new Error(
|
|
919
|
-
`Funded Pre-PegIn tx has ${
|
|
933
|
+
`Funded Pre-PegIn tx has ${T.outs.length} outputs but batch requires at least ${u.batch.length} HTLC outputs. Refund refused — funded tx shape disagrees with sibling vector.`
|
|
920
934
|
);
|
|
921
|
-
const { psbtHex:
|
|
935
|
+
const { psbtHex: P } = await fe({
|
|
922
936
|
prePeginParams: {
|
|
923
|
-
vaultCoreVersion:
|
|
924
|
-
depositorPubkey:
|
|
925
|
-
vaultProviderPubkey:
|
|
926
|
-
vaultKeeperPubkeys:
|
|
927
|
-
universalChallengerPubkeys:
|
|
928
|
-
hashlocks:
|
|
929
|
-
timelockRefund:
|
|
937
|
+
vaultCoreVersion: u.vaultCoreVersion,
|
|
938
|
+
depositorPubkey: p,
|
|
939
|
+
vaultProviderPubkey: d(a.vaultProviderPubkey),
|
|
940
|
+
vaultKeeperPubkeys: a.vaultKeeperPubkeys.map(d),
|
|
941
|
+
universalChallengerPubkeys: a.universalChallengerPubkeys.map(d),
|
|
942
|
+
hashlocks: u.batch.map((f) => d(f.hashlock)),
|
|
943
|
+
timelockRefund: a.timelockRefund,
|
|
930
944
|
// `batch[i].amount` is the on-chain vault deposit (peg-in) amount, which
|
|
931
945
|
// is exactly what WASM's `pegInAmounts` expects — it re-adds the protocol
|
|
932
946
|
// reserve (`depositorClaimValue + minPeginFee`) internally when sizing the
|
|
933
947
|
// HTLC output. `buildRefundPsbt`'s value cross-check then binds the result
|
|
934
948
|
// to the funded tx bytes, refusing the refund if the template's HTLC value
|
|
935
949
|
// disagrees with the on-chain commitment.
|
|
936
|
-
pegInAmounts:
|
|
937
|
-
feeRate:
|
|
938
|
-
minPeginFeeRate:
|
|
939
|
-
numLocalChallengers:
|
|
940
|
-
councilQuorum:
|
|
941
|
-
councilSize:
|
|
942
|
-
network:
|
|
950
|
+
pegInAmounts: u.batch.map((f) => f.amount),
|
|
951
|
+
feeRate: a.feeRate,
|
|
952
|
+
minPeginFeeRate: a.minPeginFeeRate,
|
|
953
|
+
numLocalChallengers: a.numLocalChallengers,
|
|
954
|
+
councilQuorum: a.councilQuorum,
|
|
955
|
+
councilSize: a.councilSize,
|
|
956
|
+
network: a.network,
|
|
943
957
|
authAnchorHash: y
|
|
944
958
|
},
|
|
945
|
-
fundedPrePeginTxHex:
|
|
946
|
-
htlcVout:
|
|
959
|
+
fundedPrePeginTxHex: b,
|
|
960
|
+
htlcVout: u.htlcVout,
|
|
947
961
|
refundFee: h,
|
|
948
962
|
// buildRefundPsbt's top-level `hashlock` param is documented as "no 0x
|
|
949
963
|
// prefix" and flows into the WASM HTLC connector derivation; a prefixed
|
|
950
964
|
// value would derive the wrong refund script leaf and yield an
|
|
951
965
|
// unspendable PSBT. Match the `hashlocks` array handling above.
|
|
952
|
-
hashlock:
|
|
966
|
+
hashlock: d(u.hashlock)
|
|
953
967
|
});
|
|
954
|
-
|
|
955
|
-
const
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
),
|
|
968
|
+
s == null || s.throwIfAborted();
|
|
969
|
+
const w = O(
|
|
970
|
+
u.depositorBtcPubkey,
|
|
971
|
+
je
|
|
972
|
+
), v = await l(P, w);
|
|
959
973
|
I({
|
|
960
|
-
requestedPsbtHex:
|
|
961
|
-
returnedPsbtHex:
|
|
974
|
+
requestedPsbtHex: P,
|
|
975
|
+
returnedPsbtHex: v
|
|
962
976
|
});
|
|
963
977
|
const k = 0, g = N(
|
|
964
|
-
|
|
965
|
-
|
|
978
|
+
v,
|
|
979
|
+
p,
|
|
966
980
|
k
|
|
967
981
|
);
|
|
968
982
|
H({
|
|
969
|
-
requestedPsbtHex:
|
|
983
|
+
requestedPsbtHex: P,
|
|
970
984
|
signatureHex: g,
|
|
971
|
-
signerXOnlyPubkeyHex:
|
|
985
|
+
signerXOnlyPubkeyHex: p,
|
|
972
986
|
inputIndex: k
|
|
973
987
|
});
|
|
974
|
-
const C =
|
|
975
|
-
|
|
988
|
+
const C = Je(v);
|
|
989
|
+
s == null || s.throwIfAborted();
|
|
976
990
|
try {
|
|
977
|
-
return await
|
|
991
|
+
return await n(C);
|
|
978
992
|
} catch (f) {
|
|
979
|
-
throw f instanceof Error &&
|
|
993
|
+
throw f instanceof Error && Qe.test(f.message) ? new ze(t, f) : f;
|
|
980
994
|
}
|
|
981
995
|
}
|
|
982
996
|
export {
|
|
983
|
-
|
|
997
|
+
ze as B,
|
|
984
998
|
Q as C,
|
|
985
999
|
j as R,
|
|
986
|
-
|
|
1000
|
+
lt as a,
|
|
987
1001
|
Ve as b,
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
1002
|
+
gt as c,
|
|
1003
|
+
ft as d,
|
|
1004
|
+
Fe as e,
|
|
991
1005
|
Ke as f,
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
1006
|
+
mt as g,
|
|
1007
|
+
bt as h,
|
|
1008
|
+
pt as i,
|
|
995
1009
|
Pt as j,
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1010
|
+
yt as k,
|
|
1011
|
+
wt as l,
|
|
1012
|
+
vt as m,
|
|
1013
|
+
Et as n,
|
|
1000
1014
|
xt as o,
|
|
1001
1015
|
L as p,
|
|
1002
1016
|
M as q,
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1017
|
+
ht as r,
|
|
1018
|
+
ct as s,
|
|
1019
|
+
U as t,
|
|
1006
1020
|
W as u,
|
|
1007
1021
|
dt as v,
|
|
1008
1022
|
G as w
|
|
1009
1023
|
};
|
|
1010
|
-
//# sourceMappingURL=buildAndBroadcastRefund-
|
|
1024
|
+
//# sourceMappingURL=buildAndBroadcastRefund-BtXUqBkb.js.map
|