From 078d2a04202e9645d1982158e974114585fb9625 Mon Sep 17 00:00:00 2001 From: NicolasCantu Date: Thu, 17 Oct 2024 14:30:09 +0200 Subject: [PATCH] Ignore messages that are signed by ourselves --- src/api.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/api.rs b/src/api.rs index 0961485..b831153 100644 --- a/src/api.rs +++ b/src/api.rs @@ -508,7 +508,13 @@ fn handle_transaction( tx: &Transaction, tweak_data: PublicKey, ) -> AnyhowResult { - let b_scan = lock_local_device()?.get_wallet().get_client().get_scan_key(); + let b_scan: SecretKey; + let local_address: SilentPaymentAddress; + { + let local_device = lock_local_device()?; + b_scan = local_device.get_wallet().get_client().get_scan_key(); + local_address = local_device.get_wallet().get_client().get_receiving_address().try_into()?; + } let op_return: Vec<&sdk_common::sp_client::bitcoin::TxOut> = tx .output @@ -554,7 +560,7 @@ fn handle_transaction( }) { // Calling this check that the prd we found check with the hashed commitment in transaction // We also check the signed proof that is included in the prd - let prd = Prd::extract_from_message_with_commitment(&plaintext, &commitment)?; + let prd = Prd::extract_from_message_with_commitment(&plaintext, local_address, &commitment)?; // for now the previous method doesn't error if proof is missing, // We must define if there are cases where a valid prd doesn't have proof @@ -807,6 +813,8 @@ fn confirm_prd(prd: Prd, shared_secret: &AnkSharedSecretHash) -> AnyhowResult> ) -> anyhow::Result, AnkSharedSecretHash)>> { let nonce = Nonce::from_slice(&cipher[..12]); + let local_address: SilentPaymentAddress = lock_local_device()?.get_wallet().get_client().get_receiving_address().try_into()?; for message in messages.iter_mut() { for shared_secret in message.shared_secrets.iter() { @@ -863,7 +872,7 @@ fn decrypt_with_cached_messages( )?; // A message matched against a new transaction must be a prd // We just check the commitment while we're at it - let _ = Prd::extract_from_message_with_commitment(&plain, &commitment)?; + let _ = Prd::extract_from_message_with_commitment(&plain, local_address, &commitment)?; // Update the message status message.status = CachedMessageStatus::NoStatus; message.shared_secrets = vec![]; // this way we won't check it again @@ -907,8 +916,9 @@ fn handle_prd( plain: &[u8], new_shared_secret: Option, ) -> AnyhowResult { + let local_address: SilentPaymentAddress = lock_local_device()?.get_wallet().get_client().get_receiving_address().try_into()?; // We already checked the commitment if any - let prd = Prd::extract_from_message(plain)?; + let prd = Prd::extract_from_message(plain, local_address)?; debug!("found prd: {:#?}", prd);