import { IdentityKey, NostrSubscribe, NostrPublish, Rumor, Unsubscribe, ReceiptType, ExpirationOptions, ChatSettingsPayloadV1 } from "./types"; import { StorageAdapter } from "./StorageAdapter"; import { Invite } from "./Invite"; import { type VerifiedEvent } from "nostr-tools"; import { type QueuedMessageDiagnostic } from "./session-manager/queueDiagnostics"; import type { AcceptInviteOptions, AcceptInviteResult, InviteCredentials, OnEventCallback, SessionManagerEvent, SessionManagerEventsAvailableCallback, UserRecord } from "./session-manager/types"; export type { AcceptInviteOptions, AcceptInviteResult, DeviceRecord, InviteCredentials, OnEventCallback, OnEventMeta, SessionManagerEvent, SessionManagerEventsAvailableCallback, UserRecord, } from "./session-manager/types"; export type { QueuedMessageDiagnostic, QueuedMessageStage, } from "./session-manager/queueDiagnostics"; export interface SendMessageOptions extends ExpirationOptions { kind?: number; tags?: string[][]; expiration?: ExpirationOptions | null; } export declare class SessionManager { private readonly storageVersion; private readonly versionPrefix; private deviceId; private storage; private legacyNostrSubscribe?; private legacyNostrPublish?; private identityKey; private ourPublicKey; private ownerPublicKey; private nostrFacade; private inviteKeys; private userRecords; private messageQueue; private discoveryQueue; private delegateToOwner; private processedInviteResponses; private pendingInviteResponses; private inviteAcceptPromises; private expirationSettings; private userRecordStorage; private autoAdoptChatSettings; private userSetupPromises; private bootstrapRetryTimeouts; private ourInviteResponseSubscription; private legacyRuntimeSubscriptions; private legacyDirectMessageSubscription; private legacyDirectMessageAuthors; private internalSubscriptions; private messagePushAuthorCallbacks; private eventsAvailableCallbacks; private emittedEvents; private initialized; constructor(ourPublicKey: string, identityKey: IdentityKey, deviceId: string, nostrSubscribe: NostrSubscribe, nostrPublish: NostrPublish, ownerPublicKey: string, inviteKeys: InviteCredentials, storage?: StorageAdapter); static createForRuntime(ourPublicKey: string, identityKey: IdentityKey, deviceId: string, ownerPublicKey: string, inviteKeys: InviteCredentials, storage?: StorageAdapter): SessionManager; onEventsAvailable(callback: SessionManagerEventsAvailableCallback): Unsubscribe; drainEvents(): SessionManagerEvent[]; hasPendingEvents(): boolean; private emitEvent; private handleLegacyEmittedEvent; private emitSubscribe; private emitPublish; init(): Promise; /** * Start listening for invite responses on our ephemeral key. * This is used by devices to receive session establishment responses. */ private startInviteResponseListener; private fetchAppKeys; private getOrCreateUserRecord; private handleDeviceRumor; private upsertDeviceRecord; /** * Resolve a pubkey to its owner if it's a known delegate device. * Returns the input pubkey if not a known delegate. */ private resolveToOwner; /** * Update the delegate-to-owner mapping from an AppKeys. * Extracts delegate device pubkeys and maps them to the owner. * Persists the mapping in the user record for restart recovery. */ private updateDelegateMapping; private queuePendingInviteResponse; private installInviteResponseSession; private retryPendingInviteResponses; /** * Check if a device is currently authorized by the owner's AppKeys. * Returns true if the device is in the owner's current AppKeys. */ private isDeviceAuthorized; setupUser(userPubkey: string): Promise; private doSetupUser; onEvent(callback: OnEventCallback): () => void; onMessagePushAuthorsChanged(callback: () => void): Unsubscribe; private notifyMessagePushAuthorsChanged; private syncLegacyDirectMessageSubscription; /** * Enable/disable automatically adopting incoming `chat-settings` events (kind 10448). * When enabled, receiving a valid settings payload updates per-peer expiration defaults. */ setAutoAdoptChatSettings(enabled: boolean): void; getDeviceId(): string; getUserRecords(): Map; getMessagePushAuthorPubkeys(peerPubkey: string): string[]; getKnownDeviceIdentityPubkeysForOwner(ownerPubkey: string): string[]; getAllMessagePushAuthorPubkeys(): string[]; feedEvent(event: VerifiedEvent): boolean; processReceivedEvent(event: VerifiedEvent): boolean; private processAppKeysEvent; private processInviteResponseEvent; private processInviteEvent; /** * Set a global default expiration for outgoing rumors sent via this SessionManager. * Pass `undefined` to clear. */ setDefaultExpiration(options: ExpirationOptions | undefined): Promise; /** * Set a per-peer default expiration for outgoing rumors. Pass `undefined` to clear. */ setExpirationForPeer(peerPubkey: string, options: ExpirationOptions | null | undefined): Promise; /** * Set a per-group default expiration, keyed by groupId (typically carried via `["l", groupId]`). * Pass `undefined` to clear. */ setExpirationForGroup(groupId: string, options: ExpirationOptions | null | undefined): Promise; close(): void; deactivateCurrentSessions(publicKey: string): void; deleteChat(userPubkey: string): Promise; deleteUser(userPubkey: string): Promise; queuedMessageDiagnostics(innerEventId?: string): Promise; private flushMessageQueue; private sendLinkBootstrap; private sendInviteBootstrap; acceptInvite(invite: Invite, options?: AcceptInviteOptions): Promise; private doAcceptInvite; private resolveInviteeOwnerClaim; sendEvent(recipientIdentityKey: string, event: Partial): Promise; sendMessage(recipientPublicKey: string, content: string, options?: SendMessageOptions): Promise; /** * Send an encrypted 1:1 chat settings event (inner kind 10448). * * Settings events themselves should never expire; they are sent without a NIP-40 expiration tag. */ sendChatSettings(recipientPublicKey: string, messageTtlSeconds: ChatSettingsPayloadV1["messageTtlSeconds"]): Promise; /** * Convenience: set per-peer disappearing-message TTL and notify the peer via a settings event. * * `messageTtlSeconds`: * - `> 0`: set per-peer ttlSeconds * - `0` or `null`: disable per-peer expiration even if a global default exists * - `undefined`: clear per-peer override (fall back to global default) */ setChatSettingsForPeer(peerPubkey: string, messageTtlSeconds: ChatSettingsPayloadV1["messageTtlSeconds"]): Promise; sendReceipt(recipientPublicKey: string, receiptType: ReceiptType, messageIds: string[]): Promise; sendTyping(recipientPublicKey: string): Promise; private maybeAutoAdoptChatSettings; private storeUserRecord; private loadUserRecord; private loadAllUserRecords; } //# sourceMappingURL=SessionManager.d.ts.map