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
21        for spend_plan in self.spend_plans() {
22            let rsk = sk.spend_auth_key().randomize(&spend_plan.randomizer);
23            let auth_sig = rsk.sign(&mut rng, effect_hash.as_ref());
24            spend_auths.push(auth_sig);
25        }
26        for delegator_vote_plan in self.delegator_vote_plans() {
27            let rsk = sk
28                .spend_auth_key()
29                .randomize(&delegator_vote_plan.randomizer);
30            let auth_sig = rsk.sign(&mut rng, effect_hash.as_ref());
31            delegator_vote_auths.push(auth_sig);
32        }
33        Ok(AuthorizationData {
34            effect_hash: Some(effect_hash),
35            spend_auths,
36            delegator_vote_auths,
37        })
38    }
39}