DSA Functions
cryptographer.js provides digital signature algorithms with a consistent API and production-focused guidance.
Supported Algorithms
Ed25519
Curve25519 (EdDSA)
—
64-byte raw
✅
Modern, fast, safe defaults
ECDSA (secp256r1)
NIST P-256
SHA-256
DER
✅
Compliance-friendly
ECDSA (secp256k1)
secp256k1
SHA-256
DER
✅
Bitcoin/crypto ecosystems
RSA-PSS
≥2048-bit
SHA-256/384/512
ASN.1
✅
Prefer over PKCS#1 v1.5
RSA PKCS#1 v1.5
≥2048-bit
SHA-256/384/512
ASN.1
✅
Legacy compatibility
Omitted (not implemented): DSA (DSS), Dilithium, Falcon, SPHINCS+, MQDSS (PQC) due to WASM/toolchain stability and scope.
Ed25519
Keys: private 32 B, public 32 B; signature 64 B
API
ed25519.generateKeypair(): { privateKey: Buffer; publicKey: Buffer }
ed25519.sign(privateKey: CryptoInput, message: CryptoInput): Buffer
ed25519.verify(publicKey: CryptoInput, message: CryptoInput, signature: CryptoInput): booleanExample
// Generate a fresh Ed25519 keypair (32B secret key, 32B public key)
const ed = crypto.dsa.ed25519.generateKeypair();
// Sign any message-like input (string | Buffer | Uint8Array)
const sig = crypto.dsa.ed25519.sign(ed.privateKey, 'hello');
// Verify signature returns boolean
const ok = crypto.dsa.ed25519.verify(ed.publicKey, 'hello', sig);ECDSA
Curves:
secp256r1(aka NIST P-256),secp256k1Public key: uncompressed SEC1 (65 bytes)
Hashing: library computes SHA-256 digest internally before signing/verifying
API
Example
RSA Signatures
Key formats: Public SPKI/PKCS#1 DER; Private PKCS#8/PKCS#1 DER
Hash: 'sha256' | 'sha384' | 'sha512'
API
Example
Security Guidance
Prefer Ed25519 or ECDSA
secp256r1for modern systems; choosesecp256k1when ecosystem requires it.Prefer RSA-PSS over PKCS#1 v1.5; use ≥2048-bit modulus.
Validate key encodings (DER for RSA, uncompressed SEC1 for ECDSA) and store private keys securely.
Bind signatures to context (include purpose, timestamp, nonce in message format).
Error Handling
TypeScript Types
Interoperability Notes
ECDSA public keys are uncompressed SEC1 (0x04 || X || Y). Convert from compressed form if needed.
RSA keys must be DER; if you have PEM, decode base64 between -----BEGIN ...----- and convert to Buffer.
Last updated