@affectively/aeon 1.0.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/LICENSE +21 -0
- package/README.md +332 -0
- package/dist/core/index.cjs +4 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +146 -0
- package/dist/core/index.d.ts +146 -0
- package/dist/core/index.js +3 -0
- package/dist/core/index.js.map +1 -0
- package/dist/distributed/index.cjs +1874 -0
- package/dist/distributed/index.cjs.map +1 -0
- package/dist/distributed/index.d.cts +2 -0
- package/dist/distributed/index.d.ts +2 -0
- package/dist/distributed/index.js +1869 -0
- package/dist/distributed/index.js.map +1 -0
- package/dist/index-C_4CMV5c.d.cts +1207 -0
- package/dist/index-C_4CMV5c.d.ts +1207 -0
- package/dist/index.cjs +4671 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +812 -0
- package/dist/index.d.ts +812 -0
- package/dist/index.js +4632 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/index.cjs +64 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +38 -0
- package/dist/utils/index.d.ts +38 -0
- package/dist/utils/index.js +57 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/versioning/index.cjs +871 -0
- package/dist/versioning/index.cjs.map +1 -0
- package/dist/versioning/index.d.cts +472 -0
- package/dist/versioning/index.d.ts +472 -0
- package/dist/versioning/index.js +866 -0
- package/dist/versioning/index.js.map +1 -0
- package/package.json +142 -0
|
@@ -0,0 +1,1207 @@
|
|
|
1
|
+
import { EventEmitter } from 'eventemitter3';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Aeon Crypto Types
|
|
5
|
+
*
|
|
6
|
+
* Type definitions for cryptographic operations in Aeon.
|
|
7
|
+
* These are compatible with @affectively/ucan and @affectively/zk-encryption.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Decentralized Identifier (DID)
|
|
11
|
+
* Format: did:method:identifier
|
|
12
|
+
*/
|
|
13
|
+
type DID = `did:${string}:${string}`;
|
|
14
|
+
/**
|
|
15
|
+
* Supported signing algorithms
|
|
16
|
+
*/
|
|
17
|
+
type SigningAlgorithm = 'ES256' | 'Ed25519' | 'ES384' | 'ES512';
|
|
18
|
+
/**
|
|
19
|
+
* Key pair for signing and verification
|
|
20
|
+
*/
|
|
21
|
+
interface KeyPair {
|
|
22
|
+
algorithm: SigningAlgorithm;
|
|
23
|
+
publicKey: JsonWebKey;
|
|
24
|
+
privateKey?: JsonWebKey;
|
|
25
|
+
fingerprint: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Identity representing a user or node
|
|
29
|
+
*/
|
|
30
|
+
interface Identity {
|
|
31
|
+
did: DID;
|
|
32
|
+
signingKey: KeyPair;
|
|
33
|
+
encryptionKey?: KeyPair;
|
|
34
|
+
createdAt: number;
|
|
35
|
+
displayName?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* UCAN Capability structure
|
|
39
|
+
*/
|
|
40
|
+
interface Capability {
|
|
41
|
+
can: string;
|
|
42
|
+
with: string;
|
|
43
|
+
constraints?: Record<string, unknown>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* UCAN Token payload
|
|
47
|
+
*/
|
|
48
|
+
interface UCANPayload {
|
|
49
|
+
iss: DID;
|
|
50
|
+
aud: DID;
|
|
51
|
+
exp: number;
|
|
52
|
+
nbf?: number;
|
|
53
|
+
iat?: number;
|
|
54
|
+
nonce?: string;
|
|
55
|
+
jti?: string;
|
|
56
|
+
att: Capability[];
|
|
57
|
+
prf?: string[];
|
|
58
|
+
fct?: Record<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Parsed UCAN Token
|
|
62
|
+
*/
|
|
63
|
+
interface UCANToken {
|
|
64
|
+
payload: UCANPayload;
|
|
65
|
+
raw: string;
|
|
66
|
+
signature: Uint8Array;
|
|
67
|
+
algorithm: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* UCAN verification result
|
|
71
|
+
*/
|
|
72
|
+
interface VerificationResult {
|
|
73
|
+
valid: boolean;
|
|
74
|
+
payload?: UCANPayload;
|
|
75
|
+
error?: string;
|
|
76
|
+
expired?: boolean;
|
|
77
|
+
shouldRotate?: boolean;
|
|
78
|
+
expiresIn?: number;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Encryption algorithms supported
|
|
82
|
+
*/
|
|
83
|
+
type EncryptionAlgorithm = 'ECIES-P256' | 'AES-256-GCM';
|
|
84
|
+
/**
|
|
85
|
+
* HKDF domain separator categories
|
|
86
|
+
*/
|
|
87
|
+
type DomainCategory = 'default' | 'sync' | 'message' | 'api-key' | 'personal-data' | string;
|
|
88
|
+
/**
|
|
89
|
+
* EC Key pair for ECDH operations
|
|
90
|
+
*/
|
|
91
|
+
interface ECKeyPair {
|
|
92
|
+
publicKey: JsonWebKey;
|
|
93
|
+
privateKey: JsonWebKey;
|
|
94
|
+
keyId: string;
|
|
95
|
+
createdAt: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Encrypted data envelope
|
|
99
|
+
*/
|
|
100
|
+
interface EncryptedPayload {
|
|
101
|
+
alg: EncryptionAlgorithm;
|
|
102
|
+
ct: string;
|
|
103
|
+
iv: string;
|
|
104
|
+
tag: string;
|
|
105
|
+
epk?: JsonWebKey;
|
|
106
|
+
category?: DomainCategory;
|
|
107
|
+
nonce?: string;
|
|
108
|
+
encryptedAt: number;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Decryption result
|
|
112
|
+
*/
|
|
113
|
+
interface DecryptionResult {
|
|
114
|
+
plaintext: Uint8Array;
|
|
115
|
+
category?: DomainCategory;
|
|
116
|
+
encryptedAt: number;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Aeon encryption mode
|
|
120
|
+
*/
|
|
121
|
+
type AeonEncryptionMode = 'none' | 'transport' | 'at-rest' | 'end-to-end';
|
|
122
|
+
/**
|
|
123
|
+
* Aeon sync capability namespace
|
|
124
|
+
*/
|
|
125
|
+
declare const AEON_CAPABILITIES: {
|
|
126
|
+
readonly SYNC_READ: "aeon:sync:read";
|
|
127
|
+
readonly SYNC_WRITE: "aeon:sync:write";
|
|
128
|
+
readonly SYNC_ADMIN: "aeon:sync:admin";
|
|
129
|
+
readonly NODE_REGISTER: "aeon:node:register";
|
|
130
|
+
readonly NODE_HEARTBEAT: "aeon:node:heartbeat";
|
|
131
|
+
readonly REPLICATE_READ: "aeon:replicate:read";
|
|
132
|
+
readonly REPLICATE_WRITE: "aeon:replicate:write";
|
|
133
|
+
readonly STATE_READ: "aeon:state:read";
|
|
134
|
+
readonly STATE_WRITE: "aeon:state:write";
|
|
135
|
+
readonly STATE_RECONCILE: "aeon:state:reconcile";
|
|
136
|
+
};
|
|
137
|
+
type AeonCapability = (typeof AEON_CAPABILITIES)[keyof typeof AEON_CAPABILITIES];
|
|
138
|
+
/**
|
|
139
|
+
* Crypto configuration for Aeon
|
|
140
|
+
*/
|
|
141
|
+
interface AeonCryptoConfig {
|
|
142
|
+
/** Default encryption mode for sync messages */
|
|
143
|
+
defaultEncryptionMode: AeonEncryptionMode;
|
|
144
|
+
/** Require all messages to be signed */
|
|
145
|
+
requireSignatures: boolean;
|
|
146
|
+
/** Require UCAN capability verification */
|
|
147
|
+
requireCapabilities: boolean;
|
|
148
|
+
/** Allowed signature algorithms */
|
|
149
|
+
allowedSignatureAlgorithms: string[];
|
|
150
|
+
/** Allowed encryption algorithms */
|
|
151
|
+
allowedEncryptionAlgorithms: string[];
|
|
152
|
+
/** UCAN audience DID for verification */
|
|
153
|
+
ucanAudience?: string;
|
|
154
|
+
/** Session key expiration (ms) */
|
|
155
|
+
sessionKeyExpiration?: number;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Default crypto configuration
|
|
159
|
+
*/
|
|
160
|
+
declare const DEFAULT_CRYPTO_CONFIG: AeonCryptoConfig;
|
|
161
|
+
/**
|
|
162
|
+
* Authenticated sync message fields
|
|
163
|
+
*/
|
|
164
|
+
interface AuthenticatedMessageFields {
|
|
165
|
+
/** Sender DID */
|
|
166
|
+
senderDID?: string;
|
|
167
|
+
/** Receiver DID */
|
|
168
|
+
receiverDID?: string;
|
|
169
|
+
/** UCAN token for capability verification */
|
|
170
|
+
ucan?: string;
|
|
171
|
+
/** Message signature (base64url) */
|
|
172
|
+
signature?: string;
|
|
173
|
+
/** Whether payload is encrypted */
|
|
174
|
+
encrypted?: boolean;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Secure sync session
|
|
178
|
+
*/
|
|
179
|
+
interface SecureSyncSession {
|
|
180
|
+
id: string;
|
|
181
|
+
initiator: string;
|
|
182
|
+
participants: string[];
|
|
183
|
+
sessionKey?: Uint8Array;
|
|
184
|
+
encryptionMode: AeonEncryptionMode;
|
|
185
|
+
requiredCapabilities: string[];
|
|
186
|
+
status: 'pending' | 'active' | 'completed' | 'failed';
|
|
187
|
+
startTime: string;
|
|
188
|
+
endTime?: string;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Node with identity information
|
|
192
|
+
*/
|
|
193
|
+
interface SecureNodeInfo {
|
|
194
|
+
id: string;
|
|
195
|
+
did?: string;
|
|
196
|
+
publicSigningKey?: JsonWebKey;
|
|
197
|
+
publicEncryptionKey?: JsonWebKey;
|
|
198
|
+
capabilities?: string[];
|
|
199
|
+
lastSeen?: number;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Capability verification result
|
|
203
|
+
*/
|
|
204
|
+
interface AeonCapabilityResult {
|
|
205
|
+
authorized: boolean;
|
|
206
|
+
error?: string;
|
|
207
|
+
issuer?: string;
|
|
208
|
+
grantedCapabilities?: Array<{
|
|
209
|
+
can: string;
|
|
210
|
+
with: string;
|
|
211
|
+
}>;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Signed data envelope for sync operations
|
|
215
|
+
*/
|
|
216
|
+
interface SignedSyncData<T = unknown> {
|
|
217
|
+
payload: T;
|
|
218
|
+
signature: string;
|
|
219
|
+
signer: string;
|
|
220
|
+
algorithm: string;
|
|
221
|
+
signedAt: number;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Aeon Crypto Provider Interface
|
|
226
|
+
*
|
|
227
|
+
* Abstract interface for cryptographic operations.
|
|
228
|
+
* Aeon core remains zero-dependency - crypto is injected through this interface.
|
|
229
|
+
*/
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Abstract crypto provider interface
|
|
233
|
+
*
|
|
234
|
+
* Implementations use @affectively/ucan and @affectively/zk-encryption
|
|
235
|
+
* or other compatible libraries.
|
|
236
|
+
*/
|
|
237
|
+
interface ICryptoProvider {
|
|
238
|
+
/**
|
|
239
|
+
* Generate a new identity with DID and key pairs
|
|
240
|
+
*/
|
|
241
|
+
generateIdentity(displayName?: string): Promise<{
|
|
242
|
+
did: string;
|
|
243
|
+
publicSigningKey: JsonWebKey;
|
|
244
|
+
publicEncryptionKey?: JsonWebKey;
|
|
245
|
+
}>;
|
|
246
|
+
/**
|
|
247
|
+
* Get the local identity's DID
|
|
248
|
+
*/
|
|
249
|
+
getLocalDID(): string | null;
|
|
250
|
+
/**
|
|
251
|
+
* Export local identity's public info for sharing
|
|
252
|
+
*/
|
|
253
|
+
exportPublicIdentity(): Promise<SecureNodeInfo | null>;
|
|
254
|
+
/**
|
|
255
|
+
* Register a known remote node's public keys
|
|
256
|
+
*/
|
|
257
|
+
registerRemoteNode(node: SecureNodeInfo): Promise<void>;
|
|
258
|
+
/**
|
|
259
|
+
* Get a remote node's public key
|
|
260
|
+
*/
|
|
261
|
+
getRemotePublicKey(did: string): Promise<JsonWebKey | null>;
|
|
262
|
+
/**
|
|
263
|
+
* Sign data with local identity's private key
|
|
264
|
+
*/
|
|
265
|
+
sign(data: Uint8Array): Promise<Uint8Array>;
|
|
266
|
+
/**
|
|
267
|
+
* Sign structured data and wrap in SignedSyncData envelope
|
|
268
|
+
*/
|
|
269
|
+
signData<T>(data: T): Promise<SignedSyncData<T>>;
|
|
270
|
+
/**
|
|
271
|
+
* Verify a signature from a remote node
|
|
272
|
+
*/
|
|
273
|
+
verify(did: string, signature: Uint8Array, data: Uint8Array): Promise<boolean>;
|
|
274
|
+
/**
|
|
275
|
+
* Verify a SignedSyncData envelope
|
|
276
|
+
*/
|
|
277
|
+
verifySignedData<T>(signedData: SignedSyncData<T>): Promise<boolean>;
|
|
278
|
+
/**
|
|
279
|
+
* Encrypt data for a recipient
|
|
280
|
+
*/
|
|
281
|
+
encrypt(plaintext: Uint8Array, recipientDID: string): Promise<{
|
|
282
|
+
alg: string;
|
|
283
|
+
ct: string;
|
|
284
|
+
iv: string;
|
|
285
|
+
tag: string;
|
|
286
|
+
epk?: JsonWebKey;
|
|
287
|
+
encryptedAt: number;
|
|
288
|
+
}>;
|
|
289
|
+
/**
|
|
290
|
+
* Decrypt data
|
|
291
|
+
*/
|
|
292
|
+
decrypt(encrypted: {
|
|
293
|
+
alg: string;
|
|
294
|
+
ct: string;
|
|
295
|
+
iv: string;
|
|
296
|
+
tag: string;
|
|
297
|
+
epk?: JsonWebKey;
|
|
298
|
+
}, senderDID?: string): Promise<Uint8Array>;
|
|
299
|
+
/**
|
|
300
|
+
* Derive or get a session key for communication with a peer
|
|
301
|
+
*/
|
|
302
|
+
getSessionKey(peerDID: string): Promise<Uint8Array>;
|
|
303
|
+
/**
|
|
304
|
+
* Encrypt with a session key
|
|
305
|
+
*/
|
|
306
|
+
encryptWithSessionKey(plaintext: Uint8Array, sessionKey: Uint8Array): Promise<{
|
|
307
|
+
alg: string;
|
|
308
|
+
ct: string;
|
|
309
|
+
iv: string;
|
|
310
|
+
tag: string;
|
|
311
|
+
encryptedAt: number;
|
|
312
|
+
}>;
|
|
313
|
+
/**
|
|
314
|
+
* Decrypt with a session key
|
|
315
|
+
*/
|
|
316
|
+
decryptWithSessionKey(encrypted: {
|
|
317
|
+
ct: string;
|
|
318
|
+
iv: string;
|
|
319
|
+
tag: string;
|
|
320
|
+
}, sessionKey: Uint8Array): Promise<Uint8Array>;
|
|
321
|
+
/**
|
|
322
|
+
* Create a UCAN token
|
|
323
|
+
*/
|
|
324
|
+
createUCAN(audience: string, capabilities: Array<{
|
|
325
|
+
can: string;
|
|
326
|
+
with: string;
|
|
327
|
+
}>, options?: {
|
|
328
|
+
expirationSeconds?: number;
|
|
329
|
+
proofs?: string[];
|
|
330
|
+
}): Promise<string>;
|
|
331
|
+
/**
|
|
332
|
+
* Verify a UCAN token
|
|
333
|
+
*/
|
|
334
|
+
verifyUCAN(token: string, options?: {
|
|
335
|
+
expectedAudience?: string;
|
|
336
|
+
requiredCapabilities?: Array<{
|
|
337
|
+
can: string;
|
|
338
|
+
with: string;
|
|
339
|
+
}>;
|
|
340
|
+
}): Promise<AeonCapabilityResult>;
|
|
341
|
+
/**
|
|
342
|
+
* Delegate capabilities
|
|
343
|
+
*/
|
|
344
|
+
delegateCapabilities(parentToken: string, audience: string, capabilities: Array<{
|
|
345
|
+
can: string;
|
|
346
|
+
with: string;
|
|
347
|
+
}>, options?: {
|
|
348
|
+
expirationSeconds?: number;
|
|
349
|
+
}): Promise<string>;
|
|
350
|
+
/**
|
|
351
|
+
* Compute hash of data
|
|
352
|
+
*/
|
|
353
|
+
hash(data: Uint8Array): Promise<Uint8Array>;
|
|
354
|
+
/**
|
|
355
|
+
* Generate random bytes
|
|
356
|
+
*/
|
|
357
|
+
randomBytes(length: number): Uint8Array;
|
|
358
|
+
/**
|
|
359
|
+
* Check if crypto is properly initialized
|
|
360
|
+
*/
|
|
361
|
+
isInitialized(): boolean;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Null crypto provider for when crypto is disabled
|
|
365
|
+
*
|
|
366
|
+
* All operations either throw or return permissive defaults.
|
|
367
|
+
*/
|
|
368
|
+
declare class NullCryptoProvider implements ICryptoProvider {
|
|
369
|
+
private notConfiguredError;
|
|
370
|
+
generateIdentity(): Promise<{
|
|
371
|
+
did: string;
|
|
372
|
+
publicSigningKey: JsonWebKey;
|
|
373
|
+
publicEncryptionKey?: JsonWebKey;
|
|
374
|
+
}>;
|
|
375
|
+
getLocalDID(): string | null;
|
|
376
|
+
exportPublicIdentity(): Promise<SecureNodeInfo | null>;
|
|
377
|
+
registerRemoteNode(): Promise<void>;
|
|
378
|
+
getRemotePublicKey(): Promise<JsonWebKey | null>;
|
|
379
|
+
sign(): Promise<Uint8Array>;
|
|
380
|
+
signData<T>(_data: T): Promise<SignedSyncData<T>>;
|
|
381
|
+
verify(): Promise<boolean>;
|
|
382
|
+
verifySignedData(): Promise<boolean>;
|
|
383
|
+
encrypt(): Promise<{
|
|
384
|
+
alg: string;
|
|
385
|
+
ct: string;
|
|
386
|
+
iv: string;
|
|
387
|
+
tag: string;
|
|
388
|
+
epk?: JsonWebKey;
|
|
389
|
+
encryptedAt: number;
|
|
390
|
+
}>;
|
|
391
|
+
decrypt(): Promise<Uint8Array>;
|
|
392
|
+
getSessionKey(): Promise<Uint8Array>;
|
|
393
|
+
encryptWithSessionKey(): Promise<{
|
|
394
|
+
alg: string;
|
|
395
|
+
ct: string;
|
|
396
|
+
iv: string;
|
|
397
|
+
tag: string;
|
|
398
|
+
encryptedAt: number;
|
|
399
|
+
}>;
|
|
400
|
+
decryptWithSessionKey(): Promise<Uint8Array>;
|
|
401
|
+
createUCAN(): Promise<string>;
|
|
402
|
+
verifyUCAN(): Promise<AeonCapabilityResult>;
|
|
403
|
+
delegateCapabilities(): Promise<string>;
|
|
404
|
+
hash(): Promise<Uint8Array>;
|
|
405
|
+
randomBytes(length: number): Uint8Array;
|
|
406
|
+
isInitialized(): boolean;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Sync Coordinator
|
|
411
|
+
*
|
|
412
|
+
* Coordinates synchronization between multiple nodes in a distributed system.
|
|
413
|
+
* Manages sync sessions, node registration, and synchronization workflows.
|
|
414
|
+
*
|
|
415
|
+
* Features:
|
|
416
|
+
* - Node registration and discovery
|
|
417
|
+
* - Sync session management
|
|
418
|
+
* - Synchronization workflow orchestration
|
|
419
|
+
* - Node health monitoring
|
|
420
|
+
* - Conflict detection and resolution coordination
|
|
421
|
+
* - DID-based node identification
|
|
422
|
+
* - Authenticated sync sessions
|
|
423
|
+
*/
|
|
424
|
+
|
|
425
|
+
interface SyncNode {
|
|
426
|
+
id: string;
|
|
427
|
+
address: string;
|
|
428
|
+
port: number;
|
|
429
|
+
status: 'online' | 'offline' | 'syncing';
|
|
430
|
+
lastHeartbeat: string;
|
|
431
|
+
version: string;
|
|
432
|
+
capabilities: string[];
|
|
433
|
+
did?: string;
|
|
434
|
+
publicSigningKey?: JsonWebKey;
|
|
435
|
+
publicEncryptionKey?: JsonWebKey;
|
|
436
|
+
grantedCapabilities?: string[];
|
|
437
|
+
}
|
|
438
|
+
interface SyncSession {
|
|
439
|
+
id: string;
|
|
440
|
+
initiatorId: string;
|
|
441
|
+
participantIds: string[];
|
|
442
|
+
status: 'pending' | 'active' | 'completed' | 'failed';
|
|
443
|
+
startTime: string;
|
|
444
|
+
endTime?: string;
|
|
445
|
+
itemsSynced: number;
|
|
446
|
+
itemsFailed: number;
|
|
447
|
+
conflictsDetected: number;
|
|
448
|
+
initiatorDID?: string;
|
|
449
|
+
participantDIDs?: string[];
|
|
450
|
+
encryptionMode?: AeonEncryptionMode;
|
|
451
|
+
requiredCapabilities?: string[];
|
|
452
|
+
sessionToken?: string;
|
|
453
|
+
}
|
|
454
|
+
interface SyncEvent {
|
|
455
|
+
type: 'node-joined' | 'node-left' | 'sync-started' | 'sync-completed' | 'conflict-detected';
|
|
456
|
+
sessionId?: string;
|
|
457
|
+
nodeId: string;
|
|
458
|
+
timestamp: string;
|
|
459
|
+
data?: unknown;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Sync Coordinator
|
|
463
|
+
* Coordinates synchronization across distributed nodes
|
|
464
|
+
*/
|
|
465
|
+
declare class SyncCoordinator extends EventEmitter {
|
|
466
|
+
private nodes;
|
|
467
|
+
private sessions;
|
|
468
|
+
private syncEvents;
|
|
469
|
+
private nodeHeartbeats;
|
|
470
|
+
private heartbeatInterval;
|
|
471
|
+
private cryptoProvider;
|
|
472
|
+
private nodesByDID;
|
|
473
|
+
constructor();
|
|
474
|
+
/**
|
|
475
|
+
* Configure cryptographic provider for authenticated sync
|
|
476
|
+
*/
|
|
477
|
+
configureCrypto(provider: ICryptoProvider): void;
|
|
478
|
+
/**
|
|
479
|
+
* Check if crypto is configured
|
|
480
|
+
*/
|
|
481
|
+
isCryptoEnabled(): boolean;
|
|
482
|
+
/**
|
|
483
|
+
* Register a node with DID-based identity
|
|
484
|
+
*/
|
|
485
|
+
registerAuthenticatedNode(nodeInfo: Omit<SyncNode, 'did' | 'publicSigningKey' | 'publicEncryptionKey'> & {
|
|
486
|
+
did: string;
|
|
487
|
+
publicSigningKey: JsonWebKey;
|
|
488
|
+
publicEncryptionKey?: JsonWebKey;
|
|
489
|
+
}): Promise<SyncNode>;
|
|
490
|
+
/**
|
|
491
|
+
* Get node by DID
|
|
492
|
+
*/
|
|
493
|
+
getNodeByDID(did: string): SyncNode | undefined;
|
|
494
|
+
/**
|
|
495
|
+
* Get all authenticated nodes (nodes with DIDs)
|
|
496
|
+
*/
|
|
497
|
+
getAuthenticatedNodes(): SyncNode[];
|
|
498
|
+
/**
|
|
499
|
+
* Create an authenticated sync session with UCAN-based authorization
|
|
500
|
+
*/
|
|
501
|
+
createAuthenticatedSyncSession(initiatorDID: string, participantDIDs: string[], options?: {
|
|
502
|
+
encryptionMode?: AeonEncryptionMode;
|
|
503
|
+
requiredCapabilities?: string[];
|
|
504
|
+
}): Promise<SyncSession>;
|
|
505
|
+
/**
|
|
506
|
+
* Verify a node's UCAN capabilities for a session
|
|
507
|
+
*/
|
|
508
|
+
verifyNodeCapabilities(sessionId: string, nodeDID: string, token: string): Promise<{
|
|
509
|
+
authorized: boolean;
|
|
510
|
+
error?: string;
|
|
511
|
+
}>;
|
|
512
|
+
/**
|
|
513
|
+
* Register a node in the cluster
|
|
514
|
+
*/
|
|
515
|
+
registerNode(node: SyncNode): void;
|
|
516
|
+
/**
|
|
517
|
+
* Deregister a node from the cluster
|
|
518
|
+
*/
|
|
519
|
+
deregisterNode(nodeId: string): void;
|
|
520
|
+
/**
|
|
521
|
+
* Create a new sync session
|
|
522
|
+
*/
|
|
523
|
+
createSyncSession(initiatorId: string, participantIds: string[]): SyncSession;
|
|
524
|
+
/**
|
|
525
|
+
* Update sync session
|
|
526
|
+
*/
|
|
527
|
+
updateSyncSession(sessionId: string, updates: Partial<SyncSession>): void;
|
|
528
|
+
/**
|
|
529
|
+
* Record a conflict during sync
|
|
530
|
+
*/
|
|
531
|
+
recordConflict(sessionId: string, nodeId: string, conflictData?: unknown): void;
|
|
532
|
+
/**
|
|
533
|
+
* Update node status
|
|
534
|
+
*/
|
|
535
|
+
updateNodeStatus(nodeId: string, status: SyncNode['status']): void;
|
|
536
|
+
/**
|
|
537
|
+
* Record heartbeat from node
|
|
538
|
+
*/
|
|
539
|
+
recordHeartbeat(nodeId: string): void;
|
|
540
|
+
/**
|
|
541
|
+
* Get all nodes
|
|
542
|
+
*/
|
|
543
|
+
getNodes(): SyncNode[];
|
|
544
|
+
/**
|
|
545
|
+
* Get node by ID
|
|
546
|
+
*/
|
|
547
|
+
getNode(nodeId: string): SyncNode | undefined;
|
|
548
|
+
/**
|
|
549
|
+
* Get online nodes
|
|
550
|
+
*/
|
|
551
|
+
getOnlineNodes(): SyncNode[];
|
|
552
|
+
/**
|
|
553
|
+
* Get nodes by capability
|
|
554
|
+
*/
|
|
555
|
+
getNodesByCapability(capability: string): SyncNode[];
|
|
556
|
+
/**
|
|
557
|
+
* Get sync session
|
|
558
|
+
*/
|
|
559
|
+
getSyncSession(sessionId: string): SyncSession | undefined;
|
|
560
|
+
/**
|
|
561
|
+
* Get all sync sessions
|
|
562
|
+
*/
|
|
563
|
+
getAllSyncSessions(): SyncSession[];
|
|
564
|
+
/**
|
|
565
|
+
* Get active sync sessions
|
|
566
|
+
*/
|
|
567
|
+
getActiveSyncSessions(): SyncSession[];
|
|
568
|
+
/**
|
|
569
|
+
* Get sessions for a node
|
|
570
|
+
*/
|
|
571
|
+
getSessionsForNode(nodeId: string): SyncSession[];
|
|
572
|
+
/**
|
|
573
|
+
* Get sync statistics
|
|
574
|
+
*/
|
|
575
|
+
getStatistics(): {
|
|
576
|
+
totalNodes: number;
|
|
577
|
+
onlineNodes: number;
|
|
578
|
+
offlineNodes: number;
|
|
579
|
+
totalSessions: number;
|
|
580
|
+
activeSessions: number;
|
|
581
|
+
completedSessions: number;
|
|
582
|
+
failedSessions: number;
|
|
583
|
+
successRate: number;
|
|
584
|
+
totalItemsSynced: number;
|
|
585
|
+
totalConflicts: number;
|
|
586
|
+
averageConflictsPerSession: number;
|
|
587
|
+
};
|
|
588
|
+
/**
|
|
589
|
+
* Get sync events
|
|
590
|
+
*/
|
|
591
|
+
getSyncEvents(limit?: number): SyncEvent[];
|
|
592
|
+
/**
|
|
593
|
+
* Get sync events for session
|
|
594
|
+
*/
|
|
595
|
+
getSessionEvents(sessionId: string): SyncEvent[];
|
|
596
|
+
/**
|
|
597
|
+
* Check node health
|
|
598
|
+
*/
|
|
599
|
+
getNodeHealth(): Record<string, {
|
|
600
|
+
isHealthy: boolean;
|
|
601
|
+
downtime: number;
|
|
602
|
+
}>;
|
|
603
|
+
/**
|
|
604
|
+
* Start heartbeat monitoring
|
|
605
|
+
*/
|
|
606
|
+
startHeartbeatMonitoring(interval?: number): void;
|
|
607
|
+
/**
|
|
608
|
+
* Stop heartbeat monitoring
|
|
609
|
+
*/
|
|
610
|
+
stopHeartbeatMonitoring(): void;
|
|
611
|
+
/**
|
|
612
|
+
* Clear all state (for testing)
|
|
613
|
+
*/
|
|
614
|
+
clear(): void;
|
|
615
|
+
/**
|
|
616
|
+
* Get the crypto provider (for advanced usage)
|
|
617
|
+
*/
|
|
618
|
+
getCryptoProvider(): ICryptoProvider | null;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* Replication Manager
|
|
623
|
+
*
|
|
624
|
+
* Manages data replication across multiple nodes.
|
|
625
|
+
* Handles replication policies, consistency levels, and replica coordination.
|
|
626
|
+
*
|
|
627
|
+
* Features:
|
|
628
|
+
* - Replica set management
|
|
629
|
+
* - Replication policy enforcement
|
|
630
|
+
* - Consistency level tracking
|
|
631
|
+
* - Replication health monitoring
|
|
632
|
+
* - Replica synchronization coordination
|
|
633
|
+
* - End-to-end encryption for replicated data
|
|
634
|
+
* - DID-based replica authentication
|
|
635
|
+
*/
|
|
636
|
+
|
|
637
|
+
interface Replica {
|
|
638
|
+
id: string;
|
|
639
|
+
nodeId: string;
|
|
640
|
+
status: 'primary' | 'secondary' | 'syncing' | 'failed';
|
|
641
|
+
lastSyncTime: string;
|
|
642
|
+
lagBytes: number;
|
|
643
|
+
lagMillis: number;
|
|
644
|
+
did?: string;
|
|
645
|
+
encrypted?: boolean;
|
|
646
|
+
}
|
|
647
|
+
interface ReplicationPolicy {
|
|
648
|
+
id: string;
|
|
649
|
+
name: string;
|
|
650
|
+
replicationFactor: number;
|
|
651
|
+
consistencyLevel: 'eventual' | 'read-after-write' | 'strong';
|
|
652
|
+
syncInterval: number;
|
|
653
|
+
maxReplicationLag: number;
|
|
654
|
+
encryptionMode?: AeonEncryptionMode;
|
|
655
|
+
requiredCapabilities?: string[];
|
|
656
|
+
}
|
|
657
|
+
interface ReplicationEvent {
|
|
658
|
+
type: 'replica-added' | 'replica-removed' | 'replica-synced' | 'sync-failed';
|
|
659
|
+
replicaId: string;
|
|
660
|
+
nodeId: string;
|
|
661
|
+
timestamp: string;
|
|
662
|
+
details?: unknown;
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Encrypted replication data envelope
|
|
666
|
+
*/
|
|
667
|
+
interface EncryptedReplicationData {
|
|
668
|
+
/** Encrypted ciphertext (base64) */
|
|
669
|
+
ct: string;
|
|
670
|
+
/** Initialization vector (base64) */
|
|
671
|
+
iv: string;
|
|
672
|
+
/** Authentication tag (base64) */
|
|
673
|
+
tag: string;
|
|
674
|
+
/** Ephemeral public key for ECIES */
|
|
675
|
+
epk?: JsonWebKey;
|
|
676
|
+
/** Sender DID */
|
|
677
|
+
senderDID?: string;
|
|
678
|
+
/** Target replica DID */
|
|
679
|
+
targetDID?: string;
|
|
680
|
+
/** Encryption timestamp */
|
|
681
|
+
encryptedAt: number;
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Replication Manager
|
|
685
|
+
* Manages data replication across distributed nodes
|
|
686
|
+
*/
|
|
687
|
+
declare class ReplicationManager {
|
|
688
|
+
private replicas;
|
|
689
|
+
private policies;
|
|
690
|
+
private replicationEvents;
|
|
691
|
+
private syncStatus;
|
|
692
|
+
private cryptoProvider;
|
|
693
|
+
private replicasByDID;
|
|
694
|
+
/**
|
|
695
|
+
* Configure cryptographic provider for encrypted replication
|
|
696
|
+
*/
|
|
697
|
+
configureCrypto(provider: ICryptoProvider): void;
|
|
698
|
+
/**
|
|
699
|
+
* Check if crypto is configured
|
|
700
|
+
*/
|
|
701
|
+
isCryptoEnabled(): boolean;
|
|
702
|
+
/**
|
|
703
|
+
* Register an authenticated replica with DID
|
|
704
|
+
*/
|
|
705
|
+
registerAuthenticatedReplica(replica: Omit<Replica, 'did' | 'encrypted'> & {
|
|
706
|
+
did: string;
|
|
707
|
+
publicSigningKey?: JsonWebKey;
|
|
708
|
+
publicEncryptionKey?: JsonWebKey;
|
|
709
|
+
}, encrypted?: boolean): Promise<Replica>;
|
|
710
|
+
/**
|
|
711
|
+
* Get replica by DID
|
|
712
|
+
*/
|
|
713
|
+
getReplicaByDID(did: string): Replica | undefined;
|
|
714
|
+
/**
|
|
715
|
+
* Get all encrypted replicas
|
|
716
|
+
*/
|
|
717
|
+
getEncryptedReplicas(): Replica[];
|
|
718
|
+
/**
|
|
719
|
+
* Encrypt data for replication to a specific replica
|
|
720
|
+
*/
|
|
721
|
+
encryptForReplica(data: unknown, targetReplicaDID: string): Promise<EncryptedReplicationData>;
|
|
722
|
+
/**
|
|
723
|
+
* Decrypt data received from replication
|
|
724
|
+
*/
|
|
725
|
+
decryptReplicationData<T>(encrypted: EncryptedReplicationData): Promise<T>;
|
|
726
|
+
/**
|
|
727
|
+
* Create an encrypted replication policy
|
|
728
|
+
*/
|
|
729
|
+
createEncryptedPolicy(name: string, replicationFactor: number, consistencyLevel: 'eventual' | 'read-after-write' | 'strong', encryptionMode: AeonEncryptionMode, options?: {
|
|
730
|
+
syncInterval?: number;
|
|
731
|
+
maxReplicationLag?: number;
|
|
732
|
+
requiredCapabilities?: string[];
|
|
733
|
+
}): ReplicationPolicy;
|
|
734
|
+
/**
|
|
735
|
+
* Verify a replica's capabilities via UCAN
|
|
736
|
+
*/
|
|
737
|
+
verifyReplicaCapabilities(replicaDID: string, token: string, policyId?: string): Promise<{
|
|
738
|
+
authorized: boolean;
|
|
739
|
+
error?: string;
|
|
740
|
+
}>;
|
|
741
|
+
/**
|
|
742
|
+
* Register a replica
|
|
743
|
+
*/
|
|
744
|
+
registerReplica(replica: Replica): void;
|
|
745
|
+
/**
|
|
746
|
+
* Remove a replica
|
|
747
|
+
*/
|
|
748
|
+
removeReplica(replicaId: string): void;
|
|
749
|
+
/**
|
|
750
|
+
* Create a replication policy
|
|
751
|
+
*/
|
|
752
|
+
createPolicy(name: string, replicationFactor: number, consistencyLevel: 'eventual' | 'read-after-write' | 'strong', syncInterval?: number, maxReplicationLag?: number): ReplicationPolicy;
|
|
753
|
+
/**
|
|
754
|
+
* Update replica status
|
|
755
|
+
*/
|
|
756
|
+
updateReplicaStatus(replicaId: string, status: Replica['status'], lagBytes?: number, lagMillis?: number): void;
|
|
757
|
+
/**
|
|
758
|
+
* Get replicas for node
|
|
759
|
+
*/
|
|
760
|
+
getReplicasForNode(nodeId: string): Replica[];
|
|
761
|
+
/**
|
|
762
|
+
* Get healthy replicas
|
|
763
|
+
*/
|
|
764
|
+
getHealthyReplicas(): Replica[];
|
|
765
|
+
/**
|
|
766
|
+
* Get syncing replicas
|
|
767
|
+
*/
|
|
768
|
+
getSyncingReplicas(): Replica[];
|
|
769
|
+
/**
|
|
770
|
+
* Get failed replicas
|
|
771
|
+
*/
|
|
772
|
+
getFailedReplicas(): Replica[];
|
|
773
|
+
/**
|
|
774
|
+
* Check replication health for policy
|
|
775
|
+
*/
|
|
776
|
+
checkReplicationHealth(policyId: string): {
|
|
777
|
+
healthy: boolean;
|
|
778
|
+
replicasInPolicy: number;
|
|
779
|
+
healthyReplicas: number;
|
|
780
|
+
replicationLag: number;
|
|
781
|
+
};
|
|
782
|
+
/**
|
|
783
|
+
* Get consistency level
|
|
784
|
+
*/
|
|
785
|
+
getConsistencyLevel(policyId: string): 'eventual' | 'read-after-write' | 'strong';
|
|
786
|
+
/**
|
|
787
|
+
* Get replica
|
|
788
|
+
*/
|
|
789
|
+
getReplica(replicaId: string): Replica | undefined;
|
|
790
|
+
/**
|
|
791
|
+
* Get all replicas
|
|
792
|
+
*/
|
|
793
|
+
getAllReplicas(): Replica[];
|
|
794
|
+
/**
|
|
795
|
+
* Get policy
|
|
796
|
+
*/
|
|
797
|
+
getPolicy(policyId: string): ReplicationPolicy | undefined;
|
|
798
|
+
/**
|
|
799
|
+
* Get all policies
|
|
800
|
+
*/
|
|
801
|
+
getAllPolicies(): ReplicationPolicy[];
|
|
802
|
+
/**
|
|
803
|
+
* Get replication statistics
|
|
804
|
+
*/
|
|
805
|
+
getStatistics(): {
|
|
806
|
+
totalReplicas: number;
|
|
807
|
+
healthyReplicas: number;
|
|
808
|
+
syncingReplicas: number;
|
|
809
|
+
failedReplicas: number;
|
|
810
|
+
healthiness: number;
|
|
811
|
+
averageReplicationLagMs: number;
|
|
812
|
+
maxReplicationLagMs: number;
|
|
813
|
+
totalPolicies: number;
|
|
814
|
+
};
|
|
815
|
+
/**
|
|
816
|
+
* Get replication events
|
|
817
|
+
*/
|
|
818
|
+
getReplicationEvents(limit?: number): ReplicationEvent[];
|
|
819
|
+
/**
|
|
820
|
+
* Get sync status for node
|
|
821
|
+
*/
|
|
822
|
+
getSyncStatus(nodeId: string): {
|
|
823
|
+
synced: number;
|
|
824
|
+
failed: number;
|
|
825
|
+
};
|
|
826
|
+
/**
|
|
827
|
+
* Get replication lag distribution
|
|
828
|
+
*/
|
|
829
|
+
getReplicationLagDistribution(): Record<string, number>;
|
|
830
|
+
/**
|
|
831
|
+
* Check if can satisfy consistency level
|
|
832
|
+
*/
|
|
833
|
+
canSatisfyConsistency(policyId: string, _requiredAcks: number): boolean;
|
|
834
|
+
/**
|
|
835
|
+
* Clear all state (for testing)
|
|
836
|
+
*/
|
|
837
|
+
clear(): void;
|
|
838
|
+
/**
|
|
839
|
+
* Get the crypto provider (for advanced usage)
|
|
840
|
+
*/
|
|
841
|
+
getCryptoProvider(): ICryptoProvider | null;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
/**
|
|
845
|
+
* Sync Protocol
|
|
846
|
+
*
|
|
847
|
+
* Handles synchronization protocol messages and handshaking.
|
|
848
|
+
* Manages message serialization, protocol versioning, and compatibility.
|
|
849
|
+
*
|
|
850
|
+
* Features:
|
|
851
|
+
* - Message serialization and deserialization
|
|
852
|
+
* - Protocol version management
|
|
853
|
+
* - Handshake handling
|
|
854
|
+
* - Message validation and error handling
|
|
855
|
+
* - Protocol state machine
|
|
856
|
+
* - Optional cryptographic authentication and encryption
|
|
857
|
+
*/
|
|
858
|
+
|
|
859
|
+
interface SyncMessage {
|
|
860
|
+
type: 'handshake' | 'sync-request' | 'sync-response' | 'ack' | 'error';
|
|
861
|
+
version: string;
|
|
862
|
+
sender: string;
|
|
863
|
+
receiver: string;
|
|
864
|
+
messageId: string;
|
|
865
|
+
timestamp: string;
|
|
866
|
+
payload?: unknown;
|
|
867
|
+
auth?: AuthenticatedMessageFields;
|
|
868
|
+
}
|
|
869
|
+
interface Handshake {
|
|
870
|
+
protocolVersion: string;
|
|
871
|
+
nodeId: string;
|
|
872
|
+
capabilities: string[];
|
|
873
|
+
state: 'initiating' | 'responding' | 'completed';
|
|
874
|
+
did?: string;
|
|
875
|
+
publicSigningKey?: JsonWebKey;
|
|
876
|
+
publicEncryptionKey?: JsonWebKey;
|
|
877
|
+
ucan?: string;
|
|
878
|
+
}
|
|
879
|
+
/**
|
|
880
|
+
* Crypto configuration for sync protocol
|
|
881
|
+
*/
|
|
882
|
+
interface SyncProtocolCryptoConfig {
|
|
883
|
+
/** Encryption mode for messages */
|
|
884
|
+
encryptionMode: AeonEncryptionMode;
|
|
885
|
+
/** Require all messages to be signed */
|
|
886
|
+
requireSignatures: boolean;
|
|
887
|
+
/** Require UCAN capability verification */
|
|
888
|
+
requireCapabilities: boolean;
|
|
889
|
+
/** Required capabilities for sync operations */
|
|
890
|
+
requiredCapabilities?: Array<{
|
|
891
|
+
can: string;
|
|
892
|
+
with: string;
|
|
893
|
+
}>;
|
|
894
|
+
}
|
|
895
|
+
interface SyncRequest {
|
|
896
|
+
sessionId: string;
|
|
897
|
+
fromVersion: string;
|
|
898
|
+
toVersion: string;
|
|
899
|
+
filter?: Record<string, unknown>;
|
|
900
|
+
}
|
|
901
|
+
interface SyncResponse {
|
|
902
|
+
sessionId: string;
|
|
903
|
+
fromVersion: string;
|
|
904
|
+
toVersion: string;
|
|
905
|
+
data: unknown[];
|
|
906
|
+
hasMore: boolean;
|
|
907
|
+
offset: number;
|
|
908
|
+
}
|
|
909
|
+
interface ProtocolError {
|
|
910
|
+
code: string;
|
|
911
|
+
message: string;
|
|
912
|
+
recoverable: boolean;
|
|
913
|
+
}
|
|
914
|
+
/**
|
|
915
|
+
* Sync Protocol
|
|
916
|
+
* Handles synchronization protocol messages and handshaking
|
|
917
|
+
*/
|
|
918
|
+
declare class SyncProtocol {
|
|
919
|
+
private version;
|
|
920
|
+
private messageQueue;
|
|
921
|
+
private messageMap;
|
|
922
|
+
private handshakes;
|
|
923
|
+
private protocolErrors;
|
|
924
|
+
private messageCounter;
|
|
925
|
+
private cryptoProvider;
|
|
926
|
+
private cryptoConfig;
|
|
927
|
+
/**
|
|
928
|
+
* Configure cryptographic provider for authenticated/encrypted messages
|
|
929
|
+
*/
|
|
930
|
+
configureCrypto(provider: ICryptoProvider, config?: Partial<SyncProtocolCryptoConfig>): void;
|
|
931
|
+
/**
|
|
932
|
+
* Check if crypto is configured
|
|
933
|
+
*/
|
|
934
|
+
isCryptoEnabled(): boolean;
|
|
935
|
+
/**
|
|
936
|
+
* Get crypto configuration
|
|
937
|
+
*/
|
|
938
|
+
getCryptoConfig(): SyncProtocolCryptoConfig | null;
|
|
939
|
+
/**
|
|
940
|
+
* Get protocol version
|
|
941
|
+
*/
|
|
942
|
+
getVersion(): string;
|
|
943
|
+
/**
|
|
944
|
+
* Create authenticated handshake message with DID and keys
|
|
945
|
+
*/
|
|
946
|
+
createAuthenticatedHandshake(capabilities: string[], targetDID?: string): Promise<SyncMessage>;
|
|
947
|
+
/**
|
|
948
|
+
* Verify and process an authenticated handshake
|
|
949
|
+
*/
|
|
950
|
+
verifyAuthenticatedHandshake(message: SyncMessage): Promise<{
|
|
951
|
+
valid: boolean;
|
|
952
|
+
handshake?: Handshake;
|
|
953
|
+
error?: string;
|
|
954
|
+
}>;
|
|
955
|
+
/**
|
|
956
|
+
* Sign and optionally encrypt a message payload
|
|
957
|
+
*/
|
|
958
|
+
signMessage<T>(message: SyncMessage, payload: T, encrypt?: boolean): Promise<SyncMessage>;
|
|
959
|
+
/**
|
|
960
|
+
* Verify signature and optionally decrypt a message
|
|
961
|
+
*/
|
|
962
|
+
verifyMessage<T>(message: SyncMessage): Promise<{
|
|
963
|
+
valid: boolean;
|
|
964
|
+
payload?: T;
|
|
965
|
+
error?: string;
|
|
966
|
+
}>;
|
|
967
|
+
/**
|
|
968
|
+
* Create handshake message
|
|
969
|
+
*/
|
|
970
|
+
createHandshakeMessage(nodeId: string, capabilities: string[]): SyncMessage;
|
|
971
|
+
/**
|
|
972
|
+
* Create sync request message
|
|
973
|
+
*/
|
|
974
|
+
createSyncRequestMessage(sender: string, receiver: string, sessionId: string, fromVersion: string, toVersion: string, filter?: Record<string, unknown>): SyncMessage;
|
|
975
|
+
/**
|
|
976
|
+
* Create sync response message
|
|
977
|
+
*/
|
|
978
|
+
createSyncResponseMessage(sender: string, receiver: string, sessionId: string, fromVersion: string, toVersion: string, data: unknown[], hasMore?: boolean, offset?: number): SyncMessage;
|
|
979
|
+
/**
|
|
980
|
+
* Create acknowledgement message
|
|
981
|
+
*/
|
|
982
|
+
createAckMessage(sender: string, receiver: string, messageId: string): SyncMessage;
|
|
983
|
+
/**
|
|
984
|
+
* Create error message
|
|
985
|
+
*/
|
|
986
|
+
createErrorMessage(sender: string, receiver: string, error: ProtocolError, relatedMessageId?: string): SyncMessage;
|
|
987
|
+
/**
|
|
988
|
+
* Validate message
|
|
989
|
+
*/
|
|
990
|
+
validateMessage(message: SyncMessage): {
|
|
991
|
+
valid: boolean;
|
|
992
|
+
errors: string[];
|
|
993
|
+
};
|
|
994
|
+
/**
|
|
995
|
+
* Serialize message
|
|
996
|
+
*/
|
|
997
|
+
serializeMessage(message: SyncMessage): string;
|
|
998
|
+
/**
|
|
999
|
+
* Deserialize message
|
|
1000
|
+
*/
|
|
1001
|
+
deserializeMessage(data: string): SyncMessage;
|
|
1002
|
+
/**
|
|
1003
|
+
* Process handshake
|
|
1004
|
+
*/
|
|
1005
|
+
processHandshake(message: SyncMessage): Handshake;
|
|
1006
|
+
/**
|
|
1007
|
+
* Get message
|
|
1008
|
+
*/
|
|
1009
|
+
getMessage(messageId: string): SyncMessage | undefined;
|
|
1010
|
+
/**
|
|
1011
|
+
* Get all messages
|
|
1012
|
+
*/
|
|
1013
|
+
getAllMessages(): SyncMessage[];
|
|
1014
|
+
/**
|
|
1015
|
+
* Get messages by type
|
|
1016
|
+
*/
|
|
1017
|
+
getMessagesByType(type: SyncMessage['type']): SyncMessage[];
|
|
1018
|
+
/**
|
|
1019
|
+
* Get messages from sender
|
|
1020
|
+
*/
|
|
1021
|
+
getMessagesFromSender(sender: string): SyncMessage[];
|
|
1022
|
+
/**
|
|
1023
|
+
* Get pending messages
|
|
1024
|
+
*/
|
|
1025
|
+
getPendingMessages(receiver: string): SyncMessage[];
|
|
1026
|
+
/**
|
|
1027
|
+
* Get handshakes
|
|
1028
|
+
*/
|
|
1029
|
+
getHandshakes(): Map<string, Handshake>;
|
|
1030
|
+
/**
|
|
1031
|
+
* Get protocol statistics
|
|
1032
|
+
*/
|
|
1033
|
+
getStatistics(): {
|
|
1034
|
+
totalMessages: number;
|
|
1035
|
+
messagesByType: Record<string, number>;
|
|
1036
|
+
totalHandshakes: number;
|
|
1037
|
+
totalErrors: number;
|
|
1038
|
+
recoverableErrors: number;
|
|
1039
|
+
unrecoverableErrors: number;
|
|
1040
|
+
};
|
|
1041
|
+
/**
|
|
1042
|
+
* Get protocol errors
|
|
1043
|
+
*/
|
|
1044
|
+
getErrors(): Array<{
|
|
1045
|
+
error: ProtocolError;
|
|
1046
|
+
timestamp: string;
|
|
1047
|
+
}>;
|
|
1048
|
+
/**
|
|
1049
|
+
* Generate message ID
|
|
1050
|
+
*/
|
|
1051
|
+
private generateMessageId;
|
|
1052
|
+
/**
|
|
1053
|
+
* Clear all state (for testing)
|
|
1054
|
+
*/
|
|
1055
|
+
clear(): void;
|
|
1056
|
+
/**
|
|
1057
|
+
* Get the crypto provider (for advanced usage)
|
|
1058
|
+
*/
|
|
1059
|
+
getCryptoProvider(): ICryptoProvider | null;
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
/**
|
|
1063
|
+
* State Reconciler
|
|
1064
|
+
*
|
|
1065
|
+
* Reconciles conflicting state across multiple nodes in a distributed system.
|
|
1066
|
+
* Applies merge strategies and resolves divergent state.
|
|
1067
|
+
*
|
|
1068
|
+
* Features:
|
|
1069
|
+
* - State comparison and diff generation
|
|
1070
|
+
* - Multiple merge strategies (last-write-wins, vector-clock based, custom)
|
|
1071
|
+
* - Conflict detection and resolution
|
|
1072
|
+
* - State validation and verification
|
|
1073
|
+
* - Version tracking
|
|
1074
|
+
* - Cryptographic verification of state versions
|
|
1075
|
+
* - Signed state for tamper detection
|
|
1076
|
+
*/
|
|
1077
|
+
|
|
1078
|
+
interface StateVersion {
|
|
1079
|
+
version: string;
|
|
1080
|
+
timestamp: string;
|
|
1081
|
+
nodeId: string;
|
|
1082
|
+
hash: string;
|
|
1083
|
+
data: unknown;
|
|
1084
|
+
signerDID?: string;
|
|
1085
|
+
signature?: string;
|
|
1086
|
+
signedAt?: number;
|
|
1087
|
+
}
|
|
1088
|
+
interface StateDiff {
|
|
1089
|
+
added: Record<string, unknown>;
|
|
1090
|
+
modified: Record<string, {
|
|
1091
|
+
old: unknown;
|
|
1092
|
+
new: unknown;
|
|
1093
|
+
}>;
|
|
1094
|
+
removed: string[];
|
|
1095
|
+
timestamp: string;
|
|
1096
|
+
}
|
|
1097
|
+
interface ReconciliationResult {
|
|
1098
|
+
success: boolean;
|
|
1099
|
+
mergedState: unknown;
|
|
1100
|
+
conflictsResolved: number;
|
|
1101
|
+
strategy: string;
|
|
1102
|
+
timestamp: string;
|
|
1103
|
+
}
|
|
1104
|
+
type MergeStrategy = 'last-write-wins' | 'vector-clock' | 'majority-vote' | 'custom';
|
|
1105
|
+
/**
|
|
1106
|
+
* State Reconciler
|
|
1107
|
+
* Reconciles state conflicts across distributed nodes
|
|
1108
|
+
*/
|
|
1109
|
+
declare class StateReconciler {
|
|
1110
|
+
private stateVersions;
|
|
1111
|
+
private reconciliationHistory;
|
|
1112
|
+
private cryptoProvider;
|
|
1113
|
+
private requireSignedVersions;
|
|
1114
|
+
/**
|
|
1115
|
+
* Configure cryptographic provider for signed state versions
|
|
1116
|
+
*/
|
|
1117
|
+
configureCrypto(provider: ICryptoProvider, requireSigned?: boolean): void;
|
|
1118
|
+
/**
|
|
1119
|
+
* Check if crypto is configured
|
|
1120
|
+
*/
|
|
1121
|
+
isCryptoEnabled(): boolean;
|
|
1122
|
+
/**
|
|
1123
|
+
* Record a signed state version with cryptographic verification
|
|
1124
|
+
*/
|
|
1125
|
+
recordSignedStateVersion(key: string, version: string, data: unknown): Promise<StateVersion>;
|
|
1126
|
+
/**
|
|
1127
|
+
* Verify a state version's signature
|
|
1128
|
+
*/
|
|
1129
|
+
verifyStateVersion(version: StateVersion): Promise<{
|
|
1130
|
+
valid: boolean;
|
|
1131
|
+
error?: string;
|
|
1132
|
+
}>;
|
|
1133
|
+
/**
|
|
1134
|
+
* Reconcile with verification - only accept verified versions
|
|
1135
|
+
*/
|
|
1136
|
+
reconcileWithVerification(key: string, strategy?: MergeStrategy): Promise<ReconciliationResult & {
|
|
1137
|
+
verificationErrors: string[];
|
|
1138
|
+
}>;
|
|
1139
|
+
/**
|
|
1140
|
+
* Record a state version
|
|
1141
|
+
*/
|
|
1142
|
+
recordStateVersion(key: string, version: string, timestamp: string, nodeId: string, hash: string, data: unknown): void;
|
|
1143
|
+
/**
|
|
1144
|
+
* Detect conflicts in state versions
|
|
1145
|
+
*/
|
|
1146
|
+
detectConflicts(key: string): boolean;
|
|
1147
|
+
/**
|
|
1148
|
+
* Compare two states and generate diff
|
|
1149
|
+
*/
|
|
1150
|
+
compareStates(state1: Record<string, unknown>, state2: Record<string, unknown>): StateDiff;
|
|
1151
|
+
/**
|
|
1152
|
+
* Reconcile states using last-write-wins strategy
|
|
1153
|
+
*/
|
|
1154
|
+
reconcileLastWriteWins(versions: StateVersion[]): ReconciliationResult;
|
|
1155
|
+
/**
|
|
1156
|
+
* Reconcile states using vector clock strategy
|
|
1157
|
+
*/
|
|
1158
|
+
reconcileVectorClock(versions: StateVersion[]): ReconciliationResult;
|
|
1159
|
+
/**
|
|
1160
|
+
* Reconcile states using majority vote strategy
|
|
1161
|
+
*/
|
|
1162
|
+
reconcileMajorityVote(versions: StateVersion[]): ReconciliationResult;
|
|
1163
|
+
/**
|
|
1164
|
+
* Merge multiple states
|
|
1165
|
+
*/
|
|
1166
|
+
mergeStates(states: Record<string, unknown>[]): unknown;
|
|
1167
|
+
/**
|
|
1168
|
+
* Validate state after reconciliation
|
|
1169
|
+
*/
|
|
1170
|
+
validateState(state: unknown): {
|
|
1171
|
+
valid: boolean;
|
|
1172
|
+
errors: string[];
|
|
1173
|
+
};
|
|
1174
|
+
/**
|
|
1175
|
+
* Get state versions for a key
|
|
1176
|
+
*/
|
|
1177
|
+
getStateVersions(key: string): StateVersion[];
|
|
1178
|
+
/**
|
|
1179
|
+
* Get all state versions
|
|
1180
|
+
*/
|
|
1181
|
+
getAllStateVersions(): Record<string, StateVersion[]>;
|
|
1182
|
+
/**
|
|
1183
|
+
* Get reconciliation history
|
|
1184
|
+
*/
|
|
1185
|
+
getReconciliationHistory(): ReconciliationResult[];
|
|
1186
|
+
/**
|
|
1187
|
+
* Get reconciliation statistics
|
|
1188
|
+
*/
|
|
1189
|
+
getStatistics(): {
|
|
1190
|
+
totalReconciliations: number;
|
|
1191
|
+
successfulReconciliations: number;
|
|
1192
|
+
totalConflictsResolved: number;
|
|
1193
|
+
averageConflictsPerReconciliation: number;
|
|
1194
|
+
strategyUsage: Record<string, number>;
|
|
1195
|
+
trackedKeys: number;
|
|
1196
|
+
};
|
|
1197
|
+
/**
|
|
1198
|
+
* Clear all state (for testing)
|
|
1199
|
+
*/
|
|
1200
|
+
clear(): void;
|
|
1201
|
+
/**
|
|
1202
|
+
* Get the crypto provider (for advanced usage)
|
|
1203
|
+
*/
|
|
1204
|
+
getCryptoProvider(): ICryptoProvider | null;
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
export { AEON_CAPABILITIES as A, type SyncRequest as B, type Capability as C, DEFAULT_CRYPTO_CONFIG as D, type ECKeyPair as E, type SyncResponse as F, type SyncSession as G, type Handshake as H, type ICryptoProvider as I, type UCANToken as J, type KeyPair as K, type MergeStrategy as M, NullCryptoProvider as N, type ProtocolError as P, type ReconciliationResult as R, type SecureNodeInfo as S, type UCANPayload as U, type VerificationResult as V, type AeonCapability as a, type AeonCapabilityResult as b, type AeonCryptoConfig as c, type AeonEncryptionMode as d, type AuthenticatedMessageFields as e, type DID as f, type DecryptionResult as g, type DomainCategory as h, type EncryptedPayload as i, type EncryptionAlgorithm as j, type Identity as k, type Replica as l, type ReplicationEvent as m, ReplicationManager as n, type ReplicationPolicy as o, type SecureSyncSession as p, type SignedSyncData as q, type SigningAlgorithm as r, type StateDiff as s, StateReconciler as t, type StateVersion as u, SyncCoordinator as v, type SyncEvent as w, type SyncMessage as x, type SyncNode as y, SyncProtocol as z };
|