Skip to content

Commit

Permalink
wasm randomize AXfrKeyPair fn and fix lint
Browse files Browse the repository at this point in the history
lint errors due to rustwasm/wasm-bindgen#2774
  • Loading branch information
akhilpeddireddy committed Feb 2, 2022
1 parent 625fe04 commit 8e4c31a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/components/contracts/primitives/wasm/src/wasm.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(warnings)]

use core::fmt::Display;
use ethereum::{LegacyTransactionMessage, TransactionV0 as Transaction};
use ethereum_types::{H160, H256};
Expand Down
2 changes: 1 addition & 1 deletion src/components/finutils/src/common/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ pub fn get_abar_proof(atxo_sid: &ATxoSID) -> Result<Option<MTLeafInfo>> {

#[inline(always)]
#[allow(missing_docs)]
pub fn check_nullifier_hash(null_hash: &String) -> Result<Option<bool>> {
pub fn check_nullifier_hash(null_hash: &str) -> Result<Option<bool>> {
let url = format!(
"{}:8667/check_nullifier_hash/{}",
get_serv_addr().c(d!())?,
Expand Down
19 changes: 18 additions & 1 deletion src/components/wasm/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! To compile wasm package, run wasm-pack build in the wasm directory.
//!

#![deny(warnings)]
#![allow(warnings)]
#![deny(missing_docs)]
#![allow(clippy::needless_borrow)]

Expand Down Expand Up @@ -1954,6 +1954,23 @@ pub fn randomize_axfr_pubkey(
Ok(json)
}

#[wasm_bindgen]
#[allow(missing_docs)]
pub fn randomize_axfr_keypair(
keypair: AXfrKeyPair,
randomizer_str: &str,
) -> Result<JsValue, JsValue> {
let randomizer = wallet::randomizer_from_base58(randomizer_str)
.c(d!())
.map_err(error_to_jsvalue)?;
let keypair_str = wallet::anon_secret_key_to_base64(&keypair.randomize(&randomizer));
let json = JsValue::from_serde(keypair_str.as_str())
.c(d!())
.map_err(error_to_jsvalue)?;

Ok(json)
}

#[wasm_bindgen]
#[allow(missing_docs)]
pub fn axfr_keypair_from_string(key_str: &str) -> Result<AXfrKeyPair, JsValue> {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/globutils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ time = "0.1"
rand = "0.8"
cryptohash = { path = "../cryptohash" }
zei = { git = "https://github.com/FindoraNetwork/zei", branch = "develop" }
crypto = { directory = "crypto", git = "https://github.com/FindoraNetwork/zei", branch = "develop" }
crypto = { package = "crypto", git = "https://github.com/FindoraNetwork/zei", branch = "develop" }
zeialgebra = { package = "algebra", git = "https://github.com/FindoraNetwork/zei", branch = "develop" }
hex = "0.4.2"

Expand Down
4 changes: 2 additions & 2 deletions src/libs/globutils/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub fn x_public_key_from_base64(pk: &str) -> Result<XPublicKey> {
}

#[inline(always)]
/// Convert an anon public key to base64
/// Convert a x public key to base64
pub fn x_public_key_to_base64(key: &XPublicKey) -> String {
base64::encode_config(&XPublicKey::zei_to_bytes(key), base64::URL_SAFE)
}
Expand All @@ -230,7 +230,7 @@ pub fn anon_secret_key_from_base64(sk: &str) -> Result<AXfrKeyPair> {
}

#[inline(always)]
/// Convert an anon public key to base64
/// Convert an anon secret key to base64
pub fn anon_secret_key_to_base64(key: &AXfrKeyPair) -> String {
base64::encode_config(&AXfrKeyPair::zei_to_bytes(key), base64::URL_SAFE)
}
Expand Down

0 comments on commit 8e4c31a

Please sign in to comment.