From 05e62a9de58d223febe31ae081e040551ae5cfa9 Mon Sep 17 00:00:00 2001 From: Harshad Patil Date: Wed, 18 Jan 2023 14:07:14 -0800 Subject: [PATCH 1/9] Removing reference of old Anon transfer keys and using ed25519 keys in place --- Cargo.toml | 8 - src/components/abciapp/Cargo.toml | 4 +- .../abciapp/src/abci/staking/test.rs | 12 +- .../api/query_server/query_api/ledger_api.rs | 3 +- .../src/api/query_server/query_api/mod.rs | 3 +- .../contracts/modules/account/Cargo.toml | 2 +- .../contracts/modules/account/src/tests.rs | 46 +-- .../contracts/modules/evm/Cargo.toml | 4 +- .../contracts/modules/evm/src/lib.rs | 2 +- .../contracts/modules/evm/src/utils.rs | 7 +- .../template/tests/template_integration.rs | 6 +- .../contracts/primitives/mocks/Cargo.toml | 2 +- .../contracts/primitives/mocks/src/lib.rs | 6 +- .../contracts/primitives/types/Cargo.toml | 4 +- .../primitives/types/src/actions/xhub.rs | 16 +- .../contracts/primitives/types/src/crypto.rs | 28 +- src/components/finutils/Cargo.toml | 8 +- .../finutils/src/bins/cfg_generator.rs | 2 +- src/components/finutils/src/bins/fn.rs | 264 +++++++++--------- src/components/finutils/src/bins/fn.yml | 212 +++++++------- .../finutils/src/bins/stt/init/mod.rs | 4 +- src/components/finutils/src/bins/stt/stt.rs | 14 +- .../finutils/src/common/ddev/init.rs | 6 +- src/components/finutils/src/common/evm.rs | 14 +- src/components/finutils/src/common/mod.rs | 192 +++++++------ src/components/finutils/src/common/utils.rs | 19 +- .../finutils/src/txn_builder/mod.rs | 128 ++++----- src/components/wallet_mobile/Cargo.toml | 4 +- .../wallet_mobile/src/android/constructor.rs | 2 +- .../wallet_mobile/src/rust/account.rs | 2 +- .../wallet_mobile/src/rust/crypto.rs | 14 +- .../wallet_mobile/src/rust/data_model.rs | 2 +- .../wallet_mobile/src/rust/transaction.rs | 2 +- .../wallet_mobile/src/rust/types.rs | 2 +- src/components/wasm/Cargo.toml | 6 +- src/components/wasm/src/wasm.rs | 131 +++------ src/components/wasm/src/wasm_data_model.rs | 59 +--- src/ledger/Cargo.toml | 14 +- src/ledger/src/converter/mod.rs | 6 +- src/ledger/src/data_model/__trash__.rs | 2 +- src/ledger/src/data_model/effects.rs | 2 +- src/ledger/src/data_model/mod.rs | 65 +++-- src/ledger/src/data_model/test.rs | 2 +- src/ledger/src/staking/cosig.rs | 8 +- src/ledger/src/staking/mod.rs | 4 +- src/ledger/src/staking/ops/claim.rs | 4 +- src/ledger/src/staking/ops/delegation.rs | 6 +- .../src/staking/ops/fra_distribution.rs | 2 +- src/ledger/src/staking/ops/governance.rs | 2 +- src/ledger/src/staking/ops/mint_fra.rs | 4 +- src/ledger/src/staking/ops/replace_staker.rs | 4 +- src/ledger/src/staking/ops/undelegation.rs | 4 +- src/ledger/src/staking/ops/update_staker.rs | 4 +- .../src/staking/ops/update_validator.rs | 2 +- src/ledger/src/store/api_cache.rs | 6 +- src/ledger/src/store/helpers.rs | 6 +- src/ledger/src/store/mod.rs | 2 +- src/ledger/src/store/test.rs | 26 +- src/ledger/src/utils.rs | 4 +- src/libs/credentials/Cargo.toml | 3 +- src/libs/globutils/Cargo.toml | 6 +- src/libs/globutils/src/lib.rs | 4 +- src/libs/globutils/src/wallet.rs | 68 +---- src/libs/sparse_merkle_tree/Cargo.toml | 2 +- tools/regression/evm.py | 12 +- .../triple_masking/asset_mixing_test.sh | 44 +-- .../scripts/gen_keys_test-bars.sh | 50 ++-- .../triple_masking/test_triple_masking.sh | 44 ++- tools/triple_masking/abar_to_bar_convert.sh | 4 +- tools/triple_masking/anonxfr_test_demo.sh | 22 +- tools/triple_masking/bar_to_abar_convert.sh | 21 +- 71 files changed, 791 insertions(+), 908 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4f2eee1f1..e30bbadff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,13 +58,5 @@ opt-level = 1 overflow-checks = false [patch.crates-io] -ark-ec = { git = "https://github.com/FindoraNetwork/ark-algebra", tag = "stable-2022" } -ark-ff = { git = "https://github.com/FindoraNetwork/ark-algebra", tag = "stable-2022" } -ark-serialize = { git = "https://github.com/FindoraNetwork/ark-algebra", tag = "stable-2022" } -ark-std = { git = "https://github.com/FindoraNetwork/ark-std", tag = "stable-2022" } -ark-bls12-381 = { git = "https://github.com/FindoraNetwork/ark-curves", tag = "stable-2022" } -ark-ed-on-bls12-381 = { git = "https://github.com/FindoraNetwork/ark-curves", tag = "stable-2022" } -ark-algebra-test-templates = { git = "https://github.com/FindoraNetwork/ark-algebra", tag = "stable-2022" } -curve25519-dalek = { git = "https://github.com/FindoraNetwork/curve25519-dalek", tag = "v3.2.0-f" } ed25519-dalek = { git = "https://github.com/FindoraNetwork/ed25519-dalek", tag = "v1.0.1-f" } abci = { git = "https://github.com/FindoraNetwork/tendermint-abci", tag = "0.7.5" } diff --git a/src/components/abciapp/Cargo.toml b/src/components/abciapp/Cargo.toml index 0ec73a366..fbc282785 100644 --- a/src/components/abciapp/Cargo.toml +++ b/src/components/abciapp/Cargo.toml @@ -44,8 +44,8 @@ ruc = { version = "1.0.5", default-features = false, features = ["compact"] } module-evm = { path = "../contracts/modules/evm"} ethereum-types = { version = "0.13.1", default-features = false } -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } abci = { git = "https://github.com/FindoraNetwork/tendermint-abci", tag = "0.7.5" } config = { path = "../config"} diff --git a/src/components/abciapp/src/abci/staking/test.rs b/src/components/abciapp/src/abci/staking/test.rs index 922707e4d..eaf748991 100644 --- a/src/components/abciapp/src/abci/staking/test.rs +++ b/src/components/abciapp/src/abci/staking/test.rs @@ -11,10 +11,12 @@ use { store::LedgerState, utils::fra_gen_initial_tx, }, - noah::xfr::{ - asset_record::{open_blind_asset_record, AssetRecordType}, - sig::{XfrKeyPair, XfrPublicKey}, - structs::{AssetRecordTemplate, XfrAmount}, + noah::{ + keys::{KeyPair as XfrKeyPair, PublicKey as XfrPublicKey}, + xfr::{ + asset_record::{open_blind_asset_record, AssetRecordType}, + structs::{AssetRecordTemplate, XfrAmount}, + }, }, rand::random, rand_chacha::ChaChaRng, @@ -33,7 +35,7 @@ fn staking_block_rewards_rate() { // 4. check if the block rewards rate is correct per loop fn check_block_rewards_rate() -> Result<()> { let mut ledger = LedgerState::tmp_ledger(); - let root_kp = XfrKeyPair::generate(&mut ChaChaRng::from_entropy()); + let root_kp = XfrKeyPair::generate_ed25519(&mut ChaChaRng::from_entropy()); let tx = fra_gen_initial_tx(&root_kp); diff --git a/src/components/abciapp/src/api/query_server/query_api/ledger_api.rs b/src/components/abciapp/src/api/query_server/query_api/ledger_api.rs index 399bb577a..196b8566e 100644 --- a/src/components/abciapp/src/api/query_server/query_api/ledger_api.rs +++ b/src/components/abciapp/src/api/query_server/query_api/ledger_api.rs @@ -23,7 +23,8 @@ use { TendermintAddrRef, }, }, - noah::xfr::{sig::XfrPublicKey, structs::OwnerMemo}, + noah::keys::PublicKey as XfrPublicKey, + noah::xfr::structs::OwnerMemo, parking_lot::RwLock, ruc::*, serde::{Deserialize, Serialize}, diff --git a/src/components/abciapp/src/api/query_server/query_api/mod.rs b/src/components/abciapp/src/api/query_server/query_api/mod.rs index 617f4d247..7c69ce5b2 100644 --- a/src/components/abciapp/src/api/query_server/query_api/mod.rs +++ b/src/components/abciapp/src/api/query_server/query_api/mod.rs @@ -26,7 +26,8 @@ use { ledger_api::*, noah::{ anon_xfr::structs::{AxfrOwnerMemo, Commitment, MTLeafInfo}, - xfr::{sig::XfrPublicKey, structs::OwnerMemo}, + keys::PublicKey as XfrPublicKey, + xfr::structs::OwnerMemo, }, noah_algebra::serialization::NoahFromToBytes, parking_lot::RwLock, diff --git a/src/components/contracts/modules/account/Cargo.toml b/src/components/contracts/modules/account/Cargo.toml index a22538a03..60216d22c 100644 --- a/src/components/contracts/modules/account/Cargo.toml +++ b/src/components/contracts/modules/account/Cargo.toml @@ -30,7 +30,7 @@ parking_lot = "0.12" rand_chacha = "0.3" storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } [features] web3_service = ["enterprise-web3"] diff --git a/src/components/contracts/modules/account/src/tests.rs b/src/components/contracts/modules/account/src/tests.rs index 36c8c3322..c1d17f3ea 100644 --- a/src/components/contracts/modules/account/src/tests.rs +++ b/src/components/contracts/modules/account/src/tests.rs @@ -6,7 +6,7 @@ use fp_storage::{Borrow, BorrowMut}; use fp_traits::account::AccountAsset; use fp_types::crypto::Address; use fp_types::U256; -use noah::xfr::sig::XfrKeyPair; +use noah::keys::KeyPair as XfrKeyPair; use parking_lot::RwLock; use rand_chacha::rand_core::SeedableRng; use rand_chacha::ChaChaRng; @@ -48,8 +48,8 @@ fn test_accounts_set_get() { //Generate Address let mut prng = ChaChaRng::from_entropy(); - let key = XfrKeyPair::generate(&mut prng); - let address = Address::from(key.pub_key); + let key = XfrKeyPair::generate_ed25519(&mut prng); + let address = Address::from(key.get_pk()); //Generate SmartAccount let account = SmartAccount { @@ -79,8 +79,8 @@ fn test_account_of() { //Generate Address let mut prng = ChaChaRng::from_entropy(); - let key = XfrKeyPair::generate(&mut prng); - let addr = Address::from(key.pub_key); + let key = XfrKeyPair::generate_ed25519(&mut prng); + let addr = Address::from(key.get_pk()); //Generate SmartAccount let sa1 = SmartAccount { @@ -154,8 +154,8 @@ fn test_account_balance() { //Generate Address let mut prng = ChaChaRng::from_entropy(); - let key = XfrKeyPair::generate(&mut prng); - let address = Address::from(key.pub_key); + let key = XfrKeyPair::generate_ed25519(&mut prng); + let address = Address::from(key.get_pk()); //Generate SmartAccount let account = SmartAccount { @@ -179,8 +179,8 @@ fn test_account_nonce() { //Generate Address let mut prng = ChaChaRng::from_entropy(); - let key = XfrKeyPair::generate(&mut prng); - let address = Address::from(key.pub_key); + let key = XfrKeyPair::generate_ed25519(&mut prng); + let address = Address::from(key.get_pk()); //Generate SmartAccount let account = SmartAccount { @@ -204,8 +204,8 @@ fn test_account_inc_nonce() { //Generate Address let mut prng = ChaChaRng::from_entropy(); - let key = XfrKeyPair::generate(&mut prng); - let address = Address::from(key.pub_key); + let key = XfrKeyPair::generate_ed25519(&mut prng); + let address = Address::from(key.get_pk()); //Generate SmartAccount let account = SmartAccount { @@ -232,10 +232,10 @@ fn test_account_transfer() { //Generate Addresses let mut prng = ChaChaRng::from_entropy(); - let key1 = XfrKeyPair::generate(&mut prng); - let key2 = XfrKeyPair::generate(&mut prng); - let address1 = Address::from(key1.pub_key); - let address2 = Address::from(key2.pub_key); + let key1 = XfrKeyPair::generate_ed25519(&mut prng); + let key2 = XfrKeyPair::generate_ed25519(&mut prng); + let address1 = Address::from(key1.get_pk()); + let address2 = Address::from(key2.get_pk()); //Generate accounts with different amounts let mut acct1 = SmartAccount::default(); @@ -272,8 +272,8 @@ fn test_account_mint() { //Generate Address let mut prng = ChaChaRng::from_entropy(); - let key = XfrKeyPair::generate(&mut prng); - let address = Address::from(key.pub_key); + let key = XfrKeyPair::generate_ed25519(&mut prng); + let address = Address::from(key.get_pk()); //Generate SmartAccount let account = SmartAccount { @@ -298,8 +298,8 @@ fn test_account_burn() { //Generate Address let mut prng = ChaChaRng::from_entropy(); - let key = XfrKeyPair::generate(&mut prng); - let address = Address::from(key.pub_key); + let key = XfrKeyPair::generate_ed25519(&mut prng); + let address = Address::from(key.get_pk()); //Generate SmartAccount let account = SmartAccount { @@ -325,8 +325,8 @@ fn test_account_withdraw() { //Generate Address let mut prng = ChaChaRng::from_entropy(); - let key = XfrKeyPair::generate(&mut prng); - let address = Address::from(key.pub_key); + let key = XfrKeyPair::generate_ed25519(&mut prng); + let address = Address::from(key.get_pk()); //Generate SmartAccount let account = SmartAccount { @@ -354,8 +354,8 @@ fn test_account_refund() { //Generate Address let mut prng = ChaChaRng::from_entropy(); - let key = XfrKeyPair::generate(&mut prng); - let address = Address::from(key.pub_key); + let key = XfrKeyPair::generate_ed25519(&mut prng); + let address = Address::from(key.get_pk()); //Generate SmartAccount let account = SmartAccount { diff --git a/src/components/contracts/modules/evm/Cargo.toml b/src/components/contracts/modules/evm/Cargo.toml index 163e19cb4..314148429 100644 --- a/src/components/contracts/modules/evm/Cargo.toml +++ b/src/components/contracts/modules/evm/Cargo.toml @@ -24,8 +24,8 @@ serde_json = "1.0.64" sha3 = { version = "0.10", default-features = false } hex = "0.4.2" ethabi = "17.1.0" -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } # primitives, don't depend on any modules fp-core = { path = "../../primitives/core" } diff --git a/src/components/contracts/modules/evm/src/lib.rs b/src/components/contracts/modules/evm/src/lib.rs index 45e9d916f..e6f5702ca 100644 --- a/src/components/contracts/modules/evm/src/lib.rs +++ b/src/components/contracts/modules/evm/src/lib.rs @@ -39,7 +39,7 @@ use fp_types::{ actions::evm::Action, crypto::{Address, HA160}, }; -use noah::xfr::sig::XfrPublicKey; +use noah::keys::PublicKey as XfrPublicKey; use noah_algebra::serialization::NoahFromToBytes; use precompile::PrecompileSet; use ruc::*; diff --git a/src/components/contracts/modules/evm/src/utils.rs b/src/components/contracts/modules/evm/src/utils.rs index 386826560..0323d0332 100644 --- a/src/components/contracts/modules/evm/src/utils.rs +++ b/src/components/contracts/modules/evm/src/utils.rs @@ -2,8 +2,8 @@ use ethabi::{Event, EventParam, ParamType, RawLog}; use fp_traits::evm::{DecimalsMapping, EthereumDecimalsMapping}; use fp_types::actions::xhub::NonConfidentialOutput; use ledger::data_model::ASSET_TYPE_FRA; -use noah::xfr::structs::ASSET_TYPE_LENGTH; -use noah::xfr::{sig::XfrPublicKey, structs::AssetType}; +use noah::keys::PublicKey as XfrPublicKey; +use noah::xfr::structs::{AssetType, ASSET_TYPE_LENGTH}; use noah_algebra::serialization::NoahFromToBytes; use ruc::*; @@ -69,7 +69,8 @@ pub fn parse_deposit_asset_event(data: Vec) -> Result .clone() .into_bytes() .unwrap_or_default(); - let target = XfrPublicKey::noah_from_bytes(receiver.as_slice()).unwrap_or_default(); + let target = XfrPublicKey::noah_from_bytes(receiver.as_slice()) + .unwrap_or_else(|_| XfrPublicKey::default_ed25519()); let amount = result.params[2] .value diff --git a/src/components/contracts/modules/template/tests/template_integration.rs b/src/components/contracts/modules/template/tests/template_integration.rs index 85c5f1587..c6fef9704 100644 --- a/src/components/contracts/modules/template/tests/template_integration.rs +++ b/src/components/contracts/modules/template/tests/template_integration.rs @@ -15,7 +15,7 @@ fn run_all_tests() { test_abci_info(); test_abci_init_chain(); test_mint_balance( - &ALICE_XFR.pub_key.into(), + &ALICE_XFR.get_pk().into(), 100_0000_0000_0000_0000_u64.into(), 0, ); @@ -79,7 +79,7 @@ fn test_abci_check_tx() { assert_eq!( module_account::App::::balance( &BASE_APP.lock().unwrap().check_state, - &ALICE_XFR.pub_key.into() + &ALICE_XFR.get_pk().into() ), U256::from(100_0000_0000_0000_0000_u64) ); @@ -146,7 +146,7 @@ fn test_abci_commit() { assert_eq!( module_account::App::::balance( &BASE_APP.lock().unwrap().deliver_state, - &ALICE_XFR.pub_key.into() + &ALICE_XFR.get_pk().into() ), U256::from(100_0000_0000_0000_0000_u64).saturating_sub( ::FeeCalculator::min_fee() diff --git a/src/components/contracts/primitives/mocks/Cargo.toml b/src/components/contracts/primitives/mocks/Cargo.toml index ac613434c..dc6897a0f 100644 --- a/src/components/contracts/primitives/mocks/Cargo.toml +++ b/src/components/contracts/primitives/mocks/Cargo.toml @@ -18,7 +18,7 @@ rand_chacha = "0.3" rlp = "0.5" serde_json = "1.0" sha3 = "0.10" -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } # primitives fp-traits = { path = "../traits" } diff --git a/src/components/contracts/primitives/mocks/src/lib.rs b/src/components/contracts/primitives/mocks/src/lib.rs index 302bf14f2..30080d37c 100644 --- a/src/components/contracts/primitives/mocks/src/lib.rs +++ b/src/components/contracts/primitives/mocks/src/lib.rs @@ -12,7 +12,7 @@ use fp_traits::account::AccountAsset; use fp_traits::evm::{AddressMapping, EthereumAddressMapping}; use fp_types::crypto::{Address, MultiSignature}; use lazy_static::lazy_static; -use noah::xfr::sig::XfrKeyPair; +use noah::keys::KeyPair as XfrKeyPair; use primitive_types::{H160, H256, U256}; use rand_chacha::{rand_core::SeedableRng, ChaChaRng}; use rlp::*; @@ -29,9 +29,9 @@ lazy_static! { pub static ref ALICE_ECDSA: KeyPair = generate_address(1); pub static ref BOB_ECDSA: KeyPair = generate_address(2); pub static ref ALICE_XFR: XfrKeyPair = - XfrKeyPair::generate(&mut ChaChaRng::from_entropy()); + XfrKeyPair::generate_ed25519(&mut ChaChaRng::from_entropy()); pub static ref BOB_XFR: XfrKeyPair = - XfrKeyPair::generate(&mut ChaChaRng::from_entropy()); + XfrKeyPair::generate_ed25519(&mut ChaChaRng::from_entropy()); } pub fn test_mint_balance(who: &Address, balance: U256, height: u64) { diff --git a/src/components/contracts/primitives/types/Cargo.toml b/src/components/contracts/primitives/types/Cargo.toml index d840c46cf..ad2c983c7 100644 --- a/src/components/contracts/primitives/types/Cargo.toml +++ b/src/components/contracts/primitives/types/Cargo.toml @@ -21,8 +21,8 @@ serde = { version = "1.0.124", features = ["derive"] } serde_json = "1.0" serde-big-array = "0.4" sha3 = "0.10" -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } # primitives fp-utils = { path = "../utils" } diff --git a/src/components/contracts/primitives/types/src/actions/xhub.rs b/src/components/contracts/primitives/types/src/actions/xhub.rs index 550469c28..82c2238d7 100644 --- a/src/components/contracts/primitives/types/src/actions/xhub.rs +++ b/src/components/contracts/primitives/types/src/actions/xhub.rs @@ -1,4 +1,4 @@ -use noah::xfr::sig::XfrPublicKey; +use noah::keys::{PublicKey as XfrPublicKey, PublicKey}; use noah::xfr::structs::AssetType; use serde::{Deserialize, Serialize}; @@ -15,7 +15,7 @@ pub struct NonConfidentialTransfer { } /// Evm account balance convert to NonConfidential utxo. -#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct NonConfidentialOutput { pub asset: AssetType, pub amount: u64, @@ -25,3 +25,15 @@ pub struct NonConfidentialOutput { #[serde(skip)] pub max_supply: u64, } + +impl Default for NonConfidentialOutput { + fn default() -> Self { + NonConfidentialOutput { + asset: Default::default(), + amount: 0, + target: PublicKey::default_ed25519(), + decimal: 0, + max_supply: 0, + } + } +} diff --git a/src/components/contracts/primitives/types/src/crypto.rs b/src/components/contracts/primitives/types/src/crypto.rs index 996c734de..081961998 100644 --- a/src/components/contracts/primitives/types/src/crypto.rs +++ b/src/components/contracts/primitives/types/src/crypto.rs @@ -1,3 +1,4 @@ +use noah::keys::PublicKey; use { bech32::{FromBase32, ToBase32}, core::convert::TryFrom, @@ -7,7 +8,10 @@ use { globutils::wallet, hex::FromHex, libsecp256k1::{recover, Message}, - noah::xfr::sig::{KeyType, XfrPublicKey, XfrPublicKeyInner, XfrSignature}, + noah::keys::{ + KeyType, PublicKey as XfrPublicKey, PublicKeyInner as XfrPublicKeyInner, + Signature as XfrSignature, + }, noah_algebra::serialization::NoahFromToBytes, primitive_types::{H160, H256}, ruc::{d, eg, RucResult}, @@ -94,7 +98,7 @@ impl From for Address32 { XfrPublicKeyInner::Secp256k1(pk) => { bytes.copy_from_slice(&keccak_256(&pk.serialize_compressed())); } - XfrPublicKeyInner::Address(pk) => { + XfrPublicKeyInner::EthAddress(pk) => { bytes[0..20].copy_from_slice(pk); } } @@ -275,16 +279,6 @@ impl Verify for MultiSignature { _ => false, } } - XfrSignature::Address(..) => { - let mut bytes = [0u8; 34]; - bytes[0] = KeyType::Address.to_byte(); - let signer_bytes: &[u8; 32] = signer.as_ref(); - bytes[1..21].copy_from_slice(&signer_bytes[0..20]); - match XfrPublicKey::noah_from_bytes(&bytes) { - Ok(who) => sig.verify(msg, &who), - _ => false, - } - } XfrSignature::Secp256k1(sign, rec) => { let msg_hashed = keccak_256(msg); let message = Message::parse(&msg_hashed); @@ -332,7 +326,7 @@ pub enum MultiSigner { impl Default for MultiSigner { fn default() -> Self { - Self::Xfr(Default::default()) + Self::Xfr(PublicKey::default_ed25519()) } } @@ -473,14 +467,14 @@ pub type Address = <::Signer as IdentifyAccount>::AccountId #[cfg(test)] mod tests { use super::*; - use noah::xfr::sig::XfrKeyPair; + use noah::keys::KeyPair as XfrKeyPair; use rand_chacha::rand_core::SeedableRng; use rand_chacha::ChaChaRng; #[test] fn xfr_sign_verify_work() { let mut prng = ChaChaRng::from_entropy(); - let alice = XfrKeyPair::generate(&mut prng); + let alice = XfrKeyPair::generate_ed25519(&mut prng); let sig = alice.get_sk_ref().sign(b"hello").unwrap(); let signer = MultiSigner::from(alice.get_pk()); let sig = MultiSignature::from(sig); @@ -505,8 +499,8 @@ mod tests { #[test] fn test_address_32() { let mut prng = ChaChaRng::from_entropy(); - let keypair = XfrKeyPair::generate(&mut prng); - let pubkey = keypair.pub_key; + let keypair = XfrKeyPair::generate_ed25519(&mut prng); + let pubkey = keypair.get_pk(); let address_32 = Address32::from(pubkey); let address_str = address_32.to_string(); diff --git a/src/components/finutils/Cargo.toml b/src/components/finutils/Cargo.toml index 01e29b35b..dd23d5eeb 100644 --- a/src/components/finutils/Cargo.toml +++ b/src/components/finutils/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" attohttpc = { version = "0.23", default-features = false, features = ["compress", "json", "tls-rustls"] } base64 = "0.13" clap = { version = "2.33.3", features = ["yaml"] } -curve25519-dalek = { git = "https://github.com/FindoraNetwork/curve25519-dalek", tag = "v3.2.0-f" } +curve25519-dalek = { package = "noah-curve25519-dalek", version = "4.0.0", default-features = false, features = ['serde'] } digest = '0.10' hex = "0.4.2" lazy_static = "1.4.0" @@ -25,9 +25,9 @@ tokio = "1.10.1" wasm-bindgen = { version = "=0.2.73", features = ["serde-serialize"] } getrandom = "0.2" -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } -noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } +noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } ruc = "1.0" rucv3 = { package = "ruc", version = "3.0" } diff --git a/src/components/finutils/src/bins/cfg_generator.rs b/src/components/finutils/src/bins/cfg_generator.rs index 66bb1a0b5..32c0df7be 100644 --- a/src/components/finutils/src/bins/cfg_generator.rs +++ b/src/components/finutils/src/bins/cfg_generator.rs @@ -19,7 +19,7 @@ fn gen() -> Result<()> { wallet::generate_mnemonic_custom(24, "en") .c(d!()) .and_then(|m| { - wallet::restore_keypair_from_mnemonic_default(&m) + wallet::restore_keypair_from_mnemonic_ed25519(&m) .c(d!()) .map(|k| (m, wallet::public_key_to_bech32(k.get_pk_ref()), k)) }) diff --git a/src/components/finutils/src/bins/fn.rs b/src/components/finutils/src/bins/fn.rs index 75240bbe3..54d86ec43 100644 --- a/src/components/finutils/src/bins/fn.rs +++ b/src/components/finutils/src/bins/fn.rs @@ -34,14 +34,11 @@ use { data_model::{AssetTypeCode, ASSET_TYPE_FRA, FRA_DECIMALS}, staking::{StakerMemo, VALIDATORS_MIN}, }, - noah::anon_xfr::keys::AXfrKeyPair, - noah::anon_xfr::structs::OpenAnonAssetRecordBuilder, - rand_chacha::ChaChaRng, - rand_core::SeedableRng, + noah::{ + anon_xfr::structs::OpenAnonAssetRecordBuilder, keys::SecretKey as XfrSecretKey, + }, ruc::*, - serde::{Deserialize, Serialize}, - std::fs::File, - std::{borrow::Borrow, fmt, fs}, + std::{fmt, fs}, }; fn main() { @@ -62,12 +59,12 @@ fn run() -> Result<()> { if matches.is_present("version") { println!("{}", env!("VERGEN_SHA")); } else if let Some(m) = matches.subcommand_matches("genkey") { - let is_address_fra = m.is_present("fra-address"); - common::gen_key_and_print(is_address_fra); + let is_address_eth = m.is_present("eth-address"); + common::gen_key_and_print(is_address_eth); } else if let Some(m) = matches.subcommand_matches("wallet") { if m.is_present("create") { - let is_address_fra = m.is_present("fra-address"); - common::gen_key_and_print(is_address_fra); + let is_address_eth = m.is_present("eth-address"); + common::gen_key_and_print(is_address_eth); } else if m.is_present("show") { let seckey = match m.value_of("seckey") { Some(path) => { @@ -75,7 +72,7 @@ fn run() -> Result<()> { } None => None, }; - let is_address_fra = m.is_present("fra-address"); + let is_address_eth = m.is_present("eth-address"); // FRA asset is the default case let asset = if let Some(code) = m.value_of("asset") { @@ -86,7 +83,7 @@ fn run() -> Result<()> { } else { None }; - common::show_account(seckey.as_deref(), asset, is_address_fra).c(d!())?; + common::show_account(seckey.as_deref(), asset, is_address_eth).c(d!())?; } else { println!("{}", m.usage()); } @@ -100,18 +97,18 @@ fn run() -> Result<()> { let amount = m.value_of("amount"); let validator = m.value_of("validator"); let show_info = m.is_present("info"); - let is_address_fra = m.is_present("fra-address"); + let is_address_eth = m.is_present("eth-address"); if amount.is_some() && validator.is_some() { common::delegate( seckey.as_deref(), amount.unwrap().parse::().c(d!())?, validator.unwrap(), - is_address_fra, + is_address_eth, ) .c(d!())?; } else if show_info { - common::show_delegations(seckey.as_deref(), is_address_fra).c(d!())?; + common::show_delegations(seckey.as_deref(), is_address_eth).c(d!())?; } else { println!("{}", m.usage()); } @@ -124,7 +121,7 @@ fn run() -> Result<()> { }; let amount = m.value_of("amount"); let validator = m.value_of("validator"); - let is_address_fra = m.is_present("fra-address"); + let is_address_eth = m.is_present("eth-address"); if (amount.is_none() && validator.is_some()) || (amount.is_some() && validator.is_none()) { @@ -136,7 +133,7 @@ fn run() -> Result<()> { } else { None }; - common::undelegate(seckey.as_deref(), param, is_address_fra).c(d!())?; + common::undelegate(seckey.as_deref(), param, is_address_eth).c(d!())?; } else if let Some(m) = matches.subcommand_matches("asset") { if m.is_present("create") { let memo = m.value_of("memo"); @@ -145,7 +142,7 @@ fn run() -> Result<()> { return Ok(()); } let transferable = m.is_present("transferable"); - let is_address_fra = m.is_present("fra-address"); + let is_address_eth = m.is_present("eth-address"); let decimal = if let Some(num) = m.value_of("decimal") { num.parse::() @@ -168,7 +165,7 @@ fn run() -> Result<()> { max_units, transferable, token_code, - is_address_fra, + is_address_eth, ) .c(d!())?; } else if m.is_present("show") { @@ -197,14 +194,14 @@ fn run() -> Result<()> { .parse::() .c(d!("amount should be a 64-bits unsigned integer"))?; let hidden = m.is_present("hidden"); - let is_address_fra = m.is_present("fra-address"); + let is_address_eth = m.is_present("eth-address"); common::issue_asset( seckey.as_deref(), code.unwrap(), amount, hidden, - is_address_fra, + is_address_eth, ) .c(d!())?; } else { @@ -240,7 +237,7 @@ fn run() -> Result<()> { } } }; - let is_address_fra = m.is_present("fra-address"); + let is_address_eth = m.is_present("eth-address"); let cr = m.value_of("commission-rate"); if vm.is_none() && cr.is_none() { @@ -249,7 +246,7 @@ fn run() -> Result<()> { "Tips: to update the information of your node, please specify commission-rate or memo" ); } else { - common::staker_update(cr, vm, is_address_fra).c(d!())?; + common::staker_update(cr, vm, is_address_eth).c(d!())?; } } else if let Some(m) = matches.subcommand_matches("stake") { let am = m.value_of("amount"); @@ -261,7 +258,7 @@ fn run() -> Result<()> { None => None, }; let td_addr = m.value_of("validator-td-addr"); - let is_address_fra = m.is_present("fra-address"); + let is_address_eth = m.is_present("eth-address"); if am.is_none() { println!("{}", m.usage()); } else { @@ -269,7 +266,7 @@ fn run() -> Result<()> { am.unwrap(), staker.as_deref(), td_addr, - is_address_fra, + is_address_eth, ) .c(d!())?; } @@ -277,14 +274,14 @@ fn run() -> Result<()> { let cr = m.value_of("commission-rate"); let vm = m.value_of("validator-memo"); let force = m.is_present("force"); - let is_address_fra = m.is_present("fra-address"); + let is_address_eth = m.is_present("eth-address"); if am.is_none() || cr.is_none() { println!("{}", m.usage()); println!( "Tips: if you want to raise the power of your node, please use `fn stake --append [OPTIONS]`" ); } else { - common::stake(am.unwrap(), cr.unwrap(), vm, force, is_address_fra) + common::stake(am.unwrap(), cr.unwrap(), vm, force, is_address_eth) .c(d!())?; } } @@ -297,22 +294,22 @@ fn run() -> Result<()> { None => None, }; let td_addr = m.value_of("validator-td-addr"); - let is_address_fra = m.is_present("fra-address"); - common::unstake(am, staker.as_deref(), td_addr, is_address_fra).c(d!())?; + let is_address_eth = m.is_present("eth-address"); + common::unstake(am, staker.as_deref(), td_addr, is_address_eth).c(d!())?; } else if let Some(m) = matches.subcommand_matches("claim") { let am = m.value_of("amount"); - let is_address_fra = m.is_present("fra-address"); + let is_address_eth = m.is_present("eth-address"); let seckey = match m.value_of("seckey") { Some(path) => { Some(fs::read_to_string(path).c(d!("Failed to read seckey file"))?) } None => None, }; - common::claim(am, seckey.as_deref(), is_address_fra).c(d!())?; + common::claim(am, seckey.as_deref(), is_address_eth).c(d!())?; } else if let Some(m) = matches.subcommand_matches("show") { let basic = m.is_present("basic"); - let is_address_fra = m.is_present("fra-address"); - common::show(basic, is_address_fra).c(d!())?; + let is_address_eth = m.is_present("eth-address"); + common::show(basic, is_address_eth).c(d!())?; } else if let Some(m) = matches.subcommand_matches("setup") { let sa = m.value_of("serv-addr"); let om = m.value_of("owner-mnemonic-path"); @@ -335,7 +332,7 @@ fn run() -> Result<()> { }) })?; let am = m.value_of("amount"); - let is_address_fra = m.is_present("fra-address"); + let is_address_eth = m.is_present("eth-address"); if am.is_none() { println!("{}", m.usage()); @@ -352,7 +349,7 @@ fn run() -> Result<()> { am.unwrap(), m.is_present("confidential-amount"), m.is_present("confidential-type"), - is_address_fra, + is_address_eth, ) .c(d!())?; } @@ -386,7 +383,7 @@ fn run() -> Result<()> { }) })?; let am = m.value_of("amount"); - let is_address_fra = m.is_present("fra-address"); + let is_address_eth = m.is_present("eth-address"); if am.is_none() || t.is_empty() { println!("{}", m.usage()); @@ -398,7 +395,7 @@ fn run() -> Result<()> { am.unwrap(), m.is_present("confidential-amount"), m.is_present("confidential-type"), - is_address_fra, + is_address_eth, ) .c(d!())?; } @@ -414,7 +411,7 @@ fn run() -> Result<()> { } else if let Some(m) = matches.subcommand_matches("account") { let address = m.value_of("addr"); let sec_key = m.value_of("sec-key"); - let is_address_fra = m.is_present("fra-address"); + let is_address_eth = m.is_present("eth-address"); // FRA asset is the default case let asset = if let Some(code) = m.value_of("asset") { @@ -427,48 +424,46 @@ fn run() -> Result<()> { }; if sec_key.is_some() { //Asset defaults to fra - common::show_account(sec_key, asset, is_address_fra).c(d!())?; + common::show_account(sec_key, asset, is_address_eth).c(d!())?; } if address.is_some() { - let (account, info) = contract_account_info(address, is_address_fra)?; - println!("AccountId: {account}\n{info:#?}\n",); + let (account, info) = contract_account_info(address, is_address_eth)?; + println!("AccountId: {account}\n{info:#?}\n"); } } else if let Some(m) = matches.subcommand_matches("contract-deposit") { let amount = m.value_of("amount").c(d!())?; let address = m.value_of("addr"); let asset = m.value_of("asset"); let lowlevel_data = m.value_of("lowlevel-data"); - let is_address_fra = m.is_present("fra-address"); + let is_address_eth = m.is_present("eth-address"); transfer_to_account( amount.parse::().c(d!())?, asset, address, lowlevel_data, - is_address_fra, + is_address_eth, )? } else if let Some(m) = matches.subcommand_matches("contract-withdraw") { let amount = m.value_of("amount").c(d!())?; let address = m.value_of("addr"); let eth_key = m.value_of("eth-key"); - let is_address_fra = m.is_present("fra-address"); + let is_address_eth = m.is_present("eth-address"); transfer_from_account( amount.parse::().c(d!())?, address, eth_key, - is_address_fra, + is_address_eth, )? } else if let Some(m) = matches.subcommand_matches("convert-bar-to-abar") { // sender Xfr secret key - let f = read_file_path(m.value_of("from-seckey")).c(d!())?; - let owner_sk = f.as_ref(); + let owner_sk = read_file_path(m.value_of("from-seckey")).c(d!())?; - // receiver AXfr secret key parsed & the receiver Axfr address - let anon_keys = parse_anon_key_from_path(m.value_of("anon-keys"))?; - let target_addr = anon_keys.pub_key; + // the receiver Xfr address + let target_addr = m.value_of("to-address").c(d!())?; // The TxoSID to be spent for conversion to ABAR(Anon Blind Asset Record) let txo_sid = m.value_of("txo-sid"); - let is_address_fra = m.is_present("fra-address"); + let is_address_eth = m.is_present("eth-address"); if txo_sid.is_none() { println!("{}", m.usage()); @@ -479,7 +474,7 @@ fn run() -> Result<()> { owner_sk, target_addr, txo_sid.unwrap(), - is_address_fra, + is_address_eth, ) .c(d!())?; @@ -501,9 +496,10 @@ fn run() -> Result<()> { .expect("commitment write failed"); } } else if let Some(m) = matches.subcommand_matches("convert-abar-to-bar") { - // get anon keys for conversion - let anon_keys = parse_anon_key_from_path(m.value_of("anon-keys"))?; - let spend_key = anon_keys.spend_key; + let is_address_eth = false; + // sender Xfr secret key + let owner_sk = read_file_path(m.value_of("from-seckey")).c(d!())?; + // get the BAR receiver address let to = m .value_of("to-pubkey") @@ -523,66 +519,80 @@ fn run() -> Result<()> { } else { // Build transaction and submit to network common::convert_abar2bar( - spend_key, + owner_sk, commitment.unwrap(), &to, m.is_present("confidential-amount"), m.is_present("confidential-type"), + is_address_eth, ) .c(d!())?; } - } else if let Some(m) = matches.subcommand_matches("gen-anon-keys") { - let mut prng = ChaChaRng::from_entropy(); - let keypair = AXfrKeyPair::generate(&mut prng); - - let keys = AnonKeys { - spend_key: wallet::anon_secret_key_to_base64(&keypair), - pub_key: wallet::anon_public_key_to_base64(&keypair.get_public_key()), - }; - - if let Some(path) = m.value_of("file-path") { - serde_json::to_writer_pretty(&File::create(path).c(d!())?, &keys).c(d!())?; - println!("Keys saved to file: {path}",); - } - - // print keys to terminal - println!("Keys :\n {}", serde_json::to_string_pretty(&keys).unwrap()); } else if let Some(m) = matches.subcommand_matches("owned-abars") { - // Generates a list of owned Abars (both spent and unspent) - let anon_keys = parse_anon_key_from_path(m.value_of("anon-keys"))?; - let spend_key = - wallet::anon_secret_key_from_base64(anon_keys.spend_key.as_str()).c(d!())?; + let is_address_eth = false; + // sender Xfr secret key + let owner_sk = read_file_path(m.value_of("from-seckey")).c(d!())?; + // parse sender XfrSecretKey or generate from Mnemonic setup with wallet + let from = match owner_sk { + Some(str) => ruc::info!(serde_json::from_str::(&format!( + "\"{}\"", + str + ))) + .c(d!())? + .into_keypair(), + None => get_keypair(is_address_eth).c(d!())?, + }; let commitments_list = m .value_of("commitments") .unwrap_or_else(|| panic!("Commitment list missing \n {}", m.usage())); - common::get_owned_abars(spend_key, commitments_list)?; + common::get_owned_abars(from, commitments_list)?; } else if let Some(m) = matches.subcommand_matches("anon-balance") { + let is_address_eth = false; // Generates a list of owned Abars (both spent and unspent) - let anon_keys = parse_anon_key_from_path(m.value_of("anon-keys"))?; - let spend_key = - wallet::anon_secret_key_from_base64(anon_keys.spend_key.as_str()).c(d!())?; + // sender Xfr secret key + let owner_sk = read_file_path(m.value_of("from-seckey")).c(d!())?; + // parse sender XfrSecretKey or generate from Mnemonic setup with wallet + let from = match owner_sk { + Some(str) => ruc::info!(serde_json::from_str::(&format!( + "\"{}\"", + str + ))) + .c(d!(str))? + .into_keypair(), + None => get_keypair(is_address_eth).c(d!())?, + }; let asset = m.value_of("asset"); let commitments_list = m .value_of("commitments") .unwrap_or_else(|| panic!("Commitment list missing \n {}", m.usage())); - common::anon_balance(spend_key, commitments_list, asset)?; + common::anon_balance(from, commitments_list, asset)?; } else if let Some(m) = matches.subcommand_matches("owned-open-abars") { - let anon_keys = parse_anon_key_from_path(m.value_of("anon-keys"))?; + let is_address_eth = false; + // sender Xfr secret key + let owner_sk = read_file_path(m.value_of("from-seckey")).c(d!())?; + // parse sender XfrSecretKey or generate from Mnemonic setup with wallet + let from = match owner_sk { + Some(str) => ruc::info!(serde_json::from_str::(&format!( + "\"{}\"", + str + ))) + .c(d!())? + .into_keypair(), + None => get_keypair(is_address_eth).c(d!())?, + }; let commitment_str = m.value_of("commitment"); // create derived public key let commitment = wallet::commitment_from_base58(commitment_str.unwrap())?; - let spend_key = - wallet::anon_secret_key_from_base64(anon_keys.spend_key.as_str()).c(d!())?; // get results from query server and print let (uid, abar) = utils::get_owned_abar(&commitment).c(d!())?; let memo = utils::get_abar_memo(&uid).unwrap().unwrap(); - let oabar = OpenAnonAssetRecordBuilder::from_abar(&abar, memo, &spend_key) + let oabar = OpenAnonAssetRecordBuilder::from_abar(&abar, memo, &from) .unwrap() .build() .unwrap(); @@ -594,12 +604,12 @@ fn run() -> Result<()> { } else if let Some(m) = matches.subcommand_matches("owned-utxos") { // All assets are shown in the default case let asset = m.value_of("asset"); - let is_address_fra = m.is_present("fra-address"); + let is_address_eth = m.is_present("eth-address"); // fetch filtered list by asset - let list = common::get_owned_utxos(asset, is_address_fra)?; + let list = common::get_owned_utxos(asset, is_address_eth)?; let pk = wallet::public_key_to_base64( - get_keypair(is_address_fra).unwrap().pub_key.borrow(), + get_keypair(is_address_eth).unwrap().get_pk_ref(), ); // Print UTXO table @@ -621,44 +631,41 @@ fn run() -> Result<()> { println!("{0: <8} | {1: <18} | {2: <45} ", a.0, amt, at); } } else if let Some(m) = matches.subcommand_matches("anon-transfer") { - // get anon keys of sender - let anon_keys = parse_anon_key_from_path(m.value_of("anon-keys"))?; - let secret_key = anon_keys.spend_key; + let is_eth_address = false; + // sender Xfr secret key + let owner_sk = read_file_path(m.value_of("from-seckey")).c(d!())?; // get commitments let commitment = m.value_of("commitment"); let fee_commitment = m.value_of("fra-commitment"); // get receiver keys and amount - let to_axfr_public_key = m.value_of("to-axfr-public-key"); + let to_address = m.value_of("to-address"); let amount = m.value_of("amount"); - if commitment.is_none() || to_axfr_public_key.is_none() || amount.is_none() { + if commitment.is_none() || to_address.is_none() || amount.is_none() { println!("{}", m.usage()); } else { // build transaction and submit common::gen_anon_transfer_op( - secret_key, + owner_sk, commitment.unwrap(), fee_commitment, amount.unwrap(), - to_axfr_public_key.unwrap(), + to_address.unwrap(), + is_eth_address, ) .c(d!())?; } } else if let Some(m) = matches.subcommand_matches("anon-transfer-batch") { - // get anon keys of sender - let anon_keys = parse_anon_key_from_path(m.value_of("anon-keys"))?; - let secret_key = - wallet::anon_secret_key_from_base64(anon_keys.spend_key.as_str()).c(d!())?; + // sender Xfr secret key + let owner_sk = read_file_path(m.value_of("from-seckey")).c(d!())?; - let to_axfr_public_keys = m - .value_of("to-axfr-public-key-file") - .c(d!()) - .and_then(|f| { + let to_axfr_public_keys = + m.value_of("to-address-file").c(d!()).and_then(|f| { fs::read_to_string(f).c(d!()).and_then(|pks| { pks.lines() - .map(|pk| wallet::anon_public_key_from_base64(pk.trim())) + .map(|pk| wallet::public_key_from_bech32(pk.trim())) .collect::>>() .c(d!("invalid file")) }) @@ -698,11 +705,12 @@ fn run() -> Result<()> { println!("{}", m.usage()); } else { common::gen_oabar_add_op_x( - secret_key, + owner_sk, to_axfr_public_keys, commitments, amounts, assets, + true, ) .c(d!())?; } @@ -716,29 +724,32 @@ fn run() -> Result<()> { println!("{:?}", serde_json::to_string_pretty(&mt_leaf_info)); } } else if let Some(m) = matches.subcommand_matches("check-abar-status") { - let anon_keys = match m.value_of("anon-keys") { - Some(path) => { - let f = - fs::read_to_string(path).c(d!("Failed to read anon-keys file"))?; - serde_json::from_str::(f.as_str()).c(d!())? - } - None => return Err(eg!("path for anon-keys file not found")), + let is_address_eth = false; + // sender Xfr secret key + let owner_sk = read_file_path(m.value_of("from-seckey")).c(d!())?; + // parse sender XfrSecretKey or generate from Mnemonic setup with wallet + let from = match owner_sk { + Some(str) => ruc::info!(serde_json::from_str::(&format!( + "\"{}\"", + str + ))) + .c(d!())? + .into_keypair(), + None => get_keypair(is_address_eth).c(d!())?, }; + let commitment_str = m.value_of("commitment"); let commitment = wallet::commitment_from_base58(commitment_str.unwrap())?; - let spend_key = - wallet::anon_secret_key_from_base64(anon_keys.spend_key.as_str()).c(d!())?; - let abar = utils::get_owned_abar(&commitment).c(d!())?; - common::check_abar_status(spend_key, abar).c(d!())?; + common::check_abar_status(from, abar).c(d!())?; } else if let Some(m) = matches.subcommand_matches("replace_staker") { let target = m .value_of("target") .c(d!()) .and_then(wallet::public_key_from_base64)?; - let is_address_fra = m.is_present("fra-address"); + let is_address_eth = m.is_present("eth-address"); // let new_td_addr_pk = if let Some(new_td_address_str) = m.value_of("td_address") { // let new_td_address = hex::decode(new_td_address_str) // .c(d!("`td_address` is invalid hex. "))?; @@ -761,7 +772,7 @@ fn run() -> Result<()> { // } else { // None // }; - common::replace_staker(target, None, is_address_fra)?; + common::replace_staker(target, None, is_address_eth)?; } else if let Some(m) = matches.subcommand_matches("dev") { #[cfg(not(target_arch = "wasm32"))] { @@ -1118,15 +1129,6 @@ fn read_file_path(path: Option<&str>) -> Result> { }) } -fn parse_anon_key_from_path(path: Option<&str>) -> Result { - let f = read_file_path(path).c(d!())?; - if f.is_none() { - return Err(eg!("Anon keypair path not found")); - } - - serde_json::from_str::(f.unwrap().as_str()).c(d!()) -} - fn tip_fail(e: impl fmt::Display) { eprintln!("\n\x1b[31;01mFAIL !!!\x1b[00m"); eprintln!( @@ -1140,9 +1142,3 @@ fn tip_success() { "\x1b[35;01mNote\x1b[01m:\n\tYour operations has been executed without local error,\n\tbut the final result may need an asynchronous query.\x1b[00m" ); } - -#[derive(Clone, Deserialize, Serialize)] -pub struct AnonKeys { - pub spend_key: String, - pub pub_key: String, -} diff --git a/src/components/finutils/src/bins/fn.yml b/src/components/finutils/src/bins/fn.yml index 45c468725..8fa27a158 100644 --- a/src/components/finutils/src/bins/fn.yml +++ b/src/components/finutils/src/bins/fn.yml @@ -12,9 +12,9 @@ subcommands: - genkey: about: Generate a random Findora public key/private key Pair args: - - fra-address: - help: if the fra address version of wallet is used - long: fra-address + - eth-address: + help: if the eth address version of wallet is used + long: eth-address - show: about: View Validator status and accumulated rewards args: @@ -22,9 +22,9 @@ subcommands: help: show basic account info short: b long: basic - - fra-address: - help: if the fra address version of wallet is used - long: fra-address + - eth-address: + help: if the eth address version of wallet is used + long: eth-address - setup: about: Setup environment variables for staking transactions args: @@ -87,9 +87,9 @@ subcommands: - force: help: ignore warning and stake FRAs to your target node long: force - - fra-address: - help: if the fra address version of wallet is used - long: fra-address + - eth-address: + help: if the eth address version of wallet is used + long: eth-address groups: - staking-flags: args: @@ -129,9 +129,9 @@ subcommands: long: validator-memo-logo takes_value: true value_name: Logo - - fra-address: - help: if the fra address version of wallet is used - long: fra-address + - eth-address: + help: if the eth address version of wallet is used + long: eth-address - unstake: about: Unstake tokens (i.e. unbond tokens) from a Validator args: @@ -153,9 +153,9 @@ subcommands: long: amount takes_value: true value_name: Amount - - fra-address: - help: if the fra address version of wallet is used - long: fra-address + - eth-address: + help: if the eth address version of wallet is used + long: eth-address - claim: about: Claim accumulated FRA rewards args: @@ -170,9 +170,9 @@ subcommands: long: seckey takes_value: true value_name: SECRET KEY - - fra-address: - help: if the fra address version of wallet is used - long: fra-address + - eth-address: + help: if the eth address version of wallet is used + long: eth-address - delegate: about: Delegating operations args: @@ -198,9 +198,9 @@ subcommands: conflicts_with: - amount - validator - - fra-address: - help: if the fra address version of wallet is used - long: fra-address + - eth-address: + help: if the eth address version of wallet is used + long: eth-address - undelegate: about: Undelegating operations args: @@ -220,9 +220,9 @@ subcommands: long: validator takes_value: true value_name: VALIDATOR ADDRESS - - fra-address: - help: if the fra address version of wallet is used - long: fra-address + - eth-address: + help: if the eth address version of wallet is used + long: eth-address - transfer: about: Transfer tokens from one address to another args: @@ -266,9 +266,9 @@ subcommands: - confidential-type: help: mask the asset type sent on the transaction log long: confidential-type - - fra-address: - help: if the fra address version of wallet is used - long: fra-address + - eth-address: + help: if the eth address version of wallet is used + long: eth-address - transfer-batch: about: Transfer tokens from one address to many others args: @@ -303,9 +303,9 @@ subcommands: - confidential-type: help: mask the asset type sent on the transaction log long: confidential-type - - fra-address: - help: if the fra address version of wallet is used - long: fra-address + - eth-address: + help: if the eth address version of wallet is used + long: eth-address - wallet: about: manipulates a findora wallet args: @@ -332,9 +332,9 @@ subcommands: value_name: SECRET KEY conflicts_with: - create - - fra-address: - help: if the fra address version of wallet is used - long: fra-address + - eth-address: + help: if the eth address version of wallet is used + long: eth-address - asset: about: manipulate custom asset groups: @@ -433,9 +433,9 @@ subcommands: - hidden: help: hidden asset amount when issuing asset on ledger long: hidden - - fra-address: - help: if the fra address version of wallet is used - long: fra-address + - eth-address: + help: if the eth address version of wallet is used + long: eth-address #- history # about: query operating history # args: @@ -475,9 +475,9 @@ subcommands: takes_value: true value_name: ASSET allow_hyphen_values: true - - fra-address: - help: if the fra address version of wallet is used - long: fra-address + - eth-address: + help: if the eth address version of wallet is used + long: eth-address - contract-deposit: about: Transfer FRA from a Findora account to the specified Ethereum address args: @@ -509,9 +509,9 @@ subcommands: takes_value: true value_name: LOWLEVEL required: false - - fra-address: - help: if the fra address version of wallet is used - long: fra-address + - eth-address: + help: if the eth address version of wallet is used + long: eth-address - contract-withdraw: about: Transfer FRA from an Ethereum address to the specified Findora account args: @@ -535,20 +535,11 @@ subcommands: takes_value: true value_name: MNEMONIC required: true - - fra-address: - help: if the fra address version of wallet is used - long: fra-address + - eth-address: + help: if the eth address version of wallet is used + long: eth-address - gen-eth-key: about: Generate an Ethereum address - - gen-anon-keys: - about: Generate Anon keys - args: - - file-path: - help: Path of file to save the anon keys json - short: f - long: file-path - takes_value: true - value_name: File Path - owned-abars: about: Get Anon UTXOs for a keypair use commitment args: @@ -560,13 +551,12 @@ subcommands: value_name: COMMITMENT required: true allow_hyphen_values: true - - anon-keys: - help: Anon keys file path of the sender - short: a - long: anon-keys + - from-seckey: + help: Xfr secret key file path of receiver + short: s + long: from-seckey takes_value: true - value_name: ANON KEYS PATH - required: true + value_name: SECRET KEY PATH - asset: help: code of asset, such as `fra` long: asset @@ -584,12 +574,12 @@ subcommands: value_name: COMMITMENT required: true allow_hyphen_values: true - - anon-keys: - help: Anon keys file path of the sender - short: a - long: anon-keys + - from-seckey: + help: Xfr secret key file path of converter + short: s + long: from-seckey takes_value: true - value_name: ANON KEYS PATH + value_name: SECRET KEY PATH required: true - asset: help: code of asset, such as `fra` @@ -608,12 +598,12 @@ subcommands: value_name: COMMITMENT required: true allow_hyphen_values: true - - anon-keys: - help: Anon keys file path of the sender - short: a - long: anon-keys + - from-seckey: + help: Xfr secret key file path of converter + short: s + long: from-seckey takes_value: true - value_name: ANON KEYS PATH + value_name: SECRET KEY PATH required: true - owned-utxos: about: List owned UTXOs for a public key @@ -624,24 +614,24 @@ subcommands: takes_value: true value_name: ASSET allow_hyphen_values: true - - fra-address: - help: if the fra address version of wallet is used - long: fra-address + - eth-address: + help: if the eth address version of wallet is used + long: eth-address - convert-bar-to-abar: about: Convert a BAR to Anon BAR for yourself args: - from-seckey: help: Xfr secret key file path of converter short: s - long: xfr-secretkey + long: from-seckey takes_value: true value_name: SECRET KEY PATH - - anon-keys: - help: Anon keys file path of converter + - to-address: + help: bech32 address of receiver keys short: a - long: anon-keys + long: to-address takes_value: true - value_name: ANON KEYS PATH + value_name: TO ADDRESS required: true - txo-sid: help: Txo Sid of input to convert @@ -650,19 +640,18 @@ subcommands: takes_value: true value_name: TXO SID required: true - - fra-address: - help: if the fra address version of wallet is used - long: fra-address + - eth-address: + help: if the eth address version of wallet is used + long: eth-address - convert-abar-to-bar: about: Convert a ABAR to BAR args: - - anon-keys: - help: Anon keys file path of the sender - short: a - long: anon-keys + - from-seckey: + help: Xfr secret key file path of converter + short: s + long: from-seckey takes_value: true - value_name: ANON KEYS PATH - required: true + value_name: SECRET KEY PATH - commitment: help: Commitment for the input Anon BAR short: c @@ -695,13 +684,12 @@ subcommands: - anon-transfer: about: Perform Anonymous Transfer args: - - anon-keys: - help: Anon keys file path of the sender - short: a - long: anon-keys + - from-seckey: + help: Xfr secret key file path of sender + short: s + long: from-seckey takes_value: true - value_name: ANON KEYS PATH - required: true + value_name: SECRET KEY PATH - commitment: help: Commitment for the input Anon BAR short: c @@ -716,11 +704,11 @@ subcommands: takes_value: true value_name: FRA COMMITMENT allow_hyphen_values: true - - to-axfr-public-key: - help: Axfr public key of the receiver - long: to-axfr-public-key + - to-address: + help: Address of the receiver + long: to-address takes_value: true - value_name: PUBLIC KEY + value_name: ADDRESS required: true allow_hyphen_values: true - amount: @@ -733,12 +721,12 @@ subcommands: - anon-transfer-batch: about: Anonymous Transfer of tokens from multiple inputs to multiple outputs args: - - anon-keys: - help: Anon keys file path of the sender + - from-seckey: + help: Xfr secret key file path of sender short: s - long: anon-keys + long: from-seckey takes_value: true - value_name: SECRET KEY + value_name: SECRET KEY PATH required: true - commitment-file: help: Commitments for the input Anon BARs @@ -747,9 +735,9 @@ subcommands: takes_value: true value_name: COMMITMENT required: true - - to-axfr-public-key-file: - help: Axfr public keys of the receivers - long: to-axfr-public-key-file + - to-address-file: + help: Xfr public keys of the receivers + long: to-address-file takes_value: true value_name: PUBLIC KEY required: true @@ -788,12 +776,12 @@ subcommands: value_name: COMMITMENT required: true allow_hyphen_values: true - - anon-keys: - help: Anon keys file path of the sender - short: a - long: anon-keys + - from-seckey: + help: Xfr secret key file path of sender + short: s + long: from-seckey takes_value: true - value_name: ANON KEYS PATH + value_name: SECRET KEY PATH required: true - replace_staker: about: Replace the staker of the validator with target address @@ -819,9 +807,9 @@ subcommands: value_name: TENDERMINT PUBKEY required: false allow_hyphen_values: true - - fra-address: - help: if the fra address version of wallet is used - long: fra-address + - eth-address: + help: if the eth address version of wallet is used + long: eth-address - dev: about: Manage development clusters on your localhost args: diff --git a/src/components/finutils/src/bins/stt/init/mod.rs b/src/components/finutils/src/bins/stt/init/mod.rs index d0721d999..8f25e7795 100644 --- a/src/components/finutils/src/bins/stt/init/mod.rs +++ b/src/components/finutils/src/bins/stt/init/mod.rs @@ -39,8 +39,8 @@ pub fn init( Ok(()) } else { let root_kp = - wallet::restore_keypair_from_mnemonic_default(ROOT_MNEMONIC).c(d!())?; - println!(">>> Block interval: {interval} seconds",); + wallet::restore_keypair_from_mnemonic_ed25519(ROOT_MNEMONIC).c(d!())?; + println!(">>> Block interval: {interval} seconds"); println!(">>> Define and issue FRA ..."); common::utils::send_tx(&fra_gen_initial_tx(&root_kp)).c(d!())?; diff --git a/src/components/finutils/src/bins/stt/stt.rs b/src/components/finutils/src/bins/stt/stt.rs index d757d8084..38e220bb2 100644 --- a/src/components/finutils/src/bins/stt/stt.rs +++ b/src/components/finutils/src/bins/stt/stt.rs @@ -26,7 +26,7 @@ use { }, utils::fra_gen_initial_tx, }, - noah::xfr::sig::{XfrKeyPair, XfrPublicKey}, + noah::keys::{KeyPair as XfrKeyPair, PublicKey as XfrPublicKey}, ruc::*, serde::Serialize, std::{collections::BTreeMap, env}, @@ -36,7 +36,7 @@ lazy_static! { static ref USER_LIST: BTreeMap = gen_user_list(); static ref VALIDATOR_LIST: BTreeMap = gen_valiator_list(); static ref ROOT_KP: XfrKeyPair = - pnk!(wallet::restore_keypair_from_mnemonic_default(ROOT_MNEMONIC)); + pnk!(wallet::restore_keypair_from_mnemonic_ed25519(ROOT_MNEMONIC)); } const ROOT_MNEMONIC: &str = "zoo nerve assault talk depend approve mercy surge bicycle ridge dismiss satoshi boring opera next fat cinnamon valley office actor above spray alcohol giant"; @@ -239,7 +239,7 @@ mod issue { asset_record::{build_blind_asset_record, AssetRecordType}, structs::AssetRecordTemplate, }, - noah_crypto::basic::pedersen_comm::PedersenCommitmentRistretto, + noah_algebra::ristretto::PedersenCommitmentRistretto, rand_chacha::rand_core::SeedableRng, rand_chacha::ChaChaRng, }; @@ -252,7 +252,7 @@ mod issue { fn gen_issue_tx() -> Result { let root_kp = - wallet::restore_keypair_from_mnemonic_default(ROOT_MNEMONIC).c(d!())?; + wallet::restore_keypair_from_mnemonic_ed25519(ROOT_MNEMONIC).c(d!())?; let mut builder = common::utils::new_tx_builder().c(d!())?; @@ -396,7 +396,7 @@ fn print_info( user: Option, ) -> Result<()> { if show_root_mnemonic { - let kp = wallet::restore_keypair_from_mnemonic_default(ROOT_MNEMONIC).c(d!())?; + let kp = wallet::restore_keypair_from_mnemonic_ed25519(ROOT_MNEMONIC).c(d!())?; println!( "\x1b[31;01mROOT MNEMONIC:\x1b[00m\n{}\nKeys: {}", ROOT_MNEMONIC, @@ -461,7 +461,7 @@ fn gen_user_list() -> BTreeMap { (0..MNEMONIC_LIST.len()) .map(|i| { - let keypair = pnk!(wallet::restore_keypair_from_mnemonic_default( + let keypair = pnk!(wallet::restore_keypair_from_mnemonic_ed25519( MNEMONIC_LIST[i] )); let pubkey = keypair.get_pk(); @@ -500,7 +500,7 @@ fn gen_valiator_list() -> BTreeMap { (0..NUM) .map(|i| { let td_addr = TD_ADDR_LIST[i].to_owned(); - let keypair = pnk!(wallet::restore_keypair_from_mnemonic_default( + let keypair = pnk!(wallet::restore_keypair_from_mnemonic_ed25519( MNEMONIC_LIST[i] )); let pubkey = keypair.get_pk(); diff --git a/src/components/finutils/src/common/ddev/init.rs b/src/components/finutils/src/common/ddev/init.rs index 93c7f631e..8892336eb 100644 --- a/src/components/finutils/src/common/ddev/init.rs +++ b/src/components/finutils/src/common/ddev/init.rs @@ -15,10 +15,10 @@ use ledger::{ staking::{td_addr_to_bytes, Validator as StakingValidator, ValidatorKind, FRA}, utils::fra_gen_initial_tx, }; -use noah::xfr::{ - asset_record::AssetRecordType, - sig::{XfrKeyPair, XfrPublicKey, XfrSecretKey}, +use noah::keys::{ + KeyPair as XfrKeyPair, PublicKey as XfrPublicKey, SecretKey as XfrSecretKey, }; +use noah::xfr::asset_record::AssetRecordType; use ruc::*; use serde::{Deserialize, Serialize}; diff --git a/src/components/finutils/src/common/evm.rs b/src/components/finutils/src/common/evm.rs index cdf5da825..bc0128d05 100644 --- a/src/components/finutils/src/common/evm.rs +++ b/src/components/finutils/src/common/evm.rs @@ -23,7 +23,7 @@ use fp_utils::tx::EvmRawTxWrapper; use ledger::data_model::AssetTypeCode; use ledger::data_model::ASSET_TYPE_FRA; use ledger::data_model::BLACK_HOLE_PUBKEY_STAKING; -use noah::xfr::{asset_record::AssetRecordType, sig::XfrKeyPair}; +use noah::{keys::KeyPair as XfrKeyPair, xfr::asset_record::AssetRecordType}; use ruc::*; use std::str::FromStr; use tendermint::block::Height; @@ -37,11 +37,11 @@ pub fn transfer_to_account( asset: Option<&str>, address: Option<&str>, lowlevel_data: Option<&str>, - is_address_fra: bool, + is_address_eth: bool, ) -> Result<()> { let mut builder = utils::new_tx_builder()?; - let kp = get_keypair(is_address_fra)?; + let kp = get_keypair(is_address_eth)?; let asset = if let Some(asset) = asset { let asset = AssetTypeCode::new_from_base64(asset)?; @@ -115,9 +115,9 @@ pub fn transfer_from_account( amount: u64, address: Option<&str>, eth_phrase: Option<&str>, - is_address_fra: bool, + is_address_eth: bool, ) -> Result<()> { - let fra_kp = get_keypair(is_address_fra)?; + let fra_kp = get_keypair(is_address_eth)?; let target = match address { Some(s) => { @@ -217,9 +217,9 @@ fn one_shot_abci_query( /// Query contract account info by abci/query pub fn contract_account_info( address: Option<&str>, - is_address_fra: bool, + is_address_eth: bool, ) -> Result<(Address, SmartAccount)> { - let fra_kp = get_keypair(is_address_fra)?; + let fra_kp = get_keypair(is_address_eth)?; let address = match address { Some(s) => MultiSigner::from_str(s).c(d!())?, diff --git a/src/components/finutils/src/common/mod.rs b/src/components/finutils/src/common/mod.rs index 7486d02f2..6cdc8a910 100644 --- a/src/components/finutils/src/common/mod.rs +++ b/src/components/finutils/src/common/mod.rs @@ -37,18 +37,19 @@ use { }, noah::{ anon_xfr::{ - keys::{AXfrKeyPair, AXfrPubKey}, nullify, structs::{ AnonAssetRecord, Commitment, MTLeafInfo, OpenAnonAssetRecordBuilder, }, }, + keys::{ + KeyPair as XfrKeyPair, PublicKey as XfrPublicKey, SecretKey as XfrSecretKey, + }, xfr::{ asset_record::{ AssetRecordType, AssetRecordType::NonConfidentialAmount_NonConfidentialAssetType, }, - sig::{XfrKeyPair, XfrPublicKey, XfrSecretKey}, structs::{AssetType, XfrAmount, XfrAssetType}, }, }, @@ -82,7 +83,7 @@ lazy_static! { pub fn staker_update( cr: Option<&str>, memo: Option, - is_address_fra: bool, + is_address_eth: bool, ) -> Result<()> { let addr = get_td_pubkey().map(|i| td_pubkey_to_td_addr(&i)).c(d!())?; let vd = get_validator_detail(&addr).c(d!())?; @@ -98,7 +99,7 @@ pub fn staker_update( let td_pubkey = get_td_pubkey().c(d!())?; - let kp = get_keypair(is_address_fra).c(d!())?; + let kp = get_keypair(is_address_eth).c(d!())?; let vkp = get_td_privkey().c(d!())?; let mut builder = utils::new_tx_builder().c(d!())?; @@ -126,7 +127,7 @@ pub fn stake( commission_rate: &str, memo: Option<&str>, force: bool, - is_address_fra: bool, + is_address_eth: bool, ) -> Result<()> { let am = amount.parse::().c(d!("'amount' must be an integer"))?; check_delegation_amount(am, false).c(d!())?; @@ -136,7 +137,7 @@ pub fn stake( .and_then(|cr| convert_commission_rate(cr).c(d!()))?; let td_pubkey = get_td_pubkey().c(d!())?; - let kp = get_keypair(is_address_fra).c(d!())?; + let kp = get_keypair(is_address_eth).c(d!())?; let vkp = get_td_privkey().c(d!())?; macro_rules! diff { @@ -193,7 +194,7 @@ pub fn stake_append( amount: &str, staker: Option<&str>, td_addr: Option, - is_address_fra: bool, + is_address_eth: bool, ) -> Result<()> { let am = amount.parse::().c(d!("'amount' must be an integer"))?; check_delegation_amount(am, true).c(d!())?; @@ -206,8 +207,8 @@ pub fn stake_append( let kp = staker .c(d!()) - .and_then(|sk| wallet::restore_keypair_from_mnemonic_default(sk).c(d!())) - .or_else(|_| get_keypair(is_address_fra).c(d!()))?; + .and_then(|sk| wallet::restore_keypair_from_mnemonic_ed25519(sk).c(d!())) + .or_else(|_| get_keypair(is_address_eth).c(d!()))?; let mut builder = utils::new_tx_builder().c(d!())?; builder.add_operation_delegation(&kp, am, td_addr); @@ -236,7 +237,7 @@ pub fn unstake( am: Option<&str>, staker: Option<&str>, td_addr: Option, - is_address_fra: bool, + is_address_eth: bool, ) -> Result<()> { let am = if let Some(i) = am { Some(i.parse::().c(d!("'amount' must be an integer"))?) @@ -246,8 +247,8 @@ pub fn unstake( let kp = staker .c(d!()) - .and_then(|sk| wallet::restore_keypair_from_mnemonic_default(sk).c(d!())) - .or_else(|_| get_keypair(is_address_fra).c(d!()))?; + .and_then(|sk| wallet::restore_keypair_from_mnemonic_ed25519(sk).c(d!())) + .or_else(|_| get_keypair(is_address_eth).c(d!()))?; let td_addr_bytes = td_addr .c(d!()) .and_then(|ta| td_addr_to_bytes(ta).c(d!())) @@ -289,7 +290,7 @@ pub fn unstake( pub fn claim( am: Option<&str>, sk_str: Option<&str>, - is_address_fra: bool, + is_address_eth: bool, ) -> Result<()> { let am = if let Some(i) = am { Some(i.parse::().c(d!("'amount' must be an integer"))?) @@ -297,7 +298,7 @@ pub fn claim( None }; - let kp = restore_keypair_from_str_with_default(sk_str, is_address_fra)?; + let kp = restore_keypair_from_str_with_default(sk_str, is_address_eth)?; let mut builder = utils::new_tx_builder().c(d!())?; @@ -324,14 +325,14 @@ pub fn claim( /// Delegation Information /// Validator Detail (if already staked) /// -pub fn show(basic: bool, is_address_fra: bool) -> Result<()> { - let kp = get_keypair(is_address_fra).c(d!())?; +pub fn show(basic: bool, is_address_eth: bool) -> Result<()> { + let kp = get_keypair(is_address_eth).c(d!())?; let serv_addr = ruc::info!(get_serv_addr()).map(|i| { println!("\x1b[31;01mServer URL:\x1b[00m\n{i}\n",); }); - let xfr_account = ruc::info!(get_keypair(is_address_fra)).map(|i| { + let xfr_account = ruc::info!(get_keypair(is_address_eth)).map(|i| { println!( "\x1b[31;01mFindora Address:\x1b[00m\n{}\n", wallet::public_key_to_bech32(&i.get_pk()) @@ -455,7 +456,7 @@ pub fn transfer_asset( am: &str, confidential_am: bool, confidential_ty: bool, - is_address_fra: bool, + is_address_eth: bool, ) -> Result<()> { transfer_asset_batch( owner_sk, @@ -464,7 +465,7 @@ pub fn transfer_asset( am, confidential_am, confidential_ty, - is_address_fra, + is_address_eth, ) .c(d!()) } @@ -497,9 +498,9 @@ pub fn transfer_asset_batch( am: &str, confidential_am: bool, confidential_ty: bool, - is_address_fra: bool, + is_address_eth: bool, ) -> Result<()> { - let from = restore_keypair_from_str_with_default(owner_sk, is_address_fra)?; + let from = restore_keypair_from_str_with_default(owner_sk, is_address_eth)?; let am = am.parse::().c(d!("'amount' must be an integer"))?; transfer_asset_batch_x( @@ -548,20 +549,20 @@ pub fn get_serv_addr() -> Result<&'static str> { } /// Get keypair from config file -pub fn get_keypair(is_address_fra: bool) -> Result { +pub fn get_keypair(is_address_eth: bool) -> Result { if let Some(m_path) = MNEMONIC.as_ref() { fs::read_to_string(m_path) .c(d!("can not read mnemonic from 'owner-mnemonic-path'")) .and_then(|m| { let k = m.trim(); - if is_address_fra { - wallet::restore_keypair_from_mnemonic_ed25519(k) + if is_address_eth { + wallet::restore_keypair_from_mnemonic_secp256k1(k) .c(d!("invalid 'owner-mnemonic'")) .or_else(|e| { wallet::restore_keypair_from_seckey_base64(k).c(d!(e)) }) } else { - wallet::restore_keypair_from_mnemonic_default(k) + wallet::restore_keypair_from_mnemonic_ed25519(k) .c(d!("invalid 'owner-mnemonic'")) .or_else(|e| { wallet::restore_keypair_from_seckey_base64(k).c(d!(e)) @@ -613,13 +614,13 @@ pub fn convert_commission_rate(cr: f64) -> Result<[u64; 2]> { } #[allow(missing_docs)] -pub fn gen_key(is_fra_address: bool) -> (String, String, String, XfrKeyPair) { +pub fn gen_key(is_address_eth: bool) -> (String, String, String, XfrKeyPair) { let (mnemonic, key, kp) = loop { let mnemonic = pnk!(wallet::generate_mnemonic_custom(24, "en")); - let kp: XfrKeyPair = if is_fra_address { - pnk!(wallet::restore_keypair_from_mnemonic_ed25519(&mnemonic)) + let kp: XfrKeyPair = if is_address_eth { + pnk!(wallet::restore_keypair_from_mnemonic_secp256k1(&mnemonic)) } else { - pnk!(wallet::restore_keypair_from_mnemonic_default(&mnemonic)) + pnk!(wallet::restore_keypair_from_mnemonic_ed25519(&mnemonic)) }; if let Some(key) = serde_json::to_string_pretty(&kp) .ok() @@ -635,8 +636,8 @@ pub fn gen_key(is_fra_address: bool) -> (String, String, String, XfrKeyPair) { } #[allow(missing_docs)] -pub fn gen_key_and_print(is_fra_address: bool) { - let (wallet_addr, mnemonic, key, _) = gen_key(is_fra_address); +pub fn gen_key_and_print(is_address_eth: bool) { + let (wallet_addr, mnemonic, key, _) = gen_key(is_address_eth); println!( "\n\x1b[31;01mWallet Address:\x1b[00m {wallet_addr}\n\x1b[31;01mMnemonic:\x1b[00m {mnemonic}\n\x1b[31;01mKey:\x1b[00m {key}\n", ); @@ -644,14 +645,14 @@ pub fn gen_key_and_print(is_fra_address: bool) { fn restore_keypair_from_str_with_default( sk_str: Option<&str>, - is_fra_address: bool, + is_address_eth: bool, ) -> Result { if let Some(sk) = sk_str { serde_json::from_str::(&format!("\"{sk}\"",)) .map(|sk| sk.into_keypair()) .c(d!("Invalid secret key")) } else { - get_keypair(is_fra_address).c(d!()) + get_keypair(is_address_eth).c(d!()) } } @@ -659,9 +660,9 @@ fn restore_keypair_from_str_with_default( pub fn show_account( sk_str: Option<&str>, asset: Option<&str>, - is_address_fra: bool, + is_address_eth: bool, ) -> Result<()> { - let kp = restore_keypair_from_str_with_default(sk_str, is_address_fra)?; + let kp = restore_keypair_from_str_with_default(sk_str, is_address_eth)?; let token_code = asset .map(|asset| AssetTypeCode::new_from_base64(asset).c(d!("Invalid asset code"))) .transpose()?; @@ -677,9 +678,9 @@ pub fn delegate( sk_str: Option<&str>, amount: u64, validator: &str, - is_address_fra: bool, + is_address_eth: bool, ) -> Result<()> { - restore_keypair_from_str_with_default(sk_str, is_address_fra) + restore_keypair_from_str_with_default(sk_str, is_address_eth) .c(d!()) .and_then(|kp| delegate_x(&kp, amount, validator).c(d!())) } @@ -697,9 +698,9 @@ pub fn delegate_x(kp: &XfrKeyPair, amount: u64, validator: &str) -> Result<()> { pub fn undelegate( sk_str: Option<&str>, param: Option<(u64, &str)>, - is_address_fra: bool, + is_address_eth: bool, ) -> Result<()> { - restore_keypair_from_str_with_default(sk_str, is_address_fra) + restore_keypair_from_str_with_default(sk_str, is_address_eth) .c(d!()) .and_then(|kp| undelegate_x(&kp, param).c(d!())) } @@ -713,8 +714,8 @@ pub fn undelegate_x(kp: &XfrKeyPair, param: Option<(u64, &str)>) -> Result<()> { } /// Display delegation information of a findora account -pub fn show_delegations(sk_str: Option<&str>, is_address_fra: bool) -> Result<()> { - let pk = restore_keypair_from_str_with_default(sk_str, is_address_fra)?.get_pk(); +pub fn show_delegations(sk_str: Option<&str>, is_address_eth: bool) -> Result<()> { + let pk = restore_keypair_from_str_with_default(sk_str, is_address_eth)?.get_pk(); println!( "{}", @@ -795,9 +796,9 @@ pub fn create_asset( max_units: Option, transferable: bool, token_code: Option<&str>, - is_address_fra: bool, + is_address_eth: bool, ) -> Result<()> { - let kp = get_keypair(is_address_fra).c(d!())?; + let kp = get_keypair(is_address_eth).c(d!())?; let code = if token_code.is_none() { AssetTypeCode::gen_random() @@ -857,9 +858,9 @@ pub fn issue_asset( asset: &str, amount: u64, hidden: bool, - is_address_fra: bool, + is_address_eth: bool, ) -> Result<()> { - let kp = restore_keypair_from_str_with_default(sk_str, is_address_fra)?; + let kp = restore_keypair_from_str_with_default(sk_str, is_address_eth)?; let code = AssetTypeCode::new_from_base64(asset).c(d!())?; issue_asset_x(&kp, &code, amount, hidden).c(d!()) } @@ -915,23 +916,21 @@ pub fn show_asset(addr: &str) -> Result<()> { /// * target_addr - ABAR receiving AXfr pub key after conversion in base64 /// * TxoSID - sid of BAR to convert pub fn convert_bar2abar( - owner_sk: Option<&String>, - target_addr: String, + owner_sk: Option, + target_addr: &str, txo_sid: &str, - is_address_fra: bool, + is_address_eth: bool, ) -> Result { // parse sender XfrSecretKey or generate from Mnemonic setup with wallet let from = match owner_sk { - Some(str) => { - ruc::info!(serde_json::from_str::(&format!("\"{str}\"",))) - .c(d!())? - .into_keypair() - } - None => get_keypair(is_address_fra).c(d!())?, + Some(str) => ruc::info!(serde_json::from_str::(&format!("\"{str}\""))) + .c(d!())? + .into_keypair(), + None => get_keypair(is_address_eth).c(d!())?, }; // parse receiver AxfrPubKey - let to = wallet::anon_public_key_from_base64(target_addr.as_str()) - .c(d!("invalid 'target-addr'"))?; + let to = + wallet::public_key_from_bech32(target_addr).c(d!("invalid 'target-addr'"))?; let sid = txo_sid.parse::().c(d!("error parsing TxoSID"))?; // Get OpenAssetRecord from given Owner XfrKeyPair and TxoSID @@ -962,15 +961,23 @@ pub fn convert_bar2abar( /// * confidential_am - if the output BAR should have confidential amount /// * confidential_ty - if the output BAR should have confidential type pub fn convert_abar2bar( - axfr_secret_key: String, + owner_sk: Option, com: &str, to: &XfrPublicKey, confidential_am: bool, confidential_ty: bool, + is_address_eth: bool, ) -> Result<()> { - // parse anon keys - let from = wallet::anon_secret_key_from_base64(axfr_secret_key.as_str()) - .c(d!("invalid 'from-axfr-secret-key'"))?; + // parse sender XfrSecretKey or generate from Mnemonic setup with wallet + let from = match owner_sk { + Some(str) => ruc::info!(serde_json::from_str::(&format!( + "\"{}\"", + str + ))) + .c(d!())? + .into_keypair(), + None => get_keypair(is_address_eth).c(d!())?, + }; // Get the owned ABAR from pub_key and commitment let com = wallet::commitment_from_base58(com).c(d!())?; @@ -1026,26 +1033,34 @@ pub fn convert_abar2bar( /// Generate OABAR and add anonymous transfer operation /// # Arguments -/// * axfr_secret_key - AXfrKeyPair in base64 form +/// * axfr_secret_key - XfrKeyPair in base64 form /// * com - Commitment in base64 form /// * com_fra - Commitment for paying fee /// * amount - amount to transfer -/// * to_axfr_public_key - AXfrPublicKey in base64 form +/// * to_axfr_public_key - XfrPublicKey in base64 form pub fn gen_anon_transfer_op( - axfr_secret_key: String, + owner_sk: Option, com: &str, com_fra: Option<&str>, amount: &str, - to_axfr_public_key: &str, + to_address: &str, + is_address_eth: bool, ) -> Result<()> { - // parse sender keys - let from = wallet::anon_secret_key_from_base64(axfr_secret_key.as_str()) - .c(d!("invalid 'from-axfr-secret-key'"))?; + // parse sender XfrSecretKey or generate from Mnemonic setup with wallet + let from = match owner_sk { + Some(str) => ruc::info!(serde_json::from_str::(&format!( + "\"{}\"", + str + ))) + .c(d!())? + .into_keypair(), + None => get_keypair(is_address_eth).c(d!())?, + }; let axfr_amount = amount.parse::().c(d!("error parsing amount"))?; - let to = wallet::anon_public_key_from_base64(to_axfr_public_key) - .c(d!("invalid 'to-axfr-public-key'"))?; + let to = wallet::public_key_from_bech32(to_address) + .c(d!("invalid 'to-xfr-public-key'"))?; let mut commitments = vec![com]; if let Some(fra) = com_fra { @@ -1172,12 +1187,24 @@ pub fn gen_anon_transfer_op( /// * assets - List of receiver Asset Types /// returns an error if Operation build fails pub fn gen_oabar_add_op_x( - axfr_secret_key: AXfrKeyPair, - to_axfr_public_keys: Vec, + owner_sk: Option, + to_axfr_public_keys: Vec, commitments: Vec, amounts: Vec, assets: Vec, + is_address_eth: bool, ) -> Result<()> { + // parse sender XfrSecretKey or generate from Mnemonic setup with wallet + let from = match owner_sk { + Some(str) => ruc::info!(serde_json::from_str::(&format!( + "\"{}\"", + str + ))) + .c(d!())? + .into_keypair(), + None => get_keypair(is_address_eth).c(d!())?, + }; + let receiver_count = to_axfr_public_keys.len(); // check if input counts tally @@ -1190,7 +1217,6 @@ pub fn gen_oabar_add_op_x( // Create Input Open Abars with input keys, radomizers and Owner memos let mut oabars_in = Vec::new(); for comm in commitments { - let from = &axfr_secret_key; let c = wallet::commitment_from_base58(comm.as_str()).c(d!())?; // Get OwnerMemo @@ -1202,7 +1228,7 @@ pub fn gen_oabar_add_op_x( // Build Abar let oabar_in = - OpenAnonAssetRecordBuilder::from_abar(&axtxo_abar.1, owner_memo, from) + OpenAnonAssetRecordBuilder::from_abar(&axtxo_abar.1, owner_memo, &from) .unwrap() .mt_leaf_info(mt_leaf_info) .build() @@ -1210,7 +1236,7 @@ pub fn gen_oabar_add_op_x( // check oabar is unspent. let n = nullify( - from, + &from, oabar_in.get_amount(), oabar_in.get_asset_type().as_scalar(), mt_leaf_uid, @@ -1256,7 +1282,7 @@ pub fn gen_oabar_add_op_x( .add_operation_anon_transfer_fees_remainder( &oabars_in[..], &oabars_out[..], - &axfr_secret_key, + &from, ) .c(d!())?; @@ -1318,10 +1344,10 @@ pub fn get_mtleaf_info(atxo_sid: &str) -> Result { /// Fetches list of owned TxoSIDs from LedgerStatus pub fn get_owned_utxos( asset: Option<&str>, - is_address_fra: bool, + is_address_eth: bool, ) -> Result> { // get KeyPair from current setup wallet - let kp = get_keypair(is_address_fra).c(d!())?; + let kp = get_keypair(is_address_eth).c(d!())?; // Parse Asset Type for filtering if provided let mut asset_type = ASSET_TYPE_FRA; @@ -1334,7 +1360,7 @@ pub fn get_owned_utxos( } let list: Vec<(TxoSID, XfrAmount, XfrAssetType)> = - utils::get_owned_utxos(&kp.pub_key)? + utils::get_owned_utxos(&kp.get_pk())? .iter() .filter(|a| { // Filter by asset type if given or read all @@ -1358,7 +1384,7 @@ pub fn get_owned_utxos( /// Check the spending status of an ABAR from AnonKeys and commitment pub fn check_abar_status( - from: AXfrKeyPair, + from: XfrKeyPair, axtxo_abar: (ATxoSID, AnonAssetRecord), ) -> Result<()> { let owner_memo = utils::get_abar_memo(&axtxo_abar.0).c(d!())?.unwrap(); @@ -1391,7 +1417,7 @@ pub fn check_abar_status( /// Prints a dainty list of Abar info with spent status for a given AxfrKeyPair and a list of /// commitments. pub fn get_owned_abars( - axfr_secret_key: AXfrKeyPair, + axfr_secret_key: XfrKeyPair, commitments_list: &str, ) -> Result<()> { println!("Abar data for commitments: {commitments_list}",); @@ -1443,7 +1469,7 @@ pub fn get_owned_abars( /// Prints a dainty list of Abar info with spent status for a given AxfrKeyPair and a list of /// commitments. pub fn anon_balance( - axfr_secret_key: AXfrKeyPair, + axfr_secret_key: XfrKeyPair, commitments_list: &str, asset: Option<&str>, ) -> Result<()> { @@ -1514,9 +1540,9 @@ pub fn version() -> &'static str { pub fn replace_staker( target_pubkey: XfrPublicKey, new_td_addr_pk: Option<(Vec, Vec)>, - is_address_fra: bool, + is_address_eth: bool, ) -> Result<()> { - let keypair = get_keypair(is_address_fra)?; + let keypair = get_keypair(is_address_eth)?; let mut builder = utils::new_tx_builder().c(d!())?; diff --git a/src/components/finutils/src/common/utils.rs b/src/components/finutils/src/common/utils.rs index d6f346350..d4c4e902d 100644 --- a/src/components/finutils/src/common/utils.rs +++ b/src/components/finutils/src/common/utils.rs @@ -18,15 +18,12 @@ use { }, staking::{init::get_inital_validators, TendermintAddrRef, FRA_TOTAL_AMOUNT}, }, - noah::anon_xfr::{ - keys::{AXfrKeyPair, AXfrPubKey}, - structs::{ - AnonAssetRecord, AxfrOwnerMemo, Commitment, MTLeafInfo, OpenAnonAssetRecord, - }, + noah::anon_xfr::structs::{ + AnonAssetRecord, AxfrOwnerMemo, Commitment, MTLeafInfo, OpenAnonAssetRecord, }, + noah::keys::{KeyPair as XfrKeyPair, PublicKey as XfrPublicKey}, noah::xfr::{ asset_record::{open_blind_asset_record, AssetRecordType}, - sig::{XfrKeyPair, XfrPublicKey}, structs::{AssetRecordTemplate, BlindAssetRecord, OpenAssetRecord, OwnerMemo}, }, ruc::*, @@ -367,7 +364,7 @@ pub fn gen_fee_bar_to_abar( i_am - op_fee, ASSET_TYPE_FRA, AssetRecordType::NonConfidentialAmount_NonConfidentialAssetType, - owner_kp.pub_key, + owner_kp.get_pk(), ), None, None, @@ -780,13 +777,13 @@ pub fn parse_td_validator_keys(key_data: &str) -> Result { /// Generates a BarToAbar Operation and an accompanying FeeOP and sends it to the network and return the Randomizer /// # Arguments /// * `auth_key_pair` - XfrKeyPair of the owner BAR for conversion -/// * `abar_pub_key` - AXfrPubKey of the receiver ABAR after conversion +/// * `abar_pub_key` - XfrPublicKey of the receiver ABAR after conversion /// * `txo_sid` - TxoSID of the BAR to convert /// * `input_record` - OpenAssetRecord of the BAR to convert /// * `is_bar_transparent` - if transparent bar (ar) pub fn generate_bar2abar_op( auth_key_pair: &XfrKeyPair, - abar_pub_key: &AXfrPubKey, + abar_pub_key: &XfrPublicKey, txo_sid: TxoSID, input_record: &OpenAssetRecord, is_bar_transparent: bool, @@ -832,12 +829,12 @@ pub fn generate_bar2abar_op( /// * oabar_in - Abar to convert in open form /// * fee_oabar - Abar to pay anon fee in open form /// * out_fee_oabar - Abar to get balance back after paying fee -/// * from - AXfrKeyPair of person converting ABAR +/// * from - XfrKeyPair of person converting ABAR /// * to - XfrPublicKey of person receiving new BAR /// * art - AssetRecordType of the new BAR pub fn generate_abar2bar_op( oabar_in: &OpenAnonAssetRecord, - from: &AXfrKeyPair, + from: &XfrKeyPair, to: &XfrPublicKey, art: AssetRecordType, ) -> Result<()> { diff --git a/src/components/finutils/src/txn_builder/mod.rs b/src/components/finutils/src/txn_builder/mod.rs index ad40f086e..6e64b0ab4 100644 --- a/src/components/finutils/src/txn_builder/mod.rs +++ b/src/components/finutils/src/txn_builder/mod.rs @@ -53,17 +53,16 @@ use { }, ar_to_abar::gen_ar_to_abar_note, bar_to_abar::gen_bar_to_abar_note, - keys::{AXfrKeyPair, AXfrPubKey}, structs::{Commitment, OpenAnonAssetRecord, OpenAnonAssetRecordBuilder}, TREE_DEPTH as MERKLE_TREE_DEPTH, }, + keys::{KeyPair as XfrKeyPair, PublicKey as XfrPublicKey}, setup::ProverParams, xfr::{ asset_record::{ build_blind_asset_record, build_open_asset_record, open_blind_asset_record, AssetRecordType, }, - sig::{XfrKeyPair, XfrPublicKey}, structs::{ AssetRecord, AssetRecordTemplate, AssetType, BlindAssetRecord, OpenAssetRecord, OwnerMemo, TracingPolicies, TracingPolicy, @@ -71,8 +70,7 @@ use { XfrNotePolicies, }, }, - noah_algebra::prelude::*, - noah_crypto::basic::pedersen_comm::PedersenCommitmentRistretto, + noah_algebra::{prelude::*, ristretto::PedersenCommitmentRistretto}, rand_chacha::ChaChaRng, rand_core::{CryptoRng, RngCore, SeedableRng}, serde::{Deserialize, Serialize}, @@ -204,7 +202,8 @@ impl TransactionBuilder { if 0 < am { if let Ok(oar) = open_blind_asset_record(&o, &om, &kp) { if ASSET_TYPE_FRA == oar.asset_type - && kp.get_pk_ref().to_bytes() == o.public_key.to_bytes() + && kp.get_pk_ref().noah_to_bytes() + == o.public_key.noah_to_bytes() { let n = alt!(oar.amount > am, am, oar.amount); am = am.saturating_sub(oar.amount); @@ -293,7 +292,7 @@ impl TransactionBuilder { .and_then(|o| o.create(TransferType::Standard).c(d!())) .and_then(|o| { let cmp = |a: &XfrKeyPair, b: &XfrKeyPair| { - a.get_pk().to_bytes().cmp(&b.get_pk().to_bytes()) + a.get_pk().noah_to_bytes().cmp(&b.get_pk().noah_to_bytes()) }; kps.sort_by(cmp); kps.dedup_by(|a, b| matches!(cmp(a, b), Ordering::Equal)); @@ -629,7 +628,7 @@ impl TransactionBuilder { /// Add an operation to convert a Blind Asset Record to a Anonymous record and return the Commitment /// # Arguments /// * `auth_key_pair` - XfrKeyPair of the owner BAR for conversion - /// * `abar_pub_key` - AXfrPubKey of the receiver ABAR after conversion + /// * `abar_pub_key` - XfrPublicKey of the receiver ABAR after conversion /// * `txo_sid` - TxoSID of the BAR to convert /// * `input_record` - OpenAssetRecord of the BAR to convert /// * `enc_key` - XPublicKey of OwnerMemo encryption of receiver @@ -640,7 +639,7 @@ impl TransactionBuilder { &mut self, seed: [u8; 32], auth_key_pair: &XfrKeyPair, - abar_pub_key: &AXfrPubKey, + abar_pub_key: &XfrPublicKey, txo_sid: TxoSID, input_record: &OpenAssetRecord, is_bar_transparent: bool, @@ -673,7 +672,7 @@ impl TransactionBuilder { pub fn add_operation_abar_to_bar( &mut self, input: &OpenAnonAssetRecord, - input_keypair: &AXfrKeyPair, + input_keypair: &XfrKeyPair, bar_pub_key: &XfrPublicKey, asset_record_type: AssetRecordType, ) -> Result<&mut Self> { @@ -705,13 +704,13 @@ impl TransactionBuilder { /// # Arguments /// * inputs - List of input ABARs to be used for the transfer /// * outputs - List of output ABARs - /// * input_keypair - list of AXfrKeyPair of the sender + /// * input_keypair - list of XfrKeyPair of the sender #[allow(dead_code)] pub fn add_operation_anon_transfer( &mut self, inputs: &[OpenAnonAssetRecord], outputs: &[OpenAnonAssetRecord], - input_keypair: &AXfrKeyPair, + input_keypair: &XfrKeyPair, ) -> Result<(&mut Self, AXfrPreNote)> { let fee = FEE_CALCULATING_FUNC(inputs.len() as u32, outputs.len() as u32); @@ -726,20 +725,20 @@ impl TransactionBuilder { /// # Arguments /// * inputs - List of input ABARs to be used for the transfer /// * outputs - List of output ABARs - /// * input_keypair - list of AXfrKeyPair of the sender + /// * input_keypair - list of XfrKeyPair of the sender /// * enc_key - The encryption key of the sender to send the remainder abar pub fn add_operation_anon_transfer_fees_remainder( &mut self, inputs: &[OpenAnonAssetRecord], outputs: &[OpenAnonAssetRecord], - input_keypair: &AXfrKeyPair, + input_keypair: &XfrKeyPair, ) -> Result<(&mut Self, AXfrPreNote, Vec)> { let mut prng = ChaChaRng::from_entropy(); let mut vec_outputs = outputs.to_vec(); let mut vec_changes = vec![]; let mut remainders = HashMap::new(); - let remainder_pk = input_keypair.get_public_key(); + let remainder_pk = input_keypair.get_pk(); // Create a remainders hashmap with remainder amount for each asset type for input in inputs { @@ -1134,7 +1133,7 @@ fn gen_bar_conv_note( seed: [u8; 32], input_record: &OpenAssetRecord, auth_key_pair: &XfrKeyPair, - abar_pub_key: &AXfrPubKey, + abar_pub_key: &XfrPublicKey, is_bar_transparent: bool, ) -> Result<(BarAnonConvNote, Commitment)> { // let mut prng = ChaChaRng::from_entropy(); @@ -1550,7 +1549,7 @@ impl TransferOperationBuilder { pub struct AnonTransferOperationBuilder { inputs: Vec, outputs: Vec, - keypair: Option, + keypair: Option, pre_note: Option, commitments: Vec, @@ -1598,7 +1597,7 @@ impl AnonTransferOperationBuilder { } /// add_keypair is used to specify the input keypair for nullifier generation - pub fn add_keypair(&mut self, keypair: AXfrKeyPair) -> &mut Self { + pub fn add_keypair(&mut self, keypair: XfrKeyPair) -> &mut Self { self.keypair = Some(keypair); self } @@ -1789,7 +1788,7 @@ impl AnonTransferOperationBuilder { } /// get a hashmap of commitment, public key, asset, amount - pub fn get_commitment_map(&self) -> HashMap { + pub fn get_commitment_map(&self) -> HashMap { let mut commitment_map = HashMap::new(); for out_abar in self.outputs.iter() { let abar_rand = @@ -1876,7 +1875,7 @@ impl AnonTransferOperationBuilder { let oabar_money_back = OpenAnonAssetRecordBuilder::new() .amount(remainder) .asset_type(asset) - .pub_key(&keypair.get_public_key()) + .pub_key(&keypair.get_pk()) .finalize(&mut prng) .unwrap() .build() @@ -1961,7 +1960,7 @@ mod tests { AssetRecordType::NonConfidentialAmount_NonConfidentialAssetType, }, noah::xfr::structs::AssetType as AT, - noah_crypto::basic::pedersen_comm::PedersenCommitmentRistretto, + noah_algebra::ristretto::PedersenCommitmentRistretto, rand_chacha::ChaChaRng, rand_core::SeedableRng, }; @@ -1996,10 +1995,10 @@ mod tests { let pc_gens = PedersenCommitmentRistretto::default(); let code_1 = AssetTypeCode::gen_random(); let code_2 = AssetTypeCode::gen_random(); - let alice = XfrKeyPair::generate(&mut prng); - let bob = XfrKeyPair::generate(&mut prng); - let charlie = XfrKeyPair::generate(&mut prng); - let ben = XfrKeyPair::generate(&mut prng); + let alice = XfrKeyPair::generate_ed25519(&mut prng); + let bob = XfrKeyPair::generate_ed25519(&mut prng); + let charlie = XfrKeyPair::generate_ed25519(&mut prng); + let ben = XfrKeyPair::generate_ed25519(&mut prng); let ar_1 = AssetRecordTemplate::with_no_asset_tracing( 1000, @@ -2178,8 +2177,8 @@ mod tests { #[test] fn test_check_fee_with_ledger() { let mut ledger = LedgerState::tmp_ledger(); - let fra_owner_kp = XfrKeyPair::generate(&mut ChaChaRng::from_entropy()); - let bob_kp = XfrKeyPair::generate(&mut ChaChaRng::from_entropy()); + let fra_owner_kp = XfrKeyPair::generate_ed25519(&mut ChaChaRng::from_entropy()); + let bob_kp = XfrKeyPair::generate_ed25519(&mut ChaChaRng::from_entropy()); assert_eq!( bob_kp.get_sk().into_keypair().noah_to_bytes(), bob_kp.noah_to_bytes() @@ -2316,8 +2315,8 @@ mod tests { let mut builder = TransactionBuilder::from_seq_id(1); let mut prng = ChaChaRng::from_seed([0u8; 32]); - let from = XfrKeyPair::generate(&mut prng); - let to = AXfrKeyPair::generate(&mut prng).get_public_key(); + let from = XfrKeyPair::generate_ed25519(&mut prng); + let to = XfrKeyPair::generate_ed25519(&mut prng).get_pk(); let ar = AssetRecordTemplate::with_no_asset_tracing( 10u64, @@ -2422,12 +2421,9 @@ mod tests { // simulate another oabar just to get new keypair let (_, another_keypair) = gen_oabar_and_keys(&mut prng, amount, asset_type); // negative test for input keypairs - assert_eq!(keypair_in.get_public_key(), *oabar.pub_key_ref()); - assert_ne!( - keypair_in.get_public_key(), - another_keypair.get_public_key() - ); - assert_ne!(another_keypair.get_public_key(), *oabar.pub_key_ref()); + assert_eq!(keypair_in.get_pk(), *oabar.pub_key_ref()); + assert_ne!(keypair_in.get_pk(), another_keypair.get_pk()); + assert_ne!(another_keypair.get_pk(), *oabar.pub_key_ref()); // Simulate output abar let (oabar_out, _keypair_out) = @@ -2462,8 +2458,8 @@ mod tests { let owner_memo = oabar.get_owner_memo().unwrap(); // Trying to decrypt asset type and amount from owner memo using wrong keys - let new_xfrkeys = AXfrKeyPair::generate(&mut prng); - let result_decrypt = owner_memo.decrypt(&new_xfrkeys.get_secret_key()); + let new_xfrkeys = XfrKeyPair::generate_ed25519(&mut prng); + let result_decrypt = owner_memo.decrypt(&new_xfrkeys.get_sk()); assert!(result_decrypt.is_err()); // initialize ledger and add abar to merkle tree @@ -2503,12 +2499,12 @@ mod tests { prng: &mut R, amount: u64, asset_type: AT, - ) -> (OpenAnonAssetRecord, AXfrKeyPair) { - let keypair = AXfrKeyPair::generate(prng); + ) -> (OpenAnonAssetRecord, XfrKeyPair) { + let keypair = XfrKeyPair::generate_ed25519(prng); let oabar = OpenAnonAssetRecordBuilder::new() .amount(amount) .asset_type(asset_type) - .pub_key(&keypair.get_public_key()) + .pub_key(&keypair.get_pk()) .finalize(prng) .unwrap() .build() @@ -2519,7 +2515,7 @@ mod tests { #[test] pub fn test_extra_fee_estimation_only_fra() { let mut prng = ChaChaRng::from_seed([0u8; 32]); - let k = AXfrKeyPair::generate(&mut prng); + let k = XfrKeyPair::generate_ed25519(&mut prng); { let mut b = AnonTransferOperationBuilder::new_from_seq_id(0); @@ -2527,7 +2523,7 @@ mod tests { OpenAnonAssetRecordBuilder::new() .amount(1000000) .asset_type(ASSET_TYPE_FRA) - .pub_key(&k.get_public_key()) + .pub_key(&k.get_pk()) .finalize(&mut prng) .unwrap() .build() @@ -2544,7 +2540,7 @@ mod tests { OpenAnonAssetRecordBuilder::new() .amount(1000000) .asset_type(ASSET_TYPE_FRA) - .pub_key(&k.get_public_key()) + .pub_key(&k.get_pk()) .finalize(&mut prng) .unwrap() .build() @@ -2555,7 +2551,7 @@ mod tests { OpenAnonAssetRecordBuilder::new() .amount(1000000) .asset_type(ASSET_TYPE_FRA) - .pub_key(&k.get_public_key()) + .pub_key(&k.get_pk()) .finalize(&mut prng) .unwrap() .build() @@ -2574,7 +2570,7 @@ mod tests { OpenAnonAssetRecordBuilder::new() .amount(1000000) .asset_type(ASSET_TYPE_FRA) - .pub_key(&k.get_public_key()) + .pub_key(&k.get_pk()) .finalize(&mut prng) .unwrap() .build() @@ -2585,7 +2581,7 @@ mod tests { OpenAnonAssetRecordBuilder::new() .amount(200000) .asset_type(ASSET_TYPE_FRA) - .pub_key(&k.get_public_key()) + .pub_key(&k.get_pk()) .finalize(&mut prng) .unwrap() .build() @@ -2603,7 +2599,7 @@ mod tests { OpenAnonAssetRecordBuilder::new() .amount(10) .asset_type(ASSET_TYPE_FRA) - .pub_key(&k.get_public_key()) + .pub_key(&k.get_pk()) .finalize(&mut prng) .unwrap() .build() @@ -2613,7 +2609,7 @@ mod tests { OpenAnonAssetRecordBuilder::new() .amount(200000) .asset_type(ASSET_TYPE_FRA) - .pub_key(&k.get_public_key()) + .pub_key(&k.get_pk()) .finalize(&mut prng) .unwrap() .build() @@ -2629,7 +2625,7 @@ mod tests { #[test] pub fn test_extra_fee_estimation_multi_asset() { let mut prng = ChaChaRng::from_seed([0u8; 32]); - let k = AXfrKeyPair::generate(&mut prng); + let k = XfrKeyPair::generate_ed25519(&mut prng); let asset1 = AT::from_identical_byte(1u8); let _asset2 = AT::from_identical_byte(2u8); @@ -2641,7 +2637,7 @@ mod tests { OpenAnonAssetRecordBuilder::new() .amount(1000000) .asset_type(asset1) - .pub_key(&k.get_public_key()) + .pub_key(&k.get_pk()) .finalize(&mut prng) .unwrap() .build() @@ -2658,7 +2654,7 @@ mod tests { OpenAnonAssetRecordBuilder::new() .amount(1000000) .asset_type(asset1) - .pub_key(&k.get_public_key()) + .pub_key(&k.get_pk()) .finalize(&mut prng) .unwrap() .build() @@ -2668,7 +2664,7 @@ mod tests { OpenAnonAssetRecordBuilder::new() .amount(1100000) .asset_type(ASSET_TYPE_FRA) - .pub_key(&k.get_public_key()) + .pub_key(&k.get_pk()) .finalize(&mut prng) .unwrap() .build() @@ -2685,7 +2681,7 @@ mod tests { OpenAnonAssetRecordBuilder::new() .amount(1000000) .asset_type(asset1) - .pub_key(&k.get_public_key()) + .pub_key(&k.get_pk()) .finalize(&mut prng) .unwrap() .build() @@ -2695,7 +2691,7 @@ mod tests { OpenAnonAssetRecordBuilder::new() .amount(1000000) .asset_type(asset1) - .pub_key(&k.get_public_key()) + .pub_key(&k.get_pk()) .finalize(&mut prng) .unwrap() .build() @@ -2705,7 +2701,7 @@ mod tests { OpenAnonAssetRecordBuilder::new() .amount(1100000) .asset_type(ASSET_TYPE_FRA) - .pub_key(&k.get_public_key()) + .pub_key(&k.get_pk()) .finalize(&mut prng) .unwrap() .build() @@ -2722,7 +2718,7 @@ mod tests { OpenAnonAssetRecordBuilder::new() .amount(1000000) .asset_type(asset1) - .pub_key(&k.get_public_key()) + .pub_key(&k.get_pk()) .finalize(&mut prng) .unwrap() .build() @@ -2732,7 +2728,7 @@ mod tests { OpenAnonAssetRecordBuilder::new() .amount(1000000) .asset_type(asset1) - .pub_key(&k.get_public_key()) + .pub_key(&k.get_pk()) .finalize(&mut prng) .unwrap() .build() @@ -2743,7 +2739,7 @@ mod tests { OpenAnonAssetRecordBuilder::new() .amount(fee) .asset_type(ASSET_TYPE_FRA) - .pub_key(&k.get_public_key()) + .pub_key(&k.get_pk()) .finalize(&mut prng) .unwrap() .build() @@ -2760,7 +2756,7 @@ mod tests { OpenAnonAssetRecordBuilder::new() .amount(1000000) .asset_type(asset1) - .pub_key(&k.get_public_key()) + .pub_key(&k.get_pk()) .finalize(&mut prng) .unwrap() .build() @@ -2770,7 +2766,7 @@ mod tests { OpenAnonAssetRecordBuilder::new() .amount(900000) .asset_type(asset1) - .pub_key(&k.get_public_key()) + .pub_key(&k.get_pk()) .finalize(&mut prng) .unwrap() .build() @@ -2781,7 +2777,7 @@ mod tests { OpenAnonAssetRecordBuilder::new() .amount(fee) .asset_type(ASSET_TYPE_FRA) - .pub_key(&k.get_public_key()) + .pub_key(&k.get_pk()) .finalize(&mut prng) .unwrap() .build() @@ -2798,7 +2794,7 @@ mod tests { OpenAnonAssetRecordBuilder::new() .amount(800000) .asset_type(asset1) - .pub_key(&k.get_public_key()) + .pub_key(&k.get_pk()) .finalize(&mut prng) .unwrap() .build() @@ -2808,7 +2804,7 @@ mod tests { OpenAnonAssetRecordBuilder::new() .amount(900000) .asset_type(asset1) - .pub_key(&k.get_public_key()) + .pub_key(&k.get_pk()) .finalize(&mut prng) .unwrap() .build() @@ -2819,7 +2815,7 @@ mod tests { OpenAnonAssetRecordBuilder::new() .amount(fee) .asset_type(ASSET_TYPE_FRA) - .pub_key(&k.get_public_key()) + .pub_key(&k.get_pk()) .finalize(&mut prng) .unwrap() .build() @@ -2834,7 +2830,7 @@ mod tests { OpenAnonAssetRecordBuilder::new() .amount(1000000) .asset_type(asset1) - .pub_key(&k.get_public_key()) + .pub_key(&k.get_pk()) .finalize(&mut prng) .unwrap() .build() @@ -2844,7 +2840,7 @@ mod tests { OpenAnonAssetRecordBuilder::new() .amount(900000) .asset_type(asset1) - .pub_key(&k.get_public_key()) + .pub_key(&k.get_pk()) .finalize(&mut prng) .unwrap() .build() @@ -2855,7 +2851,7 @@ mod tests { OpenAnonAssetRecordBuilder::new() .amount(2 * fee) .asset_type(ASSET_TYPE_FRA) - .pub_key(&k.get_public_key()) + .pub_key(&k.get_pk()) .finalize(&mut prng) .unwrap() .build() diff --git a/src/components/wallet_mobile/Cargo.toml b/src/components/wallet_mobile/Cargo.toml index ae87fe366..621330fd1 100644 --- a/src/components/wallet_mobile/Cargo.toml +++ b/src/components/wallet_mobile/Cargo.toml @@ -32,8 +32,8 @@ serde = { version = "1.0.124", features = ["derive"] } serde_derive = "^1.0.59" serde_json = "1.0" -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } finutils = { path = "../finutils", default-features = false, features = []} fp-types = { path = "../contracts/primitives/types" } diff --git a/src/components/wallet_mobile/src/android/constructor.rs b/src/components/wallet_mobile/src/android/constructor.rs index c6912306b..897dcd2dc 100644 --- a/src/components/wallet_mobile/src/android/constructor.rs +++ b/src/components/wallet_mobile/src/android/constructor.rs @@ -17,7 +17,7 @@ pub unsafe extern "system" fn Java_com_findora_JniApi_xfrKeyPairNew( let mut buf = [0u8; ASSET_TYPE_LENGTH]; buf.copy_from_slice(input.as_ref()); let mut prng = ChaChaRng::from_seed(buf); - let val = types::XfrKeyPair::from(RawXfrKeyPair::generate(&mut prng)); + let val = types::XfrKeyPair::from(RawXfrKeyPair::generate_ed25519(&mut prng)); Box::into_raw(Box::new(val)) as jlong } diff --git a/src/components/wallet_mobile/src/rust/account.rs b/src/components/wallet_mobile/src/rust/account.rs index e6ecdb1b9..87a52fc20 100644 --- a/src/components/wallet_mobile/src/rust/account.rs +++ b/src/components/wallet_mobile/src/rust/account.rs @@ -1,6 +1,6 @@ use core::str::FromStr; use ledger::data_model::ASSET_TYPE_FRA; -use noah::xfr::sig::{XfrKeyPair, XfrPublicKey}; +use noah::keys::{KeyPair as XfrKeyPair, PublicKey as XfrPublicKey}; use ruc::{d, Result, RucResult}; use super::transaction::TransactionBuilder; diff --git a/src/components/wallet_mobile/src/rust/crypto.rs b/src/components/wallet_mobile/src/rust/crypto.rs index 6f75ea33e..db8e33589 100644 --- a/src/components/wallet_mobile/src/rust/crypto.rs +++ b/src/components/wallet_mobile/src/rust/crypto.rs @@ -20,8 +20,10 @@ use ledger::{ }, staking::{MAX_DELEGATION_AMOUNT, MIN_DELEGATION_AMOUNT}, }; +use noah::keys::{ + KeyPair as XfrKeyPair, PublicKey as XfrPublicKey, SecretKey as XfrSecretKey, +}; use noah::xfr::asset_record::open_blind_asset_record as open_bar; -use noah::xfr::sig::{XfrKeyPair, XfrPublicKey, XfrSecretKey}; use noah::xfr::structs::{ AssetType as NoahAssetType, OpenAssetRecord, XfrBody, ASSET_TYPE_LENGTH, }; @@ -104,7 +106,7 @@ pub fn get_priv_key_str(key_pair: &XfrKeyPair) -> String { /// Creates a new transfer key pair. pub fn new_keypair() -> XfrKeyPair { let mut prng = ChaChaRng::from_entropy(); - XfrKeyPair::generate(&mut prng) + XfrKeyPair::generate_ed25519(&mut prng) } #[cfg_attr(target_arch = "wasm32", wasm_bindgen)] @@ -113,7 +115,7 @@ pub fn new_keypair_from_seed(seed_str: String, name: Option) -> XfrKeyPa let seed_str = seed_str + &name.unwrap_or_default(); let hash = sha256::hash(seed_str.as_bytes()); let mut prng = ChaChaRng::from_seed(hash.0); - XfrKeyPair::generate(&mut prng) + XfrKeyPair::generate_ed25519(&mut prng) } #[cfg_attr(target_arch = "wasm32", wasm_bindgen)] @@ -167,7 +169,7 @@ pub fn rs_wasm_credential_verify_commitment( issuer_pub_key, commitment.get_ref(), pok.get_ref(), - &xfr_pk.to_bytes(), + &xfr_pk.noah_to_bytes(), ) } @@ -248,7 +250,7 @@ pub fn rs_wasm_credential_commit( &mut prng, user_secret_key, credential.get_cred_ref(), - &user_public_key.to_bytes(), + &user_public_key.noah_to_bytes(), )?; Ok(CredentialCommitmentData { commitment: CredentialCommitment { commitment }, @@ -432,7 +434,7 @@ impl From<&BipPath> for wallet::BipPath { /// Restore the XfrKeyPair from a mnemonic with a default bip44-path, /// that is "m/44'/917'/0'/0/0" ("m/44'/coin'/account'/change/address"). pub fn rs_restore_keypair_from_mnemonic_default(phrase: &str) -> Result { - wallet::restore_keypair_from_mnemonic_default(phrase) + wallet::restore_keypair_from_mnemonic_secp256k1(phrase) } /// Restore the XfrKeyPair from a mnemonic with custom params, diff --git a/src/components/wallet_mobile/src/rust/data_model.rs b/src/components/wallet_mobile/src/rust/data_model.rs index 176eb91dc..0e5e1591f 100644 --- a/src/components/wallet_mobile/src/rust/data_model.rs +++ b/src/components/wallet_mobile/src/rust/data_model.rs @@ -14,7 +14,7 @@ use ledger::data_model::{ SignatureRules as PlatformSignatureRules, TxOutput, TxoRef as PlatformTxoRef, TxoSID, }; -use noah::xfr::sig::XfrPublicKey; +use noah::keys::PublicKey as XfrPublicKey; use noah::xfr::structs::{ AssetTracerDecKeys, AssetTracerEncKeys, AssetTracerKeyPair as NoahAssetTracerKeyPair, BlindAssetRecord, diff --git a/src/components/wallet_mobile/src/rust/transaction.rs b/src/components/wallet_mobile/src/rust/transaction.rs index b7e79ba44..492750521 100644 --- a/src/components/wallet_mobile/src/rust/transaction.rs +++ b/src/components/wallet_mobile/src/rust/transaction.rs @@ -15,8 +15,8 @@ use ledger::{ }, staking::{td_addr_to_bytes, PartialUnDelegation, TendermintAddr}, }; +use noah::keys::{KeyPair as XfrKeyPair, PublicKey as XfrPublicKey}; use noah::xfr::asset_record::{open_blind_asset_record as open_bar, AssetRecordType}; -use noah::xfr::sig::{XfrKeyPair, XfrPublicKey}; use noah::xfr::structs::AssetRecordTemplate; use ruc::{eg, Result as RucResult}; use serde_json::Result; diff --git a/src/components/wallet_mobile/src/rust/types.rs b/src/components/wallet_mobile/src/rust/types.rs index 392057631..88a9e9184 100644 --- a/src/components/wallet_mobile/src/rust/types.rs +++ b/src/components/wallet_mobile/src/rust/types.rs @@ -4,7 +4,7 @@ use credentials::{ CredUserPublicKey as PlatformCredUserPublicKey, CredUserSecretKey as PlatformCredUserSecretKey, }; -use noah::xfr::sig::{XfrKeyPair as NoahXfrKeyPair, XfrPublicKey as NoahXfrPublicKey}; +use noah::keys::{KeyPair as NoahXfrKeyPair, PublicKey as NoahXfrPublicKey}; use noah::xfr::structs::OpenAssetRecord as NoahOpenAssetRecord; use std::ops::{Deref, DerefMut}; diff --git a/src/components/wasm/Cargo.toml b/src/components/wasm/Cargo.toml index 67b5f5550..63b360f66 100644 --- a/src/components/wasm/Cargo.toml +++ b/src/components/wasm/Cargo.toml @@ -36,9 +36,9 @@ ruc = "1.0" # OR the compiling will fail. getrandom = { version = "0.2", features = ["js"] } -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } -noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } +noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } finutils = { path = "../finutils", default-features = false } globutils = { path = "../../libs/globutils" } diff --git a/src/components/wasm/src/wasm.rs b/src/components/wasm/src/wasm.rs index 25823d2d2..0eb786535 100644 --- a/src/components/wasm/src/wasm.rs +++ b/src/components/wasm/src/wasm.rs @@ -62,20 +62,20 @@ use { }, noah::{ anon_xfr::{ - decrypt_memo, - keys::{AXfrKeyPair, AXfrPubKey}, - nullify, parse_memo, + decrypt_memo, nullify, parse_memo, structs::{ AnonAssetRecord, Commitment, OpenAnonAssetRecord, OpenAnonAssetRecordBuilder, }, }, + keys::{ + KeyPair as XfrKeyPair, PublicKey as XfrPublicKey, SecretKey as XfrSecretKey, + }, xfr::{ asset_record::{ open_blind_asset_record as open_bar, AssetRecordType, AssetRecordType::NonConfidentialAmount_NonConfidentialAssetType, }, - sig::{XfrKeyPair, XfrPublicKey, XfrSecretKey}, structs::{ AssetRecordTemplate, AssetType as NoahAssetType, XfrBody, ASSET_TYPE_LENGTH, @@ -499,14 +499,14 @@ impl TransactionBuilder { /// Adds an operation to the transaction builder that converts a bar to abar. /// /// @param {XfrKeyPair} auth_key_pair - input bar owner key pair - /// @param {AXfrPubKey} abar_pubkey - abar receiver's public key + /// @param {XfrPublicKey} abar_pubkey - abar receiver's public key /// @param {TxoSID} input_sid - txo sid of input bar /// @param {ClientAssetRecord} input_record - pub fn add_operation_bar_to_abar( mut self, seed: String, auth_key_pair: &XfrKeyPair, - abar_pubkey: &AXfrPubKey, + abar_pubkey: &XfrPublicKey, txo_sid: u64, input_record: &ClientAssetRecord, owner_memo: Option, @@ -553,7 +553,7 @@ impl TransactionBuilder { /// @param {AnonAssetRecord} input - the ABAR to be converted /// @param {AxfrOwnerMemo} axfr owner_memo - the corresponding owner_memo of the ABAR to be converted /// @param {MTLeafInfo} mt_leaf_info - the Merkle Proof of the ABAR - /// @param {AXfrKeyPair} from_keypair - the owners Anon Key pair + /// @param {XfrKeyPair} from_keypair - the owners Anon Key pair /// @param {XfrPublic} recipient - the BAR owner public key /// @param {bool} conf_amount - whether the BAR amount should be confidential /// @param {bool} conf_type - whether the BAR asset type should be confidential @@ -562,7 +562,7 @@ impl TransactionBuilder { input: AnonAssetRecord, owner_memo: AxfrOwnerMemo, mt_leaf_info: MTLeafInfo, - from_keypair: &AXfrKeyPair, + from_keypair: &XfrKeyPair, recipient: &XfrPublicKey, conf_amount: bool, conf_type: bool, @@ -632,8 +632,8 @@ impl TransactionBuilder { /// /// @param {AnonAssetRecord} input - input abar /// @param {AxfrOwnerMemo} axfr owner_memo - input owner memo - /// @param {AXfrKeyPair} from_keypair - abar sender's private key - /// @param {AXfrPubKey} to_pub_key - receiver's Anon public key + /// @param {XfrKeyPair} from_keypair - abar sender's private key + /// @param {XfrPublicKey} to_pub_key - receiver's Anon public key /// @param {u64} to_amount - amount to send to receiver #[allow(clippy::too_many_arguments)] pub fn add_operation_anon_transfer( @@ -641,8 +641,8 @@ impl TransactionBuilder { input: AnonAssetRecord, owner_memo: AxfrOwnerMemo, mt_leaf_info: MTLeafInfo, - from_keypair: &AXfrKeyPair, - to_pub_key: &AXfrPubKey, + from_keypair: &XfrKeyPair, + to_pub_key: &XfrPublicKey, to_amount: u64, ) -> Result { let mut prng = ChaChaRng::from_entropy(); @@ -950,31 +950,17 @@ pub fn get_serialized_address(address: String) -> Result { String::from_utf8(sa).map_err(error_to_jsvalue) } -/// Generate new anonymous keys -#[wasm_bindgen] -pub fn gen_anon_keys() -> Result { - let mut prng = ChaChaRng::from_entropy(); - let keypair = AXfrKeyPair::generate(&mut prng); - - let keys = AnonKeys { - secret_key: wallet::anon_secret_key_to_base64(&keypair), - pub_key: wallet::anon_public_key_to_base64(&keypair.get_public_key()), - }; - - Ok(keys) -} - /// Get balance for an Anonymous Blind Asset Record /// @param {AnonAssetRecord} abar - ABAR for which balance needs to be queried /// @param {AxfrOwnerMemo} memo - memo corresponding to the abar -/// @param keypair {AXfrKeyPair} - AXfrKeyPair of the ABAR owner +/// @param keypair {XfrKeyPair} - XfrKeyPair of the ABAR owner /// @param MTLeafInfo {mt_leaf_info} - the Merkle proof of the ABAR from commitment tree /// @throws Will throw an error if abar fails to open #[wasm_bindgen] pub fn get_anon_balance( abar: AnonAssetRecord, memo: AxfrOwnerMemo, - keypair: AXfrKeyPair, + keypair: XfrKeyPair, mt_leaf_info: MTLeafInfo, ) -> Result { let oabar = OpenAnonAssetRecordBuilder::from_abar(&abar, memo.memo, &keypair) @@ -991,14 +977,14 @@ pub fn get_anon_balance( /// Get OABAR (Open ABAR) using the ABAR, OwnerMemo and MTLeafInfo /// @param {AnonAssetRecord} abar - ABAR which needs to be opened /// @param {AxfrOwnerMemo} memo - memo corresponding to the abar -/// @param keypair {AXfrKeyPair} - AXfrKeyPair of the ABAR owner +/// @param keypair {XfrKeyPair} - XfrKeyPair of the ABAR owner /// @param MTLeafInfo {mt_leaf_info} - the Merkle proof of the ABAR from commitment tree /// @throws Will throw an error if abar fails to open #[wasm_bindgen] pub fn get_open_abar( abar: AnonAssetRecord, memo: AxfrOwnerMemo, - keypair: AXfrKeyPair, + keypair: XfrKeyPair, mt_leaf_info: MTLeafInfo, ) -> Result { let oabar = OpenAnonAssetRecordBuilder::from_abar(&abar, memo.memo, &keypair) @@ -1018,14 +1004,14 @@ pub fn get_open_abar( /// Generate nullifier hash using ABAR, OwnerMemo and MTLeafInfo /// @param {AnonAssetRecord} abar - ABAR for which balance needs to be queried /// @param {AxfrOwnerMemo} memo - memo corresponding to the abar -/// @param keypair {AXfrKeyPair} - AXfrKeyPair of the ABAR owner +/// @param keypair {XfrKeyPair} - XfrKeyPair of the ABAR owner /// @param MTLeafInfo {mt_leaf_info} - the Merkle proof of the ABAR from commitment tree /// @throws Will throw an error if abar fails to open #[wasm_bindgen] pub fn gen_nullifier_hash( abar: AnonAssetRecord, memo: AxfrOwnerMemo, - keypair: AXfrKeyPair, + keypair: XfrKeyPair, mt_leaf_info: MTLeafInfo, ) -> Result { let oabar = OpenAnonAssetRecordBuilder::from_abar(&abar, memo.memo, &keypair) @@ -1345,14 +1331,14 @@ impl AnonTransferOperationBuilder { /// add_input is used to add a new input source for Anon Transfer /// @param {AnonAssetRecord} abar - input ABAR to transfer /// @param {AxfrOwnerMemo} memo - memo corresponding to the input abar - /// @param keypair {AXfrKeyPair} - AXfrKeyPair of the ABAR owner + /// @param keypair {XfrKeyPair} - XfrKeyPair of the ABAR owner /// @param MTLeafInfo {mt_leaf_info} - the Merkle proof of the ABAR from commitment tree /// @throws Will throw an error if abar fails to open, input fails to get added to Operation pub fn add_input( mut self, abar: &AnonAssetRecord, memo: &AxfrOwnerMemo, - keypair: &AXfrKeyPair, + keypair: &XfrKeyPair, mt_leaf_info: MTLeafInfo, ) -> Result { let oabar = OpenAnonAssetRecordBuilder::from_abar( @@ -1377,13 +1363,13 @@ impl AnonTransferOperationBuilder { /// add_output is used to add a output to the Anon Transfer /// @param amount {u64} - amount to be sent to the receiver - /// @param to {AXfrPubKey} - original pub key of receiver + /// @param to {XfrPublicKey} - original pub key of receiver /// @throws error if ABAR fails to be built pub fn add_output( mut self, amount: u64, asset_type: String, - to: AXfrPubKey, + to: XfrPublicKey, ) -> Result { let mut prng = ChaChaRng::from_entropy(); @@ -1408,9 +1394,9 @@ impl AnonTransferOperationBuilder { } /// add_keypair is used to add the sender's keypair for the nullifier generation - /// @param to {AXfrKeyPair} - original keypair of sender + /// @param to {XfrKeyPair} - original keypair of sender /// @throws error if ABAR fails to be built - pub fn add_keypair(mut self, keypair: &AXfrKeyPair) -> AnonTransferOperationBuilder { + pub fn add_keypair(mut self, keypair: &XfrKeyPair) -> AnonTransferOperationBuilder { self.get_builder_mut().add_keypair(keypair.clone()); self @@ -1521,7 +1507,7 @@ pub fn get_priv_key_hex_str_by_mnemonic( ) -> Result { let key_pair = wallet::restore_keypair_from_mnemonic_cus(phrase, 0, 0, num) .map_err(error_to_jsvalue)?; - let data = key_pair.get_sk_ref().to_bytes(); + let data = key_pair.get_sk_ref().noah_to_bytes(); Ok(format!("0x{}", hex::encode(&data[1..]))) } @@ -1539,7 +1525,7 @@ pub fn get_keypair_by_pri_key(hex_priv_key: &str) -> Result /// pub fn get_pub_key_hex_str_by_priv_key(hex_priv_key: &str) -> Result { let key_pair = get_keypair_by_pri_key(hex_priv_key)?; - let data = key_pair.get_pk_ref().to_bytes(); + let data = key_pair.get_pk_ref().noah_to_bytes(); Ok(format!("0x{}", hex::encode(&data[1..]))) } @@ -1553,7 +1539,7 @@ pub fn get_address_by_public_key(hex_pub_key: &str) -> Result { }; let mut data = vec![KeyType::Secp256k1 as u8]; data.extend_from_slice(&byte); - let pub_key = XfrPublicKey::from_bytes(&data).map_err(error_to_jsvalue)?; + let pub_key = XfrPublicKey::noah_from_bytes(&data).map_err(error_to_jsvalue)?; if let XfrPublicKeyInner::Secp256k1(pub_key) = pub_key.inner() { Ok(format!( "{:?}", @@ -1601,7 +1587,7 @@ pub fn new_keypair_from_seed(seed_str: String, name: Option) -> XfrKeyPa let seed_str = seed_str + &name.unwrap_or_default(); let hash = sha256::hash(&seed_str.as_bytes()); let mut prng = ChaChaRng::from_seed(hash.0); - XfrKeyPair::generate(&mut prng) + XfrKeyPair::generate_ed25519(&mut prng) } #[wasm_bindgen] @@ -1671,7 +1657,7 @@ pub fn wasm_credential_verify_commitment( issuer_pub_key, commitment.get_ref(), pok.get_ref(), - &xfr_pk.to_bytes(), + &xfr_pk.noah_to_bytes(), ) .c(d!()) .map_err(error_to_jsvalue) @@ -1783,7 +1769,7 @@ pub fn wasm_credential_commit( &mut prng, &user_secret_key, credential.get_cred_ref(), - &user_public_key.to_bytes(), + &user_public_key.noah_to_bytes(), ) .c(d!()) .map_err(error_to_jsvalue)?; @@ -1889,7 +1875,7 @@ pub fn trace_assets( // Author: Chao Ma, github.com/chaosma. // ////////////////////////////////////////// -use crate::wasm_data_model::{AmountAssetType, AnonKeys}; +use crate::wasm_data_model::AmountAssetType; use aes_gcm::aead::{generic_array::GenericArray, Aead, KeyInit}; use aes_gcm::Aes256Gcm; use base64::URL_SAFE; @@ -1898,8 +1884,9 @@ use getrandom::getrandom; use js_sys::JsString; use ledger::data_model::{ABARData, TxoSID, BAR_TO_ABAR_TX_FEE_MIN}; use ledger::staking::Amount; -use noah::xfr::sig::{ - convert_libsecp256k1_public_key_to_address, KeyType, XfrPublicKeyInner, +use noah::keys::{ + convert_libsecp256k1_public_key_to_address, KeyType, + PublicKeyInner as XfrPublicKeyInner, }; use rand_core::{CryptoRng, RngCore}; use ring::pbkdf2; @@ -2091,7 +2078,7 @@ impl From<&BipPath> for wallet::BipPath { pub fn restore_keypair_from_mnemonic_default( phrase: &str, ) -> Result { - wallet::restore_keypair_from_mnemonic_default(phrase) + wallet::restore_keypair_from_mnemonic_secp256k1(phrase) .c(d!()) .map_err(error_to_jsvalue) } @@ -2196,38 +2183,6 @@ pub fn get_delegation_max_amount() -> u64 { MAX_DELEGATION_AMOUNT } -#[wasm_bindgen] -#[allow(missing_docs)] -pub fn axfr_pubkey_from_string(key_str: &str) -> Result { - wallet::anon_public_key_from_base64(key_str) - .c(d!()) - .map_err(error_to_jsvalue) -} - -#[wasm_bindgen] -#[allow(missing_docs)] -pub fn axfr_keypair_from_string(key_str: &str) -> Result { - wallet::anon_secret_key_from_base64(key_str) - .c(d!()) - .map_err(error_to_jsvalue) -} - -#[wasm_bindgen] -#[allow(missing_docs)] -pub fn x_pubkey_from_string(key_str: &str) -> Result { - wallet::x_public_key_from_base64(key_str) - .c(d!()) - .map_err(error_to_jsvalue) -} - -#[wasm_bindgen] -#[allow(missing_docs)] -pub fn x_secretkey_from_string(key_str: &str) -> Result { - wallet::x_secret_key_from_base64(key_str) - .c(d!()) - .map_err(error_to_jsvalue) -} - #[wasm_bindgen] #[allow(missing_docs)] pub fn abar_from_json(json: JsValue) -> Result { @@ -2244,7 +2199,7 @@ pub fn abar_from_json(json: JsValue) -> Result { pub fn open_abar( abar: AnonAssetRecord, memo: AxfrOwnerMemo, - keypair: &AXfrKeyPair, + keypair: &XfrKeyPair, ) -> Result { let oabar = OpenAnonAssetRecordBuilder::from_abar(&abar, memo.memo, &keypair.clone()) @@ -2271,7 +2226,7 @@ pub fn open_abar( /// Return Ok(amount, asset_type, blinding) otherwise. pub fn decrypt_axfr_memo( memo: &AxfrOwnerMemo, - key_pair: &AXfrKeyPair, + key_pair: &XfrKeyPair, abar: &AnonAssetRecord, ) -> Result { let (amount, asset_type, blind) = decrypt_memo(&memo.memo, key_pair, abar) @@ -2291,9 +2246,9 @@ pub fn decrypt_axfr_memo( /// Return Ok(amount, asset_type, blinding) if memo is own. pub fn try_decrypt_axfr_memo( memo: &AxfrOwnerMemo, - key_pair: &AXfrKeyPair, + key_pair: &XfrKeyPair, ) -> Result, JsValue> { - let secret_key = key_pair.get_secret_key(); + let secret_key = key_pair.get_sk(); let res = memo .get_memo_ref() .decrypt(&secret_key) @@ -2311,7 +2266,7 @@ pub fn try_decrypt_axfr_memo( /// Return Ok(amount, asset_type, blinding) otherwise. pub fn parse_axfr_memo( bytes: &[u8], - key_pair: &AXfrKeyPair, + key_pair: &XfrKeyPair, abar: &AnonAssetRecord, ) -> Result { let (amount, asset_type, blind) = parse_memo(bytes, key_pair, abar) @@ -2390,12 +2345,12 @@ mod test { prng: &mut R, amount: u64, asset_type: NoahAssetType, - ) -> (OpenAnonAssetRecord, AXfrKeyPair) { - let keypair = AXfrKeyPair::generate(prng); + ) -> (OpenAnonAssetRecord, XfrKeyPair) { + let keypair = XfrKeyPair::generate_ed25519(prng); let oabar = OpenAnonAssetRecordBuilder::new() .amount(u64::from(amount)) .asset_type(asset_type) - .pub_key(&keypair.get_public_key()) + .pub_key(&keypair.get_pk()) .finalize(prng) .unwrap() .build() diff --git a/src/components/wasm/src/wasm_data_model.rs b/src/components/wasm/src/wasm_data_model.rs index c7cdba803..39f37d927 100644 --- a/src/components/wasm/src/wasm_data_model.rs +++ b/src/components/wasm/src/wasm_data_model.rs @@ -16,14 +16,12 @@ use { AnonAssetRecord, AxfrOwnerMemo as NoahAxfrOwnerMemo, MTLeafInfo as NoahMTLeafInfo, }, - noah::xfr::{ - sig::XfrPublicKey, - structs::{ - AssetTracerDecKeys, AssetTracerEncKeys, - AssetTracerKeyPair as NoahAssetTracerKeyPair, BlindAssetRecord, - IdentityRevealPolicy, OwnerMemo as NoahOwnerMemo, - TracingPolicies as NoahTracingPolicies, TracingPolicy as NoahTracingPolicy, - }, + noah::keys::PublicKey as XfrPublicKey, + noah::xfr::structs::{ + AssetTracerDecKeys, AssetTracerEncKeys, + AssetTracerKeyPair as NoahAssetTracerKeyPair, BlindAssetRecord, + IdentityRevealPolicy, OwnerMemo as NoahOwnerMemo, + TracingPolicies as NoahTracingPolicies, TracingPolicy as NoahTracingPolicy, }, noah_algebra::bls12_381::BLSScalar, rand_chacha::ChaChaRng, @@ -838,48 +836,3 @@ impl AmountAssetType { self.asset_type.clone() } } - -/// AnonKeys is used to store keys for Anon proofs -#[wasm_bindgen] -#[derive(Serialize, Deserialize)] -pub struct AnonKeys { - pub(crate) secret_key: String, - pub(crate) pub_key: String, -} - -/// AnonKeys is a struct to store keys required for anon transfer -#[wasm_bindgen] -#[allow(missing_docs)] -impl AnonKeys { - pub fn from_json(json: &JsValue) -> Result { - let anon_keys: AnonKeys = json.into_serde().c(d!()).map_err(error_to_jsvalue)?; - Ok(anon_keys) - } - - pub fn to_json(&self) -> Result { - serde_json::to_string(&self) - .map(|s| JsValue::from_str(&s)) - .c(d!()) - .map_err(error_to_jsvalue) - } - - #[wasm_bindgen(getter)] - pub fn secret_key(&self) -> String { - self.secret_key.clone() - } - - #[wasm_bindgen(setter)] - pub fn set_secret_key(&mut self, secret_key: String) { - self.secret_key = secret_key; - } - - #[wasm_bindgen(getter)] - pub fn pub_key(&self) -> String { - self.pub_key.clone() - } - - #[wasm_bindgen(setter)] - pub fn set_pub_key(&mut self, pub_key: String) { - self.pub_key = pub_key; - } -} diff --git a/src/ledger/Cargo.toml b/src/ledger/Cargo.toml index c11f12ea9..3ab63d422 100644 --- a/src/ledger/Cargo.toml +++ b/src/ledger/Cargo.toml @@ -10,7 +10,7 @@ base64 = "0.13" bs58 = "0.4" bincode = "1.3.1" byteorder = "1.0.0" -curve25519-dalek = { git = "https://github.com/FindoraNetwork/curve25519-dalek", tag = "v3.2.0-f" } +curve25519-dalek = { package = "noah-curve25519-dalek", version = "4.0.0", default-features = false, features = ['serde'] } digest = '0.10' ed25519-dalek = { git = "https://github.com/FindoraNetwork/ed25519-dalek", tag = "v1.0.1-f" } hex = "0.4.2" @@ -34,10 +34,10 @@ fp-utils = { path = "../components/contracts/primitives/utils" } itertools = "0.10" ruc = "1.0" -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } -noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } -bulletproofs = { git = "https://github.com/FindoraNetwork/bulletproofs", tag = "v1.0.1-f" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } +noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } +bulletproofs = { package = "noah-bulletproofs", version = "4.0.0" } fbnc = { version = "0.2.9", default-features = false} @@ -71,10 +71,10 @@ fs2 = "0.4" storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4", optional = true } fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4", optional = true } sparse_merkle_tree = { path = "../libs/sparse_merkle_tree" } -noah-accumulators = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } +noah-accumulators = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } [target.'cfg(target_arch = "wasm32")'.dependencies] -parking_lot = { version = "0.11", features = ["wasm-bindgen"] } +parking_lot = { version = "0.11", fetiatures = ["wasm-bindgen"] } [build-dependencies] vergen = "=3.1.0" diff --git a/src/ledger/src/converter/mod.rs b/src/ledger/src/converter/mod.rs index 0e45a3166..fef67a6c1 100644 --- a/src/ledger/src/converter/mod.rs +++ b/src/ledger/src/converter/mod.rs @@ -5,10 +5,8 @@ use crate::data_model::{ }; use config::abci::global_cfg::CFG; use fp_types::{crypto::MultiSigner, H160}; -use noah::xfr::{ - sig::XfrPublicKey, - structs::{AssetType, XfrAmount, XfrAssetType}, -}; +use noah::keys::PublicKey as XfrPublicKey; +use noah::xfr::structs::{AssetType, XfrAmount, XfrAssetType}; use ruc::*; use serde::{Deserialize, Serialize}; diff --git a/src/ledger/src/data_model/__trash__.rs b/src/ledger/src/data_model/__trash__.rs index e3df68e9f..68ce55374 100644 --- a/src/ledger/src/data_model/__trash__.rs +++ b/src/ledger/src/data_model/__trash__.rs @@ -11,7 +11,7 @@ use { crate::data_model::AssetTypeCode, fixed::types::I20F12, - noah::xfr::sig::XfrPublicKey, + noah::keys::PublicKey as XfrPublicKey, noah::xfr::structs::AssetType, serde::{Deserialize, Serialize}, }; diff --git a/src/ledger/src/data_model/effects.rs b/src/ledger/src/data_model/effects.rs index 092352723..735ed7a6e 100644 --- a/src/ledger/src/data_model/effects.rs +++ b/src/ledger/src/data_model/effects.rs @@ -23,9 +23,9 @@ use { abar_to_abar::AXfrNote, structs::{AnonAssetRecord, Nullifier}, }, + keys::PublicKey as XfrPublicKey, setup::BulletproofParams, xfr::{ - sig::XfrPublicKey, structs::{XfrAmount, XfrAssetType}, verify_xfr_body, }, diff --git a/src/ledger/src/data_model/mod.rs b/src/ledger/src/data_model/mod.rs index 0fe831488..928253d2c 100644 --- a/src/ledger/src/data_model/mod.rs +++ b/src/ledger/src/data_model/mod.rs @@ -7,7 +7,9 @@ mod __trash__; mod effects; + pub use effects::{BlockEffect, TxnEffect}; +use noah::keys::PublicKey; mod test; use { @@ -40,13 +42,12 @@ use { ar_to_abar::{verify_ar_to_abar_note, ArToAbarNote}, bar_to_abar::{verify_bar_to_abar_note, BarToAbarNote}, commit, - keys::AXfrPubKey, structs::{AnonAssetRecord, AxfrOwnerMemo, Nullifier, OpenAnonAssetRecord}, }, + keys::{KeyPair as XfrKeyPair, PublicKey as XfrPublicKey}, setup::VerifierParams, xfr::{ gen_xfr_body, - sig::{XfrKeyPair, XfrPublicKey}, structs::{ AssetRecord, AssetType as NoahAssetType, BlindAssetRecord, OwnerMemo, TracingPolicies, TracingPolicy, XfrAmount, XfrAssetType, XfrBody, @@ -397,17 +398,23 @@ pub struct ConfidentialMemo; pub struct Commitment([u8; 32]); #[allow(missing_docs)] -#[derive( - Clone, Copy, Debug, Default, Deserialize, PartialEq, Eq, PartialOrd, Ord, Serialize, -)] +#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, PartialOrd, Ord, Serialize)] pub struct XfrAddress { pub key: XfrPublicKey, } +impl Default for XfrAddress { + fn default() -> Self { + XfrAddress { + key: PublicKey::default_ed25519(), + } + } +} + impl XfrAddress { #[cfg(all(not(target_arch = "wasm32"), feature = "fin_storage"))] pub(crate) fn to_base64(self) -> String { - b64enc(&self.key.to_bytes()) + b64enc(&self.key.noah_to_bytes()) } // pub(crate) fn to_bytes(self) -> Vec { @@ -417,20 +424,6 @@ impl XfrAddress { #[allow(clippy::derive_hash_xor_eq)] impl Hash for XfrAddress { - #[inline(always)] - fn hash(&self, state: &mut H) { - self.key.to_bytes().hash(state); - } -} - -#[allow(missing_docs)] -#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Eq, Serialize)] -pub struct AXfrAddress { - pub key: AXfrPubKey, -} - -#[allow(clippy::derive_hash_xor_eq)] -impl Hash for AXfrAddress { #[inline(always)] fn hash(&self, state: &mut H) { self.key.noah_to_bytes().hash(state); @@ -438,17 +431,23 @@ impl Hash for AXfrAddress { } #[allow(missing_docs)] -#[derive( - Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Ord, PartialOrd, Serialize, -)] +#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Ord, PartialOrd, Serialize)] pub struct IssuerPublicKey { pub key: XfrPublicKey, } +impl Default for IssuerPublicKey { + fn default() -> Self { + IssuerPublicKey { + key: PublicKey::default_ed25519(), + } + } +} + impl IssuerPublicKey { #[cfg(all(not(target_arch = "wasm32"), feature = "fin_storage"))] pub(crate) fn to_base64(self) -> String { - b64enc(&self.key.to_bytes()) + b64enc(&self.key.noah_to_bytes()) } // pub(crate) fn to_bytes(&self) -> Vec { @@ -460,7 +459,7 @@ impl IssuerPublicKey { impl Hash for IssuerPublicKey { #[inline(always)] fn hash(&self, state: &mut H) { - self.key.to_bytes().hash(state); + self.key.noah_to_bytes().hash(state); } } @@ -478,11 +477,19 @@ pub struct IssuerKeyPair<'a> { pub keypair: &'a XfrKeyPair, } -#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] +#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)] struct AccountAddress { pub key: XfrPublicKey, } +impl Default for AccountAddress { + fn default() -> Self { + AccountAddress { + key: PublicKey::default_ed25519(), + } + } +} + #[allow(missing_docs)] #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] pub struct IndexedSignature { @@ -523,7 +530,7 @@ impl SignatureRules { let mut weight_map = HashMap::new(); // Convert to map for (key, weight) in self.weights.iter() { - weight_map.insert(key.to_bytes(), *weight); + weight_map.insert(key.noah_to_bytes(), *weight); } // Calculate weighted sum for key in keyset.iter() { @@ -2123,7 +2130,7 @@ impl Transaction { #[allow(missing_docs)] pub fn sign_to_map(&mut self, keypair: &XfrKeyPair) { self.pubkey_sign_map - .insert(keypair.pub_key, SignatureOf::new(keypair, &self.body)); + .insert(keypair.get_pk(), SignatureOf::new(keypair, &self.body)); } #[inline(always)] @@ -2354,7 +2361,7 @@ impl RngCore for ConsensusRng { #[inline(always)] #[allow(missing_docs)] pub fn gen_random_keypair() -> XfrKeyPair { - XfrKeyPair::generate(&mut ChaChaRng::from_entropy()) + XfrKeyPair::generate_ed25519(&mut ChaChaRng::from_entropy()) } #[inline(always)] diff --git a/src/ledger/src/data_model/test.rs b/src/ledger/src/data_model/test.rs index 8b0e1918d..956fb460b 100755 --- a/src/ledger/src/data_model/test.rs +++ b/src/ledger/src/data_model/test.rs @@ -164,7 +164,7 @@ fn gen_sample_tx() -> Transaction { let mut prng = rand_chacha::ChaChaRng::from_entropy(); - let keypair = XfrKeyPair::generate(&mut prng); + let keypair = XfrKeyPair::generate_ed25519(&mut prng); let xfr_note = XfrBody { inputs: Vec::new(), diff --git a/src/ledger/src/staking/cosig.rs b/src/ledger/src/staking/cosig.rs index 041631f71..78aa54e57 100644 --- a/src/ledger/src/staking/cosig.rs +++ b/src/ledger/src/staking/cosig.rs @@ -11,7 +11,9 @@ use { staking::{Staking, ValidatorData}, }, cryptohash::sha256::{self, Digest}, - noah::xfr::sig::{XfrKeyPair, XfrPublicKey, XfrSignature}, + noah::keys::{ + KeyPair as XfrKeyPair, PublicKey as XfrPublicKey, Signature as XfrSignature, + }, ruc::*, serde::{Deserialize, Serialize}, std::{ @@ -232,7 +234,9 @@ mod test { fn gen_keypairs(n: u8) -> Vec { let mut prng = ChaChaRng::from_entropy(); - (0..n).map(|_| XfrKeyPair::generate(&mut prng)).collect() + (0..n) + .map(|_| XfrKeyPair::generate_ed25519(&mut prng)) + .collect() } fn no_replay_token() -> NoReplayToken { diff --git a/src/ledger/src/staking/mod.rs b/src/ledger/src/staking/mod.rs index fca45ab10..d5fbd2120 100644 --- a/src/ledger/src/staking/mod.rs +++ b/src/ledger/src/staking/mod.rs @@ -33,7 +33,7 @@ use { globutils::wallet, indexmap::IndexMap, lazy_static::lazy_static, - noah::xfr::sig::{XfrKeyPair, XfrPublicKey}, + noah::keys::{KeyPair as XfrKeyPair, PublicKey as XfrPublicKey}, ops::{ fra_distribution::FraDistributionOps, mint_fra::{MintKind, MINT_AMOUNT_LIMIT}, @@ -250,7 +250,7 @@ impl Staking { #[inline(always)] fn gen_consensus_tmp_pubkey(cr: &mut ConsensusRng) -> XfrPublicKey { - XfrKeyPair::generate(cr).get_pk() + XfrKeyPair::generate_ed25519(cr).get_pk() } #[inline(always)] diff --git a/src/ledger/src/staking/ops/claim.rs b/src/ledger/src/staking/ops/claim.rs index c2e33f920..3575d4fe3 100644 --- a/src/ledger/src/staking/ops/claim.rs +++ b/src/ledger/src/staking/ops/claim.rs @@ -6,7 +6,9 @@ use { crate::{data_model::NoReplayToken, staking::Staking}, - noah::xfr::sig::{XfrKeyPair, XfrPublicKey, XfrSignature}, + noah::keys::{ + KeyPair as XfrKeyPair, PublicKey as XfrPublicKey, Signature as XfrSignature, + }, ruc::*, serde::{Deserialize, Serialize}, }; diff --git a/src/ledger/src/staking/ops/delegation.rs b/src/ledger/src/staking/ops/delegation.rs index 95739298d..cfd670866 100644 --- a/src/ledger/src/staking/ops/delegation.rs +++ b/src/ledger/src/staking/ops/delegation.rs @@ -16,10 +16,10 @@ use { }, }, ed25519_dalek::Signer, - noah::xfr::{ - sig::{XfrKeyPair, XfrPublicKey, XfrSignature}, - structs::{XfrAmount, XfrAssetType}, + noah::keys::{ + KeyPair as XfrKeyPair, PublicKey as XfrPublicKey, Signature as XfrSignature, }, + noah::xfr::structs::{XfrAmount, XfrAssetType}, ruc::*, serde::{Deserialize, Serialize}, std::collections::HashSet, diff --git a/src/ledger/src/staking/ops/fra_distribution.rs b/src/ledger/src/staking/ops/fra_distribution.rs index 591623807..d6cb7771b 100644 --- a/src/ledger/src/staking/ops/fra_distribution.rs +++ b/src/ledger/src/staking/ops/fra_distribution.rs @@ -11,7 +11,7 @@ use { data_model::{NoReplayToken, Operation, Transaction}, staking::{cosig::CoSigOp, Staking}, }, - noah::xfr::sig::{XfrKeyPair, XfrPublicKey}, + noah::keys::{KeyPair as XfrKeyPair, PublicKey as XfrPublicKey}, ruc::*, serde::{Deserialize, Serialize}, std::collections::BTreeMap, diff --git a/src/ledger/src/staking/ops/governance.rs b/src/ledger/src/staking/ops/governance.rs index f57382a53..760961464 100644 --- a/src/ledger/src/staking/ops/governance.rs +++ b/src/ledger/src/staking/ops/governance.rs @@ -13,7 +13,7 @@ use { staking::{cosig::CoSigOp, Staking, TendermintAddrRef, BLOCK_HEIGHT_MAX}, }, lazy_static::lazy_static, - noah::xfr::sig::{XfrKeyPair, XfrPublicKey}, + noah::keys::{KeyPair as XfrKeyPair, PublicKey as XfrPublicKey}, ruc::*, serde::{Deserialize, Serialize}, std::collections::BTreeMap, diff --git a/src/ledger/src/staking/ops/mint_fra.rs b/src/ledger/src/staking/ops/mint_fra.rs index 3624c7626..1d7615c8b 100644 --- a/src/ledger/src/staking/ops/mint_fra.rs +++ b/src/ledger/src/staking/ops/mint_fra.rs @@ -10,12 +10,12 @@ use { data_model::TxOutput, staking::{Amount, FRA}, }, + noah::keys::PublicKey as XfrPublicKey, noah::xfr::{ asset_record::{build_blind_asset_record, AssetRecordType}, - sig::XfrPublicKey, structs::{AssetRecordTemplate, AssetType, OwnerMemo}, }, - noah_crypto::basic::pedersen_comm::PedersenCommitmentRistretto, + noah_algebra::ristretto::PedersenCommitmentRistretto, rand_chacha::ChaChaRng, rand_core::SeedableRng, serde::{Deserialize, Serialize}, diff --git a/src/ledger/src/staking/ops/replace_staker.rs b/src/ledger/src/staking/ops/replace_staker.rs index a58f29ee1..70376e34f 100644 --- a/src/ledger/src/staking/ops/replace_staker.rs +++ b/src/ledger/src/staking/ops/replace_staker.rs @@ -6,7 +6,9 @@ use { crate::data_model::{NoReplayToken, Transaction}, crate::staking::Staking, - noah::xfr::sig::{XfrKeyPair, XfrPublicKey, XfrSignature}, + noah::keys::{ + KeyPair as XfrKeyPair, PublicKey as XfrPublicKey, Signature as XfrSignature, + }, ruc::*, serde::{Deserialize, Serialize}, }; diff --git a/src/ledger/src/staking/ops/undelegation.rs b/src/ledger/src/staking/ops/undelegation.rs index a1076c6e1..c42552469 100644 --- a/src/ledger/src/staking/ops/undelegation.rs +++ b/src/ledger/src/staking/ops/undelegation.rs @@ -9,7 +9,9 @@ use { data_model::{NoReplayToken, Operation, Transaction}, staking::{PartialUnDelegation, Staking}, }, - noah::xfr::sig::{XfrKeyPair, XfrPublicKey, XfrSignature}, + noah::keys::{ + KeyPair as XfrKeyPair, PublicKey as XfrPublicKey, Signature as XfrSignature, + }, ruc::*, serde::{Deserialize, Serialize}, }; diff --git a/src/ledger/src/staking/ops/update_staker.rs b/src/ledger/src/staking/ops/update_staker.rs index 5e03a6d55..ada0c7f58 100644 --- a/src/ledger/src/staking/ops/update_staker.rs +++ b/src/ledger/src/staking/ops/update_staker.rs @@ -10,7 +10,9 @@ use { staking::{td_addr_to_string, Staking, TendermintAddr, Validator}, }, ed25519_dalek::Signer, - noah::xfr::sig::{XfrKeyPair, XfrPublicKey, XfrSignature}, + noah::keys::{ + KeyPair as XfrKeyPair, PublicKey as XfrPublicKey, Signature as XfrSignature, + }, ruc::*, serde::{Deserialize, Serialize}, tendermint::{signature::Ed25519Signature, PrivateKey, PublicKey, Signature}, diff --git a/src/ledger/src/staking/ops/update_validator.rs b/src/ledger/src/staking/ops/update_validator.rs index fbb9b12eb..da40e798f 100644 --- a/src/ledger/src/staking/ops/update_validator.rs +++ b/src/ledger/src/staking/ops/update_validator.rs @@ -13,7 +13,7 @@ use { COSIG_THRESHOLD_DEFAULT, VALIDATORS_MIN, }, }, - noah::xfr::sig::{XfrKeyPair, XfrPublicKey}, + noah::keys::{KeyPair as XfrKeyPair, PublicKey as XfrPublicKey}, ruc::*, }; diff --git a/src/ledger/src/store/api_cache.rs b/src/ledger/src/store/api_cache.rs index 38bb290bc..5fcc2e387 100644 --- a/src/ledger/src/store/api_cache.rs +++ b/src/ledger/src/store/api_cache.rs @@ -22,10 +22,8 @@ use { globutils::{wallet, HashOf}, noah::{ anon_xfr::structs::AxfrOwnerMemo, - xfr::{ - sig::XfrPublicKey, - structs::{AssetType, OwnerMemo}, - }, + keys::PublicKey as XfrPublicKey, + xfr::structs::{AssetType, OwnerMemo}, }, ruc::*, serde::{Deserialize, Serialize}, diff --git a/src/ledger/src/store/helpers.rs b/src/ledger/src/store/helpers.rs index b74d65475..3ab410be7 100644 --- a/src/ledger/src/store/helpers.rs +++ b/src/ledger/src/store/helpers.rs @@ -12,13 +12,13 @@ use { fbnc::NumKey, fp_utils::hashing::keccak_256, globutils::SignatureOf, + noah::keys::{KeyPair as XfrKeyPair, PublicKey as XfrPublicKey}, noah::xfr::{ asset_record::AssetRecordType, asset_record::{build_blind_asset_record, open_blind_asset_record}, - sig::{XfrKeyPair, XfrPublicKey}, structs::{AssetRecord, AssetRecordTemplate, AssetType}, }, - noah_crypto::basic::pedersen_comm::PedersenCommitmentRistretto, + noah_algebra::ristretto::PedersenCommitmentRistretto, rand_core::{CryptoRng, RngCore}, ruc::*, std::fmt::Debug, @@ -27,7 +27,7 @@ use { #[inline(always)] #[allow(missing_docs)] pub fn build_keys(prng: &mut R) -> XfrKeyPair { - XfrKeyPair::generate(prng) + XfrKeyPair::generate_ed25519(prng) } #[allow(missing_docs)] diff --git a/src/ledger/src/store/mod.rs b/src/ledger/src/store/mod.rs index 75fb1a7ef..45a032a38 100644 --- a/src/ledger/src/store/mod.rs +++ b/src/ledger/src/store/mod.rs @@ -44,9 +44,9 @@ use { }, TREE_DEPTH as MERKLE_TREE_DEPTH, }, + keys::PublicKey as XfrPublicKey, setup::VerifierParams, xfr::{ - sig::XfrPublicKey, structs::{OwnerMemo, TracingPolicies, TracingPolicy}, XfrNotePolicies, }, diff --git a/src/ledger/src/store/test.rs b/src/ledger/src/store/test.rs index c095a4625..4c6abaf38 100755 --- a/src/ledger/src/store/test.rs +++ b/src/ledger/src/store/test.rs @@ -11,17 +11,19 @@ use { }, crate::utils::{self, *}, noah::{ - anon_xfr::{keys::AXfrKeyPair, structs::OpenAnonAssetRecordBuilder}, + anon_xfr::structs::OpenAnonAssetRecordBuilder, + keys::KeyPair as XfrKeyPair, xfr::{ asset_record::{ build_blind_asset_record, open_blind_asset_record, AssetRecordType, }, - sig::XfrKeyPair, structs::{AssetRecord, AssetRecordTemplate}, }, }, - noah_algebra::prelude::{One, Zero}, - noah_crypto::basic::pedersen_comm::PedersenCommitmentRistretto, + noah_algebra::{ + prelude::{One, Zero}, + ristretto::PedersenCommitmentRistretto, + }, rand_core::SeedableRng, }; @@ -155,8 +157,8 @@ fn test_asset_transfer() { let code = AssetTypeCode::gen_random(); let mut prng = ChaChaRng::from_entropy(); - let key_pair = XfrKeyPair::generate(&mut prng); - let key_pair_adversary = XfrKeyPair::generate(&mut ledger.get_prng()); + let key_pair = XfrKeyPair::generate_ed25519(&mut prng); + let key_pair_adversary = XfrKeyPair::generate_ed25519(&mut ledger.get_prng()); let (tx, mut new_code) = create_definition_transaction( &code, @@ -487,9 +489,9 @@ fn asset_issued() { #[test] pub fn test_transferable() { let mut ledger = LedgerState::tmp_ledger(); - let issuer = XfrKeyPair::generate(&mut ledger.get_prng()); - let alice = XfrKeyPair::generate(&mut ledger.get_prng()); - let bob = XfrKeyPair::generate(&mut ledger.get_prng()); + let issuer = XfrKeyPair::generate_ed25519(&mut ledger.get_prng()); + let alice = XfrKeyPair::generate_ed25519(&mut ledger.get_prng()); + let bob = XfrKeyPair::generate_ed25519(&mut ledger.get_prng()); // Define fiat token let code = AssetTypeCode::gen_random(); @@ -641,7 +643,7 @@ pub fn test_transferable() { pub fn test_max_units() { let mut ledger = LedgerState::tmp_ledger(); - let issuer = XfrKeyPair::generate(&mut ledger.get_prng()); + let issuer = XfrKeyPair::generate_ed25519(&mut ledger.get_prng()); // Define fiat token let code = AssetTypeCode::gen_random(); @@ -775,7 +777,7 @@ fn gen_fee_operation( #[test] fn test_check_fee_with_ledger() { let mut ledger = LedgerState::tmp_ledger(); - let fra_owner_kp = XfrKeyPair::generate(&mut ChaChaRng::from_entropy()); + let fra_owner_kp = XfrKeyPair::generate_ed25519(&mut ChaChaRng::from_entropy()); let tx = utils::fra_gen_initial_tx(&fra_owner_kp); assert!(tx.check_fee()); @@ -818,7 +820,7 @@ fn test_update_anon_stores() { Nullifier::one() as Nullifier, ]; - let pub_key = AXfrKeyPair::generate(&mut prng).get_public_key(); + let pub_key = XfrKeyPair::generate_ed25519(&mut prng).get_pk(); let oabar = OpenAnonAssetRecordBuilder::new() .amount(123) .asset_type(noah::xfr::structs::AssetType([39u8; 32])) diff --git a/src/ledger/src/utils.rs b/src/ledger/src/utils.rs index d2646d017..d575fdf46 100644 --- a/src/ledger/src/utils.rs +++ b/src/ledger/src/utils.rs @@ -13,12 +13,12 @@ use { }, fbnc::NumKey, fp_utils::hashing::keccak_256, + noah::keys::KeyPair as XfrKeyPair, noah::xfr::{ asset_record::{build_blind_asset_record, AssetRecordType}, - sig::XfrKeyPair, structs::{AssetRecordTemplate, AssetType}, }, - noah_crypto::basic::pedersen_comm::PedersenCommitmentRistretto, + noah_algebra::ristretto::PedersenCommitmentRistretto, rand_chacha::ChaChaRng, rand_core::SeedableRng, ruc::*, diff --git a/src/libs/credentials/Cargo.toml b/src/libs/credentials/Cargo.toml index e470b6906..35aeabead 100644 --- a/src/libs/credentials/Cargo.toml +++ b/src/libs/credentials/Cargo.toml @@ -12,5 +12,4 @@ linear-map = {version = "1.2.0", features = ["serde_impl"] } serde = "1.0.124" serde_derive = "1.0" wasm-bindgen = { version = "=0.2.73", features = ["serde-serialize"] } -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } - +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } diff --git a/src/libs/globutils/Cargo.toml b/src/libs/globutils/Cargo.toml index fcc4613db..339830a94 100644 --- a/src/libs/globutils/Cargo.toml +++ b/src/libs/globutils/Cargo.toml @@ -12,9 +12,9 @@ serde_json = "1.0" time = "0.3" rand = "0.8" cryptohash = { path = "../cryptohash" } -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } -noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } +noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } hex = "0.4.2" bip32 = "0.3.0" diff --git a/src/libs/globutils/src/lib.rs b/src/libs/globutils/src/lib.rs index ffa3c81ab..39aa1b8bd 100644 --- a/src/libs/globutils/src/lib.rs +++ b/src/libs/globutils/src/lib.rs @@ -15,7 +15,9 @@ use { sha256::{self, Digest}, Proof, }, - noah::xfr::sig::{XfrKeyPair, XfrPublicKey, XfrSignature}, + noah::keys::{ + KeyPair as XfrKeyPair, PublicKey as XfrPublicKey, Signature as XfrSignature, + }, ruc::*, serde::{Deserialize, Deserializer, Serialize, Serializer}, std::{fs, marker::PhantomData, path::PathBuf, result::Result as StdResult}, diff --git a/src/libs/globutils/src/wallet.rs b/src/libs/globutils/src/wallet.rs index 1df500b64..76d47fd0a 100644 --- a/src/libs/globutils/src/wallet.rs +++ b/src/libs/globutils/src/wallet.rs @@ -9,14 +9,12 @@ use bip0039::{Count, Language, Mnemonic}; use ed25519_dalek_bip32::{DerivationPath, ExtendedSecretKey}; use noah::anon_xfr::structs::Nullifier; use noah::{ - anon_xfr::{ - keys::{AXfrKeyPair, AXfrPubKey}, - structs::Commitment, + anon_xfr::structs::Commitment, + keys::{ + KeyPair as XfrKeyPair, PublicKey as XfrPublicKey, SecretKey as XfrSecretKey, }, - xfr::sig::{XfrKeyPair, XfrPublicKey, XfrSecretKey}, }; use noah_algebra::serialization::NoahFromToBytes; -use noah_crypto::basic::hybrid_encryption::{XPublicKey, XSecretKey}; use ruc::*; /// Randomly generate a 12words-length mnemonic. @@ -121,7 +119,7 @@ impl BipPath { /// Restore the XfrKeyPair from a mnemonic with a default bip44-path, /// that is "m/44'/60'/0'/0/0" ("m/44'/coin'/account'/change/address"). #[inline(always)] -pub fn restore_keypair_from_mnemonic_default(phrase: &str) -> Result { +pub fn restore_keypair_from_mnemonic_secp256k1(phrase: &str) -> Result { const ETH: u32 = 60; restore_secp_keypair_from_mnemonic(phrase, "en", &BipPath::new(ETH, 0, 0, 0)).c(d!()) } @@ -245,62 +243,6 @@ pub fn public_key_from_base64(pk: &str) -> Result { .and_then(|bytes| XfrPublicKey::noah_from_bytes(&bytes).c(d!())) } -#[inline(always)] -/// Restore a anon public key from base64 -pub fn anon_public_key_from_base64(pk: &str) -> Result { - base64::decode_config(pk, base64::URL_SAFE) - .c(d!()) - .and_then(|bytes| AXfrPubKey::noah_from_bytes(&bytes).c(d!())) -} - -#[inline(always)] -/// Convert an anon public key to base64 -pub fn anon_public_key_to_base64(key: &AXfrPubKey) -> String { - base64::encode_config(AXfrPubKey::noah_to_bytes(key), base64::URL_SAFE) -} - -#[inline(always)] -/// Restore a x public key from base64 -pub fn x_public_key_from_base64(pk: &str) -> Result { - base64::decode_config(pk, base64::URL_SAFE) - .c(d!()) - .and_then(|bytes| XPublicKey::noah_from_bytes(&bytes).c(d!())) -} - -#[inline(always)] -/// Convert a x public key to base64 -pub fn x_public_key_to_base64(key: &XPublicKey) -> String { - base64::encode_config(XPublicKey::noah_to_bytes(key), base64::URL_SAFE) -} - -#[inline(always)] -/// Restore a anon secret key from base64 -pub fn anon_secret_key_from_base64(sk: &str) -> Result { - base64::decode_config(sk, base64::URL_SAFE) - .c(d!()) - .and_then(|bytes| AXfrKeyPair::noah_from_bytes(&bytes).c(d!())) -} - -#[inline(always)] -/// Convert an anon secret key to base64 -pub fn anon_secret_key_to_base64(key: &AXfrKeyPair) -> String { - base64::encode_config(AXfrKeyPair::noah_to_bytes(key), base64::URL_SAFE) -} - -#[inline(always)] -/// Restore a x secret key from base64 -pub fn x_secret_key_from_base64(sk: &str) -> Result { - base64::decode_config(sk, base64::URL_SAFE) - .c(d!()) - .and_then(|bytes| XSecretKey::noah_from_bytes(&bytes).c(d!())) -} - -#[inline(always)] -/// Convert an anon public key to base64 -pub fn x_secret_key_to_base64(key: &XSecretKey) -> String { - base64::encode_config(XSecretKey::noah_to_bytes(key), base64::URL_SAFE) -} - #[inline(always)] /// Restore a Commitment from base64 pub fn commitment_from_base58(com: &str) -> Result { @@ -429,7 +371,7 @@ mod test { fn new_keypair() -> XfrKeyPair { let mut small_rng = rand_chacha::ChaChaRng::from_entropy(); - XfrKeyPair::generate(&mut small_rng) + XfrKeyPair::generate_ed25519(&mut small_rng) } #[test] diff --git a/src/libs/sparse_merkle_tree/Cargo.toml b/src/libs/sparse_merkle_tree/Cargo.toml index c90f569fd..d11acaf04 100644 --- a/src/libs/sparse_merkle_tree/Cargo.toml +++ b/src/libs/sparse_merkle_tree/Cargo.toml @@ -24,7 +24,7 @@ serde_derive = "1.0" serde_json = "1.0" sha2 = "0.10" storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } [dev-dependencies] temp_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } diff --git a/tools/regression/evm.py b/tools/regression/evm.py index dfa7fc8d8..5170cdf8c 100644 --- a/tools/regression/evm.py +++ b/tools/regression/evm.py @@ -22,7 +22,7 @@ def get_fra_balance(sec_key): def get_fra_anon_balance(anon_keys_path, commitments): out_str = subprocess.check_output( - [bin_path + '/fn', 'anon-balance', '--anon-keys', anon_keys_path, '--commitments', commitments]) + [bin_path + '/fn', 'anon-balance', '--from-seckey', anon_keys_path, '--commitments', commitments]) parsed = out_str.split() return int(parsed[1]) @@ -35,7 +35,7 @@ def get_asset_balance(sec_key, asset): def get_asset_anon_balance(anon_keys_path, commitments, asset): out_str = subprocess.check_output( - [bin_path + '/fn', 'anon-balance', '--anon-keys', anon_keys_path, '--commitments', commitments, + [bin_path + '/fn', 'anon-balance', '--from-seckey', anon_keys_path, '--commitments', commitments, '--asset', asset]) parsed = out_str.split() return int(parsed[1]) @@ -67,15 +67,15 @@ def get_balance(arguments): def get_anon_balance(arguments): - anon_keys_path = arguments['anon_keys'] + from_seckey = arguments['from_seckey'] commitments = arguments['commitments'] asset = arguments['asset'] balance = "" if asset is not None: - balance = get_asset_anon_balance(anon_keys_path, commitments, asset) + balance = get_asset_anon_balance(from_seckey, commitments, asset) else: - balance = get_fra_anon_balance(anon_keys_path, commitments) + balance = get_fra_anon_balance(from_seckey, commitments) print('{}balance is {} {}'.format(OKBLUE, balance, ENDC)) return balance @@ -152,7 +152,7 @@ def transfer(arguments): # Initialize Verify-Balance Parser parser_verify_anon_balance = subparsers.add_parser('verify-anon-balance', help='verify anon balance of a anon key ' 'and commitment') - parser_verify_anon_balance.add_argument('--anon-keys', help='path of anon key JSON file') + parser_verify_anon_balance.add_argument('--from-seckey', help='path of anon key JSON file') parser_verify_anon_balance.add_argument('--commitments', help='comma separated list of commitments') parser_verify_anon_balance.add_argument('--amount', default='0', help='expected balance for given address') parser_verify_anon_balance.add_argument('--asset', help='asset to query balance of') diff --git a/tools/regression/triple_masking/asset_mixing_test.sh b/tools/regression/triple_masking/asset_mixing_test.sh index bd65e13af..d5bc521cd 100755 --- a/tools/regression/triple_masking/asset_mixing_test.sh +++ b/tools/regression/triple_masking/asset_mixing_test.sh @@ -31,7 +31,7 @@ echo echo "\n\n FRA Bar To Abar ..." echo "===============================================================================" TXO_SID=$($BIN/fn owned-utxos | head -4 | tail -1 | awk -F ' ' '{print $1}') -$BIN/fn convert-bar-to-abar --anon-keys $FILE_ANON_KEYS --txo-sid "$TXO_SID" +$BIN/fn convert-bar-to-abar --to-address $ANON_PK_1 --txo-sid "$TXO_SID" echo "waiting block time..." sleep $TM_SLEEP @@ -42,7 +42,8 @@ then exit 1 fi commitment1=$(tail -n 1 owned_commitments) -python3 $REGRESSION_PATH/evm.py verify-anon-balance --anon-keys ./$FILE_ANON_KEYS --commitments $commitment1 --amount 210000000 +printf $ANON_SK_1 > temp +python3 $REGRESSION_PATH/evm.py verify-anon-balance --from-seckey ./temp --commitments $commitment1 --amount 210000000 if [ $? != 0 ]; then exit 1 @@ -102,14 +103,14 @@ $BIN/fn owned-utxos echo "\n\n Asset 1 Bar To Abar ..." echo "===============================================================================" TXO_SID=$($BIN/fn owned-utxos --asset "$ASSET1" | head -4 | tail -1 | awk -F ' ' '{print $1}') -$BIN/fn convert-bar-to-abar --anon-keys $FILE_ANON_KEYS --txo-sid "$TXO_SID" +$BIN/fn convert-bar-to-abar --to-address $ANON_PK_1 --txo-sid "$TXO_SID" echo "waiting block time..." sleep $TM_SLEEP echo "\n\n Asset 2 Bar To Abar ..." echo "===============================================================================" TXO_SID=$($BIN/fn owned-utxos --asset "$ASSET2" | head -4 | tail -1 | awk -F ' ' '{print $1}') -$BIN/fn convert-bar-to-abar --anon-keys $FILE_ANON_KEYS --txo-sid "$TXO_SID" +$BIN/fn convert-bar-to-abar --to-address $ANON_PK_1 --txo-sid "$TXO_SID" echo "waiting block time..." sleep $TM_SLEEP @@ -120,7 +121,8 @@ then exit 1 fi commitmentAsset1=$(tail -n 2 owned_commitments | head -n 1) -python3 $REGRESSION_PATH/evm.py verify-anon-balance --anon-keys ./$FILE_ANON_KEYS --commitments $commitmentAsset1 --amount 100000000 --asset="$ASSET1" +printf $ANON_SK_1 > temp +python3 $REGRESSION_PATH/evm.py verify-anon-balance --from-seckey ./temp --commitments $commitmentAsset1 --amount 100000000 --asset="$ASSET1" if [ $? != 0 ]; then exit 1 @@ -132,7 +134,8 @@ then exit 1 fi commitmentAsset2=$(tail -n 1 owned_commitments) -python3 $REGRESSION_PATH/evm.py verify-anon-balance --anon-keys ./$FILE_ANON_KEYS --commitments $commitmentAsset2 --amount 100000000 --asset="$ASSET2" +printf $ANON_SK_1 > temp +python3 $REGRESSION_PATH/evm.py verify-anon-balance --from-seckey ./temp --commitments $commitmentAsset2 --amount 100000000 --asset="$ASSET2" if [ $? != 0 ]; then exit 1 @@ -151,12 +154,13 @@ echo "\n\n Anon transfer Asset 1 ..." echo "===============================================================================" COMMITMENT=$(awk 'FNR==3' owned_commitments) FRA_COMMITMENT=$(awk 'FNR==2' owned_commitments) -$BIN/fn anon-transfer \ +printf $ANON_SK_1 > temp +$BIN/fn anon-transfer \ --amount 50000000 \ - --anon-keys $FILE_ANON_KEYS \ + --from-seckey ./temp \ --commitment $COMMITMENT \ --fra-commitment $FRA_COMMITMENT \ - --to-axfr-public-key $ANON_PK_2 + --to-address $ANON_PK_2 echo "waiting for transaction to complete..." sleep $TM_SLEEP @@ -192,30 +196,36 @@ echo 50000000 >> $BATCH_AMOUNT echo "" echo "Sending multi-asset transaction..." -$BIN/fn anon-transfer-batch \ - --anon-keys $FILE_ANON_KEYS \ +printf $ANON_SK_1 > temp +$BIN/fn anon-transfer-batch \ + --from-seckey ./temp \ --commitment-file $BATCH_C \ - --to-axfr-public-key-file $BATCH_PK \ + --to-address-file $BATCH_PK \ --amount-file $BATCH_AMOUNT \ --asset-file $BATCH_ASSET > /dev/null echo "waiting for transaction to complete..." sleep $TM_SLEEP echo "checking..." -$BIN/fn owned-abars --commitments $(awk 'FNR==3,FNR==4' sent_commitments | awk -v d="," '{s=(NR==1?s:s d)$0}END{print s}') --anon-keys ./$FILE_ANON_KEYS_2 -$BIN/fn owned-abars --commitments $(awk 'FNR==5' sent_commitments) --anon-keys ./$FILE_ANON_KEYS_3 +printf $ANON_SK_2 > temp +$BIN/fn owned-abars --commitments $(awk 'FNR==3,FNR==4' sent_commitments | awk -v d="," '{s=(NR==1?s:s d)$0}END{print s}') --from-seckey ./temp +printf $ANON_SK_3 > temp +$BIN/fn owned-abars --commitments $(awk 'FNR==5' sent_commitments) --from-seckey ./temp -python3 "$REGRESSION_PATH"/evm.py verify-anon-balance --anon-keys ./$FILE_ANON_KEYS_2 --commitments "$(awk 'FNR==3' sent_commitments)" --amount 10000000 +printf $ANON_SK_2 > temp +python3 "$REGRESSION_PATH"/evm.py verify-anon-balance --from-seckey ./temp --commitments "$(awk 'FNR==3' sent_commitments)" --amount 10000000 if [ $? != 0 ]; then exit 1 fi -python3 "$REGRESSION_PATH"/evm.py verify-anon-balance --anon-keys ./$FILE_ANON_KEYS_2 --commitments "$(awk 'FNR==4' sent_commitments)" --amount 10000000 --asset "$ASSET2" +printf $ANON_SK_2 > temp +python3 "$REGRESSION_PATH"/evm.py verify-anon-balance --from-seckey ./temp --commitments "$(awk 'FNR==4' sent_commitments)" --amount 10000000 --asset "$ASSET2" if [ $? != 0 ]; then exit 1 fi -python3 "$REGRESSION_PATH"/evm.py verify-anon-balance --anon-keys ./$FILE_ANON_KEYS_3 --commitments "$(awk 'FNR==5' sent_commitments)" --amount 50000000 --asset "$ASSET1" +printf $ANON_SK_3 > temp +python3 "$REGRESSION_PATH"/evm.py verify-anon-balance --from-seckey ./temp --commitments "$(awk 'FNR==5' sent_commitments)" --amount 50000000 --asset "$ASSET1" if [ $? != 0 ]; then exit 1 diff --git a/tools/regression/triple_masking/scripts/gen_keys_test-bars.sh b/tools/regression/triple_masking/scripts/gen_keys_test-bars.sh index 28bf8f286..ec6d9e86f 100755 --- a/tools/regression/triple_masking/scripts/gen_keys_test-bars.sh +++ b/tools/regression/triple_masking/scripts/gen_keys_test-bars.sh @@ -1,17 +1,18 @@ #!/usr/bin/env bash source tools/regression/triple_masking/scripts/env.sh -export KEYPAIR=$($BIN/fn genkey) -echo "Generating eth prefix address..." +export KEYPAIR=$($BIN/fn genkey ) +echo "Generating fra prefix address..." echo "$KEYPAIR" export FRA_ADDRESS=$(echo "$KEYPAIR" |awk 'NR == 2' |awk '{print $3}') -export BAR_SEC_KEY=$(echo "$KEYPAIR" |awk 'NR == 6' |awk '{gsub(/"/,""); print $2}') +export BAR_SEC_KEY=$(echo "$KEYPAIR" |awk 'NR == 5' |awk '{gsub(/"/,""); print $2}') +echo $BAR_SEC_KEY -export ED_KEYPAIR=$($BIN/fn genkey --fra-address) -echo "Generating fra prefix address..." +export ED_KEYPAIR=$($BIN/fn genkey --eth-address ) +echo "Generating eth prefix address..." echo "$ED_KEYPAIR" export ED_ADDRESS=$(echo "$ED_KEYPAIR" |awk 'NR == 2' |awk '{print $3}') -export ED_SEC_KEY=$(echo "$ED_KEYPAIR" |awk 'NR == 6' |awk '{gsub(/"/,""); print $2}') +export ED_SEC_KEY=$(echo "$ED_KEYPAIR" |awk 'NR == 5' |awk '{gsub(/"/,""); print $2}') echo -n "${ED_SEC_KEY}" > "$FILE_FRA_KEY" $BIN/fn transfer --amount 20000 --asset FRA -T $ED_ADDRESS sleep $BLOCK_INTERVAL @@ -41,33 +42,22 @@ echo "New BAR wallet with Balance:" $BIN/fn wallet --show # These wallets would be used to move Anonymous funds around -export ANON_KEYPAIR_1=$($BIN/fn gen-anon-keys) +export ANON_KEYPAIR_1=$($BIN/fn genkey) #echo "$ANON_KEYPAIR_1" |awk 'NR==2 {gsub(" ","");};1' |awk 'NR==1 {gsub("Keys :","");};1' > "$FILE_ANON_KEYS" -export ANON_SK_1=`echo "$ANON_KEYPAIR_1" |awk 'NR == 3' |awk '{gsub(/,$/,""); gsub(/"/,""); print $2}'` -export ANON_PK_1=`echo "$ANON_KEYPAIR_1" |awk 'NR == 4' |awk '{gsub(/"/,""); print $2}'` -echo " -{ - \"spend_key\": \"$ANON_SK_1\", - \"pub_key\": \"$ANON_PK_1\" -}" > "$FILE_ANON_KEYS" +export ANON_SK_1=`echo "$ANON_KEYPAIR_1" | awk 'NR == 4' | awk '{print $2}' | cut -c 2-45 ` +export ANON_PK_1=`echo "$ANON_KEYPAIR_1" | awk 'NR == 2' | awk '{print $3}' ` +echo "==================================================================" +echo $ANON_SK_1 +echo $ANON_PK_1 -export ANON_KEYPAIR_2=$($BIN/fn gen-anon-keys) +export ANON_KEYPAIR_2=$($BIN/fn genkey) #echo "$ANON_KEYPAIR_2" |awk 'NR > 1' |awk 'NR==1 {$1=$1};1' > "$FILE_ANON_KEYS_2" -export ANON_SK_2=`echo "$ANON_KEYPAIR_2" |awk 'NR == 3' |awk '{gsub(/,$/,""); gsub(/"/,""); print $2}'` -export ANON_PK_2=`echo "$ANON_KEYPAIR_2" |awk 'NR == 4' |awk '{gsub(/"/,""); print $2}'` -echo " -{ - \"spend_key\": \"$ANON_SK_2\", - \"pub_key\": \"$ANON_PK_2\" -}" > "$FILE_ANON_KEYS_2" +export ANON_SK_2=`echo "$ANON_KEYPAIR_2" | awk 'NR == 4' | awk '{print $2}' | cut -c 2-45 ` +export ANON_PK_2=`echo "$ANON_KEYPAIR_2" | awk 'NR == 2' | awk '{print $3}' ` -export ANON_KEYPAIR_3=$($BIN/fn gen-anon-keys) +export ANON_KEYPAIR_3=$($BIN/fn genkey) #echo "$ANON_KEYPAIR_3" |awk 'NR > 1' |awk 'NR==1 {$1=$1};1' > "$FILE_ANON_KEYS_3" -export ANON_SK_3=`echo "$ANON_KEYPAIR_3" |awk 'NR == 3' |awk '{gsub(/,$/,""); gsub(/"/,""); print $2}'` -export ANON_PK_3=`echo "$ANON_KEYPAIR_3" |awk 'NR == 4' |awk '{gsub(/"/,""); print $2}'` -echo " -{ - \"spend_key\": \"$ANON_SK_3\", - \"pub_key\": \"$ANON_PK_3\" -}" > "$FILE_ANON_KEYS_3" +export ANON_SK_3=`echo "$ANON_KEYPAIR_3" | awk 'NR == 4' | awk '{print $2}' | cut -c 2-45 ` +export ANON_PK_3=`echo "$ANON_KEYPAIR_3" | awk 'NR == 2' | awk '{print $3}' ` + sleep 1 \ No newline at end of file diff --git a/tools/regression/triple_masking/test_triple_masking.sh b/tools/regression/triple_masking/test_triple_masking.sh index 5017c8f04..01db56967 100755 --- a/tools/regression/triple_masking/test_triple_masking.sh +++ b/tools/regression/triple_masking/test_triple_masking.sh @@ -66,7 +66,7 @@ echo echo -e "\n ***** Bar To Abar Conversion *****" TXO_SID=$($BIN/fn owned-utxos | head -4 | tail -1 | awk -F ' ' '{print $1}') sleep 1 -$BIN/fn convert-bar-to-abar --anon-keys ./$FILE_ANON_KEYS --txo-sid $TXO_SID +$BIN/fn convert-bar-to-abar --to-address $ANON_PK_1 --txo-sid $TXO_SID sleep $TM_SLEEP echo "\n ***** Verifying balances ***** " @@ -77,7 +77,8 @@ then fi echo commitment1=$(tail -n 1 owned_commitments) -python3 $REGRESSION_PATH/evm.py verify-anon-balance --anon-keys ./$FILE_ANON_KEYS --commitments $commitment1 --amount 210000000 +printf $ANON_SK_1 > temp +python3 $REGRESSION_PATH/evm.py verify-anon-balance --from-seckey ./temp --commitments $commitment1 --amount 210000000 if [ $? != 0 ]; then exit 1 @@ -85,20 +86,24 @@ fi # test anonymous transfers echo -e "\n ***** Anonymous Transfer from Sender1 to Receiver1 ***** " -$BIN/fn anon-transfer --amount 189990000 --anon-keys ./$FILE_ANON_KEYS --to-axfr-public-key $ANON_PK_2 --commitment $commitment1 > /dev/null +printf $ANON_SK_1 > temp +$BIN/fn anon-transfer --amount 189990000 --from-seckey ./temp --to-address $ANON_PK_2 --commitment $commitment1 > /dev/null sleep $TM_SLEEP commitment2=$(tail -n 1 sent_commitments) echo -e "\n ***** Owned Abars for Receiver1 after Anon Transfer 1 ***** " -$BIN/fn owned-abars --commitments $commitment2 --anon-keys ./$FILE_ANON_KEYS_2 +printf $ANON_SK_2 > temp +$BIN/fn owned-abars --commitments $commitment2 --from-seckey ./temp echo -e "\n ***** Verifying balances ***** " -python3 "$REGRESSION_PATH"/evm.py verify-anon-balance --anon-keys ./$FILE_ANON_KEYS --commitments $commitment1 --amount 0 +printf $ANON_SK_1 > temp +python3 "$REGRESSION_PATH"/evm.py verify-anon-balance --from-seckey ./temp --commitments $commitment1 --amount 0 if [ $? != 0 ]; then exit 1 fi -python3 "$REGRESSION_PATH"/evm.py verify-anon-balance --anon-keys ./$FILE_ANON_KEYS_2 --commitments $commitment2 --amount 189990000 +printf $ANON_SK_2 > temp +python3 "$REGRESSION_PATH"/evm.py verify-anon-balance --from-seckey ./temp --commitments $commitment2 --amount 189990000 if [ $? != 0 ]; then exit 1 @@ -106,20 +111,24 @@ fi echo -e "\n ***** Anonymous Transfer from Receiver1 (Sender2) to Receiver2 ***** " -$BIN/fn anon-transfer --amount 169990000 --anon-keys ./$FILE_ANON_KEYS_2 --to-axfr-public-key $ANON_PK_3 --commitment $commitment2 > /dev/null +printf $ANON_SK_2 > temp +$BIN/fn anon-transfer --amount 169990000 --from-seckey ./temp --to-address $ANON_PK_3 --commitment $commitment2 > /dev/null sleep $TM_SLEEP commitment3=$(tail -n 1 sent_commitments) echo -e "\n ***** Owned Abars for Receiver2 after Anon Transfer 2 ***** " -$BIN/fn owned-abars --commitments $commitment3 --anon-keys ./$FILE_ANON_KEYS_3 +printf $ANON_SK_3 > temp +$BIN/fn owned-abars --commitments $commitment3 --from-seckey ./temp echo -e "\n ***** Verifying balances ***** " -python3 $REGRESSION_PATH/evm.py verify-anon-balance --anon-keys ./$FILE_ANON_KEYS_2 --commitments $commitment2 --amount 0 +printf $ANON_SK_2 > temp +python3 $REGRESSION_PATH/evm.py verify-anon-balance --from-seckey ./temp --commitments $commitment2 --amount 0 if [ $? != 0 ]; then exit 1 fi -python3 $REGRESSION_PATH/evm.py verify-anon-balance --anon-keys ./$FILE_ANON_KEYS_3 --commitments $commitment3 --amount 169990000 +printf $ANON_SK_3 > temp +python3 $REGRESSION_PATH/evm.py verify-anon-balance --from-seckey ./temp --commitments $commitment3 --amount 169990000 if [ $? != 0 ]; then exit 1 @@ -136,12 +145,14 @@ $BIN/fn owned-utxos echo -e "\n ***** Bar To Abar Conversion ***** " TXO_SID=$($BIN/fn owned-utxos | sed \$d | sed \$d | sed \$d |sort -k 1 -n | head -4 | tail -1 | awk -F ' ' '{print $1}') sleep 1 -$BIN/fn convert-bar-to-abar --anon-keys ./"$FILE_ANON_KEYS" --txo-sid "$TXO_SID" +printf $ANON_SK_1 > temp +$BIN/fn convert-bar-to-abar --txo-sid "$TXO_SID" --to-address $ANON_PK_1 sleep $TM_SLEEP commitment4=$(tail -n 1 owned_commitments) echo -e "\n Owned Abars after Bar to Abar conversion" -$BIN/fn owned-abars --commitments "$commitment4" --anon-keys ./"$FILE_ANON_KEYS" +printf $ANON_SK_1 > temp +$BIN/fn owned-abars --commitments "$commitment4" --from-seckey ./temp echo -e "\n ***** Verifying balances ***** " python3 "$REGRESSION_PATH"/evm.py verify-balance --sec-key "$BAR_SEC_KEY" --amount 419960000 @@ -149,7 +160,8 @@ if [ $? != 0 ]; then exit 1 fi -python3 "$REGRESSION_PATH"/evm.py verify-anon-balance --anon-keys ./"$FILE_ANON_KEYS" --commitments "$commitment4" --amount 210000000 +printf $ANON_SK_1 > temp +python3 "$REGRESSION_PATH"/evm.py verify-anon-balance --from-seckey ./temp --commitments "$commitment4" --amount 210000000 if [ $? != 0 ]; then exit 1 @@ -157,7 +169,8 @@ fi echo -e "\n ***** Abar To Bar Conversion ***** " -$BIN/fn convert-abar-to-bar --anon-keys ./"$FILE_ANON_KEYS" -c "$commitment4" --to-wallet-address $FRA_ADDRESS > /dev/null +printf $ANON_SK_1 > temp +$BIN/fn convert-abar-to-bar --from-seckey ./temp -c "$commitment4" --to-wallet-address $FRA_ADDRESS > /dev/null sleep $TM_SLEEP echo -e "\n ***** Verifying balances ***** " @@ -166,7 +179,8 @@ if [ $? != 0 ]; then exit 1 fi -python3 "$REGRESSION_PATH"/evm.py verify-anon-balance --anon-keys ./"$FILE_ANON_KEYS" --commitments "$commitment4" --amount 0 +printf $ANON_SK_1 > temp +python3 "$REGRESSION_PATH"/evm.py verify-anon-balance --from-seckey ./temp --commitments "$commitment4" --amount 0 if [ $? != 0 ]; then exit 1 diff --git a/tools/triple_masking/abar_to_bar_convert.sh b/tools/triple_masking/abar_to_bar_convert.sh index e30a77f9d..4f0bac9a0 100755 --- a/tools/triple_masking/abar_to_bar_convert.sh +++ b/tools/triple_masking/abar_to_bar_convert.sh @@ -13,12 +13,12 @@ tail -n 2 owned_commitments > commitment_file commitment=$(awk 'FNR==1' commitment_file) echo -e "\n\n Owned Abars after Bar to Abar conversion" sleep 20 -"$BIN"/fn owned-abars --commitments "$commitment" --anon-keys $FILE_ANON_KEYS +"$BIN"/fn owned-abars --commitments "$commitment" echo -e "\n\n\n ABAR To BAR Conversion" echo "------------------------------------------------------------------------------" sleep 5 -"$BIN"/fn convert-abar-to-bar --anon-keys ./$FILE_ANON_KEYS --commitment "$commitment" --to-wallet-address fra1ck6mu4fgmh7n3g0y5jm0zjrq6hwgckut9q2tf5fpwhrdgkhgdp9qhla5t5 +"$BIN"/fn convert-abar-to-bar --commitment "$commitment" --to-wallet-address fra1ck6mu4fgmh7n3g0y5jm0zjrq6hwgckut9q2tf5fpwhrdgkhgdp9qhla5t5 sleep 10 echo "BAR Balance: after AbarToBar" diff --git a/tools/triple_masking/anonxfr_test_demo.sh b/tools/triple_masking/anonxfr_test_demo.sh index 13006cf52..07631e955 100755 --- a/tools/triple_masking/anonxfr_test_demo.sh +++ b/tools/triple_masking/anonxfr_test_demo.sh @@ -1,14 +1,11 @@ source ./tools/devnet/env.sh || exit 1 # If breaking because of blockchain, increase the sleep time -FILE_ANON_KEYS="anon-keys-temp.keys" -FILE_ANON_KEYS_2="anon-keys-temp2.keys" +FILE_MNEMONIC_2="mnemonic-temp2.keys" +FILE_MNEMONIC_3="mnemonic-temp3.keys" -echo " -{ - \"spend_key\": \"fGAGGWYkAqcQ1DK7CbQhSbKde8WOcNld1fJlIOaDJmcdkecYCm24SiBZu44fw8uky5bBP1_1pILXyvj1O3ydJgA=\", - \"pub_key\": \"HZHnGAptuEogWbuOH8PLpMuWwT9f9aSC18r49Tt8nSYA\" -}" > $FILE_ANON_KEYS_2 +echo "neutral mirror deliver skirt rice art pulse luxury venue switch worry recycle report tackle broom beyond rapid before test supreme suggest educate cluster best" > "$FILE_MNEMONIC_2" +echo "mix sign soul link expose dinner follow bomb anchor super wisdom host baby rich west escape shock ready this primary sound rib predict round" > "$FILE_MNEMONIC_3" set -e ./tools/triple_masking/bar_to_abar_convert.sh @@ -16,21 +13,24 @@ set -e commitment1=$(tail -n 1 owned_commitments) echo "\n\n Owned Abars after Bar to Abar conversion 1" sleep 30 -"$BIN"/fn owned-abars --commitments "$commitment1" --anon-keys ./$FILE_ANON_KEYS +"$BIN"/fn owned-abars --commitments "$commitment1" echo "\n\n\n Anonymous Transfer from Sender1 to Receiver1" echo "------------------------------------------------------------------------------" -"$BIN"/fn anon-transfer --amount 189990000 --anon-keys ./$FILE_ANON_KEYS --to-axfr-public-key HZHnGAptuEogWbuOH8PLpMuWwT9f9aSC18r49Tt8nSYA --commitment "$commitment1" +"$BIN"/fn anon-transfer --amount 189990000 --to-address fra17g378zk4qn48999p8k0kdw7eawah5svayxp3xdsw4tjxkarq8suqudh6fr --commitment "$commitment1" + +"$BIN"/fn setup -O $FILE_MNEMONIC_2 -S http://0.0.0.0 commitment2=$(tail -n 1 sent_commitments) echo -e "\n\n Owned Abars for Receiver1 after Anon Transfer 1" sleep 30 -"$BIN"/fn owned-abars --commitments "$commitment2" --anon-keys ./$FILE_ANON_KEYS_2 +"$BIN"/fn owned-abars --commitments "$commitment2" echo "\n\n\n Anonymous Transfer from Receiver1 (Sender2) to Receiver2" echo "------------------------------------------------------------------------------" -"$BIN"/fn anon-transfer --amount 169990000 --anon-keys ./$FILE_ANON_KEYS_2 --to-axfr-public-key Jy2QGLGlfYJTwWwMbQsFtXXQ5nBWoAwR0hISPTAe1zEA --commitment "$commitment2" +"$BIN"/fn anon-transfer --amount 169990000 --to-address fra10n9kmllr86fxh3jaechayh9jprnq56lygchtpnnvaj68ha5cesnsa6549z --commitment "$commitment2" +"$BIN"/fn setup -O $FILE_MNEMONIC_3 -S http://0.0.0.0 sleep 2 echo "\n\n\n Fetch merkle proof for Anon Transfer 2" diff --git a/tools/triple_masking/bar_to_abar_convert.sh b/tools/triple_masking/bar_to_abar_convert.sh index 7e350b383..fe42043c6 100755 --- a/tools/triple_masking/bar_to_abar_convert.sh +++ b/tools/triple_masking/bar_to_abar_convert.sh @@ -2,31 +2,24 @@ source ./tools/devnet/env.sh || exit 1 echo "\n\n\n Simple transfer 1" echo "------------------------------------------------------------------------------" -"$BIN"/fn transfer --amount 210000000 --asset FRA -T eth1q0gdeyyac8cmu7mwfuq6sgfy63dsvja6t877jwz44lyqjra76uh5sj2faa6 +"$BIN"/fn transfer --amount 210000000 --asset FRA -T fra1qn3jkzenrktm8fmw3fmcalwzzzjwmvdry0lxzvm9lw32e4df8x0q2k7cc6 sleep 5 echo "\n\n\n Simple transfer 2" echo "------------------------------------------------------------------------------" -"$BIN"/fn transfer --amount 210000000 --asset FRA -T eth1q0gdeyyac8cmu7mwfuq6sgfy63dsvja6t877jwz44lyqjra76uh5sj2faa6 +"$BIN"/fn transfer --amount 210000000 --asset FRA -T fra1qn3jkzenrktm8fmw3fmcalwzzzjwmvdry0lxzvm9lw32e4df8x0q2k7cc6 sleep 5 echo "\n\n\n Simple transfer 3" echo "------------------------------------------------------------------------------" -"$BIN"/fn transfer --amount 210000000 --asset FRA -T eth1q0gdeyyac8cmu7mwfuq6sgfy63dsvja6t877jwz44lyqjra76uh5sj2faa6 +"$BIN"/fn transfer --amount 210000000 --asset FRA -T fra1qn3jkzenrktm8fmw3fmcalwzzzjwmvdry0lxzvm9lw32e4df8x0q2k7cc6 sleep 5 # setup the new wallet FILE_MNEMONIC="mnemonic-temp.keys" -FILE_ANON_KEYS="anon-keys-temp.keys" -echo "double quit tape enough charge fancy mandate ostrich this program laundry insect either escape cement van turtle loud immense load tip spike inquiry spice" > $FILE_MNEMONIC - -echo " -{ - \"spend_key\": \"6kpJDnAoL-_ZHekWoJBfrCmHnpYRs7WPMxdG_F9hJoQMhcLuDK2su2b4-IdYATM0Ou99yAPYcvSNdLSGnf5hBIA=\", - \"pub_key\": \"DIXC7gytrLtm-PiHWAEzNDrvfcgD2HL0jXS0hp3-YQSA\" -}" > $FILE_ANON_KEYS +echo "ivory meadow bag slide illegal phone pelican point twist eight devote view law forum loud miss host nerve mother exhaust chunk flag work arch" > $FILE_MNEMONIC "$BIN"/fn setup -O $FILE_MNEMONIC -S http://0.0.0.0 @@ -39,13 +32,13 @@ echo "\n\n\n Bar To Abar Conversion 1" echo "===============================================================================" sleep 1 TXO_SID=$("$BIN"/fn owned-utxos | head -4 | tail -1 | awk -F ' ' '{print $1}') -"$BIN"/fn convert-bar-to-abar --anon-keys ./$FILE_ANON_KEYS --txo-sid $TXO_SID +"$BIN"/fn convert-bar-to-abar --to-address fra1qn3jkzenrktm8fmw3fmcalwzzzjwmvdry0lxzvm9lw32e4df8x0q2k7cc6 --txo-sid $TXO_SID echo "\n\n\n Bar To Abar Conversion 2" echo "===============================================================================" sleep 5 TXO_SID=$("$BIN"/fn owned-utxos | head -4 | tail -1 | awk -F ' ' '{print $1}') -"$BIN"/fn convert-bar-to-abar --anon-keys ./$FILE_ANON_KEYS --txo-sid $TXO_SID +"$BIN"/fn convert-bar-to-abar --to-address fra1qn3jkzenrktm8fmw3fmcalwzzzjwmvdry0lxzvm9lw32e4df8x0q2k7cc6 --txo-sid $TXO_SID echo "Bar 2 Abar Conversion demo script executed successfully!" -echo "To check generated Abars run \`"$BIN"/fn owned-abars --anon-keys ./$FILE_ANON_KEYS --commitments COMMITMENT_STRING \`" +echo "To check generated Abars run \`"$BIN"/fn owned-abars --commitments COMMITMENT_STRING \`" From 44176751667ca4601aec802978749545c2565184 Mon Sep 17 00:00:00 2001 From: Harshad Patil Date: Tue, 31 Jan 2023 15:38:38 -0800 Subject: [PATCH 2/9] temp --- src/components/finutils/src/bins/fn.rs | 15 ++++++++++----- src/components/finutils/src/bins/fn.yml | 15 +++++++++++++++ .../triple_masking/test_triple_masking.sh | 2 ++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/components/finutils/src/bins/fn.rs b/src/components/finutils/src/bins/fn.rs index 54d86ec43..dc52395d5 100644 --- a/src/components/finutils/src/bins/fn.rs +++ b/src/components/finutils/src/bins/fn.rs @@ -496,7 +496,8 @@ fn run() -> Result<()> { .expect("commitment write failed"); } } else if let Some(m) = matches.subcommand_matches("convert-abar-to-bar") { - let is_address_eth = false; + + let is_address_eth = m.is_present("eth-address"); // sender Xfr secret key let owner_sk = read_file_path(m.value_of("from-seckey")).c(d!())?; @@ -529,7 +530,8 @@ fn run() -> Result<()> { .c(d!())?; } } else if let Some(m) = matches.subcommand_matches("owned-abars") { - let is_address_eth = false; + + let is_address_eth = m.is_present("eth-address"); // sender Xfr secret key let owner_sk = read_file_path(m.value_of("from-seckey")).c(d!())?; // parse sender XfrSecretKey or generate from Mnemonic setup with wallet @@ -549,7 +551,8 @@ fn run() -> Result<()> { common::get_owned_abars(from, commitments_list)?; } else if let Some(m) = matches.subcommand_matches("anon-balance") { - let is_address_eth = false; + + let is_address_eth = m.is_present("eth-address"); // Generates a list of owned Abars (both spent and unspent) // sender Xfr secret key let owner_sk = read_file_path(m.value_of("from-seckey")).c(d!())?; @@ -571,7 +574,8 @@ fn run() -> Result<()> { common::anon_balance(from, commitments_list, asset)?; } else if let Some(m) = matches.subcommand_matches("owned-open-abars") { - let is_address_eth = false; + + let is_address_eth = m.is_present("eth-address"); // sender Xfr secret key let owner_sk = read_file_path(m.value_of("from-seckey")).c(d!())?; // parse sender XfrSecretKey or generate from Mnemonic setup with wallet @@ -724,7 +728,8 @@ fn run() -> Result<()> { println!("{:?}", serde_json::to_string_pretty(&mt_leaf_info)); } } else if let Some(m) = matches.subcommand_matches("check-abar-status") { - let is_address_eth = false; + + let is_address_eth = m.is_present("eth-address"); // sender Xfr secret key let owner_sk = read_file_path(m.value_of("from-seckey")).c(d!())?; // parse sender XfrSecretKey or generate from Mnemonic setup with wallet diff --git a/src/components/finutils/src/bins/fn.yml b/src/components/finutils/src/bins/fn.yml index 8fa27a158..15f2b4264 100644 --- a/src/components/finutils/src/bins/fn.yml +++ b/src/components/finutils/src/bins/fn.yml @@ -563,6 +563,9 @@ subcommands: takes_value: true value_name: ASSET allow_hyphen_values: true + - eth-address: + help: if the eth address version of wallet is used + long: eth-address - anon-balance: about: List Anon balance and spending status for a public key and a list of commitments args: @@ -587,6 +590,9 @@ subcommands: takes_value: true value_name: ASSET allow_hyphen_values: true + - eth-address: + help: if the eth address version of wallet is used + long: eth-address - owned-open-abars: about: Get Open Anon UTXOs for a keypair use commitment args: @@ -605,6 +611,9 @@ subcommands: takes_value: true value_name: SECRET KEY PATH required: true + - eth-address: + help: if the eth address version of wallet is used + long: eth-address - owned-utxos: about: List owned UTXOs for a public key args: @@ -681,6 +690,9 @@ subcommands: - confidential-type: help: mask the asset type sent on the transaction log long: confidential-type + - eth-address: + help: if the eth address version of wallet is used + long: eth-address - anon-transfer: about: Perform Anonymous Transfer args: @@ -783,6 +795,9 @@ subcommands: takes_value: true value_name: SECRET KEY PATH required: true + - eth-address: + help: if the eth address version of wallet is used + long: eth-address - replace_staker: about: Replace the staker of the validator with target address args: diff --git a/tools/regression/triple_masking/test_triple_masking.sh b/tools/regression/triple_masking/test_triple_masking.sh index 01db56967..1517bb073 100755 --- a/tools/regression/triple_masking/test_triple_masking.sh +++ b/tools/regression/triple_masking/test_triple_masking.sh @@ -17,6 +17,8 @@ source $TRIPLE_MASKING_SCRIPTS_PATH/gen_keys_test-bars.sh echo -e "${YEL}Run test cases and verifying results${NC}" echo "\n ***** Verifying balances ***** " +echo $BAR_SEC_KEY +echo "====================================" python3 "$REGRESSION_PATH"/evm.py verify-balance --sec-key $BAR_SEC_KEY --amount 840000000 if [ $? != 0 ]; then From d95c6b05a0f0546fe1b41674a902ea1e795f9e2c Mon Sep 17 00:00:00 2001 From: Harshad Patil Date: Tue, 31 Jan 2023 16:41:19 -0800 Subject: [PATCH 3/9] fix integration test --- .../triple_masking/scripts/gen_keys_test-bars.sh | 9 ++++----- tools/regression/triple_masking/test_triple_masking.sh | 2 -- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/tools/regression/triple_masking/scripts/gen_keys_test-bars.sh b/tools/regression/triple_masking/scripts/gen_keys_test-bars.sh index ec6d9e86f..7e1afac99 100755 --- a/tools/regression/triple_masking/scripts/gen_keys_test-bars.sh +++ b/tools/regression/triple_masking/scripts/gen_keys_test-bars.sh @@ -4,15 +4,14 @@ source tools/regression/triple_masking/scripts/env.sh export KEYPAIR=$($BIN/fn genkey ) echo "Generating fra prefix address..." echo "$KEYPAIR" -export FRA_ADDRESS=$(echo "$KEYPAIR" |awk 'NR == 2' |awk '{print $3}') -export BAR_SEC_KEY=$(echo "$KEYPAIR" |awk 'NR == 5' |awk '{gsub(/"/,""); print $2}') -echo $BAR_SEC_KEY +export FRA_ADDRESS=$(echo "$KEYPAIR" | awk 'NR == 2' |awk '{print $3}') +export BAR_SEC_KEY=$(echo "$KEYPAIR" | awk 'NR == 4' | awk '{print $2}' | cut -c 2-45 ) export ED_KEYPAIR=$($BIN/fn genkey --eth-address ) echo "Generating eth prefix address..." echo "$ED_KEYPAIR" -export ED_ADDRESS=$(echo "$ED_KEYPAIR" |awk 'NR == 2' |awk '{print $3}') -export ED_SEC_KEY=$(echo "$ED_KEYPAIR" |awk 'NR == 5' |awk '{gsub(/"/,""); print $2}') +export ED_ADDRESS=$(echo "$ED_KEYPAIR" | awk 'NR == 2' |awk '{print $3}') +export ED_SEC_KEY=$(echo "$ED_KEYPAIR" | awk 'NR == 4' | awk '{print $2}' | cut -c 2-45 ) echo -n "${ED_SEC_KEY}" > "$FILE_FRA_KEY" $BIN/fn transfer --amount 20000 --asset FRA -T $ED_ADDRESS sleep $BLOCK_INTERVAL diff --git a/tools/regression/triple_masking/test_triple_masking.sh b/tools/regression/triple_masking/test_triple_masking.sh index 1517bb073..01db56967 100755 --- a/tools/regression/triple_masking/test_triple_masking.sh +++ b/tools/regression/triple_masking/test_triple_masking.sh @@ -17,8 +17,6 @@ source $TRIPLE_MASKING_SCRIPTS_PATH/gen_keys_test-bars.sh echo -e "${YEL}Run test cases and verifying results${NC}" echo "\n ***** Verifying balances ***** " -echo $BAR_SEC_KEY -echo "====================================" python3 "$REGRESSION_PATH"/evm.py verify-balance --sec-key $BAR_SEC_KEY --amount 840000000 if [ $? != 0 ]; then From a78763050e3363c6d671a12fbddb5cef678ebed2 Mon Sep 17 00:00:00 2001 From: Harshad Patil Date: Tue, 31 Jan 2023 20:46:04 -0800 Subject: [PATCH 4/9] fix Wasm build and formatting --- src/components/finutils/src/bins/fn.rs | 5 ----- src/components/finutils/src/common/mod.rs | 8 +++++--- src/ledger/Cargo.toml | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/components/finutils/src/bins/fn.rs b/src/components/finutils/src/bins/fn.rs index dc52395d5..20ae7934c 100644 --- a/src/components/finutils/src/bins/fn.rs +++ b/src/components/finutils/src/bins/fn.rs @@ -496,7 +496,6 @@ fn run() -> Result<()> { .expect("commitment write failed"); } } else if let Some(m) = matches.subcommand_matches("convert-abar-to-bar") { - let is_address_eth = m.is_present("eth-address"); // sender Xfr secret key let owner_sk = read_file_path(m.value_of("from-seckey")).c(d!())?; @@ -530,7 +529,6 @@ fn run() -> Result<()> { .c(d!())?; } } else if let Some(m) = matches.subcommand_matches("owned-abars") { - let is_address_eth = m.is_present("eth-address"); // sender Xfr secret key let owner_sk = read_file_path(m.value_of("from-seckey")).c(d!())?; @@ -551,7 +549,6 @@ fn run() -> Result<()> { common::get_owned_abars(from, commitments_list)?; } else if let Some(m) = matches.subcommand_matches("anon-balance") { - let is_address_eth = m.is_present("eth-address"); // Generates a list of owned Abars (both spent and unspent) // sender Xfr secret key @@ -574,7 +571,6 @@ fn run() -> Result<()> { common::anon_balance(from, commitments_list, asset)?; } else if let Some(m) = matches.subcommand_matches("owned-open-abars") { - let is_address_eth = m.is_present("eth-address"); // sender Xfr secret key let owner_sk = read_file_path(m.value_of("from-seckey")).c(d!())?; @@ -728,7 +724,6 @@ fn run() -> Result<()> { println!("{:?}", serde_json::to_string_pretty(&mt_leaf_info)); } } else if let Some(m) = matches.subcommand_matches("check-abar-status") { - let is_address_eth = m.is_present("eth-address"); // sender Xfr secret key let owner_sk = read_file_path(m.value_of("from-seckey")).c(d!())?; diff --git a/src/components/finutils/src/common/mod.rs b/src/components/finutils/src/common/mod.rs index 6cdc8a910..d68154e71 100644 --- a/src/components/finutils/src/common/mod.rs +++ b/src/components/finutils/src/common/mod.rs @@ -923,9 +923,11 @@ pub fn convert_bar2abar( ) -> Result { // parse sender XfrSecretKey or generate from Mnemonic setup with wallet let from = match owner_sk { - Some(str) => ruc::info!(serde_json::from_str::(&format!("\"{str}\""))) - .c(d!())? - .into_keypair(), + Some(str) => { + ruc::info!(serde_json::from_str::(&format!("\"{str}\""))) + .c(d!())? + .into_keypair() + } None => get_keypair(is_address_eth).c(d!())?, }; // parse receiver AxfrPubKey diff --git a/src/ledger/Cargo.toml b/src/ledger/Cargo.toml index 3ab63d422..3816cdfa9 100644 --- a/src/ledger/Cargo.toml +++ b/src/ledger/Cargo.toml @@ -74,7 +74,7 @@ sparse_merkle_tree = { path = "../libs/sparse_merkle_tree" } noah-accumulators = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } [target.'cfg(target_arch = "wasm32")'.dependencies] -parking_lot = { version = "0.11", fetiatures = ["wasm-bindgen"] } +parking_lot = { version = "0.11", features = ["wasm-bindgen"] } [build-dependencies] vergen = "=3.1.0" From 21b819ab3c979e71a6d25b53015c99fb33433fd4 Mon Sep 17 00:00:00 2001 From: Harshad Patil Date: Wed, 1 Feb 2023 12:46:34 -0800 Subject: [PATCH 5/9] fix null pointer error in WASM --- src/components/wasm/src/wasm.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/components/wasm/src/wasm.rs b/src/components/wasm/src/wasm.rs index 0eb786535..4c271523a 100644 --- a/src/components/wasm/src/wasm.rs +++ b/src/components/wasm/src/wasm.rs @@ -960,10 +960,10 @@ pub fn get_serialized_address(address: String) -> Result { pub fn get_anon_balance( abar: AnonAssetRecord, memo: AxfrOwnerMemo, - keypair: XfrKeyPair, + keypair: &XfrKeyPair, mt_leaf_info: MTLeafInfo, ) -> Result { - let oabar = OpenAnonAssetRecordBuilder::from_abar(&abar, memo.memo, &keypair) + let oabar = OpenAnonAssetRecordBuilder::from_abar(&abar, memo.memo, &keypair.clone()) .c(d!()) .map_err(error_to_jsvalue)? .mt_leaf_info(mt_leaf_info.get_noah_mt_leaf_info().clone()) @@ -984,10 +984,10 @@ pub fn get_anon_balance( pub fn get_open_abar( abar: AnonAssetRecord, memo: AxfrOwnerMemo, - keypair: XfrKeyPair, + keypair: &XfrKeyPair, mt_leaf_info: MTLeafInfo, ) -> Result { - let oabar = OpenAnonAssetRecordBuilder::from_abar(&abar, memo.memo, &keypair) + let oabar = OpenAnonAssetRecordBuilder::from_abar(&abar, memo.memo, &keypair.clone()) .c(d!()) .map_err(error_to_jsvalue)? .mt_leaf_info(mt_leaf_info.get_noah_mt_leaf_info().clone()) @@ -1011,10 +1011,10 @@ pub fn get_open_abar( pub fn gen_nullifier_hash( abar: AnonAssetRecord, memo: AxfrOwnerMemo, - keypair: XfrKeyPair, + keypair: &XfrKeyPair, mt_leaf_info: MTLeafInfo, ) -> Result { - let oabar = OpenAnonAssetRecordBuilder::from_abar(&abar, memo.memo, &keypair) + let oabar = OpenAnonAssetRecordBuilder::from_abar(&abar, memo.memo, &keypair.clone()) .c(d!()) .map_err(error_to_jsvalue)? .mt_leaf_info(mt_leaf_info.get_noah_mt_leaf_info().clone()) @@ -1023,7 +1023,7 @@ pub fn gen_nullifier_hash( .map_err(error_to_jsvalue)?; let n = nullify( - &keypair, + &keypair.clone(), oabar.get_amount(), oabar.get_asset_type().as_scalar(), mt_leaf_info.get_noah_mt_leaf_info().uid, From f8f9f3a10a35de0be659dd668e6a4bf8c2946c98 Mon Sep 17 00:00:00 2001 From: Harshad Patil Date: Wed, 1 Feb 2023 14:02:11 -0800 Subject: [PATCH 6/9] fix lint --- src/components/finutils/src/bins/fn.rs | 44 ++++++++++------------ src/components/finutils/src/common/mod.rs | 33 ++++++++--------- src/components/wasm/src/wasm.rs | 45 ++++++++++++----------- 3 files changed, 59 insertions(+), 63 deletions(-) diff --git a/src/components/finutils/src/bins/fn.rs b/src/components/finutils/src/bins/fn.rs index 20ae7934c..9b53551a7 100644 --- a/src/components/finutils/src/bins/fn.rs +++ b/src/components/finutils/src/bins/fn.rs @@ -534,12 +534,11 @@ fn run() -> Result<()> { let owner_sk = read_file_path(m.value_of("from-seckey")).c(d!())?; // parse sender XfrSecretKey or generate from Mnemonic setup with wallet let from = match owner_sk { - Some(str) => ruc::info!(serde_json::from_str::(&format!( - "\"{}\"", - str - ))) - .c(d!())? - .into_keypair(), + Some(str) => { + ruc::info!(serde_json::from_str::(&format!("\"{str}\""))) + .c(d!())? + .into_keypair() + } None => get_keypair(is_address_eth).c(d!())?, }; @@ -555,12 +554,11 @@ fn run() -> Result<()> { let owner_sk = read_file_path(m.value_of("from-seckey")).c(d!())?; // parse sender XfrSecretKey or generate from Mnemonic setup with wallet let from = match owner_sk { - Some(str) => ruc::info!(serde_json::from_str::(&format!( - "\"{}\"", - str - ))) - .c(d!(str))? - .into_keypair(), + Some(str) => { + ruc::info!(serde_json::from_str::(&format!("\"{str}\""))) + .c(d!(str))? + .into_keypair() + } None => get_keypair(is_address_eth).c(d!())?, }; let asset = m.value_of("asset"); @@ -576,12 +574,11 @@ fn run() -> Result<()> { let owner_sk = read_file_path(m.value_of("from-seckey")).c(d!())?; // parse sender XfrSecretKey or generate from Mnemonic setup with wallet let from = match owner_sk { - Some(str) => ruc::info!(serde_json::from_str::(&format!( - "\"{}\"", - str - ))) - .c(d!())? - .into_keypair(), + Some(str) => { + ruc::info!(serde_json::from_str::(&format!("\"{str}\""))) + .c(d!())? + .into_keypair() + } None => get_keypair(is_address_eth).c(d!())?, }; let commitment_str = m.value_of("commitment"); @@ -729,12 +726,11 @@ fn run() -> Result<()> { let owner_sk = read_file_path(m.value_of("from-seckey")).c(d!())?; // parse sender XfrSecretKey or generate from Mnemonic setup with wallet let from = match owner_sk { - Some(str) => ruc::info!(serde_json::from_str::(&format!( - "\"{}\"", - str - ))) - .c(d!())? - .into_keypair(), + Some(str) => { + ruc::info!(serde_json::from_str::(&format!("\"{str}\""))) + .c(d!())? + .into_keypair() + } None => get_keypair(is_address_eth).c(d!())?, }; diff --git a/src/components/finutils/src/common/mod.rs b/src/components/finutils/src/common/mod.rs index d68154e71..6cfb3b370 100644 --- a/src/components/finutils/src/common/mod.rs +++ b/src/components/finutils/src/common/mod.rs @@ -972,12 +972,11 @@ pub fn convert_abar2bar( ) -> Result<()> { // parse sender XfrSecretKey or generate from Mnemonic setup with wallet let from = match owner_sk { - Some(str) => ruc::info!(serde_json::from_str::(&format!( - "\"{}\"", - str - ))) - .c(d!())? - .into_keypair(), + Some(str) => { + ruc::info!(serde_json::from_str::(&format!("\"{str}\""))) + .c(d!())? + .into_keypair() + } None => get_keypair(is_address_eth).c(d!())?, }; @@ -1050,12 +1049,11 @@ pub fn gen_anon_transfer_op( ) -> Result<()> { // parse sender XfrSecretKey or generate from Mnemonic setup with wallet let from = match owner_sk { - Some(str) => ruc::info!(serde_json::from_str::(&format!( - "\"{}\"", - str - ))) - .c(d!())? - .into_keypair(), + Some(str) => { + ruc::info!(serde_json::from_str::(&format!("\"{str}\""))) + .c(d!())? + .into_keypair() + } None => get_keypair(is_address_eth).c(d!())?, }; @@ -1198,12 +1196,11 @@ pub fn gen_oabar_add_op_x( ) -> Result<()> { // parse sender XfrSecretKey or generate from Mnemonic setup with wallet let from = match owner_sk { - Some(str) => ruc::info!(serde_json::from_str::(&format!( - "\"{}\"", - str - ))) - .c(d!())? - .into_keypair(), + Some(str) => { + ruc::info!(serde_json::from_str::(&format!("\"{str}\""))) + .c(d!())? + .into_keypair() + } None => get_keypair(is_address_eth).c(d!())?, }; diff --git a/src/components/wasm/src/wasm.rs b/src/components/wasm/src/wasm.rs index 4c271523a..a379b0873 100644 --- a/src/components/wasm/src/wasm.rs +++ b/src/components/wasm/src/wasm.rs @@ -963,13 +963,14 @@ pub fn get_anon_balance( keypair: &XfrKeyPair, mt_leaf_info: MTLeafInfo, ) -> Result { - let oabar = OpenAnonAssetRecordBuilder::from_abar(&abar, memo.memo, &keypair.clone()) - .c(d!()) - .map_err(error_to_jsvalue)? - .mt_leaf_info(mt_leaf_info.get_noah_mt_leaf_info().clone()) - .build() - .c(d!()) - .map_err(error_to_jsvalue)?; + let oabar = + OpenAnonAssetRecordBuilder::from_abar(&abar, memo.memo, &keypair.clone()) + .c(d!()) + .map_err(error_to_jsvalue)? + .mt_leaf_info(mt_leaf_info.get_noah_mt_leaf_info().clone()) + .build() + .c(d!()) + .map_err(error_to_jsvalue)?; Ok(oabar.get_amount()) } @@ -987,13 +988,14 @@ pub fn get_open_abar( keypair: &XfrKeyPair, mt_leaf_info: MTLeafInfo, ) -> Result { - let oabar = OpenAnonAssetRecordBuilder::from_abar(&abar, memo.memo, &keypair.clone()) - .c(d!()) - .map_err(error_to_jsvalue)? - .mt_leaf_info(mt_leaf_info.get_noah_mt_leaf_info().clone()) - .build() - .c(d!()) - .map_err(error_to_jsvalue)?; + let oabar = + OpenAnonAssetRecordBuilder::from_abar(&abar, memo.memo, &keypair.clone()) + .c(d!()) + .map_err(error_to_jsvalue)? + .mt_leaf_info(mt_leaf_info.get_noah_mt_leaf_info().clone()) + .build() + .c(d!()) + .map_err(error_to_jsvalue)?; let json = JsValue::from_serde(&oabar) .c(d!()) @@ -1014,13 +1016,14 @@ pub fn gen_nullifier_hash( keypair: &XfrKeyPair, mt_leaf_info: MTLeafInfo, ) -> Result { - let oabar = OpenAnonAssetRecordBuilder::from_abar(&abar, memo.memo, &keypair.clone()) - .c(d!()) - .map_err(error_to_jsvalue)? - .mt_leaf_info(mt_leaf_info.get_noah_mt_leaf_info().clone()) - .build() - .c(d!()) - .map_err(error_to_jsvalue)?; + let oabar = + OpenAnonAssetRecordBuilder::from_abar(&abar, memo.memo, &keypair.clone()) + .c(d!()) + .map_err(error_to_jsvalue)? + .mt_leaf_info(mt_leaf_info.get_noah_mt_leaf_info().clone()) + .build() + .c(d!()) + .map_err(error_to_jsvalue)?; let n = nullify( &keypair.clone(), From 2dafb7a8e1fca93781356eaa612887f0af4afd5f Mon Sep 17 00:00:00 2001 From: Harshad Patil Date: Sun, 12 Feb 2023 22:31:24 -0800 Subject: [PATCH 7/9] Update the version of noah library & handle 32 byte public key generation --- src/components/abciapp/Cargo.toml | 4 ++-- src/components/contracts/modules/account/Cargo.toml | 2 +- src/components/contracts/modules/evm/Cargo.toml | 4 ++-- src/components/contracts/primitives/mocks/Cargo.toml | 2 +- src/components/contracts/primitives/types/Cargo.toml | 4 ++-- src/components/finutils/Cargo.toml | 6 +++--- src/components/wallet_mobile/Cargo.toml | 4 ++-- src/components/wasm/Cargo.toml | 6 +++--- src/ledger/Cargo.toml | 8 ++++---- src/libs/credentials/Cargo.toml | 2 +- src/libs/globutils/Cargo.toml | 6 +++--- src/libs/globutils/src/wallet.rs | 7 +++++-- src/libs/sparse_merkle_tree/Cargo.toml | 2 +- 13 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/components/abciapp/Cargo.toml b/src/components/abciapp/Cargo.toml index fbc282785..37534649f 100644 --- a/src/components/abciapp/Cargo.toml +++ b/src/components/abciapp/Cargo.toml @@ -44,8 +44,8 @@ ruc = { version = "1.0.5", default-features = false, features = ["compact"] } module-evm = { path = "../contracts/modules/evm"} ethereum-types = { version = "0.13.1", default-features = false } -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } abci = { git = "https://github.com/FindoraNetwork/tendermint-abci", tag = "0.7.5" } config = { path = "../config"} diff --git a/src/components/contracts/modules/account/Cargo.toml b/src/components/contracts/modules/account/Cargo.toml index 60216d22c..a1bfd2cdb 100644 --- a/src/components/contracts/modules/account/Cargo.toml +++ b/src/components/contracts/modules/account/Cargo.toml @@ -30,7 +30,7 @@ parking_lot = "0.12" rand_chacha = "0.3" storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } [features] web3_service = ["enterprise-web3"] diff --git a/src/components/contracts/modules/evm/Cargo.toml b/src/components/contracts/modules/evm/Cargo.toml index 314148429..ffb526ddb 100644 --- a/src/components/contracts/modules/evm/Cargo.toml +++ b/src/components/contracts/modules/evm/Cargo.toml @@ -24,8 +24,8 @@ serde_json = "1.0.64" sha3 = { version = "0.10", default-features = false } hex = "0.4.2" ethabi = "17.1.0" -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } # primitives, don't depend on any modules fp-core = { path = "../../primitives/core" } diff --git a/src/components/contracts/primitives/mocks/Cargo.toml b/src/components/contracts/primitives/mocks/Cargo.toml index dc6897a0f..8d388a6cd 100644 --- a/src/components/contracts/primitives/mocks/Cargo.toml +++ b/src/components/contracts/primitives/mocks/Cargo.toml @@ -18,7 +18,7 @@ rand_chacha = "0.3" rlp = "0.5" serde_json = "1.0" sha3 = "0.10" -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } # primitives fp-traits = { path = "../traits" } diff --git a/src/components/contracts/primitives/types/Cargo.toml b/src/components/contracts/primitives/types/Cargo.toml index ad2c983c7..6fdd715df 100644 --- a/src/components/contracts/primitives/types/Cargo.toml +++ b/src/components/contracts/primitives/types/Cargo.toml @@ -21,8 +21,8 @@ serde = { version = "1.0.124", features = ["derive"] } serde_json = "1.0" serde-big-array = "0.4" sha3 = "0.10" -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } # primitives fp-utils = { path = "../utils" } diff --git a/src/components/finutils/Cargo.toml b/src/components/finutils/Cargo.toml index dd23d5eeb..0c5468e9f 100644 --- a/src/components/finutils/Cargo.toml +++ b/src/components/finutils/Cargo.toml @@ -25,9 +25,9 @@ tokio = "1.10.1" wasm-bindgen = { version = "=0.2.73", features = ["serde-serialize"] } getrandom = "0.2" -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } -noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } ruc = "1.0" rucv3 = { package = "ruc", version = "3.0" } diff --git a/src/components/wallet_mobile/Cargo.toml b/src/components/wallet_mobile/Cargo.toml index 621330fd1..6d2cc1c98 100644 --- a/src/components/wallet_mobile/Cargo.toml +++ b/src/components/wallet_mobile/Cargo.toml @@ -32,8 +32,8 @@ serde = { version = "1.0.124", features = ["derive"] } serde_derive = "^1.0.59" serde_json = "1.0" -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } finutils = { path = "../finutils", default-features = false, features = []} fp-types = { path = "../contracts/primitives/types" } diff --git a/src/components/wasm/Cargo.toml b/src/components/wasm/Cargo.toml index 63b360f66..21f542064 100644 --- a/src/components/wasm/Cargo.toml +++ b/src/components/wasm/Cargo.toml @@ -36,9 +36,9 @@ ruc = "1.0" # OR the compiling will fail. getrandom = { version = "0.2", features = ["js"] } -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } -noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } finutils = { path = "../finutils", default-features = false } globutils = { path = "../../libs/globutils" } diff --git a/src/ledger/Cargo.toml b/src/ledger/Cargo.toml index 3816cdfa9..3e0e683ad 100644 --- a/src/ledger/Cargo.toml +++ b/src/ledger/Cargo.toml @@ -34,9 +34,9 @@ fp-utils = { path = "../components/contracts/primitives/utils" } itertools = "0.10" ruc = "1.0" -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } -noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } bulletproofs = { package = "noah-bulletproofs", version = "4.0.0" } fbnc = { version = "0.2.9", default-features = false} @@ -71,7 +71,7 @@ fs2 = "0.4" storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4", optional = true } fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4", optional = true } sparse_merkle_tree = { path = "../libs/sparse_merkle_tree" } -noah-accumulators = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } +noah-accumulators = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } [target.'cfg(target_arch = "wasm32")'.dependencies] parking_lot = { version = "0.11", features = ["wasm-bindgen"] } diff --git a/src/libs/credentials/Cargo.toml b/src/libs/credentials/Cargo.toml index 35aeabead..4d8dc8c51 100644 --- a/src/libs/credentials/Cargo.toml +++ b/src/libs/credentials/Cargo.toml @@ -12,4 +12,4 @@ linear-map = {version = "1.2.0", features = ["serde_impl"] } serde = "1.0.124" serde_derive = "1.0" wasm-bindgen = { version = "=0.2.73", features = ["serde-serialize"] } -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } diff --git a/src/libs/globutils/Cargo.toml b/src/libs/globutils/Cargo.toml index 339830a94..253abee70 100644 --- a/src/libs/globutils/Cargo.toml +++ b/src/libs/globutils/Cargo.toml @@ -12,9 +12,9 @@ serde_json = "1.0" time = "0.3" rand = "0.8" cryptohash = { path = "../cryptohash" } -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } -noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } hex = "0.4.2" bip32 = "0.3.0" diff --git a/src/libs/globutils/src/wallet.rs b/src/libs/globutils/src/wallet.rs index 76d47fd0a..67501ebd9 100644 --- a/src/libs/globutils/src/wallet.rs +++ b/src/libs/globutils/src/wallet.rs @@ -277,14 +277,17 @@ pub fn nullifier_to_base58(n: &Nullifier) -> String { #[inline(always)] pub fn public_key_to_bech32(key: &XfrPublicKey) -> String { let bytes = &XfrPublicKey::noah_to_bytes(key); + if bytes.len() == 32 { + return bech32enc_fra(bytes); + } match bytes[0] { 0u8 => bech32enc_fra(<&[u8; 32]>::try_from(&bytes[1..33]).unwrap()), 1u8 => bech32enc_eth(<&[u8; 33]>::try_from(&bytes[1..34]).unwrap()), 2u8 => { - panic!("public key not supported") + panic!("public key not supported {bytes:?}") } _ => { - panic!("public key not supported") + panic!("public key not supported {bytes:?}") } } } diff --git a/src/libs/sparse_merkle_tree/Cargo.toml b/src/libs/sparse_merkle_tree/Cargo.toml index d11acaf04..915f88372 100644 --- a/src/libs/sparse_merkle_tree/Cargo.toml +++ b/src/libs/sparse_merkle_tree/Cargo.toml @@ -24,7 +24,7 @@ serde_derive = "1.0" serde_json = "1.0" sha2 = "0.10" storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.2" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } [dev-dependencies] temp_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } From d7467eec9a6b01a28bcf5cfa39ed45b4ec1ad92f Mon Sep 17 00:00:00 2001 From: Harshad Patil Date: Thu, 16 Mar 2023 13:51:52 -0700 Subject: [PATCH 8/9] testing FastMSM on wasm --- src/components/abciapp/Cargo.toml | 4 ++-- src/components/contracts/modules/account/Cargo.toml | 2 +- src/components/contracts/modules/evm/Cargo.toml | 4 ++-- src/components/contracts/primitives/mocks/Cargo.toml | 2 +- src/components/contracts/primitives/types/Cargo.toml | 4 ++-- src/components/finutils/Cargo.toml | 6 +++--- src/components/wallet_mobile/Cargo.toml | 4 ++-- src/components/wasm/Cargo.toml | 6 +++--- src/ledger/Cargo.toml | 8 ++++---- src/libs/credentials/Cargo.toml | 2 +- src/libs/globutils/Cargo.toml | 6 +++--- src/libs/sparse_merkle_tree/Cargo.toml | 2 +- 12 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/components/abciapp/Cargo.toml b/src/components/abciapp/Cargo.toml index 37534649f..c4ef7c7e7 100644 --- a/src/components/abciapp/Cargo.toml +++ b/src/components/abciapp/Cargo.toml @@ -44,8 +44,8 @@ ruc = { version = "1.0.5", default-features = false, features = ["compact"] } module-evm = { path = "../contracts/modules/evm"} ethereum-types = { version = "0.13.1", default-features = false } -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } abci = { git = "https://github.com/FindoraNetwork/tendermint-abci", tag = "0.7.5" } config = { path = "../config"} diff --git a/src/components/contracts/modules/account/Cargo.toml b/src/components/contracts/modules/account/Cargo.toml index a1bfd2cdb..d3313d01c 100644 --- a/src/components/contracts/modules/account/Cargo.toml +++ b/src/components/contracts/modules/account/Cargo.toml @@ -30,7 +30,7 @@ parking_lot = "0.12" rand_chacha = "0.3" storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } [features] web3_service = ["enterprise-web3"] diff --git a/src/components/contracts/modules/evm/Cargo.toml b/src/components/contracts/modules/evm/Cargo.toml index ffb526ddb..4c71c8eac 100644 --- a/src/components/contracts/modules/evm/Cargo.toml +++ b/src/components/contracts/modules/evm/Cargo.toml @@ -24,8 +24,8 @@ serde_json = "1.0.64" sha3 = { version = "0.10", default-features = false } hex = "0.4.2" ethabi = "17.1.0" -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } # primitives, don't depend on any modules fp-core = { path = "../../primitives/core" } diff --git a/src/components/contracts/primitives/mocks/Cargo.toml b/src/components/contracts/primitives/mocks/Cargo.toml index 8d388a6cd..af2855195 100644 --- a/src/components/contracts/primitives/mocks/Cargo.toml +++ b/src/components/contracts/primitives/mocks/Cargo.toml @@ -18,7 +18,7 @@ rand_chacha = "0.3" rlp = "0.5" serde_json = "1.0" sha3 = "0.10" -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } # primitives fp-traits = { path = "../traits" } diff --git a/src/components/contracts/primitives/types/Cargo.toml b/src/components/contracts/primitives/types/Cargo.toml index 6fdd715df..c85a2f678 100644 --- a/src/components/contracts/primitives/types/Cargo.toml +++ b/src/components/contracts/primitives/types/Cargo.toml @@ -21,8 +21,8 @@ serde = { version = "1.0.124", features = ["derive"] } serde_json = "1.0" serde-big-array = "0.4" sha3 = "0.10" -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } # primitives fp-utils = { path = "../utils" } diff --git a/src/components/finutils/Cargo.toml b/src/components/finutils/Cargo.toml index 0c5468e9f..4723faff7 100644 --- a/src/components/finutils/Cargo.toml +++ b/src/components/finutils/Cargo.toml @@ -25,9 +25,9 @@ tokio = "1.10.1" wasm-bindgen = { version = "=0.2.73", features = ["serde-serialize"] } getrandom = "0.2" -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } -noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } +noah-crypto = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } ruc = "1.0" rucv3 = { package = "ruc", version = "3.0" } diff --git a/src/components/wallet_mobile/Cargo.toml b/src/components/wallet_mobile/Cargo.toml index 6d2cc1c98..719ffe3b1 100644 --- a/src/components/wallet_mobile/Cargo.toml +++ b/src/components/wallet_mobile/Cargo.toml @@ -32,8 +32,8 @@ serde = { version = "1.0.124", features = ["derive"] } serde_derive = "^1.0.59" serde_json = "1.0" -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } finutils = { path = "../finutils", default-features = false, features = []} fp-types = { path = "../contracts/primitives/types" } diff --git a/src/components/wasm/Cargo.toml b/src/components/wasm/Cargo.toml index 21f542064..cd495e382 100644 --- a/src/components/wasm/Cargo.toml +++ b/src/components/wasm/Cargo.toml @@ -36,9 +36,9 @@ ruc = "1.0" # OR the compiling will fail. getrandom = { version = "0.2", features = ["js"] } -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } -noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } +noah-crypto = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } finutils = { path = "../finutils", default-features = false } globutils = { path = "../../libs/globutils" } diff --git a/src/ledger/Cargo.toml b/src/ledger/Cargo.toml index 3e0e683ad..8135b40bb 100644 --- a/src/ledger/Cargo.toml +++ b/src/ledger/Cargo.toml @@ -34,9 +34,9 @@ fp-utils = { path = "../components/contracts/primitives/utils" } itertools = "0.10" ruc = "1.0" -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } -noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } +noah-crypto = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } bulletproofs = { package = "noah-bulletproofs", version = "4.0.0" } fbnc = { version = "0.2.9", default-features = false} @@ -71,7 +71,7 @@ fs2 = "0.4" storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4", optional = true } fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4", optional = true } sparse_merkle_tree = { path = "../libs/sparse_merkle_tree" } -noah-accumulators = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah-accumulators = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } [target.'cfg(target_arch = "wasm32")'.dependencies] parking_lot = { version = "0.11", features = ["wasm-bindgen"] } diff --git a/src/libs/credentials/Cargo.toml b/src/libs/credentials/Cargo.toml index 4d8dc8c51..11a9423d1 100644 --- a/src/libs/credentials/Cargo.toml +++ b/src/libs/credentials/Cargo.toml @@ -12,4 +12,4 @@ linear-map = {version = "1.2.0", features = ["serde_impl"] } serde = "1.0.124" serde_derive = "1.0" wasm-bindgen = { version = "=0.2.73", features = ["serde-serialize"] } -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } diff --git a/src/libs/globutils/Cargo.toml b/src/libs/globutils/Cargo.toml index 253abee70..9de987b53 100644 --- a/src/libs/globutils/Cargo.toml +++ b/src/libs/globutils/Cargo.toml @@ -12,9 +12,9 @@ serde_json = "1.0" time = "0.3" rand = "0.8" cryptohash = { path = "../cryptohash" } -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } -noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } +noah-crypto = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } hex = "0.4.2" bip32 = "0.3.0" diff --git a/src/libs/sparse_merkle_tree/Cargo.toml b/src/libs/sparse_merkle_tree/Cargo.toml index 915f88372..f863d4528 100644 --- a/src/libs/sparse_merkle_tree/Cargo.toml +++ b/src/libs/sparse_merkle_tree/Cargo.toml @@ -24,7 +24,7 @@ serde_derive = "1.0" serde_json = "1.0" sha2 = "0.10" storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } [dev-dependencies] temp_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } From bcb6374a5d791d7d4b8b6710428a13d5a40210a8 Mon Sep 17 00:00:00 2001 From: Harshad Patil Date: Fri, 17 Mar 2023 10:13:53 -0700 Subject: [PATCH 9/9] Revert "testing FastMSM on wasm" This reverts commit d7467eec9a6b01a28bcf5cfa39ed45b4ec1ad92f. --- src/components/abciapp/Cargo.toml | 4 ++-- src/components/contracts/modules/account/Cargo.toml | 2 +- src/components/contracts/modules/evm/Cargo.toml | 4 ++-- src/components/contracts/primitives/mocks/Cargo.toml | 2 +- src/components/contracts/primitives/types/Cargo.toml | 4 ++-- src/components/finutils/Cargo.toml | 6 +++--- src/components/wallet_mobile/Cargo.toml | 4 ++-- src/components/wasm/Cargo.toml | 6 +++--- src/ledger/Cargo.toml | 8 ++++---- src/libs/credentials/Cargo.toml | 2 +- src/libs/globutils/Cargo.toml | 6 +++--- src/libs/sparse_merkle_tree/Cargo.toml | 2 +- 12 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/components/abciapp/Cargo.toml b/src/components/abciapp/Cargo.toml index c4ef7c7e7..37534649f 100644 --- a/src/components/abciapp/Cargo.toml +++ b/src/components/abciapp/Cargo.toml @@ -44,8 +44,8 @@ ruc = { version = "1.0.5", default-features = false, features = ["compact"] } module-evm = { path = "../contracts/modules/evm"} ethereum-types = { version = "0.13.1", default-features = false } -noah = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } abci = { git = "https://github.com/FindoraNetwork/tendermint-abci", tag = "0.7.5" } config = { path = "../config"} diff --git a/src/components/contracts/modules/account/Cargo.toml b/src/components/contracts/modules/account/Cargo.toml index d3313d01c..a1bfd2cdb 100644 --- a/src/components/contracts/modules/account/Cargo.toml +++ b/src/components/contracts/modules/account/Cargo.toml @@ -30,7 +30,7 @@ parking_lot = "0.12" rand_chacha = "0.3" storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } -noah = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } [features] web3_service = ["enterprise-web3"] diff --git a/src/components/contracts/modules/evm/Cargo.toml b/src/components/contracts/modules/evm/Cargo.toml index 4c71c8eac..ffb526ddb 100644 --- a/src/components/contracts/modules/evm/Cargo.toml +++ b/src/components/contracts/modules/evm/Cargo.toml @@ -24,8 +24,8 @@ serde_json = "1.0.64" sha3 = { version = "0.10", default-features = false } hex = "0.4.2" ethabi = "17.1.0" -noah = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } # primitives, don't depend on any modules fp-core = { path = "../../primitives/core" } diff --git a/src/components/contracts/primitives/mocks/Cargo.toml b/src/components/contracts/primitives/mocks/Cargo.toml index af2855195..8d388a6cd 100644 --- a/src/components/contracts/primitives/mocks/Cargo.toml +++ b/src/components/contracts/primitives/mocks/Cargo.toml @@ -18,7 +18,7 @@ rand_chacha = "0.3" rlp = "0.5" serde_json = "1.0" sha3 = "0.10" -noah = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } # primitives fp-traits = { path = "../traits" } diff --git a/src/components/contracts/primitives/types/Cargo.toml b/src/components/contracts/primitives/types/Cargo.toml index c85a2f678..6fdd715df 100644 --- a/src/components/contracts/primitives/types/Cargo.toml +++ b/src/components/contracts/primitives/types/Cargo.toml @@ -21,8 +21,8 @@ serde = { version = "1.0.124", features = ["derive"] } serde_json = "1.0" serde-big-array = "0.4" sha3 = "0.10" -noah = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } # primitives fp-utils = { path = "../utils" } diff --git a/src/components/finutils/Cargo.toml b/src/components/finutils/Cargo.toml index 4723faff7..0c5468e9f 100644 --- a/src/components/finutils/Cargo.toml +++ b/src/components/finutils/Cargo.toml @@ -25,9 +25,9 @@ tokio = "1.10.1" wasm-bindgen = { version = "=0.2.73", features = ["serde-serialize"] } getrandom = "0.2" -noah = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } -noah-crypto = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } ruc = "1.0" rucv3 = { package = "ruc", version = "3.0" } diff --git a/src/components/wallet_mobile/Cargo.toml b/src/components/wallet_mobile/Cargo.toml index 719ffe3b1..6d2cc1c98 100644 --- a/src/components/wallet_mobile/Cargo.toml +++ b/src/components/wallet_mobile/Cargo.toml @@ -32,8 +32,8 @@ serde = { version = "1.0.124", features = ["derive"] } serde_derive = "^1.0.59" serde_json = "1.0" -noah = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } finutils = { path = "../finutils", default-features = false, features = []} fp-types = { path = "../contracts/primitives/types" } diff --git a/src/components/wasm/Cargo.toml b/src/components/wasm/Cargo.toml index cd495e382..21f542064 100644 --- a/src/components/wasm/Cargo.toml +++ b/src/components/wasm/Cargo.toml @@ -36,9 +36,9 @@ ruc = "1.0" # OR the compiling will fail. getrandom = { version = "0.2", features = ["js"] } -noah = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } -noah-crypto = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } finutils = { path = "../finutils", default-features = false } globutils = { path = "../../libs/globutils" } diff --git a/src/ledger/Cargo.toml b/src/ledger/Cargo.toml index 8135b40bb..3e0e683ad 100644 --- a/src/ledger/Cargo.toml +++ b/src/ledger/Cargo.toml @@ -34,9 +34,9 @@ fp-utils = { path = "../components/contracts/primitives/utils" } itertools = "0.10" ruc = "1.0" -noah = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } -noah-crypto = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } bulletproofs = { package = "noah-bulletproofs", version = "4.0.0" } fbnc = { version = "0.2.9", default-features = false} @@ -71,7 +71,7 @@ fs2 = "0.4" storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4", optional = true } fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4", optional = true } sparse_merkle_tree = { path = "../libs/sparse_merkle_tree" } -noah-accumulators = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } +noah-accumulators = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } [target.'cfg(target_arch = "wasm32")'.dependencies] parking_lot = { version = "0.11", features = ["wasm-bindgen"] } diff --git a/src/libs/credentials/Cargo.toml b/src/libs/credentials/Cargo.toml index 11a9423d1..4d8dc8c51 100644 --- a/src/libs/credentials/Cargo.toml +++ b/src/libs/credentials/Cargo.toml @@ -12,4 +12,4 @@ linear-map = {version = "1.2.0", features = ["serde_impl"] } serde = "1.0.124" serde_derive = "1.0" wasm-bindgen = { version = "=0.2.73", features = ["serde-serialize"] } -noah = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } diff --git a/src/libs/globutils/Cargo.toml b/src/libs/globutils/Cargo.toml index 9de987b53..253abee70 100644 --- a/src/libs/globutils/Cargo.toml +++ b/src/libs/globutils/Cargo.toml @@ -12,9 +12,9 @@ serde_json = "1.0" time = "0.3" rand = "0.8" cryptohash = { path = "../cryptohash" } -noah = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } -noah-crypto = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } hex = "0.4.2" bip32 = "0.3.0" diff --git a/src/libs/sparse_merkle_tree/Cargo.toml b/src/libs/sparse_merkle_tree/Cargo.toml index f863d4528..915f88372 100644 --- a/src/libs/sparse_merkle_tree/Cargo.toml +++ b/src/libs/sparse_merkle_tree/Cargo.toml @@ -24,7 +24,7 @@ serde_derive = "1.0" serde_json = "1.0" sha2 = "0.10" storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } -noah = { git = "https://github.com/FindoraNetwork/noah", branch = "msm_wasm" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" } [dev-dependencies] temp_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" }