-
Notifications
You must be signed in to change notification settings - Fork 573
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move proof generation key extension to ironfish-zkp
- Loading branch information
Showing
4 changed files
with
66 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
mod value_commitment; | ||
pub mod proof_generation_key; | ||
pub use value_commitment::ValueCommitment; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use group::GroupEncoding; | ||
use jubjub::{Fr, SubgroupPoint}; | ||
use zcash_primitives::sapling::ProofGenerationKey as ZcashProofGenerationKey; | ||
use std::fmt; | ||
use std::error::Error; | ||
use std::ops::Deref; | ||
|
||
#[derive(Debug)] | ||
pub enum ProofGenerationKeyError { | ||
InvalidAuthorizingKey, | ||
InvalidNullifierDerivingKey, | ||
HexConversionError, | ||
} | ||
|
||
impl fmt::Display for ProofGenerationKeyError { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
ProofGenerationKeyError::InvalidAuthorizingKey => write!(f, "Invalid authorizing key"), | ||
ProofGenerationKeyError::InvalidNullifierDerivingKey => write!(f, "Invalid nullifier deriving key"), | ||
ProofGenerationKeyError::HexConversionError => write!(f, "Hex conversion error"), | ||
} | ||
} | ||
} | ||
|
||
impl Error for ProofGenerationKeyError {} | ||
|
||
pub struct ProofGenerationKey(ZcashProofGenerationKey); | ||
|
||
impl ProofGenerationKey { | ||
pub fn to_bytes(&self) -> [u8; 64] { | ||
let mut proof_generation_key_bytes: [u8; 64] = [0; 64]; | ||
proof_generation_key_bytes[0..32].copy_from_slice(&self.0.ak.to_bytes()); | ||
proof_generation_key_bytes[32..].copy_from_slice(&self.0.nsk.to_bytes()); | ||
proof_generation_key_bytes | ||
} | ||
|
||
pub fn from_bytes(proof_generation_key_bytes: [u8; 64]) -> Result<Self, ProofGenerationKeyError> { | ||
let mut ak_bytes: [u8; 32] = [0; 32]; | ||
let mut nsk_bytes: [u8; 32] = [0; 32]; | ||
|
||
ak_bytes[0..32].copy_from_slice(&proof_generation_key_bytes[0..32]); | ||
nsk_bytes[0..32].copy_from_slice(&proof_generation_key_bytes[32..64]); | ||
|
||
let ak = match SubgroupPoint::from_bytes(&ak_bytes).into() { | ||
Some(ak) => ak, | ||
None => return Err(ProofGenerationKeyError::InvalidAuthorizingKey), | ||
}; | ||
|
||
let nsk = match Fr::from_bytes(&nsk_bytes).into() { | ||
Some(nsk) => nsk, | ||
None => return Err(ProofGenerationKeyError::InvalidNullifierDerivingKey), | ||
}; | ||
|
||
Ok(ProofGenerationKey(ZcashProofGenerationKey { ak, nsk })) | ||
} | ||
} | ||
|
||
impl Deref for ProofGenerationKey { | ||
type Target = ZcashProofGenerationKey; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} |