From 45bcc16f8011e8c424c450cf6210036c34df96a3 Mon Sep 17 00:00:00 2001 From: Hazel OHearn Date: Tue, 5 Jul 2022 14:54:37 -0300 Subject: [PATCH] Publicize necessary functionality for reading diversifiers and notes from data --- CHANGELOG.md | 5 +++++ src/keys.rs | 3 ++- src/note.rs | 12 ++++++++---- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5077477b..c01f0981 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to Rust's notion of [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed +- `note`: + - `RandomSeed` and its functions `from_bytes` and `as_bytes` now public + - `Note::from_parts` now public +- `keys::Diversifier::from_bytes` now public ## [0.2.0] - 2022-06-24 ### Added diff --git a/src/keys.rs b/src/keys.rs index 0504dfa4..7bb44925 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -552,7 +552,8 @@ impl DiversifierKey { pub struct Diversifier([u8; 11]); impl Diversifier { - pub(crate) fn from_bytes(d: [u8; 11]) -> Self { + ///Read a diversifier from a byte array. + pub fn from_bytes(d: [u8; 11]) -> Self { Diversifier(d) } diff --git a/src/note.rs b/src/note.rs index 6bd3f778..adbcaa76 100644 --- a/src/note.rs +++ b/src/note.rs @@ -21,7 +21,7 @@ pub use self::nullifier::Nullifier; /// The ZIP 212 seed randomness for a note. #[derive(Copy, Clone, Debug)] -pub(crate) struct RandomSeed([u8; 32]); +pub struct RandomSeed([u8; 32]); impl RandomSeed { pub(crate) fn random(rng: &mut impl RngCore, rho: &Nullifier) -> Self { @@ -35,13 +35,16 @@ impl RandomSeed { } } - pub(crate) fn from_bytes(rseed: [u8; 32], rho: &Nullifier) -> CtOption { + ///Read a note's random seed from bytes, given the note's nullifier. + ///Returns None if the nullifier is not for the same note as the seed. + pub fn from_bytes(rseed: [u8; 32], rho: &Nullifier) -> CtOption { let rseed = RandomSeed(rseed); let esk = rseed.esk_inner(rho); CtOption::new(rseed, esk.is_some()) } - pub(crate) fn as_bytes(&self) -> &[u8; 32] { + /// Returns the byte array corresponding to this seed. + pub fn as_bytes(&self) -> &[u8; 32] { &self.0 } @@ -108,7 +111,8 @@ impl PartialEq for Note { impl Eq for Note {} impl Note { - pub(crate) fn from_parts( + ///Create a Note from its component parts. + pub fn from_parts( recipient: Address, value: NoteValue, rho: Nullifier,