[][src]Struct zcash_primitives::note_encryption::SaplingNoteEncryption

pub struct SaplingNoteEncryption { /* fields omitted */ }

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]

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]

Generates outCiphertext for this note.

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T> Same<T> for T

type Output = T

Should always be Self