Skip to content

Commit

Permalink
Merge branch 'main' into feat/shuttle-gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusc93 committed Oct 13, 2023
2 parents 922ad98 + efbc292 commit 98312ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
19 changes: 9 additions & 10 deletions extensions/warp-ipfs/src/store/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,18 @@ pub struct RootDocument {

impl RootDocument {
#[tracing::instrument(skip(self, did))]
pub fn sign(&mut self, did: &DID) -> Result<(), Error> {
let mut root_document = self.clone();
pub fn sign(mut self, did: &DID) -> Result<Self, Error> {
//In case there is a signature already exist
root_document.signature = None;
if root_document.created.is_none() {
root_document.created = Some(Utc::now());
self.signature = None;
if self.created.is_none() {
self.created = Some(Utc::now());
}
root_document.modified = Some(Utc::now());
self.modified = Some(Utc::now());

let bytes = serde_json::to_vec(&root_document)?;
let bytes = serde_json::to_vec(&self)?;
let signature = did.sign(&bytes);
self.signature = Some(bs58::encode(signature).into_string());
Ok(())
Ok(self)
}

#[tracing::instrument(skip(self, ipfs))]
Expand Down Expand Up @@ -254,7 +253,7 @@ impl RootDocument {
.then_some(data.request.to_cid(ipfs).await.ok())
.flatten();

let mut root_document = RootDocument {
let root_document = RootDocument {
identity,
created: Some(data.created),
modified: Some(data.modified),
Expand All @@ -265,7 +264,7 @@ impl RootDocument {
status: None,
signature: None,
};
root_document.sign(&did_kp)?;
let root_document = root_document.sign(&did_kp)?;

Ok(root_document)
}
Expand Down
4 changes: 2 additions & 2 deletions extensions/warp-ipfs/src/store/document/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,10 @@ impl RootDocumentTask {
Ok(document)
}

async fn set_root_document(&mut self, mut document: RootDocument) -> Result<(), Error> {
async fn set_root_document(&mut self, document: RootDocument) -> Result<(), Error> {
let old_cid = self.cid;

document.sign(&self.keypair)?;
let document = document.sign(&self.keypair)?;

//Precautionary check
document.verify(&self.ipfs).await?;
Expand Down

0 comments on commit 98312ff

Please sign in to comment.