@synet/keys
Version:
Zero-dependency, secure key generation library. Supports ed25519, x25519, secp256k1, RSA, and WireGuard keys.
61 lines (60 loc) • 2.44 kB
TypeScript
/**
* Cryptographic verification functions
* Pure functions for signature verification across different algorithms
*
* These functions are designed to be:
* - Pure (no side effects)
* - Testable in isolation
* - Reusable across different units
* - Well-validated with proper error handling
*
* @author Synet Team
*/
/**
* Validate base64 format
* Ensures the signature is properly formatted base64 before crypto operations
*/
export declare function isValidBase64(str: string): boolean;
/**
* Validate base64url format
* Ensures the signature is properly formatted base64url before crypto operations
*/
export declare function isValidBase64Url(str: string): boolean;
/**
* Normalize signature to base64 format for crypto operations
* Accepts both base64 and base64url formats
*/
export declare function normalizeSignature(signature: string): string | null;
/**
* Verify Ed25519 signature
* @param data The original data that was signed
* @param signature The signature in base64 or base64url format
* @param publicKey The public key in PEM format
* @returns true if signature is valid, false otherwise
*/
export declare function verifyEd25519(data: string, signature: string, publicKey: string): boolean;
/**
* Verify RSA signature
* @param data The original data that was signed
* @param signature The signature in base64 or base64url format
* @param publicKey The public key in PEM format
* @returns true if signature is valid, false otherwise
*/
export declare function verifyRSA(data: string, signature: string, publicKey: string): boolean;
/**
* Verify secp256k1 signature
* @param data The original data that was signed
* @param signature The signature in base64 or base64url format
* @param publicKey The public key in PEM format
* @returns true if signature is valid, false otherwise
*/
export declare function verifySecp256k1(data: string, signature: string, publicKey: string): boolean;
/**
* Generic verification function that dispatches to specific algorithms
* @param data The original data that was signed
* @param signature The signature in base64 or base64url format
* @param publicKey The public key in PEM format
* @param keyType The key type/algorithm
* @returns true if signature is valid, false otherwise
*/
export declare function verifySignature(data: string, signature: string, publicKey: string, keyType: 'ed25519' | 'rsa' | 'secp256k1' | 'x25519' | 'wireguard'): boolean;