import type { SessionKey } from '@mysten/seal'; import type { Signer } from '@mysten/sui/cryptography'; import type { MessagingCompatibleClient } from '../types.js'; export interface EnvelopeEncryptionConfig { suiClient: MessagingCompatibleClient; sealApproveContract: SealApproveContract; sessionKey?: SessionKey; sessionKeyConfig?: SessionKeyConfig; encryptionPrimitives?: EncryptionPrimitives; sealConfig?: SealConfig; } export interface SessionKeyConfig { address: string; mvrName?: string; ttlMin: number; signer?: Signer; } export interface SealApproveContract { packageId: string; module: string; functionName: string; } /** * Seal configuration for messaging operations * * Note: This is separate from SealClient configuration! * - SealClient configuration (via SealClient.asClientExtension): Configures which key servers to use * - MessagingClient SealConfig: Configures operation parameters like encryption threshold */ export interface SealConfig { /** * Encryption threshold for Seal operations (default: 2) * This determines how many key servers must participate in encryption/decryption */ threshold?: number; } /** * Interface for encryption primitives used in messaging encryption */ export interface EncryptionPrimitives { generateDEK(length?: number): Promise>; generateNonce(length?: number): Uint8Array; encryptBytes(key: Uint8Array, nonce: Uint8Array, aad: Uint8Array, bytesToEncrypt: Uint8Array): Promise>; decryptBytes(key: Uint8Array, nonce: Uint8Array, aad: Uint8Array, encryptedBytes: Uint8Array): Promise>; } /** * Represents an encryption key that can be used for both encryption and decryption */ export interface SymmetricKey { $kind: 'Unencrypted'; bytes: Uint8Array; version: number; } export interface DecryptChannelDEKOpts { encryptedKey: EncryptedSymmetricKey; memberCapId: string; channelId: string; } /** * Represents an encrypted symmetric key that needs to be decrypted before use */ export interface EncryptedSymmetricKey { $kind: 'Encrypted'; encryptedBytes: Uint8Array; version: number; } export type EncryptionKey = SymmetricKey | EncryptedSymmetricKey; export interface EncryptionPrimitivesConfig { keySize: number; nonceSize: number; dekAlgorithm: 'AES-GCM'; } export interface EncryptAAD { channelId: string; keyVersion: number; sender: string; } export interface CommonEncryptOpts { channelId: string; sender: string; encryptedKey: EncryptedSymmetricKey; memberCapId: string; } export interface GenerateEncryptedChannelDEKopts { channelId: string; } /** * Represents an encrypted payload along with its metadata */ export interface EncryptedPayload { encryptedBytes: Uint8Array; nonce: Uint8Array; } export interface EncryptTextOpts extends CommonEncryptOpts { text: string; } export interface DecryptTextOpts extends CommonEncryptOpts, EncryptedPayload { } export interface AttachmentMetadata { fileName: string; mimeType: string; fileSize: number; } export interface EncryptAttachmentOpts extends CommonEncryptOpts { file: File; } export interface EncryptedAttachmentPayload { data: EncryptedPayload; metadata: EncryptedPayload; } export interface DecryptAttachmentMetadataOpts extends CommonEncryptOpts, EncryptedPayload { } export interface DecryptAttachmentDataOpts extends CommonEncryptOpts, EncryptedPayload { } export interface DecryptAttachmentOpts extends CommonEncryptOpts, EncryptedAttachmentPayload { } export interface DecryptAttachmentResult extends AttachmentMetadata { data: Uint8Array; } export interface DecryptAttachmentDataResult { data: Uint8Array; } export type DecryptAttachmentMetadataResult = AttachmentMetadata; export interface EncryptMessageOpts extends CommonEncryptOpts { text: string; attachments?: File[]; } export interface EncryptedMessagePayload { text: EncryptedPayload; attachments?: EncryptedAttachmentPayload[]; } export interface DecryptMessageOpts extends CommonEncryptOpts { ciphertext: Uint8Array; nonce: Uint8Array; attachments?: EncryptedAttachmentPayload[]; } export interface DecryptMessageResult { text: string; attachments?: DecryptAttachmentResult[]; }