Skip to main content

LocalIdentity

Struct LocalIdentity 

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

A locally held secret-key capability.

Secret bytes are parsed once and then owned by the upstream secret-bearing key type, whose destructor performs best-effort erasure. Debug never exposes secret material.

Implementations§

Source§

impl LocalIdentity

Source

pub fn create_user_metadata( &self, created_at: u64, name: Option<String>, display_name: Option<String>, about: Option<String>, picture: Option<String>, website: Option<String>, banner: Option<String>, bot: Option<bool>, unknown_json: &str, ) -> Result<UserMetadataView, SoftchatError>

Create canonical private kind-0 user metadata.

Unknown fields are supplied as a JSON object and retained unless they collide with the seven known fields.

§Errors

Returns SoftchatError::InvalidUserMetadata for malformed values.

Source

pub fn create_follow_list( &self, created_at: u64, contacts: Vec<Contact>, ) -> Result<FollowListView, SoftchatError>

Create a canonical private author-copy kind-3 contact backup.

§Errors

Returns SoftchatError::InvalidContactList for duplicate contacts, malformed relay hints, or excessive list size.

Source

pub fn create_application_data( &self, created_at: u64, identifier: String, content: String, ) -> Result<ApplicationDataView, SoftchatError>

Create a direct signed generic NIP-78 event.

§Errors

Returns SoftchatError::InvalidApplicationData for an empty identifier or an oversized event.

Source

pub fn create_app_data_sync( &self, created_at: u64, context: AppDataContext, json: &str, ) -> Result<AppDataSyncView, SoftchatError>

Create direct signed, self-encrypted Softchat application data.

§Errors

Returns SoftchatError::InvalidApplicationData for invalid JSON, bounds, encryption, or signing failure.

Source

pub fn decrypt_app_data_sync( &self, event: &SignedNostrEvent, ) -> Result<AppDataSyncView, SoftchatError>

Validate and self-decrypt one kind-30079 event.

§Errors

Returns SoftchatError::InvalidApplicationData unless the event is authored by this identity and all encrypted JSON authenticates.

Source§

impl LocalIdentity

Source

pub fn create_chat_message( &self, draft: ChatMessageDraft, ) -> Result<ChatMessageView, SoftchatError>

Create a canonical one-to-one or group kind-14 message rumor.

§Errors

Returns SoftchatError::SoftchatEventCreationFailed for invalid participants, relations, attachment metadata, or extension tags.

Source

pub fn create_subject( &self, draft: SubjectDraft, ) -> Result<SubjectView, SoftchatError>

Create a canonical subject update with dual Android/iOS icon tags.

§Errors

Returns SoftchatError::SoftchatEventCreationFailed for invalid input.

Source

pub fn create_reaction( &self, draft: ReactionDraft, ) -> Result<ReactionView, SoftchatError>

Create a canonical private reaction rumor.

§Errors

Returns a stable creation failure for malformed references or reaction.

Source

pub fn create_deletion( &self, participants: Vec<NostrPublicKey>, event_ids: Vec<NostrEventId>, reason: String, created_at: u64, ) -> Result<DeletionView, SoftchatError>

Create a canonical private deletion request.

§Errors

Returns a stable creation failure for empty, duplicate, or oversized IDs.

Source

pub fn create_edit( &self, participants: Vec<NostrPublicKey>, original_event_id: NostrEventId, content: String, emoji_tags: Vec<NostrTag>, created_at: u64, ) -> Result<EditView, SoftchatError>

Create a canonical text-and-emoji-only kind-1010 edit.

§Errors

Returns a stable creation failure for invalid participants or emoji tags.

Source

pub fn create_typing( &self, participants: Vec<NostrPublicKey>, created_at: u64, ) -> Result<TypingView, SoftchatError>

Create one ephemeral kind-21234 typing rumor.

§Errors

Returns a stable creation failure for an invalid participant set.

Source§

impl LocalIdentity

Source

pub fn from_secret_bytes(secret_key: &[u8]) -> Result<Self, SoftchatError>

Import a secret key from exactly 32 bytes.

The caller remains responsible for clearing its own input buffer after this synchronous import returns.

Guide and performance

§Errors

Returns SoftchatError::InvalidSecretKey for an invalid scalar.

Source

pub fn from_secret_hex(secret_key: &str) -> Result<Self, SoftchatError>

Import a secret key from exactly 64 hexadecimal characters.

This is retained for native Rust and legacy binding compatibility. Byte import is preferred for scoped foreign-language identities.

§Errors

Returns SoftchatError::InvalidSecretKey for an invalid scalar.

Source

pub fn public_key(&self) -> NostrPublicKey

Return this identity’s public key.

Guide and performance

Source

pub fn sign_event( &self, draft: NostrEventDraft, ) -> Result<SignedNostrEvent, SoftchatError>

Sign one explicit NIP-01 draft with this identity.

The draft’s timestamp, kind, tags, and content are preserved exactly. No hidden clock read or tag normalization occurs.

Guide and performance

§Errors

Returns a stable draft-validation, size, or signing failure.

Source

pub fn encrypt( &self, recipient: &NostrPublicKey, plaintext: &[u8], ) -> Result<Nip44EncryptedMessage, SoftchatError>

Encrypt arbitrary non-empty bytes with NIP-44 v2.

§Errors

Returns a stable validation or redacted encryption failure.

Source

pub fn encrypt_utf8( &self, recipient: &NostrPublicKey, plaintext: &str, ) -> Result<Nip44EncryptedMessage, SoftchatError>

Encrypt one non-empty UTF-8 string with NIP-44 v2.

Guide and performance

§Errors

Returns a stable validation or redacted encryption failure.

Source

pub fn decrypt( &self, message: &Nip44EncryptedMessage, ) -> Result<Vec<u8>, SoftchatError>

Authenticate and decrypt a NIP-44 message to bytes.

§Errors

All authentication, encoding, padding, and version failures map to SoftchatError::DecryptionFailed.

Source

pub fn decrypt_utf8( &self, message: &Nip44EncryptedMessage, ) -> Result<String, SoftchatError>

Authenticate and decrypt a NIP-44 message as UTF-8.

Guide and performance

§Errors

All authentication, encoding, padding, version, and UTF-8 failures map to SoftchatError::DecryptionFailed.

Source§

impl LocalIdentity

Source

pub fn create_rumor( &self, draft: NostrEventDraft, ) -> Result<NostrRumor, SoftchatError>

Create one unsigned rumor whose author is this identity.

The draft timestamp remains the canonical application timestamp.

Guide and performance

§Errors

Returns a stable draft-validation or event-size failure.

Source

pub fn gift_wrap( &self, recipient: &NostrPublicKey, rumor: &NostrRumor, kind: Nip59EnvelopeKind, now: u64, ) -> Result<SignedNostrEvent, SoftchatError>

Wrap one authenticated rumor for exactly one recipient.

A fresh wrapper key is generated for every call. Seal and wrapper timestamps are sampled independently from [now - 172800, now].

Guide and performance

§Errors

Returns SoftchatError::Nip59EnvelopeCreationFailed if the rumor author, timestamp, nested size, encryption, or signing checks fail.

Source

pub fn unwrap_gift_wrap( &self, outer: &SignedNostrEvent, ) -> Result<UnwrappedNip59Envelope, SoftchatError>

Authenticate and unwrap one already verified NIP-59 outer event.

No rumor is returned unless route, kind, both encrypted layers, seal signature, seal shape, rumor ID, and author binding all validate.

Guide and performance

§Errors

Every invalid layer maps to SoftchatError::InvalidNip59Envelope.

Source§

impl LocalIdentity

Source

pub fn create_nip17_text_message( &self, recipient: &NostrPublicKey, created_at: u64, content: impl Into<String>, ) -> Result<Nip17TextMessage, SoftchatError>

Create one minimal one-to-one NIP-17 text-message rumor.

The writer emits exactly one canonical p tag and no extension tags. Callers explicitly create separate NIP-59 copies for the recipient and sender when recoverable local history is required.

Guide and performance

§Errors

Returns SoftchatError::Nip17MessageCreationFailed for self-addressed messages, empty text, invalid timestamps, or oversized rumors.

Trait Implementations§

Source§

impl Debug for LocalIdentity

Source§

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

Formats the value using the given formatter. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
§

unsafe fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
§

unsafe fn consume_handle(handle: Handle) -> Arc<T>

Consume a handle, getting back the initial Arc<> Read more
§

unsafe fn get_arc(handle: Handle) -> Arc<Self>

Get a clone of the Arc<> using a “borrowed” handle. 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> Same for T

Source§

type Output = T

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

§

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

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,