pub fn sapling_note_encryption<R: Rng>(
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 rand::rngs::SysRng;
use rand_core::UnwrapErr;
use sapling_crypto::{
keys::OutgoingViewingKey,
note_encryption::{sapling_note_encryption, Zip212Enforcement},
util::generate_random_rseed,
value::{NoteValue, ValueCommitTrapdoor, ValueCommitment},
zip32::ExtendedSpendingKey,
};
let mut rng = UnwrapErr(SysRng);
let extsk = ExtendedSpendingKey::master(&[0; 32]).unwrap();
let (_, to) = extsk.default_address();
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);