Quick Start
This guide walks you through key generation, DID creation, credential issuance, and verification using BaseID’s Rust crates.
Generate a Key Pair
Section titled “Generate a Key Pair”use baseid_core::types::KeyType;use baseid_crypto::KeyPair;
let key_pair = KeyPair::generate(KeyType::Ed25519)?;BaseID supports Ed25519, P-256, P-384, and secp256k1 key types.
Create a DID
Section titled “Create a DID”use baseid_did::DidKeyResolver;
let doc = DidKeyResolver::create(&key_pair.public)?;let did = doc.id; // "did:key:z6Mk..."The did:key method encodes the public key directly in the DID string, making it self-contained and requiring no network resolution.
Issue a Credential
Section titled “Issue a Credential”use baseid_vc::{sign_credential_jwt, VerifiableCredential};use baseid_vc::credential::Issuer;
let vc = VerifiableCredential { context: vec!["https://www.w3.org/ns/credentials/v2".into()], id: None, r#type: vec!["VerifiableCredential".into(), "DegreeCredential".into()], issuer: Issuer::Uri(did.clone()), valid_from: Some("2024-01-01T00:00:00Z".into()), valid_until: None, credential_subject: serde_json::json!({"degree": "Computer Science"}), credential_status: None, proof: None,};
let jwt = sign_credential_jwt(&vc, &key_pair, &kid)?;The resulting JWT is a compact, signed string that can be transmitted over any channel.
Verify a Credential
Section titled “Verify a Credential”use baseid_vc::verify_credential_jwt;
let verified_vc = verify_credential_jwt(&jwt, &key_pair.public)?;println!("Subject: {:?}", verified_vc.credential_subject);Verification checks the signature, expiration, and structural validity of the credential.
Next Steps
Section titled “Next Steps”- Your First Credential for a full end-to-end tutorial
- Credential Formats to learn about SD-JWT and mDL
- CLI Reference to do the same from the command line