Skip to main content

Identity

Struct Identity 

Source
pub struct Identity { /* private fields */ }
Expand description

An identity containing signing, recipient, and optional Nostr keys

  • signing: Ed25519 key for creating digital signatures
  • recipient: X25519 key for receiving encrypted messages via ECIES
  • nostr: Optional secp256k1 key for Nostr transport (Phase 2)

Implementations§

Source§

impl Identity

Source

pub fn generate() -> Identity

Generate a new random identity (including Nostr key)

Source

pub fn from_bytes( signing: &SigningSecretKey, recipient: &RecipientSecretKey, ) -> Identity

Create from raw key bytes (backward-compatible: no Nostr key)

Source

pub fn from_bytes_with_nostr( signing: &SigningSecretKey, recipient: &RecipientSecretKey, nostr: NostrSecretKey, ) -> Identity

Create from raw key bytes including a Nostr key

Source

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.

Source

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.

Source

pub fn signing_pubkey(&self) -> SigningPubKey

Get the Ed25519 signing public key

Source

pub fn recipient_pubkey(&self) -> RecipientPubKey

Get the X25519 recipient public key

Source

pub fn signing_key_bytes(&self) -> SigningSecretKey

Get the raw signing key bytes (for storage)

Source

pub fn signing_key(&self) -> &SigningKey

Get the Ed25519 signing key (for signing operations)

Source

pub fn recipient_key_bytes(&self) -> RecipientSecretKey

Get the raw recipient key bytes (for storage)

Source

pub fn nostr_pubkey(&self) -> Option<NostrPubKey>

Get the Nostr x-only public key (if present)

Source

pub fn nostr_key_bytes(&self) -> Option<NostrSecretKey>

Get the raw Nostr secret key bytes (for storage)

Source

pub fn sign(&self, message: &[u8]) -> [u8; 64]

Sign a message with Ed25519

Source

pub fn verify( pubkey: &SigningPubKey, message: &[u8], signature: &[u8; 64], ) -> bool

Verify a signature (static method, doesn’t need identity)

Source

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

Source

pub fn decrypt(&self, ciphertext: &[u8]) -> Result<Vec<u8>, IdentityError>

ECIES decrypt with our recipient key

Source

pub fn to_identity_string(&self) -> String

Format identity pubkeys as shareable string

Format: void://ed25519:<hex>/x25519:<hex>[/nostr:<hex>]

Source

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>]

Source

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)
Source

pub fn parse_identity_string_full( s: &str, ) -> Result<ParsedIdentity, IdentityError>

Backward-compatible alias for parse_identity_string().

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V