diff --git a/src/bundle.rs b/src/bundle.rs index d7ba7e0f..035c32d2 100644 --- a/src/bundle.rs +++ b/src/bundle.rs @@ -13,7 +13,8 @@ use crate::{ constants::GROTH_PROOF_SIZE, note::ExtractedNoteCommitment, note_encryption::{ - CompactOutputDescription, SaplingDomain, COMPACT_NOTE_SIZE, ENC_CIPHERTEXT_SIZE, + CompactEncCiphertext, CompactOutputDescription, EncCiphertext, SaplingDomain, + COMPACT_NOTE_SIZE, ENC_CIPHERTEXT_SIZE, }, value::ValueCommitment, Nullifier, @@ -433,12 +434,14 @@ impl ShieldedOutput for OutputDescription { self.cmu.to_bytes() } - fn enc_ciphertext(&self) -> Option<&NoteBytesData<{ ENC_CIPHERTEXT_SIZE }>> { + fn enc_ciphertext(&self) -> Option<&EncCiphertext> { Some(&self.enc_ciphertext) } - fn enc_ciphertext_compact(&self) -> NoteBytesData<{ COMPACT_NOTE_SIZE }> { - unimplemented!("This function is not required for sapling") + fn enc_ciphertext_compact(&self) -> CompactEncCiphertext { + let mut data = [0u8; COMPACT_NOTE_SIZE]; + data.copy_from_slice(&self.enc_ciphertext.as_ref()[..COMPACT_NOTE_SIZE]); + NoteBytesData(data) } } @@ -498,12 +501,12 @@ impl OutputDescriptionV5 { impl From> for CompactOutputDescription { fn from(out: OutputDescription) -> CompactOutputDescription { + let enc_ciphertext = out.enc_ciphertext_compact().0; + CompactOutputDescription { ephemeral_key: out.ephemeral_key, cmu: out.cmu, - enc_ciphertext: out.enc_ciphertext.as_ref()[..COMPACT_NOTE_SIZE] - .try_into() - .unwrap(), + enc_ciphertext, } } } diff --git a/src/note_encryption.rs b/src/note_encryption.rs index 5305b49d..cd18a9f7 100644 --- a/src/note_encryption.rs +++ b/src/note_encryption.rs @@ -140,6 +140,9 @@ impl SaplingDomain { } } +pub(crate) type EncCiphertext = NoteBytesData<{ ENC_CIPHERTEXT_SIZE }>; +pub(crate) type CompactEncCiphertext = NoteBytesData<{ COMPACT_NOTE_SIZE }>; + impl Domain for SaplingDomain { type EphemeralSecretKey = EphemeralSecretKey; // It is acceptable for this to be a point rather than a byte array, because we @@ -160,9 +163,9 @@ impl Domain for SaplingDomain { type Memo = [u8; MEMO_SIZE]; type NotePlaintextBytes = NoteBytesData<{ NOTE_PLAINTEXT_SIZE }>; - type NoteCiphertextBytes = NoteBytesData<{ ENC_CIPHERTEXT_SIZE }>; + type NoteCiphertextBytes = EncCiphertext; type CompactNotePlaintextBytes = NoteBytesData<{ COMPACT_NOTE_SIZE }>; - type CompactNoteCiphertextBytes = NoteBytesData<{ COMPACT_NOTE_SIZE }>; + type CompactNoteCiphertextBytes = CompactEncCiphertext; fn derive_esk(note: &Self::Note) -> Option { note.derive_esk()