pub struct Identity { /* private fields */ }Expand description
An identity containing signing, recipient, and optional Nostr keys
signing: Ed25519 key for creating digital signaturesrecipient: X25519 key for receiving encrypted messages via ECIESnostr: Optional secp256k1 key for Nostr transport (Phase 2)
Implementations§
Source§impl Identity
impl Identity
Sourcepub fn from_bytes(
signing: &SigningSecretKey,
recipient: &RecipientSecretKey,
) -> Identity
pub fn from_bytes( signing: &SigningSecretKey, recipient: &RecipientSecretKey, ) -> Identity
Create from raw key bytes (backward-compatible: no Nostr key)
Sourcepub fn from_bytes_with_nostr(
signing: &SigningSecretKey,
recipient: &RecipientSecretKey,
nostr: NostrSecretKey,
) -> Identity
pub fn from_bytes_with_nostr( signing: &SigningSecretKey, recipient: &RecipientSecretKey, nostr: NostrSecretKey, ) -> Identity
Create from raw key bytes including a Nostr key
Sourcepub fn from_seed(seed: &IdentitySeed) -> Result<Identity, IdentityError>
pub fn from_seed(seed: &IdentitySeed) -> Result<Identity, IdentityError>
Create an identity from a BIP-39 seed using deterministic key derivation.
The same seed always produces the same signing, recipient, and Nostr keys, enabling identity recovery from a mnemonic phrase.
Sourcepub fn generate_with_mnemonic() -> Result<(Identity, String), IdentityError>
pub fn generate_with_mnemonic() -> Result<(Identity, String), IdentityError>
Generate a new identity with a BIP-39 mnemonic for recovery.
Returns the identity and the 24-word mnemonic phrase. The mnemonic must be stored securely by the user — it’s the only way to recover the identity if the encrypted key files are lost.
Sourcepub fn signing_pubkey(&self) -> SigningPubKey
pub fn signing_pubkey(&self) -> SigningPubKey
Get the Ed25519 signing public key
Sourcepub fn recipient_pubkey(&self) -> RecipientPubKey
pub fn recipient_pubkey(&self) -> RecipientPubKey
Get the X25519 recipient public key
Sourcepub fn signing_key_bytes(&self) -> SigningSecretKey
pub fn signing_key_bytes(&self) -> SigningSecretKey
Get the raw signing key bytes (for storage)
Sourcepub fn signing_key(&self) -> &SigningKey
pub fn signing_key(&self) -> &SigningKey
Get the Ed25519 signing key (for signing operations)
Sourcepub fn recipient_key_bytes(&self) -> RecipientSecretKey
pub fn recipient_key_bytes(&self) -> RecipientSecretKey
Get the raw recipient key bytes (for storage)
Sourcepub fn nostr_pubkey(&self) -> Option<NostrPubKey>
pub fn nostr_pubkey(&self) -> Option<NostrPubKey>
Get the Nostr x-only public key (if present)
Sourcepub fn nostr_key_bytes(&self) -> Option<NostrSecretKey>
pub fn nostr_key_bytes(&self) -> Option<NostrSecretKey>
Get the raw Nostr secret key bytes (for storage)
Sourcepub fn verify(
pubkey: &SigningPubKey,
message: &[u8],
signature: &[u8; 64],
) -> bool
pub fn verify( pubkey: &SigningPubKey, message: &[u8], signature: &[u8; 64], ) -> bool
Verify a signature (static method, doesn’t need identity)
Sourcepub fn encrypt_for(
recipient_pubkey: &RecipientPubKey,
plaintext: &[u8],
) -> Result<Vec<u8>, IdentityError>
pub fn encrypt_for( recipient_pubkey: &RecipientPubKey, plaintext: &[u8], ) -> Result<Vec<u8>, IdentityError>
ECIES encrypt for a recipient (static - anyone can encrypt to a pubkey)
Format: ephemeral_pubkey (32) || nonce (12) || ciphertext || tag (16)
Uses X25519 DH + HKDF-SHA256 + AES-256-GCM
Sourcepub fn decrypt(&self, ciphertext: &[u8]) -> Result<Vec<u8>, IdentityError>
pub fn decrypt(&self, ciphertext: &[u8]) -> Result<Vec<u8>, IdentityError>
ECIES decrypt with our recipient key
Sourcepub fn to_identity_string(&self) -> String
pub fn to_identity_string(&self) -> String
Format identity pubkeys as shareable string
Format: void://ed25519:<hex>/x25519:<hex>[/nostr:<hex>]
Sourcepub fn to_identity_string_with_username(&self, username: &str) -> String
pub fn to_identity_string_with_username(&self, username: &str) -> String
Format identity pubkeys with username as shareable string
Format: void://alice@ed25519:<hex>/x25519:<hex>[/nostr:<hex>]
Sourcepub fn parse_identity_string(s: &str) -> Result<ParsedIdentity, IdentityError>
pub fn parse_identity_string(s: &str) -> Result<ParsedIdentity, IdentityError>
Parse identity string into a ParsedIdentity with optional username.
Supports formats (all backward-compatible):
void://ed25519:<hex>/x25519:<hex>(legacy, no nostr)void://ed25519:<hex>/x25519:<hex>/nostr:<hex>(with nostr)void://alice@ed25519:<hex>/x25519:<hex>[/nostr:<hex>](with username)
Sourcepub fn parse_identity_string_full(
s: &str,
) -> Result<ParsedIdentity, IdentityError>
pub fn parse_identity_string_full( s: &str, ) -> Result<ParsedIdentity, IdentityError>
Backward-compatible alias for parse_identity_string().
Auto Trait Implementations§
impl Freeze for Identity
impl RefUnwindSafe for Identity
impl Send for Identity
impl Sync for Identity
impl Unpin for Identity
impl UnsafeUnpin for Identity
impl UnwindSafe for Identity
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more