Skip to content

Commit

Permalink
Merge pull request zcash#428 from pacu/ak-from-bytes
Browse files Browse the repository at this point in the history
Allow SpendValidatingKey to be constructed from bytes
  • Loading branch information
nuttycom authored Aug 1, 2024
2 parents 2b9c9a1 + 2bb3a08 commit d4136c6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
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> {
<[u8; 32]>::try_from(bytes)
.ok()
Expand Down

0 comments on commit d4136c6

Please sign in to comment.