@bind-protocol/sdk 0.2.0 → 0.4.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 +1 -0
- package/dist/{index-CASjN9Qe.d.ts → adapter-53dB8ogG.d.ts} +3 -67
- package/dist/{index-5j-fuebC.d.cts → adapter-DyAYLtIy.d.cts} +3 -67
- package/dist/adapters/dimo/index.d.cts +3 -2
- package/dist/adapters/dimo/index.d.ts +3 -2
- package/dist/adapters/index.cjs +499 -0
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +6 -2
- package/dist/adapters/index.d.ts +6 -2
- package/dist/adapters/index.js +497 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/zktls/index.cjs +503 -0
- package/dist/adapters/zktls/index.cjs.map +1 -0
- package/dist/adapters/zktls/index.d.cts +117 -0
- package/dist/adapters/zktls/index.d.ts +117 -0
- package/dist/adapters/zktls/index.js +499 -0
- package/dist/adapters/zktls/index.js.map +1 -0
- package/dist/client-BSwO4sTC.d.ts +135 -0
- package/dist/client-Bh8Di-5n.d.cts +135 -0
- package/dist/core/index.cjs +162 -1
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +25 -61
- package/dist/core/index.d.ts +25 -61
- package/dist/core/index.js +159 -2
- package/dist/core/index.js.map +1 -1
- package/dist/index.cjs +315 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +309 -2
- package/dist/index.js.map +1 -1
- package/dist/types-B6S0axfE.d.cts +200 -0
- package/dist/types-B6S0axfE.d.ts +200 -0
- package/dist/types-Be7Jc5V8.d.cts +68 -0
- package/dist/types-D1-qiyJO.d.ts +68 -0
- package/package.json +10 -2
- package/dist/types-o4sbOK_a.d.cts +0 -101
- package/dist/types-o4sbOK_a.d.ts +0 -101
package/dist/core/index.d.ts
CHANGED
|
@@ -1,64 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
export { B as BindClient, d as deriveCircuitId } from '../client-BSwO4sTC.js';
|
|
2
|
+
export { A as ActivateCircuitResponse, B as BindClientOptions, k as BindCredential, h as Circuit, C as CircuitStatus, g as CircuitValidationStatus, s as CreateSessionResponse, r as GetAttestationResponse, j as GetCircuitResponse, G as GetProveJobResponse, t as GetSessionResponse, q as ListAttestationsResponse, i as ListCircuitsResponse, p as ListExtractorsResponse, L as ListProveJobsOptions, f as ListProveJobsResponse, c as ProveJob, a as ProveJobInputs, b as ProveJobOutputs, P as ProveJobStatus, d as ProveJobSummary, S as SubmitProveJobRequest, e as SubmitProveJobResponse, n as ZkTlsAttestation, l as ZkTlsExtractor, o as ZkTlsSession, Z as ZkTlsSessionStatus, m as ZkTlsWitness } from '../types-B6S0axfE.js';
|
|
2
3
|
export { DisclosureSpec, OutputClaimSpec, PolicyId, PolicyMetadata, PublicPolicySpec, SubjectSpec, ValiditySpec } from '@bind-protocol/policy-spec';
|
|
3
|
-
import { B as BindClientOptions, a as ProveJobInputs, e as SubmitProveJobResponse, G as GetProveJobResponse, L as ListProveJobsOptions, f as ListProveJobsResponse, c as ProveJob } from '../types-o4sbOK_a.js';
|
|
4
|
-
export { g as BindCredential, b as ProveJobOutputs, P as ProveJobStatus, d as ProveJobSummary, S as SubmitProveJobRequest } from '../types-o4sbOK_a.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* BindClient - Main client for interacting with the Bind Protocol API
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
declare class BindClient {
|
|
11
|
-
private readonly apiKey;
|
|
12
|
-
private readonly baseUrl;
|
|
13
|
-
private readonly headers;
|
|
14
|
-
constructor(options: BindClientOptions);
|
|
15
|
-
/**
|
|
16
|
-
* Submit a prove job for async processing
|
|
17
|
-
* @param circuitId - The circuit identifier (e.g., "bind.mobility.riskband.v1")
|
|
18
|
-
* @param inputs - Circuit inputs as key-value pairs (all values must be strings)
|
|
19
|
-
* @returns The submitted job details
|
|
20
|
-
* @throws {ApiError} If the API request fails
|
|
21
|
-
* @throws {InsufficientCreditsError} If there aren't enough credits
|
|
22
|
-
*/
|
|
23
|
-
submitProveJob(circuitId: string, inputs: ProveJobInputs): Promise<SubmitProveJobResponse>;
|
|
24
|
-
/**
|
|
25
|
-
* Get the status and results of a prove job
|
|
26
|
-
* @param jobId - The unique job identifier
|
|
27
|
-
* @returns The job details including status and outputs
|
|
28
|
-
*/
|
|
29
|
-
getProveJob(jobId: string): Promise<GetProveJobResponse>;
|
|
30
|
-
/**
|
|
31
|
-
* List prove jobs for the authenticated organization
|
|
32
|
-
* @param options - Optional filters for status, limit, and offset
|
|
33
|
-
* @returns Paginated list of prove jobs
|
|
34
|
-
*/
|
|
35
|
-
listProveJobs(options?: ListProveJobsOptions): Promise<ListProveJobsResponse>;
|
|
36
|
-
/**
|
|
37
|
-
* Poll for prove job completion
|
|
38
|
-
* @param jobId - The unique job identifier
|
|
39
|
-
* @param options - Polling options
|
|
40
|
-
* @returns The completed or failed job
|
|
41
|
-
* @throws {TimeoutError} If the job doesn't complete within the timeout
|
|
42
|
-
*/
|
|
43
|
-
waitForProveJob(jobId: string, options?: {
|
|
44
|
-
intervalMs?: number;
|
|
45
|
-
timeoutMs?: number;
|
|
46
|
-
onProgress?: (job: ProveJob) => void;
|
|
47
|
-
}): Promise<ProveJob>;
|
|
48
|
-
/**
|
|
49
|
-
* List all available public policies
|
|
50
|
-
* @returns Array of public policy specifications
|
|
51
|
-
*/
|
|
52
|
-
listPolicies(): Promise<PublicPolicySpec[]>;
|
|
53
|
-
/**
|
|
54
|
-
* Get a specific policy by ID
|
|
55
|
-
* @param policyId - The unique policy identifier
|
|
56
|
-
* @returns The public policy specification, or null if not found
|
|
57
|
-
*/
|
|
58
|
-
getPolicy(policyId: string): Promise<PublicPolicySpec | null>;
|
|
59
|
-
private fetch;
|
|
60
|
-
private sleep;
|
|
61
|
-
}
|
|
62
4
|
|
|
63
5
|
/**
|
|
64
6
|
* Custom error classes for the Bind Protocol SDK
|
|
@@ -85,5 +27,27 @@ declare class InsufficientCreditsError extends BindError {
|
|
|
85
27
|
readonly available: number;
|
|
86
28
|
constructor(required: number, available: number);
|
|
87
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Thrown when a zkTLS session expires before completion
|
|
32
|
+
*/
|
|
33
|
+
declare class ZkTlsSessionExpiredError extends BindError {
|
|
34
|
+
readonly sessionId: string;
|
|
35
|
+
constructor(sessionId: string);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Thrown when a zkTLS session fails
|
|
39
|
+
*/
|
|
40
|
+
declare class ZkTlsSessionFailedError extends BindError {
|
|
41
|
+
readonly sessionId: string;
|
|
42
|
+
readonly sessionError: string;
|
|
43
|
+
constructor(sessionId: string, sessionError: string);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Thrown when an extractor is not found or disabled
|
|
47
|
+
*/
|
|
48
|
+
declare class ZkTlsExtractorError extends BindError {
|
|
49
|
+
readonly extractorId: string;
|
|
50
|
+
constructor(extractorId: string, message: string);
|
|
51
|
+
}
|
|
88
52
|
|
|
89
|
-
export { ApiError, AuthenticationError,
|
|
53
|
+
export { ApiError, AuthenticationError, BindError, InsufficientCreditsError, TimeoutError, ZkTlsExtractorError, ZkTlsSessionExpiredError, ZkTlsSessionFailedError };
|
package/dist/core/index.js
CHANGED
|
@@ -40,11 +40,37 @@ var InsufficientCreditsError = class extends BindError {
|
|
|
40
40
|
this.name = "InsufficientCreditsError";
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
|
+
var ZkTlsSessionExpiredError = class extends BindError {
|
|
44
|
+
constructor(sessionId) {
|
|
45
|
+
super(`zkTLS session expired: ${sessionId}`, "ZKTLS_SESSION_EXPIRED", { sessionId });
|
|
46
|
+
this.sessionId = sessionId;
|
|
47
|
+
this.name = "ZkTlsSessionExpiredError";
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var ZkTlsSessionFailedError = class extends BindError {
|
|
51
|
+
constructor(sessionId, sessionError) {
|
|
52
|
+
super(`zkTLS session failed: ${sessionError}`, "ZKTLS_SESSION_FAILED", { sessionId, sessionError });
|
|
53
|
+
this.sessionId = sessionId;
|
|
54
|
+
this.sessionError = sessionError;
|
|
55
|
+
this.name = "ZkTlsSessionFailedError";
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var ZkTlsExtractorError = class extends BindError {
|
|
59
|
+
constructor(extractorId, message) {
|
|
60
|
+
super(message, "ZKTLS_EXTRACTOR_ERROR", { extractorId });
|
|
61
|
+
this.extractorId = extractorId;
|
|
62
|
+
this.name = "ZkTlsExtractorError";
|
|
63
|
+
}
|
|
64
|
+
};
|
|
43
65
|
|
|
44
66
|
// src/core/client.ts
|
|
45
67
|
var DEFAULT_BASE_URL = "https://api.bindprotocol.com";
|
|
46
68
|
var DEFAULT_POLL_INTERVAL_MS = 2e3;
|
|
47
69
|
var DEFAULT_TIMEOUT_MS = 3e5;
|
|
70
|
+
function deriveCircuitId(policyId, version) {
|
|
71
|
+
const sanitizedVersion = version.replace(/\./g, "_");
|
|
72
|
+
return `${policyId}.v${sanitizedVersion}`;
|
|
73
|
+
}
|
|
48
74
|
var BindClient = class {
|
|
49
75
|
apiKey;
|
|
50
76
|
baseUrl;
|
|
@@ -154,7 +180,8 @@ var BindClient = class {
|
|
|
154
180
|
response.status
|
|
155
181
|
);
|
|
156
182
|
}
|
|
157
|
-
|
|
183
|
+
const json = await response.json();
|
|
184
|
+
return json.data ?? json;
|
|
158
185
|
}
|
|
159
186
|
/**
|
|
160
187
|
* Get a specific policy by ID
|
|
@@ -175,6 +202,136 @@ var BindClient = class {
|
|
|
175
202
|
response.status
|
|
176
203
|
);
|
|
177
204
|
}
|
|
205
|
+
const json = await response.json();
|
|
206
|
+
return json.data ?? json;
|
|
207
|
+
}
|
|
208
|
+
// ==========================================================================
|
|
209
|
+
// zkTLS Methods
|
|
210
|
+
// ==========================================================================
|
|
211
|
+
/**
|
|
212
|
+
* List available zkTLS extractors (data sources)
|
|
213
|
+
* @returns Array of available extractors
|
|
214
|
+
*/
|
|
215
|
+
async listExtractors() {
|
|
216
|
+
const response = await this.fetch("/api/zktls/extractors");
|
|
217
|
+
return response.json();
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* List zkTLS attestations for the authenticated organization
|
|
221
|
+
* @returns Array of attestations
|
|
222
|
+
*/
|
|
223
|
+
async listAttestations() {
|
|
224
|
+
const response = await this.fetch("/api/zktls/attestations");
|
|
225
|
+
return response.json();
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Get a specific attestation by ID
|
|
229
|
+
* @param attestationId - The attestation UUID
|
|
230
|
+
* @returns The attestation or null if not found
|
|
231
|
+
*/
|
|
232
|
+
async getAttestation(attestationId) {
|
|
233
|
+
const response = await this.fetch(`/api/zktls/attestations/${encodeURIComponent(attestationId)}`);
|
|
234
|
+
return response.json();
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Create a new zkTLS session for data attestation
|
|
238
|
+
* @param extractorId - The extractor to use (e.g., "coinbase")
|
|
239
|
+
* @param callbackUrl - URL to redirect to after authentication
|
|
240
|
+
* @returns Session ID and auth URL to redirect user to
|
|
241
|
+
*/
|
|
242
|
+
async createZkTlsSession(extractorId, callbackUrl) {
|
|
243
|
+
const response = await this.fetch("/api/zktls/sessions", {
|
|
244
|
+
method: "POST",
|
|
245
|
+
body: JSON.stringify({ extractor: extractorId, callbackUrl })
|
|
246
|
+
});
|
|
247
|
+
return response.json();
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Get the status of a zkTLS session
|
|
251
|
+
* @param sessionId - The session UUID
|
|
252
|
+
* @returns Session status and attestation if completed
|
|
253
|
+
*/
|
|
254
|
+
async getZkTlsSession(sessionId) {
|
|
255
|
+
const response = await this.fetch(`/api/zktls/sessions/${encodeURIComponent(sessionId)}`);
|
|
256
|
+
return response.json();
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Wait for a zkTLS session to complete
|
|
260
|
+
* @param sessionId - The session UUID
|
|
261
|
+
* @param options - Polling options
|
|
262
|
+
* @returns The completed session with attestation
|
|
263
|
+
* @throws {ZkTlsSessionExpiredError} If session expires
|
|
264
|
+
* @throws {ZkTlsSessionFailedError} If session fails
|
|
265
|
+
* @throws {TimeoutError} If timeout is reached
|
|
266
|
+
*/
|
|
267
|
+
async waitForZkTlsSession(sessionId, options = {}) {
|
|
268
|
+
const intervalMs = options.intervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
269
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
270
|
+
const startTime = Date.now();
|
|
271
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
272
|
+
const result = await this.getZkTlsSession(sessionId);
|
|
273
|
+
if (!result.success || !result.data) {
|
|
274
|
+
throw new ApiError(
|
|
275
|
+
result.error || "Failed to get zkTLS session",
|
|
276
|
+
500,
|
|
277
|
+
result
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
const session = result.data;
|
|
281
|
+
if (options.onProgress) {
|
|
282
|
+
options.onProgress(session);
|
|
283
|
+
}
|
|
284
|
+
if (session.status === "completed") {
|
|
285
|
+
return session;
|
|
286
|
+
}
|
|
287
|
+
if (session.status === "failed") {
|
|
288
|
+
throw new ZkTlsSessionFailedError(sessionId, session.error || "Unknown error");
|
|
289
|
+
}
|
|
290
|
+
if (session.status === "expired") {
|
|
291
|
+
throw new ZkTlsSessionExpiredError(sessionId);
|
|
292
|
+
}
|
|
293
|
+
await this.sleep(intervalMs);
|
|
294
|
+
}
|
|
295
|
+
throw new TimeoutError(
|
|
296
|
+
`Timeout waiting for zkTLS session ${sessionId} after ${timeoutMs}ms`,
|
|
297
|
+
timeoutMs
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
// ==========================================================================
|
|
301
|
+
// Circuit Methods
|
|
302
|
+
// ==========================================================================
|
|
303
|
+
/**
|
|
304
|
+
* List available circuits
|
|
305
|
+
* @param options - Optional filters
|
|
306
|
+
* @returns Array of circuits
|
|
307
|
+
*/
|
|
308
|
+
async listCircuits(options = {}) {
|
|
309
|
+
const params = new URLSearchParams();
|
|
310
|
+
if (options.status) params.set("status", options.status);
|
|
311
|
+
if (options.policyId) params.set("policyId", options.policyId);
|
|
312
|
+
const queryString = params.toString();
|
|
313
|
+
const path = queryString ? `/api/circuits?${queryString}` : "/api/circuits";
|
|
314
|
+
const response = await this.fetch(path);
|
|
315
|
+
return response.json();
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Get a specific circuit by ID
|
|
319
|
+
* @param circuitId - The circuit identifier
|
|
320
|
+
* @returns The circuit details or null if not found
|
|
321
|
+
*/
|
|
322
|
+
async getCircuit(circuitId) {
|
|
323
|
+
const response = await this.fetch(`/api/circuits/${encodeURIComponent(circuitId)}`);
|
|
324
|
+
return response.json();
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Activate a circuit (requires validation to have passed)
|
|
328
|
+
* @param circuitId - The circuit identifier to activate
|
|
329
|
+
* @returns The activation result
|
|
330
|
+
*/
|
|
331
|
+
async activateCircuit(circuitId) {
|
|
332
|
+
const response = await this.fetch(`/api/circuits/${encodeURIComponent(circuitId)}/activate`, {
|
|
333
|
+
method: "POST"
|
|
334
|
+
});
|
|
178
335
|
return response.json();
|
|
179
336
|
}
|
|
180
337
|
// ==========================================================================
|
|
@@ -198,6 +355,6 @@ var BindClient = class {
|
|
|
198
355
|
}
|
|
199
356
|
};
|
|
200
357
|
|
|
201
|
-
export { ApiError, AuthenticationError, BindClient, BindError, InsufficientCreditsError, TimeoutError };
|
|
358
|
+
export { ApiError, AuthenticationError, BindClient, BindError, InsufficientCreditsError, TimeoutError, ZkTlsExtractorError, ZkTlsSessionExpiredError, ZkTlsSessionFailedError, deriveCircuitId };
|
|
202
359
|
//# sourceMappingURL=index.js.map
|
|
203
360
|
//# sourceMappingURL=index.js.map
|
package/dist/core/index.js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AAY,UAAA,CAAW,OAAA,EAAS,EAAE,CAAC,CAAA;AAAA,EACzD;AACF","file":"index.js","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 * 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} from './errors';\nimport type {\n BindClientOptions,\n ProveJobInputs,\n SubmitProveJobResponse,\n GetProveJobResponse,\n ListProveJobsOptions,\n ListProveJobsResponse,\n ProveJob,\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\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 * @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 ): Promise<SubmitProveJobResponse> {\n const response = await this.fetch('/api/prove', {\n method: 'POST',\n body: JSON.stringify({ circuitId, inputs }),\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 return response.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 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}\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,OAAO,SAAS,IAAA,EAAK;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,WAAW,SAAA,EAAgD;AAC/D,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,KAAA,CAAM,iBAAiB,kBAAA,CAAmB,SAAS,CAAC,CAAA,CAAE,CAAA;AAClF,IAAA,OAAO,SAAS,IAAA,EAAK;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,gBAAgB,SAAA,EAAqD;AACzE,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,KAAA,CAAM,iBAAiB,kBAAA,CAAmB,SAAS,CAAC,CAAA,SAAA,CAAA,EAAa;AAAA,MAC3F,MAAA,EAAQ;AAAA,KACT,CAAA;AACD,IAAA,OAAO,SAAS,IAAA,EAAK;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAMA,MAAc,KAAA,CAAM,IAAA,EAAc,IAAA,EAAuC;AACvE,IAAA,MAAM,QAAA,GAAW,MAAM,KAAA,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.js","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 ListExtractorsResponse,\n ListAttestationsResponse,\n GetAttestationResponse,\n CreateSessionResponse,\n GetSessionResponse,\n ZkTlsSession,\n Circuit,\n ListCircuitsResponse,\n GetCircuitResponse,\n ActivateCircuitResponse,\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 * @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 ): Promise<SubmitProveJobResponse> {\n const response = await this.fetch('/api/prove', {\n method: 'POST',\n body: JSON.stringify({ circuitId, inputs }),\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 // 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"]}
|