@babylonlabs-io/ts-sdk 0.29.0 → 0.31.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-DmVq6ffv.cjs} +2 -2
- package/dist/{PeginManager-DcjXiKYC.cjs.map → PeginManager-DmVq6ffv.cjs.map} +1 -1
- package/dist/{PeginManager-Dj6oDaH5.js → PeginManager-c44Uvd1N.js} +3 -3
- package/dist/{PeginManager-Dj6oDaH5.js.map → PeginManager-c44Uvd1N.js.map} +1 -1
- package/dist/{buildAndBroadcastRefund-xWS8frc6.js → buildAndBroadcastRefund-BRQaCQrJ.js} +417 -304
- package/dist/buildAndBroadcastRefund-BRQaCQrJ.js.map +1 -0
- package/dist/buildAndBroadcastRefund-CLLaz8D3.cjs +2 -0
- package/dist/buildAndBroadcastRefund-CLLaz8D3.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 +146 -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 +143 -140
- 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 +21 -19
- package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts +8 -0
- package/dist/tbv/core/services/refund/buildAndBroadcastRefund.d.ts.map +1 -1
- package/dist/tbv/core/services/refund/index.d.ts +1 -1
- package/dist/tbv/core/services/refund/index.d.ts.map +1 -1
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +143 -140
- 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
|
|
6
|
-
import { s as
|
|
7
|
-
import * as
|
|
8
|
-
import {
|
|
9
|
-
import { Buffer as
|
|
1
|
+
var G = Object.defineProperty;
|
|
2
|
+
var Q = (e, t, r) => t in e ? G(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var x = (e, t, r) => Q(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { B as Y, c as j, a as q, R as J, d as O, D as y } from "./types-CnG3JsRs.js";
|
|
5
|
+
import { e as Z, s as l, u as K, v as H, p as w, f } from "./bitcoin-B-Y0DlqR.js";
|
|
6
|
+
import { s as ee } from "./sha2-6wN58S6R.js";
|
|
7
|
+
import * as te from "bitcoinjs-lib";
|
|
8
|
+
import { Transaction as m, Psbt as re } from "bitcoinjs-lib";
|
|
9
|
+
import { Buffer as oe } 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 ne, d as se, b as ie } 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 ae(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
|
-
|
|
38
|
-
const t = L(e), r =
|
|
39
|
-
return
|
|
36
|
+
function ue(e) {
|
|
37
|
+
A(e, "Secret");
|
|
38
|
+
const t = L(e), r = ee(t);
|
|
39
|
+
return ae(r);
|
|
40
40
|
}
|
|
41
|
-
function
|
|
42
|
-
return
|
|
41
|
+
function ce(e, t) {
|
|
42
|
+
return A(e, "Secret"), A(t, "Hashlock"), L(t), ue(e).toLowerCase() === t.toLowerCase();
|
|
43
43
|
}
|
|
44
|
-
const
|
|
44
|
+
const le = /^0x[0-9a-fA-F]{64}$/, de = /^0x[0-9a-fA-F]{40}$/, he = /^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 pe(e, t) {
|
|
56
|
+
if (!de.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 fe(e, t) {
|
|
62
|
+
if (!he.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(), pe(t, "btcVaultRegistryAddress"), E(r, "vaultId");
|
|
77
|
+
const a = Z(e.secret);
|
|
78
|
+
if (E(a, "secret"), o !== void 0 && (E(o, "hashlock"), !ce(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 fe(i, "activationMetadata"), u({
|
|
83
83
|
address: t,
|
|
84
|
-
abi:
|
|
84
|
+
abi: Y,
|
|
85
85
|
functionName: "activateVaultWithSecret",
|
|
86
|
-
args: [r,
|
|
86
|
+
args: [r, a, i]
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
|
-
const
|
|
89
|
+
const ge = 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 = ge,
|
|
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 c = (await t.getPeginStatus(
|
|
110
110
|
{ pegin_txid: r },
|
|
111
|
-
|
|
111
|
+
s
|
|
112
112
|
)).status;
|
|
113
|
-
if (o.has(
|
|
114
|
-
return
|
|
115
|
-
if (
|
|
113
|
+
if (o.has(c))
|
|
114
|
+
return c;
|
|
115
|
+
if (j.has(c) && !o.has(c))
|
|
116
116
|
throw new Error(
|
|
117
|
-
`Pegin ${r.slice(0, 8)}… reached terminal status "${
|
|
117
|
+
`Pegin ${r.slice(0, 8)}… reached terminal status "${c}" while waiting for ${[...o].join(", ")}`
|
|
118
118
|
);
|
|
119
119
|
} catch (n) {
|
|
120
|
-
if (!(n instanceof
|
|
120
|
+
if (!(n instanceof q && n.code === J.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, c) => {
|
|
124
124
|
const d = () => {
|
|
125
|
-
clearTimeout(h),
|
|
125
|
+
clearTimeout(h), c(
|
|
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 Pe = 300 * 1e3, ye = /* @__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 = Pe,
|
|
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: ye,
|
|
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 be(e, t, r) {
|
|
170
|
+
const o = l(r).toLowerCase(), u = [e, ...t].map(
|
|
171
|
+
(s) => l(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"
|
|
176
|
+
);
|
|
177
|
+
return u;
|
|
178
|
+
}
|
|
179
|
+
function xe(e, t) {
|
|
180
|
+
const r = e.ins[t];
|
|
181
|
+
return K(new Uint8Array(r.hash).slice().reverse());
|
|
182
|
+
}
|
|
183
|
+
function B(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 = xe(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})`
|
|
174
193
|
);
|
|
175
|
-
return o;
|
|
176
194
|
}
|
|
177
|
-
function
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
delete r.tapBip32Derivation, delete r.tapMerkleRoot;
|
|
181
|
-
return t;
|
|
182
|
-
}
|
|
183
|
-
function $(e, t, r) {
|
|
184
|
-
if (!e)
|
|
185
|
-
throw new Error(`Missing ${r} PSBT`);
|
|
186
|
-
const o = he(e, t, r);
|
|
187
|
-
return ge(o).toHex();
|
|
188
|
-
}
|
|
189
|
-
function be(e, t) {
|
|
190
|
-
const r = [], o = [], i = [], c = $(
|
|
191
|
-
e.payout_psbt,
|
|
195
|
+
async function me(e, t, r) {
|
|
196
|
+
const o = [], i = [], u = [];
|
|
197
|
+
V(
|
|
192
198
|
e.payout_tx.tx_hex,
|
|
193
|
-
|
|
199
|
+
r.registeredPayoutScriptPubKey
|
|
194
200
|
);
|
|
195
|
-
|
|
196
|
-
|
|
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
|
+
)
|
|
197
217
|
);
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
)
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
),
|
|
207
|
-
|
|
208
|
-
|
|
218
|
+
const a = be(
|
|
219
|
+
r.vaultProviderBtcPubkey,
|
|
220
|
+
r.vaultKeeperBtcPubkeys,
|
|
221
|
+
r.depositorBtcPubkey
|
|
222
|
+
), n = l(r.depositorBtcPubkey), c = m.fromHex(
|
|
223
|
+
l(e.assert_tx.tx_hex)
|
|
224
|
+
);
|
|
225
|
+
for (const d of e.challenger_presign_data) {
|
|
226
|
+
const h = l(d.challenger_pubkey), g = o.length, P = await we({
|
|
227
|
+
challenger: d,
|
|
228
|
+
challengerPubkey: h,
|
|
229
|
+
claimerPubkey: n,
|
|
230
|
+
localChallengers: a,
|
|
231
|
+
assertTxParsed: c,
|
|
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
|
+
ne(
|
|
256
|
+
t.nopayout_tx.tx_hex,
|
|
257
|
+
r,
|
|
258
|
+
s.network
|
|
259
|
+
);
|
|
260
|
+
const a = m.fromHex(
|
|
261
|
+
l(t.nopayout_tx.tx_hex)
|
|
262
|
+
), n = m.fromHex(
|
|
263
|
+
l(t.challenge_assert_x_tx.tx_hex)
|
|
264
|
+
), c = m.fromHex(
|
|
265
|
+
l(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
|
+
B(
|
|
272
|
+
a,
|
|
273
|
+
0,
|
|
274
|
+
u,
|
|
275
|
+
"Assert",
|
|
276
|
+
r
|
|
277
|
+
), B(
|
|
278
|
+
a,
|
|
279
|
+
1,
|
|
280
|
+
n,
|
|
281
|
+
"ChallengeAssertX",
|
|
282
|
+
r
|
|
283
|
+
), B(
|
|
284
|
+
a,
|
|
285
|
+
2,
|
|
286
|
+
c,
|
|
287
|
+
"ChallengeAssertY",
|
|
288
|
+
r
|
|
289
|
+
);
|
|
290
|
+
const d = [
|
|
291
|
+
u.outs[0],
|
|
292
|
+
n.outs[0],
|
|
293
|
+
c.outs[0]
|
|
294
|
+
].map((h) => ({
|
|
295
|
+
script_pubkey: K(new Uint8Array(h.script)),
|
|
296
|
+
value: h.value
|
|
297
|
+
}));
|
|
298
|
+
return se({
|
|
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 ve(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 ke(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 Te(e) {
|
|
340
|
+
const { depositorGraph: t, btcWallet: r, signingContext: o } = e, i = l(o.depositorBtcPubkey), u = await r.getPublicKeyHex(), { psbtHexes: s, signOptions: a, challengerEntries: n } = await me(
|
|
341
|
+
t,
|
|
342
|
+
u,
|
|
343
|
+
o
|
|
344
|
+
), c = await ke(
|
|
345
|
+
r,
|
|
346
|
+
s,
|
|
347
|
+
a
|
|
245
348
|
);
|
|
246
|
-
if (
|
|
349
|
+
if (c.length !== s.length)
|
|
247
350
|
throw new Error(
|
|
248
|
-
`Wallet returned ${
|
|
351
|
+
`Wallet returned ${c.length} signed PSBTs, expected ${s.length}`
|
|
249
352
|
);
|
|
250
|
-
return
|
|
251
|
-
|
|
353
|
+
return ve(
|
|
354
|
+
c,
|
|
252
355
|
n,
|
|
253
356
|
i
|
|
254
357
|
);
|
|
255
358
|
}
|
|
256
|
-
class
|
|
359
|
+
class Ee {
|
|
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: c } = H(
|
|
352
455
|
r,
|
|
353
456
|
n.depositorBtcPubkey
|
|
354
457
|
);
|
|
355
|
-
|
|
356
|
-
const d = await
|
|
458
|
+
u.push(c);
|
|
459
|
+
const d = await S({
|
|
357
460
|
payoutTxHex: n.payoutTxHex,
|
|
358
461
|
peginTxHex: n.peginTxHex,
|
|
359
462
|
assertTxHex: n.assertTxHex,
|
|
360
|
-
depositorBtcPubkey:
|
|
463
|
+
depositorBtcPubkey: c,
|
|
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 c = u[n], d = v(
|
|
483
|
+
s[n],
|
|
484
|
+
c
|
|
382
485
|
);
|
|
383
|
-
|
|
486
|
+
a.push({
|
|
384
487
|
payoutSignature: d,
|
|
385
|
-
depositorBtcPubkey:
|
|
488
|
+
depositorBtcPubkey: c
|
|
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,48 +505,36 @@ 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 Be = 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 Se(e) {
|
|
432
523
|
return e.map((t) => ({
|
|
433
|
-
claimerPubkeyXOnly:
|
|
524
|
+
claimerPubkeyXOnly: w(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
|
|
439
|
-
const { output: t } =
|
|
440
|
-
internalPubkey:
|
|
529
|
+
function Ae(e) {
|
|
530
|
+
const { output: t } = te.payments.p2tr({
|
|
531
|
+
internalPubkey: oe.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
|
|
537
|
+
function Ce(e, t) {
|
|
447
538
|
const r = l(e).toLowerCase(), o = l(
|
|
448
539
|
t.vaultProviderBtcPubkey
|
|
449
540
|
).toLowerCase(), i = l(
|
|
@@ -452,14 +543,14 @@ function ke(e, t) {
|
|
|
452
543
|
if (r === o || r === i)
|
|
453
544
|
return t.registeredPayoutScriptPubKey;
|
|
454
545
|
if (!t.vaultKeeperBtcPubkeys.some(
|
|
455
|
-
(
|
|
546
|
+
(a) => l(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${Ae(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: Ce(
|
|
473
564
|
e.claimerPubkeyXOnly,
|
|
474
565
|
t
|
|
475
566
|
)
|
|
476
567
|
};
|
|
477
568
|
}
|
|
478
|
-
async function
|
|
479
|
-
const i = new
|
|
569
|
+
async function He(e, t, r, o) {
|
|
570
|
+
const i = new Ee({
|
|
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((c) => R(c, t))
|
|
579
|
+
)).map((c) => c.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 c = await i.signPayoutTransaction(
|
|
585
|
+
R(r[n], t)
|
|
495
586
|
);
|
|
496
|
-
|
|
587
|
+
s.push(c.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 = Be,
|
|
515
606
|
signal: n,
|
|
516
|
-
onProgress:
|
|
607
|
+
onProgress: c
|
|
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
|
-
(z) =>
|
|
537
|
-
),
|
|
626
|
+
const g = w(u), P = h.txs.filter(
|
|
627
|
+
(z) => w(z.claimer_pubkey) !== g
|
|
628
|
+
), k = Se(P), T = await He(
|
|
538
629
|
o,
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
630
|
+
s,
|
|
631
|
+
k,
|
|
632
|
+
c
|
|
542
633
|
);
|
|
543
634
|
n == null || n.throwIfAborted();
|
|
544
|
-
const p = await
|
|
635
|
+
const p = await Te({
|
|
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[l(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 $e(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 Ie(e, t, r) {
|
|
614
717
|
if (!e || e.length === 0)
|
|
615
718
|
return {
|
|
616
719
|
valid: !1,
|
|
@@ -636,98 +739,106 @@ function _e(e, t, r) {
|
|
|
636
739
|
}
|
|
637
740
|
return { valid: !0 };
|
|
638
741
|
}
|
|
639
|
-
function
|
|
742
|
+
function Re(e) {
|
|
640
743
|
const t = l(e);
|
|
641
|
-
return
|
|
744
|
+
return $e(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 Ne(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 Oe(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 Ke(e) {
|
|
659
762
|
if (e.length === 0)
|
|
660
763
|
throw new Error("No spendable UTXOs available");
|
|
661
764
|
}
|
|
662
|
-
function
|
|
765
|
+
function ct(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 = Ie(
|
|
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 c = Re(o);
|
|
782
|
+
if (!c.valid)
|
|
783
|
+
throw new Error(c.error);
|
|
784
|
+
Ne(i), Oe(u), Ke(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 Ve = /* @__PURE__ */ new Set([
|
|
685
788
|
"PayoutBroadcast",
|
|
686
789
|
"Failed"
|
|
687
790
|
/* FAILED */
|
|
688
791
|
]);
|
|
689
|
-
function
|
|
792
|
+
function lt(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 && Ve.has(e);
|
|
696
799
|
}
|
|
697
|
-
class
|
|
800
|
+
class Le 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 De = /^0x[0-9a-fA-F]{64}$/, Me = /^(?:0x)?(?:[0-9a-fA-F]{2})+$/, F = /^(?:0x)?(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{66})$/, W = 160;
|
|
809
|
+
function ht(e) {
|
|
810
|
+
if (!Number.isFinite(e) || e <= 0)
|
|
811
|
+
throw new Error(
|
|
812
|
+
`feeRateSatsVb must be a positive finite number, got ${e}`
|
|
813
|
+
);
|
|
814
|
+
return BigInt(Math.ceil(e * W));
|
|
815
|
+
}
|
|
816
|
+
const Ue = 1, N = 65535, Fe = /non-BIP68-final/i;
|
|
817
|
+
function X(e, t) {
|
|
707
818
|
if (e.length !== 66)
|
|
708
819
|
throw new Error(
|
|
709
820
|
`${t} must be 32 bytes (66 hex chars with 0x prefix), got length ${e.length}`
|
|
710
821
|
);
|
|
711
|
-
if (!
|
|
822
|
+
if (!De.test(e))
|
|
712
823
|
throw new Error(
|
|
713
824
|
`${t} must contain only hex characters after the 0x prefix`
|
|
714
825
|
);
|
|
715
826
|
}
|
|
716
|
-
function
|
|
827
|
+
function _(e, t) {
|
|
717
828
|
if (!Number.isInteger(e) || e < 0)
|
|
718
829
|
throw new Error(`${t} must be a non-negative integer, got ${e}`);
|
|
719
830
|
}
|
|
720
|
-
function
|
|
721
|
-
if (
|
|
831
|
+
function We(e) {
|
|
832
|
+
if (X(e.hashlock, "hashlock"), !Number.isInteger(e.htlcVout) || e.htlcVout < 0 || e.htlcVout > N)
|
|
722
833
|
throw new Error(
|
|
723
|
-
`htlcVout must be an integer 0-${
|
|
834
|
+
`htlcVout must be an integer 0-${N}, got ${e.htlcVout}`
|
|
724
835
|
);
|
|
725
|
-
if (
|
|
836
|
+
if (_(e.offchainParamsVersion, "offchainParamsVersion"), _(e.appVaultKeepersVersion, "appVaultKeepersVersion"), _(
|
|
726
837
|
e.universalChallengersVersion,
|
|
727
838
|
"universalChallengersVersion"
|
|
728
839
|
), typeof e.unsignedPrePeginTxHex != "string" || e.unsignedPrePeginTxHex.length === 0)
|
|
729
840
|
throw new Error("unsignedPrePeginTxHex must be a non-empty hex string");
|
|
730
|
-
if (!
|
|
841
|
+
if (!Me.test(e.unsignedPrePeginTxHex))
|
|
731
842
|
throw new Error(
|
|
732
843
|
"unsignedPrePeginTxHex must be a hex byte string (optional 0x prefix, even length)"
|
|
733
844
|
);
|
|
@@ -738,7 +849,7 @@ function Ke(e) {
|
|
|
738
849
|
if (typeof e.amount != "bigint" || e.amount <= 0n)
|
|
739
850
|
throw new Error(`amount must be a positive bigint, got ${e.amount}`);
|
|
740
851
|
}
|
|
741
|
-
function
|
|
852
|
+
function Xe(e) {
|
|
742
853
|
if (!e.vaultProviderPubkey || !F.test(e.vaultProviderPubkey))
|
|
743
854
|
throw new Error("vaultProviderPubkey must be 32 or 33 bytes of hex");
|
|
744
855
|
if (e.vaultKeeperPubkeys.length === 0)
|
|
@@ -760,8 +871,8 @@ function Ue(e) {
|
|
|
760
871
|
`councilQuorum (${e.councilQuorum}) must be in [1, councilSize=${e.councilSize}]`
|
|
761
872
|
);
|
|
762
873
|
}
|
|
763
|
-
function
|
|
764
|
-
const t =
|
|
874
|
+
function ze(e) {
|
|
875
|
+
const t = re.fromHex(e);
|
|
765
876
|
try {
|
|
766
877
|
t.finalizeAllInputs();
|
|
767
878
|
} catch (r) {
|
|
@@ -771,40 +882,40 @@ function Fe(e) {
|
|
|
771
882
|
}
|
|
772
883
|
return t.extractTransaction().toHex();
|
|
773
884
|
}
|
|
774
|
-
async function
|
|
885
|
+
async function pt(e) {
|
|
775
886
|
const {
|
|
776
887
|
vaultId: t,
|
|
777
888
|
readVault: r,
|
|
778
889
|
readPrePeginContext: o,
|
|
779
890
|
feeRate: i,
|
|
780
|
-
signPsbt:
|
|
781
|
-
broadcastTx:
|
|
782
|
-
signal:
|
|
891
|
+
signPsbt: u,
|
|
892
|
+
broadcastTx: s,
|
|
893
|
+
signal: a
|
|
783
894
|
} = e;
|
|
784
|
-
|
|
895
|
+
a == null || a.throwIfAborted(), X(t, "vaultId");
|
|
785
896
|
const n = await r();
|
|
786
|
-
|
|
787
|
-
const
|
|
788
|
-
if (
|
|
897
|
+
We(n), a == null || a.throwIfAborted();
|
|
898
|
+
const c = await o(n);
|
|
899
|
+
if (Xe(c), a == null || a.throwIfAborted(), !Number.isFinite(i) || i <= 0)
|
|
789
900
|
throw new Error(`feeRate must be a positive number, got ${i}`);
|
|
790
|
-
const d = BigInt(Math.ceil(i *
|
|
791
|
-
|
|
792
|
-
const h =
|
|
901
|
+
const d = BigInt(Math.ceil(i * W));
|
|
902
|
+
a == null || a.throwIfAborted();
|
|
903
|
+
const h = w(
|
|
793
904
|
n.depositorBtcPubkey
|
|
794
|
-
), { psbtHex:
|
|
905
|
+
), { psbtHex: g } = await ie({
|
|
795
906
|
prePeginParams: {
|
|
796
907
|
depositorPubkey: h,
|
|
797
|
-
vaultProviderPubkey: l(
|
|
798
|
-
vaultKeeperPubkeys:
|
|
799
|
-
universalChallengerPubkeys:
|
|
908
|
+
vaultProviderPubkey: l(c.vaultProviderPubkey),
|
|
909
|
+
vaultKeeperPubkeys: c.vaultKeeperPubkeys.map(l),
|
|
910
|
+
universalChallengerPubkeys: c.universalChallengerPubkeys.map(l),
|
|
800
911
|
hashlocks: [l(n.hashlock)],
|
|
801
|
-
timelockRefund:
|
|
912
|
+
timelockRefund: c.timelockRefund,
|
|
802
913
|
pegInAmounts: [n.amount],
|
|
803
|
-
feeRate:
|
|
804
|
-
numLocalChallengers:
|
|
805
|
-
councilQuorum:
|
|
806
|
-
councilSize:
|
|
807
|
-
network:
|
|
914
|
+
feeRate: c.feeRate,
|
|
915
|
+
numLocalChallengers: c.numLocalChallengers,
|
|
916
|
+
councilQuorum: c.councilQuorum,
|
|
917
|
+
councilSize: c.councilSize,
|
|
918
|
+
network: c.network
|
|
808
919
|
},
|
|
809
920
|
fundedPrePeginTxHex: l(n.unsignedPrePeginTxHex),
|
|
810
921
|
htlcVout: n.htlcVout,
|
|
@@ -815,38 +926,40 @@ async function ut(e) {
|
|
|
815
926
|
// unspendable PSBT. Match the `hashlocks` array handling above.
|
|
816
927
|
hashlock: l(n.hashlock)
|
|
817
928
|
});
|
|
818
|
-
|
|
819
|
-
const
|
|
929
|
+
a == null || a.throwIfAborted();
|
|
930
|
+
const P = b(
|
|
820
931
|
n.depositorBtcPubkey,
|
|
821
|
-
|
|
822
|
-
),
|
|
823
|
-
|
|
932
|
+
Ue
|
|
933
|
+
), k = await u(g, P), T = ze(k);
|
|
934
|
+
a == null || a.throwIfAborted();
|
|
824
935
|
try {
|
|
825
|
-
return await
|
|
936
|
+
return await s(T);
|
|
826
937
|
} catch (p) {
|
|
827
|
-
throw p instanceof Error &&
|
|
938
|
+
throw p instanceof Error && Fe.test(p.message) ? new Le(t, p) : p;
|
|
828
939
|
}
|
|
829
940
|
}
|
|
830
941
|
export {
|
|
831
|
-
|
|
942
|
+
Le as B,
|
|
832
943
|
U as C,
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
944
|
+
Ee as P,
|
|
945
|
+
W as R,
|
|
946
|
+
rt as a,
|
|
947
|
+
Te as b,
|
|
948
|
+
at as c,
|
|
949
|
+
ut as d,
|
|
950
|
+
Ie as e,
|
|
951
|
+
Re as f,
|
|
952
|
+
ct as g,
|
|
953
|
+
ue as h,
|
|
954
|
+
st as i,
|
|
955
|
+
ce as j,
|
|
956
|
+
lt as k,
|
|
957
|
+
dt as l,
|
|
958
|
+
pt as m,
|
|
959
|
+
ht as n,
|
|
960
|
+
nt as p,
|
|
961
|
+
ot as s,
|
|
962
|
+
it as v,
|
|
850
963
|
D as w
|
|
851
964
|
};
|
|
852
|
-
//# sourceMappingURL=buildAndBroadcastRefund-
|
|
965
|
+
//# sourceMappingURL=buildAndBroadcastRefund-BRQaCQrJ.js.map
|