|
| 1 | +--- |
| 2 | +"@evolu/common": major |
| 3 | +"@evolu/web": major |
| 4 | +--- |
| 5 | + |
| 6 | +Replaced interface-based symmetric encryption with direct function-based API |
| 7 | + |
| 8 | +### Breaking Changes |
| 9 | + |
| 10 | +**Removed:** |
| 11 | + |
| 12 | +- `SymmetricCrypto` interface |
| 13 | +- `SymmetricCryptoDep` interface |
| 14 | +- `createSymmetricCrypto()` factory function |
| 15 | +- `SymmetricCryptoDecryptError` error type |
| 16 | + |
| 17 | +**Added:** |
| 18 | + |
| 19 | +- `encryptWithXChaCha20Poly1305()` - Direct encryption function with explicit algorithm name |
| 20 | +- `decryptWithXChaCha20Poly1305()` - Direct decryption function |
| 21 | +- `XChaCha20Poly1305Ciphertext` - Branded type for ciphertext |
| 22 | +- `Entropy24` - Branded type for 24-byte nonces |
| 23 | +- `DecryptWithXChaCha20Poly1305Error` - Algorithm-specific error type |
| 24 | +- `xChaCha20Poly1305NonceLength` - Constant for nonce length (24) |
| 25 | + |
| 26 | +### Migration Guide |
| 27 | + |
| 28 | +**Before:** |
| 29 | + |
| 30 | +```ts |
| 31 | +const symmetricCrypto = createSymmetricCrypto({ randomBytes }); |
| 32 | +const { nonce, ciphertext } = symmetricCrypto.encrypt(plaintext, key); |
| 33 | +const result = symmetricCrypto.decrypt(ciphertext, key, nonce); |
| 34 | +``` |
| 35 | + |
| 36 | +**After:** |
| 37 | + |
| 38 | +```ts |
| 39 | +const [ciphertext, nonce] = encryptWithXChaCha20Poly1305({ randomBytes })( |
| 40 | + plaintext, |
| 41 | + key, |
| 42 | +); |
| 43 | +const result = decryptWithXChaCha20Poly1305(ciphertext, nonce, key); |
| 44 | +``` |
| 45 | + |
| 46 | +**Error handling:** |
| 47 | + |
| 48 | +```ts |
| 49 | +// Before |
| 50 | +if (!result.ok && result.error.type === "SymmetricCryptoDecryptError") { ... } |
| 51 | + |
| 52 | +// After |
| 53 | +if (!result.ok && result.error.type === "DecryptWithXChaCha20Poly1305Error") { ... } |
| 54 | +``` |
| 55 | + |
| 56 | +**Dependency injection:** |
| 57 | + |
| 58 | +```ts |
| 59 | +// Before |
| 60 | +interface Deps extends SymmetricCryptoDep { ... } |
| 61 | + |
| 62 | +// After - only encrypt needs RandomBytesDep |
| 63 | +interface Deps extends RandomBytesDep { ... } |
| 64 | +``` |
| 65 | + |
| 66 | +### Rationale |
| 67 | + |
| 68 | +This change improves API extensibility by using explicit function names instead of a generic interface. Adding new encryption algorithms (e.g., `encryptWithAES256GCM`) is now straightforward without breaking existing code. |
0 commit comments