import { NostrEvent, NPool } from '@nostrify/nostrify'; import { Participant, Message, MessagingState, RelayMode, RelayListsResult, RelayInfo, FileMetadata } from '../types'; export declare const CACHE_DB_NAME = "nostr-dm-cache-v2"; export declare const CACHE_STORE_NAME = "dm-cache"; export declare const CACHE_KEY_PREFIX = "dm-cache:"; export interface Signer { signEvent?(event: Omit): Promise; nip04?: { encrypt(pubkey: string, plaintext: string): Promise; decrypt(pubkey: string, ciphertext: string): Promise; }; nip44?: { encrypt(pubkey: string, plaintext: string): Promise; decrypt(pubkey: string, ciphertext: string): Promise; }; } export interface MessageWithMetadata { event: NostrEvent; senderPubkey?: string; participants?: string[]; subject?: string; error?: string; sealEvent?: NostrEvent; giftWrapEvent?: NostrEvent; giftWrapId?: string; fileMetadata?: FileMetadata[]; } export declare enum StartupMode { COLD = "cold", WARM = "warm" } /** * Encrypted file result from encryption */ interface EncryptedFile { encryptedBlob: Blob; key: string; nonce: string; algorithm: string; hash?: string; } export declare const Pure: { Relay: { extractBlockedRelays: (kind10006: NostrEvent | null) => string[]; deriveRelaySet: (kind10002: NostrEvent | null, kind10050: NostrEvent | null, kind10006: NostrEvent | null, relayMode: RelayMode, discoveryRelays: readonly string[]) => { derivedRelays: string[]; blockedRelays: string[]; }; findNewRelaysToQuery: (participants: Record, alreadyQueried: string[]) => string[]; computeAllQueriedRelays: (mode: StartupMode, lastSessionCache: MessagingState | null, relaySet: string[], newRelays: string[]) => string[]; buildRelayToUsersMap: (participants: Record) => Map; filterNewRelayUserCombos: (relayUserMap: Map, alreadyQueriedRelays: string[]) => string[]; mergeRelayInfo: (olderRelayInfo: Map, newerRelayInfo: Map) => Map; isRelayFailed: (info?: RelayInfo) => boolean; }; Message: { dedupeMessages: (existing: Message[], incoming: Message[]) => Message[]; extractOtherPubkeysFromMessages: (messages: MessageWithMetadata[], myPubkey: string) => string[]; parseImetaTags: (imetaTags: string[][]) => FileMetadata[]; decryptFile: (encryptedBlob: Blob, keyBase64: string, nonceBase64: string, algorithm?: string) => Promise; verifyFileHash: (fileBlob: Blob, expectedHash: string) => Promise; }; Participant: { buildParticipant: (pubkey: string, lists: RelayListsResult, relayMode: RelayMode, discoveryRelays: readonly string[]) => Participant; buildParticipantsMap: (pubkeys: string[], relayListsMap: Map, relayMode: RelayMode, discoveryRelays: readonly string[]) => Record; mergeParticipants: (existing: Record, incoming: Record) => Record; getStaleParticipants: (participants: Record, relayTTL: number, now: number) => string[]; getNewPubkeys: (foundPubkeys: string[], existingPubkeys: string[]) => string[]; extractNewPubkeys: (messagesWithMetadata: MessageWithMetadata[], baseParticipants: Record, myPubkey: string) => string[]; }; Conversation: { computeConversationId: (participantPubkeys: string[]) => string; parseConversationId: (conversationId: string) => string[]; normalizeRelayUrl: (relay: string) => string; getConversationRelays: (conversationId: string, participants: Record, myPubkey: string, discoveryRelays?: readonly string[]) => Array<{ relay: string; users: Array<{ pubkey: string; isCurrentUser: boolean; source: string; }>; }>; groupMessagesIntoConversations: (messages: Message[], _myPubkey: string) => Record; }; Sync: { computeSinceTimestamp: (lastCacheTime: number | null, nip17FuzzDays: number) => number | null; buildMessagingAppState: (myPubkey: string, participants: Record, messagesFromInitialQuery: MessageWithMetadata[], messagesFromGapFilling: MessageWithMetadata[], queriedRelays: string[], queryLimitReached: boolean, relayInfoMap: Map) => MessagingState; addMessageToState: (currentState: MessagingState, messageWithMetadata: MessageWithMetadata, myPubkey: string) => MessagingState; mergeMessagingState: (base: MessagingState, updates: MessagingState) => MessagingState; }; Settings: { computeFingerprint: (settings: { discoveryRelays: readonly string[]; relayMode: RelayMode; }) => string; }; }; /** * File metadata parsed from imeta tags * Available from '../types' */ /** * File attachment for direct messages (NIP-92 compatible). */ export interface FileAttachment { url: string; mimeType: string; size: number; name: string; tags: string[][]; dim?: string; blurhash?: string; thumb?: string; fallback?: string[]; fileType?: string; encrypted?: boolean; encryptionKey?: string; encryptionNonce?: string; encryptionAlgorithm?: string; encryptionHash?: string; } export declare const Impure: { Relay: { fetchRelayLists: (nostr: NPool, discoveryRelays: readonly string[], pubkeys: string[], signer?: Signer, nip42Auth?: boolean) => Promise<{ results: Map; relayInfo: Map; }>; fetchMyRelayInfo: (nostr: NPool, discoveryRelays: readonly string[], myPubkey: string, signer?: Signer, nip42Auth?: boolean) => Promise<{ myLists: RelayListsResult; myBlockedRelays: string[]; relayInfo: Map; }>; }; Message: { fetchMessages: (nostr: NPool, relays: string[], myPubkey: string, since: number | null, queryLimit: number, signer?: Signer, nip42Auth?: boolean) => Promise<{ messages: NostrEvent[]; limitReached: boolean; relayInfo: Map; }>; processNIP04Message: (msg: NostrEvent, signer: Signer, myPubkey: string) => Promise; processNIP17Message: (msg: NostrEvent, signer: Signer) => Promise; decryptAllMessages: (messages: NostrEvent[], signer: Signer, myPubkey: string) => Promise; queryMessages: (nostr: NPool, signer: Signer, relays: string[], myPubkey: string, since: number | null, queryLimit: number, nip42Auth?: boolean) => Promise<{ messagesWithMetadata: MessageWithMetadata[]; limitReached: boolean; relayInfo: Map; }>; queryNewRelays: (nostr: NPool, signer: Signer, relays: string[], myPubkey: string, queryLimit: number, nip42Auth?: boolean) => Promise<{ allMessages: MessageWithMetadata[]; limitReached: boolean; relayInfo: Map; }>; prepareNIP04Message: (nostr: NPool, signer: Signer, myPubkey: string, recipientPubkey: string, content: string, attachments: FileAttachment[], myInboxRelays: string[], recipientInboxRelays: string[], signEvent: (event: Omit) => Promise) => Promise<{ eventId: string; publish: () => Promise; }>; prepareNIP17Message: (nostr: NPool, signer: Signer, myPubkey: string, recipients: string[], content: string, attachments: FileAttachment[], getInboxRelays: (pubkey: string) => Promise, subject?: string) => Promise<{ giftWrapId: string; publish: () => Promise; }>; prepareMessageContent: (content: string, _attachments?: FileAttachment[]) => string; createImetaTags: (attachments?: FileAttachment[]) => string[][]; prepareEncryptedAttachment: (file: File, uploadFile: (file: File) => Promise) => Promise; encryptFile: (file: File) => Promise; decryptFile: (encryptedBlob: Blob, keyBase64: string, nonceBase64: string, algorithm?: string) => Promise; verifyFileHash: (fileBlob: Blob, expectedHash: string) => Promise; extractImageDimensions: (file: File) => Promise; }; Participant: { refreshStaleParticipants: (nostr: NPool, participants: Record, relayMode: RelayMode, discoveryRelays: readonly string[], relayTTL: number) => Promise>; fetchAndMergeParticipants: (nostr: NPool, baseParticipants: Record, newPubkeys: string[], relayMode: RelayMode, discoveryRelays: readonly string[]) => Promise>; }; Cache: { loadFromCache: (myPubkey: string) => Promise; saveToCache: (myPubkey: string, data: MessagingState) => Promise; deleteUserCache: (userPubkey: string) => Promise; buildAndSaveCache: (myPubkey: string, participants: Record, messagesFromInitialQuery: MessageWithMetadata[], messagesFromGapFilling: MessageWithMetadata[], allQueriedRelays: string[], limitReached: boolean, relayInfoMap: Map) => Promise; }; }; export {};