pub struct PublicKey(/* private fields */);
Expand description
A public key on the Hedera network.
Implementations§
source§impl PublicKey
impl PublicKey
sourcepub fn is_ed25519(&self) -> bool
pub fn is_ed25519(&self) -> bool
Returns true
if the public key is Ed25519
.
sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_bytes(bytes: &[u8]) -> Result<Self>
Parse a PublicKey
from a sequence of bytes.
§Errors
Error::KeyParse
ifbytes
cannot be parsed into aPublicKey
.
sourcepub fn from_bytes_ed25519(bytes: &[u8]) -> Result<Self>
pub fn from_bytes_ed25519(bytes: &[u8]) -> Result<Self>
Parse a Ed25519 PublicKey
from a sequence of bytes.
§Errors
Error::KeyParse
ifbytes
cannot be parsed into a ed25519PublicKey
.
sourcepub fn from_bytes_ecdsa(bytes: &[u8]) -> Result<Self>
pub fn from_bytes_ecdsa(bytes: &[u8]) -> Result<Self>
Parse a ECDSA(secp256k1) PublicKey
from a sequence of bytes.
§Errors
Error::KeyParse
ifbytes
cannot be parsed into a ECDSA(secp256k1)PublicKey
.
sourcepub fn from_bytes_der(bytes: &[u8]) -> Result<Self>
pub fn from_bytes_der(bytes: &[u8]) -> Result<Self>
Parse a PublicKey
from a sequence of der encoded bytes.
§Errors
Error::KeyParse
ifbytes
cannot be parsed into aPublicKey
.
sourcepub fn from_str_der(s: &str) -> Result<Self>
pub fn from_str_der(s: &str) -> Result<Self>
Decodes self
from a der encoded str
Optionally strips a 0x
prefix.
See from_bytes_der
§Errors
Error::KeyParse
ifs
cannot be parsed into aPublicKey
.
sourcepub fn from_str_ed25519(s: &str) -> Result<Self>
pub fn from_str_ed25519(s: &str) -> Result<Self>
Parse a Ed25519 PublicKey
from a string containing the raw key material.
Optionally strips a 0x
prefix.
§Errors
Error::KeyParse
ifs
cannot be parsed into a ed25519PublicKey
.
sourcepub fn from_str_ecdsa(s: &str) -> Result<Self>
pub fn from_str_ecdsa(s: &str) -> Result<Self>
Parse a ECDSA(secp256k1) PublicKey
from a string containing the raw key material.
Optionally strips a 0x
prefix.
§Errors
Error::KeyParse
ifs
cannot be parsed into a Ecdsa(secp256k1)PublicKey
.
sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Return this PublicKey
, serialized as bytes.
If this is an ed25519 public key, this is equivalent to to_bytes_raw
If this is an ecdsa public key, this is equivalent to to_bytes_der
sourcepub fn to_bytes_der(&self) -> Vec<u8> ⓘ
pub fn to_bytes_der(&self) -> Vec<u8> ⓘ
Return this PublicKey
, serialized as der-encoded bytes.
sourcepub fn to_bytes_raw(&self) -> Vec<u8> ⓘ
pub fn to_bytes_raw(&self) -> Vec<u8> ⓘ
Return this PublicKey
, serialized as bytes.
sourcepub fn to_string_der(&self) -> String
pub fn to_string_der(&self) -> String
DER encodes self, then hex encodes the result.
sourcepub fn to_string_raw(&self) -> String
pub fn to_string_raw(&self) -> String
Returns the raw bytes of self
after hex encoding.
sourcepub fn to_account_id(&self, shard: u64, realm: u64) -> AccountId
pub fn to_account_id(&self, shard: u64, realm: u64) -> AccountId
Creates an AccountId
with the given shard
, realm
, and self
as an alias
.
§Examples
use hedera::PublicKey;
let key: PublicKey = "302d300706052b8104000a03220002703a9370b0443be6ae7c507b0aec81a55e94e4a863b9655360bd65358caa6588".parse().unwrap();
let account_id = key.to_account_id(0, 0);
assert_eq!(account_id.to_string(), "0.0.302d300706052b8104000a03220002703a9370b0443be6ae7c507b0aec81a55e94e4a863b9655360bd65358caa6588");
sourcepub fn to_evm_address(&self) -> Option<EvmAddress>
pub fn to_evm_address(&self) -> Option<EvmAddress>
Convert this public key into an evm address. The EVM address is This is the rightmost 20 bytes of the 32 byte Keccak-256 hash of the ECDSA public key.
Returns Some(evm_address)
if self.is_ecdsa
, otherwise None
.
sourcepub fn verify(&self, msg: &[u8], signature: &[u8]) -> Result<()>
pub fn verify(&self, msg: &[u8], signature: &[u8]) -> Result<()>
Verify a signature
on a msg
with this public key.
§Errors
Error::SignatureVerify
if the signature algorithm doesn’t match thisPublicKey
.Error::SignatureVerify
if the signature is invalid for thisPublicKey
.
sourcepub fn verify_transaction<D: TransactionExecute>(
&self,
transaction: &mut Transaction<D>
) -> Result<()>
pub fn verify_transaction<D: TransactionExecute>( &self, transaction: &mut Transaction<D> ) -> Result<()>
Returns Ok(())
if this public key has signed the given transaction.
§Errors
Error::SignatureVerify
if the private key associated with this public key did not sign this transaction, or the signature associated was invalid.
Trait Implementations§
source§impl PartialEq for PublicKey
impl PartialEq for PublicKey
impl Copy for PublicKey
impl Eq for PublicKey
impl StructuralPartialEq for PublicKey
Auto Trait Implementations§
impl Freeze for PublicKey
impl RefUnwindSafe for PublicKey
impl Send for PublicKey
impl Sync for PublicKey
impl Unpin for PublicKey
impl UnwindSafe for PublicKey
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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