@affectively/aeon 1.0.0 → 1.2.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/README.md +10 -0
- package/dist/compression/index.cjs +580 -0
- package/dist/compression/index.cjs.map +1 -0
- package/dist/compression/index.d.cts +189 -0
- package/dist/compression/index.d.ts +189 -0
- package/dist/compression/index.js +573 -0
- package/dist/compression/index.js.map +1 -0
- package/dist/core/index.d.cts +70 -5
- package/dist/core/index.d.ts +70 -5
- package/dist/crypto/index.cjs +100 -0
- package/dist/crypto/index.cjs.map +1 -0
- package/dist/crypto/index.d.cts +407 -0
- package/dist/crypto/index.d.ts +407 -0
- package/dist/crypto/index.js +96 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/distributed/index.cjs +420 -23
- package/dist/distributed/index.cjs.map +1 -1
- package/dist/distributed/index.d.cts +901 -2
- package/dist/distributed/index.d.ts +901 -2
- package/dist/distributed/index.js +420 -23
- package/dist/distributed/index.js.map +1 -1
- package/dist/index.cjs +1222 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -811
- package/dist/index.d.ts +11 -811
- package/dist/index.js +1221 -56
- package/dist/index.js.map +1 -1
- package/dist/offline/index.cjs +419 -0
- package/dist/offline/index.cjs.map +1 -0
- package/dist/offline/index.d.cts +148 -0
- package/dist/offline/index.d.ts +148 -0
- package/dist/offline/index.js +415 -0
- package/dist/offline/index.js.map +1 -0
- package/dist/optimization/index.cjs +797 -0
- package/dist/optimization/index.cjs.map +1 -0
- package/dist/optimization/index.d.cts +347 -0
- package/dist/optimization/index.d.ts +347 -0
- package/dist/optimization/index.js +787 -0
- package/dist/optimization/index.js.map +1 -0
- package/dist/persistence/index.cjs +145 -0
- package/dist/persistence/index.cjs.map +1 -0
- package/dist/persistence/index.d.cts +63 -0
- package/dist/persistence/index.d.ts +63 -0
- package/dist/persistence/index.js +142 -0
- package/dist/persistence/index.js.map +1 -0
- package/dist/presence/index.cjs +489 -0
- package/dist/presence/index.cjs.map +1 -0
- package/dist/presence/index.d.cts +283 -0
- package/dist/presence/index.d.ts +283 -0
- package/dist/presence/index.js +485 -0
- package/dist/presence/index.js.map +1 -0
- package/dist/types-CMxO7QF0.d.cts +33 -0
- package/dist/types-CMxO7QF0.d.ts +33 -0
- package/dist/versioning/index.cjs +296 -14
- package/dist/versioning/index.cjs.map +1 -1
- package/dist/versioning/index.d.cts +66 -1
- package/dist/versioning/index.d.ts +66 -1
- package/dist/versioning/index.js +296 -14
- package/dist/versioning/index.js.map +1 -1
- package/package.json +51 -1
- package/dist/index-C_4CMV5c.d.cts +0 -1207
- package/dist/index-C_4CMV5c.d.ts +0 -1207
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aeon Crypto Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for cryptographic operations in Aeon.
|
|
5
|
+
* These are compatible with @affectively/ucan and @affectively/zk-encryption.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Decentralized Identifier (DID)
|
|
9
|
+
* Format: did:method:identifier
|
|
10
|
+
*/
|
|
11
|
+
type DID = `did:${string}:${string}`;
|
|
12
|
+
/**
|
|
13
|
+
* Supported signing algorithms
|
|
14
|
+
*/
|
|
15
|
+
type SigningAlgorithm = 'ES256' | 'Ed25519' | 'ES384' | 'ES512';
|
|
16
|
+
/**
|
|
17
|
+
* Key pair for signing and verification
|
|
18
|
+
*/
|
|
19
|
+
interface KeyPair {
|
|
20
|
+
algorithm: SigningAlgorithm;
|
|
21
|
+
publicKey: JsonWebKey;
|
|
22
|
+
privateKey?: JsonWebKey;
|
|
23
|
+
fingerprint: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Identity representing a user or node
|
|
27
|
+
*/
|
|
28
|
+
interface Identity {
|
|
29
|
+
did: DID;
|
|
30
|
+
signingKey: KeyPair;
|
|
31
|
+
encryptionKey?: KeyPair;
|
|
32
|
+
createdAt: number;
|
|
33
|
+
displayName?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* UCAN Capability structure
|
|
37
|
+
*/
|
|
38
|
+
interface Capability {
|
|
39
|
+
can: string;
|
|
40
|
+
with: string;
|
|
41
|
+
constraints?: Record<string, unknown>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* UCAN Token payload
|
|
45
|
+
*/
|
|
46
|
+
interface UCANPayload {
|
|
47
|
+
iss: DID;
|
|
48
|
+
aud: DID;
|
|
49
|
+
exp: number;
|
|
50
|
+
nbf?: number;
|
|
51
|
+
iat?: number;
|
|
52
|
+
nonce?: string;
|
|
53
|
+
jti?: string;
|
|
54
|
+
att: Capability[];
|
|
55
|
+
prf?: string[];
|
|
56
|
+
fct?: Record<string, unknown>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Parsed UCAN Token
|
|
60
|
+
*/
|
|
61
|
+
interface UCANToken {
|
|
62
|
+
payload: UCANPayload;
|
|
63
|
+
raw: string;
|
|
64
|
+
signature: Uint8Array;
|
|
65
|
+
algorithm: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* UCAN verification result
|
|
69
|
+
*/
|
|
70
|
+
interface VerificationResult {
|
|
71
|
+
valid: boolean;
|
|
72
|
+
payload?: UCANPayload;
|
|
73
|
+
error?: string;
|
|
74
|
+
expired?: boolean;
|
|
75
|
+
shouldRotate?: boolean;
|
|
76
|
+
expiresIn?: number;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Encryption algorithms supported
|
|
80
|
+
*/
|
|
81
|
+
type EncryptionAlgorithm = 'ECIES-P256' | 'AES-256-GCM';
|
|
82
|
+
/**
|
|
83
|
+
* HKDF domain separator categories
|
|
84
|
+
*/
|
|
85
|
+
type DomainCategory = 'default' | 'sync' | 'message' | 'api-key' | 'personal-data' | string;
|
|
86
|
+
/**
|
|
87
|
+
* EC Key pair for ECDH operations
|
|
88
|
+
*/
|
|
89
|
+
interface ECKeyPair {
|
|
90
|
+
publicKey: JsonWebKey;
|
|
91
|
+
privateKey: JsonWebKey;
|
|
92
|
+
keyId: string;
|
|
93
|
+
createdAt: string;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Encrypted data envelope
|
|
97
|
+
*/
|
|
98
|
+
interface EncryptedPayload {
|
|
99
|
+
alg: EncryptionAlgorithm;
|
|
100
|
+
ct: string;
|
|
101
|
+
iv: string;
|
|
102
|
+
tag: string;
|
|
103
|
+
epk?: JsonWebKey;
|
|
104
|
+
category?: DomainCategory;
|
|
105
|
+
nonce?: string;
|
|
106
|
+
encryptedAt: number;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Decryption result
|
|
110
|
+
*/
|
|
111
|
+
interface DecryptionResult {
|
|
112
|
+
plaintext: Uint8Array;
|
|
113
|
+
category?: DomainCategory;
|
|
114
|
+
encryptedAt: number;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Aeon encryption mode
|
|
118
|
+
*/
|
|
119
|
+
type AeonEncryptionMode = 'none' | 'transport' | 'at-rest' | 'end-to-end';
|
|
120
|
+
/**
|
|
121
|
+
* Aeon sync capability namespace
|
|
122
|
+
*/
|
|
123
|
+
declare const AEON_CAPABILITIES: {
|
|
124
|
+
readonly SYNC_READ: "aeon:sync:read";
|
|
125
|
+
readonly SYNC_WRITE: "aeon:sync:write";
|
|
126
|
+
readonly SYNC_ADMIN: "aeon:sync:admin";
|
|
127
|
+
readonly NODE_REGISTER: "aeon:node:register";
|
|
128
|
+
readonly NODE_HEARTBEAT: "aeon:node:heartbeat";
|
|
129
|
+
readonly REPLICATE_READ: "aeon:replicate:read";
|
|
130
|
+
readonly REPLICATE_WRITE: "aeon:replicate:write";
|
|
131
|
+
readonly STATE_READ: "aeon:state:read";
|
|
132
|
+
readonly STATE_WRITE: "aeon:state:write";
|
|
133
|
+
readonly STATE_RECONCILE: "aeon:state:reconcile";
|
|
134
|
+
};
|
|
135
|
+
type AeonCapability = (typeof AEON_CAPABILITIES)[keyof typeof AEON_CAPABILITIES];
|
|
136
|
+
/**
|
|
137
|
+
* Crypto configuration for Aeon
|
|
138
|
+
*/
|
|
139
|
+
interface AeonCryptoConfig {
|
|
140
|
+
/** Default encryption mode for sync messages */
|
|
141
|
+
defaultEncryptionMode: AeonEncryptionMode;
|
|
142
|
+
/** Require all messages to be signed */
|
|
143
|
+
requireSignatures: boolean;
|
|
144
|
+
/** Require UCAN capability verification */
|
|
145
|
+
requireCapabilities: boolean;
|
|
146
|
+
/** Allowed signature algorithms */
|
|
147
|
+
allowedSignatureAlgorithms: string[];
|
|
148
|
+
/** Allowed encryption algorithms */
|
|
149
|
+
allowedEncryptionAlgorithms: string[];
|
|
150
|
+
/** UCAN audience DID for verification */
|
|
151
|
+
ucanAudience?: string;
|
|
152
|
+
/** Session key expiration (ms) */
|
|
153
|
+
sessionKeyExpiration?: number;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Default crypto configuration
|
|
157
|
+
*/
|
|
158
|
+
declare const DEFAULT_CRYPTO_CONFIG: AeonCryptoConfig;
|
|
159
|
+
/**
|
|
160
|
+
* Authenticated sync message fields
|
|
161
|
+
*/
|
|
162
|
+
interface AuthenticatedMessageFields {
|
|
163
|
+
/** Sender DID */
|
|
164
|
+
senderDID?: string;
|
|
165
|
+
/** Receiver DID */
|
|
166
|
+
receiverDID?: string;
|
|
167
|
+
/** UCAN token for capability verification */
|
|
168
|
+
ucan?: string;
|
|
169
|
+
/** Message signature (base64url) */
|
|
170
|
+
signature?: string;
|
|
171
|
+
/** Whether payload is encrypted */
|
|
172
|
+
encrypted?: boolean;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Secure sync session
|
|
176
|
+
*/
|
|
177
|
+
interface SecureSyncSession {
|
|
178
|
+
id: string;
|
|
179
|
+
initiator: string;
|
|
180
|
+
participants: string[];
|
|
181
|
+
sessionKey?: Uint8Array;
|
|
182
|
+
encryptionMode: AeonEncryptionMode;
|
|
183
|
+
requiredCapabilities: string[];
|
|
184
|
+
status: 'pending' | 'active' | 'completed' | 'failed';
|
|
185
|
+
startTime: string;
|
|
186
|
+
endTime?: string;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Node with identity information
|
|
190
|
+
*/
|
|
191
|
+
interface SecureNodeInfo {
|
|
192
|
+
id: string;
|
|
193
|
+
did?: string;
|
|
194
|
+
publicSigningKey?: JsonWebKey;
|
|
195
|
+
publicEncryptionKey?: JsonWebKey;
|
|
196
|
+
capabilities?: string[];
|
|
197
|
+
lastSeen?: number;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Capability verification result
|
|
201
|
+
*/
|
|
202
|
+
interface AeonCapabilityResult {
|
|
203
|
+
authorized: boolean;
|
|
204
|
+
error?: string;
|
|
205
|
+
issuer?: string;
|
|
206
|
+
grantedCapabilities?: Array<{
|
|
207
|
+
can: string;
|
|
208
|
+
with: string;
|
|
209
|
+
}>;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Signed data envelope for sync operations
|
|
213
|
+
*/
|
|
214
|
+
interface SignedSyncData<T = unknown> {
|
|
215
|
+
payload: T;
|
|
216
|
+
signature: string;
|
|
217
|
+
signer: string;
|
|
218
|
+
algorithm: string;
|
|
219
|
+
signedAt: number;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Aeon Crypto Provider Interface
|
|
224
|
+
*
|
|
225
|
+
* Abstract interface for cryptographic operations.
|
|
226
|
+
* Aeon core remains zero-dependency - crypto is injected through this interface.
|
|
227
|
+
*/
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Abstract crypto provider interface
|
|
231
|
+
*
|
|
232
|
+
* Implementations use @affectively/ucan and @affectively/zk-encryption
|
|
233
|
+
* or other compatible libraries.
|
|
234
|
+
*/
|
|
235
|
+
interface ICryptoProvider {
|
|
236
|
+
/**
|
|
237
|
+
* Generate a new identity with DID and key pairs
|
|
238
|
+
*/
|
|
239
|
+
generateIdentity(displayName?: string): Promise<{
|
|
240
|
+
did: string;
|
|
241
|
+
publicSigningKey: JsonWebKey;
|
|
242
|
+
publicEncryptionKey?: JsonWebKey;
|
|
243
|
+
}>;
|
|
244
|
+
/**
|
|
245
|
+
* Get the local identity's DID
|
|
246
|
+
*/
|
|
247
|
+
getLocalDID(): string | null;
|
|
248
|
+
/**
|
|
249
|
+
* Export local identity's public info for sharing
|
|
250
|
+
*/
|
|
251
|
+
exportPublicIdentity(): Promise<SecureNodeInfo | null>;
|
|
252
|
+
/**
|
|
253
|
+
* Register a known remote node's public keys
|
|
254
|
+
*/
|
|
255
|
+
registerRemoteNode(node: SecureNodeInfo): Promise<void>;
|
|
256
|
+
/**
|
|
257
|
+
* Get a remote node's public key
|
|
258
|
+
*/
|
|
259
|
+
getRemotePublicKey(did: string): Promise<JsonWebKey | null>;
|
|
260
|
+
/**
|
|
261
|
+
* Sign data with local identity's private key
|
|
262
|
+
*/
|
|
263
|
+
sign(data: Uint8Array): Promise<Uint8Array>;
|
|
264
|
+
/**
|
|
265
|
+
* Sign structured data and wrap in SignedSyncData envelope
|
|
266
|
+
*/
|
|
267
|
+
signData<T>(data: T): Promise<SignedSyncData<T>>;
|
|
268
|
+
/**
|
|
269
|
+
* Verify a signature from a remote node
|
|
270
|
+
*/
|
|
271
|
+
verify(did: string, signature: Uint8Array, data: Uint8Array): Promise<boolean>;
|
|
272
|
+
/**
|
|
273
|
+
* Verify a SignedSyncData envelope
|
|
274
|
+
*/
|
|
275
|
+
verifySignedData<T>(signedData: SignedSyncData<T>): Promise<boolean>;
|
|
276
|
+
/**
|
|
277
|
+
* Encrypt data for a recipient
|
|
278
|
+
*/
|
|
279
|
+
encrypt(plaintext: Uint8Array, recipientDID: string): Promise<{
|
|
280
|
+
alg: string;
|
|
281
|
+
ct: string;
|
|
282
|
+
iv: string;
|
|
283
|
+
tag: string;
|
|
284
|
+
epk?: JsonWebKey;
|
|
285
|
+
encryptedAt: number;
|
|
286
|
+
}>;
|
|
287
|
+
/**
|
|
288
|
+
* Decrypt data
|
|
289
|
+
*/
|
|
290
|
+
decrypt(encrypted: {
|
|
291
|
+
alg: string;
|
|
292
|
+
ct: string;
|
|
293
|
+
iv: string;
|
|
294
|
+
tag: string;
|
|
295
|
+
epk?: JsonWebKey;
|
|
296
|
+
}, senderDID?: string): Promise<Uint8Array>;
|
|
297
|
+
/**
|
|
298
|
+
* Derive or get a session key for communication with a peer
|
|
299
|
+
*/
|
|
300
|
+
getSessionKey(peerDID: string): Promise<Uint8Array>;
|
|
301
|
+
/**
|
|
302
|
+
* Encrypt with a session key
|
|
303
|
+
*/
|
|
304
|
+
encryptWithSessionKey(plaintext: Uint8Array, sessionKey: Uint8Array): Promise<{
|
|
305
|
+
alg: string;
|
|
306
|
+
ct: string;
|
|
307
|
+
iv: string;
|
|
308
|
+
tag: string;
|
|
309
|
+
encryptedAt: number;
|
|
310
|
+
}>;
|
|
311
|
+
/**
|
|
312
|
+
* Decrypt with a session key
|
|
313
|
+
*/
|
|
314
|
+
decryptWithSessionKey(encrypted: {
|
|
315
|
+
ct: string;
|
|
316
|
+
iv: string;
|
|
317
|
+
tag: string;
|
|
318
|
+
}, sessionKey: Uint8Array): Promise<Uint8Array>;
|
|
319
|
+
/**
|
|
320
|
+
* Create a UCAN token
|
|
321
|
+
*/
|
|
322
|
+
createUCAN(audience: string, capabilities: Array<{
|
|
323
|
+
can: string;
|
|
324
|
+
with: string;
|
|
325
|
+
}>, options?: {
|
|
326
|
+
expirationSeconds?: number;
|
|
327
|
+
proofs?: string[];
|
|
328
|
+
}): Promise<string>;
|
|
329
|
+
/**
|
|
330
|
+
* Verify a UCAN token
|
|
331
|
+
*/
|
|
332
|
+
verifyUCAN(token: string, options?: {
|
|
333
|
+
expectedAudience?: string;
|
|
334
|
+
requiredCapabilities?: Array<{
|
|
335
|
+
can: string;
|
|
336
|
+
with: string;
|
|
337
|
+
}>;
|
|
338
|
+
}): Promise<AeonCapabilityResult>;
|
|
339
|
+
/**
|
|
340
|
+
* Delegate capabilities
|
|
341
|
+
*/
|
|
342
|
+
delegateCapabilities(parentToken: string, audience: string, capabilities: Array<{
|
|
343
|
+
can: string;
|
|
344
|
+
with: string;
|
|
345
|
+
}>, options?: {
|
|
346
|
+
expirationSeconds?: number;
|
|
347
|
+
}): Promise<string>;
|
|
348
|
+
/**
|
|
349
|
+
* Compute hash of data
|
|
350
|
+
*/
|
|
351
|
+
hash(data: Uint8Array): Promise<Uint8Array>;
|
|
352
|
+
/**
|
|
353
|
+
* Generate random bytes
|
|
354
|
+
*/
|
|
355
|
+
randomBytes(length: number): Uint8Array;
|
|
356
|
+
/**
|
|
357
|
+
* Check if crypto is properly initialized
|
|
358
|
+
*/
|
|
359
|
+
isInitialized(): boolean;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Null crypto provider for when crypto is disabled
|
|
363
|
+
*
|
|
364
|
+
* All operations either throw or return permissive defaults.
|
|
365
|
+
*/
|
|
366
|
+
declare class NullCryptoProvider implements ICryptoProvider {
|
|
367
|
+
private notConfiguredError;
|
|
368
|
+
generateIdentity(): Promise<{
|
|
369
|
+
did: string;
|
|
370
|
+
publicSigningKey: JsonWebKey;
|
|
371
|
+
publicEncryptionKey?: JsonWebKey;
|
|
372
|
+
}>;
|
|
373
|
+
getLocalDID(): string | null;
|
|
374
|
+
exportPublicIdentity(): Promise<SecureNodeInfo | null>;
|
|
375
|
+
registerRemoteNode(): Promise<void>;
|
|
376
|
+
getRemotePublicKey(): Promise<JsonWebKey | null>;
|
|
377
|
+
sign(): Promise<Uint8Array>;
|
|
378
|
+
signData<T>(_data: T): Promise<SignedSyncData<T>>;
|
|
379
|
+
verify(): Promise<boolean>;
|
|
380
|
+
verifySignedData(): Promise<boolean>;
|
|
381
|
+
encrypt(): Promise<{
|
|
382
|
+
alg: string;
|
|
383
|
+
ct: string;
|
|
384
|
+
iv: string;
|
|
385
|
+
tag: string;
|
|
386
|
+
epk?: JsonWebKey;
|
|
387
|
+
encryptedAt: number;
|
|
388
|
+
}>;
|
|
389
|
+
decrypt(): Promise<Uint8Array>;
|
|
390
|
+
getSessionKey(): Promise<Uint8Array>;
|
|
391
|
+
encryptWithSessionKey(): Promise<{
|
|
392
|
+
alg: string;
|
|
393
|
+
ct: string;
|
|
394
|
+
iv: string;
|
|
395
|
+
tag: string;
|
|
396
|
+
encryptedAt: number;
|
|
397
|
+
}>;
|
|
398
|
+
decryptWithSessionKey(): Promise<Uint8Array>;
|
|
399
|
+
createUCAN(): Promise<string>;
|
|
400
|
+
verifyUCAN(): Promise<AeonCapabilityResult>;
|
|
401
|
+
delegateCapabilities(): Promise<string>;
|
|
402
|
+
hash(): Promise<Uint8Array>;
|
|
403
|
+
randomBytes(length: number): Uint8Array;
|
|
404
|
+
isInitialized(): boolean;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
export { AEON_CAPABILITIES, type AeonCapability, type AeonCapabilityResult, type AeonCryptoConfig, type AeonEncryptionMode, type AuthenticatedMessageFields, type Capability, DEFAULT_CRYPTO_CONFIG, type DID, type DecryptionResult, type DomainCategory, type ECKeyPair, type EncryptedPayload, type EncryptionAlgorithm, type ICryptoProvider, type Identity, type KeyPair, NullCryptoProvider, type SecureNodeInfo, type SecureSyncSession, type SignedSyncData, type SigningAlgorithm, type UCANPayload, type UCANToken, type VerificationResult };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// src/crypto/types.ts
|
|
2
|
+
var AEON_CAPABILITIES = {
|
|
3
|
+
// Basic sync operations
|
|
4
|
+
SYNC_READ: "aeon:sync:read",
|
|
5
|
+
SYNC_WRITE: "aeon:sync:write",
|
|
6
|
+
SYNC_ADMIN: "aeon:sync:admin",
|
|
7
|
+
// Node operations
|
|
8
|
+
NODE_REGISTER: "aeon:node:register",
|
|
9
|
+
NODE_HEARTBEAT: "aeon:node:heartbeat",
|
|
10
|
+
// Replication operations
|
|
11
|
+
REPLICATE_READ: "aeon:replicate:read",
|
|
12
|
+
REPLICATE_WRITE: "aeon:replicate:write",
|
|
13
|
+
// State operations
|
|
14
|
+
STATE_READ: "aeon:state:read",
|
|
15
|
+
STATE_WRITE: "aeon:state:write",
|
|
16
|
+
STATE_RECONCILE: "aeon:state:reconcile"
|
|
17
|
+
};
|
|
18
|
+
var DEFAULT_CRYPTO_CONFIG = {
|
|
19
|
+
defaultEncryptionMode: "none",
|
|
20
|
+
requireSignatures: false,
|
|
21
|
+
requireCapabilities: false,
|
|
22
|
+
allowedSignatureAlgorithms: ["ES256", "Ed25519"],
|
|
23
|
+
allowedEncryptionAlgorithms: ["ECIES-P256", "AES-256-GCM"],
|
|
24
|
+
sessionKeyExpiration: 24 * 60 * 60 * 1e3
|
|
25
|
+
// 24 hours
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// src/crypto/CryptoProvider.ts
|
|
29
|
+
var NullCryptoProvider = class {
|
|
30
|
+
notConfiguredError() {
|
|
31
|
+
return new Error("Crypto provider not configured");
|
|
32
|
+
}
|
|
33
|
+
async generateIdentity() {
|
|
34
|
+
throw this.notConfiguredError();
|
|
35
|
+
}
|
|
36
|
+
getLocalDID() {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
async exportPublicIdentity() {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
async registerRemoteNode() {
|
|
43
|
+
}
|
|
44
|
+
async getRemotePublicKey() {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
async sign() {
|
|
48
|
+
throw this.notConfiguredError();
|
|
49
|
+
}
|
|
50
|
+
async signData(_data) {
|
|
51
|
+
throw this.notConfiguredError();
|
|
52
|
+
}
|
|
53
|
+
async verify() {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
async verifySignedData() {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
async encrypt() {
|
|
60
|
+
throw this.notConfiguredError();
|
|
61
|
+
}
|
|
62
|
+
async decrypt() {
|
|
63
|
+
throw this.notConfiguredError();
|
|
64
|
+
}
|
|
65
|
+
async getSessionKey() {
|
|
66
|
+
throw this.notConfiguredError();
|
|
67
|
+
}
|
|
68
|
+
async encryptWithSessionKey() {
|
|
69
|
+
throw this.notConfiguredError();
|
|
70
|
+
}
|
|
71
|
+
async decryptWithSessionKey() {
|
|
72
|
+
throw this.notConfiguredError();
|
|
73
|
+
}
|
|
74
|
+
async createUCAN() {
|
|
75
|
+
throw this.notConfiguredError();
|
|
76
|
+
}
|
|
77
|
+
async verifyUCAN() {
|
|
78
|
+
return { authorized: true };
|
|
79
|
+
}
|
|
80
|
+
async delegateCapabilities() {
|
|
81
|
+
throw this.notConfiguredError();
|
|
82
|
+
}
|
|
83
|
+
async hash() {
|
|
84
|
+
throw this.notConfiguredError();
|
|
85
|
+
}
|
|
86
|
+
randomBytes(length) {
|
|
87
|
+
return crypto.getRandomValues(new Uint8Array(length));
|
|
88
|
+
}
|
|
89
|
+
isInitialized() {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export { AEON_CAPABILITIES, DEFAULT_CRYPTO_CONFIG, NullCryptoProvider };
|
|
95
|
+
//# sourceMappingURL=index.js.map
|
|
96
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/crypto/types.ts","../../src/crypto/CryptoProvider.ts"],"names":[],"mappings":"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","file":"index.js","sourcesContent":["/**\n * Aeon Crypto Types\n *\n * Type definitions for cryptographic operations in Aeon.\n * These are compatible with @affectively/ucan and @affectively/zk-encryption.\n */\n\n// =============================================================================\n// IDENTITY TYPES (compatible with @affectively/ucan)\n// =============================================================================\n\n/**\n * Decentralized Identifier (DID)\n * Format: did:method:identifier\n */\nexport type DID = `did:${string}:${string}`;\n\n/**\n * Supported signing algorithms\n */\nexport type SigningAlgorithm = 'ES256' | 'Ed25519' | 'ES384' | 'ES512';\n\n/**\n * Key pair for signing and verification\n */\nexport interface KeyPair {\n algorithm: SigningAlgorithm;\n publicKey: JsonWebKey;\n privateKey?: JsonWebKey;\n fingerprint: string;\n}\n\n/**\n * Identity representing a user or node\n */\nexport interface Identity {\n did: DID;\n signingKey: KeyPair;\n encryptionKey?: KeyPair;\n createdAt: number;\n displayName?: string;\n}\n\n/**\n * UCAN Capability structure\n */\nexport interface Capability {\n can: string;\n with: string;\n constraints?: Record<string, unknown>;\n}\n\n/**\n * UCAN Token payload\n */\nexport interface UCANPayload {\n iss: DID;\n aud: DID;\n exp: number;\n nbf?: number;\n iat?: number;\n nonce?: string;\n jti?: string;\n att: Capability[];\n prf?: string[];\n fct?: Record<string, unknown>;\n}\n\n/**\n * Parsed UCAN Token\n */\nexport interface UCANToken {\n payload: UCANPayload;\n raw: string;\n signature: Uint8Array;\n algorithm: string;\n}\n\n/**\n * UCAN verification result\n */\nexport interface VerificationResult {\n valid: boolean;\n payload?: UCANPayload;\n error?: string;\n expired?: boolean;\n shouldRotate?: boolean;\n expiresIn?: number;\n}\n\n// =============================================================================\n// ENCRYPTION TYPES (compatible with @affectively/zk-encryption)\n// =============================================================================\n\n/**\n * Encryption algorithms supported\n */\nexport type EncryptionAlgorithm = 'ECIES-P256' | 'AES-256-GCM';\n\n/**\n * HKDF domain separator categories\n */\nexport type DomainCategory =\n | 'default'\n | 'sync'\n | 'message'\n | 'api-key'\n | 'personal-data'\n | string;\n\n/**\n * EC Key pair for ECDH operations\n */\nexport interface ECKeyPair {\n publicKey: JsonWebKey;\n privateKey: JsonWebKey;\n keyId: string;\n createdAt: string;\n}\n\n/**\n * Encrypted data envelope\n */\nexport interface EncryptedPayload {\n alg: EncryptionAlgorithm;\n ct: string;\n iv: string;\n tag: string;\n epk?: JsonWebKey;\n category?: DomainCategory;\n nonce?: string;\n encryptedAt: number;\n}\n\n/**\n * Decryption result\n */\nexport interface DecryptionResult {\n plaintext: Uint8Array;\n category?: DomainCategory;\n encryptedAt: number;\n}\n\n// =============================================================================\n// AEON-SPECIFIC TYPES\n// =============================================================================\n\n/**\n * Aeon encryption mode\n */\nexport type AeonEncryptionMode =\n | 'none' // No encryption (development/testing)\n | 'transport' // Encrypt in transit only (session keys)\n | 'at-rest' // Encrypt for storage\n | 'end-to-end'; // Full E2E encryption between nodes\n\n/**\n * Aeon sync capability namespace\n */\nexport const AEON_CAPABILITIES = {\n // Basic sync operations\n SYNC_READ: 'aeon:sync:read',\n SYNC_WRITE: 'aeon:sync:write',\n SYNC_ADMIN: 'aeon:sync:admin',\n\n // Node operations\n NODE_REGISTER: 'aeon:node:register',\n NODE_HEARTBEAT: 'aeon:node:heartbeat',\n\n // Replication operations\n REPLICATE_READ: 'aeon:replicate:read',\n REPLICATE_WRITE: 'aeon:replicate:write',\n\n // State operations\n STATE_READ: 'aeon:state:read',\n STATE_WRITE: 'aeon:state:write',\n STATE_RECONCILE: 'aeon:state:reconcile',\n} as const;\n\nexport type AeonCapability =\n (typeof AEON_CAPABILITIES)[keyof typeof AEON_CAPABILITIES];\n\n/**\n * Crypto configuration for Aeon\n */\nexport interface AeonCryptoConfig {\n /** Default encryption mode for sync messages */\n defaultEncryptionMode: AeonEncryptionMode;\n /** Require all messages to be signed */\n requireSignatures: boolean;\n /** Require UCAN capability verification */\n requireCapabilities: boolean;\n /** Allowed signature algorithms */\n allowedSignatureAlgorithms: string[];\n /** Allowed encryption algorithms */\n allowedEncryptionAlgorithms: string[];\n /** UCAN audience DID for verification */\n ucanAudience?: string;\n /** Session key expiration (ms) */\n sessionKeyExpiration?: number;\n}\n\n/**\n * Default crypto configuration\n */\nexport const DEFAULT_CRYPTO_CONFIG: AeonCryptoConfig = {\n defaultEncryptionMode: 'none',\n requireSignatures: false,\n requireCapabilities: false,\n allowedSignatureAlgorithms: ['ES256', 'Ed25519'],\n allowedEncryptionAlgorithms: ['ECIES-P256', 'AES-256-GCM'],\n sessionKeyExpiration: 24 * 60 * 60 * 1000, // 24 hours\n};\n\n/**\n * Authenticated sync message fields\n */\nexport interface AuthenticatedMessageFields {\n /** Sender DID */\n senderDID?: string;\n /** Receiver DID */\n receiverDID?: string;\n /** UCAN token for capability verification */\n ucan?: string;\n /** Message signature (base64url) */\n signature?: string;\n /** Whether payload is encrypted */\n encrypted?: boolean;\n}\n\n/**\n * Secure sync session\n */\nexport interface SecureSyncSession {\n id: string;\n initiator: string;\n participants: string[];\n sessionKey?: Uint8Array;\n encryptionMode: AeonEncryptionMode;\n requiredCapabilities: string[];\n status: 'pending' | 'active' | 'completed' | 'failed';\n startTime: string;\n endTime?: string;\n}\n\n/**\n * Node with identity information\n */\nexport interface SecureNodeInfo {\n id: string;\n did?: string;\n publicSigningKey?: JsonWebKey;\n publicEncryptionKey?: JsonWebKey;\n capabilities?: string[];\n lastSeen?: number;\n}\n\n/**\n * Capability verification result\n */\nexport interface AeonCapabilityResult {\n authorized: boolean;\n error?: string;\n issuer?: string;\n grantedCapabilities?: Array<{ can: string; with: string }>;\n}\n\n/**\n * Signed data envelope for sync operations\n */\nexport interface SignedSyncData<T = unknown> {\n payload: T;\n signature: string;\n signer: string;\n algorithm: string;\n signedAt: number;\n}\n","/**\n * Aeon Crypto Provider Interface\n *\n * Abstract interface for cryptographic operations.\n * Aeon core remains zero-dependency - crypto is injected through this interface.\n */\n\nimport type {\n AeonCapabilityResult,\n SignedSyncData,\n SecureNodeInfo,\n} from './types';\n\n/**\n * Abstract crypto provider interface\n *\n * Implementations use @affectively/ucan and @affectively/zk-encryption\n * or other compatible libraries.\n */\nexport interface ICryptoProvider {\n // ===========================================================================\n // IDENTITY OPERATIONS\n // ===========================================================================\n\n /**\n * Generate a new identity with DID and key pairs\n */\n generateIdentity(displayName?: string): Promise<{\n did: string;\n publicSigningKey: JsonWebKey;\n publicEncryptionKey?: JsonWebKey;\n }>;\n\n /**\n * Get the local identity's DID\n */\n getLocalDID(): string | null;\n\n /**\n * Export local identity's public info for sharing\n */\n exportPublicIdentity(): Promise<SecureNodeInfo | null>;\n\n /**\n * Register a known remote node's public keys\n */\n registerRemoteNode(node: SecureNodeInfo): Promise<void>;\n\n /**\n * Get a remote node's public key\n */\n getRemotePublicKey(did: string): Promise<JsonWebKey | null>;\n\n // ===========================================================================\n // SIGNING OPERATIONS\n // ===========================================================================\n\n /**\n * Sign data with local identity's private key\n */\n sign(data: Uint8Array): Promise<Uint8Array>;\n\n /**\n * Sign structured data and wrap in SignedSyncData envelope\n */\n signData<T>(data: T): Promise<SignedSyncData<T>>;\n\n /**\n * Verify a signature from a remote node\n */\n verify(\n did: string,\n signature: Uint8Array,\n data: Uint8Array,\n ): Promise<boolean>;\n\n /**\n * Verify a SignedSyncData envelope\n */\n verifySignedData<T>(signedData: SignedSyncData<T>): Promise<boolean>;\n\n // ===========================================================================\n // ENCRYPTION OPERATIONS\n // ===========================================================================\n\n /**\n * Encrypt data for a recipient\n */\n encrypt(\n plaintext: Uint8Array,\n recipientDID: string,\n ): Promise<{\n alg: string;\n ct: string;\n iv: string;\n tag: string;\n epk?: JsonWebKey;\n encryptedAt: number;\n }>;\n\n /**\n * Decrypt data\n */\n decrypt(\n encrypted: {\n alg: string;\n ct: string;\n iv: string;\n tag: string;\n epk?: JsonWebKey;\n },\n senderDID?: string,\n ): Promise<Uint8Array>;\n\n /**\n * Derive or get a session key for communication with a peer\n */\n getSessionKey(peerDID: string): Promise<Uint8Array>;\n\n /**\n * Encrypt with a session key\n */\n encryptWithSessionKey(\n plaintext: Uint8Array,\n sessionKey: Uint8Array,\n ): Promise<{\n alg: string;\n ct: string;\n iv: string;\n tag: string;\n encryptedAt: number;\n }>;\n\n /**\n * Decrypt with a session key\n */\n decryptWithSessionKey(\n encrypted: {\n ct: string;\n iv: string;\n tag: string;\n },\n sessionKey: Uint8Array,\n ): Promise<Uint8Array>;\n\n // ===========================================================================\n // UCAN OPERATIONS\n // ===========================================================================\n\n /**\n * Create a UCAN token\n */\n createUCAN(\n audience: string,\n capabilities: Array<{ can: string; with: string }>,\n options?: {\n expirationSeconds?: number;\n proofs?: string[];\n },\n ): Promise<string>;\n\n /**\n * Verify a UCAN token\n */\n verifyUCAN(\n token: string,\n options?: {\n expectedAudience?: string;\n requiredCapabilities?: Array<{ can: string; with: string }>;\n },\n ): Promise<AeonCapabilityResult>;\n\n /**\n * Delegate capabilities\n */\n delegateCapabilities(\n parentToken: string,\n audience: string,\n capabilities: Array<{ can: string; with: string }>,\n options?: {\n expirationSeconds?: number;\n },\n ): Promise<string>;\n\n // ===========================================================================\n // UTILITY OPERATIONS\n // ===========================================================================\n\n /**\n * Compute hash of data\n */\n hash(data: Uint8Array): Promise<Uint8Array>;\n\n /**\n * Generate random bytes\n */\n randomBytes(length: number): Uint8Array;\n\n /**\n * Check if crypto is properly initialized\n */\n isInitialized(): boolean;\n}\n\n/**\n * Null crypto provider for when crypto is disabled\n *\n * All operations either throw or return permissive defaults.\n */\nexport class NullCryptoProvider implements ICryptoProvider {\n private notConfiguredError(): Error {\n return new Error('Crypto provider not configured');\n }\n\n async generateIdentity(): Promise<{\n did: string;\n publicSigningKey: JsonWebKey;\n publicEncryptionKey?: JsonWebKey;\n }> {\n throw this.notConfiguredError();\n }\n\n getLocalDID(): string | null {\n return null;\n }\n\n async exportPublicIdentity(): Promise<SecureNodeInfo | null> {\n return null;\n }\n\n async registerRemoteNode(): Promise<void> {\n // No-op when crypto disabled\n }\n\n async getRemotePublicKey(): Promise<JsonWebKey | null> {\n return null;\n }\n\n async sign(): Promise<Uint8Array> {\n throw this.notConfiguredError();\n }\n\n async signData<T>(_data: T): Promise<SignedSyncData<T>> {\n throw this.notConfiguredError();\n }\n\n async verify(): Promise<boolean> {\n // Permissive when crypto disabled\n return true;\n }\n\n async verifySignedData(): Promise<boolean> {\n // Permissive when crypto disabled\n return true;\n }\n\n async encrypt(): Promise<{\n alg: string;\n ct: string;\n iv: string;\n tag: string;\n epk?: JsonWebKey;\n encryptedAt: number;\n }> {\n throw this.notConfiguredError();\n }\n\n async decrypt(): Promise<Uint8Array> {\n throw this.notConfiguredError();\n }\n\n async getSessionKey(): Promise<Uint8Array> {\n throw this.notConfiguredError();\n }\n\n async encryptWithSessionKey(): Promise<{\n alg: string;\n ct: string;\n iv: string;\n tag: string;\n encryptedAt: number;\n }> {\n throw this.notConfiguredError();\n }\n\n async decryptWithSessionKey(): Promise<Uint8Array> {\n throw this.notConfiguredError();\n }\n\n async createUCAN(): Promise<string> {\n throw this.notConfiguredError();\n }\n\n async verifyUCAN(): Promise<AeonCapabilityResult> {\n // Permissive when crypto disabled\n return { authorized: true };\n }\n\n async delegateCapabilities(): Promise<string> {\n throw this.notConfiguredError();\n }\n\n async hash(): Promise<Uint8Array> {\n throw this.notConfiguredError();\n }\n\n randomBytes(length: number): Uint8Array {\n // Use crypto.getRandomValues even without full crypto setup\n return crypto.getRandomValues(new Uint8Array(length));\n }\n\n isInitialized(): boolean {\n return false;\n }\n}\n"]}
|