From b90f1463bcbaaabe81ffa706f18533856b9139b6 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Mon, 16 Dec 2024 12:23:01 -0700 Subject: [PATCH] zcash_keys: Enable `no_std` usage via a default-enabled `std` feature. --- Cargo.lock | 8 +++----- Cargo.toml | 6 +++++- zcash_keys/CHANGELOG.md | 4 ++++ zcash_keys/Cargo.toml | 5 ++++- zcash_keys/src/encoding.rs | 3 ++- zcash_keys/src/keys.rs | 4 +++- zcash_keys/src/lib.rs | 4 +++- 7 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2bcea96fc..a52791a54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2609,9 +2609,8 @@ dependencies = [ [[package]] name = "nonempty" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9e591e719385e6ebaeb5ce5d3887f7d5676fceca6411d1925ccc95745f3d6f7" +version = "0.10.0" +source = "git+https://github.com/nuttycom/nonempty.git?rev=38d37189faecb2a0e3d6adc05aa24e1b93c2483b#38d37189faecb2a0e3d6adc05aa24e1b93c2483b" [[package]] name = "notify" @@ -2789,8 +2788,7 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" [[package]] name = "orchard" version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02f7152474406422f572de163e0bc63b2126cdbfe17bc849efbbde36fcfe647e" +source = "git+https://github.com/zcash/orchard.git?rev=e0cc7ac53ad8c97661b312a8b1c064f4cd3c6629#e0cc7ac53ad8c97661b312a8b1c064f4cd3c6629" dependencies = [ "aes", "bitvec", diff --git a/Cargo.toml b/Cargo.toml index 4e37a9fe4..4237584dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,7 +65,6 @@ redjubjub = "0.7" sapling = { package = "sapling-crypto", version = "0.4", default-features = false } # - Orchard -nonempty = "0.7" orchard = { version = "0.10.1", default-features = false } pasta_curves = "0.5" @@ -77,6 +76,7 @@ transparent = { package = "zcash_transparent", version = "0.1", path = "zcash_tr # Boilerplate & missing stdlib getset = "0.1" +nonempty = { version = "0.10", default-features = false } # CSPRNG rand = { version = "0.8", default-features = false } @@ -193,3 +193,7 @@ debug = true [workspace.lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(zcash_unstable, values("zfuture"))'] } + +[patch.crates-io] +nonempty = { git = "https://github.com/nuttycom/nonempty.git", rev = "38d37189faecb2a0e3d6adc05aa24e1b93c2483b" } +orchard = { git = "https://github.com/zcash/orchard.git", rev = "e0cc7ac53ad8c97661b312a8b1c064f4cd3c6629" } diff --git a/zcash_keys/CHANGELOG.md b/zcash_keys/CHANGELOG.md index d7e33fb8d..1b2a0c9fe 100644 --- a/zcash_keys/CHANGELOG.md +++ b/zcash_keys/CHANGELOG.md @@ -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. + ## [0.6.0] - 2024-12-16 ### Changed diff --git a/zcash_keys/Cargo.toml b/zcash_keys/Cargo.toml index f950bcbf7..851e122ea 100644 --- a/zcash_keys/Cargo.toml +++ b/zcash_keys/Cargo.toml @@ -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 } @@ -76,6 +76,9 @@ orchard = { workspace = true, features = ["circuit"] } zcash_address = { workspace = true, features = ["test-dependencies"] } [features] +default = ["std"] +std = ["dep:document-features"] + ## Enables use of transparent key parts and addresses transparent-inputs = [ "dep:bip32", diff --git a/zcash_keys/src/encoding.rs b/zcash_keys/src/encoding.rs index 50270fc28..7be07a3d4 100644 --- a/zcash_keys/src/encoding.rs +++ b/zcash_keys/src/encoding.rs @@ -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")] @@ -135,6 +135,7 @@ impl fmt::Display for TransparentCodecError { } } +#[cfg(feature = "std")] impl std::error::Error for TransparentCodecError {} impl AddressCodec

for TransparentAddress { diff --git a/zcash_keys/src/keys.rs b/zcash_keys/src/keys.rs index 140e2cc58..123dd20aa 100644 --- a/zcash_keys/src/keys.rs +++ b/zcash_keys/src/keys.rs @@ -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. @@ -180,6 +181,7 @@ impl core::fmt::Display for DecodingError { } } +#[cfg(feature = "std")] impl std::error::Error for DecodingError {} #[cfg(feature = "unstable")] @@ -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. @@ -1308,7 +1311,6 @@ pub mod testing { #[cfg(test)] mod tests { - use proptest::prelude::proptest; use zcash_protocol::consensus::MAIN_NETWORK; diff --git a/zcash_keys/src/lib.rs b/zcash_keys/src/lib.rs index 28c9c98b1..48830ebd0 100644 --- a/zcash_keys/src/lib.rs +++ b/zcash_keys/src/lib.rs @@ -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] @@ -18,6 +19,7 @@ #[macro_use] extern crate alloc; +#[cfg(feature = "std")] extern crate std; pub mod address;