2019-07-12 14:20:08 -07:00
|
|
|
extern crate pairing;
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
use pairing::{Engine, CurveProjective};
|
|
|
|
use ff::PrimeField;
|
2019-07-23 06:54:53 -07:00
|
|
|
use util::hash_to_fr;
|
2019-07-12 14:20:08 -07:00
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct Wallet<E: Engine> {
|
|
|
|
pub pkc: E::Fr,
|
|
|
|
pub wpk: E::Fr,
|
|
|
|
pub bc: i32,
|
|
|
|
pub bm: i32,
|
2019-07-24 14:13:56 -07:00
|
|
|
pub close: Option<E::Fr>,
|
2019-07-12 14:20:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<E: Engine> Wallet<E> {
|
|
|
|
pub fn as_fr_vec(&self) -> Vec<E::Fr> {
|
2019-07-24 14:13:56 -07:00
|
|
|
if self.close.is_some() {
|
|
|
|
vec!(self.pkc, self.wpk, E::Fr::from_str(&self.bc.to_string()).unwrap(), E::Fr::from_str(&self.bm.to_string()).unwrap(), self.close.unwrap())
|
|
|
|
} else {
|
|
|
|
vec!(self.pkc, self.wpk, E::Fr::from_str(&self.bc.to_string()).unwrap(), E::Fr::from_str(&self.bm.to_string()).unwrap())
|
|
|
|
}
|
2019-07-12 14:20:08 -07:00
|
|
|
}
|
2019-07-23 06:54:53 -07:00
|
|
|
|
|
|
|
pub fn with_msg(&self, msg: String) -> Vec<E::Fr> {
|
|
|
|
let m = hash_to_fr::<E>(msg.into_bytes() );
|
|
|
|
let mut new_vec = self.as_fr_vec();
|
|
|
|
new_vec.push(m);
|
|
|
|
return new_vec;
|
|
|
|
}
|
2019-07-12 14:20:08 -07:00
|
|
|
}
|