@bind-protocol/sdk 0.8.0 → 0.10.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-DBvPax2O.d.cts → adapter-BRj4bkLl.d.ts} +22 -8
- package/dist/{adapter-LeDOUfnn.d.ts → adapter-CNeHM6SQ.d.cts} +22 -8
- package/dist/adapters/dimo/index.cjs +26 -10
- package/dist/adapters/dimo/index.cjs.map +1 -1
- package/dist/adapters/dimo/index.d.cts +9 -3
- package/dist/adapters/dimo/index.d.ts +9 -3
- package/dist/adapters/dimo/index.js +26 -10
- package/dist/adapters/dimo/index.js.map +1 -1
- package/dist/adapters/index.cjs +139 -148
- 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 +139 -148
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/zktls/index.cjs +113 -138
- 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 -138
- package/dist/adapters/zktls/index.js.map +1 -1
- package/dist/{client-Dlp02kxb.d.cts → client-CfYXpFLk.d.cts} +70 -32
- package/dist/{client-BsloIjSG.d.ts → client-CpJ87Xe0.d.ts} +70 -32
- package/dist/core/index.cjs +107 -125
- 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 -125
- package/dist/core/index.js.map +1 -1
- package/dist/index.cjs +139 -148
- 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 +139 -148
- package/dist/index.js.map +1 -1
- package/dist/{types-D5XJykY-.d.cts → types-BcPssdQk.d.cts} +30 -174
- package/dist/{types-D5XJykY-.d.ts → types-BcPssdQk.d.ts} +30 -174
- package/dist/{types-CXWgNPXN.d.ts → types-D7Q7ymPa.d.ts} +1 -1
- package/dist/{types-D-cTYE3o.d.cts → types-ywkMNwun.d.cts} +1 -1
- package/package.json +1 -1
|
@@ -87,33 +87,42 @@ var BindClient = class {
|
|
|
87
87
|
* @throws {InsufficientCreditsError} If there aren't enough credits
|
|
88
88
|
*/
|
|
89
89
|
async submitProveJob(circuitId, inputs, options) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
90
|
+
try {
|
|
91
|
+
return await this.fetchJson("/api/prove", {
|
|
92
|
+
method: "POST",
|
|
93
|
+
body: JSON.stringify({
|
|
94
|
+
circuitId,
|
|
95
|
+
inputs,
|
|
96
|
+
verificationMode: options?.verificationMode
|
|
97
|
+
})
|
|
98
|
+
});
|
|
99
|
+
} catch (err) {
|
|
100
|
+
if (err instanceof ApiError && err.response) {
|
|
101
|
+
const body = err.response;
|
|
102
|
+
if (body.requiredCredits !== void 0 && body.availableCredits !== void 0) {
|
|
103
|
+
throw new InsufficientCreditsError(
|
|
104
|
+
body.requiredCredits,
|
|
105
|
+
body.availableCredits
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
throw err;
|
|
101
110
|
}
|
|
102
|
-
return result;
|
|
103
111
|
}
|
|
104
112
|
/**
|
|
105
113
|
* Get the status and results of a prove job
|
|
106
114
|
* @param jobId - The unique job identifier
|
|
107
115
|
* @returns The job details including status and outputs
|
|
116
|
+
* @throws {ApiError} If the API request fails
|
|
108
117
|
*/
|
|
109
118
|
async getProveJob(jobId) {
|
|
110
|
-
|
|
111
|
-
return response.json();
|
|
119
|
+
return this.fetchJson(`/api/prove/${encodeURIComponent(jobId)}`);
|
|
112
120
|
}
|
|
113
121
|
/**
|
|
114
122
|
* List prove jobs for the authenticated organization
|
|
115
123
|
* @param options - Optional filters for status, limit, and offset
|
|
116
124
|
* @returns Paginated list of prove jobs
|
|
125
|
+
* @throws {ApiError} If the API request fails
|
|
117
126
|
*/
|
|
118
127
|
async listProveJobs(options = {}) {
|
|
119
128
|
const params = new URLSearchParams();
|
|
@@ -122,8 +131,7 @@ var BindClient = class {
|
|
|
122
131
|
if (options.offset !== void 0) params.set("offset", options.offset.toString());
|
|
123
132
|
const queryString = params.toString();
|
|
124
133
|
const path = queryString ? `/api/prove?${queryString}` : "/api/prove";
|
|
125
|
-
|
|
126
|
-
return response.json();
|
|
134
|
+
return this.fetchJson(path);
|
|
127
135
|
}
|
|
128
136
|
/**
|
|
129
137
|
* Poll for prove job completion
|
|
@@ -131,21 +139,14 @@ var BindClient = class {
|
|
|
131
139
|
* @param options - Polling options
|
|
132
140
|
* @returns The completed or failed job
|
|
133
141
|
* @throws {TimeoutError} If the job doesn't complete within the timeout
|
|
142
|
+
* @throws {ApiError} If the API request fails
|
|
134
143
|
*/
|
|
135
144
|
async waitForProveJob(jobId, options = {}) {
|
|
136
145
|
const intervalMs = options.intervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
137
146
|
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
138
147
|
const startTime = Date.now();
|
|
139
148
|
while (Date.now() - startTime < timeoutMs) {
|
|
140
|
-
const
|
|
141
|
-
if (!result.success || !result.data) {
|
|
142
|
-
throw new ApiError(
|
|
143
|
-
result.error || "Failed to get prove job",
|
|
144
|
-
500,
|
|
145
|
-
result
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
const job = result.data;
|
|
149
|
+
const job = await this.getProveJob(jobId);
|
|
149
150
|
if (options.onProgress) {
|
|
150
151
|
options.onProgress(job);
|
|
151
152
|
}
|
|
@@ -165,41 +166,28 @@ var BindClient = class {
|
|
|
165
166
|
/**
|
|
166
167
|
* List all available public policies
|
|
167
168
|
* @returns Array of public policy specifications
|
|
169
|
+
* @throws {ApiError} If the API request fails
|
|
168
170
|
*/
|
|
169
171
|
async listPolicies() {
|
|
170
|
-
|
|
171
|
-
method: "GET"
|
|
172
|
-
});
|
|
173
|
-
if (!response.ok) {
|
|
174
|
-
throw new ApiError(
|
|
175
|
-
`Failed to fetch policies: ${response.statusText}`,
|
|
176
|
-
response.status
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
const json = await response.json();
|
|
180
|
-
return json.data ?? json;
|
|
172
|
+
return this.fetchJson("/api/policies");
|
|
181
173
|
}
|
|
182
174
|
/**
|
|
183
175
|
* Get a specific policy by ID
|
|
184
176
|
* @param policyId - The unique policy identifier
|
|
185
177
|
* @returns The public policy specification, or null if not found
|
|
178
|
+
* @throws {ApiError} If the API request fails (except 404)
|
|
186
179
|
*/
|
|
187
180
|
async getPolicy(policyId) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
);
|
|
192
|
-
if (response.status === 404) {
|
|
193
|
-
return null;
|
|
194
|
-
}
|
|
195
|
-
if (!response.ok) {
|
|
196
|
-
throw new ApiError(
|
|
197
|
-
`Failed to fetch policy: ${response.statusText}`,
|
|
198
|
-
response.status
|
|
181
|
+
try {
|
|
182
|
+
return await this.fetchJson(
|
|
183
|
+
`/api/policies/${encodeURIComponent(policyId)}`
|
|
199
184
|
);
|
|
185
|
+
} catch (err) {
|
|
186
|
+
if (err instanceof ApiError && err.status === 404) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
throw err;
|
|
200
190
|
}
|
|
201
|
-
const json = await response.json();
|
|
202
|
-
return json.data ?? json;
|
|
203
191
|
}
|
|
204
192
|
// ==========================================================================
|
|
205
193
|
// zkTLS Methods
|
|
@@ -207,49 +195,49 @@ var BindClient = class {
|
|
|
207
195
|
/**
|
|
208
196
|
* List available zkTLS extractors (data sources)
|
|
209
197
|
* @returns Array of available extractors
|
|
198
|
+
* @throws {ApiError} If the API request fails
|
|
210
199
|
*/
|
|
211
200
|
async listExtractors() {
|
|
212
|
-
|
|
213
|
-
return response.json();
|
|
201
|
+
return this.fetchJson("/api/zktls/extractors");
|
|
214
202
|
}
|
|
215
203
|
/**
|
|
216
204
|
* List zkTLS attestations for the authenticated organization
|
|
217
205
|
* @returns Array of attestations
|
|
206
|
+
* @throws {ApiError} If the API request fails
|
|
218
207
|
*/
|
|
219
208
|
async listAttestations() {
|
|
220
|
-
|
|
221
|
-
return response.json();
|
|
209
|
+
return this.fetchJson("/api/zktls/attestations");
|
|
222
210
|
}
|
|
223
211
|
/**
|
|
224
212
|
* Get a specific attestation by ID
|
|
225
213
|
* @param attestationId - The attestation UUID
|
|
226
|
-
* @returns The attestation
|
|
214
|
+
* @returns The attestation details
|
|
215
|
+
* @throws {ApiError} If the API request fails
|
|
227
216
|
*/
|
|
228
217
|
async getAttestation(attestationId) {
|
|
229
|
-
|
|
230
|
-
return response.json();
|
|
218
|
+
return this.fetchJson(`/api/zktls/attestations/${encodeURIComponent(attestationId)}`);
|
|
231
219
|
}
|
|
232
220
|
/**
|
|
233
221
|
* Create a new zkTLS session for data attestation
|
|
234
222
|
* @param extractorId - The extractor to use (e.g., "coinbase")
|
|
235
223
|
* @param callbackUrl - URL to redirect to after authentication
|
|
236
224
|
* @returns Session ID and auth URL to redirect user to
|
|
225
|
+
* @throws {ApiError} If the API request fails
|
|
237
226
|
*/
|
|
238
227
|
async createZkTlsSession(extractorId, callbackUrl) {
|
|
239
|
-
|
|
228
|
+
return this.fetchJson("/api/zktls/sessions", {
|
|
240
229
|
method: "POST",
|
|
241
230
|
body: JSON.stringify({ extractor: extractorId, callbackUrl })
|
|
242
231
|
});
|
|
243
|
-
return response.json();
|
|
244
232
|
}
|
|
245
233
|
/**
|
|
246
234
|
* Get the status of a zkTLS session
|
|
247
235
|
* @param sessionId - The session UUID
|
|
248
236
|
* @returns Session status and attestation if completed
|
|
237
|
+
* @throws {ApiError} If the API request fails
|
|
249
238
|
*/
|
|
250
239
|
async getZkTlsSession(sessionId) {
|
|
251
|
-
|
|
252
|
-
return response.json();
|
|
240
|
+
return this.fetchJson(`/api/zktls/sessions/${encodeURIComponent(sessionId)}`);
|
|
253
241
|
}
|
|
254
242
|
/**
|
|
255
243
|
* Wait for a zkTLS session to complete
|
|
@@ -259,21 +247,14 @@ var BindClient = class {
|
|
|
259
247
|
* @throws {ZkTlsSessionExpiredError} If session expires
|
|
260
248
|
* @throws {ZkTlsSessionFailedError} If session fails
|
|
261
249
|
* @throws {TimeoutError} If timeout is reached
|
|
250
|
+
* @throws {ApiError} If the API request fails
|
|
262
251
|
*/
|
|
263
252
|
async waitForZkTlsSession(sessionId, options = {}) {
|
|
264
253
|
const intervalMs = options.intervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
265
254
|
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
266
255
|
const startTime = Date.now();
|
|
267
256
|
while (Date.now() - startTime < timeoutMs) {
|
|
268
|
-
const
|
|
269
|
-
if (!result.success || !result.data) {
|
|
270
|
-
throw new ApiError(
|
|
271
|
-
result.error || "Failed to get zkTLS session",
|
|
272
|
-
500,
|
|
273
|
-
result
|
|
274
|
-
);
|
|
275
|
-
}
|
|
276
|
-
const session = result.data;
|
|
257
|
+
const session = await this.getZkTlsSession(sessionId);
|
|
277
258
|
if (options.onProgress) {
|
|
278
259
|
options.onProgress(session);
|
|
279
260
|
}
|
|
@@ -300,6 +281,7 @@ var BindClient = class {
|
|
|
300
281
|
* List available circuits
|
|
301
282
|
* @param options - Optional filters
|
|
302
283
|
* @returns Array of circuits
|
|
284
|
+
* @throws {ApiError} If the API request fails
|
|
303
285
|
*/
|
|
304
286
|
async listCircuits(options = {}) {
|
|
305
287
|
const params = new URLSearchParams();
|
|
@@ -307,28 +289,27 @@ var BindClient = class {
|
|
|
307
289
|
if (options.policyId) params.set("policyId", options.policyId);
|
|
308
290
|
const queryString = params.toString();
|
|
309
291
|
const path = queryString ? `/api/circuits?${queryString}` : "/api/circuits";
|
|
310
|
-
|
|
311
|
-
return response.json();
|
|
292
|
+
return this.fetchJson(path);
|
|
312
293
|
}
|
|
313
294
|
/**
|
|
314
295
|
* Get a specific circuit by ID
|
|
315
296
|
* @param circuitId - The circuit identifier
|
|
316
|
-
* @returns The circuit details
|
|
297
|
+
* @returns The circuit details
|
|
298
|
+
* @throws {ApiError} If the API request fails
|
|
317
299
|
*/
|
|
318
300
|
async getCircuit(circuitId) {
|
|
319
|
-
|
|
320
|
-
return response.json();
|
|
301
|
+
return this.fetchJson(`/api/circuits/${encodeURIComponent(circuitId)}`);
|
|
321
302
|
}
|
|
322
303
|
/**
|
|
323
304
|
* Activate a circuit (requires validation to have passed)
|
|
324
305
|
* @param circuitId - The circuit identifier to activate
|
|
325
306
|
* @returns The activation result
|
|
307
|
+
* @throws {ApiError} If the API request fails
|
|
326
308
|
*/
|
|
327
309
|
async activateCircuit(circuitId) {
|
|
328
|
-
|
|
310
|
+
return this.fetchJson(`/api/circuits/${encodeURIComponent(circuitId)}/activate`, {
|
|
329
311
|
method: "POST"
|
|
330
312
|
});
|
|
331
|
-
return response.json();
|
|
332
313
|
}
|
|
333
314
|
// ==========================================================================
|
|
334
315
|
// Shared Proof Methods
|
|
@@ -337,18 +318,19 @@ var BindClient = class {
|
|
|
337
318
|
* Share a completed proof with a verifier organization
|
|
338
319
|
* @param request - Share proof request with proveJobId and verifierOrgId
|
|
339
320
|
* @returns The created shared proof
|
|
321
|
+
* @throws {ApiError} If the API request fails
|
|
340
322
|
*/
|
|
341
323
|
async shareProof(request) {
|
|
342
|
-
|
|
324
|
+
return this.fetchJson("/api/shared-proofs", {
|
|
343
325
|
method: "POST",
|
|
344
326
|
body: JSON.stringify(request)
|
|
345
327
|
});
|
|
346
|
-
return response.json();
|
|
347
328
|
}
|
|
348
329
|
/**
|
|
349
330
|
* List shared proofs (outgoing or incoming)
|
|
350
331
|
* @param options - Filter by direction, pagination, and inclusion options
|
|
351
332
|
* @returns Paginated list of shared proofs
|
|
333
|
+
* @throws {ApiError} If the API request fails
|
|
352
334
|
*/
|
|
353
335
|
async listSharedProofs(options = {}) {
|
|
354
336
|
const params = new URLSearchParams();
|
|
@@ -359,28 +341,27 @@ var BindClient = class {
|
|
|
359
341
|
if (options.includeRevoked) params.set("includeRevoked", "true");
|
|
360
342
|
const queryString = params.toString();
|
|
361
343
|
const path = queryString ? `/api/shared-proofs?${queryString}` : "/api/shared-proofs";
|
|
362
|
-
|
|
363
|
-
return response.json();
|
|
344
|
+
return this.fetchJson(path);
|
|
364
345
|
}
|
|
365
346
|
/**
|
|
366
347
|
* Get a specific shared proof by ID
|
|
367
348
|
* @param sharedProofId - The shared proof ID
|
|
368
349
|
* @returns The shared proof details
|
|
350
|
+
* @throws {ApiError} If the API request fails
|
|
369
351
|
*/
|
|
370
352
|
async getSharedProof(sharedProofId) {
|
|
371
|
-
|
|
372
|
-
return response.json();
|
|
353
|
+
return this.fetchJson(`/api/shared-proofs/${encodeURIComponent(sharedProofId)}`);
|
|
373
354
|
}
|
|
374
355
|
/**
|
|
375
356
|
* Revoke a shared proof. Only the sharing organization can revoke.
|
|
376
357
|
* @param sharedProofId - The shared proof ID to revoke
|
|
377
358
|
* @returns The revocation result
|
|
359
|
+
* @throws {ApiError} If the API request fails
|
|
378
360
|
*/
|
|
379
361
|
async revokeSharedProof(sharedProofId) {
|
|
380
|
-
|
|
362
|
+
return this.fetchJson(`/api/shared-proofs/${encodeURIComponent(sharedProofId)}`, {
|
|
381
363
|
method: "DELETE"
|
|
382
364
|
});
|
|
383
|
-
return response.json();
|
|
384
365
|
}
|
|
385
366
|
// ==========================================================================
|
|
386
367
|
// Verification Methods
|
|
@@ -394,84 +375,70 @@ var BindClient = class {
|
|
|
394
375
|
* @param sharedProofId - The shared proof ID to verify
|
|
395
376
|
* @param options - Optional polling configuration
|
|
396
377
|
* @returns The verification result
|
|
378
|
+
* @throws {ApiError} If the API request fails
|
|
379
|
+
* @throws {TimeoutError} If verification doesn't complete within the timeout
|
|
397
380
|
*/
|
|
398
381
|
async verifySharedProof(sharedProofId, options) {
|
|
399
|
-
const
|
|
400
|
-
const
|
|
401
|
-
const
|
|
382
|
+
const intervalMs = options?.intervalMs ?? 1e3;
|
|
383
|
+
const timeoutMs = options?.timeoutMs ?? 12e4;
|
|
384
|
+
const queueResult = await this.fetchJson(`/api/verify/shared/${encodeURIComponent(sharedProofId)}`, {
|
|
402
385
|
method: "POST"
|
|
403
386
|
});
|
|
404
|
-
const
|
|
405
|
-
if (!queueResult.success || !queueResult.data?.jobId) {
|
|
406
|
-
return {
|
|
407
|
-
success: false,
|
|
408
|
-
error: queueResult.error ?? "Failed to queue verification job"
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
const jobId = queueResult.data.jobId;
|
|
387
|
+
const jobId = queueResult.jobId;
|
|
412
388
|
const startTime = Date.now();
|
|
413
|
-
while (Date.now() - startTime <
|
|
389
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
414
390
|
const statusResult = await this.getVerifyJobStatus(jobId);
|
|
415
|
-
if (
|
|
416
|
-
return {
|
|
417
|
-
success: false,
|
|
418
|
-
error: statusResult.error ?? "Failed to get verification status"
|
|
419
|
-
};
|
|
420
|
-
}
|
|
421
|
-
const status = statusResult.data?.status;
|
|
422
|
-
if (status === "completed" || status === "failed") {
|
|
391
|
+
if (statusResult.status === "completed" || statusResult.status === "failed") {
|
|
423
392
|
return {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
verificationResultId: statusResult.data?.verificationResultId ?? jobId,
|
|
431
|
-
publicInputs: statusResult.data?.publicInputs
|
|
432
|
-
}
|
|
393
|
+
isValid: statusResult.isValid ?? false,
|
|
394
|
+
error: statusResult.error,
|
|
395
|
+
verificationTimeMs: statusResult.verificationTimeMs ?? 0,
|
|
396
|
+
creditsCharged: statusResult.creditsCharged ?? queueResult.creditsCharged,
|
|
397
|
+
verificationResultId: statusResult.verificationResultId ?? jobId,
|
|
398
|
+
publicInputs: statusResult.publicInputs
|
|
433
399
|
};
|
|
434
400
|
}
|
|
435
|
-
await
|
|
401
|
+
await this.sleep(intervalMs);
|
|
436
402
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
403
|
+
throw new TimeoutError(
|
|
404
|
+
`Verification timed out after ${timeoutMs}ms. Job ID: ${jobId}`,
|
|
405
|
+
timeoutMs
|
|
406
|
+
);
|
|
441
407
|
}
|
|
442
408
|
/**
|
|
443
409
|
* Get the status of a verification job
|
|
444
410
|
* @param jobId - The verification job ID
|
|
445
|
-
* @returns The job status
|
|
411
|
+
* @returns The job status data
|
|
412
|
+
* @throws {ApiError} If the API request fails
|
|
446
413
|
*/
|
|
447
414
|
async getVerifyJobStatus(jobId) {
|
|
448
|
-
|
|
449
|
-
return response.json();
|
|
415
|
+
return this.fetchJson(`/api/verify/jobs/${encodeURIComponent(jobId)}`);
|
|
450
416
|
}
|
|
451
417
|
/**
|
|
452
418
|
* Verify an uploaded proof
|
|
453
419
|
* @param proofBuffer - The proof binary as ArrayBuffer, Uint8Array, or Buffer
|
|
454
420
|
* @param vkBuffer - The verification key binary as ArrayBuffer, Uint8Array, or Buffer
|
|
455
421
|
* @returns The verification result
|
|
422
|
+
* @throws {ApiError} If the API request fails
|
|
456
423
|
*/
|
|
457
424
|
async verifyUploadedProof(proofBuffer, vkBuffer) {
|
|
458
425
|
const proofBytes = proofBuffer instanceof Uint8Array ? proofBuffer : new Uint8Array(proofBuffer);
|
|
459
426
|
const vkBytes = vkBuffer instanceof Uint8Array ? vkBuffer : new Uint8Array(vkBuffer);
|
|
460
427
|
const proofBase64 = typeof Buffer !== "undefined" ? Buffer.from(proofBytes).toString("base64") : btoa(String.fromCharCode(...proofBytes));
|
|
461
428
|
const vkBase64 = typeof Buffer !== "undefined" ? Buffer.from(vkBytes).toString("base64") : btoa(String.fromCharCode(...vkBytes));
|
|
462
|
-
|
|
429
|
+
return this.fetchJson("/api/verify/upload", {
|
|
463
430
|
method: "POST",
|
|
464
431
|
body: JSON.stringify({
|
|
465
432
|
proof: proofBase64,
|
|
466
433
|
vk: vkBase64
|
|
467
434
|
})
|
|
468
435
|
});
|
|
469
|
-
return response.json();
|
|
470
436
|
}
|
|
471
437
|
/**
|
|
472
438
|
* Get verification history for the authenticated organization
|
|
473
439
|
* @param options - Pagination options
|
|
474
440
|
* @returns Paginated list of verification results
|
|
441
|
+
* @throws {ApiError} If the API request fails
|
|
475
442
|
*/
|
|
476
443
|
async getVerificationHistory(options = {}) {
|
|
477
444
|
const params = new URLSearchParams();
|
|
@@ -479,8 +446,7 @@ var BindClient = class {
|
|
|
479
446
|
if (options.offset !== void 0) params.set("offset", options.offset.toString());
|
|
480
447
|
const queryString = params.toString();
|
|
481
448
|
const path = queryString ? `/api/verify/history?${queryString}` : "/api/verify/history";
|
|
482
|
-
|
|
483
|
-
return response.json();
|
|
449
|
+
return this.fetchJson(path);
|
|
484
450
|
}
|
|
485
451
|
// ==========================================================================
|
|
486
452
|
// Private Helpers
|
|
@@ -496,8 +462,24 @@ var BindClient = class {
|
|
|
496
462
|
if (response.status === 401) {
|
|
497
463
|
throw new AuthenticationError();
|
|
498
464
|
}
|
|
465
|
+
if (!response.ok) {
|
|
466
|
+
const body = await response.json().catch(() => ({}));
|
|
467
|
+
throw new ApiError(
|
|
468
|
+
body.error || `HTTP ${response.status}: ${response.statusText}`,
|
|
469
|
+
response.status,
|
|
470
|
+
body
|
|
471
|
+
);
|
|
472
|
+
}
|
|
499
473
|
return response;
|
|
500
474
|
}
|
|
475
|
+
async fetchJson(path, init) {
|
|
476
|
+
const response = await this.fetch(path, init);
|
|
477
|
+
const json = await response.json();
|
|
478
|
+
if (json.success === false) {
|
|
479
|
+
throw new ApiError(json.error || "Request failed", response.status, json);
|
|
480
|
+
}
|
|
481
|
+
return json.data ?? json;
|
|
482
|
+
}
|
|
501
483
|
sleep(ms) {
|
|
502
484
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
503
485
|
}
|
|
@@ -535,11 +517,7 @@ var ZkTlsAdapter = class {
|
|
|
535
517
|
* Client should redirect user to this URL
|
|
536
518
|
*/
|
|
537
519
|
async createSession(callbackUrl) {
|
|
538
|
-
|
|
539
|
-
if (!result.success || !result.data) {
|
|
540
|
-
throw new Error(result.error || "Failed to create zkTLS session");
|
|
541
|
-
}
|
|
542
|
-
return result.data;
|
|
520
|
+
return this.client.createZkTlsSession(this.extractorId, callbackUrl);
|
|
543
521
|
}
|
|
544
522
|
/**
|
|
545
523
|
* Wait for session completion and return attestation
|
|
@@ -550,7 +528,7 @@ var ZkTlsAdapter = class {
|
|
|
550
528
|
throw new Error("Session completed but no attestation found");
|
|
551
529
|
}
|
|
552
530
|
const extractors = await this.client.listExtractors();
|
|
553
|
-
const extractor = extractors.
|
|
531
|
+
const extractor = extractors.find((e) => e.id === this.extractorId);
|
|
554
532
|
if (!extractor) {
|
|
555
533
|
throw new Error(`Extractor not found: ${this.extractorId}`);
|
|
556
534
|
}
|
|
@@ -563,17 +541,14 @@ var ZkTlsAdapter = class {
|
|
|
563
541
|
// Protected helpers
|
|
564
542
|
// ===========================================================================
|
|
565
543
|
async fetchExistingAttestation(attestationId) {
|
|
566
|
-
const
|
|
567
|
-
if (!result.success || !result.data) {
|
|
568
|
-
throw new Error(result.error || "Attestation not found");
|
|
569
|
-
}
|
|
544
|
+
const attestation = await this.client.getAttestation(attestationId);
|
|
570
545
|
const extractors = await this.client.listExtractors();
|
|
571
|
-
const extractor = extractors.
|
|
546
|
+
const extractor = extractors.find((e) => e.id === attestation.extractor);
|
|
572
547
|
if (!extractor) {
|
|
573
|
-
throw new Error(`Extractor not found: ${
|
|
548
|
+
throw new Error(`Extractor not found: ${attestation.extractor}`);
|
|
574
549
|
}
|
|
575
550
|
return {
|
|
576
|
-
attestation
|
|
551
|
+
attestation,
|
|
577
552
|
extractor
|
|
578
553
|
};
|
|
579
554
|
}
|