zebra_chain/primitives/
zcash_note_encryption.rsuse crate::{
block::Height,
parameters::{Network, NetworkUpgrade},
primitives::zcash_primitives::convert_tx_to_librustzcash,
transaction::Transaction,
};
pub fn decrypts_successfully(transaction: &Transaction, network: &Network, height: Height) -> bool {
let network_upgrade = NetworkUpgrade::current(network, height);
let alt_tx = convert_tx_to_librustzcash(
transaction,
network_upgrade
.branch_id()
.expect("should have a branch ID"),
)
.expect("zcash_primitives and Zebra transaction formats must be compatible");
let null_sapling_ovk = sapling_crypto::keys::OutgoingViewingKey([0u8; 32]);
let zip_212_enforcement = if network_upgrade >= NetworkUpgrade::Canopy {
sapling_crypto::note_encryption::Zip212Enforcement::On
} else {
sapling_crypto::note_encryption::Zip212Enforcement::Off
};
if let Some(bundle) = alt_tx.sapling_bundle() {
for output in bundle.shielded_outputs().iter() {
let recovery = sapling_crypto::note_encryption::try_sapling_output_recovery(
&null_sapling_ovk,
output,
zip_212_enforcement,
);
if recovery.is_none() {
return false;
}
}
}
if let Some(bundle) = alt_tx.orchard_bundle() {
for act in bundle.actions() {
if zcash_note_encryption::try_output_recovery_with_ovk(
&orchard::note_encryption::OrchardDomain::for_action(act),
&orchard::keys::OutgoingViewingKey::from([0u8; 32]),
act,
act.cv_net(),
&act.encrypted_note().out_ciphertext,
)
.is_none()
{
return false;
}
}
}
true
}