pub struct PublicKey(/* private fields */);Expand description
32-byte BIP-340 x-only public key.
Display and serde use lowercase 64-char hex.
§Example
use nula_core::PublicKey;
let pk = PublicKey::parse(
"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
)
.unwrap();
assert_eq!(pk.to_hex().len(), 64);Implementations§
Source§impl PublicKey
impl PublicKey
Sourcepub fn from_byte_array(bytes: [u8; 32]) -> Result<Self, PublicKeyError>
pub fn from_byte_array(bytes: [u8; 32]) -> Result<Self, PublicKeyError>
Construct from a fixed-size byte array.
§Errors
Returns PublicKeyError::InvalidPoint when the bytes do not encode
a valid x-coordinate.
Sourcepub fn from_slice(bytes: &[u8]) -> Result<Self, PublicKeyError>
pub fn from_slice(bytes: &[u8]) -> Result<Self, PublicKeyError>
Construct from a byte slice.
§Errors
Returns PublicKeyError::InvalidLength when the slice is not 32
bytes long, or PublicKeyError::InvalidPoint otherwise.
Sourcepub fn parse<S>(input: S) -> Result<Self, PublicKeyError>
pub fn parse<S>(input: S) -> Result<Self, PublicKeyError>
Sourcepub fn to_byte_array(self) -> [u8; 32]
pub fn to_byte_array(self) -> [u8; 32]
Return the public key as raw bytes.
Sourcepub const fn as_inner(&self) -> &XOnlyPublicKey
pub const fn as_inner(&self) -> &XOnlyPublicKey
Borrow the inner secp256k1::XOnlyPublicKey.
Use this only at the boundary with the cryptography backend.
Sourcepub fn verify_schnorr(&self, message: &[u8; 32], sig: &Signature) -> bool
pub fn verify_schnorr(&self, message: &[u8; 32], sig: &Signature) -> bool
Verify a BIP-340 Schnorr signature against this public key.
message is the 32-byte digest the signer signed (typically the
canonical NIP-01 event id). The function uses the global
secp256k1 context and is therefore allocation-free.
Returns true when the signature is valid for this public key
over message, false on every other path (invalid signature,
wrong key, malformed point at construction time is impossible
because PublicKey only holds curve-valid points).
Trait Implementations§
impl Copy for PublicKey
Source§impl<'de> Deserialize<'de> for PublicKey
impl<'de> Deserialize<'de> for PublicKey
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
impl Eq for PublicKey
Source§impl From<XOnlyPublicKey> for PublicKey
impl From<XOnlyPublicKey> for PublicKey
Source§fn from(value: XOnlyPublicKey) -> Self
fn from(value: XOnlyPublicKey) -> Self
Source§impl FromBech32 for PublicKey
impl FromBech32 for PublicKey
Source§fn from_bech32(s: &str) -> Result<Self, FromBech32Error>
fn from_bech32(s: &str) -> Result<Self, FromBech32Error>
Source§impl FromNostrUri for PublicKey
impl FromNostrUri for PublicKey
Source§fn from_nostr_uri(uri: &str) -> Result<Self, Nip21Error>
fn from_nostr_uri(uri: &str) -> Result<Self, Nip21Error>
Source§impl Ord for PublicKey
impl Ord for PublicKey
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for PublicKey
impl PartialOrd for PublicKey
impl StructuralPartialEq for PublicKey
Source§impl ToNostrUri for PublicKey
impl ToNostrUri for PublicKey
Source§fn to_nostr_uri(&self) -> Result<String, Nip21Error>
fn to_nostr_uri(&self) -> Result<String, Nip21Error>
nostr:<bech32> URI for this value. Read moreAuto Trait Implementations§
impl Freeze for PublicKey
impl RefUnwindSafe for PublicKey
impl Send for PublicKey
impl Sync for PublicKey
impl Unpin for PublicKey
impl UnsafeUnpin for PublicKey
impl UnwindSafe for PublicKey
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
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> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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
key and return true if they are equal.