The verifyVC function is an asynchronous method designed to validate the authenticity and integrity of a Verifiable Credential (VC) according to its cryptographic signature. Additionally, it checks the credential’s expiration and revocation status.

Function Signature

TypeScript
async function verifyVC(
  vc: SignedCredential,
  options?: VerificationOptions
): Promise<boolean>;

Parameters

  • vc (SignedCredential): The signed credential object that needs to be verified. It must include the cryptographic proof and other essential data like the issuer’s information and the credential’s attributes.
  • options (VerificationOptions, optional): Configuration options for the verification process. This include:
    • revocationRegistryAddress (ethers.AddressLike): Optional. The address of the smart contract that handles credential revocation.
    • provider (ethers.Provider): Optional. The blockchain provider through which blockchain interactions are performed.
    • mandatoryPointers (string[]): Optional. A list of mandatory fields that must be included in the credential’s proof checking.

Returns

  • Promise<boolean>: A promise that resolves to true if the credential is verified successfully, or false if the verification fails due to any reason such as an invalid or expired signature, or if the credential has been revoked.

Examples

TypeScript
import { createEcdsaCredential, EthrDID } from "@terminal3/ecdsa_vc";
import { DID, type VerificationOptions } from "@terminal3/vc_core";
import { verifyVc } from "@terminal3/verify_vc";
import { ethers } from "ethers";

// Issuer's private key and setup
const issuerPrivateKey = "private_key_here";
const issuer = new EthrDID(issuerPrivateKey, "polygon");

// Holder's DID
const holderDid = new DID("ethr", "Ox....");

// Creating a credential with BBS+ signature
const claims = { kyc: "passed" };
const revocationRegistryAddress = "0x77Fb69B24e4C659CE03fB129c19Ad591374C349e";
const didRegistryAddress = "0x312C15922c22B60f5557bAa1A85F2CdA4891C39a";
const provider = new ethers.JsonRpcProvider(process.env.TEST_BLOCKCHAIN_URL);
const options = {
  revocationRegistryAddress,
  provider,
  didRegistryAddress,
} as unknown as VerificationOptions;

const vc = await createEcdsaCredential(
  issuer,
  holderDid,
  claims,
  ["KycCredential"],
  undefined,
  undefined,
  options
);

const verificationResult = await verifyVc(vc);
console.log("Credential verification: ", verificationResult.isValid);