baseid-anoncreds
Provides AnonCreds credential schema definition, credential issuance/holding, proof request matching, and proof response construction. Enables interoperability with the Canadian Aries ecosystem (BC Wallet, ACA-Py).
Key Features
Section titled “Key Features”- Schema & CredentialDefinition — Define credential types with validated
MAJOR.MINORversions and CL signature references - ACA-Py JSON Parsing — Parse credentials directly from ACA-Py’s JSON format with automatic issuer DID extraction
- W3C VC Mapping — Map AnonCreds credentials to W3C Verifiable Credentials for unified display across formats
- ProofRequest Matching — Match stored credentials against proof requests with single attributes, grouped names, and predicates
- CredentialHolder — Store credentials, search for matching proof requests, and build proof responses with revealed attributes
- Sovrin & DID Interop — Handles both
did:sov:prefixed and bare Sovrin-style identifiers
Quick Start
Section titled “Quick Start”use baseid_anoncreds::*;
// Define a schemalet schema = Schema::new( "did:sov:NcYx:2:degree:1.0", "degree", "1.0", vec!["name".into(), "degree".into(), "university".into()],)?;
// Parse a credential from ACA-Py JSONlet cred = AnonCredsCredential::from_aca_py_json(r#"{ "schema_id": "did:sov:NcYx:2:degree:1.0", "cred_def_id": "did:sov:NcYx:3:CL:12:default", "rev_reg_id": null, "values": { "name": {"raw": "Alice", "encoded": "27034..."}, "degree": {"raw": "Computer Science", "encoded": "123456"} }}"#)?;
// Store it in a holderlet mut holder = CredentialHolder::new();let id = holder.store_credential(cred);
// Match against a proof request and build a responselet request = ProofRequest { /* ... */ };let matches = holder.find_credentials_for_request(&request);let response = holder.create_proof_response(&id, &request).unwrap();assert_eq!(response.revealed_attrs["attr1_referent"].raw, "Alice");W3C VC Mapping
Section titled “W3C VC Mapping”AnonCreds credentials can be mapped to W3C VCs for unified rendering in wallet UIs:
let cred = AnonCredsCredential::from_aca_py_json(aca_py_json)?;let vc = cred.to_w3c_vc();
// VC uses "AnonCreds:<schema_name>" as the credential typeassert!(vc.r#type.contains(&"AnonCreds:degree".to_string()));// Raw attribute values become credentialSubject claimsassert_eq!(vc.credential_subject["name"], "Alice");Key Types
Section titled “Key Types”| Type | Description |
|---|---|
Schema | AnonCreds schema with id, name, version, and attribute names |
CredentialDefinition | References a schema with CL signature type and tag |
AnonCredsCredential | Parsed credential with schema/cred-def IDs and attribute values |
AttributeValue | Raw (human-readable) and encoded (integer) value pair |
ProofRequest | Requested attributes, predicates, and nonce for proof generation |
ProofResponse | Revealed attributes and self-attested values |
CredentialHolder | In-memory credential store with proof request matching |
Design Note
Section titled “Design Note”AnonCreds uses CL (Camenisch-Lysyanskaya) signatures which are mathematically complex. This crate provides the data model and holder logic; actual CL proof generation would wrap the Hyperledger anoncreds-rs library.
Related Crates
Section titled “Related Crates”baseid-vc— W3C Verifiable Credentials (VC mapping target)baseid-wallet-core— Wallet credential storage and presentationbaseid-didcomm— Aries-compatible credential exchange protocols