Skip to content

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).

  • Schema & CredentialDefinition — Define credential types with validated MAJOR.MINOR versions 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
use baseid_anoncreds::*;
// Define a schema
let 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 JSON
let 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 holder
let mut holder = CredentialHolder::new();
let id = holder.store_credential(cred);
// Match against a proof request and build a response
let 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");

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 type
assert!(vc.r#type.contains(&"AnonCreds:degree".to_string()));
// Raw attribute values become credentialSubject claims
assert_eq!(vc.credential_subject["name"], "Alice");
TypeDescription
SchemaAnonCreds schema with id, name, version, and attribute names
CredentialDefinitionReferences a schema with CL signature type and tag
AnonCredsCredentialParsed credential with schema/cred-def IDs and attribute values
AttributeValueRaw (human-readable) and encoded (integer) value pair
ProofRequestRequested attributes, predicates, and nonce for proof generation
ProofResponseRevealed attributes and self-attested values
CredentialHolderIn-memory credential store with proof request matching

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.