diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fd1be722..26792b0cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to Rust's notion of [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- `orchard::keys::SpendValidatingKey::{from_bytes, to_bytes}` behind the + `unstable-frost` feature flag. These are temporary APIs exposed for development + purposes, and will be replaced by type-safe FROST APIs once ZIP 312 key + generation is specified (https://github.com/zcash/zips/pull/883). ## [0.8.0] - 2024-03-25 diff --git a/Cargo.lock b/Cargo.lock index b525d0ada..983510038 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1440,6 +1440,7 @@ dependencies = [ "serde", "subtle", "tracing", + "visibility", "zcash_note_encryption", "zcash_spec", "zip32", @@ -2251,6 +2252,17 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "visibility" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3fd98999db9227cf28e59d83e1f120f42bc233d4b152e8fab9bc87d5bb1e0f8" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.31", +] + [[package]] name = "wait-timeout" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index 0ea1d289d..3267f13f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,6 +45,7 @@ zcash_note_encryption = "0.4" incrementalmerkletree = "0.5" zcash_spec = "0.1" zip32 = "0.1" +visibility = "0.1.0" # Logging tracing = "0.1" @@ -71,6 +72,7 @@ bench = false [features] default = ["multicore"] +unstable-frost = [] multicore = ["halo2_proofs/multicore"] dev-graph = ["halo2_proofs/dev-graph", "image", "plotters"] test-dependencies = ["proptest"] diff --git a/src/keys.rs b/src/keys.rs index f5bae6cb2..f66928eeb 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -186,12 +186,19 @@ impl SpendValidatingKey { /// Converts this spend validating key to its serialized form, /// I2LEOSP_256(ak). + #[cfg_attr(feature = "unstable-frost", visibility::make(pub))] pub(crate) fn to_bytes(&self) -> [u8; 32] { // This is correct because the wrapped point must have ỹ = 0, and // so the point repr is the same as I2LEOSP of its x-coordinate. - <[u8; 32]>::from(&self.0) + let b = <[u8; 32]>::from(&self.0); + assert!(b[31] & 0x80 == 0); + b } + /// Attempts to parse a byte slice as a spend validating key, `I2LEOSP_256(ak)`. + /// + /// Returns `None` if the given slice does not contain a valid spend validating key. + #[cfg_attr(feature = "unstable-frost", visibility::make(pub))] pub(crate) fn from_bytes(bytes: &[u8]) -> Option { <[u8; 32]>::try_from(bytes) .ok()