Beltic logo
Reference

Error Codes

Complete reference of all error codes for validation, signature, and trust chain operations in the Beltic SDK.

This page documents all error codes returned by the Beltic SDK. Error codes help you identify specific issues and implement appropriate error handling.

Error Code Format

Error codes follow a consistent format:

PrefixCategory
RV-Runtime Validation (date checks, freshness)
SIG-Signature operations
TC-Trust Chain verification
POL-Policy violations

Validation Errors (RV-*)

Date Order Errors

These errors indicate invalid date relationships in credentials.

CodeDescriptionSolution
RV-D001issuanceDate must be before expirationDateEnsure credential doesn't expire before it's issued
RV-D002lastUpdatedDate must be between issuanceDate and expirationDateUpdate date must fall within validity period
RV-D003proof.created must be >= issuanceDateSignature can't be created before credential issuance

Example:

// This will trigger RV-D001
const credential = {
  issuanceDate: "2025-12-01T00:00:00Z",
  expirationDate: "2025-01-01T00:00:00Z",  // Before issuance!
};

Freshness Warnings

These warnings indicate stale verification data. They don't prevent validation but should be addressed.

CodeDescriptionThreshold
RV-F001Sanctions screening is stale> 90 days
RV-F002PEP assessment is stale> 180 days
RV-F003Adverse media assessment is stale> 180 days
RV-F004Tax verification is stale> 730 days (2 years)
RV-F005Credential expiredPast expirationDate

Example:

const result = validateDeveloperCredential(credential);
if (result.ok && result.warnings.length > 0) {
  for (const warning of result.warnings) {
    if (warning.code === 'RV-F001') {
      console.log('Consider re-screening for sanctions');
    }
  }
}

Data Category Errors

These errors indicate missing compliance requirements for sensitive data types.

CodeDescriptionRequirement
RV-X001PHI data requires HIPAA certificationAdd hipaa to complianceCertifications
RV-X002Financial data requires PCI-DSS or SOC2Add pci_dss or soc2_type2 to complianceCertifications
RV-X003Children's data requires age restrictionsSet ageRestrictions to 13+ or higher

Example:

// This will trigger RV-X001
const credential = {
  dataCategoriesProcessed: ["phi"],  // Protected Health Information
  complianceCertifications: ["soc2_type2"],  // Missing HIPAA!
};

Signature Errors (SIG-*)

Parsing Errors

CodeDescriptionSolution
SIG-001Invalid JWS structureEnsure token has 3 base64url-encoded parts separated by dots
SIG-002Unsupported algorithmUse EdDSA or ES256 only
SIG-003Algorithm "none" not allowedAlways sign credentials with a real algorithm
SIG-004Invalid header encodingHeader must be valid base64url-encoded JSON
SIG-005Invalid payload encodingPayload must be valid base64url-encoded JSON
SIG-006Invalid signature encodingSignature must be valid base64url

Key Resolution Errors

CodeDescriptionSolution
SIG-007Key resolution failedEnsure keyResolver returns a valid key for the given DID/kid

Verification Errors

CodeDescriptionSolution
SIG-008Signature verification failedCheck that the correct public key is used
SIG-009Token expiredexp claim is in the past
SIG-010Token not yet validnbf claim is in the future
SIG-011Issuer mismatchiss claim doesn't match expectedIssuer
SIG-012Audience mismatchaud claim doesn't match expectedAudience
SIG-013Missing required claimRequired JWT claim (iss, sub, jti, etc.) is missing
SIG-014Schema validation failedCredential in vc claim doesn't match schema

Example:

try {
  await verifyCredential(token, options);
} catch (error) {
  if (error instanceof SignatureError) {
    switch (error.code) {
      case 'SIG-008':
        console.error('Wrong public key - check kid header');
        break;
      case 'SIG-009':
        console.error('Token expired - request new credential');
        break;
      case 'SIG-011':
        console.error('Unexpected issuer - verify trust');
        break;
    }
  }
}

Trust Chain Errors (TC-*)

CodeDescriptionSolution
TC-001Agent credential verification failedCheck agent token signature and claims
TC-002Developer credential fetch failedEnsure fetchDeveloperCredential callback works
TC-003Developer credential verification failedCheck developer token signature and claims
TC-004Developer credential ID mismatchAgent's developerCredentialId doesn't match fetched credential
TC-005Status check failedcheckStatus callback encountered an error
TC-006Agent credential revokedAgent credential is no longer valid
TC-007Developer credential revokedDeveloper credential is no longer valid

Example:

try {
  await verifyAgentTrustChain(token, options);
} catch (error) {
  if (error instanceof TrustChainError) {
    console.log(`Failed at step: ${error.step}`);
    // AGENT_VERIFY, DEVELOPER_FETCH, DEVELOPER_VERIFY, STATUS_CHECK
    
    if (error.agentCredential) {
      console.log('Partial agent data:', error.agentCredential);
    }
  }
}

Policy Violation Errors (POL-*)

CodeDescription
POL-001KYB tier requirement not met
POL-002Prompt injection score too low
POL-003PII leakage score too low
POL-004Tool abuse score too low
POL-005Harm refusal score too low
POL-006Verification level requirement not met
POL-007Prohibited data category processed

Example:

try {
  await verifyAgentTrustChain(token, {
    policy: {
      minKybTier: 'tier_2',
      minPromptInjectionScore: 85,
    },
  });
} catch (error) {
  if (error instanceof PolicyViolationError) {
    for (const violation of error.violations) {
      console.log(`${violation.type}: required ${violation.required}, got ${violation.actual}`);
    }
    
    if (error.hasType('KYB_TIER')) {
      console.error('Developer needs higher KYB verification');
    }
  }
}

HTTP Signature Errors

CodeDescriptionSolution
HTTP-001Missing Signature-Agent headerAdd Signature-Agent header to request
HTTP-002Missing Signature-Input headerAdd Signature-Input header to request
HTTP-003Missing Signature headerAdd Signature header to request
HTTP-004Invalid Signature-Input formatCheck RFC 9421 format
HTTP-005Key directory fetch failedEnsure key directory URL is accessible
HTTP-006Key not found in directoryVerify keyid matches a key in directory
HTTP-007Signature verification failedCheck private/public key pair
HTTP-008Signature expiredRequest is too old, expires has passed
HTTP-009Content-Digest mismatchRequest body was modified

Error Handling Best Practices

Categorize Errors

import {
  ValidationError,
  SignatureError,
  TrustChainError,
  PolicyViolationError,
} from '@beltic/sdk';

async function handleCredential(token: string) {
  try {
    return await verifyAgentTrustChain(token, options);
  } catch (error) {
    if (error instanceof ValidationError) {
      // Schema/format issues - likely caller error
      return { status: 400, error: 'Invalid credential format' };
    }
    
    if (error instanceof SignatureError) {
      // Cryptographic issues - could be tampering
      return { status: 401, error: 'Invalid signature' };
    }
    
    if (error instanceof TrustChainError) {
      // Trust chain broken - credential relationship issues
      return { status: 403, error: 'Trust chain verification failed' };
    }
    
    if (error instanceof PolicyViolationError) {
      // Policy issues - credential doesn't meet requirements
      return { status: 403, error: 'Policy requirements not met' };
    }
    
    // Unknown error
    throw error;
  }
}

Log Details, Return Safe Messages

import { getPublicMessage, sanitizeMessage } from '@beltic/sdk';

try {
  await verifyCredential(token, options);
} catch (error) {
  // Log full details for debugging
  logger.error('Verification failed', {
    code: error.code,
    message: error.message,
    stack: error.stack,
  });
  
  // Return safe message to client
  res.status(401).json({
    error: getPublicMessage(error),
    code: error.code,
  });
}

Error Constants

Both SDKs export error code constants for type-safe error handling:

import {
  VALIDATION_ERRORS,
  SIGNATURE_ERRORS,
  DATE_ORDER_CODES,
  FRESHNESS_CODES,
  DATA_CATEGORY_CODES,
} from '@beltic/sdk';

if (error.code === SIGNATURE_ERRORS.EXPIRED) {
  // Handle expired token
}

if (FRESHNESS_CODES.includes(warning.code)) {
  // Handle any freshness warning
}
from beltic import (
    VALIDATION_ERRORS,
    SIGNATURE_ERRORS,
    DATE_ORDER_CODES,
    FRESHNESS_CODES,
    DATA_CATEGORY_CODES,
)

if error.code == SIGNATURE_ERRORS["EXPIRED"]:
    # Handle expired token
    pass

See Also