Skip to main content

DocumentBuilder

Struct DocumentBuilder 

Source
pub struct DocumentBuilder { /* private fields */ }
Expand description

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());

Implementations§

Source§

impl DocumentBuilder

Source

pub fn new(id: &str, kind: &str) -> Self

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").
Source

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

Sets the controller DID.

Source

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

Adds a verification method from a keypair.

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

Source

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

Sets the conformance level.

Source

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

Sets the human-readable name.

Source

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

Sets the human-readable description.

Source

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

Sets the lineage section.

Source

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

Sets the governance section (ENR entities only).

Source

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

Sets the lifecycle status.

Source

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

Sets the sequence number.

Source

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

Adds a service endpoint.

Source

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

Sets the profile section (§5.8).

Source

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

Sets the contact directory (§5.9).

Source

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

Sets the calendar & scheduling section (§5.10).

Source

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

Sets the operational specification (§5.11).

Source

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

Sets the pricing & economics section (§5.12).

Source

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

Sets the interoperability section (§5.13).

Source

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

Sets the reputation summary (§5.14).

Source

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

Sets the compliance & jurisdiction section (§5.15).

Source

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

Sets the relationships & affiliations section (§5.16).

Source

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

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V