pub struct Identity {
pub keypair: Keypair,
pub peer_id: PeerId,
pub fingerprint: String,
pub profile: UserProfile,
}Expand description
In-memory identity: the loaded keypair and all derived or persisted metadata.
Constructed either by Identity::generate (first login) or
Identity::load (subsequent daemon starts).
Identity does not implement Debug because libp2p::identity::Keypair
does not expose a Debug impl (the bytes are considered secret).
Fields§
§keypair: KeypairThe Ed25519 keypair. Treat as secret — never log or serialise directly.
peer_id: PeerIdlibp2p peer identifier derived deterministically from the public key.
fingerprint: StringHex-encoded SHA-256(pubkey)[0..8] — 16 characters, immutable for this identity.
profile: UserProfilePersisted profile (alias, creation timestamp, etc.).
Implementations§
Source§impl Identity
impl Identity
Sourcepub fn generate(
alias: Option<String>,
passphrase: Option<&str>,
) -> BpResult<Self>
pub fn generate( alias: Option<String>, passphrase: Option<&str>, ) -> BpResult<Self>
Generate a brand-new Ed25519 identity and persist it.
If passphrase is Some, the keypair is encrypted with Argon2id +
ChaCha20-Poly1305 and written to identity.key.enc. If None, the
raw protobuf bytes are written to identity.key (backwards-compatible).
Sourcepub fn load(passphrase: Option<&str>) -> BpResult<Self>
pub fn load(passphrase: Option<&str>) -> BpResult<Self>
Load existing identity from disk.
- If
identity.key.encexists,passphraseis required. PassingNonereturnsBpError::Identitywith a descriptive message. - If
identity.keyexists (plaintext), thepassphraseargument is ignored. - If neither file exists, returns
BpError::NotAuthenticated.
Sourcepub fn remove() -> BpResult<()>
pub fn remove() -> BpResult<()>
Remove identity from disk (logout). Removes both plaintext and encrypted key files if present, plus the profile.
Sourcepub fn exists() -> BpResult<bool>
pub fn exists() -> BpResult<bool>
Returns true if any identity (plaintext or encrypted) is stored on disk.
Sourcepub fn secret_material(&self) -> [u8; 32]
pub fn secret_material(&self) -> [u8; 32]
Derive 32 bytes of secret material from the keypair.
Used as the master input for per-file Content Encryption Key (CEK) derivation. The output is deterministic for a given keypair but must never be stored or logged — treat it like the private key itself.
Sourcepub fn export_to_file(dest: &Path) -> BpResult<()>
pub fn export_to_file(dest: &Path) -> BpResult<()>
Export this identity to a portable JSON file at dest.
The on-disk key files are copied verbatim: passphrase-protected
identities export the encrypted form (no passphrase needed here);
plaintext identities hex-encode the raw protobuf bytes.
The output file is safe to transfer to another machine; use
Identity::import_from_file on the receiving end.
Sourcepub fn import_from_file(src: &Path, overwrite: bool) -> BpResult<UserProfile>
pub fn import_from_file(src: &Path, overwrite: bool) -> BpResult<UserProfile>
Import an identity from a portable export file created by
Identity::export_to_file.
Installs the keypair and profile to the XDG data directory.
Returns the imported UserProfile on success.
If an identity already exists and overwrite is false, returns
BpError::Config with a message asking the user to bp logout first.
Trait Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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