Trait nostr_types::Signer
source · pub trait Signer: Debug {
Show 28 methods
// Required methods
fn is_locked(&self) -> bool;
fn unlock(&mut self, password: &str) -> Result<(), Error>;
fn lock(&mut self);
fn change_passphrase(
&mut self,
old: &str,
new: &str,
log_n: u8,
) -> Result<(), Error>;
fn upgrade(&mut self, pass: &str, log_n: u8) -> Result<(), Error>;
fn public_key(&self) -> PublicKey;
fn encrypted_private_key(&self) -> Option<&EncryptedPrivateKey>;
fn sign_id(&self, id: Id) -> Result<Signature, Error>;
fn sign(&self, message: &[u8]) -> Result<Signature, Error>;
fn encrypt(
&self,
other: &PublicKey,
plaintext: &str,
algo: ContentEncryptionAlgorithm,
) -> Result<String, Error>;
fn decrypt(
&self,
other: &PublicKey,
ciphertext: &str,
) -> Result<String, Error>;
fn nip44_conversation_key(
&self,
other: &PublicKey,
) -> Result<[u8; 32], Error>;
fn export_private_key_in_hex(
&mut self,
pass: &str,
log_n: u8,
) -> Result<(String, bool), Error>;
fn export_private_key_in_bech32(
&mut self,
pass: &str,
log_n: u8,
) -> Result<(String, bool), Error>;
fn key_security(&self) -> Result<KeySecurity, Error>;
// Provided methods
fn generate_delegation_signature(
&self,
delegated_pubkey: PublicKey,
delegation_conditions: &DelegationConditions,
) -> Result<Signature, Error> { ... }
fn verify_delegation_signature(
&self,
delegated_pubkey: PublicKey,
delegation_conditions: &DelegationConditions,
signature: &Signature,
) -> Result<(), Error> { ... }
fn sign_event(&self, input: PreEvent) -> Result<Event, Error> { ... }
fn sign_event2(&self, input: PreEventV2) -> Result<EventV2, Error> { ... }
fn sign_event_with_pow(
&self,
input: PreEvent,
zero_bits: u8,
work_sender: Option<Sender<u8>>,
) -> Result<Event, Error> { ... }
fn giftwrap(
&self,
input: PreEvent,
pubkey: PublicKey,
) -> Result<Event, Error> { ... }
fn giftwrap2(
&self,
input: PreEventV2,
pubkey: PublicKey,
) -> Result<EventV2, Error> { ... }
fn create_metadata_event(
&self,
input: PreEvent,
metadata: Metadata,
) -> Result<Event, Error> { ... }
fn create_zap_request_event(
&self,
recipient_pubkey: PublicKey,
zapped_event: Option<Id>,
millisatoshis: u64,
relays: Vec<String>,
content: String,
) -> Result<Event, Error> { ... }
fn decrypt_event_contents(&self, event: &Event) -> Result<String, Error> { ... }
fn unwrap_giftwrap(&self, event: &Event) -> Result<Rumor, Error> { ... }
fn unwrap_giftwrap2(&self, event: &EventV2) -> Result<RumorV2, Error> { ... }
fn unwrap_giftwrap1(&self, event: &EventV1) -> Result<RumorV1, Error> { ... }
}
Expand description
Signer operations
Required Methods§
sourcefn unlock(&mut self, password: &str) -> Result<(), Error>
fn unlock(&mut self, password: &str) -> Result<(), Error>
Try to unlock access to the private key
sourcefn change_passphrase(
&mut self,
old: &str,
new: &str,
log_n: u8,
) -> Result<(), Error>
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
sourcefn upgrade(&mut self, pass: &str, log_n: u8) -> Result<(), Error>
fn upgrade(&mut self, pass: &str, log_n: u8) -> Result<(), Error>
Upgrade the encrypted private key to the latest format
sourcefn public_key(&self) -> PublicKey
fn public_key(&self) -> PublicKey
What is the signer’s public key?
sourcefn encrypted_private_key(&self) -> Option<&EncryptedPrivateKey>
fn encrypted_private_key(&self) -> Option<&EncryptedPrivateKey>
What is the signer’s encrypted private key?
sourcefn sign(&self, message: &[u8]) -> Result<Signature, Error>
fn sign(&self, message: &[u8]) -> Result<Signature, Error>
Sign a message (this hashes with SHA-256 first internally)
sourcefn encrypt(
&self,
other: &PublicKey,
plaintext: &str,
algo: ContentEncryptionAlgorithm,
) -> Result<String, Error>
fn encrypt( &self, other: &PublicKey, plaintext: &str, algo: ContentEncryptionAlgorithm, ) -> Result<String, Error>
Encrypt
sourcefn decrypt(&self, other: &PublicKey, ciphertext: &str) -> Result<String, Error>
fn decrypt(&self, other: &PublicKey, ciphertext: &str) -> Result<String, Error>
Decrypt NIP-04 or NIP-44
sourcefn nip44_conversation_key(&self, other: &PublicKey) -> Result<[u8; 32], Error>
fn nip44_conversation_key(&self, other: &PublicKey) -> Result<[u8; 32], Error>
Get NIP-44 conversation key
sourcefn export_private_key_in_hex(
&mut self,
pass: &str,
log_n: u8,
) -> Result<(String, bool), Error>
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
sourcefn export_private_key_in_bech32(
&mut self,
pass: &str,
log_n: u8,
) -> Result<(String, bool), Error>
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
sourcefn key_security(&self) -> Result<KeySecurity, Error>
fn key_security(&self) -> Result<KeySecurity, Error>
Get the security level of the private key
Provided Methods§
sourcefn generate_delegation_signature(
&self,
delegated_pubkey: PublicKey,
delegation_conditions: &DelegationConditions,
) -> Result<Signature, Error>
fn generate_delegation_signature( &self, delegated_pubkey: PublicKey, delegation_conditions: &DelegationConditions, ) -> Result<Signature, Error>
Generate delegation signature
sourcefn verify_delegation_signature(
&self,
delegated_pubkey: PublicKey,
delegation_conditions: &DelegationConditions,
signature: &Signature,
) -> Result<(), Error>
fn verify_delegation_signature( &self, delegated_pubkey: PublicKey, delegation_conditions: &DelegationConditions, signature: &Signature, ) -> Result<(), Error>
Verify delegation signature
sourcefn sign_event2(&self, input: PreEventV2) -> Result<EventV2, Error>
fn sign_event2(&self, input: PreEventV2) -> Result<EventV2, Error>
Sign an event
sourcefn sign_event_with_pow(
&self,
input: PreEvent,
zero_bits: u8,
work_sender: Option<Sender<u8>>,
) -> Result<Event, Error>
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
sourcefn giftwrap(&self, input: PreEvent, pubkey: PublicKey) -> Result<Event, Error>
fn giftwrap(&self, input: PreEvent, pubkey: PublicKey) -> Result<Event, Error>
Giftwrap an event
sourcefn giftwrap2(
&self,
input: PreEventV2,
pubkey: PublicKey,
) -> Result<EventV2, Error>
fn giftwrap2( &self, input: PreEventV2, pubkey: PublicKey, ) -> Result<EventV2, Error>
Giftwrap an event
sourcefn create_metadata_event(
&self,
input: PreEvent,
metadata: Metadata,
) -> Result<Event, Error>
fn create_metadata_event( &self, input: PreEvent, metadata: Metadata, ) -> Result<Event, Error>
Create an event that sets Metadata
sourcefn create_zap_request_event(
&self,
recipient_pubkey: PublicKey,
zapped_event: Option<Id>,
millisatoshis: u64,
relays: Vec<String>,
content: String,
) -> Result<Event, Error>
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.
sourcefn decrypt_event_contents(&self, event: &Event) -> Result<String, Error>
fn decrypt_event_contents(&self, event: &Event) -> Result<String, Error>
Decrypt the contents of an event
sourcefn unwrap_giftwrap(&self, event: &Event) -> Result<Rumor, Error>
fn unwrap_giftwrap(&self, event: &Event) -> Result<Rumor, Error>
If a gift wrap event, unwrap and return the inner Rumor