Skip to main content

Invite

Struct Invite 

Source
pub struct Invite {
    pub inviter_ephemeral_pubkey: String,
    pub shared_secret: String,
    pub inviter: String,
    pub inviter_ephemeral_privkey: Option<String>,
    pub device_id: Option<String>,
}
Expand description

A double-ratchet invite: the inviter’s ephemeral pubkey and the shared “link” secret. The ephemeral secret is present only on the inviter’s own copy (it is needed to receive responses).

Fields§

§inviter_ephemeral_pubkey: String

Inviter’s ephemeral public key (x-only hex).

§shared_secret: String

32-byte shared secret / link (hex).

§inviter: String

Inviter’s identity public key (x-only hex).

§inviter_ephemeral_privkey: Option<String>

Inviter’s ephemeral secret key (hex) — present only on the inviter side.

§device_id: Option<String>

Optional device id (the d-tag suffix on a published invite).

Implementations§

Source§

impl Invite

Source

pub fn create_new<K: NostrKeypair>( inviter: &str, device_id: Option<&str>, ) -> Result<Self, Nip104Error>

Mint a fresh invite for inviter (their identity pubkey). Generates a new ephemeral keypair and a random 32-byte shared secret. The returned invite holds the ephemeral secret, so keep it private — share only Self::to_url / Self::to_event output.

§Errors

Propagates keypair construction failure.

Source

pub fn to_url(&self, root: &str) -> String

Render the shareable URL. Invite parameters live in the URL hash (#…) so they never reach the server — matching the reference’s getUrl. root is the app origin, e.g. https://chat.iris.to.

Source

pub fn from_url(url: &str) -> Result<Self, Nip104Error>

Parse an invite from a shared URL (data in the # hash).

§Errors

Nip104Error::InvalidInvite if the hash is missing, not valid JSON, or missing a required field.

Source

pub fn to_event(&self, created_at: i64) -> Result<NostrNote, Nip104Error>

Build the published invite event (kind INVITE_EVENT_KIND). The caller signs it with the inviter’s identity key.

§Errors

Nip104Error::InvalidInvite if no device_id is set.

Source

pub fn from_event(event: &NostrNote) -> Result<Self, Nip104Error>

Parse and verify a published invite event (kind INVITE_EVENT_KIND). The resulting invite has no ephemeral secret (receive-side use only via the inviter’s own copy).

§Errors

Nip104Error::InvalidInvite on wrong kind, bad signature, or missing tags.

Source

pub fn accept<K: NostrKeypair>( &self, invitee: &K, owner_pubkey: Option<&str>, created_at: i64, ) -> Result<(Session<K>, NostrNote), Nip104Error>

Invitee side. Accept this invite: create the initiator session and the signed response event to publish back to the inviter.

invitee is the invitee’s identity keypair (used to authenticate via the inner DH layer and as the inner event’s pubkey). owner_pubkey is the optional multi-device owner key. created_at stamps the events.

Returns the new Session and a signed kind-INVITE_RESPONSE_KIND event. Publish the event; keep (and apply-drive) the session.

§Errors

Propagates key, NIP-44, and signing failures.

Source

pub fn receive<K: NostrKeypair>( &self, event: &NostrNote, inviter_identity: &K, ) -> Result<(Session<K>, InviteResponse), Nip104Error>

Inviter side. Consume an accepted invite-response event and build the mirror responder session.

event is the kind-INVITE_RESPONSE_KIND envelope the invitee published. inviter_identity is the inviter’s identity keypair (for the inner DH layer). This invite must carry its ephemeral secret (create_new provides it).

Returns the responder Session and the decoded InviteResponse (whose invitee_identity names the peer).

§Errors

Nip104Error::InvalidInvite on wrong kind / bad signature / missing ephemeral secret, plus any crypto failure.

Trait Implementations§

Source§

impl Clone for Invite

Source§

fn clone(&self) -> Invite

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 Invite

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for Invite

Scrub the ephemeral secret (when present) on drop. shared_secret is not a long-term key but is sensitive too, so it is wiped alongside it.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Eq for Invite

Source§

impl PartialEq for Invite

Source§

fn eq(&self, other: &Invite) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Invite

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.

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