nkey
ModuleNKey (Ed25519 challenge-response) and JWT credentials files.
Contents
use utopia_nats::auth::nkey::CredentialsAuth;Rust
pub struct CredentialsAuthA user JWT and NKey seed from a .creds file: {"jwt", "nkey", "sig"}.
use utopia_nats::auth::nkey::NKeyAuth;Rust
pub struct NKeyAuthSigns the server's nonce with an NKey seed: {"nkey": public key, "sig": base32 signature}.
Rust
use utopia_nats::auth::{Authenticator, NKeyAuth};
// A user seed (base32 of the seed prefix, 32 key bytes and a CRC).
let seed = "SUAKKTOKDASTBOY5NUJSZXWWEN5S5WI6H5ZB7SYZOELUJFGWJE6J2XGBOY";
let auth = NKeyAuth::new("", seed);
let fields = auth.authenticate(Some("nonce"))?;
assert_eq!(fields["nkey"], auth.public_key()?.as_str());
assert!(auth.public_key()?.starts_with('U'));