Merge pull request #116 from zcash/signature-validation

Signature validation APIs
This commit is contained in:
str4d 2021-06-14 22:42:36 +01:00 committed by GitHub
commit 63ca1f8d3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 1 deletions

View File

@ -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 {

View File

@ -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.