Struct Key

Source
pub struct Key { /* private fields */ }
Expand description

| An encapsulated private key. |

Implementations§

Source§

impl Key

Source

pub fn set<T>(&mut self, pbegin: T, pend: T, compressed_in: bool)

| Initialize using begin and end iterators | to byte data. |

Source

pub fn size(&self) -> u32

| Simple read-only vector-like interface. |

Source

pub fn begin(&self) -> *const u8

Source

pub fn end(&self) -> *const u8

Source

pub fn is_valid(&self) -> bool

| Check whether this private key is valid. |

Source

pub fn is_compressed(&self) -> bool

| Check whether the public key corresponding | to this private key is (to be) compressed. |

Source

pub fn check(&mut self, vch: *const u8) -> bool

| Check whether the 32-byte array pointed | to by vch is valid keydata. |

Source

pub fn make_new_key(&mut self, compressed_in: bool)

| Generate a new private key using a cryptographic | PRNG. |

Source

pub fn negate(&mut self) -> bool

| Negate private key |

Source

pub fn get_priv_key(&self) -> PrivKey

| Convert the private key to a CPrivKey | (serialized OpenSSL private key data). | | This is expensive. |

Source

pub fn get_pub_key(&self) -> PubKey

| Compute the public key from a private | key. | | This is expensive. |

Source

pub fn sign( &self, hash: &u256, vch_sig: &mut Vec<u8>, grind: Option<bool>, test_case: Option<u32>, ) -> bool

| Create a DER-serialized signature. | | The test_case parameter tweaks the | deterministic nonce. |

Source

pub fn verify_pub_key(&self, pubkey: &PubKey) -> bool

| Verify thoroughly whether a private | key and a public key match. | | This is done using a different mechanism | than just regenerating it. |

Source

pub fn sign_compact(&self, hash: &u256, vch_sig: &mut Vec<u8>) -> bool

| Create a compact signature (65 bytes), | which allows reconstructing the used | public key. | | The format is one header byte, followed | by two times 32 bytes for the serialized | r and s values. | | The header byte: 0x1B = first key with | even y, 0x1C = first key with odd y, 0x1D | = second key with even y, 0x1E = second | key with odd y, add 0x04 for compressed | keys. |

Source

pub fn sign_schnorr( &self, hash: &u256, sig: &[u8], merkle_root: *const u256, aux: *const u256, ) -> bool

| Create a BIP-340 Schnorr signature, | for the xonly-pubkey corresponding | to *this, optionally tweaked by *merkle_root. | Additional nonce entropy can be provided | through aux. merkle_root is used to | optionally perform tweaking of the | private key, as specified in BIP341: | | - If merkle_root == nullptr: no tweaking | is done, sign with key directly (this | is used for signatures in BIP342 script). | | - If merkle_root->IsNull(): sign with | key + H_TapTweak(pubkey) (this is used | for key path spending when no scripts | are present). | | - Otherwise: sign with key + H_TapTweak(pubkey | || *merkle_root) (this is used for key | path spending, with specific | | Merkle root of the script tree). |

Source

pub fn load( &mut self, seckey: &PrivKey, vch_pub_key: &PubKey, skip_check: Option<bool>, ) -> bool

| Load private key and check that public | key matches. |

Source

pub fn derive( &self, key_child: &mut Key, cc_child: &mut ChainCode, n_child: u32, cc: &ChainCode, ) -> bool

| Derive BIP32 child key. |

Trait Implementations§

Source§

impl Default for Key

Source§

fn default() -> Self

Construct an invalid private key.

Source§

impl PartialEq for Key

Source§

fn eq(&self, other: &Key) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Key

Auto Trait Implementations§

§

impl Freeze for Key

§

impl RefUnwindSafe for Key

§

impl Send for Key

§

impl Sync for Key

§

impl Unpin for Key

§

impl UnwindSafe for Key

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, U> CastInto<U> for T
where U: CastFrom<T>,

Source§

unsafe fn cast_into(self) -> U

Performs the conversion. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> StaticUpcast<T> for T

Source§

unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>

Convert type of a const pointer. 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.
Source§

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

Source§

fn vzip(self) -> V