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
561 changes: 379 additions & 182 deletions Cargo.lock

Large diffs are not rendered by default.

69 changes: 28 additions & 41 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ members = [
"crates/webzjs-requests",
"crates/webzjs-wallet",
]
# A path dependency inside the workspace directory would otherwise become a member.
exclude = ["vendor/tonic-web-wasm-client"]

[profile.release]
# Tell `rustc` to optimize for small code size.
Expand All @@ -30,32 +32,36 @@ console_error_panic_hook = { version = "0.1.7" }
tonic-web-wasm-client = "0.8.0"
tokio_with_wasm = { version = "0.7.1", features = ["rt", "rt-multi-thread", "sync", "macros", "time"] }

## Zcash dependencies - upstream librustzcash @ 0a2c6d1a (NU6.3 main, release-candidate versions;
## Nu6_3 = 0x37a5_165b, testnet activation 4,134,000, mainnet activation 3,428,143 — both finalized),
## redirected via [patch.crates-io]. zcash_client_memory = redbridge fork carrying ChainSafe's Snap patches.
## rc crates (pczt, client_backend, zip321, sqlite) keep the explicit -rc.1 so the pre-release matches.
zcash_keys = { version = "0.15.0", features = ["transparent-inputs", "orchard", "sapling", "unstable"] }
zcash_client_backend = { version = "0.24.0-rc.1", default-features = false, features = ["sync", "lightwalletd-tonic", "orchard"] }
zcash_client_memory = { git = "https://github.com/red-dev-inc/zcash_client_memory", branch = "feat/snap-nu63", features = ["orchard", "transparent-inputs"] }
zcash_primitives = { version = "0.29.0" }
zcash_transparent = { version = "0.9.0", default-features = false }
zcash_address = { version = "0.13.0" }
zcash_proofs = { version = "0.29.0", default-features = false, features = ["bundled-prover", "multicore"] }
zip321 = { version = "0.9.0-rc.1" }
zip32 = { version = "0.2" }
zcash_protocol = { version = "0.10.0", default-features = false }
pczt = { version = "0.8.0-rc.1", default-features = false, features = ["orchard", "sapling", "transparent"] }
sapling = { package = "sapling-crypto", version = "0.7", default-features = false }
bip32 = { version = "=0.6.0-pre.1", default-features = false, features = ["alloc"] }
## Zcash dependencies: librustzcash NU7 pre-releases from crates.io (pinned exactly). NU7 is active on
## testnet from block 4,465,026 with consensus branch id 0x77190AD9; mainnet has no NU7 height yet.
## `zcash_client_memory` is pinned to its NU7 port (open as a PR on red-dev-inc/zcash_client_memory);
## repoint it at red-dev-inc once that PR merges.
zcash_keys = { version = "=0.17.0-pre.1", features = ["transparent-inputs", "orchard", "sapling", "unstable"] }
zcash_client_backend = { version = "=0.25.0-pre.1", default-features = false, features = ["sync", "lightwalletd-tonic", "orchard", "zeroize"] }
zcash_client_memory = { git = "https://github.com/ETIM-PAUL/zcash_client_memory", rev = "24e3be417ccfbe4d10d9730aa19e0261385f70d4", features = ["orchard", "transparent-inputs"] }
zcash_primitives = { version = "=0.31.0-pre.1" }
zcash_transparent = { version = "=0.11.0-pre.1", default-features = false }
zcash_address = { version = "=0.14.0-pre.1" }
zcash_proofs = { version = "=0.31.0-pre.1", default-features = false, features = ["bundled-prover", "multicore"] }
zip321 = { version = "=0.10.0-pre.1" }
zip32 = { version = "0.3" }
zcash_protocol = { version = "=0.11.0-pre.0", default-features = false }
pczt = { version = "=0.10.0-pre.1", default-features = false, features = ["orchard", "sapling", "transparent"] }
sapling = { package = "sapling-crypto", version = "0.9", default-features = false }
bip32 = { version = "0.6", default-features = false, features = ["alloc"] }

## gRPC Web dependencies
prost = { version = "0.14", default-features = false }
tonic = { version = "0.14", default-features = false }


# Used in Native tests
zcash_client_sqlite = { version = "0.22.0-rc.1", default-features = false, features = ["unstable", "orchard"] }
zcash_client_sqlite = { version = "=0.23.0-pre.1", default-features = false, features = ["unstable", "orchard"] }

getrandom = { version = "0.2", features = ["js"] }
# `rand 0.10` (pulled in by the zcash crates) uses getrandom 0.4, which needs its `wasm_js` backend on wasm32.
rand10 = { package = "rand", version = "0.10", default-features = false, features = ["std", "std_rng", "sys_rng", "thread_rng"] }
getrandom04 = { package = "getrandom", version = "0.4", features = ["wasm_js"] }
thiserror = "1.0.63"
indexed_db_futures = "0.5.0"
sha2 = "0.10"
Expand Down Expand Up @@ -84,29 +90,10 @@ tokio = { version = "1.0", features = ["rt", "macros"] }
byte-unit = { version = "5.1.4", features = ["byte"] }

[patch.crates-io]
# NU6.3: redirect the librustzcash family to upstream main rev 0a2c6d1a (release-candidate versions;
# carries Nu6_3 = 0x37a5_165b, testnet activation 4,134,000, mainnet activation 3,428,143 — both
# finalized, and the Ironwood wallet layer: Signer::sign_ironwood, Verifier::with_ironwood,
# IronwoodDomain scanning). This rev MUST match the rev pinned by the red-dev-inc/zcash_client_memory
# fork, or cargo builds two zcash_primitives -> trait mismatches.
#
# orchard: main patches orchard to the ZIP-374 deferred-anchor-builder branch (rev 3bd2b736, still
# version 0.15.0). We MUST mirror this exact patch, or our crates pull orchard 0.15.0 from crates.io
# while librustzcash pulls the git rev -> two `orchard` versions -> trait mismatch. Drop once it lands
# in an orchard release.
orchard = { git = "https://github.com/zcash/orchard.git", rev = "3bd2b736d1273226595773265313fc3f3428af16" }
equihash = { git = "https://github.com/zcash/librustzcash", rev = "0a2c6d1ae6274e6af2291e312f7b7459516882f2" }
zcash_address = { git = "https://github.com/zcash/librustzcash", rev = "0a2c6d1ae6274e6af2291e312f7b7459516882f2" }
zcash_client_backend = { git = "https://github.com/zcash/librustzcash", rev = "0a2c6d1ae6274e6af2291e312f7b7459516882f2" }
zcash_client_sqlite = { git = "https://github.com/zcash/librustzcash", rev = "0a2c6d1ae6274e6af2291e312f7b7459516882f2" }
zcash_encoding = { git = "https://github.com/zcash/librustzcash", rev = "0a2c6d1ae6274e6af2291e312f7b7459516882f2" }
zcash_keys = { git = "https://github.com/zcash/librustzcash", rev = "0a2c6d1ae6274e6af2291e312f7b7459516882f2" }
zcash_protocol = { git = "https://github.com/zcash/librustzcash", rev = "0a2c6d1ae6274e6af2291e312f7b7459516882f2" }
zip321 = { git = "https://github.com/zcash/librustzcash", rev = "0a2c6d1ae6274e6af2291e312f7b7459516882f2" }
zcash_primitives = { git = "https://github.com/zcash/librustzcash", rev = "0a2c6d1ae6274e6af2291e312f7b7459516882f2" }
zcash_proofs = { git = "https://github.com/zcash/librustzcash", rev = "0a2c6d1ae6274e6af2291e312f7b7459516882f2" }
pczt = { git = "https://github.com/zcash/librustzcash", rev = "0a2c6d1ae6274e6af2291e312f7b7459516882f2" }
zcash_transparent = { git = "https://github.com/zcash/librustzcash", rev = "0a2c6d1ae6274e6af2291e312f7b7459516882f2" }
# lightwalletd v0.5.4 (Zcash testnet) answers an empty stream with a trailers-only response, which
# tonic-web-wasm-client 0.8.0 rejects as `MalformedResponse`, so sync fails. See
# vendor/tonic-web-wasm-client/VENDORED.md. Remove once fixed upstream.
tonic-web-wasm-client = { path = "vendor/tonic-web-wasm-client" }

[workspace.lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(wasm_bindgen)', 'cfg(wasm_bindgen_unstable_test_coverage)'] }
8 changes: 5 additions & 3 deletions crates/webzjs-keys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,20 @@ pczt = { workspace = true, default-features = false, features = [
"transparent",
"tx-extractor",
] }
orchard = { version = "0.15", default-features = false }
orchard = { version = "0.16", default-features = false }
wasm-bindgen-futures = "0.4.43"
serde.workspace = true
serde-wasm-bindgen.workspace = true

# Demo-only: building sample PCZTs for the connected wallet's UFVK. Gated behind
# the `demo-builder` feature so they never bloat the production Snap WASM.
rand = { version = "0.8", optional = true }
secp256k1 = { version = "0.29", optional = true }
secp256k1 = { version = "0.33", optional = true }

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

[features]
# Exposes `build_owned_demo_pczts` (src/demo_pczt.rs) — used only by the PoC demo
Expand All @@ -72,7 +74,7 @@ pczt = { workspace = true, default-features = false, features = [
rand = "0.8"
# Transparent fixture construction (tests/gen_fixtures.rs) derives a P2PKH pubkey
# and spends it; `secp256k1` is already in the graph via `zcash_transparent`.
secp256k1 = "0.29"
secp256k1 = "0.33"

[lints]
workspace = true
2 changes: 2 additions & 0 deletions crates/webzjs-keys/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub enum Error {
Derivation(#[from] zcash_keys::keys::DerivationError),
#[error("Error attempting to decode key: {0}")]
KeyDecoding(String),
#[error("Error attempting to encode key: {0}")]
KeyEncoding(String),
#[error("Failed to sign Pczt: {0}")]
PcztSign(String),
#[error("Failed to describe Pczt: {0}")]
Expand Down
8 changes: 5 additions & 3 deletions crates/webzjs-keys/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl UnifiedSpendingKey {

pub fn to_sapling_proof_generation_key(&self) -> ProofGenerationKey {
ProofGenerationKey {
inner: self.inner.sapling().expsk.proof_generation_key(),
inner: self.inner.sapling().expsk().proof_generation_key(),
}
}
}
Expand Down Expand Up @@ -146,7 +146,9 @@ impl UnifiedFullViewingKey {
///
pub fn encode(&self, network: &str) -> Result<String, Error> {
let network = Network::from_str(network)?;
Ok(self.inner.encode(&network))
self.inner
.encode(&network)
.map_err(|e| Error::KeyEncoding(e.to_string()))
}

/// Construct a UFVK from its encoded string representation
Expand All @@ -161,7 +163,7 @@ impl UnifiedFullViewingKey {
let network = Network::from_str(network)?;
Ok(Self {
inner: zcash_keys::keys::UnifiedFullViewingKey::decode(&network, encoding)
.map_err(Error::KeyDecoding)?,
.map_err(|e| Error::KeyDecoding(e.to_string()))?,
})
}

Expand Down
6 changes: 3 additions & 3 deletions crates/webzjs-keys/src/pczt_describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,12 @@ pub fn pczt_validate_inner(

/// Encode an Orchard receiver as a Unified Address string for display.
fn encode_orchard(network: &Network, addr: &orchard::Address) -> Option<String> {
UnifiedAddress::from_receivers(Some(*addr), None, None).map(|ua| ua.encode(network))
UnifiedAddress::from_receivers(Some(*addr), None, None, None, None).map(|ua| ua.encode(network))
}

/// Encode a Sapling receiver as a Unified Address string for display.
fn encode_sapling(network: &Network, addr: &sapling::PaymentAddress) -> Option<String> {
UnifiedAddress::from_receivers(None, Some(*addr), None).map(|ua| ua.encode(network))
UnifiedAddress::from_receivers(None, Some(*addr), None, None, None).map(|ua| ua.encode(network))
}

/// True iff this Orchard spend is recoverable under `ofvk`.
Expand Down Expand Up @@ -414,7 +414,7 @@ fn analyze(
let ofvk = ufvk.orchard();
let sdfvk = ufvk.sapling();
let sfvk = sdfvk.map(|dfvk| dfvk.fvk());
let tfvk = ufvk.transparent();
let tfvk = ufvk.p2pkh();

let mut outputs: Vec<PcztOutputSummary> = Vec::new();
let mut total_in: u64 = 0;
Expand Down
4 changes: 3 additions & 1 deletion crates/webzjs-keys/src/pczt_sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ pub async fn pczt_sign_inner(
KeyRef::Orchard { index } => {
signer
.sign_orchard(
rand10::rng(),
index,
&orchard::keys::SpendAuthorizingKey::from(usk.orchard()),
)
Expand All @@ -174,6 +175,7 @@ pub async fn pczt_sign_inner(
// Ironwood reuses the Orchard spend-authorizing key.
signer
.sign_ironwood(
rand10::rng(),
index,
&orchard::keys::SpendAuthorizingKey::from(usk.orchard()),
)
Expand All @@ -183,7 +185,7 @@ pub async fn pczt_sign_inner(
}
KeyRef::Sapling { index } => {
signer
.sign_sapling(index, &usk.sapling().expsk.ask)
.sign_sapling(rand10::rng(), index, usk.sapling().expsk().ask())
.map_err(|e| {
Error::PcztSign(format!("Failed to sign Sapling spend {index}: {e:?}"))
})?;
Expand Down
4 changes: 2 additions & 2 deletions crates/webzjs-keys/tests/gen_fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ use orchard::Address;
use pczt::roles::creator::Creator;
use pczt::roles::redactor::Redactor;

use rand::rngs::StdRng;
use rand::{RngCore, SeedableRng};
use rand10::rngs::StdRng;
use rand10::{Rng, SeedableRng};

use webzjs_common::Network;
use zcash_keys::keys::UnifiedSpendingKey;
Expand Down
4 changes: 2 additions & 2 deletions crates/webzjs-keys/tests/spoof_pczt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn attacker_addr() -> String {
.expect("UFVK has an Orchard key")
.clone();
let addr = ofvk.address_at(0u32, orchard::keys::Scope::External);
UnifiedAddress::from_receivers(Some(addr), None, None)
UnifiedAddress::from_receivers(Some(addr), None, None, None, None)
.expect("orchard-only UA")
.encode(&network)
}
Expand Down Expand Up @@ -305,7 +305,7 @@ fn bridge_orchard_addr() -> String {
.expect("UFVK has an Orchard key")
.clone();
let addr = ofvk.address_at(0u32, orchard::keys::Scope::External);
UnifiedAddress::from_receivers(Some(addr), None, None)
UnifiedAddress::from_receivers(Some(addr), None, None, None, None)
.expect("orchard-only UA")
.encode(&network)
}
Expand Down
1 change: 1 addition & 0 deletions crates/webzjs-requests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ serde-wasm-bindgen.workspace = true

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

[lints]
workspace = true
7 changes: 6 additions & 1 deletion crates/webzjs-wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ 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.15", default-features = false }
orchard = { version = "0.16", default-features = false }
sapling = { workspace = true }
bip32.workspace = true
## gRPC Web dependencies
Expand All @@ -76,6 +76,8 @@ tokio.workspace = true
zcash_client_sqlite = { workspace = true, optional = true }

getrandom = { workspace = true, features = ["js"] }
getrandom04.workspace = true
rand10.workspace = true
thiserror.workspace = true
indexed_db_futures = "0.5.0"
sha2 = "0.10"
Expand All @@ -100,5 +102,8 @@ serde.workspace = true
postcard = { version = "1.0.10", features = ["alloc"] }
serde-wasm-bindgen.workspace = true

[dev-dependencies]
serde_json = "1"

[lints]
workspace = true
73 changes: 73 additions & 0 deletions crates/webzjs-wallet/src/balance.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//! The per-account balance reported to JavaScript.
//!
//! Kept outside the `bindgen` module (which only builds for the browser) so the conversion from the
//! backend's balance can be unit-tested natively. A pool that is missing here is a pool whose
//! funds a JavaScript caller cannot see: the wallet would report a zero balance for them.

use serde::{Deserialize, Serialize};

// Only the browser bindings construct it outside tests.
#[cfg_attr(not(feature = "wasm"), allow(dead_code))]
#[derive(Debug, Serialize, Deserialize)]
pub struct AccountBalance {
pub sapling_balance: u64,
pub orchard_balance: u64,
/// Spendable value in the Ironwood pool, which receives new shielded value since NU6.3.
/// Absent (zero) in summaries produced before this field existed.
#[serde(default)]
pub ironwood_balance: u64,
pub unshielded_balance: u64,
/// Change from sent transactions waiting for mining confirmation
pub pending_change: u64,
/// Received notes waiting for required confirmations to become spendable
pub pending_spendable: u64,
}

impl From<zcash_client_backend::data_api::AccountBalance> for AccountBalance {
fn from(balance: zcash_client_backend::data_api::AccountBalance) -> Self {
AccountBalance {
sapling_balance: balance.sapling_balance().spendable_value().into(),
orchard_balance: balance.orchard_balance().spendable_value().into(),
ironwood_balance: balance.ironwood_balance().spendable_value().into(),
unshielded_balance: balance.unshielded_balance().spendable_value().into(),
pending_change: balance.change_pending_confirmation().into(),
pending_spendable: balance.value_pending_spendability().into(),
}
}
}

#[cfg(test)]
mod tests {
use zcash_client_backend::data_api::{AccountBalance as BackendBalance, Balance};
use zcash_protocol::value::{BalanceError, Zatoshis};

use super::AccountBalance;

#[test]
fn ironwood_value_reaches_the_javascript_balance() {
let mut backend = BackendBalance::ZERO;
backend
.with_ironwood_balance_mut::<_, BalanceError>(|b: &mut Balance| {
b.add_spendable_value(Zatoshis::const_from_u64(12_345))
})
.unwrap();

let js = AccountBalance::from(backend);

assert_eq!(js.ironwood_balance, 12_345);
// The other pools are untouched, so Ironwood is neither double counted nor dropped.
assert_eq!(js.orchard_balance, 0);
assert_eq!(js.sapling_balance, 0);
}

#[test]
fn older_serialized_balances_without_the_ironwood_field_still_load() {
let json = r#"{"sapling_balance":1,"orchard_balance":2,"unshielded_balance":3,
"pending_change":4,"pending_spendable":5}"#;
let b: AccountBalance = serde_json::from_str(json).unwrap();
assert_eq!(
(b.sapling_balance, b.orchard_balance, b.ironwood_balance),
(1, 2, 0)
);
}
}
18 changes: 9 additions & 9 deletions crates/webzjs-wallet/src/bindgen/transaction_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,16 @@ pub fn extract_transaction_history(
zcash_client_backend::wallet::Recipient::External { output_pool, .. } => {
match output_pool {
zcash_protocol::PoolType::Transparent => "transparent",
zcash_protocol::PoolType::Shielded(
zcash_protocol::ShieldedProtocol::Sapling,
) => "sapling",
zcash_protocol::PoolType::Shielded(
zcash_protocol::ShieldedProtocol::Orchard,
) => "orchard",
zcash_protocol::PoolType::Shielded(zcash_protocol::ShieldedPool::Sapling) => {
"sapling"
}
zcash_protocol::PoolType::Shielded(zcash_protocol::ShieldedPool::Orchard) => {
"orchard"
}
// NU6.3 Ironwood pool.
zcash_protocol::PoolType::Shielded(
zcash_protocol::ShieldedProtocol::Ironwood,
) => "ironwood",
zcash_protocol::PoolType::Shielded(zcash_protocol::ShieldedPool::Ironwood) => {
"ironwood"
}
}
}
zcash_client_backend::wallet::Recipient::EphemeralTransparent { .. } => "transparent",
Expand Down
Loading