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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for KeyPair
impl RefUnwindSafe for KeyPair
impl Send for KeyPair
impl Sync for KeyPair
impl Unpin for KeyPair
impl UnwindSafe for KeyPair
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)