mirror of https://github.com/zcash/orchard.git
Derive internal spending key.
This commit is contained in:
parent
dc7c699a4a
commit
2412e83400
19
src/keys.rs
19
src/keys.rs
|
@ -38,6 +38,14 @@ const ZIP32_PURPOSE: u32 = 32;
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub struct SpendingKey([u8; 32]);
|
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 {
|
impl ConstantTimeEq for SpendingKey {
|
||||||
fn ct_eq(&self, other: &Self) -> Choice {
|
fn ct_eq(&self, other: &Self) -> Choice {
|
||||||
self.to_bytes().ct_eq(other.to_bytes())
|
self.to_bytes().ct_eq(other.to_bytes())
|
||||||
|
@ -96,6 +104,11 @@ impl SpendingKey {
|
||||||
];
|
];
|
||||||
ExtendedSpendingKey::from_path(seed, path).map(|esk| esk.sk())
|
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.
|
/// 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 {
|
impl CommitIvkRandomness {
|
||||||
pub(crate) fn inner(&self) -> pallas::Scalar {
|
pub(crate) fn inner(&self) -> pallas::Scalar {
|
||||||
self.0
|
self.0
|
||||||
|
|
Loading…
Reference in New Issue