UNPKG

anon-identity

Version:

Decentralized identity framework with DIDs, Verifiable Credentials, and privacy-preserving selective disclosure

106 lines 5.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.VerificationError = exports.VerificationErrorCode = void 0; exports.isVerificationError = isVerificationError; exports.getErrorCode = getErrorCode; var VerificationErrorCode; (function (VerificationErrorCode) { VerificationErrorCode["EXPIRED_CREDENTIAL"] = "EXPIRED_CREDENTIAL"; VerificationErrorCode["REVOKED_CREDENTIAL"] = "REVOKED_CREDENTIAL"; VerificationErrorCode["UNTRUSTED_ISSUER"] = "UNTRUSTED_ISSUER"; VerificationErrorCode["INVALID_SIGNATURE"] = "INVALID_SIGNATURE"; VerificationErrorCode["MISSING_REQUIRED_ATTRIBUTE"] = "MISSING_REQUIRED_ATTRIBUTE"; VerificationErrorCode["INVALID_DISCLOSURE_PROOF"] = "INVALID_DISCLOSURE_PROOF"; VerificationErrorCode["MISSING_PROOF"] = "MISSING_PROOF"; VerificationErrorCode["INVALID_PRESENTATION_SIGNATURE"] = "INVALID_PRESENTATION_SIGNATURE"; VerificationErrorCode["INVALID_CREDENTIAL_FORMAT"] = "INVALID_CREDENTIAL_FORMAT"; VerificationErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR"; VerificationErrorCode["STORAGE_ERROR"] = "STORAGE_ERROR"; VerificationErrorCode["CREDENTIAL_SUSPENDED"] = "CREDENTIAL_SUSPENDED"; VerificationErrorCode["INVALID_CREDENTIAL"] = "INVALID_CREDENTIAL"; VerificationErrorCode["INSUFFICIENT_PERMISSIONS"] = "INSUFFICIENT_PERMISSIONS"; VerificationErrorCode["CREDENTIAL_REVOKED"] = "CREDENTIAL_REVOKED"; VerificationErrorCode["PROCESSING_ERROR"] = "PROCESSING_ERROR"; })(VerificationErrorCode || (exports.VerificationErrorCode = VerificationErrorCode = {})); class VerificationError extends Error { constructor(code, message, details = {}) { super(message); this.name = 'VerificationError'; this.code = code; this.details = details; // Maintains proper stack trace for where our error was thrown (only available on V8) if (Error.captureStackTrace) { Error.captureStackTrace(this, VerificationError); } } /** * Create a standardized error message */ toString() { return `${this.name} [${this.code}]: ${this.message}`; } /** * Convert to JSON for API responses */ toJSON() { return { name: this.name, code: this.code, message: this.message, details: this.details }; } /** * Factory methods for common errors */ static expiredCredential(credentialId, issuer) { return new VerificationError(VerificationErrorCode.EXPIRED_CREDENTIAL, `Credential ${credentialId} has expired`, { credentialId, issuer }); } static revokedCredential(credentialId, issuer) { return new VerificationError(VerificationErrorCode.REVOKED_CREDENTIAL, `Credential ${credentialId} has been revoked`, { credentialId, issuer }); } static untrustedIssuer(issuer, credentialId) { return new VerificationError(VerificationErrorCode.UNTRUSTED_ISSUER, `Credential from untrusted issuer: ${issuer}`, { issuer, credentialId }); } static invalidSignature(credentialId, reason) { return new VerificationError(VerificationErrorCode.INVALID_SIGNATURE, `Invalid signature for credential ${credentialId}${reason ? `: ${reason}` : ''}`, { credentialId, reason }); } static missingRequiredAttribute(attribute, credentialId) { return new VerificationError(VerificationErrorCode.MISSING_REQUIRED_ATTRIBUTE, `Missing required attribute: ${attribute}`, { attribute, credentialId }); } static invalidDisclosureProof(credentialId) { return new VerificationError(VerificationErrorCode.INVALID_DISCLOSURE_PROOF, `Invalid selective disclosure proof for credential ${credentialId}`, { credentialId }); } static missingProof(type, id) { return new VerificationError(VerificationErrorCode.MISSING_PROOF, `${type} missing proof${id ? ` (${id})` : ''}`, { type, id }); } static invalidPresentationSignature(reason) { return new VerificationError(VerificationErrorCode.INVALID_PRESENTATION_SIGNATURE, `Invalid presentation signature${reason ? `: ${reason}` : ''}`, { reason }); } static invalidCredentialFormat(credentialId, reason) { return new VerificationError(VerificationErrorCode.INVALID_CREDENTIAL_FORMAT, `Invalid credential format${reason ? `: ${reason}` : ''}`, { credentialId, reason }); } static networkError(operation, error) { return new VerificationError(VerificationErrorCode.NETWORK_ERROR, `Network error during ${operation}: ${error.message}`, { operation, originalError: error.message }); } static storageError(operation, error) { return new VerificationError(VerificationErrorCode.STORAGE_ERROR, `Storage error during ${operation}: ${error.message}`, { operation, originalError: error.message }); } } exports.VerificationError = VerificationError; /** * Helper to determine if an error is a VerificationError */ function isVerificationError(error) { return error instanceof VerificationError; } /** * Helper to get error code from any error */ function getErrorCode(error) { if (isVerificationError(error)) { return error.code; } return null; } //# sourceMappingURL=verification-errors.js.map