Skip to content

Commit

Permalink
Add ECPointsFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
AllFi committed Feb 8, 2023
1 parent 49ad2d6 commit b615854
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions libzkbob-rs-wasm/src/client/coldstorage.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
use libzeropool::fawkes_crypto::ff_uint::Num;
use libzeropool::{fawkes_crypto::ff_uint::Num, native::cipher::ECPointsFormat};
use crate::Fr;

#[derive(Serialize, Deserialize, PartialEq, Debug)]
Expand All @@ -17,5 +17,5 @@ pub struct BulkData {
pub root_before: Num<Fr>,
pub root_after: Num<Fr>,
pub txs: Vec<TxInputData>,
pub ec_points_compressed: bool,
pub ec_points_format: ECPointsFormat,
}
4 changes: 2 additions & 2 deletions libzkbob-rs-wasm/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ impl UserAccount {
let eta = &self.inner.borrow().keys.eta;
let params = &self.inner.borrow().params;
let range = from_index.unwrap_or(0)..to_index.unwrap_or(u64::MAX);
let ec_points_compressed = bulk.ec_points_compressed;
let ec_points_format = bulk.ec_points_format;
let bulk_results: Vec<ParseResult> = vec_into_iter(bulk.txs)
.filter(|tx| range.contains(&tx.index))
.map(|tx| -> ParseResult {
Expand All @@ -392,7 +392,7 @@ impl UserAccount {
Some(&tx.tx_hash),
eta,
params,
ec_points_compressed
ec_points_format
)
})
.collect();
Expand Down
10 changes: 5 additions & 5 deletions libzkbob-rs-wasm/src/client/tx_parser.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use byteorder::{LittleEndian, ReadBytesExt};
use libzeropool::{native::{account::Account, note::Note, cipher, key}, fawkes_crypto::ff_uint::{Num, NumRepr, Uint}};
use libzeropool::{native::{account::Account, note::Note, cipher::{self, ECPointsFormat}, key}, fawkes_crypto::ff_uint::{Num, NumRepr, Uint}};
use libzkbob_rs::{merkle::Hash, keys::Keys};
use wasm_bindgen::{prelude::*, JsCast};
use serde::{Serialize, Deserialize};
Expand Down Expand Up @@ -79,7 +79,7 @@ impl TxParser {
let memo = hex::decode(memo).unwrap();
let commitment = hex::decode(commitment).unwrap();

parse_tx(index, &commitment, &memo, None, &eta, params, true)
parse_tx(index, &commitment, &memo, None, &eta, params, Default::default())
}).collect();

let parse_result = parse_results
Expand Down Expand Up @@ -110,15 +110,15 @@ pub fn parse_tx(
tx_hash: Option<&Vec<u8>>,
eta: &Num<Fr>,
params: &PoolParams,
ec_points_compressed: bool,
ec_points_format: ECPointsFormat,
) -> ParseResult {
let num_hashes = (&memo[0..4]).read_u32::<LittleEndian>().unwrap();
let hashes = (&memo[4..])
.chunks(32)
.take(num_hashes as usize)
.map(|bytes| Num::from_uint_reduced(NumRepr(Uint::from_little_endian(bytes))));

let pair = cipher::decrypt_out(*eta, &memo, params, ec_points_compressed);
let pair = cipher::decrypt_out(*eta, &memo, params, ec_points_format);

match pair {
Some((account, notes)) => {
Expand Down Expand Up @@ -155,7 +155,7 @@ pub fn parse_tx(
}
},
None => {
let in_notes = cipher::decrypt_in(*eta, &memo, params, ec_points_compressed);
let in_notes = cipher::decrypt_in(*eta, &memo, params, ec_points_format);
let in_notes: Vec<(_, _)> = in_notes
.into_iter()
.enumerate()
Expand Down
4 changes: 2 additions & 2 deletions libzkbob-rs/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ where

/// Attempts to decrypt notes.
pub fn decrypt_notes(&self, data: Vec<u8>) -> Vec<Option<Note<P::Fr>>> {
cipher::decrypt_in(self.keys.eta, &data, &self.params, true)
cipher::decrypt_in(self.keys.eta, &data, &self.params, Default::default())
}

/// Attempts to decrypt account and notes.
pub fn decrypt_pair(&self, data: Vec<u8>) -> Option<(Account<P::Fr>, Vec<Note<P::Fr>>)> {
cipher::decrypt_out(self.keys.eta, &data, &self.params, true)
cipher::decrypt_out(self.keys.eta, &data, &self.params, Default::default())
}

pub fn is_own_address(&self, address: &str) -> bool {
Expand Down

0 comments on commit b615854

Please sign in to comment.