Sign and verify your awesome Knowledge Graphs with eccenca Corporate Memory :-)
RdfCanonicalization implements the RDFC-1.0 dataset normalization algorithm, producing a canonical N-Triples string with deterministic blank node identifiers.
import rdflib
from graph_sign_and_verify_c4gai.rdf_canonicalization import RdfCanonicalization
graph = rdflib.Graph()
graph.parse("my_graph.ttl", format="turtle")
normalizer = RdfCanonicalization(graph, max_run_time=5)
canonical = normalizer.normalize # sorted, deterministic N-Triples string
print(canonical)max_run_time(optional): maximum seconds allowed before aTimeoutErroris raised.- The
normalizeproperty runs the full pipeline and returns the canonical N-Triples string.
graphsignature provides a simpler canonicalization (sorted N-Triples) combined with RSA-PSS signing and verification.
from rdflib import Graph
from graph_sign_and_verify_c4gai.graphsignature import (
canonicalize_rdf,
hash_rdf,
generate_key_pair,
sign_hash,
verify_signature,
)
# Load an RDF graph
graph = Graph()
graph.parse("my_graph.nt")
# Canonicalize and hash
canonical = canonicalize_rdf(graph)
rdf_hash = hash_rdf(canonical)
# Generate an RSA-2048 key pair
private_key, public_key = generate_key_pair()
# Sign
signature = sign_hash(private_key, rdf_hash)
# Verify
is_valid = verify_signature(public_key, rdf_hash, signature)
print("Signature valid:", is_valid)- Run task to see all major development tasks.
- Use pre-commit to avoid errors before commit.
- This repository was created with this copier template.