@highway1/core 0.1.53 → 0.1.55
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/package.json +5 -18
- package/src/discovery/agent-card-encoder.ts +0 -119
- package/src/discovery/agent-card-schema.ts +0 -87
- package/src/discovery/agent-card-types.ts +0 -99
- package/src/discovery/agent-card.ts +0 -190
- package/src/discovery/bootstrap.ts +0 -63
- package/src/discovery/capability-matcher.ts +0 -167
- package/src/discovery/dht.ts +0 -310
- package/src/discovery/index.ts +0 -3
- package/src/discovery/relay-index.ts +0 -98
- package/src/discovery/search-index.ts +0 -247
- package/src/discovery/semantic-search.ts +0 -218
- package/src/identity/did.ts +0 -48
- package/src/identity/document.ts +0 -77
- package/src/identity/index.ts +0 -4
- package/src/identity/keys.ts +0 -79
- package/src/identity/signer.ts +0 -55
- package/src/index.ts +0 -39
- package/src/messaging/codec.ts +0 -47
- package/src/messaging/defense.ts +0 -236
- package/src/messaging/envelope.ts +0 -107
- package/src/messaging/index.ts +0 -8
- package/src/messaging/queue.ts +0 -181
- package/src/messaging/rate-limiter.ts +0 -85
- package/src/messaging/router.ts +0 -209
- package/src/messaging/storage.ts +0 -281
- package/src/messaging/types.ts +0 -149
- package/src/transport/connection.ts +0 -77
- package/src/transport/index.ts +0 -2
- package/src/transport/node.ts +0 -154
- package/src/transport/relay-client.ts +0 -437
- package/src/transport/relay-types.ts +0 -196
- package/src/trust/endorsement.ts +0 -167
- package/src/trust/index.ts +0 -194
- package/src/trust/interaction-history.ts +0 -155
- package/src/trust/sybil-defense.ts +0 -232
- package/src/trust/trust-score.ts +0 -136
- package/src/utils/errors.ts +0 -38
- package/src/utils/logger.ts +0 -48
package/src/messaging/types.ts
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Message Queue Types
|
|
3
|
-
*
|
|
4
|
-
* Types for message queue, storage, and filtering operations.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { MessageEnvelope } from './envelope.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Message direction
|
|
11
|
-
*/
|
|
12
|
-
export type MessageDirection = 'inbound' | 'outbound';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Message status
|
|
16
|
-
*/
|
|
17
|
-
export type MessageStatus = 'pending' | 'delivered' | 'failed' | 'archived';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Stored message with metadata
|
|
21
|
-
*/
|
|
22
|
-
export interface StoredMessage {
|
|
23
|
-
envelope: MessageEnvelope;
|
|
24
|
-
direction: MessageDirection;
|
|
25
|
-
status: MessageStatus;
|
|
26
|
-
receivedAt?: number;
|
|
27
|
-
sentAt?: number;
|
|
28
|
-
readAt?: number;
|
|
29
|
-
trustScore?: number;
|
|
30
|
-
error?: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Message filter for queries
|
|
35
|
-
*/
|
|
36
|
-
export interface MessageFilter {
|
|
37
|
-
fromDid?: string | string[];
|
|
38
|
-
toDid?: string | string[];
|
|
39
|
-
protocol?: string | string[];
|
|
40
|
-
minTrustScore?: number;
|
|
41
|
-
maxAge?: number; // milliseconds
|
|
42
|
-
type?: 'request' | 'response' | 'notification';
|
|
43
|
-
unreadOnly?: boolean;
|
|
44
|
-
status?: MessageStatus | MessageStatus[];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Pagination options
|
|
49
|
-
*/
|
|
50
|
-
export interface PaginationOptions {
|
|
51
|
-
limit?: number;
|
|
52
|
-
offset?: number;
|
|
53
|
-
startKey?: string; // For cursor-based pagination
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Paginated message results
|
|
58
|
-
*/
|
|
59
|
-
export interface MessagePage {
|
|
60
|
-
messages: StoredMessage[];
|
|
61
|
-
total: number;
|
|
62
|
-
hasMore: boolean;
|
|
63
|
-
nextKey?: string;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Blocklist entry
|
|
68
|
-
*/
|
|
69
|
-
export interface BlocklistEntry {
|
|
70
|
-
did: string;
|
|
71
|
-
reason: string;
|
|
72
|
-
blockedAt: number;
|
|
73
|
-
blockedBy: string; // Local agent DID
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Allowlist entry
|
|
78
|
-
*/
|
|
79
|
-
export interface AllowlistEntry {
|
|
80
|
-
did: string;
|
|
81
|
-
addedAt: number;
|
|
82
|
-
note?: string;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Seen cache entry (for deduplication)
|
|
87
|
-
*/
|
|
88
|
-
export interface SeenEntry {
|
|
89
|
-
messageId: string;
|
|
90
|
-
seenAt: number;
|
|
91
|
-
fromDid: string;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Rate limit state
|
|
96
|
-
*/
|
|
97
|
-
export interface RateLimitState {
|
|
98
|
-
did: string;
|
|
99
|
-
tokens: number;
|
|
100
|
-
lastRefill: number;
|
|
101
|
-
totalRequests: number;
|
|
102
|
-
firstSeen: number;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Defense check result
|
|
107
|
-
*/
|
|
108
|
-
export interface DefenseResult {
|
|
109
|
-
allowed: boolean;
|
|
110
|
-
reason?: 'blocked' | 'duplicate' | 'trust_too_low' | 'rate_limited' | 'invalid';
|
|
111
|
-
trustScore?: number;
|
|
112
|
-
remainingTokens?: number;
|
|
113
|
-
resetTime?: number;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Rate limit result
|
|
118
|
-
*/
|
|
119
|
-
export interface RateLimitResult {
|
|
120
|
-
allowed: boolean;
|
|
121
|
-
remaining: number;
|
|
122
|
-
resetTime: number;
|
|
123
|
-
limit: number;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Queue statistics
|
|
128
|
-
*/
|
|
129
|
-
export interface QueueStats {
|
|
130
|
-
inboxTotal: number;
|
|
131
|
-
inboxUnread: number;
|
|
132
|
-
outboxPending: number;
|
|
133
|
-
outboxFailed: number;
|
|
134
|
-
blockedAgents: number;
|
|
135
|
-
allowedAgents: number;
|
|
136
|
-
rateLimitedAgents: number;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Subscription callback
|
|
141
|
-
*/
|
|
142
|
-
export type MessageCallback = (message: StoredMessage) => void | Promise<void>;
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Subscription filter
|
|
146
|
-
*/
|
|
147
|
-
export interface SubscriptionFilter extends MessageFilter {
|
|
148
|
-
webhookUrl?: string;
|
|
149
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type { Libp2p } from 'libp2p';
|
|
2
|
-
import { createLogger } from '../utils/logger.js';
|
|
3
|
-
import { TransportError } from '../utils/errors.js';
|
|
4
|
-
|
|
5
|
-
const logger = createLogger('connection');
|
|
6
|
-
|
|
7
|
-
export interface ConnectionManager {
|
|
8
|
-
connect: (peerId: string) => Promise<void>;
|
|
9
|
-
disconnect: (peerId: string) => Promise<void>;
|
|
10
|
-
isConnected: (peerId: string) => boolean;
|
|
11
|
-
getConnectedPeers: () => string[];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Create a connection manager for a libp2p node
|
|
16
|
-
*/
|
|
17
|
-
export function createConnectionManager(
|
|
18
|
-
libp2p: Libp2p
|
|
19
|
-
): ConnectionManager {
|
|
20
|
-
return {
|
|
21
|
-
connect: async (peerIdStr: string) => {
|
|
22
|
-
try {
|
|
23
|
-
// Parse peer ID and multiaddr
|
|
24
|
-
const connections = libp2p.getConnections();
|
|
25
|
-
const existing = connections.find(
|
|
26
|
-
(conn) => conn.remotePeer.toString() === peerIdStr
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
if (existing) {
|
|
30
|
-
logger.debug('Already connected to peer', { peerId: peerIdStr });
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// In a real implementation, we would dial the peer
|
|
35
|
-
// For now, we rely on libp2p's automatic connection management
|
|
36
|
-
logger.info('Connecting to peer', { peerId: peerIdStr });
|
|
37
|
-
} catch (error) {
|
|
38
|
-
throw new TransportError('Failed to connect to peer', error);
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
disconnect: async (peerIdStr: string) => {
|
|
43
|
-
try {
|
|
44
|
-
const connections = libp2p.getConnections();
|
|
45
|
-
const matching = connections.filter(
|
|
46
|
-
(conn) => conn.remotePeer.toString() === peerIdStr
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
for (const conn of matching) {
|
|
50
|
-
await conn.close();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
logger.info('Disconnected from peer', { peerId: peerIdStr });
|
|
54
|
-
} catch (error) {
|
|
55
|
-
throw new TransportError('Failed to disconnect from peer', error);
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
isConnected: (peerIdStr: string) => {
|
|
60
|
-
const connections = libp2p.getConnections();
|
|
61
|
-
return connections.some(
|
|
62
|
-
(conn) => conn.remotePeer.toString() === peerIdStr
|
|
63
|
-
);
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
getConnectedPeers: () => {
|
|
67
|
-
const connections = libp2p.getConnections();
|
|
68
|
-
const peers = new Set<string>();
|
|
69
|
-
|
|
70
|
-
for (const conn of connections) {
|
|
71
|
-
peers.add(conn.remotePeer.toString());
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return Array.from(peers);
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
}
|
package/src/transport/index.ts
DELETED
package/src/transport/node.ts
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { createLibp2p, Libp2p } from 'libp2p';
|
|
2
|
-
import { tcp } from '@libp2p/tcp';
|
|
3
|
-
import { webSockets } from '@libp2p/websockets';
|
|
4
|
-
import { noise } from '@chainsafe/libp2p-noise';
|
|
5
|
-
import { mplex } from '@libp2p/mplex';
|
|
6
|
-
import { kadDHT, passthroughMapper } from '@libp2p/kad-dht';
|
|
7
|
-
import { bootstrap } from '@libp2p/bootstrap';
|
|
8
|
-
import { identify } from '@libp2p/identify';
|
|
9
|
-
import { ping } from '@libp2p/ping';
|
|
10
|
-
import {
|
|
11
|
-
circuitRelayTransport,
|
|
12
|
-
circuitRelayServer,
|
|
13
|
-
} from '@libp2p/circuit-relay-v2';
|
|
14
|
-
import { createLogger } from '../utils/logger.js';
|
|
15
|
-
import { TransportError } from '../utils/errors.js';
|
|
16
|
-
import type { KeyPair } from '../identity/keys.js';
|
|
17
|
-
import type { PrivateKey } from '@libp2p/interface';
|
|
18
|
-
|
|
19
|
-
const logger = createLogger('transport');
|
|
20
|
-
|
|
21
|
-
export interface TransportConfig {
|
|
22
|
-
keyPair?: KeyPair;
|
|
23
|
-
listenAddresses?: string[];
|
|
24
|
-
bootstrapPeers?: string[];
|
|
25
|
-
enableDHT?: boolean;
|
|
26
|
-
/** Run as a relay server so NAT'd agents can receive messages through this node */
|
|
27
|
-
enableRelay?: boolean;
|
|
28
|
-
/** Reserve a relay slot on bootstrap nodes so others can reach us (only needed for hw1 join) */
|
|
29
|
-
reserveRelaySlot?: boolean;
|
|
30
|
-
/** Enable mDNS local peer discovery (default: false) */
|
|
31
|
-
enableMDNS?: boolean;
|
|
32
|
-
/** libp2p PrivateKey for persistent PeerID (from @libp2p/crypto) */
|
|
33
|
-
privateKey?: PrivateKey;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface ClawiverseNode {
|
|
37
|
-
libp2p: Libp2p;
|
|
38
|
-
start: () => Promise<void>;
|
|
39
|
-
stop: () => Promise<void>;
|
|
40
|
-
getMultiaddrs: () => string[];
|
|
41
|
-
getPeerId: () => string;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Create a Clawiverse transport node with libp2p
|
|
46
|
-
*/
|
|
47
|
-
export async function createNode(
|
|
48
|
-
config: TransportConfig
|
|
49
|
-
): Promise<ClawiverseNode> {
|
|
50
|
-
try {
|
|
51
|
-
const {
|
|
52
|
-
listenAddresses = ['/ip4/0.0.0.0/tcp/0', '/ip4/0.0.0.0/tcp/0/ws'], // CVP-0010 §5: Add WebSocket listener
|
|
53
|
-
bootstrapPeers = [],
|
|
54
|
-
enableDHT = true,
|
|
55
|
-
enableRelay = false,
|
|
56
|
-
reserveRelaySlot = false,
|
|
57
|
-
enableMDNS = false,
|
|
58
|
-
privateKey,
|
|
59
|
-
} = config;
|
|
60
|
-
|
|
61
|
-
// Reserve relay slots by adding p2p-circuit listen addresses (for hw1 join)
|
|
62
|
-
const relayListenAddrs = reserveRelaySlot
|
|
63
|
-
? bootstrapPeers.map((peer) => `${peer}/p2p-circuit`)
|
|
64
|
-
: [];
|
|
65
|
-
|
|
66
|
-
const libp2pConfig: any = {
|
|
67
|
-
addresses: {
|
|
68
|
-
listen: [...listenAddresses, ...relayListenAddrs],
|
|
69
|
-
},
|
|
70
|
-
...(privateKey ? { privateKey } : {}),
|
|
71
|
-
transports: [
|
|
72
|
-
tcp(),
|
|
73
|
-
webSockets(), // CVP-0010 §5: WebSocket for firewall traversal
|
|
74
|
-
circuitRelayTransport(),
|
|
75
|
-
],
|
|
76
|
-
connectionEncrypters: [noise()],
|
|
77
|
-
streamMuxers: [mplex()],
|
|
78
|
-
connectionManager: {
|
|
79
|
-
minConnections: bootstrapPeers.length > 0 ? 1 : 0,
|
|
80
|
-
maxConnections: 50,
|
|
81
|
-
},
|
|
82
|
-
services: {
|
|
83
|
-
identify: identify(),
|
|
84
|
-
ping: ping(),
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
if (enableRelay) {
|
|
89
|
-
libp2pConfig.services.relay = circuitRelayServer({
|
|
90
|
-
reservations: {
|
|
91
|
-
maxReservations: 100, // Allow up to 100 concurrent relay reservations
|
|
92
|
-
},
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (enableDHT) {
|
|
97
|
-
libp2pConfig.services.dht = kadDHT({
|
|
98
|
-
clientMode: false,
|
|
99
|
-
peerInfoMapper: passthroughMapper,
|
|
100
|
-
validators: {
|
|
101
|
-
clawiverse: async () => {},
|
|
102
|
-
},
|
|
103
|
-
selectors: {
|
|
104
|
-
clawiverse: () => 0,
|
|
105
|
-
},
|
|
106
|
-
// Optimize for small networks: reduce replication factor and query timeout
|
|
107
|
-
kBucketSize: 20, // Default K=20, keep for compatibility
|
|
108
|
-
querySelfInterval: 30000, // Self-query every 30 seconds (libp2p default)
|
|
109
|
-
// Allow queries to complete faster in small networks
|
|
110
|
-
allowQueryWithZeroPeers: true,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const peerDiscovery: any[] = [];
|
|
115
|
-
if (bootstrapPeers.length > 0) peerDiscovery.push(bootstrap({ list: bootstrapPeers }));
|
|
116
|
-
if (enableMDNS) {
|
|
117
|
-
const { mdns } = await import('@libp2p/mdns');
|
|
118
|
-
peerDiscovery.push(mdns());
|
|
119
|
-
}
|
|
120
|
-
if (peerDiscovery.length > 0) libp2pConfig.peerDiscovery = peerDiscovery;
|
|
121
|
-
|
|
122
|
-
const libp2p = await createLibp2p(libp2pConfig);
|
|
123
|
-
|
|
124
|
-
logger.info('Libp2p node created', {
|
|
125
|
-
listenAddresses: libp2pConfig.addresses.listen,
|
|
126
|
-
reserveRelaySlot,
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
return {
|
|
130
|
-
libp2p,
|
|
131
|
-
start: async () => {
|
|
132
|
-
await libp2p.start();
|
|
133
|
-
logger.info('Node started', {
|
|
134
|
-
peerId: libp2p.peerId.toString(),
|
|
135
|
-
addresses: libp2p.getMultiaddrs().map((ma) => ma.toString()),
|
|
136
|
-
relay: enableRelay,
|
|
137
|
-
reserveRelaySlot,
|
|
138
|
-
});
|
|
139
|
-
},
|
|
140
|
-
stop: async () => {
|
|
141
|
-
await libp2p.stop();
|
|
142
|
-
logger.info('Node stopped');
|
|
143
|
-
},
|
|
144
|
-
getMultiaddrs: () => {
|
|
145
|
-
return libp2p.getMultiaddrs().map((ma) => ma.toString());
|
|
146
|
-
},
|
|
147
|
-
getPeerId: () => {
|
|
148
|
-
return libp2p.peerId.toString();
|
|
149
|
-
},
|
|
150
|
-
};
|
|
151
|
-
} catch (error) {
|
|
152
|
-
throw new TransportError('Failed to create transport node', error);
|
|
153
|
-
}
|
|
154
|
-
}
|