Struct zcash_note_encryption::NoteEncryption[][src]

pub struct NoteEncryption<D: Domain> { /* fields omitted */ }
Expand description

A struct containing context required for encrypting Sapling and Orchard notes.

This struct provides a safe API for encrypting Sapling and Orchard 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.19 of the Zcash Protocol Specification NB: the example code is only covering the post-Canopy case.

Examples

extern crate ff;
extern crate rand_core;
extern crate zcash_primitives;

use ff::Field;
use rand_core::OsRng;
use zcash_primitives::{
    consensus::{TEST_NETWORK, TestNetwork, NetworkUpgrade, Parameters},
    memo::MemoBytes,
    sapling::{
        keys::{OutgoingViewingKey, prf_expand},
        note_encryption::sapling_note_encryption,
        util::generate_random_rseed,
        Diversifier, PaymentAddress, Rseed, ValueCommitment
    },
};

let mut rng = OsRng;

let diversifier = Diversifier([0; 11]);
let pk_d = diversifier.g_d().unwrap();
let to = PaymentAddress::from_parts(diversifier, pk_d).unwrap();
let ovk = Some(OutgoingViewingKey([0; 32]));

let value = 1000;
let rcv = jubjub::Fr::random(&mut rng);
let cv = ValueCommitment {
    value,
    randomness: rcv.clone(),
};
let height = TEST_NETWORK.activation_height(NetworkUpgrade::Canopy).unwrap();
let rseed = generate_random_rseed(&TEST_NETWORK, height, &mut rng);
let note = to.create_note(value, rseed).unwrap();
let cmu = note.cmu();

let mut enc = sapling_note_encryption::<_, TestNetwork>(ovk, note, to, MemoBytes::empty(), &mut rng);
let encCiphertext = enc.encrypt_note_plaintext();
let outCiphertext = enc.encrypt_outgoing_plaintext(&cv.commitment().into(), &cmu, &mut rng);

Implementations

Construct a new note encryption context for the specified note, recipient, and memo.

For use only with Sapling. This method is preserved in order that test code be able to generate pre-ZIP-212 ciphertexts so that tests can continue to cover pre-ZIP-212 transaction decryption.

Exposes the ephemeral secret key being used to encrypt this note.

Exposes the encoding of the ephemeral public key being used to encrypt this note.

Generates encCiphertext for this note.

Generates outCiphertext for this note.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts self into T using Into<T>. Read more

Causes self to use its Binary implementation when Debug-formatted.

Causes self to use its Display implementation when Debug-formatted. Read more

Causes self to use its LowerExp implementation when Debug-formatted. Read more

Causes self to use its LowerHex implementation when Debug-formatted. Read more

Causes self to use its Octal implementation when Debug-formatted.

Causes self to use its Pointer implementation when Debug-formatted. Read more

Causes self to use its UpperExp implementation when Debug-formatted. Read more

Causes self to use its UpperHex implementation when Debug-formatted. Read more

Performs the conversion.

Performs the conversion.

Pipes by value. This is generally the method you want to use. Read more

Borrows self and passes that borrow into the pipe function. Read more

Mutably borrows self and passes that borrow into the pipe function. Read more

Borrows self, then passes self.borrow() into the pipe function. Read more

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more

Borrows self, then passes self.as_ref() into the pipe function.

Mutably borrows self, then passes self.as_mut() into the pipe function. Read more

Borrows self, then passes self.deref() into the pipe function.

Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more

Immutable access to a value. Read more

Mutable access to a value. Read more

Immutable access to the Borrow<B> of a value. Read more

Mutable access to the BorrowMut<B> of a value. Read more

Immutable access to the AsRef<R> view of a value. Read more

Mutable access to the AsMut<R> view of a value. Read more

Immutable access to the Deref::Target of a value. Read more

Mutable access to the Deref::Target of a value. Read more

Calls .tap() only in debug builds, and is erased in release builds.

Calls .tap_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more

Attempts to convert self into T using TryInto<T>. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.