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
impl DocumentBuilder
Sourcepub fn new(id: &str, kind: &str) -> Self
pub fn new(id: &str, kind: &str) -> Self
Creates a new builder with the given DID and kind.
§Arguments
id- Thedid:oasidentifier.kind- The entity kind string (e.g.,"hmr","agent").
Sourcepub fn controller(self, controller: &str) -> Self
pub fn controller(self, controller: &str) -> Self
Sets the controller DID.
Sourcepub fn add_verification_method(self, keypair: &OasKeyPair) -> Self
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.
Sourcepub fn conformance_level(self, level: ConformanceLevel) -> Self
pub fn conformance_level(self, level: ConformanceLevel) -> Self
Sets the conformance level.
Sourcepub fn description(self, description: &str) -> Self
pub fn description(self, description: &str) -> Self
Sets the human-readable description.
Sourcepub fn lineage(self, lineage: LineageSection) -> Self
pub fn lineage(self, lineage: LineageSection) -> Self
Sets the lineage section.
Sourcepub fn governance(self, governance: GovernanceSection) -> Self
pub fn governance(self, governance: GovernanceSection) -> Self
Sets the governance section (ENR entities only).
Sourcepub fn lifecycle_status(self, status: LifecycleStatus) -> Self
pub fn lifecycle_status(self, status: LifecycleStatus) -> Self
Sets the lifecycle status.
Sourcepub fn add_service(self, service: ServiceEndpoint) -> Self
pub fn add_service(self, service: ServiceEndpoint) -> Self
Adds a service endpoint.
Sourcepub fn profile(self, profile: ProfileSection) -> Self
pub fn profile(self, profile: ProfileSection) -> Self
Sets the profile section (§5.8).
Sourcepub fn contact(self, contact: ContactSection) -> Self
pub fn contact(self, contact: ContactSection) -> Self
Sets the contact directory (§5.9).
Sourcepub fn calendar(self, calendar: CalendarSection) -> Self
pub fn calendar(self, calendar: CalendarSection) -> Self
Sets the calendar & scheduling section (§5.10).
Sourcepub fn operational(self, operational: OperationalSection) -> Self
pub fn operational(self, operational: OperationalSection) -> Self
Sets the operational specification (§5.11).
Sourcepub fn pricing(self, pricing: PricingSection) -> Self
pub fn pricing(self, pricing: PricingSection) -> Self
Sets the pricing & economics section (§5.12).
Sourcepub fn interoperability(self, interop: InteroperabilitySection) -> Self
pub fn interoperability(self, interop: InteroperabilitySection) -> Self
Sets the interoperability section (§5.13).
Sourcepub fn reputation(self, reputation: ReputationSection) -> Self
pub fn reputation(self, reputation: ReputationSection) -> Self
Sets the reputation summary (§5.14).
Sourcepub fn compliance(self, compliance: ComplianceSection) -> Self
pub fn compliance(self, compliance: ComplianceSection) -> Self
Sets the compliance & jurisdiction section (§5.15).
Sourcepub fn relationships(self, relationships: RelationshipsSection) -> Self
pub fn relationships(self, relationships: RelationshipsSection) -> Self
Sets the relationships & affiliations section (§5.16).
Sourcepub fn build_and_sign(
self,
signing_keypair: &OasKeyPair,
created: &str,
) -> Result<OasDocument, DocumentError>
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.