@highway1/core 0.1.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.d.ts +920 -0
- package/dist/index.js +1876 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,920 @@
|
|
|
1
|
+
import { Libp2p } from 'libp2p';
|
|
2
|
+
import { PrivateKey } from '@libp2p/interface';
|
|
3
|
+
import { Level } from 'level';
|
|
4
|
+
|
|
5
|
+
interface KeyPair {
|
|
6
|
+
publicKey: Uint8Array;
|
|
7
|
+
privateKey: Uint8Array;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Generate a new Ed25519 key pair
|
|
11
|
+
*/
|
|
12
|
+
declare function generateKeyPair(): Promise<KeyPair>;
|
|
13
|
+
/**
|
|
14
|
+
* Sign a message with a private key
|
|
15
|
+
*/
|
|
16
|
+
declare function sign(message: Uint8Array, privateKey: Uint8Array): Promise<Uint8Array>;
|
|
17
|
+
/**
|
|
18
|
+
* Verify a signature
|
|
19
|
+
*/
|
|
20
|
+
declare function verify(signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array): Promise<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* Export key pair to JSON format
|
|
23
|
+
*/
|
|
24
|
+
declare function exportKeyPair(keyPair: KeyPair): {
|
|
25
|
+
publicKey: string;
|
|
26
|
+
privateKey: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Import key pair from JSON format
|
|
30
|
+
*/
|
|
31
|
+
declare function importKeyPair(exported: {
|
|
32
|
+
publicKey: string;
|
|
33
|
+
privateKey: string;
|
|
34
|
+
}): KeyPair;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Derive a did:clawiverse DID from a public key
|
|
38
|
+
* Format: did:clawiverse:<base58btc-encoded-pubkey>
|
|
39
|
+
*/
|
|
40
|
+
declare function deriveDID(publicKey: Uint8Array): string;
|
|
41
|
+
/**
|
|
42
|
+
* Extract public key from a did:clawiverse DID
|
|
43
|
+
*/
|
|
44
|
+
declare function extractPublicKey(did: string): Uint8Array;
|
|
45
|
+
/**
|
|
46
|
+
* Validate a did:clawiverse DID format
|
|
47
|
+
*/
|
|
48
|
+
declare function validateDID(did: string): boolean;
|
|
49
|
+
|
|
50
|
+
interface SignedMessage {
|
|
51
|
+
payload: Uint8Array;
|
|
52
|
+
signature: Uint8Array;
|
|
53
|
+
signer: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Sign a message and return a signed message object
|
|
57
|
+
*/
|
|
58
|
+
declare function signMessage(payload: Uint8Array, privateKey: Uint8Array, publicKey: Uint8Array): Promise<SignedMessage>;
|
|
59
|
+
/**
|
|
60
|
+
* Verify a signed message
|
|
61
|
+
*/
|
|
62
|
+
declare function verifyMessage(signedMessage: SignedMessage, expectedPublicKey: Uint8Array): Promise<boolean>;
|
|
63
|
+
|
|
64
|
+
interface TransportConfig {
|
|
65
|
+
keyPair?: KeyPair;
|
|
66
|
+
listenAddresses?: string[];
|
|
67
|
+
bootstrapPeers?: string[];
|
|
68
|
+
enableDHT?: boolean;
|
|
69
|
+
/** Allow private/local addresses in DHT routing (required for local testing) */
|
|
70
|
+
allowPrivateAddresses?: boolean;
|
|
71
|
+
/** Run as a relay server so NAT'd agents can receive messages through this node */
|
|
72
|
+
enableRelay?: boolean;
|
|
73
|
+
/** libp2p PrivateKey for persistent PeerID (from @libp2p/crypto) */
|
|
74
|
+
privateKey?: PrivateKey;
|
|
75
|
+
}
|
|
76
|
+
interface ClawiverseNode {
|
|
77
|
+
libp2p: Libp2p;
|
|
78
|
+
start: () => Promise<void>;
|
|
79
|
+
stop: () => Promise<void>;
|
|
80
|
+
getMultiaddrs: () => string[];
|
|
81
|
+
getPeerId: () => string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Create a Clawiverse transport node with libp2p
|
|
85
|
+
*/
|
|
86
|
+
declare function createNode(config: TransportConfig): Promise<ClawiverseNode>;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Trust Score System
|
|
90
|
+
*
|
|
91
|
+
* Tracks agent reputation based on interactions, endorsements,
|
|
92
|
+
* and network behavior.
|
|
93
|
+
*/
|
|
94
|
+
/**
|
|
95
|
+
* Trust Score Metrics
|
|
96
|
+
*/
|
|
97
|
+
interface TrustScore {
|
|
98
|
+
interactionScore: number;
|
|
99
|
+
endorsements: number;
|
|
100
|
+
completionRate: number;
|
|
101
|
+
responseTime: number;
|
|
102
|
+
uptime: number;
|
|
103
|
+
lastUpdated: number;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Interaction Record
|
|
107
|
+
*/
|
|
108
|
+
interface Interaction {
|
|
109
|
+
agentDid: string;
|
|
110
|
+
timestamp: number;
|
|
111
|
+
type: 'message' | 'task' | 'query';
|
|
112
|
+
success: boolean;
|
|
113
|
+
responseTime: number;
|
|
114
|
+
rating?: number;
|
|
115
|
+
feedback?: string;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Interaction Statistics
|
|
119
|
+
*/
|
|
120
|
+
interface InteractionStats {
|
|
121
|
+
totalInteractions: number;
|
|
122
|
+
successRate: number;
|
|
123
|
+
avgResponseTime: number;
|
|
124
|
+
lastInteraction: number;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Trust Metrics Calculator
|
|
128
|
+
*/
|
|
129
|
+
declare class TrustMetrics {
|
|
130
|
+
/**
|
|
131
|
+
* Calculate trust score from interaction history
|
|
132
|
+
*/
|
|
133
|
+
calculateScore(stats: InteractionStats, endorsements: number, uptime: number): TrustScore;
|
|
134
|
+
/**
|
|
135
|
+
* Calculate overall trust level (0-1)
|
|
136
|
+
*/
|
|
137
|
+
calculateOverallTrust(score: TrustScore): number;
|
|
138
|
+
/**
|
|
139
|
+
* Get trust level category
|
|
140
|
+
*/
|
|
141
|
+
getTrustLevel(score: TrustScore): 'new' | 'low' | 'medium' | 'high' | 'trusted';
|
|
142
|
+
/**
|
|
143
|
+
* Check if agent should be rate limited
|
|
144
|
+
*/
|
|
145
|
+
shouldRateLimit(score: TrustScore, agentAge: number): boolean;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Default trust score for new agents
|
|
149
|
+
*/
|
|
150
|
+
declare function createDefaultTrustScore(): TrustScore;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Enhanced Agent Card Types for Phase 2
|
|
154
|
+
*
|
|
155
|
+
* Adds structured capabilities, JSON-LD support, and trust metrics
|
|
156
|
+
*/
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Capability Parameter Definition
|
|
160
|
+
*/
|
|
161
|
+
interface CapabilityParameter {
|
|
162
|
+
name: string;
|
|
163
|
+
type: 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
164
|
+
required: boolean;
|
|
165
|
+
description?: string;
|
|
166
|
+
enum?: string[];
|
|
167
|
+
default?: unknown;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Structured Capability Definition
|
|
171
|
+
*/
|
|
172
|
+
interface Capability {
|
|
173
|
+
'@type'?: string;
|
|
174
|
+
id: string;
|
|
175
|
+
name: string;
|
|
176
|
+
description: string;
|
|
177
|
+
parameters?: CapabilityParameter[];
|
|
178
|
+
metadata?: Record<string, unknown>;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Enhanced Agent Card with JSON-LD support
|
|
182
|
+
*/
|
|
183
|
+
interface AgentCard {
|
|
184
|
+
'@context'?: string[];
|
|
185
|
+
did: string;
|
|
186
|
+
name: string;
|
|
187
|
+
description: string;
|
|
188
|
+
version: string;
|
|
189
|
+
capabilities: Capability[];
|
|
190
|
+
endpoints: string[];
|
|
191
|
+
peerId?: string;
|
|
192
|
+
trust?: TrustScore;
|
|
193
|
+
metadata?: Record<string, unknown>;
|
|
194
|
+
timestamp: number;
|
|
195
|
+
signature: string;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Legacy Agent Card (Phase 1 compatibility)
|
|
199
|
+
*/
|
|
200
|
+
interface LegacyAgentCard {
|
|
201
|
+
did: string;
|
|
202
|
+
name: string;
|
|
203
|
+
description: string;
|
|
204
|
+
version: string;
|
|
205
|
+
capabilities: string[];
|
|
206
|
+
endpoints: string[];
|
|
207
|
+
peerId?: string;
|
|
208
|
+
metadata?: Record<string, unknown>;
|
|
209
|
+
timestamp: number;
|
|
210
|
+
signature: string;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Check if card is legacy format
|
|
214
|
+
*/
|
|
215
|
+
declare function isLegacyCard(card: AgentCard | LegacyAgentCard): card is LegacyAgentCard;
|
|
216
|
+
/**
|
|
217
|
+
* Convert legacy card to new format
|
|
218
|
+
*/
|
|
219
|
+
declare function upgradeLegacyCard(legacy: LegacyAgentCard): AgentCard;
|
|
220
|
+
/**
|
|
221
|
+
* Convert new card to legacy format (for backward compatibility)
|
|
222
|
+
*/
|
|
223
|
+
declare function downgradeToLegacyCard(card: AgentCard): LegacyAgentCard;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Create a new Agent Card (Phase 2 format with structured capabilities)
|
|
227
|
+
*/
|
|
228
|
+
declare function createAgentCard(did: string, name: string, description: string, capabilities: Capability[], endpoints?: string[], peerId?: string, metadata?: Record<string, unknown>): Omit<AgentCard, 'signature'>;
|
|
229
|
+
/**
|
|
230
|
+
* Create a legacy Agent Card (Phase 1 format with string capabilities)
|
|
231
|
+
* For backward compatibility
|
|
232
|
+
*/
|
|
233
|
+
declare function createLegacyAgentCard(did: string, name: string, description: string, capabilities: string[], endpoints?: string[], peerId?: string, metadata?: Record<string, unknown>): Omit<LegacyAgentCard, 'signature'>;
|
|
234
|
+
/**
|
|
235
|
+
* Validate an Agent Card structure (supports both Phase 1 and Phase 2 formats)
|
|
236
|
+
*/
|
|
237
|
+
declare function validateAgentCard(card: unknown): card is AgentCard | LegacyAgentCard;
|
|
238
|
+
/**
|
|
239
|
+
* Sign an Agent Card
|
|
240
|
+
*/
|
|
241
|
+
declare function signAgentCard(card: Omit<AgentCard, 'signature'>, signFn: (data: Uint8Array) => Promise<Uint8Array>): Promise<AgentCard>;
|
|
242
|
+
/**
|
|
243
|
+
* Verify an Agent Card signature
|
|
244
|
+
*/
|
|
245
|
+
declare function verifyAgentCard(card: AgentCard, verifyFn: (signature: Uint8Array, data: Uint8Array) => Promise<boolean>): Promise<boolean>;
|
|
246
|
+
/**
|
|
247
|
+
* Check if an Agent Card matches a capability query
|
|
248
|
+
* Supports both Phase 1 (string[]) and Phase 2 (Capability[]) formats
|
|
249
|
+
*/
|
|
250
|
+
declare function matchesCapability(card: AgentCard | LegacyAgentCard, capability: string): boolean;
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* JSON-LD Schema Definitions for Agent Cards
|
|
254
|
+
*
|
|
255
|
+
* Defines the Clawiverse vocabulary and integrates with Schema.org
|
|
256
|
+
* for semantic interoperability.
|
|
257
|
+
*/
|
|
258
|
+
declare const CLAWIVERSE_CONTEXT = "https://clawiverse.org/context/v1";
|
|
259
|
+
declare const SCHEMA_ORG_CONTEXT = "https://schema.org";
|
|
260
|
+
/**
|
|
261
|
+
* Clawiverse JSON-LD Context
|
|
262
|
+
* Defines the vocabulary for Agent Cards and Capabilities
|
|
263
|
+
*/
|
|
264
|
+
declare const clawiverseContext: {
|
|
265
|
+
'@context': {
|
|
266
|
+
'@vocab': string;
|
|
267
|
+
schema: string;
|
|
268
|
+
AgentCard: string;
|
|
269
|
+
Capability: string;
|
|
270
|
+
did: string;
|
|
271
|
+
name: string;
|
|
272
|
+
description: string;
|
|
273
|
+
version: string;
|
|
274
|
+
capabilities: {
|
|
275
|
+
'@id': string;
|
|
276
|
+
'@type': string;
|
|
277
|
+
'@container': string;
|
|
278
|
+
};
|
|
279
|
+
endpoints: {
|
|
280
|
+
'@id': string;
|
|
281
|
+
'@container': string;
|
|
282
|
+
};
|
|
283
|
+
peerId: string;
|
|
284
|
+
trust: string;
|
|
285
|
+
metadata: string;
|
|
286
|
+
timestamp: string;
|
|
287
|
+
signature: string;
|
|
288
|
+
parameters: {
|
|
289
|
+
'@id': string;
|
|
290
|
+
'@container': string;
|
|
291
|
+
};
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
/**
|
|
295
|
+
* Capability Type Definitions
|
|
296
|
+
* Common capability types with semantic meaning
|
|
297
|
+
*/
|
|
298
|
+
declare const CapabilityTypes: {
|
|
299
|
+
readonly TRANSLATION: "TranslationService";
|
|
300
|
+
readonly CODE_REVIEW: "CodeReviewService";
|
|
301
|
+
readonly DATA_ANALYSIS: "DataAnalysisService";
|
|
302
|
+
readonly TEXT_GENERATION: "TextGenerationService";
|
|
303
|
+
readonly IMAGE_GENERATION: "ImageGenerationService";
|
|
304
|
+
readonly SEARCH: "SearchService";
|
|
305
|
+
readonly COMPUTATION: "ComputationService";
|
|
306
|
+
readonly STORAGE: "StorageService";
|
|
307
|
+
readonly MESSAGING: "MessagingService";
|
|
308
|
+
readonly AUTHENTICATION: "AuthenticationService";
|
|
309
|
+
};
|
|
310
|
+
/**
|
|
311
|
+
* Parameter Type Definitions
|
|
312
|
+
*/
|
|
313
|
+
declare const ParameterTypes: {
|
|
314
|
+
readonly STRING: "string";
|
|
315
|
+
readonly NUMBER: "number";
|
|
316
|
+
readonly BOOLEAN: "boolean";
|
|
317
|
+
readonly OBJECT: "object";
|
|
318
|
+
readonly ARRAY: "array";
|
|
319
|
+
};
|
|
320
|
+
/**
|
|
321
|
+
* Get JSON-LD context for Agent Card
|
|
322
|
+
*/
|
|
323
|
+
declare function getAgentCardContext(): string[];
|
|
324
|
+
/**
|
|
325
|
+
* Validate JSON-LD context
|
|
326
|
+
*/
|
|
327
|
+
declare function isValidContext(context: unknown): boolean;
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Agent Card Encoder - Dual Encoding Support
|
|
331
|
+
*
|
|
332
|
+
* Provides bidirectional conversion between:
|
|
333
|
+
* - CBOR (compact binary) for DHT storage
|
|
334
|
+
* - JSON-LD (semantic) for Web publishing
|
|
335
|
+
*/
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Encode Agent Card as CBOR for DHT storage
|
|
339
|
+
*/
|
|
340
|
+
declare function encodeForDHT(card: AgentCard): Uint8Array;
|
|
341
|
+
/**
|
|
342
|
+
* Encode Agent Card as JSON-LD for Web publishing
|
|
343
|
+
*/
|
|
344
|
+
declare function encodeForWeb(card: AgentCard): string;
|
|
345
|
+
/**
|
|
346
|
+
* Decode Agent Card from CBOR
|
|
347
|
+
*/
|
|
348
|
+
declare function decodeFromCBOR(data: Uint8Array): AgentCard;
|
|
349
|
+
/**
|
|
350
|
+
* Decode Agent Card from JSON-LD
|
|
351
|
+
*/
|
|
352
|
+
declare function decodeFromJSON(json: string): AgentCard;
|
|
353
|
+
/**
|
|
354
|
+
* Auto-detect format and decode
|
|
355
|
+
*/
|
|
356
|
+
declare function decodeAgentCard(data: Uint8Array | string): AgentCard;
|
|
357
|
+
/**
|
|
358
|
+
* Calculate encoded size for comparison
|
|
359
|
+
*/
|
|
360
|
+
declare function getEncodedSize(card: AgentCard): {
|
|
361
|
+
cbor: number;
|
|
362
|
+
json: number;
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Search Index for Agent Discovery
|
|
367
|
+
*
|
|
368
|
+
* Maintains a local index of discovered agents for fast semantic search
|
|
369
|
+
*/
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Semantic Query Interface
|
|
373
|
+
*/
|
|
374
|
+
interface SemanticQuery {
|
|
375
|
+
text?: string;
|
|
376
|
+
capability?: string;
|
|
377
|
+
filters?: {
|
|
378
|
+
language?: string;
|
|
379
|
+
minTrustScore?: number;
|
|
380
|
+
maxCost?: number;
|
|
381
|
+
tags?: string[];
|
|
382
|
+
};
|
|
383
|
+
limit?: number;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Search Result with Score
|
|
387
|
+
*/
|
|
388
|
+
interface SearchResult {
|
|
389
|
+
card: AgentCard;
|
|
390
|
+
score: number;
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Search Index Implementation
|
|
394
|
+
*/
|
|
395
|
+
declare class SearchIndex {
|
|
396
|
+
private cards;
|
|
397
|
+
private lunrIndex?;
|
|
398
|
+
private fuse?;
|
|
399
|
+
private needsRebuild;
|
|
400
|
+
/**
|
|
401
|
+
* Add or update an Agent Card in the index
|
|
402
|
+
*/
|
|
403
|
+
indexAgentCard(card: AgentCard): void;
|
|
404
|
+
/**
|
|
405
|
+
* Remove an Agent Card from the index
|
|
406
|
+
*/
|
|
407
|
+
removeAgentCard(did: string): void;
|
|
408
|
+
/**
|
|
409
|
+
* Search for agents matching a query
|
|
410
|
+
*/
|
|
411
|
+
search(query: SemanticQuery): SearchResult[];
|
|
412
|
+
/**
|
|
413
|
+
* Get all indexed cards
|
|
414
|
+
*/
|
|
415
|
+
getAllCards(): AgentCard[];
|
|
416
|
+
/**
|
|
417
|
+
* Clear the index
|
|
418
|
+
*/
|
|
419
|
+
clear(): void;
|
|
420
|
+
/**
|
|
421
|
+
* Get index size
|
|
422
|
+
*/
|
|
423
|
+
size(): number;
|
|
424
|
+
/**
|
|
425
|
+
* Rebuild search indexes
|
|
426
|
+
*/
|
|
427
|
+
private rebuild;
|
|
428
|
+
/**
|
|
429
|
+
* Search by text using Lunr
|
|
430
|
+
*/
|
|
431
|
+
private searchByText;
|
|
432
|
+
/**
|
|
433
|
+
* Search by capability using Fuse
|
|
434
|
+
*/
|
|
435
|
+
private searchByCapability;
|
|
436
|
+
/**
|
|
437
|
+
* Apply filters to search results
|
|
438
|
+
*/
|
|
439
|
+
private applyFilters;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
interface ResolvedDID {
|
|
443
|
+
peerId: string;
|
|
444
|
+
multiaddrs: string[];
|
|
445
|
+
}
|
|
446
|
+
interface DHTOperations {
|
|
447
|
+
publishAgentCard: (card: AgentCard) => Promise<void>;
|
|
448
|
+
queryAgentCard: (did: string) => Promise<AgentCard | null>;
|
|
449
|
+
queryByCapability: (capability: string) => Promise<AgentCard[]>;
|
|
450
|
+
searchSemantic: (query: SemanticQuery) => Promise<AgentCard[]>;
|
|
451
|
+
resolveDID: (did: string) => Promise<ResolvedDID | null>;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Create DHT operations for a libp2p node
|
|
455
|
+
*/
|
|
456
|
+
declare function createDHTOperations(libp2p: Libp2p): DHTOperations;
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Capability Matcher
|
|
460
|
+
*
|
|
461
|
+
* Matches semantic queries against agent capabilities
|
|
462
|
+
*/
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Capability Matcher
|
|
466
|
+
*/
|
|
467
|
+
declare class CapabilityMatcher {
|
|
468
|
+
/**
|
|
469
|
+
* Match a query against a capability
|
|
470
|
+
* Returns a score between 0 and 1
|
|
471
|
+
*/
|
|
472
|
+
match(query: SemanticQuery, capability: Capability): number;
|
|
473
|
+
/**
|
|
474
|
+
* Extract keywords from natural language text
|
|
475
|
+
*/
|
|
476
|
+
extractKeywords(text: string): string[];
|
|
477
|
+
/**
|
|
478
|
+
* Match keywords against capability
|
|
479
|
+
*/
|
|
480
|
+
matchKeywords(keywords: string[], capability: Capability): number;
|
|
481
|
+
/**
|
|
482
|
+
* Check if query matches capability type hierarchy
|
|
483
|
+
*/
|
|
484
|
+
matchesType(query: string, type: string): boolean;
|
|
485
|
+
/**
|
|
486
|
+
* Fuzzy string matching using Levenshtein distance
|
|
487
|
+
*/
|
|
488
|
+
private fuzzyMatch;
|
|
489
|
+
/**
|
|
490
|
+
* Calculate Levenshtein distance between two strings
|
|
491
|
+
*/
|
|
492
|
+
private levenshteinDistance;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Semantic Search Engine
|
|
497
|
+
*
|
|
498
|
+
* Provides intelligent agent discovery through semantic search
|
|
499
|
+
* with local-first strategy and network fallback
|
|
500
|
+
*/
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Semantic Search Engine
|
|
504
|
+
*/
|
|
505
|
+
declare class SemanticSearchEngine {
|
|
506
|
+
private dht?;
|
|
507
|
+
private index;
|
|
508
|
+
private matcher;
|
|
509
|
+
constructor(dht?: DHTOperations | undefined);
|
|
510
|
+
/**
|
|
511
|
+
* Main search interface
|
|
512
|
+
* Local-first with network fallback
|
|
513
|
+
*/
|
|
514
|
+
search(query: SemanticQuery): Promise<AgentCard[]>;
|
|
515
|
+
/**
|
|
516
|
+
* Index an Agent Card for local search
|
|
517
|
+
*/
|
|
518
|
+
indexAgentCard(card: AgentCard): void;
|
|
519
|
+
/**
|
|
520
|
+
* Remove an Agent Card from local index
|
|
521
|
+
*/
|
|
522
|
+
removeAgentCard(did: string): void;
|
|
523
|
+
/**
|
|
524
|
+
* Get all indexed cards
|
|
525
|
+
*/
|
|
526
|
+
getAllIndexedCards(): AgentCard[];
|
|
527
|
+
/**
|
|
528
|
+
* Clear local index
|
|
529
|
+
*/
|
|
530
|
+
clearIndex(): void;
|
|
531
|
+
/**
|
|
532
|
+
* Get index size
|
|
533
|
+
*/
|
|
534
|
+
getIndexSize(): number;
|
|
535
|
+
/**
|
|
536
|
+
* Search network via DHT
|
|
537
|
+
*/
|
|
538
|
+
private searchNetwork;
|
|
539
|
+
/**
|
|
540
|
+
* Merge local and network results, removing duplicates
|
|
541
|
+
*/
|
|
542
|
+
private mergeResults;
|
|
543
|
+
/**
|
|
544
|
+
* Score a card against a query
|
|
545
|
+
*/
|
|
546
|
+
private scoreCard;
|
|
547
|
+
/**
|
|
548
|
+
* Extract primary capability from natural language text
|
|
549
|
+
*/
|
|
550
|
+
private extractPrimaryCapability;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Create a semantic search engine
|
|
554
|
+
*/
|
|
555
|
+
declare function createSemanticSearch(dht?: DHTOperations): SemanticSearchEngine;
|
|
556
|
+
|
|
557
|
+
interface MessageEnvelope {
|
|
558
|
+
id: string;
|
|
559
|
+
from: string;
|
|
560
|
+
to: string;
|
|
561
|
+
type: 'request' | 'response' | 'notification';
|
|
562
|
+
protocol: string;
|
|
563
|
+
payload: unknown;
|
|
564
|
+
timestamp: number;
|
|
565
|
+
signature: string;
|
|
566
|
+
replyTo?: string;
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Create a message envelope
|
|
570
|
+
*/
|
|
571
|
+
declare function createEnvelope(from: string, to: string, type: 'request' | 'response' | 'notification', protocol: string, payload: unknown, replyTo?: string): Omit<MessageEnvelope, 'signature'>;
|
|
572
|
+
/**
|
|
573
|
+
* Sign a message envelope
|
|
574
|
+
*/
|
|
575
|
+
declare function signEnvelope(envelope: Omit<MessageEnvelope, 'signature'>, signFn: (data: Uint8Array) => Promise<Uint8Array>): Promise<MessageEnvelope>;
|
|
576
|
+
/**
|
|
577
|
+
* Verify a message envelope signature
|
|
578
|
+
*/
|
|
579
|
+
declare function verifyEnvelope(envelope: MessageEnvelope, verifyFn: (signature: Uint8Array, data: Uint8Array) => Promise<boolean>): Promise<boolean>;
|
|
580
|
+
/**
|
|
581
|
+
* Validate message envelope structure
|
|
582
|
+
*/
|
|
583
|
+
declare function validateEnvelope(msg: unknown): msg is MessageEnvelope;
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Encode a message envelope to CBOR
|
|
587
|
+
*/
|
|
588
|
+
declare function encodeMessage(envelope: MessageEnvelope): Uint8Array;
|
|
589
|
+
/**
|
|
590
|
+
* Decode a CBOR message to envelope
|
|
591
|
+
*/
|
|
592
|
+
declare function decodeMessage(data: Uint8Array): MessageEnvelope;
|
|
593
|
+
/**
|
|
594
|
+
* Encode message to JSON (for debugging/logging)
|
|
595
|
+
*/
|
|
596
|
+
declare function encodeMessageJSON(envelope: MessageEnvelope): string;
|
|
597
|
+
/**
|
|
598
|
+
* Decode JSON message to envelope
|
|
599
|
+
*/
|
|
600
|
+
declare function decodeMessageJSON(json: string): MessageEnvelope;
|
|
601
|
+
|
|
602
|
+
type MessageHandler = (envelope: MessageEnvelope) => Promise<MessageEnvelope | void>;
|
|
603
|
+
interface PeerHint {
|
|
604
|
+
peerId: string;
|
|
605
|
+
multiaddrs: string[];
|
|
606
|
+
}
|
|
607
|
+
interface MessageRouter {
|
|
608
|
+
registerHandler: (protocol: string, handler: MessageHandler) => void;
|
|
609
|
+
unregisterHandler: (protocol: string) => void;
|
|
610
|
+
sendMessage: (envelope: MessageEnvelope, peerHint?: PeerHint) => Promise<MessageEnvelope | void>;
|
|
611
|
+
start: () => Promise<void>;
|
|
612
|
+
stop: () => Promise<void>;
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Create a message router for a libp2p node.
|
|
616
|
+
* When dht is provided, sendMessage can resolve DIDs to peer addresses via DHT lookup.
|
|
617
|
+
*/
|
|
618
|
+
declare function createMessageRouter(libp2p: Libp2p, verifyFn: (signature: Uint8Array, data: Uint8Array) => Promise<boolean>, dht?: DHTOperations): MessageRouter;
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Sybil Defense Mechanisms
|
|
622
|
+
*
|
|
623
|
+
* Protects the network from Sybil attacks through:
|
|
624
|
+
* - Entry cost (Hashcash challenges)
|
|
625
|
+
* - Progressive trust (rate limiting for new agents)
|
|
626
|
+
* - DHT region protection (prefer established peers)
|
|
627
|
+
*/
|
|
628
|
+
/**
|
|
629
|
+
* Hashcash Challenge
|
|
630
|
+
*/
|
|
631
|
+
interface Challenge {
|
|
632
|
+
did: string;
|
|
633
|
+
difficulty: number;
|
|
634
|
+
nonce: string;
|
|
635
|
+
timestamp: number;
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Challenge Solution
|
|
639
|
+
*/
|
|
640
|
+
interface ChallengeSolution {
|
|
641
|
+
challenge: Challenge;
|
|
642
|
+
solution: string;
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Peer Trust Level
|
|
646
|
+
*/
|
|
647
|
+
type PeerTrustLevel = 'new' | 'established' | 'trusted';
|
|
648
|
+
/**
|
|
649
|
+
* Sybil Defense Manager
|
|
650
|
+
*/
|
|
651
|
+
declare class SybilDefense {
|
|
652
|
+
private rateLimits;
|
|
653
|
+
private peerFirstSeen;
|
|
654
|
+
private readonly NEW_AGENT_WINDOW;
|
|
655
|
+
private readonly RATE_LIMIT_WINDOW;
|
|
656
|
+
private readonly MAX_REQUESTS_NEW;
|
|
657
|
+
private readonly ESTABLISHED_THRESHOLD;
|
|
658
|
+
/**
|
|
659
|
+
* Generate a Hashcash challenge for a new DID
|
|
660
|
+
*/
|
|
661
|
+
generateChallenge(did: string, difficulty?: number): Challenge;
|
|
662
|
+
/**
|
|
663
|
+
* Verify a Hashcash challenge solution
|
|
664
|
+
*/
|
|
665
|
+
verifyChallenge(solution: ChallengeSolution): boolean;
|
|
666
|
+
/**
|
|
667
|
+
* Check if an agent should be rate limited
|
|
668
|
+
*/
|
|
669
|
+
isRateLimited(did: string): boolean;
|
|
670
|
+
/**
|
|
671
|
+
* Record a request from an agent
|
|
672
|
+
*/
|
|
673
|
+
recordRequest(did: string): void;
|
|
674
|
+
/**
|
|
675
|
+
* Get peer trust level based on age
|
|
676
|
+
*/
|
|
677
|
+
getPeerTrustLevel(peerId: string): PeerTrustLevel;
|
|
678
|
+
/**
|
|
679
|
+
* Record first seen time for a peer
|
|
680
|
+
*/
|
|
681
|
+
recordPeerSeen(peerId: string): void;
|
|
682
|
+
/**
|
|
683
|
+
* Clean up old records
|
|
684
|
+
*/
|
|
685
|
+
cleanup(): void;
|
|
686
|
+
/**
|
|
687
|
+
* Generate a random nonce
|
|
688
|
+
*/
|
|
689
|
+
private generateNonce;
|
|
690
|
+
/**
|
|
691
|
+
* Count leading zero bits in a hash
|
|
692
|
+
*/
|
|
693
|
+
private countLeadingZeroBits;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* Interaction History Tracker
|
|
698
|
+
*
|
|
699
|
+
* Records and queries agent interaction history for trust scoring
|
|
700
|
+
*/
|
|
701
|
+
|
|
702
|
+
/**
|
|
703
|
+
* Interaction History Manager
|
|
704
|
+
*/
|
|
705
|
+
declare class InteractionHistory {
|
|
706
|
+
private db;
|
|
707
|
+
constructor(dbPath: string);
|
|
708
|
+
/**
|
|
709
|
+
* Open database connection
|
|
710
|
+
*/
|
|
711
|
+
open(): Promise<void>;
|
|
712
|
+
/**
|
|
713
|
+
* Close database connection
|
|
714
|
+
*/
|
|
715
|
+
close(): Promise<void>;
|
|
716
|
+
/**
|
|
717
|
+
* Record an interaction
|
|
718
|
+
*/
|
|
719
|
+
record(interaction: Interaction): Promise<void>;
|
|
720
|
+
/**
|
|
721
|
+
* Get interaction history for an agent
|
|
722
|
+
*/
|
|
723
|
+
getHistory(agentDid: string, limit?: number): Promise<Interaction[]>;
|
|
724
|
+
/**
|
|
725
|
+
* Get interaction statistics for an agent
|
|
726
|
+
*/
|
|
727
|
+
getStats(agentDid: string): Promise<InteractionStats>;
|
|
728
|
+
/**
|
|
729
|
+
* Get all agents with interaction history
|
|
730
|
+
*/
|
|
731
|
+
getAllAgents(): Promise<string[]>;
|
|
732
|
+
/**
|
|
733
|
+
* Delete all interactions for an agent
|
|
734
|
+
*/
|
|
735
|
+
deleteAgent(agentDid: string): Promise<void>;
|
|
736
|
+
/**
|
|
737
|
+
* Clean up old interactions (older than 90 days)
|
|
738
|
+
*/
|
|
739
|
+
cleanup(maxAge?: number): Promise<number>;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
/**
|
|
743
|
+
* Endorsement System
|
|
744
|
+
*
|
|
745
|
+
* Allows agents to endorse each other, building a web of trust
|
|
746
|
+
*/
|
|
747
|
+
|
|
748
|
+
/**
|
|
749
|
+
* Endorsement Record
|
|
750
|
+
*/
|
|
751
|
+
interface Endorsement {
|
|
752
|
+
from: string;
|
|
753
|
+
to: string;
|
|
754
|
+
score: number;
|
|
755
|
+
reason: string;
|
|
756
|
+
timestamp: number;
|
|
757
|
+
signature: string;
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Sign function type
|
|
761
|
+
*/
|
|
762
|
+
type SignFunction = (data: Uint8Array) => Promise<Uint8Array>;
|
|
763
|
+
/**
|
|
764
|
+
* Verify function type
|
|
765
|
+
*/
|
|
766
|
+
type VerifyFunction = (signature: Uint8Array, data: Uint8Array, publicKey: Uint8Array) => Promise<boolean>;
|
|
767
|
+
/**
|
|
768
|
+
* Endorsement Manager
|
|
769
|
+
*/
|
|
770
|
+
declare class EndorsementManager {
|
|
771
|
+
private db;
|
|
772
|
+
private getPublicKey;
|
|
773
|
+
constructor(db: Level<string, Endorsement>, getPublicKey: (did: string) => Promise<Uint8Array>);
|
|
774
|
+
/**
|
|
775
|
+
* Create an endorsement
|
|
776
|
+
*/
|
|
777
|
+
endorse(fromDid: string, toDid: string, score: number, reason: string, signFn: SignFunction): Promise<Endorsement>;
|
|
778
|
+
/**
|
|
779
|
+
* Verify endorsement signature
|
|
780
|
+
*/
|
|
781
|
+
verify(endorsement: Endorsement, verifyFn: VerifyFunction): Promise<boolean>;
|
|
782
|
+
/**
|
|
783
|
+
* Publish endorsement to local database
|
|
784
|
+
*/
|
|
785
|
+
publish(endorsement: Endorsement): Promise<void>;
|
|
786
|
+
/**
|
|
787
|
+
* Get all endorsements for an agent
|
|
788
|
+
*/
|
|
789
|
+
getEndorsements(agentDid: string): Promise<Endorsement[]>;
|
|
790
|
+
/**
|
|
791
|
+
* Get endorsements given by an agent
|
|
792
|
+
*/
|
|
793
|
+
getEndorsementsBy(fromDid: string): Promise<Endorsement[]>;
|
|
794
|
+
/**
|
|
795
|
+
* Calculate average endorsement score
|
|
796
|
+
*/
|
|
797
|
+
getAverageScore(agentDid: string): Promise<number>;
|
|
798
|
+
/**
|
|
799
|
+
* Delete an endorsement
|
|
800
|
+
*/
|
|
801
|
+
deleteEndorsement(fromDid: string, toDid: string): Promise<void>;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
/**
|
|
805
|
+
* Trust System Configuration
|
|
806
|
+
*/
|
|
807
|
+
interface TrustSystemConfig {
|
|
808
|
+
dbPath: string;
|
|
809
|
+
getPublicKey: (did: string) => Promise<Uint8Array>;
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Unified Trust System
|
|
813
|
+
*/
|
|
814
|
+
declare class TrustSystem {
|
|
815
|
+
private metrics;
|
|
816
|
+
private history;
|
|
817
|
+
private endorsements;
|
|
818
|
+
private sybilDefense;
|
|
819
|
+
private trustCache;
|
|
820
|
+
private readonly CACHE_TTL;
|
|
821
|
+
constructor(config: TrustSystemConfig);
|
|
822
|
+
/**
|
|
823
|
+
* Initialize the trust system
|
|
824
|
+
*/
|
|
825
|
+
start(): Promise<void>;
|
|
826
|
+
/**
|
|
827
|
+
* Shutdown the trust system
|
|
828
|
+
*/
|
|
829
|
+
stop(): Promise<void>;
|
|
830
|
+
/**
|
|
831
|
+
* Record an interaction
|
|
832
|
+
*/
|
|
833
|
+
recordInteraction(interaction: Interaction): Promise<void>;
|
|
834
|
+
/**
|
|
835
|
+
* Get trust score for an agent
|
|
836
|
+
*/
|
|
837
|
+
getTrustScore(agentDid: string): Promise<TrustScore>;
|
|
838
|
+
/**
|
|
839
|
+
* Create an endorsement
|
|
840
|
+
*/
|
|
841
|
+
endorse(fromDid: string, toDid: string, score: number, reason: string, signFn: SignFunction): Promise<Endorsement>;
|
|
842
|
+
/**
|
|
843
|
+
* Get endorsements for an agent
|
|
844
|
+
*/
|
|
845
|
+
getEndorsements(agentDid: string): Promise<Endorsement[]>;
|
|
846
|
+
/**
|
|
847
|
+
* Verify an endorsement
|
|
848
|
+
*/
|
|
849
|
+
verifyEndorsement(endorsement: Endorsement, verifyFn: VerifyFunction): Promise<boolean>;
|
|
850
|
+
/**
|
|
851
|
+
* Check if agent should be rate limited
|
|
852
|
+
*/
|
|
853
|
+
isRateLimited(agentDid: string): boolean;
|
|
854
|
+
/**
|
|
855
|
+
* Generate Sybil defense challenge
|
|
856
|
+
*/
|
|
857
|
+
generateChallenge(did: string, difficulty?: number): Challenge;
|
|
858
|
+
/**
|
|
859
|
+
* Verify Sybil defense challenge
|
|
860
|
+
*/
|
|
861
|
+
verifyChallenge(solution: any): boolean;
|
|
862
|
+
/**
|
|
863
|
+
* Get peer trust level
|
|
864
|
+
*/
|
|
865
|
+
getPeerTrustLevel(peerId: string): PeerTrustLevel;
|
|
866
|
+
/**
|
|
867
|
+
* Record peer seen
|
|
868
|
+
*/
|
|
869
|
+
recordPeerSeen(peerId: string): void;
|
|
870
|
+
/**
|
|
871
|
+
* Get interaction history
|
|
872
|
+
*/
|
|
873
|
+
getHistory(agentDid: string, limit?: number): Promise<Interaction[]>;
|
|
874
|
+
/**
|
|
875
|
+
* Clean up old data
|
|
876
|
+
*/
|
|
877
|
+
cleanup(): Promise<void>;
|
|
878
|
+
}
|
|
879
|
+
/**
|
|
880
|
+
* Create a trust system instance
|
|
881
|
+
*/
|
|
882
|
+
declare function createTrustSystem(config: TrustSystemConfig): TrustSystem;
|
|
883
|
+
|
|
884
|
+
declare enum LogLevel {
|
|
885
|
+
DEBUG = 0,
|
|
886
|
+
INFO = 1,
|
|
887
|
+
WARN = 2,
|
|
888
|
+
ERROR = 3
|
|
889
|
+
}
|
|
890
|
+
declare class Logger {
|
|
891
|
+
private level;
|
|
892
|
+
private prefix;
|
|
893
|
+
constructor(prefix: string, level?: LogLevel);
|
|
894
|
+
setLevel(level: LogLevel): void;
|
|
895
|
+
debug(message: string, ...args: unknown[]): void;
|
|
896
|
+
info(message: string, ...args: unknown[]): void;
|
|
897
|
+
warn(message: string, ...args: unknown[]): void;
|
|
898
|
+
error(message: string, ...args: unknown[]): void;
|
|
899
|
+
}
|
|
900
|
+
declare const createLogger: (prefix: string, level?: LogLevel) => Logger;
|
|
901
|
+
|
|
902
|
+
declare class ClawiverseError extends Error {
|
|
903
|
+
code: string;
|
|
904
|
+
details?: unknown | undefined;
|
|
905
|
+
constructor(message: string, code: string, details?: unknown | undefined);
|
|
906
|
+
}
|
|
907
|
+
declare class IdentityError extends ClawiverseError {
|
|
908
|
+
constructor(message: string, details?: unknown);
|
|
909
|
+
}
|
|
910
|
+
declare class TransportError extends ClawiverseError {
|
|
911
|
+
constructor(message: string, details?: unknown);
|
|
912
|
+
}
|
|
913
|
+
declare class DiscoveryError extends ClawiverseError {
|
|
914
|
+
constructor(message: string, details?: unknown);
|
|
915
|
+
}
|
|
916
|
+
declare class MessagingError extends ClawiverseError {
|
|
917
|
+
constructor(message: string, details?: unknown);
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
export { type AgentCard, CLAWIVERSE_CONTEXT, type Capability, CapabilityMatcher, type CapabilityParameter, CapabilityTypes, type Challenge, type ChallengeSolution, ClawiverseError, type ClawiverseNode, type DHTOperations, DiscoveryError, type Endorsement, EndorsementManager, IdentityError, type Interaction, InteractionHistory, type InteractionStats, type KeyPair, type LegacyAgentCard, LogLevel, Logger, type MessageEnvelope, type MessageHandler, type MessageRouter, MessagingError, ParameterTypes, type PeerHint, type PeerTrustLevel, type ResolvedDID, SCHEMA_ORG_CONTEXT, SearchIndex, type SearchResult, type SemanticQuery, SemanticSearchEngine, type SignFunction, type SignedMessage, SybilDefense, type TransportConfig, TransportError, TrustMetrics, type TrustScore, TrustSystem, type TrustSystemConfig, type VerifyFunction, clawiverseContext, createAgentCard, createDHTOperations, createDefaultTrustScore, createEnvelope, createLegacyAgentCard, createLogger, createMessageRouter, createNode, createSemanticSearch, createTrustSystem, decodeAgentCard, decodeFromCBOR, decodeFromJSON, decodeMessage, decodeMessageJSON, deriveDID, downgradeToLegacyCard, encodeForDHT, encodeForWeb, encodeMessage, encodeMessageJSON, exportKeyPair, extractPublicKey, generateKeyPair, getAgentCardContext, getEncodedSize, importKeyPair, isLegacyCard, isValidContext, matchesCapability, sign, signAgentCard, signEnvelope, signMessage, upgradeLegacyCard, validateAgentCard, validateDID, validateEnvelope, verify, verifyAgentCard, verifyEnvelope, verifyMessage };
|