mirror of https://github.com/zcash/orchard.git
Merge pull request #116 from zcash/signature-validation
Signature validation APIs
This commit is contained in:
commit
63ca1f8d3a
|
@ -7,7 +7,7 @@ use crate::{
|
|||
note::{ExtractedNoteCommitment, Nullifier, TransmittedNoteCiphertext},
|
||||
primitives::redpallas::{self, Binding, SpendAuth},
|
||||
tree::Anchor,
|
||||
value::ValueCommitment,
|
||||
value::{ValueCommitTrapdoor, ValueCommitment, ValueSum},
|
||||
};
|
||||
|
||||
/// An action applied to the global ledger.
|
||||
|
@ -300,6 +300,22 @@ impl<T: Authorization, V> Bundle<T, V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Authorization, V: Copy + Into<ValueSum>> Bundle<T, V> {
|
||||
/// Returns the transaction binding validating key for this bundle.
|
||||
///
|
||||
/// This can be used to validate the [`Authorized::binding_signature`] returned from
|
||||
/// [`Bundle::authorization`].
|
||||
pub fn binding_validating_key(&self) -> redpallas::VerificationKey<Binding> {
|
||||
(self
|
||||
.actions
|
||||
.iter()
|
||||
.map(|a| a.cv_net())
|
||||
.sum::<ValueCommitment>()
|
||||
- ValueCommitment::derive(self.value_balance.into(), ValueCommitTrapdoor::zero()))
|
||||
.into_bvk()
|
||||
}
|
||||
}
|
||||
|
||||
/// Authorizing data for a bundle of actions, ready to be committed to the ledger.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Authorized {
|
||||
|
|
|
@ -5,6 +5,8 @@ use std::convert::{TryFrom, TryInto};
|
|||
use pasta_curves::pallas;
|
||||
use rand::{CryptoRng, RngCore};
|
||||
|
||||
pub use reddsa::batch;
|
||||
|
||||
#[cfg(test)]
|
||||
use rand::rngs::OsRng;
|
||||
|
||||
|
@ -108,6 +110,26 @@ impl VerificationKey<SpendAuth> {
|
|||
pub fn randomize(&self, randomizer: &pallas::Scalar) -> Self {
|
||||
VerificationKey(self.0.randomize(randomizer))
|
||||
}
|
||||
|
||||
/// Creates a batch validation item from a `SpendAuth` signature.
|
||||
pub fn create_batch_item<M: AsRef<[u8]>>(
|
||||
&self,
|
||||
sig: Signature<SpendAuth>,
|
||||
msg: &M,
|
||||
) -> batch::Item<SpendAuth, Binding> {
|
||||
batch::Item::from_spendauth(self.0.into(), sig.0, msg)
|
||||
}
|
||||
}
|
||||
|
||||
impl VerificationKey<Binding> {
|
||||
/// Creates a batch validation item from a `Binding` signature.
|
||||
pub fn create_batch_item<M: AsRef<[u8]>>(
|
||||
&self,
|
||||
sig: Signature<Binding>,
|
||||
msg: &M,
|
||||
) -> batch::Item<SpendAuth, Binding> {
|
||||
batch::Item::from_binding(self.0.into(), sig.0, msg)
|
||||
}
|
||||
}
|
||||
|
||||
/// A RedPallas signature.
|
||||
|
|
Loading…
Reference in New Issue