pub struct KeyDeriver { /* private fields */ }Expand description
Key derivation for BRC-42/BRC-43 protocols. KeyDeriver derives various types of keys using a root private key.
Supports deriving public and private keys, symmetric keys, and revealing key linkages, all using BRC-42 Type-42 derivation.
Implementations§
Source§impl KeyDeriver
impl KeyDeriver
Sourcepub fn new(private_key: PrivateKey) -> KeyDeriver
pub fn new(private_key: PrivateKey) -> KeyDeriver
Create a new KeyDeriver from a root private key.
Sourcepub fn new_anyone() -> KeyDeriver
pub fn new_anyone() -> KeyDeriver
Create a KeyDeriver using the special “anyone” key (PrivateKey(1)).
Sourcepub fn root_key(&self) -> &PrivateKey
pub fn root_key(&self) -> &PrivateKey
Returns a reference to the root private key.
Sourcepub fn identity_key(&self) -> PublicKey
pub fn identity_key(&self) -> PublicKey
Returns the public key corresponding to the root private key.
Sourcepub fn identity_key_hex(&self) -> String
pub fn identity_key_hex(&self) -> String
Returns the identity key as a compressed DER hex string.
Sourcepub fn derive_private_key(
&self,
protocol: &Protocol,
key_id: &str,
counterparty: &Counterparty,
) -> Result<PrivateKey, WalletError>
pub fn derive_private_key( &self, protocol: &Protocol, key_id: &str, counterparty: &Counterparty, ) -> Result<PrivateKey, WalletError>
Derive a private key for the given protocol, key ID, and counterparty.
Sourcepub fn derive_public_key(
&self,
protocol: &Protocol,
key_id: &str,
counterparty: &Counterparty,
for_self: bool,
) -> Result<PublicKey, WalletError>
pub fn derive_public_key( &self, protocol: &Protocol, key_id: &str, counterparty: &Counterparty, for_self: bool, ) -> Result<PublicKey, WalletError>
Derive a public key for the given protocol, key ID, and counterparty.
If for_self is true, derives the private child key first and returns
its public key. If false, derives directly on the counterparty’s public key.
Sourcepub fn derive_symmetric_key(
&self,
protocol: &Protocol,
key_id: &str,
counterparty: &Counterparty,
) -> Result<SymmetricKey, WalletError>
pub fn derive_symmetric_key( &self, protocol: &Protocol, key_id: &str, counterparty: &Counterparty, ) -> Result<SymmetricKey, WalletError>
Derive a symmetric key from the ECDH shared secret of the derived private and public keys.
The symmetric key is the x-coordinate of the shared secret point.
Sourcepub fn reveal_counterparty_secret(
&self,
counterparty: &Counterparty,
) -> Result<PublicKey, WalletError>
pub fn reveal_counterparty_secret( &self, counterparty: &Counterparty, ) -> Result<PublicKey, WalletError>
Reveal the counterparty shared secret as a public key point.
Cannot be used for counterparty type “self”.
Sourcepub fn reveal_specific_secret(
&self,
counterparty: &Counterparty,
protocol: &Protocol,
key_id: &str,
) -> Result<Vec<u8>, WalletError>
pub fn reveal_specific_secret( &self, counterparty: &Counterparty, protocol: &Protocol, key_id: &str, ) -> Result<Vec<u8>, WalletError>
Reveal a specific secret for the given protocol and key ID.
Computes HMAC-SHA256 of the shared secret (compressed) and the invoice number string.
Auto Trait Implementations§
impl Freeze for KeyDeriver
impl !RefUnwindSafe for KeyDeriver
impl Send for KeyDeriver
impl Sync for KeyDeriver
impl Unpin for KeyDeriver
impl UnsafeUnpin for KeyDeriver
impl !UnwindSafe for KeyDeriver
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> 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