pub struct DidNostr(/* private fields */);Expand description
A did:nostr principal over a 32-byte x-only secp256k1 public key.
Every value holds a key that is a valid BIP-340 x-only point, so a
DidNostr can always be used to verify a signature. The canonical text
form is did:nostr: followed by 64 lowercase hexadecimal digits, which is
what Display, FromStr and serde use. Ordering and
hashing follow the key bytes, which agrees with the order of the hex text.
§Examples
use stratum_node_core::DidNostr;
let did: DidNostr =
"did:nostr:79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798".parse()?;
assert_eq!(DidNostr::from_npub(&did.to_npub())?, did);
assert_eq!(DidNostr::from_hex(&did.to_hex())?, did);Implementations§
Source§impl DidNostr
impl DidNostr
Sourcepub fn from_bytes(bytes: [u8; 32]) -> Result<Self, ParseDidError>
pub fn from_bytes(bytes: [u8; 32]) -> Result<Self, ParseDidError>
Builds a principal from the raw 32-byte x-only public key.
§Errors
Returns ParseDidError::NotOnCurve when the bytes are not the
x-coordinate of a point on secp256k1.
Sourcepub fn from_hex(hex: &str) -> Result<Self, ParseDidError>
pub fn from_hex(hex: &str) -> Result<Self, ParseDidError>
Parses the key from 64 lowercase hexadecimal digits, with no prefix.
Uppercase digits are rejected so that each key has one text form.
§Errors
Returns ParseDidError::InvalidHex for anything other than 64
lowercase hex digits, and ParseDidError::NotOnCurve for a value
that is not a valid point.
Sourcepub fn from_npub(npub: &str) -> Result<Self, ParseDidError>
pub fn from_npub(npub: &str) -> Result<Self, ParseDidError>
Parses a NIP-19 npub1… bech32 public key.
§Errors
Returns ParseDidError::InvalidBech32 for a malformed string, a
bech32m checksum or non-zero padding bits (so each key has exactly
one accepted encoding, up to letter case), ParseDidError::WrongBech32Prefix for a prefix
other than npub, ParseDidError::InvalidLength when the payload
is not 32 bytes, and ParseDidError::NotOnCurve for a value that is
not a valid point.