VC Validator
Interactive example
Validate a Verifiable Credential (VC) or a Verifiable Presentation (VP) using our libraries.
- Result
- Source code
This validator uses the open-source library @europeum-ebsi/verifiable-credential. You can install it with your package manager:
# with npm
npm i @europeum-ebsi/verifiable-credential
# with pnpm
pnpm add @europeum-ebsi/verifiable-credential
# with yarn
yarn add @europeum-ebsi/verifiable-credential
In your code, you can now validate the input by using the vcdm20.js entry point:
import { ValidationError } from "@europeum-ebsi/verifiable-credential";
import { verifyCredentialJwt } from "@europeum-ebsi/verifiable-credential/vcdm20.js";
const config = {
hosts: ["<node host>"],
network: { name: "preprod" },
scheme: "ebsi",
services: [
"authorisation",
"contracts-registry",
"did-registry",
"issuers-registry",
"ledger",
"policies-registry",
"schemas-registry",
"timestamp",
"track-and-trace",
],
version: "v1",
};
try {
const credential = await verifyCredentialJwt(
jwt,
config,
);
console.log(credential);
} catch (error) {
if (error instanceof ValidationError) {
console.error(error.message);
} else {
throw error;
}
}
Library
The validator uses two open-source packages:
@europeum-ebsi/verifiable-credentialvalidates JWT VCs.@europeum-ebsi/verifiable-presentationvalidates JWT VPs, including every credential they embed.
Entry points
Each package has three entry points:
| Entry point | Content |
|---|---|
. | Shared types, EbsiEnvConfiguration and the error classes |
./vcdm11.js | verifyCredentialJwt / verifyPresentationJwt for VCDM 1.1 |
./vcdm20.js | verifyCredentialJwt / verifyPresentationJwt for VCDM 2.0 |
Functions
verifyCredentialJwt(jwt: string, config: EbsiEnvConfiguration, options?: VerifyCredentialOptions)
verifyPresentationJwt(jwt: string, audience: string, config: EbsiEnvConfiguration, options?: VerifyPresentationJwtOptions)
config describes the EBSI environment: hosts, network ({ name: "test" }), scheme ("ebsi"), services (the list of EBSI services to trust) and version ("v1"). The Source code tab of the validator shows a complete example.
Options
Both functions share these options:
| Option | Description |
|---|---|
validAt | Unix timestamp used instead of the current time to check validity |
clockSkew | Seconds of tolerance applied around nbf and exp (default 0) |
timeout | Timeout of the HTTP requests sent to EBSI services |
axiosHeaders | Custom headers added to those requests |
proofPurpose | Verification relationship the signing key must hold (default assertionMethod for credentials, authentication for presentations) |
didRegistryContractAddress | Target a specific DID Registry instance. DIDs must prove they belong to it |
issuersRegistryContractAddress | Target a specific Issuers Registry instance |
verifyCredentialJwt also accepts trustChainRootDid (one DID: a RootTAO attribute that grants VerifiableAuthorisationForTrustChain must be issued by it), skipAccreditationsValidation, skipAccreditationWithoutTermsOfUseValidation, skipCredentialSubjectValidation, skipStatusValidation, extraCredentialSchemaTypes and skipTrustedIssuerValidationForSelfIssuedCredentials (both VCDM versions). The issuer of a Root TAO authorisation must also be the tao recorded on chain for its attribute, so trustChainRootDid can only name a Root TAO's own DID, never the Support Office. When it is not set, no root DID is pinned.
The VCDM 2.0 version also accepts trustFrameworkPolicyValidator, a hook that decides whether the Trust Framework Policy of the chain root is acceptable for your use case. It receives { rootDid, trustFramework, policyId, legalBasis, permissionFor, trustChain }, where permissionFor[].jurisdiction is a string[] and trustChain holds the permissions of every accreditation of the chain, from the issuer's up to the Root TAO's. It is called after the whole chain has been validated, so a chain error is reported first. Throw to reject the policy. The library doesn't compare jurisdictions itself.
verifyPresentationJwt also accepts maxIatAge (maximum age of the iat claim), skipHolderDidResolutionValidation, skipHolderDidRegistryProvenanceCheck and verifyCredentialOptions (options applied to each embedded credential). The audience is a positional argument: it must match the aud claim of the presentation.
Credential status
Only BitstringStatusListEntry and EbsiAccreditationEntry are supported as credentialStatus types. StatusList2021Entry is not.
Errors
| Error | Meaning |
|---|---|
ValidationError | Base class of validation failures |
JsonSchemaValidationError | The input does not match its JSON Schema. ajvErrors lists the violations |
JsonSchemaLoadingError | A schema could not be loaded |
ConfigurationError | The environment configuration is invalid |
EbsiServiceMismatchError | A URL does not point to the expected EBSI service |
Schema, accreditation and status list URLs found in a credential (such as credentialSchema.id) must be trusted EBSI URLs: they must use the configured host and the expected service, and any query string or fragment is ignored.