@babylonlabs-io/ts-sdk 0.48.4 → 0.49.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 (54) hide show
  1. package/dist/{PeginManager-NfDjKQGV.cjs → PeginManager-BvxfSwsr.cjs} +2 -2
  2. package/dist/{PeginManager-NfDjKQGV.cjs.map → PeginManager-BvxfSwsr.cjs.map} +1 -1
  3. package/dist/{PeginManager-CNhDl1eC.js → PeginManager-COxRVrxa.js} +2 -2
  4. package/dist/{PeginManager-CNhDl1eC.js.map → PeginManager-COxRVrxa.js.map} +1 -1
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.js +79 -78
  7. package/dist/{mempoolApi-BxT89SAq.js → mempoolApi-Dc1KSVNI.js} +61 -54
  8. package/dist/mempoolApi-Dc1KSVNI.js.map +1 -0
  9. package/dist/{mempoolApi-C_9JhjCI.cjs → mempoolApi-NMiYQAXI.cjs} +2 -2
  10. package/dist/mempoolApi-NMiYQAXI.cjs.map +1 -0
  11. package/dist/{primeVpAuth-Dzxxy0-F.js → primeVpAuth-BdrwraAe.js} +767 -381
  12. package/dist/primeVpAuth-BdrwraAe.js.map +1 -0
  13. package/dist/primeVpAuth-Brl_bnBH.cjs +2 -0
  14. package/dist/primeVpAuth-Brl_bnBH.cjs.map +1 -0
  15. package/dist/tbv/core/clients/index.cjs +1 -1
  16. package/dist/tbv/core/clients/index.js +33 -32
  17. package/dist/tbv/core/clients/mempool/index.d.ts +2 -2
  18. package/dist/tbv/core/clients/mempool/index.d.ts.map +1 -1
  19. package/dist/tbv/core/clients/mempool/mempoolApi.d.ts +15 -1
  20. package/dist/tbv/core/clients/mempool/mempoolApi.d.ts.map +1 -1
  21. package/dist/tbv/core/clients/mempool/types.d.ts +20 -0
  22. package/dist/tbv/core/clients/mempool/types.d.ts.map +1 -1
  23. package/dist/tbv/core/clients/vault-provider/auth/__tests__/cborDecode.test.d.ts +2 -0
  24. package/dist/tbv/core/clients/vault-provider/auth/__tests__/cborDecode.test.d.ts.map +1 -0
  25. package/dist/tbv/core/clients/vault-provider/auth/__tests__/goldenVectors.d.ts +14 -0
  26. package/dist/tbv/core/clients/vault-provider/auth/__tests__/goldenVectors.d.ts.map +1 -1
  27. package/dist/tbv/core/clients/vault-provider/auth/__tests__/mintTestCwt.d.ts +43 -0
  28. package/dist/tbv/core/clients/vault-provider/auth/__tests__/mintTestCwt.d.ts.map +1 -0
  29. package/dist/tbv/core/clients/vault-provider/auth/__tests__/verifyDepositorCwt.test.d.ts +2 -0
  30. package/dist/tbv/core/clients/vault-provider/auth/__tests__/verifyDepositorCwt.test.d.ts.map +1 -0
  31. package/dist/tbv/core/clients/vault-provider/auth/cborDecode.d.ts +80 -0
  32. package/dist/tbv/core/clients/vault-provider/auth/cborDecode.d.ts.map +1 -0
  33. package/dist/tbv/core/clients/vault-provider/auth/createAuthenticatedVpClient.d.ts +5 -0
  34. package/dist/tbv/core/clients/vault-provider/auth/createAuthenticatedVpClient.d.ts.map +1 -1
  35. package/dist/tbv/core/clients/vault-provider/auth/primeVpAuth.d.ts +5 -0
  36. package/dist/tbv/core/clients/vault-provider/auth/primeVpAuth.d.ts.map +1 -1
  37. package/dist/tbv/core/clients/vault-provider/auth/tokenProvider.d.ts +8 -0
  38. package/dist/tbv/core/clients/vault-provider/auth/tokenProvider.d.ts.map +1 -1
  39. package/dist/tbv/core/clients/vault-provider/auth/tokenRegistry.d.ts +2 -0
  40. package/dist/tbv/core/clients/vault-provider/auth/tokenRegistry.d.ts.map +1 -1
  41. package/dist/tbv/core/clients/vault-provider/auth/verifyDepositorCwt.d.ts +80 -0
  42. package/dist/tbv/core/clients/vault-provider/auth/verifyDepositorCwt.d.ts.map +1 -0
  43. package/dist/tbv/core/index.cjs +1 -1
  44. package/dist/tbv/core/index.js +76 -75
  45. package/dist/tbv/core/managers/index.cjs +1 -1
  46. package/dist/tbv/core/managers/index.js +1 -1
  47. package/dist/tbv/index.cjs +1 -1
  48. package/dist/tbv/index.js +76 -75
  49. package/package.json +1 -1
  50. package/dist/mempoolApi-BxT89SAq.js.map +0 -1
  51. package/dist/mempoolApi-C_9JhjCI.cjs.map +0 -1
  52. package/dist/primeVpAuth-Dzxxy0-F.js.map +0 -1
  53. package/dist/primeVpAuth-wKbRw0m4.cjs +0 -2
  54. package/dist/primeVpAuth-wKbRw0m4.cjs.map +0 -1
@@ -1,28 +1,28 @@
1
- var he = Object.defineProperty;
2
- var ge = (r, e, t) => e in r ? he(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
- var p = (r, e, t) => ge(r, typeof e != "symbol" ? e + "" : e, t);
4
- import { B as X } from "./BTCVaultRegistry.abi-Chs4AFBj.js";
5
- import { P as b, A as H } from "./ApplicationRegistry.abi-Dn2qk6JG.js";
6
- import { j as fe, v as B, k as _e, i as me } from "./mempoolApi-BxT89SAq.js";
7
- import { D as be, J as ne, e as ye } from "./types-CQDRQvV-.js";
8
- import { C as q } from "./constants-Cd_fN8VT.js";
9
- import { X as R, C as j, s as E, S as we } from "./bitcoin-B5aNKtsk.js";
1
+ var Ce = Object.defineProperty;
2
+ var $e = (r, e, t) => e in r ? Ce(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
+ var f = (r, e, t) => $e(r, typeof e != "symbol" ? e + "" : e, t);
4
+ import { B as Q } from "./BTCVaultRegistry.abi-Chs4AFBj.js";
5
+ import { P as x, A as L } from "./ApplicationRegistry.abi-Dn2qk6JG.js";
6
+ import { k as Ie, v as U, l as Ve, j as Re } from "./mempoolApi-Dc1KSVNI.js";
7
+ import { D as Oe, J as _e, e as Be } from "./types-CQDRQvV-.js";
8
+ import { X as R, C as D, s as V, S as Ne, h as Ge, p as me } from "./bitcoin-B5aNKtsk.js";
9
+ import { C as ee } from "./constants-Cd_fN8VT.js";
10
10
  import { H as S } from "./validation-CxqROCno.js";
11
- import * as F from "@bitcoin-js/tiny-secp256k1-asmjs";
12
- import { payments as Pe, Transaction as O } from "bitcoinjs-lib";
13
- import { Buffer as A } from "buffer";
14
- import { s as J } from "./sha2-BYVxyZzX.js";
15
- async function ut(r, e) {
11
+ import * as H from "@bitcoin-js/tiny-secp256k1-asmjs";
12
+ import { payments as De, Transaction as X } from "bitcoinjs-lib";
13
+ import { Buffer as I } from "buffer";
14
+ import { s as q } from "./sha2-BYVxyZzX.js";
15
+ async function or(r, e) {
16
16
  const [t, n] = await r.multicall({
17
17
  contracts: [
18
18
  {
19
19
  address: e,
20
- abi: X,
20
+ abi: Q,
21
21
  functionName: "protocolParams"
22
22
  },
23
23
  {
24
24
  address: e,
25
- abi: X,
25
+ abi: Q,
26
26
  functionName: "applicationRegistry"
27
27
  }
28
28
  ],
@@ -33,8 +33,8 @@ async function ut(r, e) {
33
33
  applicationRegistry: n
34
34
  };
35
35
  }
36
- const z = 65535;
37
- function V(r) {
36
+ const te = 65535;
37
+ function B(r) {
38
38
  return {
39
39
  timelockAssert: r.timelockAssert,
40
40
  timelockChallengeAssert: r.timelockChallengeAssert,
@@ -51,7 +51,7 @@ function V(r) {
51
51
  minPrepeginDepth: r.minPrepeginDepth
52
52
  };
53
53
  }
54
- function W(r) {
54
+ function re(r) {
55
55
  return {
56
56
  minimumPegInAmount: r.minimumPegInAmount,
57
57
  maxPegInAmount: r.maxPegInAmount,
@@ -61,53 +61,53 @@ function W(r) {
61
61
  expiredPegInGraceBlocks: r.expiredPegInGraceBlocks
62
62
  };
63
63
  }
64
- function Y(r) {
65
- if (r > BigInt(z))
64
+ function ne(r) {
65
+ if (r > BigInt(te))
66
66
  throw new Error(
67
- `timelockAssert value ${r} exceeds uint16 max (${z})`
67
+ `timelockAssert value ${r} exceeds uint16 max (${te})`
68
68
  );
69
69
  return Number(r);
70
70
  }
71
- class dt {
71
+ class ar {
72
72
  constructor(e, t) {
73
73
  this.publicClient = e, this.contractAddress = t;
74
74
  }
75
75
  async getTBVProtocolParams() {
76
76
  const e = await this.publicClient.readContract({
77
77
  address: this.contractAddress,
78
- abi: b,
78
+ abi: x,
79
79
  functionName: "getTBVProtocolParams"
80
- }), t = W(e);
81
- return fe(t), t;
80
+ }), t = re(e);
81
+ return Ie(t), t;
82
82
  }
83
83
  async getLatestOffchainParams() {
84
84
  const e = await this.publicClient.readContract({
85
85
  address: this.contractAddress,
86
- abi: b,
86
+ abi: x,
87
87
  functionName: "getLatestOffchainParams"
88
- }), t = V(e);
89
- return B(t), t;
88
+ }), t = B(e);
89
+ return U(t), t;
90
90
  }
91
91
  async getOffchainParamsByVersion(e) {
92
92
  const t = await this.publicClient.readContract({
93
93
  address: this.contractAddress,
94
- abi: b,
94
+ abi: x,
95
95
  functionName: "getOffchainParamsByVersion",
96
96
  args: [e]
97
- }), n = V(t);
98
- return B(n), n;
97
+ }), n = B(t);
98
+ return U(n), n;
99
99
  }
100
100
  async getLatestOffchainParamsVersion() {
101
101
  const e = await this.publicClient.readContract({
102
102
  address: this.contractAddress,
103
- abi: b,
103
+ abi: x,
104
104
  functionName: "latestOffchainParamsVersion"
105
105
  }), t = Number(e);
106
- return _e(t), t;
106
+ return Ve(t), t;
107
107
  }
108
108
  async getTimelockPeginByVersion(e) {
109
109
  const t = await this.getOffchainParamsByVersion(e);
110
- return Y(t.timelockAssert);
110
+ return ne(t.timelockAssert);
111
111
  }
112
112
  /**
113
113
  * Read TBV protocol params, latest offchain params, and the latest version
@@ -121,35 +121,35 @@ class dt {
121
121
  contracts: [
122
122
  {
123
123
  address: this.contractAddress,
124
- abi: b,
124
+ abi: x,
125
125
  functionName: "getTBVProtocolParams"
126
126
  },
127
127
  {
128
128
  address: this.contractAddress,
129
- abi: b,
129
+ abi: x,
130
130
  functionName: "getLatestOffchainParams"
131
131
  },
132
132
  {
133
133
  address: this.contractAddress,
134
- abi: b,
134
+ abi: x,
135
135
  functionName: "latestOffchainParamsVersion"
136
136
  }
137
137
  ],
138
138
  allowFailure: !1
139
- }), t = W(e[0]), n = V(e[1]), s = Number(e[2]), i = {
139
+ }), t = re(e[0]), n = B(e[1]), i = Number(e[2]), s = {
140
140
  minimumPegInAmount: t.minimumPegInAmount,
141
141
  maxPegInAmount: t.maxPegInAmount,
142
142
  pegInAckTimeout: t.pegInAckTimeout,
143
143
  pegInActivationTimeout: t.pegInActivationTimeout,
144
144
  maxHtlcOutputCount: t.maxHtlcOutputCount,
145
145
  expiredPegInGraceBlocks: t.expiredPegInGraceBlocks,
146
- timelockPegin: Y(n.timelockAssert),
146
+ timelockPegin: ne(n.timelockAssert),
147
147
  timelockRefund: n.tRefund,
148
148
  minVpCommissionBps: n.minVpCommissionBps,
149
149
  offchainParams: n,
150
- offchainParamsVersion: s
150
+ offchainParamsVersion: i
151
151
  };
152
- return me(i), i;
152
+ return Re(s), s;
153
153
  }
154
154
  /**
155
155
  * Fetch every historical offchain params version in a single multicall.
@@ -165,135 +165,135 @@ class dt {
165
165
  const t = await this.getLatestOffchainParamsVersion();
166
166
  if (t === 0)
167
167
  return { byVersion: /* @__PURE__ */ new Map(), latestVersion: 0 };
168
- const n = Array.from({ length: t }, (c, u) => u + 1), s = n.map((c) => ({
168
+ const n = Array.from({ length: t }, (c, d) => d + 1), i = n.map((c) => ({
169
169
  address: this.contractAddress,
170
- abi: b,
170
+ abi: x,
171
171
  functionName: "getOffchainParamsByVersion",
172
172
  args: [c]
173
- })), i = await this.publicClient.multicall({
174
- contracts: s,
173
+ })), s = await this.publicClient.multicall({
174
+ contracts: i,
175
175
  allowFailure: !1
176
176
  }), o = /* @__PURE__ */ new Map();
177
177
  for (let c = 0; c < n.length; c++) {
178
- const u = V(i[c]);
178
+ const d = B(s[c]);
179
179
  try {
180
- B(u), o.set(n[c], u);
181
- } catch (d) {
180
+ U(d), o.set(n[c], d);
181
+ } catch (u) {
182
182
  e == null || e(
183
183
  n[c],
184
- d instanceof Error ? d : new Error(String(d))
184
+ u instanceof Error ? u : new Error(String(u))
185
185
  );
186
186
  }
187
187
  }
188
188
  return { byVersion: o, latestVersion: t };
189
189
  }
190
190
  }
191
- function N(r) {
191
+ function M(r) {
192
192
  return r.map((e) => ({
193
193
  ethAddress: e.ethAddress,
194
194
  btcPubKey: e.btcPubKey
195
195
  }));
196
196
  }
197
- class pt {
197
+ class cr {
198
198
  constructor(e, t) {
199
199
  this.publicClient = e, this.contractAddress = t;
200
200
  }
201
201
  async getVaultKeepersByVersion(e, t) {
202
202
  const n = await this.publicClient.readContract({
203
203
  address: this.contractAddress,
204
- abi: H,
204
+ abi: L,
205
205
  functionName: "getVaultKeepersByVersion",
206
206
  args: [e, t]
207
207
  });
208
- return N(n);
208
+ return M(n);
209
209
  }
210
210
  async getCurrentVaultKeepers(e) {
211
211
  const t = await this.publicClient.readContract({
212
212
  address: this.contractAddress,
213
- abi: H,
213
+ abi: L,
214
214
  functionName: "getCurrentVaultKeepers",
215
215
  args: [e]
216
216
  });
217
- return N(t);
217
+ return M(t);
218
218
  }
219
219
  async getCurrentVaultKeepersVersion(e) {
220
220
  return await this.publicClient.readContract({
221
221
  address: this.contractAddress,
222
- abi: H,
222
+ abi: L,
223
223
  functionName: "getCurrentVaultKeepersVersion",
224
224
  args: [e]
225
225
  });
226
226
  }
227
227
  }
228
- class ht {
228
+ class lr {
229
229
  constructor(e, t) {
230
230
  this.publicClient = e, this.contractAddress = t;
231
231
  }
232
232
  async getUniversalChallengersByVersion(e) {
233
233
  const t = await this.publicClient.readContract({
234
234
  address: this.contractAddress,
235
- abi: b,
235
+ abi: x,
236
236
  functionName: "getUniversalChallengersByVersion",
237
237
  args: [e]
238
238
  });
239
- return N(t);
239
+ return M(t);
240
240
  }
241
241
  async getCurrentUniversalChallengers() {
242
242
  const e = await this.publicClient.readContract({
243
243
  address: this.contractAddress,
244
- abi: b,
244
+ abi: x,
245
245
  functionName: "getCurrentUniversalChallengers"
246
246
  });
247
- return N(e);
247
+ return M(e);
248
248
  }
249
249
  async getLatestUniversalChallengersVersion() {
250
250
  return await this.publicClient.readContract({
251
251
  address: this.contractAddress,
252
- abi: b,
252
+ abi: x,
253
253
  functionName: "latestUniversalChallengersVersion"
254
254
  });
255
255
  }
256
256
  }
257
- var xe = /* @__PURE__ */ ((r) => (r[r.PENDING = 0] = "PENDING", r[r.VERIFIED = 1] = "VERIFIED", r[r.ACTIVE = 2] = "ACTIVE", r[r.REDEEMED = 3] = "REDEEMED", r[r.EXPIRED = 4] = "EXPIRED", r))(xe || {});
258
- const Z = new Set(Object.values(be)), ve = 200;
259
- function l(r) {
257
+ var Me = /* @__PURE__ */ ((r) => (r[r.PENDING = 0] = "PENDING", r[r.VERIFIED = 1] = "VERIFIED", r[r.ACTIVE = 2] = "ACTIVE", r[r.REDEEMED = 3] = "REDEEMED", r[r.EXPIRED = 4] = "EXPIRED", r))(Me || {});
258
+ const se = new Set(Object.values(Oe)), je = 200;
259
+ function p(r) {
260
260
  var e;
261
- return ((e = JSON.stringify(r)) == null ? void 0 : e.slice(0, ve)) ?? "undefined";
261
+ return ((e = JSON.stringify(r)) == null ? void 0 : e.slice(0, je)) ?? "undefined";
262
262
  }
263
- const Ae = "The vault provider returned an unexpected response. Please try again or contact support.";
263
+ const He = "The vault provider returned an unexpected response. Please try again or contact support.";
264
264
  class a extends Error {
265
265
  constructor(t) {
266
- super(Ae);
267
- p(this, "detail");
266
+ super(He);
267
+ f(this, "detail");
268
268
  this.name = "VpResponseValidationError", this.detail = t;
269
269
  }
270
270
  }
271
- const $ = 64;
272
- function P(r) {
271
+ const O = 64;
272
+ function C(r) {
273
273
  return typeof r == "string" && r.length > 0 && S.test(r);
274
274
  }
275
- function se(r) {
275
+ function ye(r) {
276
276
  return typeof r == "string" && r.length > 0;
277
277
  }
278
- function ie(r, e) {
279
- if (!P(r))
278
+ function be(r, e) {
279
+ if (!C(r))
280
280
  throw new a(
281
- `VP response validation failed: "${e}" must be a non-empty hex string, got ${l(r)}`
281
+ `VP response validation failed: "${e}" must be a non-empty hex string, got ${p(r)}`
282
282
  );
283
283
  }
284
- function _(r, e) {
285
- if (!se(r))
284
+ function b(r, e) {
285
+ if (!ye(r))
286
286
  throw new a(
287
- `VP response validation failed: "${e}" must be a non-empty string, got ${l(r)}`
287
+ `VP response validation failed: "${e}" must be a non-empty string, got ${p(r)}`
288
288
  );
289
289
  }
290
- function L(r, e) {
291
- if (!P(r) || r.length !== R && r.length !== j)
290
+ function Z(r, e) {
291
+ if (!C(r) || r.length !== R && r.length !== D)
292
292
  throw new a(
293
- `VP response validation failed: "${e}" must be a ${R} or ${j}-char hex string (BTC pubkey), got ${l(r)}`
293
+ `VP response validation failed: "${e}" must be a ${R} or ${D}-char hex string (BTC pubkey), got ${p(r)}`
294
294
  );
295
295
  }
296
- function $e(r) {
296
+ function Le(r) {
297
297
  const e = r.presigning;
298
298
  if (e == null) return;
299
299
  if (typeof e != "object" || Array.isArray(e))
@@ -303,49 +303,49 @@ function $e(r) {
303
303
  const t = e;
304
304
  if (t.depositor_graph_created !== void 0 && typeof t.depositor_graph_created != "boolean")
305
305
  throw new a(
306
- `VP response validation failed: "progress.presigning.depositor_graph_created" must be a boolean if present, got ${l(t.depositor_graph_created)}`
306
+ `VP response validation failed: "progress.presigning.depositor_graph_created" must be a boolean if present, got ${p(t.depositor_graph_created)}`
307
307
  );
308
308
  if (t.vk_challenger_presigning_completed !== void 0 && typeof t.vk_challenger_presigning_completed != "number")
309
309
  throw new a(
310
- `VP response validation failed: "progress.presigning.vk_challenger_presigning_completed" must be a number if present, got ${l(t.vk_challenger_presigning_completed)}`
310
+ `VP response validation failed: "progress.presigning.vk_challenger_presigning_completed" must be a number if present, got ${p(t.vk_challenger_presigning_completed)}`
311
311
  );
312
312
  if (t.vk_challenger_presigning_total !== void 0 && typeof t.vk_challenger_presigning_total != "number")
313
313
  throw new a(
314
- `VP response validation failed: "progress.presigning.vk_challenger_presigning_total" must be a number if present, got ${l(t.vk_challenger_presigning_total)}`
314
+ `VP response validation failed: "progress.presigning.vk_challenger_presigning_total" must be a number if present, got ${p(t.vk_challenger_presigning_total)}`
315
315
  );
316
316
  }
317
- function ae(r) {
317
+ function we(r) {
318
318
  if (r === null || typeof r != "object")
319
319
  throw new a(
320
320
  "VP response validation failed: getPeginStatus response is not an object"
321
321
  );
322
322
  const e = r;
323
- if (!P(e.pegin_txid) || e.pegin_txid.length !== $)
323
+ if (!C(e.pegin_txid) || e.pegin_txid.length !== O)
324
324
  throw new a(
325
- `VP response validation failed: "pegin_txid" must be a ${$}-char hex string (txid), got ${l(e.pegin_txid)}`
325
+ `VP response validation failed: "pegin_txid" must be a ${O}-char hex string (txid), got ${p(e.pegin_txid)}`
326
326
  );
327
327
  if (typeof e.status != "string")
328
328
  throw new a(
329
329
  'VP response validation failed: "status" must be a string'
330
330
  );
331
- if (!Z.has(e.status))
331
+ if (!se.has(e.status))
332
332
  throw new a(
333
- `VP response validation failed: unrecognized status "${e.status}". Expected one of: ${[...Z].join(", ")}`
333
+ `VP response validation failed: unrecognized status "${e.status}". Expected one of: ${[...se].join(", ")}`
334
334
  );
335
335
  if (e.progress === null || typeof e.progress != "object" || Array.isArray(e.progress))
336
336
  throw new a(
337
337
  'VP response validation failed: "progress" must be an object'
338
338
  );
339
- if ($e(e.progress), typeof e.health_info != "string")
339
+ if (Le(e.progress), typeof e.health_info != "string")
340
340
  throw new a(
341
341
  'VP response validation failed: "health_info" must be a string'
342
342
  );
343
343
  if (e.last_error !== void 0 && typeof e.last_error != "string")
344
344
  throw new a(
345
- `VP response validation failed: "last_error" must be a string if present, got ${l(e.last_error)}`
345
+ `VP response validation failed: "last_error" must be a string if present, got ${p(e.last_error)}`
346
346
  );
347
347
  }
348
- function Se(r) {
348
+ function Ue(r) {
349
349
  if (r === null || typeof r != "object")
350
350
  throw new a(
351
351
  "VP response validation failed: requestDepositorPresignTransactions response is not an object"
@@ -356,60 +356,60 @@ function Se(r) {
356
356
  'VP response validation failed: "txs" must be an array'
357
357
  );
358
358
  for (let t = 0; t < e.txs.length; t++)
359
- ke(e.txs[t], `txs[${t}]`);
359
+ Xe(e.txs[t], `txs[${t}]`);
360
360
  if (e.depositor_graph === null || typeof e.depositor_graph != "object")
361
361
  throw new a(
362
362
  'VP response validation failed: "depositor_graph" must be an object'
363
363
  );
364
- De(
364
+ Qe(
365
365
  e.depositor_graph
366
366
  );
367
367
  }
368
- function y(r, e) {
368
+ function v(r, e) {
369
369
  if (r === null || typeof r != "object")
370
370
  throw new a(
371
371
  `VP response validation failed: "${e}" must be an object`
372
372
  );
373
- ie(r.tx_hex, `${e}.tx_hex`);
373
+ be(r.tx_hex, `${e}.tx_hex`);
374
374
  }
375
- function ke(r, e) {
375
+ function Xe(r, e) {
376
376
  if (r === null || typeof r != "object")
377
377
  throw new a(
378
378
  `VP response validation failed: "${e}" must be an object`
379
379
  );
380
380
  const t = r;
381
- L(t.claimer_pubkey, `${e}.claimer_pubkey`), y(t.claim_tx, `${e}.claim_tx`), y(t.assert_tx, `${e}.assert_tx`), y(t.payout_tx, `${e}.payout_tx`), _(t.payout_psbt, `${e}.payout_psbt`);
381
+ Z(t.claimer_pubkey, `${e}.claimer_pubkey`), v(t.claim_tx, `${e}.claim_tx`), v(t.assert_tx, `${e}.assert_tx`), v(t.payout_tx, `${e}.payout_tx`), b(t.payout_psbt, `${e}.payout_psbt`);
382
382
  }
383
- function Te(r, e) {
383
+ function Fe(r, e) {
384
384
  if (r === null || typeof r != "object")
385
385
  throw new a(
386
386
  `VP response validation failed: "${e}" must be an object`
387
387
  );
388
388
  const t = r;
389
- _(t.wots_pks_json, `${e}.wots_pks_json`), _(t.gc_wots_keys_json, `${e}.gc_wots_keys_json`);
389
+ b(t.wots_pks_json, `${e}.wots_pks_json`), b(t.gc_wots_keys_json, `${e}.gc_wots_keys_json`);
390
390
  }
391
- function Ee(r, e) {
391
+ function Ke(r, e) {
392
392
  if (r === null || typeof r != "object")
393
393
  throw new a(
394
394
  `VP response validation failed: "${e}" must be an object`
395
395
  );
396
396
  const t = r;
397
- if (L(t.challenger_pubkey, `${e}.challenger_pubkey`), y(
397
+ if (Z(t.challenger_pubkey, `${e}.challenger_pubkey`), v(
398
398
  t.challenge_assert_x_tx,
399
399
  `${e}.challenge_assert_x_tx`
400
- ), y(
400
+ ), v(
401
401
  t.challenge_assert_y_tx,
402
402
  `${e}.challenge_assert_y_tx`
403
- ), y(t.nopayout_tx, `${e}.nopayout_tx`), _(t.nopayout_psbt, `${e}.nopayout_psbt`), !Array.isArray(t.challenge_assert_connectors))
403
+ ), v(t.nopayout_tx, `${e}.nopayout_tx`), b(t.nopayout_psbt, `${e}.nopayout_psbt`), !Array.isArray(t.challenge_assert_connectors))
404
404
  throw new a(
405
405
  `VP response validation failed: "${e}.challenge_assert_connectors" must be an array`
406
406
  );
407
- if (t.challenge_assert_connectors.length !== q)
407
+ if (t.challenge_assert_connectors.length !== ee)
408
408
  throw new a(
409
- `VP response validation failed: "${e}.challenge_assert_connectors" must have exactly ${q} entries, got ${t.challenge_assert_connectors.length}`
409
+ `VP response validation failed: "${e}.challenge_assert_connectors" must have exactly ${ee} entries, got ${t.challenge_assert_connectors.length}`
410
410
  );
411
411
  for (let n = 0; n < t.challenge_assert_connectors.length; n++)
412
- Te(
412
+ Fe(
413
413
  t.challenge_assert_connectors[n],
414
414
  `${e}.challenge_assert_connectors[${n}]`
415
415
  );
@@ -418,24 +418,24 @@ function Ee(r, e) {
418
418
  `VP response validation failed: "${e}.output_label_hashes" must be an array`
419
419
  );
420
420
  for (let n = 0; n < t.output_label_hashes.length; n++)
421
- ie(
421
+ be(
422
422
  t.output_label_hashes[n],
423
423
  `${e}.output_label_hashes[${n}]`
424
424
  );
425
425
  }
426
- function Ve(r) {
426
+ function Je(r) {
427
427
  if (r === null || typeof r != "object")
428
428
  throw new a(
429
429
  "VP response validation failed: requestDepositorClaimerArtifacts response is not an object"
430
430
  );
431
431
  const e = r;
432
- if (!se(e.tx_graph_json))
432
+ if (!ye(e.tx_graph_json))
433
433
  throw new a(
434
- `VP response validation failed: "tx_graph_json" must be a non-empty string, got ${l(e.tx_graph_json)}`
434
+ `VP response validation failed: "tx_graph_json" must be a non-empty string, got ${p(e.tx_graph_json)}`
435
435
  );
436
- if (!P(e.verifying_key_hex))
436
+ if (!C(e.verifying_key_hex))
437
437
  throw new a(
438
- `VP response validation failed: "verifying_key_hex" must be a non-empty hex string, got ${l(e.verifying_key_hex)}`
438
+ `VP response validation failed: "verifying_key_hex" must be a non-empty hex string, got ${p(e.verifying_key_hex)}`
439
439
  );
440
440
  if (e.babe_sessions === null || typeof e.babe_sessions != "object" || Array.isArray(e.babe_sessions))
441
441
  throw new a(
@@ -448,98 +448,98 @@ function Ve(r) {
448
448
  throw new a(
449
449
  'VP response validation failed: "babe_sessions" must contain at least one challenger entry'
450
450
  );
451
- for (const [n, s] of t) {
452
- if (L(n, `babe_sessions["${n}"]`), s === null || typeof s != "object")
451
+ for (const [n, i] of t) {
452
+ if (Z(n, `babe_sessions["${n}"]`), i === null || typeof i != "object")
453
453
  throw new a(
454
454
  `VP response validation failed: "babe_sessions.${n}" must be an object`
455
455
  );
456
- const i = s;
457
- if (!P(i.decryptor_artifacts_hex))
456
+ const s = i;
457
+ if (!C(s.decryptor_artifacts_hex))
458
458
  throw new a(
459
- `VP response validation failed: "babe_sessions.${n}.decryptor_artifacts_hex" must be a non-empty hex string, got ${l(i.decryptor_artifacts_hex)}`
459
+ `VP response validation failed: "babe_sessions.${n}.decryptor_artifacts_hex" must be a non-empty hex string, got ${p(s.decryptor_artifacts_hex)}`
460
460
  );
461
461
  }
462
462
  }
463
- function Ce(r) {
463
+ function qe(r) {
464
464
  if (r === null || typeof r != "object")
465
465
  throw new a(
466
466
  "VP response validation failed: pegout status payload is not an object"
467
467
  );
468
468
  const e = r;
469
- if (!P(e.pegin_txid) || e.pegin_txid.length !== $)
469
+ if (!C(e.pegin_txid) || e.pegin_txid.length !== O)
470
470
  throw new a(
471
- `VP response validation failed: "pegin_txid" must be a ${$}-char hex string (txid), got ${l(e.pegin_txid)}`
471
+ `VP response validation failed: "pegin_txid" must be a ${O}-char hex string (txid), got ${p(e.pegin_txid)}`
472
472
  );
473
473
  if (typeof e.found != "boolean")
474
474
  throw new a(
475
- `VP response validation failed: "found" must be a boolean, got ${l(e.found)}`
475
+ `VP response validation failed: "found" must be a boolean, got ${p(e.found)}`
476
476
  );
477
477
  if (e.claimer !== null) {
478
478
  if (typeof e.claimer != "object")
479
479
  throw new a(
480
- `VP response validation failed: "claimer" must be an object or null, got ${l(e.claimer)}`
480
+ `VP response validation failed: "claimer" must be an object or null, got ${p(e.claimer)}`
481
481
  );
482
- Ie(e.claimer);
482
+ We(e.claimer);
483
483
  }
484
484
  if (!Array.isArray(e.challengers))
485
485
  throw new a(
486
- `VP response validation failed: "challengers" must be an array, got ${l(e.challengers)}`
486
+ `VP response validation failed: "challengers" must be an array, got ${p(e.challengers)}`
487
487
  );
488
488
  for (let t = 0; t < e.challengers.length; t++)
489
- Re(e.challengers[t], t);
489
+ Ye(e.challengers[t], t);
490
490
  }
491
- function Ie(r) {
492
- if (_(r.status, "claimer.status"), typeof r.failed != "boolean")
491
+ function We(r) {
492
+ if (b(r.status, "claimer.status"), typeof r.failed != "boolean")
493
493
  throw new a(
494
- `VP response validation failed: "claimer.failed" must be a boolean, got ${l(r.failed)}`
494
+ `VP response validation failed: "claimer.failed" must be a boolean, got ${p(r.failed)}`
495
495
  );
496
- if (_(r.claim_txid, "claimer.claim_txid"), _(r.claimer_pubkey, "claimer.claimer_pubkey"), _(r.assert_txid, "claimer.assert_txid"), typeof r.created_at != "number")
496
+ if (b(r.claim_txid, "claimer.claim_txid"), b(r.claimer_pubkey, "claimer.claimer_pubkey"), b(r.assert_txid, "claimer.assert_txid"), typeof r.created_at != "number")
497
497
  throw new a(
498
- `VP response validation failed: "claimer.created_at" must be a number, got ${l(r.created_at)}`
498
+ `VP response validation failed: "claimer.created_at" must be a number, got ${p(r.created_at)}`
499
499
  );
500
500
  if (typeof r.updated_at != "number")
501
501
  throw new a(
502
- `VP response validation failed: "claimer.updated_at" must be a number, got ${l(r.updated_at)}`
502
+ `VP response validation failed: "claimer.updated_at" must be a number, got ${p(r.updated_at)}`
503
503
  );
504
504
  }
505
- function Re(r, e) {
505
+ function Ye(r, e) {
506
506
  if (r === null || typeof r != "object")
507
507
  throw new a(
508
- `VP response validation failed: "challengers[${e}]" must be an object, got ${l(r)}`
508
+ `VP response validation failed: "challengers[${e}]" must be an object, got ${p(r)}`
509
509
  );
510
510
  const t = r;
511
- if (_(t.status, `challengers[${e}].status`), _(t.claim_txid, `challengers[${e}].claim_txid`), _(t.claimer_pubkey, `challengers[${e}].claimer_pubkey`), C(t.assert_txid, `challengers[${e}].assert_txid`), C(
511
+ if (b(t.status, `challengers[${e}].status`), b(t.claim_txid, `challengers[${e}].claim_txid`), b(t.claimer_pubkey, `challengers[${e}].claimer_pubkey`), N(t.assert_txid, `challengers[${e}].assert_txid`), N(
512
512
  t.challenge_assert_x_txid,
513
513
  `challengers[${e}].challenge_assert_x_txid`
514
- ), C(
514
+ ), N(
515
515
  t.challenge_assert_y_txid,
516
516
  `challengers[${e}].challenge_assert_y_txid`
517
- ), C(t.nopayout_txid, `challengers[${e}].nopayout_txid`), typeof t.created_at != "number")
517
+ ), N(t.nopayout_txid, `challengers[${e}].nopayout_txid`), typeof t.created_at != "number")
518
518
  throw new a(
519
- `VP response validation failed: "challengers[${e}].created_at" must be a number, got ${l(t.created_at)}`
519
+ `VP response validation failed: "challengers[${e}].created_at" must be a number, got ${p(t.created_at)}`
520
520
  );
521
521
  if (typeof t.updated_at != "number")
522
522
  throw new a(
523
- `VP response validation failed: "challengers[${e}].updated_at" must be a number, got ${l(t.updated_at)}`
523
+ `VP response validation failed: "challengers[${e}].updated_at" must be a number, got ${p(t.updated_at)}`
524
524
  );
525
525
  }
526
- function C(r, e) {
526
+ function N(r, e) {
527
527
  if (r !== null && typeof r != "string")
528
528
  throw new a(
529
- `VP response validation failed: "${e}" must be a string or null, got ${l(r)}`
529
+ `VP response validation failed: "${e}" must be a string or null, got ${p(r)}`
530
530
  );
531
531
  }
532
- function Ne(r) {
533
- oe(r, "batchGetPeginStatus", (e) => {
534
- e.result !== null && ae(e.result);
532
+ function ze(r) {
533
+ xe(r, "batchGetPeginStatus", (e) => {
534
+ e.result !== null && we(e.result);
535
535
  });
536
536
  }
537
- function Ge(r) {
538
- oe(r, "batchGetPegoutStatus", (e) => {
539
- e.result !== null && Ce(e.result);
537
+ function Ze(r) {
538
+ xe(r, "batchGetPegoutStatus", (e) => {
539
+ e.result !== null && qe(e.result);
540
540
  });
541
541
  }
542
- function oe(r, e, t) {
542
+ function xe(r, e, t) {
543
543
  if (r === null || typeof r != "object")
544
544
  throw new a(
545
545
  `VP response validation failed: ${e} response is not an object`
@@ -547,41 +547,41 @@ function oe(r, e, t) {
547
547
  const n = r;
548
548
  if (!Array.isArray(n.results))
549
549
  throw new a(
550
- `VP response validation failed: "${e}.results" must be an array, got ${l(n.results)}`
550
+ `VP response validation failed: "${e}.results" must be an array, got ${p(n.results)}`
551
551
  );
552
- for (let s = 0; s < n.results.length; s++) {
553
- const i = n.results[s];
554
- if (i === null || typeof i != "object")
552
+ for (let i = 0; i < n.results.length; i++) {
553
+ const s = n.results[i];
554
+ if (s === null || typeof s != "object")
555
555
  throw new a(
556
- `VP response validation failed: "${e}.results[${s}]" must be an object, got ${l(i)}`
556
+ `VP response validation failed: "${e}.results[${i}]" must be an object, got ${p(s)}`
557
557
  );
558
- const o = i;
559
- if (!P(o.pegin_txid) || o.pegin_txid.length !== $)
558
+ const o = s;
559
+ if (!C(o.pegin_txid) || o.pegin_txid.length !== O)
560
560
  throw new a(
561
- `VP response validation failed: "${e}.results[${s}].pegin_txid" must be a ${$}-char hex string, got ${l(o.pegin_txid)}`
561
+ `VP response validation failed: "${e}.results[${i}].pegin_txid" must be a ${O}-char hex string, got ${p(o.pegin_txid)}`
562
562
  );
563
563
  if (o.error !== null && typeof o.error != "string")
564
564
  throw new a(
565
- `VP response validation failed: "${e}.results[${s}].error" must be a string or null, got ${l(o.error)}`
565
+ `VP response validation failed: "${e}.results[${i}].error" must be a string or null, got ${p(o.error)}`
566
566
  );
567
567
  if (o.result === null && o.error === null)
568
568
  throw new a(
569
- `VP response validation failed: "${e}.results[${s}]" has neither "result" nor "error" populated`
569
+ `VP response validation failed: "${e}.results[${i}]" has neither "result" nor "error" populated`
570
570
  );
571
571
  if (o.result !== null && o.error !== null)
572
572
  throw new a(
573
- `VP response validation failed: "${e}.results[${s}]" has both "result" and "error" populated`
573
+ `VP response validation failed: "${e}.results[${i}]" has both "result" and "error" populated`
574
574
  );
575
- t(o, s);
575
+ t(o, i);
576
576
  }
577
577
  }
578
- function De(r) {
579
- if (y(r.claim_tx, "depositor_graph.claim_tx"), y(r.assert_tx, "depositor_graph.assert_tx"), y(r.payout_tx, "depositor_graph.payout_tx"), _(r.payout_psbt, "depositor_graph.payout_psbt"), !Array.isArray(r.challenger_presign_data))
578
+ function Qe(r) {
579
+ if (v(r.claim_tx, "depositor_graph.claim_tx"), v(r.assert_tx, "depositor_graph.assert_tx"), v(r.payout_tx, "depositor_graph.payout_tx"), b(r.payout_psbt, "depositor_graph.payout_psbt"), !Array.isArray(r.challenger_presign_data))
580
580
  throw new a(
581
581
  'VP response validation failed: "depositor_graph.challenger_presign_data" must be an array'
582
582
  );
583
583
  for (let e = 0; e < r.challenger_presign_data.length; e++)
584
- Ee(
584
+ Ke(
585
585
  r.challenger_presign_data[e],
586
586
  `depositor_graph.challenger_presign_data[${e}]`
587
587
  );
@@ -590,13 +590,13 @@ function De(r) {
590
590
  'VP response validation failed: "depositor_graph.offchain_params_version" must be a number'
591
591
  );
592
592
  }
593
- const He = 6e4;
594
- class Be {
593
+ const et = 6e4;
594
+ class tt {
595
595
  constructor(e, t) {
596
- p(this, "client");
596
+ f(this, "client");
597
597
  const n = {
598
598
  baseUrl: e,
599
- timeout: (t == null ? void 0 : t.timeout) ?? He,
599
+ timeout: (t == null ? void 0 : t.timeout) ?? et,
600
600
  retries: t == null ? void 0 : t.retries,
601
601
  retryDelay: t == null ? void 0 : t.retryDelay,
602
602
  retryableFor: t == null ? void 0 : t.retryableFor,
@@ -604,7 +604,7 @@ class Be {
604
604
  tokenProvider: t == null ? void 0 : t.tokenProvider,
605
605
  maxResponseBytes: t == null ? void 0 : t.maxResponseBytes
606
606
  };
607
- this.client = new ne(n);
607
+ this.client = new _e(n);
608
608
  }
609
609
  /**
610
610
  * Request the payout/claim/assert transactions that the depositor
@@ -612,7 +612,7 @@ class Be {
612
612
  */
613
613
  async requestDepositorPresignTransactions(e, t) {
614
614
  const n = await this.client.call("vaultProvider_requestDepositorPresignTransactions", e, t);
615
- return Se(n), n;
615
+ return Ue(n), n;
616
616
  }
617
617
  /**
618
618
  * Submit the depositor's pre-signatures for the payout transactions
@@ -643,7 +643,7 @@ class Be {
643
643
  */
644
644
  async requestDepositorClaimerArtifacts(e, t) {
645
645
  const n = await this.client.call("vaultProvider_requestDepositorClaimerArtifacts", e, t);
646
- return Ve(n), n;
646
+ return Je(n), n;
647
647
  }
648
648
  /** Get the current pegin status from the vault provider daemon. */
649
649
  async getPeginStatus(e, t) {
@@ -652,7 +652,7 @@ class Be {
652
652
  e,
653
653
  t
654
654
  );
655
- return ae(n), n;
655
+ return we(n), n;
656
656
  }
657
657
  /**
658
658
  * Get pegin status for many txids in one round trip. Per-result envelope
@@ -661,7 +661,7 @@ class Be {
661
661
  */
662
662
  async batchGetPeginStatus(e, t) {
663
663
  const n = await this.client.call("vaultProvider_batchGetPeginStatus", e, t);
664
- return Ne(n), n;
664
+ return ze(n), n;
665
665
  }
666
666
  /**
667
667
  * Get pegout status for many txids in one round trip. Same per-result
@@ -669,306 +669,670 @@ class Be {
669
669
  */
670
670
  async batchGetPegoutStatus(e, t) {
671
671
  const n = await this.client.call("vaultProvider_batchGetPegoutStatus", e, t);
672
- return Ge(n), n;
672
+ return Ze(n), n;
673
673
  }
674
674
  }
675
- function Oe(r, e) {
675
+ function rt(r, e) {
676
676
  const t = /* @__PURE__ */ new Set();
677
- for (const u of r)
678
- t.add(u.toLowerCase());
679
- const n = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Set(), i = [], o = [];
680
- for (const u of e) {
681
- const d = u.pegin_txid.toLowerCase();
682
- if (!t.has(d)) {
683
- o.push(d);
677
+ for (const d of r)
678
+ t.add(d.toLowerCase());
679
+ const n = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set(), s = [], o = [];
680
+ for (const d of e) {
681
+ const u = d.pegin_txid.toLowerCase();
682
+ if (!t.has(u)) {
683
+ o.push(u);
684
684
  continue;
685
685
  }
686
- if (s.has(d)) {
687
- i.push(d);
686
+ if (i.has(u)) {
687
+ s.push(u);
688
688
  continue;
689
689
  }
690
- s.add(d), n.set(d, { result: u.result, error: u.error });
690
+ i.add(u), n.set(u, { result: d.result, error: d.error });
691
691
  }
692
692
  const c = [];
693
- for (const u of t)
694
- s.has(u) || c.push(u);
695
- return { byTxid: n, missing: c, unexpected: o, duplicate: i };
693
+ for (const d of t)
694
+ i.has(d) || c.push(d);
695
+ return { byTxid: n, missing: c, unexpected: o, duplicate: s };
696
696
  }
697
- async function gt(r) {
697
+ async function ur(r) {
698
698
  const {
699
699
  items: e,
700
700
  getTxid: t,
701
701
  batchCall: n,
702
- onItem: s,
703
- onMissing: i,
702
+ onItem: i,
703
+ onMissing: s,
704
704
  onDuplicate: o,
705
705
  onDuplicateBatch: c,
706
- onWholeBatchError: u,
707
- onUnexpected: d,
708
- batchSize: f = ye
706
+ onWholeBatchError: d,
707
+ onUnexpected: u,
708
+ batchSize: g = Be
709
709
  } = r;
710
- if (!Number.isInteger(f) || f <= 0)
710
+ if (!Number.isInteger(g) || g <= 0)
711
711
  throw new Error(
712
- `batchPollByProvider: batchSize must be a positive integer, got ${f}`
712
+ `batchPollByProvider: batchSize must be a positive integer, got ${g}`
713
713
  );
714
- for (let w = 0; w < e.length; w += f) {
715
- const x = e.slice(w, w + f), k = /* @__PURE__ */ new Map(), D = [];
716
- for (const h of x) {
717
- const m = t(h).toLowerCase();
718
- k.set(m, h), D.push(m);
714
+ for (let m = 0; m < e.length; m += g) {
715
+ const w = e.slice(m, m + g), k = /* @__PURE__ */ new Map(), T = [];
716
+ for (const _ of w) {
717
+ const l = t(_).toLowerCase();
718
+ k.set(l, _), T.push(l);
719
719
  }
720
- let v;
720
+ let A;
721
721
  try {
722
- const h = await n(D);
723
- v = Oe(D, h.results);
724
- } catch (h) {
725
- u(x, h);
722
+ const _ = await n(T);
723
+ A = rt(T, _.results);
724
+ } catch (_) {
725
+ d(w, _);
726
726
  continue;
727
727
  }
728
- d && v.unexpected.length > 0 && d(v.unexpected);
729
- const T = new Set(v.duplicate);
730
- for (const h of T) {
731
- const m = k.get(h);
732
- m && o(m);
728
+ u && A.unexpected.length > 0 && u(A.unexpected);
729
+ const $ = new Set(A.duplicate);
730
+ for (const _ of $) {
731
+ const l = k.get(_);
732
+ l && o(l);
733
733
  }
734
- c && T.size > 0 && c(T.size);
735
- for (const h of v.missing) {
736
- const m = k.get(h);
737
- m && i(m);
734
+ c && $.size > 0 && c($.size);
735
+ for (const _ of A.missing) {
736
+ const l = k.get(_);
737
+ l && s(l);
738
738
  }
739
- for (const [h, m] of v.byTxid) {
740
- if (T.has(h)) continue;
741
- const K = k.get(h);
742
- K && s(K, {
743
- pegin_txid: h,
744
- result: m.result,
745
- error: m.error
739
+ for (const [_, l] of A.byTxid) {
740
+ if ($.has(_)) continue;
741
+ const E = k.get(_);
742
+ E && i(E, {
743
+ pegin_txid: _,
744
+ result: l.result,
745
+ error: l.error
746
746
  });
747
747
  }
748
748
  }
749
749
  }
750
- const je = "BIP0322-signed-message", Me = "TapTweak", ce = 32, Ue = 64;
751
- function le(r, e) {
752
- const t = new TextEncoder().encode(r), n = J(t), s = new Uint8Array(n.length * 2 + e.length);
753
- return s.set(n, 0), s.set(n, n.length), s.set(e, n.length * 2), J(s);
750
+ const nt = "BIP0322-signed-message", st = "TapTweak", Ae = 32, it = 64;
751
+ function Pe(r, e) {
752
+ const t = new TextEncoder().encode(r), n = q(t), i = new Uint8Array(n.length * 2 + e.length);
753
+ return i.set(n, 0), i.set(n, n.length), i.set(e, n.length * 2), q(i);
754
754
  }
755
- function Fe(r) {
756
- if (r.length !== ce) return null;
757
- const e = le(Me, r), t = F.xOnlyPointAddTweak(r, e);
755
+ function ot(r) {
756
+ if (r.length !== Ae) return null;
757
+ const e = Pe(st, r), t = H.xOnlyPointAddTweak(r, e);
758
758
  return t ? t.xOnlyPubkey : null;
759
759
  }
760
- function Le(r, e, t) {
761
- if (e.length !== ce || t.length !== Ue) return !1;
760
+ function at(r, e, t) {
761
+ if (e.length !== Ae || t.length !== it) return !1;
762
762
  try {
763
- const n = le(je, r), s = Pe.p2tr({
764
- internalPubkey: A.from(e)
763
+ const n = Pe(nt, r), i = De.p2tr({
764
+ internalPubkey: I.from(e)
765
765
  });
766
- if (!s.output) return !1;
767
- const i = s.output, o = 0, c = new O();
766
+ if (!i.output) return !1;
767
+ const s = i.output, o = 0, c = new X();
768
768
  c.version = 0, c.locktime = 0;
769
- const u = A.concat([
770
- A.from([0, 32]),
771
- A.from(n)
769
+ const d = I.concat([
770
+ I.from([0, 32]),
771
+ I.from(n)
772
772
  ]);
773
773
  c.addInput(
774
- A.alloc(32, 0),
774
+ I.alloc(32, 0),
775
775
  // prev_txid = 0x0000...0000
776
776
  4294967295,
777
777
  // prev_vout = 0xFFFFFFFF
778
778
  0,
779
779
  // sequence = 0
780
- u
781
- ), c.addOutput(i, o);
782
- const d = new O();
783
- d.version = 0, d.locktime = 0;
784
- const f = c.getHash();
785
- d.addInput(f, 0, 0), d.addOutput(A.from([106]), o);
786
- const w = d.hashForWitnessV1(
780
+ d
781
+ ), c.addOutput(s, o);
782
+ const u = new X();
783
+ u.version = 0, u.locktime = 0;
784
+ const g = c.getHash();
785
+ u.addInput(g, 0, 0), u.addOutput(I.from([106]), o);
786
+ const m = u.hashForWitnessV1(
787
787
  0,
788
- [i],
788
+ [s],
789
789
  [o],
790
- O.SIGHASH_DEFAULT
791
- ), x = Fe(e);
792
- return x ? F.verifySchnorr(w, x, t) : !1;
790
+ X.SIGHASH_DEFAULT
791
+ ), w = ot(e);
792
+ return w ? H.verifySchnorr(m, w, t) : !1;
793
793
  } catch {
794
794
  return !1;
795
795
  }
796
796
  }
797
- function G(r, e) {
797
+ function j(r, e) {
798
798
  const t = (r & 7) << 5, n = typeof e == "bigint" ? e : BigInt(e);
799
799
  if (n < 0n) throw new Error("cborHead: negative argument");
800
800
  if (n < 24n) return new Uint8Array([t | Number(n)]);
801
801
  if (n < 0x100n) return new Uint8Array([t | 24, Number(n)]);
802
802
  if (n < 0x10000n) {
803
- const i = Number(n);
804
- return new Uint8Array([t | 25, i >>> 8 & 255, i & 255]);
803
+ const s = Number(n);
804
+ return new Uint8Array([t | 25, s >>> 8 & 255, s & 255]);
805
805
  }
806
806
  if (n < 0x100000000n) {
807
- const i = Number(n);
807
+ const s = Number(n);
808
808
  return new Uint8Array([
809
809
  t | 26,
810
- i >>> 24 & 255,
811
- i >>> 16 & 255,
812
- i >>> 8 & 255,
813
- i & 255
810
+ s >>> 24 & 255,
811
+ s >>> 16 & 255,
812
+ s >>> 8 & 255,
813
+ s & 255
814
814
  ]);
815
815
  }
816
- const s = new Uint8Array(9);
817
- s[0] = t | 27;
818
- for (let i = 7; i >= 0; i--)
819
- s[1 + i] = Number(n >> BigInt((7 - i) * 8)) & 255;
820
- return s;
816
+ const i = new Uint8Array(9);
817
+ i[0] = t | 27;
818
+ for (let s = 7; s >= 0; s--)
819
+ i[1 + s] = Number(n >> BigInt((7 - s) * 8)) & 255;
820
+ return i;
821
821
  }
822
- function ue(...r) {
823
- const e = r.reduce((s, i) => s + i.length, 0), t = new Uint8Array(e);
822
+ function ve(...r) {
823
+ const e = r.reduce((i, s) => i + s.length, 0), t = new Uint8Array(e);
824
824
  let n = 0;
825
- for (const s of r)
826
- t.set(s, n), n += s.length;
825
+ for (const i of r)
826
+ t.set(i, n), n += i.length;
827
827
  return t;
828
828
  }
829
- function Q(r) {
830
- const t = [G(4, r.length)];
829
+ function ie(r) {
830
+ const t = [j(4, r.length)];
831
831
  for (const n of r)
832
- t.push(G(0, n));
833
- return ue(...t);
832
+ t.push(j(0, n));
833
+ return ve(...t);
834
834
  }
835
- function Ke(r, e, t) {
835
+ function ct(r, e, t) {
836
836
  if (!Number.isSafeInteger(t) || t < 0)
837
837
  throw new Error(
838
838
  `encodeServerIdentityPayload: expires_at must be a non-negative safe integer, got ${t}`
839
839
  );
840
- const n = G(4, 3), s = Q(r), i = Q(e), o = G(0, t);
841
- return ue(n, s, i, o);
840
+ const n = j(4, 3), i = ie(r), s = ie(e), o = j(0, t);
841
+ return ve(n, i, s, o);
842
842
  }
843
- const Xe = new TextEncoder().encode(
843
+ const lt = new TextEncoder().encode(
844
844
  "btc-auth.server-identity.v1"
845
- ), qe = 2 * 3600;
846
- class g extends Error {
845
+ ), ut = 2 * 3600;
846
+ class y extends Error {
847
847
  constructor(e, t) {
848
848
  super(e), this.reason = t, this.name = "ServerIdentityError";
849
849
  }
850
850
  }
851
- function I(r) {
851
+ function G(r) {
852
852
  const e = new Uint8Array(r.length / 2);
853
853
  for (let t = 0; t < e.length; t++)
854
854
  e[t] = parseInt(r.slice(t * 2, t * 2 + 2), 16);
855
855
  return e;
856
856
  }
857
- function Je(r) {
858
- const { proof: e, pinnedServerPubkey: t, now: n } = r, s = r.maxLifetimeSecs ?? qe, i = E(t).toLowerCase();
859
- if (i.length !== R || !S.test(i))
860
- throw new g(
861
- `pinnedServerPubkey must be 32-byte hex; got ${i.length} chars`,
857
+ function dt(r) {
858
+ const { proof: e, pinnedServerPubkey: t, now: n } = r, i = r.maxLifetimeSecs ?? ut, s = V(t).toLowerCase();
859
+ if (s.length !== R || !S.test(s))
860
+ throw new y(
861
+ `pinnedServerPubkey must be 32-byte hex; got ${s.length} chars`,
862
862
  "invalid_pubkey_encoding"
863
863
  );
864
- const o = E(e.server_pubkey).toLowerCase();
864
+ const o = V(e.server_pubkey).toLowerCase();
865
865
  if (o.length !== R || !S.test(o))
866
- throw new g(
866
+ throw new y(
867
867
  `server_pubkey must be 32-byte hex; got ${o.length} chars`,
868
868
  "invalid_pubkey_encoding"
869
869
  );
870
- if (o !== i)
871
- throw new g(
872
- `server_pubkey does not match pinned value: expected ${i}, got ${o}`,
870
+ if (o !== s)
871
+ throw new y(
872
+ `server_pubkey does not match pinned value: expected ${s}, got ${o}`,
873
873
  "pinned_pubkey_mismatch"
874
874
  );
875
875
  if (!Number.isSafeInteger(e.expires_at))
876
- throw new g(
876
+ throw new y(
877
877
  `expires_at must be a finite integer; got ${JSON.stringify(e.expires_at)}`,
878
878
  "invalid_expires_at"
879
879
  );
880
880
  if (!Number.isSafeInteger(n))
881
- throw new g(
881
+ throw new y(
882
882
  `now must be a finite integer; got ${JSON.stringify(n)}`,
883
883
  "invalid_expires_at"
884
884
  );
885
885
  if (e.expires_at <= n)
886
- throw new g(
886
+ throw new y(
887
887
  `server identity proof expired at ${e.expires_at}, now ${n}`,
888
888
  "expired"
889
889
  );
890
- if (!Number.isSafeInteger(s) || s <= 0)
891
- throw new g(
892
- `maxLifetimeSecs must be a positive safe integer; got ${JSON.stringify(s)}`,
890
+ if (!Number.isSafeInteger(i) || i <= 0)
891
+ throw new y(
892
+ `maxLifetimeSecs must be a positive safe integer; got ${JSON.stringify(i)}`,
893
893
  "invalid_max_lifetime"
894
894
  );
895
- if (e.expires_at - n > s)
896
- throw new g(
897
- `server identity proof expires too far in the future: expires_at=${e.expires_at}, now=${n}, max lifetime=${s}s`,
895
+ if (e.expires_at - n > i)
896
+ throw new y(
897
+ `server identity proof expires too far in the future: expires_at=${e.expires_at}, now=${n}, max lifetime=${i}s`,
898
898
  "expires_too_far"
899
899
  );
900
- const c = E(e.ephemeral_pubkey).toLowerCase();
901
- if (c.length !== j || !S.test(c))
902
- throw new g(
900
+ const c = V(e.ephemeral_pubkey).toLowerCase();
901
+ if (c.length !== D || !S.test(c))
902
+ throw new y(
903
903
  `ephemeral_pubkey must be 33-byte compressed hex; got ${c.length} chars`,
904
904
  "invalid_ephemeral_pubkey"
905
905
  );
906
- const u = c.slice(0, 2);
907
- if (u !== "02" && u !== "03")
908
- throw new g(
909
- `ephemeral_pubkey must be compressed (prefix 02/03); got ${u}`,
906
+ const d = c.slice(0, 2);
907
+ if (d !== "02" && d !== "03")
908
+ throw new y(
909
+ `ephemeral_pubkey must be compressed (prefix 02/03); got ${d}`,
910
910
  "invalid_ephemeral_pubkey"
911
911
  );
912
- const d = I(c);
913
- if (!F.isPoint(d))
914
- throw new g(
912
+ const u = G(c);
913
+ if (!H.isPoint(u))
914
+ throw new y(
915
915
  "ephemeral_pubkey is not a valid secp256k1 point",
916
916
  "invalid_ephemeral_pubkey"
917
917
  );
918
- const f = E(e.signature).toLowerCase();
919
- if (f.length !== we || !S.test(f))
920
- throw new g(
921
- `signature must be 64-byte Schnorr hex; got ${f.length} chars`,
918
+ const g = V(e.signature).toLowerCase();
919
+ if (g.length !== Ne || !S.test(g))
920
+ throw new y(
921
+ `signature must be 64-byte Schnorr hex; got ${g.length} chars`,
922
922
  "invalid_signature_encoding"
923
923
  );
924
- const w = Ke(
925
- Xe,
926
- I(c),
924
+ const m = ct(
925
+ lt,
926
+ G(c),
927
927
  e.expires_at
928
928
  );
929
- if (!Le(w, I(o), I(f)))
930
- throw new g(
929
+ if (!at(m, G(o), G(g)))
930
+ throw new y(
931
931
  "BIP-322 signature verification failed — ephemeral key is not attested by pinned server pubkey",
932
932
  "signature_verification_failed"
933
933
  );
934
934
  }
935
- const ee = /* @__PURE__ */ new Set([
935
+ const oe = /* @__PURE__ */ new Set([
936
936
  "vaultProvider_submitDepositorWotsKey",
937
937
  "vaultProvider_submitDepositorPresignatures",
938
938
  "vaultProvider_requestDepositorPresignTransactions"
939
- ]), te = /* @__PURE__ */ new Set([
939
+ ]), ae = /* @__PURE__ */ new Set([
940
940
  "vaultProvider_requestDepositorClaimerArtifacts"
941
- ]), ze = 6e4, M = "auth_createDepositorToken", U = "auth_createDepositorTokenGrpc";
942
- function de(r, e) {
943
- return new ne({
941
+ ]), ht = 6e4, W = "auth_createDepositorToken", Y = "auth_createDepositorTokenGrpc";
942
+ function ke(r, e) {
943
+ return new _e({
944
944
  baseUrl: r,
945
- timeout: ze,
945
+ timeout: ht,
946
946
  headers: e,
947
- retryableFor: (t) => t === M || t === U
947
+ retryableFor: (t) => t === W || t === Y
948
948
  });
949
949
  }
950
- const re = 4102444800, We = 30;
951
- class Ye {
950
+ const pt = 0, gt = 1, F = 2, ft = 3, _t = 4, mt = 5, yt = 6, bt = 7, ce = 24, wt = 28, xt = 20, At = 21, Pt = 22, le = 256;
951
+ class P extends Error {
952
+ constructor(e) {
953
+ super(`CBOR decode: ${e}`), this.name = "CborDecodeError";
954
+ }
955
+ }
956
+ class Ee {
957
+ constructor(e) {
958
+ f(this, "buf");
959
+ /** Current read offset. Public so callers can slice encoded sub-ranges. */
960
+ f(this, "pos", 0);
961
+ this.buf = e;
962
+ }
963
+ nextByte() {
964
+ if (this.pos >= this.buf.length)
965
+ throw new P("unexpected end of input");
966
+ return this.buf[this.pos++];
967
+ }
968
+ /**
969
+ * Read an initial byte and its argument. Rejects indefinite-length
970
+ * and reserved additional-info encodings. Arguments wider than
971
+ * {@link Number.MAX_SAFE_INTEGER} are rejected — none of the token's
972
+ * lengths, tags, or timestamps approach that bound.
973
+ */
974
+ readHead() {
975
+ const e = this.nextByte(), t = e >> 5, n = e & 31;
976
+ if (n < ce)
977
+ return { major: t, arg: n };
978
+ if (n >= wt)
979
+ throw new P(
980
+ `unsupported additional info ${n} (indefinite-length or reserved)`
981
+ );
982
+ const i = 1 << n - ce;
983
+ let s = 0n;
984
+ for (let o = 0; o < i; o++)
985
+ s = s << 8n | BigInt(this.nextByte());
986
+ if (s > BigInt(Number.MAX_SAFE_INTEGER))
987
+ throw new P(`argument ${s} exceeds safe integer range`);
988
+ return { major: t, arg: Number(s) };
989
+ }
990
+ /** Read `length` raw bytes as a sub-array view into the backing buffer. */
991
+ readBytes(e) {
992
+ if (this.pos + e > this.buf.length)
993
+ throw new P("length overruns end of input");
994
+ const t = this.buf.subarray(this.pos, this.pos + e);
995
+ return this.pos += e, t;
996
+ }
997
+ /**
998
+ * Read a byte string (major type 2), returning its content bytes.
999
+ * Throws if the next item is not a byte string.
1000
+ */
1001
+ readByteString() {
1002
+ const e = this.readHead();
1003
+ if (e.major !== F)
1004
+ throw new P(
1005
+ `expected byte string (major ${F}), got major ${e.major}`
1006
+ );
1007
+ return this.readBytes(e.arg);
1008
+ }
1009
+ /**
1010
+ * Read the next complete data item as a decoded {@link CborValue}.
1011
+ *
1012
+ * `depth` tracks the current nesting level so a deeply-nested blob is
1013
+ * rejected with a {@link CborDecodeError} rather than overflowing the
1014
+ * native call stack (see {@link MAX_NESTING_DEPTH}).
1015
+ */
1016
+ readValue(e = 0) {
1017
+ if (e > le)
1018
+ throw new P(
1019
+ `nesting exceeds maximum depth ${le}`
1020
+ );
1021
+ const t = this.readHead();
1022
+ switch (t.major) {
1023
+ case pt:
1024
+ return t.arg;
1025
+ case gt:
1026
+ return -1 - t.arg;
1027
+ case F:
1028
+ return this.readBytes(t.arg);
1029
+ case ft:
1030
+ return new TextDecoder("utf-8", { fatal: !0 }).decode(
1031
+ this.readBytes(t.arg)
1032
+ );
1033
+ case _t: {
1034
+ const n = [];
1035
+ for (let i = 0; i < t.arg; i++)
1036
+ n.push(this.readValue(e + 1));
1037
+ return n;
1038
+ }
1039
+ case mt: {
1040
+ const n = /* @__PURE__ */ new Map();
1041
+ for (let i = 0; i < t.arg; i++) {
1042
+ const s = this.readValue(e + 1), o = this.readValue(e + 1);
1043
+ n.set(s, o);
1044
+ }
1045
+ return n;
1046
+ }
1047
+ case yt:
1048
+ return { tag: t.arg, value: this.readValue(e + 1) };
1049
+ case bt:
1050
+ if (t.arg === xt) return !1;
1051
+ if (t.arg === At) return !0;
1052
+ if (t.arg === Pt) return null;
1053
+ throw new P(
1054
+ `unsupported simple/float value ${t.arg}`
1055
+ );
1056
+ default:
1057
+ throw new P(`unsupported major type ${t.major}`);
1058
+ }
1059
+ }
1060
+ }
1061
+ function Se(r) {
1062
+ const e = new Ee(r), t = e.readValue();
1063
+ if (e.pos !== r.length)
1064
+ throw new P("trailing bytes after top-level item");
1065
+ return t;
1066
+ }
1067
+ const vt = "vaultd-jsonrpc", kt = "vaultd-grpc", ue = 18, z = 4, de = -47, Et = 1, he = 64, St = 128, Tt = 96, Ct = 64, $t = 1, It = 2, Vt = 3, Rt = 4, Ot = 5, Bt = 6, Nt = 7, pe = new TextEncoder().encode("Signature1");
1068
+ class h extends Error {
1069
+ constructor(e, t) {
1070
+ super(e), this.reason = t, this.name = "CwtVerificationError";
1071
+ }
1072
+ }
1073
+ function Gt(r) {
1074
+ const e = ge(
1075
+ r.expectedIssuerXOnlyPubkey,
1076
+ "expectedIssuerXOnlyPubkey"
1077
+ ), t = ge(
1078
+ r.expectedAudienceXOnlyPubkey,
1079
+ "expectedAudienceXOnlyPubkey"
1080
+ ), n = Lt(r.ephemeralPubkeyHex), i = Xt(r.token), s = new Ee(i), o = s.readHead();
1081
+ if (o.major !== 6 || o.arg !== ue)
1082
+ throw new h(
1083
+ `token is not a COSE Sign1 tagged value (tag ${ue})`,
1084
+ "invalid_token_structure"
1085
+ );
1086
+ const c = s.readHead();
1087
+ if (c.major !== 4 || c.arg !== z)
1088
+ throw new h(
1089
+ `COSE Sign1 must be a ${z}-element array`,
1090
+ "invalid_token_structure"
1091
+ );
1092
+ const d = s.pos, u = s.readByteString(), g = i.subarray(d, s.pos);
1093
+ s.readValue();
1094
+ const m = s.pos, w = s.readByteString(), k = i.subarray(m, s.pos), T = s.readByteString();
1095
+ if (T.length !== he)
1096
+ throw new h(
1097
+ `COSE signature must be ${he} bytes, got ${T.length}`,
1098
+ "invalid_token_structure"
1099
+ );
1100
+ if (s.pos !== i.length)
1101
+ throw new h(
1102
+ "COSE Sign1 token has trailing bytes after the signature",
1103
+ "invalid_token_structure"
1104
+ );
1105
+ const A = Dt(u);
1106
+ if (A !== de)
1107
+ throw new h(
1108
+ `unexpected COSE algorithm ${A} (expected ES256K ${de})`,
1109
+ "unexpected_algorithm"
1110
+ );
1111
+ const $ = Mt(g, k), _ = q($);
1112
+ if (!H.verify(_, n, T, !0))
1113
+ throw new h(
1114
+ "COSE signature does not verify against the server's ephemeral key",
1115
+ "signature_verification_failed"
1116
+ );
1117
+ const l = jt(w), E = l.audience.toLowerCase();
1118
+ if (E.length !== R || !S.test(E))
1119
+ throw new h(
1120
+ "token `aud` is not a 32-byte x-only pubkey hex",
1121
+ "invalid_claims"
1122
+ );
1123
+ if (l.issuedAt > l.expiresAt)
1124
+ throw new h(
1125
+ `token iat (${l.issuedAt}) is after exp (${l.expiresAt})`,
1126
+ "invalid_claims"
1127
+ );
1128
+ if (l.issuer.toLowerCase() !== e)
1129
+ throw new h(
1130
+ `token issuer does not match pinned server pubkey: expected ${e}, got ${l.issuer.toLowerCase()}`,
1131
+ "issuer_mismatch"
1132
+ );
1133
+ if (l.subject !== r.expectedSubject)
1134
+ throw new h(
1135
+ `token subject mismatch: expected ${r.expectedSubject}, got ${l.subject}`,
1136
+ "subject_mismatch"
1137
+ );
1138
+ if (E !== t)
1139
+ throw new h(
1140
+ `token audience does not match depositor pubkey: expected ${t}, got ${E}`,
1141
+ "audience_mismatch"
1142
+ );
1143
+ if (l.notBefore > r.now)
1144
+ throw new h(
1145
+ `token not yet valid: nbf ${l.notBefore} > now ${r.now}`,
1146
+ "token_not_yet_valid"
1147
+ );
1148
+ if (l.issuedAt > r.now)
1149
+ throw new h(
1150
+ `token issued in the future: iat ${l.issuedAt} > now ${r.now}`,
1151
+ "invalid_claims"
1152
+ );
1153
+ if (l.expiresAt <= r.now)
1154
+ throw new h(
1155
+ `token expired: exp ${l.expiresAt} <= now ${r.now}`,
1156
+ "token_expired"
1157
+ );
1158
+ if (r.responseExpiresAt !== l.expiresAt)
1159
+ throw new h(
1160
+ `response expires_at (${r.responseExpiresAt}) does not equal token exp (${l.expiresAt})`,
1161
+ "expiry_mismatch"
1162
+ );
1163
+ if (r.serverIdentityExpiresAt < l.expiresAt)
1164
+ throw new h(
1165
+ `server identity expires (${r.serverIdentityExpiresAt}) before token exp (${l.expiresAt})`,
1166
+ "server_identity_expires_before_token"
1167
+ );
1168
+ return {
1169
+ issuer: l.issuer,
1170
+ subject: l.subject,
1171
+ audience: E,
1172
+ expiresAt: l.expiresAt,
1173
+ notBefore: l.notBefore,
1174
+ issuedAt: l.issuedAt
1175
+ };
1176
+ }
1177
+ function Dt(r) {
1178
+ if (r.length === 0)
1179
+ throw new h(
1180
+ "empty COSE protected header (no algorithm)",
1181
+ "unexpected_algorithm"
1182
+ );
1183
+ const e = Se(r);
1184
+ if (!(e instanceof Map))
1185
+ throw new h(
1186
+ "COSE protected header is not a map",
1187
+ "invalid_token_structure"
1188
+ );
1189
+ const t = e.get(Et);
1190
+ if (typeof t != "number")
1191
+ throw new h(
1192
+ "COSE protected header missing integer algorithm label",
1193
+ "unexpected_algorithm"
1194
+ );
1195
+ return t;
1196
+ }
1197
+ function Mt(r, e) {
1198
+ return Ft(
1199
+ Uint8Array.of(St | z),
1200
+ Uint8Array.of(Tt | pe.length),
1201
+ pe,
1202
+ r,
1203
+ Uint8Array.of(Ct),
1204
+ e
1205
+ );
1206
+ }
1207
+ function jt(r) {
1208
+ const e = Se(r);
1209
+ if (!(e instanceof Map))
1210
+ throw new h(
1211
+ "CWT claims root is not a map",
1212
+ "invalid_claims"
1213
+ );
1214
+ if (Ht(e, Nt, "cti").length === 0)
1215
+ throw new h("token cti is empty", "invalid_claims");
1216
+ return {
1217
+ issuer: K(e, $t, "iss"),
1218
+ subject: K(e, It, "sub"),
1219
+ audience: K(e, Vt, "aud"),
1220
+ expiresAt: J(e, Rt, "exp"),
1221
+ notBefore: J(e, Ot, "nbf"),
1222
+ issuedAt: J(e, Bt, "iat")
1223
+ };
1224
+ }
1225
+ function K(r, e, t) {
1226
+ const n = r.get(e);
1227
+ if (typeof n != "string")
1228
+ throw new h(
1229
+ `token claim ${t} is missing or not a text string`,
1230
+ "invalid_claims"
1231
+ );
1232
+ return n;
1233
+ }
1234
+ function Ht(r, e, t) {
1235
+ const n = r.get(e);
1236
+ if (!(n instanceof Uint8Array))
1237
+ throw new h(
1238
+ `token claim ${t} is missing or not a byte string`,
1239
+ "invalid_claims"
1240
+ );
1241
+ return n;
1242
+ }
1243
+ function J(r, e, t) {
1244
+ const n = r.get(e);
1245
+ if (typeof n != "number" || !Number.isSafeInteger(n) || n < 0)
1246
+ throw new h(
1247
+ `token claim ${t} is missing or not a non-negative integer timestamp`,
1248
+ "invalid_claims"
1249
+ );
1250
+ return n;
1251
+ }
1252
+ function ge(r, e) {
1253
+ const t = V(r).toLowerCase();
1254
+ if (t.length !== R || !S.test(t))
1255
+ throw new h(
1256
+ `${e} must be 32-byte x-only hex; got ${t.length} chars`,
1257
+ "invalid_input"
1258
+ );
1259
+ return t;
1260
+ }
1261
+ function Lt(r) {
1262
+ const e = V(r).toLowerCase(), t = e.slice(0, 2);
1263
+ if (e.length !== D || !S.test(e) || t !== "02" && t !== "03")
1264
+ throw new h(
1265
+ "ephemeralPubkeyHex must be 33-byte compressed pubkey hex (prefix 02/03)",
1266
+ "invalid_input"
1267
+ );
1268
+ return Ge(e);
1269
+ }
1270
+ const Ut = (() => {
1271
+ const r = new Int16Array(128).fill(-1), e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
1272
+ for (let t = 0; t < e.length; t++)
1273
+ r[e.charCodeAt(t)] = t;
1274
+ return r;
1275
+ })();
1276
+ function Xt(r) {
1277
+ const e = r.length, t = Math.floor(e / 4), n = e % 4;
1278
+ if (n === 1)
1279
+ throw new h(
1280
+ "invalid base64url length",
1281
+ "invalid_token_structure"
1282
+ );
1283
+ const i = t * 3 + (n === 0 ? 0 : n - 1), s = new Uint8Array(i), o = (u) => {
1284
+ const g = u < 128 ? Ut[u] : -1;
1285
+ if (g < 0)
1286
+ throw new h(
1287
+ "invalid base64url character",
1288
+ "invalid_token_structure"
1289
+ );
1290
+ return g;
1291
+ };
1292
+ let c = 0, d = 0;
1293
+ for (let u = 0; u < t; u++) {
1294
+ const g = o(r.charCodeAt(c++)), m = o(r.charCodeAt(c++)), w = o(r.charCodeAt(c++)), k = o(r.charCodeAt(c++));
1295
+ s[d++] = g << 2 | m >> 4, s[d++] = (m & 15) << 4 | w >> 2, s[d++] = (w & 3) << 6 | k;
1296
+ }
1297
+ if (n === 2) {
1298
+ const u = o(r.charCodeAt(c++)), g = o(r.charCodeAt(c++));
1299
+ s[d++] = u << 2 | g >> 4;
1300
+ } else if (n === 3) {
1301
+ const u = o(r.charCodeAt(c++)), g = o(r.charCodeAt(c++)), m = o(r.charCodeAt(c++));
1302
+ s[d++] = u << 2 | g >> 4, s[d++] = (g & 15) << 4 | m >> 2;
1303
+ }
1304
+ return s;
1305
+ }
1306
+ function Ft(...r) {
1307
+ const e = r.reduce((i, s) => i + s.length, 0), t = new Uint8Array(e);
1308
+ let n = 0;
1309
+ for (const i of r)
1310
+ t.set(i, n), n += i.length;
1311
+ return t;
1312
+ }
1313
+ const fe = 4102444800, Kt = 30;
1314
+ class Jt {
952
1315
  constructor(e) {
953
1316
  // `client` is the only mutable field — see `setClient`. The
954
1317
  // identity-bearing fields (peginTxid/authAnchorHex/pinnedServerPubkey)
955
1318
  // remain readonly and are checked against re-registration in the
956
1319
  // registry's `getOrCreate`.
957
- p(this, "client");
958
- p(this, "peginTxid");
959
- p(this, "authAnchorHex");
960
- p(this, "pinnedServerPubkey");
961
- p(this, "authGatedMethods");
962
- p(this, "grpcGatedMethods");
963
- p(this, "refreshSkewSecs");
964
- p(this, "now");
1320
+ f(this, "client");
1321
+ f(this, "peginTxid");
1322
+ f(this, "authAnchorHex");
1323
+ f(this, "pinnedServerPubkey");
1324
+ f(this, "expectedAudienceXOnlyPubkey");
1325
+ f(this, "authGatedMethods");
1326
+ f(this, "grpcGatedMethods");
1327
+ f(this, "refreshSkewSecs");
1328
+ f(this, "now");
965
1329
  /** Cached JSON-RPC-subject bearer (auth_createDepositorToken). */
966
- p(this, "cachedJsonRpc", null);
967
- p(this, "inFlightJsonRpc", null);
1330
+ f(this, "cachedJsonRpc", null);
1331
+ f(this, "inFlightJsonRpc", null);
968
1332
  /** Cached gRPC-subject bearer (auth_createDepositorTokenGrpc). */
969
- p(this, "cachedGrpc", null);
970
- p(this, "inFlightGrpc", null);
971
- this.client = e.client, this.peginTxid = e.peginTxid, this.authAnchorHex = e.authAnchorHex, this.pinnedServerPubkey = e.pinnedServerPubkey, this.authGatedMethods = e.authGatedMethods, this.grpcGatedMethods = e.grpcGatedMethods, this.refreshSkewSecs = e.refreshSkewSecs ?? We, this.now = e.now ?? (() => Math.floor(Date.now() / 1e3));
1333
+ f(this, "cachedGrpc", null);
1334
+ f(this, "inFlightGrpc", null);
1335
+ this.client = e.client, this.peginTxid = e.peginTxid, this.authAnchorHex = e.authAnchorHex, this.pinnedServerPubkey = e.pinnedServerPubkey, this.expectedAudienceXOnlyPubkey = e.expectedAudienceXOnlyPubkey, this.authGatedMethods = e.authGatedMethods, this.grpcGatedMethods = e.grpcGatedMethods, this.refreshSkewSecs = e.refreshSkewSecs ?? Kt, this.now = e.now ?? (() => Math.floor(Date.now() / 1e3));
972
1336
  }
973
1337
  /**
974
1338
  * Return a bearer token for `method`, or `null` if `method` is not
@@ -988,7 +1352,7 @@ class Ye {
988
1352
  * deterministically.
989
1353
  */
990
1354
  async getToken(e) {
991
- return e === M || e === U ? null : this.grpcGatedMethods.has(e) ? this.getTokenForSubject("grpc") : this.authGatedMethods.has(e) ? this.getTokenForSubject("jsonrpc") : null;
1355
+ return e === W || e === Y ? null : this.grpcGatedMethods.has(e) ? this.getTokenForSubject("grpc") : this.authGatedMethods.has(e) ? this.getTokenForSubject("jsonrpc") : null;
992
1356
  }
993
1357
  /**
994
1358
  * Drop both cached tokens. Next `getToken` call re-acquires the slot
@@ -1021,40 +1385,50 @@ class Ye {
1021
1385
  acquireSingleFlight(e) {
1022
1386
  const t = e === "grpc" ? this.inFlightGrpc : this.inFlightJsonRpc;
1023
1387
  if (t) return t;
1024
- const n = e === "grpc" ? U : M, s = (async () => {
1388
+ const n = e === "grpc" ? Y : W, i = (async () => {
1025
1389
  try {
1026
- const i = await this.client.call(n, {
1390
+ const s = await this.client.call(n, {
1027
1391
  pegin_txid: this.peginTxid,
1028
1392
  auth_anchor: this.authAnchorHex
1029
1393
  });
1030
- if (Je({
1031
- proof: i.server_identity,
1394
+ if (dt({
1395
+ proof: s.server_identity,
1032
1396
  pinnedServerPubkey: this.pinnedServerPubkey,
1033
1397
  now: this.now()
1034
- }), typeof i.token != "string" || i.token.length === 0)
1398
+ }), typeof s.token != "string" || s.token.length === 0)
1035
1399
  throw new Error(
1036
- `VpTokenProvider: invalid token in acquire response (expected non-empty string, got ${typeof i.token})`
1400
+ `VpTokenProvider: invalid token in acquire response (expected non-empty string, got ${typeof s.token})`
1037
1401
  );
1038
1402
  const o = this.now();
1039
- if (!Number.isSafeInteger(i.expires_at) || i.expires_at <= o || i.expires_at > re)
1403
+ if (!Number.isSafeInteger(s.expires_at) || s.expires_at <= o || s.expires_at > fe)
1040
1404
  throw new Error(
1041
- `VpTokenProvider: invalid expires_at in acquire response (got ${JSON.stringify(i.expires_at)}; must be a safe integer in (${o}, ${re}])`
1405
+ `VpTokenProvider: invalid expires_at in acquire response (got ${JSON.stringify(s.expires_at)}; must be a safe integer in (${o}, ${fe}])`
1042
1406
  );
1407
+ Gt({
1408
+ token: s.token,
1409
+ ephemeralPubkeyHex: s.server_identity.ephemeral_pubkey,
1410
+ expectedIssuerXOnlyPubkey: this.pinnedServerPubkey,
1411
+ expectedSubject: e === "grpc" ? kt : vt,
1412
+ expectedAudienceXOnlyPubkey: this.expectedAudienceXOnlyPubkey,
1413
+ responseExpiresAt: s.expires_at,
1414
+ serverIdentityExpiresAt: s.server_identity.expires_at,
1415
+ now: o
1416
+ });
1043
1417
  const c = {
1044
- token: i.token,
1045
- expiresAt: i.expires_at
1418
+ token: s.token,
1419
+ expiresAt: s.expires_at
1046
1420
  };
1047
1421
  return e === "grpc" ? this.cachedGrpc = c : this.cachedJsonRpc = c, c;
1048
1422
  } finally {
1049
1423
  e === "grpc" ? this.inFlightGrpc = null : this.inFlightJsonRpc = null;
1050
1424
  }
1051
1425
  })();
1052
- return e === "grpc" ? this.inFlightGrpc = s : this.inFlightJsonRpc = s, s;
1426
+ return e === "grpc" ? this.inFlightGrpc = i : this.inFlightJsonRpc = i, i;
1053
1427
  }
1054
1428
  }
1055
- class Ze {
1429
+ class qt {
1056
1430
  constructor() {
1057
- p(this, "entries", /* @__PURE__ */ new Map());
1431
+ f(this, "entries", /* @__PURE__ */ new Map());
1058
1432
  }
1059
1433
  /**
1060
1434
  * Return the cached `VpTokenProvider` for `peginTxid` if one exists
@@ -1075,26 +1449,32 @@ class Ze {
1075
1449
  throw new Error(
1076
1450
  `VpTokenRegistry: peginTxid ${e.peginTxid} already bound to pinnedServerPubkey ${n.pinnedServerPubkey.slice(0, 8)}…; got ${e.pinnedServerPubkey.slice(0, 8)}…`
1077
1451
  );
1452
+ if (n.expectedAudienceXOnlyPubkey !== e.expectedAudienceXOnlyPubkey)
1453
+ throw new Error(
1454
+ `VpTokenRegistry: peginTxid ${e.peginTxid} already bound to expectedAudienceXOnlyPubkey ${n.expectedAudienceXOnlyPubkey.slice(0, 8)}…; got ${e.expectedAudienceXOnlyPubkey.slice(0, 8)}…`
1455
+ );
1078
1456
  if (n.enableGrpcArtifactAuth !== t)
1079
1457
  throw new Error(
1080
1458
  `VpTokenRegistry: peginTxid ${e.peginTxid} already bound to enableGrpcArtifactAuth=${n.enableGrpcArtifactAuth}; got ${t}`
1081
1459
  );
1082
1460
  return n.provider.setClient(e.client), n.provider;
1083
1461
  }
1084
- const s = new Ye({
1462
+ const i = new Jt({
1085
1463
  client: e.client,
1086
1464
  peginTxid: e.peginTxid,
1087
1465
  authAnchorHex: e.authAnchorHex,
1088
1466
  pinnedServerPubkey: e.pinnedServerPubkey,
1089
- authGatedMethods: t ? ee : /* @__PURE__ */ new Set([...ee, ...te]),
1090
- grpcGatedMethods: t ? te : /* @__PURE__ */ new Set()
1467
+ expectedAudienceXOnlyPubkey: e.expectedAudienceXOnlyPubkey,
1468
+ authGatedMethods: t ? oe : /* @__PURE__ */ new Set([...oe, ...ae]),
1469
+ grpcGatedMethods: t ? ae : /* @__PURE__ */ new Set()
1091
1470
  });
1092
1471
  return this.entries.set(e.peginTxid, {
1093
- provider: s,
1472
+ provider: i,
1094
1473
  authAnchorHex: e.authAnchorHex,
1095
1474
  pinnedServerPubkey: e.pinnedServerPubkey,
1475
+ expectedAudienceXOnlyPubkey: e.expectedAudienceXOnlyPubkey,
1096
1476
  enableGrpcArtifactAuth: t
1097
- }), s;
1477
+ }), i;
1098
1478
  }
1099
1479
  /** Return the cached provider, or `undefined` if none. */
1100
1480
  peek(e) {
@@ -1122,48 +1502,54 @@ class Ze {
1122
1502
  return this.entries.size;
1123
1503
  }
1124
1504
  }
1125
- const pe = new Ze();
1126
- function ft(r) {
1505
+ const Te = new qt();
1506
+ function dr(r) {
1127
1507
  var n;
1128
- const e = de(
1508
+ const e = ke(
1129
1509
  r.baseUrl,
1130
1510
  (n = r.options) == null ? void 0 : n.headers
1131
- ), t = pe.getOrCreate({
1511
+ ), t = Te.getOrCreate({
1132
1512
  client: e,
1133
1513
  peginTxid: r.peginTxid,
1134
1514
  authAnchorHex: r.authAnchorHex,
1135
1515
  pinnedServerPubkey: r.pinnedServerPubkey,
1516
+ expectedAudienceXOnlyPubkey: me(
1517
+ r.depositorBtcPubkey
1518
+ ),
1136
1519
  enableGrpcArtifactAuth: r.enableGrpcArtifactAuth
1137
1520
  });
1138
- return new Be(r.baseUrl, {
1521
+ return new tt(r.baseUrl, {
1139
1522
  ...r.options,
1140
1523
  tokenProvider: t
1141
1524
  });
1142
1525
  }
1143
- function _t(r) {
1144
- pe.getOrCreate({
1145
- client: de(r.baseUrl, r.headers),
1526
+ function hr(r) {
1527
+ Te.getOrCreate({
1528
+ client: ke(r.baseUrl, r.headers),
1146
1529
  peginTxid: r.peginTxid,
1147
1530
  authAnchorHex: r.authAnchorHex,
1148
1531
  pinnedServerPubkey: r.pinnedServerPubkey,
1532
+ expectedAudienceXOnlyPubkey: me(
1533
+ r.depositorBtcPubkey
1534
+ ),
1149
1535
  enableGrpcArtifactAuth: r.enableGrpcArtifactAuth
1150
1536
  });
1151
1537
  }
1152
1538
  export {
1153
- xe as O,
1154
- g as S,
1155
- Be as V,
1539
+ Me as O,
1540
+ y as S,
1541
+ tt as V,
1156
1542
  a,
1157
- gt as b,
1158
- Je as c,
1159
- Ze as d,
1160
- pe as e,
1161
- ft as f,
1162
- dt as g,
1163
- ht as h,
1164
- pt as i,
1165
- _t as p,
1166
- ut as r,
1167
- Ve as v
1543
+ ur as b,
1544
+ dt as c,
1545
+ qt as d,
1546
+ Te as e,
1547
+ dr as f,
1548
+ ar as g,
1549
+ lr as h,
1550
+ cr as i,
1551
+ hr as p,
1552
+ or as r,
1553
+ Je as v
1168
1554
  };
1169
- //# sourceMappingURL=primeVpAuth-Dzxxy0-F.js.map
1555
+ //# sourceMappingURL=primeVpAuth-BdrwraAe.js.map