Third-party certification as a Verifiable Credential¶
Generated file
This page is generated by docs/notebooks/render_notebooks.py from the marimo
notebook certification.py.
Do not edit it here: edit the notebook and regenerate. The CI notebooks job runs
every cell, so the outputs below are from a real execution. The plumbing the example
imports - graph setup, SHACL check, JWT signing - is in
common.py,
deliberately kept out of the page.
Builds a cap:Certification issued by a conformity assessment body, attaches it to a W3C Verifiable Credential v2.0 with cred:Evidence carrying an SRI digest of the source document, validates the graph against the published SHACL shapes, and signs the result as a JWT.
Import modules¶
The graph setup, the SHACL check and the JWT signing come from common.py,
the module shared by both worked examples; only the CAP modelling is here.
from datetime import datetime, timedelta
from pathlib import Path
from dateutil.relativedelta import relativedelta
from rdflib import RDF, RDFS, BNode, Graph, Literal, Node
from rdflib.namespace import FOAF, SDO, XSD
from common import compute_sri, issue_signed_vcs, new_graph, validate_against_cap_shapes
Pick Eclipse CAP version and defines the others ontologies¶
example = new_graph(cap_version="v0")
g, CAP, CRED, GX, EX = example.g, example.CAP, example.CRED, example.GX, example.EX
Generate an Eclipse cap:Certification object¶
def generate_cap_certification(g: Graph) -> tuple[Node, Node]:
certification = EX.TrustedNotary_certification01
g.add((certification, RDF.type, CAP.Certification))
g.add((certification, CAP.hasObjectOfConformityAssessment, EX.OutScaleSAS_IaaS))
scheme = BNode()
g.add((certification, CAP.hasConformityAssessmentScheme, scheme))
g.add((scheme, RDF.type, CAP.ConformityAssessmentScheme))
g.add((scheme, RDFS.label, Literal("SecNumCloud")))
g.add((scheme, RDFS.comment, Literal("version 3.2")))
issuance_date = datetime(year=2023, month=11, day=30)
valid_from = issuance_date
valid_until = valid_from + relativedelta(years=3)
g.add((certification, CAP.validFrom, Literal(valid_from.isoformat(), datatype=XSD.dateTime)))
g.add((certification, CAP.validUntil, Literal(valid_until.isoformat(), datatype=XSD.dateTime)))
g.add((certification, CAP.issuedAt, Literal(issuance_date.isoformat(), datatype=XSD.dateTime)))
issuer = EX.LNE
g.add((certification, CAP.issuedBy, issuer))
g.add((issuer, RDF.type, CAP.ConformityAssessmentBody))
g.add((issuer, RDF.type, GX.LegalPerson))
g.add((issuer, FOAF.name, Literal("LABORATOIRE NATIONAL DE METROLOGIE ET D'ESSAIS", lang="fr")))
g.add((issuer, SDO.vatID, Literal("FR313320244")))
print(f"The cap:Certification object has the id {certification.n3()}")
print(f"The cap:Certification issuer is {issuer.n3()}")
return certification, issuer
certification, certification_issuer = generate_cap_certification(g)
The cap:Certification object has the id <http://example.com/#TrustedNotary_certification01>
The cap:Certification issuer is <http://example.com/#LNE>
Generate the cred:Evidence for the Verifiable Credential¶
The credential points at the certificate document it transcribes, with a digest
so a verifier can check that the document behind the claim has not changed.
The document is the authority's qualification decision, archived in this
repository under fixtures/.
def generate_cred_evidence(g: Graph, evidence_url: str, evidence_file: Path) -> Node:
evidence = BNode()
g.add((evidence, RDF.type, CRED.Evidence))
g.add((evidence, CRED.value, Literal(evidence_url)))
g.add((evidence, CRED.digest, Literal(f"sha256-{compute_sri(evidence_file)}")))
return evidence
# The credential names the archived copy of the authority's decision, which is the only
# copy that resolves for a machine: the origin answers programmatic requests with a
# bot-protection page (`HTTP 200`, `content-type: text/html`, 212 bytes) rather than the
# document. The digest is computed from the same bytes as they sit in the repository, so
# the two must agree; `docs/notebooks/README.md` records the original source, the
# retrieval date and the digest.
evidence = generate_cred_evidence(
g,
"https://gitlab.eclipse.org/eclipse/dataspace-cap/dataspace-cap.eclipse.dev/-/raw/main/docs/notebooks/fixtures/2023_2118_np.pdf",
Path(__file__).parent / "fixtures" / "2023_2118_np.pdf",
)
Create the Verifiable Credential¶
vc = EX.myvc
g.add((vc, RDF.type, CRED.VerifiableCredential))
g.add((vc, CRED.issuer, Literal("did:web:trusted-notary.eu")))
# Fixed instant: this notebook's output is committed as a generated page,
# so it must not churn on every regeneration.
valid_from = datetime(2026, 11, 16, 12, 0, 0)
valid_until = valid_from + timedelta(days=90)
g.add((vc, CRED.validFrom, Literal(valid_from.isoformat(), datatype=XSD.dateTime)))
g.add((vc, CRED.validUntil, Literal(valid_until.isoformat(), datatype=XSD.dateTime)))
# attach the cap:Certificate to the VC
g.add((vc, CRED.credentialSubject, certification))
# attach the cred:Evidence to the VC
g.add((vc, CRED.evidence, evidence))
Display RDF data in Turtle format¶
@prefix cap: <https://w3id.org/eclipse-cap/v0/#> .
@prefix cred: <https://www.w3.org/ns/credentials/v2/> .
@prefix ex: <http://example.com/#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix gx: <https://w3id.org/gaia-x/development#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema: <https://schema.org/> .
ex:myvc a cred:VerifiableCredential ;
cred:credentialSubject ex:TrustedNotary_certification01 ;
cred:evidence [ a cred:Evidence ;
cred:digest "sha256-9b860c2fe0bc4200cf2b94369c82f3806f6db093bd92c3f341fee5e676ff1a60" ;
cred:value "https://gitlab.eclipse.org/eclipse/dataspace-cap/dataspace-cap.eclipse.dev/-/raw/main/docs/notebooks/fixtures/2023_2118_np.pdf" ] ;
cred:issuer "did:web:trusted-notary.eu" ;
cred:validFrom "2026-11-16T12:00:00"^^<http://www.w3.org/2001/XMLSchema#dateTime> ;
cred:validUntil "2027-02-14T12:00:00"^^<http://www.w3.org/2001/XMLSchema#dateTime> .
ex:LNE a cap:ConformityAssessmentBody,
gx:LegalPerson ;
foaf:name "LABORATOIRE NATIONAL DE METROLOGIE ET D'ESSAIS"@fr ;
schema:vatID "FR313320244" .
ex:TrustedNotary_certification01 a cap:Certification ;
cap:hasConformityAssessmentScheme [ a cap:ConformityAssessmentScheme ;
rdfs:label "SecNumCloud" ;
rdfs:comment "version 3.2" ] ;
cap:hasObjectOfConformityAssessment ex:OutScaleSAS_IaaS ;
cap:issuedAt "2023-11-30T00:00:00"^^<http://www.w3.org/2001/XMLSchema#dateTime> ;
cap:issuedBy ex:LNE ;
cap:validFrom "2023-11-30T00:00:00"^^<http://www.w3.org/2001/XMLSchema#dateTime> ;
cap:validUntil "2026-11-30T00:00:00"^^<http://www.w3.org/2001/XMLSchema#dateTime> .
Verify format with SHACL¶
********************************************************************************
True [a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'Memory']]. Validation Report
Conforms: True
Issue signed Verifiable Credential¶
Public Key in JWK format: {"crv":"Ed25519","kid":"zD6Ku27DiffK3Eo53dEThwg7azhZfXYV0x8egjO42jA","kty":"OKP","x":"7p4c1IU6aA65FWn6YZ-Bya5dRbfd4P6d4a6H0u9-gCg"}
eyJhbGciOiJFZERTQSIsImN0eSI6InZjIiwidHlwIjoidmMrand0In0.eyJAY29udGV4dCI6eyJjYXAiOiJodHRwczovL3czaWQub3JnL2VjbGlwc2UtY2FwL3YwLyMiLCJjcmVkIjoiaHR0cHM6Ly93d3cudzMub3JnL25zL2NyZWRlbnRpYWxzL3YyLyIsImV4IjoiaHR0cDovL2V4YW1wbGUuY29tLyMiLCJmb2FmIjoiaHR0cDovL3htbG5zLmNvbS9mb2FmLzAuMS8iLCJneCI6Imh0dHBzOi8vdzNpZC5vcmcvZ2FpYS14L2RldmVsb3BtZW50IyIsInJkZnMiOiJodHRwOi8vd3d3LnczLm9yZy8yMDAwLzAxL3JkZi1zY2hlbWEjIiwic2NoZW1hIjoiaHR0cHM6Ly9zY2hlbWEub3JnLyJ9LCJAaWQiOiJleDpteXZjIiwiQHR5cGUiOiJjcmVkOlZlcmlmaWFibGVDcmVkZW50aWFsIiwiY3JlZDpjcmVkZW50aWFsU3ViamVjdCI6eyJAaWQiOiJleDpUcnVzdGVkTm90YXJ5X2NlcnRpZmljYXRpb24wMSIsIkB0eXBlIjoiY2FwOkNlcnRpZmljYXRpb24iLCJjYXA6aGFzQ29uZm9ybWl0eUFzc2Vzc21lbnRTY2hlbWUiOnsiQHR5cGUiOiJjYXA6Q29uZm9ybWl0eUFzc2Vzc21lbnRTY2hlbWUiLCJyZGZzOmNvbW1lbnQiOiJ2ZXJzaW9uIDMuMiIsInJkZnM6bGFiZWwiOiJTZWNOdW1DbG91ZCJ9LCJjYXA6aGFzT2Jq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