diff --git a/extensions/warp-ipfs/src/store/document/root.rs b/extensions/warp-ipfs/src/store/document/root.rs index b05f475d6..69fa97965 100644 --- a/extensions/warp-ipfs/src/store/document/root.rs +++ b/extensions/warp-ipfs/src/store/document/root.rs @@ -12,6 +12,7 @@ use warp::{crypto::DID, error::Error}; use crate::store::{identity::Request, keystore::Keystore, VecExt}; use super::{ + identity::IdentityDocument, utils::{GetLocalDag, ToCid}, RootDocument, }; @@ -25,6 +26,9 @@ pub enum RootDocumentCommand { document: RootDocument, response: oneshot::Sender>, }, + Identity { + response: oneshot::Sender>, + }, AddFriend { did: DID, response: oneshot::Sender>, @@ -150,6 +154,16 @@ impl RootDocumentMap { rx.await.map_err(anyhow::Error::from)? } + pub async fn identity(&self) -> Result { + let (tx, rx) = oneshot::channel(); + let _ = self + .tx + .clone() + .send(RootDocumentCommand::Identity { response: tx }) + .await; + rx.await.map_err(anyhow::Error::from)? + } + pub async fn add_friend(&self, did: &DID) -> Result<(), Error> { let (tx, rx) = oneshot::channel(); let _ = self @@ -349,6 +363,9 @@ impl RootDocumentTask { RootDocumentCommand::Set { document, response } => { let _ = response.send(self.set_root_document(document).await); } + RootDocumentCommand::Identity { response } => { + let _ = response.send(self.identity().await); + } RootDocumentCommand::AddFriend { did, response } => { let _ = response.send(self.add_friend(did).await); } @@ -411,6 +428,15 @@ impl RootDocumentTask { Ok(document) } + async fn identity(&self) -> Result { + let root = self.get_root_document().await?; + let path = IpfsPath::from(root.identity); + let document: IdentityDocument = path.get_local_dag(&self.ipfs).await?; + document.verify()?; + + Ok(document) + } + async fn set_root_document(&mut self, document: RootDocument) -> Result<(), Error> { let old_cid = self.cid;