From e44c36847795b2dcc567f8a1a9b09ea1a90ea141 Mon Sep 17 00:00:00 2001 From: Artem Gureev Date: Tue, 7 Jul 2026 18:06:46 +0000 Subject: [PATCH] fix(wallet): locate self-sent notes by nullifier --- lez/wallet/src/lib.rs | 9 ++++++++- lez/wallet/src/storage/key_chain.rs | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lez/wallet/src/lib.rs b/lez/wallet/src/lib.rs index 18817c0a..f719a0a6 100644 --- a/lez/wallet/src/lib.rs +++ b/lez/wallet/src/lib.rs @@ -556,9 +556,16 @@ impl WalletCore { "Decode mask has {} entries but the transaction has {note_count} notes", acc_decode_mask.len(), ); - for (output_index, acc_decode_data) in acc_decode_mask.iter().enumerate() { + for acc_decode_data in acc_decode_mask { match acc_decode_data { AccDecodeData::Decode(secret, acc_account_id) => { + let Some(output_index) = self + .storage + .key_chain() + .locate_spend(*acc_account_id, &tx.message) + else { + continue; + }; let acc_ead = tx.message.encrypted_private_post_states[output_index].clone(); let (kind, res_acc) = lee_core::EncryptionScheme::decrypt( diff --git a/lez/wallet/src/storage/key_chain.rs b/lez/wallet/src/storage/key_chain.rs index 44d49787..78f32847 100644 --- a/lez/wallet/src/storage/key_chain.rs +++ b/lez/wallet/src/storage/key_chain.rs @@ -453,6 +453,21 @@ impl UserKeyChain { Some(new_nullifier) } + #[must_use] + pub fn locate_spend(&self, account_id: AccountId, message: &Message) -> Option { + let init = Nullifier::for_account_initialization(&account_id); + let update = self.private_account(account_id).map(|acc| { + Nullifier::for_account_update( + &Commitment::new(&account_id, acc.account), + &acc.key_chain.private_key_holder.nullifier_secret_key, + ) + }); + message + .new_nullifiers + .iter() + .position(|(nullifier, _)| *nullifier == init || Some(nullifier) == update.as_ref()) + } + pub fn add_imported_public_account(&mut self, private_key: lee::PrivateKey) { let account_id = AccountId::from(&lee::PublicKey::new_from_private_key(&private_key));