Skip to main content

Crate did_bio_core

Crate did_bio_core 

Source
Expand description

Data model and resolution for the did:bio DID method, a W3C DID 1.0 conformant method for biological research data, anchored on the Solana blockchain by the bio-did-registry program.

This crate is the transport free core shared by resolvers, backends, and tooling. It provides the pieces below.

  • BioDid and DidUrl parse identifiers and validate them against the method ABNF (spec Section 4).
  • multikey encodes and decodes Multikey values (Controlled Identifiers v1.0) for Ed25519, X25519, and secp256k1 keys.
  • DidDocument and its related types are the DID document data model (spec Section 5). It includes the post quantum ML-DSA-87 (FIPS 204) verification method type, a JsonWebKey with the AKP key type.
  • DidAccountState is a dependency free deserializer for the registry’s on chain account format.
  • KeyBufferState decodes the staging account through which keys larger than one transaction, such as ML-DSA-87 keys, are uploaded in chunks.
  • resolve_from_account runs steps 6-9 of the resolution algorithm (spec Section 6.2) as a pure function, with the generative fallback. resolve_with, resolve_with_async and resolve_with_async_local drive it through a pluggable RegistryReader, and dereference finds what a DID URL names.
  • Quorum reads through several readers and accepts an account only when a majority agree, against an RPC node that withholds one.
  • find_did_account_address, find_key_buffer_address and find_owned_subject derive PDAs without a Solana SDK dependency, under the pda feature.

§Resolution without a network

A subject is either an Ed25519 key or an owned subject, a program derived address that initialize_owned binds to the wallet that signed for it. BioDid::is_key_subject tells them apart. Every key subject resolves. Without on chain state it yields the deterministic generative document containing the key itself, while an owned subject without an account resolves to notFound.

use did_bio_core::{resolve_from_account, BioDid};

let did: BioDid = "did:bio:devnet:2T6zLFvMx7NJac5qQtiKTaPhMwHLkwKETWjUK1yKv4tc"
    .parse()
    .unwrap();

// Without a registry account the result is the generative document
// with versionId "0".
let resolution = resolve_from_account(&did, None);
let document = resolution.document.unwrap();
assert_eq!(document.id, did.to_string());
assert_eq!(
    document.verification_method[0].id,
    did.default_verification_method_id(),
);
assert_eq!(resolution.document_metadata.version_id.as_deref(), Some("0"));

§Features

  • pda is on by default. It adds PDA derivation (find_did_account_address) and the resolve_with and resolve_with_async drivers, in pure Rust with sha2.
  • verify adds signature verification for Ed25519, ES256K and ML-DSA-87 verification methods via aws-lc-rs.
  • fips is like verify, but binds the FIPS validated AWS-LC module.

The spec is the did:bio DID Method Specification v1.2 (https://github.com/ekayana-labs/bio-did-spec). Section references throughout this crate point there.

Re-exports§

pub use account::DidAccountState;
pub use account::KeyBufferState;
pub use account::KeyType;
pub use account::StoredService;
pub use account::StoredVerificationMethod;
pub use did::is_on_curve;
pub use did::BioDid;
pub use did::DidUrl;
pub use did::Network;
pub use document::AkpPublicJwk;
pub use document::Dereferenced;
pub use document::DidDocument;
pub use document::DidDocumentMetadata;
pub use document::DidResolution;
pub use document::DidResolutionMetadata;
pub use document::ServiceMap;
pub use document::VerificationMaterial;
pub use document::VerificationMethodMap;
pub use document::VerificationRelationship;
pub use error::resolution_error;
pub use error::Error;
pub use pda::find_did_account_address;
pub use pda::find_key_buffer_address;
pub use pda::find_owned_subject;
pub use pda::find_program_address;
pub use pda::try_find_program_address;
pub use quorum::Quorum;
pub use quorum::QuorumError;
pub use resolve::deactivated_document;
pub use resolve::dereference;
pub use resolve::generative_document;
pub use resolve::materialize_document;
pub use resolve::resolve_from_account;
pub use resolve::resolve_str;
pub use resolve::AsyncRegistryReader;
pub use resolve::LocalAsyncRegistryReader;
pub use resolve::RawAccount;
pub use resolve::RegistryReader;
pub use resolve::resolve_with;
pub use resolve::resolve_with_async;
pub use resolve::resolve_with_async_local;

Modules§

account
The bio-did-registry on chain account model (spec Section 5, Section 6) and a dependency free decoder for its Borsh account format.
datetime
Minimal formatting of a Unix timestamp as an XML datetime.
did
Parsing, validation and display of the did:bio identifier (spec Section 4).
document
W3C DID document data model for did:bio (spec Section 5) and the DID Resolution result envelope (spec Section 6.2).
error
Crate error type and W3C DID Resolution error codes.
multikey
Multikey encoding and decoding (Controlled Identifiers v1.0 Section 2.2.2).
pda
Program derived address computation (spec Section 6.2 step 4), without a Solana SDK dependency.
quorum
A registry reader that asks several readers and accepts an answer only when a majority of them agree.
resolve
The did:bio resolution algorithm (spec Section 6.2), decoupled from any transport.
verify
Signature verification for did:bio verification methods, under the verify and fips features.