feat: namespaced keychain (#428)

* feat: namespaced keychain

* fix: update device interface

* fix: update WebApplication

* chore(deps): update snjs

* fix: Bridge interface

* chore(deps): update snjs

Co-authored-by: Johnny Almonte <johnny243@users.noreply.github.com>
This commit is contained in:
Johnny A
2020-09-03 05:19:21 -07:00
committed by GitHub
parent 57aa942c91
commit 568fb14f3a
5 changed files with 36 additions and 14 deletions

View File

@@ -7,12 +7,10 @@ export class WebDeviceInterface extends DeviceInterface {
private database: Database
constructor(
namespace: string,
timeout: any,
private bridge: Bridge
) {
super(
namespace,
timeout || setTimeout.bind(getGlobalScope()),
setInterval.bind(getGlobalScope())
);
@@ -100,15 +98,39 @@ export class WebDeviceInterface extends DeviceInterface {
return this.database.clearAllPayloads();
}
getKeychainValue(): Promise<unknown> {
async getNamespacedKeychainValue() {
const keychain = await this.getRawKeychainValue();
if (!keychain) {
return;
}
return keychain[this.namespace!.identifier];
}
async setNamespacedKeychainValue(value: any) {
let keychain = await this.getRawKeychainValue();
if (!keychain) {
keychain = {};
}
this.bridge.setKeychainValue({
...keychain,
[this.namespace!.identifier]: value
});
}
async clearNamespacedKeychainValue() {
const keychain = await this.getRawKeychainValue();
if (!keychain) {
return;
}
delete keychain[this.namespace!.identifier];
this.bridge.setKeychainValue(keychain);
}
getRawKeychainValue(): Promise<any> {
return this.bridge.getKeychainValue();
}
setKeychainValue(value: any) {
return this.bridge.setKeychainValue(value);
}
clearKeychainValue() {
clearRawKeychainValue() {
return this.bridge.clearKeychainValue();
}