@bind-protocol/sdk 0.7.0 → 0.9.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/README.md +7 -11
- package/dist/{adapter-Cl7HtxU3.d.ts → adapter-J6D9MZJV.d.ts} +2 -2
- package/dist/{adapter-zyYSX6_e.d.cts → adapter-qe9f1ll3.d.cts} +2 -2
- package/dist/adapters/dimo/index.d.cts +3 -3
- package/dist/adapters/dimo/index.d.ts +3 -3
- package/dist/adapters/index.cjs +113 -137
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +4 -4
- package/dist/adapters/index.d.ts +4 -4
- package/dist/adapters/index.js +113 -137
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/zktls/index.cjs +113 -137
- package/dist/adapters/zktls/index.cjs.map +1 -1
- package/dist/adapters/zktls/index.d.cts +3 -3
- package/dist/adapters/zktls/index.d.ts +3 -3
- package/dist/adapters/zktls/index.js +113 -137
- package/dist/adapters/zktls/index.js.map +1 -1
- package/dist/{client-CadOSqx6.d.ts → client-CfYXpFLk.d.cts} +70 -32
- package/dist/{client-BkohyCGJ.d.cts → client-CpJ87Xe0.d.ts} +70 -32
- package/dist/core/index.cjs +107 -124
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +2 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +107 -124
- package/dist/core/index.js.map +1 -1
- package/dist/index.cjs +113 -137
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +113 -137
- package/dist/index.js.map +1 -1
- package/dist/{types-Cz9q5U3r.d.cts → types-BcPssdQk.d.cts} +32 -174
- package/dist/{types-Cz9q5U3r.d.ts → types-BcPssdQk.d.ts} +32 -174
- package/dist/{types-Ca_xbN13.d.ts → types-D7Q7ymPa.d.ts} +1 -1
- package/dist/{types-DAN8BlbI.d.cts → types-ywkMNwun.d.cts} +1 -1
- package/package.json +1 -1
package/dist/core/index.cjs
CHANGED
|
@@ -98,33 +98,42 @@ var BindClient = class {
|
|
|
98
98
|
* @throws {InsufficientCreditsError} If there aren't enough credits
|
|
99
99
|
*/
|
|
100
100
|
async submitProveJob(circuitId, inputs, options) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
101
|
+
try {
|
|
102
|
+
return await this.fetchJson("/api/prove", {
|
|
103
|
+
method: "POST",
|
|
104
|
+
body: JSON.stringify({
|
|
105
|
+
circuitId,
|
|
106
|
+
inputs,
|
|
107
|
+
verificationMode: options?.verificationMode
|
|
108
|
+
})
|
|
109
|
+
});
|
|
110
|
+
} catch (err) {
|
|
111
|
+
if (err instanceof ApiError && err.response) {
|
|
112
|
+
const body = err.response;
|
|
113
|
+
if (body.requiredCredits !== void 0 && body.availableCredits !== void 0) {
|
|
114
|
+
throw new InsufficientCreditsError(
|
|
115
|
+
body.requiredCredits,
|
|
116
|
+
body.availableCredits
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
throw err;
|
|
112
121
|
}
|
|
113
|
-
return result;
|
|
114
122
|
}
|
|
115
123
|
/**
|
|
116
124
|
* Get the status and results of a prove job
|
|
117
125
|
* @param jobId - The unique job identifier
|
|
118
126
|
* @returns The job details including status and outputs
|
|
127
|
+
* @throws {ApiError} If the API request fails
|
|
119
128
|
*/
|
|
120
129
|
async getProveJob(jobId) {
|
|
121
|
-
|
|
122
|
-
return response.json();
|
|
130
|
+
return this.fetchJson(`/api/prove/${encodeURIComponent(jobId)}`);
|
|
123
131
|
}
|
|
124
132
|
/**
|
|
125
133
|
* List prove jobs for the authenticated organization
|
|
126
134
|
* @param options - Optional filters for status, limit, and offset
|
|
127
135
|
* @returns Paginated list of prove jobs
|
|
136
|
+
* @throws {ApiError} If the API request fails
|
|
128
137
|
*/
|
|
129
138
|
async listProveJobs(options = {}) {
|
|
130
139
|
const params = new URLSearchParams();
|
|
@@ -133,8 +142,7 @@ var BindClient = class {
|
|
|
133
142
|
if (options.offset !== void 0) params.set("offset", options.offset.toString());
|
|
134
143
|
const queryString = params.toString();
|
|
135
144
|
const path = queryString ? `/api/prove?${queryString}` : "/api/prove";
|
|
136
|
-
|
|
137
|
-
return response.json();
|
|
145
|
+
return this.fetchJson(path);
|
|
138
146
|
}
|
|
139
147
|
/**
|
|
140
148
|
* Poll for prove job completion
|
|
@@ -142,21 +150,14 @@ var BindClient = class {
|
|
|
142
150
|
* @param options - Polling options
|
|
143
151
|
* @returns The completed or failed job
|
|
144
152
|
* @throws {TimeoutError} If the job doesn't complete within the timeout
|
|
153
|
+
* @throws {ApiError} If the API request fails
|
|
145
154
|
*/
|
|
146
155
|
async waitForProveJob(jobId, options = {}) {
|
|
147
156
|
const intervalMs = options.intervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
148
157
|
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
149
158
|
const startTime = Date.now();
|
|
150
159
|
while (Date.now() - startTime < timeoutMs) {
|
|
151
|
-
const
|
|
152
|
-
if (!result.success || !result.data) {
|
|
153
|
-
throw new ApiError(
|
|
154
|
-
result.error || "Failed to get prove job",
|
|
155
|
-
500,
|
|
156
|
-
result
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
const job = result.data;
|
|
160
|
+
const job = await this.getProveJob(jobId);
|
|
160
161
|
if (options.onProgress) {
|
|
161
162
|
options.onProgress(job);
|
|
162
163
|
}
|
|
@@ -176,41 +177,28 @@ var BindClient = class {
|
|
|
176
177
|
/**
|
|
177
178
|
* List all available public policies
|
|
178
179
|
* @returns Array of public policy specifications
|
|
180
|
+
* @throws {ApiError} If the API request fails
|
|
179
181
|
*/
|
|
180
182
|
async listPolicies() {
|
|
181
|
-
|
|
182
|
-
method: "GET"
|
|
183
|
-
});
|
|
184
|
-
if (!response.ok) {
|
|
185
|
-
throw new ApiError(
|
|
186
|
-
`Failed to fetch policies: ${response.statusText}`,
|
|
187
|
-
response.status
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
const json = await response.json();
|
|
191
|
-
return json.data ?? json;
|
|
183
|
+
return this.fetchJson("/api/policies");
|
|
192
184
|
}
|
|
193
185
|
/**
|
|
194
186
|
* Get a specific policy by ID
|
|
195
187
|
* @param policyId - The unique policy identifier
|
|
196
188
|
* @returns The public policy specification, or null if not found
|
|
189
|
+
* @throws {ApiError} If the API request fails (except 404)
|
|
197
190
|
*/
|
|
198
191
|
async getPolicy(policyId) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
);
|
|
203
|
-
if (response.status === 404) {
|
|
204
|
-
return null;
|
|
205
|
-
}
|
|
206
|
-
if (!response.ok) {
|
|
207
|
-
throw new ApiError(
|
|
208
|
-
`Failed to fetch policy: ${response.statusText}`,
|
|
209
|
-
response.status
|
|
192
|
+
try {
|
|
193
|
+
return await this.fetchJson(
|
|
194
|
+
`/api/policies/${encodeURIComponent(policyId)}`
|
|
210
195
|
);
|
|
196
|
+
} catch (err) {
|
|
197
|
+
if (err instanceof ApiError && err.status === 404) {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
throw err;
|
|
211
201
|
}
|
|
212
|
-
const json = await response.json();
|
|
213
|
-
return json.data ?? json;
|
|
214
202
|
}
|
|
215
203
|
// ==========================================================================
|
|
216
204
|
// zkTLS Methods
|
|
@@ -218,49 +206,49 @@ var BindClient = class {
|
|
|
218
206
|
/**
|
|
219
207
|
* List available zkTLS extractors (data sources)
|
|
220
208
|
* @returns Array of available extractors
|
|
209
|
+
* @throws {ApiError} If the API request fails
|
|
221
210
|
*/
|
|
222
211
|
async listExtractors() {
|
|
223
|
-
|
|
224
|
-
return response.json();
|
|
212
|
+
return this.fetchJson("/api/zktls/extractors");
|
|
225
213
|
}
|
|
226
214
|
/**
|
|
227
215
|
* List zkTLS attestations for the authenticated organization
|
|
228
216
|
* @returns Array of attestations
|
|
217
|
+
* @throws {ApiError} If the API request fails
|
|
229
218
|
*/
|
|
230
219
|
async listAttestations() {
|
|
231
|
-
|
|
232
|
-
return response.json();
|
|
220
|
+
return this.fetchJson("/api/zktls/attestations");
|
|
233
221
|
}
|
|
234
222
|
/**
|
|
235
223
|
* Get a specific attestation by ID
|
|
236
224
|
* @param attestationId - The attestation UUID
|
|
237
|
-
* @returns The attestation
|
|
225
|
+
* @returns The attestation details
|
|
226
|
+
* @throws {ApiError} If the API request fails
|
|
238
227
|
*/
|
|
239
228
|
async getAttestation(attestationId) {
|
|
240
|
-
|
|
241
|
-
return response.json();
|
|
229
|
+
return this.fetchJson(`/api/zktls/attestations/${encodeURIComponent(attestationId)}`);
|
|
242
230
|
}
|
|
243
231
|
/**
|
|
244
232
|
* Create a new zkTLS session for data attestation
|
|
245
233
|
* @param extractorId - The extractor to use (e.g., "coinbase")
|
|
246
234
|
* @param callbackUrl - URL to redirect to after authentication
|
|
247
235
|
* @returns Session ID and auth URL to redirect user to
|
|
236
|
+
* @throws {ApiError} If the API request fails
|
|
248
237
|
*/
|
|
249
238
|
async createZkTlsSession(extractorId, callbackUrl) {
|
|
250
|
-
|
|
239
|
+
return this.fetchJson("/api/zktls/sessions", {
|
|
251
240
|
method: "POST",
|
|
252
241
|
body: JSON.stringify({ extractor: extractorId, callbackUrl })
|
|
253
242
|
});
|
|
254
|
-
return response.json();
|
|
255
243
|
}
|
|
256
244
|
/**
|
|
257
245
|
* Get the status of a zkTLS session
|
|
258
246
|
* @param sessionId - The session UUID
|
|
259
247
|
* @returns Session status and attestation if completed
|
|
248
|
+
* @throws {ApiError} If the API request fails
|
|
260
249
|
*/
|
|
261
250
|
async getZkTlsSession(sessionId) {
|
|
262
|
-
|
|
263
|
-
return response.json();
|
|
251
|
+
return this.fetchJson(`/api/zktls/sessions/${encodeURIComponent(sessionId)}`);
|
|
264
252
|
}
|
|
265
253
|
/**
|
|
266
254
|
* Wait for a zkTLS session to complete
|
|
@@ -270,21 +258,14 @@ var BindClient = class {
|
|
|
270
258
|
* @throws {ZkTlsSessionExpiredError} If session expires
|
|
271
259
|
* @throws {ZkTlsSessionFailedError} If session fails
|
|
272
260
|
* @throws {TimeoutError} If timeout is reached
|
|
261
|
+
* @throws {ApiError} If the API request fails
|
|
273
262
|
*/
|
|
274
263
|
async waitForZkTlsSession(sessionId, options = {}) {
|
|
275
264
|
const intervalMs = options.intervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
276
265
|
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
277
266
|
const startTime = Date.now();
|
|
278
267
|
while (Date.now() - startTime < timeoutMs) {
|
|
279
|
-
const
|
|
280
|
-
if (!result.success || !result.data) {
|
|
281
|
-
throw new ApiError(
|
|
282
|
-
result.error || "Failed to get zkTLS session",
|
|
283
|
-
500,
|
|
284
|
-
result
|
|
285
|
-
);
|
|
286
|
-
}
|
|
287
|
-
const session = result.data;
|
|
268
|
+
const session = await this.getZkTlsSession(sessionId);
|
|
288
269
|
if (options.onProgress) {
|
|
289
270
|
options.onProgress(session);
|
|
290
271
|
}
|
|
@@ -311,6 +292,7 @@ var BindClient = class {
|
|
|
311
292
|
* List available circuits
|
|
312
293
|
* @param options - Optional filters
|
|
313
294
|
* @returns Array of circuits
|
|
295
|
+
* @throws {ApiError} If the API request fails
|
|
314
296
|
*/
|
|
315
297
|
async listCircuits(options = {}) {
|
|
316
298
|
const params = new URLSearchParams();
|
|
@@ -318,28 +300,27 @@ var BindClient = class {
|
|
|
318
300
|
if (options.policyId) params.set("policyId", options.policyId);
|
|
319
301
|
const queryString = params.toString();
|
|
320
302
|
const path = queryString ? `/api/circuits?${queryString}` : "/api/circuits";
|
|
321
|
-
|
|
322
|
-
return response.json();
|
|
303
|
+
return this.fetchJson(path);
|
|
323
304
|
}
|
|
324
305
|
/**
|
|
325
306
|
* Get a specific circuit by ID
|
|
326
307
|
* @param circuitId - The circuit identifier
|
|
327
|
-
* @returns The circuit details
|
|
308
|
+
* @returns The circuit details
|
|
309
|
+
* @throws {ApiError} If the API request fails
|
|
328
310
|
*/
|
|
329
311
|
async getCircuit(circuitId) {
|
|
330
|
-
|
|
331
|
-
return response.json();
|
|
312
|
+
return this.fetchJson(`/api/circuits/${encodeURIComponent(circuitId)}`);
|
|
332
313
|
}
|
|
333
314
|
/**
|
|
334
315
|
* Activate a circuit (requires validation to have passed)
|
|
335
316
|
* @param circuitId - The circuit identifier to activate
|
|
336
317
|
* @returns The activation result
|
|
318
|
+
* @throws {ApiError} If the API request fails
|
|
337
319
|
*/
|
|
338
320
|
async activateCircuit(circuitId) {
|
|
339
|
-
|
|
321
|
+
return this.fetchJson(`/api/circuits/${encodeURIComponent(circuitId)}/activate`, {
|
|
340
322
|
method: "POST"
|
|
341
323
|
});
|
|
342
|
-
return response.json();
|
|
343
324
|
}
|
|
344
325
|
// ==========================================================================
|
|
345
326
|
// Shared Proof Methods
|
|
@@ -348,18 +329,19 @@ var BindClient = class {
|
|
|
348
329
|
* Share a completed proof with a verifier organization
|
|
349
330
|
* @param request - Share proof request with proveJobId and verifierOrgId
|
|
350
331
|
* @returns The created shared proof
|
|
332
|
+
* @throws {ApiError} If the API request fails
|
|
351
333
|
*/
|
|
352
334
|
async shareProof(request) {
|
|
353
|
-
|
|
335
|
+
return this.fetchJson("/api/shared-proofs", {
|
|
354
336
|
method: "POST",
|
|
355
337
|
body: JSON.stringify(request)
|
|
356
338
|
});
|
|
357
|
-
return response.json();
|
|
358
339
|
}
|
|
359
340
|
/**
|
|
360
341
|
* List shared proofs (outgoing or incoming)
|
|
361
342
|
* @param options - Filter by direction, pagination, and inclusion options
|
|
362
343
|
* @returns Paginated list of shared proofs
|
|
344
|
+
* @throws {ApiError} If the API request fails
|
|
363
345
|
*/
|
|
364
346
|
async listSharedProofs(options = {}) {
|
|
365
347
|
const params = new URLSearchParams();
|
|
@@ -370,28 +352,27 @@ var BindClient = class {
|
|
|
370
352
|
if (options.includeRevoked) params.set("includeRevoked", "true");
|
|
371
353
|
const queryString = params.toString();
|
|
372
354
|
const path = queryString ? `/api/shared-proofs?${queryString}` : "/api/shared-proofs";
|
|
373
|
-
|
|
374
|
-
return response.json();
|
|
355
|
+
return this.fetchJson(path);
|
|
375
356
|
}
|
|
376
357
|
/**
|
|
377
358
|
* Get a specific shared proof by ID
|
|
378
359
|
* @param sharedProofId - The shared proof ID
|
|
379
360
|
* @returns The shared proof details
|
|
361
|
+
* @throws {ApiError} If the API request fails
|
|
380
362
|
*/
|
|
381
363
|
async getSharedProof(sharedProofId) {
|
|
382
|
-
|
|
383
|
-
return response.json();
|
|
364
|
+
return this.fetchJson(`/api/shared-proofs/${encodeURIComponent(sharedProofId)}`);
|
|
384
365
|
}
|
|
385
366
|
/**
|
|
386
367
|
* Revoke a shared proof. Only the sharing organization can revoke.
|
|
387
368
|
* @param sharedProofId - The shared proof ID to revoke
|
|
388
369
|
* @returns The revocation result
|
|
370
|
+
* @throws {ApiError} If the API request fails
|
|
389
371
|
*/
|
|
390
372
|
async revokeSharedProof(sharedProofId) {
|
|
391
|
-
|
|
373
|
+
return this.fetchJson(`/api/shared-proofs/${encodeURIComponent(sharedProofId)}`, {
|
|
392
374
|
method: "DELETE"
|
|
393
375
|
});
|
|
394
|
-
return response.json();
|
|
395
376
|
}
|
|
396
377
|
// ==========================================================================
|
|
397
378
|
// Verification Methods
|
|
@@ -405,83 +386,70 @@ var BindClient = class {
|
|
|
405
386
|
* @param sharedProofId - The shared proof ID to verify
|
|
406
387
|
* @param options - Optional polling configuration
|
|
407
388
|
* @returns The verification result
|
|
389
|
+
* @throws {ApiError} If the API request fails
|
|
390
|
+
* @throws {TimeoutError} If verification doesn't complete within the timeout
|
|
408
391
|
*/
|
|
409
392
|
async verifySharedProof(sharedProofId, options) {
|
|
410
|
-
const
|
|
411
|
-
const
|
|
412
|
-
const
|
|
393
|
+
const intervalMs = options?.intervalMs ?? 1e3;
|
|
394
|
+
const timeoutMs = options?.timeoutMs ?? 12e4;
|
|
395
|
+
const queueResult = await this.fetchJson(`/api/verify/shared/${encodeURIComponent(sharedProofId)}`, {
|
|
413
396
|
method: "POST"
|
|
414
397
|
});
|
|
415
|
-
const
|
|
416
|
-
if (!queueResult.success || !queueResult.data?.jobId) {
|
|
417
|
-
return {
|
|
418
|
-
success: false,
|
|
419
|
-
error: queueResult.error ?? "Failed to queue verification job"
|
|
420
|
-
};
|
|
421
|
-
}
|
|
422
|
-
const jobId = queueResult.data.jobId;
|
|
398
|
+
const jobId = queueResult.jobId;
|
|
423
399
|
const startTime = Date.now();
|
|
424
|
-
while (Date.now() - startTime <
|
|
400
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
425
401
|
const statusResult = await this.getVerifyJobStatus(jobId);
|
|
426
|
-
if (
|
|
402
|
+
if (statusResult.status === "completed" || statusResult.status === "failed") {
|
|
427
403
|
return {
|
|
428
|
-
|
|
429
|
-
error: statusResult.error
|
|
404
|
+
isValid: statusResult.isValid ?? false,
|
|
405
|
+
error: statusResult.error,
|
|
406
|
+
verificationTimeMs: statusResult.verificationTimeMs ?? 0,
|
|
407
|
+
creditsCharged: statusResult.creditsCharged ?? queueResult.creditsCharged,
|
|
408
|
+
verificationResultId: statusResult.verificationResultId ?? jobId,
|
|
409
|
+
publicInputs: statusResult.publicInputs
|
|
430
410
|
};
|
|
431
411
|
}
|
|
432
|
-
|
|
433
|
-
if (status === "completed" || status === "failed") {
|
|
434
|
-
return {
|
|
435
|
-
success: true,
|
|
436
|
-
data: {
|
|
437
|
-
isValid: statusResult.data?.isValid ?? false,
|
|
438
|
-
error: statusResult.data?.error,
|
|
439
|
-
verificationTimeMs: statusResult.data?.verificationTimeMs ?? 0,
|
|
440
|
-
creditsCharged: statusResult.data?.creditsCharged ?? queueResult.data.creditsCharged,
|
|
441
|
-
verificationResultId: statusResult.data?.verificationResultId ?? jobId
|
|
442
|
-
}
|
|
443
|
-
};
|
|
444
|
-
}
|
|
445
|
-
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
|
412
|
+
await this.sleep(intervalMs);
|
|
446
413
|
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
414
|
+
throw new TimeoutError(
|
|
415
|
+
`Verification timed out after ${timeoutMs}ms. Job ID: ${jobId}`,
|
|
416
|
+
timeoutMs
|
|
417
|
+
);
|
|
451
418
|
}
|
|
452
419
|
/**
|
|
453
420
|
* Get the status of a verification job
|
|
454
421
|
* @param jobId - The verification job ID
|
|
455
|
-
* @returns The job status
|
|
422
|
+
* @returns The job status data
|
|
423
|
+
* @throws {ApiError} If the API request fails
|
|
456
424
|
*/
|
|
457
425
|
async getVerifyJobStatus(jobId) {
|
|
458
|
-
|
|
459
|
-
return response.json();
|
|
426
|
+
return this.fetchJson(`/api/verify/jobs/${encodeURIComponent(jobId)}`);
|
|
460
427
|
}
|
|
461
428
|
/**
|
|
462
429
|
* Verify an uploaded proof
|
|
463
430
|
* @param proofBuffer - The proof binary as ArrayBuffer, Uint8Array, or Buffer
|
|
464
431
|
* @param vkBuffer - The verification key binary as ArrayBuffer, Uint8Array, or Buffer
|
|
465
432
|
* @returns The verification result
|
|
433
|
+
* @throws {ApiError} If the API request fails
|
|
466
434
|
*/
|
|
467
435
|
async verifyUploadedProof(proofBuffer, vkBuffer) {
|
|
468
436
|
const proofBytes = proofBuffer instanceof Uint8Array ? proofBuffer : new Uint8Array(proofBuffer);
|
|
469
437
|
const vkBytes = vkBuffer instanceof Uint8Array ? vkBuffer : new Uint8Array(vkBuffer);
|
|
470
438
|
const proofBase64 = typeof Buffer !== "undefined" ? Buffer.from(proofBytes).toString("base64") : btoa(String.fromCharCode(...proofBytes));
|
|
471
439
|
const vkBase64 = typeof Buffer !== "undefined" ? Buffer.from(vkBytes).toString("base64") : btoa(String.fromCharCode(...vkBytes));
|
|
472
|
-
|
|
440
|
+
return this.fetchJson("/api/verify/upload", {
|
|
473
441
|
method: "POST",
|
|
474
442
|
body: JSON.stringify({
|
|
475
443
|
proof: proofBase64,
|
|
476
444
|
vk: vkBase64
|
|
477
445
|
})
|
|
478
446
|
});
|
|
479
|
-
return response.json();
|
|
480
447
|
}
|
|
481
448
|
/**
|
|
482
449
|
* Get verification history for the authenticated organization
|
|
483
450
|
* @param options - Pagination options
|
|
484
451
|
* @returns Paginated list of verification results
|
|
452
|
+
* @throws {ApiError} If the API request fails
|
|
485
453
|
*/
|
|
486
454
|
async getVerificationHistory(options = {}) {
|
|
487
455
|
const params = new URLSearchParams();
|
|
@@ -489,8 +457,7 @@ var BindClient = class {
|
|
|
489
457
|
if (options.offset !== void 0) params.set("offset", options.offset.toString());
|
|
490
458
|
const queryString = params.toString();
|
|
491
459
|
const path = queryString ? `/api/verify/history?${queryString}` : "/api/verify/history";
|
|
492
|
-
|
|
493
|
-
return response.json();
|
|
460
|
+
return this.fetchJson(path);
|
|
494
461
|
}
|
|
495
462
|
// ==========================================================================
|
|
496
463
|
// Private Helpers
|
|
@@ -506,8 +473,24 @@ var BindClient = class {
|
|
|
506
473
|
if (response.status === 401) {
|
|
507
474
|
throw new AuthenticationError();
|
|
508
475
|
}
|
|
476
|
+
if (!response.ok) {
|
|
477
|
+
const body = await response.json().catch(() => ({}));
|
|
478
|
+
throw new ApiError(
|
|
479
|
+
body.error || `HTTP ${response.status}: ${response.statusText}`,
|
|
480
|
+
response.status,
|
|
481
|
+
body
|
|
482
|
+
);
|
|
483
|
+
}
|
|
509
484
|
return response;
|
|
510
485
|
}
|
|
486
|
+
async fetchJson(path, init) {
|
|
487
|
+
const response = await this.fetch(path, init);
|
|
488
|
+
const json = await response.json();
|
|
489
|
+
if (json.success === false) {
|
|
490
|
+
throw new ApiError(json.error || "Request failed", response.status, json);
|
|
491
|
+
}
|
|
492
|
+
return json.data ?? json;
|
|
493
|
+
}
|
|
511
494
|
sleep(ms) {
|
|
512
495
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
513
496
|
}
|
package/d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CAAM,CAAA,EAAG,KAAK,OAAO,CAAA,EAAG,IAAI,CAAA,CAAA,EAAI;AAAA,MACrD,GAAG,IAAA;AAAA,MACH,OAAA,EAAS;AAAA,QACP,GAAG,IAAA,CAAK,OAAA;AAAA,QACR,GAAG,IAAA,EAAM;AAAA;AACX,KACD,CAAA;AAED,IAAA,IAAI,QAAA,CAAS,WAAW,GAAA,EAAK;AAC3B,MAAA,MAAM,IAAI,mBAAA,EAAoB;AAAA,IAChC;AAEA,IAAA,OAAO,QAAA;AAAA,EACT;AAAA,EAEQ,MAAM,EAAA,EAA2B;AACvC,IAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,YAAY,UAAA,CAAW,OAAA,EAAS,EAAE,CAAC,CAAA;AAAA,EACzD;AACF","file":"index.cjs","sourcesContent":["/**\n * Custom error classes for the Bind Protocol SDK\n */\n\nexport class BindError extends Error {\n constructor(\n message: string,\n public readonly code: string,\n public readonly details?: Record<string, unknown>\n ) {\n super(message);\n this.name = 'BindError';\n }\n}\n\nexport class ApiError extends BindError {\n constructor(\n message: string,\n public readonly status: number,\n public readonly response?: unknown\n ) {\n super(message, 'API_ERROR', { status, response });\n this.name = 'ApiError';\n }\n}\n\nexport class AuthenticationError extends BindError {\n constructor(message = 'Authentication failed') {\n super(message, 'AUTH_ERROR');\n this.name = 'AuthenticationError';\n }\n}\n\nexport class TimeoutError extends BindError {\n constructor(message: string, public readonly timeoutMs: number) {\n super(message, 'TIMEOUT_ERROR', { timeoutMs });\n this.name = 'TimeoutError';\n }\n}\n\nexport class InsufficientCreditsError extends BindError {\n constructor(\n public readonly required: number,\n public readonly available: number\n ) {\n super(\n `Insufficient credits: need ${required}, have ${available}`,\n 'INSUFFICIENT_CREDITS',\n { required, available }\n );\n this.name = 'InsufficientCreditsError';\n }\n}\n\n/**\n * Thrown when a zkTLS session expires before completion\n */\nexport class ZkTlsSessionExpiredError extends BindError {\n constructor(public readonly sessionId: string) {\n super(`zkTLS session expired: ${sessionId}`, 'ZKTLS_SESSION_EXPIRED', { sessionId });\n this.name = 'ZkTlsSessionExpiredError';\n }\n}\n\n/**\n * Thrown when a zkTLS session fails\n */\nexport class ZkTlsSessionFailedError extends BindError {\n constructor(\n public readonly sessionId: string,\n public readonly sessionError: string\n ) {\n super(`zkTLS session failed: ${sessionError}`, 'ZKTLS_SESSION_FAILED', { sessionId, sessionError });\n this.name = 'ZkTlsSessionFailedError';\n }\n}\n\n/**\n * Thrown when an extractor is not found or disabled\n */\nexport class ZkTlsExtractorError extends BindError {\n constructor(\n public readonly extractorId: string,\n message: string\n ) {\n super(message, 'ZKTLS_EXTRACTOR_ERROR', { extractorId });\n this.name = 'ZkTlsExtractorError';\n }\n}\n","/**\n * BindClient - Main client for interacting with the Bind Protocol API\n */\nimport type { PublicPolicySpec } from '@bind-protocol/policy-spec';\nimport {\n ApiError,\n AuthenticationError,\n InsufficientCreditsError,\n TimeoutError,\n ZkTlsSessionExpiredError,\n ZkTlsSessionFailedError,\n} from './errors';\nimport type {\n BindClientOptions,\n ProveJobInputs,\n SubmitProveJobResponse,\n GetProveJobResponse,\n ListProveJobsOptions,\n ListProveJobsResponse,\n ProveJob,\n VerificationMode,\n ListExtractorsResponse,\n ListAttestationsResponse,\n GetAttestationResponse,\n CreateSessionResponse,\n GetSessionResponse,\n ZkTlsSession,\n Circuit,\n ListCircuitsResponse,\n GetCircuitResponse,\n ActivateCircuitResponse,\n ShareProofRequest,\n ShareProofResponse,\n ListSharedProofsOptions,\n ListSharedProofsResponse,\n GetSharedProofResponse,\n RevokeSharedProofResponse,\n VerifySharedProofResponse,\n VerifyJobQueuedResponse,\n VerifyJobStatusResponse,\n VerifyUploadedProofResponse,\n GetVerificationHistoryOptions,\n GetVerificationHistoryResponse,\n} from './types';\n\nconst DEFAULT_BASE_URL = 'https://api.bindprotocol.com';\nconst DEFAULT_POLL_INTERVAL_MS = 2000;\nconst DEFAULT_TIMEOUT_MS = 300000; // 5 minutes\n\n/**\n * Derive a circuit ID from policy ID and version\n * This matches the server's auto-generation logic.\n * Format: {policyId}.v{version} with version dots replaced by underscores\n *\n * @example\n * deriveCircuitId(\"bind.demo.credit-score\", \"0.1.0\")\n * // Returns: \"bind.demo.credit-score.v0_1_0\"\n */\nexport function deriveCircuitId(policyId: string, version: string): string {\n const sanitizedVersion = version.replace(/\\./g, '_');\n return `${policyId}.v${sanitizedVersion}`;\n}\n\nexport class BindClient {\n private readonly apiKey: string;\n private readonly baseUrl: string;\n private readonly headers: Record<string, string>;\n\n constructor(options: BindClientOptions) {\n this.apiKey = options.apiKey;\n this.baseUrl = options.baseUrl || process.env.BIND_API_URL || DEFAULT_BASE_URL;\n this.headers = {\n 'X-API-Key': this.apiKey,\n 'Content-Type': 'application/json',\n };\n }\n\n // ==========================================================================\n // Prove Job Methods\n // ==========================================================================\n\n /**\n * Submit a prove job for async processing\n * @param circuitId - The circuit identifier (e.g., \"bind.mobility.riskband.v1\")\n * @param inputs - Circuit inputs as key-value pairs (all values must be strings)\n * @param options - Optional configuration including verificationMode\n * @returns The submitted job details\n * @throws {ApiError} If the API request fails\n * @throws {InsufficientCreditsError} If there aren't enough credits\n */\n async submitProveJob(\n circuitId: string,\n inputs: ProveJobInputs,\n options?: {\n /**\n * How to verify the proof:\n * - 'zkverify': Submit to zkVerify blockchain (default if zkVerify is enabled)\n * - 'self_verify': Store in S3, client downloads and verifies locally\n */\n verificationMode?: VerificationMode;\n }\n ): Promise<SubmitProveJobResponse> {\n const response = await this.fetch('/api/prove', {\n method: 'POST',\n body: JSON.stringify({\n circuitId,\n inputs,\n verificationMode: options?.verificationMode,\n }),\n });\n\n const result: SubmitProveJobResponse = await response.json();\n\n // Check for insufficient credits\n if (!result.success && result.requiredCredits !== undefined && result.availableCredits !== undefined) {\n throw new InsufficientCreditsError(result.requiredCredits, result.availableCredits);\n }\n\n return result;\n }\n\n /**\n * Get the status and results of a prove job\n * @param jobId - The unique job identifier\n * @returns The job details including status and outputs\n */\n async getProveJob(jobId: string): Promise<GetProveJobResponse> {\n const response = await this.fetch(`/api/prove/${encodeURIComponent(jobId)}`);\n return response.json();\n }\n\n /**\n * List prove jobs for the authenticated organization\n * @param options - Optional filters for status, limit, and offset\n * @returns Paginated list of prove jobs\n */\n async listProveJobs(options: ListProveJobsOptions = {}): Promise<ListProveJobsResponse> {\n const params = new URLSearchParams();\n if (options.status) params.set('status', options.status);\n if (options.limit !== undefined) params.set('limit', options.limit.toString());\n if (options.offset !== undefined) params.set('offset', options.offset.toString());\n\n const queryString = params.toString();\n const path = queryString ? `/api/prove?${queryString}` : '/api/prove';\n\n const response = await this.fetch(path);\n return response.json();\n }\n\n /**\n * Poll for prove job completion\n * @param jobId - The unique job identifier\n * @param options - Polling options\n * @returns The completed or failed job\n * @throws {TimeoutError} If the job doesn't complete within the timeout\n */\n async waitForProveJob(\n jobId: string,\n options: {\n intervalMs?: number;\n timeoutMs?: number;\n onProgress?: (job: ProveJob) => void;\n } = {}\n ): Promise<ProveJob> {\n const intervalMs = options.intervalMs ?? DEFAULT_POLL_INTERVAL_MS;\n const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const startTime = Date.now();\n\n while (Date.now() - startTime < timeoutMs) {\n const result = await this.getProveJob(jobId);\n\n if (!result.success || !result.data) {\n throw new ApiError(\n result.error || 'Failed to get prove job',\n 500,\n result\n );\n }\n\n const job = result.data;\n\n if (options.onProgress) {\n options.onProgress(job);\n }\n\n if (job.status === 'completed' || job.status === 'failed') {\n return job;\n }\n\n await this.sleep(intervalMs);\n }\n\n throw new TimeoutError(\n `Timeout waiting for prove job ${jobId} after ${timeoutMs}ms`,\n timeoutMs\n );\n }\n\n // ==========================================================================\n // Policy Methods (Public, no authentication required)\n // ==========================================================================\n\n /**\n * List all available public policies\n * @returns Array of public policy specifications\n */\n async listPolicies(): Promise<PublicPolicySpec[]> {\n const response = await fetch(`${this.baseUrl}/api/policies`, {\n method: 'GET',\n });\n\n if (!response.ok) {\n throw new ApiError(\n `Failed to fetch policies: ${response.statusText}`,\n response.status\n );\n }\n\n const json = await response.json();\n // API wraps response in { success, data }\n return json.data ?? json;\n }\n\n /**\n * Get a specific policy by ID\n * @param policyId - The unique policy identifier\n * @returns The public policy specification, or null if not found\n */\n async getPolicy(policyId: string): Promise<PublicPolicySpec | null> {\n const response = await fetch(\n `${this.baseUrl}/api/policies/${encodeURIComponent(policyId)}`,\n { method: 'GET' }\n );\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new ApiError(\n `Failed to fetch policy: ${response.statusText}`,\n response.status\n );\n }\n\n const json = await response.json();\n // API wraps response in { success, data }\n return json.data ?? json;\n }\n\n // ==========================================================================\n // zkTLS Methods\n // ==========================================================================\n\n /**\n * List available zkTLS extractors (data sources)\n * @returns Array of available extractors\n */\n async listExtractors(): Promise<ListExtractorsResponse> {\n const response = await this.fetch('/api/zktls/extractors');\n return response.json();\n }\n\n /**\n * List zkTLS attestations for the authenticated organization\n * @returns Array of attestations\n */\n async listAttestations(): Promise<ListAttestationsResponse> {\n const response = await this.fetch('/api/zktls/attestations');\n return response.json();\n }\n\n /**\n * Get a specific attestation by ID\n * @param attestationId - The attestation UUID\n * @returns The attestation or null if not found\n */\n async getAttestation(attestationId: string): Promise<GetAttestationResponse> {\n const response = await this.fetch(`/api/zktls/attestations/${encodeURIComponent(attestationId)}`);\n return response.json();\n }\n\n /**\n * Create a new zkTLS session for data attestation\n * @param extractorId - The extractor to use (e.g., \"coinbase\")\n * @param callbackUrl - URL to redirect to after authentication\n * @returns Session ID and auth URL to redirect user to\n */\n async createZkTlsSession(\n extractorId: string,\n callbackUrl: string\n ): Promise<CreateSessionResponse> {\n const response = await this.fetch('/api/zktls/sessions', {\n method: 'POST',\n body: JSON.stringify({ extractor: extractorId, callbackUrl }),\n });\n return response.json();\n }\n\n /**\n * Get the status of a zkTLS session\n * @param sessionId - The session UUID\n * @returns Session status and attestation if completed\n */\n async getZkTlsSession(sessionId: string): Promise<GetSessionResponse> {\n const response = await this.fetch(`/api/zktls/sessions/${encodeURIComponent(sessionId)}`);\n return response.json();\n }\n\n /**\n * Wait for a zkTLS session to complete\n * @param sessionId - The session UUID\n * @param options - Polling options\n * @returns The completed session with attestation\n * @throws {ZkTlsSessionExpiredError} If session expires\n * @throws {ZkTlsSessionFailedError} If session fails\n * @throws {TimeoutError} If timeout is reached\n */\n async waitForZkTlsSession(\n sessionId: string,\n options: {\n intervalMs?: number;\n timeoutMs?: number;\n onProgress?: (session: ZkTlsSession) => void;\n } = {}\n ): Promise<ZkTlsSession> {\n const intervalMs = options.intervalMs ?? DEFAULT_POLL_INTERVAL_MS;\n const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const startTime = Date.now();\n\n while (Date.now() - startTime < timeoutMs) {\n const result = await this.getZkTlsSession(sessionId);\n\n if (!result.success || !result.data) {\n throw new ApiError(\n result.error || 'Failed to get zkTLS session',\n 500,\n result\n );\n }\n\n const session = result.data;\n\n if (options.onProgress) {\n options.onProgress(session);\n }\n\n if (session.status === 'completed') {\n return session;\n }\n\n if (session.status === 'failed') {\n throw new ZkTlsSessionFailedError(sessionId, session.error || 'Unknown error');\n }\n\n if (session.status === 'expired') {\n throw new ZkTlsSessionExpiredError(sessionId);\n }\n\n await this.sleep(intervalMs);\n }\n\n throw new TimeoutError(\n `Timeout waiting for zkTLS session ${sessionId} after ${timeoutMs}ms`,\n timeoutMs\n );\n }\n\n // ==========================================================================\n // Circuit Methods\n // ==========================================================================\n\n /**\n * List available circuits\n * @param options - Optional filters\n * @returns Array of circuits\n */\n async listCircuits(options: { status?: 'active' | 'all'; policyId?: string } = {}): Promise<ListCircuitsResponse> {\n const params = new URLSearchParams();\n if (options.status) params.set('status', options.status);\n if (options.policyId) params.set('policyId', options.policyId);\n\n const queryString = params.toString();\n const path = queryString ? `/api/circuits?${queryString}` : '/api/circuits';\n\n const response = await this.fetch(path);\n return response.json();\n }\n\n /**\n * Get a specific circuit by ID\n * @param circuitId - The circuit identifier\n * @returns The circuit details or null if not found\n */\n async getCircuit(circuitId: string): Promise<GetCircuitResponse> {\n const response = await this.fetch(`/api/circuits/${encodeURIComponent(circuitId)}`);\n return response.json();\n }\n\n /**\n * Activate a circuit (requires validation to have passed)\n * @param circuitId - The circuit identifier to activate\n * @returns The activation result\n */\n async activateCircuit(circuitId: string): Promise<ActivateCircuitResponse> {\n const response = await this.fetch(`/api/circuits/${encodeURIComponent(circuitId)}/activate`, {\n method: 'POST',\n });\n return response.json();\n }\n\n // ==========================================================================\n // Shared Proof Methods\n // ==========================================================================\n\n /**\n * Share a completed proof with a verifier organization\n * @param request - Share proof request with proveJobId and verifierOrgId\n * @returns The created shared proof\n */\n async shareProof(request: ShareProofRequest): Promise<ShareProofResponse> {\n const response = await this.fetch('/api/shared-proofs', {\n method: 'POST',\n body: JSON.stringify(request),\n });\n return response.json();\n }\n\n /**\n * List shared proofs (outgoing or incoming)\n * @param options - Filter by direction, pagination, and inclusion options\n * @returns Paginated list of shared proofs\n */\n async listSharedProofs(options: ListSharedProofsOptions = {}): Promise<ListSharedProofsResponse> {\n const params = new URLSearchParams();\n if (options.direction) params.set('direction', options.direction);\n if (options.limit !== undefined) params.set('limit', options.limit.toString());\n if (options.offset !== undefined) params.set('offset', options.offset.toString());\n if (options.includeExpired) params.set('includeExpired', 'true');\n if (options.includeRevoked) params.set('includeRevoked', 'true');\n\n const queryString = params.toString();\n const path = queryString ? `/api/shared-proofs?${queryString}` : '/api/shared-proofs';\n\n const response = await this.fetch(path);\n return response.json();\n }\n\n /**\n * Get a specific shared proof by ID\n * @param sharedProofId - The shared proof ID\n * @returns The shared proof details\n */\n async getSharedProof(sharedProofId: string): Promise<GetSharedProofResponse> {\n const response = await this.fetch(`/api/shared-proofs/${encodeURIComponent(sharedProofId)}`);\n return response.json();\n }\n\n /**\n * Revoke a shared proof. Only the sharing organization can revoke.\n * @param sharedProofId - The shared proof ID to revoke\n * @returns The revocation result\n */\n async revokeSharedProof(sharedProofId: string): Promise<RevokeSharedProofResponse> {\n const response = await this.fetch(`/api/shared-proofs/${encodeURIComponent(sharedProofId)}`, {\n method: 'DELETE',\n });\n return response.json();\n }\n\n // ==========================================================================\n // Verification Methods\n // ==========================================================================\n\n /**\n * Verify a shared proof\n *\n * This method queues a verification job and polls until completion.\n * Verification is performed asynchronously by the prover worker.\n *\n * @param sharedProofId - The shared proof ID to verify\n * @param options - Optional polling configuration\n * @returns The verification result\n */\n async verifySharedProof(\n sharedProofId: string,\n options?: { pollIntervalMs?: number; maxWaitMs?: number }\n ): Promise<VerifySharedProofResponse> {\n const pollIntervalMs = options?.pollIntervalMs ?? 1000;\n const maxWaitMs = options?.maxWaitMs ?? 120000; // 2 minutes default\n\n // Queue the verification job\n const queueResponse = await this.fetch(`/api/verify/shared/${encodeURIComponent(sharedProofId)}`, {\n method: 'POST',\n });\n const queueResult: VerifyJobQueuedResponse = await queueResponse.json();\n\n if (!queueResult.success || !queueResult.data?.jobId) {\n return {\n success: false,\n error: queueResult.error ?? 'Failed to queue verification job',\n };\n }\n\n const jobId = queueResult.data.jobId;\n const startTime = Date.now();\n\n // Poll until completion or timeout\n while (Date.now() - startTime < maxWaitMs) {\n const statusResult = await this.getVerifyJobStatus(jobId);\n\n if (!statusResult.success) {\n return {\n success: false,\n error: statusResult.error ?? 'Failed to get verification status',\n };\n }\n\n const status = statusResult.data?.status;\n\n if (status === 'completed' || status === 'failed') {\n // Verification is done\n return {\n success: true,\n data: {\n isValid: statusResult.data?.isValid ?? false,\n error: statusResult.data?.error,\n verificationTimeMs: statusResult.data?.verificationTimeMs ?? 0,\n creditsCharged: statusResult.data?.creditsCharged ?? queueResult.data.creditsCharged,\n verificationResultId: statusResult.data?.verificationResultId ?? jobId,\n },\n };\n }\n\n // Wait before polling again\n await new Promise(resolve => setTimeout(resolve, pollIntervalMs));\n }\n\n // Timeout\n return {\n success: false,\n error: `Verification timed out after ${maxWaitMs}ms. Job ID: ${jobId}`,\n };\n }\n\n /**\n * Get the status of a verification job\n * @param jobId - The verification job ID\n * @returns The job status\n */\n async getVerifyJobStatus(jobId: string): Promise<VerifyJobStatusResponse> {\n const response = await this.fetch(`/api/verify/jobs/${encodeURIComponent(jobId)}`);\n return response.json();\n }\n\n /**\n * Verify an uploaded proof\n * @param proofBuffer - The proof binary as ArrayBuffer, Uint8Array, or Buffer\n * @param vkBuffer - The verification key binary as ArrayBuffer, Uint8Array, or Buffer\n * @returns The verification result\n */\n async verifyUploadedProof(\n proofBuffer: ArrayBuffer | Uint8Array,\n vkBuffer: ArrayBuffer | Uint8Array\n ): Promise<VerifyUploadedProofResponse> {\n // Convert to Uint8Array if needed\n const proofBytes = proofBuffer instanceof Uint8Array\n ? proofBuffer\n : new Uint8Array(proofBuffer);\n const vkBytes = vkBuffer instanceof Uint8Array\n ? vkBuffer\n : new Uint8Array(vkBuffer);\n\n // Convert to base64\n const proofBase64 = typeof Buffer !== 'undefined'\n ? Buffer.from(proofBytes).toString('base64')\n : btoa(String.fromCharCode(...proofBytes));\n const vkBase64 = typeof Buffer !== 'undefined'\n ? Buffer.from(vkBytes).toString('base64')\n : btoa(String.fromCharCode(...vkBytes));\n\n const response = await this.fetch('/api/verify/upload', {\n method: 'POST',\n body: JSON.stringify({\n proof: proofBase64,\n vk: vkBase64,\n }),\n });\n return response.json();\n }\n\n /**\n * Get verification history for the authenticated organization\n * @param options - Pagination options\n * @returns Paginated list of verification results\n */\n async getVerificationHistory(options: GetVerificationHistoryOptions = {}): Promise<GetVerificationHistoryResponse> {\n const params = new URLSearchParams();\n if (options.limit !== undefined) params.set('limit', options.limit.toString());\n if (options.offset !== undefined) params.set('offset', options.offset.toString());\n\n const queryString = params.toString();\n const path = queryString ? `/api/verify/history?${queryString}` : '/api/verify/history';\n\n const response = await this.fetch(path);\n return response.json();\n }\n\n // ==========================================================================\n // Private Helpers\n // ==========================================================================\n\n private async fetch(path: string, init?: RequestInit): Promise<Response> {\n const response = await fetch(`${this.baseUrl}${path}`, {\n ...init,\n headers: {\n ...this.headers,\n ...init?.headers,\n },\n });\n\n if (response.status === 401) {\n throw new AuthenticationError();\n }\n\n return response;\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/core/errors.ts","../../src/core/client.ts"],"names":[],"mappings":";;;AAIO,IAAM,SAAA,GAAN,cAAwB,KAAA,CAAM;AAAA,EACnC,WAAA,CACE,OAAA,EACgB,IAAA,EACA,OAAA,EAChB;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AAHG,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AACA,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAGhB,IAAA,IAAA,CAAK,IAAA,GAAO,WAAA;AAAA,EACd;AACF;AAEO,IAAM,QAAA,GAAN,cAAuB,SAAA,CAAU;AAAA,EACtC,WAAA,CACE,OAAA,EACgB,MAAA,EACA,QAAA,EAChB;AACA,IAAA,KAAA,CAAM,OAAA,EAAS,WAAA,EAAa,EAAE,MAAA,EAAQ,UAAU,CAAA;AAHhC,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AACA,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AAGhB,IAAA,IAAA,CAAK,IAAA,GAAO,UAAA;AAAA,EACd;AACF;AAEO,IAAM,mBAAA,GAAN,cAAkC,SAAA,CAAU;AAAA,EACjD,WAAA,CAAY,UAAU,uBAAA,EAAyB;AAC7C,IAAA,KAAA,CAAM,SAAS,YAAY,CAAA;AAC3B,IAAA,IAAA,CAAK,IAAA,GAAO,qBAAA;AAAA,EACd;AACF;AAEO,IAAM,YAAA,GAAN,cAA2B,SAAA,CAAU;AAAA,EAC1C,WAAA,CAAY,SAAiC,SAAA,EAAmB;AAC9D,IAAA,KAAA,CAAM,OAAA,EAAS,eAAA,EAAiB,EAAE,SAAA,EAAW,CAAA;AADF,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA;AAE3C,IAAA,IAAA,CAAK,IAAA,GAAO,cAAA;AAAA,EACd;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A,IAAQ,IAAA;AAAA,EACvB;AAAA,EAEQ,MAAM,EAAA,EAA2B;AACvC,IAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,YAAY,UAAA,CAAW,OAAA,EAAS,EAAE,CAAC,CAAA;AAAA,EACzD;AACF","file":"index.cjs","sourcesContent":["/**\n * Custom error classes for the Bind Protocol SDK\n */\n\nexport class BindError extends Error {\n constructor(\n message: string,\n public readonly code: string,\n public readonly details?: Record<string, unknown>\n ) {\n super(message);\n this.name = 'BindError';\n }\n}\n\nexport class ApiError extends BindError {\n constructor(\n message: string,\n public readonly status: number,\n public readonly response?: unknown\n ) {\n super(message, 'API_ERROR', { status, response });\n this.name = 'ApiError';\n }\n}\n\nexport class AuthenticationError extends BindError {\n constructor(message = 'Authentication failed') {\n super(message, 'AUTH_ERROR');\n this.name = 'AuthenticationError';\n }\n}\n\nexport class TimeoutError extends BindError {\n constructor(message: string, public readonly timeoutMs: number) {\n super(message, 'TIMEOUT_ERROR', { timeoutMs });\n this.name = 'TimeoutError';\n }\n}\n\nexport class InsufficientCreditsError extends BindError {\n constructor(\n public readonly required: number,\n public readonly available: number\n ) {\n super(\n `Insufficient credits: need ${required}, have ${available}`,\n 'INSUFFICIENT_CREDITS',\n { required, available }\n );\n this.name = 'InsufficientCreditsError';\n }\n}\n\n/**\n * Thrown when a zkTLS session expires before completion\n */\nexport class ZkTlsSessionExpiredError extends BindError {\n constructor(public readonly sessionId: string) {\n super(`zkTLS session expired: ${sessionId}`, 'ZKTLS_SESSION_EXPIRED', { sessionId });\n this.name = 'ZkTlsSessionExpiredError';\n }\n}\n\n/**\n * Thrown when a zkTLS session fails\n */\nexport class ZkTlsSessionFailedError extends BindError {\n constructor(\n public readonly sessionId: string,\n public readonly sessionError: string\n ) {\n super(`zkTLS session failed: ${sessionError}`, 'ZKTLS_SESSION_FAILED', { sessionId, sessionError });\n this.name = 'ZkTlsSessionFailedError';\n }\n}\n\n/**\n * Thrown when an extractor is not found or disabled\n */\nexport class ZkTlsExtractorError extends BindError {\n constructor(\n public readonly extractorId: string,\n message: string\n ) {\n super(message, 'ZKTLS_EXTRACTOR_ERROR', { extractorId });\n this.name = 'ZkTlsExtractorError';\n }\n}\n","/**\n * BindClient - Main client for interacting with the Bind Protocol API\n */\nimport type { PublicPolicySpec } from '@bind-protocol/policy-spec';\nimport {\n ApiError,\n AuthenticationError,\n InsufficientCreditsError,\n TimeoutError,\n ZkTlsSessionExpiredError,\n ZkTlsSessionFailedError,\n} from './errors';\nimport type {\n BindClientOptions,\n ProveJobInputs,\n ListProveJobsOptions,\n ProveJob,\n ProveJobSummary,\n SubmitProveJobResult,\n VerificationMode,\n ZkTlsExtractor,\n ZkTlsAttestation,\n ZkTlsSession,\n Circuit,\n ActivateCircuitResult,\n ShareProofRequest,\n SharedProof,\n ListSharedProofsOptions,\n RevokeSharedProofResult,\n VerificationResult,\n VerificationHistoryEntry,\n GetVerificationHistoryOptions,\n Pagination,\n PollOptions,\n VerifyJobStatus,\n} from './types';\n\nconst DEFAULT_BASE_URL = 'https://api.bindprotocol.com';\nconst DEFAULT_POLL_INTERVAL_MS = 2000;\nconst DEFAULT_TIMEOUT_MS = 300000; // 5 minutes\n\n/**\n * Derive a circuit ID from policy ID and version\n * This matches the server's auto-generation logic.\n * Format: {policyId}.v{version} with version dots replaced by underscores\n *\n * @example\n * deriveCircuitId(\"bind.demo.credit-score\", \"0.1.0\")\n * // Returns: \"bind.demo.credit-score.v0_1_0\"\n */\nexport function deriveCircuitId(policyId: string, version: string): string {\n const sanitizedVersion = version.replace(/\\./g, '_');\n return `${policyId}.v${sanitizedVersion}`;\n}\n\nexport class BindClient {\n private readonly apiKey: string;\n private readonly baseUrl: string;\n private readonly headers: Record<string, string>;\n\n constructor(options: BindClientOptions) {\n this.apiKey = options.apiKey;\n this.baseUrl = options.baseUrl || process.env.BIND_API_URL || DEFAULT_BASE_URL;\n this.headers = {\n 'X-API-Key': this.apiKey,\n 'Content-Type': 'application/json',\n };\n }\n\n // ==========================================================================\n // Prove Job Methods\n // ==========================================================================\n\n /**\n * Submit a prove job for async processing\n * @param circuitId - The circuit identifier (e.g., \"bind.mobility.riskband.v1\")\n * @param inputs - Circuit inputs as key-value pairs (all values must be strings)\n * @param options - Optional configuration including verificationMode\n * @returns The submitted job details\n * @throws {ApiError} If the API request fails\n * @throws {InsufficientCreditsError} If there aren't enough credits\n */\n async submitProveJob(\n circuitId: string,\n inputs: ProveJobInputs,\n options?: {\n /**\n * How to verify the proof:\n * - 'zkverify': Submit to zkVerify blockchain (default if zkVerify is enabled)\n * - 'self_verify': Store in S3, client downloads and verifies locally\n */\n verificationMode?: VerificationMode;\n }\n ): Promise<SubmitProveJobResult> {\n try {\n return await this.fetchJson<SubmitProveJobResult>('/api/prove', {\n method: 'POST',\n body: JSON.stringify({\n circuitId,\n inputs,\n verificationMode: options?.verificationMode,\n }),\n });\n } catch (err) {\n if (err instanceof ApiError && err.response) {\n const body = err.response as Record<string, unknown>;\n if (body.requiredCredits !== undefined && body.availableCredits !== undefined) {\n throw new InsufficientCreditsError(\n body.requiredCredits as number,\n body.availableCredits as number\n );\n }\n }\n throw err;\n }\n }\n\n /**\n * Get the status and results of a prove job\n * @param jobId - The unique job identifier\n * @returns The job details including status and outputs\n * @throws {ApiError} If the API request fails\n */\n async getProveJob(jobId: string): Promise<ProveJob> {\n return this.fetchJson<ProveJob>(`/api/prove/${encodeURIComponent(jobId)}`);\n }\n\n /**\n * List prove jobs for the authenticated organization\n * @param options - Optional filters for status, limit, and offset\n * @returns Paginated list of prove jobs\n * @throws {ApiError} If the API request fails\n */\n async listProveJobs(options: ListProveJobsOptions = {}): Promise<{ jobs: ProveJobSummary[]; pagination: Pagination }> {\n const params = new URLSearchParams();\n if (options.status) params.set('status', options.status);\n if (options.limit !== undefined) params.set('limit', options.limit.toString());\n if (options.offset !== undefined) params.set('offset', options.offset.toString());\n\n const queryString = params.toString();\n const path = queryString ? `/api/prove?${queryString}` : '/api/prove';\n\n return this.fetchJson<{ jobs: ProveJobSummary[]; pagination: Pagination }>(path);\n }\n\n /**\n * Poll for prove job completion\n * @param jobId - The unique job identifier\n * @param options - Polling options\n * @returns The completed or failed job\n * @throws {TimeoutError} If the job doesn't complete within the timeout\n * @throws {ApiError} If the API request fails\n */\n async waitForProveJob(\n jobId: string,\n options: PollOptions & { onProgress?: (job: ProveJob) => void } = {}\n ): Promise<ProveJob> {\n const intervalMs = options.intervalMs ?? DEFAULT_POLL_INTERVAL_MS;\n const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const startTime = Date.now();\n\n while (Date.now() - startTime < timeoutMs) {\n const job = await this.getProveJob(jobId);\n\n if (options.onProgress) {\n options.onProgress(job);\n }\n\n if (job.status === 'completed' || job.status === 'failed') {\n return job;\n }\n\n await this.sleep(intervalMs);\n }\n\n throw new TimeoutError(\n `Timeout waiting for prove job ${jobId} after ${timeoutMs}ms`,\n timeoutMs\n );\n }\n\n // ==========================================================================\n // Policy Methods (Public, no authentication required)\n // ==========================================================================\n\n /**\n * List all available public policies\n * @returns Array of public policy specifications\n * @throws {ApiError} If the API request fails\n */\n async listPolicies(): Promise<PublicPolicySpec[]> {\n return this.fetchJson<PublicPolicySpec[]>('/api/policies');\n }\n\n /**\n * Get a specific policy by ID\n * @param policyId - The unique policy identifier\n * @returns The public policy specification, or null if not found\n * @throws {ApiError} If the API request fails (except 404)\n */\n async getPolicy(policyId: string): Promise<PublicPolicySpec | null> {\n try {\n return await this.fetchJson<PublicPolicySpec>(\n `/api/policies/${encodeURIComponent(policyId)}`\n );\n } catch (err) {\n if (err instanceof ApiError && err.status === 404) {\n return null;\n }\n throw err;\n }\n }\n\n // ==========================================================================\n // zkTLS Methods\n // ==========================================================================\n\n /**\n * List available zkTLS extractors (data sources)\n * @returns Array of available extractors\n * @throws {ApiError} If the API request fails\n */\n async listExtractors(): Promise<ZkTlsExtractor[]> {\n return this.fetchJson<ZkTlsExtractor[]>('/api/zktls/extractors');\n }\n\n /**\n * List zkTLS attestations for the authenticated organization\n * @returns Array of attestations\n * @throws {ApiError} If the API request fails\n */\n async listAttestations(): Promise<ZkTlsAttestation[]> {\n return this.fetchJson<ZkTlsAttestation[]>('/api/zktls/attestations');\n }\n\n /**\n * Get a specific attestation by ID\n * @param attestationId - The attestation UUID\n * @returns The attestation details\n * @throws {ApiError} If the API request fails\n */\n async getAttestation(attestationId: string): Promise<ZkTlsAttestation> {\n return this.fetchJson<ZkTlsAttestation>(`/api/zktls/attestations/${encodeURIComponent(attestationId)}`);\n }\n\n /**\n * Create a new zkTLS session for data attestation\n * @param extractorId - The extractor to use (e.g., \"coinbase\")\n * @param callbackUrl - URL to redirect to after authentication\n * @returns Session ID and auth URL to redirect user to\n * @throws {ApiError} If the API request fails\n */\n async createZkTlsSession(\n extractorId: string,\n callbackUrl: string\n ): Promise<{ sessionId: string; authUrl: string }> {\n return this.fetchJson<{ sessionId: string; authUrl: string }>('/api/zktls/sessions', {\n method: 'POST',\n body: JSON.stringify({ extractor: extractorId, callbackUrl }),\n });\n }\n\n /**\n * Get the status of a zkTLS session\n * @param sessionId - The session UUID\n * @returns Session status and attestation if completed\n * @throws {ApiError} If the API request fails\n */\n async getZkTlsSession(sessionId: string): Promise<ZkTlsSession> {\n return this.fetchJson<ZkTlsSession>(`/api/zktls/sessions/${encodeURIComponent(sessionId)}`);\n }\n\n /**\n * Wait for a zkTLS session to complete\n * @param sessionId - The session UUID\n * @param options - Polling options\n * @returns The completed session with attestation\n * @throws {ZkTlsSessionExpiredError} If session expires\n * @throws {ZkTlsSessionFailedError} If session fails\n * @throws {TimeoutError} If timeout is reached\n * @throws {ApiError} If the API request fails\n */\n async waitForZkTlsSession(\n sessionId: string,\n options: PollOptions & { onProgress?: (session: ZkTlsSession) => void } = {}\n ): Promise<ZkTlsSession> {\n const intervalMs = options.intervalMs ?? DEFAULT_POLL_INTERVAL_MS;\n const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const startTime = Date.now();\n\n while (Date.now() - startTime < timeoutMs) {\n const session = await this.getZkTlsSession(sessionId);\n\n if (options.onProgress) {\n options.onProgress(session);\n }\n\n if (session.status === 'completed') {\n return session;\n }\n\n if (session.status === 'failed') {\n throw new ZkTlsSessionFailedError(sessionId, session.error || 'Unknown error');\n }\n\n if (session.status === 'expired') {\n throw new ZkTlsSessionExpiredError(sessionId);\n }\n\n await this.sleep(intervalMs);\n }\n\n throw new TimeoutError(\n `Timeout waiting for zkTLS session ${sessionId} after ${timeoutMs}ms`,\n timeoutMs\n );\n }\n\n // ==========================================================================\n // Circuit Methods\n // ==========================================================================\n\n /**\n * List available circuits\n * @param options - Optional filters\n * @returns Array of circuits\n * @throws {ApiError} If the API request fails\n */\n async listCircuits(options: { status?: 'active' | 'all'; policyId?: string } = {}): Promise<Circuit[]> {\n const params = new URLSearchParams();\n if (options.status) params.set('status', options.status);\n if (options.policyId) params.set('policyId', options.policyId);\n\n const queryString = params.toString();\n const path = queryString ? `/api/circuits?${queryString}` : '/api/circuits';\n\n return this.fetchJson<Circuit[]>(path);\n }\n\n /**\n * Get a specific circuit by ID\n * @param circuitId - The circuit identifier\n * @returns The circuit details\n * @throws {ApiError} If the API request fails\n */\n async getCircuit(circuitId: string): Promise<Circuit> {\n return this.fetchJson<Circuit>(`/api/circuits/${encodeURIComponent(circuitId)}`);\n }\n\n /**\n * Activate a circuit (requires validation to have passed)\n * @param circuitId - The circuit identifier to activate\n * @returns The activation result\n * @throws {ApiError} If the API request fails\n */\n async activateCircuit(circuitId: string): Promise<ActivateCircuitResult> {\n return this.fetchJson<ActivateCircuitResult>(`/api/circuits/${encodeURIComponent(circuitId)}/activate`, {\n method: 'POST',\n });\n }\n\n // ==========================================================================\n // Shared Proof Methods\n // ==========================================================================\n\n /**\n * Share a completed proof with a verifier organization\n * @param request - Share proof request with proveJobId and verifierOrgId\n * @returns The created shared proof\n * @throws {ApiError} If the API request fails\n */\n async shareProof(request: ShareProofRequest): Promise<SharedProof> {\n return this.fetchJson<SharedProof>('/api/shared-proofs', {\n method: 'POST',\n body: JSON.stringify(request),\n });\n }\n\n /**\n * List shared proofs (outgoing or incoming)\n * @param options - Filter by direction, pagination, and inclusion options\n * @returns Paginated list of shared proofs\n * @throws {ApiError} If the API request fails\n */\n async listSharedProofs(options: ListSharedProofsOptions = {}): Promise<{ shares: SharedProof[]; pagination: Pagination }> {\n const params = new URLSearchParams();\n if (options.direction) params.set('direction', options.direction);\n if (options.limit !== undefined) params.set('limit', options.limit.toString());\n if (options.offset !== undefined) params.set('offset', options.offset.toString());\n if (options.includeExpired) params.set('includeExpired', 'true');\n if (options.includeRevoked) params.set('includeRevoked', 'true');\n\n const queryString = params.toString();\n const path = queryString ? `/api/shared-proofs?${queryString}` : '/api/shared-proofs';\n\n return this.fetchJson<{ shares: SharedProof[]; pagination: Pagination }>(path);\n }\n\n /**\n * Get a specific shared proof by ID\n * @param sharedProofId - The shared proof ID\n * @returns The shared proof details\n * @throws {ApiError} If the API request fails\n */\n async getSharedProof(sharedProofId: string): Promise<SharedProof> {\n return this.fetchJson<SharedProof>(`/api/shared-proofs/${encodeURIComponent(sharedProofId)}`);\n }\n\n /**\n * Revoke a shared proof. Only the sharing organization can revoke.\n * @param sharedProofId - The shared proof ID to revoke\n * @returns The revocation result\n * @throws {ApiError} If the API request fails\n */\n async revokeSharedProof(sharedProofId: string): Promise<RevokeSharedProofResult> {\n return this.fetchJson<RevokeSharedProofResult>(`/api/shared-proofs/${encodeURIComponent(sharedProofId)}`, {\n method: 'DELETE',\n });\n }\n\n // ==========================================================================\n // Verification Methods\n // ==========================================================================\n\n /**\n * Verify a shared proof\n *\n * This method queues a verification job and polls until completion.\n * Verification is performed asynchronously by the prover worker.\n *\n * @param sharedProofId - The shared proof ID to verify\n * @param options - Optional polling configuration\n * @returns The verification result\n * @throws {ApiError} If the API request fails\n * @throws {TimeoutError} If verification doesn't complete within the timeout\n */\n async verifySharedProof(\n sharedProofId: string,\n options?: PollOptions\n ): Promise<VerificationResult> {\n const intervalMs = options?.intervalMs ?? 1000;\n const timeoutMs = options?.timeoutMs ?? 120000; // 2 minutes default\n\n // Queue the verification job\n const queueResult = await this.fetchJson<{\n jobId: string;\n status: VerifyJobStatus;\n creditsCharged: number;\n message?: string;\n }>(`/api/verify/shared/${encodeURIComponent(sharedProofId)}`, {\n method: 'POST',\n });\n\n const jobId = queueResult.jobId;\n const startTime = Date.now();\n\n // Poll until completion or timeout\n while (Date.now() - startTime < timeoutMs) {\n const statusResult = await this.getVerifyJobStatus(jobId);\n\n if (statusResult.status === 'completed' || statusResult.status === 'failed') {\n return {\n isValid: statusResult.isValid ?? false,\n error: statusResult.error,\n verificationTimeMs: statusResult.verificationTimeMs ?? 0,\n creditsCharged: statusResult.creditsCharged ?? queueResult.creditsCharged,\n verificationResultId: statusResult.verificationResultId ?? jobId,\n publicInputs: statusResult.publicInputs,\n };\n }\n\n await this.sleep(intervalMs);\n }\n\n throw new TimeoutError(\n `Verification timed out after ${timeoutMs}ms. Job ID: ${jobId}`,\n timeoutMs\n );\n }\n\n /**\n * Get the status of a verification job\n * @param jobId - The verification job ID\n * @returns The job status data\n * @throws {ApiError} If the API request fails\n */\n async getVerifyJobStatus(jobId: string): Promise<{\n status: VerifyJobStatus;\n isValid?: boolean;\n error?: string;\n verificationTimeMs?: number;\n creditsCharged: number;\n verificationResultId?: string;\n publicInputs?: string[];\n publicInputsMatch?: boolean;\n }> {\n return this.fetchJson(`/api/verify/jobs/${encodeURIComponent(jobId)}`);\n }\n\n /**\n * Verify an uploaded proof\n * @param proofBuffer - The proof binary as ArrayBuffer, Uint8Array, or Buffer\n * @param vkBuffer - The verification key binary as ArrayBuffer, Uint8Array, or Buffer\n * @returns The verification result\n * @throws {ApiError} If the API request fails\n */\n async verifyUploadedProof(\n proofBuffer: ArrayBuffer | Uint8Array,\n vkBuffer: ArrayBuffer | Uint8Array\n ): Promise<VerificationResult> {\n // Convert to Uint8Array if needed\n const proofBytes = proofBuffer instanceof Uint8Array\n ? proofBuffer\n : new Uint8Array(proofBuffer);\n const vkBytes = vkBuffer instanceof Uint8Array\n ? vkBuffer\n : new Uint8Array(vkBuffer);\n\n // Convert to base64\n const proofBase64 = typeof Buffer !== 'undefined'\n ? Buffer.from(proofBytes).toString('base64')\n : btoa(String.fromCharCode(...proofBytes));\n const vkBase64 = typeof Buffer !== 'undefined'\n ? Buffer.from(vkBytes).toString('base64')\n : btoa(String.fromCharCode(...vkBytes));\n\n return this.fetchJson<VerificationResult>('/api/verify/upload', {\n method: 'POST',\n body: JSON.stringify({\n proof: proofBase64,\n vk: vkBase64,\n }),\n });\n }\n\n /**\n * Get verification history for the authenticated organization\n * @param options - Pagination options\n * @returns Paginated list of verification results\n * @throws {ApiError} If the API request fails\n */\n async getVerificationHistory(options: GetVerificationHistoryOptions = {}): Promise<{ results: VerificationHistoryEntry[]; pagination: Pagination }> {\n const params = new URLSearchParams();\n if (options.limit !== undefined) params.set('limit', options.limit.toString());\n if (options.offset !== undefined) params.set('offset', options.offset.toString());\n\n const queryString = params.toString();\n const path = queryString ? `/api/verify/history?${queryString}` : '/api/verify/history';\n\n return this.fetchJson<{ results: VerificationHistoryEntry[]; pagination: Pagination }>(path);\n }\n\n // ==========================================================================\n // Private Helpers\n // ==========================================================================\n\n private async fetch(path: string, init?: RequestInit): Promise<Response> {\n const response = await fetch(`${this.baseUrl}${path}`, {\n ...init,\n headers: {\n ...this.headers,\n ...init?.headers,\n },\n });\n\n if (response.status === 401) {\n throw new AuthenticationError();\n }\n\n if (!response.ok) {\n const body = await response.json().catch(() => ({}));\n throw new ApiError(\n body.error || `HTTP ${response.status}: ${response.statusText}`,\n response.status,\n body\n );\n }\n\n return response;\n }\n\n private async fetchJson<T>(path: string, init?: RequestInit): Promise<T> {\n const response = await this.fetch(path, init);\n const json = await response.json();\n\n if (json.success === false) {\n throw new ApiError(json.error || 'Request failed', response.status, json);\n }\n\n return (json.data ?? json) as T;\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n}\n"]}
|