pub struct KeyPair { /* private fields */ }
Expand description
The main interface used for reading and writing nkey-encoded key pairs, including seeds and public keys.
Implementations§
Source§impl KeyPair
impl KeyPair
Sourcepub fn new(kp_type: KeyPairType) -> KeyPair
pub fn new(kp_type: KeyPairType) -> KeyPair
Creates a new key pair of the given type.
NOTE: This is not available if using on a wasm32-unknown-unknown target due to the lack of
rand support. Use new_from_raw
instead
Sourcepub fn new_from_raw(
kp_type: KeyPairType,
random_bytes: [u8; 32],
) -> Result<KeyPair, Error>
pub fn new_from_raw( kp_type: KeyPairType, random_bytes: [u8; 32], ) -> Result<KeyPair, Error>
Create a new keypair using a pre-existing set of random bytes.
Returns an error if there is an issue using the bytes to generate the key NOTE: These bytes should be generated from a cryptographically secure random source.
Sourcepub fn new_user() -> KeyPair
pub fn new_user() -> KeyPair
Creates a new user key pair with a seed that has a U prefix
NOTE: This is not available if using on a wasm32-unknown-unknown target due to the lack of
rand support. Use new_from_raw
instead
Sourcepub fn new_account() -> KeyPair
pub fn new_account() -> KeyPair
Creates a new account key pair with a seed that has an A prefix
NOTE: This is not available if using on a wasm32-unknown-unknown target due to the lack of
rand support. Use new_from_raw
instead
Sourcepub fn new_operator() -> KeyPair
pub fn new_operator() -> KeyPair
Creates a new operator key pair with a seed that has an O prefix
NOTE: This is not available if using on a wasm32-unknown-unknown target due to the lack of
rand support. Use new_from_raw
instead
Sourcepub fn new_cluster() -> KeyPair
pub fn new_cluster() -> KeyPair
Creates a new cluster key pair with a seed that has the C prefix
NOTE: This is not available if using on a wasm32-unknown-unknown target due to the lack of
rand support. Use new_from_raw
instead
Sourcepub fn new_server() -> KeyPair
pub fn new_server() -> KeyPair
Creates a new server key pair with a seed that has the N prefix
NOTE: This is not available if using on a wasm32-unknown-unknown target due to the lack of
rand support. Use new_from_raw
instead
Sourcepub fn new_module() -> KeyPair
pub fn new_module() -> KeyPair
Creates a new module (e.g. WebAssembly) key pair with a seed that has the M prefix
NOTE: This is not available if using on a wasm32-unknown-unknown target due to the lack of
rand support. Use new_from_raw
instead
Sourcepub fn new_service() -> KeyPair
pub fn new_service() -> KeyPair
Creates a new service / service provider key pair with a seed that has the V prefix
NOTE: This is not available if using on a wasm32-unknown-unknown target due to the lack of
rand support. Use new_from_raw
instead
Sourcepub fn public_key(&self) -> String
pub fn public_key(&self) -> String
Returns the encoded, human-readable public key of this key pair
Sourcepub fn sign(&self, input: &[u8]) -> Result<Vec<u8>, Error>
pub fn sign(&self, input: &[u8]) -> Result<Vec<u8>, Error>
Attempts to sign the given input with the key pair’s seed
Sourcepub fn verify(&self, input: &[u8], sig: &[u8]) -> Result<(), Error>
pub fn verify(&self, input: &[u8], sig: &[u8]) -> Result<(), Error>
Attempts to verify that the given signature is valid for the given input
Sourcepub fn seed(&self) -> Result<String, Error>
pub fn seed(&self) -> Result<String, Error>
Attempts to return the encoded, human-readable string for this key pair’s seed. Remember that this value should be treated as a secret. Do not store it for any longer than necessary
Sourcepub fn from_public_key(source: &str) -> Result<KeyPair, Error>
pub fn from_public_key(source: &str) -> Result<KeyPair, Error>
Attempts to produce a public-only key pair from the given encoded public key string
Sourcepub fn from_seed(source: &str) -> Result<KeyPair, Error>
pub fn from_seed(source: &str) -> Result<KeyPair, Error>
Attempts to produce a full key pair from the given encoded seed string
Sourcepub fn key_pair_type(&self) -> KeyPairType
pub fn key_pair_type(&self) -> KeyPairType
Returns the type of this key pair.