Struct avalanche_types::key::secp256k1::private_key::Key
source · [−]pub struct Key(_);
Expand description
Represents “k256::SecretKey” and “k256::ecdsa::SigningKey”.
Implementations
sourceimpl Key
impl Key
sourcepub fn from_bytes(raw: &[u8]) -> Result<Self>
pub fn from_bytes(raw: &[u8]) -> Result<Self>
Loads the private key from the raw scalar bytes.
sourcepub fn to_hex(&self) -> String
pub fn to_hex(&self) -> String
Hex-encodes the raw private key to string with “0x” prefix (e.g., Ethereum).
sourcepub fn from_hex<S>(s: S) -> Result<Self>where
S: Into<String>,
pub fn from_hex<S>(s: S) -> Result<Self>where
S: Into<String>,
Loads the private key from a hex-encoded string (e.g., Ethereum).
sourcepub fn to_cb58(&self) -> String
pub fn to_cb58(&self) -> String
Encodes the raw private key to string with “PrivateKey-” prefix (e.g., Avalanche).
sourcepub fn from_cb58<S>(s: S) -> Result<Self>where
S: Into<String>,
pub fn from_cb58<S>(s: S) -> Result<Self>where
S: Into<String>,
Loads the private key from a CB58-encoded string (e.g., Avalanche). Once decoded and with its “PrivateKey-” prefix removed, the length must be 32-byte.
sourcepub fn to_public_key(&self) -> PublicKey
pub fn to_public_key(&self) -> PublicKey
Derives the public key from this private key.
sourcepub fn sign_digest(&self, digest: &[u8]) -> Result<Sig>
pub fn sign_digest(&self, digest: &[u8]) -> Result<Sig>
Signs the 32-byte SHA256 output message with the ECDSA private key and the recoverable code. “github.com/decred/dcrd/dcrec/secp256k1/v3/ecdsa.SignCompact” outputs 65-byte signature. ref. “avalanchego/utils/crypto.PrivateKeySECP256K1R.SignHash” ref. https://github.com/rust-bitcoin/rust-secp256k1/blob/master/src/ecdsa/recovery.rs
pub fn to_ethers_signing_key(&self) -> Result<EthersSigningKey>
Trait Implementations
sourceimpl Display for Key
impl Display for Key
ref. https://doc.rust-lang.org/std/string/trait.ToString.html ref. https://doc.rust-lang.org/std/fmt/trait.Display.html Use “Self.to_string()” to directly invoke this
sourceimpl ReadOnly for Key
impl ReadOnly for Key
ref. https://doc.rust-lang.org/book/ch10-02-traits.html
sourcefn get_address(&self, network_id: u32, chain_id_alias: &str) -> Result<String>
fn get_address(&self, network_id: u32, chain_id_alias: &str) -> Result<String>
fn get_short_address(&self) -> Result<Id>
fn get_short_address_bytes(&self) -> Result<Vec<u8>>
fn get_eth_address(&self) -> String
fn get_h160_address(&self) -> H160
sourceimpl SignOnly for Key
impl SignOnly for Key
sourcefn sign_digest(&self, msg: &[u8]) -> Result<[u8; 65]>
fn sign_digest(&self, msg: &[u8]) -> Result<[u8; 65]>
sourcefn ethers_signing_key(&self) -> Result<EthersSigningKey>
fn ethers_signing_key(&self) -> Result<EthersSigningKey>
impl Eq for Key
impl StructuralEq for Key
impl StructuralPartialEq for Key
Auto Trait Implementations
impl RefUnwindSafe for Key
impl Send for Key
impl Sync for Key
impl Unpin for Key
impl UnwindSafe for Key
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
sourcefn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request