@bind-protocol/sdk 0.2.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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/errors.ts","../src/core/client.ts","../src/adapters/dimo/queries.ts","../src/adapters/dimo/adapter.ts"],"names":[],"mappings":";AAIO,IAAM,SAAA,GAAN,cAAwB,KAAA,CAAM;AAAA,EACnC,WAAA,CACE,OAAA,EACgB,IAAA,EACA,OAAA,EAChB;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AAHG,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AACA,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAGhB,IAAA,IAAA,CAAK,IAAA,GAAO,WAAA;AAAA,EACd;AACF;AAEO,IAAM,QAAA,GAAN,cAAuB,SAAA,CAAU;AAAA,EACtC,WAAA,CACE,OAAA,EACgB,MAAA,EACA,QAAA,EAChB;AACA,IAAA,KAAA,CAAM,OAAA,EAAS,WAAA,EAAa,EAAE,MAAA,EAAQ,UAAU,CAAA;AAHhC,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AACA,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AAGhB,IAAA,IAAA,CAAK,IAAA,GAAO,UAAA;AAAA,EACd;AACF;AAEO,IAAM,mBAAA,GAAN,cAAkC,SAAA,CAAU;AAAA,EACjD,WAAA,CAAY,UAAU,uBAAA,EAAyB;AAC7C,IAAA,KAAA,CAAM,SAAS,YAAY,CAAA;AAC3B,IAAA,IAAA,CAAK,IAAA,GAAO,qBAAA;AAAA,EACd;AACF;AAEO,IAAM,YAAA,GAAN,cAA2B,SAAA,CAAU;AAAA,EAC1C,WAAA,CAAY,SAAiC,SAAA,EAAmB;AAC9D,IAAA,KAAA,CAAM,OAAA,EAAS,eAAA,EAAiB,EAAE,SAAA,EAAW,CAAA;AADF,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA;AAE3C,IAAA,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AwC;AACxE,EAAA,OAAO,IAAI,YAAY,MAAM,CAAA;AAC/B","file":"index.js","sourcesContent":["/**\n * Custom error classes for the Bind Protocol SDK\n */\n\nexport class BindError extends Error {\n constructor(\n message: string,\n public readonly code: string,\n public readonly details?: Record<string, unknown>\n ) {\n super(message);\n this.name = 'BindError';\n }\n}\n\nexport class ApiError extends BindError {\n constructor(\n message: string,\n public readonly status: number,\n public readonly response?: unknown\n ) {\n super(message, 'API_ERROR', { status, response });\n this.name = 'ApiError';\n }\n}\n\nexport class AuthenticationError extends BindError {\n constructor(message = 'Authentication failed') {\n super(message, 'AUTH_ERROR');\n this.name = 'AuthenticationError';\n }\n}\n\nexport class TimeoutError extends BindError {\n constructor(message: string, public readonly timeoutMs: number) {\n super(message, 'TIMEOUT_ERROR', { timeoutMs });\n this.name = 'TimeoutError';\n }\n}\n\nexport class InsufficientCreditsError extends BindError {\n constructor(\n public readonly required: number,\n public readonly available: number\n ) {\n super(\n `Insufficient credits: need ${required}, have ${available}`,\n 'INSUFFICIENT_CREDITS',\n { required, available }\n );\n this.name = 'InsufficientCreditsError';\n }\n}\n","/**\n * BindClient - Main client for interacting with the Bind Protocol API\n */\nimport type { PublicPolicySpec } from '@bind-protocol/policy-spec';\nimport {\n ApiError,\n AuthenticationError,\n InsufficientCreditsError,\n TimeoutError,\n} from './errors';\nimport type {\n BindClientOptions,\n ProveJobInputs,\n SubmitProveJobResponse,\n GetProveJobResponse,\n ListProveJobsOptions,\n ListProveJobsResponse,\n ProveJob,\n} from './types';\n\nconst DEFAULT_BASE_URL = 'https://api.bindprotocol.com';\nconst DEFAULT_POLL_INTERVAL_MS = 2000;\nconst DEFAULT_TIMEOUT_MS = 300000; // 5 minutes\n\nexport class BindClient {\n private readonly apiKey: string;\n private readonly baseUrl: string;\n private readonly headers: Record<string, string>;\n\n constructor(options: BindClientOptions) {\n this.apiKey = options.apiKey;\n this.baseUrl = options.baseUrl || process.env.BIND_API_URL || DEFAULT_BASE_URL;\n this.headers = {\n 'X-API-Key': this.apiKey,\n 'Content-Type': 'application/json',\n };\n }\n\n // ==========================================================================\n // Prove Job Methods\n // ==========================================================================\n\n /**\n * Submit a prove job for async processing\n * @param circuitId - The circuit identifier (e.g., \"bind.mobility.riskband.v1\")\n * @param inputs - Circuit inputs as key-value pairs (all values must be strings)\n * @returns The submitted job details\n * @throws {ApiError} If the API request fails\n * @throws {InsufficientCreditsError} If there aren't enough credits\n */\n async submitProveJob(\n circuitId: string,\n inputs: ProveJobInputs\n ): Promise<SubmitProveJobResponse> {\n const response = await this.fetch('/api/prove', {\n method: 'POST',\n body: JSON.stringify({ circuitId, inputs }),\n });\n\n const result: SubmitProveJobResponse = await response.json();\n\n // Check for insufficient credits\n if (!result.success && result.requiredCredits !== undefined && result.availableCredits !== undefined) {\n throw new InsufficientCreditsError(result.requiredCredits, result.availableCredits);\n }\n\n return result;\n }\n\n /**\n * Get the status and results of a prove job\n * @param jobId - The unique job identifier\n * @returns The job details including status and outputs\n */\n async getProveJob(jobId: string): Promise<GetProveJobResponse> {\n const response = await this.fetch(`/api/prove/${encodeURIComponent(jobId)}`);\n return response.json();\n }\n\n /**\n * List prove jobs for the authenticated organization\n * @param options - Optional filters for status, limit, and offset\n * @returns Paginated list of prove jobs\n */\n async listProveJobs(options: ListProveJobsOptions = {}): Promise<ListProveJobsResponse> {\n const params = new URLSearchParams();\n if (options.status) params.set('status', options.status);\n if (options.limit !== undefined) params.set('limit', options.limit.toString());\n if (options.offset !== undefined) params.set('offset', options.offset.toString());\n\n const queryString = params.toString();\n const path = queryString ? `/api/prove?${queryString}` : '/api/prove';\n\n const response = await this.fetch(path);\n return response.json();\n }\n\n /**\n * Poll for prove job completion\n * @param jobId - The unique job identifier\n * @param options - Polling options\n * @returns The completed or failed job\n * @throws {TimeoutError} If the job doesn't complete within the timeout\n */\n async waitForProveJob(\n jobId: string,\n options: {\n intervalMs?: number;\n timeoutMs?: number;\n onProgress?: (job: ProveJob) => void;\n } = {}\n ): Promise<ProveJob> {\n const intervalMs = options.intervalMs ?? DEFAULT_POLL_INTERVAL_MS;\n const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const startTime = Date.now();\n\n while (Date.now() - startTime < timeoutMs) {\n const result = await this.getProveJob(jobId);\n\n if (!result.success || !result.data) {\n throw new ApiError(\n result.error || 'Failed to get prove job',\n 500,\n result\n );\n }\n\n const job = result.data;\n\n if (options.onProgress) {\n options.onProgress(job);\n }\n\n if (job.status === 'completed' || job.status === 'failed') {\n return job;\n }\n\n await this.sleep(intervalMs);\n }\n\n throw new TimeoutError(\n `Timeout waiting for prove job ${jobId} after ${timeoutMs}ms`,\n timeoutMs\n );\n }\n\n // ==========================================================================\n // Policy Methods (Public, no authentication required)\n // ==========================================================================\n\n /**\n * List all available public policies\n * @returns Array of public policy specifications\n */\n async listPolicies(): Promise<PublicPolicySpec[]> {\n const response = await fetch(`${this.baseUrl}/api/policies`, {\n method: 'GET',\n });\n\n if (!response.ok) {\n throw new ApiError(\n `Failed to fetch policies: ${response.statusText}`,\n response.status\n );\n }\n\n return response.json();\n }\n\n /**\n * Get a specific policy by ID\n * @param policyId - The unique policy identifier\n * @returns The public policy specification, or null if not found\n */\n async getPolicy(policyId: string): Promise<PublicPolicySpec | null> {\n const response = await fetch(\n `${this.baseUrl}/api/policies/${encodeURIComponent(policyId)}`,\n { method: 'GET' }\n );\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new ApiError(\n `Failed to fetch policy: ${response.statusText}`,\n response.status\n );\n }\n\n return response.json();\n }\n\n // ==========================================================================\n // Private Helpers\n // ==========================================================================\n\n private async fetch(path: string, init?: RequestInit): Promise<Response> {\n const response = await fetch(`${this.baseUrl}${path}`, {\n ...init,\n headers: {\n ...this.headers,\n ...init?.headers,\n },\n });\n\n if (response.status === 401) {\n throw new AuthenticationError();\n }\n\n return response;\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n}\n","/**\n * DIMO GraphQL query builders\n */\n\n/**\n * Build a GraphQL query for fetching vehicle telemetry\n * @param vehicleTokenId - The DIMO vehicle token ID\n * @param from - Start date (ISO 8601 or date string)\n * @param to - End date (ISO 8601 or date string)\n * @returns GraphQL query string\n */\nexport function buildTelemetryQuery(\n vehicleTokenId: string,\n from: string,\n to: string\n): string {\n return `{\n signals(\n tokenId: ${vehicleTokenId},\n interval: \"1h\",\n from: ${from},\n to: ${to}\n ) {\n powertrainTransmissionTravelledDistance(agg: AVG)\n speed(agg: AVG)\n powertrainCombustionEngineSpeed(agg: AVG)\n obdEngineLoad(agg: AVG)\n obdDTCList(agg: UNIQUE)\n obdRunTime(agg: AVG)\n timestamp\n }\n}`;\n}\n\n/**\n * Build a GraphQL query for fetching specific signals\n * Allows customization of which signals to fetch and their aggregation\n */\nexport function buildCustomTelemetryQuery(\n vehicleTokenId: string,\n from: string,\n to: string,\n signals: Array<{\n name: string;\n aggregation?: 'AVG' | 'SUM' | 'MIN' | 'MAX' | 'UNIQUE' | 'COUNT';\n }>,\n interval = '1h'\n): string {\n const signalLines = signals\n .map((s) => {\n if (s.aggregation) {\n return ` ${s.name}(agg: ${s.aggregation})`;\n }\n return ` ${s.name}`;\n })\n .join('\\n');\n\n return `{\n signals(\n tokenId: ${vehicleTokenId},\n interval: \"${interval}\",\n from: ${from},\n to: ${to}\n ) {\n${signalLines}\n timestamp\n }\n}`;\n}\n","/**\n * DIMO Adapter\n *\n * Fetches vehicle telemetry data from the DIMO network and transforms it\n * into circuit inputs for Bind Protocol prove jobs.\n */\n\nimport type { DataAdapter } from '../types';\nimport type { ProveJobInputs } from '../../core/types';\nimport type { DimoAdapterConfig, DimoQuery, DimoTelemetryData, DimoClient } from './types';\nimport { buildTelemetryQuery } from './queries';\n\nconst SUPPORTED_CIRCUITS = [\n 'bind.mobility.riskband.v1',\n];\n\nexport class DimoAdapter implements DataAdapter<DimoAdapterConfig, DimoQuery, DimoTelemetryData> {\n readonly id = 'dimo';\n readonly name = 'DIMO Network';\n readonly description = 'Fetches vehicle telemetry data from the DIMO decentralized network';\n\n private readonly dimoClient: DimoClient;\n\n constructor(config: DimoAdapterConfig) {\n this.dimoClient = config.dimoClient;\n }\n\n /**\n * Fetch telemetry data from DIMO for a vehicle\n * @param query - Query parameters including vehicle token ID and date range\n * @returns Raw telemetry data from DIMO\n */\n async fetchData(query: DimoQuery): Promise<DimoTelemetryData> {\n const graphqlQuery = buildTelemetryQuery(query.vehicleTokenId, query.from, query.to);\n const result = await this.dimoClient.telemetry.query(graphqlQuery);\n return result;\n }\n\n /**\n * Transform DIMO telemetry data into circuit inputs\n * @param data - Raw telemetry data from DIMO\n * @param circuitId - Target circuit ID\n * @returns Inputs ready for prove job submission\n */\n toCircuitInputs(data: DimoTelemetryData, circuitId: string): ProveJobInputs {\n if (!SUPPORTED_CIRCUITS.includes(circuitId)) {\n throw new Error(\n `Circuit \"${circuitId}\" is not supported by the DIMO adapter. ` +\n `Supported circuits: ${SUPPORTED_CIRCUITS.join(', ')}`\n );\n }\n\n // Transform based on circuit type\n switch (circuitId) {\n case 'bind.mobility.riskband.v1':\n return this.toRiskBandInputs(data);\n default:\n throw new Error(`No input transformer for circuit: ${circuitId}`);\n }\n }\n\n /**\n * Get the list of circuits this adapter supports\n */\n getSupportedCircuits(): string[] {\n return [...SUPPORTED_CIRCUITS];\n }\n\n // ===========================================================================\n // Private transformers\n // ===========================================================================\n\n private toRiskBandInputs(data: DimoTelemetryData): ProveJobInputs {\n return {\n signals: JSON.stringify(data.signals),\n timestamp: data.timestamp,\n };\n }\n}\n\n/**\n * Factory function to create a DIMO adapter\n */\nexport function createDimoAdapter(config: DimoAdapterConfig): DimoAdapter {\n return new DimoAdapter(config);\n}\n"]}
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Core types for the Bind Protocol SDK
3
+ */
4
+
5
+ /**
6
+ * Configuration options for BindClient
7
+ */
8
+ interface BindClientOptions {
9
+ /** Your Bind Protocol API key */
10
+ apiKey: string;
11
+ /** API base URL (default: https://api.bindprotocol.com) */
12
+ baseUrl?: string;
13
+ }
14
+ type ProveJobStatus = 'pending' | 'processing' | 'completed' | 'failed';
15
+ type ProveJobInputs = Record<string, string>;
16
+ interface ProveJobOutputs {
17
+ proofKey: string | null;
18
+ vkKey: string | null;
19
+ pubsKey: string | null;
20
+ proofHexKey: string | null;
21
+ vkHexKey: string | null;
22
+ pubsHexKey: string | null;
23
+ }
24
+ interface SubmitProveJobRequest {
25
+ circuitId: string;
26
+ inputs: ProveJobInputs;
27
+ }
28
+ interface ProveJob {
29
+ jobId: string;
30
+ status: ProveJobStatus;
31
+ circuitId: string;
32
+ createdAt: string;
33
+ startedAt: string | null;
34
+ completedAt: string | null;
35
+ error: string | null;
36
+ outputs?: ProveJobOutputs;
37
+ attestationId?: string;
38
+ zkVerifyTxHash?: string;
39
+ }
40
+ interface ProveJobSummary {
41
+ jobId: string;
42
+ status: ProveJobStatus;
43
+ circuitId: string;
44
+ createdAt: string;
45
+ startedAt: string | null;
46
+ completedAt: string | null;
47
+ error: string | null;
48
+ }
49
+ interface SubmitProveJobResponse {
50
+ success: boolean;
51
+ data?: {
52
+ jobId: string;
53
+ status: ProveJobStatus;
54
+ circuitId: string;
55
+ createdAt: string;
56
+ };
57
+ error?: string;
58
+ requiredCredits?: number;
59
+ availableCredits?: number;
60
+ }
61
+ interface GetProveJobResponse {
62
+ success: boolean;
63
+ data?: ProveJob;
64
+ error?: string;
65
+ }
66
+ interface ListProveJobsOptions {
67
+ status?: ProveJobStatus;
68
+ limit?: number;
69
+ offset?: number;
70
+ }
71
+ interface ListProveJobsResponse {
72
+ success: boolean;
73
+ data?: {
74
+ jobs: ProveJobSummary[];
75
+ pagination: {
76
+ limit: number;
77
+ offset: number;
78
+ count: number;
79
+ total: number;
80
+ };
81
+ };
82
+ error?: string;
83
+ }
84
+ interface BindCredential {
85
+ /** The policy used to generate this credential */
86
+ policyId: string;
87
+ /** Prove job ID that generated the proof */
88
+ jobId: string;
89
+ /** zkVerify attestation ID (on-chain proof reference) */
90
+ attestationId?: string;
91
+ /** zkVerify transaction hash */
92
+ zkVerifyTxHash?: string;
93
+ /** Disclosed claims (visible to verifiers) */
94
+ claims: Record<string, unknown>;
95
+ /** Credential issuance timestamp */
96
+ issuedAt: string;
97
+ /** Credential expiration timestamp */
98
+ expiresAt?: string;
99
+ }
100
+
101
+ export type { BindClientOptions as B, GetProveJobResponse as G, ListProveJobsOptions as L, ProveJobStatus as P, SubmitProveJobRequest as S, ProveJobInputs as a, ProveJobOutputs as b, ProveJob as c, ProveJobSummary as d, SubmitProveJobResponse as e, ListProveJobsResponse as f, BindCredential as g };
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Core types for the Bind Protocol SDK
3
+ */
4
+
5
+ /**
6
+ * Configuration options for BindClient
7
+ */
8
+ interface BindClientOptions {
9
+ /** Your Bind Protocol API key */
10
+ apiKey: string;
11
+ /** API base URL (default: https://api.bindprotocol.com) */
12
+ baseUrl?: string;
13
+ }
14
+ type ProveJobStatus = 'pending' | 'processing' | 'completed' | 'failed';
15
+ type ProveJobInputs = Record<string, string>;
16
+ interface ProveJobOutputs {
17
+ proofKey: string | null;
18
+ vkKey: string | null;
19
+ pubsKey: string | null;
20
+ proofHexKey: string | null;
21
+ vkHexKey: string | null;
22
+ pubsHexKey: string | null;
23
+ }
24
+ interface SubmitProveJobRequest {
25
+ circuitId: string;
26
+ inputs: ProveJobInputs;
27
+ }
28
+ interface ProveJob {
29
+ jobId: string;
30
+ status: ProveJobStatus;
31
+ circuitId: string;
32
+ createdAt: string;
33
+ startedAt: string | null;
34
+ completedAt: string | null;
35
+ error: string | null;
36
+ outputs?: ProveJobOutputs;
37
+ attestationId?: string;
38
+ zkVerifyTxHash?: string;
39
+ }
40
+ interface ProveJobSummary {
41
+ jobId: string;
42
+ status: ProveJobStatus;
43
+ circuitId: string;
44
+ createdAt: string;
45
+ startedAt: string | null;
46
+ completedAt: string | null;
47
+ error: string | null;
48
+ }
49
+ interface SubmitProveJobResponse {
50
+ success: boolean;
51
+ data?: {
52
+ jobId: string;
53
+ status: ProveJobStatus;
54
+ circuitId: string;
55
+ createdAt: string;
56
+ };
57
+ error?: string;
58
+ requiredCredits?: number;
59
+ availableCredits?: number;
60
+ }
61
+ interface GetProveJobResponse {
62
+ success: boolean;
63
+ data?: ProveJob;
64
+ error?: string;
65
+ }
66
+ interface ListProveJobsOptions {
67
+ status?: ProveJobStatus;
68
+ limit?: number;
69
+ offset?: number;
70
+ }
71
+ interface ListProveJobsResponse {
72
+ success: boolean;
73
+ data?: {
74
+ jobs: ProveJobSummary[];
75
+ pagination: {
76
+ limit: number;
77
+ offset: number;
78
+ count: number;
79
+ total: number;
80
+ };
81
+ };
82
+ error?: string;
83
+ }
84
+ interface BindCredential {
85
+ /** The policy used to generate this credential */
86
+ policyId: string;
87
+ /** Prove job ID that generated the proof */
88
+ jobId: string;
89
+ /** zkVerify attestation ID (on-chain proof reference) */
90
+ attestationId?: string;
91
+ /** zkVerify transaction hash */
92
+ zkVerifyTxHash?: string;
93
+ /** Disclosed claims (visible to verifiers) */
94
+ claims: Record<string, unknown>;
95
+ /** Credential issuance timestamp */
96
+ issuedAt: string;
97
+ /** Credential expiration timestamp */
98
+ expiresAt?: string;
99
+ }
100
+
101
+ export type { BindClientOptions as B, GetProveJobResponse as G, ListProveJobsOptions as L, ProveJobStatus as P, SubmitProveJobRequest as S, ProveJobInputs as a, ProveJobOutputs as b, ProveJob as c, ProveJobSummary as d, SubmitProveJobResponse as e, ListProveJobsResponse as f, BindCredential as g };
package/package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "@bind-protocol/sdk",
3
+ "version": "0.2.0",
4
+ "description": "TypeScript SDK for the Bind Protocol - privacy-preserving credential issuance and verification",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "bind-protocol",
8
+ "zero-knowledge",
9
+ "zkp",
10
+ "credentials",
11
+ "privacy",
12
+ "verifiable-credentials",
13
+ "dimo"
14
+ ],
15
+ "type": "module",
16
+ "main": "./dist/index.js",
17
+ "module": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js",
23
+ "require": "./dist/index.cjs"
24
+ },
25
+ "./core": {
26
+ "types": "./dist/core/index.d.ts",
27
+ "import": "./dist/core/index.js",
28
+ "require": "./dist/core/index.cjs"
29
+ },
30
+ "./adapters": {
31
+ "types": "./dist/adapters/index.d.ts",
32
+ "import": "./dist/adapters/index.js",
33
+ "require": "./dist/adapters/index.cjs"
34
+ },
35
+ "./adapters/dimo": {
36
+ "types": "./dist/adapters/dimo/index.d.ts",
37
+ "import": "./dist/adapters/dimo/index.js",
38
+ "require": "./dist/adapters/dimo/index.cjs"
39
+ }
40
+ },
41
+ "files": [
42
+ "dist",
43
+ "README.md",
44
+ "LICENSE"
45
+ ],
46
+ "scripts": {
47
+ "build": "tsup",
48
+ "dev": "tsup --watch",
49
+ "test": "vitest",
50
+ "typecheck": "tsc --noEmit",
51
+ "lint": "eslint src",
52
+ "clean": "rm -rf dist",
53
+ "prepublishOnly": "npm run build"
54
+ },
55
+ "dependencies": {
56
+ "@bind-protocol/policy-spec": "^0.2.0"
57
+ },
58
+ "devDependencies": {
59
+ "@dimo-network/data-sdk": "^1.4.0",
60
+ "@types/node": "^20.0.0",
61
+ "tsup": "^8.0.0",
62
+ "typescript": "^5.3.0",
63
+ "vitest": "^1.0.0"
64
+ },
65
+ "peerDependencies": {
66
+ "@dimo-network/data-sdk": "^1.0.0"
67
+ },
68
+ "peerDependenciesMeta": {
69
+ "@dimo-network/data-sdk": {
70
+ "optional": true
71
+ }
72
+ },
73
+ "engines": {
74
+ "node": ">=18.0.0"
75
+ }
76
+ }