mirror of
https://github.com/standardnotes/app.git
synced 2026-01-16 23:01:30 +00:00
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:
parent
57aa942c91
commit
568fb14f3a
5 changed files with 36 additions and 14 deletions
|
|
@ -8,12 +8,14 @@ export interface Bridge {
|
|||
const KEYCHAIN_STORAGE_KEY = 'keychain';
|
||||
|
||||
export class BrowserBridge implements Bridge {
|
||||
|
||||
async getKeychainValue(): Promise<unknown> {
|
||||
const value = localStorage.getItem(KEYCHAIN_STORAGE_KEY);
|
||||
if (value) {
|
||||
return JSON.parse(value);
|
||||
}
|
||||
}
|
||||
|
||||
async setKeychainValue(value: any): Promise<void> {
|
||||
localStorage.setItem(KEYCHAIN_STORAGE_KEY, JSON.stringify(value));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,9 +59,7 @@ export class WebApplication extends SNApplication {
|
|||
defaultSyncServerHost: string,
|
||||
bridge: Bridge,
|
||||
) {
|
||||
const namespace = '';
|
||||
const deviceInterface = new WebDeviceInterface(
|
||||
namespace,
|
||||
$timeout,
|
||||
bridge
|
||||
);
|
||||
|
|
@ -71,7 +69,7 @@ export class WebApplication extends SNApplication {
|
|||
deviceInterface,
|
||||
new SNWebCrypto(),
|
||||
new AlertService(),
|
||||
namespace,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
defaultSyncServerHost
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -10956,8 +10956,8 @@
|
|||
"from": "github:standardnotes/sncrypto#4a080efeb646dbf9ca3dffdfcfa9d081b4dc6de0"
|
||||
},
|
||||
"snjs": {
|
||||
"version": "github:standardnotes/snjs#7c983dc558ea7777a4957b44efa3362aaf18d3c9",
|
||||
"from": "github:standardnotes/snjs#7c983dc558ea7777a4957b44efa3362aaf18d3c9"
|
||||
"version": "github:standardnotes/snjs#cb83f0dfacd6b0a9ac4b51cb32f2534f2a23d232",
|
||||
"from": "github:standardnotes/snjs#cb83f0dfacd6b0a9ac4b51cb32f2534f2a23d232"
|
||||
},
|
||||
"sockjs": {
|
||||
"version": "0.3.20",
|
||||
|
|
|
|||
|
|
@ -67,6 +67,6 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"sncrypto": "github:standardnotes/sncrypto#4a080efeb646dbf9ca3dffdfcfa9d081b4dc6de0",
|
||||
"snjs": "github:standardnotes/snjs#7c983dc558ea7777a4957b44efa3362aaf18d3c9"
|
||||
"snjs": "github:standardnotes/snjs#cb83f0dfacd6b0a9ac4b51cb32f2534f2a23d232"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue