pub struct NostrKeypair { /* private fields */ }Expand description
A Nostr keypair with memory-locked secret key.
§Example
use keep_core::keys::NostrKeypair;
let keypair = NostrKeypair::generate()?;
println!("npub: {}", keypair.to_npub());
println!("nsec: {}", keypair.to_nsec());
let signature = keypair.sign(b"hello nostr")?;Implementations§
Source§impl NostrKeypair
impl NostrKeypair
Sourcepub fn from_secret_bytes(secret: &mut [u8; 32]) -> Result<Self>
pub fn from_secret_bytes(secret: &mut [u8; 32]) -> Result<Self>
Create a keypair from secret bytes. Zeroes the source.
Sourcepub fn from_nsec(nsec: &str) -> Result<Self>
pub fn from_nsec(nsec: &str) -> Result<Self>
Create a keypair from a bech32 nsec string.
§Example
use keep_core::keys::NostrKeypair;
let keypair = NostrKeypair::generate()?;
let nsec = keypair.to_nsec();
let restored = NostrKeypair::from_nsec(&nsec)?;
assert_eq!(keypair.public_bytes(), restored.public_bytes());§Errors
Returns KeepError::InvalidNsec if the string is not a valid nsec.
Sourcepub fn secret_bytes(&self) -> &[u8; 32]
pub fn secret_bytes(&self) -> &[u8; 32]
The secret key bytes.
Sourcepub fn public_bytes(&self) -> &[u8; 32]
pub fn public_bytes(&self) -> &[u8; 32]
The public key bytes.
Sourcepub fn public_hex(&self) -> String
pub fn public_hex(&self) -> String
The public key as hex.
Trait Implementations§
Auto Trait Implementations§
impl Forget for NostrKeypair
impl Freeze for NostrKeypair
impl Move for NostrKeypair
impl RefUnwindSafe for NostrKeypair
impl Send for NostrKeypair
impl Sync for NostrKeypair
impl Unpin for NostrKeypair
impl UnsafeUnpin for NostrKeypair
impl UnwindSafe for NostrKeypair
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
Mutably borrows from an owned value. Read more