From 58a1e674bc2f1707f996a23e215bb41a98c2b3e9 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sat, 20 Jul 2024 13:43:10 +0200 Subject: [PATCH] renaming Signable trait and method names --- src/da/mod.rs | 6 +++--- src/utils.rs | 8 ++++---- src/webserver.rs | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/da/mod.rs b/src/da/mod.rs index 25d98b96..e789a476 100644 --- a/src/da/mod.rs +++ b/src/da/mod.rs @@ -1,6 +1,6 @@ use crate::{ error::{DAResult, DeimosResult, GeneralError}, - utils::Signable, + utils::SignedContent, zk_snark::{Bls12Proof, VerifyingKey}, }; use async_trait::async_trait; @@ -22,7 +22,7 @@ pub struct EpochJson { pub signature: Option, } -impl Signable for EpochJson { +impl SignedContent for EpochJson { fn get_signature(&self) -> DeimosResult { match &self.signature { Some(signature) => Signature::from_str(signature) @@ -31,7 +31,7 @@ impl Signable for EpochJson { } } - fn get_content_to_sign(&self) -> DeimosResult { + fn get_plaintext(&self) -> DeimosResult { let mut copy = self.clone(); copy.signature = None; serde_json::to_string(©).map_err(|e| GeneralError::EncodingError(e.to_string()).into()) diff --git a/src/utils.rs b/src/utils.rs index 38d19f41..3d0749bf 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -110,14 +110,14 @@ pub fn validate_epoch( Ok(proof) } -pub trait Signable { +pub trait SignedContent { fn get_signature(&self) -> DeimosResult; - fn get_content_to_sign(&self) -> DeimosResult; + fn get_plaintext(&self) -> DeimosResult; fn get_public_key(&self) -> DeimosResult; } // verifies the signature of a given signable item and returns the content of the item if the signature is valid -pub fn verify_signature( +pub fn verify_signature( item: &T, optional_public_key: Option, ) -> DeimosResult { @@ -129,7 +129,7 @@ pub fn verify_signature( let public_key = decode_public_key(&public_key_str) .map_err(|_| DeimosError::General(GeneralError::InvalidPublicKey))?; - let content = item.get_content_to_sign()?; + let content = item.get_plaintext()?; let signature = item.get_signature()?; match public_key.verify(content.as_bytes(), &signature) { diff --git a/src/webserver.rs b/src/webserver.rs index a8938d7c..ae02c226 100644 --- a/src/webserver.rs +++ b/src/webserver.rs @@ -3,7 +3,7 @@ use crate::{ error::{DeimosResult, GeneralError}, node_types::sequencer::Sequencer, storage::{ChainEntry, IncomingEntry}, - utils::Signable, + utils::SignedContent, }; use axum::{ extract::State, @@ -73,13 +73,13 @@ pub struct UserKeyResponse { )] struct ApiDoc; -impl Signable for UpdateEntryJson { +impl SignedContent for UpdateEntryJson { fn get_signature(&self) -> DeimosResult { Signature::from_str(self.signed_incoming_entry.as_str()) .map_err(|e| GeneralError::ParsingError(format!("signature: {}", e)).into()) } - fn get_content_to_sign(&self) -> DeimosResult { + fn get_plaintext(&self) -> DeimosResult { serde_json::to_string(&self.incoming_entry) .map_err(|e| GeneralError::DecodingError(e.to_string()).into()) }