Struct sn_transfers::CashNote
source · pub struct CashNote {
pub id: UniquePubkey,
pub src_tx: Transaction,
pub signed_spends: BTreeSet<SignedSpend>,
pub main_pubkey: MainPubkey,
pub derivation_index: DerivationIndex,
}
Expand description
Types used in the public API Represents a CashNote (CashNote).
A CashNote is like a check. Only the recipient can spend it.
A CashNote has a MainPubkey representing the recipient of the CashNote.
An MainPubkey consists of a PublicKey. The user who receives payments to this MainPubkey, will be holding a MainSecretKey - a secret key, which corresponds to the MainPubkey.
The MainPubkey can be given out to multiple parties and multiple CashNotes can share the same MainPubkey.
The spentbook nodes never sees the MainPubkey. Instead, when a transaction output cashnote is created for a given MainPubkey, a random derivation index is generated and used to derive a UniquePubkey, which will be used for this new cashnote.
The UniquePubkey is a unique identifier of a CashNote. So there can only ever be one CashNote with that id, previously, now and forever. The UniquePubkey consists of a PublicKey. To unlock the tokens of the CashNote, the corresponding DerivedSecretKey (consists of a SecretKey) must be used. It is derived from the MainSecretKey, in the same way as the UniquePubkey was derived from the MainPubkey to get the UniquePubkey.
So, there are two important pairs to conceptually be aware of. The MainSecretKey and MainPubkey is a unique pair of a user, where the MainSecretKey is held secret, and the MainPubkey is given to all and anyone who wishes to send tokens to you. A sender of tokens will derive the UniquePubkey from the MainPubkey, which will identify the CashNote that holds the tokens going to the recipient. The sender does this using a derivation index. The recipient of the tokens, will use the same derivation index, to derive the DerivedSecretKey from the MainSecretKey. The DerivedSecretKey and UniquePubkey pair is the second important pair. For an outsider, there is no way to associate either the DerivedSecretKey or the UniquePubkey to the MainPubkey (or for that matter to the MainSecretKey, if they were ever to see it, which they shouldn’t of course). Only by having the derivation index, which is only known to sender and recipient, can such a connection be made.
To spend or work with a CashNote, wallet software must obtain the corresponding
MainSecretKey from the user, and then call an API function that accepts a MainSecretKey,
eg: cashnote.derivation_index(&main_key)
Fields§
§id: UniquePubkey
The unique pulbic key of this CashNote. It is unique, and there can never be another CashNote with the same pulbic key. It used in SignedSpends.
src_tx: Transaction
The transaction where this CashNote was created.
signed_spends: BTreeSet<SignedSpend>
The transaction’s input’s SignedSpends
main_pubkey: MainPubkey
This is the MainPubkey of the recipient of this CashNote.
derivation_index: DerivationIndex
This indicates which index to use when deriving the UniquePubkey of the CashNote, from the MainPubkey.
Implementations§
source§impl CashNote
impl CashNote
sourcepub fn unique_pubkey(&self) -> UniquePubkey
pub fn unique_pubkey(&self) -> UniquePubkey
Return the id of this CashNote.
pub fn main_pubkey(&self) -> &MainPubkey
sourcepub fn derived_key(&self, main_key: &MainSecretKey) -> Result<DerivedSecretKey>
pub fn derived_key(&self, main_key: &MainSecretKey) -> Result<DerivedSecretKey>
Return DerivedSecretKey using MainSecretKey supplied by caller. Will return an error if the supplied MainSecretKey does not match the CashNote MainPubkey.
sourcepub fn derived_pubkey(&self, main_pubkey: &MainPubkey) -> Result<UniquePubkey>
pub fn derived_pubkey(&self, main_pubkey: &MainPubkey) -> Result<UniquePubkey>
Return UniquePubkey using MainPubkey supplied by caller. Will return an error if the supplied MainPubkey does not match the CashNote MainPubkey.
sourcepub fn derivation_index(&self) -> DerivationIndex
pub fn derivation_index(&self) -> DerivationIndex
Return the derivation index that was used to derive UniquePubkey and corresponding DerivedSecretKey of a CashNote.
sourcepub fn reason(&self) -> Hash
pub fn reason(&self) -> Hash
Return the reason why this CashNote was spent. Will be the default Hash (empty) if reason is none.
sourcepub fn value(&self) -> Result<NanoTokens>
pub fn value(&self) -> Result<NanoTokens>
Return the value in NanoTokens for this CashNote.
sourcepub fn verify(&self, main_key: &MainSecretKey) -> Result<(), TransferError>
pub fn verify(&self, main_key: &MainSecretKey) -> Result<(), TransferError>
Verifies that this CashNote is valid.
A CashNote recipient should call this immediately upon receipt.
important: this will verify there is a matching transaction provided for each SignedSpend, although this does not check if the CashNote has been spent. For that, one must query the spentbook nodes.
Note that the spentbook nodes cannot perform this check. Only the CashNote recipient (private key holder) can.
see TransactionVerifier::verify() for a description of verifier requirements.
sourcepub fn from_hex(hex: &str) -> Result<Self, TransferError>
pub fn from_hex(hex: &str) -> Result<Self, TransferError>
Deserializes a CashNote
represented as a hex string to a CashNote
.
sourcepub fn to_hex(&self) -> Result<String, TransferError>
pub fn to_hex(&self) -> Result<String, TransferError>
Serialize this CashNote
instance to a hex string.
Trait Implementations§
source§impl<'de> Deserialize<'de> for CashNote
impl<'de> Deserialize<'de> for CashNote
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl PartialEq for CashNote
impl PartialEq for CashNote
impl Eq for CashNote
impl StructuralPartialEq for CashNote
Auto Trait Implementations§
impl Freeze for CashNote
impl RefUnwindSafe for CashNote
impl Send for CashNote
impl Sync for CashNote
impl Unpin for CashNote
impl UnwindSafe for CashNote
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<T> FmtForward for T
impl<T> FmtForward for T
source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> R
source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> Tap for T
impl<T> Tap for T
source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moresource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moresource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moresource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moresource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moresource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moresource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.