subspace_farmer::single_disk_farm::identity

Struct Identity

source
pub struct Identity { /* private fields */ }
Expand description

Identity struct is an abstraction of public & secret key related operations.

It is basically a wrapper of the keypair (which holds public & secret keys) and a context that will be used for signing.

Implementations§

source§

impl Identity

source

pub fn file_size() -> usize

Size of the identity file on disk

source

pub fn open_or_create<B: AsRef<Path>>( base_directory: B, ) -> Result<Self, IdentityError>

Opens the existing identity, or creates a new one.

source

pub fn open<B: AsRef<Path>>( base_directory: B, ) -> Result<Option<Self>, IdentityError>

Opens the existing identity, returns Ok(None) if it doesn’t exist.

source

pub fn create<B: AsRef<Path>>(base_directory: B) -> Result<Self, IdentityError>

Creates new identity, overrides identity that might already exist.

source

pub fn public_key(&self) -> &PublicKey

Returns the public key of the identity.

source

pub fn secret_key(&self) -> &SecretKey

Returns the secret key of the identity.

source

pub fn entropy(&self) -> &[u8]

Returns entropy used to generate keypair.

source

pub fn sign_reward_hash(&self, header_hash: &[u8]) -> Signature

Sign reward hash.

Methods from Deref<Target = Keypair>§

pub fn to_bytes(&self) -> [u8; 96]

Serialize Keypair to bytes.

§Returns

A byte array [u8; KEYPAIR_LENGTH] consisting of first a SecretKey serialized canonically, and next the Ristterro PublicKey

§Examples
use schnorrkel::{Keypair, KEYPAIR_LENGTH};

let keypair: Keypair = Keypair::generate();
let bytes: [u8; KEYPAIR_LENGTH] = keypair.to_bytes();
let keypair_too = Keypair::from_bytes(&bytes[..]).unwrap();
assert_eq!(&bytes[..], & keypair_too.to_bytes()[..]);

pub fn to_half_ed25519_bytes(&self) -> [u8; 96]

Serialize Keypair to bytes with Ed25519 secret key format.

§Returns

A byte array [u8; KEYPAIR_LENGTH] consisting of first a SecretKey serialized like Ed25519, and next the Ristterro PublicKey

pub fn sign<T>(&self, t: T) -> Signature
where T: SigningTranscript,

Sign a transcript with this keypair’s secret key.

Requires a SigningTranscript, normally created from a SigningContext and a message. Returns a Schnorr signature.

§Examples

Internally, we manage signature transcripts using a 128 bit secure STROBE construction based on Keccak, which itself is extremely fast and secure. You might however influence performance or security by prehashing your message, like

use schnorrkel::{Signature,Keypair};
use rand::prelude::*; // ThreadRng,thread_rng
use sha3::Shake128;
use sha3::digest::{Update};

let mut csprng: ThreadRng = thread_rng();
let keypair: Keypair = Keypair::generate_with(&mut csprng);
let message: &[u8] = b"All I want is to pet all of the dogs.";

// Create a hash digest object and feed it the message:
let prehashed = Shake128::default().chain(message);

We require a “context” string for all signatures, which should be chosen judiciously for your project. It should represent the role the signature plays in your application. If you use the context in two purposes, and the same key, then a signature for one purpose can be substituted for the other.

let ctx = signing_context(b"My Signing Context");

let sig: Signature = keypair.sign(ctx.xof(prehashed));

pub fn sign_simple(&self, ctx: &[u8], msg: &[u8]) -> Signature

Sign a message with this keypair’s secret key.

pub fn verify<T>( &self, t: T, signature: &Signature, ) -> Result<(), SignatureError>
where T: SigningTranscript,

Verify a signature by keypair’s public key on a transcript.

Requires a SigningTranscript, normally created from a SigningContext and a message, as well as the signature to be verified.

§Examples
use schnorrkel::{Keypair,Signature,signing_context};
use rand::prelude::*; // ThreadRng,thread_rng

let mut csprng: ThreadRng = thread_rng();
let keypair: Keypair = Keypair::generate_with(&mut csprng);
let message: &[u8] = b"All I want is to pet all of the dogs.";

let ctx = signing_context(b"Some context string");

let sig: Signature = keypair.sign(ctx.bytes(message));

assert!( keypair.public.verify(ctx.bytes(message), &sig).is_ok() );

pub fn verify_simple( &self, ctx: &[u8], msg: &[u8], signature: &Signature, ) -> Result<(), SignatureError>

Verify a signature by keypair’s public key on a message.

pub fn sign_doublecheck<T>(&self, t: T) -> Result<Signature, SignatureError>
where T: SigningTranscript + Clone,

Sign a message with this SecretKey, but doublecheck the result.

pub fn sign_simple_doublecheck( &self, ctx: &[u8], msg: &[u8], ) -> Result<Signature, SignatureError>

Sign a message with this SecretKey, but doublecheck the result.

pub fn vrf_create_hash<T>(&self, t: T) -> VRFInOut
where T: VRFSigningTranscript,

Evaluate the VRF on the given transcript.

pub fn dleq_proove<T>( &self, t: T, p: &VRFInOut, kusama: bool, ) -> (VRFProof, VRFProofBatchable)
where T: SigningTranscript,

Produce DLEQ proof.

We assume the VRFInOut paramater has been computed correctly by multiplying every input point by self.secret, like by using one of the vrf_create_* methods on SecretKey. If so, we produce a proof that this multiplication was done correctly.

pub fn vrf_sign<T>(&self, t: T) -> (VRFInOut, VRFProof, VRFProofBatchable)
where T: VRFSigningTranscript,

Run VRF on one single input transcript, producing the outpus and corresponding short proof.

There are schemes like Ouroboros Praos in which nodes evaluate VRFs repeatedly until they win some contest. In these case, you should probably use vrf_sign_n_check to gain access to the VRFInOut from vrf_create_hash first, and then avoid computing the proof whenever you do not win.

pub fn vrf_sign_extra<T, E>( &self, t: T, extra: E, ) -> (VRFInOut, VRFProof, VRFProofBatchable)
where T: VRFSigningTranscript, E: SigningTranscript,

Run VRF on one single input transcript and an extra message transcript, producing the outpus and corresponding short proof.

pub fn vrf_sign_after_check<T, F>( &self, t: T, check: F, ) -> Option<(VRFInOut, VRFProof, VRFProofBatchable)>
where T: VRFSigningTranscript, F: FnMut(&VRFInOut) -> bool,

Run VRF on one single input transcript, producing the outpus and corresponding short proof only if the result first passes some check.

There are schemes like Ouroboros Praos in which nodes evaluate VRFs repeatedly until they win some contest. In these case, you might use this function to short circuit computing the full proof.

pub fn vrf_sign_extra_after_check<T, E, F>( &self, t: T, check: F, ) -> Option<(VRFInOut, VRFProof, VRFProofBatchable)>
where T: VRFSigningTranscript, E: SigningTranscript, F: FnMut(&VRFInOut) -> Option<E>,

Run VRF on one single input transcript, producing the outpus and corresponding short proof only if the result first passes some check, which itself returns an extra message transcript.

pub fn vrfs_sign<T, I>( &self, ts: I, ) -> (Box<[VRFInOut]>, VRFProof, VRFProofBatchable)
where T: VRFSigningTranscript, I: IntoIterator<Item = T>,

Run VRF on several input transcripts, producing their outputs and a common short proof.

We merge the VRF outputs using variable time arithmetic, so if even the hash of the message being signed is sensitive then you might reimplement some constant time variant.

pub fn vrfs_sign_extra<T, E, I>( &self, ts: I, extra: E, ) -> (Box<[VRFInOut]>, VRFProof, VRFProofBatchable)
where T: VRFSigningTranscript, E: SigningTranscript, I: IntoIterator<Item = T>,

Run VRF on several input transcripts and an extra message transcript, producing their outputs and a common short proof.

We merge the VRF outputs using variable time arithmetic, so if even the hash of the message being signed is sensitive then you might reimplement some constant time variant.

pub fn hard_derive_mini_secret_key<B>( &self, cc: Option<ChainCode>, i: B, ) -> (MiniSecretKey, ChainCode)
where B: AsRef<[u8]>,

Vaguely BIP32-like “hard” derivation of a MiniSecretKey from a SecretKey

We do not envision any “good reasons” why these “hard” derivations should ever be used after the soft Derivation trait. We similarly do not believe hard derivations make any sense for ChainCodes or ExtendedKeys types. Yet, some existing BIP32 workflows might do these things, due to BIP32’s de facto standardization and poor design. In consequence, we provide this method to do “hard” derivations in a way that should work with all BIP32 workflows and any permissible mutations of SecretKey. This means only that we hash the SecretKey’s scalar, but not its nonce because the secret key remains valid if the nonce is changed.

pub fn derive_secret_key<T>( &self, t: T, cc: ChainCode, ) -> (SecretKey, ChainCode)
where T: SigningTranscript,

Derive a secret key and new chain code from a key pair and chain code.

We expect the trait methods of Keypair as Derivation to be more useful since signing anything requires the public key too.

pub fn issue_adaptor_cert<T>( &self, t: T, seed_public_key: &PublicKey, ) -> AdaptorCertSecret
where T: SigningTranscript,

Issue an Adaptor implicit certificate

Aside from the issuing Keypair supplied as self, you provide both (1) a SigningTranscript called t that incorporates both the context and the certificate requester’s identity, and (2) the seed_public_key supplied by the certificate recipient in their certificate request. We return an AdaptorCertSecret which the issuer sent to the certificate requester, ans from which the certificate requester derives their certified key pair.

pub fn issue_self_adaptor_cert<T>(&self, t: T) -> (AdaptorCertPublic, SecretKey)
where T: SigningTranscript + Clone,

Issue an Adaptor Implicit Certificate for yourself

We can issue an implicit certificate to ourselves if we merely want to certify an associated public key. We should prefer this option over “hierarchical deterministic” key derivation because compromising the resulting secret key does not compromise the issuer’s secret key.

In this case, we avoid the entire interactive protocol described by issue_adaptor_cert and accept_adaptor_cert by hiding it an all management of the ephemeral Keypair inside this function.

Aside from the issuing secret key supplied as self, you provide only a digest h that incorporates any context and metadata pertaining to the issued key.

pub fn musig<'k, T>(&'k self, t: T) -> MuSig<T, CommitStage<&'k Keypair>>
where T: SigningTranscript + Clone,

👎Deprecated since 0.11.0: This module will be replaced in the future

Initialize a multi-signature aka cosignature protocol run.

We borrow the keypair here to discurage keeping too many copies of the private key, but the MuSig::new method can create an owned version, or use Rc or Arc.

Trait Implementations§

source§

impl Clone for Identity

source§

fn clone(&self) -> Identity

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Identity

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Deref for Identity

source§

type Target = Keypair

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<T> Conv for T

§

fn conv<T>(self) -> T
where Self: Into<T>,

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

impl<T> FmtForward for T

§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

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

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

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

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

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

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

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

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

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

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

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

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

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

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

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

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pipe for T
where T: ?Sized,

§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

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

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

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

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

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

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

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

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

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

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

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

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

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

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

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

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

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

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
§

impl<T> Tap for T

§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

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

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

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

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

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

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

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

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

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

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

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

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

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

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

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

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

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

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

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

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

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

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

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

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

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

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> TryConv for T

§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> JsonSchemaMaybe for T

§

impl<T> MaybeSend for T
where T: Send,