@babylonlabs-io/ts-sdk 0.31.0 → 0.33.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 (120) hide show
  1. package/dist/{PeginManager-c44Uvd1N.js → PeginManager-BMrWtTji.js} +137 -125
  2. package/dist/PeginManager-BMrWtTji.js.map +1 -0
  3. package/dist/PeginManager-DUMF84XK.cjs +2 -0
  4. package/dist/PeginManager-DUMF84XK.cjs.map +1 -0
  5. package/dist/{bitcoin-B-Y0DlqR.js → bitcoin-0_T6KJON.js} +32 -28
  6. package/dist/bitcoin-0_T6KJON.js.map +1 -0
  7. package/dist/bitcoin-EYBKDtEW.cjs +2 -0
  8. package/dist/bitcoin-EYBKDtEW.cjs.map +1 -0
  9. package/dist/{buildAndBroadcastRefund-CLLaz8D3.cjs → buildAndBroadcastRefund-6pR681fI.cjs} +2 -2
  10. package/dist/buildAndBroadcastRefund-6pR681fI.cjs.map +1 -0
  11. package/dist/{buildAndBroadcastRefund-BRQaCQrJ.js → buildAndBroadcastRefund-Ba56IKL7.js} +40 -40
  12. package/dist/buildAndBroadcastRefund-Ba56IKL7.js.map +1 -0
  13. package/dist/challengeAssert-DSlCIBoT.js +304 -0
  14. package/dist/challengeAssert-DSlCIBoT.js.map +1 -0
  15. package/dist/challengeAssert-DuhkzZG-.cjs +2 -0
  16. package/dist/challengeAssert-DuhkzZG-.cjs.map +1 -0
  17. package/dist/index.cjs +1 -1
  18. package/dist/index.js +75 -71
  19. package/dist/{noPayout-CwgYkZYs.cjs → noPayout-CDhbGn_B.cjs} +2 -2
  20. package/dist/{noPayout-CwgYkZYs.cjs.map → noPayout-CDhbGn_B.cjs.map} +1 -1
  21. package/dist/{noPayout-B8JiTaYt.js → noPayout-DohtepqZ.js} +2 -2
  22. package/dist/{noPayout-B8JiTaYt.js.map → noPayout-DohtepqZ.js.map} +1 -1
  23. package/dist/{psbtInputFields-CB8hqjQ5.cjs → psbtInputFields-BLi7Ta-T.cjs} +2 -2
  24. package/dist/{psbtInputFields-CB8hqjQ5.cjs.map → psbtInputFields-BLi7Ta-T.cjs.map} +1 -1
  25. package/dist/{psbtInputFields-DeTFSJOq.js → psbtInputFields-DPCFHgGd.js} +2 -2
  26. package/dist/{psbtInputFields-DeTFSJOq.js.map → psbtInputFields-DPCFHgGd.js.map} +1 -1
  27. package/dist/tbv/core/clients/eth/index.d.ts +1 -1
  28. package/dist/tbv/core/clients/eth/index.d.ts.map +1 -1
  29. package/dist/tbv/core/clients/eth/types.d.ts +13 -0
  30. package/dist/tbv/core/clients/eth/types.d.ts.map +1 -1
  31. package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts +8 -1
  32. package/dist/tbv/core/clients/eth/vault-registry-reader.d.ts.map +1 -1
  33. package/dist/tbv/core/clients/index.cjs +1 -1
  34. package/dist/tbv/core/clients/index.js +30 -27
  35. package/dist/tbv/core/clients/vault-provider/api.d.ts +13 -2
  36. package/dist/tbv/core/clients/vault-provider/api.d.ts.map +1 -1
  37. package/dist/tbv/core/clients/vault-provider/auth/__tests__/createAuthenticatedVpClient.test.d.ts +11 -0
  38. package/dist/tbv/core/clients/vault-provider/auth/__tests__/createAuthenticatedVpClient.test.d.ts.map +1 -0
  39. package/dist/tbv/core/clients/vault-provider/auth/__tests__/tokenRegistry.test.d.ts +2 -0
  40. package/dist/tbv/core/clients/vault-provider/auth/__tests__/tokenRegistry.test.d.ts.map +1 -0
  41. package/dist/tbv/core/clients/vault-provider/auth/createAuthenticatedVpClient.d.ts +16 -0
  42. package/dist/tbv/core/clients/vault-provider/auth/createAuthenticatedVpClient.d.ts.map +1 -0
  43. package/dist/tbv/core/clients/vault-provider/auth/gatedMethods.d.ts +10 -0
  44. package/dist/tbv/core/clients/vault-provider/auth/gatedMethods.d.ts.map +1 -0
  45. package/dist/tbv/core/clients/vault-provider/auth/index.d.ts +5 -2
  46. package/dist/tbv/core/clients/vault-provider/auth/index.d.ts.map +1 -1
  47. package/dist/tbv/core/clients/vault-provider/auth/innerTokenClient.d.ts +4 -0
  48. package/dist/tbv/core/clients/vault-provider/auth/innerTokenClient.d.ts.map +1 -0
  49. package/dist/tbv/core/clients/vault-provider/auth/primeVpAuth.d.ts +11 -0
  50. package/dist/tbv/core/clients/vault-provider/auth/primeVpAuth.d.ts.map +1 -0
  51. package/dist/tbv/core/clients/vault-provider/auth/tokenProvider.d.ts +18 -23
  52. package/dist/tbv/core/clients/vault-provider/auth/tokenProvider.d.ts.map +1 -1
  53. package/dist/tbv/core/clients/vault-provider/auth/tokenRegistry.d.ts +48 -0
  54. package/dist/tbv/core/clients/vault-provider/auth/tokenRegistry.d.ts.map +1 -0
  55. package/dist/tbv/core/clients/vault-provider/json-rpc-client.d.ts +8 -12
  56. package/dist/tbv/core/clients/vault-provider/json-rpc-client.d.ts.map +1 -1
  57. package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts +14 -0
  58. package/dist/tbv/core/contracts/abis/BTCVaultRegistry.abi.d.ts.map +1 -1
  59. package/dist/tbv/core/index.cjs +1 -1
  60. package/dist/tbv/core/index.js +66 -62
  61. package/dist/tbv/core/managers/index.d.ts +1 -1
  62. package/dist/tbv/core/primitives/index.cjs +1 -1
  63. package/dist/tbv/core/primitives/index.js +3 -3
  64. package/dist/tbv/core/primitives/psbt/challengeAssert.d.ts +10 -7
  65. package/dist/tbv/core/primitives/psbt/challengeAssert.d.ts.map +1 -1
  66. package/dist/tbv/core/primitives/psbt/constants.d.ts +26 -0
  67. package/dist/tbv/core/primitives/psbt/constants.d.ts.map +1 -0
  68. package/dist/tbv/core/primitives/psbt/depositorPayout.d.ts +13 -6
  69. package/dist/tbv/core/primitives/psbt/depositorPayout.d.ts.map +1 -1
  70. package/dist/tbv/core/primitives/utils/bitcoin.d.ts +13 -0
  71. package/dist/tbv/core/primitives/utils/bitcoin.d.ts.map +1 -1
  72. package/dist/tbv/core/services/deposit/__tests__/runDepositorPresignFlow.test.d.ts +2 -0
  73. package/dist/tbv/core/services/deposit/__tests__/runDepositorPresignFlow.test.d.ts.map +1 -0
  74. package/dist/tbv/core/services/deposit/index.d.ts +2 -2
  75. package/dist/tbv/core/services/deposit/index.d.ts.map +1 -1
  76. package/dist/tbv/core/services/deposit/{signAndSubmitPayouts.d.ts → runDepositorPresignFlow.d.ts} +3 -3
  77. package/dist/tbv/core/services/deposit/runDepositorPresignFlow.d.ts.map +1 -0
  78. package/dist/tbv/core/services/index.cjs +1 -1
  79. package/dist/tbv/core/services/index.js +11 -11
  80. package/dist/tbv/core/utils/index.cjs +1 -1
  81. package/dist/tbv/core/utils/index.js +2 -2
  82. package/dist/tbv/core/vault-secrets/__tests__/parseFundingOutpoints.test.d.ts +2 -0
  83. package/dist/tbv/core/vault-secrets/__tests__/parseFundingOutpoints.test.d.ts.map +1 -0
  84. package/dist/tbv/core/vault-secrets/index.d.ts +1 -0
  85. package/dist/tbv/core/vault-secrets/index.d.ts.map +1 -1
  86. package/dist/tbv/core/vault-secrets/parseFundingOutpoints.d.ts +3 -0
  87. package/dist/tbv/core/vault-secrets/parseFundingOutpoints.d.ts.map +1 -0
  88. package/dist/tbv/index.cjs +1 -1
  89. package/dist/tbv/index.js +66 -62
  90. package/dist/testing/index.cjs +1 -1
  91. package/dist/testing/index.js +1 -1
  92. package/dist/{types-jmEyzzhY.cjs → types-C2IUB0Jd.cjs} +2 -2
  93. package/dist/types-C2IUB0Jd.cjs.map +1 -0
  94. package/dist/{types-CnG3JsRs.js → types-D1o_3Q__.js} +20 -9
  95. package/dist/types-D1o_3Q__.js.map +1 -0
  96. package/dist/{vault-registry-reader-BywZhqJL.js → vault-registry-reader-BeIEh62N.js} +436 -292
  97. package/dist/vault-registry-reader-BeIEh62N.js.map +1 -0
  98. package/dist/vault-registry-reader-DdUgC5IF.cjs +2 -0
  99. package/dist/vault-registry-reader-DdUgC5IF.cjs.map +1 -0
  100. package/package.json +1 -1
  101. package/dist/PeginManager-DmVq6ffv.cjs +0 -2
  102. package/dist/PeginManager-DmVq6ffv.cjs.map +0 -1
  103. package/dist/PeginManager-c44Uvd1N.js.map +0 -1
  104. package/dist/bitcoin-B-Y0DlqR.js.map +0 -1
  105. package/dist/bitcoin-DIN0OupO.cjs +0 -2
  106. package/dist/bitcoin-DIN0OupO.cjs.map +0 -1
  107. package/dist/buildAndBroadcastRefund-BRQaCQrJ.js.map +0 -1
  108. package/dist/buildAndBroadcastRefund-CLLaz8D3.cjs.map +0 -1
  109. package/dist/challengeAssert-mYikGC34.js +0 -269
  110. package/dist/challengeAssert-mYikGC34.js.map +0 -1
  111. package/dist/challengeAssert-yYFflBOx.cjs +0 -2
  112. package/dist/challengeAssert-yYFflBOx.cjs.map +0 -1
  113. package/dist/tbv/core/services/deposit/__tests__/signAndSubmitPayouts.test.d.ts +0 -2
  114. package/dist/tbv/core/services/deposit/__tests__/signAndSubmitPayouts.test.d.ts.map +0 -1
  115. package/dist/tbv/core/services/deposit/signAndSubmitPayouts.d.ts.map +0 -1
  116. package/dist/types-CnG3JsRs.js.map +0 -1
  117. package/dist/types-jmEyzzhY.cjs.map +0 -1
  118. package/dist/vault-registry-reader-BywZhqJL.js.map +0 -1
  119. package/dist/vault-registry-reader-DdruADqa.cjs +0 -2
  120. package/dist/vault-registry-reader-DdruADqa.cjs.map +0 -1
@@ -1,74 +1,74 @@
1
- var ae = Object.defineProperty;
2
- var se = (n, e, t) => e in n ? ae(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var l = (n, e, t) => se(n, typeof e != "symbol" ? e + "" : e, t);
4
- import { B as ie, H as y, K as oe, T as ce } from "./validation-CxqROCno.js";
5
- import { D as le, J as ue, B as P } from "./types-CnG3JsRs.js";
6
- import { X as v, C as F, s as _, S as pe } from "./bitcoin-B-Y0DlqR.js";
7
- import * as N from "@bitcoin-js/tiny-secp256k1-asmjs";
8
- import { payments as de, Transaction as k } from "bitcoinjs-lib";
9
- import { Buffer as f } from "buffer";
1
+ var oe = Object.defineProperty;
2
+ var ce = (n, e, t) => e in n ? oe(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var l = (n, e, t) => ce(n, typeof e != "symbol" ? e + "" : e, t);
4
+ import { B as le, H as f, K as ue, T as pe } from "./validation-CxqROCno.js";
5
+ import { D as de, J as G, B as b } from "./types-D1o_3Q__.js";
6
+ import { X as v, C as O, s as _, S as he, h as me } from "./bitcoin-0_T6KJON.js";
7
+ import * as $ from "@bitcoin-js/tiny-secp256k1-asmjs";
8
+ import { payments as ye, Transaction as I } from "bitcoinjs-lib";
9
+ import { Buffer as y } from "buffer";
10
10
  import { s as K } from "./sha2-6wN58S6R.js";
11
- const me = 21e6 * 1e8, U = 3e4;
12
- async function $(n, e) {
11
+ const fe = 21e6 * 1e8, U = 3e4;
12
+ async function k(n, e) {
13
13
  const t = new AbortController(), r = setTimeout(
14
14
  () => t.abort(),
15
15
  U
16
- ), s = [t.signal, e == null ? void 0 : e.signal].filter(
16
+ ), i = [t.signal, e == null ? void 0 : e.signal].filter(
17
17
  Boolean
18
18
  );
19
19
  try {
20
20
  return await fetch(n, {
21
21
  ...e,
22
- signal: AbortSignal.any(s)
22
+ signal: AbortSignal.any(i)
23
23
  });
24
- } catch (a) {
25
- throw clearTimeout(r), a != null && typeof a == "object" && "name" in a && a.name === "AbortError" ? new Error(
24
+ } catch (s) {
25
+ throw clearTimeout(r), s != null && typeof s == "object" && "name" in s && s.name === "AbortError" ? new Error(
26
26
  `Mempool API request timed out after ${U}ms: ${n}`
27
- ) : a;
27
+ ) : s;
28
28
  }
29
29
  }
30
- const G = 1e4;
31
- function W(n) {
32
- return Number.isInteger(n) && n > 0 && n <= me;
30
+ const W = 1e4;
31
+ function J(n) {
32
+ return Number.isInteger(n) && n > 0 && n <= fe;
33
33
  }
34
- function he(n) {
35
- return Number.isInteger(n) && n > 0 && n <= G;
34
+ function ge(n) {
35
+ return Number.isInteger(n) && n > 0 && n <= W;
36
36
  }
37
- function J(n, e) {
37
+ function z(n, e) {
38
38
  return !Number.isInteger(n) || n < 0 ? !1 : e === void 0 || n < e;
39
39
  }
40
- function E(n) {
41
- if (!ce.test(n))
40
+ function C(n) {
41
+ if (!pe.test(n))
42
42
  throw new Error(`Invalid transaction ID format: ${n}`);
43
43
  }
44
- function z(n) {
45
- if (!ie.test(n))
44
+ function Y(n) {
45
+ if (!le.test(n))
46
46
  throw new Error(`Invalid Bitcoin address format: ${n}`);
47
47
  }
48
- function Y(n, e) {
49
- if (!y.test(n))
48
+ function Q(n, e) {
49
+ if (!f.test(n))
50
50
  throw new Error(
51
51
  `Invalid scriptPubKey: not valid hex for ${e}`
52
52
  );
53
- if (!oe.some(
53
+ if (!ue.some(
54
54
  (r) => n.toLowerCase().startsWith(r)
55
55
  ))
56
56
  throw new Error(
57
57
  `Unrecognized scriptPubKey type for ${e}: prefix ${n.slice(0, 6)} does not match any known Bitcoin script type`
58
58
  );
59
59
  }
60
- const fe = {
60
+ const be = {
61
61
  mainnet: "https://mempool.space/api",
62
62
  testnet: "https://mempool.space/testnet/api",
63
63
  signet: "https://mempool.space/signet/api"
64
64
  };
65
65
  async function T(n, e) {
66
66
  try {
67
- const t = await $(n, e);
67
+ const t = await k(n, e);
68
68
  if (!t.ok) {
69
- const s = await t.text();
69
+ const i = await t.text();
70
70
  throw new Error(
71
- `Mempool API error (${t.status}): ${s || t.statusText}`
71
+ `Mempool API error (${t.status}): ${i || t.statusText}`
72
72
  );
73
73
  }
74
74
  const r = t.headers.get("content-type");
@@ -77,9 +77,9 @@ async function T(n, e) {
77
77
  throw t instanceof Error ? new Error(`Failed to fetch from mempool API: ${t.message}`) : new Error("Failed to fetch from mempool API: Unknown error");
78
78
  }
79
79
  }
80
- async function Xe(n, e) {
80
+ async function Ze(n, e) {
81
81
  try {
82
- const t = await $(`${e}/tx`, {
82
+ const t = await k(`${e}/tx`, {
83
83
  method: "POST",
84
84
  body: n,
85
85
  headers: {
@@ -87,15 +87,15 @@ async function Xe(n, e) {
87
87
  }
88
88
  });
89
89
  if (!t.ok) {
90
- const s = await t.text();
91
- let a;
90
+ const i = await t.text();
91
+ let s;
92
92
  try {
93
- a = JSON.parse(s).message;
93
+ s = JSON.parse(i).message;
94
94
  } catch {
95
- a = s;
95
+ s = i;
96
96
  }
97
97
  throw new Error(
98
- a || `Failed to broadcast transaction: ${t.statusText}`
98
+ s || `Failed to broadcast transaction: ${t.statusText}`
99
99
  );
100
100
  }
101
101
  return await t.text();
@@ -103,13 +103,13 @@ async function Xe(n, e) {
103
103
  throw t instanceof Error ? new Error(`Failed to broadcast BTC transaction: ${t.message}`) : new Error("Failed to broadcast BTC transaction: Unknown error");
104
104
  }
105
105
  }
106
- async function ye(n, e) {
107
- return E(n), T(`${e}/tx/${n}`);
106
+ async function we(n, e) {
107
+ return C(n), T(`${e}/tx/${n}`);
108
108
  }
109
- async function qe(n, e) {
110
- E(n);
109
+ async function et(n, e) {
110
+ C(n);
111
111
  try {
112
- const t = await $(`${e}/tx/${n}/hex`);
112
+ const t = await k(`${e}/tx/${n}/hex`);
113
113
  if (!t.ok) {
114
114
  const r = await t.text();
115
115
  throw new Error(
@@ -121,46 +121,46 @@ async function qe(n, e) {
121
121
  throw t instanceof Error ? new Error(`Failed to get transaction hex for ${n}: ${t.message}`) : new Error(`Failed to get transaction hex for ${n}: Unknown error`);
122
122
  }
123
123
  }
124
- async function Ge(n, e, t) {
125
- E(n);
126
- const r = await ye(n, t);
127
- if (!J(e, r.vout.length))
124
+ async function tt(n, e, t) {
125
+ C(n);
126
+ const r = await we(n, t);
127
+ if (!z(e, r.vout.length))
128
128
  throw new Error(
129
129
  `Invalid vout ${e} for transaction ${n} (has ${r.vout.length} outputs)`
130
130
  );
131
- const s = r.vout[e];
132
- if (!W(s.value))
133
- throw new Error(`Invalid UTXO value ${s.value} for ${n}:${e}`);
134
- return Y(s.scriptpubkey, `${n}:${e}`), {
131
+ const i = r.vout[e];
132
+ if (!J(i.value))
133
+ throw new Error(`Invalid UTXO value ${i.value} for ${n}:${e}`);
134
+ return Q(i.scriptpubkey, `${n}:${e}`), {
135
135
  txid: n,
136
136
  vout: e,
137
- value: s.value,
138
- scriptPubKey: s.scriptpubkey
137
+ value: i.value,
138
+ scriptPubKey: i.scriptpubkey
139
139
  };
140
140
  }
141
- async function We(n, e) {
142
- z(n);
141
+ async function nt(n, e) {
142
+ Y(n);
143
143
  try {
144
144
  const t = await T(`${e}/address/${n}/utxo`), r = await T(`${e}/v1/validate-address/${n}`);
145
145
  if (!r.isvalid)
146
146
  throw new Error(
147
147
  `Invalid Bitcoin address: ${n}. Mempool API validation failed.`
148
148
  );
149
- Y(r.scriptPubKey, n);
150
- for (const a of t) {
151
- if (E(a.txid), !J(a.vout))
152
- throw new Error(`Invalid vout ${a.vout} for ${a.txid}`);
153
- if (!W(a.value))
149
+ Q(r.scriptPubKey, n);
150
+ for (const s of t) {
151
+ if (C(s.txid), !z(s.vout))
152
+ throw new Error(`Invalid vout ${s.vout} for ${s.txid}`);
153
+ if (!J(s.value))
154
154
  throw new Error(
155
- `Invalid UTXO value ${a.value} for ${a.txid}:${a.vout}`
155
+ `Invalid UTXO value ${s.value} for ${s.txid}:${s.vout}`
156
156
  );
157
157
  }
158
- return t.sort((a, c) => c.value - a.value).map((a) => ({
159
- txid: a.txid,
160
- vout: a.vout,
161
- value: a.value,
158
+ return t.sort((s, c) => c.value - s.value).map((s) => ({
159
+ txid: s.txid,
160
+ vout: s.vout,
161
+ value: s.value,
162
162
  scriptPubKey: r.scriptPubKey,
163
- confirmed: a.status.confirmed
163
+ confirmed: s.status.confirmed
164
164
  }));
165
165
  } catch (t) {
166
166
  throw t instanceof Error ? new Error(
@@ -170,14 +170,14 @@ async function We(n, e) {
170
170
  );
171
171
  }
172
172
  }
173
- function Je(n) {
174
- return fe[n];
173
+ function rt(n) {
174
+ return be[n];
175
175
  }
176
- async function ze(n, e) {
177
- return z(n), T(`${e}/address/${n}/txs`);
176
+ async function st(n, e) {
177
+ return Y(n), T(`${e}/address/${n}/txs`);
178
178
  }
179
- async function Ye(n) {
180
- const e = await $(`${n}/v1/fees/recommended`);
179
+ async function it(n) {
180
+ const e = await k(`${n}/v1/fees/recommended`);
181
181
  if (!e.ok)
182
182
  throw new Error(
183
183
  `Failed to fetch network fees: ${e.status} ${e.statusText}`
@@ -189,10 +189,10 @@ async function Ye(n) {
189
189
  "economyFee",
190
190
  "minimumFee"
191
191
  ];
192
- for (const s of r)
193
- if (!he(t[s]))
192
+ for (const i of r)
193
+ if (!ge(t[i]))
194
194
  throw new Error(
195
- `Invalid fee rate ${s}=${t[s]} from mempool API: expected a positive number ≤ ${G}`
195
+ `Invalid fee rate ${i}=${t[i]} from mempool API: expected a positive number ≤ ${W}`
196
196
  );
197
197
  if (t.minimumFee > t.economyFee || t.economyFee > t.hourFee || t.hourFee > t.halfHourFee || t.halfHourFee > t.fastestFee)
198
198
  throw new Error(
@@ -200,7 +200,7 @@ async function Ye(n) {
200
200
  );
201
201
  return t;
202
202
  }
203
- const S = [
203
+ const B = [
204
204
  {
205
205
  type: "function",
206
206
  name: "getVaultKeepersByVersion",
@@ -287,7 +287,7 @@ const S = [
287
287
  ],
288
288
  stateMutability: "view"
289
289
  }
290
- ], m = [
290
+ ], h = [
291
291
  {
292
292
  type: "function",
293
293
  name: "getTBVProtocolParams",
@@ -576,260 +576,260 @@ const S = [
576
576
  ],
577
577
  stateMutability: "view"
578
578
  }
579
- ], j = new Set(Object.values(le)), ge = 200;
579
+ ], D = new Set(Object.values(de)), _e = 200;
580
580
  function o(n) {
581
581
  var e;
582
- return ((e = JSON.stringify(n)) == null ? void 0 : e.slice(0, ge)) ?? "undefined";
582
+ return ((e = JSON.stringify(n)) == null ? void 0 : e.slice(0, _e)) ?? "undefined";
583
583
  }
584
- const be = "The vault provider returned an unexpected response. Please try again or contact support.";
585
- class i extends Error {
584
+ const Pe = "The vault provider returned an unexpected response. Please try again or contact support.";
585
+ class a extends Error {
586
586
  constructor(t) {
587
- super(be);
587
+ super(Pe);
588
588
  l(this, "detail");
589
589
  this.name = "VpResponseValidationError", this.detail = t;
590
590
  }
591
591
  }
592
592
  const x = 64;
593
593
  function g(n) {
594
- return typeof n == "string" && n.length > 0 && y.test(n);
594
+ return typeof n == "string" && n.length > 0 && f.test(n);
595
595
  }
596
- function Q(n) {
596
+ function Z(n) {
597
597
  return typeof n == "string" && n.length > 0;
598
598
  }
599
- function Z(n, e) {
599
+ function ee(n, e) {
600
600
  if (!g(n))
601
- throw new i(
601
+ throw new a(
602
602
  `VP response validation failed: "${e}" must be a non-empty hex string, got ${o(n)}`
603
603
  );
604
604
  }
605
- function b(n, e) {
606
- if (!Q(n))
607
- throw new i(
605
+ function w(n, e) {
606
+ if (!Z(n))
607
+ throw new a(
608
608
  `VP response validation failed: "${e}" must be a non-empty string, got ${o(n)}`
609
609
  );
610
610
  }
611
- function ee(n, e) {
612
- if (!g(n) || n.length !== v && n.length !== F)
613
- throw new i(
614
- `VP response validation failed: "${e}" must be a ${v} or ${F}-char hex string (BTC pubkey), got ${o(n)}`
611
+ function te(n, e) {
612
+ if (!g(n) || n.length !== v && n.length !== O)
613
+ throw new a(
614
+ `VP response validation failed: "${e}" must be a ${v} or ${O}-char hex string (BTC pubkey), got ${o(n)}`
615
615
  );
616
616
  }
617
- function _e(n) {
617
+ function ve(n) {
618
618
  const e = n.presigning;
619
619
  if (e == null) return;
620
620
  if (typeof e != "object" || Array.isArray(e))
621
- throw new i(
621
+ throw new a(
622
622
  'VP response validation failed: "progress.presigning" must be an object if present'
623
623
  );
624
624
  const t = e;
625
625
  if (t.depositor_graph_created !== void 0 && typeof t.depositor_graph_created != "boolean")
626
- throw new i(
626
+ throw new a(
627
627
  `VP response validation failed: "progress.presigning.depositor_graph_created" must be a boolean if present, got ${o(t.depositor_graph_created)}`
628
628
  );
629
629
  if (t.vk_challenger_presigning_completed !== void 0 && typeof t.vk_challenger_presigning_completed != "number")
630
- throw new i(
630
+ throw new a(
631
631
  `VP response validation failed: "progress.presigning.vk_challenger_presigning_completed" must be a number if present, got ${o(t.vk_challenger_presigning_completed)}`
632
632
  );
633
633
  if (t.vk_challenger_presigning_total !== void 0 && typeof t.vk_challenger_presigning_total != "number")
634
- throw new i(
634
+ throw new a(
635
635
  `VP response validation failed: "progress.presigning.vk_challenger_presigning_total" must be a number if present, got ${o(t.vk_challenger_presigning_total)}`
636
636
  );
637
637
  }
638
- function we(n) {
638
+ function Te(n) {
639
639
  if (n === null || typeof n != "object")
640
- throw new i(
640
+ throw new a(
641
641
  "VP response validation failed: getPeginStatus response is not an object"
642
642
  );
643
643
  const e = n;
644
644
  if (!g(e.pegin_txid) || e.pegin_txid.length !== x)
645
- throw new i(
645
+ throw new a(
646
646
  `VP response validation failed: "pegin_txid" must be a ${x}-char hex string (txid), got ${o(e.pegin_txid)}`
647
647
  );
648
648
  if (typeof e.status != "string")
649
- throw new i(
649
+ throw new a(
650
650
  'VP response validation failed: "status" must be a string'
651
651
  );
652
- if (!j.has(e.status))
653
- throw new i(
654
- `VP response validation failed: unrecognized status "${e.status}". Expected one of: ${[...j].join(", ")}`
652
+ if (!D.has(e.status))
653
+ throw new a(
654
+ `VP response validation failed: unrecognized status "${e.status}". Expected one of: ${[...D].join(", ")}`
655
655
  );
656
656
  if (e.progress === null || typeof e.progress != "object" || Array.isArray(e.progress))
657
- throw new i(
657
+ throw new a(
658
658
  'VP response validation failed: "progress" must be an object'
659
659
  );
660
- if (_e(e.progress), typeof e.health_info != "string")
661
- throw new i(
660
+ if (ve(e.progress), typeof e.health_info != "string")
661
+ throw new a(
662
662
  'VP response validation failed: "health_info" must be a string'
663
663
  );
664
664
  if (e.last_error !== void 0 && typeof e.last_error != "string")
665
- throw new i(
665
+ throw new a(
666
666
  `VP response validation failed: "last_error" must be a string if present, got ${o(e.last_error)}`
667
667
  );
668
668
  }
669
- function Pe(n) {
669
+ function xe(n) {
670
670
  if (n === null || typeof n != "object")
671
- throw new i(
671
+ throw new a(
672
672
  "VP response validation failed: requestDepositorPresignTransactions response is not an object"
673
673
  );
674
674
  const e = n;
675
675
  if (!Array.isArray(e.txs))
676
- throw new i(
676
+ throw new a(
677
677
  'VP response validation failed: "txs" must be an array'
678
678
  );
679
679
  for (let t = 0; t < e.txs.length; t++)
680
- ve(e.txs[t], `txs[${t}]`);
680
+ Ae(e.txs[t], `txs[${t}]`);
681
681
  if (e.depositor_graph === null || typeof e.depositor_graph != "object")
682
- throw new i(
682
+ throw new a(
683
683
  'VP response validation failed: "depositor_graph" must be an object'
684
684
  );
685
- $e(
685
+ Se(
686
686
  e.depositor_graph
687
687
  );
688
688
  }
689
- function h(n, e) {
689
+ function m(n, e) {
690
690
  if (n === null || typeof n != "object")
691
- throw new i(
691
+ throw new a(
692
692
  `VP response validation failed: "${e}" must be an object`
693
693
  );
694
- Z(n.tx_hex, `${e}.tx_hex`);
694
+ ee(n.tx_hex, `${e}.tx_hex`);
695
695
  }
696
- function ve(n, e) {
696
+ function Ae(n, e) {
697
697
  if (n === null || typeof n != "object")
698
- throw new i(
698
+ throw new a(
699
699
  `VP response validation failed: "${e}" must be an object`
700
700
  );
701
701
  const t = n;
702
- ee(t.claimer_pubkey, `${e}.claimer_pubkey`), h(t.claim_tx, `${e}.claim_tx`), h(t.assert_tx, `${e}.assert_tx`), h(t.payout_tx, `${e}.payout_tx`), b(t.payout_psbt, `${e}.payout_psbt`);
702
+ te(t.claimer_pubkey, `${e}.claimer_pubkey`), m(t.claim_tx, `${e}.claim_tx`), m(t.assert_tx, `${e}.assert_tx`), m(t.payout_tx, `${e}.payout_tx`), w(t.payout_psbt, `${e}.payout_psbt`);
703
703
  }
704
- function Te(n, e) {
704
+ function Ve(n, e) {
705
705
  if (n === null || typeof n != "object")
706
- throw new i(
706
+ throw new a(
707
707
  `VP response validation failed: "${e}" must be an object`
708
708
  );
709
709
  const t = n;
710
- b(t.wots_pks_json, `${e}.wots_pks_json`), b(t.gc_wots_keys_json, `${e}.gc_wots_keys_json`);
710
+ w(t.wots_pks_json, `${e}.wots_pks_json`), w(t.gc_wots_keys_json, `${e}.gc_wots_keys_json`);
711
711
  }
712
- function xe(n, e) {
712
+ function $e(n, e) {
713
713
  if (n === null || typeof n != "object")
714
- throw new i(
714
+ throw new a(
715
715
  `VP response validation failed: "${e}" must be an object`
716
716
  );
717
717
  const t = n;
718
- if (ee(t.challenger_pubkey, `${e}.challenger_pubkey`), h(
718
+ if (te(t.challenger_pubkey, `${e}.challenger_pubkey`), m(
719
719
  t.challenge_assert_x_tx,
720
720
  `${e}.challenge_assert_x_tx`
721
- ), h(
721
+ ), m(
722
722
  t.challenge_assert_y_tx,
723
723
  `${e}.challenge_assert_y_tx`
724
- ), h(t.nopayout_tx, `${e}.nopayout_tx`), b(t.nopayout_psbt, `${e}.nopayout_psbt`), !Array.isArray(t.challenge_assert_connectors))
725
- throw new i(
724
+ ), m(t.nopayout_tx, `${e}.nopayout_tx`), w(t.nopayout_psbt, `${e}.nopayout_psbt`), !Array.isArray(t.challenge_assert_connectors))
725
+ throw new a(
726
726
  `VP response validation failed: "${e}.challenge_assert_connectors" must be an array`
727
727
  );
728
728
  for (let r = 0; r < t.challenge_assert_connectors.length; r++)
729
- Te(
729
+ Ve(
730
730
  t.challenge_assert_connectors[r],
731
731
  `${e}.challenge_assert_connectors[${r}]`
732
732
  );
733
733
  if (!Array.isArray(t.output_label_hashes))
734
- throw new i(
734
+ throw new a(
735
735
  `VP response validation failed: "${e}.output_label_hashes" must be an array`
736
736
  );
737
737
  for (let r = 0; r < t.output_label_hashes.length; r++)
738
- Z(
738
+ ee(
739
739
  t.output_label_hashes[r],
740
740
  `${e}.output_label_hashes[${r}]`
741
741
  );
742
742
  }
743
- function Ae(n) {
743
+ function ke(n) {
744
744
  if (n === null || typeof n != "object")
745
- throw new i(
745
+ throw new a(
746
746
  "VP response validation failed: requestDepositorClaimerArtifacts response is not an object"
747
747
  );
748
748
  const e = n;
749
- if (!Q(e.tx_graph_json))
750
- throw new i(
749
+ if (!Z(e.tx_graph_json))
750
+ throw new a(
751
751
  `VP response validation failed: "tx_graph_json" must be a non-empty string, got ${o(e.tx_graph_json)}`
752
752
  );
753
753
  if (!g(e.verifying_key_hex))
754
- throw new i(
754
+ throw new a(
755
755
  `VP response validation failed: "verifying_key_hex" must be a non-empty hex string, got ${o(e.verifying_key_hex)}`
756
756
  );
757
757
  if (e.babe_sessions === null || typeof e.babe_sessions != "object")
758
- throw new i(
758
+ throw new a(
759
759
  'VP response validation failed: "babe_sessions" must be an object'
760
760
  );
761
761
  for (const [t, r] of Object.entries(
762
762
  e.babe_sessions
763
763
  )) {
764
764
  if (r === null || typeof r != "object")
765
- throw new i(
765
+ throw new a(
766
766
  `VP response validation failed: "babe_sessions.${t}" must be an object`
767
767
  );
768
- const s = r;
769
- if (!g(s.decryptor_artifacts_hex))
770
- throw new i(
771
- `VP response validation failed: "babe_sessions.${t}.decryptor_artifacts_hex" must be a non-empty hex string, got ${o(s.decryptor_artifacts_hex)}`
768
+ const i = r;
769
+ if (!g(i.decryptor_artifacts_hex))
770
+ throw new a(
771
+ `VP response validation failed: "babe_sessions.${t}.decryptor_artifacts_hex" must be a non-empty hex string, got ${o(i.decryptor_artifacts_hex)}`
772
772
  );
773
773
  }
774
774
  }
775
- function Ve(n) {
775
+ function Ce(n) {
776
776
  if (n === null || typeof n != "object")
777
- throw new i(
777
+ throw new a(
778
778
  "VP response validation failed: getPegoutStatus response is not an object"
779
779
  );
780
780
  const e = n;
781
781
  if (!g(e.pegin_txid) || e.pegin_txid.length !== x)
782
- throw new i(
782
+ throw new a(
783
783
  `VP response validation failed: "pegin_txid" must be a ${x}-char hex string (txid), got ${o(e.pegin_txid)}`
784
784
  );
785
785
  if (typeof e.found != "boolean")
786
- throw new i(
786
+ throw new a(
787
787
  `VP response validation failed: "found" must be a boolean, got ${o(e.found)}`
788
788
  );
789
789
  if (e.claimer !== void 0) {
790
790
  if (e.claimer === null || typeof e.claimer != "object")
791
- throw new i(
791
+ throw new a(
792
792
  'VP response validation failed: "claimer" must be an object if present'
793
793
  );
794
794
  const t = e.claimer;
795
795
  if (typeof t.status != "string")
796
- throw new i(
796
+ throw new a(
797
797
  `VP response validation failed: "claimer.status" must be a string, got ${o(t.status)}`
798
798
  );
799
799
  if (typeof t.failed != "boolean")
800
- throw new i(
800
+ throw new a(
801
801
  `VP response validation failed: "claimer.failed" must be a boolean, got ${o(t.failed)}`
802
802
  );
803
803
  }
804
804
  if (e.challenger !== void 0) {
805
805
  if (e.challenger === null || typeof e.challenger != "object")
806
- throw new i(
806
+ throw new a(
807
807
  'VP response validation failed: "challenger" must be an object if present'
808
808
  );
809
809
  const t = e.challenger;
810
810
  if (typeof t.status != "string")
811
- throw new i(
811
+ throw new a(
812
812
  `VP response validation failed: "challenger.status" must be a string, got ${o(t.status)}`
813
813
  );
814
814
  }
815
815
  }
816
- function $e(n) {
817
- if (h(n.claim_tx, "depositor_graph.claim_tx"), h(n.assert_tx, "depositor_graph.assert_tx"), h(n.payout_tx, "depositor_graph.payout_tx"), b(n.payout_psbt, "depositor_graph.payout_psbt"), !Array.isArray(n.challenger_presign_data))
818
- throw new i(
816
+ function Se(n) {
817
+ if (m(n.claim_tx, "depositor_graph.claim_tx"), m(n.assert_tx, "depositor_graph.assert_tx"), m(n.payout_tx, "depositor_graph.payout_tx"), w(n.payout_psbt, "depositor_graph.payout_psbt"), !Array.isArray(n.challenger_presign_data))
818
+ throw new a(
819
819
  'VP response validation failed: "depositor_graph.challenger_presign_data" must be an array'
820
820
  );
821
821
  for (let e = 0; e < n.challenger_presign_data.length; e++)
822
- xe(
822
+ $e(
823
823
  n.challenger_presign_data[e],
824
824
  `depositor_graph.challenger_presign_data[${e}]`
825
825
  );
826
826
  if (typeof n.offchain_params_version != "number")
827
- throw new i(
827
+ throw new a(
828
828
  'VP response validation failed: "depositor_graph.offchain_params_version" must be a number'
829
829
  );
830
830
  }
831
831
  const Ee = 6e4;
832
- class Qe {
832
+ class Ie {
833
833
  constructor(e, t) {
834
834
  l(this, "client");
835
835
  const r = {
@@ -838,9 +838,10 @@ class Qe {
838
838
  retries: t == null ? void 0 : t.retries,
839
839
  retryDelay: t == null ? void 0 : t.retryDelay,
840
840
  retryableFor: t == null ? void 0 : t.retryableFor,
841
- headers: t == null ? void 0 : t.headers
841
+ headers: t == null ? void 0 : t.headers,
842
+ tokenProvider: t == null ? void 0 : t.tokenProvider
842
843
  };
843
- this.client = new ue(r);
844
+ this.client = new G(r);
844
845
  }
845
846
  /**
846
847
  * Request the payout/claim/assert transactions that the depositor
@@ -848,7 +849,7 @@ class Qe {
848
849
  */
849
850
  async requestDepositorPresignTransactions(e, t) {
850
851
  const r = await this.client.call("vaultProvider_requestDepositorPresignTransactions", e, t);
851
- return Pe(r), r;
852
+ return xe(r), r;
852
853
  }
853
854
  /**
854
855
  * Submit the depositor's pre-signatures for the payout transactions
@@ -879,7 +880,7 @@ class Qe {
879
880
  */
880
881
  async requestDepositorClaimerArtifacts(e, t) {
881
882
  const r = await this.client.call("vaultProvider_requestDepositorClaimerArtifacts", e, t);
882
- return Ae(r), r;
883
+ return ke(r), r;
883
884
  }
884
885
  /** Get the current pegin status from the vault provider daemon. */
885
886
  async getPeginStatus(e, t) {
@@ -888,7 +889,7 @@ class Qe {
888
889
  e,
889
890
  t
890
891
  );
891
- return we(r), r;
892
+ return Te(r), r;
892
893
  }
893
894
  /** Get the current pegout status from the vault provider daemon. */
894
895
  async getPegoutStatus(e, t) {
@@ -897,52 +898,52 @@ class Qe {
897
898
  e,
898
899
  t
899
900
  );
900
- return Ve(r), r;
901
+ return Ce(r), r;
901
902
  }
902
903
  }
903
- const Ce = "BIP0322-signed-message", Ie = "TapTweak", te = 32, ke = 64;
904
- function ne(n, e) {
905
- const t = new TextEncoder().encode(n), r = K(t), s = new Uint8Array(r.length * 2 + e.length);
906
- return s.set(r, 0), s.set(r, r.length), s.set(e, r.length * 2), K(s);
904
+ const Be = "BIP0322-signed-message", Fe = "TapTweak", ne = 32, Oe = 64;
905
+ function re(n, e) {
906
+ const t = new TextEncoder().encode(n), r = K(t), i = new Uint8Array(r.length * 2 + e.length);
907
+ return i.set(r, 0), i.set(r, r.length), i.set(e, r.length * 2), K(i);
907
908
  }
908
- function Se(n) {
909
- if (n.length !== te) return null;
910
- const e = ne(Ie, n), t = N.xOnlyPointAddTweak(n, e);
909
+ function Re(n) {
910
+ if (n.length !== ne) return null;
911
+ const e = re(Fe, n), t = $.xOnlyPointAddTweak(n, e);
911
912
  return t ? t.xOnlyPubkey : null;
912
913
  }
913
- function Be(n, e, t) {
914
- if (e.length !== te || t.length !== ke) return !1;
914
+ function Ne(n, e, t) {
915
+ if (e.length !== ne || t.length !== Oe) return !1;
915
916
  try {
916
- const r = ne(Ce, n), s = de.p2tr({
917
- internalPubkey: f.from(e)
917
+ const r = re(Be, n), i = ye.p2tr({
918
+ internalPubkey: y.from(e)
918
919
  });
919
- if (!s.output) return !1;
920
- const a = s.output, c = 0, d = new k();
920
+ if (!i.output) return !1;
921
+ const s = i.output, c = 0, d = new I();
921
922
  d.version = 0, d.locktime = 0;
922
- const C = f.concat([
923
- f.from([0, 32]),
924
- f.from(r)
923
+ const S = y.concat([
924
+ y.from([0, 32]),
925
+ y.from(r)
925
926
  ]);
926
927
  d.addInput(
927
- f.alloc(32, 0),
928
+ y.alloc(32, 0),
928
929
  // prev_txid = 0x0000...0000
929
930
  4294967295,
930
931
  // prev_vout = 0xFFFFFFFF
931
932
  0,
932
933
  // sequence = 0
933
- C
934
- ), d.addOutput(a, c);
935
- const p = new k();
934
+ S
935
+ ), d.addOutput(s, c);
936
+ const p = new I();
936
937
  p.version = 0, p.locktime = 0;
937
- const I = d.getHash();
938
- p.addInput(I, 0, 0), p.addOutput(f.from([106]), c);
939
- const R = p.hashForWitnessV1(
938
+ const E = d.getHash();
939
+ p.addInput(E, 0, 0), p.addOutput(y.from([106]), c);
940
+ const N = p.hashForWitnessV1(
940
941
  0,
941
- [a],
942
+ [s],
942
943
  [c],
943
- k.SIGHASH_DEFAULT
944
- ), O = Se(e);
945
- return O ? N.verifySchnorr(R, O, t) : !1;
944
+ I.SIGHASH_DEFAULT
945
+ ), H = Re(e);
946
+ return H ? $.verifySchnorr(N, H, t) : !1;
946
947
  } catch {
947
948
  return !1;
948
949
  }
@@ -953,47 +954,47 @@ function A(n, e) {
953
954
  if (r < 24n) return new Uint8Array([t | Number(r)]);
954
955
  if (r < 0x100n) return new Uint8Array([t | 24, Number(r)]);
955
956
  if (r < 0x10000n) {
956
- const a = Number(r);
957
- return new Uint8Array([t | 25, a >>> 8 & 255, a & 255]);
957
+ const s = Number(r);
958
+ return new Uint8Array([t | 25, s >>> 8 & 255, s & 255]);
958
959
  }
959
960
  if (r < 0x100000000n) {
960
- const a = Number(r);
961
+ const s = Number(r);
961
962
  return new Uint8Array([
962
963
  t | 26,
963
- a >>> 24 & 255,
964
- a >>> 16 & 255,
965
- a >>> 8 & 255,
966
- a & 255
964
+ s >>> 24 & 255,
965
+ s >>> 16 & 255,
966
+ s >>> 8 & 255,
967
+ s & 255
967
968
  ]);
968
969
  }
969
- const s = new Uint8Array(9);
970
- s[0] = t | 27;
971
- for (let a = 7; a >= 0; a--)
972
- s[1 + a] = Number(r >> BigInt((7 - a) * 8)) & 255;
973
- return s;
970
+ const i = new Uint8Array(9);
971
+ i[0] = t | 27;
972
+ for (let s = 7; s >= 0; s--)
973
+ i[1 + s] = Number(r >> BigInt((7 - s) * 8)) & 255;
974
+ return i;
974
975
  }
975
- function re(...n) {
976
- const e = n.reduce((s, a) => s + a.length, 0), t = new Uint8Array(e);
976
+ function se(...n) {
977
+ const e = n.reduce((i, s) => i + s.length, 0), t = new Uint8Array(e);
977
978
  let r = 0;
978
- for (const s of n)
979
- t.set(s, r), r += s.length;
979
+ for (const i of n)
980
+ t.set(i, r), r += i.length;
980
981
  return t;
981
982
  }
982
- function H(n) {
983
+ function j(n) {
983
984
  const t = [A(4, n.length)];
984
985
  for (const r of n)
985
986
  t.push(A(0, r));
986
- return re(...t);
987
+ return se(...t);
987
988
  }
988
- function Fe(n, e, t) {
989
+ function He(n, e, t) {
989
990
  if (!Number.isSafeInteger(t) || t < 0)
990
991
  throw new Error(
991
992
  `encodeServerIdentityPayload: expires_at must be a non-negative safe integer, got ${t}`
992
993
  );
993
- const r = A(4, 3), s = H(n), a = H(e), c = A(0, t);
994
- return re(r, s, a, c);
994
+ const r = A(4, 3), i = j(n), s = j(e), c = A(0, t);
995
+ return se(r, i, s, c);
995
996
  }
996
- const Ne = new TextEncoder().encode(
997
+ const Ke = new TextEncoder().encode(
997
998
  "btc-auth.server-identity.v1"
998
999
  );
999
1000
  class u extends Error {
@@ -1001,28 +1002,28 @@ class u extends Error {
1001
1002
  super(e), this.reason = t, this.name = "ServerIdentityError";
1002
1003
  }
1003
1004
  }
1004
- function w(n) {
1005
+ function P(n) {
1005
1006
  const e = new Uint8Array(n.length / 2);
1006
1007
  for (let t = 0; t < e.length; t++)
1007
1008
  e[t] = parseInt(n.slice(t * 2, t * 2 + 2), 16);
1008
1009
  return e;
1009
1010
  }
1010
- function Re(n) {
1011
- const { proof: e, pinnedServerPubkey: t, now: r } = n, s = _(t).toLowerCase();
1012
- if (s.length !== v || !y.test(s))
1011
+ function Ue(n) {
1012
+ const { proof: e, pinnedServerPubkey: t, now: r } = n, i = _(t).toLowerCase();
1013
+ if (i.length !== v || !f.test(i))
1013
1014
  throw new u(
1014
- `pinnedServerPubkey must be 32-byte hex; got ${s.length} chars`,
1015
+ `pinnedServerPubkey must be 32-byte hex; got ${i.length} chars`,
1015
1016
  "invalid_pubkey_encoding"
1016
1017
  );
1017
- const a = _(e.server_pubkey).toLowerCase();
1018
- if (a.length !== v || !y.test(a))
1018
+ const s = _(e.server_pubkey).toLowerCase();
1019
+ if (s.length !== v || !f.test(s))
1019
1020
  throw new u(
1020
- `server_pubkey must be 32-byte hex; got ${a.length} chars`,
1021
+ `server_pubkey must be 32-byte hex; got ${s.length} chars`,
1021
1022
  "invalid_pubkey_encoding"
1022
1023
  );
1023
- if (a !== s)
1024
+ if (s !== i)
1024
1025
  throw new u(
1025
- `server_pubkey does not match pinned value: expected ${s}, got ${a}`,
1026
+ `server_pubkey does not match pinned value: expected ${i}, got ${s}`,
1026
1027
  "pinned_pubkey_mismatch"
1027
1028
  );
1028
1029
  if (!Number.isSafeInteger(e.expires_at))
@@ -1041,7 +1042,7 @@ function Re(n) {
1041
1042
  "expired"
1042
1043
  );
1043
1044
  const c = _(e.ephemeral_pubkey).toLowerCase();
1044
- if (c.length !== F || !y.test(c))
1045
+ if (c.length !== O || !f.test(c))
1045
1046
  throw new u(
1046
1047
  `ephemeral_pubkey must be 33-byte compressed hex; got ${c.length} chars`,
1047
1048
  "invalid_ephemeral_pubkey"
@@ -1052,32 +1053,49 @@ function Re(n) {
1052
1053
  `ephemeral_pubkey must be compressed (prefix 02/03); got ${d}`,
1053
1054
  "invalid_ephemeral_pubkey"
1054
1055
  );
1055
- const C = w(c);
1056
- if (!N.isPoint(C))
1056
+ const S = P(c);
1057
+ if (!$.isPoint(S))
1057
1058
  throw new u(
1058
1059
  "ephemeral_pubkey is not a valid secp256k1 point",
1059
1060
  "invalid_ephemeral_pubkey"
1060
1061
  );
1061
1062
  const p = _(e.signature).toLowerCase();
1062
- if (p.length !== pe || !y.test(p))
1063
+ if (p.length !== he || !f.test(p))
1063
1064
  throw new u(
1064
1065
  `signature must be 64-byte Schnorr hex; got ${p.length} chars`,
1065
1066
  "invalid_signature_encoding"
1066
1067
  );
1067
- const I = Fe(
1068
- Ne,
1069
- w(c),
1068
+ const E = He(
1069
+ Ke,
1070
+ P(c),
1070
1071
  e.expires_at
1071
1072
  );
1072
- if (!Be(I, w(a), w(p)))
1073
+ if (!Ne(E, P(s), P(p)))
1073
1074
  throw new u(
1074
1075
  "BIP-322 signature verification failed — ephemeral key is not attested by pinned server pubkey",
1075
1076
  "signature_verification_failed"
1076
1077
  );
1077
1078
  }
1078
- const D = "auth_createDepositorToken", M = 4102444800, Oe = 30;
1079
- class Ze {
1079
+ const De = /* @__PURE__ */ new Set([
1080
+ "vaultProvider_submitDepositorWotsKey",
1081
+ "vaultProvider_submitDepositorPresignatures",
1082
+ "vaultProvider_requestDepositorPresignTransactions"
1083
+ ]), je = 6e4, R = "auth_createDepositorToken";
1084
+ function ie(n, e) {
1085
+ return new G({
1086
+ baseUrl: n,
1087
+ timeout: je,
1088
+ headers: e,
1089
+ retryableFor: (t) => t === R
1090
+ });
1091
+ }
1092
+ const M = 4102444800, Me = 30;
1093
+ class Le {
1080
1094
  constructor(e) {
1095
+ // `client` is the only mutable field — see `setClient`. The
1096
+ // identity-bearing fields (peginTxid/authAnchorHex/pinnedServerPubkey)
1097
+ // remain readonly and are checked against re-registration in the
1098
+ // registry's `getOrCreate`.
1081
1099
  l(this, "client");
1082
1100
  l(this, "peginTxid");
1083
1101
  l(this, "authAnchorHex");
@@ -1087,7 +1105,7 @@ class Ze {
1087
1105
  l(this, "now");
1088
1106
  l(this, "cached", null);
1089
1107
  l(this, "inFlight", null);
1090
- this.client = e.client, this.peginTxid = e.peginTxid, this.authAnchorHex = e.authAnchorHex, this.pinnedServerPubkey = e.pinnedServerPubkey, this.authGatedMethods = e.authGatedMethods, this.refreshSkewSecs = e.refreshSkewSecs ?? Oe, this.now = e.now ?? (() => Math.floor(Date.now() / 1e3));
1108
+ this.client = e.client, this.peginTxid = e.peginTxid, this.authAnchorHex = e.authAnchorHex, this.pinnedServerPubkey = e.pinnedServerPubkey, this.authGatedMethods = e.authGatedMethods, this.refreshSkewSecs = e.refreshSkewSecs ?? Me, this.now = e.now ?? (() => Math.floor(Date.now() / 1e3));
1091
1109
  }
1092
1110
  /**
1093
1111
  * Return a bearer token for `method`, or `null` if `method` is not
@@ -1102,7 +1120,7 @@ class Ze {
1102
1120
  * guard. Returning `null` here breaks that recursion deterministically.
1103
1121
  */
1104
1122
  async getToken(e) {
1105
- if (e === D || !this.authGatedMethods.has(e)) return null;
1123
+ if (e === R || !this.authGatedMethods.has(e)) return null;
1106
1124
  const t = this.cached;
1107
1125
  return t && this.now() + this.refreshSkewSecs < t.expiresAt ? t.token : (await this.acquireSingleFlight()).token;
1108
1126
  }
@@ -1113,16 +1131,27 @@ class Ze {
1113
1131
  invalidate() {
1114
1132
  this.cached = null;
1115
1133
  }
1134
+ /**
1135
+ * Swap in a different transport for subsequent token-issuing calls.
1136
+ * Used by the registry when a later caller registers the same
1137
+ * `peginTxid` against a different `baseUrl` — the cached token
1138
+ * (bound to identity, not transport) stays valid, but future
1139
+ * refreshes hit the new URL. An in-flight acquire keeps using the
1140
+ * old client (it captured the reference); next call uses the new.
1141
+ */
1142
+ setClient(e) {
1143
+ this.client = e;
1144
+ }
1116
1145
  acquireSingleFlight() {
1117
1146
  const e = this.inFlight;
1118
1147
  if (e) return e;
1119
1148
  const t = (async () => {
1120
1149
  try {
1121
- const r = await this.client.call(D, {
1150
+ const r = await this.client.call(R, {
1122
1151
  pegin_txid: this.peginTxid,
1123
1152
  auth_anchor: this.authAnchorHex
1124
1153
  });
1125
- if (Re({
1154
+ if (Ue({
1126
1155
  proof: r.server_identity,
1127
1156
  pinnedServerPubkey: this.pinnedServerPubkey,
1128
1157
  now: this.now()
@@ -1130,16 +1159,16 @@ class Ze {
1130
1159
  throw new Error(
1131
1160
  `VpTokenProvider: invalid token in acquire response (expected non-empty string, got ${typeof r.token})`
1132
1161
  );
1133
- const s = this.now();
1134
- if (!Number.isSafeInteger(r.expires_at) || r.expires_at <= s || r.expires_at > M)
1162
+ const i = this.now();
1163
+ if (!Number.isSafeInteger(r.expires_at) || r.expires_at <= i || r.expires_at > M)
1135
1164
  throw new Error(
1136
- `VpTokenProvider: invalid expires_at in acquire response (got ${JSON.stringify(r.expires_at)}; must be a safe integer in (${s}, ${M}])`
1165
+ `VpTokenProvider: invalid expires_at in acquire response (got ${JSON.stringify(r.expires_at)}; must be a safe integer in (${i}, ${M}])`
1137
1166
  );
1138
- const a = {
1167
+ const s = {
1139
1168
  token: r.token,
1140
1169
  expiresAt: r.expires_at
1141
1170
  };
1142
- return this.cached = a, a;
1171
+ return this.cached = s, s;
1143
1172
  } finally {
1144
1173
  this.inFlight = null;
1145
1174
  }
@@ -1147,17 +1176,105 @@ class Ze {
1147
1176
  return this.inFlight = t, t;
1148
1177
  }
1149
1178
  }
1150
- async function et(n, e) {
1179
+ class Xe {
1180
+ constructor() {
1181
+ l(this, "entries", /* @__PURE__ */ new Map());
1182
+ }
1183
+ /**
1184
+ * Return the cached `VpTokenProvider` for `peginTxid` if one exists
1185
+ * with matching `authAnchorHex` and `pinnedServerPubkey`, otherwise
1186
+ * construct and cache a fresh provider. A mismatch on either field
1187
+ * throws — silent overwrite would mask derivation drift or VP
1188
+ * pubkey rotation.
1189
+ */
1190
+ getOrCreate(e) {
1191
+ const t = this.entries.get(e.peginTxid);
1192
+ if (t) {
1193
+ if (t.authAnchorHex !== e.authAnchorHex)
1194
+ throw new Error(
1195
+ `VpTokenRegistry: peginTxid ${e.peginTxid} already bound to authAnchorHex ${t.authAnchorHex.slice(0, 8)}…; got ${e.authAnchorHex.slice(0, 8)}…`
1196
+ );
1197
+ if (t.pinnedServerPubkey !== e.pinnedServerPubkey)
1198
+ throw new Error(
1199
+ `VpTokenRegistry: peginTxid ${e.peginTxid} already bound to pinnedServerPubkey ${t.pinnedServerPubkey.slice(0, 8)}…; got ${e.pinnedServerPubkey.slice(0, 8)}…`
1200
+ );
1201
+ return t.provider.setClient(e.client), t.provider;
1202
+ }
1203
+ const r = new Le({
1204
+ client: e.client,
1205
+ peginTxid: e.peginTxid,
1206
+ authAnchorHex: e.authAnchorHex,
1207
+ pinnedServerPubkey: e.pinnedServerPubkey,
1208
+ authGatedMethods: De
1209
+ });
1210
+ return this.entries.set(e.peginTxid, {
1211
+ provider: r,
1212
+ authAnchorHex: e.authAnchorHex,
1213
+ pinnedServerPubkey: e.pinnedServerPubkey
1214
+ }), r;
1215
+ }
1216
+ /** Return the cached provider, or `undefined` if none. */
1217
+ peek(e) {
1218
+ var t;
1219
+ return (t = this.entries.get(e)) == null ? void 0 : t.provider;
1220
+ }
1221
+ /**
1222
+ * Evict the entry for `peginTxid`. Idempotent. Called on terminal
1223
+ * paths — activation success, user-cancel, or component unmount —
1224
+ * so `authAnchorHex` doesn't outlive the deposit session.
1225
+ */
1226
+ release(e) {
1227
+ this.entries.delete(e);
1228
+ }
1229
+ /**
1230
+ * Wipe every cached entry. Test-only escape hatch — not exposed on
1231
+ * the public {@link VpTokenRegistryPublic} singleton type.
1232
+ *
1233
+ * @internal
1234
+ */
1235
+ clear() {
1236
+ this.entries.clear();
1237
+ }
1238
+ get size() {
1239
+ return this.entries.size;
1240
+ }
1241
+ }
1242
+ const ae = new Xe();
1243
+ function at(n) {
1244
+ var r;
1245
+ const e = ie(
1246
+ n.baseUrl,
1247
+ (r = n.options) == null ? void 0 : r.headers
1248
+ ), t = ae.getOrCreate({
1249
+ client: e,
1250
+ peginTxid: n.peginTxid,
1251
+ authAnchorHex: n.authAnchorHex,
1252
+ pinnedServerPubkey: n.pinnedServerPubkey
1253
+ });
1254
+ return new Ie(n.baseUrl, {
1255
+ ...n.options,
1256
+ tokenProvider: t
1257
+ });
1258
+ }
1259
+ function ot(n) {
1260
+ ae.getOrCreate({
1261
+ client: ie(n.baseUrl, n.headers),
1262
+ peginTxid: n.peginTxid,
1263
+ authAnchorHex: n.authAnchorHex,
1264
+ pinnedServerPubkey: n.pinnedServerPubkey
1265
+ });
1266
+ }
1267
+ async function ct(n, e) {
1151
1268
  const [t, r] = await n.multicall({
1152
1269
  contracts: [
1153
1270
  {
1154
1271
  address: e,
1155
- abi: P,
1272
+ abi: b,
1156
1273
  functionName: "protocolParams"
1157
1274
  },
1158
1275
  {
1159
1276
  address: e,
1160
- abi: P,
1277
+ abi: b,
1161
1278
  functionName: "applicationRegistry"
1162
1279
  }
1163
1280
  ],
@@ -1169,7 +1286,7 @@ async function et(n, e) {
1169
1286
  };
1170
1287
  }
1171
1288
  const L = 65535;
1172
- function B(n) {
1289
+ function F(n) {
1173
1290
  return {
1174
1291
  timelockAssert: n.timelockAssert,
1175
1292
  timelockChallengeAssert: n.timelockChallengeAssert,
@@ -1202,14 +1319,14 @@ function q(n) {
1202
1319
  );
1203
1320
  return Number(n);
1204
1321
  }
1205
- class tt {
1322
+ class lt {
1206
1323
  constructor(e, t) {
1207
1324
  this.publicClient = e, this.contractAddress = t;
1208
1325
  }
1209
1326
  async getTBVProtocolParams() {
1210
1327
  const e = await this.publicClient.readContract({
1211
1328
  address: this.contractAddress,
1212
- abi: m,
1329
+ abi: h,
1213
1330
  functionName: "getTBVProtocolParams"
1214
1331
  });
1215
1332
  return X(e);
@@ -1217,24 +1334,24 @@ class tt {
1217
1334
  async getLatestOffchainParams() {
1218
1335
  const e = await this.publicClient.readContract({
1219
1336
  address: this.contractAddress,
1220
- abi: m,
1337
+ abi: h,
1221
1338
  functionName: "getLatestOffchainParams"
1222
1339
  });
1223
- return B(e);
1340
+ return F(e);
1224
1341
  }
1225
1342
  async getOffchainParamsByVersion(e) {
1226
1343
  const t = await this.publicClient.readContract({
1227
1344
  address: this.contractAddress,
1228
- abi: m,
1345
+ abi: h,
1229
1346
  functionName: "getOffchainParamsByVersion",
1230
1347
  args: [e]
1231
1348
  });
1232
- return B(t);
1349
+ return F(t);
1233
1350
  }
1234
1351
  async getLatestOffchainParamsVersion() {
1235
1352
  return await this.publicClient.readContract({
1236
1353
  address: this.contractAddress,
1237
- abi: m,
1354
+ abi: h,
1238
1355
  functionName: "latestOffchainParamsVersion"
1239
1356
  });
1240
1357
  }
@@ -1251,17 +1368,17 @@ class tt {
1251
1368
  contracts: [
1252
1369
  {
1253
1370
  address: this.contractAddress,
1254
- abi: m,
1371
+ abi: h,
1255
1372
  functionName: "getTBVProtocolParams"
1256
1373
  },
1257
1374
  {
1258
1375
  address: this.contractAddress,
1259
- abi: m,
1376
+ abi: h,
1260
1377
  functionName: "getLatestOffchainParams"
1261
1378
  }
1262
1379
  ],
1263
1380
  allowFailure: !1
1264
- }), t = X(e[0]), r = B(e[1]);
1381
+ }), t = X(e[0]), r = F(e[1]);
1265
1382
  return {
1266
1383
  minimumPegInAmount: t.minimumPegInAmount,
1267
1384
  maxPegInAmount: t.maxPegInAmount,
@@ -1281,14 +1398,14 @@ function V(n) {
1281
1398
  btcPubKey: e.btcPubKey
1282
1399
  }));
1283
1400
  }
1284
- class nt {
1401
+ class ut {
1285
1402
  constructor(e, t) {
1286
1403
  this.publicClient = e, this.contractAddress = t;
1287
1404
  }
1288
1405
  async getVaultKeepersByVersion(e, t) {
1289
1406
  const r = await this.publicClient.readContract({
1290
1407
  address: this.contractAddress,
1291
- abi: S,
1408
+ abi: B,
1292
1409
  functionName: "getVaultKeepersByVersion",
1293
1410
  args: [e, t]
1294
1411
  });
@@ -1297,7 +1414,7 @@ class nt {
1297
1414
  async getCurrentVaultKeepers(e) {
1298
1415
  const t = await this.publicClient.readContract({
1299
1416
  address: this.contractAddress,
1300
- abi: S,
1417
+ abi: B,
1301
1418
  functionName: "getCurrentVaultKeepers",
1302
1419
  args: [e]
1303
1420
  });
@@ -1306,20 +1423,20 @@ class nt {
1306
1423
  async getCurrentVaultKeepersVersion(e) {
1307
1424
  return await this.publicClient.readContract({
1308
1425
  address: this.contractAddress,
1309
- abi: S,
1426
+ abi: B,
1310
1427
  functionName: "getCurrentVaultKeepersVersion",
1311
1428
  args: [e]
1312
1429
  });
1313
1430
  }
1314
1431
  }
1315
- class rt {
1432
+ class pt {
1316
1433
  constructor(e, t) {
1317
1434
  this.publicClient = e, this.contractAddress = t;
1318
1435
  }
1319
1436
  async getUniversalChallengersByVersion(e) {
1320
1437
  const t = await this.publicClient.readContract({
1321
1438
  address: this.contractAddress,
1322
- abi: m,
1439
+ abi: h,
1323
1440
  functionName: "getUniversalChallengersByVersion",
1324
1441
  args: [e]
1325
1442
  });
@@ -1328,7 +1445,7 @@ class rt {
1328
1445
  async getCurrentUniversalChallengers() {
1329
1446
  const e = await this.publicClient.readContract({
1330
1447
  address: this.contractAddress,
1331
- abi: m,
1448
+ abi: h,
1332
1449
  functionName: "getCurrentUniversalChallengers"
1333
1450
  });
1334
1451
  return V(e);
@@ -1336,19 +1453,43 @@ class rt {
1336
1453
  async getLatestUniversalChallengersVersion() {
1337
1454
  return await this.publicClient.readContract({
1338
1455
  address: this.contractAddress,
1339
- abi: m,
1456
+ abi: h,
1340
1457
  functionName: "latestUniversalChallengersVersion"
1341
1458
  });
1342
1459
  }
1343
1460
  }
1344
- class at {
1461
+ class dt {
1345
1462
  constructor(e, t) {
1346
1463
  this.publicClient = e, this.contractAddress = t;
1347
1464
  }
1465
+ /**
1466
+ * Read the VP's persistent x-only BTC pubkey from the on-chain
1467
+ * registry. Validates length, hex form, and secp256k1 curve
1468
+ * membership before minting the brand. Returns 64-char lowercase
1469
+ * hex without the `0x` prefix.
1470
+ */
1471
+ async getVaultProviderBtcPubKey(e) {
1472
+ const r = (await this.publicClient.readContract({
1473
+ address: this.contractAddress,
1474
+ abi: b,
1475
+ functionName: "getVaultProviderBTCKey",
1476
+ args: [e]
1477
+ })).toLowerCase();
1478
+ if (!/^0x[0-9a-f]{64}$/.test(r))
1479
+ throw new Error(
1480
+ `getVaultProviderBTCKey returned an unexpected value (vp=${e}, length ${r.length}, prefix "${r.slice(0, 2)}")`
1481
+ );
1482
+ const i = r.slice(2);
1483
+ if (!$.isXOnlyPoint(me(i)))
1484
+ throw new Error(
1485
+ `getVaultProviderBTCKey returned a value that is not on the secp256k1 curve (vp=${e})`
1486
+ );
1487
+ return i;
1488
+ }
1348
1489
  async getVaultBasicInfo(e) {
1349
1490
  const t = await this.publicClient.readContract({
1350
1491
  address: this.contractAddress,
1351
- abi: P,
1492
+ abi: b,
1352
1493
  functionName: "getBtcVaultBasicInfo",
1353
1494
  args: [e]
1354
1495
  });
@@ -1365,7 +1506,7 @@ class at {
1365
1506
  async getVaultProtocolInfo(e) {
1366
1507
  const t = await this.publicClient.readContract({
1367
1508
  address: this.contractAddress,
1368
- abi: P,
1509
+ abi: b,
1369
1510
  functionName: "getBtcVaultProtocolInfo",
1370
1511
  args: [e]
1371
1512
  });
@@ -1396,27 +1537,30 @@ class at {
1396
1537
  }
1397
1538
  }
1398
1539
  export {
1399
- S as A,
1400
- fe as M,
1401
- m as P,
1540
+ B as A,
1541
+ be as M,
1542
+ h as P,
1402
1543
  u as S,
1403
- Qe as V,
1404
- We as a,
1405
- Je as b,
1406
- Ye as c,
1407
- qe as d,
1408
- ye as e,
1409
- Ge as f,
1410
- ze as g,
1411
- i as h,
1412
- Re as i,
1413
- Ze as j,
1414
- tt as k,
1415
- rt as l,
1416
- nt as m,
1417
- at as n,
1418
- Xe as p,
1419
- et as r,
1420
- Ae as v
1544
+ Ie as V,
1545
+ nt as a,
1546
+ rt as b,
1547
+ it as c,
1548
+ et as d,
1549
+ we as e,
1550
+ tt as f,
1551
+ st as g,
1552
+ a as h,
1553
+ Ue as i,
1554
+ Xe as j,
1555
+ ae as k,
1556
+ at as l,
1557
+ ot as m,
1558
+ lt as n,
1559
+ pt as o,
1560
+ Ze as p,
1561
+ ut as q,
1562
+ ct as r,
1563
+ dt as s,
1564
+ ke as v
1421
1565
  };
1422
- //# sourceMappingURL=vault-registry-reader-BywZhqJL.js.map
1566
+ //# sourceMappingURL=vault-registry-reader-BeIEh62N.js.map