@babylonlabs-io/ts-sdk 0.33.7 → 0.34.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.
Files changed (37) hide show
  1. package/dist/{PeginManager-C5HaMAcw.js → PeginManager-C8-I4gFH.js} +2 -2
  2. package/dist/PeginManager-C8-I4gFH.js.map +1 -0
  3. package/dist/PeginManager-D0TW9RET.cjs +2 -0
  4. package/dist/PeginManager-D0TW9RET.cjs.map +1 -0
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.js +63 -60
  7. package/dist/tbv/core/clients/eth/index.d.ts +2 -1
  8. package/dist/tbv/core/clients/eth/index.d.ts.map +1 -1
  9. package/dist/tbv/core/clients/eth/protocol-params-reader.d.ts +21 -3
  10. package/dist/tbv/core/clients/eth/protocol-params-reader.d.ts.map +1 -1
  11. package/dist/tbv/core/clients/eth/protocol-params-validation.d.ts +27 -0
  12. package/dist/tbv/core/clients/eth/protocol-params-validation.d.ts.map +1 -0
  13. package/dist/tbv/core/clients/eth/types.d.ts +30 -0
  14. package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
  15. package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts +6 -0
  16. package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts.map +1 -1
  17. package/dist/tbv/core/clients/index.cjs +1 -1
  18. package/dist/tbv/core/clients/index.js +30 -27
  19. package/dist/tbv/core/index.cjs +1 -1
  20. package/dist/tbv/core/index.js +90 -87
  21. package/dist/tbv/core/managers/index.cjs +1 -1
  22. package/dist/tbv/core/managers/index.js +1 -1
  23. package/dist/tbv/core/vault-secrets/info.d.ts +1 -1
  24. package/dist/tbv/index.cjs +1 -1
  25. package/dist/tbv/index.js +90 -87
  26. package/dist/vault-registry-reader-Brkh1j7p.cjs +2 -0
  27. package/dist/vault-registry-reader-Brkh1j7p.cjs.map +1 -0
  28. package/dist/vault-registry-reader-CqhD3Iyd.js +1292 -0
  29. package/dist/vault-registry-reader-CqhD3Iyd.js.map +1 -0
  30. package/package.json +1 -1
  31. package/dist/PeginManager-BXg2S1mH.cjs +0 -2
  32. package/dist/PeginManager-BXg2S1mH.cjs.map +0 -1
  33. package/dist/PeginManager-C5HaMAcw.js.map +0 -1
  34. package/dist/vault-registry-reader-DNiXOSYM.cjs +0 -2
  35. package/dist/vault-registry-reader-DNiXOSYM.cjs.map +0 -1
  36. package/dist/vault-registry-reader-PsSxB0JZ.js +0 -1162
  37. package/dist/vault-registry-reader-PsSxB0JZ.js.map +0 -1
@@ -0,0 +1,1292 @@
1
+ var fe = Object.defineProperty;
2
+ var me = (t, e, n) => e in t ? fe(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
+ var p = (t, e, n) => me(t, typeof e != "symbol" ? e + "" : e, n);
4
+ import { D as be, J as re, e as _e } from "./types-TiIjyo2b.js";
5
+ import { X as R, C as L, s as C, S as ye, h as Pe } from "./bitcoin-B0S8SHCX.js";
6
+ import { H as T } from "./validation-CxqROCno.js";
7
+ import * as j from "@bitcoin-js/tiny-secp256k1-asmjs";
8
+ import { payments as we, Transaction as K } from "bitcoinjs-lib";
9
+ import { Buffer as A } from "buffer";
10
+ import { s as q } from "./sha2-6wN58S6R.js";
11
+ import { B as V } from "./BTCVaultRegistry.abi-DbJ5lsFJ.js";
12
+ import { P as _, A as F } from "./ProtocolParams.abi-DXu8L0Fn.js";
13
+ const W = new Set(Object.values(be)), ve = 200;
14
+ function l(t) {
15
+ var e;
16
+ return ((e = JSON.stringify(t)) == null ? void 0 : e.slice(0, ve)) ?? "undefined";
17
+ }
18
+ const xe = "The vault provider returned an unexpected response. Please try again or contact support.";
19
+ class s extends Error {
20
+ constructor(n) {
21
+ super(xe);
22
+ p(this, "detail");
23
+ this.name = "VpResponseValidationError", this.detail = n;
24
+ }
25
+ }
26
+ const $ = 64;
27
+ function w(t) {
28
+ return typeof t == "string" && t.length > 0 && T.test(t);
29
+ }
30
+ function ie(t) {
31
+ return typeof t == "string" && t.length > 0;
32
+ }
33
+ function se(t, e) {
34
+ if (!w(t))
35
+ throw new s(
36
+ `VP response validation failed: "${e}" must be a non-empty hex string, got ${l(t)}`
37
+ );
38
+ }
39
+ function m(t, e) {
40
+ if (!ie(t))
41
+ throw new s(
42
+ `VP response validation failed: "${e}" must be a non-empty string, got ${l(t)}`
43
+ );
44
+ }
45
+ function oe(t, e) {
46
+ if (!w(t) || t.length !== R && t.length !== L)
47
+ throw new s(
48
+ `VP response validation failed: "${e}" must be a ${R} or ${L}-char hex string (BTC pubkey), got ${l(t)}`
49
+ );
50
+ }
51
+ function Ae(t) {
52
+ const e = t.presigning;
53
+ if (e == null) return;
54
+ if (typeof e != "object" || Array.isArray(e))
55
+ throw new s(
56
+ 'VP response validation failed: "progress.presigning" must be an object if present'
57
+ );
58
+ const n = e;
59
+ if (n.depositor_graph_created !== void 0 && typeof n.depositor_graph_created != "boolean")
60
+ throw new s(
61
+ `VP response validation failed: "progress.presigning.depositor_graph_created" must be a boolean if present, got ${l(n.depositor_graph_created)}`
62
+ );
63
+ if (n.vk_challenger_presigning_completed !== void 0 && typeof n.vk_challenger_presigning_completed != "number")
64
+ throw new s(
65
+ `VP response validation failed: "progress.presigning.vk_challenger_presigning_completed" must be a number if present, got ${l(n.vk_challenger_presigning_completed)}`
66
+ );
67
+ if (n.vk_challenger_presigning_total !== void 0 && typeof n.vk_challenger_presigning_total != "number")
68
+ throw new s(
69
+ `VP response validation failed: "progress.presigning.vk_challenger_presigning_total" must be a number if present, got ${l(n.vk_challenger_presigning_total)}`
70
+ );
71
+ }
72
+ function ae(t) {
73
+ if (t === null || typeof t != "object")
74
+ throw new s(
75
+ "VP response validation failed: getPeginStatus response is not an object"
76
+ );
77
+ const e = t;
78
+ if (!w(e.pegin_txid) || e.pegin_txid.length !== $)
79
+ throw new s(
80
+ `VP response validation failed: "pegin_txid" must be a ${$}-char hex string (txid), got ${l(e.pegin_txid)}`
81
+ );
82
+ if (typeof e.status != "string")
83
+ throw new s(
84
+ 'VP response validation failed: "status" must be a string'
85
+ );
86
+ if (!W.has(e.status))
87
+ throw new s(
88
+ `VP response validation failed: unrecognized status "${e.status}". Expected one of: ${[...W].join(", ")}`
89
+ );
90
+ if (e.progress === null || typeof e.progress != "object" || Array.isArray(e.progress))
91
+ throw new s(
92
+ 'VP response validation failed: "progress" must be an object'
93
+ );
94
+ if (Ae(e.progress), typeof e.health_info != "string")
95
+ throw new s(
96
+ 'VP response validation failed: "health_info" must be a string'
97
+ );
98
+ if (e.last_error !== void 0 && typeof e.last_error != "string")
99
+ throw new s(
100
+ `VP response validation failed: "last_error" must be a string if present, got ${l(e.last_error)}`
101
+ );
102
+ }
103
+ function Ve(t) {
104
+ if (t === null || typeof t != "object")
105
+ throw new s(
106
+ "VP response validation failed: requestDepositorPresignTransactions response is not an object"
107
+ );
108
+ const e = t;
109
+ if (!Array.isArray(e.txs))
110
+ throw new s(
111
+ 'VP response validation failed: "txs" must be an array'
112
+ );
113
+ for (let n = 0; n < e.txs.length; n++)
114
+ $e(e.txs[n], `txs[${n}]`);
115
+ if (e.depositor_graph === null || typeof e.depositor_graph != "object")
116
+ throw new s(
117
+ 'VP response validation failed: "depositor_graph" must be an object'
118
+ );
119
+ Re(
120
+ e.depositor_graph
121
+ );
122
+ }
123
+ function y(t, e) {
124
+ if (t === null || typeof t != "object")
125
+ throw new s(
126
+ `VP response validation failed: "${e}" must be an object`
127
+ );
128
+ se(t.tx_hex, `${e}.tx_hex`);
129
+ }
130
+ function $e(t, e) {
131
+ if (t === null || typeof t != "object")
132
+ throw new s(
133
+ `VP response validation failed: "${e}" must be an object`
134
+ );
135
+ const n = t;
136
+ oe(n.claimer_pubkey, `${e}.claimer_pubkey`), y(n.claim_tx, `${e}.claim_tx`), y(n.assert_tx, `${e}.assert_tx`), y(n.payout_tx, `${e}.payout_tx`), m(n.payout_psbt, `${e}.payout_psbt`);
137
+ }
138
+ function Te(t, e) {
139
+ if (t === null || typeof t != "object")
140
+ throw new s(
141
+ `VP response validation failed: "${e}" must be an object`
142
+ );
143
+ const n = t;
144
+ m(n.wots_pks_json, `${e}.wots_pks_json`), m(n.gc_wots_keys_json, `${e}.gc_wots_keys_json`);
145
+ }
146
+ function ke(t, e) {
147
+ if (t === null || typeof t != "object")
148
+ throw new s(
149
+ `VP response validation failed: "${e}" must be an object`
150
+ );
151
+ const n = t;
152
+ if (oe(n.challenger_pubkey, `${e}.challenger_pubkey`), y(
153
+ n.challenge_assert_x_tx,
154
+ `${e}.challenge_assert_x_tx`
155
+ ), y(
156
+ n.challenge_assert_y_tx,
157
+ `${e}.challenge_assert_y_tx`
158
+ ), y(n.nopayout_tx, `${e}.nopayout_tx`), m(n.nopayout_psbt, `${e}.nopayout_psbt`), !Array.isArray(n.challenge_assert_connectors))
159
+ throw new s(
160
+ `VP response validation failed: "${e}.challenge_assert_connectors" must be an array`
161
+ );
162
+ for (let r = 0; r < n.challenge_assert_connectors.length; r++)
163
+ Te(
164
+ n.challenge_assert_connectors[r],
165
+ `${e}.challenge_assert_connectors[${r}]`
166
+ );
167
+ if (!Array.isArray(n.output_label_hashes))
168
+ throw new s(
169
+ `VP response validation failed: "${e}.output_label_hashes" must be an array`
170
+ );
171
+ for (let r = 0; r < n.output_label_hashes.length; r++)
172
+ se(
173
+ n.output_label_hashes[r],
174
+ `${e}.output_label_hashes[${r}]`
175
+ );
176
+ }
177
+ function Se(t) {
178
+ if (t === null || typeof t != "object")
179
+ throw new s(
180
+ "VP response validation failed: requestDepositorClaimerArtifacts response is not an object"
181
+ );
182
+ const e = t;
183
+ if (!ie(e.tx_graph_json))
184
+ throw new s(
185
+ `VP response validation failed: "tx_graph_json" must be a non-empty string, got ${l(e.tx_graph_json)}`
186
+ );
187
+ if (!w(e.verifying_key_hex))
188
+ throw new s(
189
+ `VP response validation failed: "verifying_key_hex" must be a non-empty hex string, got ${l(e.verifying_key_hex)}`
190
+ );
191
+ if (e.babe_sessions === null || typeof e.babe_sessions != "object")
192
+ throw new s(
193
+ 'VP response validation failed: "babe_sessions" must be an object'
194
+ );
195
+ for (const [n, r] of Object.entries(
196
+ e.babe_sessions
197
+ )) {
198
+ if (r === null || typeof r != "object")
199
+ throw new s(
200
+ `VP response validation failed: "babe_sessions.${n}" must be an object`
201
+ );
202
+ const i = r;
203
+ if (!w(i.decryptor_artifacts_hex))
204
+ throw new s(
205
+ `VP response validation failed: "babe_sessions.${n}.decryptor_artifacts_hex" must be a non-empty hex string, got ${l(i.decryptor_artifacts_hex)}`
206
+ );
207
+ }
208
+ }
209
+ function Ce(t) {
210
+ if (t === null || typeof t != "object")
211
+ throw new s(
212
+ "VP response validation failed: pegout status payload is not an object"
213
+ );
214
+ const e = t;
215
+ if (!w(e.pegin_txid) || e.pegin_txid.length !== $)
216
+ throw new s(
217
+ `VP response validation failed: "pegin_txid" must be a ${$}-char hex string (txid), got ${l(e.pegin_txid)}`
218
+ );
219
+ if (typeof e.found != "boolean")
220
+ throw new s(
221
+ `VP response validation failed: "found" must be a boolean, got ${l(e.found)}`
222
+ );
223
+ if (e.claimer !== null) {
224
+ if (typeof e.claimer != "object")
225
+ throw new s(
226
+ `VP response validation failed: "claimer" must be an object or null, got ${l(e.claimer)}`
227
+ );
228
+ Ie(e.claimer);
229
+ }
230
+ if (!Array.isArray(e.challengers))
231
+ throw new s(
232
+ `VP response validation failed: "challengers" must be an array, got ${l(e.challengers)}`
233
+ );
234
+ for (let n = 0; n < e.challengers.length; n++)
235
+ Ee(e.challengers[n], n);
236
+ }
237
+ function Ie(t) {
238
+ if (m(t.status, "claimer.status"), typeof t.failed != "boolean")
239
+ throw new s(
240
+ `VP response validation failed: "claimer.failed" must be a boolean, got ${l(t.failed)}`
241
+ );
242
+ if (m(t.claim_txid, "claimer.claim_txid"), m(t.claimer_pubkey, "claimer.claimer_pubkey"), m(t.assert_txid, "claimer.assert_txid"), t.challenger_pubkey !== null && typeof t.challenger_pubkey != "string")
243
+ throw new s(
244
+ `VP response validation failed: "claimer.challenger_pubkey" must be a string or null, got ${l(t.challenger_pubkey)}`
245
+ );
246
+ if (typeof t.created_at != "number")
247
+ throw new s(
248
+ `VP response validation failed: "claimer.created_at" must be a number, got ${l(t.created_at)}`
249
+ );
250
+ if (typeof t.updated_at != "number")
251
+ throw new s(
252
+ `VP response validation failed: "claimer.updated_at" must be a number, got ${l(t.updated_at)}`
253
+ );
254
+ }
255
+ function Ee(t, e) {
256
+ if (t === null || typeof t != "object")
257
+ throw new s(
258
+ `VP response validation failed: "challengers[${e}]" must be an object, got ${l(t)}`
259
+ );
260
+ const n = t;
261
+ if (m(n.status, `challengers[${e}].status`), m(n.claim_txid, `challengers[${e}].claim_txid`), m(n.claimer_pubkey, `challengers[${e}].claimer_pubkey`), I(n.assert_txid, `challengers[${e}].assert_txid`), I(
262
+ n.challenge_assert_x_txid,
263
+ `challengers[${e}].challenge_assert_x_txid`
264
+ ), I(
265
+ n.challenge_assert_y_txid,
266
+ `challengers[${e}].challenge_assert_y_txid`
267
+ ), I(n.nopayout_txid, `challengers[${e}].nopayout_txid`), typeof n.created_at != "number")
268
+ throw new s(
269
+ `VP response validation failed: "challengers[${e}].created_at" must be a number, got ${l(n.created_at)}`
270
+ );
271
+ if (typeof n.updated_at != "number")
272
+ throw new s(
273
+ `VP response validation failed: "challengers[${e}].updated_at" must be a number, got ${l(n.updated_at)}`
274
+ );
275
+ }
276
+ function I(t, e) {
277
+ if (t !== null && typeof t != "string")
278
+ throw new s(
279
+ `VP response validation failed: "${e}" must be a string or null, got ${l(t)}`
280
+ );
281
+ }
282
+ function Be(t) {
283
+ ce(t, "batchGetPeginStatus", (e) => {
284
+ e.result !== null && ae(e.result);
285
+ });
286
+ }
287
+ function Ne(t) {
288
+ ce(t, "batchGetPegoutStatus", (e) => {
289
+ e.result !== null && Ce(e.result);
290
+ });
291
+ }
292
+ function ce(t, e, n) {
293
+ if (t === null || typeof t != "object")
294
+ throw new s(
295
+ `VP response validation failed: ${e} response is not an object`
296
+ );
297
+ const r = t;
298
+ if (!Array.isArray(r.results))
299
+ throw new s(
300
+ `VP response validation failed: "${e}.results" must be an array, got ${l(r.results)}`
301
+ );
302
+ for (let i = 0; i < r.results.length; i++) {
303
+ const o = r.results[i];
304
+ if (o === null || typeof o != "object")
305
+ throw new s(
306
+ `VP response validation failed: "${e}.results[${i}]" must be an object, got ${l(o)}`
307
+ );
308
+ const a = o;
309
+ if (!w(a.pegin_txid) || a.pegin_txid.length !== $)
310
+ throw new s(
311
+ `VP response validation failed: "${e}.results[${i}].pegin_txid" must be a ${$}-char hex string, got ${l(a.pegin_txid)}`
312
+ );
313
+ if (a.error !== null && typeof a.error != "string")
314
+ throw new s(
315
+ `VP response validation failed: "${e}.results[${i}].error" must be a string or null, got ${l(a.error)}`
316
+ );
317
+ if (a.result === null && a.error === null)
318
+ throw new s(
319
+ `VP response validation failed: "${e}.results[${i}]" has neither "result" nor "error" populated`
320
+ );
321
+ if (a.result !== null && a.error !== null)
322
+ throw new s(
323
+ `VP response validation failed: "${e}.results[${i}]" has both "result" and "error" populated`
324
+ );
325
+ n(a, i);
326
+ }
327
+ }
328
+ function Re(t) {
329
+ if (y(t.claim_tx, "depositor_graph.claim_tx"), y(t.assert_tx, "depositor_graph.assert_tx"), y(t.payout_tx, "depositor_graph.payout_tx"), m(t.payout_psbt, "depositor_graph.payout_psbt"), !Array.isArray(t.challenger_presign_data))
330
+ throw new s(
331
+ 'VP response validation failed: "depositor_graph.challenger_presign_data" must be an array'
332
+ );
333
+ for (let e = 0; e < t.challenger_presign_data.length; e++)
334
+ ke(
335
+ t.challenger_presign_data[e],
336
+ `depositor_graph.challenger_presign_data[${e}]`
337
+ );
338
+ if (typeof t.offchain_params_version != "number")
339
+ throw new s(
340
+ 'VP response validation failed: "depositor_graph.offchain_params_version" must be a number'
341
+ );
342
+ }
343
+ const Oe = 6e4;
344
+ class He {
345
+ constructor(e, n) {
346
+ p(this, "client");
347
+ const r = {
348
+ baseUrl: e,
349
+ timeout: (n == null ? void 0 : n.timeout) ?? Oe,
350
+ retries: n == null ? void 0 : n.retries,
351
+ retryDelay: n == null ? void 0 : n.retryDelay,
352
+ retryableFor: n == null ? void 0 : n.retryableFor,
353
+ headers: n == null ? void 0 : n.headers,
354
+ tokenProvider: n == null ? void 0 : n.tokenProvider,
355
+ maxResponseBytes: n == null ? void 0 : n.maxResponseBytes
356
+ };
357
+ this.client = new re(r);
358
+ }
359
+ /**
360
+ * Request the payout/claim/assert transactions that the depositor
361
+ * needs to pre-sign before the vault can be activated on Bitcoin.
362
+ */
363
+ async requestDepositorPresignTransactions(e, n) {
364
+ const r = await this.client.call("vaultProvider_requestDepositorPresignTransactions", e, n);
365
+ return Ve(r), r;
366
+ }
367
+ /**
368
+ * Submit the depositor's pre-signatures for the payout transactions
369
+ * and the depositor-as-claimer graph.
370
+ */
371
+ async submitDepositorPresignatures(e, n) {
372
+ return this.client.call(
373
+ "vaultProvider_submitDepositorPresignatures",
374
+ e,
375
+ n
376
+ );
377
+ }
378
+ /**
379
+ * Submit the depositor's WOTS public key to the vault provider.
380
+ * Called after the pegin is finalized on Ethereum, when the VP is in
381
+ * `PendingDepositorWotsPK` status.
382
+ */
383
+ async submitDepositorWotsKey(e, n) {
384
+ return this.client.call(
385
+ "vaultProvider_submitDepositorWotsKey",
386
+ e,
387
+ n
388
+ );
389
+ }
390
+ /**
391
+ * Request the BaBe DecryptorArtifacts needed for the depositor to
392
+ * independently evaluate garbled circuits during a challenge.
393
+ */
394
+ async requestDepositorClaimerArtifacts(e, n) {
395
+ const r = await this.client.call("vaultProvider_requestDepositorClaimerArtifacts", e, n);
396
+ return Se(r), r;
397
+ }
398
+ /** Get the current pegin status from the vault provider daemon. */
399
+ async getPeginStatus(e, n) {
400
+ const r = await this.client.call(
401
+ "vaultProvider_getPeginStatus",
402
+ e,
403
+ n
404
+ );
405
+ return ae(r), r;
406
+ }
407
+ /**
408
+ * Get pegin status for many txids in one round trip. Per-result envelope
409
+ * isolates per-pegin failures from the overall RPC. Caller must chunk
410
+ * inputs at `VP_BATCH_MAX_SIZE`.
411
+ */
412
+ async batchGetPeginStatus(e, n) {
413
+ const r = await this.client.call("vaultProvider_batchGetPeginStatus", e, n);
414
+ return Be(r), r;
415
+ }
416
+ /**
417
+ * Get pegout status for many txids in one round trip. Same per-result
418
+ * envelope semantics as `batchGetPeginStatus`.
419
+ */
420
+ async batchGetPegoutStatus(e, n) {
421
+ const r = await this.client.call("vaultProvider_batchGetPegoutStatus", e, n);
422
+ return Ne(r), r;
423
+ }
424
+ }
425
+ function De(t, e) {
426
+ const n = /* @__PURE__ */ new Set();
427
+ for (const u of t)
428
+ n.add(u.toLowerCase());
429
+ const r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set(), o = [], a = [];
430
+ for (const u of e) {
431
+ const h = u.pegin_txid.toLowerCase();
432
+ if (!n.has(h)) {
433
+ a.push(h);
434
+ continue;
435
+ }
436
+ if (i.has(h)) {
437
+ o.push(h);
438
+ continue;
439
+ }
440
+ i.add(h), r.set(h, { result: u.result, error: u.error });
441
+ }
442
+ const c = [];
443
+ for (const u of n)
444
+ i.has(u) || c.push(u);
445
+ return { byTxid: r, missing: c, unexpected: a, duplicate: o };
446
+ }
447
+ async function lt(t) {
448
+ const {
449
+ items: e,
450
+ getTxid: n,
451
+ batchCall: r,
452
+ onItem: i,
453
+ onMissing: o,
454
+ onDuplicate: a,
455
+ onDuplicateBatch: c,
456
+ onWholeBatchError: u,
457
+ onUnexpected: h,
458
+ batchSize: f = _e
459
+ } = t;
460
+ if (!Number.isInteger(f) || f <= 0)
461
+ throw new Error(
462
+ `batchPollByProvider: batchSize must be a positive integer, got ${f}`
463
+ );
464
+ for (let P = 0; P < e.length; P += f) {
465
+ const v = e.slice(P, P + f), k = /* @__PURE__ */ new Map(), U = [];
466
+ for (const d of v) {
467
+ const b = n(d).toLowerCase();
468
+ k.set(b, d), U.push(b);
469
+ }
470
+ let x;
471
+ try {
472
+ const d = await r(U);
473
+ x = De(U, d.results);
474
+ } catch (d) {
475
+ u(v, d);
476
+ continue;
477
+ }
478
+ h && x.unexpected.length > 0 && h(x.unexpected);
479
+ const S = new Set(x.duplicate);
480
+ for (const d of S) {
481
+ const b = k.get(d);
482
+ b && a(b);
483
+ }
484
+ c && S.size > 0 && c(S.size);
485
+ for (const d of x.missing) {
486
+ const b = k.get(d);
487
+ b && o(b);
488
+ }
489
+ for (const [d, b] of x.byTxid) {
490
+ if (S.has(d)) continue;
491
+ const z = k.get(d);
492
+ z && i(z, {
493
+ pegin_txid: d,
494
+ result: b.result,
495
+ error: b.error
496
+ });
497
+ }
498
+ }
499
+ }
500
+ const je = "BIP0322-signed-message", Ue = "TapTweak", le = 32, Ke = 64;
501
+ function ue(t, e) {
502
+ const n = new TextEncoder().encode(t), r = q(n), i = new Uint8Array(r.length * 2 + e.length);
503
+ return i.set(r, 0), i.set(r, r.length), i.set(e, r.length * 2), q(i);
504
+ }
505
+ function Fe(t) {
506
+ if (t.length !== le) return null;
507
+ const e = ue(Ue, t), n = j.xOnlyPointAddTweak(t, e);
508
+ return n ? n.xOnlyPubkey : null;
509
+ }
510
+ function Me(t, e, n) {
511
+ if (e.length !== le || n.length !== Ke) return !1;
512
+ try {
513
+ const r = ue(je, t), i = we.p2tr({
514
+ internalPubkey: A.from(e)
515
+ });
516
+ if (!i.output) return !1;
517
+ const o = i.output, a = 0, c = new K();
518
+ c.version = 0, c.locktime = 0;
519
+ const u = A.concat([
520
+ A.from([0, 32]),
521
+ A.from(r)
522
+ ]);
523
+ c.addInput(
524
+ A.alloc(32, 0),
525
+ // prev_txid = 0x0000...0000
526
+ 4294967295,
527
+ // prev_vout = 0xFFFFFFFF
528
+ 0,
529
+ // sequence = 0
530
+ u
531
+ ), c.addOutput(o, a);
532
+ const h = new K();
533
+ h.version = 0, h.locktime = 0;
534
+ const f = c.getHash();
535
+ h.addInput(f, 0, 0), h.addOutput(A.from([106]), a);
536
+ const P = h.hashForWitnessV1(
537
+ 0,
538
+ [o],
539
+ [a],
540
+ K.SIGHASH_DEFAULT
541
+ ), v = Fe(e);
542
+ return v ? j.verifySchnorr(P, v, n) : !1;
543
+ } catch {
544
+ return !1;
545
+ }
546
+ }
547
+ function O(t, e) {
548
+ const n = (t & 7) << 5, r = typeof e == "bigint" ? e : BigInt(e);
549
+ if (r < 0n) throw new Error("cborHead: negative argument");
550
+ if (r < 24n) return new Uint8Array([n | Number(r)]);
551
+ if (r < 0x100n) return new Uint8Array([n | 24, Number(r)]);
552
+ if (r < 0x10000n) {
553
+ const o = Number(r);
554
+ return new Uint8Array([n | 25, o >>> 8 & 255, o & 255]);
555
+ }
556
+ if (r < 0x100000000n) {
557
+ const o = Number(r);
558
+ return new Uint8Array([
559
+ n | 26,
560
+ o >>> 24 & 255,
561
+ o >>> 16 & 255,
562
+ o >>> 8 & 255,
563
+ o & 255
564
+ ]);
565
+ }
566
+ const i = new Uint8Array(9);
567
+ i[0] = n | 27;
568
+ for (let o = 7; o >= 0; o--)
569
+ i[1 + o] = Number(r >> BigInt((7 - o) * 8)) & 255;
570
+ return i;
571
+ }
572
+ function he(...t) {
573
+ const e = t.reduce((i, o) => i + o.length, 0), n = new Uint8Array(e);
574
+ let r = 0;
575
+ for (const i of t)
576
+ n.set(i, r), r += i.length;
577
+ return n;
578
+ }
579
+ function Q(t) {
580
+ const n = [O(4, t.length)];
581
+ for (const r of t)
582
+ n.push(O(0, r));
583
+ return he(...n);
584
+ }
585
+ function Le(t, e, n) {
586
+ if (!Number.isSafeInteger(n) || n < 0)
587
+ throw new Error(
588
+ `encodeServerIdentityPayload: expires_at must be a non-negative safe integer, got ${n}`
589
+ );
590
+ const r = O(4, 3), i = Q(t), o = Q(e), a = O(0, n);
591
+ return he(r, i, o, a);
592
+ }
593
+ const Ge = new TextEncoder().encode(
594
+ "btc-auth.server-identity.v1"
595
+ ), Xe = 2 * 3600;
596
+ class g extends Error {
597
+ constructor(e, n) {
598
+ super(e), this.reason = n, this.name = "ServerIdentityError";
599
+ }
600
+ }
601
+ function E(t) {
602
+ const e = new Uint8Array(t.length / 2);
603
+ for (let n = 0; n < e.length; n++)
604
+ e[n] = parseInt(t.slice(n * 2, n * 2 + 2), 16);
605
+ return e;
606
+ }
607
+ function ze(t) {
608
+ const { proof: e, pinnedServerPubkey: n, now: r } = t, i = t.maxLifetimeSecs ?? Xe, o = C(n).toLowerCase();
609
+ if (o.length !== R || !T.test(o))
610
+ throw new g(
611
+ `pinnedServerPubkey must be 32-byte hex; got ${o.length} chars`,
612
+ "invalid_pubkey_encoding"
613
+ );
614
+ const a = C(e.server_pubkey).toLowerCase();
615
+ if (a.length !== R || !T.test(a))
616
+ throw new g(
617
+ `server_pubkey must be 32-byte hex; got ${a.length} chars`,
618
+ "invalid_pubkey_encoding"
619
+ );
620
+ if (a !== o)
621
+ throw new g(
622
+ `server_pubkey does not match pinned value: expected ${o}, got ${a}`,
623
+ "pinned_pubkey_mismatch"
624
+ );
625
+ if (!Number.isSafeInteger(e.expires_at))
626
+ throw new g(
627
+ `expires_at must be a finite integer; got ${JSON.stringify(e.expires_at)}`,
628
+ "invalid_expires_at"
629
+ );
630
+ if (!Number.isSafeInteger(r))
631
+ throw new g(
632
+ `now must be a finite integer; got ${JSON.stringify(r)}`,
633
+ "invalid_expires_at"
634
+ );
635
+ if (e.expires_at <= r)
636
+ throw new g(
637
+ `server identity proof expired at ${e.expires_at}, now ${r}`,
638
+ "expired"
639
+ );
640
+ if (!Number.isSafeInteger(i) || i <= 0)
641
+ throw new g(
642
+ `maxLifetimeSecs must be a positive safe integer; got ${JSON.stringify(i)}`,
643
+ "invalid_max_lifetime"
644
+ );
645
+ if (e.expires_at - r > i)
646
+ throw new g(
647
+ `server identity proof expires too far in the future: expires_at=${e.expires_at}, now=${r}, max lifetime=${i}s`,
648
+ "expires_too_far"
649
+ );
650
+ const c = C(e.ephemeral_pubkey).toLowerCase();
651
+ if (c.length !== L || !T.test(c))
652
+ throw new g(
653
+ `ephemeral_pubkey must be 33-byte compressed hex; got ${c.length} chars`,
654
+ "invalid_ephemeral_pubkey"
655
+ );
656
+ const u = c.slice(0, 2);
657
+ if (u !== "02" && u !== "03")
658
+ throw new g(
659
+ `ephemeral_pubkey must be compressed (prefix 02/03); got ${u}`,
660
+ "invalid_ephemeral_pubkey"
661
+ );
662
+ const h = E(c);
663
+ if (!j.isPoint(h))
664
+ throw new g(
665
+ "ephemeral_pubkey is not a valid secp256k1 point",
666
+ "invalid_ephemeral_pubkey"
667
+ );
668
+ const f = C(e.signature).toLowerCase();
669
+ if (f.length !== ye || !T.test(f))
670
+ throw new g(
671
+ `signature must be 64-byte Schnorr hex; got ${f.length} chars`,
672
+ "invalid_signature_encoding"
673
+ );
674
+ const P = Le(
675
+ Ge,
676
+ E(c),
677
+ e.expires_at
678
+ );
679
+ if (!Me(P, E(a), E(f)))
680
+ throw new g(
681
+ "BIP-322 signature verification failed — ephemeral key is not attested by pinned server pubkey",
682
+ "signature_verification_failed"
683
+ );
684
+ }
685
+ const qe = /* @__PURE__ */ new Set([
686
+ "vaultProvider_submitDepositorWotsKey",
687
+ "vaultProvider_submitDepositorPresignatures",
688
+ "vaultProvider_requestDepositorPresignTransactions"
689
+ ]), We = 6e4, G = "auth_createDepositorToken";
690
+ function de(t, e) {
691
+ return new re({
692
+ baseUrl: t,
693
+ timeout: We,
694
+ headers: e,
695
+ retryableFor: (n) => n === G
696
+ });
697
+ }
698
+ const J = 4102444800, Qe = 30;
699
+ class Je {
700
+ constructor(e) {
701
+ // `client` is the only mutable field — see `setClient`. The
702
+ // identity-bearing fields (peginTxid/authAnchorHex/pinnedServerPubkey)
703
+ // remain readonly and are checked against re-registration in the
704
+ // registry's `getOrCreate`.
705
+ p(this, "client");
706
+ p(this, "peginTxid");
707
+ p(this, "authAnchorHex");
708
+ p(this, "pinnedServerPubkey");
709
+ p(this, "authGatedMethods");
710
+ p(this, "refreshSkewSecs");
711
+ p(this, "now");
712
+ p(this, "cached", null);
713
+ p(this, "inFlight", null);
714
+ this.client = e.client, this.peginTxid = e.peginTxid, this.authAnchorHex = e.authAnchorHex, this.pinnedServerPubkey = e.pinnedServerPubkey, this.authGatedMethods = e.authGatedMethods, this.refreshSkewSecs = e.refreshSkewSecs ?? Qe, this.now = e.now ?? (() => Math.floor(Date.now() / 1e3));
715
+ }
716
+ /**
717
+ * Return a bearer token for `method`, or `null` if `method` is not
718
+ * auth-gated. Triggers a token acquisition if no token is cached or
719
+ * the cached token is within {@link refreshSkewSecs} of expiry.
720
+ *
721
+ * The token-issuing method itself is hard-exempted from the gate —
722
+ * if `auth_createDepositorToken` were ever included in
723
+ * `authGatedMethods` (caller misconfiguration) the provider would
724
+ * recurse into `acquireSingleFlight` from inside the JSON-RPC header
725
+ * builder before `inFlight` is assigned, defeating the single-flight
726
+ * guard. Returning `null` here breaks that recursion deterministically.
727
+ */
728
+ async getToken(e) {
729
+ if (e === G || !this.authGatedMethods.has(e)) return null;
730
+ const n = this.cached;
731
+ return n && this.now() + this.refreshSkewSecs < n.expiresAt ? n.token : (await this.acquireSingleFlight()).token;
732
+ }
733
+ /**
734
+ * Drop the cached token. Next `getToken` call re-acquires.
735
+ * Called by `JsonRpcClient` on wire `auth_expired` responses.
736
+ */
737
+ invalidate() {
738
+ this.cached = null;
739
+ }
740
+ /**
741
+ * Swap in a different transport for subsequent token-issuing calls.
742
+ * Used by the registry when a later caller registers the same
743
+ * `peginTxid` against a different `baseUrl` — the cached token
744
+ * (bound to identity, not transport) stays valid, but future
745
+ * refreshes hit the new URL. An in-flight acquire keeps using the
746
+ * old client (it captured the reference); next call uses the new.
747
+ */
748
+ setClient(e) {
749
+ this.client = e;
750
+ }
751
+ acquireSingleFlight() {
752
+ const e = this.inFlight;
753
+ if (e) return e;
754
+ const n = (async () => {
755
+ try {
756
+ const r = await this.client.call(G, {
757
+ pegin_txid: this.peginTxid,
758
+ auth_anchor: this.authAnchorHex
759
+ });
760
+ if (ze({
761
+ proof: r.server_identity,
762
+ pinnedServerPubkey: this.pinnedServerPubkey,
763
+ now: this.now()
764
+ }), typeof r.token != "string" || r.token.length === 0)
765
+ throw new Error(
766
+ `VpTokenProvider: invalid token in acquire response (expected non-empty string, got ${typeof r.token})`
767
+ );
768
+ const i = this.now();
769
+ if (!Number.isSafeInteger(r.expires_at) || r.expires_at <= i || r.expires_at > J)
770
+ throw new Error(
771
+ `VpTokenProvider: invalid expires_at in acquire response (got ${JSON.stringify(r.expires_at)}; must be a safe integer in (${i}, ${J}])`
772
+ );
773
+ const o = {
774
+ token: r.token,
775
+ expiresAt: r.expires_at
776
+ };
777
+ return this.cached = o, o;
778
+ } finally {
779
+ this.inFlight = null;
780
+ }
781
+ })();
782
+ return this.inFlight = n, n;
783
+ }
784
+ }
785
+ class Ye {
786
+ constructor() {
787
+ p(this, "entries", /* @__PURE__ */ new Map());
788
+ }
789
+ /**
790
+ * Return the cached `VpTokenProvider` for `peginTxid` if one exists
791
+ * with matching `authAnchorHex` and `pinnedServerPubkey`, otherwise
792
+ * construct and cache a fresh provider. A mismatch on either field
793
+ * throws — silent overwrite would mask derivation drift or VP
794
+ * pubkey rotation.
795
+ */
796
+ getOrCreate(e) {
797
+ const n = this.entries.get(e.peginTxid);
798
+ if (n) {
799
+ if (n.authAnchorHex !== e.authAnchorHex)
800
+ throw new Error(
801
+ `VpTokenRegistry: peginTxid ${e.peginTxid} already bound to authAnchorHex ${n.authAnchorHex.slice(0, 8)}…; got ${e.authAnchorHex.slice(0, 8)}…`
802
+ );
803
+ if (n.pinnedServerPubkey !== e.pinnedServerPubkey)
804
+ throw new Error(
805
+ `VpTokenRegistry: peginTxid ${e.peginTxid} already bound to pinnedServerPubkey ${n.pinnedServerPubkey.slice(0, 8)}…; got ${e.pinnedServerPubkey.slice(0, 8)}…`
806
+ );
807
+ return n.provider.setClient(e.client), n.provider;
808
+ }
809
+ const r = new Je({
810
+ client: e.client,
811
+ peginTxid: e.peginTxid,
812
+ authAnchorHex: e.authAnchorHex,
813
+ pinnedServerPubkey: e.pinnedServerPubkey,
814
+ authGatedMethods: qe
815
+ });
816
+ return this.entries.set(e.peginTxid, {
817
+ provider: r,
818
+ authAnchorHex: e.authAnchorHex,
819
+ pinnedServerPubkey: e.pinnedServerPubkey
820
+ }), r;
821
+ }
822
+ /** Return the cached provider, or `undefined` if none. */
823
+ peek(e) {
824
+ var n;
825
+ return (n = this.entries.get(e)) == null ? void 0 : n.provider;
826
+ }
827
+ /**
828
+ * Evict the entry for `peginTxid`. Idempotent. Called on terminal
829
+ * paths — activation success, user-cancel, or component unmount —
830
+ * so `authAnchorHex` doesn't outlive the deposit session.
831
+ */
832
+ release(e) {
833
+ this.entries.delete(e);
834
+ }
835
+ /**
836
+ * Wipe every cached entry. Test-only escape hatch — not exposed on
837
+ * the public {@link VpTokenRegistryPublic} singleton type.
838
+ *
839
+ * @internal
840
+ */
841
+ clear() {
842
+ this.entries.clear();
843
+ }
844
+ get size() {
845
+ return this.entries.size;
846
+ }
847
+ }
848
+ const pe = new Ye();
849
+ function ut(t) {
850
+ var r;
851
+ const e = de(
852
+ t.baseUrl,
853
+ (r = t.options) == null ? void 0 : r.headers
854
+ ), n = pe.getOrCreate({
855
+ client: e,
856
+ peginTxid: t.peginTxid,
857
+ authAnchorHex: t.authAnchorHex,
858
+ pinnedServerPubkey: t.pinnedServerPubkey
859
+ });
860
+ return new He(t.baseUrl, {
861
+ ...t.options,
862
+ tokenProvider: n
863
+ });
864
+ }
865
+ function ht(t) {
866
+ pe.getOrCreate({
867
+ client: de(t.baseUrl, t.headers),
868
+ peginTxid: t.peginTxid,
869
+ authAnchorHex: t.authAnchorHex,
870
+ pinnedServerPubkey: t.pinnedServerPubkey
871
+ });
872
+ }
873
+ async function dt(t, e) {
874
+ const [n, r] = await t.multicall({
875
+ contracts: [
876
+ {
877
+ address: e,
878
+ abi: V,
879
+ functionName: "protocolParams"
880
+ },
881
+ {
882
+ address: e,
883
+ abi: V,
884
+ functionName: "applicationRegistry"
885
+ }
886
+ ],
887
+ allowFailure: !1
888
+ });
889
+ return {
890
+ protocolParams: n,
891
+ applicationRegistry: r
892
+ };
893
+ }
894
+ const M = 65535, Y = 1e4, H = 4294967295, Z = 255;
895
+ function X(t) {
896
+ if (!Number.isInteger(t) || t < 0 || t > H)
897
+ throw new Error(
898
+ `Invalid offchainParamsVersion from contract: must be a uint32, got ${t}`
899
+ );
900
+ }
901
+ function N(t) {
902
+ const e = [];
903
+ if (t.timelockAssert <= 0n && e.push(
904
+ `timelockAssert must be positive, got ${t.timelockAssert}`
905
+ ), t.timelockAssert > BigInt(M) && e.push(
906
+ `timelockAssert ${t.timelockAssert} exceeds uint16 max (${M})`
907
+ ), t.timelockChallengeAssert <= 0n && e.push(
908
+ `timelockChallengeAssert must be positive, got ${t.timelockChallengeAssert}`
909
+ ), t.tRefund <= 0 && e.push(`tRefund must be positive, got ${t.tRefund}`), t.tStale <= 0 && e.push(`tStale must be positive, got ${t.tStale}`), t.securityCouncilKeys.length === 0 && e.push("securityCouncilKeys must not be empty"), t.councilQuorum <= 0 && e.push(`councilQuorum must be positive, got ${t.councilQuorum}`), t.councilQuorum > t.securityCouncilKeys.length && e.push(
910
+ `councilQuorum (${t.councilQuorum}) exceeds securityCouncilKeys count (${t.securityCouncilKeys.length})`
911
+ ), t.feeRate <= 0n && e.push(`feeRate must be positive, got ${t.feeRate}`), t.minPeginFeeRate <= 0n && e.push(
912
+ `minPeginFeeRate must be positive, got ${t.minPeginFeeRate}`
913
+ ), (!Number.isInteger(t.proverProgramVersion) || t.proverProgramVersion < 0 || t.proverProgramVersion > M) && e.push(
914
+ `proverProgramVersion must be a uint16, got ${t.proverProgramVersion}`
915
+ ), (!Number.isInteger(t.minPrepeginDepth) || t.minPrepeginDepth <= 0 || t.minPrepeginDepth > H) && e.push(
916
+ `minPrepeginDepth must be a uint32 in [1, ${H}], got ${t.minPrepeginDepth}`
917
+ ), t.babeTotalInstances <= 0 && e.push(
918
+ `babeTotalInstances must be positive, got ${t.babeTotalInstances}`
919
+ ), t.babeInstancesToFinalize <= 0 && e.push(
920
+ `babeInstancesToFinalize must be positive, got ${t.babeInstancesToFinalize}`
921
+ ), t.babeInstancesToFinalize > t.babeTotalInstances && e.push(
922
+ `babeInstancesToFinalize (${t.babeInstancesToFinalize}) exceeds babeTotalInstances (${t.babeTotalInstances})`
923
+ ), (t.minVpCommissionBps < 0 || t.minVpCommissionBps > Y) && e.push(
924
+ `minVpCommissionBps must be in [0, ${Y}], got ${t.minVpCommissionBps}`
925
+ ), e.length > 0)
926
+ throw new Error(
927
+ `Invalid offchain protocol parameters: ${e.join("; ")}`
928
+ );
929
+ }
930
+ function ge(t) {
931
+ const e = [];
932
+ if (t.minimumPegInAmount <= 0n && e.push(
933
+ `minimumPegInAmount must be positive, got ${t.minimumPegInAmount}`
934
+ ), t.maxPegInAmount < t.minimumPegInAmount && e.push(
935
+ `maxPegInAmount (${t.maxPegInAmount}) must be >= minimumPegInAmount (${t.minimumPegInAmount})`
936
+ ), t.pegInAckTimeout <= 0n && e.push(
937
+ `pegInAckTimeout must be positive, got ${t.pegInAckTimeout}`
938
+ ), t.pegInActivationTimeout <= 0n && e.push(
939
+ `pegInActivationTimeout must be positive, got ${t.pegInActivationTimeout}`
940
+ ), (!Number.isInteger(t.maxHtlcOutputCount) || t.maxHtlcOutputCount <= 0 || t.maxHtlcOutputCount > Z) && e.push(
941
+ `maxHtlcOutputCount must be an integer in [1, ${Z}], got ${t.maxHtlcOutputCount}`
942
+ ), e.length > 0)
943
+ throw new Error(`Invalid TBV protocol parameters: ${e.join("; ")}`);
944
+ }
945
+ function Ze(t) {
946
+ if (ge(t), N(t.offchainParams), !Number.isInteger(t.offchainParamsVersion) || t.offchainParamsVersion < 0 || t.offchainParamsVersion > H)
947
+ throw new Error(
948
+ `Invalid peg-in configuration: offchainParamsVersion must be a uint32, got ${t.offchainParamsVersion}`
949
+ );
950
+ }
951
+ const ee = 65535;
952
+ function B(t) {
953
+ return {
954
+ timelockAssert: t.timelockAssert,
955
+ timelockChallengeAssert: t.timelockChallengeAssert,
956
+ securityCouncilKeys: [...t.securityCouncilKeys],
957
+ councilQuorum: t.councilQuorum,
958
+ feeRate: t.feeRate,
959
+ babeTotalInstances: t.babeTotalInstances,
960
+ babeInstancesToFinalize: t.babeInstancesToFinalize,
961
+ minVpCommissionBps: t.minVpCommissionBps,
962
+ tRefund: t.tRefund,
963
+ tStale: t.tStale,
964
+ minPeginFeeRate: t.minPeginFeeRate,
965
+ proverProgramVersion: t.proverProgramVersion,
966
+ minPrepeginDepth: t.minPrepeginDepth
967
+ };
968
+ }
969
+ function te(t) {
970
+ return {
971
+ minimumPegInAmount: t.minimumPegInAmount,
972
+ maxPegInAmount: t.maxPegInAmount,
973
+ pegInAckTimeout: t.pegInAckTimeout,
974
+ pegInActivationTimeout: t.pegInActivationTimeout,
975
+ maxHtlcOutputCount: t.maxHtlcOutputCount
976
+ };
977
+ }
978
+ function ne(t) {
979
+ if (t > BigInt(ee))
980
+ throw new Error(
981
+ `timelockAssert value ${t} exceeds uint16 max (${ee})`
982
+ );
983
+ return Number(t);
984
+ }
985
+ class pt {
986
+ constructor(e, n) {
987
+ this.publicClient = e, this.contractAddress = n;
988
+ }
989
+ async getTBVProtocolParams() {
990
+ const e = await this.publicClient.readContract({
991
+ address: this.contractAddress,
992
+ abi: _,
993
+ functionName: "getTBVProtocolParams"
994
+ }), n = te(e);
995
+ return ge(n), n;
996
+ }
997
+ async getLatestOffchainParams() {
998
+ const e = await this.publicClient.readContract({
999
+ address: this.contractAddress,
1000
+ abi: _,
1001
+ functionName: "getLatestOffchainParams"
1002
+ }), n = B(e);
1003
+ return N(n), n;
1004
+ }
1005
+ async getOffchainParamsByVersion(e) {
1006
+ const n = await this.publicClient.readContract({
1007
+ address: this.contractAddress,
1008
+ abi: _,
1009
+ functionName: "getOffchainParamsByVersion",
1010
+ args: [e]
1011
+ }), r = B(n);
1012
+ return N(r), r;
1013
+ }
1014
+ async getLatestOffchainParamsVersion() {
1015
+ const e = await this.publicClient.readContract({
1016
+ address: this.contractAddress,
1017
+ abi: _,
1018
+ functionName: "latestOffchainParamsVersion"
1019
+ }), n = Number(e);
1020
+ return X(n), n;
1021
+ }
1022
+ async getTimelockPeginByVersion(e) {
1023
+ const n = await this.getOffchainParamsByVersion(e);
1024
+ return ne(n.timelockAssert);
1025
+ }
1026
+ /**
1027
+ * Read TBV protocol params, latest offchain params, and the latest version
1028
+ * label atomically via multicall. The version is paired with the params so
1029
+ * that a governance update between separate reads cannot let JS build BTC
1030
+ * scripts with version N params while the contract registers the vault
1031
+ * under version N+1.
1032
+ */
1033
+ async getPegInConfiguration() {
1034
+ const e = await this.publicClient.multicall({
1035
+ contracts: [
1036
+ {
1037
+ address: this.contractAddress,
1038
+ abi: _,
1039
+ functionName: "getTBVProtocolParams"
1040
+ },
1041
+ {
1042
+ address: this.contractAddress,
1043
+ abi: _,
1044
+ functionName: "getLatestOffchainParams"
1045
+ },
1046
+ {
1047
+ address: this.contractAddress,
1048
+ abi: _,
1049
+ functionName: "latestOffchainParamsVersion"
1050
+ }
1051
+ ],
1052
+ allowFailure: !1
1053
+ }), n = te(e[0]), r = B(e[1]), i = Number(e[2]), o = {
1054
+ minimumPegInAmount: n.minimumPegInAmount,
1055
+ maxPegInAmount: n.maxPegInAmount,
1056
+ pegInAckTimeout: n.pegInAckTimeout,
1057
+ pegInActivationTimeout: n.pegInActivationTimeout,
1058
+ maxHtlcOutputCount: n.maxHtlcOutputCount,
1059
+ timelockPegin: ne(r.timelockAssert),
1060
+ timelockRefund: r.tRefund,
1061
+ minVpCommissionBps: r.minVpCommissionBps,
1062
+ offchainParams: r,
1063
+ offchainParamsVersion: i
1064
+ };
1065
+ return Ze(o), o;
1066
+ }
1067
+ /**
1068
+ * Fetch every historical offchain params version in a single multicall.
1069
+ * Iterates 1..latestVersion and calls `getOffchainParamsByVersion` for each.
1070
+ * Versions whose payload fails validation are skipped (not included in the
1071
+ * returned map) so a single bad historical version doesn't block the
1072
+ * lookup of the rest.
1073
+ *
1074
+ * @param onSkippedVersion - optional observer invoked once per skipped
1075
+ * version. Use to log/telemeter without coupling the SDK to a logger.
1076
+ */
1077
+ async fetchAllOffchainParams(e) {
1078
+ const n = await this.getLatestOffchainParamsVersion();
1079
+ if (n === 0)
1080
+ return { byVersion: /* @__PURE__ */ new Map(), latestVersion: 0 };
1081
+ const r = Array.from({ length: n }, (c, u) => u + 1), i = r.map((c) => ({
1082
+ address: this.contractAddress,
1083
+ abi: _,
1084
+ functionName: "getOffchainParamsByVersion",
1085
+ args: [c]
1086
+ })), o = await this.publicClient.multicall({
1087
+ contracts: i,
1088
+ allowFailure: !1
1089
+ }), a = /* @__PURE__ */ new Map();
1090
+ for (let c = 0; c < r.length; c++) {
1091
+ const u = B(o[c]);
1092
+ try {
1093
+ N(u), a.set(r[c], u);
1094
+ } catch (h) {
1095
+ e == null || e(
1096
+ r[c],
1097
+ h instanceof Error ? h : new Error(String(h))
1098
+ );
1099
+ }
1100
+ }
1101
+ return { byVersion: a, latestVersion: n };
1102
+ }
1103
+ }
1104
+ function D(t) {
1105
+ return t.map((e) => ({
1106
+ ethAddress: e.ethAddress,
1107
+ btcPubKey: e.btcPubKey
1108
+ }));
1109
+ }
1110
+ class gt {
1111
+ constructor(e, n) {
1112
+ this.publicClient = e, this.contractAddress = n;
1113
+ }
1114
+ async getVaultKeepersByVersion(e, n) {
1115
+ const r = await this.publicClient.readContract({
1116
+ address: this.contractAddress,
1117
+ abi: F,
1118
+ functionName: "getVaultKeepersByVersion",
1119
+ args: [e, n]
1120
+ });
1121
+ return D(r);
1122
+ }
1123
+ async getCurrentVaultKeepers(e) {
1124
+ const n = await this.publicClient.readContract({
1125
+ address: this.contractAddress,
1126
+ abi: F,
1127
+ functionName: "getCurrentVaultKeepers",
1128
+ args: [e]
1129
+ });
1130
+ return D(n);
1131
+ }
1132
+ async getCurrentVaultKeepersVersion(e) {
1133
+ return await this.publicClient.readContract({
1134
+ address: this.contractAddress,
1135
+ abi: F,
1136
+ functionName: "getCurrentVaultKeepersVersion",
1137
+ args: [e]
1138
+ });
1139
+ }
1140
+ }
1141
+ class ft {
1142
+ constructor(e, n) {
1143
+ this.publicClient = e, this.contractAddress = n;
1144
+ }
1145
+ async getUniversalChallengersByVersion(e) {
1146
+ const n = await this.publicClient.readContract({
1147
+ address: this.contractAddress,
1148
+ abi: _,
1149
+ functionName: "getUniversalChallengersByVersion",
1150
+ args: [e]
1151
+ });
1152
+ return D(n);
1153
+ }
1154
+ async getCurrentUniversalChallengers() {
1155
+ const e = await this.publicClient.readContract({
1156
+ address: this.contractAddress,
1157
+ abi: _,
1158
+ functionName: "getCurrentUniversalChallengers"
1159
+ });
1160
+ return D(e);
1161
+ }
1162
+ async getLatestUniversalChallengersVersion() {
1163
+ return await this.publicClient.readContract({
1164
+ address: this.contractAddress,
1165
+ abi: _,
1166
+ functionName: "latestUniversalChallengersVersion"
1167
+ });
1168
+ }
1169
+ }
1170
+ class mt {
1171
+ constructor(e, n) {
1172
+ this.publicClient = e, this.contractAddress = n;
1173
+ }
1174
+ /**
1175
+ * Read the VP's persistent x-only BTC pubkey from the on-chain
1176
+ * registry. Validates length, hex form, and secp256k1 curve
1177
+ * membership before minting the brand. Returns 64-char lowercase
1178
+ * hex without the `0x` prefix.
1179
+ */
1180
+ async getVaultProviderBtcPubKey(e) {
1181
+ const r = (await this.publicClient.readContract({
1182
+ address: this.contractAddress,
1183
+ abi: V,
1184
+ functionName: "getVaultProviderBTCKey",
1185
+ args: [e]
1186
+ })).toLowerCase();
1187
+ if (!/^0x[0-9a-f]{64}$/.test(r))
1188
+ throw new Error(
1189
+ `getVaultProviderBTCKey returned an unexpected value (vp=${e}, length ${r.length}, prefix "${r.slice(0, 2)}")`
1190
+ );
1191
+ const i = r.slice(2);
1192
+ if (!j.isXOnlyPoint(Pe(i)))
1193
+ throw new Error(
1194
+ `getVaultProviderBTCKey returned a value that is not on the secp256k1 curve (vp=${e})`
1195
+ );
1196
+ return i;
1197
+ }
1198
+ async getVaultBasicInfo(e) {
1199
+ const n = await this.publicClient.readContract({
1200
+ address: this.contractAddress,
1201
+ abi: V,
1202
+ functionName: "getBtcVaultBasicInfo",
1203
+ args: [e]
1204
+ });
1205
+ return {
1206
+ depositor: n.depositor,
1207
+ depositorBtcPubKey: n.depositorBtcPubKey,
1208
+ amount: n.amount,
1209
+ vaultProvider: n.vaultProvider,
1210
+ status: n.status,
1211
+ applicationEntryPoint: n.applicationEntryPoint,
1212
+ createdAt: n.createdAt
1213
+ };
1214
+ }
1215
+ async getVaultProtocolInfo(e) {
1216
+ const n = await this.publicClient.readContract({
1217
+ address: this.contractAddress,
1218
+ abi: V,
1219
+ functionName: "getBtcVaultProtocolInfo",
1220
+ args: [e]
1221
+ }), r = Number(n.offchainParamsVersion);
1222
+ return X(r), {
1223
+ depositorSignedPeginTx: n.depositorSignedPeginTx,
1224
+ universalChallengersVersion: n.universalChallengersVersion,
1225
+ appVaultKeepersVersion: n.appVaultKeepersVersion,
1226
+ offchainParamsVersion: r,
1227
+ verifiedAt: n.verifiedAt,
1228
+ depositorWotsPkHash: n.depositorWotsPkHash,
1229
+ hashlock: n.hashlock,
1230
+ htlcVout: n.htlcVout,
1231
+ depositorPopSignature: n.depositorPopSignature,
1232
+ prePeginTxHash: n.prePeginTxHash,
1233
+ vaultProviderCommissionBps: n.vaultProviderCommissionBps
1234
+ };
1235
+ }
1236
+ async getVaultData(e) {
1237
+ const [n, r] = await Promise.all([
1238
+ this.getVaultBasicInfo(e),
1239
+ this.getVaultProtocolInfo(e)
1240
+ ]);
1241
+ if (!r.depositorSignedPeginTx || r.depositorSignedPeginTx === "0x")
1242
+ throw new Error(
1243
+ `Vault ${e} not found on-chain or has no pegin transaction`
1244
+ );
1245
+ return { basic: n, protocol: r };
1246
+ }
1247
+ /**
1248
+ * Read `offchainParamsVersion` for many vaults in a single multicall.
1249
+ * Reads only `getBtcVaultProtocolInfo` (one read per vault), so an N-vault
1250
+ * batch costs one RPC round-trip instead of 2N parallel `eth_call`s.
1251
+ */
1252
+ async getOffchainParamsVersionsByVaultIds(e) {
1253
+ return e.length === 0 ? [] : (await this.publicClient.multicall({
1254
+ contracts: e.map((r) => ({
1255
+ address: this.contractAddress,
1256
+ abi: V,
1257
+ functionName: "getBtcVaultProtocolInfo",
1258
+ args: [r]
1259
+ })),
1260
+ allowFailure: !1
1261
+ })).map((r) => {
1262
+ const i = r;
1263
+ if (!i.depositorSignedPeginTx || i.depositorSignedPeginTx === "0x")
1264
+ throw new Error(
1265
+ "Vault not found on-chain or has no pegin transaction while reading offchain params version"
1266
+ );
1267
+ const o = Number(i.offchainParamsVersion);
1268
+ return X(o), o;
1269
+ });
1270
+ }
1271
+ }
1272
+ export {
1273
+ g as S,
1274
+ He as V,
1275
+ s as a,
1276
+ lt as b,
1277
+ ze as c,
1278
+ Ye as d,
1279
+ pe as e,
1280
+ ut as f,
1281
+ N as g,
1282
+ Ze as h,
1283
+ ge as i,
1284
+ pt as j,
1285
+ ft as k,
1286
+ gt as l,
1287
+ mt as m,
1288
+ ht as p,
1289
+ dt as r,
1290
+ Se as v
1291
+ };
1292
+ //# sourceMappingURL=vault-registry-reader-CqhD3Iyd.js.map