driggsby 0.1.11 → 0.1.12
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.
|
@@ -1,31 +1,39 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
2
|
export class KeyringSecretStore {
|
|
3
3
|
serviceName;
|
|
4
|
-
|
|
4
|
+
entryLoader;
|
|
5
|
+
constructor(serviceName = "driggsby.local-broker", entryLoader = loadAsyncEntry) {
|
|
5
6
|
this.serviceName = serviceName;
|
|
7
|
+
this.entryLoader = entryLoader;
|
|
6
8
|
}
|
|
7
9
|
async isAvailable() {
|
|
10
|
+
let probeEntry = null;
|
|
8
11
|
try {
|
|
9
|
-
const
|
|
10
|
-
await
|
|
11
|
-
|
|
12
|
+
const probeSecret = randomBytes(18).toString("hex");
|
|
13
|
+
probeEntry = await this.createEntry(`driggsby-probe-${randomBytes(12).toString("hex")}`);
|
|
14
|
+
await probeEntry.setPassword(probeSecret);
|
|
15
|
+
return (await probeEntry.getPassword()) === probeSecret;
|
|
12
16
|
}
|
|
13
17
|
catch {
|
|
14
18
|
return false;
|
|
15
19
|
}
|
|
20
|
+
finally {
|
|
21
|
+
await probeEntry?.deleteCredential().catch(() => undefined);
|
|
22
|
+
}
|
|
16
23
|
}
|
|
17
24
|
async setSecret(account, secret) {
|
|
18
|
-
|
|
19
|
-
await new AsyncEntry(this.serviceName, account).setPassword(secret);
|
|
25
|
+
await (await this.createEntry(account)).setPassword(secret);
|
|
20
26
|
}
|
|
21
27
|
async getSecret(account) {
|
|
22
|
-
const
|
|
23
|
-
const secret = await new AsyncEntry(this.serviceName, account).getPassword();
|
|
28
|
+
const secret = await (await this.createEntry(account)).getPassword();
|
|
24
29
|
return secret ?? null;
|
|
25
30
|
}
|
|
26
31
|
async deleteSecret(account) {
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
return await (await this.createEntry(account)).deleteCredential();
|
|
33
|
+
}
|
|
34
|
+
async createEntry(account) {
|
|
35
|
+
const AsyncEntry = await this.entryLoader();
|
|
36
|
+
return new AsyncEntry(this.serviceName, account);
|
|
29
37
|
}
|
|
30
38
|
}
|
|
31
39
|
async function loadAsyncEntry() {
|