credential Class
Overview
The credential
class implements W3C Verifiable Credentials, providing a standardized way to represent cryptographically-verifiable digital credentials. This class extends verifiable_data
to support the full W3C data model with multiple attestations.
Core Methods
get_id() / set_id()
Gets or sets the credential identifier.
std::string get_id() const
void set_id(const std::string& id)
get_type() / set_type()
Gets or sets the credential type.
std::string get_type() const
void set_type(const std::string& type)
Validity Management
get_valid_from() / set_valid_from()
Gets or sets the credential validity start timestamp.
uint64_t get_valid_from() const
void set_valid_from(uint64_t timestamp)
Example Usage
#include <keychain/keychain_headers.hpp>
// Create a new credential
credential cred;
cred.set_id("https://example.com/credentials/123");
cred.set_type("UniversityDegreeCredential");
cred.set_issuer("did:keychain:university123");
cred.set_subject("did:keychain:student456");
// Set validity period (1 year from now)
uint64_t now = time(nullptr);
cred.set_valid_from(now);
cred.set_valid_until(now + (365 * 24 * 60 * 60));
// Add claims
tag_set claims;
claims.set("degree", "Bachelor of Science");
claims.set("major", "Computer Science");
claims.set("gpa", "3.8");
cred.set_claims(claims);
// Sign the credential (assuming gateway is configured)
gateway gw;
verifiable_data signed_cred = gw.sign(cred, persona_instance);
See Also
-
verifiable_data - Base class for signed data
-
transaction - Consensus-based transactions
-
gateway - Main API for cryptographic operations