@moltos/sdk 0.11.0 → 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/dist/index.mjs CHANGED
@@ -1,4 +1,17 @@
1
- // src/index.ts
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
2
15
  import { createHash, randomBytes } from "crypto";
3
16
  var DEFAULT_CONFIG = {
4
17
  baseUrl: "https://moltos.org/api",
@@ -161,20 +174,424 @@ var TAPClient = class {
161
174
  return randomBytes(16).toString("hex");
162
175
  }
163
176
  };
164
- async function submitAttestation(apiKey, request, baseUrl) {
165
- const client = new TAPClient({ apiKey, baseUrl });
166
- return client.attest(request);
167
- }
168
- async function getAgentScore(apiKey, agentId, baseUrl) {
169
- const client = new TAPClient({ apiKey, baseUrl });
170
- return client.getScore(agentId);
171
- }
172
- var VERSION = "0.1.0-alpha.1";
173
- var index_default = TAPClient;
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";
174
581
  export {
582
+ MoltOS,
583
+ MoltOSSDK,
584
+ STAKE_TIERS,
175
585
  TAPClient,
176
586
  VERSION,
177
- index_default as default,
178
- getAgentScore,
179
- submitAttestation
587
+ aggregateSignatures,
588
+ batchVerifyAttestations,
589
+ deriveKeypair,
590
+ generateKeypair,
591
+ hashPayload,
592
+ isStubMode,
593
+ setStubMode,
594
+ signAttestation,
595
+ verifyAggregate,
596
+ verifyAttestation
180
597
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moltos/sdk",
3
- "version": "0.11.0",
4
- "description": "MoltOS SDK - Trust and Attestation Protocol for Autonomous Agents",
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
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
@@ -24,6 +24,7 @@
24
24
  ],
25
25
  "scripts": {
26
26
  "build": "tsup src/index.ts src/crypto.ts --format cjs,esm --dts",
27
+ "build:cli": "tsup src/cli.ts --format cjs,esm --dts",
27
28
  "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
28
29
  "test": "vitest",
29
30
  "typecheck": "tsc --noEmit",
@@ -31,32 +32,50 @@
31
32
  "prepublishOnly": "npm run build"
32
33
  },
33
34
  "keywords": [
34
- "tap",
35
35
  "moltos",
36
- "attestation",
37
- "reputation",
38
- "eigentrust",
39
36
  "agents",
40
- "ai"
37
+ "ai",
38
+ "reputation",
39
+ "tap",
40
+ "clawid",
41
+ "web3",
42
+ "attestation",
43
+ "eigentrust"
41
44
  ],
42
45
  "author": "MoltOS Team",
43
46
  "license": "MIT",
44
47
  "repository": {
45
48
  "type": "git",
46
- "url": "https://github.com/Shepherd217/trust-audit-framework.git",
49
+ "url": "https://github.com/Shepherd217/MoltOS.git",
47
50
  "directory": "tap-sdk"
48
51
  },
49
52
  "bugs": {
50
- "url": "https://github.com/Shepherd217/trust-audit-framework/issues"
53
+ "url": "https://github.com/Shepherd217/MoltOS/issues"
51
54
  },
52
- "homepage": "https://docs.moltos.ai",
55
+ "homepage": "https://moltos.org",
53
56
  "engines": {
54
57
  "node": ">=18.0.0"
55
58
  },
56
59
  "dependencies": {
57
- "@noble/hashes": "^1.4.0"
60
+ "@noble/curves": "^2.0.1",
61
+ "@noble/hashes": "^1.4.0",
62
+ "@supabase/supabase-js": "^2.39.0",
63
+ "boxen": "^7.1.1",
64
+ "chalk": "^5.3.0",
65
+ "cli-table3": "^0.6.3",
66
+ "commander": "^11.1.0",
67
+ "cross-fetch": "^4.0.0",
68
+ "figlet": "^1.7.0",
69
+ "gradient-string": "^2.0.2",
70
+ "inquirer": "^9.2.12",
71
+ "log-symbols": "^6.0.0",
72
+ "nanospinner": "^1.1.0",
73
+ "ora": "^8.0.1"
58
74
  },
59
75
  "devDependencies": {
76
+ "@types/figlet": "^1.5.8",
77
+ "@types/gradient-string": "^1.1.5",
78
+ "@types/inquirer": "^9.0.7",
60
79
  "@types/node": "^20.0.0",
61
80
  "tsup": "^8.0.0",
62
81
  "typescript": "^5.3.0",