2019-12-03 12:22:35 -08:00
|
|
|
use std::{convert::TryFrom, marker::PhantomData};
|
2019-12-02 21:58:19 -08:00
|
|
|
|
2019-12-03 13:39:26 -08:00
|
|
|
use crate::{Binding, Error, Randomizer, SigType, Signature, SpendAuth};
|
2019-12-02 21:58:19 -08:00
|
|
|
|
|
|
|
/// A refinement type indicating that the inner `[u8; 32]` represents an
|
|
|
|
/// encoding of a RedJubJub public key.
|
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
2019-12-03 12:22:35 -08:00
|
|
|
pub struct PublicKeyBytes<T: SigType> {
|
|
|
|
bytes: [u8; 32],
|
|
|
|
_marker: PhantomData<T>,
|
|
|
|
}
|
2019-12-02 21:58:19 -08:00
|
|
|
|
2019-12-03 12:22:35 -08:00
|
|
|
impl<T: SigType> From<[u8; 32]> for PublicKeyBytes<T> {
|
|
|
|
fn from(bytes: [u8; 32]) -> PublicKeyBytes<T> {
|
2019-12-03 13:39:26 -08:00
|
|
|
PublicKeyBytes {
|
|
|
|
bytes,
|
|
|
|
_marker: PhantomData,
|
|
|
|
}
|
2019-12-02 21:58:19 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-03 12:22:35 -08:00
|
|
|
impl<T: SigType> From<PublicKeyBytes<T>> for [u8; 32] {
|
|
|
|
fn from(refined: PublicKeyBytes<T>) -> [u8; 32] {
|
|
|
|
refined.bytes
|
2019-12-02 21:58:19 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A RedJubJub public key.
|
|
|
|
// XXX PartialEq, Eq?
|
|
|
|
#[derive(Copy, Clone, Debug)]
|
2019-12-03 12:22:35 -08:00
|
|
|
pub struct PublicKey<T: SigType> {
|
2019-12-02 21:58:19 -08:00
|
|
|
// fields
|
2019-12-03 12:22:35 -08:00
|
|
|
_marker: PhantomData<T>,
|
2019-12-02 21:58:19 -08:00
|
|
|
}
|
|
|
|
|
2019-12-03 12:22:35 -08:00
|
|
|
impl<T: SigType> From<PublicKey<T>> for PublicKeyBytes<T> {
|
|
|
|
fn from(pk: PublicKey<T>) -> PublicKeyBytes<T> {
|
2019-12-02 21:58:19 -08:00
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-03 12:22:35 -08:00
|
|
|
impl<T: SigType> TryFrom<PublicKeyBytes<T>> for PublicKey<T> {
|
2019-12-02 21:58:19 -08:00
|
|
|
type Error = Error;
|
|
|
|
|
2019-12-03 12:22:35 -08:00
|
|
|
fn try_from(bytes: PublicKeyBytes<T>) -> Result<Self, Self::Error> {
|
2019-12-02 21:58:19 -08:00
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
2019-12-02 22:20:21 -08:00
|
|
|
|
2019-12-03 12:22:35 -08:00
|
|
|
impl<T: SigType> PublicKey<T> {
|
2019-12-02 22:32:55 -08:00
|
|
|
/// Randomize this public key with the given `randomizer`.
|
2019-12-03 12:22:35 -08:00
|
|
|
pub fn randomize(&self, randomizer: Randomizer) -> PublicKey<T> {
|
2019-12-02 22:32:55 -08:00
|
|
|
unimplemented!();
|
|
|
|
}
|
2019-12-03 12:22:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl PublicKey<Binding> {
|
|
|
|
/// Verify a Zcash `BindingSig` over `msg` made by this public key.
|
|
|
|
// This is similar to impl signature::Verifier but without boxed errors
|
|
|
|
pub fn verify(&self, msg: &[u8], signature: &Signature<Binding>) -> Result<(), Error> {
|
|
|
|
// this lets us specialize the basepoint parameter, could call a verify_inner
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
2019-12-02 22:32:55 -08:00
|
|
|
|
2019-12-03 12:22:35 -08:00
|
|
|
impl PublicKey<SpendAuth> {
|
|
|
|
/// Verify a Zcash `SpendAuthSig` over `msg` made by this public key.
|
2019-12-02 22:32:55 -08:00
|
|
|
// This is similar to impl signature::Verifier but without boxed errors
|
2019-12-03 12:22:35 -08:00
|
|
|
pub fn verify(&self, msg: &[u8], signature: &Signature<SpendAuth>) -> Result<(), Error> {
|
|
|
|
// this lets us specialize the basepoint parameter, could call a verify_inner
|
2019-12-02 22:20:21 -08:00
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|