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: StringInviter’s ephemeral public key (x-only hex).
32-byte shared secret / link (hex).
inviter: StringInviter’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
impl Invite
Sourcepub fn create_new<K: NostrKeypair>(
inviter: &str,
device_id: Option<&str>,
) -> Result<Self, Nip104Error>
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.
Sourcepub fn to_url(&self, root: &str) -> String
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.
Sourcepub fn from_url(url: &str) -> Result<Self, Nip104Error>
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.
Sourcepub fn to_event(&self, created_at: i64) -> Result<NostrNote, Nip104Error>
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.
Sourcepub fn from_event(event: &NostrNote) -> Result<Self, Nip104Error>
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.
Sourcepub fn accept<K: NostrKeypair>(
&self,
invitee: &K,
owner_pubkey: Option<&str>,
created_at: i64,
) -> Result<(Session<K>, NostrNote), Nip104Error>
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.
Sourcepub fn receive<K: NostrKeypair>(
&self,
event: &NostrNote,
inviter_identity: &K,
) -> Result<(Session<K>, InviteResponse), Nip104Error>
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 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.
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.