Skip to content

Commit

Permalink
zcash_keys: Enable no_std usage via a default-enabled std feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
nuttycom committed Dec 16, 2024
1 parent 97f378e commit 7e23130
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 10 deletions.
7 changes: 3 additions & 4 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ redjubjub = "0.7"
sapling = { package = "sapling-crypto", version = "0.3", default-features = false }

# - Orchard
nonempty = "0.7"
orchard = { version = "0.10", default-features = false }
pasta_curves = "0.5"

Expand All @@ -77,6 +76,7 @@ transparent = { package = "zcash_transparent", version = "0.0", path = "zcash_tr

# Boilerplate & missing stdlib
getset = "0.1"
nonempty = { version = "0.10", default-features = false }

# CSPRNG
rand = { version = "0.8", default-features = false }
Expand Down Expand Up @@ -195,5 +195,6 @@ debug = true
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(zcash_unstable, values("zfuture"))'] }

[patch.crates-io]
orchard = { git = "https://github.com/zcash/orchard.git", rev = "f99b6565a78763b58dac792d7492c55067bae680" }
nonempty = { git = "https://github.com/nuttycom/nonempty.git", rev = "38d37189faecb2a0e3d6adc05aa24e1b93c2483b" }
orchard = { git = "https://github.com/zcash/orchard.git", rev = "159966b80e2d956907f853bb24513ff5bef4087d" }
sapling-crypto = { git = "https://github.com/zcash/sapling-crypto.git", rev = "e47d57f5c9c46f05740328f8ef9601f6d697cf34" }
4 changes: 4 additions & 0 deletions zcash_keys/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this library adheres to Rust's notion of

## [Unreleased]

### Added
- `no-std` compatibility (`alloc` is required). A default-enabled `std` feature
flag has been added gating the `std::error::Error` usage.

### Changed
- Migrated to `bech32 0.11`.
- The `UnifiedAddressRequest` argument to the following methods is now optional:
Expand Down
5 changes: 4 additions & 1 deletion zcash_keys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ proptest = { workspace = true, optional = true }
# Dependencies used internally:
# (Breaking upgrades to these are usually backwards-compatible, but check MSRVs.)
# - Documentation
document-features.workspace = true
document-features = { workspace = true, optional = true }

# - Encodings
byteorder = { workspace = true, optional = true }
Expand All @@ -76,6 +76,9 @@ zcash_address = { workspace = true, features = ["test-dependencies"] }
zcash_primitives = { workspace = true, features = ["test-dependencies"] }

[features]
default = ["std"]
std = ["dep:document-features"]

## Enables use of transparent key parts and addresses
transparent-inputs = ["dep:bip32", "zcash_primitives/transparent-inputs"]

Expand Down
3 changes: 2 additions & 1 deletion zcash_keys/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl fmt::Display for Bech32DecodeError {
}
}

#[cfg(feature = "sapling")]
#[cfg(all(feature = "sapling", feature = "std"))]
impl std::error::Error for Bech32DecodeError {}

#[cfg(feature = "sapling")]
Expand Down Expand Up @@ -135,6 +135,7 @@ impl fmt::Display for TransparentCodecError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for TransparentCodecError {}

impl<P: consensus::Parameters> AddressCodec<P> for TransparentAddress {
Expand Down
4 changes: 3 additions & 1 deletion zcash_keys/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ impl Display for DerivationError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for DerivationError {}

/// A version identifier for the encoding of unified spending keys.
Expand Down Expand Up @@ -180,6 +181,7 @@ impl core::fmt::Display for DecodingError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for DecodingError {}

#[cfg(feature = "unstable")]
Expand Down Expand Up @@ -547,6 +549,7 @@ impl fmt::Display for AddressGenerationError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for AddressGenerationError {}

/// Specification for how a unified address should be generated from a unified viewing key.
Expand Down Expand Up @@ -1308,7 +1311,6 @@ pub mod testing {

#[cfg(test)]
mod tests {

use proptest::prelude::proptest;

use {zcash_primitives::consensus::MAIN_NETWORK, zip32::AccountId};
Expand Down
4 changes: 3 additions & 1 deletion zcash_keys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
//! and viewing keys and addresses.
//!
//! ## Feature flags
#![doc = document_features::document_features!()]
#![cfg_attr(feature = "std", doc = "## Feature flags")]
#![cfg_attr(feature = "std", doc = document_features::document_features!())]
//!
#![no_std]
Expand All @@ -19,6 +20,7 @@
#[macro_use]
extern crate alloc;

#[cfg(feature = "std")]
extern crate std;

pub mod address;
Expand Down

0 comments on commit 7e23130

Please sign in to comment.