@babylonlabs-io/ts-sdk 0.29.0 → 0.30.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/{PeginManager-DcjXiKYC.cjs → PeginManager-Zrv-ncJi.cjs} +2 -2
- package/dist/{PeginManager-DcjXiKYC.cjs.map → PeginManager-Zrv-ncJi.cjs.map} +1 -1
- package/dist/{PeginManager-Dj6oDaH5.js → PeginManager-_pamUKlS.js} +3 -3
- package/dist/{PeginManager-Dj6oDaH5.js.map → PeginManager-_pamUKlS.js.map} +1 -1
- package/dist/{buildAndBroadcastRefund-xWS8frc6.js → buildAndBroadcastRefund-BY6mYmFl.js} +406 -303
- package/dist/buildAndBroadcastRefund-BY6mYmFl.js.map +1 -0
- package/dist/buildAndBroadcastRefund-CO60ReNf.cjs +2 -0
- package/dist/buildAndBroadcastRefund-CO60ReNf.cjs.map +1 -0
- package/dist/challengeAssert-mYikGC34.js +269 -0
- package/dist/challengeAssert-mYikGC34.js.map +1 -0
- package/dist/challengeAssert-yYFflBOx.cjs +2 -0
- package/dist/challengeAssert-yYFflBOx.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +144 -143
- package/dist/noPayout-B8JiTaYt.js +333 -0
- package/dist/noPayout-B8JiTaYt.js.map +1 -0
- package/dist/noPayout-CwgYkZYs.cjs +2 -0
- package/dist/noPayout-CwgYkZYs.cjs.map +1 -0
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.js +145 -144
- package/dist/tbv/core/managers/PayoutManager.d.ts.map +1 -1
- 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 +26 -25
- package/dist/tbv/core/primitives/psbt/noPayout.d.ts +18 -1
- package/dist/tbv/core/primitives/psbt/noPayout.d.ts.map +1 -1
- package/dist/tbv/core/primitives/psbt/payout.d.ts +15 -0
- package/dist/tbv/core/primitives/psbt/payout.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/index.d.ts +1 -1
- package/dist/tbv/core/services/deposit/index.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/signAndSubmitPayouts.d.ts +21 -0
- package/dist/tbv/core/services/deposit/signAndSubmitPayouts.d.ts.map +1 -1
- package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts +50 -4
- package/dist/tbv/core/services/deposit/signDepositorGraph.d.ts.map +1 -1
- package/dist/tbv/core/services/index.cjs +1 -1
- package/dist/tbv/core/services/index.js +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +145 -144
- package/package.json +1 -1
- package/dist/buildAndBroadcastRefund-DkEpTFkv.cjs +0 -2
- package/dist/buildAndBroadcastRefund-DkEpTFkv.cjs.map +0 -1
- package/dist/buildAndBroadcastRefund-xWS8frc6.js.map +0 -1
- package/dist/challengeAssert-BM8m9gPM.cjs +0 -2
- package/dist/challengeAssert-BM8m9gPM.cjs.map +0 -1
- package/dist/challengeAssert-j2Vwqo0-.js +0 -304
- package/dist/challengeAssert-j2Vwqo0-.js.map +0 -1
- package/dist/payout-B_fvQU3q.js +0 -261
- package/dist/payout-B_fvQU3q.js.map +0 -1
- package/dist/payout-DP6KMFP1.cjs +0 -2
- package/dist/payout-DP6KMFP1.cjs.map +0 -1
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { B as
|
|
5
|
-
import { e as
|
|
1
|
+
var z = Object.defineProperty;
|
|
2
|
+
var G = (e, t, r) => t in e ? z(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var x = (e, t, r) => G(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { B as Q, c as Y, a as j, R as q, d as O, D as y } from "./types-CnG3JsRs.js";
|
|
5
|
+
import { e as J, s as c, u as K, v as H, p as m, f } from "./bitcoin-B-Y0DlqR.js";
|
|
6
6
|
import { s as Z } from "./sha2-6wN58S6R.js";
|
|
7
7
|
import * as ee from "bitcoinjs-lib";
|
|
8
|
-
import {
|
|
9
|
-
import { Buffer as
|
|
8
|
+
import { Transaction as w, Psbt as te } from "bitcoinjs-lib";
|
|
9
|
+
import { Buffer as re } from "buffer";
|
|
10
10
|
import { c as b } from "./signing-BZigafm0.js";
|
|
11
11
|
import "@babylonlabs-io/babylon-tbv-rust-wasm";
|
|
12
|
-
import { e as
|
|
13
|
-
const
|
|
12
|
+
import { a as V, c as S, e as v, g as oe, d as ne, b as se } from "./noPayout-B8JiTaYt.js";
|
|
13
|
+
const $ = 66;
|
|
14
14
|
function L(e) {
|
|
15
15
|
if (!e.startsWith("0x") && !e.startsWith("0X"))
|
|
16
16
|
throw new Error("Expected 0x-prefixed hex string");
|
|
@@ -24,201 +24,300 @@ function L(e) {
|
|
|
24
24
|
r[o] = parseInt(t.slice(o * 2, o * 2 + 2), 16);
|
|
25
25
|
return r;
|
|
26
26
|
}
|
|
27
|
-
function
|
|
27
|
+
function ie(e) {
|
|
28
28
|
return `0x${Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("")}`;
|
|
29
29
|
}
|
|
30
|
-
function
|
|
31
|
-
if (e.length !==
|
|
30
|
+
function A(e, t) {
|
|
31
|
+
if (e.length !== $)
|
|
32
32
|
throw new Error(
|
|
33
|
-
`${t} must be exactly 32 bytes (${
|
|
33
|
+
`${t} must be exactly 32 bytes (${$} hex chars with 0x prefix), got ${e.length}`
|
|
34
34
|
);
|
|
35
35
|
}
|
|
36
|
-
function
|
|
37
|
-
|
|
36
|
+
function ae(e) {
|
|
37
|
+
A(e, "Secret");
|
|
38
38
|
const t = L(e), r = Z(t);
|
|
39
|
-
return
|
|
39
|
+
return ie(r);
|
|
40
40
|
}
|
|
41
|
-
function
|
|
42
|
-
return
|
|
41
|
+
function ue(e, t) {
|
|
42
|
+
return A(e, "Secret"), A(t, "Hashlock"), L(t), ae(e).toLowerCase() === t.toLowerCase();
|
|
43
43
|
}
|
|
44
|
-
const
|
|
44
|
+
const le = /^0x[0-9a-fA-F]{64}$/, ce = /^0x[0-9a-fA-F]{40}$/, de = /^0x([0-9a-fA-F]{2})*$/;
|
|
45
45
|
function E(e, t) {
|
|
46
46
|
if (e.length !== 66)
|
|
47
47
|
throw new Error(
|
|
48
48
|
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
49
49
|
);
|
|
50
|
-
if (!
|
|
50
|
+
if (!le.test(e))
|
|
51
51
|
throw new Error(
|
|
52
52
|
`${t} must contain only hex characters after the 0x prefix`
|
|
53
53
|
);
|
|
54
54
|
}
|
|
55
|
-
function
|
|
56
|
-
if (!
|
|
55
|
+
function he(e, t) {
|
|
56
|
+
if (!ce.test(e))
|
|
57
57
|
throw new Error(
|
|
58
58
|
`${t} must be a 20-byte 0x-prefixed hex address (42 chars)`
|
|
59
59
|
);
|
|
60
60
|
}
|
|
61
|
-
function
|
|
62
|
-
if (!
|
|
61
|
+
function pe(e, t) {
|
|
62
|
+
if (!de.test(e))
|
|
63
63
|
throw new Error(
|
|
64
64
|
`${t} must be a 0x-prefixed hex string with an even number of hex chars`
|
|
65
65
|
);
|
|
66
66
|
}
|
|
67
|
-
async function
|
|
67
|
+
async function rt(e) {
|
|
68
68
|
const {
|
|
69
69
|
btcVaultRegistryAddress: t,
|
|
70
70
|
vaultId: r,
|
|
71
71
|
hashlock: o,
|
|
72
72
|
activationMetadata: i,
|
|
73
|
-
writeContract:
|
|
74
|
-
signal:
|
|
73
|
+
writeContract: u,
|
|
74
|
+
signal: s
|
|
75
75
|
} = e;
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
if (E(
|
|
76
|
+
s == null || s.throwIfAborted(), he(t, "btcVaultRegistryAddress"), E(r, "vaultId");
|
|
77
|
+
const a = J(e.secret);
|
|
78
|
+
if (E(a, "secret"), o !== void 0 && (E(o, "hashlock"), !ue(a, o)))
|
|
79
79
|
throw new Error(
|
|
80
80
|
"Invalid secret: SHA256(secret) does not match the provided hashlock"
|
|
81
81
|
);
|
|
82
|
-
return
|
|
82
|
+
return pe(i, "activationMetadata"), u({
|
|
83
83
|
address: t,
|
|
84
|
-
abi:
|
|
84
|
+
abi: Q,
|
|
85
85
|
functionName: "activateVaultWithSecret",
|
|
86
|
-
args: [r,
|
|
86
|
+
args: [r, a, i]
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
|
-
const
|
|
89
|
+
const fe = 1e4;
|
|
90
90
|
async function D(e) {
|
|
91
91
|
const {
|
|
92
92
|
statusReader: t,
|
|
93
93
|
peginTxid: r,
|
|
94
94
|
targetStatuses: o,
|
|
95
95
|
timeoutMs: i,
|
|
96
|
-
pollIntervalMs:
|
|
97
|
-
signal:
|
|
98
|
-
} = e,
|
|
96
|
+
pollIntervalMs: u = fe,
|
|
97
|
+
signal: s
|
|
98
|
+
} = e, a = Date.now();
|
|
99
99
|
for (; ; ) {
|
|
100
|
-
if (
|
|
100
|
+
if (s != null && s.aborted)
|
|
101
101
|
throw new Error(
|
|
102
102
|
`Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...o].join(", ")})`
|
|
103
103
|
);
|
|
104
|
-
if (Date.now() -
|
|
104
|
+
if (Date.now() - a >= i)
|
|
105
105
|
throw new Error(
|
|
106
106
|
`Polling timeout after ${i}ms for pegin ${r.slice(0, 8)}… (target: ${[...o].join(", ")})`
|
|
107
107
|
);
|
|
108
108
|
try {
|
|
109
|
-
const
|
|
109
|
+
const l = (await t.getPeginStatus(
|
|
110
110
|
{ pegin_txid: r },
|
|
111
|
-
|
|
111
|
+
s
|
|
112
112
|
)).status;
|
|
113
|
-
if (o.has(
|
|
114
|
-
return
|
|
115
|
-
if (Y.has(
|
|
113
|
+
if (o.has(l))
|
|
114
|
+
return l;
|
|
115
|
+
if (Y.has(l) && !o.has(l))
|
|
116
116
|
throw new Error(
|
|
117
|
-
`Pegin ${r.slice(0, 8)}… reached terminal status "${
|
|
117
|
+
`Pegin ${r.slice(0, 8)}… reached terminal status "${l}" while waiting for ${[...o].join(", ")}`
|
|
118
118
|
);
|
|
119
119
|
} catch (n) {
|
|
120
120
|
if (!(n instanceof j && n.code === q.NOT_FOUND || n instanceof Error && n.message.includes("PegIn not found")))
|
|
121
121
|
throw n;
|
|
122
122
|
}
|
|
123
|
-
await new Promise((n,
|
|
123
|
+
await new Promise((n, l) => {
|
|
124
124
|
const d = () => {
|
|
125
|
-
clearTimeout(h),
|
|
125
|
+
clearTimeout(h), l(
|
|
126
126
|
new Error(
|
|
127
127
|
`Polling aborted for pegin ${r.slice(0, 8)}… (target: ${[...o].join(", ")})`
|
|
128
128
|
)
|
|
129
129
|
);
|
|
130
130
|
}, h = setTimeout(() => {
|
|
131
|
-
|
|
132
|
-
},
|
|
133
|
-
|
|
131
|
+
s == null || s.removeEventListener("abort", d), n();
|
|
132
|
+
}, u);
|
|
133
|
+
s == null || s.addEventListener("abort", d, { once: !0 });
|
|
134
134
|
});
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
...
|
|
137
|
+
const ge = 300 * 1e3, Pe = /* @__PURE__ */ new Set([
|
|
138
|
+
y.PENDING_DEPOSITOR_WOTS_PK,
|
|
139
|
+
...O
|
|
140
140
|
]);
|
|
141
|
-
async function
|
|
141
|
+
async function ot(e) {
|
|
142
142
|
const {
|
|
143
143
|
statusReader: t,
|
|
144
144
|
wotsSubmitter: r,
|
|
145
145
|
peginTxid: o,
|
|
146
146
|
depositorPk: i,
|
|
147
|
-
wotsPublicKeys:
|
|
148
|
-
timeoutMs:
|
|
149
|
-
signal:
|
|
147
|
+
wotsPublicKeys: u,
|
|
148
|
+
timeoutMs: s = ge,
|
|
149
|
+
signal: a
|
|
150
150
|
} = e;
|
|
151
|
-
|
|
151
|
+
a == null || a.throwIfAborted();
|
|
152
152
|
const n = await D({
|
|
153
153
|
statusReader: t,
|
|
154
154
|
peginTxid: o,
|
|
155
|
-
targetStatuses:
|
|
156
|
-
timeoutMs:
|
|
157
|
-
signal:
|
|
155
|
+
targetStatuses: Pe,
|
|
156
|
+
timeoutMs: s,
|
|
157
|
+
signal: a
|
|
158
158
|
});
|
|
159
|
-
|
|
159
|
+
O.has(n) || (a == null || a.throwIfAborted(), await r.submitDepositorWotsKey(
|
|
160
160
|
{
|
|
161
161
|
pegin_txid: o,
|
|
162
162
|
depositor_pk: i,
|
|
163
|
-
wots_public_keys:
|
|
163
|
+
wots_public_keys: u
|
|
164
164
|
},
|
|
165
|
-
|
|
165
|
+
a
|
|
166
166
|
));
|
|
167
167
|
}
|
|
168
|
-
const
|
|
169
|
-
function
|
|
170
|
-
const o =
|
|
171
|
-
|
|
168
|
+
const I = 1;
|
|
169
|
+
function ye(e, t, r) {
|
|
170
|
+
const o = c(r).toLowerCase(), u = [e, ...t].map(
|
|
171
|
+
(s) => c(s).toLowerCase()
|
|
172
|
+
).filter((s) => s !== o);
|
|
173
|
+
if (u.length === 0)
|
|
172
174
|
throw new Error(
|
|
173
|
-
|
|
175
|
+
"Cannot derive localChallengers: removing depositor from {vaultProvider, vaultKeepers} left an empty set"
|
|
174
176
|
);
|
|
175
|
-
return
|
|
177
|
+
return u;
|
|
176
178
|
}
|
|
177
|
-
function
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
delete r.tapBip32Derivation, delete r.tapMerkleRoot;
|
|
181
|
-
return t;
|
|
179
|
+
function be(e, t) {
|
|
180
|
+
const r = e.ins[t];
|
|
181
|
+
return K(new Uint8Array(r.hash).slice().reverse());
|
|
182
182
|
}
|
|
183
|
-
function
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
183
|
+
function _(e, t, r, o, i) {
|
|
184
|
+
const u = e.ins[t];
|
|
185
|
+
if (u.index !== 0)
|
|
186
|
+
throw new Error(
|
|
187
|
+
`NoPayout (challenger ${i}) input ${t} expected to spend ${o} vout 0, got vout ${u.index}`
|
|
188
|
+
);
|
|
189
|
+
const s = r.getId(), a = be(e, t);
|
|
190
|
+
if (a !== s)
|
|
191
|
+
throw new Error(
|
|
192
|
+
`NoPayout (challenger ${i}) input ${t} does not reference ${o} (expected txid ${s}, got ${a})`
|
|
193
|
+
);
|
|
188
194
|
}
|
|
189
|
-
function
|
|
190
|
-
const
|
|
191
|
-
|
|
195
|
+
async function xe(e, t, r) {
|
|
196
|
+
const o = [], i = [], u = [];
|
|
197
|
+
V(
|
|
192
198
|
e.payout_tx.tx_hex,
|
|
193
|
-
|
|
199
|
+
r.registeredPayoutScriptPubKey
|
|
200
|
+
);
|
|
201
|
+
const s = await S({
|
|
202
|
+
payoutTxHex: e.payout_tx.tx_hex,
|
|
203
|
+
peginTxHex: r.peginTxHex,
|
|
204
|
+
assertTxHex: e.assert_tx.tx_hex,
|
|
205
|
+
depositorBtcPubkey: r.depositorBtcPubkey,
|
|
206
|
+
vaultProviderBtcPubkey: r.vaultProviderBtcPubkey,
|
|
207
|
+
vaultKeeperBtcPubkeys: r.vaultKeeperBtcPubkeys,
|
|
208
|
+
universalChallengerBtcPubkeys: r.universalChallengerBtcPubkeys,
|
|
209
|
+
timelockPegin: r.timelockPegin,
|
|
210
|
+
network: r.network
|
|
211
|
+
});
|
|
212
|
+
o.push(s.psbtHex), i.push(
|
|
213
|
+
b(
|
|
214
|
+
t,
|
|
215
|
+
I
|
|
216
|
+
)
|
|
194
217
|
);
|
|
195
|
-
|
|
196
|
-
|
|
218
|
+
const a = ye(
|
|
219
|
+
r.vaultProviderBtcPubkey,
|
|
220
|
+
r.vaultKeeperBtcPubkeys,
|
|
221
|
+
r.depositorBtcPubkey
|
|
222
|
+
), n = c(r.depositorBtcPubkey), l = w.fromHex(
|
|
223
|
+
c(e.assert_tx.tx_hex)
|
|
197
224
|
);
|
|
198
|
-
for (const
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
)
|
|
207
|
-
|
|
208
|
-
|
|
225
|
+
for (const d of e.challenger_presign_data) {
|
|
226
|
+
const h = c(d.challenger_pubkey), g = o.length, P = await we({
|
|
227
|
+
challenger: d,
|
|
228
|
+
challengerPubkey: h,
|
|
229
|
+
claimerPubkey: n,
|
|
230
|
+
localChallengers: a,
|
|
231
|
+
assertTxParsed: l,
|
|
232
|
+
ctx: r
|
|
233
|
+
});
|
|
234
|
+
o.push(P), i.push(
|
|
235
|
+
b(
|
|
236
|
+
t,
|
|
237
|
+
I
|
|
238
|
+
)
|
|
239
|
+
), u.push({
|
|
240
|
+
challengerPubkey: h,
|
|
241
|
+
noPayoutIdx: g
|
|
209
242
|
});
|
|
210
243
|
}
|
|
211
|
-
return { psbtHexes:
|
|
244
|
+
return { psbtHexes: o, signOptions: i, challengerEntries: u };
|
|
212
245
|
}
|
|
213
|
-
function
|
|
214
|
-
const
|
|
246
|
+
async function we(e) {
|
|
247
|
+
const {
|
|
248
|
+
challenger: t,
|
|
249
|
+
challengerPubkey: r,
|
|
250
|
+
claimerPubkey: o,
|
|
251
|
+
localChallengers: i,
|
|
252
|
+
assertTxParsed: u,
|
|
253
|
+
ctx: s
|
|
254
|
+
} = e;
|
|
255
|
+
oe(
|
|
256
|
+
t.nopayout_tx.tx_hex,
|
|
257
|
+
r,
|
|
258
|
+
s.network
|
|
259
|
+
);
|
|
260
|
+
const a = w.fromHex(
|
|
261
|
+
c(t.nopayout_tx.tx_hex)
|
|
262
|
+
), n = w.fromHex(
|
|
263
|
+
c(t.challenge_assert_x_tx.tx_hex)
|
|
264
|
+
), l = w.fromHex(
|
|
265
|
+
c(t.challenge_assert_y_tx.tx_hex)
|
|
266
|
+
);
|
|
267
|
+
if (a.ins.length !== 3)
|
|
268
|
+
throw new Error(
|
|
269
|
+
`NoPayout (challenger ${r}) must have exactly 3 inputs, got ${a.ins.length}`
|
|
270
|
+
);
|
|
271
|
+
_(
|
|
272
|
+
a,
|
|
273
|
+
0,
|
|
274
|
+
u,
|
|
275
|
+
"Assert",
|
|
276
|
+
r
|
|
277
|
+
), _(
|
|
278
|
+
a,
|
|
279
|
+
1,
|
|
280
|
+
n,
|
|
281
|
+
"ChallengeAssertX",
|
|
282
|
+
r
|
|
283
|
+
), _(
|
|
284
|
+
a,
|
|
285
|
+
2,
|
|
286
|
+
l,
|
|
287
|
+
"ChallengeAssertY",
|
|
288
|
+
r
|
|
289
|
+
);
|
|
290
|
+
const d = [
|
|
291
|
+
u.outs[0],
|
|
292
|
+
n.outs[0],
|
|
293
|
+
l.outs[0]
|
|
294
|
+
].map((h) => ({
|
|
295
|
+
script_pubkey: K(new Uint8Array(h.script)),
|
|
296
|
+
value: h.value
|
|
297
|
+
}));
|
|
298
|
+
return ne({
|
|
299
|
+
noPayoutTxHex: t.nopayout_tx.tx_hex,
|
|
300
|
+
challengerPubkey: r,
|
|
301
|
+
prevouts: d,
|
|
302
|
+
connectorParams: {
|
|
303
|
+
claimer: o,
|
|
304
|
+
localChallengers: i,
|
|
305
|
+
universalChallengers: s.universalChallengerBtcPubkeys,
|
|
306
|
+
timelockAssert: s.timelockAssert,
|
|
307
|
+
councilMembers: s.councilMembers,
|
|
308
|
+
councilQuorum: s.councilQuorum
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
function me(e, t, r) {
|
|
313
|
+
const o = v(
|
|
215
314
|
e[0],
|
|
216
315
|
r
|
|
217
316
|
), i = {};
|
|
218
|
-
for (const
|
|
219
|
-
i[
|
|
220
|
-
nopayout_signature:
|
|
221
|
-
e[
|
|
317
|
+
for (const u of t)
|
|
318
|
+
i[u.challengerPubkey] = {
|
|
319
|
+
nopayout_signature: v(
|
|
320
|
+
e[u.noPayoutIdx],
|
|
222
321
|
r
|
|
223
322
|
)
|
|
224
323
|
};
|
|
@@ -229,7 +328,7 @@ function ye(e, t, r) {
|
|
|
229
328
|
per_challenger: i
|
|
230
329
|
};
|
|
231
330
|
}
|
|
232
|
-
async function
|
|
331
|
+
async function ve(e, t, r) {
|
|
233
332
|
if (typeof e.signPsbts == "function")
|
|
234
333
|
return e.signPsbts(t, r);
|
|
235
334
|
const o = [];
|
|
@@ -237,30 +336,34 @@ async function Pe(e, t, r) {
|
|
|
237
336
|
o.push(await e.signPsbt(t[i], r == null ? void 0 : r[i]));
|
|
238
337
|
return o;
|
|
239
338
|
}
|
|
240
|
-
async function
|
|
241
|
-
const { depositorGraph: t,
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
339
|
+
async function ke(e) {
|
|
340
|
+
const { depositorGraph: t, btcWallet: r, signingContext: o } = e, i = c(o.depositorBtcPubkey), u = await r.getPublicKeyHex(), { psbtHexes: s, signOptions: a, challengerEntries: n } = await xe(
|
|
341
|
+
t,
|
|
342
|
+
u,
|
|
343
|
+
o
|
|
344
|
+
), l = await ve(
|
|
345
|
+
r,
|
|
346
|
+
s,
|
|
347
|
+
a
|
|
245
348
|
);
|
|
246
|
-
if (
|
|
349
|
+
if (l.length !== s.length)
|
|
247
350
|
throw new Error(
|
|
248
|
-
`Wallet returned ${
|
|
351
|
+
`Wallet returned ${l.length} signed PSBTs, expected ${s.length}`
|
|
249
352
|
);
|
|
250
|
-
return
|
|
251
|
-
|
|
353
|
+
return me(
|
|
354
|
+
l,
|
|
252
355
|
n,
|
|
253
356
|
i
|
|
254
357
|
);
|
|
255
358
|
}
|
|
256
|
-
class
|
|
359
|
+
class Te {
|
|
257
360
|
/**
|
|
258
361
|
* Creates a new PayoutManager instance.
|
|
259
362
|
*
|
|
260
363
|
* @param config - Manager configuration including wallet
|
|
261
364
|
*/
|
|
262
365
|
constructor(t) {
|
|
263
|
-
|
|
366
|
+
x(this, "config");
|
|
264
367
|
this.config = t;
|
|
265
368
|
}
|
|
266
369
|
/**
|
|
@@ -290,10 +393,10 @@ class xe {
|
|
|
290
393
|
t.payoutTxHex,
|
|
291
394
|
t.registeredPayoutScriptPubKey
|
|
292
395
|
);
|
|
293
|
-
const r = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey: o } =
|
|
396
|
+
const r = await this.config.btcWallet.getPublicKeyHex(), { depositorPubkey: o } = H(
|
|
294
397
|
r,
|
|
295
398
|
t.depositorBtcPubkey
|
|
296
|
-
), i = await
|
|
399
|
+
), i = await S({
|
|
297
400
|
payoutTxHex: t.payoutTxHex,
|
|
298
401
|
peginTxHex: t.peginTxHex,
|
|
299
402
|
assertTxHex: t.assertTxHex,
|
|
@@ -303,12 +406,12 @@ class xe {
|
|
|
303
406
|
universalChallengerBtcPubkeys: t.universalChallengerBtcPubkeys,
|
|
304
407
|
timelockPegin: t.timelockPegin,
|
|
305
408
|
network: this.config.network
|
|
306
|
-
}),
|
|
409
|
+
}), u = await this.config.btcWallet.signPsbt(
|
|
307
410
|
i.psbtHex,
|
|
308
411
|
b(r, 1)
|
|
309
412
|
);
|
|
310
413
|
return {
|
|
311
|
-
signature:
|
|
414
|
+
signature: v(u, o),
|
|
312
415
|
depositorBtcPubkey: o
|
|
313
416
|
};
|
|
314
417
|
}
|
|
@@ -342,22 +445,22 @@ class xe {
|
|
|
342
445
|
throw new Error(
|
|
343
446
|
"Wallet does not support batch signing (signPsbts method not available)"
|
|
344
447
|
);
|
|
345
|
-
const r = await this.config.btcWallet.getPublicKeyHex(), o = [], i = [],
|
|
448
|
+
const r = await this.config.btcWallet.getPublicKeyHex(), o = [], i = [], u = [];
|
|
346
449
|
for (const n of t) {
|
|
347
450
|
this.validatePayoutOutputs(
|
|
348
451
|
n.payoutTxHex,
|
|
349
452
|
n.registeredPayoutScriptPubKey
|
|
350
453
|
);
|
|
351
|
-
const { depositorPubkey:
|
|
454
|
+
const { depositorPubkey: l } = H(
|
|
352
455
|
r,
|
|
353
456
|
n.depositorBtcPubkey
|
|
354
457
|
);
|
|
355
|
-
|
|
356
|
-
const d = await
|
|
458
|
+
u.push(l);
|
|
459
|
+
const d = await S({
|
|
357
460
|
payoutTxHex: n.payoutTxHex,
|
|
358
461
|
peginTxHex: n.peginTxHex,
|
|
359
462
|
assertTxHex: n.assertTxHex,
|
|
360
|
-
depositorBtcPubkey:
|
|
463
|
+
depositorBtcPubkey: l,
|
|
361
464
|
vaultProviderBtcPubkey: n.vaultProviderBtcPubkey,
|
|
362
465
|
vaultKeeperBtcPubkeys: n.vaultKeeperBtcPubkeys,
|
|
363
466
|
universalChallengerBtcPubkeys: n.universalChallengerBtcPubkeys,
|
|
@@ -366,26 +469,26 @@ class xe {
|
|
|
366
469
|
});
|
|
367
470
|
o.push(d.psbtHex), i.push(b(r, 1));
|
|
368
471
|
}
|
|
369
|
-
const
|
|
472
|
+
const s = await this.config.btcWallet.signPsbts(
|
|
370
473
|
o,
|
|
371
474
|
i
|
|
372
475
|
);
|
|
373
|
-
if (
|
|
476
|
+
if (s.length !== t.length)
|
|
374
477
|
throw new Error(
|
|
375
|
-
`Expected ${t.length} signed PSBTs but received ${
|
|
478
|
+
`Expected ${t.length} signed PSBTs but received ${s.length}`
|
|
376
479
|
);
|
|
377
|
-
const
|
|
480
|
+
const a = [];
|
|
378
481
|
for (let n = 0; n < t.length; n++) {
|
|
379
|
-
const
|
|
380
|
-
|
|
381
|
-
|
|
482
|
+
const l = u[n], d = v(
|
|
483
|
+
s[n],
|
|
484
|
+
l
|
|
382
485
|
);
|
|
383
|
-
|
|
486
|
+
a.push({
|
|
384
487
|
payoutSignature: d,
|
|
385
|
-
depositorBtcPubkey:
|
|
488
|
+
depositorBtcPubkey: l
|
|
386
489
|
});
|
|
387
490
|
}
|
|
388
|
-
return
|
|
491
|
+
return a;
|
|
389
492
|
}
|
|
390
493
|
/**
|
|
391
494
|
* Validates that the payout transaction's largest output pays to the
|
|
@@ -402,64 +505,52 @@ class xe {
|
|
|
402
505
|
* @throws Error if the largest output does not pay to the registered address
|
|
403
506
|
*/
|
|
404
507
|
validatePayoutOutputs(t, r) {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
const o = V.from(
|
|
410
|
-
l(r),
|
|
411
|
-
"hex"
|
|
412
|
-
), i = te.fromHex(l(t));
|
|
413
|
-
if (i.outs.length === 0)
|
|
414
|
-
throw new Error("Payout transaction has no outputs");
|
|
415
|
-
if (!i.outs.reduce(
|
|
416
|
-
(a, s) => s.value > a.value ? s : a
|
|
417
|
-
).script.equals(o))
|
|
418
|
-
throw new Error(
|
|
419
|
-
"Payout transaction does not pay to the registered depositor payout address"
|
|
420
|
-
);
|
|
508
|
+
V(
|
|
509
|
+
t,
|
|
510
|
+
r
|
|
511
|
+
);
|
|
421
512
|
}
|
|
422
513
|
}
|
|
423
|
-
const
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
]),
|
|
428
|
-
|
|
429
|
-
...
|
|
514
|
+
const Ee = 1200 * 1e3, M = /* @__PURE__ */ new Set([
|
|
515
|
+
y.PENDING_ACKS,
|
|
516
|
+
y.PENDING_ACTIVATION,
|
|
517
|
+
y.ACTIVATED
|
|
518
|
+
]), _e = /* @__PURE__ */ new Set([
|
|
519
|
+
y.PENDING_DEPOSITOR_SIGNATURES,
|
|
520
|
+
...M
|
|
430
521
|
]);
|
|
431
|
-
function
|
|
522
|
+
function Be(e) {
|
|
432
523
|
return e.map((t) => ({
|
|
433
|
-
claimerPubkeyXOnly:
|
|
524
|
+
claimerPubkeyXOnly: m(t.claimer_pubkey),
|
|
434
525
|
payoutTxHex: t.payout_tx.tx_hex,
|
|
435
526
|
assertTxHex: t.assert_tx.tx_hex
|
|
436
527
|
}));
|
|
437
528
|
}
|
|
438
|
-
function
|
|
529
|
+
function Se(e) {
|
|
439
530
|
const { output: t } = ee.payments.p2tr({
|
|
440
|
-
internalPubkey:
|
|
531
|
+
internalPubkey: re.from(e, "hex")
|
|
441
532
|
});
|
|
442
533
|
if (!t)
|
|
443
534
|
throw new Error("Failed to derive BIP-86 P2TR scriptPubKey");
|
|
444
535
|
return t.toString("hex");
|
|
445
536
|
}
|
|
446
|
-
function
|
|
447
|
-
const r =
|
|
537
|
+
function Ae(e, t) {
|
|
538
|
+
const r = c(e).toLowerCase(), o = c(
|
|
448
539
|
t.vaultProviderBtcPubkey
|
|
449
|
-
).toLowerCase(), i =
|
|
540
|
+
).toLowerCase(), i = c(
|
|
450
541
|
t.depositorBtcPubkey
|
|
451
542
|
).toLowerCase();
|
|
452
543
|
if (r === o || r === i)
|
|
453
544
|
return t.registeredPayoutScriptPubKey;
|
|
454
545
|
if (!t.vaultKeeperBtcPubkeys.some(
|
|
455
|
-
(
|
|
546
|
+
(a) => c(a).toLowerCase() === r
|
|
456
547
|
))
|
|
457
548
|
throw new Error(
|
|
458
549
|
`Unknown claimer pubkey ${r}: not VP, depositor, or a registered vault keeper`
|
|
459
550
|
);
|
|
460
|
-
return `0x${
|
|
551
|
+
return `0x${Se(r)}`;
|
|
461
552
|
}
|
|
462
|
-
function
|
|
553
|
+
function R(e, t) {
|
|
463
554
|
return {
|
|
464
555
|
payoutTxHex: e.payoutTxHex,
|
|
465
556
|
peginTxHex: t.peginTxHex,
|
|
@@ -469,110 +560,122 @@ function C(e, t) {
|
|
|
469
560
|
universalChallengerBtcPubkeys: t.universalChallengerBtcPubkeys,
|
|
470
561
|
depositorBtcPubkey: t.depositorBtcPubkey,
|
|
471
562
|
timelockPegin: t.timelockPegin,
|
|
472
|
-
registeredPayoutScriptPubKey:
|
|
563
|
+
registeredPayoutScriptPubKey: Ae(
|
|
473
564
|
e.claimerPubkeyXOnly,
|
|
474
565
|
t
|
|
475
566
|
)
|
|
476
567
|
};
|
|
477
568
|
}
|
|
478
|
-
async function
|
|
479
|
-
const i = new
|
|
569
|
+
async function Ce(e, t, r, o) {
|
|
570
|
+
const i = new Te({
|
|
480
571
|
network: t.network,
|
|
481
572
|
btcWallet: e
|
|
482
|
-
}),
|
|
483
|
-
o == null || o(0,
|
|
484
|
-
let
|
|
573
|
+
}), u = r.length;
|
|
574
|
+
o == null || o(0, u);
|
|
575
|
+
let s;
|
|
485
576
|
if (i.supportsBatchSigning())
|
|
486
|
-
|
|
487
|
-
r.map((
|
|
488
|
-
)).map((
|
|
577
|
+
s = (await i.signPayoutTransactionsBatch(
|
|
578
|
+
r.map((l) => R(l, t))
|
|
579
|
+
)).map((l) => l.payoutSignature);
|
|
489
580
|
else {
|
|
490
|
-
|
|
581
|
+
s = [];
|
|
491
582
|
for (let n = 0; n < r.length; n++) {
|
|
492
|
-
o == null || o(n,
|
|
493
|
-
const
|
|
494
|
-
|
|
583
|
+
o == null || o(n, u);
|
|
584
|
+
const l = await i.signPayoutTransaction(
|
|
585
|
+
R(r[n], t)
|
|
495
586
|
);
|
|
496
|
-
|
|
587
|
+
s.push(l.signature);
|
|
497
588
|
}
|
|
498
589
|
}
|
|
499
|
-
const
|
|
590
|
+
const a = {};
|
|
500
591
|
for (let n = 0; n < r.length; n++)
|
|
501
|
-
|
|
502
|
-
payout_signature:
|
|
592
|
+
a[r[n].claimerPubkeyXOnly] = {
|
|
593
|
+
payout_signature: s[n]
|
|
503
594
|
};
|
|
504
|
-
return o == null || o(
|
|
595
|
+
return o == null || o(u, u), a;
|
|
505
596
|
}
|
|
506
|
-
async function
|
|
597
|
+
async function nt(e) {
|
|
507
598
|
const {
|
|
508
599
|
statusReader: t,
|
|
509
600
|
presignClient: r,
|
|
510
601
|
btcWallet: o,
|
|
511
602
|
peginTxid: i,
|
|
512
|
-
depositorPk:
|
|
513
|
-
signingContext:
|
|
514
|
-
timeoutMs:
|
|
603
|
+
depositorPk: u,
|
|
604
|
+
signingContext: s,
|
|
605
|
+
timeoutMs: a = Ee,
|
|
515
606
|
signal: n,
|
|
516
|
-
onProgress:
|
|
607
|
+
onProgress: l
|
|
517
608
|
} = e, d = await D({
|
|
518
609
|
statusReader: t,
|
|
519
610
|
peginTxid: i,
|
|
520
|
-
targetStatuses:
|
|
521
|
-
timeoutMs:
|
|
611
|
+
targetStatuses: _e,
|
|
612
|
+
timeoutMs: a,
|
|
522
613
|
signal: n
|
|
523
614
|
});
|
|
524
|
-
if (
|
|
615
|
+
if (M.has(d))
|
|
525
616
|
return;
|
|
526
617
|
n == null || n.throwIfAborted();
|
|
527
618
|
const h = await r.requestDepositorPresignTransactions(
|
|
528
619
|
{
|
|
529
620
|
pegin_txid: i,
|
|
530
|
-
depositor_pk:
|
|
621
|
+
depositor_pk: u
|
|
531
622
|
},
|
|
532
623
|
n
|
|
533
624
|
);
|
|
534
625
|
n == null || n.throwIfAborted();
|
|
535
|
-
const
|
|
536
|
-
(
|
|
537
|
-
),
|
|
626
|
+
const g = m(u), P = h.txs.filter(
|
|
627
|
+
(X) => m(X.claimer_pubkey) !== g
|
|
628
|
+
), k = Be(P), T = await Ce(
|
|
538
629
|
o,
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
630
|
+
s,
|
|
631
|
+
k,
|
|
632
|
+
l
|
|
542
633
|
);
|
|
543
634
|
n == null || n.throwIfAborted();
|
|
544
|
-
const p = await
|
|
635
|
+
const p = await ke({
|
|
545
636
|
depositorGraph: h.depositor_graph,
|
|
546
|
-
|
|
547
|
-
|
|
637
|
+
btcWallet: o,
|
|
638
|
+
signingContext: {
|
|
639
|
+
peginTxHex: s.peginTxHex,
|
|
640
|
+
depositorBtcPubkey: u,
|
|
641
|
+
vaultProviderBtcPubkey: s.vaultProviderBtcPubkey,
|
|
642
|
+
vaultKeeperBtcPubkeys: s.vaultKeeperBtcPubkeys,
|
|
643
|
+
universalChallengerBtcPubkeys: s.universalChallengerBtcPubkeys,
|
|
644
|
+
timelockPegin: s.timelockPegin,
|
|
645
|
+
timelockAssert: s.timelockAssert,
|
|
646
|
+
councilMembers: s.councilMembers,
|
|
647
|
+
councilQuorum: s.councilQuorum,
|
|
648
|
+
network: s.network,
|
|
649
|
+
registeredPayoutScriptPubKey: s.registeredPayoutScriptPubKey
|
|
650
|
+
}
|
|
548
651
|
});
|
|
549
652
|
n == null || n.throwIfAborted();
|
|
550
|
-
const
|
|
551
|
-
|
|
653
|
+
const C = { ...T };
|
|
654
|
+
C[c(u)] = p.payout_signatures, await r.submitDepositorPresignatures(
|
|
552
655
|
{
|
|
553
656
|
pegin_txid: i,
|
|
554
|
-
depositor_pk:
|
|
555
|
-
signatures:
|
|
657
|
+
depositor_pk: u,
|
|
658
|
+
signatures: C,
|
|
556
659
|
depositor_claimer_presignatures: p
|
|
557
660
|
},
|
|
558
661
|
n
|
|
559
662
|
);
|
|
560
663
|
}
|
|
561
|
-
function
|
|
664
|
+
function He(e) {
|
|
562
665
|
return /^[0-9a-fA-F]{64}$/.test(e);
|
|
563
666
|
}
|
|
564
|
-
function
|
|
667
|
+
function st(e) {
|
|
565
668
|
const {
|
|
566
669
|
amountSats: t,
|
|
567
670
|
minDeposit: r,
|
|
568
671
|
maxDeposit: o,
|
|
569
672
|
btcBalance: i,
|
|
570
|
-
estimatedFeeSats:
|
|
571
|
-
depositorClaimValue:
|
|
673
|
+
estimatedFeeSats: u,
|
|
674
|
+
depositorClaimValue: s
|
|
572
675
|
} = e;
|
|
573
|
-
return !(t <= 0n || t < r || o && o > 0n && t > o ||
|
|
676
|
+
return !(t <= 0n || t < r || o && o > 0n && t > o || u == null || s == null || t + u + s > i);
|
|
574
677
|
}
|
|
575
|
-
function
|
|
678
|
+
function it(e, t, r) {
|
|
576
679
|
return e <= 0n ? {
|
|
577
680
|
valid: !1,
|
|
578
681
|
error: "Deposit amount must be greater than zero"
|
|
@@ -584,7 +687,7 @@ function rt(e, t, r) {
|
|
|
584
687
|
error: `Maximum deposit is ${f(r)} BTC`
|
|
585
688
|
} : { valid: !0 };
|
|
586
689
|
}
|
|
587
|
-
function
|
|
690
|
+
function at(e) {
|
|
588
691
|
const { amount: t, effectiveRemaining: r } = e;
|
|
589
692
|
return r === null ? { valid: !0 } : r === 0n ? {
|
|
590
693
|
valid: !1,
|
|
@@ -594,7 +697,7 @@ function ot(e) {
|
|
|
594
697
|
error: `Vault size exceeds remaining capacity (${f(r)} BTC)`
|
|
595
698
|
} : { valid: !0 };
|
|
596
699
|
}
|
|
597
|
-
function
|
|
700
|
+
function ut(e, t) {
|
|
598
701
|
if (!e || e.length === 0)
|
|
599
702
|
return {
|
|
600
703
|
valid: !1,
|
|
@@ -610,7 +713,7 @@ function nt(e, t) {
|
|
|
610
713
|
error: "Invalid vault provider selected"
|
|
611
714
|
} : { valid: !0 };
|
|
612
715
|
}
|
|
613
|
-
function
|
|
716
|
+
function $e(e, t, r) {
|
|
614
717
|
if (!e || e.length === 0)
|
|
615
718
|
return {
|
|
616
719
|
valid: !1,
|
|
@@ -636,98 +739,98 @@ function _e(e, t, r) {
|
|
|
636
739
|
}
|
|
637
740
|
return { valid: !0 };
|
|
638
741
|
}
|
|
639
|
-
function
|
|
640
|
-
const t =
|
|
641
|
-
return
|
|
742
|
+
function Ie(e) {
|
|
743
|
+
const t = c(e);
|
|
744
|
+
return He(t) ? { valid: !0 } : {
|
|
642
745
|
valid: !1,
|
|
643
746
|
error: "Invalid pubkey format: must be 64 hex characters (32-byte x-only public key, no 0x prefix)"
|
|
644
747
|
};
|
|
645
748
|
}
|
|
646
|
-
function
|
|
749
|
+
function Re(e) {
|
|
647
750
|
if (!e || e.length === 0)
|
|
648
751
|
throw new Error(
|
|
649
752
|
"No vault keepers available. The system requires at least one vault keeper to create a deposit."
|
|
650
753
|
);
|
|
651
754
|
}
|
|
652
|
-
function
|
|
755
|
+
function Ne(e) {
|
|
653
756
|
if (!e || e.length === 0)
|
|
654
757
|
throw new Error(
|
|
655
758
|
"No universal challengers available. The system requires at least one universal challenger to create a deposit."
|
|
656
759
|
);
|
|
657
760
|
}
|
|
658
|
-
function
|
|
761
|
+
function Oe(e) {
|
|
659
762
|
if (e.length === 0)
|
|
660
763
|
throw new Error("No spendable UTXOs available");
|
|
661
764
|
}
|
|
662
|
-
function
|
|
765
|
+
function lt(e) {
|
|
663
766
|
const {
|
|
664
767
|
vaultAmounts: t,
|
|
665
768
|
confirmedUTXOs: r,
|
|
666
769
|
vaultProviderBtcPubkey: o,
|
|
667
770
|
vaultKeeperBtcPubkeys: i,
|
|
668
|
-
universalChallengerBtcPubkeys:
|
|
669
|
-
minDeposit:
|
|
670
|
-
maxDeposit:
|
|
671
|
-
} = e, n =
|
|
771
|
+
universalChallengerBtcPubkeys: u,
|
|
772
|
+
minDeposit: s,
|
|
773
|
+
maxDeposit: a
|
|
774
|
+
} = e, n = $e(
|
|
672
775
|
t,
|
|
673
|
-
|
|
674
|
-
|
|
776
|
+
s,
|
|
777
|
+
a
|
|
675
778
|
);
|
|
676
779
|
if (!n.valid)
|
|
677
780
|
throw new Error(n.error);
|
|
678
|
-
const
|
|
679
|
-
if (!
|
|
680
|
-
throw new Error(
|
|
681
|
-
|
|
781
|
+
const l = Ie(o);
|
|
782
|
+
if (!l.valid)
|
|
783
|
+
throw new Error(l.error);
|
|
784
|
+
Re(i), Ne(u), Oe(r);
|
|
682
785
|
}
|
|
683
786
|
var U = /* @__PURE__ */ ((e) => (e.CLAIM_EVENT_RECEIVED = "ClaimEventReceived", e.CLAIM_BROADCAST = "ClaimBroadcast", e.ASSERT_BROADCAST = "AssertBroadcast", e.CHALLENGE_ASSERT_OBSERVED = "ChallengeAssertObserved", e.WRONGLY_CHALLENGED_BROADCAST = "WronglyChallengedBroadcast", e.PAYOUT_BROADCAST = "PayoutBroadcast", e.FAILED = "Failed", e))(U || {});
|
|
684
|
-
const
|
|
787
|
+
const Ke = /* @__PURE__ */ new Set([
|
|
685
788
|
"PayoutBroadcast",
|
|
686
789
|
"Failed"
|
|
687
790
|
/* FAILED */
|
|
688
791
|
]);
|
|
689
|
-
function
|
|
792
|
+
function ct(e) {
|
|
690
793
|
return Object.values(U).includes(
|
|
691
794
|
e
|
|
692
795
|
);
|
|
693
796
|
}
|
|
694
|
-
function
|
|
695
|
-
return !!e &&
|
|
797
|
+
function dt(e) {
|
|
798
|
+
return !!e && Ke.has(e);
|
|
696
799
|
}
|
|
697
|
-
class
|
|
800
|
+
class Ve extends Error {
|
|
698
801
|
constructor(r, o) {
|
|
699
802
|
super(`Refund not yet mature (BIP68 not final): ${o.message}`);
|
|
700
|
-
|
|
701
|
-
|
|
803
|
+
x(this, "vaultId");
|
|
804
|
+
x(this, "cause");
|
|
702
805
|
this.name = "BIP68NotMatureError", this.vaultId = r, this.cause = o;
|
|
703
806
|
}
|
|
704
807
|
}
|
|
705
|
-
const
|
|
706
|
-
function
|
|
808
|
+
const Le = /^0x[0-9a-fA-F]{64}$/, De = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, F = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, Me = 160, Ue = 1, N = 65535, Fe = /non-BIP68-final/i;
|
|
809
|
+
function W(e, t) {
|
|
707
810
|
if (e.length !== 66)
|
|
708
811
|
throw new Error(
|
|
709
812
|
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
710
813
|
);
|
|
711
|
-
if (!
|
|
814
|
+
if (!Le.test(e))
|
|
712
815
|
throw new Error(
|
|
713
816
|
`${t} must contain only hex characters after the 0x prefix`
|
|
714
817
|
);
|
|
715
818
|
}
|
|
716
|
-
function
|
|
819
|
+
function B(e, t) {
|
|
717
820
|
if (!Number.isInteger(e) || e < 0)
|
|
718
821
|
throw new Error(`${t} must be a non-negative integer, got ${e}`);
|
|
719
822
|
}
|
|
720
|
-
function
|
|
721
|
-
if (
|
|
823
|
+
function We(e) {
|
|
824
|
+
if (W(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0 || e.htlcVout > N)
|
|
722
825
|
throw new Error(
|
|
723
|
-
`htlcVout must be an integer 0-${
|
|
826
|
+
`htlcVout must be an integer 0-${N}, got ${e.htlcVout}`
|
|
724
827
|
);
|
|
725
|
-
if (
|
|
828
|
+
if (B(e.offchainParamsVersion, "offchainParamsVersion"), B(e.appVaultKeepersVersion, "appVaultKeepersVersion"), B(
|
|
726
829
|
e.universalChallengersVersion,
|
|
727
830
|
"universalChallengersVersion"
|
|
728
831
|
), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
|
|
729
832
|
throw new Error("unsignedPrePeginTxHex must be a non-empty hex string");
|
|
730
|
-
if (!
|
|
833
|
+
if (!De.test(e.unsignedPrePeginTxHex))
|
|
731
834
|
throw new Error(
|
|
732
835
|
"unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
|
|
733
836
|
);
|
|
@@ -738,7 +841,7 @@ function Ke(e) {
|
|
|
738
841
|
if (typeof e.amount != "bigint" || e.amount <= 0n)
|
|
739
842
|
throw new Error(`amount must be a positive bigint, got ${e.amount}`);
|
|
740
843
|
}
|
|
741
|
-
function
|
|
844
|
+
function Xe(e) {
|
|
742
845
|
if (!e.vaultProviderPubkey || !F.test(e.vaultProviderPubkey))
|
|
743
846
|
throw new Error("vaultProviderPubkey must be 32 or 33 bytes of hex");
|
|
744
847
|
if (e.vaultKeeperPubkeys.length === 0)
|
|
@@ -760,8 +863,8 @@ function Ue(e) {
|
|
|
760
863
|
`councilQuorum (${e.councilQuorum}) must be in [1, councilSize=${e.councilSize}]`
|
|
761
864
|
);
|
|
762
865
|
}
|
|
763
|
-
function
|
|
764
|
-
const t =
|
|
866
|
+
function ze(e) {
|
|
867
|
+
const t = te.fromHex(e);
|
|
765
868
|
try {
|
|
766
869
|
t.finalizeAllInputs();
|
|
767
870
|
} catch (r) {
|
|
@@ -771,82 +874,82 @@ function Fe(e) {
|
|
|
771
874
|
}
|
|
772
875
|
return t.extractTransaction().toHex();
|
|
773
876
|
}
|
|
774
|
-
async function
|
|
877
|
+
async function ht(e) {
|
|
775
878
|
const {
|
|
776
879
|
vaultId: t,
|
|
777
880
|
readVault: r,
|
|
778
881
|
readPrePeginContext: o,
|
|
779
882
|
feeRate: i,
|
|
780
|
-
signPsbt:
|
|
781
|
-
broadcastTx:
|
|
782
|
-
signal:
|
|
883
|
+
signPsbt: u,
|
|
884
|
+
broadcastTx: s,
|
|
885
|
+
signal: a
|
|
783
886
|
} = e;
|
|
784
|
-
|
|
887
|
+
a == null || a.throwIfAborted(), W(t, "vaultId");
|
|
785
888
|
const n = await r();
|
|
786
|
-
|
|
787
|
-
const
|
|
788
|
-
if (
|
|
889
|
+
We(n), a == null || a.throwIfAborted();
|
|
890
|
+
const l = await o(n);
|
|
891
|
+
if (Xe(l), a == null || a.throwIfAborted(), !Number.isFinite(i) || i <= 0)
|
|
789
892
|
throw new Error(`feeRate must be a positive number, got ${i}`);
|
|
790
|
-
const d = BigInt(Math.ceil(i *
|
|
791
|
-
|
|
792
|
-
const h =
|
|
893
|
+
const d = BigInt(Math.ceil(i * Me));
|
|
894
|
+
a == null || a.throwIfAborted();
|
|
895
|
+
const h = m(
|
|
793
896
|
n.depositorBtcPubkey
|
|
794
|
-
), { psbtHex:
|
|
897
|
+
), { psbtHex: g } = await se({
|
|
795
898
|
prePeginParams: {
|
|
796
899
|
depositorPubkey: h,
|
|
797
|
-
vaultProviderPubkey: l
|
|
798
|
-
vaultKeeperPubkeys:
|
|
799
|
-
universalChallengerPubkeys:
|
|
800
|
-
hashlocks: [
|
|
801
|
-
timelockRefund:
|
|
900
|
+
vaultProviderPubkey: c(l.vaultProviderPubkey),
|
|
901
|
+
vaultKeeperPubkeys: l.vaultKeeperPubkeys.map(c),
|
|
902
|
+
universalChallengerPubkeys: l.universalChallengerPubkeys.map(c),
|
|
903
|
+
hashlocks: [c(n.hashlock)],
|
|
904
|
+
timelockRefund: l.timelockRefund,
|
|
802
905
|
pegInAmounts: [n.amount],
|
|
803
|
-
feeRate:
|
|
804
|
-
numLocalChallengers:
|
|
805
|
-
councilQuorum:
|
|
806
|
-
councilSize:
|
|
807
|
-
network:
|
|
906
|
+
feeRate: l.feeRate,
|
|
907
|
+
numLocalChallengers: l.numLocalChallengers,
|
|
908
|
+
councilQuorum: l.councilQuorum,
|
|
909
|
+
councilSize: l.councilSize,
|
|
910
|
+
network: l.network
|
|
808
911
|
},
|
|
809
|
-
fundedPrePeginTxHex:
|
|
912
|
+
fundedPrePeginTxHex: c(n.unsignedPrePeginTxHex),
|
|
810
913
|
htlcVout: n.htlcVout,
|
|
811
914
|
refundFee: d,
|
|
812
915
|
// buildRefundPsbt's top-level `hashlock` param is documented as "no 0x
|
|
813
916
|
// prefix" and flows into the WASM HTLC connector derivation; a prefixed
|
|
814
917
|
// value would derive the wrong refund script leaf and yield an
|
|
815
918
|
// unspendable PSBT. Match the `hashlocks` array handling above.
|
|
816
|
-
hashlock:
|
|
919
|
+
hashlock: c(n.hashlock)
|
|
817
920
|
});
|
|
818
|
-
|
|
819
|
-
const
|
|
921
|
+
a == null || a.throwIfAborted();
|
|
922
|
+
const P = b(
|
|
820
923
|
n.depositorBtcPubkey,
|
|
821
|
-
|
|
822
|
-
),
|
|
823
|
-
|
|
924
|
+
Ue
|
|
925
|
+
), k = await u(g, P), T = ze(k);
|
|
926
|
+
a == null || a.throwIfAborted();
|
|
824
927
|
try {
|
|
825
|
-
return await
|
|
928
|
+
return await s(T);
|
|
826
929
|
} catch (p) {
|
|
827
|
-
throw p instanceof Error &&
|
|
930
|
+
throw p instanceof Error && Fe.test(p.message) ? new Ve(t, p) : p;
|
|
828
931
|
}
|
|
829
932
|
}
|
|
830
933
|
export {
|
|
831
|
-
|
|
934
|
+
Ve as B,
|
|
832
935
|
U as C,
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
936
|
+
Te as P,
|
|
937
|
+
rt as a,
|
|
938
|
+
ke as b,
|
|
939
|
+
at as c,
|
|
940
|
+
ut as d,
|
|
941
|
+
$e as e,
|
|
942
|
+
Ie as f,
|
|
943
|
+
lt as g,
|
|
944
|
+
ae as h,
|
|
945
|
+
st as i,
|
|
946
|
+
ue as j,
|
|
947
|
+
ct as k,
|
|
948
|
+
dt as l,
|
|
949
|
+
ht as m,
|
|
950
|
+
nt as p,
|
|
951
|
+
ot as s,
|
|
952
|
+
it as v,
|
|
850
953
|
D as w
|
|
851
954
|
};
|
|
852
|
-
//# sourceMappingURL=buildAndBroadcastRefund-
|
|
955
|
+
//# sourceMappingURL=buildAndBroadcastRefund-BY6mYmFl.js.map
|