pub fn sapling_note_encryption<R: RngCore>(
ovk: Option<OutgoingViewingKey>,
note: Note,
memo: [u8; 512],
rng: &mut R,
) -> NoteEncryption<SaplingDomain>Expand description
Creates a new encryption context for the given note.
Setting ovk to None represents the ovk = ⊥ case, where the note cannot be
recovered by the sender.
NB: the example code here only covers the post-Canopy case.
§Examples
use ff::Field;
use rand_core::OsRng;
use sapling_crypto::{
keys::OutgoingViewingKey,
note_encryption::{sapling_note_encryption, Zip212Enforcement},
util::generate_random_rseed,
value::{NoteValue, ValueCommitTrapdoor, ValueCommitment},
Diversifier, PaymentAddress, Rseed, SaplingIvk,
};
let mut rng = OsRng;
let ivk = SaplingIvk(jubjub::Scalar::random(&mut rng));
let diversifier = Diversifier([0; 11]);
let to = ivk.to_payment_address(diversifier).unwrap();
let ovk = Some(OutgoingViewingKey([0; 32]));
let value = NoteValue::from_raw(1000);
let rcv = ValueCommitTrapdoor::random(&mut rng);
let cv = ValueCommitment::derive(value, rcv);
let rseed = generate_random_rseed(
Zip212Enforcement::GracePeriod,
&mut rng,
);
let note = to.create_note(value, rseed);
let cmu = note.cmu();
let mut enc = sapling_note_encryption(ovk, note, [0x37; 512], &mut rng);
let encCiphertext = enc.encrypt_note_plaintext();
let outCiphertext = enc.encrypt_outgoing_plaintext(&cv, &cmu, &mut rng);