pub struct Keys { /* private fields */ }Expand description
secp256k1 BIP-340 keypair.
Construct from a SecretKey (Keys::from_secret_key) or generate a fresh
pair (Keys::generate). The public key is computed eagerly so signing has
O(1) overhead.
§Example
use nula_core::Keys;
let keys = Keys::generate().unwrap();
let pk_hex = keys.public_key().to_hex();
assert_eq!(pk_hex.len(), 64);Implementations§
Source§impl Keys
impl Keys
Sourcepub fn from_secret_key(secret_key: SecretKey) -> Self
pub fn from_secret_key(secret_key: SecretKey) -> Self
Sourcepub fn generate() -> Result<Self, SecretKeyError>
pub fn generate() -> Result<Self, SecretKeyError>
Generate a fresh Keys pair using the operating system’s entropy.
§Errors
Returns SecretKeyError::Rng if the OS RNG fails.
Sourcepub fn parse<S>(input: S) -> Result<Self, SecretKeyError>
pub fn parse<S>(input: S) -> Result<Self, SecretKeyError>
Sourcepub const fn secret_key(&self) -> &SecretKey
pub const fn secret_key(&self) -> &SecretKey
Borrow the secret key.
Sourcepub const fn public_key(&self) -> &PublicKey
pub const fn public_key(&self) -> &PublicKey
Borrow the public key.
Sourcepub const fn as_inner(&self) -> &Keypair
pub const fn as_inner(&self) -> &Keypair
Borrow the inner secp256k1::Keypair.
Use this only at the boundary with the cryptography backend.
Sourcepub fn sign_schnorr(&self, message: &[u8; 32]) -> Signature
pub fn sign_schnorr(&self, message: &[u8; 32]) -> Signature
Sign an arbitrary message digest with BIP-340 Schnorr.
Callers are responsible for hashing application data — for Nostr events, the digest is the SHA-256 of the canonical serialization described in NIP-01.
Trait Implementations§
impl Eq for Keys
Source§impl NostrSigner for Keys
impl NostrSigner for Keys
Source§fn get_public_key(&self) -> SignerFuture<'_, Result<PublicKey, SignerError>>
fn get_public_key(&self) -> SignerFuture<'_, Result<PublicKey, SignerError>>
Return the signer’s public key. Read more
Source§fn sign_event(
&self,
unsigned: UnsignedEvent,
) -> SignerFuture<'_, Result<Event, SignerError>>
fn sign_event( &self, unsigned: UnsignedEvent, ) -> SignerFuture<'_, Result<Event, SignerError>>
Source§fn nip04_encrypt<'a>(
&'a self,
peer: &'a PublicKey,
plaintext: &'a str,
) -> SignerFuture<'a, Result<String, SignerError>>
fn nip04_encrypt<'a>( &'a self, peer: &'a PublicKey, plaintext: &'a str, ) -> SignerFuture<'a, Result<String, SignerError>>
NIP-04 (legacy) encrypt to
peer. Read moreSource§fn nip04_decrypt<'a>(
&'a self,
peer: &'a PublicKey,
ciphertext: &'a str,
) -> SignerFuture<'a, Result<String, SignerError>>
fn nip04_decrypt<'a>( &'a self, peer: &'a PublicKey, ciphertext: &'a str, ) -> SignerFuture<'a, Result<String, SignerError>>
NIP-04 (legacy) decrypt from
peer. Read moreSource§fn nip44_encrypt<'a>(
&'a self,
peer: &'a PublicKey,
plaintext: &'a str,
) -> SignerFuture<'a, Result<String, SignerError>>
fn nip44_encrypt<'a>( &'a self, peer: &'a PublicKey, plaintext: &'a str, ) -> SignerFuture<'a, Result<String, SignerError>>
NIP-44 v2 encrypt to
peer. Read moreSource§fn nip44_decrypt<'a>(
&'a self,
peer: &'a PublicKey,
payload: &'a str,
) -> SignerFuture<'a, Result<String, SignerError>>
fn nip44_decrypt<'a>( &'a self, peer: &'a PublicKey, payload: &'a str, ) -> SignerFuture<'a, Result<String, SignerError>>
NIP-44 v2 decrypt from
peer. Read moreAuto Trait Implementations§
impl Freeze for Keys
impl RefUnwindSafe for Keys
impl Send for Keys
impl Sync for Keys
impl Unpin for Keys
impl UnsafeUnpin for Keys
impl UnwindSafe for Keys
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.