diff --git a/Cargo.lock b/Cargo.lock index fc0782b7..d3a545b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8689,6 +8689,7 @@ dependencies = [ name = "serai-message-queue" version = "0.1.0" dependencies = [ + "bincode", "ciphersuite", "flexible-transcript", "hex", diff --git a/message-queue/Cargo.toml b/message-queue/Cargo.toml index cadefb37..9f366887 100644 --- a/message-queue/Cargo.toml +++ b/message-queue/Cargo.toml @@ -20,6 +20,7 @@ serde = { version = "1", features = ["derive"] } # Encoders hex = "0.4" +bincode = "1" serde_json = "1" # Cryptography diff --git a/message-queue/src/main.rs b/message-queue/src/main.rs index a94fc5d2..aa059de5 100644 --- a/message-queue/src/main.rs +++ b/message-queue/src/main.rs @@ -27,13 +27,13 @@ lazy_static::lazy_static! { fn queue_message(meta: Metadata, msg: Vec, sig: SchnorrSignature) { { let from = (*KEYS).read().unwrap()[&meta.from]; - assert!(sig.verify(from, message_challenge(from, &msg, sig.R))); + assert!(sig.verify(from, message_challenge(from, meta.to, &meta.intent, &msg, sig.R))); } // Assert one, and only one of these, is the coordinator assert!(matches!(meta.from, Service::Coordinator) ^ matches!(meta.to, Service::Coordinator)); - // TODO: Verify the from_id hasn't been prior seen + // TODO: Verify the intent hasn't been prior seen // Queue it (*QUEUES).read().unwrap()[&meta.to].write().unwrap().queue_message(QueuedMessage { diff --git a/message-queue/src/messages.rs b/message-queue/src/messages.rs index 87bb54c1..ce26aed8 100644 --- a/message-queue/src/messages.rs +++ b/message-queue/src/messages.rs @@ -18,21 +18,26 @@ pub struct QueuedMessage { pub sig: Vec, } -#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize)] +#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] pub struct Metadata { pub from: Service, pub to: Service, - pub from_id: u64, + pub intent: Vec, } pub fn message_challenge( from: ::G, + to: Service, + intent: &[u8], msg: &[u8], nonce: ::G, ) -> ::F { let mut transcript = RecommendedTranscript::new(b"Serai Message Queue v0.1"); - transcript.domain_separate(b"message"); + transcript.domain_separate(b"metadata"); transcript.append_message(b"from", from.to_bytes()); + transcript.append_message(b"to", bincode::serialize(&to).unwrap()); + transcript.append_message(b"intent", intent); + transcript.domain_separate(b"message"); transcript.append_message(b"msg", msg); transcript.domain_separate(b"signature"); transcript.append_message(b"nonce", nonce.to_bytes());