@reverbia/sdk 1.0.0-next.20251229084841 → 1.1.0-next.20251230221037

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -969,12 +969,14 @@ declare function clearAllEncryptionKeys(): void;
969
969
  /**
970
970
  * Encrypts data using AES-GCM with the stored encryption key
971
971
  * @param plaintext - The data to encrypt (string or Uint8Array)
972
+ * @param address - The wallet address for encryption
972
973
  * @returns Encrypted data as hex string (IV + ciphertext + auth tag)
973
974
  */
974
975
  declare function encryptData(plaintext: string | Uint8Array, address: string): Promise<string>;
975
976
  /**
976
977
  * Decrypts data using AES-GCM with the stored encryption key
977
978
  * @param encryptedHex - Encrypted data as hex string (IV + ciphertext + auth tag)
979
+ * @param address - The wallet address for decryption
978
980
  * @returns Decrypted data as string
979
981
  */
980
982
  declare function decryptData(encryptedHex: string, address: string): Promise<string>;
@@ -999,19 +1001,61 @@ type SignMessageFn = (message: string) => Promise<string>;
999
1001
  * Note: Keys are stored in memory only and do not persist across page reloads.
1000
1002
  * This is a security feature - users must sign once per session to derive their key.
1001
1003
  *
1004
+ * Handles Privy rate limits (429 errors) with automatic retry and exponential backoff.
1005
+ *
1002
1006
  * @param walletAddress - The wallet address to generate the key for
1003
1007
  * @param signMessage - Function to sign a message (returns signature hex string)
1004
1008
  * @returns Promise that resolves when the key is available
1005
1009
  */
1006
1010
  declare function requestEncryptionKey(walletAddress: string, signMessage: SignMessageFn): Promise<void>;
1011
+ /**
1012
+ * Requests the user to sign a message to generate an ECDH key pair.
1013
+ * If a key pair already exists in memory for the given wallet, resolves immediately.
1014
+ *
1015
+ * Note: Key pairs are stored in memory only and do not persist across page reloads.
1016
+ * This is a security feature - users must sign once per session to derive their key pair.
1017
+ *
1018
+ * Handles Privy rate limits (429 errors) with automatic retry and exponential backoff.
1019
+ *
1020
+ * @param walletAddress - The wallet address to generate the key pair for
1021
+ * @param signMessage - Function to sign a message (returns signature hex string)
1022
+ * @returns Promise that resolves when the key pair is available
1023
+ */
1024
+ declare function requestKeyPair(walletAddress: string, signMessage: SignMessageFn): Promise<void>;
1025
+ /**
1026
+ * Exports the public key for a wallet address as SPKI format (base64)
1027
+ * @param address - The wallet address
1028
+ * @param signMessage - Function to sign a message (returns signature hex string)
1029
+ * @returns The public key as base64-encoded SPKI string
1030
+ */
1031
+ declare function exportPublicKey(address: string, signMessage: SignMessageFn): Promise<string>;
1032
+ /**
1033
+ * Checks if a key pair exists in memory for the given wallet address
1034
+ * @param address - The wallet address
1035
+ * @returns True if key pair exists, false otherwise
1036
+ */
1037
+ declare function hasKeyPair(address: string): boolean;
1038
+ /**
1039
+ * Clears the key pair for a wallet address from memory
1040
+ * @param address - The wallet address
1041
+ */
1042
+ declare function clearKeyPair(address: string): void;
1043
+ /**
1044
+ * Clears all key pairs from memory
1045
+ */
1046
+ declare function clearAllKeyPairs(): void;
1007
1047
  /**
1008
1048
  * Hook that provides on-demand encryption key management.
1009
1049
  * @param signMessage - Function to sign a message (from Privy's useSignMessage)
1010
- * @returns Functions to request encryption keys
1050
+ * @returns Functions to request encryption keys and manage key pairs
1011
1051
  * @category Hooks
1012
1052
  */
1013
1053
  declare function useEncryption(signMessage: SignMessageFn): {
1014
1054
  requestEncryptionKey: (walletAddress: string) => Promise<void>;
1055
+ requestKeyPair: (walletAddress: string) => Promise<void>;
1056
+ exportPublicKey: (walletAddress: string) => Promise<string>;
1057
+ hasKeyPair: (walletAddress: string) => boolean;
1058
+ clearKeyPair: (walletAddress: string) => void;
1015
1059
  };
1016
1060
 
1017
1061
  declare const chatStorageSchema: Readonly<{
@@ -1075,6 +1119,12 @@ interface BaseUseMemoryStorageOptions {
1075
1119
  onFactsExtracted?: (facts: MemoryExtractionResult) => void;
1076
1120
  getToken?: () => Promise<string | null>;
1077
1121
  baseUrl?: string;
1122
+ /** Wallet address for encryption (optional - encryption disabled if not provided) */
1123
+ walletAddress?: string | null;
1124
+ /** Function to request encryption key (optional - encryption disabled if not provided) */
1125
+ requestEncryptionKey?: (address: string) => Promise<void>;
1126
+ /** Function to sign message for migration (optional - migration disabled if not provided) */
1127
+ signMessage?: (message: string) => Promise<string>;
1078
1128
  }
1079
1129
  interface BaseUseMemoryStorageResult {
1080
1130
  memories: StoredMemory[];
@@ -1209,6 +1259,12 @@ interface BaseUseChatStorageOptions {
1209
1259
  onData?: (chunk: string) => void;
1210
1260
  onFinish?: (response: LlmapiResponseResponse) => void;
1211
1261
  onError?: (error: Error) => void;
1262
+ /** Wallet address for encryption (optional - encryption disabled if not provided) */
1263
+ walletAddress?: string | null;
1264
+ /** Function to request encryption key (optional - encryption disabled if not provided) */
1265
+ requestEncryptionKey?: (address: string) => Promise<void>;
1266
+ /** Function to sign message for migration (optional - required for migrating old encrypted data) */
1267
+ signMessage?: (message: string) => Promise<string>;
1212
1268
  }
1213
1269
  interface BaseSendMessageWithStorageArgs {
1214
1270
  content: string;
@@ -1588,6 +1644,151 @@ type UseMemoryStorageResult = BaseUseMemoryStorageResult;
1588
1644
  */
1589
1645
  declare function useMemoryStorage(options: UseMemoryStorageOptions): UseMemoryStorageResult;
1590
1646
 
1647
+ /**
1648
+ * Memory Encryption Utilities
1649
+ *
1650
+ * Encrypts sensitive memory fields at rest while keeping search/index fields unencrypted.
1651
+ * Based on the implementation from ai-memoryless-client.
1652
+ */
1653
+
1654
+ /**
1655
+ * Get the encryption version from an encrypted value
1656
+ */
1657
+ declare function getEncryptionVersion(value: string): "v1" | "v2" | null;
1658
+ /**
1659
+ * Encrypt a single string value using the SDK's encryption.
1660
+ * Returns the encrypted value with a prefix for identification.
1661
+ *
1662
+ * @param value - The plain text value to encrypt
1663
+ * @param address - The user's wallet address (encryption key identifier)
1664
+ * @returns The encrypted value with prefix
1665
+ * @throws {Error} If encryption fails - prevents sensitive data from being stored unencrypted
1666
+ */
1667
+ declare function encryptField(value: string, address: string): Promise<string>;
1668
+ /**
1669
+ * Placeholder returned when decryption fails.
1670
+ * Allows UI to render a friendly message instead of gibberish.
1671
+ */
1672
+ declare const DECRYPTION_FAILED_PLACEHOLDER = "[Decryption Failed]";
1673
+ /**
1674
+ * Decrypt a single string value using the SDK's decryption.
1675
+ * Supports both v1 (legacy) and v2 encryption formats.
1676
+ * Automatically migrates old encrypted values to new format.
1677
+ *
1678
+ * @param value - The encrypted value (with prefix)
1679
+ * @param address - The user's wallet address (encryption key identifier)
1680
+ * @param signMessage - Optional function to sign message for migration (required if old encryption detected)
1681
+ * @param onMigrated - Optional callback when a value is migrated
1682
+ * @returns The decrypted plain text, original value if not encrypted, or placeholder on error
1683
+ */
1684
+ declare function decryptField(value: string, address: string, signMessage?: SignMessageFn, onMigrated?: (migratedValue: string) => Promise<void>): Promise<string>;
1685
+ /**
1686
+ * Memory data structure with fields that may be encrypted
1687
+ */
1688
+ interface MemoryData {
1689
+ value?: string;
1690
+ rawEvidence?: string;
1691
+ key?: string;
1692
+ namespace?: string;
1693
+ [key: string]: unknown;
1694
+ }
1695
+ /**
1696
+ * Encrypt sensitive fields in a memory object.
1697
+ * Only encrypts the fields defined in ENCRYPTED_FIELDS.
1698
+ * Embeddings and other indexed fields are left unencrypted.
1699
+ *
1700
+ * @param memory - The memory object with plain text fields
1701
+ * @param address - The user's wallet address
1702
+ * @returns A new memory object with sensitive fields encrypted
1703
+ */
1704
+ declare function encryptMemoryFields<T extends MemoryData>(memory: T, address: string): Promise<T>;
1705
+ /**
1706
+ * Decrypt sensitive fields in a memory object.
1707
+ * Only decrypts the fields defined in ENCRYPTED_FIELDS.
1708
+ * Automatically migrates old encrypted values to new format.
1709
+ * Also encrypts unencrypted fields when found (for users migrating to encryption).
1710
+ *
1711
+ * @param memory - The memory object with encrypted fields
1712
+ * @param address - The user's wallet address
1713
+ * @param signMessage - Optional function to sign message for migration (required if old encryption detected)
1714
+ * @param updateMemory - Optional function to update memory in storage after migration/encryption
1715
+ * @returns A new memory object with sensitive fields decrypted
1716
+ */
1717
+ declare function decryptMemoryFields<T extends MemoryData>(memory: T, address: string, signMessage?: SignMessageFn, updateMemory?: (id: string, data: Partial<T>) => Promise<void>): Promise<T>;
1718
+ /**
1719
+ * Batch encrypt multiple memory objects.
1720
+ * Uses parallel processing for performance.
1721
+ *
1722
+ * @param memories - Array of memory objects
1723
+ * @param address - The user's wallet address
1724
+ * @returns Array of memory objects with encrypted fields
1725
+ */
1726
+ declare function encryptMemoriesBatch<T extends MemoryData>(memories: T[], address: string): Promise<T[]>;
1727
+ /**
1728
+ * Batch decrypt multiple memory objects.
1729
+ * Uses parallel processing for performance.
1730
+ * Automatically migrates old encrypted values to new format.
1731
+ *
1732
+ * @param memories - Array of memory objects
1733
+ * @param address - The user's wallet address
1734
+ * @param signMessage - Optional function to sign message for migration (required if old encryption detected)
1735
+ * @param updateMemory - Optional function to update memory in storage after migration
1736
+ * @returns Array of memory objects with decrypted fields
1737
+ */
1738
+ declare function decryptMemoriesBatch<T extends MemoryData>(memories: T[], address: string, signMessage?: SignMessageFn, updateMemory?: (id: string, data: Partial<T>) => Promise<void>): Promise<T[]>;
1739
+ /**
1740
+ * Check if a memory has any encrypted fields.
1741
+ * Useful for determining if migration is needed.
1742
+ */
1743
+ declare function hasEncryptedFields(memory: MemoryData): boolean;
1744
+ /**
1745
+ * Check if a memory needs encryption (has unencrypted sensitive fields).
1746
+ */
1747
+ declare function needsEncryption(memory: MemoryData): boolean;
1748
+ /**
1749
+ * Memory fields needed for encryption update
1750
+ */
1751
+ interface MemoryEncryptionFields extends MemoryData {
1752
+ type: string;
1753
+ namespace: string;
1754
+ key: string;
1755
+ value: string;
1756
+ rawEvidence: string;
1757
+ confidence: number;
1758
+ pii: boolean;
1759
+ }
1760
+ /**
1761
+ * Memory object with the required fields for batch encryption
1762
+ */
1763
+ interface MemoryForBatchEncryption {
1764
+ uniqueId: string;
1765
+ type: string;
1766
+ namespace: string;
1767
+ key: string;
1768
+ value: string;
1769
+ rawEvidence: string;
1770
+ confidence: number;
1771
+ pii: boolean;
1772
+ }
1773
+ /**
1774
+ * Encrypt a batch of memories in parallel with rate limiting and retry logic.
1775
+ * Tracks failed memories for error reporting.
1776
+ *
1777
+ * @param memories - Array of memories to encrypt
1778
+ * @param address - User's wallet address
1779
+ * @param updateFn - Function to update a memory in storage
1780
+ * @param batchSize - Number of memories to process in parallel (default: 5)
1781
+ * @returns Object with success count and failed memory IDs
1782
+ */
1783
+ declare function encryptMemoriesBatchInPlace(memories: MemoryForBatchEncryption[], address: string, updateFn: (id: string, data: MemoryData) => Promise<unknown>, batchSize?: number): Promise<{
1784
+ success: number;
1785
+ failed: string[];
1786
+ errors: Array<{
1787
+ id: string;
1788
+ error: string;
1789
+ }>;
1790
+ }>;
1791
+
1591
1792
  declare const settingsStorageSchema: Readonly<{
1592
1793
  version: _nozbe_watermelondb_Schema.SchemaVersion;
1593
1794
  tables: _nozbe_watermelondb_Schema.TableMap;
@@ -2003,6 +2204,7 @@ declare function useDropboxBackup(options: UseDropboxBackupOptions): UseDropboxB
2003
2204
  declare function clearToken(): void;
2004
2205
  /**
2005
2206
  * Check if we have any stored credentials (including refresh token)
2207
+ * Works with both encrypted and unencrypted credentials
2006
2208
  */
2007
2209
  declare function hasDropboxCredentials(): boolean;
2008
2210
 
@@ -2112,6 +2314,7 @@ declare function getGoogleDriveStoredToken(): string | null;
2112
2314
  declare function clearGoogleDriveToken(): void;
2113
2315
  /**
2114
2316
  * Check if we have any stored credentials (including refresh token)
2317
+ * Works with both encrypted and unencrypted credentials
2115
2318
  */
2116
2319
  declare function hasGoogleDriveCredentials(): boolean;
2117
2320
 
@@ -2933,4 +3136,4 @@ interface UseBackupResult {
2933
3136
  */
2934
3137
  declare function useBackup(options: UseBackupOptions): UseBackupResult;
2935
3138
 
2936
- export { DEFAULT_CONVERSATIONS_FOLDER as BACKUP_DRIVE_CONVERSATIONS_FOLDER, DEFAULT_ROOT_FOLDER as BACKUP_DRIVE_ROOT_FOLDER, DEFAULT_BACKUP_FOLDER as BACKUP_ICLOUD_FOLDER, type BackupAuthContextValue, BackupAuthProvider, type BackupAuthProviderProps, type BackupOperationOptions, Conversation as ChatConversation, Message as ChatMessage, type ChatRole, type CreateConversationOptions, type CreateMemoryOptions, type CreateMessageOptions, type CreateModelPreferenceOptions, DEFAULT_BACKUP_FOLDER$1 as DEFAULT_BACKUP_FOLDER, DEFAULT_CONVERSATIONS_FOLDER as DEFAULT_DRIVE_CONVERSATIONS_FOLDER, DEFAULT_ROOT_FOLDER as DEFAULT_DRIVE_ROOT_FOLDER, DEFAULT_BACKUP_FOLDER$1 as DEFAULT_DROPBOX_FOLDER, DEFAULT_BACKUP_FOLDER as DEFAULT_ICLOUD_BACKUP_FOLDER, type DropboxAuthContextValue, DropboxAuthProvider, type DropboxAuthProviderProps, type DropboxExportResult, type DropboxImportResult, type FileMetadata, type GoogleDriveAuthContextValue, GoogleDriveAuthProvider, type GoogleDriveAuthProviderProps, type GoogleDriveExportResult, type GoogleDriveImportResult, type ICloudAuthContextValue, ICloudAuthProvider, type ICloudAuthProviderProps, type ICloudExportResult, type ICloudImportResult, type MemoryItem, type MemoryType, type OCRFile, type PdfFile, type ProgressCallback, type ProviderAuthState, type ProviderBackupState, type SearchMessagesOptions, type SearchSource, type SendMessageWithStorageArgs, type SendMessageWithStorageResult, type SignMessageFn, type ChatCompletionUsage as StoredChatCompletionUsage, type StoredConversation, type StoredMemory, Memory as StoredMemoryModel, type StoredMemoryWithSimilarity, type StoredMessage, type StoredMessageWithSimilarity, type StoredModelPreference, ModelPreference as StoredModelPreferenceModel, type UpdateMemoryOptions, type UpdateModelPreferenceOptions, type UseBackupOptions, type UseBackupResult, type UseChatStorageOptions, type UseChatStorageResult, type UseDropboxBackupOptions, type UseDropboxBackupResult, type UseGoogleDriveBackupOptions, type UseGoogleDriveBackupResult, type UseICloudBackupOptions, type UseICloudBackupResult, type UseMemoryStorageOptions, type UseMemoryStorageResult, type UseSettingsOptions, type UseSettingsResult, chatStorageMigrations, chatStorageSchema, clearAllEncryptionKeys, clearToken as clearDropboxToken, clearEncryptionKey, clearGoogleDriveToken, clearICloudAuth, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, extractConversationContext, formatMemoriesForChat, generateCompositeKey, generateConversationId, generateUniqueKey, getGoogleDriveStoredToken, hasDropboxCredentials, hasEncryptionKey, hasGoogleDriveCredentials, hasICloudCredentials, memoryStorageSchema, requestEncryptionKey, sdkMigrations, sdkModelClasses, sdkSchema, settingsStorageSchema, useBackup, useBackupAuth, useChat, useChatStorage, useDropboxAuth, useDropboxBackup, useEncryption, useGoogleDriveAuth, useGoogleDriveBackup, useICloudAuth, useICloudBackup, useImageGeneration, useMemoryStorage, useModels, useOCR, usePdf, useSearch, useSettings };
3139
+ export { DEFAULT_CONVERSATIONS_FOLDER as BACKUP_DRIVE_CONVERSATIONS_FOLDER, DEFAULT_ROOT_FOLDER as BACKUP_DRIVE_ROOT_FOLDER, DEFAULT_BACKUP_FOLDER as BACKUP_ICLOUD_FOLDER, type BackupAuthContextValue, BackupAuthProvider, type BackupAuthProviderProps, type BackupOperationOptions, Conversation as ChatConversation, Message as ChatMessage, type ChatRole, type CreateConversationOptions, type CreateMemoryOptions, type CreateMessageOptions, type CreateModelPreferenceOptions, DECRYPTION_FAILED_PLACEHOLDER, DEFAULT_BACKUP_FOLDER$1 as DEFAULT_BACKUP_FOLDER, DEFAULT_CONVERSATIONS_FOLDER as DEFAULT_DRIVE_CONVERSATIONS_FOLDER, DEFAULT_ROOT_FOLDER as DEFAULT_DRIVE_ROOT_FOLDER, DEFAULT_BACKUP_FOLDER$1 as DEFAULT_DROPBOX_FOLDER, DEFAULT_BACKUP_FOLDER as DEFAULT_ICLOUD_BACKUP_FOLDER, type DropboxAuthContextValue, DropboxAuthProvider, type DropboxAuthProviderProps, type DropboxExportResult, type DropboxImportResult, type FileMetadata, type GoogleDriveAuthContextValue, GoogleDriveAuthProvider, type GoogleDriveAuthProviderProps, type GoogleDriveExportResult, type GoogleDriveImportResult, type ICloudAuthContextValue, ICloudAuthProvider, type ICloudAuthProviderProps, type ICloudExportResult, type ICloudImportResult, type MemoryData, type MemoryEncryptionFields, type MemoryItem, type MemoryType, type OCRFile, type PdfFile, type ProgressCallback, type ProviderAuthState, type ProviderBackupState, type SearchMessagesOptions, type SearchSource, type SendMessageWithStorageArgs, type SendMessageWithStorageResult, type SignMessageFn, type ChatCompletionUsage as StoredChatCompletionUsage, type StoredConversation, type StoredMemory, Memory as StoredMemoryModel, type StoredMemoryWithSimilarity, type StoredMessage, type StoredMessageWithSimilarity, type StoredModelPreference, ModelPreference as StoredModelPreferenceModel, type UpdateMemoryOptions, type UpdateModelPreferenceOptions, type UseBackupOptions, type UseBackupResult, type UseChatStorageOptions, type UseChatStorageResult, type UseDropboxBackupOptions, type UseDropboxBackupResult, type UseGoogleDriveBackupOptions, type UseGoogleDriveBackupResult, type UseICloudBackupOptions, type UseICloudBackupResult, type UseMemoryStorageOptions, type UseMemoryStorageResult, type UseSettingsOptions, type UseSettingsResult, chatStorageMigrations, chatStorageSchema, clearAllEncryptionKeys, clearAllKeyPairs, clearToken as clearDropboxToken, clearEncryptionKey, clearGoogleDriveToken, clearICloudAuth, clearKeyPair, createMemoryContextSystemMessage, decryptData, decryptDataBytes, decryptField, decryptMemoriesBatch, decryptMemoryFields, encryptData, encryptField, encryptMemoriesBatch, encryptMemoriesBatchInPlace, encryptMemoryFields, exportPublicKey, extractConversationContext, formatMemoriesForChat, generateCompositeKey, generateConversationId, generateUniqueKey, getEncryptionVersion, getGoogleDriveStoredToken, hasDropboxCredentials, hasEncryptedFields, hasEncryptionKey, hasGoogleDriveCredentials, hasICloudCredentials, hasKeyPair, memoryStorageSchema, needsEncryption, requestEncryptionKey, requestKeyPair, sdkMigrations, sdkModelClasses, sdkSchema, settingsStorageSchema, useBackup, useBackupAuth, useChat, useChatStorage, useDropboxAuth, useDropboxBackup, useEncryption, useGoogleDriveAuth, useGoogleDriveBackup, useICloudAuth, useICloudBackup, useImageGeneration, useMemoryStorage, useModels, useOCR, usePdf, useSearch, useSettings };
@@ -969,12 +969,14 @@ declare function clearAllEncryptionKeys(): void;
969
969
  /**
970
970
  * Encrypts data using AES-GCM with the stored encryption key
971
971
  * @param plaintext - The data to encrypt (string or Uint8Array)
972
+ * @param address - The wallet address for encryption
972
973
  * @returns Encrypted data as hex string (IV + ciphertext + auth tag)
973
974
  */
974
975
  declare function encryptData(plaintext: string | Uint8Array, address: string): Promise<string>;
975
976
  /**
976
977
  * Decrypts data using AES-GCM with the stored encryption key
977
978
  * @param encryptedHex - Encrypted data as hex string (IV + ciphertext + auth tag)
979
+ * @param address - The wallet address for decryption
978
980
  * @returns Decrypted data as string
979
981
  */
980
982
  declare function decryptData(encryptedHex: string, address: string): Promise<string>;
@@ -999,19 +1001,61 @@ type SignMessageFn = (message: string) => Promise<string>;
999
1001
  * Note: Keys are stored in memory only and do not persist across page reloads.
1000
1002
  * This is a security feature - users must sign once per session to derive their key.
1001
1003
  *
1004
+ * Handles Privy rate limits (429 errors) with automatic retry and exponential backoff.
1005
+ *
1002
1006
  * @param walletAddress - The wallet address to generate the key for
1003
1007
  * @param signMessage - Function to sign a message (returns signature hex string)
1004
1008
  * @returns Promise that resolves when the key is available
1005
1009
  */
1006
1010
  declare function requestEncryptionKey(walletAddress: string, signMessage: SignMessageFn): Promise<void>;
1011
+ /**
1012
+ * Requests the user to sign a message to generate an ECDH key pair.
1013
+ * If a key pair already exists in memory for the given wallet, resolves immediately.
1014
+ *
1015
+ * Note: Key pairs are stored in memory only and do not persist across page reloads.
1016
+ * This is a security feature - users must sign once per session to derive their key pair.
1017
+ *
1018
+ * Handles Privy rate limits (429 errors) with automatic retry and exponential backoff.
1019
+ *
1020
+ * @param walletAddress - The wallet address to generate the key pair for
1021
+ * @param signMessage - Function to sign a message (returns signature hex string)
1022
+ * @returns Promise that resolves when the key pair is available
1023
+ */
1024
+ declare function requestKeyPair(walletAddress: string, signMessage: SignMessageFn): Promise<void>;
1025
+ /**
1026
+ * Exports the public key for a wallet address as SPKI format (base64)
1027
+ * @param address - The wallet address
1028
+ * @param signMessage - Function to sign a message (returns signature hex string)
1029
+ * @returns The public key as base64-encoded SPKI string
1030
+ */
1031
+ declare function exportPublicKey(address: string, signMessage: SignMessageFn): Promise<string>;
1032
+ /**
1033
+ * Checks if a key pair exists in memory for the given wallet address
1034
+ * @param address - The wallet address
1035
+ * @returns True if key pair exists, false otherwise
1036
+ */
1037
+ declare function hasKeyPair(address: string): boolean;
1038
+ /**
1039
+ * Clears the key pair for a wallet address from memory
1040
+ * @param address - The wallet address
1041
+ */
1042
+ declare function clearKeyPair(address: string): void;
1043
+ /**
1044
+ * Clears all key pairs from memory
1045
+ */
1046
+ declare function clearAllKeyPairs(): void;
1007
1047
  /**
1008
1048
  * Hook that provides on-demand encryption key management.
1009
1049
  * @param signMessage - Function to sign a message (from Privy's useSignMessage)
1010
- * @returns Functions to request encryption keys
1050
+ * @returns Functions to request encryption keys and manage key pairs
1011
1051
  * @category Hooks
1012
1052
  */
1013
1053
  declare function useEncryption(signMessage: SignMessageFn): {
1014
1054
  requestEncryptionKey: (walletAddress: string) => Promise<void>;
1055
+ requestKeyPair: (walletAddress: string) => Promise<void>;
1056
+ exportPublicKey: (walletAddress: string) => Promise<string>;
1057
+ hasKeyPair: (walletAddress: string) => boolean;
1058
+ clearKeyPair: (walletAddress: string) => void;
1015
1059
  };
1016
1060
 
1017
1061
  declare const chatStorageSchema: Readonly<{
@@ -1075,6 +1119,12 @@ interface BaseUseMemoryStorageOptions {
1075
1119
  onFactsExtracted?: (facts: MemoryExtractionResult) => void;
1076
1120
  getToken?: () => Promise<string | null>;
1077
1121
  baseUrl?: string;
1122
+ /** Wallet address for encryption (optional - encryption disabled if not provided) */
1123
+ walletAddress?: string | null;
1124
+ /** Function to request encryption key (optional - encryption disabled if not provided) */
1125
+ requestEncryptionKey?: (address: string) => Promise<void>;
1126
+ /** Function to sign message for migration (optional - migration disabled if not provided) */
1127
+ signMessage?: (message: string) => Promise<string>;
1078
1128
  }
1079
1129
  interface BaseUseMemoryStorageResult {
1080
1130
  memories: StoredMemory[];
@@ -1209,6 +1259,12 @@ interface BaseUseChatStorageOptions {
1209
1259
  onData?: (chunk: string) => void;
1210
1260
  onFinish?: (response: LlmapiResponseResponse) => void;
1211
1261
  onError?: (error: Error) => void;
1262
+ /** Wallet address for encryption (optional - encryption disabled if not provided) */
1263
+ walletAddress?: string | null;
1264
+ /** Function to request encryption key (optional - encryption disabled if not provided) */
1265
+ requestEncryptionKey?: (address: string) => Promise<void>;
1266
+ /** Function to sign message for migration (optional - required for migrating old encrypted data) */
1267
+ signMessage?: (message: string) => Promise<string>;
1212
1268
  }
1213
1269
  interface BaseSendMessageWithStorageArgs {
1214
1270
  content: string;
@@ -1588,6 +1644,151 @@ type UseMemoryStorageResult = BaseUseMemoryStorageResult;
1588
1644
  */
1589
1645
  declare function useMemoryStorage(options: UseMemoryStorageOptions): UseMemoryStorageResult;
1590
1646
 
1647
+ /**
1648
+ * Memory Encryption Utilities
1649
+ *
1650
+ * Encrypts sensitive memory fields at rest while keeping search/index fields unencrypted.
1651
+ * Based on the implementation from ai-memoryless-client.
1652
+ */
1653
+
1654
+ /**
1655
+ * Get the encryption version from an encrypted value
1656
+ */
1657
+ declare function getEncryptionVersion(value: string): "v1" | "v2" | null;
1658
+ /**
1659
+ * Encrypt a single string value using the SDK's encryption.
1660
+ * Returns the encrypted value with a prefix for identification.
1661
+ *
1662
+ * @param value - The plain text value to encrypt
1663
+ * @param address - The user's wallet address (encryption key identifier)
1664
+ * @returns The encrypted value with prefix
1665
+ * @throws {Error} If encryption fails - prevents sensitive data from being stored unencrypted
1666
+ */
1667
+ declare function encryptField(value: string, address: string): Promise<string>;
1668
+ /**
1669
+ * Placeholder returned when decryption fails.
1670
+ * Allows UI to render a friendly message instead of gibberish.
1671
+ */
1672
+ declare const DECRYPTION_FAILED_PLACEHOLDER = "[Decryption Failed]";
1673
+ /**
1674
+ * Decrypt a single string value using the SDK's decryption.
1675
+ * Supports both v1 (legacy) and v2 encryption formats.
1676
+ * Automatically migrates old encrypted values to new format.
1677
+ *
1678
+ * @param value - The encrypted value (with prefix)
1679
+ * @param address - The user's wallet address (encryption key identifier)
1680
+ * @param signMessage - Optional function to sign message for migration (required if old encryption detected)
1681
+ * @param onMigrated - Optional callback when a value is migrated
1682
+ * @returns The decrypted plain text, original value if not encrypted, or placeholder on error
1683
+ */
1684
+ declare function decryptField(value: string, address: string, signMessage?: SignMessageFn, onMigrated?: (migratedValue: string) => Promise<void>): Promise<string>;
1685
+ /**
1686
+ * Memory data structure with fields that may be encrypted
1687
+ */
1688
+ interface MemoryData {
1689
+ value?: string;
1690
+ rawEvidence?: string;
1691
+ key?: string;
1692
+ namespace?: string;
1693
+ [key: string]: unknown;
1694
+ }
1695
+ /**
1696
+ * Encrypt sensitive fields in a memory object.
1697
+ * Only encrypts the fields defined in ENCRYPTED_FIELDS.
1698
+ * Embeddings and other indexed fields are left unencrypted.
1699
+ *
1700
+ * @param memory - The memory object with plain text fields
1701
+ * @param address - The user's wallet address
1702
+ * @returns A new memory object with sensitive fields encrypted
1703
+ */
1704
+ declare function encryptMemoryFields<T extends MemoryData>(memory: T, address: string): Promise<T>;
1705
+ /**
1706
+ * Decrypt sensitive fields in a memory object.
1707
+ * Only decrypts the fields defined in ENCRYPTED_FIELDS.
1708
+ * Automatically migrates old encrypted values to new format.
1709
+ * Also encrypts unencrypted fields when found (for users migrating to encryption).
1710
+ *
1711
+ * @param memory - The memory object with encrypted fields
1712
+ * @param address - The user's wallet address
1713
+ * @param signMessage - Optional function to sign message for migration (required if old encryption detected)
1714
+ * @param updateMemory - Optional function to update memory in storage after migration/encryption
1715
+ * @returns A new memory object with sensitive fields decrypted
1716
+ */
1717
+ declare function decryptMemoryFields<T extends MemoryData>(memory: T, address: string, signMessage?: SignMessageFn, updateMemory?: (id: string, data: Partial<T>) => Promise<void>): Promise<T>;
1718
+ /**
1719
+ * Batch encrypt multiple memory objects.
1720
+ * Uses parallel processing for performance.
1721
+ *
1722
+ * @param memories - Array of memory objects
1723
+ * @param address - The user's wallet address
1724
+ * @returns Array of memory objects with encrypted fields
1725
+ */
1726
+ declare function encryptMemoriesBatch<T extends MemoryData>(memories: T[], address: string): Promise<T[]>;
1727
+ /**
1728
+ * Batch decrypt multiple memory objects.
1729
+ * Uses parallel processing for performance.
1730
+ * Automatically migrates old encrypted values to new format.
1731
+ *
1732
+ * @param memories - Array of memory objects
1733
+ * @param address - The user's wallet address
1734
+ * @param signMessage - Optional function to sign message for migration (required if old encryption detected)
1735
+ * @param updateMemory - Optional function to update memory in storage after migration
1736
+ * @returns Array of memory objects with decrypted fields
1737
+ */
1738
+ declare function decryptMemoriesBatch<T extends MemoryData>(memories: T[], address: string, signMessage?: SignMessageFn, updateMemory?: (id: string, data: Partial<T>) => Promise<void>): Promise<T[]>;
1739
+ /**
1740
+ * Check if a memory has any encrypted fields.
1741
+ * Useful for determining if migration is needed.
1742
+ */
1743
+ declare function hasEncryptedFields(memory: MemoryData): boolean;
1744
+ /**
1745
+ * Check if a memory needs encryption (has unencrypted sensitive fields).
1746
+ */
1747
+ declare function needsEncryption(memory: MemoryData): boolean;
1748
+ /**
1749
+ * Memory fields needed for encryption update
1750
+ */
1751
+ interface MemoryEncryptionFields extends MemoryData {
1752
+ type: string;
1753
+ namespace: string;
1754
+ key: string;
1755
+ value: string;
1756
+ rawEvidence: string;
1757
+ confidence: number;
1758
+ pii: boolean;
1759
+ }
1760
+ /**
1761
+ * Memory object with the required fields for batch encryption
1762
+ */
1763
+ interface MemoryForBatchEncryption {
1764
+ uniqueId: string;
1765
+ type: string;
1766
+ namespace: string;
1767
+ key: string;
1768
+ value: string;
1769
+ rawEvidence: string;
1770
+ confidence: number;
1771
+ pii: boolean;
1772
+ }
1773
+ /**
1774
+ * Encrypt a batch of memories in parallel with rate limiting and retry logic.
1775
+ * Tracks failed memories for error reporting.
1776
+ *
1777
+ * @param memories - Array of memories to encrypt
1778
+ * @param address - User's wallet address
1779
+ * @param updateFn - Function to update a memory in storage
1780
+ * @param batchSize - Number of memories to process in parallel (default: 5)
1781
+ * @returns Object with success count and failed memory IDs
1782
+ */
1783
+ declare function encryptMemoriesBatchInPlace(memories: MemoryForBatchEncryption[], address: string, updateFn: (id: string, data: MemoryData) => Promise<unknown>, batchSize?: number): Promise<{
1784
+ success: number;
1785
+ failed: string[];
1786
+ errors: Array<{
1787
+ id: string;
1788
+ error: string;
1789
+ }>;
1790
+ }>;
1791
+
1591
1792
  declare const settingsStorageSchema: Readonly<{
1592
1793
  version: _nozbe_watermelondb_Schema.SchemaVersion;
1593
1794
  tables: _nozbe_watermelondb_Schema.TableMap;
@@ -2003,6 +2204,7 @@ declare function useDropboxBackup(options: UseDropboxBackupOptions): UseDropboxB
2003
2204
  declare function clearToken(): void;
2004
2205
  /**
2005
2206
  * Check if we have any stored credentials (including refresh token)
2207
+ * Works with both encrypted and unencrypted credentials
2006
2208
  */
2007
2209
  declare function hasDropboxCredentials(): boolean;
2008
2210
 
@@ -2112,6 +2314,7 @@ declare function getGoogleDriveStoredToken(): string | null;
2112
2314
  declare function clearGoogleDriveToken(): void;
2113
2315
  /**
2114
2316
  * Check if we have any stored credentials (including refresh token)
2317
+ * Works with both encrypted and unencrypted credentials
2115
2318
  */
2116
2319
  declare function hasGoogleDriveCredentials(): boolean;
2117
2320
 
@@ -2933,4 +3136,4 @@ interface UseBackupResult {
2933
3136
  */
2934
3137
  declare function useBackup(options: UseBackupOptions): UseBackupResult;
2935
3138
 
2936
- export { DEFAULT_CONVERSATIONS_FOLDER as BACKUP_DRIVE_CONVERSATIONS_FOLDER, DEFAULT_ROOT_FOLDER as BACKUP_DRIVE_ROOT_FOLDER, DEFAULT_BACKUP_FOLDER as BACKUP_ICLOUD_FOLDER, type BackupAuthContextValue, BackupAuthProvider, type BackupAuthProviderProps, type BackupOperationOptions, Conversation as ChatConversation, Message as ChatMessage, type ChatRole, type CreateConversationOptions, type CreateMemoryOptions, type CreateMessageOptions, type CreateModelPreferenceOptions, DEFAULT_BACKUP_FOLDER$1 as DEFAULT_BACKUP_FOLDER, DEFAULT_CONVERSATIONS_FOLDER as DEFAULT_DRIVE_CONVERSATIONS_FOLDER, DEFAULT_ROOT_FOLDER as DEFAULT_DRIVE_ROOT_FOLDER, DEFAULT_BACKUP_FOLDER$1 as DEFAULT_DROPBOX_FOLDER, DEFAULT_BACKUP_FOLDER as DEFAULT_ICLOUD_BACKUP_FOLDER, type DropboxAuthContextValue, DropboxAuthProvider, type DropboxAuthProviderProps, type DropboxExportResult, type DropboxImportResult, type FileMetadata, type GoogleDriveAuthContextValue, GoogleDriveAuthProvider, type GoogleDriveAuthProviderProps, type GoogleDriveExportResult, type GoogleDriveImportResult, type ICloudAuthContextValue, ICloudAuthProvider, type ICloudAuthProviderProps, type ICloudExportResult, type ICloudImportResult, type MemoryItem, type MemoryType, type OCRFile, type PdfFile, type ProgressCallback, type ProviderAuthState, type ProviderBackupState, type SearchMessagesOptions, type SearchSource, type SendMessageWithStorageArgs, type SendMessageWithStorageResult, type SignMessageFn, type ChatCompletionUsage as StoredChatCompletionUsage, type StoredConversation, type StoredMemory, Memory as StoredMemoryModel, type StoredMemoryWithSimilarity, type StoredMessage, type StoredMessageWithSimilarity, type StoredModelPreference, ModelPreference as StoredModelPreferenceModel, type UpdateMemoryOptions, type UpdateModelPreferenceOptions, type UseBackupOptions, type UseBackupResult, type UseChatStorageOptions, type UseChatStorageResult, type UseDropboxBackupOptions, type UseDropboxBackupResult, type UseGoogleDriveBackupOptions, type UseGoogleDriveBackupResult, type UseICloudBackupOptions, type UseICloudBackupResult, type UseMemoryStorageOptions, type UseMemoryStorageResult, type UseSettingsOptions, type UseSettingsResult, chatStorageMigrations, chatStorageSchema, clearAllEncryptionKeys, clearToken as clearDropboxToken, clearEncryptionKey, clearGoogleDriveToken, clearICloudAuth, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, extractConversationContext, formatMemoriesForChat, generateCompositeKey, generateConversationId, generateUniqueKey, getGoogleDriveStoredToken, hasDropboxCredentials, hasEncryptionKey, hasGoogleDriveCredentials, hasICloudCredentials, memoryStorageSchema, requestEncryptionKey, sdkMigrations, sdkModelClasses, sdkSchema, settingsStorageSchema, useBackup, useBackupAuth, useChat, useChatStorage, useDropboxAuth, useDropboxBackup, useEncryption, useGoogleDriveAuth, useGoogleDriveBackup, useICloudAuth, useICloudBackup, useImageGeneration, useMemoryStorage, useModels, useOCR, usePdf, useSearch, useSettings };
3139
+ export { DEFAULT_CONVERSATIONS_FOLDER as BACKUP_DRIVE_CONVERSATIONS_FOLDER, DEFAULT_ROOT_FOLDER as BACKUP_DRIVE_ROOT_FOLDER, DEFAULT_BACKUP_FOLDER as BACKUP_ICLOUD_FOLDER, type BackupAuthContextValue, BackupAuthProvider, type BackupAuthProviderProps, type BackupOperationOptions, Conversation as ChatConversation, Message as ChatMessage, type ChatRole, type CreateConversationOptions, type CreateMemoryOptions, type CreateMessageOptions, type CreateModelPreferenceOptions, DECRYPTION_FAILED_PLACEHOLDER, DEFAULT_BACKUP_FOLDER$1 as DEFAULT_BACKUP_FOLDER, DEFAULT_CONVERSATIONS_FOLDER as DEFAULT_DRIVE_CONVERSATIONS_FOLDER, DEFAULT_ROOT_FOLDER as DEFAULT_DRIVE_ROOT_FOLDER, DEFAULT_BACKUP_FOLDER$1 as DEFAULT_DROPBOX_FOLDER, DEFAULT_BACKUP_FOLDER as DEFAULT_ICLOUD_BACKUP_FOLDER, type DropboxAuthContextValue, DropboxAuthProvider, type DropboxAuthProviderProps, type DropboxExportResult, type DropboxImportResult, type FileMetadata, type GoogleDriveAuthContextValue, GoogleDriveAuthProvider, type GoogleDriveAuthProviderProps, type GoogleDriveExportResult, type GoogleDriveImportResult, type ICloudAuthContextValue, ICloudAuthProvider, type ICloudAuthProviderProps, type ICloudExportResult, type ICloudImportResult, type MemoryData, type MemoryEncryptionFields, type MemoryItem, type MemoryType, type OCRFile, type PdfFile, type ProgressCallback, type ProviderAuthState, type ProviderBackupState, type SearchMessagesOptions, type SearchSource, type SendMessageWithStorageArgs, type SendMessageWithStorageResult, type SignMessageFn, type ChatCompletionUsage as StoredChatCompletionUsage, type StoredConversation, type StoredMemory, Memory as StoredMemoryModel, type StoredMemoryWithSimilarity, type StoredMessage, type StoredMessageWithSimilarity, type StoredModelPreference, ModelPreference as StoredModelPreferenceModel, type UpdateMemoryOptions, type UpdateModelPreferenceOptions, type UseBackupOptions, type UseBackupResult, type UseChatStorageOptions, type UseChatStorageResult, type UseDropboxBackupOptions, type UseDropboxBackupResult, type UseGoogleDriveBackupOptions, type UseGoogleDriveBackupResult, type UseICloudBackupOptions, type UseICloudBackupResult, type UseMemoryStorageOptions, type UseMemoryStorageResult, type UseSettingsOptions, type UseSettingsResult, chatStorageMigrations, chatStorageSchema, clearAllEncryptionKeys, clearAllKeyPairs, clearToken as clearDropboxToken, clearEncryptionKey, clearGoogleDriveToken, clearICloudAuth, clearKeyPair, createMemoryContextSystemMessage, decryptData, decryptDataBytes, decryptField, decryptMemoriesBatch, decryptMemoryFields, encryptData, encryptField, encryptMemoriesBatch, encryptMemoriesBatchInPlace, encryptMemoryFields, exportPublicKey, extractConversationContext, formatMemoriesForChat, generateCompositeKey, generateConversationId, generateUniqueKey, getEncryptionVersion, getGoogleDriveStoredToken, hasDropboxCredentials, hasEncryptedFields, hasEncryptionKey, hasGoogleDriveCredentials, hasICloudCredentials, hasKeyPair, memoryStorageSchema, needsEncryption, requestEncryptionKey, requestKeyPair, sdkMigrations, sdkModelClasses, sdkSchema, settingsStorageSchema, useBackup, useBackupAuth, useChat, useChatStorage, useDropboxAuth, useDropboxBackup, useEncryption, useGoogleDriveAuth, useGoogleDriveBackup, useICloudAuth, useICloudBackup, useImageGeneration, useMemoryStorage, useModels, useOCR, usePdf, useSearch, useSettings };