Skip to Content

Errors

All Credat errors extend the CredatError base class and include a machine-readable code and a human-readable message.

Error classes

import { CredatError, // Base class AgentError, // Agent creation/loading DelegationError,// Delegation issuance/verification HandshakeError, // Handshake protocol DIDError, // DID resolution CredentialError,// Low-level credential operations } from "@credat/sdk";

CredatError

The base error class. All other error classes extend it.

PropertyTypeDescription
codestringMachine-readable error code (from ErrorCodes)
messagestringTechnical error message
humanMessagestring | undefinedOptional plain-language explanation

Example

import { createAgent, AgentError, ErrorCodes } from "@credat/sdk"; try { await createAgent({ domain: "" }); } catch (error) { if (error instanceof AgentError) { console.log(error.code); // "AGENT_CREATION_FAILED" console.log(error.message); // "Domain is required to create an agent" } }

Error codes

DID errors

CodeThrown byMeaning
DID_NOT_FOUNDresolveDID, resolveDidWebDID could not be found at the expected URL
DID_METHOD_UNSUPPORTEDresolveDIDUnsupported DID method (only key and web are supported)
DID_RESOLUTION_FAILEDresolveDIDInvalid DID format

Agent errors

CodeThrown byMeaning
AGENT_CREATION_FAILEDcreateAgentMissing or invalid configuration (e.g. empty domain)
AGENT_NOT_FOUNDloadAgentNo agent with this DID in storage
AGENT_KEY_INVALIDvariousKey material is corrupt or invalid

Delegation errors

CodeWhereMeaning
DELEGATION_INVALIDverifyDelegationDelegation credential is malformed
DELEGATION_EXPIREDverifyDelegationDelegation has expired (validUntil in the past)
DELEGATION_REVOKEDverifyDelegationOwner revoked this delegation via status list
DELEGATION_SIGNATURE_INVALIDverifyDelegationSignature doesn’t match the owner’s public key
DELEGATION_SCOPE_INVALIDdelegateEmpty scopes array
DELEGATION_NOT_YET_VALIDverifyDelegationDelegation’s validFrom is in the future

Handshake errors

CodeWhereMeaning
HANDSHAKE_INVALID_NONCEverifyPresentationPresentation nonce doesn’t match challenge nonce
HANDSHAKE_EXPIREDverifyPresentationChallenge has expired
HANDSHAKE_VERIFICATION_FAILEDverifyPresentationAgent’s nonce signature is invalid

Credential errors (low-level)

CodeWhereMeaning
CREDENTIAL_INVALID_FORMATverifySdJwtVcCredential is not a valid SD-JWT VC
CREDENTIAL_EXPIREDverifySdJwtVcCredential has expired
CREDENTIAL_SIGNATURE_INVALIDverifySdJwtVcSignature verification failed
STATUS_LIST_INVALIDstatus list functionsStatus list data is malformed

ErrorCodes constant

All error codes are available as a constant for switch statements and comparisons:

import { ErrorCodes } from "@credat/sdk"; // ErrorCodes.DID_NOT_FOUND === "DID_NOT_FOUND" // ErrorCodes.DELEGATION_EXPIRED === "DELEGATION_EXPIRED" // etc.

Full list

const ErrorCodes = { // DID DID_NOT_FOUND: "DID_NOT_FOUND", DID_METHOD_UNSUPPORTED: "DID_METHOD_UNSUPPORTED", DID_RESOLUTION_FAILED: "DID_RESOLUTION_FAILED", // Credential CREDENTIAL_INVALID_FORMAT: "CREDENTIAL_INVALID_FORMAT", CREDENTIAL_EXPIRED: "CREDENTIAL_EXPIRED", CREDENTIAL_SIGNATURE_INVALID: "CREDENTIAL_SIGNATURE_INVALID", STATUS_LIST_INVALID: "STATUS_LIST_INVALID", // Agent AGENT_CREATION_FAILED: "AGENT_CREATION_FAILED", AGENT_NOT_FOUND: "AGENT_NOT_FOUND", AGENT_KEY_INVALID: "AGENT_KEY_INVALID", // Delegation DELEGATION_INVALID: "DELEGATION_INVALID", DELEGATION_EXPIRED: "DELEGATION_EXPIRED", DELEGATION_REVOKED: "DELEGATION_REVOKED", DELEGATION_SIGNATURE_INVALID: "DELEGATION_SIGNATURE_INVALID", DELEGATION_SCOPE_INVALID: "DELEGATION_SCOPE_INVALID", DELEGATION_NOT_YET_VALID: "DELEGATION_NOT_YET_VALID", // Handshake HANDSHAKE_INVALID_NONCE: "HANDSHAKE_INVALID_NONCE", HANDSHAKE_EXPIRED: "HANDSHAKE_EXPIRED", HANDSHAKE_VERIFICATION_FAILED: "HANDSHAKE_VERIFICATION_FAILED", } as const;

Verification errors vs thrown errors

There are two kinds of errors in Credat:

Thrown errors

Functions like createAgent, delegate, resolveDID throw on invalid input. These are programming errors --- your code passed bad data.

try { await createAgent({ domain: "" }); // Throws AgentError } catch (e) { // Handle the error }

Result errors

Functions like verifyDelegation and verifyPresentation return errors in the result object. These are expected failures --- a credential might be expired or have an invalid signature.

const result = await verifyDelegation(token, options); if (!result.valid) { // result.errors contains VerificationError[] for (const err of result.errors) { console.log(err.code, err.message); } }

This distinction is intentional. Verification is a normal operation that can legitimately fail --- it shouldn’t require try/catch.

Last updated on