OpenAgentID documentation
Source referencesRust module referenceoas-document

oas-document · builder

Declared module signatures, types, configuration, and source documentation.

Source: oas/oas/oas-document/src/builder.rs. SHA-256: 4e2c69ae88dc0a619072d629a1b848631be7c9b191d768d3bcd3783d78860646.

This source reference follows declared modules and preserves feature attributes. It includes public declarations and implementation methods in those modules. Private-module exports and trait resolution still require the compiler; not every declaration is a crate-root import. Function bodies and constant values are omitted. Source comments describe their implementation context and are not a production deployment claim.

builder::DocumentBuilder

Builder for constructing [OasDocument] instances.

Provides an ergonomic API for building OAS Identity Documents with proper defaults and validation.

Examples

use oas_document::builder::DocumentBuilder;
use oas_document::conformance::ConformanceLevel;
use oas_crypto::keypair::OasKeyPair;

let keypair = OasKeyPair::generate();
let doc = DocumentBuilder::new("did:oas:test:hmr:alice", "hmr")
    .controller("did:oas:test:hmr:alice")
    .conformance_level(ConformanceLevel::L1)
    .add_verification_method(&keypair)
    .name("Alice")
    .build_and_sign(&keypair, "2026-01-15T00:00:00Z")
    .unwrap();
assert_eq!(doc.kind, "hmr");
assert!(doc.proof.is_some());
pub struct DocumentBuilder {

}

Source line: 48.

builder::DocumentBuilder::new

Creates a new builder with the given DID and kind.

Arguments

  • id - The did:oas identifier.
  • kind - The entity kind string (e.g., "hmr", "agent").
pub fn new(id: &str, kind: &str) -> Self;

Source line: 84.

builder::DocumentBuilder::controller

Sets the controller DID.

pub fn controller(mut self, controller: &str) -> Self;

Source line: 115.

builder::DocumentBuilder::add_verification_method

Adds a verification method from a keypair.

Automatically adds the key to authentication, assertionMethod, capabilityInvocation, and capabilityDelegation relationships.

pub fn add_verification_method(mut self, keypair: &OasKeyPair) -> Self;

Source line: 124.

builder::DocumentBuilder::conformance_level

Sets the conformance level.

pub fn conformance_level(mut self, level: ConformanceLevel) -> Self;

Source line: 137.

builder::DocumentBuilder::name

Sets the human-readable name.

pub fn name(mut self, name: &str) -> Self;

Source line: 143.

builder::DocumentBuilder::description

Sets the human-readable description.

pub fn description(mut self, description: &str) -> Self;

Source line: 149.

builder::DocumentBuilder::lineage

Sets the lineage section.

pub fn lineage(mut self, lineage: LineageSection) -> Self;

Source line: 155.

builder::DocumentBuilder::governance

Sets the governance section (ENR entities only).

pub fn governance(mut self, governance: GovernanceSection) -> Self;

Source line: 161.

builder::DocumentBuilder::lifecycle_status

Sets the lifecycle status.

pub fn lifecycle_status(mut self, status: LifecycleStatus) -> Self;

Source line: 167.

builder::DocumentBuilder::sequence

Sets the sequence number.

pub fn sequence(mut self, seq: u64) -> Self;

Source line: 173.

builder::DocumentBuilder::add_service

Adds a service endpoint.

pub fn add_service(mut self, service: ServiceEndpoint) -> Self;

Source line: 179.

builder::DocumentBuilder::profile

Sets the profile section (§5.8).

pub fn profile(mut self, profile: ProfileSection) -> Self;

Source line: 185.

builder::DocumentBuilder::contact

Sets the contact directory (§5.9).

pub fn contact(mut self, contact: ContactSection) -> Self;

Source line: 191.

builder::DocumentBuilder::calendar

Sets the calendar & scheduling section (§5.10).

pub fn calendar(mut self, calendar: CalendarSection) -> Self;

Source line: 197.

builder::DocumentBuilder::operational

Sets the operational specification (§5.11).

pub fn operational(mut self, operational: OperationalSection) -> Self;

Source line: 203.

builder::DocumentBuilder::pricing

Sets the pricing & economics section (§5.12).

pub fn pricing(mut self, pricing: PricingSection) -> Self;

Source line: 209.

builder::DocumentBuilder::interoperability

Sets the interoperability section (§5.13).

pub fn interoperability(mut self, interop: InteroperabilitySection) -> Self;

Source line: 215.

builder::DocumentBuilder::reputation

Sets the reputation summary (§5.14).

pub fn reputation(mut self, reputation: ReputationSection) -> Self;

Source line: 221.

builder::DocumentBuilder::compliance

Sets the compliance & jurisdiction section (§5.15).

pub fn compliance(mut self, compliance: ComplianceSection) -> Self;

Source line: 227.

builder::DocumentBuilder::relationships

Sets the relationships & affiliations section (§5.16).

pub fn relationships(mut self, relationships: RelationshipsSection) -> Self;

Source line: 233.

builder::DocumentBuilder::build_and_sign

Builds the document and signs it.

Arguments

  • signing_keypair - The keypair to sign the document with.
  • created - ISO 8601 timestamp for both document creation and proof.

Returns

A complete, signed [OasDocument].

Errors

Returns [DocumentError] if signing fails.

pub fn build_and_sign(
        self,
        signing_keypair: &OasKeyPair,
        created: &str,
    ) -> Result<OasDocument, DocumentError>;

Source line: 252.

On this page