Struct nkeys::KeyPair

source ·
pub struct KeyPair { /* private fields */ }
Expand description

The main interface used for reading and writing nkey-encoded key pairs, including seeds and public keys. Instances of this type cannot be cloned.

Implementations§

source§

impl KeyPair

source

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

source

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.

source

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

source

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

source

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

source

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

source

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

source

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

source

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

source

pub fn public_key(&self) -> String

Returns the encoded, human-readable public key of this key pair

source

pub fn sign(&self, input: &[u8]) -> Result<Vec<u8>, Error>

Attempts to sign the given input with the key pair’s seed

source

pub fn verify(&self, input: &[u8], sig: &[u8]) -> Result<(), Error>

Attempts to verify that the given signature is valid for the given input

source

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

source

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

source

pub fn from_seed(source: &str) -> Result<KeyPair, Error>

Attempts to produce a full key pair from the given encoded seed string

source

pub fn key_pair_type(&self) -> KeyPairType

Returns the type of this key pair.

Trait Implementations§

source§

impl Debug for KeyPair

source§

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

Formats the value using the given formatter. Read more

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

§

type Output = T

Should always be Self
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