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 {
|
|
|
|
|
constructor(context) {
|
|
|
|
|
this.storage = context;
|
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
async generateRandomKey() {
|
|
|
|
|
const passwordBytes = randomBytes(124);
|
|
|
|
|
const password = passwordBytes.toString("base64");
|
|
|
|
|
return await this.storage.generateCryptoKey(password, false);
|
|
|
|
|
}
|
2020-02-02 20:07:11 +05:00
|
|
|
}
|