Skip to content

Commit

Permalink
Merge pull request #1 from Zondax/keystore
Browse files Browse the repository at this point in the history
Modularize keystore functionality
  • Loading branch information
becominginsane committed Jun 17, 2022
2 parents 89be353 + 87420c3 commit 0803231
Show file tree
Hide file tree
Showing 16 changed files with 1,800 additions and 1,353 deletions.
24 changes: 14 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions LICENSE
@@ -0,0 +1,23 @@
The MIT License (MIT)

Copyright (c) 2018-present Zecwallet

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


2 changes: 0 additions & 2 deletions cli/src/lib.rs
Expand Up @@ -231,6 +231,4 @@ pub fn attempt_recover_seed(_password: Option<String>) {
anchor_offset: [0u32; 5],
data_dir: None,
};

}

3 changes: 2 additions & 1 deletion lib/Cargo.toml
Expand Up @@ -10,7 +10,6 @@ edition = "2018"
default = ["embed_params"]
embed_params = []


[dependencies]
arr_macro = "0.1.3"
base64 = "0.13.0"
Expand All @@ -30,6 +29,7 @@ ring = "0.16.20"
dirs = "3.0.2"
json = "0.12.4"
webpki-roots = "0.21.0"
async-trait = "0.1.53"

lazy_static = "1.4.0"
secp256k1 = "=0.20.2"
Expand All @@ -39,6 +39,7 @@ base58 = "0.1.0"
tiny-bip39 = "0.8.0"
sodiumoxide = "0.2.5"
byteorder = "1"
thiserror = "1.0.31"

pairing = "0.18.0"
ff = "0.8"
Expand Down
12 changes: 8 additions & 4 deletions lib/src/blaze/fetch_full_tx.rs
Expand Up @@ -2,7 +2,7 @@ use crate::{
lightclient::lightclient_config::LightClientConfig,
lightwallet::{
data::OutgoingTxMetadata,
keys::{Keys, ToBase58Check},
keys::{InMemoryKeys, ToBase58Check},
wallet_txns::WalletTxns,
},
};
Expand Down Expand Up @@ -39,12 +39,16 @@ use super::syncdata::BlazeSyncData;

pub struct FetchFullTxns {
config: LightClientConfig,
keys: Arc<RwLock<Keys>>,
keys: Arc<RwLock<InMemoryKeys>>,
wallet_txns: Arc<RwLock<WalletTxns>>,
}

impl FetchFullTxns {
pub fn new(config: &LightClientConfig, keys: Arc<RwLock<Keys>>, wallet_txns: Arc<RwLock<WalletTxns>>) -> Self {
pub fn new(
config: &LightClientConfig,
keys: Arc<RwLock<InMemoryKeys>>,
wallet_txns: Arc<RwLock<WalletTxns>>,
) -> Self {
Self {
config: config.clone(),
keys,
Expand Down Expand Up @@ -154,7 +158,7 @@ impl FetchFullTxns {
height: BlockHeight,
unconfirmed: bool,
block_time: u32,
keys: Arc<RwLock<Keys>>,
keys: Arc<RwLock<InMemoryKeys>>,
wallet_txns: Arc<RwLock<WalletTxns>>,
price: Option<f64>,
) {
Expand Down
10 changes: 5 additions & 5 deletions lib/src/blaze/fetch_taddr_txns.rs
@@ -1,6 +1,6 @@
use crate::compact_formats::RawTransaction;

use crate::lightwallet::keys::Keys;
use crate::lightwallet::keys::InMemoryKeys;
use std::sync::Arc;
use tokio::join;
use tokio::sync::mpsc::unbounded_channel;
Expand All @@ -15,11 +15,11 @@ use zcash_primitives::consensus::BlockHeight;
use zcash_primitives::transaction::Transaction;

pub struct FetchTaddrTxns {
keys: Arc<RwLock<Keys>>,
keys: Arc<RwLock<InMemoryKeys>>,
}

impl FetchTaddrTxns {
pub fn new(keys: Arc<RwLock<Keys>>) -> Self {
pub fn new(keys: Arc<RwLock<InMemoryKeys>>) -> Self {
Self { keys }
}

Expand Down Expand Up @@ -149,15 +149,15 @@ mod test {
use crate::compact_formats::RawTransaction;
use zcash_primitives::transaction::{Transaction, TransactionData};

use crate::lightwallet::keys::Keys;
use crate::lightwallet::keys::InMemoryKeys;
use crate::lightwallet::wallettkey::WalletTKey;

use super::FetchTaddrTxns;

#[tokio::test]
async fn out_of_order_txns() {
// 5 t addresses
let mut keys = Keys::new_empty();
let mut keys = InMemoryKeys::new_empty();
let gened_taddrs: Vec<_> = (0..5).into_iter().map(|n| format!("taddr{}", n)).collect();
keys.tkeys = gened_taddrs.iter().map(|ta| WalletTKey::empty(ta)).collect::<Vec<_>>();

Expand Down
2 changes: 1 addition & 1 deletion lib/src/blaze/syncdata.rs
Expand Up @@ -49,7 +49,7 @@ impl BlazeSyncData {
.write()
.await
.new_sync_batch(start_block, end_block, batch_num);

self.wallet_options = wallet_options;

self.block_data.setup_sync(existing_blocks, verified_tree).await;
Expand Down
33 changes: 23 additions & 10 deletions lib/src/blaze/trial_decryptions.rs
@@ -1,20 +1,34 @@
use crate::{compact_formats::CompactBlock, lightwallet::{MemoDownloadOption, data::WalletTx, keys::Keys, wallet_txns::WalletTxns}};
use crate::{
compact_formats::CompactBlock,
lightwallet::{data::WalletTx, keys::InMemoryKeys, wallet_txns::WalletTxns, MemoDownloadOption},
};
use futures::{stream::FuturesUnordered, StreamExt};
use log::info;
use std::sync::Arc;
use tokio::{sync::{RwLock, mpsc::{unbounded_channel, UnboundedSender}, oneshot}, task::JoinHandle};

use zcash_primitives::{consensus::BlockHeight, note_encryption::try_sapling_compact_note_decryption, primitives::{Nullifier, SaplingIvk}, transaction::{Transaction, TxId}};
use tokio::{
sync::{
mpsc::{unbounded_channel, UnboundedSender},
oneshot, RwLock,
},
task::JoinHandle,
};

use zcash_primitives::{
consensus::BlockHeight,
note_encryption::try_sapling_compact_note_decryption,
primitives::{Nullifier, SaplingIvk},
transaction::{Transaction, TxId},
};

use super::syncdata::BlazeSyncData;

pub struct TrialDecryptions {
keys: Arc<RwLock<Keys>>,
keys: Arc<RwLock<InMemoryKeys>>,
wallet_txns: Arc<RwLock<WalletTxns>>,
}

impl TrialDecryptions {
pub fn new(keys: Arc<RwLock<Keys>>, wallet_txns: Arc<RwLock<WalletTxns>>) -> Self {
pub fn new(keys: Arc<RwLock<InMemoryKeys>>, wallet_txns: Arc<RwLock<WalletTxns>>) -> Self {
Self { keys, wallet_txns }
}

Expand Down Expand Up @@ -89,7 +103,7 @@ impl TrialDecryptions {

async fn trial_decrypt_batch(
cbs: Vec<CompactBlock>,
keys: Arc<RwLock<Keys>>,
keys: Arc<RwLock<InMemoryKeys>>,
bsync_data: Arc<RwLock<BlazeSyncData>>,
ivks: Arc<Vec<SaplingIvk>>,
wallet_txns: Arc<RwLock<WalletTxns>>,
Expand All @@ -107,7 +121,7 @@ impl TrialDecryptions {

for (tx_num, ctx) in cb.vtx.iter().enumerate() {
let mut wallet_tx = false;

for (output_num, co) in ctx.outputs.iter().enumerate() {
let cmu = co.cmu().map_err(|_| "No CMU".to_string())?;
let epk = match co.epk() {
Expand Down Expand Up @@ -163,7 +177,7 @@ impl TrialDecryptions {
);

info!("Trial decrypt Detected txid {}", &txid);

detected_txid_sender
.send((txid, nullifier, height, Some(output_num as u32)))
.unwrap();
Expand All @@ -187,7 +201,6 @@ impl TrialDecryptions {
// Discard the result, because this was not a wallet tx.
rx.await.unwrap().map(|_r| ())
}));

}
}
}
Expand Down

0 comments on commit 0803231

Please sign in to comment.