diff --git a/CHANGELOG.md b/CHANGELOG.md index b464b50..9ec5ec9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,12 +7,27 @@ and this library adheres to Rust's notion of ## [Unreleased] ### Changed +- **Breaking change:** removed the constants `COMPACT_NOTE_SIZE`, + `NOTE_PLAINTEXT_SIZE`, and `ENC_CIPHERTEXT_SIZE` as they are now + implementation spesific (located in `orchard` and `sapling-crypto` crates). - Generalized the note plaintext size to support variable sizes by adding the abstract types `NotePlaintextBytes`, `NoteCiphertextBytes`, `CompactNotePlaintextBytes`, and `CompactNoteCiphertextBytes` to the `Domain` trait. -- Moved the specific constants into the `Domain` trait implementations. - +- Removed the separate `NotePlaintextBytes` type definition (as it is now an + associated type). +- Added new `parse_note_plaintext_bytes`, `parse_note_ciphertext_bytes`, and + `parse_compact_note_plaintext_bytes` methods to the `Domain` trait. +- Updated the `note_plaintext_bytes` method of the `Domain` trait to return the + `NotePlaintextBytes` associated type. +- Updated the `encrypt_note_plaintext` method of `NoteEncryption` to return the + `NoteCiphertextBytes` associated type of the `Domain` instead of the explicit + array. +- Updated the `enc_ciphertext` method of the `ShieldedOutput` trait to return an + `Option` of a reference instead of a copy. +- Added a new `note_bytes` module with helper trait and struct to deal with note + bytes data with abstracted underlying array size. + ## [0.4.0] - 2023-06-06 ### Changed - The `esk` and `ephemeral_key` arguments have been removed from diff --git a/rust-toolchain.toml b/rust-toolchain.toml index bd93f58..57237a5 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] channel = "1.56.1" -components = [ "clippy", "rustfmt" ] +components = ["clippy", "rustfmt"] diff --git a/src/lib.rs b/src/lib.rs index 4d18376..3e28501 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -44,28 +44,13 @@ pub mod note_bytes; use note_bytes::NoteBytes; -/// The size of a compact note for Sapling and Orchard Vanilla. -pub const COMPACT_NOTE_SIZE: usize = 1 + // version - 11 + // diversifier - 8 + // value - 32; // rseed (or rcm prior to ZIP 212) -/// The size of `NotePlaintextBytes` for Sapling and Orchard Vanilla. -pub const NOTE_PLAINTEXT_SIZE: usize = COMPACT_NOTE_SIZE + 512; - -/// The size of the memo. -pub const MEMO_SIZE: usize = 512; -/// The size of the authentication tag used for note encryption. -pub const AEAD_TAG_SIZE: usize = 16; - /// The size of [`OutPlaintextBytes`]. pub const OUT_PLAINTEXT_SIZE: usize = 32 + // pk_d 32; // esk +const AEAD_TAG_SIZE: usize = 16; /// The size of an encrypted outgoing plaintext. pub const OUT_CIPHERTEXT_SIZE: usize = OUT_PLAINTEXT_SIZE + AEAD_TAG_SIZE; -/// The size of an encrypted note plaintext for Sapling and Orchard Vanilla. -pub const ENC_CIPHERTEXT_SIZE: usize = NOTE_PLAINTEXT_SIZE + AEAD_TAG_SIZE; - /// A symmetric key that can be used to recover a single Sapling or Orchard output. pub struct OutgoingCipherKey(pub [u8; 32]); @@ -270,7 +255,8 @@ pub trait Domain { plaintext: &Self::CompactNotePlaintextBytes, ) -> Option<(Self::Note, Self::Recipient)>; - /// Splits the memo field from the given note plaintext. + /// Splits the given note plaintext into the compact part (containing the note) and + /// the memo field. /// /// # Compatibility /// @@ -374,7 +360,7 @@ pub trait ShieldedOutput { fn cmstar_bytes(&self) -> D::ExtractedCommitmentBytes; /// Exposes the note ciphertext of the output. Returns `None` if the output is compact. - fn enc_ciphertext(&self) -> Option; + fn enc_ciphertext(&self) -> Option<&D::NoteCiphertextBytes>; // FIXME: Should we return `Option` or // `&D::CompactNoteCiphertextBytes` instead? (complexity)? @@ -383,8 +369,7 @@ pub trait ShieldedOutput { //// Splits the AEAD tag from the ciphertext. fn split_ciphertext_at_tag(&self) -> Option<(D::NotePlaintextBytes, [u8; AEAD_TAG_SIZE])> { - let enc_ciphertext = self.enc_ciphertext()?; - let enc_ciphertext_bytes = enc_ciphertext.as_ref(); + let enc_ciphertext_bytes = self.enc_ciphertext()?.as_ref(); let (plaintext, tail) = enc_ciphertext_bytes .len()