crypto: lazily import sodium

This commit is contained in:
Abdullah Atta
2025-12-03 19:15:31 +05:00
parent f74d7cf37e
commit bc9cbbc1f6
4 changed files with 15 additions and 7 deletions

View File

@@ -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,

View File

@@ -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();

View File

@@ -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;
}

View File

@@ -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,