From 01367ff710647a848f0e5a4ca06006ce9676d95f Mon Sep 17 00:00:00 2001 From: Francisco Gindre Date: Wed, 31 Jul 2024 11:01:27 -0300 Subject: [PATCH] Allow creating a FullViewingKey from a given SpendValidatingKey Allows creating a FullViewingKey from a given SpendValidatingKey and from the other components which can be randomly generated, but there may be some utility in specifying them too like supporting FROST backup schemes that don't centralize spend authority closes #431 see related #430 --- CHANGELOG.md | 11 ++++++++++- src/keys.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26792b0cd..9185a6ba0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,16 @@ and this project adheres to Rust's notion of [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] -### Added +### added +- Added [Visibility crate](https://crates.io/crates/visibility) to modify +visibility of methods and struct for the `unstable-frost` feature. +- Added `SpendValidatingKey` serialization and deserialization from bytes +visibility under the `unstable-frost` feature + - `orchard::keys::SpendValidatingKey` +- Added `from_sk_and_ask::keys::FullViewingKey::from_sk_and_ask` under the +`unstable-frost` feature flag +- Added `from_sk_and_ask::keys::FullViewingKey::from_checked_parts` under the +`unstable-frost` feature flag - `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 diff --git a/src/keys.rs b/src/keys.rs index f66928eeb..cd61daa0c 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -225,6 +225,7 @@ impl SpendValidatingKey { /// [`Note`]: crate::note::Note /// [orchardkeycomponents]: https://zips.z.cash/protocol/nu5.pdf#orchardkeycomponents #[derive(Copy, Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "unstable-frost", visibility::make(pub))] pub(crate) struct NullifierDerivingKey(pallas::Base); impl NullifierDerivingKey { @@ -266,6 +267,7 @@ impl NullifierDerivingKey { /// /// [orchardkeycomponents]: https://zips.z.cash/protocol/nu5.pdf#orchardkeycomponents #[derive(Copy, Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "unstable-frost", visibility::make(pub))] pub(crate) struct CommitIvkRandomness(pallas::Scalar); impl From<&SpendingKey> for CommitIvkRandomness { @@ -333,6 +335,36 @@ impl From for SpendValidatingKey { } impl FullViewingKey { + /// Creates a `FullViewingKey` from a `SpendingKey` and `SpendValidatingKey`. + /// This is necessary for FROST key management. + /// + /// Note: See [FROST Book - Technical details](https://frost.zfnd.org/zcash/technical-details.html) + #[cfg(feature = "unstable-frost")] + pub fn from_sk_and_ask(sk: &SpendingKey, ask: SpendValidatingKey) -> FullViewingKey { + FullViewingKey { + ak: ask, + nk: NullifierDerivingKey::from(sk), + rivk: CommitIvkRandomness::from(sk), + } + } + + /// Creates a `FullViewingKey` from its checked parts. This is necessary for FROST + /// key management in order to avoid centralizing spend authority in a backup scheme. + /// + /// Note: See [FROST Book - Technical details - Backing Up Key Shares](https://frost.zfnd.org/zcash/technical-details.html) + #[cfg(feature = "unstable-frost")] + pub fn from_checked_parts( + ask: SpendValidatingKey, + nk: NullifierDerivingKey, + rivk: CommitIvkRandomness, + ) -> FullViewingKey { + FullViewingKey { + ak: ask, + nk, + rivk, + } + } + pub(crate) fn nk(&self) -> &NullifierDerivingKey { &self.nk }