Put transparent dependencies behind a feature flag.
This commit is contained in:
parent
cff457ff15
commit
862e221a9b
|
@ -20,6 +20,7 @@ base64 = "0.13"
|
|||
ff = "0.8"
|
||||
group = "0.8"
|
||||
hex = "0.4"
|
||||
hdwallet = { version = "0.3.0", optional = true }
|
||||
jubjub = "0.5.1"
|
||||
nom = "6.1"
|
||||
percent-encoding = "2.1.0"
|
||||
|
@ -27,7 +28,7 @@ proptest = { version = "0.10.1", optional = true }
|
|||
protobuf = "2.20"
|
||||
rand_core = "0.5.1"
|
||||
ripemd160 = { version = "0.9.1", optional = true }
|
||||
secp256k1 = { version = "0.20", optional = true }
|
||||
secp256k1 = { version = "0.19", optional = true }
|
||||
sha2 = "0.9"
|
||||
subtle = "2.2.3"
|
||||
time = "0.2"
|
||||
|
|
|
@ -7,7 +7,6 @@ use std::fmt::Debug;
|
|||
use zcash_primitives::{
|
||||
block::BlockHash,
|
||||
consensus::BlockHeight,
|
||||
legacy::TransparentAddress,
|
||||
memo::{Memo, MemoBytes},
|
||||
merkle_tree::{CommitmentTree, IncrementalWitness},
|
||||
sapling::{Node, Nullifier, PaymentAddress},
|
||||
|
@ -23,9 +22,12 @@ use crate::{
|
|||
data_api::wallet::ANCHOR_OFFSET,
|
||||
decrypt::DecryptedOutput,
|
||||
proto::compact_formats::CompactBlock,
|
||||
wallet::{AccountId, SpendableNote, WalletTransparentOutput, WalletTx},
|
||||
wallet::{AccountId, SpendableNote, WalletTx},
|
||||
};
|
||||
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
use {crate::wallet::WalletTransparentOutput, zcash_primitives::legacy::TransparentAddress};
|
||||
|
||||
pub mod chain;
|
||||
pub mod error;
|
||||
pub mod wallet;
|
||||
|
@ -179,6 +181,7 @@ pub trait WalletRead {
|
|||
anchor_height: BlockHeight,
|
||||
) -> Result<Vec<SpendableNote>, Self::Error>;
|
||||
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
fn get_spendable_transparent_utxos(
|
||||
&self,
|
||||
address: &TransparentAddress,
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
//! Helper functions for managing light client key material.
|
||||
#![cfg(feature = "transparent-inputs")]
|
||||
|
||||
use zcash_primitives::{
|
||||
legacy::TransparentAddress,
|
||||
zip32::{ChildIndex, ExtendedSpendingKey},
|
||||
use zcash_primitives::zip32::{ChildIndex, ExtendedSpendingKey};
|
||||
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
use {
|
||||
crate::wallet::AccountId,
|
||||
bs58::decode::Error as Bs58Error,
|
||||
hdwallet::{ExtendedPrivKey, KeyIndex},
|
||||
secp256k1::{key::PublicKey, Secp256k1, SecretKey},
|
||||
sha2::{Digest, Sha256},
|
||||
std::convert::TryInto,
|
||||
zcash_primitives::{consensus, legacy::TransparentAddress},
|
||||
};
|
||||
|
||||
use secp256k1::{key::PublicKey, Secp256k1};
|
||||
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
/// Derives the ZIP 32 [`ExtendedSpendingKey`] for a given coin type and account from the
|
||||
/// given seed.
|
||||
///
|
||||
|
@ -41,6 +44,7 @@ pub fn spending_key(seed: &[u8], coin_type: u32, account: u32) -> ExtendedSpendi
|
|||
)
|
||||
}
|
||||
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
pub fn derive_transparent_address_from_secret_key(
|
||||
secret_key: secp256k1::key::SecretKey,
|
||||
) -> TransparentAddress {
|
||||
|
@ -51,6 +55,56 @@ pub fn derive_transparent_address_from_secret_key(
|
|||
TransparentAddress::PublicKey(*hash160.finalize().as_ref())
|
||||
}
|
||||
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
pub fn derive_secret_key_from_seed<P: consensus::Parameters>(
|
||||
params: &P,
|
||||
seed: &[u8],
|
||||
account: AccountId,
|
||||
index: u32,
|
||||
) -> Result<SecretKey, hdwallet::error::Error> {
|
||||
let ext_t_key = ExtendedPrivKey::with_seed(&seed)?;
|
||||
let private_key = ext_t_key
|
||||
.derive_private_key(KeyIndex::hardened_from_normalize_index(44)?)?
|
||||
.derive_private_key(KeyIndex::hardened_from_normalize_index(params.coin_type())?)?
|
||||
.derive_private_key(KeyIndex::hardened_from_normalize_index(account.0)?)?
|
||||
.derive_private_key(KeyIndex::Normal(0))?
|
||||
.derive_private_key(KeyIndex::Normal(index))?
|
||||
.private_key;
|
||||
|
||||
Ok(private_key)
|
||||
}
|
||||
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
pub struct Wif(pub String);
|
||||
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
impl Wif {
|
||||
pub fn from_secret_key(sk: &SecretKey, compressed: bool) -> Self {
|
||||
let secret_key = sk.as_ref();
|
||||
let mut wif = [0u8; 34];
|
||||
wif[0] = 0x80;
|
||||
wif[1..33].copy_from_slice(secret_key);
|
||||
if compressed {
|
||||
wif[33] = 0x01;
|
||||
Wif(bs58::encode(&wif[..]).with_check().into_string())
|
||||
} else {
|
||||
Wif(bs58::encode(&wif[..]).with_check().into_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
impl TryInto<SecretKey> for Wif {
|
||||
type Error = Bs58Error;
|
||||
|
||||
fn try_into(self) -> Result<SecretKey, Self::Error> {
|
||||
bs58::decode(&self.0)
|
||||
.with_check(None)
|
||||
.into_vec()
|
||||
.map(|decoded| SecretKey::from_slice(&decoded[1..33]).expect("wrong size key"))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::spending_key;
|
||||
|
|
|
@ -4,16 +4,16 @@
|
|||
use subtle::{Choice, ConditionallySelectable};
|
||||
|
||||
use zcash_primitives::{
|
||||
consensus::BlockHeight,
|
||||
legacy::TransparentAddress,
|
||||
merkle_tree::IncrementalWitness,
|
||||
sapling::{
|
||||
keys::OutgoingViewingKey, Diversifier, Node, Note, Nullifier, PaymentAddress, Rseed,
|
||||
},
|
||||
transaction::{
|
||||
components::{Amount, OutPoint},
|
||||
TxId,
|
||||
},
|
||||
transaction::{components::Amount, TxId},
|
||||
};
|
||||
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
use zcash_primitives::{
|
||||
consensus::BlockHeight, legacy::TransparentAddress, transaction::components::OutPoint,
|
||||
};
|
||||
|
||||
/// A type-safe wrapper for account identifiers.
|
||||
|
@ -44,6 +44,7 @@ pub struct WalletTx<N> {
|
|||
pub shielded_outputs: Vec<WalletShieldedOutput<N>>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
pub struct WalletTransparentOutput {
|
||||
pub address: TransparentAddress,
|
||||
pub outpoint: OutPoint,
|
||||
|
|
|
@ -32,4 +32,5 @@ zcash_proofs = { version = "0.5", path = "../zcash_proofs" }
|
|||
|
||||
[features]
|
||||
mainnet = []
|
||||
transparent-inputs = []
|
||||
test-dependencies = ["zcash_client_backend/test-dependencies"]
|
||||
|
|
|
@ -41,7 +41,6 @@ use rusqlite::{Connection, Statement, NO_PARAMS};
|
|||
use zcash_primitives::{
|
||||
block::BlockHash,
|
||||
consensus::{self, BlockHeight},
|
||||
legacy::TransparentAddress,
|
||||
memo::Memo,
|
||||
merkle_tree::{CommitmentTree, IncrementalWitness},
|
||||
sapling::{Node, Nullifier, PaymentAddress},
|
||||
|
@ -55,11 +54,17 @@ use zcash_client_backend::{
|
|||
},
|
||||
encoding::encode_payment_address,
|
||||
proto::compact_formats::CompactBlock,
|
||||
wallet::{AccountId, SpendableNote, WalletTransparentOutput},
|
||||
wallet::{AccountId, SpendableNote},
|
||||
};
|
||||
|
||||
use crate::error::SqliteClientError;
|
||||
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
use {
|
||||
zcash_client_backend::wallet::WalletTransparentOutput,
|
||||
zcash_primitives::legacy::TransparentAddress,
|
||||
};
|
||||
|
||||
pub mod chain;
|
||||
pub mod error;
|
||||
pub mod wallet;
|
||||
|
@ -83,8 +88,9 @@ impl fmt::Display for NoteId {
|
|||
|
||||
/// A newtype wrapper for sqlite primary key values for the utxos
|
||||
/// table.
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct UtxoId(i64);
|
||||
pub struct UtxoId(pub i64);
|
||||
|
||||
/// A wrapper for the SQLite connection to the wallet database.
|
||||
pub struct WalletDb<P> {
|
||||
|
@ -138,6 +144,7 @@ impl<P: consensus::Parameters> WalletDb<P> {
|
|||
WHERE prevout_txid = :prevout_txid
|
||||
AND prevout_idx = :prevout_idx"
|
||||
)?,
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
stmt_insert_received_transparent_utxo: self.conn.prepare(
|
||||
"INSERT INTO utxos (address, prevout_txid, prevout_idx, script, value_zat, height)
|
||||
VALUES (:address, :prevout_txid, :prevout_idx, :script, :value_zat, :height)"
|
||||
|
@ -278,6 +285,7 @@ impl<P: consensus::Parameters> WalletRead for WalletDb<P> {
|
|||
)
|
||||
}
|
||||
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
fn get_spendable_transparent_utxos(
|
||||
&self,
|
||||
address: &TransparentAddress,
|
||||
|
@ -308,6 +316,7 @@ pub struct DataConnStmtCache<'a, P> {
|
|||
stmt_mark_sapling_note_spent: Statement<'a>,
|
||||
stmt_mark_transparent_utxo_spent: Statement<'a>,
|
||||
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
stmt_insert_received_transparent_utxo: Statement<'a>,
|
||||
stmt_insert_received_note: Statement<'a>,
|
||||
stmt_update_received_note: Statement<'a>,
|
||||
|
@ -406,6 +415,7 @@ impl<'a, P: consensus::Parameters> WalletRead for DataConnStmtCache<'a, P> {
|
|||
.select_spendable_sapling_notes(account, target_value, anchor_height)
|
||||
}
|
||||
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
fn get_spendable_transparent_utxos(
|
||||
&self,
|
||||
address: &TransparentAddress,
|
||||
|
|
|
@ -15,7 +15,6 @@ use std::convert::TryFrom;
|
|||
use zcash_primitives::{
|
||||
block::BlockHash,
|
||||
consensus::{self, BlockHeight, NetworkUpgrade},
|
||||
legacy::TransparentAddress,
|
||||
memo::{Memo, MemoBytes},
|
||||
merkle_tree::{CommitmentTree, IncrementalWitness},
|
||||
sapling::{Node, Note, Nullifier, PaymentAddress},
|
||||
|
@ -31,13 +30,20 @@ use zcash_client_backend::{
|
|||
data_api::error::Error,
|
||||
encoding::{
|
||||
decode_extended_full_viewing_key, decode_payment_address, encode_extended_full_viewing_key,
|
||||
encode_payment_address, AddressCodec,
|
||||
encode_payment_address,
|
||||
},
|
||||
wallet::{AccountId, WalletShieldedOutput, WalletTransparentOutput, WalletTx},
|
||||
wallet::{AccountId, WalletShieldedOutput, WalletTx},
|
||||
DecryptedOutput,
|
||||
};
|
||||
|
||||
use crate::{error::SqliteClientError, DataConnStmtCache, NoteId, UtxoId, WalletDb};
|
||||
use crate::{error::SqliteClientError, DataConnStmtCache, NoteId, WalletDb};
|
||||
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
use {
|
||||
crate::UtxoId,
|
||||
zcash_client_backend::{encoding::AddressCodec, wallet::WalletTransparentOutput},
|
||||
zcash_primitives::legacy::TransparentAddress,
|
||||
};
|
||||
|
||||
pub mod init;
|
||||
pub mod transact;
|
||||
|
@ -592,6 +598,7 @@ pub fn get_nullifiers<P>(
|
|||
Ok(res)
|
||||
}
|
||||
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
pub fn get_spendable_transparent_utxos<P: consensus::Parameters>(
|
||||
wdb: &WalletDb<P>,
|
||||
address: &TransparentAddress,
|
||||
|
@ -761,6 +768,7 @@ pub fn mark_transparent_utxo_spent<'a, P>(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
pub fn put_received_transparent_utxo<'a, P: consensus::Parameters>(
|
||||
stmts: &mut DataConnStmtCache<'a, P>,
|
||||
output: &WalletTransparentOutput,
|
||||
|
|
|
@ -35,7 +35,7 @@ proptest = { version = "0.10.1", optional = true }
|
|||
rand = "0.7"
|
||||
rand_core = "0.5.1"
|
||||
ripemd160 = { version = "0.9", optional = true }
|
||||
secp256k1 = { version = "0.20", optional = true }
|
||||
secp256k1 = { version = "0.19", optional = true }
|
||||
sha2 = "0.9"
|
||||
subtle = "2.2.3"
|
||||
zcash_note_encryption = { version = "0.0", path = "../components/zcash_note_encryption" }
|
||||
|
|
Loading…
Reference in New Issue