@screamingvoid/crypto v0.3.0
@screamingvoid/crypto
Shared cryptographic primitives and utilities used by packages in Void project. All crypto operations use libsodium.
API
type KeyPair = { publicKey: Uint8Array, secretKey: Uint8Array }
ed25519 key pair.
random(size: number, seed?: string | Uint8Array): Uint8Array
Generate size buffer filled with random bytes. If seed is provided,
it's instead used to deterministically derive pseudo random bytes.
increment(buffer: Uint8Array): Uint8Array
Increment buffer in place as large integer. Returns buffer.
hash(size: number, ...hashables: (string | Uint8Array)[]): Uint8Array
Generate size length hash of hashables.
keyPair(seed?: string | Uint8Array): KeyPair
Generate random ed25519 key pair. If seed is provided, deterministically derive key pair.
sign(message: Uint8Array, secretKey: Uint8Array): Uint8Array
Generate ed25519 signature for message using ed25519 secretKey.
verifySignature(message: Uint8Array, signature: Uint8Array, publicKey: Uint8Array): boolean
Verify that signature is valid for message and ed25519 publicKey.
verifyPublicKey(identity: KeyPair | Uint8Array, publicKey: Uint8Array, ...tweaks: (string | Uint8Array)[]): boolean
Verify that publicKey was derived from identity using given sequence of tweaks.
ecdh(keyPair: KeyPair, remotePublicKey: Uint8Array): Uint8Array
Generate shared secret suitable for symmetric encryption from ed25519 keyPair and remotePublicKey using Elliptic Curve Diffie Hellman algorithm.
encrypt(message: Uint8Array, secret: Uint8Array): Uint8Array
Symmetrically encrypt message with secret. Returns binary encoded ciphertext and random nonce.
decrypt(message: Uint8Array, secret: Uint8Array): Uint8Array
Decrypt message (as returned by encrypt()) using secret.