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