| Crates.io | oxirs-did |
| lib.rs | oxirs-did |
| version | 0.1.0 |
| created_at | 2025-12-26 14:52:21.431602+00 |
| updated_at | 2026-01-20 21:07:15.627063+00 |
| description | W3C DID and Verifiable Credentials implementation with Signed RDF Graphs for OxiRS |
| homepage | https://github.com/cool-japan/oxirs |
| repository | https://github.com/cool-japan/oxirs |
| max_upload_size | |
| id | 2005816 |
| size | 207,820 |
W3C DID and Verifiable Credentials implementation with Signed RDF Graphs
Full implementation of W3C Decentralized Identifiers (DID) and Verifiable Credentials (VC) specifications, with support for cryptographically signed RDF graphs.
use oxirs_did::{Did, DidResolver};
use oxirs_did::proof::ed25519::Ed25519Signer;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Generate Ed25519 keypair
let signer = Ed25519Signer::generate();
let public_key = signer.public_key_bytes();
// Create did:key from public key
let did = Did::new_key_ed25519(&public_key)?;
println!("DID: {}", did);
// Output: did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK
// Resolve DID to DID Document
let resolver = DidResolver::new();
let doc = resolver.resolve(&did).await?;
println!("DID Document: {}", serde_json::to_string_pretty(&doc)?);
Ok(())
}
use oxirs_did::{Did, VerifiableCredential, VcIssuer};
use oxirs_did::proof::ed25519::Ed25519Signer;
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Issuer identity
let issuer_signer = Ed25519Signer::generate();
let issuer_did = Did::new_key_ed25519(&issuer_signer.public_key_bytes())?;
// Create credential
let mut vc = VerifiableCredential::new(
issuer_did.clone(),
json!({
"id": "did:key:z6Mk...",
"email": "alice@example.com",
"role": "Researcher"
}),
)
.with_type("EmailCredential")
.with_expiration_days(365);
// Issue (sign) the credential
let issuer = VcIssuer::new(issuer_signer);
issuer.issue(&mut vc, None).await?;
println!("{}", serde_json::to_string_pretty(&vc)?);
Ok(())
}
use oxirs_did::{DidResolver, VcVerifier, VerifiableCredential};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let resolver = DidResolver::new();
let verifier = VcVerifier::new(resolver);
// Parse VC from JSON
let vc: VerifiableCredential = serde_json::from_str(vc_json)?;
// Verify
let result = verifier.verify(&vc).await?;
if result.valid {
println!("✓ Credential is VALID");
println!(" Issued by: {}", result.issuer.unwrap());
} else {
println!("✗ Credential is INVALID");
for error in &result.errors {
println!(" - {}", error);
}
}
Ok(())
}
use oxirs_did::signed_graph::{SignedGraph, RdfTriple};
use oxirs_did::proof::ed25519::Ed25519Signer;
use oxirs_did::{Did, DidResolver};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create signer
let signer = Ed25519Signer::generate();
let did = Did::new_key_ed25519(&signer.public_key_bytes())?;
// Create RDF graph
let triples = vec![
RdfTriple::iri(
"http://data.example/entity-1",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
"http://schema.org/Dataset"
),
];
// Sign graph
let graph = SignedGraph::new(
"http://data.example/research-2025",
triples,
did.clone()
);
let signed = graph.sign(&signer)?;
println!("Graph hash: {}", signed.hash()?);
// Verify later
let resolver = DidResolver::new();
let valid = signed.verify(&resolver).await?;
println!("Verification: {}", if valid.valid { "✓" } else { "✗" });
Ok(())
}
No network required, deterministic from public key:
did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK
└─ Base58btc(0xed01 + Ed25519_public_key)
HTTPS-based resolution:
did:web:example.com
→ https://example.com/.well-known/did.json
did:web:example.com:users:alice
→ https://example.com/users/alice/did.json
did:web:example.com%3A8080
→ https://example.com:8080/.well-known/did.json
[dependencies]
oxirs-did = { version = "0.1", features = ["did-web", "signed-graphs"] }
Available features:
did-key (default) - did:key methoddid-web - did:web method (requires reqwest)did-ebsi - European Blockchain Services Infrastructurevc-data-model-2 (default) - W3C VC 2.0signed-graphs - RDF graph signing/verificationkey-management - Key storageed25519-dalek - Ed25519 signaturesmultibase, bs58 - Multiformat encodingsha2 - Cryptographic hashingscirs2-core - Secure random number generationLicensed under either of Apache License, Version 2.0 or MIT license at your option.