[−][src]Struct zcash_primitives::note_encryption::SaplingNoteEncryption
An API for encrypting Sapling notes.
This struct provides a safe API for encrypting Sapling notes. In particular, it enforces that fresh ephemeral keys are used for every note, and that the ciphertexts are consistent with each other.
Implements section 4.17.1 of the Zcash Protocol Specification.
Examples
extern crate ff; extern crate pairing; extern crate rand_core; extern crate zcash_primitives; use ff::Field; use pairing::bls12_381::Bls12; use rand_core::OsRng; use zcash_primitives::{ jubjub::fs::Fs, keys::OutgoingViewingKey, note_encryption::{Memo, SaplingNoteEncryption}, primitives::{Diversifier, PaymentAddress, ValueCommitment}, JUBJUB, }; let mut rng = OsRng; let diversifier = Diversifier([0; 11]); let pk_d = diversifier.g_d::<Bls12>(&JUBJUB).unwrap(); let to = PaymentAddress::from_parts(diversifier, pk_d).unwrap(); let ovk = OutgoingViewingKey([0; 32]); let value = 1000; let rcv = Fs::random(&mut rng); let cv = ValueCommitment::<Bls12> { value, randomness: rcv.clone(), }; let note = to.create_note(value, rcv, &JUBJUB).unwrap(); let cmu = note.cm(&JUBJUB); let enc = SaplingNoteEncryption::new(ovk, note, to, Memo::default(), &mut rng); let encCiphertext = enc.encrypt_note_plaintext(); let outCiphertext = enc.encrypt_outgoing_plaintext(&cv.cm(&JUBJUB).into(), &cmu);
Methods
impl SaplingNoteEncryption
[src]
pub fn new<R: RngCore + CryptoRng>(
ovk: OutgoingViewingKey,
note: Note<Bls12>,
to: PaymentAddress<Bls12>,
memo: Memo,
rng: &mut R
) -> SaplingNoteEncryption
[src]
ovk: OutgoingViewingKey,
note: Note<Bls12>,
to: PaymentAddress<Bls12>,
memo: Memo,
rng: &mut R
) -> SaplingNoteEncryption
Creates a new encryption context for the given note.
pub fn esk(&self) -> &Fs
[src]
Exposes the ephemeral secret key being used to encrypt this note.
pub fn epk(&self) -> &Point<Bls12, PrimeOrder>
[src]
Exposes the ephemeral public key being used to encrypt this note.
pub fn encrypt_note_plaintext(&self) -> [u8; 580]
[src]
Generates encCiphertext
for this note.
pub fn encrypt_outgoing_plaintext(
&self,
cv: &Point<Bls12, Unknown>,
cmu: &Fr
) -> [u8; 80]
[src]
&self,
cv: &Point<Bls12, Unknown>,
cmu: &Fr
) -> [u8; 80]
Generates outCiphertext
for this note.
Auto Trait Implementations
impl Send for SaplingNoteEncryption
impl Sync for SaplingNoteEncryption
impl Unpin for SaplingNoteEncryption
impl UnwindSafe for SaplingNoteEncryption
impl RefUnwindSafe for SaplingNoteEncryption
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,
fn vzip(self) -> V
impl<T> Same<T> for T
type Output = T
Should always be Self