Verify Credentials

Tutorial: Verify a Verifiable Credential

This tutorial walks you through verifying a Verifiable Credential (VC) using LearnCard. Verification checks that:

  1. The credential's cryptographic proof is valid

  2. The credential hasn't been tampered with

  3. The credential hasn't expired

Prerequisites

Installation

npm install @learncard/init

Basic Verification

import { initLearnCard } from '@learncard/init';

// Initialize LearnCard (no seed needed for verification-only)
const learnCard = await initLearnCard();

// Example signed credential (you'd receive this from an issuer)
const signedCredential = {
  "@context": ["https://www.w3.org/2018/credentials/v1"],
  "type": ["VerifiableCredential"],
  "issuer": "did:key:z6MkjZ...",
  "issuanceDate": "2024-01-01T00:00:00Z",
  "credentialSubject": {
    "id": "did:key:z6Mkp...",
    "achievement": "Completed Tutorial"
  },
  "proof": {
    "type": "Ed25519Signature2020",
    // ... proof details
  }
};

// Verify the credential
const result = await learnCard.invoke.verifyCredential(signedCredential);

console.log(result);
// { checks: ['proof', 'expiration'], warnings: [], errors: [] }

Understanding Results

Valid Credential

Human-Readable Output

For a more detailed, human-readable result, pass true as the third argument:

Handling Invalid Credentials

Complete Example

Next Steps

Last updated

Was this helpful?