@kokuin/electron 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/entry.d.ts +1 -1
- package/lib/entry.js +16 -8
- package/lib/store.d.ts +4 -2
- package/lib/store.js +12 -7
- package/package.json +4 -4
package/lib/entry.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { KeyEntry } from '@kokuin/token';
|
|
|
2
2
|
import type { KeyStorage } from './types.js';
|
|
3
3
|
export declare class ElectronKeyEntry implements KeyEntry<string> {
|
|
4
4
|
#private;
|
|
5
|
-
constructor(storage: KeyStorage, keyID: string, key?: string);
|
|
5
|
+
constructor(storage: KeyStorage, keyID: string, key?: string, allowInsecureStorage?: boolean);
|
|
6
6
|
get keyID(): string;
|
|
7
7
|
getAsync(): Promise<string | null>;
|
|
8
8
|
get(): string | null;
|
package/lib/entry.js
CHANGED
|
@@ -12,10 +12,17 @@ export class ElectronKeyEntry {
|
|
|
12
12
|
#keyID;
|
|
13
13
|
#key;
|
|
14
14
|
#storage;
|
|
15
|
-
|
|
15
|
+
#allowInsecureStorage;
|
|
16
|
+
constructor(storage, keyID, key, allowInsecureStorage = false){
|
|
16
17
|
this.#keyID = keyID;
|
|
17
18
|
this.#key = key;
|
|
18
19
|
this.#storage = storage;
|
|
20
|
+
this.#allowInsecureStorage = allowInsecureStorage;
|
|
21
|
+
}
|
|
22
|
+
#assertEncryptionAvailable() {
|
|
23
|
+
if (!this.#allowInsecureStorage && !safeStorage.isEncryptionAvailable()) {
|
|
24
|
+
throw new Error('Electron safeStorage encryption is unavailable (e.g. Linux without a keyring); ' + 'refusing to persist a plaintext-equivalent private key. ' + 'Pass { allowInsecureStorage: true } to ElectronKeyStore.open to override.');
|
|
25
|
+
}
|
|
19
26
|
}
|
|
20
27
|
get keyID() {
|
|
21
28
|
return this.#keyID;
|
|
@@ -38,18 +45,19 @@ export class ElectronKeyEntry {
|
|
|
38
45
|
this.#key = key;
|
|
39
46
|
return this.#key;
|
|
40
47
|
}
|
|
41
|
-
setAsync(key) {
|
|
42
|
-
return
|
|
48
|
+
async setAsync(key) {
|
|
49
|
+
return this.set(key);
|
|
43
50
|
}
|
|
44
51
|
set(key) {
|
|
52
|
+
this.#assertEncryptionAvailable();
|
|
45
53
|
const encrypted = encryptKey(key);
|
|
46
|
-
this.#storage.
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
const keys = this.#storage.getKeys();
|
|
55
|
+
keys[this.#keyID] = encrypted;
|
|
56
|
+
this.#storage.setKeys(keys);
|
|
49
57
|
this.#key = key;
|
|
50
58
|
}
|
|
51
|
-
provideAsync() {
|
|
52
|
-
return
|
|
59
|
+
async provideAsync() {
|
|
60
|
+
return this.provide();
|
|
53
61
|
}
|
|
54
62
|
provide() {
|
|
55
63
|
const existing = this.get();
|
package/lib/store.d.ts
CHANGED
|
@@ -2,7 +2,9 @@ import type { KeyStore } from '@kokuin/token';
|
|
|
2
2
|
import { ElectronKeyEntry } from './entry.js';
|
|
3
3
|
export declare class ElectronKeyStore implements KeyStore<string, ElectronKeyEntry> {
|
|
4
4
|
#private;
|
|
5
|
-
static open(name?: string
|
|
6
|
-
|
|
5
|
+
static open(name?: string, options?: {
|
|
6
|
+
allowInsecureStorage?: boolean;
|
|
7
|
+
}): ElectronKeyStore;
|
|
8
|
+
constructor(name: string, allowInsecureStorage?: boolean);
|
|
7
9
|
entry(keyID: string): ElectronKeyEntry;
|
|
8
10
|
}
|
package/lib/store.js
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import Store from 'electron-store';
|
|
2
2
|
import { ElectronKeyEntry } from './entry.js';
|
|
3
3
|
export class ElectronKeyStore {
|
|
4
|
-
static #byName =
|
|
5
|
-
static open(name = 'keystore') {
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
static #byName = Object.create(null);
|
|
5
|
+
static open(name = 'keystore', options) {
|
|
6
|
+
const cached = ElectronKeyStore.#byName[name];
|
|
7
|
+
if (cached == null) {
|
|
8
|
+
ElectronKeyStore.#byName[name] = new ElectronKeyStore(name, options?.allowInsecureStorage ?? false);
|
|
9
|
+
} else if (options?.allowInsecureStorage != null && options.allowInsecureStorage !== cached.#allowInsecureStorage) {
|
|
10
|
+
throw new Error(`ElectronKeyStore.open('${name}') was already opened with allowInsecureStorage: ` + `${cached.#allowInsecureStorage}; cannot reopen with conflicting allowInsecureStorage: ` + `${options.allowInsecureStorage}.`);
|
|
8
11
|
}
|
|
9
12
|
return ElectronKeyStore.#byName[name];
|
|
10
13
|
}
|
|
11
|
-
#entries =
|
|
14
|
+
#entries = Object.create(null);
|
|
12
15
|
#storage;
|
|
13
|
-
|
|
16
|
+
#allowInsecureStorage;
|
|
17
|
+
constructor(name, allowInsecureStorage = false){
|
|
18
|
+
this.#allowInsecureStorage = allowInsecureStorage;
|
|
14
19
|
const store = new Store({
|
|
15
20
|
name,
|
|
16
21
|
schema: {
|
|
@@ -33,7 +38,7 @@ export class ElectronKeyStore {
|
|
|
33
38
|
};
|
|
34
39
|
}
|
|
35
40
|
entry(keyID) {
|
|
36
|
-
this.#entries[keyID] ??= new ElectronKeyEntry(this.#storage, keyID);
|
|
41
|
+
this.#entries[keyID] ??= new ElectronKeyEntry(this.#storage, keyID, undefined, this.#allowInsecureStorage);
|
|
37
42
|
return this.#entries[keyID];
|
|
38
43
|
}
|
|
39
44
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kokuin/electron",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Electron keystore",
|
|
6
6
|
"keywords": [
|
|
@@ -25,15 +25,15 @@
|
|
|
25
25
|
],
|
|
26
26
|
"sideEffects": false,
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@sozai/codec": "^0.
|
|
28
|
+
"@sozai/codec": "^0.2.0",
|
|
29
29
|
"@sozai/log": "^0.1.0",
|
|
30
30
|
"@sozai/otel": "^0.2.0",
|
|
31
31
|
"electron-store": "^11.0.2",
|
|
32
32
|
"@kokuin/otel": "^0.1.0",
|
|
33
|
-
"@kokuin/token": "^0.
|
|
33
|
+
"@kokuin/token": "^0.2.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"electron": "^
|
|
36
|
+
"electron": "^43.1.0"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build:clean": "del lib",
|