Derive internal spending key.

This commit is contained in:
therealyingtong 2022-01-06 23:10:59 +08:00
parent dc7c699a4a
commit 2412e83400
1 changed files with 19 additions and 0 deletions

View File

@ -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