diff --git a/packages/crypto/src/index.ts b/packages/crypto/src/index.ts index 3eccee6d..b39e4986 100644 --- a/packages/crypto/src/index.ts +++ b/packages/crypto/src/index.ts @@ -9,6 +9,7 @@ export { Xchacha20poly1305IetfKey, Xchacha20poly1305IetfMessage, Xchacha20poly1305IetfNonce, + xchacha20NonceLength, Argon2id, Argon2idOptions, Ed25519, diff --git a/packages/crypto/src/libsodium.ts b/packages/crypto/src/libsodium.ts index a094a8e5..a27b0c9d 100644 --- a/packages/crypto/src/libsodium.ts +++ b/packages/crypto/src/libsodium.ts @@ -91,6 +91,13 @@ export class Ed25519 { } } +/** + * Nonce length in bytes for all flavours of XChaCha20. + * + * @see https://libsodium.gitbook.io/doc/advanced/stream_ciphers/xchacha20#notes + */ +export const xchacha20NonceLength = 24; + export class Xchacha20poly1305Ietf { public static async encrypt( message: Xchacha20poly1305IetfMessage, diff --git a/packages/crypto/types/index.d.ts b/packages/crypto/types/index.d.ts index 3eccee6d..b39e4986 100644 --- a/packages/crypto/types/index.d.ts +++ b/packages/crypto/types/index.d.ts @@ -9,6 +9,7 @@ export { Xchacha20poly1305IetfKey, Xchacha20poly1305IetfMessage, Xchacha20poly1305IetfNonce, + xchacha20NonceLength, Argon2id, Argon2idOptions, Ed25519, diff --git a/packages/crypto/types/libsodium.d.ts b/packages/crypto/types/libsodium.d.ts index d045971f..1ab48dca 100644 --- a/packages/crypto/types/libsodium.d.ts +++ b/packages/crypto/types/libsodium.d.ts @@ -31,6 +31,12 @@ export declare class Ed25519 { static createSignature(message: Uint8Array, keyPair: Ed25519Keypair): Promise; static verifySignature(signature: Uint8Array, message: Uint8Array, pubkey: Uint8Array): Promise; } +/** + * Nonce length in bytes for all flavours of XChaCha20. + * + * @see https://libsodium.gitbook.io/doc/advanced/stream_ciphers/xchacha20#notes + */ +export declare const xchacha20NonceLength = 24; export declare class Xchacha20poly1305Ietf { static encrypt( message: Xchacha20poly1305IetfMessage,