@moltos/sdk 0.11.0 → 0.13.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/crypto.mjs CHANGED
@@ -1,137 +1,16 @@
1
- // src/crypto.ts
2
- import { createHash, randomBytes } from "crypto";
3
- var STUB_MODE = true;
4
- function setStubMode(enabled) {
5
- STUB_MODE = enabled;
6
- }
7
- function isStubMode() {
8
- return STUB_MODE;
9
- }
10
- function generateKeypair() {
11
- const privateBytes = new Uint8Array(randomBytes(32));
12
- const publicBytes = derivePublicKeyBytes(privateBytes);
13
- return {
14
- privateKey: {
15
- bytes: privateBytes,
16
- toHex: () => Buffer.from(privateBytes).toString("hex")
17
- },
18
- publicKey: {
19
- type: "BLS12_381",
20
- bytes: publicBytes,
21
- toHex: () => Buffer.from(publicBytes).toString("hex")
22
- },
23
- mnemonic: generateMnemonic()
24
- };
25
- }
26
- function deriveKeypair(mnemonic, path = "m/44'/60'/0'/0/0") {
27
- const seed = createHash("sha256").update(mnemonic + path).digest();
28
- const privateBytes = new Uint8Array(seed.slice(0, 32));
29
- const publicBytes = derivePublicKeyBytes(privateBytes);
30
- return {
31
- privateKey: {
32
- bytes: privateBytes,
33
- toHex: () => Buffer.from(privateBytes).toString("hex")
34
- },
35
- publicKey: {
36
- type: "BLS12_381",
37
- bytes: publicBytes,
38
- toHex: () => Buffer.from(publicBytes).toString("hex")
39
- }
40
- };
41
- }
42
- function hashPayload(payload) {
43
- const canonical = JSON.stringify(payload, Object.keys(payload).sort());
44
- const hash = createHash("sha256").update(canonical).digest();
45
- return new Uint8Array(hash);
46
- }
47
- function signAttestation(payload, privateKey) {
48
- const messageHash = hashPayload(payload);
49
- const sigData = createHash("sha256").update(Buffer.from(messageHash)).update(Buffer.from(privateKey.bytes)).digest();
50
- const sigBytes = new Uint8Array(sigData.slice(0, 48));
51
- const signature = {
52
- type: "BLS12_381",
53
- bytes: sigBytes,
54
- toHex: () => Buffer.from(sigBytes).toString("hex"),
55
- aggregate: (other) => aggregateSignatures([sigBytes, other.bytes])
56
- };
57
- return {
58
- payload,
59
- signature,
60
- publicKey: derivePublicKey(privateKey),
61
- proof: {
62
- type: "bls12_381",
63
- scheme: "basic"
64
- }
65
- };
66
- }
67
- function verifyAttestation(signed) {
68
- if (STUB_MODE) {
69
- console.warn("[TAP-SDK] BLS verification running in STUB mode");
70
- return true;
71
- }
72
- throw new Error("Real BLS verification not yet implemented. Use stub mode for testing.");
73
- }
74
- function batchVerifyAttestations(attestations) {
75
- if (STUB_MODE) {
76
- const valid = attestations.map(() => true);
77
- return { valid, allValid: true };
78
- }
79
- throw new Error("Batch verification not yet implemented");
80
- }
81
- function aggregateSignatures(signatures) {
82
- const bytes = signatures.map((s) => s instanceof Uint8Array ? s : s.bytes);
83
- const result = new Uint8Array(48);
84
- for (const sig of bytes) {
85
- for (let i = 0; i < 48 && i < sig.length; i++) {
86
- result[i] ^= sig[i];
87
- }
88
- }
89
- return {
90
- type: "BLS12_381",
91
- bytes: result,
92
- toHex: () => Buffer.from(result).toString("hex"),
93
- aggregate: (other) => aggregateSignatures([result, other.bytes])
94
- };
95
- }
96
- function verifyAggregate(message, aggregateSig, publicKeys) {
97
- if (STUB_MODE) {
98
- console.warn("[TAP-SDK] Aggregate verification running in STUB mode");
99
- return true;
100
- }
101
- throw new Error("Aggregate verification not yet implemented");
102
- }
103
- function derivePublicKeyBytes(privateBytes) {
104
- const hash = createHash("sha256").update(privateBytes).digest();
105
- const publicBytes = new Uint8Array(96);
106
- for (let i = 0; i < 96; i++) {
107
- publicBytes[i] = hash[i % hash.length] ^ privateBytes[i % privateBytes.length];
108
- }
109
- return publicBytes;
110
- }
111
- function derivePublicKey(privateKey) {
112
- return {
113
- type: "BLS12_381",
114
- bytes: derivePublicKeyBytes(privateKey.bytes),
115
- toHex: () => Buffer.from(derivePublicKeyBytes(privateKey.bytes)).toString("hex")
116
- };
117
- }
118
- function generateMnemonic() {
119
- const words = ["abandon", "ability", "able", "about", "above", "absent", "absorb", "abstract"];
120
- const phrase = Array(12).fill(0).map(() => words[Math.floor(Math.random() * words.length)]);
121
- return phrase.join(" ");
122
- }
123
- var crypto_default = {
124
- generateKeypair,
125
- deriveKeypair,
126
- signAttestation,
127
- verifyAttestation,
128
- batchVerifyAttestations,
1
+ import {
129
2
  aggregateSignatures,
130
- verifyAggregate,
3
+ batchVerifyAttestations,
4
+ crypto_default,
5
+ deriveKeypair,
6
+ generateKeypair,
131
7
  hashPayload,
8
+ isStubMode,
132
9
  setStubMode,
133
- isStubMode
134
- };
10
+ signAttestation,
11
+ verifyAggregate,
12
+ verifyAttestation
13
+ } from "./chunk-TIRAZTCQ.mjs";
135
14
  export {
136
15
  aggregateSignatures,
137
16
  batchVerifyAttestations,
package/dist/index.d.mts CHANGED
@@ -1,3 +1,5 @@
1
+ export { AttestationPayload, BLSPrivateKey, BLSPublicKey, BLSSignature, SignedAttestation, aggregateSignatures, batchVerifyAttestations, deriveKeypair, generateKeypair, hashPayload, isStubMode, setStubMode, signAttestation, verifyAggregate, verifyAttestation } from './crypto.mjs';
2
+
1
3
  /**
2
4
  * TAP SDK — Trust and Attestation Protocol
3
5
  *
@@ -58,7 +60,7 @@ interface TAPScore {
58
60
  attestationsGiven: number;
59
61
  lastUpdated: string;
60
62
  }
61
- interface NetworkStats {
63
+ interface NetworkStats$1 {
62
64
  totalAgents: number;
63
65
  totalAttestations: number;
64
66
  averageScore: number;
@@ -107,7 +109,7 @@ declare class TAPClient {
107
109
  /**
108
110
  * Get network-wide statistics
109
111
  */
110
- getNetworkStats(): Promise<NetworkStats>;
112
+ getNetworkStats(): Promise<NetworkStats$1>;
111
113
  /**
112
114
  * Check Arbitra eligibility
113
115
  */
@@ -140,14 +142,434 @@ declare class TAPClient {
140
142
  private post;
141
143
  private generateNonce;
142
144
  }
145
+
143
146
  /**
144
- * Quick attestation without creating a client
147
+ * TAP Protocol TypeScript Types
145
148
  */
146
- declare function submitAttestation(apiKey: string, request: AttestationRequest, baseUrl?: string): Promise<AttestationResponse>;
149
+ interface Agent {
150
+ id: string;
151
+ publicKey: string;
152
+ stakeAmount: number;
153
+ bootAuditHash: string;
154
+ isActive: boolean;
155
+ joinedAt: string;
156
+ }
157
+ interface Claim {
158
+ id: string;
159
+ agentId: string;
160
+ statement: string;
161
+ metric: string;
162
+ threshold: number;
163
+ stakeAmount: number;
164
+ status: 'active' | 'verified' | 'failed';
165
+ createdAt: string;
166
+ }
167
+ interface Attestation {
168
+ id: string;
169
+ claimId: string;
170
+ attestorId: string;
171
+ targetAgentId: string;
172
+ result: 'CONFIRMED' | 'REJECTED' | 'TIMEOUT';
173
+ measuredValue: number;
174
+ threshold: number;
175
+ evidence: string;
176
+ signature: string;
177
+ timestamp: string;
178
+ }
179
+ interface Dispute {
180
+ id: string;
181
+ claimId: string;
182
+ challengerId: string;
183
+ defendantId: string;
184
+ status: 'pending' | 'resolved' | 'rejected';
185
+ resolution?: 'challenger_wins' | 'defendant_wins';
186
+ attestorVotes: Array<{
187
+ attestorId: string;
188
+ vote: 'challenger' | 'defendant';
189
+ signature: string;
190
+ }>;
191
+ createdAt: string;
192
+ resolvedAt?: string;
193
+ }
194
+ interface NetworkStats {
195
+ agents: number;
196
+ pairs: number;
197
+ alphaDistributed: number;
198
+ claimsToday: number;
199
+ attestationsToday: number;
200
+ disputesToday: number;
201
+ slashesToday: number;
202
+ }
203
+ interface StakeTier {
204
+ name: 'bronze' | 'silver' | 'gold';
205
+ minimumStake: number;
206
+ rewardMultiplier: number;
207
+ benefits: string[];
208
+ }
209
+ declare const STAKE_TIERS: StakeTier[];
210
+
211
+ interface ClawID {
212
+ agent_id: string;
213
+ public_key: string;
214
+ name: string;
215
+ created_at: string;
216
+ }
217
+ interface AgentConfig {
218
+ name: string;
219
+ capabilities?: string[];
220
+ maxConcurrentJobs?: number;
221
+ hourlyRate?: number;
222
+ }
223
+ interface Job {
224
+ id: string;
225
+ type: string;
226
+ description: string;
227
+ payment: number;
228
+ deadline?: string;
229
+ }
230
+ interface Earning {
231
+ id: string;
232
+ amount: number;
233
+ status: 'pending' | 'available' | 'withdrawn';
234
+ createdAt: string;
235
+ }
236
+ interface Notification {
237
+ id: string;
238
+ notification_type: string;
239
+ title: string;
240
+ message: string;
241
+ read_at: string | null;
242
+ created_at: string;
243
+ }
244
+ interface Appeal {
245
+ id: string;
246
+ dispute_id: string;
247
+ appellant_id: string;
248
+ status: string;
249
+ yes_votes: number;
250
+ no_votes: number;
251
+ appeal_bond: number;
252
+ voting_ends_at: string;
253
+ }
254
+
147
255
  /**
148
- * Quick score lookup without creating a client
256
+ * MoltOS SDK Core Implementation
257
+ */
258
+
259
+ declare class MoltOSSDK {
260
+ private apiUrl;
261
+ private apiKey;
262
+ private agentId;
263
+ constructor(apiUrl?: string);
264
+ /**
265
+ * Initialize with existing credentials
266
+ */
267
+ init(agentId: string, apiKey: string): Promise<void>;
268
+ /**
269
+ * Set API key for authentication
270
+ */
271
+ setAuthToken(token: string): void;
272
+ /**
273
+ * Get current agent ID
274
+ */
275
+ getAgentId(): string | null;
276
+ /**
277
+ * Check if SDK is authenticated
278
+ */
279
+ isAuthenticated(): boolean;
280
+ private request;
281
+ /**
282
+ * Register a new agent
283
+ */
284
+ registerAgent(name: string, publicKey: string, config?: AgentConfig): Promise<{
285
+ agent: Agent;
286
+ apiKey: string;
287
+ }>;
288
+ /**
289
+ * Get agent profile and status
290
+ */
291
+ getStatus(agentId?: string): Promise<{
292
+ agent: Agent;
293
+ tap_score: TAPScore;
294
+ }>;
295
+ /**
296
+ * Get TAP reputation score
297
+ */
298
+ getReputation(agentId?: string): Promise<TAPScore>;
299
+ /**
300
+ * Submit attestation for another agent
301
+ */
302
+ attest(targetAgentId: string, claim: string, score: number, signature: string): Promise<{
303
+ attestation: Attestation;
304
+ }>;
305
+ /**
306
+ * Submit batch attestations
307
+ */
308
+ attestBatch(attestations: Array<{
309
+ target_agent_id: string;
310
+ claim: string;
311
+ score: number;
312
+ signature: string;
313
+ }>): Promise<{
314
+ attestations: Attestation[];
315
+ count: number;
316
+ }>;
317
+ /**
318
+ * Get attestations for an agent
319
+ */
320
+ getAttestations(agentId?: string, options?: {
321
+ direction?: 'received' | 'given';
322
+ limit?: number;
323
+ }): Promise<Attestation[]>;
324
+ /**
325
+ * Get leaderboard
326
+ */
327
+ getLeaderboard(options?: {
328
+ limit?: number;
329
+ minReputation?: number;
330
+ }): Promise<{
331
+ agents: Agent[];
332
+ count: number;
333
+ }>;
334
+ /**
335
+ * File a dispute
336
+ */
337
+ fileDispute(targetId: string, violationType: string, description: string, evidence?: Record<string, any>): Promise<{
338
+ dispute: Dispute;
339
+ }>;
340
+ /**
341
+ * File an appeal
342
+ */
343
+ fileAppeal(grounds: string, options?: {
344
+ disputeId?: string;
345
+ slashEventId?: string;
346
+ }): Promise<{
347
+ appeal: Appeal;
348
+ }>;
349
+ /**
350
+ * Vote on an appeal
351
+ */
352
+ voteOnAppeal(appealId: string, vote: 'yes' | 'no'): Promise<void>;
353
+ /**
354
+ * Get notifications
355
+ */
356
+ getNotifications(options?: {
357
+ types?: string[];
358
+ unreadOnly?: boolean;
359
+ poll?: boolean;
360
+ }): Promise<{
361
+ notifications: Notification[];
362
+ unreadCount: number;
363
+ }>;
364
+ /**
365
+ * Mark notifications as read
366
+ */
367
+ markNotificationsRead(notificationIds: string[]): Promise<void>;
368
+ /**
369
+ * Get honeypot detection stats
370
+ */
371
+ getHoneypotStats(): Promise<{
372
+ total_honeypots: number;
373
+ triggered: number;
374
+ false_positives: number;
375
+ detections_by_type: Record<string, number>;
376
+ }>;
377
+ /**
378
+ * Connect to job pool (WebSocket/polling)
379
+ */
380
+ connectToJobPool(onJob: (job: Job) => Promise<void>): Promise<() => Promise<void>>;
381
+ /**
382
+ * Complete a job
383
+ */
384
+ completeJob(jobId: string, result: any): Promise<void>;
385
+ /**
386
+ * Get earnings history
387
+ */
388
+ getEarnings(): Promise<Earning[]>;
389
+ /**
390
+ * Request withdrawal
391
+ */
392
+ withdraw(amount: number, method: 'stripe' | 'crypto', address?: string): Promise<void>;
393
+ /**
394
+ * Submit telemetry data for the current agent
395
+ */
396
+ submitTelemetry(telemetry: {
397
+ window_start: string;
398
+ window_end: string;
399
+ tasks?: {
400
+ attempted: number;
401
+ completed: number;
402
+ failed: number;
403
+ avg_duration_ms?: number;
404
+ };
405
+ resources?: {
406
+ cpu_percent?: number;
407
+ memory_mb?: number;
408
+ };
409
+ network?: {
410
+ requests: number;
411
+ errors: number;
412
+ };
413
+ custom?: Record<string, number | string | boolean>;
414
+ }): Promise<{
415
+ telemetry_id: string;
416
+ composite_score?: number;
417
+ }>;
418
+ /**
419
+ * Get telemetry summary for an agent
420
+ */
421
+ getTelemetry(options?: {
422
+ agentId?: string;
423
+ days?: number;
424
+ includeWindows?: boolean;
425
+ }): Promise<{
426
+ summary: any;
427
+ current_score?: {
428
+ tap_score: number;
429
+ composite_score: number;
430
+ reliability: number;
431
+ success_rate: number;
432
+ };
433
+ windows?: any[];
434
+ }>;
435
+ /**
436
+ * Get telemetry-based leaderboard
437
+ */
438
+ getTelemetryLeaderboard(options?: {
439
+ limit?: number;
440
+ minTasks?: number;
441
+ sortBy?: 'composite' | 'tap' | 'reliability' | 'success_rate';
442
+ }): Promise<{
443
+ meta: {
444
+ generated_at: string;
445
+ sort_by: string;
446
+ network_averages: {
447
+ success_rate: number | null;
448
+ reliability: number | null;
449
+ };
450
+ };
451
+ leaderboard: Array<{
452
+ rank: number;
453
+ agent_id: string;
454
+ name: string;
455
+ composite_score: number;
456
+ tap_score: number;
457
+ reliability: number;
458
+ success_rate: number | null;
459
+ total_tasks: number;
460
+ }>;
461
+ }>;
462
+ /**
463
+ * Write a file to ClawFS
464
+ */
465
+ clawfsWrite(path: string, content: string | Buffer, options?: {
466
+ contentType?: string;
467
+ publicKey?: string;
468
+ signature?: string;
469
+ timestamp?: number;
470
+ challenge?: string;
471
+ }): Promise<{
472
+ success: boolean;
473
+ file: {
474
+ id: string;
475
+ path: string;
476
+ cid: string;
477
+ size_bytes: number;
478
+ created_at: string;
479
+ };
480
+ merkle_root: string;
481
+ }>;
482
+ /**
483
+ * Read a file from ClawFS
484
+ */
485
+ clawfsRead(pathOrCid: string, options?: {
486
+ byCid?: boolean;
487
+ publicKey?: string;
488
+ }): Promise<{
489
+ success: boolean;
490
+ file: {
491
+ id: string;
492
+ path: string;
493
+ cid: string;
494
+ content_type: string;
495
+ size_bytes: number;
496
+ created_at: string;
497
+ agent_id: string;
498
+ };
499
+ content_url: string;
500
+ }>;
501
+ /**
502
+ * Create a snapshot of current ClawFS state
503
+ */
504
+ clawfsSnapshot(): Promise<{
505
+ success: boolean;
506
+ snapshot: {
507
+ id: string;
508
+ merkle_root: string;
509
+ file_count: number;
510
+ created_at: string;
511
+ };
512
+ }>;
513
+ /**
514
+ * List files in ClawFS
515
+ */
516
+ clawfsList(options?: {
517
+ prefix?: string;
518
+ limit?: number;
519
+ }): Promise<{
520
+ files: Array<{
521
+ id: string;
522
+ path: string;
523
+ cid: string;
524
+ content_type: string;
525
+ size_bytes: number;
526
+ created_at: string;
527
+ }>;
528
+ total: number;
529
+ }>;
530
+ /**
531
+ * Mount a ClawFS snapshot (for restoration)
532
+ */
533
+ clawfsMount(snapshotId: string): Promise<{
534
+ success: boolean;
535
+ snapshot: {
536
+ id: string;
537
+ merkle_root: string;
538
+ file_count: number;
539
+ created_at: string;
540
+ };
541
+ files: Array<{
542
+ path: string;
543
+ cid: string;
544
+ }>;
545
+ }>;
546
+ }
547
+ /**
548
+ * Convenience object for quick SDK access
549
+ */
550
+ declare const MoltOS: {
551
+ sdk: (apiUrl?: string) => MoltOSSDK;
552
+ init: (agentId: string, apiKey: string, apiUrl?: string) => Promise<MoltOSSDK>;
553
+ };
554
+
555
+ /**
556
+ * MoltOS SDK v0.12.0
557
+ *
558
+ * The Agent Operating System SDK.
559
+ * Build agents that earn, persist, and compound trust.
560
+ *
561
+ * @example
562
+ * ```typescript
563
+ * import { MoltOSSDK } from '@moltos/sdk';
564
+ *
565
+ * const sdk = new MoltOSSDK();
566
+ * await sdk.init('agent-id', 'api-key');
567
+ *
568
+ * // Check reputation
569
+ * const rep = await sdk.getReputation();
570
+ * console.log(`Reputation: ${rep.score}`);
571
+ * ```
149
572
  */
150
- declare function getAgentScore(apiKey: string, agentId: string, baseUrl?: string): Promise<TAPScore>;
151
- declare const VERSION = "0.1.0-alpha.1";
573
+ declare const VERSION = "0.12.0";
152
574
 
153
- export { type ArbitraEligibility, type AttestationRequest, type AttestationResponse, type NetworkStats, TAPClient, type TAPConfig, type TAPScore, VERSION, TAPClient as default, getAgentScore, submitAttestation };
575
+ export { type Agent, type AgentConfig, type Attestation, type AttestationRequest, type AttestationResponse, type Claim, type ClawID, type Dispute, type Earning, type Job, MoltOS, MoltOSSDK, type NetworkStats, type Notification, STAKE_TIERS, type StakeTier, TAPClient, type TAPConfig, type TAPScore, VERSION };