Skip to content

Quick Start

This guide walks you through key generation, DID creation, credential issuance, and verification using BaseID’s Rust crates.

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.

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.

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.

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.