Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
623 changes: 343 additions & 280 deletions Cargo.lock

Large diffs are not rendered by default.

39 changes: 19 additions & 20 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,31 @@ wasm-bindgen-rayon = { version = "1.3" } # Update to higher version cause playwr
# WASM specific dependencies
tracing-web = { version = "0.1.3" }
console_error_panic_hook = { version = "0.1.7" }
tonic-web-wasm-client = "0.6.0"
tonic-web-wasm-client = "0.8.0"
tokio_with_wasm = { version = "0.7.1", features = ["rt", "rt-multi-thread", "sync", "macros", "time"] }

## Zcash dependencies

zcash_keys = { git = "https://github.com/ChainSafe/librustzcash", rev = "46e8ee0937b61fdbb417df7c663f62e6945d8090", features = ["transparent-inputs", "orchard", "sapling", "unstable"] }
zcash_client_backend = { git = "https://github.com/ChainSafe/librustzcash", rev = "46e8ee0937b61fdbb417df7c663f62e6945d8090", default-features = false, features = ["sync", "lightwalletd-tonic", "wasm-bindgen", "orchard"] }
zcash_client_memory = { git = "https://github.com/ChainSafe/librustzcash", rev = "46e8ee0937b61fdbb417df7c663f62e6945d8090", features = ["orchard", "transparent-inputs"] }
zcash_primitives = { git = "https://github.com/ChainSafe/librustzcash", rev = "46e8ee0937b61fdbb417df7c663f62e6945d8090" }
zcash_address = { git = "https://github.com/ChainSafe/librustzcash", rev = "46e8ee0937b61fdbb417df7c663f62e6945d8090" }
zcash_proofs = { git = "https://github.com/ChainSafe/librustzcash", rev = "46e8ee0937b61fdbb417df7c663f62e6945d8090", default-features = false, features = ["bundled-prover", "multicore"] }
zip321 = { git = "https://github.com/ChainSafe/librustzcash", rev = "46e8ee0937b61fdbb417df7c663f62e6945d8090" }
zip32 = { version = "0.1.3" }
zcash_protocol = { git = "https://github.com/ChainSafe/librustzcash", rev = "46e8ee0937b61fdbb417df7c663f62e6945d8090", default-features = false }
pczt = { git = "https://github.com/ChainSafe/librustzcash", rev = "46e8ee0937b61fdbb417df7c663f62e6945d8090", default-features = false, features = ["orchard", "sapling", "transparent"] }
sapling = { package = "sapling-crypto", version = "0.4", default-features = false }

zcash_keys = { git = "https://github.com/zcash/librustzcash", rev = "a40ee353bba84d1cb3eaf1889df433d3be9c79e5", features = ["transparent-inputs", "orchard", "sapling", "unstable"] }
zcash_client_backend = { git = "https://github.com/zcash/librustzcash", rev = "a40ee353bba84d1cb3eaf1889df433d3be9c79e5", default-features = false, features = ["sync", "lightwalletd-tonic", "orchard"] }
zcash_client_memory = { git = "https://github.com/zcash/librustzcash", rev = "a40ee353bba84d1cb3eaf1889df433d3be9c79e5", features = ["orchard", "transparent-inputs"] }
zcash_primitives = { git = "https://github.com/zcash/librustzcash", rev = "a40ee353bba84d1cb3eaf1889df433d3be9c79e5" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@irubido is there a reason why you are pointing to this commit and not versions of the crates?

zcash_transparent = { git = "https://github.com/zcash/librustzcash", rev = "a40ee353bba84d1cb3eaf1889df433d3be9c79e5", default-features = false}
zcash_address = { git = "https://github.com/zcash/librustzcash", rev = "a40ee353bba84d1cb3eaf1889df433d3be9c79e5" }
zcash_proofs = { git = "https://github.com/zcash/librustzcash", rev = "a40ee353bba84d1cb3eaf1889df433d3be9c79e5", default-features = false, features = ["bundled-prover", "multicore"] }
zip321 = { git = "https://github.com/zcash/librustzcash", rev = "a40ee353bba84d1cb3eaf1889df433d3be9c79e5" }
zip32 = { version = "0.2" }
zcash_protocol = { git = "https://github.com/zcash/librustzcash", rev = "a40ee353bba84d1cb3eaf1889df433d3be9c79e5", default-features = false }
pczt = { git = "https://github.com/zcash/librustzcash", rev = "a40ee353bba84d1cb3eaf1889df433d3be9c79e5", default-features = false, features = ["orchard", "sapling", "transparent"] }
sapling = { package = "sapling-crypto", version = "0.5", default-features = false }
bip32 = { version = "=0.6.0-pre.1", default-features = false, features = ["alloc"] }
## gRPC Web dependencies
prost = { version = "0.12", default-features = false }
tonic = { version = "0.12", default-features = false, features = [
"prost",
] }
prost = { version = "0.14", default-features = false }
tonic = { version = "0.14", default-features = false }


# Used in Native tests
zcash_client_sqlite = { git = "https://github.com/ChainSafe/librustzcash", rev = "46e8ee0937b61fdbb417df7c663f62e6945d8090", default-features = false, features = ["unstable", "orchard"] }
zcash_client_sqlite = { git = "https://github.com/zcash/librustzcash", rev = "a40ee353bba84d1cb3eaf1889df433d3be9c79e5", default-features = false, features = ["unstable", "orchard"] }

getrandom = { version = "0.2", features = ["js"] }
thiserror = "1.0.63"
Expand Down Expand Up @@ -86,8 +85,8 @@ byte-unit = { version = "5.1.4", features = ["byte"] }
[patch.crates-io]
# Also patching for pczt improvments
# See: https://github.com/zcash/librustzcash/pull/1661
orchard = { git = "https://github.com/zcash/orchard.git", rev = "4fa6d3b549f8803016a309281404eab095d04de8" }
sapling = { package = "sapling-crypto", git = "https://github.com/zcash/sapling-crypto.git", rev = "3c2235747553da642fb142d1eeb9b1afa8391987" }
# orchard = { git = "https://github.com/zcash/orchard.git", rev = "4fa6d3b549f8803016a309281404eab095d04de8" }
# sapling = { package = "sapling-crypto", git = "https://github.com/zcash/sapling-crypto.git", rev = "3c2235747553da642fb142d1eeb9b1afa8391987" }

[workspace.lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(wasm_bindgen)', 'cfg(wasm_bindgen_unstable_test_coverage)'] }
Expand Down
4 changes: 2 additions & 2 deletions crates/webzjs-common/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ impl Parameters for Network {
fn activation_height(&self, nu: consensus::NetworkUpgrade) -> Option<consensus::BlockHeight> {
match self {
Network::MainNetwork => {
zcash_primitives::consensus::Network::MainNetwork.activation_height(nu)
zcash_protocol::consensus::Network::MainNetwork.activation_height(nu)
}
Network::TestNetwork => {
zcash_primitives::consensus::Network::TestNetwork.activation_height(nu)
zcash_protocol::consensus::Network::TestNetwork.activation_height(nu)
}
}
}
Expand Down
20 changes: 14 additions & 6 deletions crates/webzjs-keys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,24 @@ thiserror.workspace = true
wasm-bindgen.workspace = true
zcash_primitives = { workspace = true, features = ["transparent-inputs"] }
zcash_keys.workspace = true
zcash_protocol.workspace = true
bip0039.workspace = true
zip32 = "0.1"
zip32.workspace = true
zcash_transparent.workspace = true
sapling = { workspace = true }
bip32 = "0.5"
pczt = { workspace = true, default-features = false, features = ["signer", "orchard", "sapling", "transparent", "tx-extractor"] }
orchard = { version = "0.10.1", default-features = false }
bip32.workspace = true
pczt = { workspace = true, default-features = false, features = [
"signer",
"orchard",
"sapling",
"transparent",
"tx-extractor",
] }
orchard = { version = "0.11", default-features = false }
wasm-bindgen-futures = "0.4.43"

# fixes "failed to resolve: use of undeclared crate or module `imp`" error
getrandom = { version = "0.2", features = ["js"] }
getrandom = { workspace = true, features = ["js"] }

[lints]
workspace = true
workspace = true
2 changes: 1 addition & 1 deletion crates/webzjs-keys/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub enum Error {
#[error("webzjs-common crate gives error: {0}")]
WebzJSCommon(#[from] webzjs_common::Error),
#[error("Invalid account id")]
AccountIdConversion(#[from] zcash_primitives::zip32::TryFromIntError),
AccountIdConversion(#[from] zip32::TryFromIntError),
#[error("Failed to derive key from seed")]
Derivation(#[from] zcash_keys::keys::DerivationError),
#[error("Error attempting to decode key: {0}")]
Expand Down
2 changes: 1 addition & 1 deletion crates/webzjs-keys/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use wasm_bindgen::prelude::*;
use crate::error::Error;
use bip0039::{Count, English, Mnemonic};
use webzjs_common::Network;
use zcash_primitives::zip32::AccountId;
use zip32::AccountId;

/// A ZIP32 seed fingerprint. Essentially a Blake2b hash of the seed.
///
Expand Down
14 changes: 5 additions & 9 deletions crates/webzjs-keys/src/pczt_sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use std::convert::Infallible;
use std::str::FromStr;
use wasm_bindgen::prelude::wasm_bindgen;
use webzjs_common::{Network, Pczt};
use zcash_primitives::consensus::{NetworkConstants, Parameters};
use zcash_primitives::legacy::keys::{NonHardenedChildIndex, TransparentKeyScope};
use zcash_protocol::consensus::{NetworkConstants, Parameters};
use zcash_transparent::keys::{NonHardenedChildIndex, TransparentKeyScope};

/// Signs and applies signatures to a PCZT.
/// Should in a secure environment (e.g. Metamask snap).
Expand Down Expand Up @@ -57,7 +57,7 @@ pub async fn pczt_sign_inner(
address_index: NonHardenedChildIndex,
},
}
let mut keys = BTreeMap::<zcash_primitives::zip32::AccountId, Vec<KeyRef>>::new();
let mut keys = BTreeMap::<zip32::AccountId, Vec<KeyRef>>::new();
let pczt = Verifier::new(pczt)
.with_orchard::<Infallible, _>(|bundle| {
for (index, action) in bundle.actions().iter().enumerate() {
Expand All @@ -69,9 +69,7 @@ pub async fn pczt_sign_inner(
.and_then(|derivation| {
derivation.extract_account_index(
&seed_fp,
zcash_primitives::zip32::ChildIndex::hardened(
network.network_type().coin_type(),
),
zip32::ChildIndex::hardened(network.network_type().coin_type()),
)
})
{
Expand All @@ -89,9 +87,7 @@ pub async fn pczt_sign_inner(
spend.zip32_derivation().as_ref().and_then(|derivation| {
derivation.extract_account_index(
&seed_fp,
zcash_primitives::zip32::ChildIndex::hardened(
network.network_type().coin_type(),
),
zip32::ChildIndex::hardened(network.network_type().coin_type()),
)
})
{
Expand Down
4 changes: 2 additions & 2 deletions crates/webzjs-requests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ thiserror.workspace = true
serde-wasm-bindgen.workspace = true

# fixes "failed to resolve: use of undeclared crate or module `imp`" error
getrandom = { version = "0.2", features = ["js"] }
getrandom = { workspace = true, features = ["js"] }

[lints]
workspace = true
workspace = true
2 changes: 1 addition & 1 deletion crates/webzjs-requests/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub enum Error {
#[error("Error constructing ZIP321 transaction request: {0}")]
Zip321(#[from] zip321::Zip321Error),
#[error("Error decoding memo: {0}")]
MemoDecoding(#[from] zcash_primitives::memo::Error),
MemoDecoding(#[from] zcash_protocol::memo::Error),
#[error("Error attempting to decode address: {0}")]
AddressDecoding(#[from] zcash_address::ParseError),
#[error("serde wasm-bindgen error")]
Expand Down
2 changes: 1 addition & 1 deletion crates/webzjs-requests/src/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::error::Error;
use wasm_bindgen::prelude::*;
use zcash_address::ZcashAddress;
use zcash_primitives::memo::MemoBytes;
use zcash_protocol::memo::MemoBytes;

/// A [ZIP-321](https://zips.z.cash/zip-0321) transaction request
///
Expand Down
38 changes: 23 additions & 15 deletions crates/webzjs-wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ default = ["native", "multicore"]

multicore = ["zcash_proofs/multicore", "zcash_primitives/multicore", "zcash_client_memory/multicore"]


# WASM specific features
wasm = ["console_error_panic_hook", "dep:tracing-web", "zcash_client_backend/wasm-bindgen"]
wasm = ["console_error_panic_hook", "dep:tracing-web"]
wasm-parallel = ["wasm", "wasm-bindgen-rayon", "multicore"]
native = ["tonic/channel", "tonic/gzip", "tonic/tls-webpki-roots", "tokio/macros", "tokio/rt", "tokio/rt-multi-thread"]
sqlite-db = ["dep:zcash_client_sqlite"]
Expand All @@ -41,13 +40,19 @@ wasm-bindgen-rayon = { version = "1.3", optional = true }
# WASM specific dependencies
tracing-web = { version = "0.1.3", optional = true }
console_error_panic_hook = { version = "0.1.7", optional = true }
tonic-web-wasm-client = "0.6.0"
tonic-web-wasm-client = "0.8.0"
tokio_with_wasm = { version = "0.7.1", features = ["rt", "rt-multi-thread", "sync", "macros", "time"] }

## Zcash dependencies

zcash_keys = { workspace = true, features = ["transparent-inputs", "orchard", "sapling", "unstable"] }
zcash_client_backend = { workspace = true, default-features = false, features = ["sync", "lightwalletd-tonic", "wasm-bindgen", "orchard", "pczt", "transparent-inputs"] }
zcash_client_backend = { workspace = true, default-features = false, features = [
"sync",
"lightwalletd-tonic",
"orchard",
"pczt",
"transparent-inputs",
] }
zcash_client_memory = { workspace = true, features = ["orchard", "transparent-inputs"] }
zcash_primitives = { workspace = true }
zcash_address = { workspace = true }
Expand All @@ -56,21 +61,21 @@ zcash_proofs = { workspace = true, default-features = false, features = ["bundle
zip321 = { workspace = true }
zip32 = { workspace = true }
pczt = { workspace = true, default-features = false, features = ["orchard", "sapling", "transparent"] }
orchard = { version = "0.10.1", default-features = false }
orchard = { version = "0.11", default-features = false }
sapling = { workspace = true }
bip32 = "0.5"
bip32.workspace = true
## gRPC Web dependencies
prost = { version = "0.13", default-features = false }
tonic = { version = "0.12", default-features = false, features = [
"prost",
] }

prost = { version = "0.14", default-features = false }
tonic = { version = "0.14", default-features = false, features = ["codegen"] }

# Used in Native tests
tokio.workspace = true
zcash_client_sqlite = { git = "https://github.com/ChainSafe/librustzcash", rev = "46e8ee0937b61fdbb417df7c663f62e6945d8090", default-features = false, features = ["unstable", "orchard"], optional = true }
zcash_client_sqlite = { git = "https://github.com/zcash/librustzcash", rev = "a40ee353bba84d1cb3eaf1889df433d3be9c79e5", default-features = false, features = [
"unstable",
"orchard",
], optional = true }

getrandom = { version = "0.2", features = ["js"] }
getrandom = { workspace = true, features = ["js"] }
thiserror.workspace = true
indexed_db_futures = "0.5.0"
sha2 = "0.10"
Expand All @@ -84,7 +89,10 @@ tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
tracing = "0.1.40"
rayon = { version = "1.8", features = ["web_spin_lock"] }
subtle = "2.6.1"
wasm_thread = { git = "https://github.com/ec2/wasm_thread", rev = "9e432077948d927d49373d1d039c23447d3648df", default-features = false, features = ["keep_worker_alive", "es_modules"] }
wasm_thread = { git = "https://github.com/ec2/wasm_thread", rev = "9e432077948d927d49373d1d039c23447d3648df", default-features = false, features = [
"keep_worker_alive",
"es_modules",
] }

wasm_sync = "0.1.2"
http = { version = "1.1.0", default-features = false }
Expand All @@ -93,4 +101,4 @@ postcard = { version = "1.0.10", features = ["alloc"] }
serde-wasm-bindgen.workspace = true

[lints]
workspace = true
workspace = true
2 changes: 0 additions & 2 deletions crates/webzjs-wallet/src/bindgen/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
use serde::{Deserialize, Serialize};

pub mod proposal;
pub mod wallet;
30 changes: 21 additions & 9 deletions crates/webzjs-wallet/src/bindgen/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::num::NonZeroU32;
use std::str::FromStr;

use nonempty::NonEmpty;
use prost::Message;
use serde::{Deserialize, Serialize};
use wasm_bindgen::prelude::*;

Expand All @@ -13,17 +12,17 @@ use crate::wallet::usk_from_seed_str;
use crate::{bindgen::proposal::Proposal, Wallet, PRUNING_DEPTH};
use wasm_thread as thread;
use webzjs_common::{Network, Pczt};
use webzjs_keys::{ProofGenerationKey, SeedFingerprint, UnifiedSpendingKey};
use webzjs_keys::{ProofGenerationKey, SeedFingerprint};
use zcash_address::ZcashAddress;
use zcash_client_backend::data_api::wallet::ConfirmationsPolicy;
use zcash_client_backend::data_api::{AccountPurpose, InputSource, WalletRead, Zip32Derivation};
use zcash_client_backend::proto::service::{
compact_tx_streamer_client::CompactTxStreamerClient, ChainSpec,
};
use zcash_client_memory::MemoryWalletDb;
use zcash_keys::encoding::AddressCodec;
use zcash_keys::keys::UnifiedFullViewingKey;
use zcash_keys::keys::{UnifiedAddressRequest, UnifiedFullViewingKey};
use zcash_primitives::transaction::TxId;
use zcash_primitives::zip32;

pub type MemoryWallet<T> = Wallet<MemoryWalletDb<Network>, T>;
pub type AccountId = <MemoryWalletDb<Network> as WalletRead>::AccountId;
Expand Down Expand Up @@ -130,12 +129,19 @@ impl WebWallet {
pub fn new(
network: &str,
lightwalletd_url: &str,
min_confirmations: u32,
min_confirmations_trusted: u32,
min_confirmations_untrusted: u32,
db_bytes: Option<Box<[u8]>>,
) -> Result<WebWallet, Error> {
let network = Network::from_str(network)?;
let min_confirmations = NonZeroU32::try_from(min_confirmations)
.map_err(|_| Error::InvalidMinConformations(min_confirmations))?;
let min_confirmations_trusted = NonZeroU32::try_from(min_confirmations_trusted)
.map_err(|_| Error::InvalidMinConformations)?;
let min_confirmations_untrusted = NonZeroU32::try_from(min_confirmations_untrusted)
.map_err(|_| Error::InvalidMinConformations)?;

let min_confirmations =
ConfirmationsPolicy::new(min_confirmations_trusted, min_confirmations_untrusted, true)
.map_err(|_| Error::InvalidMinConformations)?;
let client = Client::new(lightwalletd_url.to_string());

let db = match db_bytes {
Expand Down Expand Up @@ -432,7 +438,10 @@ impl WebWallet {
///
pub async fn get_current_address(&self, account_id: u32) -> Result<String, Error> {
let db = self.inner.db.read().await;
if let Some(address) = db.get_current_address(account_id.into())? {
if let Some(address) = db.get_last_generated_address_matching(
account_id.into(),
UnifiedAddressRequest::ALLOW_ALL,
)? {
Ok(address.encode(&self.inner.network))
} else {
Err(Error::AccountNotFound(account_id))
Expand Down Expand Up @@ -518,7 +527,10 @@ impl WebWallet {
///
pub async fn get_current_address_transparent(&self, account_id: u32) -> Result<String, Error> {
let db = self.inner.db.read().await;
if let Some(address) = db.get_current_address(account_id.into())? {
if let Some(address) = db.get_last_generated_address_matching(
account_id.into(),
UnifiedAddressRequest::ALLOW_ALL,
)? {
Ok(address.transparent().unwrap().encode(&self.inner.network))
} else {
Err(Error::AccountNotFound(account_id))
Expand Down
10 changes: 4 additions & 6 deletions crates/webzjs-wallet/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub enum Error {
#[error("webzjs-common crate gives error: {0}")]
WebzJSCommon(#[from] webzjs_common::Error),
#[error("Invalid account id")]
AccountIdConversion(#[from] zcash_primitives::zip32::TryFromIntError),
AccountIdConversion(#[from] zip32::TryFromIntError),
#[error("Failed to derive key from seed")]
// doesn't implement std::error. Should probably fix this upstream
Derivation(#[from] zcash_keys::keys::DerivationError),
Expand Down Expand Up @@ -41,10 +41,8 @@ pub enum Error {
Scan(zcash_client_backend::scanning::ScanError),
#[error("IO Error: {0}")]
Io(#[from] std::io::Error),
#[error(
"Error parsing min_confirmations argument {0}. Must be an integer > 0 (e.g. at least 1)"
)]
InvalidMinConformations(u32),
#[error("Error parsing min_confirmations. Must be an integer > 0 (e.g. at least 1)")]
InvalidMinConformations,
#[error("Error parsing zatoshi amount: {0}")]
InvalidAmount(#[from] zcash_protocol::value::BalanceError),
#[error("Failed to send transaction")]
Expand All @@ -61,7 +59,7 @@ pub enum Error {
#[error("Attempted to create a transaction with a memo to an unsupported recipient. Only shielded addresses are supported.")]
UnsupportedMemoRecipient,
#[error("Error decoding memo: {0}")]
MemoDecoding(#[from] zcash_primitives::memo::Error),
MemoDecoding(#[from] zcash_protocol::memo::Error),

#[cfg(feature = "sqlite-db")]
#[error("Sqlite error: {0}")]
Expand Down
Loading