Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

chore: migrate to @notesnook/crypto package

thecodrrdf9fe90d6274
diff --git a/apps/web/package.json b/apps/web/package.json
index 3ea2b0a97..9781d05cb 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -9,6 +9,7 @@
"dependencies": {
"@mdi/js": "^6.5.95",
"@mdi/react": "^1.4.0",
+ "@notesnook/crypto": "^1.0.0",
"@notesnook/desktop": "file:desktop",
"@rebass/forms": "^4.0.6",
"@streetwriters/tinymce-plugins": "^1.5.9",
@@ -33,7 +34,6 @@
"just-debounce-it": "^3.0.1",
"localforage": "^1.10.0",
"localforage-getitems": "https://github.com/thecodrr/localForage-getItems.git",
- "nncrypto": "file:packages/nncrypto",
"nncryptoworker": "file:packages/nncryptoworker",
"notes-core": "npm:@streetwriters/notesnook-core@latest",
"platform": "^1.3.6",
diff --git a/apps/web/packages/nncrypto/index.ts b/apps/web/packages/nncrypto/index.ts
deleted file mode 100644
index e9c3a2130..000000000
--- a/apps/web/packages/nncrypto/index.ts
+++ /dev/null
@@ -1,124 +0,0 @@
-import { ready } from "libsodium-wrappers";
-import { Chunk } from "streamablefs/dist/src/types";
-import Decryption from "./src/decryption";
-import Encryption from "./src/encryption";
-import { INNCrypto, IStreamable } from "./src/interfaces";
-import KeyUtils from "./src/keyutils";
-import Password from "./src/password";
-import {
- Cipher,
- EncryptionKey,
- OutputFormat,
- Plaintext,
- SerializedKey,
-} from "./src/types";
-
-export class NNCrypto implements INNCrypto {
- private isReady: boolean = false;
-
- private async init() {
- if (this.isReady) return;
- await ready;
- this.isReady = true;
- }
-
- async encrypt(
- key: SerializedKey,
- plaintext: Plaintext,
- outputFormat: OutputFormat = "uint8array"
- ): Promise<Cipher> {
- await this.init();
- return Encryption.encrypt(key, plaintext, outputFormat);
- }
-
- async decrypt(
- key: SerializedKey,
- cipherData: Cipher,
- outputFormat: OutputFormat = "text"
- ): Promise<Plaintext> {
- await this.init();
- return Decryption.decrypt(key, cipherData, outputFormat);
- }
-
- async hash(password: string, salt: string): Promise<string> {
- await this.init();
- return Password.hash(password, salt);
- }
-
- async deriveKey(password: string, salt?: string): Promise<EncryptionKey> {
- await this.init();
- return KeyUtils.deriveKey(password, salt);
- }
-
- async exportKey(password: string, salt?: string): Promise<SerializedKey> {
- await this.init();
- return KeyUtils.exportKey(password, salt);
- }
-
- async createEncryptionStream(
- key: SerializedKey,
- stream: IStreamable
- ): Promise<string> {
- await this.init();
- const encryptionStream = Encryption.createStream(key);
- while (true) {
- const chunk = await stream.read();
- if (!chunk) break;
-
- const { data, final } = chunk;
- if (!data) break;
-
- const encryptedChunk: Chunk = {
- data: encryptionStream.write(data, final),
- final,
- };
- await stream.write(encryptedChunk);
-
- if (final) break;
- }
- return encryptionStream.header;
- }
-
- async createDecryptionStream(
- iv: string,
- key: SerializedKey,
- stream: IStreamable
- ) {
- await this.init();
- const decryptionStream = Decryption.createStream(iv, key);
- while (true) {
- const chunk = await stream.read();
- if (!chunk) break;
-
- const { data, final } = chunk;
- if (!data) break;
-
- const decryptedChunk: Chunk = {
- data: decryptionStream.read(data),
- final,
- };
- await stream.write(decryptedChunk);
-
- if (final) break;
- }
- }
-
- async encryptStream(
- key: SerializedKey,
- stream: IStreamable,
- _streamId?: string
- ): Promise<string> {
- await this.init();
- return await this.createEncryptionStream(key, stream);
- }
-
- async decryptStream(
- key: SerializedKey,
- iv: string,
- stream: IStreamable,
- _streamId?: string
- ): Promise<void> {
- await this.init();
- await this.createDecryptionStream(iv, key, stream);
- }
-}
diff --git a/apps/web/packages/nncrypto/package.json b/apps/web/packages/nncrypto/package.json
deleted file mode 100644
index 23c63872b..000000000
--- a/apps/web/packages/nncrypto/package.json
+++ /dev/null
@@ -1,25 +0,0 @@
-{
- "name": "nncrypto",
- "version": "1.0.0",
- "main": "dist/index.js",
- "types": "dist/index.d.ts",
- "scripts": {
- "es": "esbuild ./js/index.js --external:path --external:crypto --minify --bundle --outdir=./dist --platform=browser",
- "build": "tsc --declaration --outDir ./dist",
- "prod": "NODE_ENV=production webpack",
- "dev": "NODE_ENV=development webpack",
- "check": "tsc --noEmit",
- "types": "tsc --declaration --emitDeclarationOnly --outDir ./dist/"
- },
- "keywords": [],
- "author": "",
- "license": "ISC",
- "dependencies": {
- "libsodium-wrappers": "^0.7.9"
- },
- "devDependencies": {
- "streamablefs": "file:../streamablefs",
- "@types/libsodium-wrappers": "^0.7.9"
- },
- "description": ""
-}
diff --git a/apps/web/packages/nncrypto/src/decryption.ts b/apps/web/packages/nncrypto/src/decryption.ts
deleted file mode 100644
index 0c9ba3bfb..000000000
--- a/apps/web/packages/nncrypto/src/decryption.ts
+++ /dev/null
@@ -1,94 +0,0 @@
-import {
- crypto_aead_xchacha20poly1305_ietf_decrypt,
- crypto_secretstream_xchacha20poly1305_init_pull,
- crypto_secretstream_xchacha20poly1305_pull,
- to_base64,
- from_base64,
- base64_variants,
- StateAddress,
- to_string,
- from_hex,
-} from "libsodium-wrappers";
-import KeyUtils from "./keyutils";
-import {
- Cipher,
- EncryptionKey,
- OutputFormat,
- Plaintext,
- SerializedKey,
-} from "./types";
-
-export default class Decryption {
- private static transformInput(cipherData: Cipher): Uint8Array {
- let input: Uint8Array | null = null;
- if (
- typeof cipherData.cipher === "string" &&
- cipherData.format === "base64"
- ) {
- input = from_base64(
- cipherData.cipher,
- base64_variants.URLSAFE_NO_PADDING
- );
- } else if (
- typeof cipherData.cipher === "string" &&
- cipherData.format === "hex"
- ) {
- input = from_hex(cipherData.cipher);
- } else if (cipherData.cipher instanceof Uint8Array) {
- input = cipherData.cipher;
- }
- if (!input) throw new Error("Data cannot be null.");
- return input;
- }
-
- static decrypt(
- key: SerializedKey,
- cipherData: Cipher,
- outputFormat: OutputFormat = "text"
- ): Plaintext {
- if (!key.salt && cipherData.salt) key.salt = cipherData.salt;
- const encryptionKey = KeyUtils.transform(key);
-
- const input = this.transformInput(cipherData);
- const plaintext = crypto_aead_xchacha20poly1305_ietf_decrypt(
- null,
- input,
- null,
- from_base64(cipherData.iv),
- encryptionKey.key
- );
-
- return {
- format: outputFormat,
- data:
- outputFormat === "base64"
- ? to_base64(plaintext, base64_variants.ORIGINAL)
- : outputFormat === "text"
- ? to_string(plaintext)
- : plaintext,
- };
- }
-
- static createStream(header: string, key: SerializedKey): DecryptionStream {
- return new DecryptionStream(header, KeyUtils.transform(key));
- }
-}
-
-class DecryptionStream {
- state: StateAddress;
- constructor(header: string, key: EncryptionKey) {
- this.state = crypto_secretstream_xchacha20poly1305_init_pull(
- from_base64(header),
- key.key
- );
- }
-
- read(chunk: Uint8Array): Uint8Array {
- const { message } = crypto_secretstream_xchacha20poly1305_pull(
- this.state,
- chunk,
- null
- );
- return message;
- }
-}
diff --git a/apps/web/packages/nncrypto/src/encryption.ts b/apps/web/packages/nncrypto/src/encryption.ts
deleted file mode 100644
index 8b8274fd8..000000000
--- a/apps/web/packages/nncrypto/src/encryption.ts
+++ /dev/null
@@ -1,105 +0,0 @@
-import {
- crypto_aead_xchacha20poly1305_ietf_encrypt,
- crypto_secretstream_xchacha20poly1305_init_push,
- crypto_secretstream_xchacha20poly1305_push,
- randombytes_buf,
- crypto_aead_xchacha20poly1305_ietf_NPUBBYTES,
- crypto_secretstream_xchacha20poly1305_TAG_FINAL,
- crypto_secretstream_xchacha20poly1305_TAG_MESSAGE,
- to_base64,
- from_base64,
- base64_variants,
- StateAddress,
-} from "libsodium-wrappers";
-import KeyUtils from "./keyutils";
-import {
- Cipher,
- EncryptionKey,
- OutputFormat,
- Plaintext,
- SerializedKey,
-} from "./types";
-
-const encoder = new TextEncoder();
-export default class Encryption {
- private static transformInput(plaintext: Plaintext): Uint8Array {
- let data: Uint8Array | null = null;
- if (typeof plaintext.data === "string" && plaintext.format === "base64") {
- data = from_base64(plaintext.data, base64_variants.ORIGINAL);
- } else if (typeof plaintext.data === "string") {
- data = encoder.encode(plaintext.data);
- } else if (plaintext.data instanceof Uint8Array) {
- data = plaintext.data;
- }
- if (!data) throw new Error("Data cannot be null.");
- return data;
- }
-
- static encrypt(
- key: SerializedKey,
- plaintext: Plaintext,
- outputFormat: OutputFormat = "uint8array"
- ): Cipher {
- const encryptionKey = KeyUtils.transform(key);
- const data = this.transformInput(plaintext);
-
- const nonce = randombytes_buf(crypto_aead_xchacha20poly1305_ietf_NPUBBYTES);
-
- const cipher: string | Uint8Array =
- crypto_aead_xchacha20poly1305_ietf_encrypt(
- data,
- null,
- null,
- nonce,
- encryptionKey.key
- );
-
- let output: string | Uint8Array = cipher;
- if (outputFormat === "base64") {
- output = to_base64(cipher, base64_variants.URLSAFE_NO_PADDING);
- }
-
- const iv = to_base64(nonce);
- return {
- format: outputFormat,
- alg: getAlgorithm(base64_variants.URLSAFE_NO_PADDING),
- cipher: output,
- iv,
- salt: encryptionKey.salt,
- length: data.length,
- };
- }
-
- static createStream(key: SerializedKey): EncryptionStream {
- return new EncryptionStream(KeyUtils.transform(key));
- }
-}
-
-class EncryptionStream {
- state: StateAddress;
- header: string;
- constructor(key: EncryptionKey) {
- const { state, header } = crypto_secretstream_xchacha20poly1305_init_push(
- key.key,
- "base64"
- );
- this.state = state;
- this.header = header;
- }
-
- write(chunk: Uint8Array, final?: boolean): Uint8Array {
- return crypto_secretstream_xchacha20poly1305_push(
- this.state,
- chunk,
- null,
- final
- ? crypto_secretstream_xchacha20poly1305_TAG_FINAL
- : crypto_secretstream_xchacha20poly1305_TAG_MESSAGE
- );
- }
-}
-
-function getAlgorithm(base64Variant: base64_variants) {
- //Template: encryptionAlgorithm-kdfAlgorithm-base64variant
- return `xcha-argon2i13-${base64Variant}`;
-}
diff --git a/apps/web/packages/nncrypto/src/interfaces.ts b/apps/web/packages/nncrypto/src/interfaces.ts
deleted file mode 100644
index 832d165c2..000000000
--- a/apps/web/packages/nncrypto/src/interfaces.ts
+++ /dev/null
@@ -1,46 +0,0 @@
-import { Chunk } from "streamablefs/dist/src/types";
-import {
- Cipher,
- EncryptionKey,
- OutputFormat,
- Plaintext,
- SerializedKey,
-} from "./types";
-
-export interface IStreamable {
- read(): Promise<Chunk | undefined>;
- write(chunk: Chunk | undefined): Promise<void>;
-}
-
-export interface INNCrypto {
- encrypt(
- key: SerializedKey,
- plaintext: Plaintext,
- outputFormat?: OutputFormat
- ): Promise<Cipher>;
-
- decrypt(
- key: SerializedKey,
- cipherData: Cipher,
- outputFormat?: OutputFormat
- ): Promise<Plaintext>;
-
- hash(password: string, salt: string): Promise<string>;
-
- deriveKey(password: string, salt?: string): Promise<EncryptionKey>;
-
- exportKey(password: string, salt?: string): Promise<SerializedKey>;
-
- encryptStream(
- key: SerializedKey,
- stream: IStreamable,
- streamId?: string
- ): Promise<string>;
-
- decryptStream(
- key: SerializedKey,
- iv: string,
- stream: IStreamable,
- streamId?: string
- ): Promise<void>;
-}
diff --git a/apps/web/packages/nncrypto/src/keyutils.ts b/apps/web/packages/nncrypto/src/keyutils.ts
deleted file mode 100644
index ba24cf319..000000000
--- a/apps/web/packages/nncrypto/src/keyutils.ts
+++ /dev/null
@@ -1,57 +0,0 @@
-import {
- from_base64,
- to_base64,
- randombytes_buf,
- crypto_pwhash,
- crypto_pwhash_SALTBYTES,
- crypto_pwhash_ALG_ARGON2I13,
- crypto_aead_xchacha20poly1305_ietf_KEYBYTES,
-} from "libsodium-wrappers";
-import { EncryptionKey, SerializedKey } from "./types";
-
-export default class KeyUtils {
- static deriveKey(password: string, salt?: string): EncryptionKey {
- let saltBytes: Uint8Array;
- if (!salt) saltBytes = randombytes_buf(crypto_pwhash_SALTBYTES);
- else {
- saltBytes = from_base64(salt);
- }
-
- if (!saltBytes)
- throw new Error("Could not generate bytes from the given salt.");
-
- const key = crypto_pwhash(
- crypto_aead_xchacha20poly1305_ietf_KEYBYTES,
- password,
- saltBytes,
- 3, // operations limit
- 1024 * 1024 * 8, // memory limit (8MB)
- crypto_pwhash_ALG_ARGON2I13
- );
-
- return {
- key,
- salt: typeof salt === "string" ? salt : to_base64(saltBytes),
- };
- }
-
- static exportKey(password: string, salt?: string): SerializedKey {
- const { key, salt: keySalt } = this.deriveKey(password, salt);
- return { key: to_base64(key), salt: keySalt };
- }
-
- /**
- * Takes in either a password or a serialized encryption key
- * and spits out a key that can be directly used for encryption/decryption.
- * @param input
- */
- static transform(input: SerializedKey): EncryptionKey {
- if ("password" in input && !!input.password) {
- const { password, salt } = input;
- return this.deriveKey(password, salt);
- } else if ("key" in input && !!input.salt && !!input.key) {
- return { key: from_base64(input.key), salt: input.salt };
- }
- throw new Error("Invalid input.");
- }
-}
diff --git a/apps/web/packages/nncrypto/src/password.ts b/apps/web/packages/nncrypto/src/password.ts
deleted file mode 100644
index c2af55082..000000000
--- a/apps/web/packages/nncrypto/src/password.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-import {
- crypto_generichash,
- crypto_pwhash,
- crypto_pwhash_ALG_ARGON2ID13,
- crypto_pwhash_SALTBYTES,
-} from "libsodium-wrappers";
-
-export default class Password {
- static hash(password: string, salt: string): string {
- const saltBytes = crypto_generichash(crypto_pwhash_SALTBYTES, salt);
- const hash = crypto_pwhash(
- 32,
- password,
- saltBytes,
- 3, // operations limit
- 1024 * 1024 * 64, // memory limit (8MB)
- crypto_pwhash_ALG_ARGON2ID13,
- "base64"
- );
- return hash;
- }
-}
diff --git a/apps/web/packages/nncrypto/src/types.ts b/apps/web/packages/nncrypto/src/types.ts
deleted file mode 100644
index 53fdedd0c..000000000
--- a/apps/web/packages/nncrypto/src/types.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-import { StringOutputFormat, Uint8ArrayOutputFormat } from "libsodium-wrappers";
-
-export type OutputFormat = Uint8ArrayOutputFormat | StringOutputFormat;
-
-export type Cipher = {
- format: OutputFormat;
- alg: string;
- cipher: string | Uint8Array;
- iv: string;
- salt: string;
- length: number;
-};
-
-export type Plaintext = {
- format: OutputFormat;
- data: string | Uint8Array;
-};
-
-export type SerializedKey = {
- password?: string;
- key?: string;
- salt?: string;
-};
-
-export type EncryptionKey = {
- key: Uint8Array;
- salt: string;
-};
diff --git a/apps/web/packages/nncrypto/tsconfig.json b/apps/web/packages/nncrypto/tsconfig.json
deleted file mode 100644
index 37bff4060..000000000
--- a/apps/web/packages/nncrypto/tsconfig.json
+++ /dev/null
@@ -1,105 +0,0 @@
-{
- "compilerOptions": {
- /* Visit https://aka.ms/tsconfig.json to read more about this file */
-
- /* Projects */
- // "incremental": true, /* Enable incremental compilation */
- // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
- // "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */
- // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */
- // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
- // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
-
- /* Language and Environment */
- "target": "es2020" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
- "lib": [
- "DOM"
- ] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
- // "jsx": "preserve", /* Specify what JSX code is generated. */
- // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
- // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
- // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */
- // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
- // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */
- // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */
- // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
- // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
-
- /* Modules */
- "module": "commonjs",
- // "module": "commonjs" /* Specify what module code is generated. */,
- // "rootDir": "./", /* Specify the root folder within your source files. */
- // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
- // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
- // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
- // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
- // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */
- // "types": [], /* Specify type package names to be included without being referenced in a source file. */
- // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
- // "resolveJsonModule": true, /* Enable importing .json files */
- // "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
-
- /* JavaScript Support */
- // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
- // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
- // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */
-
- /* Emit */
- //"declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
- // "declarationMap": true, /* Create sourcemaps for d.ts files. */
- // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
- // "sourceMap": true /* Create source map files for emitted JavaScript files. */,
- // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
- // "outDir": "./", /* Specify an output folder for all emitted files. */
- // "removeComments": true, /* Disable emitting comments. */
- // "noEmit": true, /* Disable emitting files from a compilation. */
- // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
- // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
- // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
- // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
- // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
- // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
- // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
- // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
- // "newLine": "crlf", /* Set the newline character for emitting files. */
- // "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
- // "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */
- // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
- // "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
- // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
-
- /* Interop Constraints */
- "isolatedModules": true /* Ensure that each file can be safely transpiled without relying on other imports. */,
- // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
- "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */,
- // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
- "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
-
- /* Type Checking */
- "strict": true /* Enable all strict type-checking options. */,
- // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
- // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */
- // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
- // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */
- // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
- // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */
- // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */
- // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
- // "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */
- // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */
- // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
- // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
- // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
- // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
- // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
- // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */
- // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
- // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
-
- /* Completeness */
- // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
- "skipLibCheck": true /* Skip type checking all .d.ts files. */
- },
- "exclude": ["webpack.config.js", "dist", "node_modules"],
- "include": ["./index.ts", "./src/"]
-}
diff --git a/apps/web/packages/nncrypto/webpack.config.js b/apps/web/packages/nncrypto/webpack.config.js
deleted file mode 100644
index 26ba8a348..000000000
--- a/apps/web/packages/nncrypto/webpack.config.js
+++ /dev/null
@@ -1,28 +0,0 @@
-const path = require("path");
-
-module.exports = {
- entry: "./index.ts",
- mode: process.env.NODE_ENV === "production" ? "production" : "development",
- module: {
- rules: [
- {
- test: /\.tsx?$/,
- use: "ts-loader",
- exclude: /node_modules/,
- },
- ],
- },
- resolve: {
- extensions: [".ts", ".tsx", ".js", ".jsx"],
- fallback: { path: false, crypto: false },
- },
- output: {
- filename: "index.js",
- path: path.resolve(__dirname, "dist"),
- library: {
- type: "commonjs2",
- name: "NNCrypto",
- export: "NNCrypto",
- },
- },
-};
diff --git a/apps/web/packages/nncryptoworker/index.ts b/apps/web/packages/nncryptoworker/index.ts
index 577933b9c..704a70da6 100644
--- a/apps/web/packages/nncryptoworker/index.ts
+++ b/apps/web/packages/nncryptoworker/index.ts
@@ -4,10 +4,10 @@ import {
OutputFormat,
Cipher,
EncryptionKey,
-} from "nncrypto/dist/src/types";
-import { Chunk } from "streamablefs/dist/src/types";
+ Chunk,
+} from "@notesnook/crypto/dist/src/types";
import { NNCryptoWorkerModule } from "./src/worker";
-import { INNCrypto, IStreamable } from "nncrypto/dist/src/interfaces";
+import { INNCrypto, IStreamable } from "@notesnook/crypto/dist/src/interfaces";
import { wrap } from "comlink";
export class NNCryptoWorker implements INNCrypto {
diff --git a/apps/web/packages/nncryptoworker/package.json b/apps/web/packages/nncryptoworker/package.json
index b77857bc0..d8f62af94 100644
--- a/apps/web/packages/nncryptoworker/package.json
+++ b/apps/web/packages/nncryptoworker/package.json
@@ -10,8 +10,8 @@
"author": "",
"license": "ISC",
"dependencies": {
+ "@notesnook/crypto": "^1.0.0",
"comlink": "^4.3.1",
- "nncrypto": "file:../nncrypto",
"streamablefs": "file:../streamablefs"
},
"devDependencies": {
diff --git a/apps/web/packages/nncryptoworker/src/worker.ts b/apps/web/packages/nncryptoworker/src/worker.ts
index 2100986d6..a4cda5872 100644
--- a/apps/web/packages/nncryptoworker/src/worker.ts
+++ b/apps/web/packages/nncryptoworker/src/worker.ts
@@ -3,15 +3,15 @@ import {
OutputFormat,
Plaintext,
SerializedKey,
-} from "nncrypto/dist/src/types";
+} from "@notesnook/crypto/dist/src/types";
import { expose } from "comlink";
import WorkerStream from "./workerstream";
-import { NNCrypto } from "nncrypto";
+import { NNCrypto } from "@notesnook/crypto";
var crypto: NNCrypto | null = null;
async function loadNNCrypto(): Promise<NNCrypto> {
if (crypto) return crypto;
- const { NNCrypto } = await import("nncrypto");
+ const { NNCrypto } = await import("@notesnook/crypto");
return (crypto = new NNCrypto());
}
diff --git a/apps/web/packages/nncryptoworker/src/workerstream.ts b/apps/web/packages/nncryptoworker/src/workerstream.ts
index 797444615..bd3b67b11 100644
--- a/apps/web/packages/nncryptoworker/src/workerstream.ts
+++ b/apps/web/packages/nncryptoworker/src/workerstream.ts
@@ -1,5 +1,5 @@
-import { IStreamable } from "nncrypto/dist/src/interfaces";
-import { Chunk } from "streamablefs/dist/src/types";
+import { IStreamable } from "@notesnook/crypto/dist/src/interfaces";
+import { Chunk } from "@notesnook/crypto/dist/src/types";
import { sendEventWithResult } from "./utils";
export default class WorkerStream
diff --git a/apps/web/packages/streamablefs/package.json b/apps/web/packages/streamablefs/package.json
index 3cbcc01af..83b73fa0f 100644
--- a/apps/web/packages/streamablefs/package.json
+++ b/apps/web/packages/streamablefs/package.json
@@ -10,6 +10,7 @@
"author": "",
"license": "ISC",
"dependencies": {
+ "@notesnook/crypto": "^1.0.0",
"localforage": "^1.10.0"
},
"devDependencies": {
diff --git a/apps/web/packages/streamablefs/src/filestreamsource.ts b/apps/web/packages/streamablefs/src/filestreamsource.ts
index 56a35ad58..269b9a3ea 100644
--- a/apps/web/packages/streamablefs/src/filestreamsource.ts
+++ b/apps/web/packages/streamablefs/src/filestreamsource.ts
@@ -1,4 +1,5 @@
-import { Chunk, File } from "./types";
+import { File } from "./types";
+import { Chunk } from "@notesnook/crypto/dist/src/types";
export default class FileStreamSource implements UnderlyingSource<Chunk> {
private storage: LocalForage;
diff --git a/apps/web/packages/streamablefs/src/types.ts b/apps/web/packages/streamablefs/src/types.ts
index 2e1a2910f..768897e90 100644
--- a/apps/web/packages/streamablefs/src/types.ts
+++ b/apps/web/packages/streamablefs/src/types.ts
@@ -5,8 +5,3 @@ export type File = {
chunks: number;
additionalData?: { [key: string]: any };
};
-
-export type Chunk = {
- data: Uint8Array;
- final: boolean;
-};
diff --git a/apps/web/scripts/build-deps.sh b/apps/web/scripts/build-deps.sh
index 4258e3a48..718939145 100755
--- a/apps/web/scripts/build-deps.sh
+++ b/apps/web/scripts/build-deps.sh
@@ -1,8 +1,5 @@
cd ./packages/streamablefs
npm run build
-cd ../nncrypto
-npm run build
-
cd ../nncryptoworker
npm run build
\ No newline at end of file
diff --git a/apps/web/src/interfaces/nncrypto.stub.js b/apps/web/src/interfaces/nncrypto.stub.js
index a9b3a8ca1..77d8ed4d2 100644
--- a/apps/web/src/interfaces/nncrypto.stub.js
+++ b/apps/web/src/interfaces/nncrypto.stub.js
@@ -9,7 +9,7 @@ async function loadNNCrypto() {
const { NNCryptoWorker } = await import("nncryptoworker");
return NNCryptoWorker;
} else {
- const { NNCrypto } = await import("nncrypto");
+ const { NNCrypto } = await import("@notesnook/crypto");
return NNCrypto;
}
}