vc #
The W3C Verifiable Credentials 2.0 family (W3C Recommendations, 15 May 2025)
without a JSON-LD processor:
- the Verifiable Credentials Data Model v2.0: credentials and
presentations (application/vc,application/vp) read as JSON documents
that carry the base context first and the properties the model requires,
each in the shape its section gives; - Securing Verifiable Credentials using JOSE and COSE: a
credential enveloped as a JWS (vc+jwt), an SD-JWT (vc+sd-jwt) or a
COSE_Sign1(vc+cose), and carried in a presentation as an
EnvelopedVerifiableCredential; - Data Integrity 1.0 embedded proofs with the JCS cryptosuites
eddsa-jcs-2022(EdDSA Cryptosuites v1.0) andecdsa-jcs-2019
(ECDSA Cryptosuites v1.0, P-256 and P-384), which canonicalize by
RFC 8785 and resolve their verification methods through DIDs (did:key, and
did:web by a resolver) toMultikeykeys.
Contents #
Installation #
$ opam install vc
The library is vc and its module is Vc; the package installs the vc
command.
Usage #
A credential is read and checked against the data model:
# let credential () = Json.Value.of_string_exn {|{
"@context": ["https://www.w3.org/ns/credentials/v2"],
"type": ["VerifiableCredential"],
"issuer": "did:key:z6MkrJVnaZkeFzdQyMZu1cgjg7k1pZZ6pvBQ7XJPt4swbTQ2",
"credentialSubject": {"id": "did:example:abcdefgh", "alumniOf": "The School of Examples"}
}|};;
val credential : unit -> Json.t = <fun>
# Vc.Credential.of_json (credential ()) |> Result.map Vc.Credential.issuer;;
- : (string, [ `Msg of string ]) result =
Ok "did:key:z6MkrJVnaZkeFzdQyMZu1cgjg7k1pZZ6pvBQ7XJPt4swbTQ2"
The issuer adds an eddsa-jcs-2022 proof with its Multikey secret key, and
a verifier checks it, resolving the did:key verification method by itself:
# let signed () =
let pub = "z6MkrJVnaZkeFzdQyMZu1cgjg7k1pZZ6pvBQ7XJPt4swbTQ2" in
let key =
Did.Multikey.secret_of_multibase
"z3u2en7t5LR2WtQH5PfFqMqwVHBeXouLzo6haApm8XHqvjxq"
in
Result.bind key (fun key ->
Vc.Data_integrity.add_proof Eddsa_jcs_2022 ~key
~verification_method:("did:key:" ^ pub ^ "#" ^ pub)
~proof_purpose:"assertionMethod" (credential ()));;
val signed : unit -> (Json.t, Did.error) result = <fun>
# let now = Option.get (Ptime.of_date (2026, 1, 1));;
val now : Ptime.t = <abstr>
# Result.bind (signed ())
(Vc.Data_integrity.verify_credential
~resolve:Vc.Verification_method.did_key ~now)
|> Result.map (fun (_, proofs) -> List.length proofs);;
- : (int, Did.error) result = Ok 1
A did:web issuer's keys are in its DID document: Vc.Verification_method.did ~documents resolves a did:key by itself and any other DID through
documents, such as Did_resolve.resolve of the did-resolve package.
Command line #
$ vc check credential.json
$ vc sign --cryptosuite eddsa-jcs-2022 --key issuer.key \
--verification-method "did:key:z6Mk...#z6Mk..." credential.json > signed.json
$ vc verify signed.json
$ vc verify --jwk issuer.jwk credential.jwt
vc verify takes the cryptosuites and JWS algorithms it accepts as repeatable
--cryptosuite and --algorithm flags, and resolves a did:web or did:plc
verification method over the network.
What it covers #
- The data model is checked as JSON, never expanded: the base context
https://www.w3.org/ns/credentials/v2comes first, and each type is a term
matched as a string. Vc.Data_integrity.verify_credentialrequires a proof by a verification
method of the issuer: the method's URL before its#is the issuer's URL.
Vc.Data_integrity.verifychecks the proofs alone.- The cryptosuites' allowlist defaults to both JCS suites; the JOSE
algorithms' to ES256, ES384 and Ed25519; the COSE algorithms' to ES256,
ES384 and EdDSA. - The RDF canonicalization cryptosuites (
eddsa-rdfc-2022,
ecdsa-rdfc-2019) andecdsa-sd-2023need JSON-LD expansion and RDF
Dataset Canonicalization, which this library does not do.
License #
ISC. See LICENSE.md.