Skip to content

Commit

Permalink
aligned for new sign and verify_signature functions - will remove one…
Browse files Browse the repository at this point in the history
… unwrap later
  • Loading branch information
arkanoider committed Feb 15, 2025
1 parent 3208b8a commit c9e2930
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ uuid = { version = "1.8.0", features = [
"serde",
] }
reqwest = { version = "0.12.1", features = ["json"] }
# mostro-core = { version = "0.6.25", features = ["sqlx"] }
mostro-core = { git = "https://github.com/MostroP2P/mostro-core", rev = "7e53875cc8370a8da4dcc80b243f9eae630ae345" , features = ["sqlx"] }
mostro-core = { version = "0.6.26", features = ["sqlx"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
config = "0.15.8"
Expand Down
18 changes: 16 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,15 @@ async fn check_trade_index(
.await;
return Err(MostroError::MostroCantDo(CantDoReason::InvalidTradeIndex));
}
let text_message = if let Ok(message) = message_kind.as_json() {
message
} else {
return Err(MostroError::MostroInternalErr(
ServiceError::MessageSerializationError,
));
};

if !message_kind.verify_signature(event.rumor.pubkey, sig) {
if !Message::verify_signature(text_message, event.rumor.pubkey, sig) {
tracing::info!("Invalid signature");
return Err(MostroError::MostroCantDo(CantDoReason::InvalidSignature));
}
Expand Down Expand Up @@ -297,10 +304,17 @@ pub async fn run(

let sender_matches_rumor = event.sender == event.rumor.pubkey;

let text_message = if let Ok(message) = inner_message.as_json() {
message
} else {
tracing::warn!("Error in event verification");
continue;
};

if let Some(sig) = sig {
// Verify signature only if sender and rumor pubkey are different
if !sender_matches_rumor
&& !inner_message.verify_signature(event.rumor.pubkey, sig)
&& !Message::verify_signature(text_message, event.rumor.pubkey, sig)
{
tracing::warn!("Error in event verification");
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ pub async fn send_dm(
let message = Message::from_json(&payload)
.map_err(|_| MostroInternalErr(ServiceError::MessageSerializationError))?;
// We sign the message
let sig = message.get_inner_message_kind().sign(&sender_keys);
let sig = Message::sign(message.as_json().unwrap(), &sender_keys);
// We compose the content
let content = (message, sig);
let content = serde_json::to_string(&content)
Expand Down

0 comments on commit c9e2930

Please sign in to comment.