Skip to content

Commit

Permalink
Adds functions to convert nk, ak, rivk from and to bytes.
Browse files Browse the repository at this point in the history
Exposes FVK's components for FROST clients
  • Loading branch information
pacu committed Aug 3, 2024
1 parent 6da15c1 commit 388195a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ visibility under the `unstable-frost` feature
`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).
- `orchard::keys::SpendValidatingKey` exposes its composing parts through functions
gated by the `unstable-frost` feature flag. These functions are intended to be used
by FROST clients to backup the key elements.
- `orchard::keys::NullifierDerivingKey::from_bytes` made `pub` behind the
`unstable-frost` feature flag.
- `orchard::keys::NullifierDerivingKey::to_bytes` made `pub` behind the
`unstable-frost` feature flag.
- `orchard::keys::CommitIvkRandomness::from_bytes` made `pub` behind the
`unstable-frost` feature flag.
- `orchard::keys::CommitIvkRandomness::to_bytes` made `pub` behind the
`unstable-frost` feature flag.


## [0.8.0] - 2024-03-25

Expand Down
22 changes: 21 additions & 1 deletion src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,13 @@ impl NullifierDerivingKey {
}

/// Converts this nullifier deriving key to its serialized form.
#[cfg_attr(feature = "unstable-frost", visibility::make(pub))]
pub(crate) fn to_bytes(self) -> [u8; 32] {
<[u8; 32]>::from(self.0)
}

/// Converts this nullifier deriving key from its serialized form.
#[cfg_attr(feature = "unstable-frost", visibility::make(pub))]
pub(crate) fn from_bytes(bytes: &[u8]) -> Option<Self> {
let nk_bytes = <[u8; 32]>::try_from(bytes).ok()?;
let nk = pallas::Base::from_repr(nk_bytes).map(NullifierDerivingKey);
Expand Down Expand Up @@ -281,11 +284,14 @@ impl CommitIvkRandomness {
self.0
}

/// Converts this nullifier deriving key to its serialized form.
/// Converts this [`CommitIvkRandomness`] to its serialized form.
#[cfg_attr(feature = "unstable-frost", visibility::make(pub))]
pub(crate) fn to_bytes(self) -> [u8; 32] {
<[u8; 32]>::from(self.0)
}

#[cfg_attr(feature = "unstable-frost", visibility::make(pub))]
/// Converts this [`CommitIvkRandomness`] from its serialized form.
pub(crate) fn from_bytes(bytes: &[u8]) -> Option<Self> {
let rivk_bytes = <[u8; 32]>::try_from(bytes).ok()?;
let rivk = pallas::Scalar::from_repr(rivk_bytes).map(CommitIvkRandomness);
Expand Down Expand Up @@ -361,11 +367,25 @@ impl FullViewingKey {
FullViewingKey { ak, nk, rivk }
}

/// Returns the `SpendValidatingKey` of this `FullViewingKey`
/// - Note: this is intended for the "unstable-frost" feature to
/// facilitate the DKG'd key backup scheme. See [Backing Up Key Shares](https://frost.zfnd.org/zcash/technical-details.html#backing-up-key-shares)
#[cfg_attr(feature = "unstable-frost", visibility::make(pub))]
pub fn ak(&self) -> &SpendValidatingKey {
&self.ak
}
/// Returns the `NullifierDerivingKey` of this `FullViewingKey`
/// - Note: this is `pub` for the "unstable-frost" feature to
/// facilitate the DKG'd key backup scheme. See [Backing Up Key Shares](https://frost.zfnd.org/zcash/technical-details.html#backing-up-key-shares)
#[cfg_attr(feature = "unstable-frost", visibility::make(pub))]
pub(crate) fn nk(&self) -> &NullifierDerivingKey {
&self.nk
}

/// Returns either `rivk` or `rivk_internal` based on `scope`.
/// - Note: this is `pub` for the "unstable-frost" feature to
/// facilitate the DKG'd key backup scheme. See [Backing Up Key Shares](https://frost.zfnd.org/zcash/technical-details.html#backing-up-key-shares)
#[cfg_attr(feature = "unstable-frost", visibility::make(pub))]
pub(crate) fn rivk(&self, scope: Scope) -> CommitIvkRandomness {
match scope {
Scope::External => self.rivk,
Expand Down

0 comments on commit 388195a

Please sign in to comment.