diff --git a/src/keys.rs b/src/keys.rs index ad218b15..5572024c 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -38,6 +38,14 @@ const ZIP32_PURPOSE: u32 = 32; #[derive(Debug, Copy, Clone)] pub struct SpendingKey([u8; 32]); +/// An internal spending key, derived from a spending key. +/// +/// Specified in [ZIP32][orchardinternalspendingkey]. +/// +/// [orchardinternalspendingkey]: https://zips.z.cash/zip-0032#orchard-internal-key-derivation +#[derive(Debug, Copy, Clone)] +pub struct InternalSpendingKey([u8; 32]); + impl ConstantTimeEq for SpendingKey { fn ct_eq(&self, other: &Self) -> Choice { self.to_bytes().ct_eq(other.to_bytes()) @@ -96,6 +104,11 @@ impl SpendingKey { ]; ExtendedSpendingKey::from_path(seed, path).map(|esk| esk.sk()) } + + /// Derives an internal spending key from a spending key, + pub fn derive_internal(&self) -> InternalSpendingKey { + InternalSpendingKey(self.0) + } } /// A spend authorizing key, used to create spend authorization signatures. @@ -256,6 +269,12 @@ impl From<&SpendingKey> for CommitIvkRandomness { } } +impl From<&InternalSpendingKey> for CommitIvkRandomness { + fn from(sk: &InternalSpendingKey) -> Self { + CommitIvkRandomness(to_scalar(PrfExpand::OrchardRivkInternal.expand(&sk.0))) + } +} + impl CommitIvkRandomness { pub(crate) fn inner(&self) -> pallas::Scalar { self.0