@babylonlabs-io/ts-sdk 0.37.3 → 0.38.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/dist/BTCVaultRegistry.abi-CHFGevwa.cjs +2 -0
- package/dist/BTCVaultRegistry.abi-CHFGevwa.cjs.map +1 -0
- package/dist/{BTCVaultRegistry.abi-DbJ5lsFJ.js → BTCVaultRegistry.abi-Cq9-JlqT.js} +38 -2
- package/dist/BTCVaultRegistry.abi-Cq9-JlqT.js.map +1 -0
- package/dist/PayoutManager-D29D-K-V.js +250 -0
- package/dist/PayoutManager-D29D-K-V.js.map +1 -0
- package/dist/PayoutManager-DERMRuUU.cjs +2 -0
- package/dist/PayoutManager-DERMRuUU.cjs.map +1 -0
- package/dist/{PeginManager-HCYTUzh6.js → PeginManager-Cp2Tn5sH.js} +444 -406
- package/dist/PeginManager-Cp2Tn5sH.js.map +1 -0
- package/dist/PeginManager-DaDs-bGr.cjs +2 -0
- package/dist/PeginManager-DaDs-bGr.cjs.map +1 -0
- package/dist/{ProtocolParams.abi-DXu8L0Fn.js → ProtocolParams.abi-C2brDWTI.js} +8 -3
- package/dist/ProtocolParams.abi-C2brDWTI.js.map +1 -0
- package/dist/ProtocolParams.abi-DQhcqsNr.cjs +2 -0
- package/dist/ProtocolParams.abi-DQhcqsNr.cjs.map +1 -0
- package/dist/assertPsbtUnsignedTxMatches-fNkAaZZm.cjs +2 -0
- package/dist/assertPsbtUnsignedTxMatches-fNkAaZZm.cjs.map +1 -0
- package/dist/assertPsbtUnsignedTxMatches-mTAnLhCz.js +340 -0
- package/dist/assertPsbtUnsignedTxMatches-mTAnLhCz.js.map +1 -0
- package/dist/{buildAndBroadcastRefund-CI_x6OtX.js → buildAndBroadcastRefund-B5cOyUzj.js} +234 -227
- package/dist/buildAndBroadcastRefund-B5cOyUzj.js.map +1 -0
- package/dist/buildAndBroadcastRefund-DVMT-pXQ.cjs +2 -0
- package/dist/buildAndBroadcastRefund-DVMT-pXQ.cjs.map +1 -0
- package/dist/{challengeAssert-D7OCrDIc.js → challengeAssert-CBp4mEs0.js} +2 -2
- package/dist/{challengeAssert-D7OCrDIc.js.map → challengeAssert-CBp4mEs0.js.map} +1 -1
- package/dist/{challengeAssert-CMb7r-je.cjs → challengeAssert-CNRdpCzm.cjs} +2 -2
- package/dist/{challengeAssert-CMb7r-je.cjs.map → challengeAssert-CNRdpCzm.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +38 -38
- package/dist/noPayout-jtZsoOzY.cjs +2 -0
- package/dist/noPayout-jtZsoOzY.cjs.map +1 -0
- package/dist/noPayout-qbaSEKGC.js +145 -0
- package/dist/noPayout-qbaSEKGC.js.map +1 -0
- package/dist/peginInput-BPRB9tUi.js +104 -0
- package/dist/peginInput-BPRB9tUi.js.map +1 -0
- package/dist/peginInput-DH6X4ITS.cjs +2 -0
- package/dist/peginInput-DH6X4ITS.cjs.map +1 -0
- package/dist/tbv/core/clients/eth/protocol-params-reader.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/protocol-params-validation.d.ts.map +1 -1
- package/dist/tbv/core/clients/eth/types.d.ts +12 -1
- package/dist/tbv/core/clients/eth/types.d.ts.map +1 -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 +9 -9
- package/dist/tbv/core/clients/vault-provider/json-rpc-client.d.ts +0 -9
- package/dist/tbv/core/clients/vault-provider/json-rpc-client.d.ts.map +1 -1
- package/dist/tbv/core/clients/vault-provider/types.d.ts +38 -21
- package/dist/tbv/core/clients/vault-provider/types.d.ts.map +1 -1
- package/dist/tbv/core/clients/vault-provider/validators.d.ts.map +1 -1
- package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts +36 -2
- package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts.map +1 -1
- package/dist/tbv/core/contracts/abis/ProtocolParams.abi.d.ts +6 -2
- 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.js +2 -2
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +25 -25
- package/dist/tbv/core/managers/PeginManager.d.ts +5 -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/managers/pegin/assertAuthAnchorOpReturn.d.ts +37 -0
- package/dist/tbv/core/managers/pegin/assertAuthAnchorOpReturn.d.ts.map +1 -1
- package/dist/tbv/core/managers/pegin/index.d.ts +1 -1
- package/dist/tbv/core/managers/pegin/index.d.ts.map +1 -1
- package/dist/tbv/core/primitives/index.cjs +1 -1
- package/dist/tbv/core/primitives/index.js +17 -17
- package/dist/tbv/core/primitives/psbt/__tests__/refund.test.d.ts +12 -0
- package/dist/tbv/core/primitives/psbt/__tests__/refund.test.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/pegin.d.ts +5 -0
- package/dist/tbv/core/primitives/psbt/pegin.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/refund.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/waitForPeginStatus.d.ts +4 -2
- package/dist/tbv/core/services/deposit/waitForPeginStatus.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/services/pegout/state.d.ts +5 -8
- package/dist/tbv/core/services/pegout/state.d.ts.map +1 -1
- package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +25 -25
- package/dist/tbv/integrations/aave/clients/query.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.js +23 -22
- package/dist/tbv/integrations/aave/index.js.map +1 -1
- package/dist/tbv/integrations/aave/types.d.ts +6 -0
- package/dist/tbv/integrations/aave/types.d.ts.map +1 -1
- package/dist/types-D2jcXfm7.cjs +2 -0
- package/dist/types-D2jcXfm7.cjs.map +1 -0
- package/dist/types-TOmEvvRy.js +322 -0
- package/dist/types-TOmEvvRy.js.map +1 -0
- package/dist/{vault-registry-reader-Blhu9FW2.js → vault-registry-reader-BrARgFre.js} +207 -202
- package/dist/vault-registry-reader-BrARgFre.js.map +1 -0
- package/dist/vault-registry-reader-CbJHSxVe.cjs +2 -0
- package/dist/vault-registry-reader-CbJHSxVe.cjs.map +1 -0
- package/package.json +1 -1
- package/dist/BTCVaultRegistry.abi-DbJ5lsFJ.js.map +0 -1
- package/dist/BTCVaultRegistry.abi-ZdPpION2.cjs +0 -2
- package/dist/BTCVaultRegistry.abi-ZdPpION2.cjs.map +0 -1
- package/dist/PayoutManager-BfT0V-tm.cjs +0 -2
- package/dist/PayoutManager-BfT0V-tm.cjs.map +0 -1
- package/dist/PayoutManager-Cf51DBcu.js +0 -208
- package/dist/PayoutManager-Cf51DBcu.js.map +0 -1
- package/dist/PeginManager-CTznAVPT.cjs +0 -2
- package/dist/PeginManager-CTznAVPT.cjs.map +0 -1
- package/dist/PeginManager-HCYTUzh6.js.map +0 -1
- package/dist/ProtocolParams.abi-BmvHwQJV.cjs +0 -2
- package/dist/ProtocolParams.abi-BmvHwQJV.cjs.map +0 -1
- package/dist/ProtocolParams.abi-DXu8L0Fn.js.map +0 -1
- package/dist/assertPsbtUnsignedTxMatches-CagW7XqW.cjs +0 -2
- package/dist/assertPsbtUnsignedTxMatches-CagW7XqW.cjs.map +0 -1
- package/dist/assertPsbtUnsignedTxMatches-Dry5dTfl.js +0 -266
- package/dist/assertPsbtUnsignedTxMatches-Dry5dTfl.js.map +0 -1
- package/dist/buildAndBroadcastRefund-Bj2e94CC.cjs +0 -2
- package/dist/buildAndBroadcastRefund-Bj2e94CC.cjs.map +0 -1
- package/dist/buildAndBroadcastRefund-CI_x6OtX.js.map +0 -1
- package/dist/noPayout-B6s8vrW6.cjs +0 -2
- package/dist/noPayout-B6s8vrW6.cjs.map +0 -1
- package/dist/noPayout-BhgknZBx.js +0 -141
- package/dist/noPayout-BhgknZBx.js.map +0 -1
- package/dist/peginInput-57FK2O99.cjs +0 -2
- package/dist/peginInput-57FK2O99.cjs.map +0 -1
- package/dist/peginInput-CYJzbuwA.js +0 -177
- package/dist/peginInput-CYJzbuwA.js.map +0 -1
- package/dist/types-DnyyBNcC.cjs +0 -2
- package/dist/types-DnyyBNcC.cjs.map +0 -1
- package/dist/types-TiIjyo2b.js +0 -320
- package/dist/types-TiIjyo2b.js.map +0 -1
- package/dist/vault-registry-reader-7gOYnrQD.cjs +0 -2
- package/dist/vault-registry-reader-7gOYnrQD.cjs.map +0 -1
- package/dist/vault-registry-reader-Blhu9FW2.js.map +0 -1
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
var Q = (e, t, r) => t in e ?
|
|
3
|
-
var
|
|
4
|
-
import { B as j } from "./BTCVaultRegistry.abi-
|
|
5
|
-
import { e as
|
|
6
|
-
import { v as
|
|
7
|
-
import { c as te, a as re, R as ne, d as
|
|
8
|
-
import { Transaction as
|
|
9
|
-
import {
|
|
10
|
-
import { c as ie, a as ue, b as le } from "./noPayout-
|
|
1
|
+
var G = Object.defineProperty;
|
|
2
|
+
var Q = (e, t, r) => t in e ? G(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var S = (e, t, r) => Q(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { B as j } from "./BTCVaultRegistry.abi-Cq9-JlqT.js";
|
|
5
|
+
import { e as q, v as W, s as h, u as N, p as k, d as Y, f as x } from "./bitcoin-B5aNKtsk.js";
|
|
6
|
+
import { v as J, P as Z, f as ee } from "./PayoutManager-D29D-K-V.js";
|
|
7
|
+
import { D as v, c as te, a as re, R as ne, d as O } from "./types-TOmEvvRy.js";
|
|
8
|
+
import { Transaction as _, Psbt as oe } from "bitcoinjs-lib";
|
|
9
|
+
import { c as se, d as ae, f as V, e as I } from "./assertPsbtUnsignedTxMatches-mTAnLhCz.js";
|
|
10
|
+
import { c as ie, a as ue, b as le } from "./noPayout-qbaSEKGC.js";
|
|
11
11
|
import { c as $ } from "./signing-DaLvGwQe.js";
|
|
12
12
|
const ce = /^0x[0-9a-fA-F]{64}$/, de = /^0x[0-9a-fA-F]{40}$/, he = /^0x([0-9a-fA-F]{2})*$/;
|
|
13
|
-
function
|
|
13
|
+
function A(e, t) {
|
|
14
14
|
if (e.length !== 66)
|
|
15
15
|
throw new Error(
|
|
16
16
|
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
@@ -26,7 +26,7 @@ function pe(e, t) {
|
|
|
26
26
|
`${t} must be a 20-byte 0x-prefixed hex address (42 chars)`
|
|
27
27
|
);
|
|
28
28
|
}
|
|
29
|
-
function
|
|
29
|
+
function fe(e, t) {
|
|
30
30
|
if (!he.test(e))
|
|
31
31
|
throw new Error(
|
|
32
32
|
`${t} must be a 0x-prefixed hex string with an even number of hex chars`
|
|
@@ -37,31 +37,31 @@ async function tt(e) {
|
|
|
37
37
|
btcVaultRegistryAddress: t,
|
|
38
38
|
vaultId: r,
|
|
39
39
|
hashlock: n,
|
|
40
|
-
activationMetadata:
|
|
40
|
+
activationMetadata: o,
|
|
41
41
|
writeContract: u,
|
|
42
42
|
signal: a
|
|
43
43
|
} = e;
|
|
44
|
-
a == null || a.throwIfAborted(), pe(t, "btcVaultRegistryAddress"),
|
|
45
|
-
const i =
|
|
46
|
-
if (
|
|
44
|
+
a == null || a.throwIfAborted(), pe(t, "btcVaultRegistryAddress"), A(r, "vaultId");
|
|
45
|
+
const i = q(e.secret);
|
|
46
|
+
if (A(i, "secret"), n !== void 0 && (A(n, "hashlock"), !J(i, n)))
|
|
47
47
|
throw new Error(
|
|
48
48
|
"Invalid secret: SHA256(secret) does not match the provided hashlock"
|
|
49
49
|
);
|
|
50
|
-
return
|
|
50
|
+
return fe(o, "activationMetadata"), u({
|
|
51
51
|
address: t,
|
|
52
52
|
abi: j,
|
|
53
53
|
functionName: "activateVaultWithSecret",
|
|
54
|
-
args: [r, i,
|
|
54
|
+
args: [r, i, o]
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
|
-
const
|
|
57
|
+
const ge = 1e4;
|
|
58
58
|
async function D(e) {
|
|
59
59
|
const {
|
|
60
60
|
statusReader: t,
|
|
61
61
|
peginTxid: r,
|
|
62
62
|
targetStatuses: n,
|
|
63
|
-
timeoutMs:
|
|
64
|
-
pollIntervalMs: u =
|
|
63
|
+
timeoutMs: o,
|
|
64
|
+
pollIntervalMs: u = ge,
|
|
65
65
|
signal: a
|
|
66
66
|
} = e, i = Date.now();
|
|
67
67
|
for (; ; ) {
|
|
@@ -69,31 +69,31 @@ async function D(e) {
|
|
|
69
69
|
throw new Error(
|
|
70
70
|
`Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...n].join(", ")})`
|
|
71
71
|
);
|
|
72
|
-
if (Date.now() - i >=
|
|
72
|
+
if (Date.now() - i >= o)
|
|
73
73
|
throw new Error(
|
|
74
|
-
`Polling timeout after ${
|
|
74
|
+
`Polling timeout after ${o}ms for pegin ${r.slice(0, 8)}… (target: ${[...n].join(", ")})`
|
|
75
75
|
);
|
|
76
76
|
try {
|
|
77
|
-
const
|
|
77
|
+
const s = await t.getPeginStatus(
|
|
78
78
|
{ pegin_txid: r },
|
|
79
79
|
a
|
|
80
80
|
);
|
|
81
|
-
if (
|
|
81
|
+
if (s.pegin_txid.toLowerCase() !== r.toLowerCase())
|
|
82
82
|
throw new Error(
|
|
83
|
-
`getPeginStatus returned status for pegin ${
|
|
83
|
+
`getPeginStatus returned status for pegin ${s.pegin_txid.slice(0, 8)}…, requested ${r.slice(0, 8)}…`
|
|
84
84
|
);
|
|
85
|
-
const l =
|
|
86
|
-
if (n.has(l))
|
|
85
|
+
const l = s.status;
|
|
86
|
+
if (n.has(l) || l === v.ACTIVATED)
|
|
87
87
|
return l;
|
|
88
|
-
if (
|
|
88
|
+
if (l === v.EXPIRED || te.has(l))
|
|
89
89
|
throw new Error(
|
|
90
90
|
`Pegin ${r.slice(0, 8)}… reached terminal status "${l}" while waiting for ${[...n].join(", ")}`
|
|
91
91
|
);
|
|
92
|
-
} catch (
|
|
93
|
-
if (!(
|
|
94
|
-
throw
|
|
92
|
+
} catch (s) {
|
|
93
|
+
if (!(s instanceof re && s.code === ne.PEGIN_NOT_FOUND))
|
|
94
|
+
throw s;
|
|
95
95
|
}
|
|
96
|
-
await new Promise((
|
|
96
|
+
await new Promise((s, l) => {
|
|
97
97
|
const d = () => {
|
|
98
98
|
clearTimeout(c), l(
|
|
99
99
|
new Error(
|
|
@@ -101,38 +101,38 @@ async function D(e) {
|
|
|
101
101
|
)
|
|
102
102
|
);
|
|
103
103
|
}, c = setTimeout(() => {
|
|
104
|
-
a == null || a.removeEventListener("abort", d),
|
|
104
|
+
a == null || a.removeEventListener("abort", d), s();
|
|
105
105
|
}, u);
|
|
106
106
|
a == null || a.addEventListener("abort", d, { once: !0 });
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
...
|
|
110
|
+
const Pe = 300 * 1e3, ye = /* @__PURE__ */ new Set([
|
|
111
|
+
v.PENDING_DEPOSITOR_WOTS_PK,
|
|
112
|
+
...O
|
|
113
113
|
]);
|
|
114
114
|
async function rt(e) {
|
|
115
115
|
const {
|
|
116
116
|
statusReader: t,
|
|
117
117
|
wotsSubmitter: r,
|
|
118
118
|
peginTxid: n,
|
|
119
|
-
depositorPk:
|
|
119
|
+
depositorPk: o,
|
|
120
120
|
wotsPublicKeys: u,
|
|
121
|
-
timeoutMs: a =
|
|
121
|
+
timeoutMs: a = Pe,
|
|
122
122
|
signal: i
|
|
123
123
|
} = e;
|
|
124
124
|
i == null || i.throwIfAborted();
|
|
125
|
-
const
|
|
125
|
+
const s = await D({
|
|
126
126
|
statusReader: t,
|
|
127
127
|
peginTxid: n,
|
|
128
|
-
targetStatuses:
|
|
128
|
+
targetStatuses: ye,
|
|
129
129
|
timeoutMs: a,
|
|
130
130
|
signal: i
|
|
131
131
|
});
|
|
132
|
-
|
|
132
|
+
O.has(s) || (i == null || i.throwIfAborted(), await r.submitDepositorWotsKey(
|
|
133
133
|
{
|
|
134
134
|
pegin_txid: n,
|
|
135
|
-
depositor_pk:
|
|
135
|
+
depositor_pk: o,
|
|
136
136
|
wots_public_keys: u
|
|
137
137
|
},
|
|
138
138
|
i
|
|
@@ -140,24 +140,24 @@ async function rt(e) {
|
|
|
140
140
|
}
|
|
141
141
|
const H = 1;
|
|
142
142
|
function be(e, t) {
|
|
143
|
-
const r = h(t).toLowerCase(),
|
|
144
|
-
if (
|
|
143
|
+
const r = h(t).toLowerCase(), o = e.map((u) => h(u).toLowerCase()).filter((u) => u !== r);
|
|
144
|
+
if (o.length === 0)
|
|
145
145
|
throw new Error(
|
|
146
146
|
"Cannot derive localChallengers: vault keeper set is empty (or contains only the depositor)"
|
|
147
147
|
);
|
|
148
|
-
if (new Set(
|
|
148
|
+
if (new Set(o).size !== o.length)
|
|
149
149
|
throw new Error(
|
|
150
150
|
"Cannot derive localChallengers: duplicate vaultKeeper key — signing context is misconfigured"
|
|
151
151
|
);
|
|
152
|
-
return
|
|
152
|
+
return o;
|
|
153
153
|
}
|
|
154
154
|
function me(e, t, r) {
|
|
155
155
|
const n = r.map(
|
|
156
156
|
(c) => h(c).toLowerCase()
|
|
157
|
-
),
|
|
158
|
-
if (
|
|
157
|
+
), o = t.filter((c) => n.includes(c));
|
|
158
|
+
if (o.length > 0)
|
|
159
159
|
throw new Error(
|
|
160
|
-
`Cannot validate challenger set: vault keepers and universal challengers overlap (${
|
|
160
|
+
`Cannot validate challenger set: vault keepers and universal challengers overlap (${o.join(", ")})`
|
|
161
161
|
);
|
|
162
162
|
const u = [...t, ...n], a = e.map(
|
|
163
163
|
(c) => h(c.challenger_pubkey).toLowerCase()
|
|
@@ -166,30 +166,30 @@ function me(e, t, r) {
|
|
|
166
166
|
throw new Error(
|
|
167
167
|
"Depositor graph contains duplicate challenger entries in challenger_presign_data"
|
|
168
168
|
);
|
|
169
|
-
const
|
|
169
|
+
const s = new Set(u), l = u.filter((c) => !i.has(c)), d = a.filter((c) => !s.has(c));
|
|
170
170
|
if (l.length > 0 || d.length > 0)
|
|
171
171
|
throw new Error(
|
|
172
172
|
"Depositor graph challenger set does not match expected (local ∪ universal)" + (l.length > 0 ? ` (missing: ${l.join(", ")})` : "") + (d.length > 0 ? ` (unexpected: ${d.join(", ")})` : "")
|
|
173
173
|
);
|
|
174
174
|
}
|
|
175
|
-
function
|
|
175
|
+
function ve(e, t) {
|
|
176
176
|
const r = e.ins[t];
|
|
177
177
|
return N(new Uint8Array(r.hash).slice().reverse());
|
|
178
178
|
}
|
|
179
|
-
function B(e, t, r, n,
|
|
179
|
+
function B(e, t, r, n, o) {
|
|
180
180
|
const u = e.ins[t];
|
|
181
181
|
if (u.index !== 0)
|
|
182
182
|
throw new Error(
|
|
183
|
-
`NoPayout (challenger ${
|
|
183
|
+
`NoPayout (challenger ${o}) input ${t} expected to spend ${n} vout 0, got vout ${u.index}`
|
|
184
184
|
);
|
|
185
|
-
const a = r.getId(), i =
|
|
185
|
+
const a = r.getId(), i = ve(e, t);
|
|
186
186
|
if (i !== a)
|
|
187
187
|
throw new Error(
|
|
188
|
-
`NoPayout (challenger ${
|
|
188
|
+
`NoPayout (challenger ${o}) input ${t} does not reference ${n} (expected txid ${a}, got ${i})`
|
|
189
189
|
);
|
|
190
190
|
}
|
|
191
|
-
async function
|
|
192
|
-
const n = [],
|
|
191
|
+
async function we(e, t, r) {
|
|
192
|
+
const n = [], o = [], u = [], a = be(
|
|
193
193
|
r.vaultKeeperBtcPubkeys,
|
|
194
194
|
r.depositorBtcPubkey
|
|
195
195
|
);
|
|
@@ -212,25 +212,25 @@ async function ve(e, t, r) {
|
|
|
212
212
|
timelockPegin: r.timelockPegin,
|
|
213
213
|
network: r.network
|
|
214
214
|
});
|
|
215
|
-
n.push(i.psbtHex),
|
|
215
|
+
n.push(i.psbtHex), o.push(
|
|
216
216
|
$(
|
|
217
217
|
t,
|
|
218
218
|
H
|
|
219
219
|
)
|
|
220
220
|
);
|
|
221
|
-
const
|
|
221
|
+
const s = h(r.depositorBtcPubkey), l = _.fromHex(
|
|
222
222
|
h(e.assert_tx.tx_hex)
|
|
223
223
|
);
|
|
224
224
|
for (const d of e.challenger_presign_data) {
|
|
225
225
|
const c = h(d.challenger_pubkey), g = n.length, P = await xe({
|
|
226
226
|
challenger: d,
|
|
227
227
|
challengerPubkey: c,
|
|
228
|
-
claimerPubkey:
|
|
228
|
+
claimerPubkey: s,
|
|
229
229
|
localChallengers: a,
|
|
230
230
|
assertTxParsed: l,
|
|
231
231
|
ctx: r
|
|
232
232
|
});
|
|
233
|
-
n.push(P),
|
|
233
|
+
n.push(P), o.push(
|
|
234
234
|
$(
|
|
235
235
|
t,
|
|
236
236
|
H
|
|
@@ -240,14 +240,14 @@ async function ve(e, t, r) {
|
|
|
240
240
|
noPayoutIdx: g
|
|
241
241
|
});
|
|
242
242
|
}
|
|
243
|
-
return { psbtHexes: n, signOptions:
|
|
243
|
+
return { psbtHexes: n, signOptions: o, challengerEntries: u };
|
|
244
244
|
}
|
|
245
245
|
async function xe(e) {
|
|
246
246
|
const {
|
|
247
247
|
challenger: t,
|
|
248
248
|
challengerPubkey: r,
|
|
249
249
|
claimerPubkey: n,
|
|
250
|
-
localChallengers:
|
|
250
|
+
localChallengers: o,
|
|
251
251
|
assertTxParsed: u,
|
|
252
252
|
ctx: a
|
|
253
253
|
} = e;
|
|
@@ -256,11 +256,11 @@ async function xe(e) {
|
|
|
256
256
|
r,
|
|
257
257
|
a.network
|
|
258
258
|
);
|
|
259
|
-
const i =
|
|
259
|
+
const i = _.fromHex(
|
|
260
260
|
h(t.nopayout_tx.tx_hex)
|
|
261
|
-
),
|
|
261
|
+
), s = _.fromHex(
|
|
262
262
|
h(t.challenge_assert_x_tx.tx_hex)
|
|
263
|
-
), l =
|
|
263
|
+
), l = _.fromHex(
|
|
264
264
|
h(t.challenge_assert_y_tx.tx_hex)
|
|
265
265
|
);
|
|
266
266
|
if (i.ins.length !== 3)
|
|
@@ -276,7 +276,7 @@ async function xe(e) {
|
|
|
276
276
|
), B(
|
|
277
277
|
i,
|
|
278
278
|
1,
|
|
279
|
-
|
|
279
|
+
s,
|
|
280
280
|
"ChallengeAssertX",
|
|
281
281
|
r
|
|
282
282
|
), B(
|
|
@@ -288,7 +288,7 @@ async function xe(e) {
|
|
|
288
288
|
);
|
|
289
289
|
const d = [
|
|
290
290
|
u.outs[0],
|
|
291
|
-
|
|
291
|
+
s.outs[0],
|
|
292
292
|
l.outs[0]
|
|
293
293
|
].map((c) => ({
|
|
294
294
|
script_pubkey: N(new Uint8Array(c.script)),
|
|
@@ -300,7 +300,7 @@ async function xe(e) {
|
|
|
300
300
|
prevouts: d,
|
|
301
301
|
connectorParams: {
|
|
302
302
|
claimer: n,
|
|
303
|
-
localChallengers:
|
|
303
|
+
localChallengers: o,
|
|
304
304
|
universalChallengers: a.universalChallengerBtcPubkeys,
|
|
305
305
|
timelockAssert: a.timelockAssert,
|
|
306
306
|
councilMembers: a.councilMembers,
|
|
@@ -308,14 +308,14 @@ async function xe(e) {
|
|
|
308
308
|
}
|
|
309
309
|
});
|
|
310
310
|
}
|
|
311
|
-
function
|
|
312
|
-
|
|
311
|
+
function Te(e, t, r) {
|
|
312
|
+
V(e[0]);
|
|
313
313
|
const n = I(
|
|
314
314
|
e[0].returnedPsbtHex,
|
|
315
315
|
r
|
|
316
|
-
),
|
|
316
|
+
), o = {};
|
|
317
317
|
for (const u of t)
|
|
318
|
-
|
|
318
|
+
V(e[u.noPayoutIdx]), o[u.challengerPubkey] = {
|
|
319
319
|
nopayout_signature: I(
|
|
320
320
|
e[u.noPayoutIdx].returnedPsbtHex,
|
|
321
321
|
r
|
|
@@ -325,26 +325,26 @@ function ke(e, t, r) {
|
|
|
325
325
|
payout_signatures: {
|
|
326
326
|
payout_signature: n
|
|
327
327
|
},
|
|
328
|
-
per_challenger:
|
|
328
|
+
per_challenger: o
|
|
329
329
|
};
|
|
330
330
|
}
|
|
331
|
-
async function
|
|
331
|
+
async function ke(e, t, r) {
|
|
332
332
|
if (typeof e.signPsbts == "function")
|
|
333
333
|
return e.signPsbts(t, r);
|
|
334
334
|
const n = [];
|
|
335
|
-
for (let
|
|
336
|
-
n.push(await e.signPsbt(t[
|
|
335
|
+
for (let o = 0; o < t.length; o++)
|
|
336
|
+
n.push(await e.signPsbt(t[o], r == null ? void 0 : r[o]));
|
|
337
337
|
return n;
|
|
338
338
|
}
|
|
339
339
|
async function Ee(e) {
|
|
340
|
-
const { depositorGraph: t, btcWallet: r, signingContext: n } = e,
|
|
341
|
-
|
|
340
|
+
const { depositorGraph: t, btcWallet: r, signingContext: n } = e, o = await r.getPublicKeyHex(), { depositorPubkey: u } = W(
|
|
341
|
+
o,
|
|
342
342
|
h(n.depositorBtcPubkey)
|
|
343
|
-
), { psbtHexes: a, signOptions: i, challengerEntries:
|
|
343
|
+
), { psbtHexes: a, signOptions: i, challengerEntries: s } = await we(
|
|
344
344
|
t,
|
|
345
|
-
|
|
345
|
+
o,
|
|
346
346
|
n
|
|
347
|
-
), l = await
|
|
347
|
+
), l = await ke(
|
|
348
348
|
r,
|
|
349
349
|
a,
|
|
350
350
|
i
|
|
@@ -357,19 +357,20 @@ async function Ee(e) {
|
|
|
357
357
|
requestedPsbtHex: c,
|
|
358
358
|
returnedPsbtHex: l[g]
|
|
359
359
|
}));
|
|
360
|
-
return
|
|
360
|
+
return Te(
|
|
361
361
|
d,
|
|
362
|
-
|
|
362
|
+
s,
|
|
363
363
|
u
|
|
364
364
|
);
|
|
365
365
|
}
|
|
366
|
-
const _e = 1200 * 1e3,
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
366
|
+
const _e = 1200 * 1e3, L = /* @__PURE__ */ new Set([
|
|
367
|
+
v.PENDING_ACKS,
|
|
368
|
+
v.PENDING_ACTIVATION,
|
|
369
|
+
v.ACTIVATED_PENDING_BROADCAST,
|
|
370
|
+
v.ACTIVATED
|
|
370
371
|
]), Ce = /* @__PURE__ */ new Set([
|
|
371
|
-
|
|
372
|
-
...
|
|
372
|
+
v.PENDING_DEPOSITOR_SIGNATURES,
|
|
373
|
+
...L
|
|
373
374
|
]);
|
|
374
375
|
function Se(e) {
|
|
375
376
|
return e.map((t) => ({
|
|
@@ -378,13 +379,13 @@ function Se(e) {
|
|
|
378
379
|
assertTxHex: t.assert_tx.tx_hex
|
|
379
380
|
}));
|
|
380
381
|
}
|
|
381
|
-
function
|
|
382
|
+
function Ae(e, t) {
|
|
382
383
|
const r = h(e).toLowerCase(), n = h(
|
|
383
384
|
t.vaultProviderBtcPubkey
|
|
384
|
-
).toLowerCase(),
|
|
385
|
+
).toLowerCase(), o = h(
|
|
385
386
|
t.depositorBtcPubkey
|
|
386
387
|
).toLowerCase();
|
|
387
|
-
if (r === n || r ===
|
|
388
|
+
if (r === n || r === o)
|
|
388
389
|
return t.registeredPayoutScriptPubKey;
|
|
389
390
|
if (!t.vaultKeeperBtcPubkeys.some(
|
|
390
391
|
(a) => h(a).toLowerCase() === r
|
|
@@ -392,7 +393,7 @@ function Be(e, t) {
|
|
|
392
393
|
throw new Error(
|
|
393
394
|
`Unknown claimer pubkey ${r}: not VP, depositor, or a registered vault keeper`
|
|
394
395
|
);
|
|
395
|
-
return
|
|
396
|
+
return Y(r);
|
|
396
397
|
}
|
|
397
398
|
function K(e, t) {
|
|
398
399
|
return {
|
|
@@ -404,37 +405,37 @@ function K(e, t) {
|
|
|
404
405
|
universalChallengerBtcPubkeys: t.universalChallengerBtcPubkeys,
|
|
405
406
|
depositorBtcPubkey: t.depositorBtcPubkey,
|
|
406
407
|
timelockPegin: t.timelockPegin,
|
|
407
|
-
registeredPayoutScriptPubKey:
|
|
408
|
+
registeredPayoutScriptPubKey: Ae(
|
|
408
409
|
e.claimerPubkeyXOnly,
|
|
409
410
|
t
|
|
410
411
|
)
|
|
411
412
|
};
|
|
412
413
|
}
|
|
413
|
-
async function
|
|
414
|
-
const
|
|
414
|
+
async function Be(e, t, r, n) {
|
|
415
|
+
const o = new Z({
|
|
415
416
|
network: t.network,
|
|
416
417
|
btcWallet: e
|
|
417
418
|
}), u = r.length;
|
|
418
419
|
n == null || n(0, u);
|
|
419
420
|
let a;
|
|
420
|
-
if (
|
|
421
|
-
a = (await
|
|
421
|
+
if (o.supportsBatchSigning())
|
|
422
|
+
a = (await o.signPayoutTransactionsBatch(
|
|
422
423
|
r.map((l) => K(l, t))
|
|
423
424
|
)).map((l) => l.payoutSignature);
|
|
424
425
|
else {
|
|
425
426
|
a = [];
|
|
426
|
-
for (let
|
|
427
|
-
n == null || n(
|
|
428
|
-
const l = await
|
|
429
|
-
K(r[
|
|
427
|
+
for (let s = 0; s < r.length; s++) {
|
|
428
|
+
n == null || n(s, u);
|
|
429
|
+
const l = await o.signPayoutTransaction(
|
|
430
|
+
K(r[s], t)
|
|
430
431
|
);
|
|
431
432
|
a.push(l.signature);
|
|
432
433
|
}
|
|
433
434
|
}
|
|
434
435
|
const i = {};
|
|
435
|
-
for (let
|
|
436
|
-
i[r[
|
|
437
|
-
payout_signature: a[
|
|
436
|
+
for (let s = 0; s < r.length; s++)
|
|
437
|
+
i[r[s].claimerPubkeyXOnly] = {
|
|
438
|
+
payout_signature: a[s]
|
|
438
439
|
};
|
|
439
440
|
return n == null || n(u, u), i;
|
|
440
441
|
}
|
|
@@ -443,40 +444,40 @@ async function nt(e) {
|
|
|
443
444
|
statusReader: t,
|
|
444
445
|
presignClient: r,
|
|
445
446
|
btcWallet: n,
|
|
446
|
-
peginTxid:
|
|
447
|
+
peginTxid: o,
|
|
447
448
|
depositorPk: u,
|
|
448
449
|
signingContext: a,
|
|
449
450
|
timeoutMs: i = _e,
|
|
450
|
-
signal:
|
|
451
|
+
signal: s,
|
|
451
452
|
onProgress: l
|
|
452
453
|
} = e, d = await D({
|
|
453
454
|
statusReader: t,
|
|
454
|
-
peginTxid:
|
|
455
|
+
peginTxid: o,
|
|
455
456
|
targetStatuses: Ce,
|
|
456
457
|
timeoutMs: i,
|
|
457
|
-
signal:
|
|
458
|
+
signal: s
|
|
458
459
|
});
|
|
459
|
-
if (
|
|
460
|
+
if (L.has(d))
|
|
460
461
|
return;
|
|
461
|
-
|
|
462
|
+
s == null || s.throwIfAborted();
|
|
462
463
|
const c = await r.requestDepositorPresignTransactions(
|
|
463
464
|
{
|
|
464
|
-
pegin_txid:
|
|
465
|
+
pegin_txid: o,
|
|
465
466
|
depositor_pk: u
|
|
466
467
|
},
|
|
467
|
-
|
|
468
|
+
s
|
|
468
469
|
);
|
|
469
|
-
|
|
470
|
+
s == null || s.throwIfAborted();
|
|
470
471
|
const g = k(u), P = c.txs.filter(
|
|
471
|
-
(
|
|
472
|
-
),
|
|
472
|
+
(b) => k(b.claimer_pubkey) !== g
|
|
473
|
+
), p = Se(P), y = await Be(
|
|
473
474
|
n,
|
|
474
475
|
a,
|
|
475
|
-
|
|
476
|
+
p,
|
|
476
477
|
l
|
|
477
478
|
);
|
|
478
|
-
|
|
479
|
-
const
|
|
479
|
+
s == null || s.throwIfAborted();
|
|
480
|
+
const T = await Ee({
|
|
480
481
|
depositorGraph: c.depositor_graph,
|
|
481
482
|
btcWallet: n,
|
|
482
483
|
signingContext: {
|
|
@@ -493,16 +494,16 @@ async function nt(e) {
|
|
|
493
494
|
registeredPayoutScriptPubKey: a.registeredPayoutScriptPubKey
|
|
494
495
|
}
|
|
495
496
|
});
|
|
496
|
-
|
|
497
|
-
const w = { ...
|
|
498
|
-
w[h(u)] =
|
|
497
|
+
s == null || s.throwIfAborted();
|
|
498
|
+
const w = { ...y };
|
|
499
|
+
w[h(u)] = T.payout_signatures, await r.submitDepositorPresignatures(
|
|
499
500
|
{
|
|
500
|
-
pegin_txid:
|
|
501
|
+
pegin_txid: o,
|
|
501
502
|
depositor_pk: u,
|
|
502
503
|
signatures: w,
|
|
503
|
-
depositor_claimer_presignatures:
|
|
504
|
+
depositor_claimer_presignatures: T
|
|
504
505
|
},
|
|
505
|
-
|
|
506
|
+
s
|
|
506
507
|
);
|
|
507
508
|
}
|
|
508
509
|
function Re(e) {
|
|
@@ -513,11 +514,11 @@ function ot(e) {
|
|
|
513
514
|
amountSats: t,
|
|
514
515
|
minDeposit: r,
|
|
515
516
|
maxDeposit: n,
|
|
516
|
-
btcBalance:
|
|
517
|
+
btcBalance: o,
|
|
517
518
|
estimatedFeeSats: u,
|
|
518
519
|
depositorClaimValue: a
|
|
519
520
|
} = e;
|
|
520
|
-
return !(t <= 0n || t < r || n && n > 0n && t > n || u == null || a == null || t + u + a >
|
|
521
|
+
return !(t <= 0n || t < r || n && n > 0n && t > n || u == null || a == null || t + u + a > o);
|
|
521
522
|
}
|
|
522
523
|
function st(e, t, r) {
|
|
523
524
|
return e <= 0n ? {
|
|
@@ -525,10 +526,10 @@ function st(e, t, r) {
|
|
|
525
526
|
error: "Deposit amount must be greater than zero"
|
|
526
527
|
} : e < t ? {
|
|
527
528
|
valid: !1,
|
|
528
|
-
error: `Minimum deposit is ${
|
|
529
|
+
error: `Minimum deposit is ${x(t)} BTC`
|
|
529
530
|
} : r && r > 0n && e > r ? {
|
|
530
531
|
valid: !1,
|
|
531
|
-
error: `Maximum deposit is ${
|
|
532
|
+
error: `Maximum deposit is ${x(r)} BTC`
|
|
532
533
|
} : { valid: !0 };
|
|
533
534
|
}
|
|
534
535
|
function at(e) {
|
|
@@ -538,7 +539,7 @@ function at(e) {
|
|
|
538
539
|
error: "Supply cap reached — deposits temporarily paused"
|
|
539
540
|
} : t > r ? {
|
|
540
541
|
valid: !1,
|
|
541
|
-
error: `Vault size exceeds remaining capacity (${
|
|
542
|
+
error: `Vault size exceeds remaining capacity (${x(r)} BTC)`
|
|
542
543
|
} : { valid: !0 };
|
|
543
544
|
}
|
|
544
545
|
function it(e, t) {
|
|
@@ -548,42 +549,42 @@ function it(e, t) {
|
|
|
548
549
|
error: "At least one vault provider must be selected"
|
|
549
550
|
};
|
|
550
551
|
const r = t.map(
|
|
551
|
-
(
|
|
552
|
+
(o) => o.toLowerCase()
|
|
552
553
|
);
|
|
553
554
|
return e.filter(
|
|
554
|
-
(
|
|
555
|
+
(o) => !r.includes(o.toLowerCase())
|
|
555
556
|
).length > 0 ? {
|
|
556
557
|
valid: !1,
|
|
557
558
|
error: "Invalid vault provider selected"
|
|
558
559
|
} : { valid: !0 };
|
|
559
560
|
}
|
|
560
|
-
function
|
|
561
|
+
function Ve(e, t, r) {
|
|
561
562
|
if (!e || e.length === 0)
|
|
562
563
|
return {
|
|
563
564
|
valid: !1,
|
|
564
565
|
error: "At least one vault amount required"
|
|
565
566
|
};
|
|
566
567
|
for (let n = 0; n < e.length; n++) {
|
|
567
|
-
const
|
|
568
|
-
if (
|
|
568
|
+
const o = e[n];
|
|
569
|
+
if (o <= 0n)
|
|
569
570
|
return {
|
|
570
571
|
valid: !1,
|
|
571
572
|
error: `Vault ${n + 1} amount must be positive`
|
|
572
573
|
};
|
|
573
|
-
if (t &&
|
|
574
|
+
if (t && o < t)
|
|
574
575
|
return {
|
|
575
576
|
valid: !1,
|
|
576
|
-
error: `Vault ${n + 1} amount ${
|
|
577
|
+
error: `Vault ${n + 1} amount ${x(o)} BTC is below minimum deposit ${x(t)} BTC`
|
|
577
578
|
};
|
|
578
|
-
if (r &&
|
|
579
|
+
if (r && o > r)
|
|
579
580
|
return {
|
|
580
581
|
valid: !1,
|
|
581
|
-
error: `Vault ${n + 1} amount ${
|
|
582
|
+
error: `Vault ${n + 1} amount ${x(o)} BTC exceeds maximum deposit ${x(r)} BTC`
|
|
582
583
|
};
|
|
583
584
|
}
|
|
584
585
|
return { valid: !0 };
|
|
585
586
|
}
|
|
586
|
-
function
|
|
587
|
+
function $e(e) {
|
|
587
588
|
const t = h(e);
|
|
588
589
|
return Re(t) ? { valid: !0 } : {
|
|
589
590
|
valid: !1,
|
|
@@ -611,38 +612,38 @@ function ut(e) {
|
|
|
611
612
|
vaultAmounts: t,
|
|
612
613
|
confirmedUTXOs: r,
|
|
613
614
|
vaultProviderBtcPubkey: n,
|
|
614
|
-
vaultKeeperBtcPubkeys:
|
|
615
|
+
vaultKeeperBtcPubkeys: o,
|
|
615
616
|
universalChallengerBtcPubkeys: u,
|
|
616
617
|
minDeposit: a,
|
|
617
618
|
maxDeposit: i
|
|
618
|
-
} = e,
|
|
619
|
+
} = e, s = Ve(
|
|
619
620
|
t,
|
|
620
621
|
a,
|
|
621
622
|
i
|
|
622
623
|
);
|
|
623
|
-
if (!
|
|
624
|
-
throw new Error(
|
|
625
|
-
const l =
|
|
624
|
+
if (!s.valid)
|
|
625
|
+
throw new Error(s.error);
|
|
626
|
+
const l = $e(n);
|
|
626
627
|
if (!l.valid)
|
|
627
628
|
throw new Error(l.error);
|
|
628
|
-
Ie(
|
|
629
|
+
Ie(o), He(u), Ke(r);
|
|
629
630
|
}
|
|
630
631
|
async function lt(e) {
|
|
631
632
|
const {
|
|
632
633
|
vaultRegistryReader: t,
|
|
633
634
|
vaultKeeperReader: r,
|
|
634
635
|
universalChallengerReader: n,
|
|
635
|
-
vaultProviderEthAddress:
|
|
636
|
+
vaultProviderEthAddress: o,
|
|
636
637
|
applicationEntryPoint: u,
|
|
637
638
|
expectedVaultProviderBtcPubkey: a,
|
|
638
639
|
expectedVaultKeeperBtcPubkeys: i,
|
|
639
|
-
expectedUniversalChallengerBtcPubkeys:
|
|
640
|
+
expectedUniversalChallengerBtcPubkeys: s
|
|
640
641
|
} = e, [
|
|
641
642
|
l,
|
|
642
643
|
d,
|
|
643
644
|
c
|
|
644
645
|
] = await Promise.all([
|
|
645
|
-
t.getVaultProviderBtcPubKey(
|
|
646
|
+
t.getVaultProviderBtcPubKey(o),
|
|
646
647
|
r.getCurrentVaultKeepersVersion(u),
|
|
647
648
|
n.getLatestUniversalChallengersVersion()
|
|
648
649
|
]), [g, P] = await Promise.all([
|
|
@@ -653,29 +654,29 @@ async function lt(e) {
|
|
|
653
654
|
n.getUniversalChallengersByVersion(
|
|
654
655
|
c
|
|
655
656
|
)
|
|
656
|
-
]),
|
|
657
|
-
if (
|
|
657
|
+
]), p = (f) => k(f).toLowerCase(), y = (f) => f.map(p).sort();
|
|
658
|
+
if (p(a) !== l)
|
|
658
659
|
throw new Error(
|
|
659
|
-
`Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${
|
|
660
|
+
`Vault provider BTC pubkey indexer hint does not match BTCVaultRegistry for ${o}. Refresh and try again.`
|
|
660
661
|
);
|
|
661
|
-
const w =
|
|
662
|
-
g.map((
|
|
662
|
+
const w = y(i), b = y(
|
|
663
|
+
g.map((f) => f.btcPubKey)
|
|
663
664
|
);
|
|
664
|
-
if (w.length !==
|
|
665
|
+
if (w.length !== b.length || w.some((f, C) => f !== b[C]))
|
|
665
666
|
throw new Error(
|
|
666
667
|
`Vault keeper BTC pubkeys (v${d}) indexer set does not match ApplicationRegistry on-chain set. Refresh and try again.`
|
|
667
668
|
);
|
|
668
|
-
const
|
|
669
|
-
P.map((
|
|
669
|
+
const E = y(s), m = y(
|
|
670
|
+
P.map((f) => f.btcPubKey)
|
|
670
671
|
);
|
|
671
|
-
if (
|
|
672
|
+
if (E.length !== m.length || E.some((f, C) => f !== m[C]))
|
|
672
673
|
throw new Error(
|
|
673
674
|
`Universal challenger BTC pubkeys (v${c}) indexer set does not match ProtocolParams on-chain set. Refresh and try again.`
|
|
674
675
|
);
|
|
675
676
|
return {
|
|
676
677
|
vaultProviderBtcPubkeyXOnly: l,
|
|
677
|
-
vaultKeeperBtcPubkeysSorted:
|
|
678
|
-
universalChallengerBtcPubkeysSorted:
|
|
678
|
+
vaultKeeperBtcPubkeysSorted: b,
|
|
679
|
+
universalChallengerBtcPubkeysSorted: m,
|
|
679
680
|
expectedAppVaultKeepersVersion: d,
|
|
680
681
|
expectedUniversalChallengersVersion: c
|
|
681
682
|
};
|
|
@@ -693,83 +694,83 @@ async function dt(e) {
|
|
|
693
694
|
vaultRegistryReader: t,
|
|
694
695
|
vaultIds: r,
|
|
695
696
|
expectedOffchainParamsVersion: n,
|
|
696
|
-
expectedAppVaultKeepersVersion:
|
|
697
|
+
expectedAppVaultKeepersVersion: o,
|
|
697
698
|
expectedUniversalChallengersVersion: u
|
|
698
699
|
} = e, a = await t.getProtocolInfoBatch(r), i = [];
|
|
699
|
-
if (a.forEach((
|
|
700
|
+
if (a.forEach((s, l) => {
|
|
700
701
|
const d = r[l];
|
|
701
|
-
|
|
702
|
-
`vault ${d}: offchainParams expected v${n}, got v${
|
|
703
|
-
),
|
|
704
|
-
`vault ${d}: appVaultKeepers expected v${
|
|
705
|
-
),
|
|
706
|
-
`vault ${d}: universalChallengers expected v${u}, got v${
|
|
702
|
+
s.offchainParamsVersion !== n && i.push(
|
|
703
|
+
`vault ${d}: offchainParams expected v${n}, got v${s.offchainParamsVersion}`
|
|
704
|
+
), s.appVaultKeepersVersion !== o && i.push(
|
|
705
|
+
`vault ${d}: appVaultKeepers expected v${o}, got v${s.appVaultKeepersVersion}`
|
|
706
|
+
), s.universalChallengersVersion !== u && i.push(
|
|
707
|
+
`vault ${d}: universalChallengers expected v${u}, got v${s.universalChallengersVersion}`
|
|
707
708
|
);
|
|
708
709
|
}), i.length > 0)
|
|
709
710
|
throw new U(
|
|
710
711
|
`Aborting BTC broadcast: signer-set or offchain-params versions changed during registration (${i.join("; ")}). The Pre-PegIn was not broadcast; the registered ETH vault will time out per protocol rules.`
|
|
711
712
|
);
|
|
712
713
|
}
|
|
713
|
-
var
|
|
714
|
-
const
|
|
714
|
+
var M = /* @__PURE__ */ ((e) => (e.CLAIM_EVENT_RECEIVED = "ClaimEventReceived", e.CLAIM_BROADCAST = "ClaimBroadcast", e.ASSERT_BROADCAST = "AssertBroadcast", e.PAYOUT_BROADCAST = "PayoutBroadcast", e.PAYOUT_BLOCKED = "PayoutBlocked", e))(M || {});
|
|
715
|
+
const Ne = /* @__PURE__ */ new Set([
|
|
715
716
|
"PayoutBroadcast",
|
|
716
|
-
"
|
|
717
|
-
/*
|
|
717
|
+
"PayoutBlocked"
|
|
718
|
+
/* PAYOUT_BLOCKED */
|
|
718
719
|
]);
|
|
719
720
|
function ht(e) {
|
|
720
|
-
return Object.values(
|
|
721
|
+
return Object.values(M).includes(
|
|
721
722
|
e
|
|
722
723
|
);
|
|
723
724
|
}
|
|
724
725
|
function pt(e) {
|
|
725
|
-
return !!e &&
|
|
726
|
+
return !!e && Ne.has(e);
|
|
726
727
|
}
|
|
727
|
-
class
|
|
728
|
+
class Oe extends Error {
|
|
728
729
|
constructor(r, n) {
|
|
729
730
|
super(`Refund not yet mature (BIP68 not final): ${n.message}`);
|
|
730
|
-
|
|
731
|
-
|
|
731
|
+
S(this, "vaultId");
|
|
732
|
+
S(this, "cause");
|
|
732
733
|
this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = n;
|
|
733
734
|
}
|
|
734
735
|
}
|
|
735
|
-
const
|
|
736
|
-
function
|
|
736
|
+
const De = /^0x[0-9a-fA-F]{64}$/, Le = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, F = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, X = 160;
|
|
737
|
+
function ft(e) {
|
|
737
738
|
if (!Number.isFinite(e) || e <= 0)
|
|
738
739
|
throw new Error(
|
|
739
740
|
`feeRateSatsVb must be a positive finite number, got ${e}`
|
|
740
741
|
);
|
|
741
|
-
return BigInt(Math.ceil(e *
|
|
742
|
+
return BigInt(Math.ceil(e * X));
|
|
742
743
|
}
|
|
743
|
-
const
|
|
744
|
-
function
|
|
744
|
+
const Ue = 1, Me = /non-BIP68-final/i;
|
|
745
|
+
function z(e, t) {
|
|
745
746
|
if (e.length !== 66)
|
|
746
747
|
throw new Error(
|
|
747
748
|
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
748
749
|
);
|
|
749
|
-
if (!
|
|
750
|
+
if (!De.test(e))
|
|
750
751
|
throw new Error(
|
|
751
752
|
`${t} must contain only hex characters after the 0x prefix`
|
|
752
753
|
);
|
|
753
754
|
}
|
|
754
|
-
function
|
|
755
|
+
function R(e, t) {
|
|
755
756
|
if (!Number.isInteger(e) || e < 0)
|
|
756
757
|
throw new Error(`${t} must be a non-negative integer, got ${e}`);
|
|
757
758
|
}
|
|
758
759
|
function Fe(e) {
|
|
759
|
-
if (
|
|
760
|
+
if (z(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout !== 0)
|
|
760
761
|
throw new Error(
|
|
761
|
-
`
|
|
762
|
+
`Multi-vault Pre-PegIn refund is not supported by this SDK call (htlcVout=${e.htlcVout}, expected 0). Refund of batched-deposit vaults requires reconstructing all sibling HTLCs.`
|
|
762
763
|
);
|
|
763
|
-
if (
|
|
764
|
+
if (R(e.offchainParamsVersion, "offchainParamsVersion"), R(e.appVaultKeepersVersion, "appVaultKeepersVersion"), R(
|
|
764
765
|
e.universalChallengersVersion,
|
|
765
766
|
"universalChallengersVersion"
|
|
766
767
|
), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
|
|
767
768
|
throw new Error("unsignedPrePeginTxHex must be a non-empty hex string");
|
|
768
|
-
if (!
|
|
769
|
+
if (!Le.test(e.unsignedPrePeginTxHex))
|
|
769
770
|
throw new Error(
|
|
770
771
|
"unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
|
|
771
772
|
);
|
|
772
|
-
if (!e.depositorBtcPubkey || !
|
|
773
|
+
if (!e.depositorBtcPubkey || !F.test(e.depositorBtcPubkey))
|
|
773
774
|
throw new Error(
|
|
774
775
|
"depositorBtcPubkey must be 32 or 33 bytes of hex (optional 0x prefix)"
|
|
775
776
|
);
|
|
@@ -777,7 +778,7 @@ function Fe(e) {
|
|
|
777
778
|
throw new Error(`amount must be a positive bigint, got ${e.amount}`);
|
|
778
779
|
}
|
|
779
780
|
function Xe(e) {
|
|
780
|
-
if (!e.vaultProviderPubkey || !
|
|
781
|
+
if (!e.vaultProviderPubkey || !F.test(e.vaultProviderPubkey))
|
|
781
782
|
throw new Error("vaultProviderPubkey must be 32 or 33 bytes of hex");
|
|
782
783
|
if (e.vaultKeeperPubkeys.length === 0)
|
|
783
784
|
throw new Error("vaultKeeperPubkeys must be non-empty");
|
|
@@ -809,77 +810,83 @@ function ze(e) {
|
|
|
809
810
|
}
|
|
810
811
|
return t.extractTransaction().toHex();
|
|
811
812
|
}
|
|
812
|
-
async function
|
|
813
|
+
async function gt(e) {
|
|
813
814
|
const {
|
|
814
815
|
vaultId: t,
|
|
815
816
|
readVault: r,
|
|
816
817
|
readPrePeginContext: n,
|
|
817
|
-
feeRate:
|
|
818
|
+
feeRate: o,
|
|
818
819
|
signPsbt: u,
|
|
819
820
|
broadcastTx: a,
|
|
820
821
|
signal: i
|
|
821
822
|
} = e;
|
|
822
|
-
i == null || i.throwIfAborted(),
|
|
823
|
-
const
|
|
824
|
-
Fe(
|
|
825
|
-
const l = await n(
|
|
826
|
-
if (Xe(l), i == null || i.throwIfAborted(), !Number.isFinite(
|
|
827
|
-
throw new Error(`feeRate must be a positive number, got ${
|
|
828
|
-
const d = BigInt(Math.ceil(
|
|
823
|
+
i == null || i.throwIfAborted(), z(t, "vaultId");
|
|
824
|
+
const s = await r();
|
|
825
|
+
Fe(s), i == null || i.throwIfAborted();
|
|
826
|
+
const l = await n(s);
|
|
827
|
+
if (Xe(l), i == null || i.throwIfAborted(), !Number.isFinite(o) || o <= 0)
|
|
828
|
+
throw new Error(`feeRate must be a positive number, got ${o}`);
|
|
829
|
+
const d = BigInt(Math.ceil(o * X));
|
|
829
830
|
i == null || i.throwIfAborted();
|
|
830
831
|
const c = k(
|
|
831
|
-
|
|
832
|
-
),
|
|
832
|
+
s.depositorBtcPubkey
|
|
833
|
+
), g = h(s.unsignedPrePeginTxHex), P = 1, p = ee(g);
|
|
834
|
+
if (p !== void 0 && p.vout !== P)
|
|
835
|
+
throw new Error(
|
|
836
|
+
`Multi-vault Pre-PegIn refund is not supported by this SDK call (auth-anchor OP_RETURN at vout ${p.vout}; single-vault refund expects vout ${P}). Refund of batched-deposit vaults requires reconstructing all sibling HTLCs.`
|
|
837
|
+
);
|
|
838
|
+
const y = p == null ? void 0 : p.hash, { psbtHex: T } = await le({
|
|
833
839
|
prePeginParams: {
|
|
834
840
|
depositorPubkey: c,
|
|
835
841
|
vaultProviderPubkey: h(l.vaultProviderPubkey),
|
|
836
842
|
vaultKeeperPubkeys: l.vaultKeeperPubkeys.map(h),
|
|
837
843
|
universalChallengerPubkeys: l.universalChallengerPubkeys.map(h),
|
|
838
|
-
hashlocks: [h(
|
|
844
|
+
hashlocks: [h(s.hashlock)],
|
|
839
845
|
timelockRefund: l.timelockRefund,
|
|
840
|
-
pegInAmounts: [
|
|
846
|
+
pegInAmounts: [s.amount],
|
|
841
847
|
feeRate: l.feeRate,
|
|
842
848
|
numLocalChallengers: l.numLocalChallengers,
|
|
843
849
|
councilQuorum: l.councilQuorum,
|
|
844
850
|
councilSize: l.councilSize,
|
|
845
|
-
network: l.network
|
|
851
|
+
network: l.network,
|
|
852
|
+
authAnchorHash: y
|
|
846
853
|
},
|
|
847
|
-
fundedPrePeginTxHex:
|
|
848
|
-
htlcVout:
|
|
854
|
+
fundedPrePeginTxHex: g,
|
|
855
|
+
htlcVout: s.htlcVout,
|
|
849
856
|
refundFee: d,
|
|
850
857
|
// buildRefundPsbt's top-level `hashlock` param is documented as "no 0x
|
|
851
858
|
// prefix" and flows into the WASM HTLC connector derivation; a prefixed
|
|
852
859
|
// value would derive the wrong refund script leaf and yield an
|
|
853
860
|
// unspendable PSBT. Match the `hashlocks` array handling above.
|
|
854
|
-
hashlock: h(
|
|
861
|
+
hashlock: h(s.hashlock)
|
|
855
862
|
});
|
|
856
863
|
i == null || i.throwIfAborted();
|
|
857
|
-
const
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
), b = await u(
|
|
861
|
-
|
|
862
|
-
requestedPsbtHex:
|
|
864
|
+
const w = $(
|
|
865
|
+
s.depositorBtcPubkey,
|
|
866
|
+
Ue
|
|
867
|
+
), b = await u(T, w);
|
|
868
|
+
V({
|
|
869
|
+
requestedPsbtHex: T,
|
|
863
870
|
returnedPsbtHex: b
|
|
864
871
|
});
|
|
865
|
-
const
|
|
872
|
+
const E = ze(b);
|
|
866
873
|
i == null || i.throwIfAborted();
|
|
867
874
|
try {
|
|
868
|
-
return await a(
|
|
869
|
-
} catch (
|
|
870
|
-
throw
|
|
875
|
+
return await a(E);
|
|
876
|
+
} catch (m) {
|
|
877
|
+
throw m instanceof Error && Me.test(m.message) ? new Oe(t, m) : m;
|
|
871
878
|
}
|
|
872
879
|
}
|
|
873
880
|
export {
|
|
874
|
-
|
|
875
|
-
|
|
881
|
+
Oe as B,
|
|
882
|
+
M as C,
|
|
876
883
|
U as R,
|
|
877
884
|
tt as a,
|
|
878
885
|
Ee as b,
|
|
879
886
|
at as c,
|
|
880
887
|
it as d,
|
|
881
|
-
|
|
882
|
-
|
|
888
|
+
Ve as e,
|
|
889
|
+
$e as f,
|
|
883
890
|
ut as g,
|
|
884
891
|
lt as h,
|
|
885
892
|
ot as i,
|
|
@@ -887,12 +894,12 @@ export {
|
|
|
887
894
|
dt as k,
|
|
888
895
|
ht as l,
|
|
889
896
|
pt as m,
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
897
|
+
gt as n,
|
|
898
|
+
ft as o,
|
|
899
|
+
X as p,
|
|
893
900
|
nt as r,
|
|
894
901
|
rt as s,
|
|
895
902
|
st as v,
|
|
896
903
|
D as w
|
|
897
904
|
};
|
|
898
|
-
//# sourceMappingURL=buildAndBroadcastRefund-
|
|
905
|
+
//# sourceMappingURL=buildAndBroadcastRefund-B5cOyUzj.js.map
|