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