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