Files
grateful-journal/src/lib/libsodium.d.ts
2026-03-09 10:54:07 +05:30

81 lines
2.2 KiB
TypeScript

declare module 'libsodium-wrappers' {
interface SodiumPlus {
ready: Promise<void>
// Random bytes
randombytes_buf(length: number): Uint8Array
// Secret-box (XSalsa20-Poly1305) — "_easy" variants
crypto_secretbox_easy(
message: Uint8Array,
nonce: Uint8Array,
key: Uint8Array
): Uint8Array
/** Throws on failure (wrong key / corrupted ciphertext) */
crypto_secretbox_open_easy(
ciphertext: Uint8Array,
nonce: Uint8Array,
key: Uint8Array
): Uint8Array
crypto_secretbox_keygen(): Uint8Array
// Box (X25519 + XSalsa20-Poly1305)
crypto_box_easy(
message: Uint8Array,
nonce: Uint8Array,
publicKey: Uint8Array,
secretKey: Uint8Array
): Uint8Array
crypto_box_open_easy(
ciphertext: Uint8Array,
nonce: Uint8Array,
publicKey: Uint8Array,
secretKey: Uint8Array
): Uint8Array
crypto_box_keypair(): { publicKey: Uint8Array; privateKey: Uint8Array; keyType: string }
// Password hashing
crypto_pwhash(
outlen: number,
passwd: string,
salt: Uint8Array,
opslimit: number,
memlimit: number,
alg: number
): Uint8Array
// Encoding helpers
to_base64(data: Uint8Array, variant?: number): string
from_base64(data: string, variant?: number): Uint8Array
to_string(data: Uint8Array): string
from_string(data: string): Uint8Array
to_hex(data: Uint8Array): string
from_hex(data: string): Uint8Array
// Base64 variant constants
base64_variants: {
ORIGINAL: number
ORIGINAL_NO_PADDING: number
URLSAFE: number
URLSAFE_NO_PADDING: number
}
// Constants
crypto_pwhash_SALTBYTES: number
crypto_pwhash_OPSLIMIT_SENSITIVE: number
crypto_pwhash_MEMLIMIT_SENSITIVE: number
crypto_pwhash_OPSLIMIT_MODERATE: number
crypto_pwhash_MEMLIMIT_MODERATE: number
crypto_pwhash_ALG_DEFAULT: number
crypto_secretbox_NONCEBYTES: number
crypto_secretbox_KEYBYTES: number
crypto_secretbox_MACBYTES: number
crypto_box_NONCEBYTES: number
crypto_box_PUBLICKEYBYTES: number
crypto_box_SECRETKEYBYTES: number
}
const sodium: SodiumPlus
export default sodium
}