Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
AllFi committed Jan 27, 2023
1 parent be8f838 commit 49ad2d6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
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 compressed = bulk.ec_points_compressed;
let ec_points_compressed = bulk.ec_points_compressed;
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,
compressed
ec_points_compressed
)
})
.collect();
Expand Down
14 changes: 3 additions & 11 deletions libzkbob-rs-wasm/src/client/tx_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,15 @@ pub fn parse_tx(
tx_hash: Option<&Vec<u8>>,
eta: &Num<Fr>,
params: &PoolParams,
compressed: bool,
ec_points_compressed: bool,
) -> 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 = if compressed {
cipher::decrypt_out(*eta, &memo, params)
} else {
cipher::decrypt_out_decompressed(*eta, &memo, params)
};
let pair = cipher::decrypt_out(*eta, &memo, params, ec_points_compressed);

match pair {
Some((account, notes)) => {
Expand Down Expand Up @@ -159,11 +155,7 @@ pub fn parse_tx(
}
},
None => {
let in_notes = if compressed {
cipher::decrypt_in(*eta, &memo, params)
} else {
cipher::decrypt_in_decompressed(*eta, &memo, params)
};
let in_notes = cipher::decrypt_in(*eta, &memo, params, ec_points_compressed);
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)
cipher::decrypt_in(self.keys.eta, &data, &self.params, true)
}

/// 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)
cipher::decrypt_out(self.keys.eta, &data, &self.params, true)
}

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

0 comments on commit 49ad2d6

Please sign in to comment.