2022-08-31 06:33:37 +05:00
|
|
|
/*
|
|
|
|
|
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
|
|
|
|
2021-10-25 11:35:00 +05:00
|
|
|
import { randomBytes } from "../utils/random";
|
|
|
|
|
|
2020-02-02 20:07:11 +05:00
|
|
|
export default class Storage {
|
2022-10-12 10:47:18 +05:00
|
|
|
constructor(storage) {
|
|
|
|
|
this.storage = storage;
|
2020-02-02 20:07:11 +05:00
|
|
|
}
|
2021-02-13 12:05:15 +05:00
|
|
|
|
2020-03-09 00:12:40 +05:00
|
|
|
write(key, data) {
|
|
|
|
|
return this.storage.write(key, data);
|
2020-02-02 20:07:11 +05:00
|
|
|
}
|
2021-02-13 12:05:15 +05:00
|
|
|
|
2020-03-09 00:12:40 +05:00
|
|
|
readMulti(keys) {
|
|
|
|
|
return this.storage.readMulti(keys);
|
2020-02-02 20:07:11 +05:00
|
|
|
}
|
2021-02-13 12:05:15 +05:00
|
|
|
|
2020-03-09 12:44:55 +05:00
|
|
|
read(key, isArray = false) {
|
|
|
|
|
return this.storage.read(key, isArray);
|
2020-02-02 20:07:11 +05:00
|
|
|
}
|
2021-02-13 12:05:15 +05:00
|
|
|
|
2020-03-09 00:12:40 +05:00
|
|
|
clear() {
|
|
|
|
|
return this.storage.clear();
|
|
|
|
|
}
|
2021-02-13 12:05:15 +05:00
|
|
|
|
2020-03-09 00:12:40 +05:00
|
|
|
remove(key) {
|
|
|
|
|
return this.storage.remove(key);
|
2020-02-02 20:07:11 +05:00
|
|
|
}
|
2021-02-13 12:05:15 +05:00
|
|
|
|
2020-09-13 13:24:24 +05:00
|
|
|
getAllKeys() {
|
|
|
|
|
return this.storage.getAllKeys();
|
|
|
|
|
}
|
2021-02-13 12:05:15 +05:00
|
|
|
|
2021-02-18 18:23:19 +05:00
|
|
|
encrypt(password, data) {
|
|
|
|
|
return this.storage.encrypt(password, data);
|
2020-04-13 11:07:03 +05:00
|
|
|
}
|
2021-02-13 12:05:15 +05:00
|
|
|
|
2020-04-13 11:07:03 +05:00
|
|
|
decrypt(password, cipher) {
|
|
|
|
|
return this.storage.decrypt(password, cipher);
|
|
|
|
|
}
|
2020-11-17 11:40:41 +05:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-17 11:40:41 +05:00
|
|
|
getCryptoKey(name) {
|
|
|
|
|
return this.storage.getCryptoKey(name);
|
2020-04-13 11:23:02 +05:00
|
|
|
}
|
2021-10-25 11:35:00 +05:00
|
|
|
|
2022-01-10 13:10:21 +05:00
|
|
|
generateCryptoKey(password, salt) {
|
|
|
|
|
return this.storage.generateCryptoKey(password, salt);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-25 11:35:00 +05:00
|
|
|
async generateRandomKey() {
|
|
|
|
|
const passwordBytes = randomBytes(124);
|
|
|
|
|
const password = passwordBytes.toString("base64");
|
2022-01-12 09:47:10 +05:00
|
|
|
return await this.storage.generateCryptoKey(password);
|
2021-10-25 11:35:00 +05:00
|
|
|
}
|
2020-02-02 20:07:11 +05:00
|
|
|
}
|