From 43abadfb55b92dc818fadc7c1c0b93ac89d808ba Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Wed, 18 Aug 2021 19:00:21 -0600 Subject: [PATCH] Adds decryption for a specific index within a bundle. --- src/bundle.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/bundle.rs b/src/bundle.rs index b92fdf5e..302c0fc6 100644 --- a/src/bundle.rs +++ b/src/bundle.rs @@ -362,7 +362,7 @@ impl Bundle { /// 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 Bundle { .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> Bundle {