[−][src]Crate nkeys
nkeys
The nkeys
is a Rust port of the official NATS Go nkeys implementation.
While it is a port, every effort has been made to make this library feel like idiomatic Rust and to do things
in a "rusty" way.
Nkeys provides library functions to create ed25519 keys using the special prefix encoding system used by NATS 2.0+ security
Examples
use nkeys::KeyPair; fn main() { // Create a user key pair let user = KeyPair::new_user(); // Sign some data with the user's full key pair let msg = "this is super secret".as_bytes(); let sig = user.sign(&msg).unwrap(); let res = user.verify(msg, sig.as_slice()); assert!(res.is_ok()); // Access the encoded seed (the information that needs to be kept safe/secret) let seed = user.seed().unwrap(); // Access the public key, which can be safely shared let pk = user.public_key(); // Create a full User who can sign and verify from a private seed. let user = KeyPair::from_seed(&seed); // Create a user that can only verify and not sign let user = KeyPair::from_public_key(&pk).unwrap(); assert!(user.seed().is_err()); }
Modules
error | Error wrappers and boilerplate |
Macros
err | A handy macro borrowed from the |
Structs
KeyPair | The main interface used for reading and writing nkey-encoded key pairs, including seeds and public keys. |