pub struct CredentialBuilder {
issuer: Option<String>,
subject: Option<String>,
credential_type: Option<AgentCredentialType>,
claims: HashMap<String, Value>,
expiration: Option<DateTime<Utc>>,
}Expand description
Builder for creating Verifiable Credentials.
Uses the builder pattern to construct well-formed credentials with required and optional fields.
§Example
let credential = CredentialBuilder::new()
.issuer("did:web:cellstate.batterypack.dev")
.subject("did:web:cellstate.batterypack.dev:agents:00000000-0000-0000-0000-000000000000")
.credential_type(AgentCredentialType::Identity)
.claim("name", serde_json::json!("test-agent"))
.build()
.expect("credential should build");Fields§
§issuer: Option<String>§subject: Option<String>§credential_type: Option<AgentCredentialType>§claims: HashMap<String, Value>§expiration: Option<DateTime<Utc>>Implementations§
Source§impl CredentialBuilder
impl CredentialBuilder
Sourcepub fn credential_type(self, cred_type: AgentCredentialType) -> Self
pub fn credential_type(self, cred_type: AgentCredentialType) -> Self
Set the credential type.
Sourcepub fn expiration(self, expires: DateTime<Utc>) -> Self
pub fn expiration(self, expires: DateTime<Utc>) -> Self
Set the expiration date.
Sourcepub fn build(self) -> Result<VerifiableCredential, CredentialError>
pub fn build(self) -> Result<VerifiableCredential, CredentialError>
Build the Verifiable Credential.
Returns Err if required fields (issuer, subject) are missing.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CredentialBuilder
impl RefUnwindSafe for CredentialBuilder
impl Send for CredentialBuilder
impl Sync for CredentialBuilder
impl Unpin for CredentialBuilder
impl UnwindSafe for CredentialBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more