@blindmarket/sdk 0.6.1 → 0.6.2
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/CHANGELOG.md +99 -0
- package/README.md +141 -40
- package/dist/executor/WorkerRuntime.d.ts +80 -18
- package/dist/executor/WorkerRuntime.js +306 -101
- package/dist/index.d.ts +101 -22
- package/dist/index.js +158 -14
- package/dist/tools/helpers.js +33 -11
- package/dist/types.d.ts +96 -9
- package/dist/worker/Worker.d.ts +5 -3
- package/dist/worker/Worker.js +5 -3
- package/package.json +9 -5
package/dist/types.d.ts
CHANGED
|
@@ -81,6 +81,43 @@ export interface OpenTask {
|
|
|
81
81
|
status: number;
|
|
82
82
|
taskHash?: Hex;
|
|
83
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Body of `POST /api/v1/tasks` — mirrors `createTaskSchema` in
|
|
86
|
+
* `backend/src/routes/tasks.ts`. The poster is the authenticated caller; the
|
|
87
|
+
* deadline is derived on-chain from `duration`.
|
|
88
|
+
*/
|
|
89
|
+
export interface CreateTaskRequest {
|
|
90
|
+
/** bytes32 commitment to the brief (0x + 64 hex) — sha256 of the ciphertext. */
|
|
91
|
+
taskHash: Hex;
|
|
92
|
+
/** Payment token address (USDC on Base; the zero address = native on 0G). */
|
|
93
|
+
token: Address;
|
|
94
|
+
/** Reward, as an integer string in the payment token's smallest unit. */
|
|
95
|
+
amount: string;
|
|
96
|
+
locationZone: string;
|
|
97
|
+
/** Task duration in SECONDS, as a string. */
|
|
98
|
+
duration: string;
|
|
99
|
+
targetExecutorType?: 'human' | 'agent';
|
|
100
|
+
/**
|
|
101
|
+
* 'oracle' is deliberately absent: it is reserved/unwired and the index route
|
|
102
|
+
* rejects it (400 VERIFICATION_MODE_UNSUPPORTED).
|
|
103
|
+
*/
|
|
104
|
+
verificationMode?: 'manual' | 'auto' | 'agent';
|
|
105
|
+
/** Designated verifier — only with verificationMode 'agent'. */
|
|
106
|
+
verifierAddress?: Address;
|
|
107
|
+
/**
|
|
108
|
+
* REQUIRED in practice for 'auto': `POST /a2a/tasks/index` rejects an 'auto'
|
|
109
|
+
* task without at least one real check (400 AUTO_CRITERIA_REQUIRED) —
|
|
110
|
+
* min_length, contains_keywords, required_fields, expected_schema,
|
|
111
|
+
* regex_pattern, rubric, forbidden_phrases or expected_answer. Send the same
|
|
112
|
+
* criteria to both calls.
|
|
113
|
+
*/
|
|
114
|
+
verificationCriteria?: Record<string, unknown>;
|
|
115
|
+
requiredCapabilities?: AgentCapability[];
|
|
116
|
+
/** 0G Storage root hash of the (encrypted) brief. */
|
|
117
|
+
rootHash?: string;
|
|
118
|
+
/** Lowercased executor address → hex ECIES blob (no 0x) of the brief AES key. */
|
|
119
|
+
wrappedKeys?: Record<string, string>;
|
|
120
|
+
}
|
|
84
121
|
export interface CreateTaskTx {
|
|
85
122
|
unsignedTx: {
|
|
86
123
|
to: Address;
|
|
@@ -92,9 +129,13 @@ export interface TaskDetail extends OpenTask {
|
|
|
92
129
|
metadata?: Record<string, unknown>;
|
|
93
130
|
a2aState?: A2ATaskState;
|
|
94
131
|
}
|
|
132
|
+
/** Mirrors `A2ATaskStateStatus` in `backend/src/types.ts`. */
|
|
133
|
+
export type A2ATaskStatus = 'open' | 'accepted' | 'in_progress' | 'submitted' | 'awaiting_verification' | 'verified' | 'completed' | 'failed';
|
|
95
134
|
export interface A2ATaskState {
|
|
96
135
|
taskId: string;
|
|
97
|
-
|
|
136
|
+
/** One of A2ATaskStatus; left open so a newer backend doesn't break parsing. */
|
|
137
|
+
status: A2ATaskStatus | (string & {});
|
|
138
|
+
failedReason?: string;
|
|
98
139
|
executorAddress?: string;
|
|
99
140
|
acceptedAt?: string;
|
|
100
141
|
submittedAt?: string;
|
|
@@ -115,6 +156,31 @@ export interface A2ATaskState {
|
|
|
115
156
|
verifyTxHash?: Hex;
|
|
116
157
|
wrappedKeys?: Record<string, string>;
|
|
117
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Public task metadata as served by the unauthenticated browse surface
|
|
161
|
+
* (`projectPublicMeta` in the backend): key material is stripped, and
|
|
162
|
+
* `rootHash` appears only on public tasks.
|
|
163
|
+
*/
|
|
164
|
+
export interface A2APublicTaskMeta {
|
|
165
|
+
taskId: string;
|
|
166
|
+
targetExecutorType?: 'human' | 'agent';
|
|
167
|
+
verificationMode?: string;
|
|
168
|
+
requiredCapabilities?: AgentCapability[];
|
|
169
|
+
posterAddress?: string;
|
|
170
|
+
/** Which escrow holds the task. Absent on rows indexed before the field existed. */
|
|
171
|
+
chain?: 'base' | '0g';
|
|
172
|
+
/** Unix seconds. */
|
|
173
|
+
deadline?: number;
|
|
174
|
+
privacy?: 'public';
|
|
175
|
+
hasEncryptedBrief?: boolean;
|
|
176
|
+
rootHash?: string;
|
|
177
|
+
[key: string]: unknown;
|
|
178
|
+
}
|
|
179
|
+
/** One entry of `GET /api/v1/a2a/tasks` (and /tasks/posted, /executions). */
|
|
180
|
+
export interface A2ATaskEntry {
|
|
181
|
+
meta: A2APublicTaskMeta;
|
|
182
|
+
state: A2ATaskState;
|
|
183
|
+
}
|
|
118
184
|
export interface ExecutorProfile {
|
|
119
185
|
address: Address;
|
|
120
186
|
displayName: string;
|
|
@@ -129,8 +195,9 @@ export interface ExecutorProfile {
|
|
|
129
195
|
minReward?: string;
|
|
130
196
|
preferredCapabilities?: AgentCapability[];
|
|
131
197
|
/** Settlement chains the executor declared at registration. `null` means it
|
|
132
|
-
* never declared any
|
|
133
|
-
* backends that predate the
|
|
198
|
+
* never declared any. Informational: the backend stores it but does not
|
|
199
|
+
* filter offers or /accept by it. Absent from backends that predate the
|
|
200
|
+
* field. */
|
|
134
201
|
supportedChains?: string[] | null;
|
|
135
202
|
registeredAt: string;
|
|
136
203
|
decayedScore?: number;
|
|
@@ -138,29 +205,46 @@ export interface ExecutorProfile {
|
|
|
138
205
|
avgRating?: number;
|
|
139
206
|
}
|
|
140
207
|
export interface RegisterExecutorInput {
|
|
141
|
-
|
|
208
|
+
/**
|
|
209
|
+
* Ignored by the backend: the registered executor is ALWAYS the wallet that
|
|
210
|
+
* owns the API key. Kept optional for source compatibility.
|
|
211
|
+
*/
|
|
212
|
+
address?: Address;
|
|
142
213
|
displayName: string;
|
|
143
214
|
capabilities: AgentCapability[];
|
|
215
|
+
/** Uncompressed secp256k1 public key: 130 hex chars, leading `04`, NO 0x prefix. */
|
|
144
216
|
publicKey: string;
|
|
145
217
|
agentCardUrl?: string;
|
|
146
218
|
mcpEndpointUrl?: string;
|
|
147
219
|
minReward?: string;
|
|
148
220
|
preferredCapabilities?: AgentCapability[];
|
|
149
221
|
/** Settlement chains ('0g', 'base', …) this executor can sign
|
|
150
|
-
* `submitEvidence` on.
|
|
151
|
-
*
|
|
152
|
-
*
|
|
222
|
+
* `submitEvidence` on. A DECLARATION ONLY: the backend stores it on the
|
|
223
|
+
* executor record and does not filter offers or /accept by it, so the
|
|
224
|
+
* caller must check a task's chain (`entry.meta.chain`) before accepting —
|
|
225
|
+
* WorkerRuntime does. Backends that predate the field drop it. */
|
|
153
226
|
supportedChains?: string[];
|
|
154
227
|
}
|
|
155
|
-
/** Params for BlindMarket.createAgent() —
|
|
228
|
+
/** Params for BlindMarket.createAgent() — derives the pubkey from your key + registers the executor in one call. */
|
|
156
229
|
export interface CreateAgentParams {
|
|
230
|
+
/**
|
|
231
|
+
* Private key of the wallet that OWNS the API key. The backend registers the
|
|
232
|
+
* API key's owner as the executor (never an address from the request), wraps
|
|
233
|
+
* briefs to the public key registered here, and builds `submitEvidence` for
|
|
234
|
+
* the owner address — so this must be that wallet's key. Never sent to the
|
|
235
|
+
* backend; only its public half is. Defaults to
|
|
236
|
+
* `BlindMarketConfig.executor.privateKey`. With neither, a random wallet is
|
|
237
|
+
* generated (it can decrypt briefs but cannot sign `submitEvidence` for the
|
|
238
|
+
* owner's address).
|
|
239
|
+
*/
|
|
240
|
+
privateKey?: string;
|
|
157
241
|
/** Display name for the agent in the marketplace. */
|
|
158
242
|
displayName: string;
|
|
159
243
|
/** Capabilities this agent offers. Use AgentCap.DATA_PROCESSING etc. */
|
|
160
244
|
capabilities: AgentCapability[];
|
|
161
245
|
/** Which of the above the agent prefers (subset of capabilities). */
|
|
162
246
|
preferredCapabilities?: AgentCapability[];
|
|
163
|
-
/** Minimum reward per task (
|
|
247
|
+
/** Minimum reward per task, as an integer string in the payment token's smallest unit (USDC: 6 decimals). */
|
|
164
248
|
minReward?: string;
|
|
165
249
|
/** Agent card URL for marketplace display. */
|
|
166
250
|
agentCardUrl?: string;
|
|
@@ -172,9 +256,12 @@ export interface CreateAgentParams {
|
|
|
172
256
|
}
|
|
173
257
|
/** Result of BlindMarket.createAgent(). */
|
|
174
258
|
export interface CreateAgentResult {
|
|
259
|
+
/** The registered executor — `executor.address` is the API key's owner wallet. */
|
|
175
260
|
executor: ExecutorProfile;
|
|
261
|
+
/** The wallet of the `privateKey` you passed in, or the generated one. */
|
|
176
262
|
wallet: {
|
|
177
263
|
address: Address;
|
|
264
|
+
/** Uncompressed secp256k1 public key, 0x-prefixed (`0x04…`); registered without the 0x. */
|
|
178
265
|
publicKey: string;
|
|
179
266
|
privateKey: string;
|
|
180
267
|
};
|
package/dist/worker/Worker.d.ts
CHANGED
|
@@ -45,9 +45,11 @@ export declare class Worker {
|
|
|
45
45
|
decryptInstructions(input: DecryptInstructionsInput): Promise<Uint8Array>;
|
|
46
46
|
submitEvidence(input: SubmitEvidenceInput): Promise<SubmitEvidenceResult>;
|
|
47
47
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
48
|
+
* Reclaim escrow after the deadline if completeVerification was never called.
|
|
49
|
+
* BlindEscrow.claimTimeout is `onlyAgent`: only the POSTER can call it, and it
|
|
50
|
+
* refunds the poster the full escrowed amount — the worker is paid nothing on
|
|
51
|
+
* a timeout (the 90% worker / 10% platform split applies only to a passed
|
|
52
|
+
* verification). Called from a worker wallet this reverts.
|
|
51
53
|
*/
|
|
52
54
|
claimTimeout(taskId: TaskId): Promise<TxReceiptLike>;
|
|
53
55
|
}
|
package/dist/worker/Worker.js
CHANGED
|
@@ -41,9 +41,11 @@ export class Worker {
|
|
|
41
41
|
return { rootHash, txHash: receipt.hash, receipt };
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
44
|
+
* Reclaim escrow after the deadline if completeVerification was never called.
|
|
45
|
+
* BlindEscrow.claimTimeout is `onlyAgent`: only the POSTER can call it, and it
|
|
46
|
+
* refunds the poster the full escrowed amount — the worker is paid nothing on
|
|
47
|
+
* a timeout (the 90% worker / 10% platform split applies only to a passed
|
|
48
|
+
* verification). Called from a worker wallet this reverts.
|
|
47
49
|
*/
|
|
48
50
|
async claimTimeout(taskId) {
|
|
49
51
|
const receipt = await this.deps.escrow.claimTimeout(taskId);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blindmarket/sdk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "BlindMarket SDK — deploy agents, assign workers, verify evidence",
|
|
5
5
|
"author": "BlindMarket Team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
],
|
|
33
33
|
"type": "module",
|
|
34
34
|
"files": [
|
|
35
|
-
"dist"
|
|
35
|
+
"dist",
|
|
36
|
+
"CHANGELOG.md"
|
|
36
37
|
],
|
|
37
38
|
"main": "./dist/index.js",
|
|
38
39
|
"types": "./dist/index.d.ts",
|
|
@@ -52,13 +53,16 @@
|
|
|
52
53
|
},
|
|
53
54
|
"scripts": {
|
|
54
55
|
"build": "tsc",
|
|
55
|
-
"dev": "tsc --watch"
|
|
56
|
+
"dev": "tsc --watch",
|
|
57
|
+
"test": "vitest run"
|
|
56
58
|
},
|
|
57
59
|
"dependencies": {
|
|
58
|
-
"ethers": "6.
|
|
60
|
+
"ethers": "6.17.0"
|
|
59
61
|
},
|
|
60
62
|
"devDependencies": {
|
|
61
63
|
"@types/node": "^22.15.3",
|
|
62
|
-
"
|
|
64
|
+
"fast-check": "^4.10.1",
|
|
65
|
+
"typescript": "^5.7.3",
|
|
66
|
+
"vitest": "^4.1.11"
|
|
63
67
|
}
|
|
64
68
|
}
|