Identity

Struct Identity 

Source
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: Keypair

The Ed25519 keypair. Treat as secret — never log or serialise directly.

§peer_id: PeerId

libp2p peer identifier derived deterministically from the public key.

§fingerprint: String

Hex-encoded SHA-256(pubkey)[0..8] — 16 characters, immutable for this identity.

§profile: UserProfile

Persisted profile (alias, creation timestamp, etc.).

Implementations§

Source§

impl Identity

Source

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).

Source

pub fn load(passphrase: Option<&str>) -> BpResult<Self>

Load existing identity from disk.

  • If identity.key.enc exists, passphrase is required. Passing None returns BpError::Identity with a descriptive message.
  • If identity.key exists (plaintext), the passphrase argument is ignored.
  • If neither file exists, returns BpError::NotAuthenticated.
Source

pub fn remove() -> BpResult<()>

Remove identity from disk (logout). Removes both plaintext and encrypted key files if present, plus the profile.

Source

pub fn exists() -> BpResult<bool>

Returns true if any identity (plaintext or encrypted) is stored on disk.

Source

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.

Source

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.

Source

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§

Source§

impl Clone for Identity

Source§

fn clone(&self) -> Identity

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

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

Performs copy-assignment from source. Read more

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
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