feat: change wallet decode functionality

This commit is contained in:
agureev 2026-06-22 23:18:39 +04:00
parent a5cb2e484b
commit 64be428d7f

View File

@ -514,21 +514,25 @@ impl WalletCore {
tx: &lee::privacy_preserving_transaction::PrivacyPreservingTransaction, tx: &lee::privacy_preserving_transaction::PrivacyPreservingTransaction,
acc_decode_mask: &[AccDecodeData], acc_decode_mask: &[AccDecodeData],
) -> Result<()> { ) -> Result<()> {
for (output_index, acc_decode_data) in acc_decode_mask.iter().enumerate() { for acc_decode_data in acc_decode_mask {
match acc_decode_data { match acc_decode_data {
AccDecodeData::Decode(secret, acc_account_id) => { AccDecodeData::Decode(secret, acc_account_id) => {
let acc_ead = tx.message.encrypted_private_post_states[output_index].clone(); let (kind, res_acc) = tx
let acc_comm = tx.message.new_commitments[output_index].clone(); .message
.encrypted_private_post_states
let (kind, res_acc) = lee_core::EncryptionScheme::decrypt( .iter()
&acc_ead.ciphertext, .find_map(|encrypted_data| {
secret, tx.message.new_commitments.iter().find_map(|commitment| {
&acc_comm, let (kind, res_acc) = lee_core::EncryptionScheme::decrypt(
output_index &encrypted_data.ciphertext,
.try_into() secret,
.expect("Output index is expected to fit in u32"), commitment,
) )?;
.unwrap(); (Commitment::new(acc_account_id, &res_acc) == *commitment)
.then_some((kind, res_acc))
})
})
.expect("Self-sent account output expected to be decodable");
println!("Received new acc {res_acc:#?}"); println!("Received new acc {res_acc:#?}");
@ -745,26 +749,20 @@ impl WalletCore {
tx.message() tx.message()
.encrypted_private_post_states .encrypted_private_post_states
.iter() .iter()
.enumerate() .filter(move |encrypted_data| encrypted_data.view_tag == view_tag)
.filter(move |(_, encrypted_data)| encrypted_data.view_tag == view_tag) .filter_map(move |encrypted_data| {
.filter_map(move |(ciph_id, encrypted_data)| {
let ciphertext = &encrypted_data.ciphertext;
let commitment = &new_commitments[ciph_id];
let shared_secret = let shared_secret =
key_chain.calculate_shared_secret_receiver(&encrypted_data.epk)?; key_chain.calculate_shared_secret_receiver(&encrypted_data.epk)?;
let npk = &key_chain.nullifier_public_key;
lee_core::EncryptionScheme::decrypt( new_commitments.iter().find_map(|commitment| {
ciphertext, let (kind, res_acc) = lee_core::EncryptionScheme::decrypt(
&shared_secret, &encrypted_data.ciphertext,
commitment, &shared_secret,
ciph_id commitment,
.try_into() )?;
.expect("Ciphertext ID is expected to fit in u32"),
)
.map(|(kind, res_acc)| {
let npk = &key_chain.nullifier_public_key;
let account_id = lee::AccountId::for_private_account(npk, &kind); let account_id = lee::AccountId::for_private_account(npk, &kind);
(account_id, kind, res_acc) (Commitment::new(&account_id, &res_acc) == *commitment)
.then_some((account_id, kind, res_acc))
}) })
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()
@ -823,12 +821,7 @@ impl WalletCore {
for (account_id, npk, vpk, vsk) in shared_keys { for (account_id, npk, vpk, vsk) in shared_keys {
let view_tag = EncryptedAccountData::compute_view_tag(&npk, &vpk); let view_tag = EncryptedAccountData::compute_view_tag(&npk, &vpk);
for (ciph_id, encrypted_data) in tx for encrypted_data in &tx.message().encrypted_private_post_states {
.message()
.encrypted_private_post_states
.iter()
.enumerate()
{
if encrypted_data.view_tag != view_tag { if encrypted_data.view_tag != view_tag {
continue; continue;
} }
@ -838,16 +831,17 @@ impl WalletCore {
else { else {
continue; continue;
}; };
let commitment = &tx.message.new_commitments[ciph_id];
if let Some((_kind, new_acc)) = lee_core::EncryptionScheme::decrypt( let matched = tx.message.new_commitments.iter().find_map(|commitment| {
&encrypted_data.ciphertext, let (_kind, new_acc) = lee_core::EncryptionScheme::decrypt(
&shared_secret, &encrypted_data.ciphertext,
commitment, &shared_secret,
ciph_id commitment,
.try_into() )?;
.expect("Ciphertext ID is expected to fit in u32"), (Commitment::new(&account_id, &new_acc) == *commitment).then_some(new_acc)
) { });
if let Some(new_acc) = matched {
info!("Synced shared account {account_id:#?} with new state {new_acc:#?}"); info!("Synced shared account {account_id:#?} with new state {new_acc:#?}");
self.storage self.storage
.key_chain_mut() .key_chain_mut()