Struct avalanche_types::key::secp256k1::public_key::Key
source · pub struct Key(pub PublicKey);
Expand description
Represents “k256::PublicKey” and “k256::ecdsa::VerifyingKey”. By default serializes as hex string.
Tuple Fields§
§0: PublicKey
Implementations§
source§impl Key
impl Key
sourcepub fn from_sec1_bytes(b: &[u8]) -> Result<Self>
pub fn from_sec1_bytes(b: &[u8]) -> Result<Self>
Decodes compressed or uncompressed public key bytes with Elliptic-Curve-Point-to-Octet-String encoding described in SEC 1: Elliptic Curve Cryptography (Version 2.0) section 2.3.3 (page 10). ref. http://www.secg.org/sec1-v2.pdf
sourcepub fn from_public_key_der(b: &[u8]) -> Result<Self>
pub fn from_public_key_der(b: &[u8]) -> Result<Self>
Decodes ASN.1 DER-encoded public key bytes.
sourcepub fn from_signature(digest: &[u8], sig: &[u8]) -> Result<Self>
pub fn from_signature(digest: &[u8], sig: &[u8]) -> Result<Self>
Loads the public key from a message and its recoverable signature. ref. “fx.SECPFactory.RecoverHashPublicKey”
pub fn from_verifying_key(verifying_key: &VerifyingKey) -> Self
pub fn to_verifying_key(&self) -> VerifyingKey
sourcepub fn verify(&self, digest: &[u8], sig: &[u8]) -> Result<bool>
pub fn verify(&self, digest: &[u8], sig: &[u8]) -> Result<bool>
Verifies the message and the validity of its signature with recoverable code.
sourcepub fn to_compressed_bytes(&self) -> [u8; 33]
pub fn to_compressed_bytes(&self) -> [u8; 33]
Converts the public key to compressed bytes.
sourcepub fn to_uncompressed_bytes(&self) -> [u8; 65]
pub fn to_uncompressed_bytes(&self) -> [u8; 65]
Converts the public key to uncompressed bytes.
sourcepub fn to_short_id(&self) -> Result<Id>
pub fn to_short_id(&self) -> Result<Id>
“hashing.PubkeyBytesToAddress”
ref. “pk.PublicKey().Address().Bytes()”
ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/hashing#PubkeyBytesToAddress
sourcepub fn to_short_bytes(&self) -> Result<Vec<u8>>
pub fn to_short_bytes(&self) -> Result<Vec<u8>>
“hashing.PubkeyBytesToAddress” and “ids.ToShortID”
ref. https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/hashing#PubkeyBytesToAddress
pub fn to_h160(&self) -> H160
sourcepub fn to_eth_address(&self) -> String
pub fn to_eth_address(&self) -> String
Encodes the public key in ETH address format. Make sure to not double-hash. ref. https://pkg.go.dev/github.com/ethereum/go-ethereum/crypto#PubkeyToAddress ref. https://pkg.go.dev/github.com/ethereum/go-ethereum/common#Address.Hex
pub fn to_hrp_address( &self, network_id: u32, chain_id_alias: &str ) -> Result<String>
Trait Implementations§
source§impl<'de> Deserialize<'de> for Key
impl<'de> Deserialize<'de> for Key
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 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
source§impl From<Key> for VerifyingKey
impl From<Key> for VerifyingKey
source§impl From<VerifyingKey<Secp256k1>> for Key
impl From<VerifyingKey<Secp256k1>> for Key
source§fn from(vkey: VerifyingKey) -> Self
fn from(vkey: VerifyingKey) -> Self
source§impl ReadOnly for Key
impl ReadOnly for Key
fn key_type(&self) -> KeyType
source§fn hrp_address(&self, network_id: u32, chain_id_alias: &str) -> Result<String>
fn hrp_address(&self, network_id: u32, chain_id_alias: &str) -> Result<String>
fn short_address(&self) -> Result<Id>
fn short_address_bytes(&self) -> Result<Vec<u8>>
fn eth_address(&self) -> String
fn h160_address(&self) -> H160
impl Copy for Key
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§
source§impl<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,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request