pub struct PublicKey { /* private fields */ }Expand description
An Ed25519 public key
Implementations§
Source§impl PublicKey
impl PublicKey
Sourcepub fn is_torsion_free(&self) -> bool
pub fn is_torsion_free(&self) -> bool
Return true if and only if the key is contained within the prime order subgroup
Sourcepub fn is_canonical(&self) -> bool
pub fn is_canonical(&self) -> bool
Return true if and only if the public key uses a canonical encoding
Sourcepub fn convert_raw_to_der(raw: &[u8]) -> Result<Vec<u8>, PublicKeyDecodingError>
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.
Sourcepub fn serialize_raw(&self) -> [u8; 32]
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
Sourcepub fn deserialize_raw(bytes: &[u8]) -> Result<Self, PublicKeyDecodingError>
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
Sourcepub fn serialize_rfc8410_der(&self) -> Vec<u8> ⓘ
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
Sourcepub fn serialize_rfc8410_pem(&self) -> Vec<u8> ⓘ
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
Sourcepub fn deserialize_rfc8410_der(
bytes: &[u8],
) -> Result<Self, PublicKeyDecodingError>
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
Sourcepub fn deserialize_rfc8410_pem(
pem: &str,
) -> Result<Self, PublicKeyDecodingError>
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
Sourcepub fn verify_signature(
&self,
msg: &[u8],
signature: &[u8],
) -> Result<(), SignatureError>
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
Sourcepub fn batch_verify<R: CryptoRng + Rng>(
messages: &[&[u8]],
signatures: &[&[u8]],
keys: &[Self],
rng: &mut R,
) -> Result<(), SignatureError>
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
Sourcepub fn mainnet_key(key_id: MasterPublicKeyId) -> Self
pub fn mainnet_key(key_id: MasterPublicKeyId) -> Self
Return the public master keys used in the production mainnet
Sourcepub fn pocketic_key(key_id: PocketIcMasterPublicKeyId) -> Self
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
Sourcepub fn derive_mainnet_key(
key_id: MasterPublicKeyId,
canister_id: &CanisterId,
derivation_path: &[Vec<u8>],
) -> (Self, [u8; 32])
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
Sourcepub fn derive_pocketic_key(
key_id: PocketIcMasterPublicKeyId,
canister_id: &CanisterId,
derivation_path: &[Vec<u8>],
) -> (Self, [u8; 32])
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
Sourcepub fn derive_subkey(
&self,
derivation_path: &DerivationPath,
) -> (Self, [u8; 32])
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
Sourcepub fn derive_subkey_with_chain_code(
&self,
derivation_path: &DerivationPath,
chain_code: &[u8; 32],
) -> (Self, [u8; 32])
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