Enum nostr_types::Identity

source ·
pub enum Identity {
    None,
    Public(PublicKey),
    Signer(Box<dyn Signer>),
}
Expand description

All states that your identity can be in

Variants§

§

None

No identity information

§

Public(PublicKey)

Public key only

§

Signer(Box<dyn Signer>)

Signer (locked or unlocked)

Implementations§

source§

impl Identity

source

pub fn from_public_key(pk: PublicKey) -> Self

New Identity from a public key

source

pub fn from_private_key( pk: PrivateKey, pass: &str, log_n: u8, ) -> Result<Self, Error>

New Identity from a private key

source

pub fn from_locked_parts(pk: PublicKey, epk: EncryptedPrivateKey) -> Self

New Identity from an encrypted private key and a public key

source

pub fn from_encrypted_private_key( epk: EncryptedPrivateKey, pass: &str, ) -> Result<Self, Error>

New Identity from an encrypted private key and its password

source

pub fn generate(password: &str, log_n: u8) -> Result<Self, Error>

Generate a new Identity

source

pub fn unlock(&mut self, password: &str) -> Result<(), Error>

Unlock

source

pub fn lock(&mut self)

Lock access to the private key

source

pub fn has_public_key(&self) -> bool

Has a public key

source

pub fn has_private_key(&self) -> bool

Has a private key

source

pub fn is_locked(&self) -> bool

Is the identity locked?

source

pub fn is_unlocked(&self) -> bool

Is the identity unlocked?

source

pub fn change_passphrase( &mut self, old: &str, new: &str, log_n: u8, ) -> Result<(), Error>

Change the passphrase used for locking access to the private key

source

pub fn public_key(&self) -> Option<PublicKey>

What is the public key?

source

pub fn encrypted_private_key(&self) -> Option<&EncryptedPrivateKey>

What is the signer’s encrypted private key?

source

pub fn sign_id(&self, id: Id) -> Result<Signature, Error>

Sign a 32-bit hash

source

pub fn sign(&self, message: &[u8]) -> Result<Signature, Error>

Sign a message (this hashes with SHA-256 first internally)

source

pub fn encrypt( &self, other: &PublicKey, plaintext: &str, algo: ContentEncryptionAlgorithm, ) -> Result<String, Error>

Encrypt

source

pub fn decrypt( &self, other: &PublicKey, ciphertext: &str, ) -> Result<String, Error>

Decrypt

source

pub fn nip44_conversation_key( &self, other: &PublicKey, ) -> Result<[u8; 32], Error>

Get NIP-44 conversation key

source

pub fn export_private_key_in_hex( &mut self, pass: &str, log_n: u8, ) -> Result<(String, bool), Error>

Export the private key in hex.

This returns a boolean indicating if the key security was downgraded. If it was, the caller should save the new self.encrypted_private_key()

We need the password and log_n parameters to possibly rebuild the EncryptedPrivateKey when downgrading key security

source

pub fn export_private_key_in_bech32( &mut self, pass: &str, log_n: u8, ) -> Result<(String, bool), Error>

Export the private key in bech32.

This returns a boolean indicating if the key security was downgraded. If it was, the caller should save the new self.encrypted_private_key()

We need the password and log_n parameters to possibly rebuild the EncryptedPrivateKey when downgrading key security

source

pub fn key_security(&self) -> Result<KeySecurity, Error>

Get the security level of the private key

source

pub fn upgrade(&mut self, pass: &str, log_n: u8) -> Result<(), Error>

Upgrade the encrypted private key to the latest format

source

pub fn create_metadata_event( &self, input: PreEvent, metadata: Metadata, ) -> Result<Event, Error>

Create an event that sets Metadata

source

pub fn create_zap_request_event( &self, recipient_pubkey: PublicKey, zapped_event: Option<Id>, millisatoshis: u64, relays: Vec<String>, content: String, ) -> Result<Event, Error>

Create a ZapRequest event These events are not published to nostr, they are sent to a lnurl.

source

pub fn decrypt_event_contents(&self, event: &Event) -> Result<String, Error>

Decrypt the contents of an event

source

pub fn unwrap_giftwrap(&self, event: &Event) -> Result<Rumor, Error>

If a gift wrap event, unwrap and return the inner Rumor

source

pub fn unwrap_giftwrap1(&self, event: &EventV1) -> Result<RumorV1, Error>

If a gift wrap event, unwrap and return the inner Rumor @deprecated for migrations only

source

pub fn unwrap_giftwrap2(&self, event: &EventV2) -> Result<RumorV2, Error>

If a gift wrap event, unwrap and return the inner Rumor @deprecated for migrations only

source

pub fn generate_delegation_signature( &self, delegated_pubkey: PublicKey, delegation_conditions: &DelegationConditions, ) -> Result<Signature, Error>

Generate delegation signature

source

pub fn giftwrap( &self, input: PreEvent, pubkey: PublicKey, ) -> Result<Event, Error>

Giftwrap an event

source

pub fn sign_event(&self, input: PreEvent) -> Result<Event, Error>

Sign an event

source

pub fn sign_event_with_pow( &self, input: PreEvent, zero_bits: u8, work_sender: Option<Sender<u8>>, ) -> Result<Event, Error>

Sign an event with Proof-of-Work

source

pub fn verify_delegation_signature( &self, delegated_pubkey: PublicKey, delegation_conditions: &DelegationConditions, signature: &Signature, ) -> Result<(), Error>

Verify delegation signature

Trait Implementations§

source§

impl Debug for Identity

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Identity

source§

fn default() -> Identity

Returns the “default value” for a type. Read more
source§

impl Send for Identity

source§

impl Sync for Identity

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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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

§

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.
§

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

§

fn vzip(self) -> V