@bind-protocol/sdk 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{adapter-TZa35x8K.d.ts → adapter-Cl7HtxU3.d.ts} +2 -2
- package/dist/{adapter-D5b7G1RU.d.cts → adapter-zyYSX6_e.d.cts} +2 -2
- package/dist/adapters/dimo/index.d.cts +4 -3
- package/dist/adapters/dimo/index.d.ts +4 -3
- package/dist/adapters/index.cjs +151 -0
- 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 +151 -0
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/zktls/index.cjs +151 -0
- 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 +151 -0
- package/dist/adapters/zktls/index.js.map +1 -1
- package/dist/{client-BgnXV1AH.d.ts → client-BkohyCGJ.d.cts} +58 -1
- package/dist/{client-BN68auuk.d.cts → client-CadOSqx6.d.ts} +58 -1
- package/dist/core/index.cjs +151 -0
- 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 +151 -0
- package/dist/core/index.js.map +1 -1
- package/dist/index.cjs +151 -0
- 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 +151 -0
- package/dist/index.js.map +1 -1
- package/dist/{types-ohCQhfQK.d.ts → types-Ca_xbN13.d.ts} +1 -1
- package/dist/{types-CWadrDVs.d.cts → types-Cz9q5U3r.d.cts} +156 -1
- package/dist/{types-CWadrDVs.d.ts → types-Cz9q5U3r.d.ts} +156 -1
- package/dist/{types-CsmX8NG4.d.cts → types-DAN8BlbI.d.cts} +1 -1
- package/package.json +1 -1
package/dist/core/index.cjs
CHANGED
|
@@ -342,6 +342,157 @@ var BindClient = class {
|
|
|
342
342
|
return response.json();
|
|
343
343
|
}
|
|
344
344
|
// ==========================================================================
|
|
345
|
+
// Shared Proof Methods
|
|
346
|
+
// ==========================================================================
|
|
347
|
+
/**
|
|
348
|
+
* Share a completed proof with a verifier organization
|
|
349
|
+
* @param request - Share proof request with proveJobId and verifierOrgId
|
|
350
|
+
* @returns The created shared proof
|
|
351
|
+
*/
|
|
352
|
+
async shareProof(request) {
|
|
353
|
+
const response = await this.fetch("/api/shared-proofs", {
|
|
354
|
+
method: "POST",
|
|
355
|
+
body: JSON.stringify(request)
|
|
356
|
+
});
|
|
357
|
+
return response.json();
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* List shared proofs (outgoing or incoming)
|
|
361
|
+
* @param options - Filter by direction, pagination, and inclusion options
|
|
362
|
+
* @returns Paginated list of shared proofs
|
|
363
|
+
*/
|
|
364
|
+
async listSharedProofs(options = {}) {
|
|
365
|
+
const params = new URLSearchParams();
|
|
366
|
+
if (options.direction) params.set("direction", options.direction);
|
|
367
|
+
if (options.limit !== void 0) params.set("limit", options.limit.toString());
|
|
368
|
+
if (options.offset !== void 0) params.set("offset", options.offset.toString());
|
|
369
|
+
if (options.includeExpired) params.set("includeExpired", "true");
|
|
370
|
+
if (options.includeRevoked) params.set("includeRevoked", "true");
|
|
371
|
+
const queryString = params.toString();
|
|
372
|
+
const path = queryString ? `/api/shared-proofs?${queryString}` : "/api/shared-proofs";
|
|
373
|
+
const response = await this.fetch(path);
|
|
374
|
+
return response.json();
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Get a specific shared proof by ID
|
|
378
|
+
* @param sharedProofId - The shared proof ID
|
|
379
|
+
* @returns The shared proof details
|
|
380
|
+
*/
|
|
381
|
+
async getSharedProof(sharedProofId) {
|
|
382
|
+
const response = await this.fetch(`/api/shared-proofs/${encodeURIComponent(sharedProofId)}`);
|
|
383
|
+
return response.json();
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Revoke a shared proof. Only the sharing organization can revoke.
|
|
387
|
+
* @param sharedProofId - The shared proof ID to revoke
|
|
388
|
+
* @returns The revocation result
|
|
389
|
+
*/
|
|
390
|
+
async revokeSharedProof(sharedProofId) {
|
|
391
|
+
const response = await this.fetch(`/api/shared-proofs/${encodeURIComponent(sharedProofId)}`, {
|
|
392
|
+
method: "DELETE"
|
|
393
|
+
});
|
|
394
|
+
return response.json();
|
|
395
|
+
}
|
|
396
|
+
// ==========================================================================
|
|
397
|
+
// Verification Methods
|
|
398
|
+
// ==========================================================================
|
|
399
|
+
/**
|
|
400
|
+
* Verify a shared proof
|
|
401
|
+
*
|
|
402
|
+
* This method queues a verification job and polls until completion.
|
|
403
|
+
* Verification is performed asynchronously by the prover worker.
|
|
404
|
+
*
|
|
405
|
+
* @param sharedProofId - The shared proof ID to verify
|
|
406
|
+
* @param options - Optional polling configuration
|
|
407
|
+
* @returns The verification result
|
|
408
|
+
*/
|
|
409
|
+
async verifySharedProof(sharedProofId, options) {
|
|
410
|
+
const pollIntervalMs = options?.pollIntervalMs ?? 1e3;
|
|
411
|
+
const maxWaitMs = options?.maxWaitMs ?? 12e4;
|
|
412
|
+
const queueResponse = await this.fetch(`/api/verify/shared/${encodeURIComponent(sharedProofId)}`, {
|
|
413
|
+
method: "POST"
|
|
414
|
+
});
|
|
415
|
+
const queueResult = await queueResponse.json();
|
|
416
|
+
if (!queueResult.success || !queueResult.data?.jobId) {
|
|
417
|
+
return {
|
|
418
|
+
success: false,
|
|
419
|
+
error: queueResult.error ?? "Failed to queue verification job"
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
const jobId = queueResult.data.jobId;
|
|
423
|
+
const startTime = Date.now();
|
|
424
|
+
while (Date.now() - startTime < maxWaitMs) {
|
|
425
|
+
const statusResult = await this.getVerifyJobStatus(jobId);
|
|
426
|
+
if (!statusResult.success) {
|
|
427
|
+
return {
|
|
428
|
+
success: false,
|
|
429
|
+
error: statusResult.error ?? "Failed to get verification status"
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
const status = statusResult.data?.status;
|
|
433
|
+
if (status === "completed" || status === "failed") {
|
|
434
|
+
return {
|
|
435
|
+
success: true,
|
|
436
|
+
data: {
|
|
437
|
+
isValid: statusResult.data?.isValid ?? false,
|
|
438
|
+
error: statusResult.data?.error,
|
|
439
|
+
verificationTimeMs: statusResult.data?.verificationTimeMs ?? 0,
|
|
440
|
+
creditsCharged: statusResult.data?.creditsCharged ?? queueResult.data.creditsCharged,
|
|
441
|
+
verificationResultId: statusResult.data?.verificationResultId ?? jobId
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
|
446
|
+
}
|
|
447
|
+
return {
|
|
448
|
+
success: false,
|
|
449
|
+
error: `Verification timed out after ${maxWaitMs}ms. Job ID: ${jobId}`
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Get the status of a verification job
|
|
454
|
+
* @param jobId - The verification job ID
|
|
455
|
+
* @returns The job status
|
|
456
|
+
*/
|
|
457
|
+
async getVerifyJobStatus(jobId) {
|
|
458
|
+
const response = await this.fetch(`/api/verify/jobs/${encodeURIComponent(jobId)}`);
|
|
459
|
+
return response.json();
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Verify an uploaded proof
|
|
463
|
+
* @param proofBuffer - The proof binary as ArrayBuffer, Uint8Array, or Buffer
|
|
464
|
+
* @param vkBuffer - The verification key binary as ArrayBuffer, Uint8Array, or Buffer
|
|
465
|
+
* @returns The verification result
|
|
466
|
+
*/
|
|
467
|
+
async verifyUploadedProof(proofBuffer, vkBuffer) {
|
|
468
|
+
const proofBytes = proofBuffer instanceof Uint8Array ? proofBuffer : new Uint8Array(proofBuffer);
|
|
469
|
+
const vkBytes = vkBuffer instanceof Uint8Array ? vkBuffer : new Uint8Array(vkBuffer);
|
|
470
|
+
const proofBase64 = typeof Buffer !== "undefined" ? Buffer.from(proofBytes).toString("base64") : btoa(String.fromCharCode(...proofBytes));
|
|
471
|
+
const vkBase64 = typeof Buffer !== "undefined" ? Buffer.from(vkBytes).toString("base64") : btoa(String.fromCharCode(...vkBytes));
|
|
472
|
+
const response = await this.fetch("/api/verify/upload", {
|
|
473
|
+
method: "POST",
|
|
474
|
+
body: JSON.stringify({
|
|
475
|
+
proof: proofBase64,
|
|
476
|
+
vk: vkBase64
|
|
477
|
+
})
|
|
478
|
+
});
|
|
479
|
+
return response.json();
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Get verification history for the authenticated organization
|
|
483
|
+
* @param options - Pagination options
|
|
484
|
+
* @returns Paginated list of verification results
|
|
485
|
+
*/
|
|
486
|
+
async getVerificationHistory(options = {}) {
|
|
487
|
+
const params = new URLSearchParams();
|
|
488
|
+
if (options.limit !== void 0) params.set("limit", options.limit.toString());
|
|
489
|
+
if (options.offset !== void 0) params.set("offset", options.offset.toString());
|
|
490
|
+
const queryString = params.toString();
|
|
491
|
+
const path = queryString ? `/api/verify/history?${queryString}` : "/api/verify/history";
|
|
492
|
+
const response = await this.fetch(path);
|
|
493
|
+
return response.json();
|
|
494
|
+
}
|
|
495
|
+
// ==========================================================================
|
|
345
496
|
// Private Helpers
|
|
346
497
|
// ==========================================================================
|
|
347
498
|
async fetch(path, init) {
|
package/dist/core/index.cjs.map
CHANGED
|
@@ -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,IA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AAO,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.cjs","sourcesContent":["/**\n * Custom error classes for the Bind Protocol SDK\n */\n\nexport class BindError extends Error {\n constructor(\n message: string,\n public readonly code: string,\n public readonly details?: Record<string, unknown>\n ) {\n super(message);\n this.name = 'BindError';\n }\n}\n\nexport class ApiError extends BindError {\n constructor(\n message: string,\n public readonly status: number,\n public readonly response?: unknown\n ) {\n super(message, 'API_ERROR', { status, response });\n this.name = 'ApiError';\n }\n}\n\nexport class AuthenticationError extends BindError {\n constructor(message = 'Authentication failed') {\n super(message, 'AUTH_ERROR');\n this.name = 'AuthenticationError';\n }\n}\n\nexport class TimeoutError extends BindError {\n constructor(message: string, public readonly timeoutMs: number) {\n super(message, 'TIMEOUT_ERROR', { timeoutMs });\n this.name = 'TimeoutError';\n }\n}\n\nexport class InsufficientCreditsError extends BindError {\n constructor(\n public readonly required: number,\n public readonly available: number\n ) {\n super(\n `Insufficient credits: need ${required}, have ${available}`,\n 'INSUFFICIENT_CREDITS',\n { required, available }\n );\n this.name = 'InsufficientCreditsError';\n }\n}\n\n/**\n * Thrown when a zkTLS session expires before completion\n */\nexport class ZkTlsSessionExpiredError extends BindError {\n constructor(public readonly sessionId: string) {\n super(`zkTLS session expired: ${sessionId}`, 'ZKTLS_SESSION_EXPIRED', { sessionId });\n this.name = 'ZkTlsSessionExpiredError';\n }\n}\n\n/**\n * Thrown when a zkTLS session fails\n */\nexport class ZkTlsSessionFailedError extends BindError {\n constructor(\n public readonly sessionId: string,\n public readonly sessionError: string\n ) {\n super(`zkTLS session failed: ${sessionError}`, 'ZKTLS_SESSION_FAILED', { sessionId, sessionError });\n this.name = 'ZkTlsSessionFailedError';\n }\n}\n\n/**\n * Thrown when an extractor is not found or disabled\n */\nexport class ZkTlsExtractorError extends BindError {\n constructor(\n public readonly extractorId: string,\n message: string\n ) {\n super(message, 'ZKTLS_EXTRACTOR_ERROR', { extractorId });\n this.name = 'ZkTlsExtractorError';\n }\n}\n","/**\n * BindClient - Main client for interacting with the Bind Protocol API\n */\nimport type { PublicPolicySpec } from '@bind-protocol/policy-spec';\nimport {\n ApiError,\n AuthenticationError,\n InsufficientCreditsError,\n TimeoutError,\n ZkTlsSessionExpiredError,\n ZkTlsSessionFailedError,\n} from './errors';\nimport type {\n BindClientOptions,\n ProveJobInputs,\n SubmitProveJobResponse,\n GetProveJobResponse,\n ListProveJobsOptions,\n ListProveJobsResponse,\n ProveJob,\n VerificationMode,\n ListExtractorsResponse,\n ListAttestationsResponse,\n GetAttestationResponse,\n CreateSessionResponse,\n GetSessionResponse,\n ZkTlsSession,\n Circuit,\n ListCircuitsResponse,\n GetCircuitResponse,\n ActivateCircuitResponse,\n} from './types';\n\nconst DEFAULT_BASE_URL = 'https://api.bindprotocol.com';\nconst DEFAULT_POLL_INTERVAL_MS = 2000;\nconst DEFAULT_TIMEOUT_MS = 300000; // 5 minutes\n\n/**\n * Derive a circuit ID from policy ID and version\n * This matches the server's auto-generation logic.\n * Format: {policyId}.v{version} with version dots replaced by underscores\n *\n * @example\n * deriveCircuitId(\"bind.demo.credit-score\", \"0.1.0\")\n * // Returns: \"bind.demo.credit-score.v0_1_0\"\n */\nexport function deriveCircuitId(policyId: string, version: string): string {\n const sanitizedVersion = version.replace(/\\./g, '_');\n return `${policyId}.v${sanitizedVersion}`;\n}\n\nexport class BindClient {\n private readonly apiKey: string;\n private readonly baseUrl: string;\n private readonly headers: Record<string, string>;\n\n constructor(options: BindClientOptions) {\n this.apiKey = options.apiKey;\n this.baseUrl = options.baseUrl || process.env.BIND_API_URL || DEFAULT_BASE_URL;\n this.headers = {\n 'X-API-Key': this.apiKey,\n 'Content-Type': 'application/json',\n };\n }\n\n // ==========================================================================\n // Prove Job Methods\n // ==========================================================================\n\n /**\n * Submit a prove job for async processing\n * @param circuitId - The circuit identifier (e.g., \"bind.mobility.riskband.v1\")\n * @param inputs - Circuit inputs as key-value pairs (all values must be strings)\n * @param options - Optional configuration including verificationMode\n * @returns The submitted job details\n * @throws {ApiError} If the API request fails\n * @throws {InsufficientCreditsError} If there aren't enough credits\n */\n async submitProveJob(\n circuitId: string,\n inputs: ProveJobInputs,\n options?: {\n /**\n * How to verify the proof:\n * - 'zkverify': Submit to zkVerify blockchain (default if zkVerify is enabled)\n * - 'self_verify': Store in S3, client downloads and verifies locally\n */\n verificationMode?: VerificationMode;\n }\n ): Promise<SubmitProveJobResponse> {\n const response = await this.fetch('/api/prove', {\n method: 'POST',\n body: JSON.stringify({\n circuitId,\n inputs,\n verificationMode: options?.verificationMode,\n }),\n });\n\n const result: SubmitProveJobResponse = await response.json();\n\n // Check for insufficient credits\n if (!result.success && result.requiredCredits !== undefined && result.availableCredits !== undefined) {\n throw new InsufficientCreditsError(result.requiredCredits, result.availableCredits);\n }\n\n return result;\n }\n\n /**\n * Get the status and results of a prove job\n * @param jobId - The unique job identifier\n * @returns The job details including status and outputs\n */\n async getProveJob(jobId: string): Promise<GetProveJobResponse> {\n const response = await this.fetch(`/api/prove/${encodeURIComponent(jobId)}`);\n return response.json();\n }\n\n /**\n * List prove jobs for the authenticated organization\n * @param options - Optional filters for status, limit, and offset\n * @returns Paginated list of prove jobs\n */\n async listProveJobs(options: ListProveJobsOptions = {}): Promise<ListProveJobsResponse> {\n const params = new URLSearchParams();\n if (options.status) params.set('status', options.status);\n if (options.limit !== undefined) params.set('limit', options.limit.toString());\n if (options.offset !== undefined) params.set('offset', options.offset.toString());\n\n const queryString = params.toString();\n const path = queryString ? `/api/prove?${queryString}` : '/api/prove';\n\n const response = await this.fetch(path);\n return response.json();\n }\n\n /**\n * Poll for prove job completion\n * @param jobId - The unique job identifier\n * @param options - Polling options\n * @returns The completed or failed job\n * @throws {TimeoutError} If the job doesn't complete within the timeout\n */\n async waitForProveJob(\n jobId: string,\n options: {\n intervalMs?: number;\n timeoutMs?: number;\n onProgress?: (job: ProveJob) => void;\n } = {}\n ): Promise<ProveJob> {\n const intervalMs = options.intervalMs ?? DEFAULT_POLL_INTERVAL_MS;\n const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const startTime = Date.now();\n\n while (Date.now() - startTime < timeoutMs) {\n const result = await this.getProveJob(jobId);\n\n if (!result.success || !result.data) {\n throw new ApiError(\n result.error || 'Failed to get prove job',\n 500,\n result\n );\n }\n\n const job = result.data;\n\n if (options.onProgress) {\n options.onProgress(job);\n }\n\n if (job.status === 'completed' || job.status === 'failed') {\n return job;\n }\n\n await this.sleep(intervalMs);\n }\n\n throw new TimeoutError(\n `Timeout waiting for prove job ${jobId} after ${timeoutMs}ms`,\n timeoutMs\n );\n }\n\n // ==========================================================================\n // Policy Methods (Public, no authentication required)\n // ==========================================================================\n\n /**\n * List all available public policies\n * @returns Array of public policy specifications\n */\n async listPolicies(): Promise<PublicPolicySpec[]> {\n const response = await fetch(`${this.baseUrl}/api/policies`, {\n method: 'GET',\n });\n\n if (!response.ok) {\n throw new ApiError(\n `Failed to fetch policies: ${response.statusText}`,\n response.status\n );\n }\n\n const json = await response.json();\n // API wraps response in { success, data }\n return json.data ?? json;\n }\n\n /**\n * Get a specific policy by ID\n * @param policyId - The unique policy identifier\n * @returns The public policy specification, or null if not found\n */\n async getPolicy(policyId: string): Promise<PublicPolicySpec | null> {\n const response = await fetch(\n `${this.baseUrl}/api/policies/${encodeURIComponent(policyId)}`,\n { method: 'GET' }\n );\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new ApiError(\n `Failed to fetch policy: ${response.statusText}`,\n response.status\n );\n }\n\n const json = await response.json();\n // API wraps response in { success, data }\n return json.data ?? json;\n }\n\n // ==========================================================================\n // zkTLS Methods\n // ==========================================================================\n\n /**\n * List available zkTLS extractors (data sources)\n * @returns Array of available extractors\n */\n async listExtractors(): Promise<ListExtractorsResponse> {\n const response = await this.fetch('/api/zktls/extractors');\n return response.json();\n }\n\n /**\n * List zkTLS attestations for the authenticated organization\n * @returns Array of attestations\n */\n async listAttestations(): Promise<ListAttestationsResponse> {\n const response = await this.fetch('/api/zktls/attestations');\n return response.json();\n }\n\n /**\n * Get a specific attestation by ID\n * @param attestationId - The attestation UUID\n * @returns The attestation or null if not found\n */\n async getAttestation(attestationId: string): Promise<GetAttestationResponse> {\n const response = await this.fetch(`/api/zktls/attestations/${encodeURIComponent(attestationId)}`);\n return response.json();\n }\n\n /**\n * Create a new zkTLS session for data attestation\n * @param extractorId - The extractor to use (e.g., \"coinbase\")\n * @param callbackUrl - URL to redirect to after authentication\n * @returns Session ID and auth URL to redirect user to\n */\n async createZkTlsSession(\n extractorId: string,\n callbackUrl: string\n ): Promise<CreateSessionResponse> {\n const response = await this.fetch('/api/zktls/sessions', {\n method: 'POST',\n body: JSON.stringify({ extractor: extractorId, callbackUrl }),\n });\n return response.json();\n }\n\n /**\n * Get the status of a zkTLS session\n * @param sessionId - The session UUID\n * @returns Session status and attestation if completed\n */\n async getZkTlsSession(sessionId: string): Promise<GetSessionResponse> {\n const response = await this.fetch(`/api/zktls/sessions/${encodeURIComponent(sessionId)}`);\n return response.json();\n }\n\n /**\n * Wait for a zkTLS session to complete\n * @param sessionId - The session UUID\n * @param options - Polling options\n * @returns The completed session with attestation\n * @throws {ZkTlsSessionExpiredError} If session expires\n * @throws {ZkTlsSessionFailedError} If session fails\n * @throws {TimeoutError} If timeout is reached\n */\n async waitForZkTlsSession(\n sessionId: string,\n options: {\n intervalMs?: number;\n timeoutMs?: number;\n onProgress?: (session: ZkTlsSession) => void;\n } = {}\n ): Promise<ZkTlsSession> {\n const intervalMs = options.intervalMs ?? DEFAULT_POLL_INTERVAL_MS;\n const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const startTime = Date.now();\n\n while (Date.now() - startTime < timeoutMs) {\n const result = await this.getZkTlsSession(sessionId);\n\n if (!result.success || !result.data) {\n throw new ApiError(\n result.error || 'Failed to get zkTLS session',\n 500,\n result\n );\n }\n\n const session = result.data;\n\n if (options.onProgress) {\n options.onProgress(session);\n }\n\n if (session.status === 'completed') {\n return session;\n }\n\n if (session.status === 'failed') {\n throw new ZkTlsSessionFailedError(sessionId, session.error || 'Unknown error');\n }\n\n if (session.status === 'expired') {\n throw new ZkTlsSessionExpiredError(sessionId);\n }\n\n await this.sleep(intervalMs);\n }\n\n throw new TimeoutError(\n `Timeout waiting for zkTLS session ${sessionId} after ${timeoutMs}ms`,\n timeoutMs\n );\n }\n\n // ==========================================================================\n // Circuit Methods\n // ==========================================================================\n\n /**\n * List available circuits\n * @param options - Optional filters\n * @returns Array of circuits\n */\n async listCircuits(options: { status?: 'active' | 'all'; policyId?: string } = {}): Promise<ListCircuitsResponse> {\n const params = new URLSearchParams();\n if (options.status) params.set('status', options.status);\n if (options.policyId) params.set('policyId', options.policyId);\n\n const queryString = params.toString();\n const path = queryString ? `/api/circuits?${queryString}` : '/api/circuits';\n\n const response = await this.fetch(path);\n return response.json();\n }\n\n /**\n * Get a specific circuit by ID\n * @param circuitId - The circuit identifier\n * @returns The circuit details or null if not found\n */\n async getCircuit(circuitId: string): Promise<GetCircuitResponse> {\n const response = await this.fetch(`/api/circuits/${encodeURIComponent(circuitId)}`);\n return response.json();\n }\n\n /**\n * Activate a circuit (requires validation to have passed)\n * @param circuitId - The circuit identifier to activate\n * @returns The activation result\n */\n async activateCircuit(circuitId: string): Promise<ActivateCircuitResponse> {\n const response = await this.fetch(`/api/circuits/${encodeURIComponent(circuitId)}/activate`, {\n method: 'POST',\n });\n return response.json();\n }\n\n // ==========================================================================\n // 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,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custom error classes for the Bind Protocol SDK\n */\n\nexport class BindError extends Error {\n constructor(\n message: string,\n public readonly code: string,\n public readonly details?: Record<string, unknown>\n ) {\n super(message);\n this.name = 'BindError';\n }\n}\n\nexport class ApiError extends BindError {\n constructor(\n message: string,\n public readonly status: number,\n public readonly response?: unknown\n ) {\n super(message, 'API_ERROR', { status, response });\n this.name = 'ApiError';\n }\n}\n\nexport class AuthenticationError extends BindError {\n constructor(message = 'Authentication failed') {\n super(message, 'AUTH_ERROR');\n this.name = 'AuthenticationError';\n }\n}\n\nexport class TimeoutError extends BindError {\n constructor(message: string, public readonly timeoutMs: number) {\n super(message, 'TIMEOUT_ERROR', { timeoutMs });\n this.name = 'TimeoutError';\n }\n}\n\nexport class InsufficientCreditsError extends BindError {\n constructor(\n public readonly required: number,\n public readonly available: number\n ) {\n super(\n `Insufficient credits: need ${required}, have ${available}`,\n 'INSUFFICIENT_CREDITS',\n { required, available }\n );\n this.name = 'InsufficientCreditsError';\n }\n}\n\n/**\n * Thrown when a zkTLS session expires before completion\n */\nexport class ZkTlsSessionExpiredError extends BindError {\n constructor(public readonly sessionId: string) {\n super(`zkTLS session expired: ${sessionId}`, 'ZKTLS_SESSION_EXPIRED', { sessionId });\n this.name = 'ZkTlsSessionExpiredError';\n }\n}\n\n/**\n * Thrown when a zkTLS session fails\n */\nexport class ZkTlsSessionFailedError extends BindError {\n constructor(\n public readonly sessionId: string,\n public readonly sessionError: string\n ) {\n super(`zkTLS session failed: ${sessionError}`, 'ZKTLS_SESSION_FAILED', { sessionId, sessionError });\n this.name = 'ZkTlsSessionFailedError';\n }\n}\n\n/**\n * Thrown when an extractor is not found or disabled\n */\nexport class ZkTlsExtractorError extends BindError {\n constructor(\n public readonly extractorId: string,\n message: string\n ) {\n super(message, 'ZKTLS_EXTRACTOR_ERROR', { extractorId });\n this.name = 'ZkTlsExtractorError';\n }\n}\n","/**\n * BindClient - Main client for interacting with the Bind Protocol API\n */\nimport type { PublicPolicySpec } from '@bind-protocol/policy-spec';\nimport {\n ApiError,\n AuthenticationError,\n InsufficientCreditsError,\n TimeoutError,\n ZkTlsSessionExpiredError,\n ZkTlsSessionFailedError,\n} from './errors';\nimport type {\n BindClientOptions,\n ProveJobInputs,\n SubmitProveJobResponse,\n GetProveJobResponse,\n ListProveJobsOptions,\n ListProveJobsResponse,\n ProveJob,\n VerificationMode,\n ListExtractorsResponse,\n ListAttestationsResponse,\n GetAttestationResponse,\n CreateSessionResponse,\n GetSessionResponse,\n ZkTlsSession,\n Circuit,\n ListCircuitsResponse,\n GetCircuitResponse,\n ActivateCircuitResponse,\n ShareProofRequest,\n ShareProofResponse,\n ListSharedProofsOptions,\n ListSharedProofsResponse,\n GetSharedProofResponse,\n RevokeSharedProofResponse,\n VerifySharedProofResponse,\n VerifyJobQueuedResponse,\n VerifyJobStatusResponse,\n VerifyUploadedProofResponse,\n GetVerificationHistoryOptions,\n GetVerificationHistoryResponse,\n} from './types';\n\nconst DEFAULT_BASE_URL = 'https://api.bindprotocol.com';\nconst DEFAULT_POLL_INTERVAL_MS = 2000;\nconst DEFAULT_TIMEOUT_MS = 300000; // 5 minutes\n\n/**\n * Derive a circuit ID from policy ID and version\n * This matches the server's auto-generation logic.\n * Format: {policyId}.v{version} with version dots replaced by underscores\n *\n * @example\n * deriveCircuitId(\"bind.demo.credit-score\", \"0.1.0\")\n * // Returns: \"bind.demo.credit-score.v0_1_0\"\n */\nexport function deriveCircuitId(policyId: string, version: string): string {\n const sanitizedVersion = version.replace(/\\./g, '_');\n return `${policyId}.v${sanitizedVersion}`;\n}\n\nexport class BindClient {\n private readonly apiKey: string;\n private readonly baseUrl: string;\n private readonly headers: Record<string, string>;\n\n constructor(options: BindClientOptions) {\n this.apiKey = options.apiKey;\n this.baseUrl = options.baseUrl || process.env.BIND_API_URL || DEFAULT_BASE_URL;\n this.headers = {\n 'X-API-Key': this.apiKey,\n 'Content-Type': 'application/json',\n };\n }\n\n // ==========================================================================\n // Prove Job Methods\n // ==========================================================================\n\n /**\n * Submit a prove job for async processing\n * @param circuitId - The circuit identifier (e.g., \"bind.mobility.riskband.v1\")\n * @param inputs - Circuit inputs as key-value pairs (all values must be strings)\n * @param options - Optional configuration including verificationMode\n * @returns The submitted job details\n * @throws {ApiError} If the API request fails\n * @throws {InsufficientCreditsError} If there aren't enough credits\n */\n async submitProveJob(\n circuitId: string,\n inputs: ProveJobInputs,\n options?: {\n /**\n * How to verify the proof:\n * - 'zkverify': Submit to zkVerify blockchain (default if zkVerify is enabled)\n * - 'self_verify': Store in S3, client downloads and verifies locally\n */\n verificationMode?: VerificationMode;\n }\n ): Promise<SubmitProveJobResponse> {\n const response = await this.fetch('/api/prove', {\n method: 'POST',\n body: JSON.stringify({\n circuitId,\n inputs,\n verificationMode: options?.verificationMode,\n }),\n });\n\n const result: SubmitProveJobResponse = await response.json();\n\n // Check for insufficient credits\n if (!result.success && result.requiredCredits !== undefined && result.availableCredits !== undefined) {\n throw new InsufficientCreditsError(result.requiredCredits, result.availableCredits);\n }\n\n return result;\n }\n\n /**\n * Get the status and results of a prove job\n * @param jobId - The unique job identifier\n * @returns The job details including status and outputs\n */\n async getProveJob(jobId: string): Promise<GetProveJobResponse> {\n const response = await this.fetch(`/api/prove/${encodeURIComponent(jobId)}`);\n return response.json();\n }\n\n /**\n * List prove jobs for the authenticated organization\n * @param options - Optional filters for status, limit, and offset\n * @returns Paginated list of prove jobs\n */\n async listProveJobs(options: ListProveJobsOptions = {}): Promise<ListProveJobsResponse> {\n const params = new URLSearchParams();\n if (options.status) params.set('status', options.status);\n if (options.limit !== undefined) params.set('limit', options.limit.toString());\n if (options.offset !== undefined) params.set('offset', options.offset.toString());\n\n const queryString = params.toString();\n const path = queryString ? `/api/prove?${queryString}` : '/api/prove';\n\n const response = await this.fetch(path);\n return response.json();\n }\n\n /**\n * Poll for prove job completion\n * @param jobId - The unique job identifier\n * @param options - Polling options\n * @returns The completed or failed job\n * @throws {TimeoutError} If the job doesn't complete within the timeout\n */\n async waitForProveJob(\n jobId: string,\n options: {\n intervalMs?: number;\n timeoutMs?: number;\n onProgress?: (job: ProveJob) => void;\n } = {}\n ): Promise<ProveJob> {\n const intervalMs = options.intervalMs ?? DEFAULT_POLL_INTERVAL_MS;\n const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const startTime = Date.now();\n\n while (Date.now() - startTime < timeoutMs) {\n const result = await this.getProveJob(jobId);\n\n if (!result.success || !result.data) {\n throw new ApiError(\n result.error || 'Failed to get prove job',\n 500,\n result\n );\n }\n\n const job = result.data;\n\n if (options.onProgress) {\n options.onProgress(job);\n }\n\n if (job.status === 'completed' || job.status === 'failed') {\n return job;\n }\n\n await this.sleep(intervalMs);\n }\n\n throw new TimeoutError(\n `Timeout waiting for prove job ${jobId} after ${timeoutMs}ms`,\n timeoutMs\n );\n }\n\n // ==========================================================================\n // Policy Methods (Public, no authentication required)\n // ==========================================================================\n\n /**\n * List all available public policies\n * @returns Array of public policy specifications\n */\n async listPolicies(): Promise<PublicPolicySpec[]> {\n const response = await fetch(`${this.baseUrl}/api/policies`, {\n method: 'GET',\n });\n\n if (!response.ok) {\n throw new ApiError(\n `Failed to fetch policies: ${response.statusText}`,\n response.status\n );\n }\n\n const json = await response.json();\n // API wraps response in { success, data }\n return json.data ?? json;\n }\n\n /**\n * Get a specific policy by ID\n * @param policyId - The unique policy identifier\n * @returns The public policy specification, or null if not found\n */\n async getPolicy(policyId: string): Promise<PublicPolicySpec | null> {\n const response = await fetch(\n `${this.baseUrl}/api/policies/${encodeURIComponent(policyId)}`,\n { method: 'GET' }\n );\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new ApiError(\n `Failed to fetch policy: ${response.statusText}`,\n response.status\n );\n }\n\n const json = await response.json();\n // API wraps response in { success, data }\n return json.data ?? json;\n }\n\n // ==========================================================================\n // zkTLS Methods\n // ==========================================================================\n\n /**\n * List available zkTLS extractors (data sources)\n * @returns Array of available extractors\n */\n async listExtractors(): Promise<ListExtractorsResponse> {\n const response = await this.fetch('/api/zktls/extractors');\n return response.json();\n }\n\n /**\n * List zkTLS attestations for the authenticated organization\n * @returns Array of attestations\n */\n async listAttestations(): Promise<ListAttestationsResponse> {\n const response = await this.fetch('/api/zktls/attestations');\n return response.json();\n }\n\n /**\n * Get a specific attestation by ID\n * @param attestationId - The attestation UUID\n * @returns The attestation or null if not found\n */\n async getAttestation(attestationId: string): Promise<GetAttestationResponse> {\n const response = await this.fetch(`/api/zktls/attestations/${encodeURIComponent(attestationId)}`);\n return response.json();\n }\n\n /**\n * Create a new zkTLS session for data attestation\n * @param extractorId - The extractor to use (e.g., \"coinbase\")\n * @param callbackUrl - URL to redirect to after authentication\n * @returns Session ID and auth URL to redirect user to\n */\n async createZkTlsSession(\n extractorId: string,\n callbackUrl: string\n ): Promise<CreateSessionResponse> {\n const response = await this.fetch('/api/zktls/sessions', {\n method: 'POST',\n body: JSON.stringify({ extractor: extractorId, callbackUrl }),\n });\n return response.json();\n }\n\n /**\n * Get the status of a zkTLS session\n * @param sessionId - The session UUID\n * @returns Session status and attestation if completed\n */\n async getZkTlsSession(sessionId: string): Promise<GetSessionResponse> {\n const response = await this.fetch(`/api/zktls/sessions/${encodeURIComponent(sessionId)}`);\n return response.json();\n }\n\n /**\n * Wait for a zkTLS session to complete\n * @param sessionId - The session UUID\n * @param options - Polling options\n * @returns The completed session with attestation\n * @throws {ZkTlsSessionExpiredError} If session expires\n * @throws {ZkTlsSessionFailedError} If session fails\n * @throws {TimeoutError} If timeout is reached\n */\n async waitForZkTlsSession(\n sessionId: string,\n options: {\n intervalMs?: number;\n timeoutMs?: number;\n onProgress?: (session: ZkTlsSession) => void;\n } = {}\n ): Promise<ZkTlsSession> {\n const intervalMs = options.intervalMs ?? DEFAULT_POLL_INTERVAL_MS;\n const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const startTime = Date.now();\n\n while (Date.now() - startTime < timeoutMs) {\n const result = await this.getZkTlsSession(sessionId);\n\n if (!result.success || !result.data) {\n throw new ApiError(\n result.error || 'Failed to get zkTLS session',\n 500,\n result\n );\n }\n\n const session = result.data;\n\n if (options.onProgress) {\n options.onProgress(session);\n }\n\n if (session.status === 'completed') {\n return session;\n }\n\n if (session.status === 'failed') {\n throw new ZkTlsSessionFailedError(sessionId, session.error || 'Unknown error');\n }\n\n if (session.status === 'expired') {\n throw new ZkTlsSessionExpiredError(sessionId);\n }\n\n await this.sleep(intervalMs);\n }\n\n throw new TimeoutError(\n `Timeout waiting for zkTLS session ${sessionId} after ${timeoutMs}ms`,\n timeoutMs\n );\n }\n\n // ==========================================================================\n // Circuit Methods\n // ==========================================================================\n\n /**\n * List available circuits\n * @param options - Optional filters\n * @returns Array of circuits\n */\n async listCircuits(options: { status?: 'active' | 'all'; policyId?: string } = {}): Promise<ListCircuitsResponse> {\n const params = new URLSearchParams();\n if (options.status) params.set('status', options.status);\n if (options.policyId) params.set('policyId', options.policyId);\n\n const queryString = params.toString();\n const path = queryString ? `/api/circuits?${queryString}` : '/api/circuits';\n\n const response = await this.fetch(path);\n return response.json();\n }\n\n /**\n * Get a specific circuit by ID\n * @param circuitId - The circuit identifier\n * @returns The circuit details or null if not found\n */\n async getCircuit(circuitId: string): Promise<GetCircuitResponse> {\n const response = await this.fetch(`/api/circuits/${encodeURIComponent(circuitId)}`);\n return response.json();\n }\n\n /**\n * Activate a circuit (requires validation to have passed)\n * @param circuitId - The circuit identifier to activate\n * @returns The activation result\n */\n async activateCircuit(circuitId: string): Promise<ActivateCircuitResponse> {\n const response = await this.fetch(`/api/circuits/${encodeURIComponent(circuitId)}/activate`, {\n method: 'POST',\n });\n return response.json();\n }\n\n // ==========================================================================\n // Shared Proof Methods\n // ==========================================================================\n\n /**\n * Share a completed proof with a verifier organization\n * @param request - Share proof request with proveJobId and verifierOrgId\n * @returns The created shared proof\n */\n async shareProof(request: ShareProofRequest): Promise<ShareProofResponse> {\n const response = await this.fetch('/api/shared-proofs', {\n method: 'POST',\n body: JSON.stringify(request),\n });\n return response.json();\n }\n\n /**\n * List shared proofs (outgoing or incoming)\n * @param options - Filter by direction, pagination, and inclusion options\n * @returns Paginated list of shared proofs\n */\n async listSharedProofs(options: ListSharedProofsOptions = {}): Promise<ListSharedProofsResponse> {\n const params = new URLSearchParams();\n if (options.direction) params.set('direction', options.direction);\n if (options.limit !== undefined) params.set('limit', options.limit.toString());\n if (options.offset !== undefined) params.set('offset', options.offset.toString());\n if (options.includeExpired) params.set('includeExpired', 'true');\n if (options.includeRevoked) params.set('includeRevoked', 'true');\n\n const queryString = params.toString();\n const path = queryString ? `/api/shared-proofs?${queryString}` : '/api/shared-proofs';\n\n const response = await this.fetch(path);\n return response.json();\n }\n\n /**\n * Get a specific shared proof by ID\n * @param sharedProofId - The shared proof ID\n * @returns The shared proof details\n */\n async getSharedProof(sharedProofId: string): Promise<GetSharedProofResponse> {\n const response = await this.fetch(`/api/shared-proofs/${encodeURIComponent(sharedProofId)}`);\n return response.json();\n }\n\n /**\n * Revoke a shared proof. Only the sharing organization can revoke.\n * @param sharedProofId - The shared proof ID to revoke\n * @returns The revocation result\n */\n async revokeSharedProof(sharedProofId: string): Promise<RevokeSharedProofResponse> {\n const response = await this.fetch(`/api/shared-proofs/${encodeURIComponent(sharedProofId)}`, {\n method: 'DELETE',\n });\n return response.json();\n }\n\n // ==========================================================================\n // Verification Methods\n // ==========================================================================\n\n /**\n * Verify a shared proof\n *\n * This method queues a verification job and polls until completion.\n * Verification is performed asynchronously by the prover worker.\n *\n * @param sharedProofId - The shared proof ID to verify\n * @param options - Optional polling configuration\n * @returns The verification result\n */\n async verifySharedProof(\n sharedProofId: string,\n options?: { pollIntervalMs?: number; maxWaitMs?: number }\n ): Promise<VerifySharedProofResponse> {\n const pollIntervalMs = options?.pollIntervalMs ?? 1000;\n const maxWaitMs = options?.maxWaitMs ?? 120000; // 2 minutes default\n\n // Queue the verification job\n const queueResponse = await this.fetch(`/api/verify/shared/${encodeURIComponent(sharedProofId)}`, {\n method: 'POST',\n });\n const queueResult: VerifyJobQueuedResponse = await queueResponse.json();\n\n if (!queueResult.success || !queueResult.data?.jobId) {\n return {\n success: false,\n error: queueResult.error ?? 'Failed to queue verification job',\n };\n }\n\n const jobId = queueResult.data.jobId;\n const startTime = Date.now();\n\n // Poll until completion or timeout\n while (Date.now() - startTime < maxWaitMs) {\n const statusResult = await this.getVerifyJobStatus(jobId);\n\n if (!statusResult.success) {\n return {\n success: false,\n error: statusResult.error ?? 'Failed to get verification status',\n };\n }\n\n const status = statusResult.data?.status;\n\n if (status === 'completed' || status === 'failed') {\n // Verification is done\n return {\n success: true,\n data: {\n isValid: statusResult.data?.isValid ?? false,\n error: statusResult.data?.error,\n verificationTimeMs: statusResult.data?.verificationTimeMs ?? 0,\n creditsCharged: statusResult.data?.creditsCharged ?? queueResult.data.creditsCharged,\n verificationResultId: statusResult.data?.verificationResultId ?? jobId,\n },\n };\n }\n\n // Wait before polling again\n await new Promise(resolve => setTimeout(resolve, pollIntervalMs));\n }\n\n // Timeout\n return {\n success: false,\n error: `Verification timed out after ${maxWaitMs}ms. Job ID: ${jobId}`,\n };\n }\n\n /**\n * Get the status of a verification job\n * @param jobId - The verification job ID\n * @returns The job status\n */\n async getVerifyJobStatus(jobId: string): Promise<VerifyJobStatusResponse> {\n const response = await this.fetch(`/api/verify/jobs/${encodeURIComponent(jobId)}`);\n return response.json();\n }\n\n /**\n * Verify an uploaded proof\n * @param proofBuffer - The proof binary as ArrayBuffer, Uint8Array, or Buffer\n * @param vkBuffer - The verification key binary as ArrayBuffer, Uint8Array, or Buffer\n * @returns The verification result\n */\n async verifyUploadedProof(\n proofBuffer: ArrayBuffer | Uint8Array,\n vkBuffer: ArrayBuffer | Uint8Array\n ): Promise<VerifyUploadedProofResponse> {\n // Convert to Uint8Array if needed\n const proofBytes = proofBuffer instanceof Uint8Array\n ? proofBuffer\n : new Uint8Array(proofBuffer);\n const vkBytes = vkBuffer instanceof Uint8Array\n ? vkBuffer\n : new Uint8Array(vkBuffer);\n\n // Convert to base64\n const proofBase64 = typeof Buffer !== 'undefined'\n ? Buffer.from(proofBytes).toString('base64')\n : btoa(String.fromCharCode(...proofBytes));\n const vkBase64 = typeof Buffer !== 'undefined'\n ? Buffer.from(vkBytes).toString('base64')\n : btoa(String.fromCharCode(...vkBytes));\n\n const response = await this.fetch('/api/verify/upload', {\n method: 'POST',\n body: JSON.stringify({\n proof: proofBase64,\n vk: vkBase64,\n }),\n });\n return response.json();\n }\n\n /**\n * Get verification history for the authenticated organization\n * @param options - Pagination options\n * @returns Paginated list of verification results\n */\n async getVerificationHistory(options: GetVerificationHistoryOptions = {}): Promise<GetVerificationHistoryResponse> {\n const params = new URLSearchParams();\n if (options.limit !== undefined) params.set('limit', options.limit.toString());\n if (options.offset !== undefined) params.set('offset', options.offset.toString());\n\n const queryString = params.toString();\n const path = queryString ? `/api/verify/history?${queryString}` : '/api/verify/history';\n\n const response = await this.fetch(path);\n return response.json();\n }\n\n // ==========================================================================\n // Private Helpers\n // ==========================================================================\n\n private async fetch(path: string, init?: RequestInit): Promise<Response> {\n const response = await fetch(`${this.baseUrl}${path}`, {\n ...init,\n headers: {\n ...this.headers,\n ...init?.headers,\n },\n });\n\n if (response.status === 401) {\n throw new AuthenticationError();\n }\n\n return response;\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n}\n"]}
|
package/dist/core/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { B as BindClient, d as deriveCircuitId } from '../client-
|
|
2
|
-
export { A as ActivateCircuitResponse, B as BindClientOptions, l as BindCredential, i as Circuit, C as CircuitStatus, h as CircuitValidationStatus, t as CreateSessionResponse, s as GetAttestationResponse, k as GetCircuitResponse, G as GetProveJobResponse, u as GetSessionResponse, r as ListAttestationsResponse, j as ListCircuitsResponse, q as ListExtractorsResponse, L as ListProveJobsOptions, g as ListProveJobsResponse, c as ProofDownloadUrls, d as ProveJob, a as ProveJobInputs, b as ProveJobOutputs, P as ProveJobStatus, e as ProveJobSummary, S as SubmitProveJobRequest, f as SubmitProveJobResponse, V as VerificationMode, o as ZkTlsAttestation, m as ZkTlsExtractor, p as ZkTlsSession, Z as ZkTlsSessionStatus, n as ZkTlsWitness } from '../types-
|
|
1
|
+
export { B as BindClient, d as deriveCircuitId } from '../client-BkohyCGJ.cjs';
|
|
2
|
+
export { A as ActivateCircuitResponse, B as BindClientOptions, l as BindCredential, i as Circuit, C as CircuitStatus, h as CircuitValidationStatus, t as CreateSessionResponse, s as GetAttestationResponse, k as GetCircuitResponse, G as GetProveJobResponse, u as GetSessionResponse, D as GetSharedProofResponse, O as GetVerificationHistoryOptions, Q as GetVerificationHistoryResponse, r as ListAttestationsResponse, j as ListCircuitsResponse, q as ListExtractorsResponse, L as ListProveJobsOptions, g as ListProveJobsResponse, y as ListSharedProofsOptions, z as ListSharedProofsResponse, c as ProofDownloadUrls, d as ProveJob, a as ProveJobInputs, b as ProveJobOutputs, P as ProveJobStatus, e as ProveJobSummary, R as RevokeSharedProofResponse, w as ShareProofRequest, x as ShareProofResponse, v as SharedProof, S as SubmitProveJobRequest, f as SubmitProveJobResponse, N as VerificationHistoryEntry, V as VerificationMode, I as VerificationResult, F as VerifyJobQueuedResponse, E as VerifyJobStatus, H as VerifyJobStatusResponse, J as VerifySharedProofResponse, K as VerifyUploadedProofRequest, M as VerifyUploadedProofResponse, o as ZkTlsAttestation, m as ZkTlsExtractor, p as ZkTlsSession, Z as ZkTlsSessionStatus, n as ZkTlsWitness } from '../types-Cz9q5U3r.cjs';
|
|
3
3
|
export { DisclosureSpec, OutputClaimSpec, PolicyId, PolicyMetadata, PublicPolicySpec, SubjectSpec, ValiditySpec } from '@bind-protocol/policy-spec';
|
|
4
4
|
|
|
5
5
|
/**
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { B as BindClient, d as deriveCircuitId } from '../client-
|
|
2
|
-
export { A as ActivateCircuitResponse, B as BindClientOptions, l as BindCredential, i as Circuit, C as CircuitStatus, h as CircuitValidationStatus, t as CreateSessionResponse, s as GetAttestationResponse, k as GetCircuitResponse, G as GetProveJobResponse, u as GetSessionResponse, r as ListAttestationsResponse, j as ListCircuitsResponse, q as ListExtractorsResponse, L as ListProveJobsOptions, g as ListProveJobsResponse, c as ProofDownloadUrls, d as ProveJob, a as ProveJobInputs, b as ProveJobOutputs, P as ProveJobStatus, e as ProveJobSummary, S as SubmitProveJobRequest, f as SubmitProveJobResponse, V as VerificationMode, o as ZkTlsAttestation, m as ZkTlsExtractor, p as ZkTlsSession, Z as ZkTlsSessionStatus, n as ZkTlsWitness } from '../types-
|
|
1
|
+
export { B as BindClient, d as deriveCircuitId } from '../client-CadOSqx6.js';
|
|
2
|
+
export { A as ActivateCircuitResponse, B as BindClientOptions, l as BindCredential, i as Circuit, C as CircuitStatus, h as CircuitValidationStatus, t as CreateSessionResponse, s as GetAttestationResponse, k as GetCircuitResponse, G as GetProveJobResponse, u as GetSessionResponse, D as GetSharedProofResponse, O as GetVerificationHistoryOptions, Q as GetVerificationHistoryResponse, r as ListAttestationsResponse, j as ListCircuitsResponse, q as ListExtractorsResponse, L as ListProveJobsOptions, g as ListProveJobsResponse, y as ListSharedProofsOptions, z as ListSharedProofsResponse, c as ProofDownloadUrls, d as ProveJob, a as ProveJobInputs, b as ProveJobOutputs, P as ProveJobStatus, e as ProveJobSummary, R as RevokeSharedProofResponse, w as ShareProofRequest, x as ShareProofResponse, v as SharedProof, S as SubmitProveJobRequest, f as SubmitProveJobResponse, N as VerificationHistoryEntry, V as VerificationMode, I as VerificationResult, F as VerifyJobQueuedResponse, E as VerifyJobStatus, H as VerifyJobStatusResponse, J as VerifySharedProofResponse, K as VerifyUploadedProofRequest, M as VerifyUploadedProofResponse, o as ZkTlsAttestation, m as ZkTlsExtractor, p as ZkTlsSession, Z as ZkTlsSessionStatus, n as ZkTlsWitness } from '../types-Cz9q5U3r.js';
|
|
3
3
|
export { DisclosureSpec, OutputClaimSpec, PolicyId, PolicyMetadata, PublicPolicySpec, SubjectSpec, ValiditySpec } from '@bind-protocol/policy-spec';
|
|
4
4
|
|
|
5
5
|
/**
|
package/dist/core/index.js
CHANGED
|
@@ -340,6 +340,157 @@ var BindClient = class {
|
|
|
340
340
|
return response.json();
|
|
341
341
|
}
|
|
342
342
|
// ==========================================================================
|
|
343
|
+
// Shared Proof Methods
|
|
344
|
+
// ==========================================================================
|
|
345
|
+
/**
|
|
346
|
+
* Share a completed proof with a verifier organization
|
|
347
|
+
* @param request - Share proof request with proveJobId and verifierOrgId
|
|
348
|
+
* @returns The created shared proof
|
|
349
|
+
*/
|
|
350
|
+
async shareProof(request) {
|
|
351
|
+
const response = await this.fetch("/api/shared-proofs", {
|
|
352
|
+
method: "POST",
|
|
353
|
+
body: JSON.stringify(request)
|
|
354
|
+
});
|
|
355
|
+
return response.json();
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* List shared proofs (outgoing or incoming)
|
|
359
|
+
* @param options - Filter by direction, pagination, and inclusion options
|
|
360
|
+
* @returns Paginated list of shared proofs
|
|
361
|
+
*/
|
|
362
|
+
async listSharedProofs(options = {}) {
|
|
363
|
+
const params = new URLSearchParams();
|
|
364
|
+
if (options.direction) params.set("direction", options.direction);
|
|
365
|
+
if (options.limit !== void 0) params.set("limit", options.limit.toString());
|
|
366
|
+
if (options.offset !== void 0) params.set("offset", options.offset.toString());
|
|
367
|
+
if (options.includeExpired) params.set("includeExpired", "true");
|
|
368
|
+
if (options.includeRevoked) params.set("includeRevoked", "true");
|
|
369
|
+
const queryString = params.toString();
|
|
370
|
+
const path = queryString ? `/api/shared-proofs?${queryString}` : "/api/shared-proofs";
|
|
371
|
+
const response = await this.fetch(path);
|
|
372
|
+
return response.json();
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Get a specific shared proof by ID
|
|
376
|
+
* @param sharedProofId - The shared proof ID
|
|
377
|
+
* @returns The shared proof details
|
|
378
|
+
*/
|
|
379
|
+
async getSharedProof(sharedProofId) {
|
|
380
|
+
const response = await this.fetch(`/api/shared-proofs/${encodeURIComponent(sharedProofId)}`);
|
|
381
|
+
return response.json();
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Revoke a shared proof. Only the sharing organization can revoke.
|
|
385
|
+
* @param sharedProofId - The shared proof ID to revoke
|
|
386
|
+
* @returns The revocation result
|
|
387
|
+
*/
|
|
388
|
+
async revokeSharedProof(sharedProofId) {
|
|
389
|
+
const response = await this.fetch(`/api/shared-proofs/${encodeURIComponent(sharedProofId)}`, {
|
|
390
|
+
method: "DELETE"
|
|
391
|
+
});
|
|
392
|
+
return response.json();
|
|
393
|
+
}
|
|
394
|
+
// ==========================================================================
|
|
395
|
+
// Verification Methods
|
|
396
|
+
// ==========================================================================
|
|
397
|
+
/**
|
|
398
|
+
* Verify a shared proof
|
|
399
|
+
*
|
|
400
|
+
* This method queues a verification job and polls until completion.
|
|
401
|
+
* Verification is performed asynchronously by the prover worker.
|
|
402
|
+
*
|
|
403
|
+
* @param sharedProofId - The shared proof ID to verify
|
|
404
|
+
* @param options - Optional polling configuration
|
|
405
|
+
* @returns The verification result
|
|
406
|
+
*/
|
|
407
|
+
async verifySharedProof(sharedProofId, options) {
|
|
408
|
+
const pollIntervalMs = options?.pollIntervalMs ?? 1e3;
|
|
409
|
+
const maxWaitMs = options?.maxWaitMs ?? 12e4;
|
|
410
|
+
const queueResponse = await this.fetch(`/api/verify/shared/${encodeURIComponent(sharedProofId)}`, {
|
|
411
|
+
method: "POST"
|
|
412
|
+
});
|
|
413
|
+
const queueResult = await queueResponse.json();
|
|
414
|
+
if (!queueResult.success || !queueResult.data?.jobId) {
|
|
415
|
+
return {
|
|
416
|
+
success: false,
|
|
417
|
+
error: queueResult.error ?? "Failed to queue verification job"
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
const jobId = queueResult.data.jobId;
|
|
421
|
+
const startTime = Date.now();
|
|
422
|
+
while (Date.now() - startTime < maxWaitMs) {
|
|
423
|
+
const statusResult = await this.getVerifyJobStatus(jobId);
|
|
424
|
+
if (!statusResult.success) {
|
|
425
|
+
return {
|
|
426
|
+
success: false,
|
|
427
|
+
error: statusResult.error ?? "Failed to get verification status"
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
const status = statusResult.data?.status;
|
|
431
|
+
if (status === "completed" || status === "failed") {
|
|
432
|
+
return {
|
|
433
|
+
success: true,
|
|
434
|
+
data: {
|
|
435
|
+
isValid: statusResult.data?.isValid ?? false,
|
|
436
|
+
error: statusResult.data?.error,
|
|
437
|
+
verificationTimeMs: statusResult.data?.verificationTimeMs ?? 0,
|
|
438
|
+
creditsCharged: statusResult.data?.creditsCharged ?? queueResult.data.creditsCharged,
|
|
439
|
+
verificationResultId: statusResult.data?.verificationResultId ?? jobId
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
|
444
|
+
}
|
|
445
|
+
return {
|
|
446
|
+
success: false,
|
|
447
|
+
error: `Verification timed out after ${maxWaitMs}ms. Job ID: ${jobId}`
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Get the status of a verification job
|
|
452
|
+
* @param jobId - The verification job ID
|
|
453
|
+
* @returns The job status
|
|
454
|
+
*/
|
|
455
|
+
async getVerifyJobStatus(jobId) {
|
|
456
|
+
const response = await this.fetch(`/api/verify/jobs/${encodeURIComponent(jobId)}`);
|
|
457
|
+
return response.json();
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Verify an uploaded proof
|
|
461
|
+
* @param proofBuffer - The proof binary as ArrayBuffer, Uint8Array, or Buffer
|
|
462
|
+
* @param vkBuffer - The verification key binary as ArrayBuffer, Uint8Array, or Buffer
|
|
463
|
+
* @returns The verification result
|
|
464
|
+
*/
|
|
465
|
+
async verifyUploadedProof(proofBuffer, vkBuffer) {
|
|
466
|
+
const proofBytes = proofBuffer instanceof Uint8Array ? proofBuffer : new Uint8Array(proofBuffer);
|
|
467
|
+
const vkBytes = vkBuffer instanceof Uint8Array ? vkBuffer : new Uint8Array(vkBuffer);
|
|
468
|
+
const proofBase64 = typeof Buffer !== "undefined" ? Buffer.from(proofBytes).toString("base64") : btoa(String.fromCharCode(...proofBytes));
|
|
469
|
+
const vkBase64 = typeof Buffer !== "undefined" ? Buffer.from(vkBytes).toString("base64") : btoa(String.fromCharCode(...vkBytes));
|
|
470
|
+
const response = await this.fetch("/api/verify/upload", {
|
|
471
|
+
method: "POST",
|
|
472
|
+
body: JSON.stringify({
|
|
473
|
+
proof: proofBase64,
|
|
474
|
+
vk: vkBase64
|
|
475
|
+
})
|
|
476
|
+
});
|
|
477
|
+
return response.json();
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Get verification history for the authenticated organization
|
|
481
|
+
* @param options - Pagination options
|
|
482
|
+
* @returns Paginated list of verification results
|
|
483
|
+
*/
|
|
484
|
+
async getVerificationHistory(options = {}) {
|
|
485
|
+
const params = new URLSearchParams();
|
|
486
|
+
if (options.limit !== void 0) params.set("limit", options.limit.toString());
|
|
487
|
+
if (options.offset !== void 0) params.set("offset", options.offset.toString());
|
|
488
|
+
const queryString = params.toString();
|
|
489
|
+
const path = queryString ? `/api/verify/history?${queryString}` : "/api/verify/history";
|
|
490
|
+
const response = await this.fetch(path);
|
|
491
|
+
return response.json();
|
|
492
|
+
}
|
|
493
|
+
// ==========================================================================
|
|
343
494
|
// Private Helpers
|
|
344
495
|
// ==========================================================================
|
|
345
496
|
async fetch(path, init) {
|