Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow SpendValidatingKey to be constructed from bytes #428

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"]
Expand Down
9 changes: 8 additions & 1 deletion src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
pacu marked this conversation as resolved.
Show resolved Hide resolved
<[u8; 32]>::try_from(bytes)
.ok()
Expand Down
Loading