W3C Verifiable Credentials 2.0 with VC-JOSE-COSE and Data Integrity
README.md

vc #

The W3C Verifiable Credentials 2.0 family (W3C Recommendations, 15 May 2025)
without a JSON-LD processor:

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/v2 comes first, and each type is a term
    matched as a string.
  • Vc.Data_integrity.verify_credential requires a proof by a verification
    method of the issuer: the method's URL before its # is the issuer's URL.
    Vc.Data_integrity.verify checks 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) and ecdsa-sd-2023 need JSON-LD expansion and RDF
    Dataset Canonicalization, which this library does not do.

License #

ISC. See LICENSE.md.