@blindmarket/sdk 0.1.4 → 0.1.6
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/dist/index.d.ts +1 -47
- package/dist/index.js +1 -79
- package/package.json +2 -2
- package/src/index.ts +8 -104
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
2
|
export interface BlindMarketConfig {
|
|
3
3
|
apiBase?: string;
|
|
4
4
|
apiKey: string;
|
|
@@ -15,14 +15,6 @@ export interface DeployAgentParams {
|
|
|
15
15
|
capabilities?: string[];
|
|
16
16
|
tools?: object[];
|
|
17
17
|
}
|
|
18
|
-
export interface PostTaskParams {
|
|
19
|
-
instructions: string;
|
|
20
|
-
category: string;
|
|
21
|
-
amount: string;
|
|
22
|
-
token: string;
|
|
23
|
-
locationZone?: string;
|
|
24
|
-
duration?: string;
|
|
25
|
-
}
|
|
26
18
|
export interface DeployedAgent {
|
|
27
19
|
id: string;
|
|
28
20
|
name: string;
|
|
@@ -31,11 +23,6 @@ export interface DeployedAgent {
|
|
|
31
23
|
inftTokenId?: number;
|
|
32
24
|
status: string;
|
|
33
25
|
}
|
|
34
|
-
export interface PostedTask {
|
|
35
|
-
unsignedTx: object;
|
|
36
|
-
taskHash: string;
|
|
37
|
-
storageRoot: string;
|
|
38
|
-
}
|
|
39
26
|
export declare class BlindMarket {
|
|
40
27
|
private apiBase;
|
|
41
28
|
private apiKey;
|
|
@@ -60,20 +47,6 @@ export declare class BlindMarket {
|
|
|
60
47
|
* List all agents owned by an address.
|
|
61
48
|
*/
|
|
62
49
|
listAgents(ownerAddress: string): Promise<DeployedAgent[]>;
|
|
63
|
-
/**
|
|
64
|
-
* Encrypt instructions and post a task. Returns an unsigned tx to sign + broadcast.
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* const { unsignedTx, taskHash } = await bb.postTask({
|
|
68
|
-
* instructions: 'Photograph the exterior of 42 Oak Street, NYC.',
|
|
69
|
-
* category: 'photography',
|
|
70
|
-
* amount: ethers.parseEther('30').toString(),
|
|
71
|
-
* token: '0x317227efcA18D004E12CA8046AEf7E1597458F25',
|
|
72
|
-
* locationZone: 'US-NY',
|
|
73
|
-
* });
|
|
74
|
-
* const receipt = await wallet.sendTransaction(unsignedTx);
|
|
75
|
-
*/
|
|
76
|
-
postTask(params: PostTaskParams): Promise<PostedTask>;
|
|
77
50
|
/**
|
|
78
51
|
* Assign a worker to a task. Returns an unsigned tx.
|
|
79
52
|
*/
|
|
@@ -93,15 +66,6 @@ export declare class BlindMarket {
|
|
|
93
66
|
confidence: number;
|
|
94
67
|
reasoning: string;
|
|
95
68
|
}>;
|
|
96
|
-
/**
|
|
97
|
-
* Submit evidence for an assigned task.
|
|
98
|
-
*/
|
|
99
|
-
submitEvidence(params: {
|
|
100
|
-
taskId: number;
|
|
101
|
-
evidence: string;
|
|
102
|
-
}): Promise<{
|
|
103
|
-
unsignedTx: object;
|
|
104
|
-
}>;
|
|
105
69
|
/**
|
|
106
70
|
* Get task status.
|
|
107
71
|
*/
|
|
@@ -115,15 +79,5 @@ export declare class BlindMarket {
|
|
|
115
79
|
* List open tasks.
|
|
116
80
|
*/
|
|
117
81
|
listTasks(limit?: number): Promise<object[]>;
|
|
118
|
-
/**
|
|
119
|
-
* Authenticate with a wallet and return a JWT.
|
|
120
|
-
* Use this to get the apiKey for the constructor.
|
|
121
|
-
*
|
|
122
|
-
* @example
|
|
123
|
-
* const wallet = new ethers.Wallet(privateKey);
|
|
124
|
-
* const apiKey = await BlindMarket.authenticate(wallet, 'http://localhost:3001');
|
|
125
|
-
* const bb = new BlindMarket({ apiKey });
|
|
126
|
-
*/
|
|
127
|
-
static authenticate(wallet: Wallet, apiBase?: string): Promise<string>;
|
|
128
82
|
}
|
|
129
83
|
export { ethers };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { ethers } from 'ethers';
|
|
2
|
-
import { createCipheriv, randomBytes, createHash } from 'crypto';
|
|
3
2
|
export class BlindMarket {
|
|
4
3
|
apiBase;
|
|
5
4
|
apiKey;
|
|
6
5
|
constructor(config) {
|
|
7
|
-
this.apiBase = config.apiBase ?? '
|
|
6
|
+
this.apiBase = config.apiBase ?? 'https://api.blindmarket.xyz';
|
|
8
7
|
this.apiKey = config.apiKey;
|
|
9
8
|
}
|
|
10
9
|
async req(method, path, body) {
|
|
@@ -43,42 +42,6 @@ export class BlindMarket {
|
|
|
43
42
|
return this.req('GET', `/api/v1/agents?owner=${ownerAddress}`);
|
|
44
43
|
}
|
|
45
44
|
// ── Task lifecycle ────────────────────────────────────────────────────────
|
|
46
|
-
/**
|
|
47
|
-
* Encrypt instructions and post a task. Returns an unsigned tx to sign + broadcast.
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* const { unsignedTx, taskHash } = await bb.postTask({
|
|
51
|
-
* instructions: 'Photograph the exterior of 42 Oak Street, NYC.',
|
|
52
|
-
* category: 'photography',
|
|
53
|
-
* amount: ethers.parseEther('30').toString(),
|
|
54
|
-
* token: '0x317227efcA18D004E12CA8046AEf7E1597458F25',
|
|
55
|
-
* locationZone: 'US-NY',
|
|
56
|
-
* });
|
|
57
|
-
* const receipt = await wallet.sendTransaction(unsignedTx);
|
|
58
|
-
*/
|
|
59
|
-
async postTask(params) {
|
|
60
|
-
// Encrypt instructions
|
|
61
|
-
const key = randomBytes(32);
|
|
62
|
-
const iv = randomBytes(12);
|
|
63
|
-
const cipher = createCipheriv('aes-256-gcm', key, iv);
|
|
64
|
-
const encrypted = Buffer.concat([cipher.update(params.instructions, 'utf8'), cipher.final()]);
|
|
65
|
-
const tag = cipher.getAuthTag();
|
|
66
|
-
const blob = Buffer.concat([iv, tag, encrypted]).toString('base64');
|
|
67
|
-
// Upload to storage
|
|
68
|
-
const { rootHash } = await this.req('POST', '/api/v1/storage/upload', { data: blob });
|
|
69
|
-
// taskHash = SHA-256 of ciphertext
|
|
70
|
-
const taskHash = '0x' + createHash('sha256').update(Buffer.concat([iv, tag, encrypted])).digest('hex');
|
|
71
|
-
// Build unsigned tx
|
|
72
|
-
const { unsignedTx } = await this.req('POST', '/api/v1/tasks', {
|
|
73
|
-
taskHash,
|
|
74
|
-
token: params.token,
|
|
75
|
-
amount: params.amount,
|
|
76
|
-
category: params.category,
|
|
77
|
-
locationZone: params.locationZone ?? 'global',
|
|
78
|
-
duration: params.duration ?? '86400',
|
|
79
|
-
});
|
|
80
|
-
return { unsignedTx, taskHash, storageRoot: rootHash };
|
|
81
|
-
}
|
|
82
45
|
/**
|
|
83
46
|
* Assign a worker to a task. Returns an unsigned tx.
|
|
84
47
|
*/
|
|
@@ -96,20 +59,6 @@ export class BlindMarket {
|
|
|
96
59
|
evidenceSummary: params.evidenceSummary,
|
|
97
60
|
});
|
|
98
61
|
}
|
|
99
|
-
/**
|
|
100
|
-
* Submit evidence for an assigned task.
|
|
101
|
-
*/
|
|
102
|
-
async submitEvidence(params) {
|
|
103
|
-
const key = randomBytes(32);
|
|
104
|
-
const iv = randomBytes(12);
|
|
105
|
-
const cipher = createCipheriv('aes-256-gcm', key, iv);
|
|
106
|
-
const encrypted = Buffer.concat([cipher.update(params.evidence, 'utf8'), cipher.final()]);
|
|
107
|
-
const tag = cipher.getAuthTag();
|
|
108
|
-
const blob = Buffer.concat([iv, tag, encrypted]).toString('base64');
|
|
109
|
-
await this.req('POST', '/api/v1/storage/upload', { data: blob });
|
|
110
|
-
const evidenceHash = '0x' + createHash('sha256').update(Buffer.concat([iv, tag, encrypted])).digest('hex');
|
|
111
|
-
return this.req('POST', '/api/v1/submissions/submit', { taskId: params.taskId, evidenceHash });
|
|
112
|
-
}
|
|
113
62
|
/**
|
|
114
63
|
* Get task status.
|
|
115
64
|
*/
|
|
@@ -123,32 +72,5 @@ export class BlindMarket {
|
|
|
123
72
|
const { tasks } = await this.req('GET', `/api/v1/tasks?limit=${limit}`);
|
|
124
73
|
return tasks;
|
|
125
74
|
}
|
|
126
|
-
// ── Auth helper ───────────────────────────────────────────────────────────
|
|
127
|
-
/**
|
|
128
|
-
* Authenticate with a wallet and return a JWT.
|
|
129
|
-
* Use this to get the apiKey for the constructor.
|
|
130
|
-
*
|
|
131
|
-
* @example
|
|
132
|
-
* const wallet = new ethers.Wallet(privateKey);
|
|
133
|
-
* const apiKey = await BlindMarket.authenticate(wallet, 'http://localhost:3001');
|
|
134
|
-
* const bb = new BlindMarket({ apiKey });
|
|
135
|
-
*/
|
|
136
|
-
static async authenticate(wallet, apiBase = 'http://localhost:3001') {
|
|
137
|
-
const nonceRes = await fetch(`${apiBase}/api/v1/auth/nonce`, {
|
|
138
|
-
method: 'POST',
|
|
139
|
-
headers: { 'Content-Type': 'application/json' },
|
|
140
|
-
body: JSON.stringify({ address: wallet.address }),
|
|
141
|
-
});
|
|
142
|
-
const { data: { nonce } } = await nonceRes.json();
|
|
143
|
-
const message = `Sign this message to authenticate with BlindMarket.\n\nNonce: ${nonce}`;
|
|
144
|
-
const signature = await wallet.signMessage(message);
|
|
145
|
-
const verifyRes = await fetch(`${apiBase}/api/v1/auth/verify`, {
|
|
146
|
-
method: 'POST',
|
|
147
|
-
headers: { 'Content-Type': 'application/json' },
|
|
148
|
-
body: JSON.stringify({ address: wallet.address, signature }),
|
|
149
|
-
});
|
|
150
|
-
const { data: { token } } = await verifyRes.json();
|
|
151
|
-
return token;
|
|
152
|
-
}
|
|
153
75
|
}
|
|
154
76
|
export { ethers };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blindmarket/sdk",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "BlindMarket SDK — deploy agents,
|
|
3
|
+
"version": "0.1.6",
|
|
4
|
+
"description": "BlindMarket SDK — deploy agents, assign workers, verify evidence",
|
|
5
5
|
"author": "BlindMarket Team",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/JemIIahh/BlindMarket#readme",
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createCipheriv, randomBytes, createHash } from 'crypto';
|
|
1
|
+
import { ethers } from 'ethers';
|
|
3
2
|
|
|
4
3
|
export interface BlindMarketConfig {
|
|
5
4
|
apiBase?: string;
|
|
@@ -19,15 +18,6 @@ export interface DeployAgentParams {
|
|
|
19
18
|
tools?: object[];
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
export interface PostTaskParams {
|
|
23
|
-
instructions: string;
|
|
24
|
-
category: string;
|
|
25
|
-
amount: string; // wei as string
|
|
26
|
-
token: string; // ERC-20 address
|
|
27
|
-
locationZone?: string;
|
|
28
|
-
duration?: string; // seconds
|
|
29
|
-
}
|
|
30
|
-
|
|
31
21
|
export interface DeployedAgent {
|
|
32
22
|
id: string;
|
|
33
23
|
name: string;
|
|
@@ -37,18 +27,12 @@ export interface DeployedAgent {
|
|
|
37
27
|
status: string;
|
|
38
28
|
}
|
|
39
29
|
|
|
40
|
-
export interface PostedTask {
|
|
41
|
-
unsignedTx: object;
|
|
42
|
-
taskHash: string;
|
|
43
|
-
storageRoot: string;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
30
|
export class BlindMarket {
|
|
47
31
|
private apiBase: string;
|
|
48
32
|
private apiKey: string;
|
|
49
33
|
|
|
50
34
|
constructor(config: BlindMarketConfig) {
|
|
51
|
-
this.apiBase = config.apiBase ?? '
|
|
35
|
+
this.apiBase = config.apiBase ?? 'https://api.blindmarket.xyz';
|
|
52
36
|
this.apiKey = config.apiKey;
|
|
53
37
|
}
|
|
54
38
|
|
|
@@ -92,47 +76,6 @@ export class BlindMarket {
|
|
|
92
76
|
|
|
93
77
|
// ── Task lifecycle ────────────────────────────────────────────────────────
|
|
94
78
|
|
|
95
|
-
/**
|
|
96
|
-
* Encrypt instructions and post a task. Returns an unsigned tx to sign + broadcast.
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* const { unsignedTx, taskHash } = await bb.postTask({
|
|
100
|
-
* instructions: 'Photograph the exterior of 42 Oak Street, NYC.',
|
|
101
|
-
* category: 'photography',
|
|
102
|
-
* amount: ethers.parseEther('30').toString(),
|
|
103
|
-
* token: '0x317227efcA18D004E12CA8046AEf7E1597458F25',
|
|
104
|
-
* locationZone: 'US-NY',
|
|
105
|
-
* });
|
|
106
|
-
* const receipt = await wallet.sendTransaction(unsignedTx);
|
|
107
|
-
*/
|
|
108
|
-
async postTask(params: PostTaskParams): Promise<PostedTask> {
|
|
109
|
-
// Encrypt instructions
|
|
110
|
-
const key = randomBytes(32);
|
|
111
|
-
const iv = randomBytes(12);
|
|
112
|
-
const cipher = createCipheriv('aes-256-gcm', key, iv);
|
|
113
|
-
const encrypted = Buffer.concat([cipher.update(params.instructions, 'utf8'), cipher.final()]);
|
|
114
|
-
const tag = (cipher as any).getAuthTag() as Buffer;
|
|
115
|
-
const blob = Buffer.concat([iv, tag, encrypted]).toString('base64');
|
|
116
|
-
|
|
117
|
-
// Upload to storage
|
|
118
|
-
const { rootHash } = await this.req<{ rootHash: string }>('POST', '/api/v1/storage/upload', { data: blob });
|
|
119
|
-
|
|
120
|
-
// taskHash = SHA-256 of ciphertext
|
|
121
|
-
const taskHash = '0x' + createHash('sha256').update(Buffer.concat([iv, tag, encrypted])).digest('hex');
|
|
122
|
-
|
|
123
|
-
// Build unsigned tx
|
|
124
|
-
const { unsignedTx } = await this.req<{ unsignedTx: object }>('POST', '/api/v1/tasks', {
|
|
125
|
-
taskHash,
|
|
126
|
-
token: params.token,
|
|
127
|
-
amount: params.amount,
|
|
128
|
-
category: params.category,
|
|
129
|
-
locationZone: params.locationZone ?? 'global',
|
|
130
|
-
duration: params.duration ?? '86400',
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
return { unsignedTx, taskHash, storageRoot: rootHash };
|
|
134
|
-
}
|
|
135
|
-
|
|
136
79
|
/**
|
|
137
80
|
* Assign a worker to a task. Returns an unsigned tx.
|
|
138
81
|
*/
|
|
@@ -157,23 +100,6 @@ export class BlindMarket {
|
|
|
157
100
|
});
|
|
158
101
|
}
|
|
159
102
|
|
|
160
|
-
/**
|
|
161
|
-
* Submit evidence for an assigned task.
|
|
162
|
-
*/
|
|
163
|
-
async submitEvidence(params: { taskId: number; evidence: string }): Promise<{ unsignedTx: object }> {
|
|
164
|
-
const key = randomBytes(32);
|
|
165
|
-
const iv = randomBytes(12);
|
|
166
|
-
const cipher = createCipheriv('aes-256-gcm', key, iv);
|
|
167
|
-
const encrypted = Buffer.concat([cipher.update(params.evidence, 'utf8'), cipher.final()]);
|
|
168
|
-
const tag = (cipher as any).getAuthTag() as Buffer;
|
|
169
|
-
const blob = Buffer.concat([iv, tag, encrypted]).toString('base64');
|
|
170
|
-
|
|
171
|
-
await this.req('POST', '/api/v1/storage/upload', { data: blob });
|
|
172
|
-
const evidenceHash = '0x' + createHash('sha256').update(Buffer.concat([iv, tag, encrypted])).digest('hex');
|
|
173
|
-
|
|
174
|
-
return this.req('POST', '/api/v1/submissions/submit', { taskId: params.taskId, evidenceHash });
|
|
175
|
-
}
|
|
176
|
-
|
|
177
103
|
/**
|
|
178
104
|
* Get task status.
|
|
179
105
|
*/
|
|
@@ -189,34 +115,12 @@ export class BlindMarket {
|
|
|
189
115
|
return tasks;
|
|
190
116
|
}
|
|
191
117
|
|
|
192
|
-
//
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
* @example
|
|
199
|
-
* const wallet = new ethers.Wallet(privateKey);
|
|
200
|
-
* const apiKey = await BlindMarket.authenticate(wallet, 'http://localhost:3001');
|
|
201
|
-
* const bb = new BlindMarket({ apiKey });
|
|
202
|
-
*/
|
|
203
|
-
static async authenticate(wallet: Wallet, apiBase = 'http://localhost:3001'): Promise<string> {
|
|
204
|
-
const nonceRes = await fetch(`${apiBase}/api/v1/auth/nonce`, {
|
|
205
|
-
method: 'POST',
|
|
206
|
-
headers: { 'Content-Type': 'application/json' },
|
|
207
|
-
body: JSON.stringify({ address: wallet.address }),
|
|
208
|
-
});
|
|
209
|
-
const { data: { nonce } } = await nonceRes.json() as { data: { nonce: string } };
|
|
210
|
-
const message = `Sign this message to authenticate with BlindMarket.\n\nNonce: ${nonce}`;
|
|
211
|
-
const signature = await wallet.signMessage(message);
|
|
212
|
-
const verifyRes = await fetch(`${apiBase}/api/v1/auth/verify`, {
|
|
213
|
-
method: 'POST',
|
|
214
|
-
headers: { 'Content-Type': 'application/json' },
|
|
215
|
-
body: JSON.stringify({ address: wallet.address, signature }),
|
|
216
|
-
});
|
|
217
|
-
const { data: { token } } = await verifyRes.json() as { data: { token: string } };
|
|
218
|
-
return token;
|
|
219
|
-
}
|
|
118
|
+
// Auth: there's no SDK-side authenticate() anymore. Browser users
|
|
119
|
+
// sign in via Privy; agents obtain an API key one of two ways:
|
|
120
|
+
// 1. Ask the operator for the shared AGENT_API_KEY (set on the backend)
|
|
121
|
+
// 2. Run `blind register --name <agent>` from @blindmarket/cli to mint
|
|
122
|
+
// a per-agent token via the device-flow registration endpoint
|
|
123
|
+
// Pass the resulting key to `new BlindMarket({ apiKey })`.
|
|
220
124
|
}
|
|
221
125
|
|
|
222
126
|
export { ethers };
|