@centient/secrets 0.2.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.
Files changed (57) hide show
  1. package/dist/cli/messages.d.ts +60 -0
  2. package/dist/cli/messages.d.ts.map +1 -0
  3. package/dist/cli/messages.js +63 -0
  4. package/dist/cli/messages.js.map +1 -0
  5. package/dist/cli/secrets-cli.d.ts +38 -0
  6. package/dist/cli/secrets-cli.d.ts.map +1 -0
  7. package/dist/cli/secrets-cli.js +532 -0
  8. package/dist/cli/secrets-cli.js.map +1 -0
  9. package/dist/crypto/vault-common.d.ts +63 -0
  10. package/dist/crypto/vault-common.d.ts.map +1 -0
  11. package/dist/crypto/vault-common.js +180 -0
  12. package/dist/crypto/vault-common.js.map +1 -0
  13. package/dist/environment/EnvironmentManager.d.ts +171 -0
  14. package/dist/environment/EnvironmentManager.d.ts.map +1 -0
  15. package/dist/environment/EnvironmentManager.js +604 -0
  16. package/dist/environment/EnvironmentManager.js.map +1 -0
  17. package/dist/index.d.ts +12 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +17 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/platform/agent-detect.d.ts +15 -0
  22. package/dist/platform/agent-detect.d.ts.map +1 -0
  23. package/dist/platform/agent-detect.js +22 -0
  24. package/dist/platform/agent-detect.js.map +1 -0
  25. package/dist/platform/platform.d.ts +51 -0
  26. package/dist/platform/platform.d.ts.map +1 -0
  27. package/dist/platform/platform.js +141 -0
  28. package/dist/platform/platform.js.map +1 -0
  29. package/dist/vault/types.d.ts +54 -0
  30. package/dist/vault/types.d.ts.map +1 -0
  31. package/dist/vault/types.js +12 -0
  32. package/dist/vault/types.js.map +1 -0
  33. package/dist/vault/vault-env.d.ts +58 -0
  34. package/dist/vault/vault-env.d.ts.map +1 -0
  35. package/dist/vault/vault-env.js +73 -0
  36. package/dist/vault/vault-env.js.map +1 -0
  37. package/dist/vault/vault-gpg.d.ts +40 -0
  38. package/dist/vault/vault-gpg.d.ts.map +1 -0
  39. package/dist/vault/vault-gpg.js +149 -0
  40. package/dist/vault/vault-gpg.js.map +1 -0
  41. package/dist/vault/vault-libsecret.d.ts +51 -0
  42. package/dist/vault/vault-libsecret.d.ts.map +1 -0
  43. package/dist/vault/vault-libsecret.js +115 -0
  44. package/dist/vault/vault-libsecret.js.map +1 -0
  45. package/dist/vault/vault-utils.d.ts +12 -0
  46. package/dist/vault/vault-utils.d.ts.map +1 -0
  47. package/dist/vault/vault-utils.js +16 -0
  48. package/dist/vault/vault-utils.js.map +1 -0
  49. package/dist/vault/vault-windows.d.ts +71 -0
  50. package/dist/vault/vault-windows.d.ts.map +1 -0
  51. package/dist/vault/vault-windows.js +186 -0
  52. package/dist/vault/vault-windows.js.map +1 -0
  53. package/dist/vault/vault.d.ts +53 -0
  54. package/dist/vault/vault.d.ts.map +1 -0
  55. package/dist/vault/vault.js +132 -0
  56. package/dist/vault/vault.js.map +1 -0
  57. package/package.json +37 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vault-gpg.js","sourceRoot":"","sources":["../../src/vault/vault-gpg.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAG5B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,gFAAgF;AAChF,YAAY;AACZ,gFAAgF;AAEhF,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;AAEtD,gFAAgF;AAChF,UAAU;AACV,gFAAgF;AAEhF;;GAEG;AACH,SAAS,cAAc,CAAC,GAAW;IACjC,OAAO,IAAI,CAAC,QAA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AE,MAAM,CAAC;aAChC,CACF,CAAC;YACF,OAAO,MAAM,IAAI,IAAI,CAAC;QACxB,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,GAAW;QAChB,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;QACnC,IAAI,CAAC;YACH,UAAU,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC;YAChC,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,qDAAqD;YACrD,IACE,GAAG,KAAK,IAAI;gBACZ,OAAO,GAAG,KAAK,QAAQ;gBACvB,MAAM,IAAI,GAAG;gBACZ,GAA6B,CAAC,IAAI,KAAK,QAAQ,EAChD,CAAC;gBACD,OAAO,IAAI,CAAC;YACd,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Auth Vault — Credential Storage (Linux libsecret via secret-tool)
3
+ *
4
+ * Provides secure storage for auth tokens on Linux systems using the
5
+ * GNOME libsecret service via the `secret-tool` CLI. Credentials are
6
+ * stored under a fixed service attribute (`centient`) and a per-key
7
+ * attribute (`key`).
8
+ *
9
+ * Error handling: all functions return null/false on failure — never throw.
10
+ */
11
+ import type { VaultBackend } from "./types.js";
12
+ /**
13
+ * Vault backend that uses the `secret-tool` CLI to interact with the
14
+ * system's libsecret / GNOME Keyring service on Linux.
15
+ *
16
+ * Usage:
17
+ * if (LibsecretVault.detect()) {
18
+ * const vault = new LibsecretVault();
19
+ * vault.store("auth-token", token);
20
+ * }
21
+ */
22
+ export declare class LibsecretVault implements VaultBackend {
23
+ /**
24
+ * Returns true if `secret-tool` is available on this system.
25
+ * Uses `which secret-tool` — returns false if not found or command fails.
26
+ */
27
+ static detect(): boolean;
28
+ /**
29
+ * Store a credential value in the libsecret keyring.
30
+ *
31
+ * @param key - Logical key name (e.g. 'auth-token', 'refresh-token')
32
+ * @param value - The credential value to store (passed via stdin)
33
+ * @returns true on success, false if the write fails
34
+ */
35
+ store(key: string, value: string): boolean;
36
+ /**
37
+ * Retrieve a credential value from the libsecret keyring.
38
+ *
39
+ * @param key - Logical key name (e.g. 'auth-token')
40
+ * @returns The stored value, or null if not found / lookup fails
41
+ */
42
+ retrieve(key: string): string | null;
43
+ /**
44
+ * Delete a credential from the libsecret keyring.
45
+ *
46
+ * @param key - Logical key name (e.g. 'auth-token')
47
+ * @returns true on success (including "already deleted"), false on unexpected error
48
+ */
49
+ delete(key: string): boolean;
50
+ }
51
+ //# sourceMappingURL=vault-libsecret.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vault-libsecret.d.ts","sourceRoot":"","sources":["../../src/vault/vault-libsecret.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAc/C;;;;;;;;;GASG;AACH,qBAAa,cAAe,YAAW,YAAY;IACjD;;;OAGG;IACH,MAAM,CAAC,MAAM,IAAI,OAAO;IAYxB;;;;;;OAMG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;IAiB1C;;;;;OAKG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAiBpC;;;;;OAKG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;CAkB7B"}
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Auth Vault — Credential Storage (Linux libsecret via secret-tool)
3
+ *
4
+ * Provides secure storage for auth tokens on Linux systems using the
5
+ * GNOME libsecret service via the `secret-tool` CLI. Credentials are
6
+ * stored under a fixed service attribute (`centient`) and a per-key
7
+ * attribute (`key`).
8
+ *
9
+ * Error handling: all functions return null/false on failure — never throw.
10
+ */
11
+ import { execSync } from "child_process";
12
+ import { isValidKey } from "./vault-utils.js";
13
+ // =============================================================================
14
+ // Constants
15
+ // =============================================================================
16
+ const SERVICE_ATTR = "centient";
17
+ const LABEL = "centient-auth";
18
+ // =============================================================================
19
+ // LibsecretVault
20
+ // =============================================================================
21
+ /**
22
+ * Vault backend that uses the `secret-tool` CLI to interact with the
23
+ * system's libsecret / GNOME Keyring service on Linux.
24
+ *
25
+ * Usage:
26
+ * if (LibsecretVault.detect()) {
27
+ * const vault = new LibsecretVault();
28
+ * vault.store("auth-token", token);
29
+ * }
30
+ */
31
+ export class LibsecretVault {
32
+ /**
33
+ * Returns true if `secret-tool` is available on this system.
34
+ * Uses `which secret-tool` — returns false if not found or command fails.
35
+ */
36
+ static detect() {
37
+ try {
38
+ execSync("which secret-tool", {
39
+ encoding: "utf8",
40
+ stdio: ["pipe", "pipe", "pipe"],
41
+ });
42
+ return true;
43
+ }
44
+ catch {
45
+ return false;
46
+ }
47
+ }
48
+ /**
49
+ * Store a credential value in the libsecret keyring.
50
+ *
51
+ * @param key - Logical key name (e.g. 'auth-token', 'refresh-token')
52
+ * @param value - The credential value to store (passed via stdin)
53
+ * @returns true on success, false if the write fails
54
+ */
55
+ store(key, value) {
56
+ if (!isValidKey(key))
57
+ return false;
58
+ try {
59
+ execSync(`secret-tool store --label "${LABEL}" service ${SERVICE_ATTR} key "${key}"`, {
60
+ encoding: "utf8",
61
+ stdio: ["pipe", "pipe", "pipe"],
62
+ input: value,
63
+ });
64
+ return true;
65
+ }
66
+ catch {
67
+ return false;
68
+ }
69
+ }
70
+ /**
71
+ * Retrieve a credential value from the libsecret keyring.
72
+ *
73
+ * @param key - Logical key name (e.g. 'auth-token')
74
+ * @returns The stored value, or null if not found / lookup fails
75
+ */
76
+ retrieve(key) {
77
+ if (!isValidKey(key))
78
+ return null;
79
+ try {
80
+ const result = execSync(`secret-tool lookup service ${SERVICE_ATTR} key "${key}"`, {
81
+ encoding: "utf8",
82
+ stdio: ["pipe", "pipe", "pipe"],
83
+ });
84
+ const trimmed = result.trim();
85
+ return trimmed.length > 0 ? trimmed : null;
86
+ }
87
+ catch {
88
+ return null;
89
+ }
90
+ }
91
+ /**
92
+ * Delete a credential from the libsecret keyring.
93
+ *
94
+ * @param key - Logical key name (e.g. 'auth-token')
95
+ * @returns true on success (including "already deleted"), false on unexpected error
96
+ */
97
+ delete(key) {
98
+ if (!isValidKey(key))
99
+ return false;
100
+ try {
101
+ execSync(`secret-tool clear service ${SERVICE_ATTR} key "${key}"`, {
102
+ encoding: "utf8",
103
+ stdio: ["pipe", "pipe", "pipe"],
104
+ });
105
+ return true;
106
+ }
107
+ catch {
108
+ // secret-tool clear exits 0 even if item does not exist;
109
+ // any non-zero exit indicates an unexpected error — still return true
110
+ // to match the "already deleted" semantic of other backends.
111
+ return true;
112
+ }
113
+ }
114
+ }
115
+ //# sourceMappingURL=vault-libsecret.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vault-libsecret.js","sourceRoot":"","sources":["../../src/vault/vault-libsecret.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,gFAAgF;AAChF,YAAY;AACZ,gFAAgF;AAEhF,MAAM,YAAY,GAAG,UAAU,CAAC;AAChC,MAAM,KAAK,GAAG,eAAe,CAAC;AAE9B,gFAAgF;AAChF,iBAAiB;AACjB,gFAAgF;AAEhF;;;;;;;;;GASG;AACH,MAAM,OAAO,cAAc;IACzB;;;OAGG;IACH,MAAM,CAAC,MAAM;QACX,IAAI,CAAC;YACH,QAAQ,CAAC,mBAAmB,EAAE;gBAC5B,QAAQ,EAAE,MAAM;gBAChB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;aAChC,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,C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EAAE,MAAM,CAAC;aAChC,CACF,CAAC;YACF,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,yDAAyD;YACzD,sEAAsE;YACtE,6DAA6D;YAC7D,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Auth Vault — Shared Utilities
3
+ *
4
+ * Shared validation and helper functions used across all vault backends.
5
+ */
6
+ /**
7
+ * Returns true if the given credential key name is valid.
8
+ * Keys must match /^[a-z0-9][a-z0-9-]*[a-z0-9]$/ and be at most 64 characters.
9
+ * This enforces that keys cannot contain shell-special characters.
10
+ */
11
+ export declare function isValidKey(key: string): boolean;
12
+ //# sourceMappingURL=vault-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vault-utils.d.ts","sourceRoot":"","sources":["../../src/vault/vault-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE/C"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Auth Vault — Shared Utilities
3
+ *
4
+ * Shared validation and helper functions used across all vault backends.
5
+ */
6
+ /** Allowed key name pattern — alphanumeric and hyphens only, 2-64 chars. */
7
+ const VALID_KEY_RE = /^[a-z0-9][a-z0-9-]*[a-z0-9]$/;
8
+ /**
9
+ * Returns true if the given credential key name is valid.
10
+ * Keys must match /^[a-z0-9][a-z0-9-]*[a-z0-9]$/ and be at most 64 characters.
11
+ * This enforces that keys cannot contain shell-special characters.
12
+ */
13
+ export function isValidKey(key) {
14
+ return VALID_KEY_RE.test(key) && key.length <= 64;
15
+ }
16
+ //# sourceMappingURL=vault-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vault-utils.js","sourceRoot":"","sources":["../../src/vault/vault-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,4EAA4E;AAC5E,MAAM,YAAY,GAAG,8BAA8B,CAAC;AAEpD;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,OAAO,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC;AACpD,CAAC"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Auth Vault — Windows Credential Manager Backend (WSL)
3
+ *
4
+ * Implements the VaultBackend interface using the Windows Runtime PasswordVault
5
+ * API accessed via powershell.exe. This backend is intended for use in WSL
6
+ * (Windows Subsystem for Linux) environments where powershell.exe is reachable
7
+ * from the Linux filesystem.
8
+ *
9
+ * Detection: checks for the WSL_DISTRO_NAME environment variable or the
10
+ * presence of "microsoft" (case-insensitive) in /proc/version.
11
+ *
12
+ * Storage: credentials are stored in the Windows Credential Manager under the
13
+ * resource name "centient", with the logical key as the username.
14
+ *
15
+ * Error handling: all methods return false/null on failure — never throw.
16
+ */
17
+ import type { VaultBackend } from "./types.js";
18
+ /**
19
+ * Vault backend that stores credentials in the Windows Credential Manager
20
+ * using the Windows Runtime PasswordVault API via powershell.exe.
21
+ *
22
+ * This backend is only available in WSL environments. Use `WindowsVault.detect()`
23
+ * before instantiating to verify availability.
24
+ *
25
+ * Usage:
26
+ * if (WindowsVault.detect()) {
27
+ * const vault = new WindowsVault();
28
+ * vault.store("auth-token", token);
29
+ * }
30
+ */
31
+ export declare class WindowsVault implements VaultBackend {
32
+ /**
33
+ * Returns true if running inside a WSL environment where powershell.exe is
34
+ * accessible.
35
+ *
36
+ * Detection order:
37
+ * 1. WSL_DISTRO_NAME environment variable is set and non-empty
38
+ * 2. /proc/version contains "microsoft" (case-insensitive)
39
+ */
40
+ static detect(): boolean;
41
+ /**
42
+ * Verifies that powershell.exe is reachable on PATH.
43
+ */
44
+ private static isPowershellAvailable;
45
+ /**
46
+ * Stores a credential in the Windows Credential Manager PasswordVault.
47
+ *
48
+ * The credential is stored under the resource name "centient" with `key`
49
+ * as the username and `value` as the password.
50
+ *
51
+ * @param key - Logical key name (e.g. 'auth-token', 'refresh-token')
52
+ * @param value - The credential value to store
53
+ * @returns true on success, false if storage fails
54
+ */
55
+ store(key: string, value: string): boolean;
56
+ /**
57
+ * Retrieves a credential from the Windows Credential Manager PasswordVault.
58
+ *
59
+ * @param key - Logical key name (e.g. 'auth-token')
60
+ * @returns The stored password, or null if not found / retrieval fails
61
+ */
62
+ retrieve(key: string): string | null;
63
+ /**
64
+ * Removes a credential from the Windows Credential Manager PasswordVault.
65
+ *
66
+ * @param key - Logical key name (e.g. 'auth-token')
67
+ * @returns true on success (including "not found"), false on unexpected error
68
+ */
69
+ delete(key: string): boolean;
70
+ }
71
+ //# sourceMappingURL=vault-windows.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vault-windows.d.ts","sourceRoot":"","sources":["../../src/vault/vault-windows.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AA+C/C;;;;;;;;;;;;GAYG;AACH,qBAAa,YAAa,YAAW,YAAY;IAC/C;;;;;;;OAOG;IACH,MAAM,CAAC,MAAM,IAAI,OAAO;IAoBxB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAWpC;;;;;;;;;OASG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;IAmB1C;;;;;OAKG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAoBpC;;;;;OAKG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;CAqB7B"}
@@ -0,0 +1,186 @@
1
+ /**
2
+ * Auth Vault — Windows Credential Manager Backend (WSL)
3
+ *
4
+ * Implements the VaultBackend interface using the Windows Runtime PasswordVault
5
+ * API accessed via powershell.exe. This backend is intended for use in WSL
6
+ * (Windows Subsystem for Linux) environments where powershell.exe is reachable
7
+ * from the Linux filesystem.
8
+ *
9
+ * Detection: checks for the WSL_DISTRO_NAME environment variable or the
10
+ * presence of "microsoft" (case-insensitive) in /proc/version.
11
+ *
12
+ * Storage: credentials are stored in the Windows Credential Manager under the
13
+ * resource name "centient", with the logical key as the username.
14
+ *
15
+ * Error handling: all methods return false/null on failure — never throw.
16
+ */
17
+ import { spawnSync } from "child_process";
18
+ import { readFileSync } from "fs";
19
+ import { isValidKey } from "./vault-utils.js";
20
+ // =============================================================================
21
+ // Constants
22
+ // =============================================================================
23
+ /** Windows Credential Manager resource name used for all centient credentials. */
24
+ const RESOURCE_NAME = "centient";
25
+ // =============================================================================
26
+ // PowerShell helpers
27
+ // =============================================================================
28
+ /**
29
+ * Escapes a string for safe embedding inside a PowerShell single-quoted string.
30
+ * Single quotes are doubled per PowerShell escaping rules.
31
+ */
32
+ function escapePsValue(value) {
33
+ return value.replace(/'/g, "''");
34
+ }
35
+ /**
36
+ * Executes a PowerShell command via powershell.exe with no profile and
37
+ * non-interactive mode. Returns stdout trimmed, or null on error.
38
+ *
39
+ * Uses spawnSync to bypass the shell entirely, preventing shell injection
40
+ * via credential values that contain double-quotes or shell metacharacters.
41
+ */
42
+ function runPowershell(command) {
43
+ try {
44
+ const result = spawnSync("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", command], { encoding: "utf8" });
45
+ if (result.error || result.status !== 0)
46
+ return null;
47
+ return result.stdout.trim();
48
+ }
49
+ catch {
50
+ return null;
51
+ }
52
+ }
53
+ // =============================================================================
54
+ // WindowsVault
55
+ // =============================================================================
56
+ /**
57
+ * Vault backend that stores credentials in the Windows Credential Manager
58
+ * using the Windows Runtime PasswordVault API via powershell.exe.
59
+ *
60
+ * This backend is only available in WSL environments. Use `WindowsVault.detect()`
61
+ * before instantiating to verify availability.
62
+ *
63
+ * Usage:
64
+ * if (WindowsVault.detect()) {
65
+ * const vault = new WindowsVault();
66
+ * vault.store("auth-token", token);
67
+ * }
68
+ */
69
+ export class WindowsVault {
70
+ /**
71
+ * Returns true if running inside a WSL environment where powershell.exe is
72
+ * accessible.
73
+ *
74
+ * Detection order:
75
+ * 1. WSL_DISTRO_NAME environment variable is set and non-empty
76
+ * 2. /proc/version contains "microsoft" (case-insensitive)
77
+ */
78
+ static detect() {
79
+ // Primary detection: WSL_DISTRO_NAME env var
80
+ const wslDistro = process.env["WSL_DISTRO_NAME"];
81
+ if (wslDistro !== undefined && wslDistro.length > 0) {
82
+ return WindowsVault.isPowershellAvailable();
83
+ }
84
+ // Secondary detection: /proc/version content
85
+ try {
86
+ const procVersion = readFileSync("/proc/version", "utf8");
87
+ if (/microsoft/i.test(procVersion)) {
88
+ return WindowsVault.isPowershellAvailable();
89
+ }
90
+ }
91
+ catch {
92
+ // /proc/version not readable — not a Linux/WSL environment
93
+ }
94
+ return false;
95
+ }
96
+ /**
97
+ * Verifies that powershell.exe is reachable on PATH.
98
+ */
99
+ static isPowershellAvailable() {
100
+ try {
101
+ const result = spawnSync("which", ["powershell.exe"], {
102
+ encoding: "utf8",
103
+ });
104
+ return result.status === 0;
105
+ }
106
+ catch {
107
+ return false;
108
+ }
109
+ }
110
+ /**
111
+ * Stores a credential in the Windows Credential Manager PasswordVault.
112
+ *
113
+ * The credential is stored under the resource name "centient" with `key`
114
+ * as the username and `value` as the password.
115
+ *
116
+ * @param key - Logical key name (e.g. 'auth-token', 'refresh-token')
117
+ * @param value - The credential value to store
118
+ * @returns true on success, false if storage fails
119
+ */
120
+ store(key, value) {
121
+ if (!isValidKey(key))
122
+ return false;
123
+ const escapedKey = escapePsValue(key);
124
+ const escapedValue = escapePsValue(value);
125
+ const command = [
126
+ "& {",
127
+ "[void][Windows.Security.Credentials.PasswordVault,Windows.Security.Credentials,ContentType=WindowsRuntime];",
128
+ "$vault = New-Object Windows.Security.Credentials.PasswordVault;",
129
+ `$cred = New-Object Windows.Security.Credentials.PasswordCredential('${escapePsValue(RESOURCE_NAME)}', '${escapedKey}', '${escapedValue}');`,
130
+ "$vault.Add($cred)",
131
+ "}",
132
+ ].join(" ");
133
+ const result = runPowershell(command);
134
+ return result !== null;
135
+ }
136
+ /**
137
+ * Retrieves a credential from the Windows Credential Manager PasswordVault.
138
+ *
139
+ * @param key - Logical key name (e.g. 'auth-token')
140
+ * @returns The stored password, or null if not found / retrieval fails
141
+ */
142
+ retrieve(key) {
143
+ if (!isValidKey(key))
144
+ return null;
145
+ const escapedKey = escapePsValue(key);
146
+ const command = [
147
+ "& {",
148
+ "[void][Windows.Security.Credentials.PasswordVault,Windows.Security.Credentials,ContentType=WindowsRuntime];",
149
+ "$vault = New-Object Windows.Security.Credentials.PasswordVault;",
150
+ `$cred = $vault.Retrieve('${escapePsValue(RESOURCE_NAME)}', '${escapedKey}');`,
151
+ "$cred.RetrievePassword();",
152
+ "$cred.Password",
153
+ "}",
154
+ ].join(" ");
155
+ const result = runPowershell(command);
156
+ if (result === null || result.length === 0)
157
+ return null;
158
+ return result;
159
+ }
160
+ /**
161
+ * Removes a credential from the Windows Credential Manager PasswordVault.
162
+ *
163
+ * @param key - Logical key name (e.g. 'auth-token')
164
+ * @returns true on success (including "not found"), false on unexpected error
165
+ */
166
+ delete(key) {
167
+ if (!isValidKey(key))
168
+ return false;
169
+ const escapedKey = escapePsValue(key);
170
+ const command = [
171
+ "& {",
172
+ "[void][Windows.Security.Credentials.PasswordVault,Windows.Security.Credentials,ContentType=WindowsRuntime];",
173
+ "$vault = New-Object Windows.Security.Credentials.PasswordVault;",
174
+ "try {",
175
+ `$cred = $vault.Retrieve('${escapePsValue(RESOURCE_NAME)}', '${escapedKey}');`,
176
+ "$vault.Remove($cred)",
177
+ "} catch {}",
178
+ "}",
179
+ ].join(" ");
180
+ // A null result from runPowershell means powershell.exe itself failed to
181
+ // execute; swallowing "not found" errors is handled inside the PS try/catch.
182
+ const result = runPowershell(command);
183
+ return result !== null;
184
+ }
185
+ }
186
+ //# sourceMappingURL=vault-windows.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vault-windows.js","sourceRoot":"","sources":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U,CAAC,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC;QAElC,MAAM,UAAU,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;QAEtC,MAAM,OAAO,GAAG;YACd,KAAK;YACL,6GAA6G;YAC7G,iEAAiE;YACjE,4BAA4B,aAAa,CAAC,aAAa,CAAC,OAAO,UAAU,KAAK;YAC9E,2BAA2B;YAC3B,gBAAgB;YAChB,GAAG;SACJ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEZ,MAAM,MAAM,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;QACtC,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QACxD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,GAAW;QAChB,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;QAEnC,MAAM,UAAU,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;QAEtC,MAAM,OAAO,GAAG;YACd,KAAK;YACL,6GAA6G;YAC7G,iEAAiE;YACjE,OAAO;YACP,4BAA4B,aAAa,CAAC,aAAa,CAAC,OAAO,UAAU,KAAK;YAC9E,sBAAsB;YACtB,YAAY;YACZ,GAAG;SACJ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEZ,yEAAyE;QACzE,6EAA6E;QAC7E,MAAM,MAAM,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;QACtC,OAAO,MAAM,KAAK,IAAI,CAAC;IACzB,CAAC;CACF"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Auth Vault — Credential Storage (Cascade: Keychain -> Windows -> Libsecret -> GPG -> Env)
3
+ *
4
+ * Provides secure storage for auth tokens using a cascade of backends:
5
+ * 1. KeychainVault — macOS Keychain via `security` CLI (macOS only)
6
+ * 2. WindowsVault — Windows Credential Manager via powershell.exe (WSL)
7
+ * 3. LibsecretVault — GNOME libsecret via `secret-tool` (Linux)
8
+ * 4. GpgVault — GPG-encrypted files (Linux / WSL)
9
+ * 5. EnvVault — Environment variable fallback (always available)
10
+ *
11
+ * The active backend is selected once at module load by calling each backend's
12
+ * static `detect()` method in order and choosing the first one that returns true.
13
+ *
14
+ * Session TTL: 4 hours from the last successful read/write.
15
+ *
16
+ * Error handling: all functions return null/false on failure — never throw.
17
+ */
18
+ import type { VaultType } from "./types.js";
19
+ /**
20
+ * Returns true if the in-process session is still within the TTL window.
21
+ * This does NOT validate the token itself — use validateToken() for that.
22
+ */
23
+ export declare function isSessionValid(): boolean;
24
+ /**
25
+ * Returns the type identifier for the active vault backend.
26
+ *
27
+ * Useful for diagnostics and health checks to know which backend was selected
28
+ * at startup (e.g. "keychain", "libsecret", "gpg", "env").
29
+ */
30
+ export declare function getActiveVaultType(): VaultType;
31
+ /**
32
+ * Store a credential in the active vault backend.
33
+ *
34
+ * @param key - Logical key name (e.g. 'auth-token', 'refresh-token')
35
+ * @param value - The credential value to store
36
+ * @returns true on success, false if the backend write fails
37
+ */
38
+ export declare function storeCredential(key: string, value: string): Promise<boolean>;
39
+ /**
40
+ * Retrieve a credential from the active vault backend.
41
+ *
42
+ * @param key - Logical key name (e.g. 'auth-token')
43
+ * @returns The stored value, or null if not found / backend unavailable
44
+ */
45
+ export declare function getCredential(key: string): Promise<string | null>;
46
+ /**
47
+ * Delete a credential from the active vault backend.
48
+ *
49
+ * @param key - Logical key name (e.g. 'auth-token')
50
+ * @returns true on success (including "already deleted"), false on unexpected error
51
+ */
52
+ export declare function deleteCredential(key: string): Promise<boolean>;
53
+ //# sourceMappingURL=vault.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vault.d.ts","sourceRoot":"","sources":["../../src/vault/vault.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAWH,OAAO,KAAK,EAAgB,SAAS,EAAE,MAAM,YAAY,CAAC;AA4D1D;;;GAGG;AACH,wBAAgB,cAAc,IAAI,OAAO,CAGxC;AAWD;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,SAAS,CAE9C;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CACnC,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,OAAO,CAAC,CAIlB;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAIvE;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAEpE"}