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
  • Loading branch information
pacu committed Jul 5, 2024
1 parent 2b9c9a1 commit eb78047
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 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]
### changed
- changed `SpendValidatingKey` serialization and deserialization from bytes
visibility from `pub(crate)` to `pub`
- `orchard::keys::SpendValidatingKey`

## [0.8.0] - 2024-03-25

Expand Down
7 changes: 5 additions & 2 deletions src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,16 @@ impl SpendValidatingKey {

/// Converts this spend validating key to its serialized form,
/// I2LEOSP_256(ak).
pub(crate) fn to_bytes(&self) -> [u8; 32] {
pub 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)
}

pub(crate) fn from_bytes(bytes: &[u8]) -> Option<Self> {
/// 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 fn from_bytes(bytes: &[u8]) -> Option<Self> {
<[u8; 32]>::try_from(bytes)
.ok()
.and_then(|b| {
Expand Down

0 comments on commit eb78047

Please sign in to comment.