pub struct SharedKey(/* private fields */);Expand description
Shared key derived via ECDH between two parties’ trade keys.
Internally a Keys instance whose secret is the 32-byte ECDH output of
(local_secret, counterparty_pubkey). Both sides of the conversation
derive an identical value and therefore an identical public key, which
is what gift wraps are addressed to.
Implementations§
Sourcepub fn derive(
secret: &SecretKey,
counterparty: &PublicKey,
) -> Result<Self, MostroError>
pub fn derive( secret: &SecretKey, counterparty: &PublicKey, ) -> Result<Self, MostroError>
Derive a shared key from a local secret key and the counterparty’s
public key using the secp256k1 ECDH primitive exposed by
nostr_sdk::util::generate_shared_key.
Both peers obtain the same SharedKey by swapping arguments
(A.derive(a_sk, b_pk) == B.derive(b_sk, a_pk)).
Sourcepub fn from_keys(keys: Keys) -> Self
pub fn from_keys(keys: Keys) -> Self
Build a SharedKey from an already-derived Keys value.
Useful when a client persists a freshly-generated Keys instead of
re-deriving it on every load.
Sourcepub fn public_key(&self) -> PublicKey
pub fn public_key(&self) -> PublicKey
Public key of this shared key — the value used as the p tag on
every gift wrap belonging to the channel.
Sourcepub fn secret_key(&self) -> &SecretKey
pub fn secret_key(&self) -> &SecretKey
Borrow the underlying secret key.
Sourcepub fn to_hex(&self) -> String
pub fn to_hex(&self) -> String
Serialize the secret as a lower-case hex string suitable for client
persistence. Pair with SharedKey::from_hex to round-trip.
Sourcepub fn from_hex(hex: &str) -> Result<Self, MostroError>
pub fn from_hex(hex: &str) -> Result<Self, MostroError>
Rebuild a SharedKey from a hex-encoded secret previously produced
by SharedKey::to_hex.
Trait Implementations§
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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