mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-16 11:47:54 +01:00
crypto: lazily import sodium
This commit is contained in:
@@ -17,8 +17,8 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { base64_variants, ISodium } from "@notesnook/sodium";
|
||||
import KeyUtils from "./keyutils.js";
|
||||
import { ISodium } from "@notesnook/sodium";
|
||||
import KeyUtils, { base64_variants } from "./keyutils.js";
|
||||
import {
|
||||
Cipher,
|
||||
Output,
|
||||
|
||||
@@ -17,8 +17,8 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { ISodium, base64_variants } from "@notesnook/sodium";
|
||||
import KeyUtils from "./keyutils.js";
|
||||
import { ISodium } from "@notesnook/sodium";
|
||||
import KeyUtils, { base64_variants } from "./keyutils.js";
|
||||
import { Chunk, Cipher, Input, DataFormat, SerializedKey } from "./types.js";
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
|
||||
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { ISodium, Sodium } from "@notesnook/sodium";
|
||||
import { ISodium } from "@notesnook/sodium";
|
||||
import Decryption from "./decryption.js";
|
||||
import Encryption from "./encryption.js";
|
||||
import { INNCrypto } from "./interfaces.js";
|
||||
@@ -37,10 +37,11 @@ import {
|
||||
|
||||
export class NNCrypto implements INNCrypto {
|
||||
private isReady = false;
|
||||
private sodium: ISodium = new Sodium();
|
||||
private sodium!: ISodium;
|
||||
|
||||
private async init() {
|
||||
if (this.isReady) return;
|
||||
this.sodium = new (await import("@notesnook/sodium")).Sodium();
|
||||
await this.sodium.initialize();
|
||||
this.isReady = true;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { base64_variants, ISodium } from "@notesnook/sodium";
|
||||
import { ISodium } from "@notesnook/sodium";
|
||||
import {
|
||||
EncryptionKey,
|
||||
EncryptionKeyPair,
|
||||
@@ -25,6 +25,13 @@ import {
|
||||
SerializedKeyPair
|
||||
} from "./types.js";
|
||||
|
||||
export enum base64_variants {
|
||||
ORIGINAL = 1,
|
||||
ORIGINAL_NO_PADDING = 3,
|
||||
URLSAFE = 5,
|
||||
URLSAFE_NO_PADDING = 7
|
||||
}
|
||||
|
||||
export default class KeyUtils {
|
||||
static deriveKey(
|
||||
sodium: ISodium,
|
||||
|
||||
Reference in New Issue
Block a user