Struct hedera::PublicKey

source ·
pub struct PublicKey(/* private fields */);
Expand description

A public key on the Hedera network.

Implementations§

source§

impl PublicKey

source

pub fn is_ed25519(&self) -> bool

Returns true if the public key is Ed25519.

source

pub fn is_ecdsa(&self) -> bool

Returns true if the public key data is Ecdsa.

source

pub fn from_bytes(bytes: &[u8]) -> Result<Self>

Parse a PublicKey from a sequence of bytes.

§Errors
source

pub fn from_bytes_ed25519(bytes: &[u8]) -> Result<Self>

Parse a Ed25519 PublicKey from a sequence of bytes.

§Errors
source

pub fn from_bytes_ecdsa(bytes: &[u8]) -> Result<Self>

Parse a ECDSA(secp256k1) PublicKey from a sequence of bytes.

§Errors
  • Error::KeyParse if bytes cannot be parsed into a ECDSA(secp256k1) PublicKey.
source

pub fn from_bytes_der(bytes: &[u8]) -> Result<Self>

Parse a PublicKey from a sequence of der encoded bytes.

§Errors
source

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
source

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
source

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
source

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

source

pub fn to_bytes_der(&self) -> Vec<u8>

Return this PublicKey, serialized as der-encoded bytes.

source

pub fn to_bytes_raw(&self) -> Vec<u8>

Return this PublicKey, serialized as bytes.

source

pub fn to_string_der(&self) -> String

DER encodes self, then hex encodes the result.

source

pub fn to_string_raw(&self) -> String

Returns the raw bytes of self after hex encoding.

source

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");
source

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.

source

pub fn verify(&self, msg: &[u8], signature: &[u8]) -> Result<()>

Verify a signature on a msg with this public key.

§Errors
source

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 Clone for PublicKey

source§

fn clone(&self) -> PublicKey

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 PublicKey

source§

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

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

impl Display for PublicKey

source§

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

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

impl From<PublicKey> for AccountId

source§

fn from(alias: PublicKey) -> Self

Converts to this type from the input type.
source§

impl From<PublicKey> for Key

source§

fn from(key: PublicKey) -> Self

Converts to this type from the input type.
source§

impl FromStr for PublicKey

§

type Err = Error

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl Hash for PublicKey

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for PublicKey

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for PublicKey

source§

impl Eq for PublicKey

source§

impl StructuralPartialEq for PublicKey

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<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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

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

Checks if this value is equivalent to the given key. 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> FromRef<T> for T
where T: Clone,

source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
source§

impl<T> Instrument for T

source§

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

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

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

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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