Struct PrivateKey

Source
pub struct PrivateKey(/* private fields */);
Expand description

This is a private key which is to be kept secret and is used to prove identity

Implementations§

Source§

impl PrivateKey

Source

pub fn export_encrypted( &self, password: &str, log2_rounds: u8, ) -> Result<EncryptedPrivateKey, Error>

Export in a (non-portable) encrypted form. This does not downgrade the security of the key, but you are responsible to keep it encrypted. You should not attempt to decrypt it, only use import_encrypted() on it, or something similar in another library/client which also respects key security.

This currently exports into EncryptedPrivateKey version 2.

We recommend you zeroize() the password you pass in after you are done with it.

Source

pub fn import_encrypted( encrypted: &EncryptedPrivateKey, password: &str, ) -> Result<PrivateKey, Error>

Import an encrypted private key which was exported with export_encrypted().

We recommend you zeroize() the password you pass in after you are done with it.

This is backwards-compatible with keys that were exported with older code.

Source§

impl PrivateKey

Source

pub fn shared_secret( &self, other: &PublicKey, algo: ContentEncryptionAlgorithm, ) -> [u8; 32]

Get the shared secret

Source

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

Encrypt

Source

pub fn detect_encryption_algorithm( ciphertext: &str, ) -> ContentEncryptionAlgorithm

Detect encryption algorithm of ciphertext

Source

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

Decrypt (detects encryption version)

Source

pub fn decrypt_nip04( &self, other: &PublicKey, ciphertext: &str, ) -> Result<Vec<u8>, Error>

Decrypt NIP-04 only

Source

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

Decrypt NIP-44 only, version is detected

Source§

impl PrivateKey

Source

pub fn new() -> PrivateKey

Generate a new PrivateKey (which can be used to get the PublicKey)

Source

pub fn generate() -> PrivateKey

Generate a new PrivateKey (which can be used to get the PublicKey)

Source

pub fn public_key(&self) -> PublicKey

Get the PublicKey matching this PrivateKey

Source

pub fn key_security(&self) -> KeySecurity

Get the security level of the private key

Source

pub fn as_hex_string(&mut self) -> String

Render into a hexadecimal string

WARNING: This weakens the security of your key. Your key will be marked with KeySecurity::Weak if you execute this.

Source

pub fn try_from_hex_string(v: &str) -> Result<PrivateKey, Error>

Create from a hexadecimal string

This creates a key with KeySecurity::Weak. Use generate() or import_encrypted() for KeySecurity::Medium

Source

pub fn as_bech32_string(&mut self) -> String

Export as a bech32 encoded string

WARNING: This weakens the security of your key. Your key will be marked with KeySecurity::Weak if you execute this.

Source

pub fn try_from_bech32_string(s: &str) -> Result<PrivateKey, Error>

Import from a bech32 encoded string

This creates a key with KeySecurity::Weak. Use generate() or import_encrypted() for KeySecurity::Medium

Source

pub fn as_secret_key(&self) -> SecretKey

As a secp256k1::SecretKey

Trait Implementations§

Source§

impl Clone for PrivateKey

Source§

fn clone(&self) -> PrivateKey

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PrivateKey

Source§

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

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

impl Default for PrivateKey

Source§

fn default() -> Self

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

impl Drop for PrivateKey

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl MutExportableSigner for PrivateKey

Source§

fn export_private_key_in_hex<'life0, 'life1, 'async_trait>( &'life0 mut self, _pass: &'life1 str, _log_n: u8, ) -> Pin<Box<dyn Future<Output = Result<(String, bool), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Export the private key in hex. Read more
Source§

fn export_private_key_in_bech32<'life0, 'life1, 'async_trait>( &'life0 mut self, _pass: &'life1 str, _log_n: u8, ) -> Pin<Box<dyn Future<Output = Result<(String, bool), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Export the private key in bech32. Read more
Source§

impl Signer for PrivateKey

Source§

fn decrypt<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, other: &'life1 PublicKey, ciphertext: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Decrypt NIP-44

Source§

fn public_key(&self) -> PublicKey

What is the signer’s public key?
Source§

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

What is the signer’s encrypted private key?
Source§

fn sign_event<'life0, 'async_trait>( &'life0 self, input: PreEvent, ) -> Pin<Box<dyn Future<Output = Result<Event, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Sign an event
Source§

fn encrypt<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, other: &'life1 PublicKey, plaintext: &'life2 str, algo: ContentEncryptionAlgorithm, ) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Encrypt
Source§

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

Get the security level of the private key
Source§

fn giftwrap<'life0, 'async_trait>( &'life0 self, input: PreEvent, pubkey: PublicKey, ) -> Pin<Box<dyn Future<Output = Result<Event, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Giftwrap an event
Source§

fn create_metadata_event<'life0, 'async_trait>( &'life0 self, input: PreEvent, metadata: Metadata, ) -> Pin<Box<dyn Future<Output = Result<Event, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Create an event that sets Metadata
Source§

fn create_zap_request_event<'life0, 'async_trait>( &'life0 self, recipient_pubkey: PublicKey, zapped_event: Option<Id>, millisatoshis: u64, relays: Vec<String>, content: String, ) -> Pin<Box<dyn Future<Output = Result<Event, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

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

fn decrypt_event_contents<'life0, 'life1, 'async_trait>( &'life0 self, event: &'life1 Event, ) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Decrypt the contents of an event
Source§

fn unwrap_giftwrap<'life0, 'life1, 'async_trait>( &'life0 self, event: &'life1 Event, ) -> Pin<Box<dyn Future<Output = Result<Rumor, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

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

impl SignerExt for PrivateKey

Source§

fn sign_id<'life0, 'async_trait>( &'life0 self, id: Id, ) -> Pin<Box<dyn Future<Output = Result<Signature, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Sign a 32-bit hash asynchronously
Source§

fn sign<'life0, 'life1, 'async_trait>( &'life0 self, message: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<Signature, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

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

fn nip44_conversation_key<'life0, 'life1, 'async_trait>( &'life0 self, other: &'life1 PublicKey, ) -> Pin<Box<dyn Future<Output = Result<[u8; 32], Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get NIP-44 conversation key
Source§

fn generate_delegation_signature<'life0, 'life1, 'async_trait>( &'life0 self, delegated_pubkey: PublicKey, delegation_conditions: &'life1 DelegationConditions, ) -> Pin<Box<dyn Future<Output = Result<Signature, Error>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Generate delegation signature
Source§

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

Verify delegation signature
Source§

fn sign_event_with_pow<'life0, 'async_trait>( &'life0 self, input: PreEvent, zero_bits: u8, work_sender: Option<Sender<u8>>, ) -> Pin<Box<dyn Future<Output = Result<Event, Error>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait,

Sign an event with Proof-of-Work

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T