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,
) -> Self
pub fn from_bytes( signing: &SigningSecretKey, recipient: &RecipientSecretKey, ) -> Self
Create from raw key bytes (backward-compatible: no Nostr key)
Sourcepub fn from_bytes_with_nostr(
signing: &SigningSecretKey,
recipient: &RecipientSecretKey,
nostr: NostrSecretKey,
) -> Self
pub fn from_bytes_with_nostr( signing: &SigningSecretKey, recipient: &RecipientSecretKey, nostr: NostrSecretKey, ) -> Self
Create from raw key bytes including a Nostr key
Sourcepub fn from_seed(seed: &IdentitySeed) -> Result<Self, IdentityError>
pub fn from_seed(seed: &IdentitySeed) -> Result<Self, 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<(Self, String), IdentityError>
pub fn generate_with_mnemonic() -> Result<(Self, 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().