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