Skip to content

Commit

Permalink
renaming Signable trait and method names
Browse files Browse the repository at this point in the history
  • Loading branch information
distractedm1nd committed Jul 20, 2024
1 parent 2f223ac commit 58a1e67
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/da/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
error::{DAResult, DeimosResult, GeneralError},
utils::Signable,
utils::SignedContent,
zk_snark::{Bls12Proof, VerifyingKey},
};
use async_trait::async_trait;
Expand All @@ -22,7 +22,7 @@ pub struct EpochJson {
pub signature: Option<String>,
}

impl Signable for EpochJson {
impl SignedContent for EpochJson {
fn get_signature(&self) -> DeimosResult<Signature> {
match &self.signature {
Some(signature) => Signature::from_str(signature)
Expand All @@ -31,7 +31,7 @@ impl Signable for EpochJson {
}
}

fn get_content_to_sign(&self) -> DeimosResult<String> {
fn get_plaintext(&self) -> DeimosResult<String> {
let mut copy = self.clone();
copy.signature = None;
serde_json::to_string(&copy).map_err(|e| GeneralError::EncodingError(e.to_string()).into())
Expand Down
8 changes: 4 additions & 4 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ pub fn validate_epoch(
Ok(proof)
}

pub trait Signable {
pub trait SignedContent {
fn get_signature(&self) -> DeimosResult<Signature>;
fn get_content_to_sign(&self) -> DeimosResult<String>;
fn get_plaintext(&self) -> DeimosResult<String>;
fn get_public_key(&self) -> DeimosResult<String>;
}

// verifies the signature of a given signable item and returns the content of the item if the signature is valid
pub fn verify_signature<T: Signable>(
pub fn verify_signature<T: SignedContent>(
item: &T,
optional_public_key: Option<String>,
) -> DeimosResult<String> {
Expand All @@ -129,7 +129,7 @@ pub fn verify_signature<T: Signable>(
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) {
Expand Down
6 changes: 3 additions & 3 deletions src/webserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
error::{DeimosResult, GeneralError},
node_types::sequencer::Sequencer,
storage::{ChainEntry, IncomingEntry},
utils::Signable,
utils::SignedContent,
};
use axum::{
extract::State,
Expand Down Expand Up @@ -73,13 +73,13 @@ pub struct UserKeyResponse {
)]
struct ApiDoc;

impl Signable for UpdateEntryJson {
impl SignedContent for UpdateEntryJson {
fn get_signature(&self) -> DeimosResult<Signature> {
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<String> {
fn get_plaintext(&self) -> DeimosResult<String> {
serde_json::to_string(&self.incoming_entry)
.map_err(|e| GeneralError::DecodingError(e.to_string()).into())
}
Expand Down

0 comments on commit 58a1e67

Please sign in to comment.