Change return type of ScanningKey::to_sapling_keys to an associated type.

This commit is contained in:
Kris Nuttycombe 2022-07-28 11:02:15 -06:00
parent 73314dc682
commit 8a6e979cb9
1 changed files with 12 additions and 7 deletions

View File

@ -38,12 +38,14 @@ pub trait ScanningKey {
/// The type of key that is used to decrypt Sapling outputs; /// The type of key that is used to decrypt Sapling outputs;
type SaplingNk; type SaplingNk;
type SaplingKeys: IntoIterator<Item = (SaplingIvk, Self::SaplingNk)>;
/// The type of nullifier extracted when a note is successfully /// The type of nullifier extracted when a note is successfully
/// obtained by trial decryption. /// obtained by trial decryption.
type Nf; type Nf;
/// Obtain the underlying Sapling incoming viewing key(s) for this scanning key. /// Obtain the underlying Sapling incoming viewing key(s) for this scanning key.
fn to_sapling_keys(&self) -> Vec<(SaplingIvk, Self::SaplingNk)>; fn to_sapling_keys(&self) -> Self::SaplingKeys;
/// Produces the nullifier for the specified note and witness, if possible. /// Produces the nullifier for the specified note and witness, if possible.
/// ///
@ -59,10 +61,11 @@ pub trait ScanningKey {
impl ScanningKey for DiversifiableFullViewingKey { impl ScanningKey for DiversifiableFullViewingKey {
type SaplingNk = NullifierDerivingKey; type SaplingNk = NullifierDerivingKey;
type SaplingKeys = [(SaplingIvk, Self::SaplingNk); 2];
type Nf = sapling::Nullifier; type Nf = sapling::Nullifier;
fn to_sapling_keys(&self) -> Vec<(SaplingIvk, Self::SaplingNk)> { fn to_sapling_keys(&self) -> Self::SaplingKeys {
vec![ [
(self.to_ivk(Scope::External), self.to_nk(Scope::External)), (self.to_ivk(Scope::External), self.to_nk(Scope::External)),
(self.to_ivk(Scope::Internal), self.to_nk(Scope::Internal)), (self.to_ivk(Scope::Internal), self.to_nk(Scope::Internal)),
] ]
@ -83,10 +86,11 @@ impl ScanningKey for DiversifiableFullViewingKey {
/// [`ExtendedFullViewingKey`]: zcash_primitives::zip32::ExtendedFullViewingKey /// [`ExtendedFullViewingKey`]: zcash_primitives::zip32::ExtendedFullViewingKey
impl ScanningKey for ExtendedFullViewingKey { impl ScanningKey for ExtendedFullViewingKey {
type SaplingNk = NullifierDerivingKey; type SaplingNk = NullifierDerivingKey;
type SaplingKeys = [(SaplingIvk, Self::SaplingNk); 1];
type Nf = sapling::Nullifier; type Nf = sapling::Nullifier;
fn to_sapling_keys(&self) -> Vec<(SaplingIvk, Self::SaplingNk)> { fn to_sapling_keys(&self) -> Self::SaplingKeys {
vec![(self.fvk.vk.ivk(), self.fvk.vk.nk)] [(self.fvk.vk.ivk(), self.fvk.vk.nk)]
} }
fn sapling_nf( fn sapling_nf(
@ -104,10 +108,11 @@ impl ScanningKey for ExtendedFullViewingKey {
/// [`SaplingIvk`]: zcash_primitives::sapling::SaplingIvk /// [`SaplingIvk`]: zcash_primitives::sapling::SaplingIvk
impl ScanningKey for SaplingIvk { impl ScanningKey for SaplingIvk {
type SaplingNk = (); type SaplingNk = ();
type SaplingKeys = [(SaplingIvk, Self::SaplingNk); 1];
type Nf = (); type Nf = ();
fn to_sapling_keys(&self) -> Vec<(SaplingIvk, Self::SaplingNk)> { fn to_sapling_keys(&self) -> Self::SaplingKeys {
vec![(self.clone(), ())] [(self.clone(), ())]
} }
fn sapling_nf(_key: &Self::SaplingNk, _note: &Note, _witness: &IncrementalWitness<Node>) {} fn sapling_nf(_key: &Self::SaplingNk, _note: &Note, _witness: &IncrementalWitness<Node>) {}