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_did::{generate_identity, Document};
let id = generate_identity(
"k51qzi5uqu5dj9807pbuod1pplf0vxh8m4lfy3ewl9qbm2s8dsf9ugdf9gedhr"
).unwrap();
// Verify the signature
id.document.verify().unwrap();
// Validate structural correctness
id.document.validate().unwrap();
// Round-trip through JSON
let json = id.document.marshal().unwrap();
let restored = Document::unmarshal(&json).unwrap();
assert_eq!(id.document, restored);
// Round-trip through CBOR
let cbor = id.document.to_cbor().unwrap();
let restored = Document::from_cbor(&cbor).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 dag-cbor/dag-json
round-tripping.
use std::collections::BTreeMap;
use ipld_core::ipld::Ipld;
use ma_did::{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) -> Document
pub fn to_cbor(&self) -> Result<Vec<u8>, MaError>
pub fn from_cbor(bytes: &[u8]) -> Result<Document, MaError>
pub fn marshal(&self) -> Result<String, MaError>
pub fn unmarshal(s: &str) -> Result<Document, MaError>
pub fn add_controller( &mut self, controller: impl Into<String>, ) -> Result<(), MaError>
pub fn add_verification_method( &mut self, method: VerificationMethod, ) -> Result<(), MaError>
pub fn get_verification_method_by_id( &self, method_id: &str, ) -> Result<&VerificationMethod, MaError>
pub fn set_identity( &mut self, identity: impl Into<String>, ) -> Result<(), MaError>
pub fn assertion_method_public_key(&self) -> Result<VerifyingKey, MaError>
pub fn key_agreement_public_key_bytes(&self) -> Result<[u8; 32], MaError>
pub fn payload_document(&self) -> Document
pub fn payload_bytes(&self) -> Result<Vec<u8>, MaError>
pub fn payload_hash(&self) -> Result<[u8; 32], MaError>
pub fn sign( &mut self, signing_key: &SigningKey, verification_method: &VerificationMethod, ) -> Result<(), MaError>
pub fn verify(&self) -> Result<(), MaError>
pub fn validate(&self) -> Result<(), MaError>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Document
impl<'de> Deserialize<'de> for Document
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Document, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Document, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for Document
impl Serialize for Document
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
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
Mutably borrows from an owned value. Read more
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
Compare self to
key and return true if they are equal.