Adds decryption for a specific index within a bundle.

This commit is contained in:
Kris Nuttycombe 2021-08-18 19:00:21 -06:00
parent c406461f64
commit 43abadfb55
1 changed files with 16 additions and 2 deletions

View File

@ -362,7 +362,7 @@ impl<T: Authorization, V> Bundle<T, V> {
/// 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<'a>(
pub fn decrypt_outputs_for_keys(
&self,
keys: &[IncomingViewingKey],
) -> Vec<(usize, IncomingViewingKey, Note, Address, [u8; 512])> {
@ -372,11 +372,25 @@ impl<T: Authorization, V> Bundle<T, V> {
.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, ivk.clone(), n, a, m))
try_note_decryption(&domain, ivk, action)
.map(|(n, a, m)| (idx, ivk.clone(), n, a, m))
})
})
.collect()
}
/// Perform trial decryption of each action at `action_idx` in the bundle with the
/// specified incoming viewing key, and return the decrypted note contents.
pub fn decrypt_output_with_key(
&self,
action_idx: usize,
key: &IncomingViewingKey,
) -> Option<(Note, Address, [u8; 512])> {
self.actions.get(action_idx).and_then(move |action| {
let domain = OrchardDomain::for_action(action);
try_note_decryption(&domain, key, action)
})
}
}
impl<T: Authorization, V: Copy + Into<ValueSum>> Bundle<T, V> {