@sentclose/sentc-nodejs
Version:
End-to-end encryption sdk
194 lines (193 loc) • 9.44 kB
TypeScript
/// <reference types="node" />
/// <reference types="node" />
import { AbstractAsymCrypto } from "./crypto/AbstractAsymCrypto";
import { FileCreateOutput, FileMetaInformation, FilePrepareCreateOutput, GroupOutDataHmacKeys, UserData, UserPublicKeyData } from "./Enities";
import { UserData as NativeUserData } from "@sentclose/sentc_node_js";
import { SymKey } from ".";
import { GroupInviteListItem, GroupList, OtpRegister, UserDeviceList } from "@sentclose/sentc-common";
import { FileHandle } from "node:fs/promises";
export declare function getUser(deviceIdentifier: string, data: NativeUserData, mfa: boolean): Promise<User>;
export declare class User extends AbstractAsymCrypto {
user_data: UserData;
private userIdentifier;
group_invites: GroupInviteListItem[];
constructor(base_url: string, app_token: string, user_data: UserData, userIdentifier: string, group_invites?: GroupInviteListItem[]);
private getUserKeys;
private getUserKeysSync;
getUserSymKey(key_id: string): Promise<string>;
getPrivateKey(key_id: string): Promise<string>;
getPrivateKeySync(key_id: string): string;
getPublicKey(reply_id: string): Promise<UserPublicKeyData>;
getNewestHmacKey(): string;
private getNewestKey;
getNewestPublicKey(): string;
getNewestSignKey(): string;
getSignKey(): Promise<string>;
getSignKeySync(): string;
enabledMfa(): boolean;
decryptHmacKeys(fetchedKeys: GroupOutDataHmacKeys[]): Promise<string[]>;
fetchUserKey(key_id: string, first?: boolean): Promise<any>;
getJwt(): Promise<string>;
private getFreshJwt;
updateUser(newIdentifier: string): Promise<void>;
registerRawOtp(password: string, mfa_token?: string, mfa_recovery?: boolean): Promise<OtpRegister>;
registerOtp(issuer: string, audience: string, password: string, mfa_token?: string, mfa_recovery?: boolean): Promise<[string, string[]]>;
getOtpRecoverKeys(password: string, mfa_token?: string, mfa_recovery?: boolean): Promise<string[]>;
resetRawOtp(password: string, mfa_token?: string, mfa_recovery?: boolean): Promise<OtpRegister>;
resetOtp(issuer: string, audience: string, password: string, mfa_token?: string, mfa_recovery?: boolean): Promise<[string, string[]]>;
disableOtp(password: string, mfa_token?: string, mfa_recovery?: boolean): Promise<any>;
resetPassword(newPassword: string): Promise<void>;
changePassword(oldPassword: string, newPassword: string, mfa_token?: string, mfa_recovery?: boolean): Promise<void>;
logOut(): Promise<void>;
deleteUser(password: string, mfa_token?: string, mfa_recovery?: boolean): Promise<void>;
deleteDevice(password: string, device_id: string, mfa_token?: string, mfa_recovery?: boolean): Promise<void>;
prepareRegisterDevice(server_output: string, page?: number): import("@sentclose/sentc_node_js").PreRegisterDeviceData;
registerDevice(server_output: string): Promise<PromiseSettledResult<any>[]>;
getDevices(last_fetched_item?: UserDeviceList | null): Promise<UserDeviceList[]>;
createSafetyNumber(user_to_compare?: {
user_id: string;
verify_key_id: string;
}): Promise<string>;
keyRotation(): Promise<any>;
finishKeyRotation(): Promise<void>;
getGroups(last_fetched_item?: GroupList | null): Promise<GroupList[]>;
getGroupInvites(last_fetched_item?: GroupInviteListItem | null): Promise<GroupInviteListItem[]>;
acceptGroupInvite(group_id: string): Promise<void>;
rejectGroupInvite(group_id: string): Promise<void>;
groupJoinRequest(group_id: string): Promise<void>;
sentJoinReq(last_fetched_item?: GroupInviteListItem | null): Promise<GroupInviteListItem[]>;
deleteJoinReq(id: string): Promise<void>;
prepareGroupCreate(sign?: boolean): string;
createGroup(sign?: boolean): Promise<string>;
getGroup(group_id: string, group_as_member?: string, verify?: number): Promise<import("./Group").Group>;
/**
* 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<FilePrepareCreateOutput>;
/**
* 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
*
* this file is registered for another user to open it
*
* @param file
* @param reply_id
* @throws SentcError
*/
prepareRegisterFile(file: File, reply_id: string): Promise<FilePrepareCreateOutput>;
/**
* 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
*
*/
uploadFile(fileHandle: FileHandle, fileSize: number, content_key: SymKey, session_id: string): Promise<void>;
/**
* Upload a registered file.
* Session id is returned from the sentc api. The rest from @prepareRegisterFile
* upload the chunks signed by the creator sign key
*
*/
uploadFile(fileHandle: FileHandle, fileSize: number, content_key: SymKey, session_id: string, sign: true): Promise<void>;
/**
* Upload a registered file.
* Session id is returned from the sentc api. The rest from @prepareRegisterFile
* optionally upload the chunks signed by the creators sign key
* Show the upload progress of how many chunks are already uploaded
*
*/
uploadFile(fileHandle: FileHandle, fileSize: number, content_key: SymKey, session_id: string, sign: boolean, upload_callback: (progress?: number) => void): Promise<void>;
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
*
*/
downloadFileWithMetaInfo(fileHandle: FileHandle, key: SymKey, file_meta: FileMetaInformation): Promise<void>;
/**
* The same but with a verify-key to verify each file part
*
*/
downloadFileWithMetaInfo(fileHandle: FileHandle, key: SymKey, file_meta: FileMetaInformation, verify_key: string): Promise<void>;
/**
* The same but with optional verify key and a function to show the download progress
*
*/
downloadFileWithMetaInfo(fileHandle: FileHandle, key: SymKey, file_meta: FileMetaInformation, verify_key: string, updateProgressCb: (progress: number) => void): Promise<void>;
/**
* Register and upload a file to the sentc api.
* The file will be encrypted
*
*/
createFile(file: FileHandle, file_name: string): Promise<FileCreateOutput>;
/**
* Create a file and sign each file part with the sign key of the creator
*
*/
createFile(file: FileHandle, file_name: string, sign: true): Promise<FileCreateOutput>;
createFile(file: FileHandle, file_name: string, sign: boolean, reply_id: string): Promise<FileCreateOutput>;
/**
* The same but with optional signing and a function to show the upload progress
*
*/
createFile(file: FileHandle, file_name: string, sign: boolean, reply_id: string, upload_callback: (progress?: number) => void): Promise<FileCreateOutput>;
/**
* Register and upload a file to the sentc api.
* The file will be encrypted
*
*/
createFileWithPath(path: string): Promise<FileCreateOutput>;
/**
* Create a file and sign each file part with the sign key of the creator
*
*/
createFileWithPath(path: string, sign: true): Promise<FileCreateOutput>;
createFileWithPath(path: string, sign: boolean, reply_id: string): Promise<FileCreateOutput>;
/**
* Download a file. THis function will also download the file meta-information before
*
*/
downloadFile(file_path: string, file_id: string): Promise<[FileMetaInformation, SymKey]>;
/**
* The same but with a verify-key of the file creator
*
*/
downloadFile(file_path: string, file_id: string, verify_key: string): Promise<[FileMetaInformation, SymKey]>;
/**
* The same but with an optional verify-key and a function to show the download progress
*
*/
downloadFile(file_path: string, file_id: string, verify_key: string, updateProgressCb: (progress: number) => void): Promise<[FileMetaInformation, SymKey]>;
updateFileName(file_id: string, content_key: SymKey, file_name?: string): Promise<void>;
deleteFile(file_id: string): Promise<void>;
}