@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 +309 -0
- package/dist/adapters/dimo/index.cjs +108 -0
- package/dist/adapters/dimo/index.cjs.map +1 -0
- package/dist/adapters/dimo/index.d.cts +24 -0
- package/dist/adapters/dimo/index.d.ts +24 -0
- package/dist/adapters/dimo/index.js +103 -0
- package/dist/adapters/dimo/index.js.map +1 -0
- package/dist/adapters/index.cjs +83 -0
- package/dist/adapters/index.cjs.map +1 -0
- package/dist/adapters/index.d.cts +2 -0
- package/dist/adapters/index.d.ts +2 -0
- package/dist/adapters/index.js +81 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/core/index.cjs +210 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +89 -0
- package/dist/core/index.d.ts +89 -0
- package/dist/core/index.js +203 -0
- package/dist/core/index.js.map +1 -0
- package/dist/index-5j-fuebC.d.cts +155 -0
- package/dist/index-CASjN9Qe.d.ts +155 -0
- package/dist/index.cjs +317 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +303 -0
- package/dist/index.js.map +1 -0
- package/dist/types-o4sbOK_a.d.cts +101 -0
- package/dist/types-o4sbOK_a.d.ts +101 -0
- package/package.json +76 -0
|
@@ -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;;;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OAAO;AAAA,MACL,OAAA,EAAS,IAAA,CAAK,SAAA,CAAU,IAAA,CAAK,OAAO,CAAA;AAAA,MACpC,WAAW,IAAA,CAAK;AAAA,KAClB;AAAA,EACF;AACF","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,81 @@
|
|
|
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
|
+
|
|
21
|
+
// src/adapters/dimo/adapter.ts
|
|
22
|
+
var SUPPORTED_CIRCUITS = [
|
|
23
|
+
"bind.mobility.riskband.v1"
|
|
24
|
+
];
|
|
25
|
+
var DimoAdapter = class {
|
|
26
|
+
id = "dimo";
|
|
27
|
+
name = "DIMO Network";
|
|
28
|
+
description = "Fetches vehicle telemetry data from the DIMO decentralized network";
|
|
29
|
+
dimoClient;
|
|
30
|
+
constructor(config) {
|
|
31
|
+
this.dimoClient = config.dimoClient;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Fetch telemetry data from DIMO for a vehicle
|
|
35
|
+
* @param query - Query parameters including vehicle token ID and date range
|
|
36
|
+
* @returns Raw telemetry data from DIMO
|
|
37
|
+
*/
|
|
38
|
+
async fetchData(query) {
|
|
39
|
+
const graphqlQuery = buildTelemetryQuery(query.vehicleTokenId, query.from, query.to);
|
|
40
|
+
const result = await this.dimoClient.telemetry.query(graphqlQuery);
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Transform DIMO telemetry data into circuit inputs
|
|
45
|
+
* @param data - Raw telemetry data from DIMO
|
|
46
|
+
* @param circuitId - Target circuit ID
|
|
47
|
+
* @returns Inputs ready for prove job submission
|
|
48
|
+
*/
|
|
49
|
+
toCircuitInputs(data, circuitId) {
|
|
50
|
+
if (!SUPPORTED_CIRCUITS.includes(circuitId)) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
`Circuit "${circuitId}" is not supported by the DIMO adapter. Supported circuits: ${SUPPORTED_CIRCUITS.join(", ")}`
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
switch (circuitId) {
|
|
56
|
+
case "bind.mobility.riskband.v1":
|
|
57
|
+
return this.toRiskBandInputs(data);
|
|
58
|
+
default:
|
|
59
|
+
throw new Error(`No input transformer for circuit: ${circuitId}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get the list of circuits this adapter supports
|
|
64
|
+
*/
|
|
65
|
+
getSupportedCircuits() {
|
|
66
|
+
return [...SUPPORTED_CIRCUITS];
|
|
67
|
+
}
|
|
68
|
+
// ===========================================================================
|
|
69
|
+
// Private transformers
|
|
70
|
+
// ===========================================================================
|
|
71
|
+
toRiskBandInputs(data) {
|
|
72
|
+
return {
|
|
73
|
+
signals: JSON.stringify(data.signals),
|
|
74
|
+
timestamp: data.timestamp
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export { DimoAdapter };
|
|
80
|
+
//# sourceMappingURL=index.js.map
|
|
81
|
+
//# 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;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AC/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","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,210 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/core/errors.ts
|
|
4
|
+
var BindError = class extends Error {
|
|
5
|
+
constructor(message, code, details) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.code = code;
|
|
8
|
+
this.details = details;
|
|
9
|
+
this.name = "BindError";
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var ApiError = class extends BindError {
|
|
13
|
+
constructor(message, status, response) {
|
|
14
|
+
super(message, "API_ERROR", { status, response });
|
|
15
|
+
this.status = status;
|
|
16
|
+
this.response = response;
|
|
17
|
+
this.name = "ApiError";
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var AuthenticationError = class extends BindError {
|
|
21
|
+
constructor(message = "Authentication failed") {
|
|
22
|
+
super(message, "AUTH_ERROR");
|
|
23
|
+
this.name = "AuthenticationError";
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var TimeoutError = class extends BindError {
|
|
27
|
+
constructor(message, timeoutMs) {
|
|
28
|
+
super(message, "TIMEOUT_ERROR", { timeoutMs });
|
|
29
|
+
this.timeoutMs = timeoutMs;
|
|
30
|
+
this.name = "TimeoutError";
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var InsufficientCreditsError = class extends BindError {
|
|
34
|
+
constructor(required, available) {
|
|
35
|
+
super(
|
|
36
|
+
`Insufficient credits: need ${required}, have ${available}`,
|
|
37
|
+
"INSUFFICIENT_CREDITS",
|
|
38
|
+
{ required, available }
|
|
39
|
+
);
|
|
40
|
+
this.required = required;
|
|
41
|
+
this.available = available;
|
|
42
|
+
this.name = "InsufficientCreditsError";
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// src/core/client.ts
|
|
47
|
+
var DEFAULT_BASE_URL = "https://api.bindprotocol.com";
|
|
48
|
+
var DEFAULT_POLL_INTERVAL_MS = 2e3;
|
|
49
|
+
var DEFAULT_TIMEOUT_MS = 3e5;
|
|
50
|
+
var BindClient = class {
|
|
51
|
+
apiKey;
|
|
52
|
+
baseUrl;
|
|
53
|
+
headers;
|
|
54
|
+
constructor(options) {
|
|
55
|
+
this.apiKey = options.apiKey;
|
|
56
|
+
this.baseUrl = options.baseUrl || process.env.BIND_API_URL || DEFAULT_BASE_URL;
|
|
57
|
+
this.headers = {
|
|
58
|
+
"X-API-Key": this.apiKey,
|
|
59
|
+
"Content-Type": "application/json"
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
// ==========================================================================
|
|
63
|
+
// Prove Job Methods
|
|
64
|
+
// ==========================================================================
|
|
65
|
+
/**
|
|
66
|
+
* Submit a prove job for async processing
|
|
67
|
+
* @param circuitId - The circuit identifier (e.g., "bind.mobility.riskband.v1")
|
|
68
|
+
* @param inputs - Circuit inputs as key-value pairs (all values must be strings)
|
|
69
|
+
* @returns The submitted job details
|
|
70
|
+
* @throws {ApiError} If the API request fails
|
|
71
|
+
* @throws {InsufficientCreditsError} If there aren't enough credits
|
|
72
|
+
*/
|
|
73
|
+
async submitProveJob(circuitId, inputs) {
|
|
74
|
+
const response = await this.fetch("/api/prove", {
|
|
75
|
+
method: "POST",
|
|
76
|
+
body: JSON.stringify({ circuitId, inputs })
|
|
77
|
+
});
|
|
78
|
+
const result = await response.json();
|
|
79
|
+
if (!result.success && result.requiredCredits !== void 0 && result.availableCredits !== void 0) {
|
|
80
|
+
throw new InsufficientCreditsError(result.requiredCredits, result.availableCredits);
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get the status and results of a prove job
|
|
86
|
+
* @param jobId - The unique job identifier
|
|
87
|
+
* @returns The job details including status and outputs
|
|
88
|
+
*/
|
|
89
|
+
async getProveJob(jobId) {
|
|
90
|
+
const response = await this.fetch(`/api/prove/${encodeURIComponent(jobId)}`);
|
|
91
|
+
return response.json();
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* List prove jobs for the authenticated organization
|
|
95
|
+
* @param options - Optional filters for status, limit, and offset
|
|
96
|
+
* @returns Paginated list of prove jobs
|
|
97
|
+
*/
|
|
98
|
+
async listProveJobs(options = {}) {
|
|
99
|
+
const params = new URLSearchParams();
|
|
100
|
+
if (options.status) params.set("status", options.status);
|
|
101
|
+
if (options.limit !== void 0) params.set("limit", options.limit.toString());
|
|
102
|
+
if (options.offset !== void 0) params.set("offset", options.offset.toString());
|
|
103
|
+
const queryString = params.toString();
|
|
104
|
+
const path = queryString ? `/api/prove?${queryString}` : "/api/prove";
|
|
105
|
+
const response = await this.fetch(path);
|
|
106
|
+
return response.json();
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Poll for prove job completion
|
|
110
|
+
* @param jobId - The unique job identifier
|
|
111
|
+
* @param options - Polling options
|
|
112
|
+
* @returns The completed or failed job
|
|
113
|
+
* @throws {TimeoutError} If the job doesn't complete within the timeout
|
|
114
|
+
*/
|
|
115
|
+
async waitForProveJob(jobId, options = {}) {
|
|
116
|
+
const intervalMs = options.intervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
117
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
118
|
+
const startTime = Date.now();
|
|
119
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
120
|
+
const result = await this.getProveJob(jobId);
|
|
121
|
+
if (!result.success || !result.data) {
|
|
122
|
+
throw new ApiError(
|
|
123
|
+
result.error || "Failed to get prove job",
|
|
124
|
+
500,
|
|
125
|
+
result
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
const job = result.data;
|
|
129
|
+
if (options.onProgress) {
|
|
130
|
+
options.onProgress(job);
|
|
131
|
+
}
|
|
132
|
+
if (job.status === "completed" || job.status === "failed") {
|
|
133
|
+
return job;
|
|
134
|
+
}
|
|
135
|
+
await this.sleep(intervalMs);
|
|
136
|
+
}
|
|
137
|
+
throw new TimeoutError(
|
|
138
|
+
`Timeout waiting for prove job ${jobId} after ${timeoutMs}ms`,
|
|
139
|
+
timeoutMs
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
// ==========================================================================
|
|
143
|
+
// Policy Methods (Public, no authentication required)
|
|
144
|
+
// ==========================================================================
|
|
145
|
+
/**
|
|
146
|
+
* List all available public policies
|
|
147
|
+
* @returns Array of public policy specifications
|
|
148
|
+
*/
|
|
149
|
+
async listPolicies() {
|
|
150
|
+
const response = await fetch(`${this.baseUrl}/api/policies`, {
|
|
151
|
+
method: "GET"
|
|
152
|
+
});
|
|
153
|
+
if (!response.ok) {
|
|
154
|
+
throw new ApiError(
|
|
155
|
+
`Failed to fetch policies: ${response.statusText}`,
|
|
156
|
+
response.status
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
return response.json();
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Get a specific policy by ID
|
|
163
|
+
* @param policyId - The unique policy identifier
|
|
164
|
+
* @returns The public policy specification, or null if not found
|
|
165
|
+
*/
|
|
166
|
+
async getPolicy(policyId) {
|
|
167
|
+
const response = await fetch(
|
|
168
|
+
`${this.baseUrl}/api/policies/${encodeURIComponent(policyId)}`,
|
|
169
|
+
{ method: "GET" }
|
|
170
|
+
);
|
|
171
|
+
if (response.status === 404) {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
if (!response.ok) {
|
|
175
|
+
throw new ApiError(
|
|
176
|
+
`Failed to fetch policy: ${response.statusText}`,
|
|
177
|
+
response.status
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
return response.json();
|
|
181
|
+
}
|
|
182
|
+
// ==========================================================================
|
|
183
|
+
// Private Helpers
|
|
184
|
+
// ==========================================================================
|
|
185
|
+
async fetch(path, init) {
|
|
186
|
+
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
187
|
+
...init,
|
|
188
|
+
headers: {
|
|
189
|
+
...this.headers,
|
|
190
|
+
...init?.headers
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
if (response.status === 401) {
|
|
194
|
+
throw new AuthenticationError();
|
|
195
|
+
}
|
|
196
|
+
return response;
|
|
197
|
+
}
|
|
198
|
+
sleep(ms) {
|
|
199
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
exports.ApiError = ApiError;
|
|
204
|
+
exports.AuthenticationError = AuthenticationError;
|
|
205
|
+
exports.BindClient = BindClient;
|
|
206
|
+
exports.BindError = BindError;
|
|
207
|
+
exports.InsufficientCreditsError = InsufficientCreditsError;
|
|
208
|
+
exports.TimeoutError = TimeoutError;
|
|
209
|
+
//# sourceMappingURL=index.cjs.map
|
|
210
|
+
//# sourceMappingURL=index.cjs.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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AAA;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 * 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,89 @@
|
|
|
1
|
+
import { PublicPolicySpec } from '@bind-protocol/policy-spec';
|
|
2
|
+
export { DisclosureSpec, OutputClaimSpec, PolicyId, PolicyMetadata, PublicPolicySpec, SubjectSpec, ValiditySpec } from '@bind-protocol/policy-spec';
|
|
3
|
+
import { B as BindClientOptions, a as ProveJobInputs, e as SubmitProveJobResponse, G as GetProveJobResponse, L as ListProveJobsOptions, f as ListProveJobsResponse, c as ProveJob } from '../types-o4sbOK_a.cjs';
|
|
4
|
+
export { g as BindCredential, b as ProveJobOutputs, P as ProveJobStatus, d as ProveJobSummary, S as SubmitProveJobRequest } from '../types-o4sbOK_a.cjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* BindClient - Main client for interacting with the Bind Protocol API
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
declare class BindClient {
|
|
11
|
+
private readonly apiKey;
|
|
12
|
+
private readonly baseUrl;
|
|
13
|
+
private readonly headers;
|
|
14
|
+
constructor(options: BindClientOptions);
|
|
15
|
+
/**
|
|
16
|
+
* Submit a prove job for async processing
|
|
17
|
+
* @param circuitId - The circuit identifier (e.g., "bind.mobility.riskband.v1")
|
|
18
|
+
* @param inputs - Circuit inputs as key-value pairs (all values must be strings)
|
|
19
|
+
* @returns The submitted job details
|
|
20
|
+
* @throws {ApiError} If the API request fails
|
|
21
|
+
* @throws {InsufficientCreditsError} If there aren't enough credits
|
|
22
|
+
*/
|
|
23
|
+
submitProveJob(circuitId: string, inputs: ProveJobInputs): Promise<SubmitProveJobResponse>;
|
|
24
|
+
/**
|
|
25
|
+
* Get the status and results of a prove job
|
|
26
|
+
* @param jobId - The unique job identifier
|
|
27
|
+
* @returns The job details including status and outputs
|
|
28
|
+
*/
|
|
29
|
+
getProveJob(jobId: string): Promise<GetProveJobResponse>;
|
|
30
|
+
/**
|
|
31
|
+
* List prove jobs for the authenticated organization
|
|
32
|
+
* @param options - Optional filters for status, limit, and offset
|
|
33
|
+
* @returns Paginated list of prove jobs
|
|
34
|
+
*/
|
|
35
|
+
listProveJobs(options?: ListProveJobsOptions): Promise<ListProveJobsResponse>;
|
|
36
|
+
/**
|
|
37
|
+
* Poll for prove job completion
|
|
38
|
+
* @param jobId - The unique job identifier
|
|
39
|
+
* @param options - Polling options
|
|
40
|
+
* @returns The completed or failed job
|
|
41
|
+
* @throws {TimeoutError} If the job doesn't complete within the timeout
|
|
42
|
+
*/
|
|
43
|
+
waitForProveJob(jobId: string, options?: {
|
|
44
|
+
intervalMs?: number;
|
|
45
|
+
timeoutMs?: number;
|
|
46
|
+
onProgress?: (job: ProveJob) => void;
|
|
47
|
+
}): Promise<ProveJob>;
|
|
48
|
+
/**
|
|
49
|
+
* List all available public policies
|
|
50
|
+
* @returns Array of public policy specifications
|
|
51
|
+
*/
|
|
52
|
+
listPolicies(): Promise<PublicPolicySpec[]>;
|
|
53
|
+
/**
|
|
54
|
+
* Get a specific policy by ID
|
|
55
|
+
* @param policyId - The unique policy identifier
|
|
56
|
+
* @returns The public policy specification, or null if not found
|
|
57
|
+
*/
|
|
58
|
+
getPolicy(policyId: string): Promise<PublicPolicySpec | null>;
|
|
59
|
+
private fetch;
|
|
60
|
+
private sleep;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Custom error classes for the Bind Protocol SDK
|
|
65
|
+
*/
|
|
66
|
+
declare class BindError extends Error {
|
|
67
|
+
readonly code: string;
|
|
68
|
+
readonly details?: Record<string, unknown> | undefined;
|
|
69
|
+
constructor(message: string, code: string, details?: Record<string, unknown> | undefined);
|
|
70
|
+
}
|
|
71
|
+
declare class ApiError extends BindError {
|
|
72
|
+
readonly status: number;
|
|
73
|
+
readonly response?: unknown | undefined;
|
|
74
|
+
constructor(message: string, status: number, response?: unknown | undefined);
|
|
75
|
+
}
|
|
76
|
+
declare class AuthenticationError extends BindError {
|
|
77
|
+
constructor(message?: string);
|
|
78
|
+
}
|
|
79
|
+
declare class TimeoutError extends BindError {
|
|
80
|
+
readonly timeoutMs: number;
|
|
81
|
+
constructor(message: string, timeoutMs: number);
|
|
82
|
+
}
|
|
83
|
+
declare class InsufficientCreditsError extends BindError {
|
|
84
|
+
readonly required: number;
|
|
85
|
+
readonly available: number;
|
|
86
|
+
constructor(required: number, available: number);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export { ApiError, AuthenticationError, BindClient, BindClientOptions, BindError, GetProveJobResponse, InsufficientCreditsError, ListProveJobsOptions, ListProveJobsResponse, ProveJob, ProveJobInputs, SubmitProveJobResponse, TimeoutError };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { PublicPolicySpec } from '@bind-protocol/policy-spec';
|
|
2
|
+
export { DisclosureSpec, OutputClaimSpec, PolicyId, PolicyMetadata, PublicPolicySpec, SubjectSpec, ValiditySpec } from '@bind-protocol/policy-spec';
|
|
3
|
+
import { B as BindClientOptions, a as ProveJobInputs, e as SubmitProveJobResponse, G as GetProveJobResponse, L as ListProveJobsOptions, f as ListProveJobsResponse, c as ProveJob } from '../types-o4sbOK_a.js';
|
|
4
|
+
export { g as BindCredential, b as ProveJobOutputs, P as ProveJobStatus, d as ProveJobSummary, S as SubmitProveJobRequest } from '../types-o4sbOK_a.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* BindClient - Main client for interacting with the Bind Protocol API
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
declare class BindClient {
|
|
11
|
+
private readonly apiKey;
|
|
12
|
+
private readonly baseUrl;
|
|
13
|
+
private readonly headers;
|
|
14
|
+
constructor(options: BindClientOptions);
|
|
15
|
+
/**
|
|
16
|
+
* Submit a prove job for async processing
|
|
17
|
+
* @param circuitId - The circuit identifier (e.g., "bind.mobility.riskband.v1")
|
|
18
|
+
* @param inputs - Circuit inputs as key-value pairs (all values must be strings)
|
|
19
|
+
* @returns The submitted job details
|
|
20
|
+
* @throws {ApiError} If the API request fails
|
|
21
|
+
* @throws {InsufficientCreditsError} If there aren't enough credits
|
|
22
|
+
*/
|
|
23
|
+
submitProveJob(circuitId: string, inputs: ProveJobInputs): Promise<SubmitProveJobResponse>;
|
|
24
|
+
/**
|
|
25
|
+
* Get the status and results of a prove job
|
|
26
|
+
* @param jobId - The unique job identifier
|
|
27
|
+
* @returns The job details including status and outputs
|
|
28
|
+
*/
|
|
29
|
+
getProveJob(jobId: string): Promise<GetProveJobResponse>;
|
|
30
|
+
/**
|
|
31
|
+
* List prove jobs for the authenticated organization
|
|
32
|
+
* @param options - Optional filters for status, limit, and offset
|
|
33
|
+
* @returns Paginated list of prove jobs
|
|
34
|
+
*/
|
|
35
|
+
listProveJobs(options?: ListProveJobsOptions): Promise<ListProveJobsResponse>;
|
|
36
|
+
/**
|
|
37
|
+
* Poll for prove job completion
|
|
38
|
+
* @param jobId - The unique job identifier
|
|
39
|
+
* @param options - Polling options
|
|
40
|
+
* @returns The completed or failed job
|
|
41
|
+
* @throws {TimeoutError} If the job doesn't complete within the timeout
|
|
42
|
+
*/
|
|
43
|
+
waitForProveJob(jobId: string, options?: {
|
|
44
|
+
intervalMs?: number;
|
|
45
|
+
timeoutMs?: number;
|
|
46
|
+
onProgress?: (job: ProveJob) => void;
|
|
47
|
+
}): Promise<ProveJob>;
|
|
48
|
+
/**
|
|
49
|
+
* List all available public policies
|
|
50
|
+
* @returns Array of public policy specifications
|
|
51
|
+
*/
|
|
52
|
+
listPolicies(): Promise<PublicPolicySpec[]>;
|
|
53
|
+
/**
|
|
54
|
+
* Get a specific policy by ID
|
|
55
|
+
* @param policyId - The unique policy identifier
|
|
56
|
+
* @returns The public policy specification, or null if not found
|
|
57
|
+
*/
|
|
58
|
+
getPolicy(policyId: string): Promise<PublicPolicySpec | null>;
|
|
59
|
+
private fetch;
|
|
60
|
+
private sleep;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Custom error classes for the Bind Protocol SDK
|
|
65
|
+
*/
|
|
66
|
+
declare class BindError extends Error {
|
|
67
|
+
readonly code: string;
|
|
68
|
+
readonly details?: Record<string, unknown> | undefined;
|
|
69
|
+
constructor(message: string, code: string, details?: Record<string, unknown> | undefined);
|
|
70
|
+
}
|
|
71
|
+
declare class ApiError extends BindError {
|
|
72
|
+
readonly status: number;
|
|
73
|
+
readonly response?: unknown | undefined;
|
|
74
|
+
constructor(message: string, status: number, response?: unknown | undefined);
|
|
75
|
+
}
|
|
76
|
+
declare class AuthenticationError extends BindError {
|
|
77
|
+
constructor(message?: string);
|
|
78
|
+
}
|
|
79
|
+
declare class TimeoutError extends BindError {
|
|
80
|
+
readonly timeoutMs: number;
|
|
81
|
+
constructor(message: string, timeoutMs: number);
|
|
82
|
+
}
|
|
83
|
+
declare class InsufficientCreditsError extends BindError {
|
|
84
|
+
readonly required: number;
|
|
85
|
+
readonly available: number;
|
|
86
|
+
constructor(required: number, available: number);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export { ApiError, AuthenticationError, BindClient, BindClientOptions, BindError, GetProveJobResponse, InsufficientCreditsError, ListProveJobsOptions, ListProveJobsResponse, ProveJob, ProveJobInputs, SubmitProveJobResponse, TimeoutError };
|