Files
notesnook/packages/core/database/storage.js

81 lines
1.9 KiB
JavaScript
Raw Normal View History

/*
This file is part of the Notesnook project (https://notesnook.com/)
Copyright (C) 2022 Streetwriters (Private) Limited
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2022-08-30 16:13:11 +05:00
import { randomBytes } from "../utils/random";
2020-02-02 20:07:11 +05:00
export default class Storage {
constructor(context) {
this.storage = context;
}
write(key, data) {
return this.storage.write(key, data);
2020-02-02 20:07:11 +05:00
}
readMulti(keys) {
return this.storage.readMulti(keys);
2020-02-02 20:07:11 +05:00
}
read(key, isArray = false) {
return this.storage.read(key, isArray);
2020-02-02 20:07:11 +05:00
}
clear() {
return this.storage.clear();
}
remove(key) {
return this.storage.remove(key);
2020-02-02 20:07:11 +05:00
}
2020-09-13 13:24:24 +05:00
getAllKeys() {
return this.storage.getAllKeys();
}
2021-02-18 18:23:19 +05:00
encrypt(password, data) {
return this.storage.encrypt(password, data);
}
decrypt(password, cipher) {
return this.storage.decrypt(password, cipher);
}
deriveCryptoKey(name, data) {
return this.storage.deriveCryptoKey(name, data);
}
2021-01-18 23:29:49 +05:00
hash(password, userId) {
return this.storage.hash(password, userId);
}
getCryptoKey(name) {
return this.storage.getCryptoKey(name);
}
generateCryptoKey(password, salt) {
return this.storage.generateCryptoKey(password, salt);
}
async generateRandomKey() {
const passwordBytes = randomBytes(124);
const password = passwordBytes.toString("base64");
return await this.storage.generateCryptoKey(password);
}
2020-02-02 20:07:11 +05:00
}