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