penumbra_sdk_transaction/plan/
auth.rs

1use anyhow::Result;
2use rand::{CryptoRng, RngCore};
3
4use penumbra_sdk_keys::keys::SpendKey;
5
6use crate::{AuthorizationData, TransactionPlan};
7
8impl TransactionPlan {
9    /// Authorize this [`TransactionPlan`] with the provided [`SpendKey`].
10    ///
11    /// The returned [`AuthorizationData`] can be used to build a [`Transaction`](crate::Transaction).
12    pub fn authorize<R: RngCore + CryptoRng>(
13        &self,
14        mut rng: R,
15        sk: &SpendKey,
16    ) -> Result<AuthorizationData> {
17        let effect_hash = self.effect_hash(sk.full_viewing_key())?;
18        let mut spend_auths = Vec::new();
19        let mut delegator_vote_auths = Vec::new();
20        let mut lqt_vote_auths = Vec::new();
21
22        for spend_plan in self.spend_plans() {
23            let rsk = sk.spend_auth_key().randomize(&spend_plan.randomizer);
24            let auth_sig = rsk.sign(&mut rng, effect_hash.as_ref());
25            spend_auths.push(auth_sig);
26        }
27        for delegator_vote_plan in self.delegator_vote_plans() {
28            let rsk = sk
29                .spend_auth_key()
30                .randomize(&delegator_vote_plan.randomizer);
31            let auth_sig = rsk.sign(&mut rng, effect_hash.as_ref());
32            delegator_vote_auths.push(auth_sig);
33        }
34        for lqt_vote_plan in self.lqt_vote_plans() {
35            let rsk = sk.spend_auth_key().randomize(&lqt_vote_plan.randomizer);
36            let auth_sig = rsk.sign(&mut rng, effect_hash.as_ref());
37            lqt_vote_auths.push(auth_sig);
38        }
39        Ok(AuthorizationData {
40            effect_hash: Some(effect_hash),
41            spend_auths,
42            delegator_vote_auths,
43            lqt_vote_auths,
44        })
45    }
46}