@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/dist/crypto.js ADDED
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/crypto.ts
21
+ var crypto_exports = {};
22
+ __export(crypto_exports, {
23
+ aggregateSignatures: () => aggregateSignatures,
24
+ batchVerifyAttestations: () => batchVerifyAttestations,
25
+ default: () => crypto_default,
26
+ deriveKeypair: () => deriveKeypair,
27
+ generateKeypair: () => generateKeypair,
28
+ hashPayload: () => hashPayload,
29
+ isStubMode: () => isStubMode,
30
+ setStubMode: () => setStubMode,
31
+ signAttestation: () => signAttestation,
32
+ verifyAggregate: () => verifyAggregate,
33
+ verifyAttestation: () => verifyAttestation
34
+ });
35
+ module.exports = __toCommonJS(crypto_exports);
36
+ var import_crypto = require("crypto");
37
+ var STUB_MODE = true;
38
+ function setStubMode(enabled) {
39
+ STUB_MODE = enabled;
40
+ }
41
+ function isStubMode() {
42
+ return STUB_MODE;
43
+ }
44
+ function generateKeypair() {
45
+ const privateBytes = new Uint8Array((0, import_crypto.randomBytes)(32));
46
+ const publicBytes = derivePublicKeyBytes(privateBytes);
47
+ return {
48
+ privateKey: {
49
+ bytes: privateBytes,
50
+ toHex: () => Buffer.from(privateBytes).toString("hex")
51
+ },
52
+ publicKey: {
53
+ type: "BLS12_381",
54
+ bytes: publicBytes,
55
+ toHex: () => Buffer.from(publicBytes).toString("hex")
56
+ },
57
+ mnemonic: generateMnemonic()
58
+ };
59
+ }
60
+ function deriveKeypair(mnemonic, path = "m/44'/60'/0'/0/0") {
61
+ const seed = (0, import_crypto.createHash)("sha256").update(mnemonic + path).digest();
62
+ const privateBytes = new Uint8Array(seed.slice(0, 32));
63
+ const publicBytes = derivePublicKeyBytes(privateBytes);
64
+ return {
65
+ privateKey: {
66
+ bytes: privateBytes,
67
+ toHex: () => Buffer.from(privateBytes).toString("hex")
68
+ },
69
+ publicKey: {
70
+ type: "BLS12_381",
71
+ bytes: publicBytes,
72
+ toHex: () => Buffer.from(publicBytes).toString("hex")
73
+ }
74
+ };
75
+ }
76
+ function hashPayload(payload) {
77
+ const canonical = JSON.stringify(payload, Object.keys(payload).sort());
78
+ const hash = (0, import_crypto.createHash)("sha256").update(canonical).digest();
79
+ return new Uint8Array(hash);
80
+ }
81
+ function signAttestation(payload, privateKey) {
82
+ const messageHash = hashPayload(payload);
83
+ const sigData = (0, import_crypto.createHash)("sha256").update(Buffer.from(messageHash)).update(Buffer.from(privateKey.bytes)).digest();
84
+ const sigBytes = new Uint8Array(sigData.slice(0, 48));
85
+ const signature = {
86
+ type: "BLS12_381",
87
+ bytes: sigBytes,
88
+ toHex: () => Buffer.from(sigBytes).toString("hex"),
89
+ aggregate: (other) => aggregateSignatures([sigBytes, other.bytes])
90
+ };
91
+ return {
92
+ payload,
93
+ signature,
94
+ publicKey: derivePublicKey(privateKey),
95
+ proof: {
96
+ type: "bls12_381",
97
+ scheme: "basic"
98
+ }
99
+ };
100
+ }
101
+ function verifyAttestation(signed) {
102
+ if (STUB_MODE) {
103
+ console.warn("[TAP-SDK] BLS verification running in STUB mode");
104
+ return true;
105
+ }
106
+ throw new Error("Real BLS verification not yet implemented. Use stub mode for testing.");
107
+ }
108
+ function batchVerifyAttestations(attestations) {
109
+ if (STUB_MODE) {
110
+ const valid = attestations.map(() => true);
111
+ return { valid, allValid: true };
112
+ }
113
+ throw new Error("Batch verification not yet implemented");
114
+ }
115
+ function aggregateSignatures(signatures) {
116
+ const bytes = signatures.map((s) => s instanceof Uint8Array ? s : s.bytes);
117
+ const result = new Uint8Array(48);
118
+ for (const sig of bytes) {
119
+ for (let i = 0; i < 48 && i < sig.length; i++) {
120
+ result[i] ^= sig[i];
121
+ }
122
+ }
123
+ return {
124
+ type: "BLS12_381",
125
+ bytes: result,
126
+ toHex: () => Buffer.from(result).toString("hex"),
127
+ aggregate: (other) => aggregateSignatures([result, other.bytes])
128
+ };
129
+ }
130
+ function verifyAggregate(message, aggregateSig, publicKeys) {
131
+ if (STUB_MODE) {
132
+ console.warn("[TAP-SDK] Aggregate verification running in STUB mode");
133
+ return true;
134
+ }
135
+ throw new Error("Aggregate verification not yet implemented");
136
+ }
137
+ function derivePublicKeyBytes(privateBytes) {
138
+ const hash = (0, import_crypto.createHash)("sha256").update(privateBytes).digest();
139
+ const publicBytes = new Uint8Array(96);
140
+ for (let i = 0; i < 96; i++) {
141
+ publicBytes[i] = hash[i % hash.length] ^ privateBytes[i % privateBytes.length];
142
+ }
143
+ return publicBytes;
144
+ }
145
+ function derivePublicKey(privateKey) {
146
+ return {
147
+ type: "BLS12_381",
148
+ bytes: derivePublicKeyBytes(privateKey.bytes),
149
+ toHex: () => Buffer.from(derivePublicKeyBytes(privateKey.bytes)).toString("hex")
150
+ };
151
+ }
152
+ function generateMnemonic() {
153
+ const words = ["abandon", "ability", "able", "about", "above", "absent", "absorb", "abstract"];
154
+ const phrase = Array(12).fill(0).map(() => words[Math.floor(Math.random() * words.length)]);
155
+ return phrase.join(" ");
156
+ }
157
+ var crypto_default = {
158
+ generateKeypair,
159
+ deriveKeypair,
160
+ signAttestation,
161
+ verifyAttestation,
162
+ batchVerifyAttestations,
163
+ aggregateSignatures,
164
+ verifyAggregate,
165
+ hashPayload,
166
+ setStubMode,
167
+ isStubMode
168
+ };
169
+ // Annotate the CommonJS export names for ESM import in node:
170
+ 0 && (module.exports = {
171
+ aggregateSignatures,
172
+ batchVerifyAttestations,
173
+ deriveKeypair,
174
+ generateKeypair,
175
+ hashPayload,
176
+ isStubMode,
177
+ setStubMode,
178
+ signAttestation,
179
+ verifyAggregate,
180
+ verifyAttestation
181
+ });
@@ -0,0 +1,26 @@
1
+ import {
2
+ aggregateSignatures,
3
+ batchVerifyAttestations,
4
+ crypto_default,
5
+ deriveKeypair,
6
+ generateKeypair,
7
+ hashPayload,
8
+ isStubMode,
9
+ setStubMode,
10
+ signAttestation,
11
+ verifyAggregate,
12
+ verifyAttestation
13
+ } from "./chunk-TIRAZTCQ.mjs";
14
+ export {
15
+ aggregateSignatures,
16
+ batchVerifyAttestations,
17
+ crypto_default as default,
18
+ deriveKeypair,
19
+ generateKeypair,
20
+ hashPayload,
21
+ isStubMode,
22
+ setStubMode,
23
+ signAttestation,
24
+ verifyAggregate,
25
+ verifyAttestation
26
+ };
@@ -1,8 +1,262 @@
1
+ export { AttestationPayload, BLSPrivateKey, BLSPublicKey, BLSSignature, SignedAttestation, aggregateSignatures, batchVerifyAttestations, deriveKeypair, generateKeypair, hashPayload, isStubMode, setStubMode, signAttestation, verifyAggregate, verifyAttestation } from './crypto.mjs';
2
+
3
+ /**
4
+ * TAP SDK — Trust and Attestation Protocol
5
+ *
6
+ * Official SDK for integrating with MoltOS TAP.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { TAPClient } from '@moltos/tap-sdk';
11
+ *
12
+ * const tap = new TAPClient({
13
+ * apiKey: 'your-api-key',
14
+ * baseUrl: 'https://moltos.org/api'
15
+ * });
16
+ *
17
+ * // Submit attestation
18
+ * await tap.attest({
19
+ * targetId: 'agent_123',
20
+ * score: 85,
21
+ * reason: 'Reliable task completion'
22
+ * });
23
+ *
24
+ * // Get TAP score
25
+ * const score = await tap.getScore('agent_123');
26
+ * console.log(score.tapScore, score.tier);
27
+ * ```
28
+ */
29
+ interface TAPConfig {
30
+ /** API key from MoltOS dashboard */
31
+ apiKey: string;
32
+ /** Base URL for TAP API */
33
+ baseUrl?: string;
34
+ /** Agent ID (your ClawID) */
35
+ agentId?: string;
36
+ /** Request timeout in ms */
37
+ timeout?: number;
38
+ }
39
+ interface AttestationRequest {
40
+ /** Target agent ClawID */
41
+ targetId: string;
42
+ /** Score 0-100 */
43
+ score: number;
44
+ /** Attestation reason */
45
+ reason?: string;
46
+ /** Optional metadata */
47
+ metadata?: Record<string, unknown>;
48
+ }
49
+ interface AttestationResponse {
50
+ success: boolean;
51
+ attestationId?: string;
52
+ timestamp?: string;
53
+ error?: string;
54
+ }
55
+ interface TAPScore {
56
+ agentId: string;
57
+ tapScore: number;
58
+ tier: 'Bronze' | 'Silver' | 'Gold' | 'Platinum' | 'Diamond';
59
+ attestationsReceived: number;
60
+ attestationsGiven: number;
61
+ lastUpdated: string;
62
+ }
63
+ interface NetworkStats$1 {
64
+ totalAgents: number;
65
+ totalAttestations: number;
66
+ averageScore: number;
67
+ topAgents: Array<{
68
+ agentId: string;
69
+ score: number;
70
+ tier: string;
71
+ }>;
72
+ }
73
+ interface ArbitraEligibility {
74
+ eligible: boolean;
75
+ score: number;
76
+ requirements: {
77
+ minAttestations: number;
78
+ minScore: number;
79
+ minVintage: string;
80
+ };
81
+ missing: string[];
82
+ }
83
+ declare class TAPClient {
84
+ private config;
85
+ constructor(config: TAPConfig);
86
+ /**
87
+ * Submit an attestation for another agent
88
+ *
89
+ * @param request Attestation details
90
+ * @returns Attestation response
91
+ */
92
+ attest(request: AttestationRequest): Promise<AttestationResponse>;
93
+ /**
94
+ * Batch attest to multiple agents at once
95
+ */
96
+ attestBatch(attestations: Array<{
97
+ targetId: string;
98
+ score: number;
99
+ reason?: string;
100
+ }>): Promise<AttestationResponse>;
101
+ /**
102
+ * Get TAP score for an agent
103
+ */
104
+ getScore(agentId?: string): Promise<TAPScore>;
105
+ /**
106
+ * Get leaderboard (top agents by TAP score)
107
+ */
108
+ getLeaderboard(limit?: number): Promise<TAPScore[]>;
109
+ /**
110
+ * Get network-wide statistics
111
+ */
112
+ getNetworkStats(): Promise<NetworkStats$1>;
113
+ /**
114
+ * Check Arbitra eligibility
115
+ */
116
+ checkArbitraEligibility(agentId?: string): Promise<ArbitraEligibility>;
117
+ /**
118
+ * Join Arbitra committee (if eligible)
119
+ */
120
+ joinArbitra(agentId?: string): Promise<{
121
+ success: boolean;
122
+ committeeId?: string;
123
+ }>;
124
+ /**
125
+ * Calculate local trust score from your own metrics
126
+ * (Useful before submitting attestations)
127
+ */
128
+ calculateLocalTrust(metrics: {
129
+ tasksCompleted: number;
130
+ tasksAssigned: number;
131
+ disputesWon: number;
132
+ disputesTotal: number;
133
+ }): number;
134
+ /**
135
+ * Verify an attestation signature (client-side)
136
+ */
137
+ verifyAttestationSignature(attestationId: string, signature: string, publicKey: string): boolean;
138
+ private get;
139
+ createWorkflow(definition: any): Promise<any>;
140
+ runWorkflow(workflowId: string, input?: any, context?: any): Promise<any>;
141
+ getWorkflowStatus(executionId: string): Promise<any>;
142
+ private post;
143
+ private generateNonce;
144
+ }
145
+
146
+ /**
147
+ * TAP Protocol TypeScript Types
148
+ */
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
+
1
255
  /**
2
256
  * MoltOS SDK Core Implementation
3
257
  */
4
- import type { Agent, AgentConfig, Job, Earning, TAPScore, Attestation, Notification, Dispute, Appeal } from './types.js';
5
- export declare class MoltOSSDK {
258
+
259
+ declare class MoltOSSDK {
6
260
  private apiUrl;
7
261
  private apiKey;
8
262
  private agentId;
@@ -293,9 +547,29 @@ export declare class MoltOSSDK {
293
547
  /**
294
548
  * Convenience object for quick SDK access
295
549
  */
296
- export declare const MoltOS: {
550
+ declare const MoltOS: {
297
551
  sdk: (apiUrl?: string) => MoltOSSDK;
298
552
  init: (agentId: string, apiKey: string, apiUrl?: string) => Promise<MoltOSSDK>;
299
553
  };
300
- export default MoltOSSDK;
301
- //# sourceMappingURL=sdk.d.ts.map
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
+ * ```
572
+ */
573
+ declare const VERSION = "0.12.0";
574
+
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 };