Credential Utilities

Functions
  • extractIssuerId(issuer) — Extract the issuer DID string from a VC's issuer field (accepts string or {id: string})
  • isCredentialActive(ref, now?) — Check if a credential reference is still active (optional now: Date parameter)
  • isCredentialForAgent(vc, agentOwner) — Verify a VC belongs to a specific agent
  • buildCredentialsExtension(credentials) — Build the credentials extension for agent updates
  • hashCredential(vcJson) — SHA-256 hash a VC JSON string
TypeScript
import { isCredentialActive, isCredentialForAgent, extractIssuerId, buildCredentialsExtension, CREDENTIAL_TYPES } from '@vouch-protocol/sdk';

// Check if a credential reference is still active
const active = isCredentialActive(credentialRef); // Uses current date by default
const activeAt = isCredentialActive(credentialRef, new Date('2026-06-01')); // Check at a specific date

// Verify a VC belongs to a specific agent owner
const matches = isCredentialForAgent(verifiableCredential, agentOwnerPubkey);

// Extract the issuer DID from a VC's issuer field
const issuerId = extractIssuerId(vc.issuer); // Accepts string or { id: string }

// Build the credentials extension for agent card updates
const ext = buildCredentialsExtension(credentials);

Example Returns

extractIssuerId()

Returns
// string — the issuer DID
"did:sol:AuditorPubkey123..."

isCredentialActive()

Returns
// boolean
true

isCredentialForAgent()

Returns
// boolean — true if vc.credentialSubject.id matches the agent's DID
true

buildCredentialsExtension()

Returns
// VouchCredentialsExtension
{
  "credentials": [
    {
      "type": "SecurityAuditCredential",
      "issuer": "did:sol:AuditorPubkey123...",
      "credentialUrl": "https://auditor.example/vc/123.json",
      "validFrom": "2026-01-01T00:00:00Z",
      "validUntil": "2027-01-01T00:00:00Z"
    }
  ]
}

hashCredential()

Returns
// Promise<Uint8Array> — 32-byte SHA-256 hash
Uint8Array(32) [171, 62, 14, ...]