Skip to main content

User

Struct User 

Source
pub struct User { /* private fields */ }
Expand description

Authenticated user with shared session state Clones share the same underlying session — leave() invalidates all holders.

Implementations§

Source§

impl User

Source

pub async fn create( alias: &str, pass: &str, db: &mut Node, ) -> Result<Self, SeaError>

Create a new user with alias and password. Stores encrypted key pair in BEAM’s graph at ~@alias.

Source

pub async fn auth( alias: &str, pass: &str, db: &mut Node, ) -> Result<Self, SeaError>

Authenticate existing user from BEAM’s graph.

Source

pub fn from_pair(pair: KeyPair, alias: Option<&str>) -> Self

Create user directly from existing key pair.

Source

pub async fn recall( alias: &str, storage: &dyn SessionStorage, ) -> Result<Self, SeaError>

Recall user from session storage.

Source

pub async fn save_to( &self, storage: &dyn SessionStorage, ) -> Result<(), SeaError>

Save current session to storage.

Note: clones the KeyPair and alias out of the session lock before awaiting storage.save(...) to keep the future Send. Holding the std::sync::RwLock read guard across an .await would make the returned future non-Send (the std guard is not Send), which breaks callers that need to await auth flows while holding a tokio lock (e.g. the MCP identity_auth tool).

Source§

impl User

Source

pub async fn trust( &self, recipient_pubkey: &str, path: Option<&str>, db: &mut Node, ) -> Result<(), SeaError>

Delegate write trust to a recipient for an optional path. Stores a capability certificate at ~{pub}/trust/{path}.

Source

pub async fn grant( &self, recipient_pubkey: &str, recipient_epub: &str, data_path: &str, db: &mut Node, ) -> Result<(), SeaError>

Grant a recipient access to decrypt data at a path. Stores signed ECDH-encrypted copies at ~{pub}/grant/{path}/{recipient} and ~{pub}/grant/{path}/{my_pub}.

Source

pub async fn secret( &self, data: &JsonValue, path: &str, db: &mut Node, ) -> Result<(), SeaError>

Encrypt and store data under a self-derived symmetric key. Only this user can decrypt it — the key comes from ECDH(self.pub, self.priv). Stored at ~{pub}/secret/{path_key} as a signed payload.

Source§

impl User

Source

pub fn from_state(state: SessionState) -> Self

Source

pub fn pub_key(&self) -> String

Source

pub fn pair(&self) -> KeyPair

Source

pub fn alias(&self) -> Option<String>

Source

pub fn is_authenticated(&self) -> bool

Source

pub fn is(&self) -> Option<Identity>

Return the user’s identity if authenticated. Mirrors Gun.js user.is — returns alias, pub, epub or None.

Source

pub fn leave(&self)

Clear key pair from memory and mark unauthenticated (all clones invalidated)

Trait Implementations§

Source§

impl Clone for User

Source§

fn clone(&self) -> User

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for User

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for User

§

impl RefUnwindSafe for User

§

impl Send for User

§

impl Sync for User

§

impl Unpin for User

§

impl UnsafeUnpin for User

§

impl UnwindSafe for User

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V