pub struct Document {
pub context: Vec<String>,
pub id: String,
pub controller: Vec<String>,
pub verification_method: Vec<VerificationMethod>,
pub assertion_method: Vec<String>,
pub key_agreement: Vec<String>,
pub proof: Proof,
pub identity: Option<String>,
pub created_at: String,
pub updated_at: String,
pub ma: Option<Ipld>,
}Expand description
A did:ma: DID document.
Contains verification methods, proof, and optional extension data.
Documents are signed with Ed25519 over a BLAKE3 hash of the dag-cbor-serialized
payload (all fields except proof).
§Examples
use ma_core::{generate_identity_from_secret, Document};
let id = generate_identity_from_secret([7u8; 32]).unwrap();
// Verify the signature
id.document.verify().unwrap();
// Validate structural correctness
id.document.validate().unwrap();
// Round-trip through the canonical wire format
let bytes = id.document.encode().unwrap();
let restored = Document::decode(&bytes).unwrap();
assert_eq!(id.document, restored);§Extension namespace
The ma field is an opaque IPLD value for application-defined
extension data. did-ma does not interpret or validate its contents.
Using Ipld gives native support for CID links and canonical DAG-CBOR
round-tripping.
use std::collections::BTreeMap;
use ipld_core::ipld::Ipld;
use ma_core::{Did, Document};
let did = Did::new_url("k51qzi5uqu5dj9807pbuod1pplf0vxh8m4lfy3ewl9qbm2s8dsf9ugdf9gedhr", None::<String>).unwrap();
let mut doc = Document::new(&did, &did);
let ma = Ipld::Map(BTreeMap::from([
("type".into(), Ipld::String("agent".into())),
("services".into(), Ipld::Map(BTreeMap::new())),
]));
doc.set_ma(ma);
assert!(doc.ma.is_some());
doc.clear_ma();
assert!(doc.ma.is_none());Fields§
§context: Vec<String>§id: String§controller: Vec<String>§verification_method: Vec<VerificationMethod>§assertion_method: Vec<String>§key_agreement: Vec<String>§proof: Proof§identity: Option<String>§created_at: String§updated_at: String§ma: Option<Ipld>Implementations§
Source§impl Document
impl Document
pub fn new(identity: &Did, controller: &Did) -> Self
Sourcepub fn set_ma(&mut self, ma: Ipld)
pub fn set_ma(&mut self, ma: Ipld)
Set the opaque ma extension namespace from a raw Ipld value.
For the ergonomic, structured way to populate this field, prefer
Document::set_ma_extension with a MaExtension builder.
Sourcepub fn set_ma_extension(&mut self, ext: MaExtension)
pub fn set_ma_extension(&mut self, ext: MaExtension)
Set the ma extension field from a MaExtension builder.
This is the recommended way to populate the ma: namespace. Build an
extension with MaExtension, then call this method before signing
the document. An empty builder (or one whose MaExtension::build
returns Ipld::Null) clears the field.
§Example
let ma = endpoint.ma_extension().kind("world");
document.set_ma_extension(ma);
document.sign(&signing_key, &assertion_vm)?;Sourcepub fn encode(&self) -> Result<Vec<u8>>
pub fn encode(&self) -> Result<Vec<u8>>
Encode the DID document to its canonical wire format.
DID documents are always serialized as DAG-CBOR. Use this for transport, storage, hashing, signing, and IPFS/IPNS publication.
Sourcepub fn decode(bytes: &[u8]) -> Result<Self>
pub fn decode(bytes: &[u8]) -> Result<Self>
Decode a DID document from its canonical wire format.
DID documents are always encoded as DAG-CBOR.
pub fn add_controller(&mut self, controller: impl Into<String>) -> Result<()>
pub fn add_verification_method( &mut self, method: VerificationMethod, ) -> Result<()>
pub fn get_verification_method_by_id( &self, method_id: &str, ) -> Result<&VerificationMethod>
pub fn set_identity(&mut self, identity: impl Into<String>) -> Result<()>
pub fn assertion_method_public_key(&self) -> Result<VerifyingKey>
pub fn key_agreement_public_key_bytes(&self) -> Result<[u8; 32]>
pub fn payload_document(&self) -> Self
pub fn payload_bytes(&self) -> Result<Vec<u8>>
pub fn payload_hash(&self) -> Result<[u8; 32]>
pub fn sign( &mut self, signing_key: &SigningKey, verification_method: &VerificationMethod, ) -> Result<()>
pub fn verify(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Document
impl<'de> Deserialize<'de> for Document
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Document
impl StructuralPartialEq for Document
Auto Trait Implementations§
impl Freeze for Document
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnsafeUnpin for Document
impl UnwindSafe for Document
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more