API reference@evolu/common › Crypto

Cryptographic utilities.

Type-safe cryptographic operations including random bytes generation, SLIP21 key derivation, XChaCha20-Poly1305 symmetric encryption, PADMÉ padding, and timing-safe comparisons.

Random bytes

NameDescription
RandomBytesCryptographically secure random bytes with length-branded results.
RandomBytesDepDependency wrapper for RandomBytes.
Entropy16Cryptographic entropy of exactly 16 bytes.
Entropy24Cryptographic entropy of exactly 24 bytes.
Entropy32Cryptographic entropy of exactly 32 bytes.
Entropy64Cryptographic entropy of exactly 64 bytes.
Entropy16Cryptographic entropy of exactly 16 bytes.
Entropy24Cryptographic entropy of exactly 24 bytes.
Entropy32Cryptographic entropy of exactly 32 bytes.
Entropy64Cryptographic entropy of exactly 64 bytes.
createRandomBytesCreates RandomBytes backed by the platform's secure random number generator.

Key derivation

FunctionDescription
createSlip21SLIP21.
deriveSlip21NodeDerives a single node in the SLIP-21 hierarchical key derivation.

Encryption

NameDescription
DecryptWithXChaCha20Poly1305ErrorError returned by decryptWithXChaCha20Poly1305 when decryption fails.
EncryptionKeyThe encryption key for symmetric encryption.
XChaCha20Poly1305CiphertextBranded Uint8Array for XChaCha20-Poly1305 encryption.
EncryptionKeyThe encryption key for symmetric encryption.
XChaCha20Poly1305CiphertextBranded Uint8Array for XChaCha20-Poly1305 encryption.
xChaCha20Poly1305NonceLengthThe nonce length for XChaCha20-Poly1305 encryption.
decryptWithXChaCha20Poly1305Decrypts ciphertext with XChaCha20-Poly1305.
encryptWithXChaCha20Poly1305Encrypts plaintext with XChaCha20-Poly1305.

Padding

FunctionDescription
createPadmePaddedLengthReturns the PADMÉ padded length for a given input length.
createPadmePaddingCreates a PADMÉ padding array of zeros for the given input length.

Comparison

NameDescription
TimingSafeEqualDepDependency wrapper for TimingSafeEqual.
TimingSafeEqualPerforms a timing-safe comparison of two Uint8Arrays. Returns true if they are equal, false otherwise. Takes constant time regardless of where the arrays differ.

Testing

FunctionDescription
testCreateRandomBytesCreates seeded random bytes for deterministic tests.