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
impl Identity
sourcepub fn from_public_key(pk: PublicKey) -> Self
pub fn from_public_key(pk: PublicKey) -> Self
New Identity
from a public key
sourcepub fn from_private_key(
pk: PrivateKey,
pass: &str,
log_n: u8,
) -> Result<Self, Error>
pub fn from_private_key( pk: PrivateKey, pass: &str, log_n: u8, ) -> Result<Self, Error>
New Identity
from a private key
sourcepub fn from_locked_parts(pk: PublicKey, epk: EncryptedPrivateKey) -> Self
pub fn from_locked_parts(pk: PublicKey, epk: EncryptedPrivateKey) -> Self
New Identity
from an encrypted private key and a public key
sourcepub fn from_encrypted_private_key(
epk: EncryptedPrivateKey,
pass: &str,
) -> Result<Self, Error>
pub fn from_encrypted_private_key( epk: EncryptedPrivateKey, pass: &str, ) -> Result<Self, Error>
New Identity
from an encrypted private key and its password
sourcepub fn has_public_key(&self) -> bool
pub fn has_public_key(&self) -> bool
Has a public key
sourcepub fn has_private_key(&self) -> bool
pub fn has_private_key(&self) -> bool
Has a private key
sourcepub fn is_unlocked(&self) -> bool
pub fn is_unlocked(&self) -> bool
Is the identity unlocked?
sourcepub fn change_passphrase(
&mut self,
old: &str,
new: &str,
log_n: u8,
) -> Result<(), Error>
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
sourcepub fn public_key(&self) -> Option<PublicKey>
pub fn public_key(&self) -> Option<PublicKey>
What is the public key?
sourcepub fn encrypted_private_key(&self) -> Option<&EncryptedPrivateKey>
pub fn encrypted_private_key(&self) -> Option<&EncryptedPrivateKey>
What is the signer’s encrypted private key?
sourcepub fn sign(&self, message: &[u8]) -> Result<Signature, Error>
pub fn sign(&self, message: &[u8]) -> Result<Signature, Error>
Sign a message (this hashes with SHA-256 first internally)
sourcepub fn encrypt(
&self,
other: &PublicKey,
plaintext: &str,
algo: ContentEncryptionAlgorithm,
) -> Result<String, Error>
pub fn encrypt( &self, other: &PublicKey, plaintext: &str, algo: ContentEncryptionAlgorithm, ) -> Result<String, Error>
Encrypt
sourcepub fn nip44_conversation_key(
&self,
other: &PublicKey,
) -> Result<[u8; 32], Error>
pub fn nip44_conversation_key( &self, other: &PublicKey, ) -> Result<[u8; 32], Error>
Get NIP-44 conversation key
sourcepub fn export_private_key_in_hex(
&mut self,
pass: &str,
log_n: u8,
) -> Result<(String, bool), Error>
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
sourcepub fn export_private_key_in_bech32(
&mut self,
pass: &str,
log_n: u8,
) -> Result<(String, bool), Error>
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
sourcepub fn key_security(&self) -> Result<KeySecurity, Error>
pub fn key_security(&self) -> Result<KeySecurity, Error>
Get the security level of the private key
sourcepub fn upgrade(&mut self, pass: &str, log_n: u8) -> Result<(), Error>
pub fn upgrade(&mut self, pass: &str, log_n: u8) -> Result<(), Error>
Upgrade the encrypted private key to the latest format
sourcepub fn create_metadata_event(
&self,
input: PreEvent,
metadata: Metadata,
) -> Result<Event, Error>
pub fn create_metadata_event( &self, input: PreEvent, metadata: Metadata, ) -> Result<Event, Error>
Create an event that sets Metadata
sourcepub fn create_zap_request_event(
&self,
recipient_pubkey: PublicKey,
zapped_event: Option<Id>,
millisatoshis: u64,
relays: Vec<String>,
content: String,
) -> Result<Event, Error>
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.
sourcepub fn decrypt_event_contents(&self, event: &Event) -> Result<String, Error>
pub fn decrypt_event_contents(&self, event: &Event) -> Result<String, Error>
Decrypt the contents of an event
sourcepub fn unwrap_giftwrap(&self, event: &Event) -> Result<Rumor, Error>
pub fn unwrap_giftwrap(&self, event: &Event) -> Result<Rumor, Error>
If a gift wrap event, unwrap and return the inner Rumor
sourcepub fn unwrap_giftwrap1(&self, event: &EventV1) -> Result<RumorV1, Error>
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
sourcepub fn unwrap_giftwrap2(&self, event: &EventV2) -> Result<RumorV2, Error>
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
sourcepub fn generate_delegation_signature(
&self,
delegated_pubkey: PublicKey,
delegation_conditions: &DelegationConditions,
) -> Result<Signature, Error>
pub fn generate_delegation_signature( &self, delegated_pubkey: PublicKey, delegation_conditions: &DelegationConditions, ) -> Result<Signature, Error>
Generate delegation signature
sourcepub fn giftwrap(
&self,
input: PreEvent,
pubkey: PublicKey,
) -> Result<Event, Error>
pub fn giftwrap( &self, input: PreEvent, pubkey: PublicKey, ) -> Result<Event, Error>
Giftwrap an event
sourcepub fn sign_event_with_pow(
&self,
input: PreEvent,
zero_bits: u8,
work_sender: Option<Sender<u8>>,
) -> Result<Event, Error>
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
sourcepub fn verify_delegation_signature(
&self,
delegated_pubkey: PublicKey,
delegation_conditions: &DelegationConditions,
signature: &Signature,
) -> Result<(), Error>
pub fn verify_delegation_signature( &self, delegated_pubkey: PublicKey, delegation_conditions: &DelegationConditions, signature: &Signature, ) -> Result<(), Error>
Verify delegation signature