π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Remove unused code
Neeraj Gupta155ab947a4e9
diff --git a/apps/cast/src/constants/crypto.ts b/apps/cast/src/constants/crypto.tsdeleted file mode 100644index e39e675030..0000000000--- a/apps/cast/src/constants/crypto.ts+++ /dev/null@@ -1,7 +0,0 @@-export const ENCRYPTION_CHUNK_SIZE = 4 * 1024 * 1024;--export enum PasswordStrength {- WEAK = 'WEAK',- MODERATE = 'MODERATE',- STRONG = 'STRONG',-}diff --git a/apps/cast/src/services/downloadManager.ts b/apps/cast/src/services/downloadManager.tsindex caa579e1bc..f4b855bf39 100644--- a/apps/cast/src/services/downloadManager.ts+++ b/apps/cast/src/services/downloadManager.ts@@ -18,6 +18,7 @@ import { getToken } from '@ente/shared/storage/localStorage/helpers';import { getFileURL, getThumbnailURL } from '@ente/shared/network/api';import HTTPService from '@ente/shared/network/HTTPService';import { logError } from '@ente/shared/sentry';+import { addLogLine } from '@ente/shared/logging';class DownloadManager {private fileObjectURLPromise = new Map<diff --git a/apps/cast/src/services/ffmpeg/ffmpegService.ts b/apps/cast/src/services/ffmpeg/ffmpegService.tsindex 7766947192..4e6a6241fb 100644--- a/apps/cast/src/services/ffmpeg/ffmpegService.ts+++ b/apps/cast/src/services/ffmpeg/ffmpegService.ts@@ -4,79 +4,9 @@ import {OUTPUT_PATH_PLACEHOLDER,} from 'constants/ffmpeg';import { ElectronFile } from 'types/upload';-import { parseFFmpegExtractedMetadata } from 'utils/ffmpeg';import ffmpegFactory from './ffmpegFactory';import { logError } from '@ente/shared/sentry';-export async function generateVideoThumbnail(- file: File | ElectronFile-): Promise<File | ElectronFile> {- try {- let seekTime = 1;- const ffmpegClient = await ffmpegFactory.getFFmpegClient();- while (seekTime >= 0) {- try {- return await ffmpegClient.run(- [- FFMPEG_PLACEHOLDER,- '-i',- INPUT_PATH_PLACEHOLDER,- '-ss',- `00:00:0${seekTime}`,- '-vframes',- '1',- '-vf',- 'scale=-1:720',- OUTPUT_PATH_PLACEHOLDER,- ],- file,- 'thumb.jpeg'- );- } catch (e) {- if (seekTime === 0) {- throw e;- }- }- seekTime--;- }- } catch (e) {- logError(e, 'ffmpeg generateVideoThumbnail failed');- throw e;- }-}--export async function extractVideoMetadata(file: File | ElectronFile) {- try {- const ffmpegClient = await ffmpegFactory.getFFmpegClient();- // https://stackoverflow.com/questions/9464617/retrieving-and-saving-media-metadata-using-ffmpeg- // -c [short for codex] copy[(stream_specifier)[ffmpeg.org/ffmpeg.html#Stream-specifiers]] => copies all the stream without re-encoding- // -map_metadata [http://ffmpeg.org/ffmpeg.html#Advanced-options search for map_metadata] => copies all stream metadata to the out- // -f ffmetadata [https://ffmpeg.org/ffmpeg-formats.html#Metadata-1] => dump metadata from media files into a simple UTF-8-encoded INI-like text file- const metadata = await ffmpegClient.run(- [- FFMPEG_PLACEHOLDER,- '-i',- INPUT_PATH_PLACEHOLDER,- '-c',- 'copy',- '-map_metadata',- '0',- '-f',- 'ffmetadata',- OUTPUT_PATH_PLACEHOLDER,- ],- file,- `metadata.txt`- );- return parseFFmpegExtractedMetadata(- new Uint8Array(await metadata.arrayBuffer())- );- } catch (e) {- logError(e, 'ffmpeg extractVideoMetadata failed');- throw e;- }-}-export async function convertToMP4(file: File | ElectronFile) {try {const ffmpegClient = await ffmpegFactory.getFFmpegClient();diff --git a/apps/cast/src/types/crypto/index.ts b/apps/cast/src/types/crypto/index.tsdeleted file mode 100644index 6b5a64b44a..0000000000--- a/apps/cast/src/types/crypto/index.ts+++ /dev/null@@ -1,19 +0,0 @@-import { DataStream } from 'types/upload';--export interface LocalFileAttributes<- T extends string | Uint8Array | DataStream-> {- encryptedData: T;- decryptionHeader: string;-}--export interface EncryptionResult<T extends string | Uint8Array | DataStream> {- file: LocalFileAttributes<T>;- key: string;-}--export interface B64EncryptionResult {- encryptedData: string;- key: string;- nonce: string;-}diff --git a/apps/cast/src/types/crypto/libsodium.ts b/apps/cast/src/types/crypto/libsodium.tsdeleted file mode 100644index 02c12c8dfc..0000000000--- a/apps/cast/src/types/crypto/libsodium.ts+++ /dev/null@@ -1,422 +0,0 @@-import sodium, { StateAddress } from 'libsodium-wrappers';-import { ENCRYPTION_CHUNK_SIZE } from 'constants/crypto';-import { B64EncryptionResult } from 'types/crypto';-import { CustomError } from '@ente/shared/error';--export async function decryptChaChaOneShot(- data: Uint8Array,- header: Uint8Array,- key: string-) {- await sodium.ready;- const pullState = sodium.crypto_secretstream_xchacha20poly1305_init_pull(- header,- await fromB64(key)- );- const pullResult = sodium.crypto_secretstream_xchacha20poly1305_pull(- pullState,- data,- null- );- return pullResult.message;-}--export async function decryptChaCha(- data: Uint8Array,- header: Uint8Array,- key: string-) {- await sodium.ready;- const pullState = sodium.crypto_secretstream_xchacha20poly1305_init_pull(- header,- await fromB64(key)- );- const decryptionChunkSize =- ENCRYPTION_CHUNK_SIZE +- sodium.crypto_secretstream_xchacha20poly1305_ABYTES;- let bytesRead = 0;- const decryptedData = [];- let tag = sodium.crypto_secretstream_xchacha20poly1305_TAG_MESSAGE;- while (tag !== sodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL) {- let chunkSize = decryptionChunkSize;- if (bytesRead + chunkSize > data.length) {- chunkSize = data.length - bytesRead;- }- const buffer = data.slice(bytesRead, bytesRead + chunkSize);- const pullResult = sodium.crypto_secretstream_xchacha20poly1305_pull(- pullState,- buffer- );- if (!pullResult.message) {- throw new Error(CustomError.PROCESSING_FAILED);- }- for (let index = 0; index < pullResult.message.length; index++) {- decryptedData.push(pullResult.message[index]);- }- tag = pullResult.tag;- bytesRead += chunkSize;- }- return Uint8Array.from(decryptedData);-}--export async function initChunkDecryption(header: Uint8Array, key: Uint8Array) {- await sodium.ready;- const pullState = sodium.crypto_secretstream_xchacha20poly1305_init_pull(- header,- key- );- const decryptionChunkSize =- ENCRYPTION_CHUNK_SIZE +- sodium.crypto_secretstream_xchacha20poly1305_ABYTES;- const tag = sodium.crypto_secretstream_xchacha20poly1305_TAG_MESSAGE;- return { pullState, decryptionChunkSize, tag };-}--export async function decryptFileChunk(- data: Uint8Array,- pullState: StateAddress-) {- await sodium.ready;- const pullResult = sodium.crypto_secretstream_xchacha20poly1305_pull(- pullState,- data- );- if (!pullResult.message) {- throw new Error(CustomError.PROCESSING_FAILED);- }- const newTag = pullResult.tag;- return { decryptedData: pullResult.message, newTag };-}--export async function encryptChaChaOneShot(data: Uint8Array, key: string) {- await sodium.ready;-- const uintkey: Uint8Array = await fromB64(key);- const initPushResult =- sodium.crypto_secretstream_xchacha20poly1305_init_push(uintkey);- const [pushState, header] = [initPushResult.state, initPushResult.header];-- const pushResult = sodium.crypto_secretstream_xchacha20poly1305_push(- pushState,- data,- null,- sodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL- );- return {- key: await toB64(uintkey),- file: {- encryptedData: pushResult,- decryptionHeader: await toB64(header),- },- };-}--export async function encryptChaCha(data: Uint8Array) {- await sodium.ready;-- const uintkey: Uint8Array =- sodium.crypto_secretstream_xchacha20poly1305_keygen();-- const initPushResult =- sodium.crypto_secretstream_xchacha20poly1305_init_push(uintkey);- const [pushState, header] = [initPushResult.state, initPushResult.header];- let bytesRead = 0;- let tag = sodium.crypto_secretstream_xchacha20poly1305_TAG_MESSAGE;-- const encryptedData = [];-- while (tag !== sodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL) {- let chunkSize = ENCRYPTION_CHUNK_SIZE;- if (bytesRead + chunkSize >= data.length) {- chunkSize = data.length - bytesRead;- tag = sodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL;- }-- const buffer = data.slice(bytesRead, bytesRead + chunkSize);- bytesRead += chunkSize;- const pushResult = sodium.crypto_secretstream_xchacha20poly1305_push(- pushState,- buffer,- null,- tag- );- for (let index = 0; index < pushResult.length; index++) {- encryptedData.push(pushResult[index]);- }- }- return {- key: await toB64(uintkey),- file: {- encryptedData: new Uint8Array(encryptedData),- decryptionHeader: await toB64(header),- },- };-}--export async function initChunkEncryption() {- await sodium.ready;- const key = sodium.crypto_secretstream_xchacha20poly1305_keygen();- const initPushResult =- sodium.crypto_secretstream_xchacha20poly1305_init_push(key);- const [pushState, header] = [initPushResult.state, initPushResult.header];- return {- key: await toB64(key),- decryptionHeader: await toB64(header),- pushState,- };-}--export async function encryptFileChunk(- data: Uint8Array,- pushState: sodium.StateAddress,- isFinalChunk: boolean-) {- await sodium.ready;- const tag = isFinalChunk- ? sodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL- : sodium.crypto_secretstream_xchacha20poly1305_TAG_MESSAGE;- const pushResult = sodium.crypto_secretstream_xchacha20poly1305_push(- pushState,- data,- null,- tag- );-- return pushResult;-}-export async function encryptToB64(data: string, key: string) {- await sodium.ready;- const encrypted = await encrypt(await fromB64(data), await fromB64(key));-- return {- encryptedData: await toB64(encrypted.encryptedData),- key: await toB64(encrypted.key),- nonce: await toB64(encrypted.nonce),- } as B64EncryptionResult;-}--export async function generateKeyAndEncryptToB64(data: string) {- await sodium.ready;- const key = sodium.crypto_secretbox_keygen();- return await encryptToB64(data, await toB64(key));-}--export async function encryptUTF8(data: string, key: string) {- const b64Data = await toB64(await fromUTF8(data));- return await encryptToB64(b64Data, key);-}--export async function decryptB64(data: string, nonce: string, key: string) {- await sodium.ready;- const decrypted = await decrypt(- await fromB64(data),- await fromB64(nonce),- await fromB64(key)- );-- return await toB64(decrypted);-}--export async function decryptToUTF8(data: string, nonce: string, key: string) {- await sodium.ready;- const decrypted = await decrypt(- await fromB64(data),- await fromB64(nonce),- await fromB64(key)- );-- return sodium.to_string(decrypted);-}--async function encrypt(data: Uint8Array, key: Uint8Array) {- await sodium.ready;- const nonce = sodium.randombytes_buf(sodium.crypto_secretbox_NONCEBYTES);- const encryptedData = sodium.crypto_secretbox_easy(data, nonce, key);- return {- encryptedData,- key,- nonce,- };-}--async function decrypt(data: Uint8Array, nonce: Uint8Array, key: Uint8Array) {- await sodium.ready;- return sodium.crypto_secretbox_open_easy(data, nonce, key);-}--export async function initChunkHashing() {- await sodium.ready;- const hashState = sodium.crypto_generichash_init(- null,- sodium.crypto_generichash_BYTES_MAX- );- return hashState;-}--export async function hashFileChunk(- hashState: sodium.StateAddress,- chunk: Uint8Array-) {- await sodium.ready;- sodium.crypto_generichash_update(hashState, chunk);-}--export async function completeChunkHashing(hashState: sodium.StateAddress) {- await sodium.ready;- const hash = sodium.crypto_generichash_final(- hashState,- sodium.crypto_generichash_BYTES_MAX- );- const hashString = toB64(hash);- return hashString;-}--export async function deriveKey(- passphrase: string,- salt: string,- opsLimit: number,- memLimit: number-) {- await sodium.ready;- return await toB64(- sodium.crypto_pwhash(- sodium.crypto_secretbox_KEYBYTES,- await fromUTF8(passphrase),- await fromB64(salt),- opsLimit,- memLimit,- sodium.crypto_pwhash_ALG_ARGON2ID13- )- );-}--export async function deriveSensitiveKey(passphrase: string, salt: string) {- await sodium.ready;- const minMemLimit = sodium.crypto_pwhash_MEMLIMIT_MIN;- let opsLimit = sodium.crypto_pwhash_OPSLIMIT_SENSITIVE;- let memLimit = sodium.crypto_pwhash_MEMLIMIT_SENSITIVE;- while (memLimit > minMemLimit) {- try {- const key = await deriveKey(passphrase, salt, opsLimit, memLimit);- return {- key,- opsLimit,- memLimit,- };- } catch (e) {- opsLimit *= 2;- memLimit /= 2;- }- }-}--export async function deriveInteractiveKey(passphrase: string, salt: string) {- await sodium.ready;- const key = await toB64(- sodium.crypto_pwhash(- sodium.crypto_secretbox_KEYBYTES,- await fromUTF8(passphrase),- await fromB64(salt),- sodium.crypto_pwhash_OPSLIMIT_INTERACTIVE,- sodium.crypto_pwhash_MEMLIMIT_INTERACTIVE,- sodium.crypto_pwhash_ALG_ARGON2ID13- )- );- return {- key,- opsLimit: sodium.crypto_pwhash_OPSLIMIT_INTERACTIVE,- memLimit: sodium.crypto_pwhash_MEMLIMIT_INTERACTIVE,- };-}--export async function generateEncryptionKey() {- await sodium.ready;- return await toB64(sodium.crypto_kdf_keygen());-}--export async function generateSaltToDeriveKey() {- await sodium.ready;- return await toB64(sodium.randombytes_buf(sodium.crypto_pwhash_SALTBYTES));-}--export async function generateKeyPair() {- await sodium.ready;- const keyPair: sodium.KeyPair = sodium.crypto_box_keypair();- return {- privateKey: await toB64(keyPair.privateKey),- publicKey: await toB64(keyPair.publicKey),- };-}--export async function boxSealOpen(- input: string,- publicKey: string,- secretKey: string-) {- await sodium.ready;- return await toB64(- sodium.crypto_box_seal_open(- await fromB64(input),- await fromB64(publicKey),- await fromB64(secretKey)- )- );-}--export async function boxSeal(input: string, publicKey: string) {- await sodium.ready;- return await toB64(- sodium.crypto_box_seal(await fromB64(input), await fromB64(publicKey))- );-}--export async function generateSubKey(- key: string,- subKeyLength: number,- subKeyID: number,- context: string-) {- await sodium.ready;- return await toB64(- sodium.crypto_kdf_derive_from_key(- subKeyLength,- subKeyID,- context,- await fromB64(key)- )- );-}--export async function fromB64(input: string) {- await sodium.ready;- return sodium.from_base64(input, sodium.base64_variants.ORIGINAL);-}--export async function toB64(input: Uint8Array) {- await sodium.ready;- return sodium.to_base64(input, sodium.base64_variants.ORIGINAL);-}--export async function toURLSafeB64(input: Uint8Array) {- await sodium.ready;- return sodium.to_base64(input, sodium.base64_variants.URLSAFE);-}--export async function fromUTF8(input: string) {- await sodium.ready;- return sodium.from_string(input);-}--export async function toUTF8(input: string) {- await sodium.ready;- return sodium.to_string(await fromB64(input));-}-export async function toHex(input: string) {- await sodium.ready;- return sodium.to_hex(await fromB64(input));-}--export async function fromHex(input: string) {- await sodium.ready;- return await toB64(sodium.from_hex(input));-}diff --git a/apps/cast/src/utils/collection/index.ts b/apps/cast/src/utils/collection/index.tsindex 6bdc4b10d6..45856205ef 100644--- a/apps/cast/src/utils/collection/index.ts+++ b/apps/cast/src/utils/collection/index.ts@@ -46,137 +46,6 @@ export function getSelectedCollection(return collections.find((collection) => collection.id === collectionID);}-// export async function downloadCollectionHelper(-// collectionID: number,-// setCollectionDownloadProgressAttributes: SetCollectionDownloadProgressAttributes-// ) {-// try {-// const allFiles = await getAllLocalFiles();-// const collectionFiles = allFiles.filter(-// (file) => file.collectionID === collectionID-// );-// const allCollections = await getAllLocalCollections();-// const collection = allCollections.find(-// (collection) => collection.id === collectionID-// );-// if (!collection) {-// throw Error('collection not found');-// }-// await downloadCollectionFiles(-// collection.name,-// collection.id,-// isHiddenCollection(collection),-// collectionFiles,-// setCollectionDownloadProgressAttributes-// );-// } catch (e) {-// logError(e, 'download collection failed ');-// }-// }--// export async function downloadDefaultHiddenCollectionHelper(-// setCollectionDownloadProgressAttributes: SetCollectionDownloadProgressAttributes-// ) {-// try {-// const hiddenCollections = await getLocalCollections('hidden');-// const defaultHiddenCollectionsIds =-// getDefaultHiddenCollectionIDs(hiddenCollections);-// const hiddenFiles = await getLocalFiles('hidden');-// const defaultHiddenCollectionFiles = hiddenFiles.filter((file) =>-// defaultHiddenCollectionsIds.has(file.collectionID)-// );-// await downloadCollectionFiles(-// DEFAULT_HIDDEN_COLLECTION_USER_FACING_NAME,-// HIDDEN_ITEMS_SECTION,-// true,-// defaultHiddenCollectionFiles,-// setCollectionDownloadProgressAttributes-// );-// } catch (e) {-// logError(e, 'download hidden files failed ');-// }-// }--// async function downloadCollectionFiles(-// collectionName: string,-// collectionID: number,-// isHidden: boolean,-// collectionFiles: EnteFile[],-// setCollectionDownloadProgressAttributes: SetCollectionDownloadProgressAttributes-// ) {-// if (!collectionFiles.length) {-// return;-// }-// const canceller = new AbortController();-// const increaseSuccess = () => {-// if (canceller.signal.aborted) return;-// setCollectionDownloadProgressAttributes((prev) => ({-// ...prev,-// success: prev.success + 1,-// }));-// };-// const increaseFailed = () => {-// if (canceller.signal.aborted) return;-// setCollectionDownloadProgressAttributes((prev) => ({-// ...prev,-// failed: prev.failed + 1,-// }));-// };-// const isCancelled = () => canceller.signal.aborted;-// const initialProgressAttributes: CollectionDownloadProgressAttributes = {-// collectionName,-// collectionID,-// isHidden,-// canceller,-// total: collectionFiles.length,-// success: 0,-// failed: 0,-// downloadDirPath: null,-// };-// if (isElectron()) {-// const selectedDir = await ElectronService.selectDirectory();-// if (!selectedDir) {-// return;-// }-// const downloadDirPath = await createCollectionDownloadFolder(-// selectedDir,-// collectionName-// );-// setCollectionDownloadProgressAttributes({-// ...initialProgressAttributes,-// downloadDirPath,-// });-// await downloadFilesDesktop(-// collectionFiles,-// { increaseSuccess, increaseFailed, isCancelled },-// downloadDirPath-// );-// } else {-// setCollectionDownloadProgressAttributes(initialProgressAttributes);-// await downloadFiles(collectionFiles, {-// increaseSuccess,-// increaseFailed,-// isCancelled,-// });-// }-// }--// async function createCollectionDownloadFolder(-// downloadDirPath: string,-// collectionName: string-// ) {-// const collectionDownloadName = getUniqueCollectionExportName(-// downloadDirPath,-// collectionName-// );-// const collectionDownloadPath = getCollectionExportPath(-// downloadDirPath,-// collectionDownloadName-// );-// await exportService.checkExistsAndCreateDir(collectionDownloadPath);-// return collectionDownloadPath;-// }-export function appendCollectionKeyToShareURL(url: string,collectionKey: stringdiff --git a/apps/cast/src/utils/file/index.ts b/apps/cast/src/utils/file/index.tsindex b0c171d449..d3e0c9069a 100644--- a/apps/cast/src/utils/file/index.ts+++ b/apps/cast/src/utils/file/index.ts@@ -35,7 +35,6 @@ import {updateFileMagicMetadata,} from 'services/fileService';import isElectron from 'is-electron';-// import imageProcessor from 'services/electron/imageProcessor';import { isPlaybackPossible } from 'utils/photoFrame';import { FileTypeInfo } from 'types/upload';import { moveToHiddenCollection } from 'services/collectionService';@@ -44,9 +43,6 @@ import { User } from '@ente/shared/user/types';import { addLogLine, addLocalLog } from '@ente/shared/logging';import { convertBytesToHumanReadable } from '@ente/shared/utils/size';-// import ElectronFSService from 'services/electron/fs';-// import { getFileExportPath, getUniqueFileExportName } from 'utils/export';-const WAIT_TIME_IMAGE_CONVERSION = 30 * 1000;export enum FILE_OPS_TYPE {