@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,203 @@
1
+ // src/core/errors.ts
2
+ var BindError = class extends Error {
3
+ constructor(message, code, details) {
4
+ super(message);
5
+ this.code = code;
6
+ this.details = details;
7
+ this.name = "BindError";
8
+ }
9
+ };
10
+ var ApiError = class extends BindError {
11
+ constructor(message, status, response) {
12
+ super(message, "API_ERROR", { status, response });
13
+ this.status = status;
14
+ this.response = response;
15
+ this.name = "ApiError";
16
+ }
17
+ };
18
+ var AuthenticationError = class extends BindError {
19
+ constructor(message = "Authentication failed") {
20
+ super(message, "AUTH_ERROR");
21
+ this.name = "AuthenticationError";
22
+ }
23
+ };
24
+ var TimeoutError = class extends BindError {
25
+ constructor(message, timeoutMs) {
26
+ super(message, "TIMEOUT_ERROR", { timeoutMs });
27
+ this.timeoutMs = timeoutMs;
28
+ this.name = "TimeoutError";
29
+ }
30
+ };
31
+ var InsufficientCreditsError = class extends BindError {
32
+ constructor(required, available) {
33
+ super(
34
+ `Insufficient credits: need ${required}, have ${available}`,
35
+ "INSUFFICIENT_CREDITS",
36
+ { required, available }
37
+ );
38
+ this.required = required;
39
+ this.available = available;
40
+ this.name = "InsufficientCreditsError";
41
+ }
42
+ };
43
+
44
+ // src/core/client.ts
45
+ var DEFAULT_BASE_URL = "https://api.bindprotocol.com";
46
+ var DEFAULT_POLL_INTERVAL_MS = 2e3;
47
+ var DEFAULT_TIMEOUT_MS = 3e5;
48
+ var BindClient = class {
49
+ apiKey;
50
+ baseUrl;
51
+ headers;
52
+ constructor(options) {
53
+ this.apiKey = options.apiKey;
54
+ this.baseUrl = options.baseUrl || process.env.BIND_API_URL || DEFAULT_BASE_URL;
55
+ this.headers = {
56
+ "X-API-Key": this.apiKey,
57
+ "Content-Type": "application/json"
58
+ };
59
+ }
60
+ // ==========================================================================
61
+ // Prove Job Methods
62
+ // ==========================================================================
63
+ /**
64
+ * Submit a prove job for async processing
65
+ * @param circuitId - The circuit identifier (e.g., "bind.mobility.riskband.v1")
66
+ * @param inputs - Circuit inputs as key-value pairs (all values must be strings)
67
+ * @returns The submitted job details
68
+ * @throws {ApiError} If the API request fails
69
+ * @throws {InsufficientCreditsError} If there aren't enough credits
70
+ */
71
+ async submitProveJob(circuitId, inputs) {
72
+ const response = await this.fetch("/api/prove", {
73
+ method: "POST",
74
+ body: JSON.stringify({ circuitId, inputs })
75
+ });
76
+ const result = await response.json();
77
+ if (!result.success && result.requiredCredits !== void 0 && result.availableCredits !== void 0) {
78
+ throw new InsufficientCreditsError(result.requiredCredits, result.availableCredits);
79
+ }
80
+ return result;
81
+ }
82
+ /**
83
+ * Get the status and results of a prove job
84
+ * @param jobId - The unique job identifier
85
+ * @returns The job details including status and outputs
86
+ */
87
+ async getProveJob(jobId) {
88
+ const response = await this.fetch(`/api/prove/${encodeURIComponent(jobId)}`);
89
+ return response.json();
90
+ }
91
+ /**
92
+ * List prove jobs for the authenticated organization
93
+ * @param options - Optional filters for status, limit, and offset
94
+ * @returns Paginated list of prove jobs
95
+ */
96
+ async listProveJobs(options = {}) {
97
+ const params = new URLSearchParams();
98
+ if (options.status) params.set("status", options.status);
99
+ if (options.limit !== void 0) params.set("limit", options.limit.toString());
100
+ if (options.offset !== void 0) params.set("offset", options.offset.toString());
101
+ const queryString = params.toString();
102
+ const path = queryString ? `/api/prove?${queryString}` : "/api/prove";
103
+ const response = await this.fetch(path);
104
+ return response.json();
105
+ }
106
+ /**
107
+ * Poll for prove job completion
108
+ * @param jobId - The unique job identifier
109
+ * @param options - Polling options
110
+ * @returns The completed or failed job
111
+ * @throws {TimeoutError} If the job doesn't complete within the timeout
112
+ */
113
+ async waitForProveJob(jobId, options = {}) {
114
+ const intervalMs = options.intervalMs ?? DEFAULT_POLL_INTERVAL_MS;
115
+ const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
116
+ const startTime = Date.now();
117
+ while (Date.now() - startTime < timeoutMs) {
118
+ const result = await this.getProveJob(jobId);
119
+ if (!result.success || !result.data) {
120
+ throw new ApiError(
121
+ result.error || "Failed to get prove job",
122
+ 500,
123
+ result
124
+ );
125
+ }
126
+ const job = result.data;
127
+ if (options.onProgress) {
128
+ options.onProgress(job);
129
+ }
130
+ if (job.status === "completed" || job.status === "failed") {
131
+ return job;
132
+ }
133
+ await this.sleep(intervalMs);
134
+ }
135
+ throw new TimeoutError(
136
+ `Timeout waiting for prove job ${jobId} after ${timeoutMs}ms`,
137
+ timeoutMs
138
+ );
139
+ }
140
+ // ==========================================================================
141
+ // Policy Methods (Public, no authentication required)
142
+ // ==========================================================================
143
+ /**
144
+ * List all available public policies
145
+ * @returns Array of public policy specifications
146
+ */
147
+ async listPolicies() {
148
+ const response = await fetch(`${this.baseUrl}/api/policies`, {
149
+ method: "GET"
150
+ });
151
+ if (!response.ok) {
152
+ throw new ApiError(
153
+ `Failed to fetch policies: ${response.statusText}`,
154
+ response.status
155
+ );
156
+ }
157
+ return response.json();
158
+ }
159
+ /**
160
+ * Get a specific policy by ID
161
+ * @param policyId - The unique policy identifier
162
+ * @returns The public policy specification, or null if not found
163
+ */
164
+ async getPolicy(policyId) {
165
+ const response = await fetch(
166
+ `${this.baseUrl}/api/policies/${encodeURIComponent(policyId)}`,
167
+ { method: "GET" }
168
+ );
169
+ if (response.status === 404) {
170
+ return null;
171
+ }
172
+ if (!response.ok) {
173
+ throw new ApiError(
174
+ `Failed to fetch policy: ${response.statusText}`,
175
+ response.status
176
+ );
177
+ }
178
+ return response.json();
179
+ }
180
+ // ==========================================================================
181
+ // Private Helpers
182
+ // ==========================================================================
183
+ async fetch(path, init) {
184
+ const response = await fetch(`${this.baseUrl}${path}`, {
185
+ ...init,
186
+ headers: {
187
+ ...this.headers,
188
+ ...init?.headers
189
+ }
190
+ });
191
+ if (response.status === 401) {
192
+ throw new AuthenticationError();
193
+ }
194
+ return response;
195
+ }
196
+ sleep(ms) {
197
+ return new Promise((resolve) => setTimeout(resolve, ms));
198
+ }
199
+ };
200
+
201
+ export { ApiError, AuthenticationError, BindClient, BindError, InsufficientCreditsError, TimeoutError };
202
+ //# sourceMappingURL=index.js.map
203
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,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,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AAoB;AAAA,IAChC;AAEA,IAAA,OAAO,QAAA;AAAA,EACT;AAAA,EAEQ,MAAM,EAAA,EAA2B;AACvC,IAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,YAAY,UAAA,CAAW,OAAA,EAAS,EAAE,CAAC,CAAA;AAAA,EACzD;AACF","file":"index.js","sourcesContent":["/**\n * Custom error classes for the Bind Protocol SDK\n */\n\nexport class BindError extends Error {\n constructor(\n message: string,\n public readonly code: string,\n public readonly details?: Record<string, unknown>\n ) {\n super(message);\n this.name = 'BindError';\n }\n}\n\nexport class ApiError extends BindError {\n constructor(\n message: string,\n public readonly status: number,\n public readonly response?: unknown\n ) {\n super(message, 'API_ERROR', { status, response });\n this.name = 'ApiError';\n }\n}\n\nexport class AuthenticationError extends BindError {\n constructor(message = 'Authentication failed') {\n super(message, 'AUTH_ERROR');\n this.name = 'AuthenticationError';\n }\n}\n\nexport class TimeoutError extends BindError {\n constructor(message: string, public readonly timeoutMs: number) {\n super(message, 'TIMEOUT_ERROR', { timeoutMs });\n this.name = 'TimeoutError';\n }\n}\n\nexport class InsufficientCreditsError extends BindError {\n constructor(\n public readonly required: number,\n public readonly available: number\n ) {\n super(\n `Insufficient credits: need ${required}, have ${available}`,\n 'INSUFFICIENT_CREDITS',\n { required, available }\n );\n this.name = 'InsufficientCreditsError';\n }\n}\n","/**\n * 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"]}
@@ -0,0 +1,155 @@
1
+ import { a as ProveJobInputs } from './types-o4sbOK_a.cjs';
2
+
3
+ /**
4
+ * Base types for data source adapters
5
+ *
6
+ * Adapters abstract away the data source specifics and provide a uniform
7
+ * interface for fetching data that can be used as circuit inputs.
8
+ */
9
+
10
+ /**
11
+ * Base interface for all data source adapters
12
+ * Each adapter knows how to fetch data from a specific source
13
+ * and transform it into circuit inputs.
14
+ */
15
+ interface DataAdapter<TConfig = unknown, TQuery = unknown, TData = unknown> {
16
+ /** Unique identifier for this adapter */
17
+ readonly id: string;
18
+ /** Human-readable name */
19
+ readonly name: string;
20
+ /** Description of what data source this adapter connects to */
21
+ readonly description: string;
22
+ /**
23
+ * Fetch raw data from the data source
24
+ * @param query - Adapter-specific query parameters
25
+ * @returns Raw data from the source
26
+ */
27
+ fetchData(query: TQuery): Promise<TData>;
28
+ /**
29
+ * Transform raw data into circuit inputs
30
+ * @param data - Raw data from fetchData
31
+ * @param circuitId - Target circuit ID (adapters may support multiple circuits)
32
+ * @returns Inputs ready for prove job submission
33
+ */
34
+ toCircuitInputs(data: TData, circuitId: string): ProveJobInputs;
35
+ }
36
+ /**
37
+ * Adapter registration entry
38
+ */
39
+ interface AdapterRegistration<TConfig = unknown> {
40
+ /** Adapter factory function */
41
+ create: (config: TConfig) => DataAdapter;
42
+ /** Default configuration */
43
+ defaultConfig?: Partial<TConfig>;
44
+ /** Supported circuit IDs */
45
+ supportedCircuits: string[];
46
+ }
47
+ /**
48
+ * Common telemetry data structure that adapters can transform their data into
49
+ */
50
+ interface TelemetryData {
51
+ /** Array of telemetry signal readings */
52
+ signals: TelemetrySignal[];
53
+ /** Timestamp of the data collection period start */
54
+ periodStart: string;
55
+ /** Timestamp of the data collection period end */
56
+ periodEnd: string;
57
+ /** Subject identifier (e.g., vehicle ID) */
58
+ subjectId: string;
59
+ }
60
+ /**
61
+ * Individual telemetry signal reading
62
+ */
63
+ interface TelemetrySignal {
64
+ timestamp: string;
65
+ [key: string]: string | number | boolean | string[] | null;
66
+ }
67
+
68
+ /**
69
+ * DIMO Adapter Types
70
+ */
71
+ /**
72
+ * Configuration for the DIMO adapter
73
+ */
74
+ interface DimoAdapterConfig {
75
+ /** DIMO SDK client instance (from @dimo-network/data-sdk) */
76
+ dimoClient: DimoClient;
77
+ }
78
+ /**
79
+ * Query parameters for fetching DIMO telemetry
80
+ */
81
+ interface DimoQuery {
82
+ /** Vehicle token ID */
83
+ vehicleTokenId: string;
84
+ /** Start date for telemetry range (ISO 8601) */
85
+ from: string;
86
+ /** End date for telemetry range (ISO 8601) */
87
+ to: string;
88
+ }
89
+ /**
90
+ * Telemetry data structure returned by DIMO API
91
+ */
92
+ interface DimoTelemetryData {
93
+ signals: DimoSignal[];
94
+ timestamp: string;
95
+ }
96
+ /**
97
+ * Individual DIMO telemetry signal
98
+ */
99
+ interface DimoSignal {
100
+ powertrainTransmissionTravelledDistance: number;
101
+ speed: number;
102
+ powertrainCombustionEngineSpeed: number;
103
+ obdEngineLoad: number;
104
+ obdDTCList: string[];
105
+ obdRunTime: number;
106
+ timestamp?: string;
107
+ }
108
+ /**
109
+ * Minimal interface for DIMO SDK client
110
+ * This allows us to work with the DIMO SDK without directly depending on it
111
+ */
112
+ interface DimoClient {
113
+ telemetry: {
114
+ query: (graphqlQuery: string) => Promise<DimoTelemetryData>;
115
+ };
116
+ }
117
+
118
+ /**
119
+ * DIMO Adapter
120
+ *
121
+ * Fetches vehicle telemetry data from the DIMO network and transforms it
122
+ * into circuit inputs for Bind Protocol prove jobs.
123
+ */
124
+
125
+ declare class DimoAdapter implements DataAdapter<DimoAdapterConfig, DimoQuery, DimoTelemetryData> {
126
+ readonly id = "dimo";
127
+ readonly name = "DIMO Network";
128
+ readonly description = "Fetches vehicle telemetry data from the DIMO decentralized network";
129
+ private readonly dimoClient;
130
+ constructor(config: DimoAdapterConfig);
131
+ /**
132
+ * Fetch telemetry data from DIMO for a vehicle
133
+ * @param query - Query parameters including vehicle token ID and date range
134
+ * @returns Raw telemetry data from DIMO
135
+ */
136
+ fetchData(query: DimoQuery): Promise<DimoTelemetryData>;
137
+ /**
138
+ * Transform DIMO telemetry data into circuit inputs
139
+ * @param data - Raw telemetry data from DIMO
140
+ * @param circuitId - Target circuit ID
141
+ * @returns Inputs ready for prove job submission
142
+ */
143
+ toCircuitInputs(data: DimoTelemetryData, circuitId: string): ProveJobInputs;
144
+ /**
145
+ * Get the list of circuits this adapter supports
146
+ */
147
+ getSupportedCircuits(): string[];
148
+ private toRiskBandInputs;
149
+ }
150
+ /**
151
+ * Factory function to create a DIMO adapter
152
+ */
153
+ declare function createDimoAdapter(config: DimoAdapterConfig): DimoAdapter;
154
+
155
+ export { type AdapterRegistration as A, DimoAdapter as D, type TelemetryData as T, type DimoAdapterConfig as a, type DimoQuery as b, createDimoAdapter as c, type DimoTelemetryData as d, type DimoSignal as e, type DimoClient as f, type DataAdapter as g, type TelemetrySignal as h };
@@ -0,0 +1,155 @@
1
+ import { a as ProveJobInputs } from './types-o4sbOK_a.js';
2
+
3
+ /**
4
+ * Base types for data source adapters
5
+ *
6
+ * Adapters abstract away the data source specifics and provide a uniform
7
+ * interface for fetching data that can be used as circuit inputs.
8
+ */
9
+
10
+ /**
11
+ * Base interface for all data source adapters
12
+ * Each adapter knows how to fetch data from a specific source
13
+ * and transform it into circuit inputs.
14
+ */
15
+ interface DataAdapter<TConfig = unknown, TQuery = unknown, TData = unknown> {
16
+ /** Unique identifier for this adapter */
17
+ readonly id: string;
18
+ /** Human-readable name */
19
+ readonly name: string;
20
+ /** Description of what data source this adapter connects to */
21
+ readonly description: string;
22
+ /**
23
+ * Fetch raw data from the data source
24
+ * @param query - Adapter-specific query parameters
25
+ * @returns Raw data from the source
26
+ */
27
+ fetchData(query: TQuery): Promise<TData>;
28
+ /**
29
+ * Transform raw data into circuit inputs
30
+ * @param data - Raw data from fetchData
31
+ * @param circuitId - Target circuit ID (adapters may support multiple circuits)
32
+ * @returns Inputs ready for prove job submission
33
+ */
34
+ toCircuitInputs(data: TData, circuitId: string): ProveJobInputs;
35
+ }
36
+ /**
37
+ * Adapter registration entry
38
+ */
39
+ interface AdapterRegistration<TConfig = unknown> {
40
+ /** Adapter factory function */
41
+ create: (config: TConfig) => DataAdapter;
42
+ /** Default configuration */
43
+ defaultConfig?: Partial<TConfig>;
44
+ /** Supported circuit IDs */
45
+ supportedCircuits: string[];
46
+ }
47
+ /**
48
+ * Common telemetry data structure that adapters can transform their data into
49
+ */
50
+ interface TelemetryData {
51
+ /** Array of telemetry signal readings */
52
+ signals: TelemetrySignal[];
53
+ /** Timestamp of the data collection period start */
54
+ periodStart: string;
55
+ /** Timestamp of the data collection period end */
56
+ periodEnd: string;
57
+ /** Subject identifier (e.g., vehicle ID) */
58
+ subjectId: string;
59
+ }
60
+ /**
61
+ * Individual telemetry signal reading
62
+ */
63
+ interface TelemetrySignal {
64
+ timestamp: string;
65
+ [key: string]: string | number | boolean | string[] | null;
66
+ }
67
+
68
+ /**
69
+ * DIMO Adapter Types
70
+ */
71
+ /**
72
+ * Configuration for the DIMO adapter
73
+ */
74
+ interface DimoAdapterConfig {
75
+ /** DIMO SDK client instance (from @dimo-network/data-sdk) */
76
+ dimoClient: DimoClient;
77
+ }
78
+ /**
79
+ * Query parameters for fetching DIMO telemetry
80
+ */
81
+ interface DimoQuery {
82
+ /** Vehicle token ID */
83
+ vehicleTokenId: string;
84
+ /** Start date for telemetry range (ISO 8601) */
85
+ from: string;
86
+ /** End date for telemetry range (ISO 8601) */
87
+ to: string;
88
+ }
89
+ /**
90
+ * Telemetry data structure returned by DIMO API
91
+ */
92
+ interface DimoTelemetryData {
93
+ signals: DimoSignal[];
94
+ timestamp: string;
95
+ }
96
+ /**
97
+ * Individual DIMO telemetry signal
98
+ */
99
+ interface DimoSignal {
100
+ powertrainTransmissionTravelledDistance: number;
101
+ speed: number;
102
+ powertrainCombustionEngineSpeed: number;
103
+ obdEngineLoad: number;
104
+ obdDTCList: string[];
105
+ obdRunTime: number;
106
+ timestamp?: string;
107
+ }
108
+ /**
109
+ * Minimal interface for DIMO SDK client
110
+ * This allows us to work with the DIMO SDK without directly depending on it
111
+ */
112
+ interface DimoClient {
113
+ telemetry: {
114
+ query: (graphqlQuery: string) => Promise<DimoTelemetryData>;
115
+ };
116
+ }
117
+
118
+ /**
119
+ * DIMO Adapter
120
+ *
121
+ * Fetches vehicle telemetry data from the DIMO network and transforms it
122
+ * into circuit inputs for Bind Protocol prove jobs.
123
+ */
124
+
125
+ declare class DimoAdapter implements DataAdapter<DimoAdapterConfig, DimoQuery, DimoTelemetryData> {
126
+ readonly id = "dimo";
127
+ readonly name = "DIMO Network";
128
+ readonly description = "Fetches vehicle telemetry data from the DIMO decentralized network";
129
+ private readonly dimoClient;
130
+ constructor(config: DimoAdapterConfig);
131
+ /**
132
+ * Fetch telemetry data from DIMO for a vehicle
133
+ * @param query - Query parameters including vehicle token ID and date range
134
+ * @returns Raw telemetry data from DIMO
135
+ */
136
+ fetchData(query: DimoQuery): Promise<DimoTelemetryData>;
137
+ /**
138
+ * Transform DIMO telemetry data into circuit inputs
139
+ * @param data - Raw telemetry data from DIMO
140
+ * @param circuitId - Target circuit ID
141
+ * @returns Inputs ready for prove job submission
142
+ */
143
+ toCircuitInputs(data: DimoTelemetryData, circuitId: string): ProveJobInputs;
144
+ /**
145
+ * Get the list of circuits this adapter supports
146
+ */
147
+ getSupportedCircuits(): string[];
148
+ private toRiskBandInputs;
149
+ }
150
+ /**
151
+ * Factory function to create a DIMO adapter
152
+ */
153
+ declare function createDimoAdapter(config: DimoAdapterConfig): DimoAdapter;
154
+
155
+ export { type AdapterRegistration as A, DimoAdapter as D, type TelemetryData as T, type DimoAdapterConfig as a, type DimoQuery as b, createDimoAdapter as c, type DimoTelemetryData as d, type DimoSignal as e, type DimoClient as f, type DataAdapter as g, type TelemetrySignal as h };