Skip to content

Commit

Permalink
chore: Added RootDocumentMap::identity
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusc93 committed Oct 22, 2023
1 parent 7d09a0b commit 9c0da71
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions extensions/warp-ipfs/src/store/document/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -25,6 +26,9 @@ pub enum RootDocumentCommand {
document: RootDocument,
response: oneshot::Sender<Result<(), Error>>,
},
Identity {
response: oneshot::Sender<Result<IdentityDocument, Error>>,
},
AddFriend {
did: DID,
response: oneshot::Sender<Result<(), Error>>,
Expand Down Expand Up @@ -150,6 +154,16 @@ impl RootDocumentMap {
rx.await.map_err(anyhow::Error::from)?
}

pub async fn identity(&self) -> Result<IdentityDocument, Error> {
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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -411,6 +428,15 @@ impl RootDocumentTask {
Ok(document)
}

async fn identity(&self) -> Result<IdentityDocument, Error> {
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;

Expand Down

0 comments on commit 9c0da71

Please sign in to comment.