@babylonlabs-io/ts-sdk 0.33.3 → 0.33.5

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 (153) hide show
  1. package/dist/BTCVaultRegistry.abi-DbJ5lsFJ.js +417 -0
  2. package/dist/BTCVaultRegistry.abi-DbJ5lsFJ.js.map +1 -0
  3. package/dist/BTCVaultRegistry.abi-ZdPpION2.cjs +2 -0
  4. package/dist/BTCVaultRegistry.abi-ZdPpION2.cjs.map +1 -0
  5. package/dist/PayoutManager-C9XHKZ5j.js +200 -0
  6. package/dist/PayoutManager-C9XHKZ5j.js.map +1 -0
  7. package/dist/PayoutManager-DDnNB0mj.cjs +2 -0
  8. package/dist/PayoutManager-DDnNB0mj.cjs.map +1 -0
  9. package/dist/PeginManager-BXg2S1mH.cjs +2 -0
  10. package/dist/PeginManager-BXg2S1mH.cjs.map +1 -0
  11. package/dist/{PeginManager-C-L3huRO.js → PeginManager-C5HaMAcw.js} +328 -437
  12. package/dist/PeginManager-C5HaMAcw.js.map +1 -0
  13. package/dist/ProtocolParams.abi-BmvHwQJV.cjs +2 -0
  14. package/dist/ProtocolParams.abi-BmvHwQJV.cjs.map +1 -0
  15. package/dist/ProtocolParams.abi-DXu8L0Fn.js +382 -0
  16. package/dist/ProtocolParams.abi-DXu8L0Fn.js.map +1 -0
  17. package/dist/buildAndBroadcastRefund-B332dykQ.cjs +2 -0
  18. package/dist/buildAndBroadcastRefund-B332dykQ.cjs.map +1 -0
  19. package/dist/buildAndBroadcastRefund-CPjXNaMi.js +782 -0
  20. package/dist/buildAndBroadcastRefund-CPjXNaMi.js.map +1 -0
  21. package/dist/challengeAssert-BzxQmdZy.js +128 -0
  22. package/dist/challengeAssert-BzxQmdZy.js.map +1 -0
  23. package/dist/challengeAssert-Yyyj-EdR.cjs +2 -0
  24. package/dist/challengeAssert-Yyyj-EdR.cjs.map +1 -0
  25. package/dist/errors-9AkghWyk.js +22 -0
  26. package/dist/errors-9AkghWyk.js.map +1 -0
  27. package/dist/errors-BP73_stm.cjs +2 -0
  28. package/dist/errors-BP73_stm.cjs.map +1 -0
  29. package/dist/errors-Bu0H-dZD.cjs +2 -0
  30. package/dist/errors-Bu0H-dZD.cjs.map +1 -0
  31. package/dist/errors-CznAK5NB.js +96 -0
  32. package/dist/errors-CznAK5NB.js.map +1 -0
  33. package/dist/index.cjs +1 -1
  34. package/dist/index.js +159 -147
  35. package/dist/index.js.map +1 -1
  36. package/dist/mempoolApi-CAIge7Nj.js +205 -0
  37. package/dist/mempoolApi-CAIge7Nj.js.map +1 -0
  38. package/dist/mempoolApi-YNkKjQCU.cjs +2 -0
  39. package/dist/mempoolApi-YNkKjQCU.cjs.map +1 -0
  40. package/dist/noPayout-BXeUw0Qq.cjs +2 -0
  41. package/dist/noPayout-BXeUw0Qq.cjs.map +1 -0
  42. package/dist/noPayout-DBX6G96_.js +141 -0
  43. package/dist/noPayout-DBX6G96_.js.map +1 -0
  44. package/dist/payout-BNFMBXS6.js +193 -0
  45. package/dist/payout-BNFMBXS6.js.map +1 -0
  46. package/dist/payout-DQ_fmJUA.cjs +2 -0
  47. package/dist/payout-DQ_fmJUA.cjs.map +1 -0
  48. package/dist/peginInput-C2QPvuhR.js +177 -0
  49. package/dist/peginInput-C2QPvuhR.js.map +1 -0
  50. package/dist/peginInput-tbw9BpZy.cjs +2 -0
  51. package/dist/peginInput-tbw9BpZy.cjs.map +1 -0
  52. package/dist/peginState-BijNNT15.cjs +2 -0
  53. package/dist/peginState-BijNNT15.cjs.map +1 -0
  54. package/dist/peginState-CBAlxgXk.js +51 -0
  55. package/dist/peginState-CBAlxgXk.js.map +1 -0
  56. package/dist/psbtInputFields-2224j2ZY.js +128 -0
  57. package/dist/psbtInputFields-2224j2ZY.js.map +1 -0
  58. package/dist/psbtInputFields-B1lrwYzH.cjs +2 -0
  59. package/dist/psbtInputFields-B1lrwYzH.cjs.map +1 -0
  60. package/dist/reservation-CHUGW0F_.js +142 -0
  61. package/dist/reservation-CHUGW0F_.js.map +1 -0
  62. package/dist/reservation-ho7mjW3X.cjs +2 -0
  63. package/dist/reservation-ho7mjW3X.cjs.map +1 -0
  64. package/dist/signing-Bnsro0hE.cjs +2 -0
  65. package/dist/signing-Bnsro0hE.cjs.map +1 -0
  66. package/dist/signing-DaLvGwQe.js +16 -0
  67. package/dist/signing-DaLvGwQe.js.map +1 -0
  68. package/dist/tbv/core/clients/index.cjs +1 -1
  69. package/dist/tbv/core/clients/index.js +35 -32
  70. package/dist/tbv/core/clients/index.js.map +1 -1
  71. package/dist/tbv/core/clients/vault-provider/__tests__/batchAttribution.test.d.ts +2 -0
  72. package/dist/tbv/core/clients/vault-provider/__tests__/batchAttribution.test.d.ts.map +1 -0
  73. package/dist/tbv/core/clients/vault-provider/__tests__/batchPoll.test.d.ts +2 -0
  74. package/dist/tbv/core/clients/vault-provider/__tests__/batchPoll.test.d.ts.map +1 -0
  75. package/dist/tbv/core/clients/vault-provider/api.d.ts +13 -4
  76. package/dist/tbv/core/clients/vault-provider/api.d.ts.map +1 -1
  77. package/dist/tbv/core/clients/vault-provider/batchAttribution.d.ts +45 -0
  78. package/dist/tbv/core/clients/vault-provider/batchAttribution.d.ts.map +1 -0
  79. package/dist/tbv/core/clients/vault-provider/batchPoll.d.ts +55 -0
  80. package/dist/tbv/core/clients/vault-provider/batchPoll.d.ts.map +1 -0
  81. package/dist/tbv/core/clients/vault-provider/index.d.ts +2 -0
  82. package/dist/tbv/core/clients/vault-provider/index.d.ts.map +1 -1
  83. package/dist/tbv/core/clients/vault-provider/json-rpc-client.d.ts +3 -3
  84. package/dist/tbv/core/clients/vault-provider/json-rpc-client.d.ts.map +1 -1
  85. package/dist/tbv/core/clients/vault-provider/types.d.ts +68 -24
  86. package/dist/tbv/core/clients/vault-provider/types.d.ts.map +1 -1
  87. package/dist/tbv/core/clients/vault-provider/validators.d.ts +12 -2
  88. package/dist/tbv/core/clients/vault-provider/validators.d.ts.map +1 -1
  89. package/dist/tbv/core/contracts/index.cjs +2 -0
  90. package/dist/tbv/core/contracts/index.cjs.map +1 -0
  91. package/dist/tbv/core/contracts/index.js +14 -0
  92. package/dist/tbv/core/contracts/index.js.map +1 -0
  93. package/dist/tbv/core/index.cjs +1 -1
  94. package/dist/tbv/core/index.js +157 -145
  95. package/dist/tbv/core/index.js.map +1 -1
  96. package/dist/tbv/core/managers/index.cjs +2 -0
  97. package/dist/tbv/core/managers/index.cjs.map +1 -0
  98. package/dist/tbv/core/managers/index.js +7 -0
  99. package/dist/tbv/core/managers/index.js.map +1 -0
  100. package/dist/tbv/core/primitives/index.cjs +1 -1
  101. package/dist/tbv/core/primitives/index.js +31 -29
  102. package/dist/tbv/core/primitives/index.js.map +1 -1
  103. package/dist/tbv/core/services/deposit/waitForPeginStatus.d.ts.map +1 -1
  104. package/dist/tbv/core/services/index.cjs +1 -1
  105. package/dist/tbv/core/services/index.js +28 -27
  106. package/dist/tbv/core/services/index.js.map +1 -1
  107. package/dist/tbv/core/services/pegout/state.d.ts +1 -1
  108. package/dist/tbv/core/utils/index.cjs +1 -1
  109. package/dist/tbv/core/utils/index.js +21 -20
  110. package/dist/tbv/core/utils/index.js.map +1 -1
  111. package/dist/tbv/index.cjs +1 -1
  112. package/dist/tbv/index.js +157 -145
  113. package/dist/tbv/index.js.map +1 -1
  114. package/dist/types-DnyyBNcC.cjs +2 -0
  115. package/dist/types-DnyyBNcC.cjs.map +1 -0
  116. package/dist/types-TiIjyo2b.js +320 -0
  117. package/dist/types-TiIjyo2b.js.map +1 -0
  118. package/dist/vault-registry-reader-BDFpXeH7.js +1152 -0
  119. package/dist/vault-registry-reader-BDFpXeH7.js.map +1 -0
  120. package/dist/vault-registry-reader-ejm2UYzk.cjs +2 -0
  121. package/dist/vault-registry-reader-ejm2UYzk.cjs.map +1 -0
  122. package/package.json +11 -1
  123. package/dist/PeginManager-C-L3huRO.js.map +0 -1
  124. package/dist/PeginManager-DmPmzPHz.cjs +0 -2
  125. package/dist/PeginManager-DmPmzPHz.cjs.map +0 -1
  126. package/dist/buildAndBroadcastRefund-Dx09Zbla.js +0 -965
  127. package/dist/buildAndBroadcastRefund-Dx09Zbla.js.map +0 -1
  128. package/dist/buildAndBroadcastRefund-PmJMNrhO.cjs +0 -2
  129. package/dist/buildAndBroadcastRefund-PmJMNrhO.cjs.map +0 -1
  130. package/dist/challengeAssert-D3tHnLWb.js +0 -298
  131. package/dist/challengeAssert-D3tHnLWb.js.map +0 -1
  132. package/dist/challengeAssert-Dp9d1bg1.cjs +0 -2
  133. package/dist/challengeAssert-Dp9d1bg1.cjs.map +0 -1
  134. package/dist/noPayout-BnsetBKW.js +0 -327
  135. package/dist/noPayout-BnsetBKW.js.map +0 -1
  136. package/dist/noPayout-DWaCtpMU.cjs +0 -2
  137. package/dist/noPayout-DWaCtpMU.cjs.map +0 -1
  138. package/dist/psbtInputFields-6sRcZqdb.cjs +0 -2
  139. package/dist/psbtInputFields-6sRcZqdb.cjs.map +0 -1
  140. package/dist/psbtInputFields-C5QPn1YK.js +0 -264
  141. package/dist/psbtInputFields-C5QPn1YK.js.map +0 -1
  142. package/dist/signing-BZigafm0.js +0 -64
  143. package/dist/signing-BZigafm0.js.map +0 -1
  144. package/dist/signing-DHSXjhLM.cjs +0 -2
  145. package/dist/signing-DHSXjhLM.cjs.map +0 -1
  146. package/dist/types-PthVHz5q.cjs +0 -2
  147. package/dist/types-PthVHz5q.cjs.map +0 -1
  148. package/dist/types-SYvSQWnc.js +0 -732
  149. package/dist/types-SYvSQWnc.js.map +0 -1
  150. package/dist/vault-registry-reader-CKe9TbX6.cjs +0 -2
  151. package/dist/vault-registry-reader-CKe9TbX6.cjs.map +0 -1
  152. package/dist/vault-registry-reader-CWGbw_wZ.js +0 -1567
  153. package/dist/vault-registry-reader-CWGbw_wZ.js.map +0 -1
@@ -1,1567 +0,0 @@
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-SYvSQWnc.js";
6
- import { X as v, C as F, s as _, S as he, h as me } from "./bitcoin-B0S8SHCX.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
- import { s as K } from "./sha2-6wN58S6R.js";
11
- const fe = 21e6 * 1e8, U = 3e4;
12
- async function k(n, e) {
13
- const t = new AbortController(), r = setTimeout(
14
- () => t.abort(),
15
- U
16
- ), a = [t.signal, e == null ? void 0 : e.signal].filter(
17
- Boolean
18
- );
19
- try {
20
- return await fetch(n, {
21
- ...e,
22
- signal: AbortSignal.any(a)
23
- });
24
- } catch (s) {
25
- throw clearTimeout(r), s != null && typeof s == "object" && "name" in s && s.name === "AbortError" ? new Error(
26
- `Mempool API request timed out after ${U}ms: ${n}`
27
- ) : s;
28
- }
29
- }
30
- const W = 1e4;
31
- function J(n) {
32
- return Number.isInteger(n) && n > 0 && n <= fe;
33
- }
34
- function ge(n) {
35
- return Number.isInteger(n) && n > 0 && n <= W;
36
- }
37
- function z(n, e) {
38
- return !Number.isInteger(n) || n < 0 ? !1 : e === void 0 || n < e;
39
- }
40
- function C(n) {
41
- if (!pe.test(n))
42
- throw new Error(`Invalid transaction ID format: ${n}`);
43
- }
44
- function Y(n) {
45
- if (!le.test(n))
46
- throw new Error(`Invalid Bitcoin address format: ${n}`);
47
- }
48
- function Q(n, e) {
49
- if (!f.test(n))
50
- throw new Error(
51
- `Invalid scriptPubKey: not valid hex for ${e}`
52
- );
53
- if (!ue.some(
54
- (r) => n.toLowerCase().startsWith(r)
55
- ))
56
- throw new Error(
57
- `Unrecognized scriptPubKey type for ${e}: prefix ${n.slice(0, 6)} does not match any known Bitcoin script type`
58
- );
59
- }
60
- const be = {
61
- mainnet: "https://mempool.space/api",
62
- testnet: "https://mempool.space/testnet/api",
63
- signet: "https://mempool.space/signet/api"
64
- };
65
- async function T(n, e) {
66
- try {
67
- const t = await k(n, e);
68
- if (!t.ok) {
69
- const a = await t.text();
70
- throw new Error(
71
- `Mempool API error (${t.status}): ${a || t.statusText}`
72
- );
73
- }
74
- const r = t.headers.get("content-type");
75
- return r != null && r.includes("application/json") ? await t.json() : await t.text();
76
- } catch (t) {
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
- }
79
- }
80
- async function Ze(n, e) {
81
- try {
82
- const t = await k(`${e}/tx`, {
83
- method: "POST",
84
- body: n,
85
- headers: {
86
- "Content-Type": "text/plain"
87
- }
88
- });
89
- if (!t.ok) {
90
- const a = await t.text();
91
- let s;
92
- try {
93
- s = JSON.parse(a).message;
94
- } catch {
95
- s = a;
96
- }
97
- throw new Error(
98
- s || `Failed to broadcast transaction: ${t.statusText}`
99
- );
100
- }
101
- return await t.text();
102
- } catch (t) {
103
- throw t instanceof Error ? new Error(`Failed to broadcast BTC transaction: ${t.message}`) : new Error("Failed to broadcast BTC transaction: Unknown error");
104
- }
105
- }
106
- async function we(n, e) {
107
- return C(n), T(`${e}/tx/${n}`);
108
- }
109
- async function et(n, e) {
110
- C(n);
111
- try {
112
- const t = await k(`${e}/tx/${n}/hex`);
113
- if (!t.ok) {
114
- const r = await t.text();
115
- throw new Error(
116
- `Mempool API error (${t.status}): ${r || t.statusText}`
117
- );
118
- }
119
- return await t.text();
120
- } catch (t) {
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
- }
123
- }
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
- throw new Error(
129
- `Invalid vout ${e} for transaction ${n} (has ${r.vout.length} outputs)`
130
- );
131
- const a = r.vout[e];
132
- if (!J(a.value))
133
- throw new Error(`Invalid UTXO value ${a.value} for ${n}:${e}`);
134
- return Q(a.scriptpubkey, `${n}:${e}`), {
135
- txid: n,
136
- vout: e,
137
- value: a.value,
138
- scriptPubKey: a.scriptpubkey
139
- };
140
- }
141
- async function nt(n, e) {
142
- Y(n);
143
- try {
144
- const t = await T(`${e}/address/${n}/utxo`), r = await T(`${e}/v1/validate-address/${n}`);
145
- if (!r.isvalid)
146
- throw new Error(
147
- `Invalid Bitcoin address: ${n}. Mempool API validation failed.`
148
- );
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
- throw new Error(
155
- `Invalid UTXO value ${s.value} for ${s.txid}:${s.vout}`
156
- );
157
- }
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
- scriptPubKey: r.scriptPubKey,
163
- confirmed: s.status.confirmed
164
- }));
165
- } catch (t) {
166
- throw t instanceof Error ? new Error(
167
- `Failed to get UTXOs for address ${n}: ${t.message}`
168
- ) : new Error(
169
- `Failed to get UTXOs for address ${n}: Unknown error`
170
- );
171
- }
172
- }
173
- function rt(n) {
174
- return be[n];
175
- }
176
- async function st(n, e) {
177
- return Y(n), T(`${e}/address/${n}/txs`);
178
- }
179
- async function at(n) {
180
- const e = await k(`${n}/v1/fees/recommended`);
181
- if (!e.ok)
182
- throw new Error(
183
- `Failed to fetch network fees: ${e.status} ${e.statusText}`
184
- );
185
- const t = await e.json(), r = [
186
- "fastestFee",
187
- "halfHourFee",
188
- "hourFee",
189
- "economyFee",
190
- "minimumFee"
191
- ];
192
- for (const a of r)
193
- if (!ge(t[a]))
194
- throw new Error(
195
- `Invalid fee rate ${a}=${t[a]} from mempool API: expected a positive number ≤ ${W}`
196
- );
197
- if (t.minimumFee > t.economyFee || t.economyFee > t.hourFee || t.hourFee > t.halfHourFee || t.halfHourFee > t.fastestFee)
198
- throw new Error(
199
- `Fee rate ordering violation from mempool API: expected minimumFee (${t.minimumFee}) <= economyFee (${t.economyFee}) <= hourFee (${t.hourFee}) <= halfHourFee (${t.halfHourFee}) <= fastestFee (${t.fastestFee}).`
200
- );
201
- return t;
202
- }
203
- const B = [
204
- {
205
- type: "function",
206
- name: "getVaultKeepersByVersion",
207
- inputs: [
208
- {
209
- name: "appEntryPoint",
210
- type: "address",
211
- internalType: "address"
212
- },
213
- {
214
- name: "versionNumber",
215
- type: "uint16",
216
- internalType: "uint16"
217
- }
218
- ],
219
- outputs: [
220
- {
221
- name: "",
222
- type: "tuple[]",
223
- internalType: "struct BTCVaultTypes.AddressBTCKeyPair[]",
224
- components: [
225
- {
226
- name: "ethAddress",
227
- type: "address",
228
- internalType: "address"
229
- },
230
- {
231
- name: "btcPubKey",
232
- type: "bytes32",
233
- internalType: "bytes32"
234
- }
235
- ]
236
- }
237
- ],
238
- stateMutability: "view"
239
- },
240
- {
241
- type: "function",
242
- name: "getCurrentVaultKeepers",
243
- inputs: [
244
- {
245
- name: "appEntryPoint",
246
- type: "address",
247
- internalType: "address"
248
- }
249
- ],
250
- outputs: [
251
- {
252
- name: "",
253
- type: "tuple[]",
254
- internalType: "struct BTCVaultTypes.AddressBTCKeyPair[]",
255
- components: [
256
- {
257
- name: "ethAddress",
258
- type: "address",
259
- internalType: "address"
260
- },
261
- {
262
- name: "btcPubKey",
263
- type: "bytes32",
264
- internalType: "bytes32"
265
- }
266
- ]
267
- }
268
- ],
269
- stateMutability: "view"
270
- },
271
- {
272
- type: "function",
273
- name: "getCurrentVaultKeepersVersion",
274
- inputs: [
275
- {
276
- name: "appEntryPoint",
277
- type: "address",
278
- internalType: "address"
279
- }
280
- ],
281
- outputs: [
282
- {
283
- name: "",
284
- type: "uint16",
285
- internalType: "uint16"
286
- }
287
- ],
288
- stateMutability: "view"
289
- }
290
- ], h = [
291
- {
292
- type: "function",
293
- name: "getTBVProtocolParams",
294
- inputs: [],
295
- outputs: [
296
- {
297
- name: "",
298
- type: "tuple",
299
- internalType: "struct IProtocolParams.TBVProtocolParams",
300
- components: [
301
- {
302
- name: "minimumPegInAmount",
303
- type: "uint64",
304
- internalType: "uint64"
305
- },
306
- {
307
- name: "maxPegInAmount",
308
- type: "uint64",
309
- internalType: "uint64"
310
- },
311
- {
312
- name: "pegInAckTimeout",
313
- type: "uint64",
314
- internalType: "uint64"
315
- },
316
- {
317
- name: "pegInActivationTimeout",
318
- type: "uint64",
319
- internalType: "uint64"
320
- },
321
- {
322
- name: "maxHtlcOutputCount",
323
- type: "uint8",
324
- internalType: "uint8"
325
- }
326
- ]
327
- }
328
- ],
329
- stateMutability: "view"
330
- },
331
- {
332
- type: "function",
333
- name: "getLatestOffchainParams",
334
- inputs: [],
335
- outputs: [
336
- {
337
- name: "",
338
- type: "tuple",
339
- internalType: "struct IProtocolParams.VersionedOffchainParams",
340
- components: [
341
- {
342
- name: "timelockAssert",
343
- type: "uint256",
344
- internalType: "uint256"
345
- },
346
- {
347
- name: "timelockChallengeAssert",
348
- type: "uint256",
349
- internalType: "uint256"
350
- },
351
- {
352
- name: "securityCouncilKeys",
353
- type: "bytes32[]",
354
- internalType: "bytes32[]"
355
- },
356
- {
357
- name: "councilQuorum",
358
- type: "uint8",
359
- internalType: "uint8"
360
- },
361
- {
362
- name: "feeRate",
363
- type: "uint64",
364
- internalType: "uint64"
365
- },
366
- {
367
- name: "babeTotalInstances",
368
- type: "uint16",
369
- internalType: "uint16"
370
- },
371
- {
372
- name: "babeInstancesToFinalize",
373
- type: "uint8",
374
- internalType: "uint8"
375
- },
376
- {
377
- name: "minVpCommissionBps",
378
- type: "uint16",
379
- internalType: "uint16"
380
- },
381
- {
382
- name: "tRefund",
383
- type: "uint32",
384
- internalType: "uint32"
385
- },
386
- {
387
- name: "tStale",
388
- type: "uint32",
389
- internalType: "uint32"
390
- },
391
- {
392
- name: "minPeginFeeRate",
393
- type: "uint64",
394
- internalType: "uint64"
395
- },
396
- {
397
- name: "proverProgramVersion",
398
- type: "uint16",
399
- internalType: "uint16"
400
- },
401
- {
402
- name: "minPrepeginDepth",
403
- type: "uint32",
404
- internalType: "uint32"
405
- }
406
- ]
407
- }
408
- ],
409
- stateMutability: "view"
410
- },
411
- {
412
- type: "function",
413
- name: "getOffchainParamsByVersion",
414
- inputs: [
415
- {
416
- name: "versionNumber",
417
- type: "uint16",
418
- internalType: "uint16"
419
- }
420
- ],
421
- outputs: [
422
- {
423
- name: "",
424
- type: "tuple",
425
- internalType: "struct IProtocolParams.VersionedOffchainParams",
426
- components: [
427
- {
428
- name: "timelockAssert",
429
- type: "uint256",
430
- internalType: "uint256"
431
- },
432
- {
433
- name: "timelockChallengeAssert",
434
- type: "uint256",
435
- internalType: "uint256"
436
- },
437
- {
438
- name: "securityCouncilKeys",
439
- type: "bytes32[]",
440
- internalType: "bytes32[]"
441
- },
442
- {
443
- name: "councilQuorum",
444
- type: "uint8",
445
- internalType: "uint8"
446
- },
447
- {
448
- name: "feeRate",
449
- type: "uint64",
450
- internalType: "uint64"
451
- },
452
- {
453
- name: "babeTotalInstances",
454
- type: "uint16",
455
- internalType: "uint16"
456
- },
457
- {
458
- name: "babeInstancesToFinalize",
459
- type: "uint8",
460
- internalType: "uint8"
461
- },
462
- {
463
- name: "minVpCommissionBps",
464
- type: "uint16",
465
- internalType: "uint16"
466
- },
467
- {
468
- name: "tRefund",
469
- type: "uint32",
470
- internalType: "uint32"
471
- },
472
- {
473
- name: "tStale",
474
- type: "uint32",
475
- internalType: "uint32"
476
- },
477
- {
478
- name: "minPeginFeeRate",
479
- type: "uint64",
480
- internalType: "uint64"
481
- },
482
- {
483
- name: "proverProgramVersion",
484
- type: "uint16",
485
- internalType: "uint16"
486
- },
487
- {
488
- name: "minPrepeginDepth",
489
- type: "uint32",
490
- internalType: "uint32"
491
- }
492
- ]
493
- }
494
- ],
495
- stateMutability: "view"
496
- },
497
- {
498
- type: "function",
499
- name: "latestOffchainParamsVersion",
500
- inputs: [],
501
- outputs: [
502
- {
503
- name: "",
504
- type: "uint16",
505
- internalType: "uint16"
506
- }
507
- ],
508
- stateMutability: "view"
509
- },
510
- {
511
- type: "function",
512
- name: "getUniversalChallengersByVersion",
513
- inputs: [
514
- {
515
- name: "versionNumber",
516
- type: "uint16",
517
- internalType: "uint16"
518
- }
519
- ],
520
- outputs: [
521
- {
522
- name: "",
523
- type: "tuple[]",
524
- internalType: "struct BTCVaultTypes.AddressBTCKeyPair[]",
525
- components: [
526
- {
527
- name: "ethAddress",
528
- type: "address",
529
- internalType: "address"
530
- },
531
- {
532
- name: "btcPubKey",
533
- type: "bytes32",
534
- internalType: "bytes32"
535
- }
536
- ]
537
- }
538
- ],
539
- stateMutability: "view"
540
- },
541
- {
542
- type: "function",
543
- name: "getCurrentUniversalChallengers",
544
- inputs: [],
545
- outputs: [
546
- {
547
- name: "",
548
- type: "tuple[]",
549
- internalType: "struct BTCVaultTypes.AddressBTCKeyPair[]",
550
- components: [
551
- {
552
- name: "ethAddress",
553
- type: "address",
554
- internalType: "address"
555
- },
556
- {
557
- name: "btcPubKey",
558
- type: "bytes32",
559
- internalType: "bytes32"
560
- }
561
- ]
562
- }
563
- ],
564
- stateMutability: "view"
565
- },
566
- {
567
- type: "function",
568
- name: "latestUniversalChallengersVersion",
569
- inputs: [],
570
- outputs: [
571
- {
572
- name: "",
573
- type: "uint16",
574
- internalType: "uint16"
575
- }
576
- ],
577
- stateMutability: "view"
578
- }
579
- ], D = new Set(Object.values(de)), _e = 200;
580
- function o(n) {
581
- var e;
582
- return ((e = JSON.stringify(n)) == null ? void 0 : e.slice(0, _e)) ?? "undefined";
583
- }
584
- const Pe = "The vault provider returned an unexpected response. Please try again or contact support.";
585
- class i extends Error {
586
- constructor(t) {
587
- super(Pe);
588
- l(this, "detail");
589
- this.name = "VpResponseValidationError", this.detail = t;
590
- }
591
- }
592
- const x = 64;
593
- function g(n) {
594
- return typeof n == "string" && n.length > 0 && f.test(n);
595
- }
596
- function Z(n) {
597
- return typeof n == "string" && n.length > 0;
598
- }
599
- function ee(n, e) {
600
- if (!g(n))
601
- throw new i(
602
- `VP response validation failed: "${e}" must be a non-empty hex string, got ${o(n)}`
603
- );
604
- }
605
- function w(n, e) {
606
- if (!Z(n))
607
- throw new i(
608
- `VP response validation failed: "${e}" must be a non-empty string, got ${o(n)}`
609
- );
610
- }
611
- function te(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)}`
615
- );
616
- }
617
- function ve(n) {
618
- const e = n.presigning;
619
- if (e == null) return;
620
- if (typeof e != "object" || Array.isArray(e))
621
- throw new i(
622
- 'VP response validation failed: "progress.presigning" must be an object if present'
623
- );
624
- const t = e;
625
- if (t.depositor_graph_created !== void 0 && typeof t.depositor_graph_created != "boolean")
626
- throw new i(
627
- `VP response validation failed: "progress.presigning.depositor_graph_created" must be a boolean if present, got ${o(t.depositor_graph_created)}`
628
- );
629
- if (t.vk_challenger_presigning_completed !== void 0 && typeof t.vk_challenger_presigning_completed != "number")
630
- throw new i(
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
- );
633
- if (t.vk_challenger_presigning_total !== void 0 && typeof t.vk_challenger_presigning_total != "number")
634
- throw new i(
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
- );
637
- }
638
- function Te(n) {
639
- if (n === null || typeof n != "object")
640
- throw new i(
641
- "VP response validation failed: getPeginStatus response is not an object"
642
- );
643
- const e = n;
644
- if (!g(e.pegin_txid) || e.pegin_txid.length !== x)
645
- throw new i(
646
- `VP response validation failed: "pegin_txid" must be a ${x}-char hex string (txid), got ${o(e.pegin_txid)}`
647
- );
648
- if (typeof e.status != "string")
649
- throw new i(
650
- 'VP response validation failed: "status" must be a string'
651
- );
652
- if (!D.has(e.status))
653
- throw new i(
654
- `VP response validation failed: unrecognized status "${e.status}". Expected one of: ${[...D].join(", ")}`
655
- );
656
- if (e.progress === null || typeof e.progress != "object" || Array.isArray(e.progress))
657
- throw new i(
658
- 'VP response validation failed: "progress" must be an object'
659
- );
660
- if (ve(e.progress), typeof e.health_info != "string")
661
- throw new i(
662
- 'VP response validation failed: "health_info" must be a string'
663
- );
664
- if (e.last_error !== void 0 && typeof e.last_error != "string")
665
- throw new i(
666
- `VP response validation failed: "last_error" must be a string if present, got ${o(e.last_error)}`
667
- );
668
- }
669
- function xe(n) {
670
- if (n === null || typeof n != "object")
671
- throw new i(
672
- "VP response validation failed: requestDepositorPresignTransactions response is not an object"
673
- );
674
- const e = n;
675
- if (!Array.isArray(e.txs))
676
- throw new i(
677
- 'VP response validation failed: "txs" must be an array'
678
- );
679
- for (let t = 0; t < e.txs.length; t++)
680
- Ae(e.txs[t], `txs[${t}]`);
681
- if (e.depositor_graph === null || typeof e.depositor_graph != "object")
682
- throw new i(
683
- 'VP response validation failed: "depositor_graph" must be an object'
684
- );
685
- Se(
686
- e.depositor_graph
687
- );
688
- }
689
- function m(n, e) {
690
- if (n === null || typeof n != "object")
691
- throw new i(
692
- `VP response validation failed: "${e}" must be an object`
693
- );
694
- ee(n.tx_hex, `${e}.tx_hex`);
695
- }
696
- function Ae(n, e) {
697
- if (n === null || typeof n != "object")
698
- throw new i(
699
- `VP response validation failed: "${e}" must be an object`
700
- );
701
- const t = n;
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
- }
704
- function Ve(n, e) {
705
- if (n === null || typeof n != "object")
706
- throw new i(
707
- `VP response validation failed: "${e}" must be an object`
708
- );
709
- const t = n;
710
- w(t.wots_pks_json, `${e}.wots_pks_json`), w(t.gc_wots_keys_json, `${e}.gc_wots_keys_json`);
711
- }
712
- function $e(n, e) {
713
- if (n === null || typeof n != "object")
714
- throw new i(
715
- `VP response validation failed: "${e}" must be an object`
716
- );
717
- const t = n;
718
- if (te(t.challenger_pubkey, `${e}.challenger_pubkey`), m(
719
- t.challenge_assert_x_tx,
720
- `${e}.challenge_assert_x_tx`
721
- ), m(
722
- t.challenge_assert_y_tx,
723
- `${e}.challenge_assert_y_tx`
724
- ), m(t.nopayout_tx, `${e}.nopayout_tx`), w(t.nopayout_psbt, `${e}.nopayout_psbt`), !Array.isArray(t.challenge_assert_connectors))
725
- throw new i(
726
- `VP response validation failed: "${e}.challenge_assert_connectors" must be an array`
727
- );
728
- for (let r = 0; r < t.challenge_assert_connectors.length; r++)
729
- Ve(
730
- t.challenge_assert_connectors[r],
731
- `${e}.challenge_assert_connectors[${r}]`
732
- );
733
- if (!Array.isArray(t.output_label_hashes))
734
- throw new i(
735
- `VP response validation failed: "${e}.output_label_hashes" must be an array`
736
- );
737
- for (let r = 0; r < t.output_label_hashes.length; r++)
738
- ee(
739
- t.output_label_hashes[r],
740
- `${e}.output_label_hashes[${r}]`
741
- );
742
- }
743
- function ke(n) {
744
- if (n === null || typeof n != "object")
745
- throw new i(
746
- "VP response validation failed: requestDepositorClaimerArtifacts response is not an object"
747
- );
748
- const e = n;
749
- if (!Z(e.tx_graph_json))
750
- throw new i(
751
- `VP response validation failed: "tx_graph_json" must be a non-empty string, got ${o(e.tx_graph_json)}`
752
- );
753
- if (!g(e.verifying_key_hex))
754
- throw new i(
755
- `VP response validation failed: "verifying_key_hex" must be a non-empty hex string, got ${o(e.verifying_key_hex)}`
756
- );
757
- if (e.babe_sessions === null || typeof e.babe_sessions != "object")
758
- throw new i(
759
- 'VP response validation failed: "babe_sessions" must be an object'
760
- );
761
- for (const [t, r] of Object.entries(
762
- e.babe_sessions
763
- )) {
764
- if (r === null || typeof r != "object")
765
- throw new i(
766
- `VP response validation failed: "babe_sessions.${t}" must be an object`
767
- );
768
- const a = r;
769
- if (!g(a.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(a.decryptor_artifacts_hex)}`
772
- );
773
- }
774
- }
775
- function Ce(n) {
776
- if (n === null || typeof n != "object")
777
- throw new i(
778
- "VP response validation failed: getPegoutStatus response is not an object"
779
- );
780
- const e = n;
781
- if (!g(e.pegin_txid) || e.pegin_txid.length !== x)
782
- throw new i(
783
- `VP response validation failed: "pegin_txid" must be a ${x}-char hex string (txid), got ${o(e.pegin_txid)}`
784
- );
785
- if (typeof e.found != "boolean")
786
- throw new i(
787
- `VP response validation failed: "found" must be a boolean, got ${o(e.found)}`
788
- );
789
- if (e.claimer !== void 0) {
790
- if (e.claimer === null || typeof e.claimer != "object")
791
- throw new i(
792
- 'VP response validation failed: "claimer" must be an object if present'
793
- );
794
- const t = e.claimer;
795
- if (typeof t.status != "string")
796
- throw new i(
797
- `VP response validation failed: "claimer.status" must be a string, got ${o(t.status)}`
798
- );
799
- if (typeof t.failed != "boolean")
800
- throw new i(
801
- `VP response validation failed: "claimer.failed" must be a boolean, got ${o(t.failed)}`
802
- );
803
- }
804
- if (e.challenger !== void 0) {
805
- if (e.challenger === null || typeof e.challenger != "object")
806
- throw new i(
807
- 'VP response validation failed: "challenger" must be an object if present'
808
- );
809
- const t = e.challenger;
810
- if (typeof t.status != "string")
811
- throw new i(
812
- `VP response validation failed: "challenger.status" must be a string, got ${o(t.status)}`
813
- );
814
- }
815
- }
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 i(
819
- 'VP response validation failed: "depositor_graph.challenger_presign_data" must be an array'
820
- );
821
- for (let e = 0; e < n.challenger_presign_data.length; e++)
822
- $e(
823
- n.challenger_presign_data[e],
824
- `depositor_graph.challenger_presign_data[${e}]`
825
- );
826
- if (typeof n.offchain_params_version != "number")
827
- throw new i(
828
- 'VP response validation failed: "depositor_graph.offchain_params_version" must be a number'
829
- );
830
- }
831
- const Ee = 6e4;
832
- class Ie {
833
- constructor(e, t) {
834
- l(this, "client");
835
- const r = {
836
- baseUrl: e,
837
- timeout: (t == null ? void 0 : t.timeout) ?? Ee,
838
- retries: t == null ? void 0 : t.retries,
839
- retryDelay: t == null ? void 0 : t.retryDelay,
840
- retryableFor: t == null ? void 0 : t.retryableFor,
841
- headers: t == null ? void 0 : t.headers,
842
- tokenProvider: t == null ? void 0 : t.tokenProvider,
843
- maxResponseBytes: t == null ? void 0 : t.maxResponseBytes
844
- };
845
- this.client = new G(r);
846
- }
847
- /**
848
- * Request the payout/claim/assert transactions that the depositor
849
- * needs to pre-sign before the vault can be activated on Bitcoin.
850
- */
851
- async requestDepositorPresignTransactions(e, t) {
852
- const r = await this.client.call("vaultProvider_requestDepositorPresignTransactions", e, t);
853
- return xe(r), r;
854
- }
855
- /**
856
- * Submit the depositor's pre-signatures for the payout transactions
857
- * and the depositor-as-claimer graph.
858
- */
859
- async submitDepositorPresignatures(e, t) {
860
- return this.client.call(
861
- "vaultProvider_submitDepositorPresignatures",
862
- e,
863
- t
864
- );
865
- }
866
- /**
867
- * Submit the depositor's WOTS public key to the vault provider.
868
- * Called after the pegin is finalized on Ethereum, when the VP is in
869
- * `PendingDepositorWotsPK` status.
870
- */
871
- async submitDepositorWotsKey(e, t) {
872
- return this.client.call(
873
- "vaultProvider_submitDepositorWotsKey",
874
- e,
875
- t
876
- );
877
- }
878
- /**
879
- * Request the BaBe DecryptorArtifacts needed for the depositor to
880
- * independently evaluate garbled circuits during a challenge.
881
- */
882
- async requestDepositorClaimerArtifacts(e, t) {
883
- const r = await this.client.call("vaultProvider_requestDepositorClaimerArtifacts", e, t);
884
- return ke(r), r;
885
- }
886
- /** Get the current pegin status from the vault provider daemon. */
887
- async getPeginStatus(e, t) {
888
- const r = await this.client.call(
889
- "vaultProvider_getPeginStatus",
890
- e,
891
- t
892
- );
893
- return Te(r), r;
894
- }
895
- /** Get the current pegout status from the vault provider daemon. */
896
- async getPegoutStatus(e, t) {
897
- const r = await this.client.call(
898
- "vaultProvider_getPegoutStatus",
899
- e,
900
- t
901
- );
902
- return Ce(r), r;
903
- }
904
- }
905
- const Be = "BIP0322-signed-message", Re = "TapTweak", ne = 32, Fe = 64;
906
- function re(n, e) {
907
- const t = new TextEncoder().encode(n), r = K(t), a = new Uint8Array(r.length * 2 + e.length);
908
- return a.set(r, 0), a.set(r, r.length), a.set(e, r.length * 2), K(a);
909
- }
910
- function Oe(n) {
911
- if (n.length !== ne) return null;
912
- const e = re(Re, n), t = $.xOnlyPointAddTweak(n, e);
913
- return t ? t.xOnlyPubkey : null;
914
- }
915
- function Ne(n, e, t) {
916
- if (e.length !== ne || t.length !== Fe) return !1;
917
- try {
918
- const r = re(Be, n), a = ye.p2tr({
919
- internalPubkey: y.from(e)
920
- });
921
- if (!a.output) return !1;
922
- const s = a.output, c = 0, d = new I();
923
- d.version = 0, d.locktime = 0;
924
- const S = y.concat([
925
- y.from([0, 32]),
926
- y.from(r)
927
- ]);
928
- d.addInput(
929
- y.alloc(32, 0),
930
- // prev_txid = 0x0000...0000
931
- 4294967295,
932
- // prev_vout = 0xFFFFFFFF
933
- 0,
934
- // sequence = 0
935
- S
936
- ), d.addOutput(s, c);
937
- const p = new I();
938
- p.version = 0, p.locktime = 0;
939
- const E = d.getHash();
940
- p.addInput(E, 0, 0), p.addOutput(y.from([106]), c);
941
- const N = p.hashForWitnessV1(
942
- 0,
943
- [s],
944
- [c],
945
- I.SIGHASH_DEFAULT
946
- ), H = Oe(e);
947
- return H ? $.verifySchnorr(N, H, t) : !1;
948
- } catch {
949
- return !1;
950
- }
951
- }
952
- function A(n, e) {
953
- const t = (n & 7) << 5, r = typeof e == "bigint" ? e : BigInt(e);
954
- if (r < 0n) throw new Error("cborHead: negative argument");
955
- if (r < 24n) return new Uint8Array([t | Number(r)]);
956
- if (r < 0x100n) return new Uint8Array([t | 24, Number(r)]);
957
- if (r < 0x10000n) {
958
- const s = Number(r);
959
- return new Uint8Array([t | 25, s >>> 8 & 255, s & 255]);
960
- }
961
- if (r < 0x100000000n) {
962
- const s = Number(r);
963
- return new Uint8Array([
964
- t | 26,
965
- s >>> 24 & 255,
966
- s >>> 16 & 255,
967
- s >>> 8 & 255,
968
- s & 255
969
- ]);
970
- }
971
- const a = new Uint8Array(9);
972
- a[0] = t | 27;
973
- for (let s = 7; s >= 0; s--)
974
- a[1 + s] = Number(r >> BigInt((7 - s) * 8)) & 255;
975
- return a;
976
- }
977
- function se(...n) {
978
- const e = n.reduce((a, s) => a + s.length, 0), t = new Uint8Array(e);
979
- let r = 0;
980
- for (const a of n)
981
- t.set(a, r), r += a.length;
982
- return t;
983
- }
984
- function j(n) {
985
- const t = [A(4, n.length)];
986
- for (const r of n)
987
- t.push(A(0, r));
988
- return se(...t);
989
- }
990
- function He(n, e, t) {
991
- if (!Number.isSafeInteger(t) || t < 0)
992
- throw new Error(
993
- `encodeServerIdentityPayload: expires_at must be a non-negative safe integer, got ${t}`
994
- );
995
- const r = A(4, 3), a = j(n), s = j(e), c = A(0, t);
996
- return se(r, a, s, c);
997
- }
998
- const Ke = new TextEncoder().encode(
999
- "btc-auth.server-identity.v1"
1000
- );
1001
- class u extends Error {
1002
- constructor(e, t) {
1003
- super(e), this.reason = t, this.name = "ServerIdentityError";
1004
- }
1005
- }
1006
- function P(n) {
1007
- const e = new Uint8Array(n.length / 2);
1008
- for (let t = 0; t < e.length; t++)
1009
- e[t] = parseInt(n.slice(t * 2, t * 2 + 2), 16);
1010
- return e;
1011
- }
1012
- function Ue(n) {
1013
- const { proof: e, pinnedServerPubkey: t, now: r } = n, a = _(t).toLowerCase();
1014
- if (a.length !== v || !f.test(a))
1015
- throw new u(
1016
- `pinnedServerPubkey must be 32-byte hex; got ${a.length} chars`,
1017
- "invalid_pubkey_encoding"
1018
- );
1019
- const s = _(e.server_pubkey).toLowerCase();
1020
- if (s.length !== v || !f.test(s))
1021
- throw new u(
1022
- `server_pubkey must be 32-byte hex; got ${s.length} chars`,
1023
- "invalid_pubkey_encoding"
1024
- );
1025
- if (s !== a)
1026
- throw new u(
1027
- `server_pubkey does not match pinned value: expected ${a}, got ${s}`,
1028
- "pinned_pubkey_mismatch"
1029
- );
1030
- if (!Number.isSafeInteger(e.expires_at))
1031
- throw new u(
1032
- `expires_at must be a finite integer; got ${JSON.stringify(e.expires_at)}`,
1033
- "invalid_expires_at"
1034
- );
1035
- if (!Number.isSafeInteger(r))
1036
- throw new u(
1037
- `now must be a finite integer; got ${JSON.stringify(r)}`,
1038
- "invalid_expires_at"
1039
- );
1040
- if (e.expires_at <= r)
1041
- throw new u(
1042
- `server identity proof expired at ${e.expires_at}, now ${r}`,
1043
- "expired"
1044
- );
1045
- const c = _(e.ephemeral_pubkey).toLowerCase();
1046
- if (c.length !== F || !f.test(c))
1047
- throw new u(
1048
- `ephemeral_pubkey must be 33-byte compressed hex; got ${c.length} chars`,
1049
- "invalid_ephemeral_pubkey"
1050
- );
1051
- const d = c.slice(0, 2);
1052
- if (d !== "02" && d !== "03")
1053
- throw new u(
1054
- `ephemeral_pubkey must be compressed (prefix 02/03); got ${d}`,
1055
- "invalid_ephemeral_pubkey"
1056
- );
1057
- const S = P(c);
1058
- if (!$.isPoint(S))
1059
- throw new u(
1060
- "ephemeral_pubkey is not a valid secp256k1 point",
1061
- "invalid_ephemeral_pubkey"
1062
- );
1063
- const p = _(e.signature).toLowerCase();
1064
- if (p.length !== he || !f.test(p))
1065
- throw new u(
1066
- `signature must be 64-byte Schnorr hex; got ${p.length} chars`,
1067
- "invalid_signature_encoding"
1068
- );
1069
- const E = He(
1070
- Ke,
1071
- P(c),
1072
- e.expires_at
1073
- );
1074
- if (!Ne(E, P(s), P(p)))
1075
- throw new u(
1076
- "BIP-322 signature verification failed — ephemeral key is not attested by pinned server pubkey",
1077
- "signature_verification_failed"
1078
- );
1079
- }
1080
- const De = /* @__PURE__ */ new Set([
1081
- "vaultProvider_submitDepositorWotsKey",
1082
- "vaultProvider_submitDepositorPresignatures",
1083
- "vaultProvider_requestDepositorPresignTransactions"
1084
- ]), je = 6e4, O = "auth_createDepositorToken";
1085
- function ae(n, e) {
1086
- return new G({
1087
- baseUrl: n,
1088
- timeout: je,
1089
- headers: e,
1090
- retryableFor: (t) => t === O
1091
- });
1092
- }
1093
- const M = 4102444800, Me = 30;
1094
- class Le {
1095
- constructor(e) {
1096
- // `client` is the only mutable field — see `setClient`. The
1097
- // identity-bearing fields (peginTxid/authAnchorHex/pinnedServerPubkey)
1098
- // remain readonly and are checked against re-registration in the
1099
- // registry's `getOrCreate`.
1100
- l(this, "client");
1101
- l(this, "peginTxid");
1102
- l(this, "authAnchorHex");
1103
- l(this, "pinnedServerPubkey");
1104
- l(this, "authGatedMethods");
1105
- l(this, "refreshSkewSecs");
1106
- l(this, "now");
1107
- l(this, "cached", null);
1108
- l(this, "inFlight", null);
1109
- 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));
1110
- }
1111
- /**
1112
- * Return a bearer token for `method`, or `null` if `method` is not
1113
- * auth-gated. Triggers a token acquisition if no token is cached or
1114
- * the cached token is within {@link refreshSkewSecs} of expiry.
1115
- *
1116
- * The token-issuing method itself is hard-exempted from the gate —
1117
- * if `auth_createDepositorToken` were ever included in
1118
- * `authGatedMethods` (caller misconfiguration) the provider would
1119
- * recurse into `acquireSingleFlight` from inside the JSON-RPC header
1120
- * builder before `inFlight` is assigned, defeating the single-flight
1121
- * guard. Returning `null` here breaks that recursion deterministically.
1122
- */
1123
- async getToken(e) {
1124
- if (e === O || !this.authGatedMethods.has(e)) return null;
1125
- const t = this.cached;
1126
- return t && this.now() + this.refreshSkewSecs < t.expiresAt ? t.token : (await this.acquireSingleFlight()).token;
1127
- }
1128
- /**
1129
- * Drop the cached token. Next `getToken` call re-acquires.
1130
- * Called by `JsonRpcClient` on wire `auth_expired` responses.
1131
- */
1132
- invalidate() {
1133
- this.cached = null;
1134
- }
1135
- /**
1136
- * Swap in a different transport for subsequent token-issuing calls.
1137
- * Used by the registry when a later caller registers the same
1138
- * `peginTxid` against a different `baseUrl` — the cached token
1139
- * (bound to identity, not transport) stays valid, but future
1140
- * refreshes hit the new URL. An in-flight acquire keeps using the
1141
- * old client (it captured the reference); next call uses the new.
1142
- */
1143
- setClient(e) {
1144
- this.client = e;
1145
- }
1146
- acquireSingleFlight() {
1147
- const e = this.inFlight;
1148
- if (e) return e;
1149
- const t = (async () => {
1150
- try {
1151
- const r = await this.client.call(O, {
1152
- pegin_txid: this.peginTxid,
1153
- auth_anchor: this.authAnchorHex
1154
- });
1155
- if (Ue({
1156
- proof: r.server_identity,
1157
- pinnedServerPubkey: this.pinnedServerPubkey,
1158
- now: this.now()
1159
- }), typeof r.token != "string" || r.token.length === 0)
1160
- throw new Error(
1161
- `VpTokenProvider: invalid token in acquire response (expected non-empty string, got ${typeof r.token})`
1162
- );
1163
- const a = this.now();
1164
- if (!Number.isSafeInteger(r.expires_at) || r.expires_at <= a || r.expires_at > M)
1165
- throw new Error(
1166
- `VpTokenProvider: invalid expires_at in acquire response (got ${JSON.stringify(r.expires_at)}; must be a safe integer in (${a}, ${M}])`
1167
- );
1168
- const s = {
1169
- token: r.token,
1170
- expiresAt: r.expires_at
1171
- };
1172
- return this.cached = s, s;
1173
- } finally {
1174
- this.inFlight = null;
1175
- }
1176
- })();
1177
- return this.inFlight = t, t;
1178
- }
1179
- }
1180
- class Xe {
1181
- constructor() {
1182
- l(this, "entries", /* @__PURE__ */ new Map());
1183
- }
1184
- /**
1185
- * Return the cached `VpTokenProvider` for `peginTxid` if one exists
1186
- * with matching `authAnchorHex` and `pinnedServerPubkey`, otherwise
1187
- * construct and cache a fresh provider. A mismatch on either field
1188
- * throws — silent overwrite would mask derivation drift or VP
1189
- * pubkey rotation.
1190
- */
1191
- getOrCreate(e) {
1192
- const t = this.entries.get(e.peginTxid);
1193
- if (t) {
1194
- if (t.authAnchorHex !== e.authAnchorHex)
1195
- throw new Error(
1196
- `VpTokenRegistry: peginTxid ${e.peginTxid} already bound to authAnchorHex ${t.authAnchorHex.slice(0, 8)}…; got ${e.authAnchorHex.slice(0, 8)}…`
1197
- );
1198
- if (t.pinnedServerPubkey !== e.pinnedServerPubkey)
1199
- throw new Error(
1200
- `VpTokenRegistry: peginTxid ${e.peginTxid} already bound to pinnedServerPubkey ${t.pinnedServerPubkey.slice(0, 8)}…; got ${e.pinnedServerPubkey.slice(0, 8)}…`
1201
- );
1202
- return t.provider.setClient(e.client), t.provider;
1203
- }
1204
- const r = new Le({
1205
- client: e.client,
1206
- peginTxid: e.peginTxid,
1207
- authAnchorHex: e.authAnchorHex,
1208
- pinnedServerPubkey: e.pinnedServerPubkey,
1209
- authGatedMethods: De
1210
- });
1211
- return this.entries.set(e.peginTxid, {
1212
- provider: r,
1213
- authAnchorHex: e.authAnchorHex,
1214
- pinnedServerPubkey: e.pinnedServerPubkey
1215
- }), r;
1216
- }
1217
- /** Return the cached provider, or `undefined` if none. */
1218
- peek(e) {
1219
- var t;
1220
- return (t = this.entries.get(e)) == null ? void 0 : t.provider;
1221
- }
1222
- /**
1223
- * Evict the entry for `peginTxid`. Idempotent. Called on terminal
1224
- * paths — activation success, user-cancel, or component unmount —
1225
- * so `authAnchorHex` doesn't outlive the deposit session.
1226
- */
1227
- release(e) {
1228
- this.entries.delete(e);
1229
- }
1230
- /**
1231
- * Wipe every cached entry. Test-only escape hatch — not exposed on
1232
- * the public {@link VpTokenRegistryPublic} singleton type.
1233
- *
1234
- * @internal
1235
- */
1236
- clear() {
1237
- this.entries.clear();
1238
- }
1239
- get size() {
1240
- return this.entries.size;
1241
- }
1242
- }
1243
- const ie = new Xe();
1244
- function it(n) {
1245
- var r;
1246
- const e = ae(
1247
- n.baseUrl,
1248
- (r = n.options) == null ? void 0 : r.headers
1249
- ), t = ie.getOrCreate({
1250
- client: e,
1251
- peginTxid: n.peginTxid,
1252
- authAnchorHex: n.authAnchorHex,
1253
- pinnedServerPubkey: n.pinnedServerPubkey
1254
- });
1255
- return new Ie(n.baseUrl, {
1256
- ...n.options,
1257
- tokenProvider: t
1258
- });
1259
- }
1260
- function ot(n) {
1261
- ie.getOrCreate({
1262
- client: ae(n.baseUrl, n.headers),
1263
- peginTxid: n.peginTxid,
1264
- authAnchorHex: n.authAnchorHex,
1265
- pinnedServerPubkey: n.pinnedServerPubkey
1266
- });
1267
- }
1268
- async function ct(n, e) {
1269
- const [t, r] = await n.multicall({
1270
- contracts: [
1271
- {
1272
- address: e,
1273
- abi: b,
1274
- functionName: "protocolParams"
1275
- },
1276
- {
1277
- address: e,
1278
- abi: b,
1279
- functionName: "applicationRegistry"
1280
- }
1281
- ],
1282
- allowFailure: !1
1283
- });
1284
- return {
1285
- protocolParams: t,
1286
- applicationRegistry: r
1287
- };
1288
- }
1289
- const L = 65535;
1290
- function R(n) {
1291
- return {
1292
- timelockAssert: n.timelockAssert,
1293
- timelockChallengeAssert: n.timelockChallengeAssert,
1294
- securityCouncilKeys: [...n.securityCouncilKeys],
1295
- councilQuorum: n.councilQuorum,
1296
- feeRate: n.feeRate,
1297
- babeTotalInstances: n.babeTotalInstances,
1298
- babeInstancesToFinalize: n.babeInstancesToFinalize,
1299
- minVpCommissionBps: n.minVpCommissionBps,
1300
- tRefund: n.tRefund,
1301
- tStale: n.tStale,
1302
- minPeginFeeRate: n.minPeginFeeRate,
1303
- proverProgramVersion: n.proverProgramVersion,
1304
- minPrepeginDepth: n.minPrepeginDepth
1305
- };
1306
- }
1307
- function X(n) {
1308
- return {
1309
- minimumPegInAmount: n.minimumPegInAmount,
1310
- maxPegInAmount: n.maxPegInAmount,
1311
- pegInAckTimeout: n.pegInAckTimeout,
1312
- pegInActivationTimeout: n.pegInActivationTimeout,
1313
- maxHtlcOutputCount: n.maxHtlcOutputCount
1314
- };
1315
- }
1316
- function q(n) {
1317
- if (n > BigInt(L))
1318
- throw new Error(
1319
- `timelockAssert value ${n} exceeds uint16 max (${L})`
1320
- );
1321
- return Number(n);
1322
- }
1323
- class lt {
1324
- constructor(e, t) {
1325
- this.publicClient = e, this.contractAddress = t;
1326
- }
1327
- async getTBVProtocolParams() {
1328
- const e = await this.publicClient.readContract({
1329
- address: this.contractAddress,
1330
- abi: h,
1331
- functionName: "getTBVProtocolParams"
1332
- });
1333
- return X(e);
1334
- }
1335
- async getLatestOffchainParams() {
1336
- const e = await this.publicClient.readContract({
1337
- address: this.contractAddress,
1338
- abi: h,
1339
- functionName: "getLatestOffchainParams"
1340
- });
1341
- return R(e);
1342
- }
1343
- async getOffchainParamsByVersion(e) {
1344
- const t = await this.publicClient.readContract({
1345
- address: this.contractAddress,
1346
- abi: h,
1347
- functionName: "getOffchainParamsByVersion",
1348
- args: [e]
1349
- });
1350
- return R(t);
1351
- }
1352
- async getLatestOffchainParamsVersion() {
1353
- return await this.publicClient.readContract({
1354
- address: this.contractAddress,
1355
- abi: h,
1356
- functionName: "latestOffchainParamsVersion"
1357
- });
1358
- }
1359
- async getTimelockPeginByVersion(e) {
1360
- const t = await this.getOffchainParamsByVersion(e);
1361
- return q(t.timelockAssert);
1362
- }
1363
- /**
1364
- * Read TBV protocol params and latest offchain params atomically via multicall.
1365
- * Prevents TOCTOU inconsistency if governance updates params between reads.
1366
- */
1367
- async getPegInConfiguration() {
1368
- const e = await this.publicClient.multicall({
1369
- contracts: [
1370
- {
1371
- address: this.contractAddress,
1372
- abi: h,
1373
- functionName: "getTBVProtocolParams"
1374
- },
1375
- {
1376
- address: this.contractAddress,
1377
- abi: h,
1378
- functionName: "getLatestOffchainParams"
1379
- }
1380
- ],
1381
- allowFailure: !1
1382
- }), t = X(e[0]), r = R(e[1]);
1383
- return {
1384
- minimumPegInAmount: t.minimumPegInAmount,
1385
- maxPegInAmount: t.maxPegInAmount,
1386
- pegInAckTimeout: t.pegInAckTimeout,
1387
- pegInActivationTimeout: t.pegInActivationTimeout,
1388
- maxHtlcOutputCount: t.maxHtlcOutputCount,
1389
- timelockPegin: q(r.timelockAssert),
1390
- timelockRefund: r.tRefund,
1391
- minVpCommissionBps: r.minVpCommissionBps,
1392
- offchainParams: r
1393
- };
1394
- }
1395
- }
1396
- function V(n) {
1397
- return n.map((e) => ({
1398
- ethAddress: e.ethAddress,
1399
- btcPubKey: e.btcPubKey
1400
- }));
1401
- }
1402
- class ut {
1403
- constructor(e, t) {
1404
- this.publicClient = e, this.contractAddress = t;
1405
- }
1406
- async getVaultKeepersByVersion(e, t) {
1407
- const r = await this.publicClient.readContract({
1408
- address: this.contractAddress,
1409
- abi: B,
1410
- functionName: "getVaultKeepersByVersion",
1411
- args: [e, t]
1412
- });
1413
- return V(r);
1414
- }
1415
- async getCurrentVaultKeepers(e) {
1416
- const t = await this.publicClient.readContract({
1417
- address: this.contractAddress,
1418
- abi: B,
1419
- functionName: "getCurrentVaultKeepers",
1420
- args: [e]
1421
- });
1422
- return V(t);
1423
- }
1424
- async getCurrentVaultKeepersVersion(e) {
1425
- return await this.publicClient.readContract({
1426
- address: this.contractAddress,
1427
- abi: B,
1428
- functionName: "getCurrentVaultKeepersVersion",
1429
- args: [e]
1430
- });
1431
- }
1432
- }
1433
- class pt {
1434
- constructor(e, t) {
1435
- this.publicClient = e, this.contractAddress = t;
1436
- }
1437
- async getUniversalChallengersByVersion(e) {
1438
- const t = await this.publicClient.readContract({
1439
- address: this.contractAddress,
1440
- abi: h,
1441
- functionName: "getUniversalChallengersByVersion",
1442
- args: [e]
1443
- });
1444
- return V(t);
1445
- }
1446
- async getCurrentUniversalChallengers() {
1447
- const e = await this.publicClient.readContract({
1448
- address: this.contractAddress,
1449
- abi: h,
1450
- functionName: "getCurrentUniversalChallengers"
1451
- });
1452
- return V(e);
1453
- }
1454
- async getLatestUniversalChallengersVersion() {
1455
- return await this.publicClient.readContract({
1456
- address: this.contractAddress,
1457
- abi: h,
1458
- functionName: "latestUniversalChallengersVersion"
1459
- });
1460
- }
1461
- }
1462
- class dt {
1463
- constructor(e, t) {
1464
- this.publicClient = e, this.contractAddress = t;
1465
- }
1466
- /**
1467
- * Read the VP's persistent x-only BTC pubkey from the on-chain
1468
- * registry. Validates length, hex form, and secp256k1 curve
1469
- * membership before minting the brand. Returns 64-char lowercase
1470
- * hex without the `0x` prefix.
1471
- */
1472
- async getVaultProviderBtcPubKey(e) {
1473
- const r = (await this.publicClient.readContract({
1474
- address: this.contractAddress,
1475
- abi: b,
1476
- functionName: "getVaultProviderBTCKey",
1477
- args: [e]
1478
- })).toLowerCase();
1479
- if (!/^0x[0-9a-f]{64}$/.test(r))
1480
- throw new Error(
1481
- `getVaultProviderBTCKey returned an unexpected value (vp=${e}, length ${r.length}, prefix "${r.slice(0, 2)}")`
1482
- );
1483
- const a = r.slice(2);
1484
- if (!$.isXOnlyPoint(me(a)))
1485
- throw new Error(
1486
- `getVaultProviderBTCKey returned a value that is not on the secp256k1 curve (vp=${e})`
1487
- );
1488
- return a;
1489
- }
1490
- async getVaultBasicInfo(e) {
1491
- const t = await this.publicClient.readContract({
1492
- address: this.contractAddress,
1493
- abi: b,
1494
- functionName: "getBtcVaultBasicInfo",
1495
- args: [e]
1496
- });
1497
- return {
1498
- depositor: t.depositor,
1499
- depositorBtcPubKey: t.depositorBtcPubKey,
1500
- amount: t.amount,
1501
- vaultProvider: t.vaultProvider,
1502
- status: t.status,
1503
- applicationEntryPoint: t.applicationEntryPoint,
1504
- createdAt: t.createdAt
1505
- };
1506
- }
1507
- async getVaultProtocolInfo(e) {
1508
- const t = await this.publicClient.readContract({
1509
- address: this.contractAddress,
1510
- abi: b,
1511
- functionName: "getBtcVaultProtocolInfo",
1512
- args: [e]
1513
- });
1514
- return {
1515
- depositorSignedPeginTx: t.depositorSignedPeginTx,
1516
- universalChallengersVersion: t.universalChallengersVersion,
1517
- appVaultKeepersVersion: t.appVaultKeepersVersion,
1518
- offchainParamsVersion: t.offchainParamsVersion,
1519
- verifiedAt: t.verifiedAt,
1520
- depositorWotsPkHash: t.depositorWotsPkHash,
1521
- hashlock: t.hashlock,
1522
- htlcVout: t.htlcVout,
1523
- depositorPopSignature: t.depositorPopSignature,
1524
- prePeginTxHash: t.prePeginTxHash,
1525
- vaultProviderCommissionBps: t.vaultProviderCommissionBps
1526
- };
1527
- }
1528
- async getVaultData(e) {
1529
- const [t, r] = await Promise.all([
1530
- this.getVaultBasicInfo(e),
1531
- this.getVaultProtocolInfo(e)
1532
- ]);
1533
- if (!r.depositorSignedPeginTx || r.depositorSignedPeginTx === "0x")
1534
- throw new Error(
1535
- `Vault ${e} not found on-chain or has no pegin transaction`
1536
- );
1537
- return { basic: t, protocol: r };
1538
- }
1539
- }
1540
- export {
1541
- B as A,
1542
- be as M,
1543
- h as P,
1544
- u as S,
1545
- Ie as V,
1546
- nt as a,
1547
- rt as b,
1548
- at as c,
1549
- et as d,
1550
- we as e,
1551
- tt as f,
1552
- st as g,
1553
- i as h,
1554
- Ue as i,
1555
- Xe as j,
1556
- ie as k,
1557
- it as l,
1558
- ot as m,
1559
- lt as n,
1560
- pt as o,
1561
- Ze as p,
1562
- ut as q,
1563
- ct as r,
1564
- dt as s,
1565
- ke as v
1566
- };
1567
- //# sourceMappingURL=vault-registry-reader-CWGbw_wZ.js.map