Add identify function
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
use std::convert::TryFrom;
|
||||
|
||||
use crate::error::Result;
|
||||
use crate::scheme::keygen::PublicKeyUser;
|
||||
use crate::scheme::setup::Parameters;
|
||||
use crate::scheme::spend::{PayInfo, Payment};
|
||||
|
||||
pub fn identify(params: &Parameters, pay1: Payment, pay2: Payment, payInfo1: PayInfo, payInfo2: PayInfo) -> Result<PublicKeyUser> {
|
||||
// TODO: We had to include checks for S1, S2 and payinfo1 and payinfo2
|
||||
let pkUser = (pay2.T * pay1.R - pay1.T * pay2.R) * (pay1.R - pay2.R).invert().unwrap();
|
||||
Ok(PublicKeyUser { pk: pkUser })
|
||||
}
|
||||
@@ -15,6 +15,7 @@ pub mod keygen;
|
||||
pub mod setup;
|
||||
pub mod spend;
|
||||
pub mod withdrawal;
|
||||
pub mod identify;
|
||||
|
||||
pub type SignerIndex = u64;
|
||||
|
||||
|
||||
@@ -17,15 +17,15 @@ pub struct PayInfo {
|
||||
}
|
||||
|
||||
pub struct Payment {
|
||||
kappa: G2Projective,
|
||||
sig: Signature,
|
||||
S: G1Projective,
|
||||
T: G1Projective,
|
||||
A: G1Projective,
|
||||
C: G1Projective,
|
||||
D: G1Projective,
|
||||
R: Scalar,
|
||||
zk_proof: SpendProof,
|
||||
pub kappa: G2Projective,
|
||||
pub sig: Signature,
|
||||
pub S: G1Projective,
|
||||
pub T: G1Projective,
|
||||
pub A: G1Projective,
|
||||
pub C: G1Projective,
|
||||
pub D: G1Projective,
|
||||
pub R: Scalar,
|
||||
pub zk_proof: SpendProof,
|
||||
}
|
||||
|
||||
pub fn pseudorandom_fgv(params: &Parameters, v: Scalar, l: u64) -> G1Projective {
|
||||
@@ -134,7 +134,7 @@ pub fn spend(params: &Parameters, wallet: &Wallet, verification_key: &Verificati
|
||||
Ok((pay, wallet_upd))
|
||||
}
|
||||
|
||||
pub fn spend_verify(params: &Parameters, verification_key: VerificationKeyAuth, pay: Payment, payinfo: PayInfo) -> Result<bool> {
|
||||
pub fn spend_verify(params: &Parameters, verification_key: &VerificationKeyAuth, pay: &Payment, payinfo: &PayInfo) -> Result<bool> {
|
||||
if bool::from(pay.sig.0.is_identity()) {
|
||||
return Err(CompactEcashError::Spend(
|
||||
"The element h of the signature equals the identity".to_string(),
|
||||
|
||||
@@ -7,6 +7,7 @@ use crate::scheme::keygen::{
|
||||
generate_keypair_user, PublicKeyUser, SecretKeyUser, ttp_keygen, VerificationKeyAuth,
|
||||
};
|
||||
use crate::scheme::setup::Parameters;
|
||||
use crate::scheme::spend::{PayInfo, spend, spend_verify};
|
||||
use crate::scheme::withdrawal::{issue_verify, issue_wallet, withdrawal_request};
|
||||
|
||||
#[test]
|
||||
@@ -43,7 +44,16 @@ fn main() -> Result<(), CompactEcashError> {
|
||||
.collect();
|
||||
|
||||
// Aggregate partial wallets
|
||||
let aggr_wallet = aggregate_wallets(¶ms, &verification_key, &user_keypair.secret_key(), &unblinded_wallet_shares, &req_info);
|
||||
let aggr_wallet = aggregate_wallets(¶ms, &verification_key, &user_keypair.secret_key(), &unblinded_wallet_shares, &req_info)?;
|
||||
|
||||
// Let's try to spend some coins
|
||||
let payInfo = PayInfo {
|
||||
info: [6u8; 32],
|
||||
};
|
||||
|
||||
let (payment, upd_wallet) = spend(¶ms, &aggr_wallet, &verification_key, &user_keypair.secret_key(), &payInfo)?;
|
||||
|
||||
assert!(spend_verify(¶ms, &verification_key, &payment, &payInfo).unwrap());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user