@gjsify/secret-store 0.0.0-stage → 0.64.59

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 gjsify contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,72 @@
1
- # Temporary Holding Version
1
+ # @gjsify/secret-store
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Secrets an app owns: a password the user typed, a refresh token from the app's own OAuth flow. One store per namespace, one driver per platform ([ADR 0152](../../../docs/adr/0152-app-owned-secrets-get-their-own-seam.md)).
4
+
5
+ Part of the [gjsify](https://github.com/gjsify/gjsify) project. **Tier 3 (experimental, ADR 0003)**: the interface, the `memory` driver and the GJS `libsecret` driver (unsandboxed Linux); the Android Keystore driver ships as [`@gjsify/native-secret-store-bridge`](../../nativescript-bridge/secret-store) (NativeScript, Android only); the Flatpak `portal-secret` driver is the same GJS driver (libsecret's file backend over `org.freedesktop.portal.Secret`); Keychain follows.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ gjsify install @gjsify/secret-store
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```typescript
16
+ import { openSecretStore } from '@gjsify/secret-store';
17
+
18
+ const store = await openSecretStore('curlew/accounts');
19
+ await store.set('acc1:imap', password);
20
+ const again = await store.get('acc1:imap'); // string | null
21
+ ```
22
+
23
+ | Call | Answers |
24
+ |---|---|
25
+ | `openSecretStore(namespace)` | a `SecretStore`; throws, naming the platform, where there is no driver |
26
+ | `store.get(key)` / `set` / `delete` | the secret or `null`; replace; missing is not an error |
27
+ | `store.keys()` | keys only, never values |
28
+ | `store.clear()` | forgets the namespace |
29
+ | `secretStoreInfo()` | `{ driver, persistent, encryptedAtRest }` for an about dialog; never branch on it |
30
+
31
+ ## Not `system-accounts`
32
+
33
+ [`@gjsify/system-accounts`](../system-accounts) reports a missing account store as a *value* (`Unavailable`), because a host without one is normal. An app cannot work without its own secret, so this package has no `Unavailable`: **no driver means `openSecretStore` throws.** There is no plaintext fallback. A credential obtained from `system-accounts` is never stored here.
34
+
35
+ ## Drivers
36
+
37
+ | Driver | Where | How it is installed |
38
+ |---|---|---|
39
+ | `libsecret` | GJS, Linux, no sandbox | `import '@gjsify/secret-store/libsecret'` once, in the app entry |
40
+ | `keystore-file` | NativeScript, Android | `import '@gjsify/native-secret-store-bridge'` |
41
+ | `memory` | tests, any runtime | `useSecretStoreDriver(createMemoryDriver())`; never selected automatically |
42
+ | `portal-secret` | GJS inside a Flatpak | the same `import '@gjsify/secret-store/libsecret'`; chosen automatically when `/.flatpak-info` exists |
43
+
44
+ Nothing is chosen behind your back: without an installed driver `openSecretStore` throws, naming the platform.
45
+
46
+ ### `libsecret`
47
+
48
+ ```typescript
49
+ import '@gjsify/secret-store/libsecret'; // installs the driver
50
+ import { openSecretStore } from '@gjsify/secret-store';
51
+
52
+ const store = await openSecretStore('curlew/accounts');
53
+ ```
54
+
55
+ `secretStoreInfo()` reports `{ driver: 'libsecret', persistent: true, encryptedAtRest: true }`.
56
+
57
+ - One `Secret.Schema` (`org.gjsify.SecretStore`), attributes `namespace` and `key`, stored in the default collection. `keys()` searches on `namespace`; `clear()` removes every item of the namespace and throws if some stayed behind (a locked keyring). The label is `<namespace>: <key>`, never the value.
58
+ - Every call is libsecret's async form, so unlocking the keyring never blocks the main loop.
59
+ - `openSecretStore` asks the session bus for the Secret Service. No service (no gnome-keyring, KeePassXC, …) or no `Secret-1` typelib throws an error naming that cause. There is no fallback to `memory`.
60
+ - **Inside a Flatpak** (`/.flatpak-info` exists) the same driver reports `{ driver: 'portal-secret', persistent: true, encryptedAtRest: true }`. libsecret (≥ 0.20) switches to its file backend there by itself: the master secret comes from `org.freedesktop.portal.Secret` and the items are encrypted into `$XDG_DATA_HOME/keyrings/default.keyring`. The app needs no `--talk-name=org.freedesktop.secrets`. `openSecretStore` probes the portal first; if it is missing or the keyring file cannot be opened, it throws, naming `portal-secret`, the portal and the cause. There is no fallback to `memory`.
61
+ - **Why libsecret's file backend and not our own file.** Wrapping an app-private file with the portal secret ourselves would mean writing the key derivation, the cipher, the file format and its migration: our own crypto. libsecret already does exactly that, is maintained by GNOME and is in the runtime. The cost is a Secret Service-shaped file format we do not control.
62
+ - Flatpak proof: `flatpak-probe/run.sh` builds `org.gjsify.SecretStoreProbe` (`--user`, empty `finish-args`, build dir under `/tmp`), runs the contract over two namespaces, runs a second process that re-reads after the restart, and uninstalls the app with its data. Needs `flatpak-builder` and `org.gnome.Platform//49` + `Sdk//49`. It is not part of the published package.
63
+ - Errors carry the operation and the Secret Service's own message, never a key's value.
64
+ - Tests: `gjsify run test` runs the real-service suite when a Secret Service is on the bus and skips it, printing why, when not. To run it by hand without touching your keyring: `XDG_DATA_HOME=$(mktemp -d) dbus-run-session -- sh -c 'echo | gnome-keyring-daemon --unlock --components=secrets >/dev/null; gjsify run test.gjs.mjs'`.
65
+
66
+ ### Memory and NativeScript
67
+
68
+ `createMemoryDriver()` keeps secrets for the life of the process (`persistent: false`). On NativeScript Android, importing `@gjsify/native-secret-store-bridge` installs the `keystore-file` driver. Other platforms throw until their driver lands (ADR 0152 step 3 onward).
69
+
70
+ ## License
71
+
72
+ MIT
@@ -0,0 +1 @@
1
+ var e=Object.defineProperty,__name=(t,n)=>e(t,`name`,{value:n,configurable:!0});export{__name};
@@ -0,0 +1 @@
1
+ import{openSecretStore as e,secretStoreInfo as t,useSecretStoreDriver as n}from"./secret-store.js";import{createMemoryDriver as r}from"./memory.js";export{r as createMemoryDriver,e as openSecretStore,t as secretStoreInfo,n as useSecretStoreDriver};
@@ -0,0 +1 @@
1
+ import"./_virtual/_rolldown/runtime.js";const e=`org.gjsify.SecretStore`,t=`@gjsify/secret-store (libsecret)`,n=`@gjsify/secret-store/portal-probe`;function noTypelibError(){return Error(`${t}: the Secret typelib (libsecret, namespace Secret-1) is not installed on this host. Install libsecret with its GObject introspection data (Fedora: libsecret, Debian/Ubuntu: gir1.2-secret-1).`)}function failure(e,n){let r=n instanceof Error?n.message:`unknown error`;return Error(`${t}: ${e} failed: ${r}`)}function asyncCall(e,t){return new Promise((n,r)=>{try{e((e,i)=>{try{n(t(i))}catch(e){r(e)}})}catch(e){r(e)}})}function createLibsecretDriver(r){let{secret:i,sandboxed:a}=r,o={driver:a?`portal-secret`:`libsecret`,persistent:!0,encryptedAtRest:!0};if(!i)return{info:o,async open(){throw noTypelibError()}};let s=i,c=s.Schema.new(e,s.SchemaFlags.NONE,{namespace:s.SchemaAttributeType.STRING,key:s.SchemaAttributeType.STRING});async function requireService(){if(a)return requirePortal();try{await asyncCall(e=>s.Service.get(s.ServiceFlags.OPEN_SESSION,null,e),e=>s.Service.get_finish(e))}catch(e){throw Error(`${t}: no Secret Service is reachable on the session bus (is gnome-keyring, KeePassXC or another provider running?): ${e instanceof Error?e.message:`unknown error`}`)}}async function requirePortal(){try{await asyncCall(e=>s.password_lookup(c,{namespace:n,key:n},null,e),e=>s.password_lookup_finish(e))}catch(e){throw Error(`@gjsify/secret-store (portal-secret): the secret portal (org.freedesktop.portal.Secret) is not reachable, or the app's keyring file could not be opened (is an xdg-desktop-portal with a Secret backend running, and is the app's data directory writable?): ${e instanceof Error?e.message:`unknown error`}`)}}return{info:o,async open(e){await requireService();let attributesOf=t=>t===void 0?{namespace:e}:{namespace:e,key:t};async function listKeys(){let e;try{e=await asyncCall(e=>s.password_search(c,attributesOf(),s.SearchFlags.ALL|s.SearchFlags.UNLOCK,null,e),e=>s.password_search_finish(e))}catch(e){throw failure(`listing the keys`,e)}let t=new Set;for(let n of e??[]){let e=n.get_attributes().key;e!==void 0&&t.add(e)}return[...t].sort()}return{namespace:e,async get(e){try{return await asyncCall(t=>s.password_lookup(c,attributesOf(e),null,t),e=>s.password_lookup_finish(e))??null}catch(e){throw failure(`reading a secret`,e)}},async set(t,n){try{await asyncCall(r=>s.password_store(c,attributesOf(t),s.COLLECTION_DEFAULT,`${e}: ${t}`,n,null,r),e=>s.password_store_finish(e))}catch(e){throw failure(`storing a secret`,e)}},async delete(e){try{await asyncCall(t=>s.password_clear(c,attributesOf(e),null,t),e=>s.password_clear_finish(e))}catch(e){throw failure(`deleting a secret`,e)}},keys:listKeys,async clear(){try{await asyncCall(e=>s.password_clear(c,attributesOf(),null,e),e=>s.password_clear_finish(e))}catch(e){throw failure(`clearing the namespace`,e)}let e=await listKeys();if(e.length>0)throw Error(`${t}: clearing the namespace left ${e.length} item(s); is the keyring locked?`)}}}}}export{e as SCHEMA_NAME,createLibsecretDriver};
@@ -0,0 +1 @@
1
+ import"./_virtual/_rolldown/runtime.js";import{useSecretStoreDriver as e}from"./secret-store.js";import{createLibsecretDriver as t}from"./libsecret-driver.js";import n from"gi://Gio?version=2.0";import r from"gi://Secret?version=1&optional";function installLibsecretDriver(){e(t({secret:r,sandboxed:n.File.new_for_path(`/.flatpak-info`).query_exists(null)}))}installLibsecretDriver();export{installLibsecretDriver};
@@ -0,0 +1 @@
1
+ import"./_virtual/_rolldown/runtime.js";function createMemoryDriver(){let e=new Map;return{info:{driver:`memory`,persistent:!1,encryptedAtRest:!1},async open(t){let n=e.get(t);n||(n=new Map,e.set(t,n));let r=n;return{namespace:t,async get(e){return r.get(e)??null},async set(e,t){r.set(e,t)},async delete(e){r.delete(e)},async keys(){return[...r.keys()]},async clear(){r.clear()}}}}}export{createMemoryDriver};
@@ -0,0 +1 @@
1
+ import"./_virtual/_rolldown/runtime.js";let e=null;function useSecretStoreDriver(t){e=t}function platformName(){return globalThis.process?.platform??`this platform`}function requireDriver(){if(!e)throw Error(`@gjsify/secret-store has no driver for ${platformName()}`);return e}async function openSecretStore(e){return requireDriver().open(e)}function secretStoreInfo(){return requireDriver().info}export{openSecretStore,secretStoreInfo,useSecretStoreDriver};
File without changes
@@ -0,0 +1,3 @@
1
+ export { openSecretStore, secretStoreInfo, useSecretStoreDriver } from './secret-store.js';
2
+ export { createMemoryDriver } from './memory.js';
3
+ export type { SecretStore, SecretStoreDriver, SecretStoreInfo } from './types.js';
@@ -0,0 +1,13 @@
1
+ import type Secret from 'gi://Secret?version=1';
2
+ import type { SecretStoreDriver } from './types.js';
3
+ type SecretNamespace = typeof Secret;
4
+ export interface LibsecretOptions {
5
+ /** `gi://Secret`, or `undefined` when the typelib is not installed on this host. */
6
+ secret: SecretNamespace | undefined;
7
+ /** Running inside a sandbox (`/.flatpak-info`): libsecret then uses the secret portal, and this is the `portal-secret` driver. */
8
+ sandboxed: boolean;
9
+ }
10
+ /** Names the schema in the keyring; part of the stored items, so it must never change. */
11
+ export declare const SCHEMA_NAME = "org.gjsify.SecretStore";
12
+ export declare function createLibsecretDriver(options: LibsecretOptions): SecretStoreDriver;
13
+ export {};
@@ -0,0 +1,2 @@
1
+ declare const _default: () => Promise<void>;
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ /** Install the driver again, e.g. after a test removed it. Importing this module already did. */
2
+ export declare function installLibsecretDriver(): void;
@@ -0,0 +1,2 @@
1
+ declare const _default: () => Promise<void>;
2
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import type { SecretStoreDriver } from './types.js';
2
+ /** Secrets that live as long as the process. For tests; never selected automatically. */
3
+ export declare function createMemoryDriver(): SecretStoreDriver;
@@ -0,0 +1,7 @@
1
+ import type { SecretStore, SecretStoreDriver, SecretStoreInfo } from './types.js';
2
+ /** Install the driver of this platform, or `null` to remove it. Called by driver packages and tests. */
3
+ export declare function useSecretStoreDriver(driver: SecretStoreDriver | null): void;
4
+ /** Throws, naming the platform, where this build has no driver (ADR 0101). */
5
+ export declare function openSecretStore(namespace: string): Promise<SecretStore>;
6
+ /** Diagnostics only; throws like `openSecretStore` where there is no driver. */
7
+ export declare function secretStoreInfo(): SecretStoreInfo;
@@ -0,0 +1,2 @@
1
+ declare const _default: () => Promise<void>;
2
+ export default _default;
@@ -0,0 +1,27 @@
1
+ /** What a store does. Opaque namespaces; two namespaces never see each other. */
2
+ export interface SecretStore {
3
+ readonly namespace: string;
4
+ /** The stored secret, or `null` when this namespace has no such key. */
5
+ get(key: string): Promise<string | null>;
6
+ /** Store or replace. The value is never logged, cached or put in an error by this package. */
7
+ set(key: string, secret: string): Promise<void>;
8
+ /** Missing is not an error. */
9
+ delete(key: string): Promise<void>;
10
+ /** Keys only, never values — for cleaning up after an account the app removed. */
11
+ keys(): Promise<string[]>;
12
+ /** Forget this namespace: sign-out, account removal, "delete my data". */
13
+ clear(): Promise<void>;
14
+ }
15
+ /** Diagnostics for an about dialog or a bug report. An app reports it; it never branches on it. */
16
+ export interface SecretStoreInfo {
17
+ readonly driver: 'libsecret' | 'portal-secret' | 'keystore-file' | 'keychain' | 'memory';
18
+ /** False when the secrets live only as long as the process. */
19
+ readonly persistent: boolean;
20
+ /** False when nothing but file permissions protects the bytes. */
21
+ readonly encryptedAtRest: boolean;
22
+ }
23
+ /** One platform's implementation, installed with `useSecretStoreDriver`. */
24
+ export interface SecretStoreDriver {
25
+ readonly info: SecretStoreInfo;
26
+ open(namespace: string): Promise<SecretStore>;
27
+ }
package/package.json CHANGED
@@ -1,6 +1,79 @@
1
1
  {
2
- "name": "@gjsify/secret-store",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@gjsify/secret-store",
3
+ "version": "0.64.59",
4
+ "description": "Secrets an app owns (a typed password, its own refresh token), kept per namespace by a platform driver. No driver means it throws, naming the platform: never a silent plaintext fallback (ADR 0152).",
5
+ "module": "lib/esm/index.js",
6
+ "types": "lib/types/index.d.ts",
7
+ "type": "module",
8
+ "sideEffects": [
9
+ "./lib/esm/libsecret.js"
10
+ ],
11
+ "exports": {
12
+ ".": {
13
+ "types": "./lib/types/index.d.ts",
14
+ "default": "./lib/esm/index.js"
15
+ },
16
+ "./libsecret": {
17
+ "types": "./lib/types/libsecret.d.ts",
18
+ "default": "./lib/esm/libsecret.js"
19
+ }
20
+ },
21
+ "files": [
22
+ "lib",
23
+ "!lib/types/**/*.spec.d.ts"
24
+ ],
25
+ "scripts": {
26
+ "clear": "gjsify clear lib tmp tsconfig.tsbuildinfo test.gjs.mjs test.node.mjs",
27
+ "check": "gjsify tsc --noEmit",
28
+ "build": "gjsify run build:gjsify && gjsify run build:types",
29
+ "build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}' 'src/test.gjs.mts' 'src/**/*.gjs.spec.ts'",
30
+ "build:types": "gjsify tsc",
31
+ "build:test": "gjsify run build:test:gjs && gjsify run build:test:node",
32
+ "build:test:gjs": "gjsify build src/test.gjs.mts --app gjs --outfile test.gjs.mjs",
33
+ "build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
34
+ "test": "gjsify run build:gjsify && gjsify run build:test && gjsify run test:node && gjsify run test:gjs",
35
+ "test:gjs": "gjsify run test.gjs.mjs",
36
+ "test:node": "node test.node.mjs"
37
+ },
38
+ "keywords": [
39
+ "gjs",
40
+ "secret",
41
+ "password",
42
+ "keystore",
43
+ "keychain",
44
+ "libsecret"
45
+ ],
46
+ "dependencies": {
47
+ "@girs/gio-2.0": "5.4.0",
48
+ "@girs/gjs": "5.4.0",
49
+ "@girs/glib-2.0": "5.4.0",
50
+ "@girs/gobject-2.0": "5.4.0",
51
+ "@girs/secret-1": "5.4.0"
52
+ },
53
+ "devDependencies": {
54
+ "@gjsify/cli": "^0.64.59",
55
+ "@gjsify/unit": "^0.64.59",
56
+ "@types/node": "^25.9.2",
57
+ "typescript": "^6.0.3"
58
+ },
59
+ "license": "MIT",
60
+ "repository": {
61
+ "type": "git",
62
+ "url": "git+https://github.com/gjsify/gjsify.git",
63
+ "directory": "packages/gjs/secret-store"
64
+ },
65
+ "bugs": {
66
+ "url": "https://github.com/gjsify/gjsify/issues"
67
+ },
68
+ "homepage": "https://github.com/gjsify/gjsify/tree/main/packages/gjs/secret-store#readme",
69
+ "gjsify": {
70
+ "tier": 3,
71
+ "runtimes": {
72
+ "gjs": "partial",
73
+ "node": "none",
74
+ "browser": "none",
75
+ "nativescript": "partial"
76
+ },
77
+ "headless": true
78
+ }
79
+ }