@bind-protocol/sdk 0.2.0 → 0.3.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.
Files changed (38) hide show
  1. package/README.md +1 -0
  2. package/dist/{index-CASjN9Qe.d.ts → adapter-53dB8ogG.d.ts} +3 -67
  3. package/dist/{index-5j-fuebC.d.cts → adapter-DyAYLtIy.d.cts} +3 -67
  4. package/dist/adapters/dimo/index.d.cts +3 -2
  5. package/dist/adapters/dimo/index.d.ts +3 -2
  6. package/dist/adapters/index.cjs +499 -0
  7. package/dist/adapters/index.cjs.map +1 -1
  8. package/dist/adapters/index.d.cts +6 -2
  9. package/dist/adapters/index.d.ts +6 -2
  10. package/dist/adapters/index.js +497 -1
  11. package/dist/adapters/index.js.map +1 -1
  12. package/dist/adapters/zktls/index.cjs +503 -0
  13. package/dist/adapters/zktls/index.cjs.map +1 -0
  14. package/dist/adapters/zktls/index.d.cts +117 -0
  15. package/dist/adapters/zktls/index.d.ts +117 -0
  16. package/dist/adapters/zktls/index.js +499 -0
  17. package/dist/adapters/zktls/index.js.map +1 -0
  18. package/dist/client-BSwO4sTC.d.ts +135 -0
  19. package/dist/client-Bh8Di-5n.d.cts +135 -0
  20. package/dist/core/index.cjs +162 -1
  21. package/dist/core/index.cjs.map +1 -1
  22. package/dist/core/index.d.cts +25 -61
  23. package/dist/core/index.d.ts +25 -61
  24. package/dist/core/index.js +159 -2
  25. package/dist/core/index.js.map +1 -1
  26. package/dist/index.cjs +310 -1
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +6 -3
  29. package/dist/index.d.ts +6 -3
  30. package/dist/index.js +305 -2
  31. package/dist/index.js.map +1 -1
  32. package/dist/types-B6S0axfE.d.cts +200 -0
  33. package/dist/types-B6S0axfE.d.ts +200 -0
  34. package/dist/types-Be7Jc5V8.d.cts +68 -0
  35. package/dist/types-D1-qiyJO.d.ts +68 -0
  36. package/package.json +10 -2
  37. package/dist/types-o4sbOK_a.d.cts +0 -101
  38. package/dist/types-o4sbOK_a.d.ts +0 -101
@@ -0,0 +1,135 @@
1
+ import { PublicPolicySpec } from '@bind-protocol/policy-spec';
2
+ import { B as BindClientOptions, a as ProveJobInputs, e as SubmitProveJobResponse, G as GetProveJobResponse, L as ListProveJobsOptions, f as ListProveJobsResponse, c as ProveJob, p as ListExtractorsResponse, q as ListAttestationsResponse, r as GetAttestationResponse, s as CreateSessionResponse, t as GetSessionResponse, o as ZkTlsSession, i as ListCircuitsResponse, j as GetCircuitResponse, A as ActivateCircuitResponse } from './types-B6S0axfE.js';
3
+
4
+ /**
5
+ * BindClient - Main client for interacting with the Bind Protocol API
6
+ */
7
+
8
+ /**
9
+ * Derive a circuit ID from policy ID and version
10
+ * This matches the server's auto-generation logic.
11
+ * Format: {policyId}.v{version} with version dots replaced by underscores
12
+ *
13
+ * @example
14
+ * deriveCircuitId("bind.demo.credit-score", "0.1.0")
15
+ * // Returns: "bind.demo.credit-score.v0_1_0"
16
+ */
17
+ declare function deriveCircuitId(policyId: string, version: string): string;
18
+ declare class BindClient {
19
+ private readonly apiKey;
20
+ private readonly baseUrl;
21
+ private readonly headers;
22
+ constructor(options: BindClientOptions);
23
+ /**
24
+ * Submit a prove job for async processing
25
+ * @param circuitId - The circuit identifier (e.g., "bind.mobility.riskband.v1")
26
+ * @param inputs - Circuit inputs as key-value pairs (all values must be strings)
27
+ * @returns The submitted job details
28
+ * @throws {ApiError} If the API request fails
29
+ * @throws {InsufficientCreditsError} If there aren't enough credits
30
+ */
31
+ submitProveJob(circuitId: string, inputs: ProveJobInputs): Promise<SubmitProveJobResponse>;
32
+ /**
33
+ * Get the status and results of a prove job
34
+ * @param jobId - The unique job identifier
35
+ * @returns The job details including status and outputs
36
+ */
37
+ getProveJob(jobId: string): Promise<GetProveJobResponse>;
38
+ /**
39
+ * List prove jobs for the authenticated organization
40
+ * @param options - Optional filters for status, limit, and offset
41
+ * @returns Paginated list of prove jobs
42
+ */
43
+ listProveJobs(options?: ListProveJobsOptions): Promise<ListProveJobsResponse>;
44
+ /**
45
+ * Poll for prove job completion
46
+ * @param jobId - The unique job identifier
47
+ * @param options - Polling options
48
+ * @returns The completed or failed job
49
+ * @throws {TimeoutError} If the job doesn't complete within the timeout
50
+ */
51
+ waitForProveJob(jobId: string, options?: {
52
+ intervalMs?: number;
53
+ timeoutMs?: number;
54
+ onProgress?: (job: ProveJob) => void;
55
+ }): Promise<ProveJob>;
56
+ /**
57
+ * List all available public policies
58
+ * @returns Array of public policy specifications
59
+ */
60
+ listPolicies(): Promise<PublicPolicySpec[]>;
61
+ /**
62
+ * Get a specific policy by ID
63
+ * @param policyId - The unique policy identifier
64
+ * @returns The public policy specification, or null if not found
65
+ */
66
+ getPolicy(policyId: string): Promise<PublicPolicySpec | null>;
67
+ /**
68
+ * List available zkTLS extractors (data sources)
69
+ * @returns Array of available extractors
70
+ */
71
+ listExtractors(): Promise<ListExtractorsResponse>;
72
+ /**
73
+ * List zkTLS attestations for the authenticated organization
74
+ * @returns Array of attestations
75
+ */
76
+ listAttestations(): Promise<ListAttestationsResponse>;
77
+ /**
78
+ * Get a specific attestation by ID
79
+ * @param attestationId - The attestation UUID
80
+ * @returns The attestation or null if not found
81
+ */
82
+ getAttestation(attestationId: string): Promise<GetAttestationResponse>;
83
+ /**
84
+ * Create a new zkTLS session for data attestation
85
+ * @param extractorId - The extractor to use (e.g., "coinbase")
86
+ * @param callbackUrl - URL to redirect to after authentication
87
+ * @returns Session ID and auth URL to redirect user to
88
+ */
89
+ createZkTlsSession(extractorId: string, callbackUrl: string): Promise<CreateSessionResponse>;
90
+ /**
91
+ * Get the status of a zkTLS session
92
+ * @param sessionId - The session UUID
93
+ * @returns Session status and attestation if completed
94
+ */
95
+ getZkTlsSession(sessionId: string): Promise<GetSessionResponse>;
96
+ /**
97
+ * Wait for a zkTLS session to complete
98
+ * @param sessionId - The session UUID
99
+ * @param options - Polling options
100
+ * @returns The completed session with attestation
101
+ * @throws {ZkTlsSessionExpiredError} If session expires
102
+ * @throws {ZkTlsSessionFailedError} If session fails
103
+ * @throws {TimeoutError} If timeout is reached
104
+ */
105
+ waitForZkTlsSession(sessionId: string, options?: {
106
+ intervalMs?: number;
107
+ timeoutMs?: number;
108
+ onProgress?: (session: ZkTlsSession) => void;
109
+ }): Promise<ZkTlsSession>;
110
+ /**
111
+ * List available circuits
112
+ * @param options - Optional filters
113
+ * @returns Array of circuits
114
+ */
115
+ listCircuits(options?: {
116
+ status?: 'active' | 'all';
117
+ policyId?: string;
118
+ }): Promise<ListCircuitsResponse>;
119
+ /**
120
+ * Get a specific circuit by ID
121
+ * @param circuitId - The circuit identifier
122
+ * @returns The circuit details or null if not found
123
+ */
124
+ getCircuit(circuitId: string): Promise<GetCircuitResponse>;
125
+ /**
126
+ * Activate a circuit (requires validation to have passed)
127
+ * @param circuitId - The circuit identifier to activate
128
+ * @returns The activation result
129
+ */
130
+ activateCircuit(circuitId: string): Promise<ActivateCircuitResponse>;
131
+ private fetch;
132
+ private sleep;
133
+ }
134
+
135
+ export { BindClient as B, deriveCircuitId as d };
@@ -0,0 +1,135 @@
1
+ import { PublicPolicySpec } from '@bind-protocol/policy-spec';
2
+ import { B as BindClientOptions, a as ProveJobInputs, e as SubmitProveJobResponse, G as GetProveJobResponse, L as ListProveJobsOptions, f as ListProveJobsResponse, c as ProveJob, p as ListExtractorsResponse, q as ListAttestationsResponse, r as GetAttestationResponse, s as CreateSessionResponse, t as GetSessionResponse, o as ZkTlsSession, i as ListCircuitsResponse, j as GetCircuitResponse, A as ActivateCircuitResponse } from './types-B6S0axfE.cjs';
3
+
4
+ /**
5
+ * BindClient - Main client for interacting with the Bind Protocol API
6
+ */
7
+
8
+ /**
9
+ * Derive a circuit ID from policy ID and version
10
+ * This matches the server's auto-generation logic.
11
+ * Format: {policyId}.v{version} with version dots replaced by underscores
12
+ *
13
+ * @example
14
+ * deriveCircuitId("bind.demo.credit-score", "0.1.0")
15
+ * // Returns: "bind.demo.credit-score.v0_1_0"
16
+ */
17
+ declare function deriveCircuitId(policyId: string, version: string): string;
18
+ declare class BindClient {
19
+ private readonly apiKey;
20
+ private readonly baseUrl;
21
+ private readonly headers;
22
+ constructor(options: BindClientOptions);
23
+ /**
24
+ * Submit a prove job for async processing
25
+ * @param circuitId - The circuit identifier (e.g., "bind.mobility.riskband.v1")
26
+ * @param inputs - Circuit inputs as key-value pairs (all values must be strings)
27
+ * @returns The submitted job details
28
+ * @throws {ApiError} If the API request fails
29
+ * @throws {InsufficientCreditsError} If there aren't enough credits
30
+ */
31
+ submitProveJob(circuitId: string, inputs: ProveJobInputs): Promise<SubmitProveJobResponse>;
32
+ /**
33
+ * Get the status and results of a prove job
34
+ * @param jobId - The unique job identifier
35
+ * @returns The job details including status and outputs
36
+ */
37
+ getProveJob(jobId: string): Promise<GetProveJobResponse>;
38
+ /**
39
+ * List prove jobs for the authenticated organization
40
+ * @param options - Optional filters for status, limit, and offset
41
+ * @returns Paginated list of prove jobs
42
+ */
43
+ listProveJobs(options?: ListProveJobsOptions): Promise<ListProveJobsResponse>;
44
+ /**
45
+ * Poll for prove job completion
46
+ * @param jobId - The unique job identifier
47
+ * @param options - Polling options
48
+ * @returns The completed or failed job
49
+ * @throws {TimeoutError} If the job doesn't complete within the timeout
50
+ */
51
+ waitForProveJob(jobId: string, options?: {
52
+ intervalMs?: number;
53
+ timeoutMs?: number;
54
+ onProgress?: (job: ProveJob) => void;
55
+ }): Promise<ProveJob>;
56
+ /**
57
+ * List all available public policies
58
+ * @returns Array of public policy specifications
59
+ */
60
+ listPolicies(): Promise<PublicPolicySpec[]>;
61
+ /**
62
+ * Get a specific policy by ID
63
+ * @param policyId - The unique policy identifier
64
+ * @returns The public policy specification, or null if not found
65
+ */
66
+ getPolicy(policyId: string): Promise<PublicPolicySpec | null>;
67
+ /**
68
+ * List available zkTLS extractors (data sources)
69
+ * @returns Array of available extractors
70
+ */
71
+ listExtractors(): Promise<ListExtractorsResponse>;
72
+ /**
73
+ * List zkTLS attestations for the authenticated organization
74
+ * @returns Array of attestations
75
+ */
76
+ listAttestations(): Promise<ListAttestationsResponse>;
77
+ /**
78
+ * Get a specific attestation by ID
79
+ * @param attestationId - The attestation UUID
80
+ * @returns The attestation or null if not found
81
+ */
82
+ getAttestation(attestationId: string): Promise<GetAttestationResponse>;
83
+ /**
84
+ * Create a new zkTLS session for data attestation
85
+ * @param extractorId - The extractor to use (e.g., "coinbase")
86
+ * @param callbackUrl - URL to redirect to after authentication
87
+ * @returns Session ID and auth URL to redirect user to
88
+ */
89
+ createZkTlsSession(extractorId: string, callbackUrl: string): Promise<CreateSessionResponse>;
90
+ /**
91
+ * Get the status of a zkTLS session
92
+ * @param sessionId - The session UUID
93
+ * @returns Session status and attestation if completed
94
+ */
95
+ getZkTlsSession(sessionId: string): Promise<GetSessionResponse>;
96
+ /**
97
+ * Wait for a zkTLS session to complete
98
+ * @param sessionId - The session UUID
99
+ * @param options - Polling options
100
+ * @returns The completed session with attestation
101
+ * @throws {ZkTlsSessionExpiredError} If session expires
102
+ * @throws {ZkTlsSessionFailedError} If session fails
103
+ * @throws {TimeoutError} If timeout is reached
104
+ */
105
+ waitForZkTlsSession(sessionId: string, options?: {
106
+ intervalMs?: number;
107
+ timeoutMs?: number;
108
+ onProgress?: (session: ZkTlsSession) => void;
109
+ }): Promise<ZkTlsSession>;
110
+ /**
111
+ * List available circuits
112
+ * @param options - Optional filters
113
+ * @returns Array of circuits
114
+ */
115
+ listCircuits(options?: {
116
+ status?: 'active' | 'all';
117
+ policyId?: string;
118
+ }): Promise<ListCircuitsResponse>;
119
+ /**
120
+ * Get a specific circuit by ID
121
+ * @param circuitId - The circuit identifier
122
+ * @returns The circuit details or null if not found
123
+ */
124
+ getCircuit(circuitId: string): Promise<GetCircuitResponse>;
125
+ /**
126
+ * Activate a circuit (requires validation to have passed)
127
+ * @param circuitId - The circuit identifier to activate
128
+ * @returns The activation result
129
+ */
130
+ activateCircuit(circuitId: string): Promise<ActivateCircuitResponse>;
131
+ private fetch;
132
+ private sleep;
133
+ }
134
+
135
+ export { BindClient as B, deriveCircuitId as d };
@@ -42,11 +42,37 @@ var InsufficientCreditsError = class extends BindError {
42
42
  this.name = "InsufficientCreditsError";
43
43
  }
44
44
  };
45
+ var ZkTlsSessionExpiredError = class extends BindError {
46
+ constructor(sessionId) {
47
+ super(`zkTLS session expired: ${sessionId}`, "ZKTLS_SESSION_EXPIRED", { sessionId });
48
+ this.sessionId = sessionId;
49
+ this.name = "ZkTlsSessionExpiredError";
50
+ }
51
+ };
52
+ var ZkTlsSessionFailedError = class extends BindError {
53
+ constructor(sessionId, sessionError) {
54
+ super(`zkTLS session failed: ${sessionError}`, "ZKTLS_SESSION_FAILED", { sessionId, sessionError });
55
+ this.sessionId = sessionId;
56
+ this.sessionError = sessionError;
57
+ this.name = "ZkTlsSessionFailedError";
58
+ }
59
+ };
60
+ var ZkTlsExtractorError = class extends BindError {
61
+ constructor(extractorId, message) {
62
+ super(message, "ZKTLS_EXTRACTOR_ERROR", { extractorId });
63
+ this.extractorId = extractorId;
64
+ this.name = "ZkTlsExtractorError";
65
+ }
66
+ };
45
67
 
46
68
  // src/core/client.ts
47
69
  var DEFAULT_BASE_URL = "https://api.bindprotocol.com";
48
70
  var DEFAULT_POLL_INTERVAL_MS = 2e3;
49
71
  var DEFAULT_TIMEOUT_MS = 3e5;
72
+ function deriveCircuitId(policyId, version) {
73
+ const sanitizedVersion = version.replace(/\./g, "_");
74
+ return `${policyId}.v${sanitizedVersion}`;
75
+ }
50
76
  var BindClient = class {
51
77
  apiKey;
52
78
  baseUrl;
@@ -156,7 +182,8 @@ var BindClient = class {
156
182
  response.status
157
183
  );
158
184
  }
159
- return response.json();
185
+ const json = await response.json();
186
+ return json.data ?? json;
160
187
  }
161
188
  /**
162
189
  * Get a specific policy by ID
@@ -177,6 +204,136 @@ var BindClient = class {
177
204
  response.status
178
205
  );
179
206
  }
207
+ const json = await response.json();
208
+ return json.data ?? json;
209
+ }
210
+ // ==========================================================================
211
+ // zkTLS Methods
212
+ // ==========================================================================
213
+ /**
214
+ * List available zkTLS extractors (data sources)
215
+ * @returns Array of available extractors
216
+ */
217
+ async listExtractors() {
218
+ const response = await this.fetch("/api/zktls/extractors");
219
+ return response.json();
220
+ }
221
+ /**
222
+ * List zkTLS attestations for the authenticated organization
223
+ * @returns Array of attestations
224
+ */
225
+ async listAttestations() {
226
+ const response = await this.fetch("/api/zktls/attestations");
227
+ return response.json();
228
+ }
229
+ /**
230
+ * Get a specific attestation by ID
231
+ * @param attestationId - The attestation UUID
232
+ * @returns The attestation or null if not found
233
+ */
234
+ async getAttestation(attestationId) {
235
+ const response = await this.fetch(`/api/zktls/attestations/${encodeURIComponent(attestationId)}`);
236
+ return response.json();
237
+ }
238
+ /**
239
+ * Create a new zkTLS session for data attestation
240
+ * @param extractorId - The extractor to use (e.g., "coinbase")
241
+ * @param callbackUrl - URL to redirect to after authentication
242
+ * @returns Session ID and auth URL to redirect user to
243
+ */
244
+ async createZkTlsSession(extractorId, callbackUrl) {
245
+ const response = await this.fetch("/api/zktls/sessions", {
246
+ method: "POST",
247
+ body: JSON.stringify({ extractor: extractorId, callbackUrl })
248
+ });
249
+ return response.json();
250
+ }
251
+ /**
252
+ * Get the status of a zkTLS session
253
+ * @param sessionId - The session UUID
254
+ * @returns Session status and attestation if completed
255
+ */
256
+ async getZkTlsSession(sessionId) {
257
+ const response = await this.fetch(`/api/zktls/sessions/${encodeURIComponent(sessionId)}`);
258
+ return response.json();
259
+ }
260
+ /**
261
+ * Wait for a zkTLS session to complete
262
+ * @param sessionId - The session UUID
263
+ * @param options - Polling options
264
+ * @returns The completed session with attestation
265
+ * @throws {ZkTlsSessionExpiredError} If session expires
266
+ * @throws {ZkTlsSessionFailedError} If session fails
267
+ * @throws {TimeoutError} If timeout is reached
268
+ */
269
+ async waitForZkTlsSession(sessionId, options = {}) {
270
+ const intervalMs = options.intervalMs ?? DEFAULT_POLL_INTERVAL_MS;
271
+ const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
272
+ const startTime = Date.now();
273
+ while (Date.now() - startTime < timeoutMs) {
274
+ const result = await this.getZkTlsSession(sessionId);
275
+ if (!result.success || !result.data) {
276
+ throw new ApiError(
277
+ result.error || "Failed to get zkTLS session",
278
+ 500,
279
+ result
280
+ );
281
+ }
282
+ const session = result.data;
283
+ if (options.onProgress) {
284
+ options.onProgress(session);
285
+ }
286
+ if (session.status === "completed") {
287
+ return session;
288
+ }
289
+ if (session.status === "failed") {
290
+ throw new ZkTlsSessionFailedError(sessionId, session.error || "Unknown error");
291
+ }
292
+ if (session.status === "expired") {
293
+ throw new ZkTlsSessionExpiredError(sessionId);
294
+ }
295
+ await this.sleep(intervalMs);
296
+ }
297
+ throw new TimeoutError(
298
+ `Timeout waiting for zkTLS session ${sessionId} after ${timeoutMs}ms`,
299
+ timeoutMs
300
+ );
301
+ }
302
+ // ==========================================================================
303
+ // Circuit Methods
304
+ // ==========================================================================
305
+ /**
306
+ * List available circuits
307
+ * @param options - Optional filters
308
+ * @returns Array of circuits
309
+ */
310
+ async listCircuits(options = {}) {
311
+ const params = new URLSearchParams();
312
+ if (options.status) params.set("status", options.status);
313
+ if (options.policyId) params.set("policyId", options.policyId);
314
+ const queryString = params.toString();
315
+ const path = queryString ? `/api/circuits?${queryString}` : "/api/circuits";
316
+ const response = await this.fetch(path);
317
+ return response.json();
318
+ }
319
+ /**
320
+ * Get a specific circuit by ID
321
+ * @param circuitId - The circuit identifier
322
+ * @returns The circuit details or null if not found
323
+ */
324
+ async getCircuit(circuitId) {
325
+ const response = await this.fetch(`/api/circuits/${encodeURIComponent(circuitId)}`);
326
+ return response.json();
327
+ }
328
+ /**
329
+ * Activate a circuit (requires validation to have passed)
330
+ * @param circuitId - The circuit identifier to activate
331
+ * @returns The activation result
332
+ */
333
+ async activateCircuit(circuitId) {
334
+ const response = await this.fetch(`/api/circuits/${encodeURIComponent(circuitId)}/activate`, {
335
+ method: "POST"
336
+ });
180
337
  return response.json();
181
338
  }
182
339
  // ==========================================================================
@@ -206,5 +363,9 @@ exports.BindClient = BindClient;
206
363
  exports.BindError = BindError;
207
364
  exports.InsufficientCreditsError = InsufficientCreditsError;
208
365
  exports.TimeoutError = TimeoutError;
366
+ exports.ZkTlsExtractorError = ZkTlsExtractorError;
367
+ exports.ZkTlsSessionExpiredError = ZkTlsSessionExpiredError;
368
+ exports.ZkTlsSessionFailedError = ZkTlsSessionFailedError;
369
+ exports.deriveCircuitId = deriveCircuitId;
209
370
  //# sourceMappingURL=index.cjs.map
210
371
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
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,IAA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,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 * 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}\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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AAK;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 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"]}
@@ -1,64 +1,6 @@
1
- import { PublicPolicySpec } from '@bind-protocol/policy-spec';
1
+ export { B as BindClient, d as deriveCircuitId } from '../client-Bh8Di-5n.cjs';
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.cjs';
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.cjs';
4
- export { g as BindCredential, b as ProveJobOutputs, P as ProveJobStatus, d as ProveJobSummary, S as SubmitProveJobRequest } from '../types-o4sbOK_a.cjs';
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, BindClient, BindClientOptions, BindError, GetProveJobResponse, InsufficientCreditsError, ListProveJobsOptions, ListProveJobsResponse, ProveJob, ProveJobInputs, SubmitProveJobResponse, TimeoutError };
53
+ export { ApiError, AuthenticationError, BindError, InsufficientCreditsError, TimeoutError, ZkTlsExtractorError, ZkTlsSessionExpiredError, ZkTlsSessionFailedError };