From 41743ab3e75bd5aa1c11ba329bbc7687bb5db0cc Mon Sep 17 00:00:00 2001 From: Sosthene Date: Tue, 4 Jun 2024 11:56:32 +0200 Subject: [PATCH] Replace CipherMessage with Prd and put data in Pcd --- src/network.rs | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/network.rs b/src/network.rs index 586bdb1..3a4534a 100644 --- a/src/network.rs +++ b/src/network.rs @@ -109,18 +109,36 @@ impl NewTxMessage { } } -#[derive(Debug, Serialize, Deserialize, Tsify)] +#[derive(Debug, Serialize, Deserialize, Clone, Tsify)] #[tsify(into_wasm_abi, from_wasm_abi)] -pub struct CipherMessage { +pub struct Prd { pub sender: String, + pub keys: Vec, + pub pcd_commitment: String, // hash of the pcd + pub error: Option, +} + +impl Prd { + pub fn new(sender: String, keys: Vec, pcd_commitment: String) -> Self { + Self { + sender, + keys, + pcd_commitment, + error: None, + } + } +} + +#[derive(Debug, Serialize, Deserialize, Clone, Tsify)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct Pcd { pub message: String, pub error: Option, } -impl CipherMessage { - pub fn new(sender: String, message: String) -> Self { +impl Pcd { + pub fn new(message: String) -> Self { Self { - sender, message, error: None, } @@ -199,6 +217,11 @@ pub struct CachedMessage { pub recipient: Option, // Never None when message sent pub shared_secret: Option, // Never None when message sent pub key: Option, // Never None when message sent + pub prd_cipher: Option, // When we receive message we can't decrypt we only have this and commited_in_tx + pub prd: Option, // Never None when message sent + pub pcd_cipher: Option, + pub pcd: Option, // Never None when message sent + pub pcd_commitment: Option, pub confirmed_by: Option, // If this None, Sender keeps sending pub timestamp: u64, pub error: Option, @@ -237,7 +260,7 @@ impl CachedMessage { } pub fn try_decrypt_with_shared_secret(&self, shared_secret: [u8; 32]) -> Result> { - if self.ciphertext.is_none() || self.shared_secret.is_some() { + if self.prd_cipher.is_none() || self.shared_secret.is_some() { return Err(Error::msg( "Can't try decrypt this message, ciphertext is none or shared_secret already found", ));