pub struct Identity {
pub peer_id: PeerId,
pub libp2p_keypair: Keypair,
pub hpke_context: HpkeContext,
}Expand description
Represents the user’s identity, including their libp2p and HPKE keypairs.
Fields§
§peer_id: PeerIdThe user’s peer ID, derived from the libp2p public key.
libp2p_keypair: KeypairThe libp2p keypair.
hpke_context: HpkeContextThe HPKE context, containing the HPKE keypair.
Implementations§
Source§impl Identity
impl Identity
Sourcepub fn generate() -> Result<Self>
pub fn generate() -> Result<Self>
Generates a new identity.
This will create a new Identity with a randomly generated libp2p Ed25519
keypair and an HPKE X25519 keypair.
§Errors
This function will return an error if key generation fails.
Sourcepub fn load_or_generate(path: &str) -> Result<Self>
pub fn load_or_generate(path: &str) -> Result<Self>
Sourcepub fn hpke_public_key(&self) -> Vec<u8> ⓘ
pub fn hpke_public_key(&self) -> Vec<u8> ⓘ
Returns the HPKE public key bytes.
Sourcepub fn encrypt_for(
&self,
recipient_public_key: &[u8],
plaintext: &[u8],
) -> Result<Vec<u8>>
pub fn encrypt_for( &self, recipient_public_key: &[u8], plaintext: &[u8], ) -> Result<Vec<u8>>
Encrypts a message for a recipient using their public key.
§Arguments
recipient_public_key- The public key of the recipient.plaintext- The data to encrypt. This function will return an error if encryption fails.
Auto Trait Implementations§
impl Freeze for Identity
impl RefUnwindSafe for Identity
impl Send for Identity
impl Sync for Identity
impl Unpin for Identity
impl UnwindSafe for Identity
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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