2021-01-20 10:54:00 -08:00
|
|
|
//! Key structures for Orchard.
|
|
|
|
|
2021-01-21 04:16:50 -08:00
|
|
|
use crate::address::Address;
|
2021-01-20 10:54:00 -08:00
|
|
|
|
|
|
|
/// A spending key, from which all key material is derived.
|
|
|
|
///
|
|
|
|
/// TODO: In Sapling we never actually used this, instead deriving everything via ZIP 32,
|
|
|
|
/// so that we could maintain Bitcoin-like HD keys with properties like non-hardened
|
|
|
|
/// derivation. If we decide that we don't actually require non-hardened derivation, then
|
|
|
|
/// we could greatly simplify the HD structure and use this struct directly.
|
|
|
|
#[derive(Debug)]
|
2021-01-21 04:16:50 -08:00
|
|
|
pub struct SpendingKey;
|
2021-01-20 10:54:00 -08:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
2021-01-21 04:16:50 -08:00
|
|
|
pub(crate) struct SpendAuthorizingKey;
|
2021-01-20 10:54:00 -08:00
|
|
|
|
2021-01-21 04:16:50 -08:00
|
|
|
impl From<&SpendingKey> for SpendAuthorizingKey {
|
|
|
|
fn from(_: &SpendingKey) -> Self {
|
2021-01-20 10:54:00 -08:00
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// TODO: This is its protocol spec name for Sapling, but I'd prefer a different name.
|
|
|
|
#[derive(Debug)]
|
2021-01-21 04:16:50 -08:00
|
|
|
pub(crate) struct AuthorizingKey;
|
2021-01-20 10:54:00 -08:00
|
|
|
|
2021-01-21 04:16:50 -08:00
|
|
|
impl From<&SpendAuthorizingKey> for AuthorizingKey {
|
|
|
|
fn from(_: &SpendAuthorizingKey) -> Self {
|
2021-01-20 10:54:00 -08:00
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2021-01-21 04:16:50 -08:00
|
|
|
pub(crate) struct NullifierDerivingKey;
|
2021-01-20 10:54:00 -08:00
|
|
|
|
2021-01-21 04:16:50 -08:00
|
|
|
impl From<&SpendingKey> for NullifierDerivingKey {
|
|
|
|
fn from(_: &SpendingKey) -> Self {
|
2021-01-20 10:54:00 -08:00
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A key that provides the capability to view incoming and outgoing transactions.
|
|
|
|
///
|
2021-02-03 06:19:29 -08:00
|
|
|
/// This key is useful anywhere you need to maintain accurate balance, but do not want the
|
|
|
|
/// ability to spend funds (such as a view-only wallet).
|
2021-01-20 10:54:00 -08:00
|
|
|
///
|
|
|
|
/// TODO: Should we just define the FVK to include extended stuff like the diversifier key?
|
|
|
|
#[derive(Debug)]
|
2021-01-21 04:16:50 -08:00
|
|
|
pub struct FullViewingKey {
|
|
|
|
ak: AuthorizingKey,
|
|
|
|
nk: NullifierDerivingKey,
|
2021-02-08 07:01:34 -08:00
|
|
|
rivk: (),
|
2021-01-20 10:54:00 -08:00
|
|
|
}
|
|
|
|
|
2021-01-21 04:16:50 -08:00
|
|
|
impl From<&SpendingKey> for FullViewingKey {
|
|
|
|
fn from(_: &SpendingKey) -> Self {
|
2021-01-20 10:54:00 -08:00
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-21 04:16:50 -08:00
|
|
|
impl FullViewingKey {
|
2021-01-20 10:54:00 -08:00
|
|
|
/// Returns the payment address for this key corresponding to the given diversifier.
|
2021-01-21 04:16:50 -08:00
|
|
|
pub fn address(&self, d: Diversifier) -> Address {
|
2021-01-20 10:54:00 -08:00
|
|
|
IncomingViewingKey::from(self).address(d)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A diversifier that can be used to derive a specific [`Address`] from a
|
|
|
|
/// [`FullViewingKey`] or [`IncomingViewingKey`].
|
|
|
|
#[derive(Debug)]
|
2021-02-03 06:16:58 -08:00
|
|
|
pub struct Diversifier([u8; 11]);
|
2021-01-20 10:54:00 -08:00
|
|
|
|
|
|
|
/// A key that provides the capability to detect and decrypt incoming notes from the block
|
|
|
|
/// chain, without being able to spend the notes or detect when they are spent.
|
|
|
|
///
|
|
|
|
/// This key is useful in situations where you only need the capability to detect inbound
|
|
|
|
/// payments, such as merchant terminals.
|
|
|
|
///
|
2021-02-08 07:01:34 -08:00
|
|
|
/// This key is not suitable for use on its own in a wallet, as it cannot maintain
|
|
|
|
/// accurate balance. You should use a [`FullViewingKey`] instead.
|
2021-01-20 10:54:00 -08:00
|
|
|
#[derive(Debug)]
|
2021-01-21 04:16:50 -08:00
|
|
|
pub struct IncomingViewingKey;
|
2021-01-20 10:54:00 -08:00
|
|
|
|
2021-01-21 04:16:50 -08:00
|
|
|
impl From<&FullViewingKey> for IncomingViewingKey {
|
|
|
|
fn from(_: &FullViewingKey) -> Self {
|
2021-01-20 10:54:00 -08:00
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-21 04:16:50 -08:00
|
|
|
impl IncomingViewingKey {
|
2021-01-20 10:54:00 -08:00
|
|
|
/// Returns the payment address for this key corresponding to the given diversifier.
|
2021-01-21 04:16:50 -08:00
|
|
|
pub fn address(&self, _: Diversifier) -> Address {
|
2021-01-20 10:54:00 -08:00
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|
2021-02-08 07:01:34 -08:00
|
|
|
|
|
|
|
/// A key that provides the capability to recover outgoing transaction information from
|
|
|
|
/// the block chain.
|
|
|
|
///
|
|
|
|
/// This key is not suitable for use on its own in a wallet, as it cannot maintain
|
|
|
|
/// accurate balance. You should use a [`FullViewingKey`] instead.
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct OutgoingViewingKey;
|
|
|
|
|
|
|
|
impl From<&FullViewingKey> for OutgoingViewingKey {
|
|
|
|
fn from(_: &FullViewingKey) -> Self {
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|