/** * @author Jörn Heinemann * @since 2022/08/12 */ import { FileCreateOutput, FileMetaInformation, FilePrepareCreateOutput, GroupData, GroupJoinReqListItem, GroupKey, GroupOutDataHmacKeys, GroupOutDataKeys, GroupOutDataSortableKeys, GroupUserListItem, UserKeyData } from "./Enities"; import { AbstractSymCrypto } from "./crypto/AbstractSymCrypto"; import { User } from "./User"; import { SymKey } from "."; import { GroupChildrenListItem, GroupList, GroupInviteListItem } from "@sentclose/sentc-common"; export declare function prepareKeys(keys: GroupKey[] | UserKeyData[], page?: number): [string, boolean]; /** * Get a group, from the storage or the server * */ export declare function getGroup(group_id: string, base_url: string, app_token: string, user: User, parent?: boolean, group_as_member?: string, verify?: number, rek?: boolean): Promise; export declare class Group extends AbstractSymCrypto { data: GroupData; private user; constructor(data: GroupData, base_url: string, app_token: string, user: User); set groupKeys(keys: GroupKey[]); set groupKeyMap(key_map: Map); getChildGroup(group_id: string, verify?: number): Promise; getConnectedGroup(group_id: string, verify?: number): Promise; getChildren(last_fetched_item?: GroupChildrenListItem | null): Promise; prepareCreateChildGroup(sign?: boolean): string[]; createChildGroup(sign?: boolean): Promise; createConnectedGroup(sign?: boolean): Promise; groupUpdateCheck(): Promise; getMember(last_fetched_item?: GroupUserListItem | null): Promise; stopInvites(): Promise; prepareKeysForNewMember(user_id: string, rank?: number, page?: number, group?: boolean): Promise; handleInviteSessionKeysForNewMember(session_id: string, user_id: string, auto?: boolean, group?: boolean): Promise[]>; invite(user_id: string, rank?: number): Promise[]>; inviteAuto(user_id: string, rank?: number): Promise[]>; inviteGroup(group_id: string, rank?: number): Promise[]>; inviteGroupAuto(group_id: string, rank?: number): Promise[]>; reInviteUser(user_id: string): Promise[]>; reInviteGroup(group_id: string): Promise[]>; private inviteUserInternally; getJoinRequests(last_fetched_item?: GroupJoinReqListItem | null): Promise; rejectJoinRequest(user_id: string): Promise; acceptJoinRequest(user_id: string, user_type?: 0 | 2, rank?: number): Promise[]>; leave(): Promise; /** * Get the actual used public key. * For the user, or if user joined via parent group the parent group public key * * Returns only the public key format, not the exported public key! * * @private */ private getPublicKey; private getNewestKey; /** * Gets the right private key to the used public key * * If it is from user -> get it from user * * If not then form the parent group * * @param private_key_id * @private */ private getPrivateKey; private getKeyRotationServerOut; /** * Prepares the key rotation to use it with own backend. * * The newest public key is used to encrypt the key for the starter. * If the starter joined via parent group then the parent group public key is used */ prepareKeyRotation(sign?: boolean): Promise; keyRotation(sign?: boolean): Promise; finishKeyRotation(verify?: number): Promise; prepareUpdateRank(user_id: string, new_rank: number): string; updateRank(user_id: string, new_rank: number): Promise; kickUser(user_id: string): Promise; getGroups(last_fetched_item?: GroupList | null): Promise; getGroupInvites(last_fetched_item?: GroupInviteListItem | null): Promise; acceptGroupInvite(group_id: string): Promise; rejectGroupInvite(group_id: string): Promise; groupJoinRequest(group_id: string): Promise; sentJoinReq(last_fetched_item?: GroupInviteListItem | null): Promise; deleteJoinReq(id: string): Promise; deleteGroup(): Promise; fetchKeys(jwt: string, verify?: number): Promise; /** * Decrypt the key with the right private key. * * get the right private key for each key * * @param fetchedKeys * @param verify */ decryptKey(fetchedKeys: GroupOutDataKeys[], verify?: number): Promise; decryptHmacKeys(fetchedKeys: GroupOutDataHmacKeys[]): Promise; decryptSortableKeys(fetchedKeys: GroupOutDataSortableKeys[]): Promise; private prepareKeys; private getGroupKey; private getGroupKeySync; getSymKeyToEncrypt(): Promise<[string, string]>; getSymKeyToEncryptSync(): [string, string]; getSymKeyById(key_id: string): Promise; getSymKeyByIdSync(key_id: string): string; getJwt(): Promise; getSignKey(): Promise; getSignKeySync(): string; getNewestHmacKey(): string; getNewestSortableKey(): string; /** * Prepare the register of a file. The server input could be passed to the sentc api from your backend * * encrypted_file_name, key and master_key_id are only for the frontend to encrypt more data if necessary * * @param file * @throws SentcError */ prepareRegisterFile(file: File): Promise; /** * Validates the sentc file register output * Returns the file id * * @param server_output */ doneFileRegister(server_output: string): string[]; /** * Upload a registered file. * Session id is returned from the sentc api. The rest from @prepareRegisterFile * * @param file * @param content_key * @param session_id */ uploadFile(file: File, content_key: SymKey, session_id: string): Promise; /** * Upload a registered file. * Session id is returned from the sentc api. The rest from @prepareRegisterFile * upload the chunks signed by the creators sign key * * @param file * @param content_key * @param session_id * @param sign */ uploadFile(file: File, content_key: SymKey, session_id: string, sign: true): Promise; /** * Upload a registered file. * Session id is returned from the sentc api. The rest from @prepareRegisterFile * optional upload the chunks signed by the creators sign key * Show the upload progress of how many chunks are already uploaded * * @param file * @param content_key * @param session_id * @param sign * @param upload_callback */ uploadFile(file: File, content_key: SymKey, session_id: string, sign: boolean, upload_callback: (progress?: number) => void): Promise; private getFileMetaInfo; /** * Get the FileMetaInformation which contains all Information about the file * Return also the file key back. * * This function can be used if the user needs the decrypted file name. * * @param file_id */ downloadFileMetaInfo(file_id: string): Promise<[FileMetaInformation, SymKey]>; /** * The same but with a verify key * * @param file_id * @param verify_key */ downloadFileMetaInfo(file_id: string, verify_key: string): Promise<[FileMetaInformation, SymKey]>; /** * Download a file but with already downloaded file information and * the file key to not fetch the info and the key again. * * This function can be used after the downloadFileMetaInfo function * * @param key * @param file_meta */ downloadFileWithMetaInfo(key: SymKey, file_meta: FileMetaInformation): Promise; /** * The same but with a verify key to verify each file part * * @param key * @param file_meta * @param verify_key */ downloadFileWithMetaInfo(key: SymKey, file_meta: FileMetaInformation, verify_key: string): Promise; /** * The same but with optional verify key and a function to show the download progress * * @param key * @param file_meta * @param verify_key * @param updateProgressCb */ downloadFileWithMetaInfo(key: SymKey, file_meta: FileMetaInformation, verify_key: string, updateProgressCb: (progress: number) => void): Promise; /** * Register and upload a file to the sentc api. * The file will be encrypted * * @param file */ createFile(file: File): Promise; /** * Create a file and sign each file part with the sign key of the creator * * @param file * @param sign */ createFile(file: File, sign: true): Promise; /** * The same but with optional signing and a function to show the upload progress * * @param file * @param sign * @param upload_callback */ createFile(file: File, sign: boolean, upload_callback: (progress?: number) => void): Promise; /** * Download a file. THis function will also download the file meta information before * * @param file_id */ downloadFile(file_id: string): Promise<[string, FileMetaInformation, SymKey]>; /** * The same but with a verify key of the file creator * * @param file_id * @param verify_key */ downloadFile(file_id: string, verify_key: string): Promise<[string, FileMetaInformation, SymKey]>; /** * The same but with an optional verify key and a function to show the download progress * * @param file_id * @param verify_key * @param updateProgressCb */ downloadFile(file_id: string, verify_key: string, updateProgressCb: (progress: number) => void): Promise<[string, FileMetaInformation, SymKey]>; /** * Delete a file at the backend. Only creator or group admin can delete files * * @param file_id */ deleteFile(file_id: string): Promise; createSearchRaw(data: string, full?: boolean, limit?: number): string[]; createSearch(data: string, full?: boolean, limit?: number): [string[], string, string]; search(data: string): string; encryptSortableRawNumber(number: number): bigint; encryptSortableNumber(number: number): [BigInt, string, string]; encryptSortableRawString(data: string): bigint; encryptSortableString(data: string): [BigInt, string, string]; }