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