@moltos/sdk 0.10.14 → 0.12.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 +92 -45
- package/dist/chunk-TIRAZTCQ.mjs +148 -0
- package/dist/crypto.d.mts +128 -0
- package/dist/crypto.d.ts +128 -0
- package/dist/crypto.js +181 -0
- package/dist/crypto.mjs +26 -0
- package/dist/{sdk.d.ts → index.d.mts} +279 -5
- package/dist/index.d.ts +559 -5
- package/dist/index.js +758 -22
- package/dist/index.mjs +597 -0
- package/package.json +40 -15
- package/dist/cli.d.ts +0 -18
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -857
- package/dist/cli.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/react.d.ts +0 -138
- package/dist/react.d.ts.map +0 -1
- package/dist/react.js +0 -335
- package/dist/react.js.map +0 -1
- package/dist/sdk.d.ts.map +0 -1
- package/dist/sdk.js +0 -412
- package/dist/sdk.js.map +0 -1
- package/dist/types.d.ts +0 -118
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -5
- package/dist/types.js.map +0 -1
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,597 @@
|
|
|
1
|
+
import {
|
|
2
|
+
aggregateSignatures,
|
|
3
|
+
batchVerifyAttestations,
|
|
4
|
+
deriveKeypair,
|
|
5
|
+
generateKeypair,
|
|
6
|
+
hashPayload,
|
|
7
|
+
isStubMode,
|
|
8
|
+
setStubMode,
|
|
9
|
+
signAttestation,
|
|
10
|
+
verifyAggregate,
|
|
11
|
+
verifyAttestation
|
|
12
|
+
} from "./chunk-TIRAZTCQ.mjs";
|
|
13
|
+
|
|
14
|
+
// src/index-legacy.ts
|
|
15
|
+
import { createHash, randomBytes } from "crypto";
|
|
16
|
+
var DEFAULT_CONFIG = {
|
|
17
|
+
baseUrl: "https://moltos.org/api",
|
|
18
|
+
timeout: 3e4
|
|
19
|
+
};
|
|
20
|
+
var TAPClient = class {
|
|
21
|
+
constructor(config) {
|
|
22
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
23
|
+
if (!this.config.apiKey) {
|
|
24
|
+
throw new Error("TAPClient: apiKey is required");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// --------------------------------------------------------------------------
|
|
28
|
+
// Attestations
|
|
29
|
+
// --------------------------------------------------------------------------
|
|
30
|
+
/**
|
|
31
|
+
* Submit an attestation for another agent
|
|
32
|
+
*
|
|
33
|
+
* @param request Attestation details
|
|
34
|
+
* @returns Attestation response
|
|
35
|
+
*/
|
|
36
|
+
async attest(request) {
|
|
37
|
+
const payload = {
|
|
38
|
+
target_agents: [request.targetId],
|
|
39
|
+
scores: [request.score],
|
|
40
|
+
reason: request.reason || "Attestation",
|
|
41
|
+
metadata: request.metadata,
|
|
42
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
43
|
+
nonce: this.generateNonce()
|
|
44
|
+
};
|
|
45
|
+
return this.post("/agent/attest", payload);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Batch attest to multiple agents at once
|
|
49
|
+
*/
|
|
50
|
+
async attestBatch(attestations) {
|
|
51
|
+
const payload = {
|
|
52
|
+
target_agents: attestations.map((a) => a.targetId),
|
|
53
|
+
scores: attestations.map((a) => a.score),
|
|
54
|
+
reasons: attestations.map((a) => a.reason || "Batch attestation"),
|
|
55
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
56
|
+
nonce: this.generateNonce()
|
|
57
|
+
};
|
|
58
|
+
return this.post("/agent/attest", payload);
|
|
59
|
+
}
|
|
60
|
+
// --------------------------------------------------------------------------
|
|
61
|
+
// Scores & Leaderboard
|
|
62
|
+
// --------------------------------------------------------------------------
|
|
63
|
+
/**
|
|
64
|
+
* Get TAP score for an agent
|
|
65
|
+
*/
|
|
66
|
+
async getScore(agentId) {
|
|
67
|
+
const id = agentId || this.config.agentId;
|
|
68
|
+
if (!id) {
|
|
69
|
+
throw new Error("TAPClient: agentId required");
|
|
70
|
+
}
|
|
71
|
+
return this.get(`/eigentrust?agent_id=${id}`);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get leaderboard (top agents by TAP score)
|
|
75
|
+
*/
|
|
76
|
+
async getLeaderboard(limit = 100) {
|
|
77
|
+
return this.get(`/leaderboard?limit=${limit}`);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get network-wide statistics
|
|
81
|
+
*/
|
|
82
|
+
async getNetworkStats() {
|
|
83
|
+
return this.get("/stats");
|
|
84
|
+
}
|
|
85
|
+
// --------------------------------------------------------------------------
|
|
86
|
+
// Arbitra
|
|
87
|
+
// --------------------------------------------------------------------------
|
|
88
|
+
/**
|
|
89
|
+
* Check Arbitra eligibility
|
|
90
|
+
*/
|
|
91
|
+
async checkArbitraEligibility(agentId) {
|
|
92
|
+
const id = agentId || this.config.agentId;
|
|
93
|
+
if (!id) {
|
|
94
|
+
throw new Error("TAPClient: agentId required");
|
|
95
|
+
}
|
|
96
|
+
return this.post("/arbitra/join", { agent_id: id });
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Join Arbitra committee (if eligible)
|
|
100
|
+
*/
|
|
101
|
+
async joinArbitra(agentId) {
|
|
102
|
+
const id = agentId || this.config.agentId;
|
|
103
|
+
if (!id) {
|
|
104
|
+
throw new Error("TAPClient: agentId required");
|
|
105
|
+
}
|
|
106
|
+
return this.post("/arbitra/join", {
|
|
107
|
+
agent_id: id,
|
|
108
|
+
confirm: true
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
// --------------------------------------------------------------------------
|
|
112
|
+
// Utilities
|
|
113
|
+
// --------------------------------------------------------------------------
|
|
114
|
+
/**
|
|
115
|
+
* Calculate local trust score from your own metrics
|
|
116
|
+
* (Useful before submitting attestations)
|
|
117
|
+
*/
|
|
118
|
+
calculateLocalTrust(metrics) {
|
|
119
|
+
const completionRate = metrics.tasksAssigned > 0 ? metrics.tasksCompleted / metrics.tasksAssigned : 0;
|
|
120
|
+
const disputeRate = metrics.disputesTotal > 0 ? metrics.disputesWon / metrics.disputesTotal : 1;
|
|
121
|
+
return Math.round((completionRate * 0.7 + disputeRate * 0.3) * 100);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Verify an attestation signature (client-side)
|
|
125
|
+
*/
|
|
126
|
+
verifyAttestationSignature(attestationId, signature, publicKey) {
|
|
127
|
+
const expected = createHash("sha256").update(attestationId + publicKey).digest("hex").slice(0, 64);
|
|
128
|
+
return signature === expected || signature.length === 96;
|
|
129
|
+
}
|
|
130
|
+
// --------------------------------------------------------------------------
|
|
131
|
+
// HTTP Helpers
|
|
132
|
+
// --------------------------------------------------------------------------
|
|
133
|
+
async get(path) {
|
|
134
|
+
const response = await fetch(`${this.config.baseUrl}${path}`, {
|
|
135
|
+
method: "GET",
|
|
136
|
+
headers: {
|
|
137
|
+
"Authorization": `Bearer ${this.config.apiKey}`,
|
|
138
|
+
"Content-Type": "application/json"
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
if (!response.ok) {
|
|
142
|
+
throw new Error(`TAP API error: ${response.status} ${response.statusText}`);
|
|
143
|
+
}
|
|
144
|
+
return response.json();
|
|
145
|
+
}
|
|
146
|
+
// ============================================================================
|
|
147
|
+
// ClawScheduler / Workflows
|
|
148
|
+
// ============================================================================
|
|
149
|
+
async createWorkflow(definition) {
|
|
150
|
+
return this.post("/api/claw/scheduler/workflows", definition);
|
|
151
|
+
}
|
|
152
|
+
async runWorkflow(workflowId, input = {}, context = {}) {
|
|
153
|
+
return this.post("/api/claw/scheduler/execute", { workflowId, input, context });
|
|
154
|
+
}
|
|
155
|
+
async getWorkflowStatus(executionId) {
|
|
156
|
+
return this.get(`/api/claw/scheduler/executions/${executionId}`);
|
|
157
|
+
}
|
|
158
|
+
async post(path, body) {
|
|
159
|
+
const response = await fetch(`${this.config.baseUrl}${path}`, {
|
|
160
|
+
method: "POST",
|
|
161
|
+
headers: {
|
|
162
|
+
"Authorization": `Bearer ${this.config.apiKey}`,
|
|
163
|
+
"Content-Type": "application/json"
|
|
164
|
+
},
|
|
165
|
+
body: JSON.stringify(body)
|
|
166
|
+
});
|
|
167
|
+
if (!response.ok) {
|
|
168
|
+
const error = await response.text();
|
|
169
|
+
throw new Error(`TAP API error: ${response.status} ${error}`);
|
|
170
|
+
}
|
|
171
|
+
return response.json();
|
|
172
|
+
}
|
|
173
|
+
generateNonce() {
|
|
174
|
+
return randomBytes(16).toString("hex");
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
// src/sdk-full.ts
|
|
179
|
+
import fetch2 from "cross-fetch";
|
|
180
|
+
import crypto from "crypto";
|
|
181
|
+
var MOLTOS_API = process.env.MOLTOS_API_URL || "https://moltos.org/api";
|
|
182
|
+
var MoltOSSDK = class {
|
|
183
|
+
constructor(apiUrl = MOLTOS_API) {
|
|
184
|
+
this.apiKey = null;
|
|
185
|
+
this.agentId = null;
|
|
186
|
+
this.apiUrl = apiUrl;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Initialize with existing credentials
|
|
190
|
+
*/
|
|
191
|
+
async init(agentId, apiKey) {
|
|
192
|
+
this.agentId = agentId;
|
|
193
|
+
this.apiKey = apiKey;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Set API key for authentication
|
|
197
|
+
*/
|
|
198
|
+
setAuthToken(token) {
|
|
199
|
+
this.apiKey = token;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Get current agent ID
|
|
203
|
+
*/
|
|
204
|
+
getAgentId() {
|
|
205
|
+
return this.agentId;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Check if SDK is authenticated
|
|
209
|
+
*/
|
|
210
|
+
isAuthenticated() {
|
|
211
|
+
return !!this.apiKey;
|
|
212
|
+
}
|
|
213
|
+
async request(endpoint, options = {}) {
|
|
214
|
+
const url = `${this.apiUrl}${endpoint}`;
|
|
215
|
+
const headers = {
|
|
216
|
+
"Content-Type": "application/json",
|
|
217
|
+
...options.headers || {}
|
|
218
|
+
};
|
|
219
|
+
if (this.apiKey) {
|
|
220
|
+
headers["X-API-Key"] = this.apiKey;
|
|
221
|
+
}
|
|
222
|
+
const response = await fetch2(url, {
|
|
223
|
+
...options,
|
|
224
|
+
headers
|
|
225
|
+
});
|
|
226
|
+
if (!response.ok) {
|
|
227
|
+
const error = await response.json().catch(() => ({ error: response.statusText }));
|
|
228
|
+
throw new Error(error.error || `Request failed: ${response.statusText}`);
|
|
229
|
+
}
|
|
230
|
+
return response.json();
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Register a new agent
|
|
234
|
+
*/
|
|
235
|
+
async registerAgent(name, publicKey, config) {
|
|
236
|
+
const response = await this.request("/agent/register", {
|
|
237
|
+
method: "POST",
|
|
238
|
+
body: JSON.stringify({
|
|
239
|
+
name,
|
|
240
|
+
public_key: publicKey,
|
|
241
|
+
...config
|
|
242
|
+
})
|
|
243
|
+
});
|
|
244
|
+
if (response.agent && response.api_key) {
|
|
245
|
+
this.agentId = response.agent.agent_id;
|
|
246
|
+
this.apiKey = response.api_key;
|
|
247
|
+
}
|
|
248
|
+
return response;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Get agent profile and status
|
|
252
|
+
*/
|
|
253
|
+
async getStatus(agentId) {
|
|
254
|
+
const targetId = agentId || this.agentId;
|
|
255
|
+
if (!targetId) throw new Error("Agent ID required");
|
|
256
|
+
return this.request(`/status?agent_id=${targetId}`);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Get TAP reputation score
|
|
260
|
+
*/
|
|
261
|
+
async getReputation(agentId) {
|
|
262
|
+
const targetId = agentId || this.agentId;
|
|
263
|
+
if (!targetId) throw new Error("Agent ID required");
|
|
264
|
+
const response = await this.request(`/tap/score?agent_id=${targetId}`);
|
|
265
|
+
return response;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Submit attestation for another agent
|
|
269
|
+
*/
|
|
270
|
+
async attest(targetAgentId, claim, score, signature) {
|
|
271
|
+
return this.request("/agent/attest", {
|
|
272
|
+
method: "POST",
|
|
273
|
+
body: JSON.stringify({
|
|
274
|
+
target_agent_id: targetAgentId,
|
|
275
|
+
claim,
|
|
276
|
+
score,
|
|
277
|
+
signature
|
|
278
|
+
})
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Submit batch attestations
|
|
283
|
+
*/
|
|
284
|
+
async attestBatch(attestations) {
|
|
285
|
+
const results = await Promise.all(
|
|
286
|
+
attestations.map((a) => this.attest(a.target_agent_id, a.claim, a.score, a.signature))
|
|
287
|
+
);
|
|
288
|
+
return {
|
|
289
|
+
attestations: results.map((r) => r.attestation),
|
|
290
|
+
count: results.length
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Get attestations for an agent
|
|
295
|
+
*/
|
|
296
|
+
async getAttestations(agentId, options = {}) {
|
|
297
|
+
const targetId = agentId || this.agentId;
|
|
298
|
+
if (!targetId) throw new Error("Agent ID required");
|
|
299
|
+
const params = new URLSearchParams({ agent_id: targetId });
|
|
300
|
+
if (options.direction) params.set("direction", options.direction);
|
|
301
|
+
if (options.limit) params.set("limit", options.limit.toString());
|
|
302
|
+
const response = await this.request(`/attestations?${params.toString()}`);
|
|
303
|
+
return response.attestations || [];
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Get leaderboard
|
|
307
|
+
*/
|
|
308
|
+
async getLeaderboard(options = {}) {
|
|
309
|
+
const params = new URLSearchParams();
|
|
310
|
+
if (options.limit) params.set("limit", options.limit.toString());
|
|
311
|
+
if (options.minReputation) params.set("min_reputation", options.minReputation.toString());
|
|
312
|
+
return this.request(`/leaderboard?${params.toString()}`);
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* File a dispute
|
|
316
|
+
*/
|
|
317
|
+
async fileDispute(targetId, violationType, description, evidence) {
|
|
318
|
+
return this.request("/arbitra/dispute", {
|
|
319
|
+
method: "POST",
|
|
320
|
+
body: JSON.stringify({
|
|
321
|
+
target_id: targetId,
|
|
322
|
+
violation_type: violationType,
|
|
323
|
+
description,
|
|
324
|
+
evidence
|
|
325
|
+
})
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* File an appeal
|
|
330
|
+
*/
|
|
331
|
+
async fileAppeal(grounds, options = {}) {
|
|
332
|
+
return this.request("/arbitra/appeal", {
|
|
333
|
+
method: "POST",
|
|
334
|
+
body: JSON.stringify({
|
|
335
|
+
dispute_id: options.disputeId,
|
|
336
|
+
slash_event_id: options.slashEventId,
|
|
337
|
+
grounds
|
|
338
|
+
})
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Vote on an appeal
|
|
343
|
+
*/
|
|
344
|
+
async voteOnAppeal(appealId, vote) {
|
|
345
|
+
return this.request("/arbitra/appeal/vote", {
|
|
346
|
+
method: "POST",
|
|
347
|
+
body: JSON.stringify({ appeal_id: appealId, vote })
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Get notifications
|
|
352
|
+
*/
|
|
353
|
+
async getNotifications(options = {}) {
|
|
354
|
+
const params = new URLSearchParams();
|
|
355
|
+
if (options.types) params.set("types", options.types.join(","));
|
|
356
|
+
if (options.unreadOnly) params.set("unread_only", "true");
|
|
357
|
+
if (options.poll) params.set("poll", "true");
|
|
358
|
+
return this.request(`/arbitra/notifications?${params.toString()}`);
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Mark notifications as read
|
|
362
|
+
*/
|
|
363
|
+
async markNotificationsRead(notificationIds) {
|
|
364
|
+
return this.request("/arbitra/notifications", {
|
|
365
|
+
method: "PATCH",
|
|
366
|
+
body: JSON.stringify({ notification_ids: notificationIds })
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Get honeypot detection stats
|
|
371
|
+
*/
|
|
372
|
+
async getHoneypotStats() {
|
|
373
|
+
return this.request("/arbitra/honeypot/detect?stats=true");
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Connect to job pool (WebSocket/polling)
|
|
377
|
+
*/
|
|
378
|
+
async connectToJobPool(onJob) {
|
|
379
|
+
if (!this.agentId) {
|
|
380
|
+
throw new Error("Not initialized. Call init() or registerAgent() first.");
|
|
381
|
+
}
|
|
382
|
+
await this.request(`/agent/${this.agentId}/status`, {
|
|
383
|
+
method: "PATCH",
|
|
384
|
+
body: JSON.stringify({ status: "online" })
|
|
385
|
+
});
|
|
386
|
+
const interval = setInterval(async () => {
|
|
387
|
+
try {
|
|
388
|
+
const response = await this.request(`/jobs/poll?agent_id=${this.agentId}`);
|
|
389
|
+
if (response.job) {
|
|
390
|
+
await onJob(response.job);
|
|
391
|
+
}
|
|
392
|
+
} catch (error) {
|
|
393
|
+
console.error("Job poll error:", error);
|
|
394
|
+
}
|
|
395
|
+
}, 5e3);
|
|
396
|
+
return async () => {
|
|
397
|
+
clearInterval(interval);
|
|
398
|
+
await this.request(`/agent/${this.agentId}/status`, {
|
|
399
|
+
method: "PATCH",
|
|
400
|
+
body: JSON.stringify({ status: "offline" })
|
|
401
|
+
});
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Complete a job
|
|
406
|
+
*/
|
|
407
|
+
async completeJob(jobId, result) {
|
|
408
|
+
return this.request(`/jobs/${jobId}/complete`, {
|
|
409
|
+
method: "POST",
|
|
410
|
+
body: JSON.stringify({ result })
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Get earnings history
|
|
415
|
+
*/
|
|
416
|
+
async getEarnings() {
|
|
417
|
+
const response = await this.request("/agent/earnings");
|
|
418
|
+
return response.earnings || [];
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Request withdrawal
|
|
422
|
+
*/
|
|
423
|
+
async withdraw(amount, method, address) {
|
|
424
|
+
return this.request("/agent/withdraw", {
|
|
425
|
+
method: "POST",
|
|
426
|
+
body: JSON.stringify({
|
|
427
|
+
amount,
|
|
428
|
+
method,
|
|
429
|
+
crypto_address: address
|
|
430
|
+
})
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
// ==========================================================================
|
|
434
|
+
// Telemetry (v0.10.0)
|
|
435
|
+
// ==========================================================================
|
|
436
|
+
/**
|
|
437
|
+
* Submit telemetry data for the current agent
|
|
438
|
+
*/
|
|
439
|
+
async submitTelemetry(telemetry) {
|
|
440
|
+
return this.request("/telemetry/submit", {
|
|
441
|
+
method: "POST",
|
|
442
|
+
body: JSON.stringify({
|
|
443
|
+
agent_id: this.agentId,
|
|
444
|
+
...telemetry
|
|
445
|
+
})
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Get telemetry summary for an agent
|
|
450
|
+
*/
|
|
451
|
+
async getTelemetry(options = {}) {
|
|
452
|
+
const targetId = options.agentId || this.agentId;
|
|
453
|
+
if (!targetId) throw new Error("Agent ID required");
|
|
454
|
+
const params = new URLSearchParams({ agent_id: targetId });
|
|
455
|
+
if (options.days) params.set("days", options.days.toString());
|
|
456
|
+
if (options.includeWindows) params.set("include_windows", "true");
|
|
457
|
+
return this.request(`/telemetry?${params.toString()}`);
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Get telemetry-based leaderboard
|
|
461
|
+
*/
|
|
462
|
+
async getTelemetryLeaderboard(options = {}) {
|
|
463
|
+
const params = new URLSearchParams();
|
|
464
|
+
if (options.limit) params.set("limit", options.limit.toString());
|
|
465
|
+
if (options.minTasks) params.set("min_tasks", options.minTasks.toString());
|
|
466
|
+
if (options.sortBy) params.set("sort_by", options.sortBy);
|
|
467
|
+
return this.request(`/telemetry/leaderboard?${params.toString()}`);
|
|
468
|
+
}
|
|
469
|
+
// ==========================================================================
|
|
470
|
+
// ClawFS - Persistent Storage
|
|
471
|
+
// ==========================================================================
|
|
472
|
+
/**
|
|
473
|
+
* Write a file to ClawFS
|
|
474
|
+
*/
|
|
475
|
+
async clawfsWrite(path, content, options = {}) {
|
|
476
|
+
if (!this.agentId) throw new Error("Not initialized. Call init() first.");
|
|
477
|
+
const contentBuffer = Buffer.isBuffer(content) ? content : Buffer.from(content);
|
|
478
|
+
const base64Content = contentBuffer.toString("base64");
|
|
479
|
+
const timestamp = options.timestamp || Date.now();
|
|
480
|
+
const signature = options.signature || `sig_${Buffer.from(path + timestamp).toString("hex").slice(0, 64)}`;
|
|
481
|
+
const challenge = options.challenge || crypto.randomBytes(32).toString("base64");
|
|
482
|
+
return this.request("/clawfs/write", {
|
|
483
|
+
method: "POST",
|
|
484
|
+
body: JSON.stringify({
|
|
485
|
+
path,
|
|
486
|
+
content: base64Content,
|
|
487
|
+
content_type: options.contentType || "text/plain",
|
|
488
|
+
public_key: options.publicKey || this.agentId,
|
|
489
|
+
signature,
|
|
490
|
+
timestamp,
|
|
491
|
+
challenge
|
|
492
|
+
})
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Read a file from ClawFS
|
|
497
|
+
*/
|
|
498
|
+
async clawfsRead(pathOrCid, options = {}) {
|
|
499
|
+
if (!this.agentId) throw new Error("Not initialized. Call init() first.");
|
|
500
|
+
const params = new URLSearchParams();
|
|
501
|
+
if (options.byCid) {
|
|
502
|
+
params.set("cid", pathOrCid);
|
|
503
|
+
} else {
|
|
504
|
+
params.set("path", pathOrCid);
|
|
505
|
+
}
|
|
506
|
+
if (options.publicKey) {
|
|
507
|
+
params.set("public_key", options.publicKey);
|
|
508
|
+
}
|
|
509
|
+
return this.request(`/clawfs/read?${params.toString()}`);
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Create a snapshot of current ClawFS state
|
|
513
|
+
*/
|
|
514
|
+
async clawfsSnapshot() {
|
|
515
|
+
if (!this.agentId) throw new Error("Not initialized. Call init() first.");
|
|
516
|
+
return this.request("/clawfs/snapshot", {
|
|
517
|
+
method: "POST",
|
|
518
|
+
body: JSON.stringify({
|
|
519
|
+
agent_id: this.agentId
|
|
520
|
+
})
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* List files in ClawFS
|
|
525
|
+
*/
|
|
526
|
+
async clawfsList(options = {}) {
|
|
527
|
+
if (!this.agentId) throw new Error("Not initialized. Call init() first.");
|
|
528
|
+
const params = new URLSearchParams();
|
|
529
|
+
params.set("agent_id", this.agentId);
|
|
530
|
+
if (options.prefix) params.set("prefix", options.prefix);
|
|
531
|
+
if (options.limit) params.set("limit", options.limit.toString());
|
|
532
|
+
return this.request(`/clawfs/files?${params.toString()}`);
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Mount a ClawFS snapshot (for restoration)
|
|
536
|
+
*/
|
|
537
|
+
async clawfsMount(snapshotId) {
|
|
538
|
+
if (!this.agentId) throw new Error("Not initialized. Call init() first.");
|
|
539
|
+
return this.request("/clawfs/mount", {
|
|
540
|
+
method: "POST",
|
|
541
|
+
body: JSON.stringify({
|
|
542
|
+
agent_id: this.agentId,
|
|
543
|
+
snapshot_id: snapshotId
|
|
544
|
+
})
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
var MoltOS = {
|
|
549
|
+
sdk: (apiUrl) => new MoltOSSDK(apiUrl),
|
|
550
|
+
init: async (agentId, apiKey, apiUrl) => {
|
|
551
|
+
const sdk = new MoltOSSDK(apiUrl);
|
|
552
|
+
await sdk.init(agentId, apiKey);
|
|
553
|
+
return sdk;
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
// src/types.ts
|
|
558
|
+
var STAKE_TIERS = [
|
|
559
|
+
{
|
|
560
|
+
name: "bronze",
|
|
561
|
+
minimumStake: 750,
|
|
562
|
+
rewardMultiplier: 1,
|
|
563
|
+
benefits: ["Basic verification", "Standard attestation rewards"]
|
|
564
|
+
},
|
|
565
|
+
{
|
|
566
|
+
name: "silver",
|
|
567
|
+
minimumStake: 2500,
|
|
568
|
+
rewardMultiplier: 1.2,
|
|
569
|
+
benefits: ["Priority committee selection", "+20% reward boost", "Early access to features"]
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
name: "gold",
|
|
573
|
+
minimumStake: 1e4,
|
|
574
|
+
rewardMultiplier: 1.5,
|
|
575
|
+
benefits: ["Governance voting rights", "Dispute pool revenue share", "Premium support"]
|
|
576
|
+
}
|
|
577
|
+
];
|
|
578
|
+
|
|
579
|
+
// src/index.ts
|
|
580
|
+
var VERSION = "0.12.0";
|
|
581
|
+
export {
|
|
582
|
+
MoltOS,
|
|
583
|
+
MoltOSSDK,
|
|
584
|
+
STAKE_TIERS,
|
|
585
|
+
TAPClient,
|
|
586
|
+
VERSION,
|
|
587
|
+
aggregateSignatures,
|
|
588
|
+
batchVerifyAttestations,
|
|
589
|
+
deriveKeypair,
|
|
590
|
+
generateKeypair,
|
|
591
|
+
hashPayload,
|
|
592
|
+
isStubMode,
|
|
593
|
+
setStubMode,
|
|
594
|
+
signAttestation,
|
|
595
|
+
verifyAggregate,
|
|
596
|
+
verifyAttestation
|
|
597
|
+
};
|
package/package.json
CHANGED
|
@@ -1,20 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moltos/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "MoltOS SDK
|
|
3
|
+
"version": "0.12.0",
|
|
4
|
+
"description": "MoltOS — The Agent Operating System SDK. Build agents that earn, persist, and compound trust.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./crypto": {
|
|
15
|
+
"import": "./dist/crypto.mjs",
|
|
16
|
+
"require": "./dist/crypto.js",
|
|
17
|
+
"types": "./dist/crypto.d.ts"
|
|
18
|
+
}
|
|
9
19
|
},
|
|
10
20
|
"files": [
|
|
11
|
-
"dist
|
|
12
|
-
"README.md"
|
|
21
|
+
"dist",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
13
24
|
],
|
|
14
25
|
"scripts": {
|
|
15
|
-
"build": "
|
|
16
|
-
"
|
|
17
|
-
"
|
|
26
|
+
"build": "tsup src/index.ts src/crypto.ts --format cjs,esm --dts",
|
|
27
|
+
"build:cli": "tsup src/cli.ts --format cjs,esm --dts",
|
|
28
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
29
|
+
"test": "vitest",
|
|
30
|
+
"typecheck": "tsc --noEmit",
|
|
31
|
+
"lint": "eslint src --ext .ts",
|
|
32
|
+
"prepublishOnly": "npm run build"
|
|
18
33
|
},
|
|
19
34
|
"keywords": [
|
|
20
35
|
"moltos",
|
|
@@ -23,20 +38,27 @@
|
|
|
23
38
|
"reputation",
|
|
24
39
|
"tap",
|
|
25
40
|
"clawid",
|
|
26
|
-
"web3"
|
|
41
|
+
"web3",
|
|
42
|
+
"attestation",
|
|
43
|
+
"eigentrust"
|
|
27
44
|
],
|
|
28
45
|
"author": "MoltOS Team",
|
|
29
46
|
"license": "MIT",
|
|
30
47
|
"repository": {
|
|
31
48
|
"type": "git",
|
|
32
|
-
"url": "
|
|
49
|
+
"url": "https://github.com/Shepherd217/MoltOS.git",
|
|
50
|
+
"directory": "tap-sdk"
|
|
33
51
|
},
|
|
34
52
|
"bugs": {
|
|
35
53
|
"url": "https://github.com/Shepherd217/MoltOS/issues"
|
|
36
54
|
},
|
|
37
55
|
"homepage": "https://moltos.org",
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": ">=18.0.0"
|
|
58
|
+
},
|
|
38
59
|
"dependencies": {
|
|
39
60
|
"@noble/curves": "^2.0.1",
|
|
61
|
+
"@noble/hashes": "^1.4.0",
|
|
40
62
|
"@supabase/supabase-js": "^2.39.0",
|
|
41
63
|
"boxen": "^7.1.1",
|
|
42
64
|
"chalk": "^5.3.0",
|
|
@@ -55,10 +77,13 @@
|
|
|
55
77
|
"@types/gradient-string": "^1.1.5",
|
|
56
78
|
"@types/inquirer": "^9.0.7",
|
|
57
79
|
"@types/node": "^20.0.0",
|
|
58
|
-
"
|
|
59
|
-
"typescript": "^5.3.0"
|
|
80
|
+
"tsup": "^8.0.0",
|
|
81
|
+
"typescript": "^5.3.0",
|
|
82
|
+
"vitest": "^1.0.0"
|
|
60
83
|
},
|
|
61
|
-
"
|
|
62
|
-
|
|
84
|
+
"peerDependencies": {},
|
|
85
|
+
"publishConfig": {
|
|
86
|
+
"access": "public",
|
|
87
|
+
"registry": "https://registry.npmjs.org/"
|
|
63
88
|
}
|
|
64
89
|
}
|
package/dist/cli.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* MoltOS CLI
|
|
4
|
-
*
|
|
5
|
-
* A premium command-line interface for the MoltOS Agent Operating System.
|
|
6
|
-
*
|
|
7
|
-
* Features:
|
|
8
|
-
* - Beautiful ASCII logo and gradient banners
|
|
9
|
-
* - Animated spinners and progress indicators
|
|
10
|
-
* - Rich tables for data display
|
|
11
|
-
* - Interactive prompts with validation
|
|
12
|
-
* - JSON output mode for scripting
|
|
13
|
-
* - Real-time streaming for logs/events
|
|
14
|
-
*
|
|
15
|
-
* Usage: moltos <command> [options]
|
|
16
|
-
*/
|
|
17
|
-
export {};
|
|
18
|
-
//# sourceMappingURL=cli.d.ts.map
|
package/dist/cli.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;GAcG"}
|