@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.
package/README.md ADDED
@@ -0,0 +1,309 @@
1
+ # @bind-protocol/sdk
2
+
3
+ TypeScript SDK for the **Bind Protocol** - privacy-preserving credential issuance and verification using zero-knowledge proofs.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @bind-protocol/sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { BindClient } from '@bind-protocol/sdk';
15
+
16
+ const client = new BindClient({
17
+ apiKey: 'your-api-key',
18
+ });
19
+
20
+ // Submit a prove job
21
+ const result = await client.submitProveJob('bind.mobility.riskband.v1', {
22
+ signals: JSON.stringify(telemetryData),
23
+ timestamp: new Date().toISOString(),
24
+ });
25
+
26
+ // Wait for completion
27
+ const job = await client.waitForProveJob(result.data.jobId);
28
+
29
+ if (job.status === 'completed') {
30
+ console.log('Proof generated:', job.attestationId);
31
+ }
32
+ ```
33
+
34
+ ## Architecture
35
+
36
+ The SDK is organized into modules:
37
+
38
+ ```
39
+ @bind-protocol/sdk
40
+ ├── core/ # Main client, types, and errors
41
+ │ ├── BindClient # API client for prove jobs and policies
42
+ │ ├── types # TypeScript type definitions
43
+ │ └── errors # Custom error classes
44
+ └── adapters/ # Data source adapters
45
+ └── dimo/ # DIMO Network integration
46
+ ```
47
+
48
+ ### Import Paths
49
+
50
+ ```typescript
51
+ // Main entry point (recommended)
52
+ import { BindClient, DimoAdapter } from '@bind-protocol/sdk';
53
+
54
+ // Or import specific modules
55
+ import { BindClient } from '@bind-protocol/sdk/core';
56
+ import { DimoAdapter } from '@bind-protocol/sdk/adapters/dimo';
57
+ ```
58
+
59
+ ## Core Module
60
+
61
+ ### BindClient
62
+
63
+ The main client for interacting with the Bind Protocol API.
64
+
65
+ ```typescript
66
+ import { BindClient } from '@bind-protocol/sdk';
67
+
68
+ const client = new BindClient({
69
+ apiKey: 'your-api-key',
70
+ baseUrl: 'https://api.bindprotocol.com', // optional
71
+ });
72
+ ```
73
+
74
+ #### Methods
75
+
76
+ | Method | Description |
77
+ |--------|-------------|
78
+ | `submitProveJob(circuitId, inputs)` | Submit a prove job for async processing |
79
+ | `getProveJob(jobId)` | Get status and results of a prove job |
80
+ | `listProveJobs(options?)` | List prove jobs with optional filters |
81
+ | `waitForProveJob(jobId, options?)` | Poll until job completes or fails |
82
+ | `listPolicies()` | List all public policies (no auth required) |
83
+ | `getPolicy(policyId)` | Get a specific policy by ID |
84
+
85
+ ### Error Handling
86
+
87
+ The SDK provides typed errors for common scenarios:
88
+
89
+ ```typescript
90
+ import {
91
+ BindError,
92
+ ApiError,
93
+ AuthenticationError,
94
+ TimeoutError,
95
+ InsufficientCreditsError
96
+ } from '@bind-protocol/sdk';
97
+
98
+ try {
99
+ await client.submitProveJob(circuitId, inputs);
100
+ } catch (error) {
101
+ if (error instanceof InsufficientCreditsError) {
102
+ console.log(`Need ${error.required} credits, have ${error.available}`);
103
+ } else if (error instanceof AuthenticationError) {
104
+ console.log('Invalid API key');
105
+ } else if (error instanceof TimeoutError) {
106
+ console.log(`Timed out after ${error.timeoutMs}ms`);
107
+ }
108
+ }
109
+ ```
110
+
111
+ ## Adapters
112
+
113
+ Adapters abstract data sources and transform their data into circuit inputs.
114
+
115
+ ### DIMO Adapter
116
+
117
+ Fetches vehicle telemetry from the [DIMO Network](https://dimo.zone) and transforms it for risk band evaluation.
118
+
119
+ ```typescript
120
+ import { BindClient, DimoAdapter } from '@bind-protocol/sdk';
121
+ import { DIMO } from '@dimo-network/data-sdk';
122
+
123
+ // Initialize DIMO client (see DIMO docs for auth)
124
+ const dimoClient = new DIMO('Production');
125
+ await dimoClient.auth.getToken({ /* ... */ });
126
+
127
+ // Create adapter
128
+ const dimo = new DimoAdapter({ dimoClient });
129
+
130
+ // Fetch telemetry
131
+ const data = await dimo.fetchData({
132
+ vehicleTokenId: '12345',
133
+ from: '2024-01-01',
134
+ to: '2024-01-31',
135
+ });
136
+
137
+ // Transform to circuit inputs
138
+ const inputs = dimo.toCircuitInputs(data, 'bind.mobility.riskband.v1');
139
+
140
+ // Submit prove job
141
+ const client = new BindClient({ apiKey: 'your-api-key' });
142
+ const result = await client.submitProveJob('bind.mobility.riskband.v1', inputs);
143
+ ```
144
+
145
+ ### Creating Custom Adapters
146
+
147
+ Implement the `DataAdapter` interface to create adapters for other data sources:
148
+
149
+ ```typescript
150
+ import type { DataAdapter, ProveJobInputs } from '@bind-protocol/sdk';
151
+
152
+ interface MyDataQuery {
153
+ userId: string;
154
+ dateRange: { from: string; to: string };
155
+ }
156
+
157
+ interface MyData {
158
+ metrics: number[];
159
+ timestamp: string;
160
+ }
161
+
162
+ class MyAdapter implements DataAdapter<MyConfig, MyDataQuery, MyData> {
163
+ readonly id = 'my-adapter';
164
+ readonly name = 'My Data Source';
165
+ readonly description = 'Fetches data from my service';
166
+
167
+ async fetchData(query: MyDataQuery): Promise<MyData> {
168
+ // Fetch from your data source
169
+ }
170
+
171
+ toCircuitInputs(data: MyData, circuitId: string): ProveJobInputs {
172
+ // Transform to circuit inputs
173
+ return {
174
+ metrics: JSON.stringify(data.metrics),
175
+ timestamp: data.timestamp,
176
+ };
177
+ }
178
+ }
179
+ ```
180
+
181
+ ## Policies and Circuits
182
+
183
+ ### Understanding Policies
184
+
185
+ A **Policy** defines what data is evaluated and what credentials are issued:
186
+
187
+ - Input specifications (what data is needed)
188
+ - Evaluation rules (how data is scored/validated)
189
+ - Output claims (what the credential asserts)
190
+ - Privacy controls (what verifiers can see)
191
+
192
+ ### Understanding Circuits
193
+
194
+ A **Circuit** is the zero-knowledge proof implementation that cryptographically proves a policy was evaluated correctly without revealing the underlying data.
195
+
196
+ ```typescript
197
+ // List available policies
198
+ const policies = await client.listPolicies();
199
+
200
+ for (const policy of policies) {
201
+ console.log(`${policy.id}: ${policy.metadata.title}`);
202
+ console.log(` Outputs: ${policy.outputs.map(o => o.name).join(', ')}`);
203
+ }
204
+
205
+ // Get policy details
206
+ const policy = await client.getPolicy('bind.mobility.riskband.v1');
207
+ console.log(policy.outputs); // [{ name: 'riskBand', type: 'enum', ... }]
208
+ ```
209
+
210
+ ## Complete Example: Insurance Risk Assessment
211
+
212
+ ```typescript
213
+ import { BindClient, DimoAdapter } from '@bind-protocol/sdk';
214
+ import { DIMO } from '@dimo-network/data-sdk';
215
+
216
+ async function generateRiskCredential(vehicleTokenId: string) {
217
+ // 1. Set up clients
218
+ const dimoClient = new DIMO('Production');
219
+ await dimoClient.auth.getToken({ /* ... */ });
220
+
221
+ const dimo = new DimoAdapter({ dimoClient });
222
+ const bind = new BindClient({ apiKey: process.env.BIND_API_KEY });
223
+
224
+ // 2. Fetch 30 days of telemetry
225
+ const telemetry = await dimo.fetchData({
226
+ vehicleTokenId,
227
+ from: '2024-12-01',
228
+ to: '2024-12-31',
229
+ });
230
+
231
+ // 3. Transform and submit prove job
232
+ const inputs = dimo.toCircuitInputs(telemetry, 'bind.mobility.riskband.v1');
233
+ const result = await bind.submitProveJob('bind.mobility.riskband.v1', inputs);
234
+
235
+ if (!result.success) {
236
+ throw new Error(result.error);
237
+ }
238
+
239
+ // 4. Wait for proof generation
240
+ const job = await bind.waitForProveJob(result.data.jobId, {
241
+ onProgress: (j) => console.log(`Status: ${j.status}`),
242
+ });
243
+
244
+ if (job.status !== 'completed') {
245
+ throw new Error(job.error || 'Proof generation failed');
246
+ }
247
+
248
+ // 5. Return credential
249
+ return {
250
+ policyId: 'bind.mobility.riskband.v1',
251
+ attestationId: job.attestationId,
252
+ zkVerifyTxHash: job.zkVerifyTxHash,
253
+ };
254
+ }
255
+ ```
256
+
257
+ ## Types
258
+
259
+ All types are exported from the main package:
260
+
261
+ ```typescript
262
+ import type {
263
+ // Client options
264
+ BindClientOptions,
265
+
266
+ // Prove job types
267
+ ProveJobStatus,
268
+ ProveJobInputs,
269
+ ProveJob,
270
+ ProveJobSummary,
271
+ SubmitProveJobResponse,
272
+ GetProveJobResponse,
273
+ ListProveJobsOptions,
274
+ ListProveJobsResponse,
275
+
276
+ // Credential types
277
+ BindCredential,
278
+
279
+ // Policy types (from @bind-protocol/policy-spec)
280
+ PublicPolicySpec,
281
+ PolicyId,
282
+ PolicyMetadata,
283
+
284
+ // Adapter types
285
+ DataAdapter,
286
+ TelemetryData,
287
+
288
+ // DIMO types
289
+ DimoAdapterConfig,
290
+ DimoQuery,
291
+ DimoTelemetryData,
292
+ } from '@bind-protocol/sdk';
293
+ ```
294
+
295
+ ## Environment Variables
296
+
297
+ | Variable | Description | Default |
298
+ |----------|-------------|---------|
299
+ | `BIND_API_URL` | API base URL | `https://api.bindprotocol.com` |
300
+
301
+ ## License
302
+
303
+ MIT
304
+
305
+ ## Links
306
+
307
+ - [Bind Protocol](https://bindprotocol.com)
308
+ - [Documentation](https://docs.bindprotocol.com)
309
+ - [DIMO Network](https://dimo.zone)
@@ -0,0 +1,108 @@
1
+ 'use strict';
2
+
3
+ // src/adapters/dimo/queries.ts
4
+ function buildTelemetryQuery(vehicleTokenId, from, to) {
5
+ return `{
6
+ signals(
7
+ tokenId: ${vehicleTokenId},
8
+ interval: "1h",
9
+ from: ${from},
10
+ to: ${to}
11
+ ) {
12
+ powertrainTransmissionTravelledDistance(agg: AVG)
13
+ speed(agg: AVG)
14
+ powertrainCombustionEngineSpeed(agg: AVG)
15
+ obdEngineLoad(agg: AVG)
16
+ obdDTCList(agg: UNIQUE)
17
+ obdRunTime(agg: AVG)
18
+ timestamp
19
+ }
20
+ }`;
21
+ }
22
+ function buildCustomTelemetryQuery(vehicleTokenId, from, to, signals, interval = "1h") {
23
+ const signalLines = signals.map((s) => {
24
+ if (s.aggregation) {
25
+ return ` ${s.name}(agg: ${s.aggregation})`;
26
+ }
27
+ return ` ${s.name}`;
28
+ }).join("\n");
29
+ return `{
30
+ signals(
31
+ tokenId: ${vehicleTokenId},
32
+ interval: "${interval}",
33
+ from: ${from},
34
+ to: ${to}
35
+ ) {
36
+ ${signalLines}
37
+ timestamp
38
+ }
39
+ }`;
40
+ }
41
+
42
+ // src/adapters/dimo/adapter.ts
43
+ var SUPPORTED_CIRCUITS = [
44
+ "bind.mobility.riskband.v1"
45
+ ];
46
+ var DimoAdapter = class {
47
+ id = "dimo";
48
+ name = "DIMO Network";
49
+ description = "Fetches vehicle telemetry data from the DIMO decentralized network";
50
+ dimoClient;
51
+ constructor(config) {
52
+ this.dimoClient = config.dimoClient;
53
+ }
54
+ /**
55
+ * Fetch telemetry data from DIMO for a vehicle
56
+ * @param query - Query parameters including vehicle token ID and date range
57
+ * @returns Raw telemetry data from DIMO
58
+ */
59
+ async fetchData(query) {
60
+ const graphqlQuery = buildTelemetryQuery(query.vehicleTokenId, query.from, query.to);
61
+ const result = await this.dimoClient.telemetry.query(graphqlQuery);
62
+ return result;
63
+ }
64
+ /**
65
+ * Transform DIMO telemetry data into circuit inputs
66
+ * @param data - Raw telemetry data from DIMO
67
+ * @param circuitId - Target circuit ID
68
+ * @returns Inputs ready for prove job submission
69
+ */
70
+ toCircuitInputs(data, circuitId) {
71
+ if (!SUPPORTED_CIRCUITS.includes(circuitId)) {
72
+ throw new Error(
73
+ `Circuit "${circuitId}" is not supported by the DIMO adapter. Supported circuits: ${SUPPORTED_CIRCUITS.join(", ")}`
74
+ );
75
+ }
76
+ switch (circuitId) {
77
+ case "bind.mobility.riskband.v1":
78
+ return this.toRiskBandInputs(data);
79
+ default:
80
+ throw new Error(`No input transformer for circuit: ${circuitId}`);
81
+ }
82
+ }
83
+ /**
84
+ * Get the list of circuits this adapter supports
85
+ */
86
+ getSupportedCircuits() {
87
+ return [...SUPPORTED_CIRCUITS];
88
+ }
89
+ // ===========================================================================
90
+ // Private transformers
91
+ // ===========================================================================
92
+ toRiskBandInputs(data) {
93
+ return {
94
+ signals: JSON.stringify(data.signals),
95
+ timestamp: data.timestamp
96
+ };
97
+ }
98
+ };
99
+ function createDimoAdapter(config) {
100
+ return new DimoAdapter(config);
101
+ }
102
+
103
+ exports.DimoAdapter = DimoAdapter;
104
+ exports.buildCustomTelemetryQuery = buildCustomTelemetryQuery;
105
+ exports.buildTelemetryQuery = buildTelemetryQuery;
106
+ exports.createDimoAdapter = createDimoAdapter;
107
+ //# sourceMappingURL=index.cjs.map
108
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/adapters/dimo/queries.ts","../../../src/adapters/dimo/adapter.ts"],"names":[],"mappings":";;;AAWO,SAAS,mBAAA,CACd,cAAA,EACA,IAAA,EACA,EAAA,EACQ;AACR,EAAA,OAAO,CAAA;AAAA;AAAA,aAAA,EAEM,cAAc,CAAA;AAAA;AAAA,UAAA,EAEjB,IAAI,CAAA;AAAA,QAAA,EACN,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA,CAAA;AAWZ;AAMO,SAAS,0BACd,cAAA,EACA,IAAA,EACA,EAAA,EACA,OAAA,EAIA,WAAW,IAAA,EACH;AACR,EAAA,MAAM,WAAA,GAAc,OAAA,CACjB,GAAA,CAAI,CAAC,CAAA,KAAM;AACV,IAAA,IAAI,EAAE,WAAA,EAAa;AACjB,MAAA,OAAO,CAAA,IAAA,EAAO,CAAA,CAAE,IAAI,CAAA,MAAA,EAAS,EAAE,WAAW,CAAA,CAAA,CAAA;AAAA,IAC5C;AACA,IAAA,OAAO,CAAA,IAAA,EAAO,EAAE,IAAI,CAAA,CAAA;AAAA,EACtB,CAAC,CAAA,CACA,IAAA,CAAK,IAAI,CAAA;AAEZ,EAAA,OAAO,CAAA;AAAA;AAAA,aAAA,EAEM,cAAc,CAAA;AAAA,eAAA,EACZ,QAAQ,CAAA;AAAA,UAAA,EACb,IAAI,CAAA;AAAA,QAAA,EACN,EAAE;AAAA;AAAA,EAEV,WAAW;AAAA;AAAA;AAAA,CAAA,CAAA;AAIb;;;ACxDA,IAAM,kBAAA,GAAqB;AAAA,EACzB;AACF,CAAA;AAEO,IAAM,cAAN,MAA0F;AAAA,EAC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MACpC,WAAW,IAAA,CAAK;AAAA,KAClB;AAAA,EACF;AACF;AAKO,SAAS,kBAAkB,MAAA,EAAwC;AACxE,EAAA,OAAO,IAAI,YAAY,MAAM,CAAA;AAC/B","file":"index.cjs","sourcesContent":["/**\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,24 @@
1
+ export { D as DimoAdapter, a as DimoAdapterConfig, f as DimoClient, b as DimoQuery, e as DimoSignal, d as DimoTelemetryData, c as createDimoAdapter } from '../../index-5j-fuebC.cjs';
2
+ import '../../types-o4sbOK_a.cjs';
3
+
4
+ /**
5
+ * DIMO GraphQL query builders
6
+ */
7
+ /**
8
+ * Build a GraphQL query for fetching vehicle telemetry
9
+ * @param vehicleTokenId - The DIMO vehicle token ID
10
+ * @param from - Start date (ISO 8601 or date string)
11
+ * @param to - End date (ISO 8601 or date string)
12
+ * @returns GraphQL query string
13
+ */
14
+ declare function buildTelemetryQuery(vehicleTokenId: string, from: string, to: string): string;
15
+ /**
16
+ * Build a GraphQL query for fetching specific signals
17
+ * Allows customization of which signals to fetch and their aggregation
18
+ */
19
+ declare function buildCustomTelemetryQuery(vehicleTokenId: string, from: string, to: string, signals: Array<{
20
+ name: string;
21
+ aggregation?: 'AVG' | 'SUM' | 'MIN' | 'MAX' | 'UNIQUE' | 'COUNT';
22
+ }>, interval?: string): string;
23
+
24
+ export { buildCustomTelemetryQuery, buildTelemetryQuery };
@@ -0,0 +1,24 @@
1
+ export { D as DimoAdapter, a as DimoAdapterConfig, f as DimoClient, b as DimoQuery, e as DimoSignal, d as DimoTelemetryData, c as createDimoAdapter } from '../../index-CASjN9Qe.js';
2
+ import '../../types-o4sbOK_a.js';
3
+
4
+ /**
5
+ * DIMO GraphQL query builders
6
+ */
7
+ /**
8
+ * Build a GraphQL query for fetching vehicle telemetry
9
+ * @param vehicleTokenId - The DIMO vehicle token ID
10
+ * @param from - Start date (ISO 8601 or date string)
11
+ * @param to - End date (ISO 8601 or date string)
12
+ * @returns GraphQL query string
13
+ */
14
+ declare function buildTelemetryQuery(vehicleTokenId: string, from: string, to: string): string;
15
+ /**
16
+ * Build a GraphQL query for fetching specific signals
17
+ * Allows customization of which signals to fetch and their aggregation
18
+ */
19
+ declare function buildCustomTelemetryQuery(vehicleTokenId: string, from: string, to: string, signals: Array<{
20
+ name: string;
21
+ aggregation?: 'AVG' | 'SUM' | 'MIN' | 'MAX' | 'UNIQUE' | 'COUNT';
22
+ }>, interval?: string): string;
23
+
24
+ export { buildCustomTelemetryQuery, buildTelemetryQuery };
@@ -0,0 +1,103 @@
1
+ // src/adapters/dimo/queries.ts
2
+ function buildTelemetryQuery(vehicleTokenId, from, to) {
3
+ return `{
4
+ signals(
5
+ tokenId: ${vehicleTokenId},
6
+ interval: "1h",
7
+ from: ${from},
8
+ to: ${to}
9
+ ) {
10
+ powertrainTransmissionTravelledDistance(agg: AVG)
11
+ speed(agg: AVG)
12
+ powertrainCombustionEngineSpeed(agg: AVG)
13
+ obdEngineLoad(agg: AVG)
14
+ obdDTCList(agg: UNIQUE)
15
+ obdRunTime(agg: AVG)
16
+ timestamp
17
+ }
18
+ }`;
19
+ }
20
+ function buildCustomTelemetryQuery(vehicleTokenId, from, to, signals, interval = "1h") {
21
+ const signalLines = signals.map((s) => {
22
+ if (s.aggregation) {
23
+ return ` ${s.name}(agg: ${s.aggregation})`;
24
+ }
25
+ return ` ${s.name}`;
26
+ }).join("\n");
27
+ return `{
28
+ signals(
29
+ tokenId: ${vehicleTokenId},
30
+ interval: "${interval}",
31
+ from: ${from},
32
+ to: ${to}
33
+ ) {
34
+ ${signalLines}
35
+ timestamp
36
+ }
37
+ }`;
38
+ }
39
+
40
+ // src/adapters/dimo/adapter.ts
41
+ var SUPPORTED_CIRCUITS = [
42
+ "bind.mobility.riskband.v1"
43
+ ];
44
+ var DimoAdapter = class {
45
+ id = "dimo";
46
+ name = "DIMO Network";
47
+ description = "Fetches vehicle telemetry data from the DIMO decentralized network";
48
+ dimoClient;
49
+ constructor(config) {
50
+ this.dimoClient = config.dimoClient;
51
+ }
52
+ /**
53
+ * Fetch telemetry data from DIMO for a vehicle
54
+ * @param query - Query parameters including vehicle token ID and date range
55
+ * @returns Raw telemetry data from DIMO
56
+ */
57
+ async fetchData(query) {
58
+ const graphqlQuery = buildTelemetryQuery(query.vehicleTokenId, query.from, query.to);
59
+ const result = await this.dimoClient.telemetry.query(graphqlQuery);
60
+ return result;
61
+ }
62
+ /**
63
+ * Transform DIMO telemetry data into circuit inputs
64
+ * @param data - Raw telemetry data from DIMO
65
+ * @param circuitId - Target circuit ID
66
+ * @returns Inputs ready for prove job submission
67
+ */
68
+ toCircuitInputs(data, circuitId) {
69
+ if (!SUPPORTED_CIRCUITS.includes(circuitId)) {
70
+ throw new Error(
71
+ `Circuit "${circuitId}" is not supported by the DIMO adapter. Supported circuits: ${SUPPORTED_CIRCUITS.join(", ")}`
72
+ );
73
+ }
74
+ switch (circuitId) {
75
+ case "bind.mobility.riskband.v1":
76
+ return this.toRiskBandInputs(data);
77
+ default:
78
+ throw new Error(`No input transformer for circuit: ${circuitId}`);
79
+ }
80
+ }
81
+ /**
82
+ * Get the list of circuits this adapter supports
83
+ */
84
+ getSupportedCircuits() {
85
+ return [...SUPPORTED_CIRCUITS];
86
+ }
87
+ // ===========================================================================
88
+ // Private transformers
89
+ // ===========================================================================
90
+ toRiskBandInputs(data) {
91
+ return {
92
+ signals: JSON.stringify(data.signals),
93
+ timestamp: data.timestamp
94
+ };
95
+ }
96
+ };
97
+ function createDimoAdapter(config) {
98
+ return new DimoAdapter(config);
99
+ }
100
+
101
+ export { DimoAdapter, buildCustomTelemetryQuery, buildTelemetryQuery, createDimoAdapter };
102
+ //# sourceMappingURL=index.js.map
103
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/adapters/dimo/queries.ts","../../../src/adapters/dimo/adapter.ts"],"names":[],"mappings":";AAWO,SAAS,mBAAA,CACd,cAAA,EACA,IAAA,EACA,EAAA,EACQ;AACR,EAAA,OAAO,CAAA;AAAA;AAAA,aAAA,EAEM,cAAc,CAAA;AAAA;AAAA,UAAA,EAEjB,IAAI,CAAA;AAAA,QAAA,EACN,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA,CA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AAAA,EAQA,eAAA,CAAgB,MAAyB,SAAA,EAAmC;AAC1E,IAAA,IAAI,CAAC,kBAAA,CAAmB,QAAA,CAAS,SAAS,CAAA,EAAG;AAC3C,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,YAAY,SAAS,CAAA,4DAAA,EACE,kBAAA,CAAmB,IAAA,CAAK,IAAI,CAAC,CAAA;AAAA,OACtD;AAAA,IACF;AAGA,IAAA,QAAQ,SAAA;AAAW,MACjB,KAAK,2BAAA;AACH,QAAA,OAAO,IAAA,CAAK,iBAAiB,IAAI,CAAA;AAAA,MACnC;AACE,QAAA,MAAM,IAAI,KAAA,CAAM,CAAA,kCAAA,EAAqC,SAAS,CAAA,CAAE,CAAA;AAAA;AACpE,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,oBAAA,GAAiC;AAC/B,IAAA,OAAO,CAAC,GAAG,kBAAkB,CAAA;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA,EAMQ,iBAAiB,IAAA,EAAyC;AAChE,IAAA,OAAO;AAAA,MACL,OAAA,EAAS,IAAA,CAAK,SAAA,CAAU,IAAA,CAAK,OAAO,CAAA;AAAA,MACpC,WAAW,IAAA,CAAK;AAAA,KAClB;AAAA,EACF;AACF;AAKO,SAAS,kBAAkB,MAAA,EAAwC;AACxE,EAAA,OAAO,IAAI,YAAY,MAAM,CAAA;AAC/B","file":"index.js","sourcesContent":["/**\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,83 @@
1
+ 'use strict';
2
+
3
+ // src/adapters/dimo/queries.ts
4
+ function buildTelemetryQuery(vehicleTokenId, from, to) {
5
+ return `{
6
+ signals(
7
+ tokenId: ${vehicleTokenId},
8
+ interval: "1h",
9
+ from: ${from},
10
+ to: ${to}
11
+ ) {
12
+ powertrainTransmissionTravelledDistance(agg: AVG)
13
+ speed(agg: AVG)
14
+ powertrainCombustionEngineSpeed(agg: AVG)
15
+ obdEngineLoad(agg: AVG)
16
+ obdDTCList(agg: UNIQUE)
17
+ obdRunTime(agg: AVG)
18
+ timestamp
19
+ }
20
+ }`;
21
+ }
22
+
23
+ // src/adapters/dimo/adapter.ts
24
+ var SUPPORTED_CIRCUITS = [
25
+ "bind.mobility.riskband.v1"
26
+ ];
27
+ var DimoAdapter = class {
28
+ id = "dimo";
29
+ name = "DIMO Network";
30
+ description = "Fetches vehicle telemetry data from the DIMO decentralized network";
31
+ dimoClient;
32
+ constructor(config) {
33
+ this.dimoClient = config.dimoClient;
34
+ }
35
+ /**
36
+ * Fetch telemetry data from DIMO for a vehicle
37
+ * @param query - Query parameters including vehicle token ID and date range
38
+ * @returns Raw telemetry data from DIMO
39
+ */
40
+ async fetchData(query) {
41
+ const graphqlQuery = buildTelemetryQuery(query.vehicleTokenId, query.from, query.to);
42
+ const result = await this.dimoClient.telemetry.query(graphqlQuery);
43
+ return result;
44
+ }
45
+ /**
46
+ * Transform DIMO telemetry data into circuit inputs
47
+ * @param data - Raw telemetry data from DIMO
48
+ * @param circuitId - Target circuit ID
49
+ * @returns Inputs ready for prove job submission
50
+ */
51
+ toCircuitInputs(data, circuitId) {
52
+ if (!SUPPORTED_CIRCUITS.includes(circuitId)) {
53
+ throw new Error(
54
+ `Circuit "${circuitId}" is not supported by the DIMO adapter. Supported circuits: ${SUPPORTED_CIRCUITS.join(", ")}`
55
+ );
56
+ }
57
+ switch (circuitId) {
58
+ case "bind.mobility.riskband.v1":
59
+ return this.toRiskBandInputs(data);
60
+ default:
61
+ throw new Error(`No input transformer for circuit: ${circuitId}`);
62
+ }
63
+ }
64
+ /**
65
+ * Get the list of circuits this adapter supports
66
+ */
67
+ getSupportedCircuits() {
68
+ return [...SUPPORTED_CIRCUITS];
69
+ }
70
+ // ===========================================================================
71
+ // Private transformers
72
+ // ===========================================================================
73
+ toRiskBandInputs(data) {
74
+ return {
75
+ signals: JSON.stringify(data.signals),
76
+ timestamp: data.timestamp
77
+ };
78
+ }
79
+ };
80
+
81
+ exports.DimoAdapter = DimoAdapter;
82
+ //# sourceMappingURL=index.cjs.map
83
+ //# sourceMappingURL=index.cjs.map