PublicKey

Struct PublicKey 

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

An Ed25519 public key

Implementations§

Source§

impl PublicKey

Source

pub const BYTES: usize = 32usize

The number of bytes in the raw public key

Source

pub fn is_torsion_free(&self) -> bool

Return true if and only if the key is contained within the prime order subgroup

Source

pub fn is_canonical(&self) -> bool

Return true if and only if the public key uses a canonical encoding

Source

pub fn convert_raw_to_der(raw: &[u8]) -> Result<Vec<u8>, PublicKeyDecodingError>

Convert a raw Ed25519 public key (32 bytes) to the DER encoding

§Warning

This performs no validity check on the public key aside from verifying that it is exactly 32 bytes long. If you pass an invalid key (ie a encoding of a point not in the prime order subgroup), then the DER encoding of that invalid key will be returned.

Source

pub fn serialize_raw(&self) -> [u8; 32]

Serialize this public key in raw format

This is just the 32 byte encoding of the public point

Source

pub fn deserialize_raw(bytes: &[u8]) -> Result<Self, PublicKeyDecodingError>

Deserialize a public key in raw format

This is just the 32 byte encoding of the public point, cooresponding to Self::serialize_raw

§Warning

This does not verify that the key is within the prime order subgroup, or that the public key is canonical. To check these properties, use is_torsion_free and is_canonical

Source

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

Serialize this public key as a DER encoded structure

See RFC 8410 for details on the format

Source

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

Serialize this public key as a PEM encoded structure

See RFC 8410 for details on the format

Source

pub fn deserialize_rfc8410_der( bytes: &[u8], ) -> Result<Self, PublicKeyDecodingError>

Deserialize the DER encoded public key

See RFC 8410 for details on the format. This cooresponds to Self::serialize_rfc8410_der

§Warning

This does not verify that the key is within the prime order subgroup, or that the public key is canonical. To check these properties, use is_torsion_free and is_canonical

Source

pub fn deserialize_rfc8410_pem( pem: &str, ) -> Result<Self, PublicKeyDecodingError>

Deserialize the PEM encoded public key

See RFC 8410 for details on the format. This cooresponds to Self::serialize_rfc8410_pem

§Warning

This does not verify that the key is within the prime order subgroup, or that the public key is canonical. To check these properties, use is_torsion_free and is_canonical

Source

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

Verify a Ed25519 signature

Returns Ok if the signature is valid, or Err otherwise

This verification follows ZIP215 validation rules

Source

pub fn batch_verify<R: CryptoRng + Rng>( messages: &[&[u8]], signatures: &[&[u8]], keys: &[Self], rng: &mut R, ) -> Result<(), SignatureError>

Verify a batch of signatures

Returns Ok if the signatures are all valid, or Err otherwise

Note that this does not indicate which of the signature(s) are invalid; if batch verification fails you must then test serially to find the valid signatures (if any).

This verification follows ZIP215 validation rules

Source

pub fn mainnet_key(key_id: MasterPublicKeyId) -> Self

Return the public master keys used in the production mainnet

Source

pub fn pocketic_key(key_id: PocketIcMasterPublicKeyId) -> Self

Return the public master keys used by PocketIC

Note that the secret keys for these public keys are known, and these keys should only be used for offline testing with PocketIC

Source

pub fn derive_mainnet_key( key_id: MasterPublicKeyId, canister_id: &CanisterId, derivation_path: &[Vec<u8>], ) -> (Self, [u8; 32])

Derive a public key from the mainnet parameters

This is an offline equivalent to the schnorr_public_key management canister call

Source

pub fn derive_pocketic_key( key_id: PocketIcMasterPublicKeyId, canister_id: &CanisterId, derivation_path: &[Vec<u8>], ) -> (Self, [u8; 32])

Derive a public key as is done on PocketIC

This is an offline equivalent to the schnorr_public_key management canister call when running on PocketIC

Source

pub fn derive_subkey( &self, derivation_path: &DerivationPath, ) -> (Self, [u8; 32])

Derive a public key from this public key using a derivation path

This is the same derivation system used by the Internet Computer when deriving subkeys for Ed25519

Source

pub fn derive_subkey_with_chain_code( &self, derivation_path: &DerivationPath, chain_code: &[u8; 32], ) -> (Self, [u8; 32])

Derive a public key from this public key using a derivation path and chain code

This is the same derivation system used by the Internet Computer when deriving subkeys for Ed25519

Trait Implementations§

Source§

impl Clone for PublicKey

Source§

fn clone(&self) -> PublicKey

Returns a duplicate 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 PartialEq for PublicKey

Source§

fn eq(&self, other: &PublicKey) -> 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 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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