@f2a/network 0.1.2 → 0.1.3
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 +8 -1
- package/.github/workflows/ci.yml +0 -113
- package/.github/workflows/publish.yml +0 -60
- package/MONOREPO.md +0 -58
- package/SKILL.md +0 -137
- package/dist/adapters/openclaw.d.ts +0 -103
- package/dist/adapters/openclaw.d.ts.map +0 -1
- package/dist/adapters/openclaw.js +0 -297
- package/dist/adapters/openclaw.js.map +0 -1
- package/dist/core/connection-manager.d.ts +0 -80
- package/dist/core/connection-manager.d.ts.map +0 -1
- package/dist/core/connection-manager.js +0 -235
- package/dist/core/connection-manager.js.map +0 -1
- package/dist/core/connection-manager.test.d.ts +0 -2
- package/dist/core/connection-manager.test.d.ts.map +0 -1
- package/dist/core/connection-manager.test.js +0 -52
- package/dist/core/connection-manager.test.js.map +0 -1
- package/dist/core/identity.d.ts +0 -47
- package/dist/core/identity.d.ts.map +0 -1
- package/dist/core/identity.js +0 -130
- package/dist/core/identity.js.map +0 -1
- package/dist/core/identity.test.d.ts +0 -2
- package/dist/core/identity.test.d.ts.map +0 -1
- package/dist/core/identity.test.js +0 -43
- package/dist/core/identity.test.js.map +0 -1
- package/dist/core/serverless.d.ts +0 -155
- package/dist/core/serverless.d.ts.map +0 -1
- package/dist/core/serverless.js +0 -615
- package/dist/core/serverless.js.map +0 -1
- package/dist/daemon/webhook.test.d.ts +0 -2
- package/dist/daemon/webhook.test.d.ts.map +0 -1
- package/dist/daemon/webhook.test.js +0 -24
- package/dist/daemon/webhook.test.js.map +0 -1
- package/dist/protocol/messages.d.ts +0 -739
- package/dist/protocol/messages.d.ts.map +0 -1
- package/dist/protocol/messages.js +0 -188
- package/dist/protocol/messages.js.map +0 -1
- package/dist/protocol/messages.test.d.ts +0 -2
- package/dist/protocol/messages.test.d.ts.map +0 -1
- package/dist/protocol/messages.test.js +0 -55
- package/dist/protocol/messages.test.js.map +0 -1
- package/docs/F2A-PROTOCOL.md +0 -61
- package/docs/MOBILE_BOOTSTRAP_DESIGN.md +0 -126
- package/docs/a2a-lessons.md +0 -316
- package/docs/middleware-guide.md +0 -448
- package/docs/readme-update-checklist.md +0 -90
- package/docs/reputation-guide.md +0 -396
- package/docs/rfcs/001-reputation-system.md +0 -712
- package/docs/security-design.md +0 -247
- package/install.sh +0 -231
- package/packages/openclaw-adapter/README.md +0 -510
- package/packages/openclaw-adapter/openclaw.plugin.json +0 -106
- package/packages/openclaw-adapter/package.json +0 -40
- package/packages/openclaw-adapter/src/announcement-queue.test.ts +0 -449
- package/packages/openclaw-adapter/src/announcement-queue.ts +0 -403
- package/packages/openclaw-adapter/src/capability-detector.test.ts +0 -99
- package/packages/openclaw-adapter/src/capability-detector.ts +0 -183
- package/packages/openclaw-adapter/src/claim-handlers.test.ts +0 -974
- package/packages/openclaw-adapter/src/claim-handlers.ts +0 -482
- package/packages/openclaw-adapter/src/connector.business.test.ts +0 -583
- package/packages/openclaw-adapter/src/connector.ts +0 -795
- package/packages/openclaw-adapter/src/index.test.ts +0 -82
- package/packages/openclaw-adapter/src/index.ts +0 -18
- package/packages/openclaw-adapter/src/integration.e2e.test.ts +0 -829
- package/packages/openclaw-adapter/src/logger.ts +0 -51
- package/packages/openclaw-adapter/src/network-client.test.ts +0 -266
- package/packages/openclaw-adapter/src/network-client.ts +0 -251
- package/packages/openclaw-adapter/src/network-recovery.test.ts +0 -465
- package/packages/openclaw-adapter/src/node-manager.test.ts +0 -136
- package/packages/openclaw-adapter/src/node-manager.ts +0 -429
- package/packages/openclaw-adapter/src/plugin.test.ts +0 -439
- package/packages/openclaw-adapter/src/plugin.ts +0 -104
- package/packages/openclaw-adapter/src/reputation.test.ts +0 -221
- package/packages/openclaw-adapter/src/reputation.ts +0 -368
- package/packages/openclaw-adapter/src/task-guard.test.ts +0 -502
- package/packages/openclaw-adapter/src/task-guard.ts +0 -860
- package/packages/openclaw-adapter/src/task-queue.concurrency.test.ts +0 -462
- package/packages/openclaw-adapter/src/task-queue.edge-cases.test.ts +0 -284
- package/packages/openclaw-adapter/src/task-queue.persistence.test.ts +0 -408
- package/packages/openclaw-adapter/src/task-queue.ts +0 -668
- package/packages/openclaw-adapter/src/tool-handlers.test.ts +0 -906
- package/packages/openclaw-adapter/src/tool-handlers.ts +0 -574
- package/packages/openclaw-adapter/src/types.ts +0 -361
- package/packages/openclaw-adapter/src/webhook-pusher.test.ts +0 -188
- package/packages/openclaw-adapter/src/webhook-pusher.ts +0 -220
- package/packages/openclaw-adapter/src/webhook-server.test.ts +0 -580
- package/packages/openclaw-adapter/src/webhook-server.ts +0 -202
- package/packages/openclaw-adapter/tsconfig.json +0 -20
- package/src/cli/commands.test.ts +0 -157
- package/src/cli/commands.ts +0 -129
- package/src/cli/index.test.ts +0 -77
- package/src/cli/index.ts +0 -234
- package/src/core/autonomous-economy.test.ts +0 -291
- package/src/core/autonomous-economy.ts +0 -428
- package/src/core/e2ee-crypto.test.ts +0 -125
- package/src/core/e2ee-crypto.ts +0 -246
- package/src/core/f2a.test.ts +0 -269
- package/src/core/f2a.ts +0 -618
- package/src/core/p2p-network.test.ts +0 -199
- package/src/core/p2p-network.ts +0 -1432
- package/src/core/reputation-security.test.ts +0 -403
- package/src/core/reputation-security.ts +0 -562
- package/src/core/reputation.test.ts +0 -260
- package/src/core/reputation.ts +0 -576
- package/src/core/review-committee.test.ts +0 -380
- package/src/core/review-committee.ts +0 -401
- package/src/core/token-manager.test.ts +0 -133
- package/src/core/token-manager.ts +0 -140
- package/src/daemon/control-server.test.ts +0 -216
- package/src/daemon/control-server.ts +0 -292
- package/src/daemon/index.test.ts +0 -85
- package/src/daemon/index.ts +0 -89
- package/src/daemon/main.ts +0 -44
- package/src/daemon/start.ts +0 -29
- package/src/daemon/webhook.test.ts +0 -68
- package/src/daemon/webhook.ts +0 -105
- package/src/index.test.ts +0 -436
- package/src/index.ts +0 -72
- package/src/types/index.test.ts +0 -87
- package/src/types/index.ts +0 -341
- package/src/types/result.ts +0 -68
- package/src/utils/benchmark.ts +0 -237
- package/src/utils/logger.ts +0 -331
- package/src/utils/middleware.ts +0 -229
- package/src/utils/rate-limiter.ts +0 -207
- package/src/utils/signature.ts +0 -136
- package/src/utils/validation.ts +0 -186
- package/tests/docker/Dockerfile.node +0 -23
- package/tests/docker/Dockerfile.runner +0 -18
- package/tests/docker/docker-compose.test.yml +0 -73
- package/tests/integration/message-passing.test.ts +0 -109
- package/tests/integration/multi-node.test.ts +0 -92
- package/tests/integration/p2p-connection.test.ts +0 -83
- package/tests/integration/test-config.ts +0 -32
- package/tsconfig.json +0 -21
- package/vitest.config.ts +0 -26
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { P2PNetwork } from './p2p-network.js';
|
|
3
|
-
import { AgentInfo } from '../types/index.js';
|
|
4
|
-
|
|
5
|
-
describe('P2PNetwork', () => {
|
|
6
|
-
let network: P2PNetwork;
|
|
7
|
-
let mockAgentInfo: AgentInfo;
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
mockAgentInfo = {
|
|
11
|
-
peerId: '',
|
|
12
|
-
displayName: 'Test Agent',
|
|
13
|
-
agentType: 'openclaw',
|
|
14
|
-
version: '1.0.0',
|
|
15
|
-
capabilities: [],
|
|
16
|
-
protocolVersion: 'f2a/1.0',
|
|
17
|
-
lastSeen: Date.now(),
|
|
18
|
-
multiaddrs: []
|
|
19
|
-
};
|
|
20
|
-
network = new P2PNetwork(mockAgentInfo);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
afterEach(async () => {
|
|
24
|
-
await network.stop();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
describe('initialization', () => {
|
|
28
|
-
it('should initialize with correct default config', () => {
|
|
29
|
-
expect(network).toBeDefined();
|
|
30
|
-
expect(network.getPeerId()).toBe('');
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('should handle multiple stop calls gracefully', async () => {
|
|
34
|
-
await network.stop();
|
|
35
|
-
await network.stop(); // Should not throw
|
|
36
|
-
expect(network.getPeerId()).toBe('');
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
describe('peer management', () => {
|
|
41
|
-
it('should return empty array when no peers connected', () => {
|
|
42
|
-
const peers = network.getConnectedPeers();
|
|
43
|
-
expect(peers).toEqual([]);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('should return empty array for all peers initially', () => {
|
|
47
|
-
const peers = network.getAllPeers();
|
|
48
|
-
expect(peers).toEqual([]);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe('capability checking', () => {
|
|
53
|
-
it('should correctly identify agent capabilities', () => {
|
|
54
|
-
const agentWithCaps: AgentInfo = {
|
|
55
|
-
...mockAgentInfo,
|
|
56
|
-
capabilities: [
|
|
57
|
-
{ name: 'file-operation', description: 'File ops', tools: ['read'] }
|
|
58
|
-
]
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const hasCap = (network as any).hasCapability(agentWithCaps, 'file-operation');
|
|
62
|
-
expect(hasCap).toBe(true);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('should return false for missing capabilities', () => {
|
|
66
|
-
const agentWithCaps: AgentInfo = {
|
|
67
|
-
...mockAgentInfo,
|
|
68
|
-
capabilities: []
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const hasCap = (network as any).hasCapability(agentWithCaps, 'file-operation');
|
|
72
|
-
expect(hasCap).toBe(false);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
describe('DHT features', () => {
|
|
77
|
-
it('should return false for isDHTEnabled when not started', () => {
|
|
78
|
-
expect(network.isDHTEnabled()).toBe(false);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('should return 0 for getDHTPeerCount when not started', () => {
|
|
82
|
-
expect(network.getDHTPeerCount()).toBe(0);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('should return error when findPeerViaDHT called before start', async () => {
|
|
86
|
-
const result = await network.findPeerViaDHT('test-peer-id');
|
|
87
|
-
expect(result.success).toBe(false);
|
|
88
|
-
expect(result.error?.code).toBe('NETWORK_NOT_STARTED');
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
describe('E2EE features', () => {
|
|
93
|
-
it('should return null for getEncryptionPublicKey when not started', () => {
|
|
94
|
-
expect(network.getEncryptionPublicKey()).toBeNull();
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('should return 0 for getEncryptedPeerCount when not started', () => {
|
|
98
|
-
expect(network.getEncryptedPeerCount()).toBe(0);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
describe('events', () => {
|
|
103
|
-
it('should emit error event', async () => {
|
|
104
|
-
const errorPromise = new Promise<Error>((resolve) => {
|
|
105
|
-
network.on('error', (error) => {
|
|
106
|
-
resolve(error);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
(network as any).emit('error', new Error('Test error'));
|
|
111
|
-
|
|
112
|
-
const error = await errorPromise;
|
|
113
|
-
expect(error).toBeInstanceOf(Error);
|
|
114
|
-
expect(error.message).toBe('Test error');
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
describe('message handling', () => {
|
|
119
|
-
it('should process DISCOVER_RESP and upsert peer', async () => {
|
|
120
|
-
const agentInfo: AgentInfo = {
|
|
121
|
-
...mockAgentInfo,
|
|
122
|
-
peerId: 'peer-remote',
|
|
123
|
-
multiaddrs: ['/ip4/127.0.0.1/tcp/9002']
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
await (network as any).handleMessage(
|
|
127
|
-
{
|
|
128
|
-
id: '00000000-0000-4000-8000-000000000001',
|
|
129
|
-
type: 'DISCOVER_RESP',
|
|
130
|
-
from: 'peer-remote',
|
|
131
|
-
timestamp: Date.now(),
|
|
132
|
-
payload: { agentInfo }
|
|
133
|
-
},
|
|
134
|
-
'peer-remote'
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
const peers = network.getAllPeers();
|
|
138
|
-
expect(peers).toHaveLength(1);
|
|
139
|
-
expect(peers[0].agentInfo?.peerId).toBe('peer-remote');
|
|
140
|
-
expect(peers[0].multiaddrs[0].toString()).toContain('/tcp/9002');
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('should process CAPABILITY_RESPONSE and upsert peer', async () => {
|
|
144
|
-
const agentInfo: AgentInfo = {
|
|
145
|
-
...mockAgentInfo,
|
|
146
|
-
peerId: 'peer-cap',
|
|
147
|
-
capabilities: [{ name: 'code-gen', description: 'Code Gen', tools: ['generate'] }],
|
|
148
|
-
multiaddrs: ['/ip4/127.0.0.1/tcp/9003']
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
await (network as any).handleMessage(
|
|
152
|
-
{
|
|
153
|
-
id: '00000000-0000-4000-8000-000000000002',
|
|
154
|
-
type: 'CAPABILITY_RESPONSE',
|
|
155
|
-
from: 'peer-cap',
|
|
156
|
-
timestamp: Date.now(),
|
|
157
|
-
payload: { agentInfo }
|
|
158
|
-
},
|
|
159
|
-
'peer-cap'
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
const peers = network.getAllPeers();
|
|
163
|
-
expect(peers).toHaveLength(1);
|
|
164
|
-
expect(peers[0].agentInfo?.capabilities[0].name).toBe('code-gen');
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
describe('broadcast', () => {
|
|
169
|
-
it('should count fulfilled failures in broadcast warning', async () => {
|
|
170
|
-
const warnSpy = vi.spyOn((network as any).logger, 'warn');
|
|
171
|
-
|
|
172
|
-
(network as any).node = {
|
|
173
|
-
getPeers: vi.fn().mockReturnValue([
|
|
174
|
-
{ toString: () => 'peer-a' },
|
|
175
|
-
{ toString: () => 'peer-b' }
|
|
176
|
-
]),
|
|
177
|
-
stop: vi.fn().mockResolvedValue(undefined)
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
const sendSpy = vi.spyOn(network as any, 'sendMessage')
|
|
181
|
-
.mockResolvedValueOnce({ success: true, data: undefined })
|
|
182
|
-
.mockResolvedValueOnce({ success: false, error: { code: 'PEER_NOT_FOUND', message: 'Peer not found' } });
|
|
183
|
-
|
|
184
|
-
await (network as any).broadcast({
|
|
185
|
-
id: 'msg-broadcast',
|
|
186
|
-
type: 'DISCOVER',
|
|
187
|
-
from: 'self',
|
|
188
|
-
timestamp: Date.now(),
|
|
189
|
-
payload: { agentInfo: mockAgentInfo }
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
expect(sendSpy).toHaveBeenCalledTimes(2);
|
|
193
|
-
expect(warnSpy).toHaveBeenCalledWith('Broadcast failed to some peers', {
|
|
194
|
-
failed: 1,
|
|
195
|
-
total: 2
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
});
|