diff --git a/Cargo.toml b/Cargo.toml index 5d87e4f..249f6e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,74 +4,13 @@ version = "0.1.0" edition = "2018" [dependencies] -tower-grpc = { git = "https://github.com/tower-rs/tower-grpc" } -futures = "0.1" -bytes = "0.4" -base58 = "0.1.0" +rustyline = "5.0.2" +clap = "2.33" log = "0.4" log4rs = "0.8.3" -dirs = "2.0.2" -http = "0.1" -prost = "0.5" -tokio = "0.1" -tower-request-modifier = { git = "https://github.com/tower-rs/tower-http" } -tower-util = "0.1" -hex = "0.3" -protobuf = "2" -rustyline = "5.0.2" -byteorder = "1" -json = "0.12.0" shellwords = "1.0.0" -tiny-bip39 = "0.6.2" -clap = "2.33" -secp256k1 = "=0.15.0" -sha2 = "0.8.0" -ripemd160 = "0.8.0" -ring = "0.14.0" -lazy_static = "1.2.0" -tower-service = "0.2" -tokio-rustls = "0.10.0-alpha.3" -rustls = { version = "0.15.2", features = ["dangerous_configuration"] } -webpki = "0.19.1" -webpki-roots = "0.16.0" -tower-h2 = { git = "https://github.com/tower-rs/tower-h2" } -rust-embed = "5.1.0" -rand = "0.7.2" - -[dependencies.bellman] -git = "https://github.com/adityapk00/librustzcash.git" -rev = "188537ea025fcb7fbdfc11266f307a084a5451e4" -default-features = false -features = ["groth16"] - -[dependencies.pairing] -git = "https://github.com/adityapk00/librustzcash.git" -rev = "188537ea025fcb7fbdfc11266f307a084a5451e4" - -[dependencies.zcash_client_backend] -git = "https://github.com/adityapk00/librustzcash.git" -rev = "188537ea025fcb7fbdfc11266f307a084a5451e4" -default-features = false - -[dependencies.zcash_primitives] -git = "https://github.com/adityapk00/librustzcash.git" -rev = "188537ea025fcb7fbdfc11266f307a084a5451e4" -default-features = false -features = ["transparent-inputs"] - -[dependencies.zcash_proofs] -git = "https://github.com/adityapk00/librustzcash.git" -rev = "188537ea025fcb7fbdfc11266f307a084a5451e4" -default-features = false - -[dependencies.ff] -git = "https://github.com/adityapk00/librustzcash.git" -rev = "188537ea025fcb7fbdfc11266f307a084a5451e4" -features = ["ff_derive"] - -[build-dependencies] -tower-grpc-build = { git = "https://github.com/tower-rs/tower-grpc", features = ["tower-hyper"] } +zecwalletlitelib = { path = "./lib/" } [profile.release] diff --git a/lib/Cargo.toml b/lib/Cargo.toml new file mode 100644 index 0000000..cec1775 --- /dev/null +++ b/lib/Cargo.toml @@ -0,0 +1,75 @@ +[package] +name = "zecwalletlitelib" +version = "0.1.0" +edition = "2018" + +[dependencies] +tower-grpc = { git = "https://github.com/tower-rs/tower-grpc" } +futures = "0.1" +bytes = "0.4" +base58 = "0.1.0" +log = "0.4" +log4rs = "0.8.3" +dirs = "2.0.2" +http = "0.1" +prost = "0.5" +tokio = "0.1" +tower-request-modifier = { git = "https://github.com/tower-rs/tower-http" } +tower-util = "0.1" +hex = "0.3" +protobuf = "2" +byteorder = "1" +rand = "0.5.6" +json = "0.12.0" +tiny-bip39 = "0.6.2" +secp256k1 = "=0.15.0" +sha2 = "0.8.0" +ripemd160 = "0.8.0" +ring = "0.14.0" +lazy_static = "1.2.0" +tower-service = "0.2" +tokio-rustls = "0.10.0-alpha.3" +webpki = "0.19.1" +webpki-roots = "0.16.0" +tower-h2 = { git = "https://github.com/tower-rs/tower-h2" } +rust-embed = "5.1.0" + +[dependencies.bellman] +git = "https://github.com/adityapk00/librustzcash.git" +rev = "0743dadcd017b60a0ac7123d04f0d6e7ce1e8016" +default-features = false +features = ["groth16"] + +[dependencies.pairing] +git = "https://github.com/adityapk00/librustzcash.git" +rev = "0743dadcd017b60a0ac7123d04f0d6e7ce1e8016" + +[dependencies.zcash_client_backend] +git = "https://github.com/adityapk00/librustzcash.git" +rev = "0743dadcd017b60a0ac7123d04f0d6e7ce1e8016" +default-features = false + +[dependencies.zcash_primitives] +git = "https://github.com/adityapk00/librustzcash.git" +rev = "0743dadcd017b60a0ac7123d04f0d6e7ce1e8016" +default-features = false +features = ["transparent-inputs"] + +[dependencies.zcash_proofs] +git = "https://github.com/adityapk00/librustzcash.git" +rev = "0743dadcd017b60a0ac7123d04f0d6e7ce1e8016" +default-features = false + +[dependencies.ff] +git = "https://github.com/adityapk00/librustzcash.git" +rev = "0743dadcd017b60a0ac7123d04f0d6e7ce1e8016" +features = ["ff_derive"] + +[build-dependencies] +tower-grpc-build = { git = "https://github.com/tower-rs/tower-grpc", features = ["tower-hyper"] } + +[dev-dependencies] +rand_core = "0.5.1" + +[profile.release] +debug = false \ No newline at end of file diff --git a/build.rs b/lib/build.rs similarity index 100% rename from build.rs rename to lib/build.rs diff --git a/proto/compact_formats.proto b/lib/proto/compact_formats.proto similarity index 100% rename from proto/compact_formats.proto rename to lib/proto/compact_formats.proto diff --git a/proto/service.proto b/lib/proto/service.proto similarity index 100% rename from proto/service.proto rename to lib/proto/service.proto diff --git a/src/commands.rs b/lib/src/commands.rs similarity index 99% rename from src/commands.rs rename to lib/src/commands.rs index e7e627f..c9c3e8d 100644 --- a/src/commands.rs +++ b/lib/src/commands.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use json::{object}; -use crate::LightClient; +use crate::lightclient::LightClient; pub trait Command { fn help(&self) -> String; diff --git a/src/grpcconnector.rs b/lib/src/grpcconnector.rs similarity index 100% rename from src/grpcconnector.rs rename to lib/src/grpcconnector.rs diff --git a/lib/src/lib.rs b/lib/src/lib.rs new file mode 100644 index 0000000..3e4fe27 --- /dev/null +++ b/lib/src/lib.rs @@ -0,0 +1,19 @@ +#[macro_use] +extern crate rust_embed; + +pub mod lightclient; +pub mod grpcconnector; +pub mod lightwallet; +pub mod commands; + + +#[derive(RustEmbed)] +#[folder = "zcash-params/"] +pub struct SaplingParams; + +pub const ANCHOR_OFFSET: u32 = 4; + + +pub mod grpc_client { + include!(concat!(env!("OUT_DIR"), "/cash.z.wallet.sdk.rpc.rs")); +} diff --git a/src/lightclient.rs b/lib/src/lightclient.rs similarity index 100% rename from src/lightclient.rs rename to lib/src/lightclient.rs diff --git a/src/lightwallet.rs b/lib/src/lightwallet.rs similarity index 99% rename from src/lightwallet.rs rename to lib/src/lightwallet.rs index f9fe0bb..b795f59 100644 --- a/src/lightwallet.rs +++ b/lib/src/lightwallet.rs @@ -40,7 +40,7 @@ use zcash_primitives::{ }; -use crate::{LightClientConfig}; +use crate::lightclient::{LightClientConfig}; mod data; mod extended_key; @@ -1308,7 +1308,7 @@ pub mod tests { use sha2::{Sha256, Digest}; use super::LightWallet; - use crate::LightClientConfig; + use super::LightClientConfig; use secp256k1::{Secp256k1, key::PublicKey, key::SecretKey}; use crate::SaplingParams; diff --git a/src/lightwallet/address.rs b/lib/src/lightwallet/address.rs similarity index 100% rename from src/lightwallet/address.rs rename to lib/src/lightwallet/address.rs diff --git a/src/lightwallet/data.rs b/lib/src/lightwallet/data.rs similarity index 100% rename from src/lightwallet/data.rs rename to lib/src/lightwallet/data.rs diff --git a/src/lightwallet/extended_key.rs b/lib/src/lightwallet/extended_key.rs similarity index 70% rename from src/lightwallet/extended_key.rs rename to lib/src/lightwallet/extended_key.rs index 058b3b7..a6cba82 100644 --- a/src/lightwallet/extended_key.rs +++ b/lib/src/lightwallet/extended_key.rs @@ -27,17 +27,6 @@ pub enum KeyIndex { impl KeyIndex { /// Check index range. - /// - /// # Examples - /// - /// ```rust - /// # extern crate hdwallet; - /// use hdwallet::KeyIndex; - /// - /// assert!(KeyIndex::Normal(0).is_valid()); - /// assert!(!KeyIndex::Normal(2_147_483_648).is_valid()); - /// assert!(KeyIndex::Hardened(2_147_483_648).is_valid()); - /// ``` pub fn is_valid(self) -> bool { match self { KeyIndex::Normal(i) => i < HARDENED_KEY_START_INDEX, @@ -46,20 +35,6 @@ impl KeyIndex { } /// Generate Hardened KeyIndex from normalize index value. - /// - /// # Examples - /// - /// ```rust - /// # extern crate hdwallet; - /// use hdwallet::KeyIndex; - /// - /// // hardended key from zero - /// let hardened_index_zero = KeyIndex::hardened_from_normalize_index(0).unwrap(); - /// assert_eq!(hardened_index_zero, KeyIndex::Hardened(2_147_483_648)); - /// // also allow raw index for convernient - /// let hardened_index_zero = KeyIndex::hardened_from_normalize_index(2_147_483_648).unwrap(); - /// assert_eq!(hardened_index_zero, KeyIndex::Hardened(2_147_483_648)); - /// ``` pub fn hardened_from_normalize_index(i: u32) -> Result { if i < HARDENED_KEY_START_INDEX { Ok(KeyIndex::Hardened(HARDENED_KEY_START_INDEX + i)) @@ -69,18 +44,6 @@ impl KeyIndex { } /// Generate KeyIndex from raw index value. - /// - /// # Examples - /// - /// ```rust - /// # extern crate hdwallet; - /// use hdwallet::KeyIndex; - /// - /// let normal_key = KeyIndex::from_index(0).unwrap(); - /// assert_eq!(normal_key, KeyIndex::Normal(0)); - /// let hardened_key = KeyIndex::from_index(2_147_483_648).unwrap(); - /// assert_eq!(hardened_key, KeyIndex::Hardened(2_147_483_648)); - /// ``` pub fn from_index(i: u32) -> Result { if i < HARDENED_KEY_START_INDEX { Ok(KeyIndex::Normal(i)) @@ -99,19 +62,6 @@ impl From for KeyIndex { /// ExtendedPrivKey is used for child key derivation. /// See [secp256k1 crate documentation](https://docs.rs/secp256k1) for SecretKey signatures usage. -/// -/// # Examples -/// -/// ```rust -/// # extern crate hdwallet; -/// use hdwallet::{ExtendedPrivKey, KeyIndex}; -/// -/// let master_key = ExtendedPrivKey::random().unwrap(); -/// let hardened_key_index = KeyIndex::hardened_from_normalize_index(0).unwrap(); -/// let hardended_child_priv_key = master_key.derive_private_key(hardened_key_index).unwrap(); -/// let normal_key_index = KeyIndex::Normal(0); -/// let noamal_child_priv_key = master_key.derive_private_key(normal_key_index).unwrap(); -/// ``` #[derive(Debug, Clone, PartialEq, Eq)] pub struct ExtendedPrivKey { pub private_key: SecretKey, diff --git a/src/lightwallet/prover.rs b/lib/src/lightwallet/prover.rs similarity index 100% rename from src/lightwallet/prover.rs rename to lib/src/lightwallet/prover.rs diff --git a/src/lightwallet/utils.rs b/lib/src/lightwallet/utils.rs similarity index 100% rename from src/lightwallet/utils.rs rename to lib/src/lightwallet/utils.rs diff --git a/lib/zcash-params/sapling-output.params b/lib/zcash-params/sapling-output.params new file mode 100644 index 0000000..01760fa Binary files /dev/null and b/lib/zcash-params/sapling-output.params differ diff --git a/lib/zcash-params/sapling-spend.params b/lib/zcash-params/sapling-spend.params new file mode 100644 index 0000000..b91cd77 Binary files /dev/null and b/lib/zcash-params/sapling-spend.params differ diff --git a/src/main.rs b/src/main.rs index c8483f5..c23f152 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,17 +1,12 @@ -#[macro_use] -extern crate rust_embed; - -mod lightclient; -mod grpcconnector; -mod lightwallet; -mod commands; - use std::io::{Result, Error, ErrorKind}; use std::sync::{Arc}; use std::sync::mpsc::{channel, Sender, Receiver}; use std::time::Duration; -use lightclient::{LightClient, LightClientConfig}; +use zecwalletlitelib::{grpcconnector, commands, + lightclient::{self, LightClient, LightClientConfig}, + ANCHOR_OFFSET, +}; use log::{info, error, LevelFilter}; use log4rs::append::rolling_file::RollingFileAppender; @@ -29,15 +24,6 @@ use rustyline::Editor; use clap::{Arg, App}; -pub mod grpc_client { - include!(concat!(env!("OUT_DIR"), "/cash.z.wallet.sdk.rpc.rs")); -} - -#[derive(RustEmbed)] -#[folder = "zcash-params/"] -pub struct SaplingParams; - -const ANCHOR_OFFSET: u32 = 4; /// Build the Logging config fn get_log_config(config: &LightClientConfig) -> Result {