Add trial decryption of actions to Bundle

This commit is contained in:
Kris Nuttycombe 2021-07-21 14:31:37 -06:00
parent 77cf4c9831
commit e33cd4ade4
2 changed files with 25 additions and 2 deletions

View File

@ -7,11 +7,15 @@ use std::mem;
use blake2b_simd::Hash as Blake2bHash;
use nonempty::NonEmpty;
use zcash_note_encryption::try_note_decryption;
use crate::{
address::Address,
bundle::commitments::{hash_bundle_auth_data, hash_bundle_txid_data},
circuit::{Instance, Proof, VerifyingKey},
note::{ExtractedNoteCommitment, Nullifier, TransmittedNoteCiphertext},
keys::IncomingViewingKey,
note::{ExtractedNoteCommitment, Note, Nullifier, TransmittedNoteCiphertext},
note_encryption::OrchardDomain,
primitives::redpallas::{self, Binding, SpendAuth},
tree::Anchor,
value::{ValueCommitTrapdoor, ValueCommitment, ValueSum},
@ -354,6 +358,25 @@ impl<T: Authorization, V> Bundle<T, V> {
.map(|a| a.to_instance(self.flags, self.anchor))
.collect()
}
/// Perform trial decryption of each action in the bundle with each of the
/// specified incoming viewing keys, and return the decrypted note contents
/// along with the index of the action from which it was derived.
pub fn decrypt_outputs_for_keys(
&self,
keys: &[IncomingViewingKey],
) -> Vec<(usize, Note, Address, [u8; 512])> {
self.actions
.iter()
.enumerate()
.filter_map(|(idx, action)| {
let domain = OrchardDomain::for_action(action);
keys.iter().find_map(move |ivk| {
try_note_decryption(&domain, ivk, action).map(|(n, a, m)| (idx, n, a, m))
})
})
.collect()
}
}
impl<T: Authorization, V: Copy + Into<ValueSum>> Bundle<T, V> {

View File

@ -311,7 +311,7 @@ impl DiversifierKey {
&self.0
}
/// Construct a diversifier key from bytes
/// Construct a diversifier key from bytes
pub fn from_bytes(bytes: [u8; 32]) -> Self {
DiversifierKey(bytes)
}