Skip to content

Commit

Permalink
Allow SpendValidatingKey to be constructed from bytes
Browse files Browse the repository at this point in the history
closes #427

This adds a FROST feature flag so that public interface of the
crate is not altered in its meaning for non-FROST applications.

Key derivation is intended to be done on a specific way for usual
applications. Interface changes introduce by FROST can pose a risk
for the rest of the use cases that don't involve the assumptions
of the FROST signature scheme protocol. we don't want non-FROST
cases to make use the helper functions FROST needs to derive the
needed key elements.
  • Loading branch information
pacu committed Jul 23, 2024
1 parent 2b9c9a1 commit b98c14d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to Rust's notion of
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### added
- Added `SpendValidatingKey` serialization and deserialization from bytes
visibility under the `FROST` feature
- `orchard::keys::SpendValidatingKey`

## [0.8.0] - 2024-03-25

Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ bench = false
default = ["multicore"]
multicore = ["halo2_proofs/multicore"]
dev-graph = ["halo2_proofs/dev-graph", "image", "plotters"]
FROST = []
test-dependencies = ["proptest"]

[[bench]]
Expand Down
17 changes: 17 additions & 0 deletions src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,16 @@ impl SpendValidatingKey {
// so the point repr is the same as I2LEOSP of its x-coordinate.
<[u8; 32]>::from(&self.0)
}
/// Converts this spend validating key to its serialized form,
/// I2LEOSP_256(ak).
#[cfg(feature = "FROST")]
pub fn into_bytes(&self) -> [u8; 32] {
self.to_bytes()
}

/// Attempts to convert these bytes into a spend validating key
/// from its serialized form, I2LEOSP_256(ak). Returns None if
/// it can't be created.
pub(crate) fn from_bytes(bytes: &[u8]) -> Option<Self> {
<[u8; 32]>::try_from(bytes)
.ok()
Expand All @@ -208,6 +217,14 @@ impl SpendValidatingKey {
})
.map(SpendValidatingKey)
}

/// Attempts to convert these bytes into a spend validating key
/// from its serialized form, I2LEOSP_256(ak). Returns None if
/// it can't be created.
#[cfg(feature = "FROST")]
pub fn with_bytes(bytes: &[u8]) -> Option<Self> {
SpendValidatingKey::from_bytes(bytes)
}
}

/// A key used to derive [`Nullifier`]s from [`Note`]s.
Expand Down

0 comments on commit b98c14d

Please sign in to comment.