Branded error class for all crypto-lib operations.
Allows consumers to catch library-specific errors distinctly from other runtime errors using instanceof CryptoError.
instanceof CryptoError
import { CryptoError } from "@sebastienrousseau/crypto-lib";try { crypto.sign("ed25519", invalidKey, message);} catch (err) { if (err instanceof CryptoError) { console.error(err.code, err.message); }} Copy
import { CryptoError } from "@sebastienrousseau/crypto-lib";try { crypto.sign("ed25519", invalidKey, message);} catch (err) { if (err instanceof CryptoError) { console.error(err.code, err.message); }}
Create a new CryptoError.
Human-readable error description.
Machine-readable error code.
throw new CryptoError("Key must be 32 bytes", "INVALID_KEY_LENGTH"); Copy
throw new CryptoError("Key must be 32 bytes", "INVALID_KEY_LENGTH");
Readonly
Machine-readable error code (e.g., "INVALID_KEY", "UNSUPPORTED_ALGORITHM").
Remarks
Branded error class for all crypto-lib operations.
Allows consumers to catch library-specific errors distinctly from other runtime errors using
instanceof CryptoError.Example