Skip to Content
API ReferenceCredentials

Credentials (Low-level)

These are low-level building blocks. Most applications should use delegate and verifyDelegation instead.

SD-JWT VCs (Selective Disclosure JSON Web Token Verifiable Credentials) allow the holder to reveal only specific claims to a verifier. These functions give you direct control over credential creation, verification, and selective disclosure.


createSdJwtVc

Creates an SD-JWT Verifiable Credential with optional selective disclosure for individual claims.

function createSdJwtVc(options: SdJwtVcCreateOptions): Promise<string>

Parameters

SdJwtVcCreateOptions

ParameterTypeRequiredDefaultDescription
issuerPrivateKeyUint8ArrayYes---Issuer’s private key for signing
issuerPublicKeyUint8ArrayYes---Issuer’s public key
issuerDidstringYes---DID of the credential issuer
typestringYes---Verifiable Credential Type (e.g. "AgentDelegationCredential")
claimsCredentialClaimsYes---The credential claims (payload)
selectiveDisclosurestring[]Yes---Claim names to make selectively disclosable
algorithmAlgorithmNo"ES256"Signing algorithm ("ES256" or "EdDSA")
holderDidstringNo---DID of the credential holder (set as sub claim)
expiresAtDateNo---Expiration date
statusList{ url: string; index: number }No---Status list reference for revocation

Returns

string --- the signed SD-JWT VC token. Contains the JWT, disclosures, and key binding material.

Example

import { createSdJwtVc, generateKeyPair } from "@credat/sdk"; const issuerKeys = generateKeyPair("ES256"); const vc = await createSdJwtVc({ issuerPrivateKey: issuerKeys.privateKey, issuerPublicKey: issuerKeys.publicKey, issuerDid: "did:web:acme.com", type: "EmployeeCredential", claims: { name: "Alice Martin", email: "alice@example.com", role: "engineer", department: "platform", }, selectiveDisclosure: ["email", "department"], holderDid: "did:web:acme.com:users:alice", statusList: { url: "https://acme.com/.well-known/status/1", index: 7, }, });

verifySdJwtVc

Verifies the signature and structure of an SD-JWT VC token.

function verifySdJwtVc( sdJwt: string, issuerPublicKey: Uint8Array, ): Promise<SdJwtVcVerifyResult>

Parameters

ParameterTypeRequiredDescription
sdJwtstringYesThe SD-JWT VC token to verify
issuerPublicKeyUint8ArrayYesIssuer’s public key

Returns

SdJwtVcVerifyResult

FieldTypeDescription
validbooleanWhether the token is valid
claimsCredentialClaimsDecoded claims (disclosed claims only)
issuerstringIssuer DID (empty string on failure)
format"sd-jwt-vc"Always "sd-jwt-vc"
issuedAtDateWhen the credential was issued
expiresAtDate | undefinedExpiration date, if set
statusListEntry{ statusListUrl: string; statusListIndex: number } | undefinedStatus list reference, if embedded
errorsstring[] | undefinedError messages (present when valid is false)

Example

import { verifySdJwtVc, generateKeyPair } from "@credat/sdk"; const issuerKeys = generateKeyPair("ES256"); const result = await verifySdJwtVc(vc, issuerKeys.publicKey); if (result.valid) { console.log(result.claims); // Only disclosed claims are present } else { console.error(result.errors); }

selectDisclosures

Selects which claims to reveal from an SD-JWT VC. Returns a new token containing only the chosen disclosures --- claims not listed in revealClaims are omitted entirely.

function selectDisclosures(sdJwt: string, revealClaims: string[]): string

Parameters

ParameterTypeRequiredDescription
sdJwtstringYesThe full SD-JWT with all disclosures
revealClaimsstring[]YesNames of claims to reveal

Returns

string --- a new SD-JWT containing only the selected disclosures. Non-selectively-disclosable claims (those not listed in selectiveDisclosure at creation time) are always included.

Example

import { createSdJwtVc, selectDisclosures, verifySdJwtVc, generateKeyPair } from "@credat/sdk"; const issuerKeys = generateKeyPair("ES256"); // Create a credential with selective disclosure on email and department const vc = await createSdJwtVc({ issuerPrivateKey: issuerKeys.privateKey, issuerPublicKey: issuerKeys.publicKey, issuerDid: "did:web:acme.com", type: "EmployeeCredential", claims: { name: "Alice Martin", email: "alice@example.com", role: "engineer", department: "platform", }, selectiveDisclosure: ["email", "department"], holderDid: "did:web:acme.com:users:alice", }); // Reveal only the email --- name and role are always visible, // department is hidden const presented = selectDisclosures(vc, ["email"]); // Verifier sees: name, role, email (but not department) const result = await verifySdJwtVc(presented, issuerKeys.publicKey);

Errors

CodeWhen
CREDENTIAL_INVALID_FORMATA disclosure in the token is malformed
Last updated on