Struct sn_dbc::Dbc

source · []
pub struct Dbc {
    pub content: DbcContent,
    pub transaction: RingCtTransaction,
    pub spent_proofs: BTreeSet<SpentProof>,
}
Expand description

Represents a Digital Bearer Certificate (Dbc).

A Dbc may be owned or bearer.

An owned Dbc is like a check. Only the recipient can spend it. A bearer Dbc is like cash. Anyone in possession of it can spend it.

An owned Dbc includes a PublicKey representing the Owner. A bearer Dbc includes a SecretKey representing the Owner.

An Owner consists of either a SecretKey (with implicit PublicKey) or a PublicKey.

The included Owner is called an Owner Base. The public key can be given out to multiple parties and thus multiple Dbc can share the same Owner Base.

The Spentbook never sees the Owner Base. Instead, when a transaction Output is created for a given Owner Base, a random derivation index is generated and used to derive a one-time-use Owner Once.

The Owner Once is used for a single transaction only and must be unique within the transaction as well as globally for the output DBC’s to be spendable.

Separate methods are available for Owned and Bearer DBCs.

To spend or work with an Owned Dbc, wallet software must obtain the corresponding SecretKey from the user, and then call an API function that accepts a SecretKey for the Owner Base.

To spend or work with a Bearer Dbc, wallet software can either:

  1. use the bearer API methods that do not require a SecretKey, eg: dbc.amount_secrets_bearer()

– or –

  1. obtain the Owner Base SecretKey from the Dbc and then call the Owner API methods that require a SecretKey. eg: dbc.amount_secrets(&dbc.dbc.owner_base().secret_key()?)

Sometimes the latter method can be better when working with mixed types of Dbcs. A useful pattern is to check up-front if the Dbc is bearer or not and obtain the SecretKey from the Dbc itself (bearer) or from the user (owned). Subsequent code is then the same for both types.

Fields

content: DbcContenttransaction: RingCtTransactionspent_proofs: BTreeSet<SpentProof>

Implementations

returns derived one-time-use owner using SecretKey supplied by caller. will return an error if the supplied SecretKey does not match the Dbc owner’s public key.

returns derived one-time-use owner using SecretKey stored in bearer Dbc. will return an error if the SecretKey is not available. (not bearer)

returns derivation index used to derive one-time-use keypair from owner base

returns derivation index used to derive one-time-use keypair from owner base will return an error if the SecretKey is not available. (not bearer)

returns true if owner base includes a SecretKey.

If the SecretKey is present, this Dbc can be spent by anyone in possession of it, making it a true “Bearer” instrument.

If the SecretKey is not present, then only the person(s) holding the SecretKey matching the PublicKey can spend it.

decypts and returns the AmountSecrets

decypts and returns the AmountSecrets will return an error if the SecretKey is not available. (not bearer)

returns KeyImage for the owner’s derived public key This is useful for checking if a Dbc has been spent.

returns KeyImage for the owner’s derived public key This is useful for checking if a Dbc has been spent. will return an error if the SecretKey is not available. (not bearer)

returns a TrueInput that represents this Dbc for use as a transaction input.

returns a TrueInput that represents this Dbc for use as a transaction input. will return an error if the SecretKey is not available. (not bearer)

Generate hash of this DBC

Verifies that this Dbc is valid.

A Dbc recipient should call this immediately upon receipt.

important: this does not check if the Dbc has been spent. For that, one must query the SpentBook.

Note that the spentbook cannot perform this check. Only the Dbc recipient (private key holder) can.

see TransactionVerifier::verify() for a description of verifier requirements.

see comments for Dbc::verify_amount_matches_commitment() for a description of how to handle Error::AmountCommitmentsDoNotMatch

bearer version of verify() will return an error if the SecretKey is not available. (not bearer)

Convert this instance from owned to bearer by supplying the secret key for the corresponding public key.

Will return an error if this instance is already bearer or if the supplied secret key doesn’t match the public key.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts self into T using Into<T>. Read more

Causes self to use its Binary implementation when Debug-formatted.

Causes self to use its Display implementation when Debug-formatted. Read more

Causes self to use its LowerExp implementation when Debug-formatted. Read more

Causes self to use its LowerHex implementation when Debug-formatted. Read more

Causes self to use its Octal implementation when Debug-formatted.

Causes self to use its Pointer implementation when Debug-formatted. Read more

Causes self to use its UpperExp implementation when Debug-formatted. Read more

Causes self to use its UpperHex implementation when Debug-formatted. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Pipes by value. This is generally the method you want to use. Read more

Borrows self and passes that borrow into the pipe function. Read more

Mutably borrows self and passes that borrow into the pipe function. Read more

Borrows self, then passes self.borrow() into the pipe function. Read more

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more

Borrows self, then passes self.as_ref() into the pipe function.

Mutably borrows self, then passes self.as_mut() into the pipe function. Read more

Borrows self, then passes self.deref() into the pipe function.

Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more

Should always be Self

Immutable access to a value. Read more

Mutable access to a value. Read more

Immutable access to the Borrow<B> of a value. Read more

Mutable access to the BorrowMut<B> of a value. Read more

Immutable access to the AsRef<R> view of a value. Read more

Mutable access to the AsMut<R> view of a value. Read more

Immutable access to the Deref::Target of a value. Read more

Mutable access to the Deref::Target of a value. Read more

Calls .tap() only in debug builds, and is erased in release builds.

Calls .tap_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

Attempts to convert self into T using TryInto<T>. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.