@skrr-ai/auth-core 0.1.2

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 (147) hide show
  1. package/README.md +21 -0
  2. package/dist/cjs/aead.d.ts +24 -0
  3. package/dist/cjs/aead.js +65 -0
  4. package/dist/cjs/authExpiredDetector.d.ts +65 -0
  5. package/dist/cjs/authExpiredDetector.js +89 -0
  6. package/dist/cjs/authHelper.d.ts +51 -0
  7. package/dist/cjs/authHelper.js +321 -0
  8. package/dist/cjs/credentialEnvelope.d.ts +85 -0
  9. package/dist/cjs/credentialEnvelope.js +230 -0
  10. package/dist/cjs/credentialEnvelopeBridge.d.ts +116 -0
  11. package/dist/cjs/credentialEnvelopeBridge.js +637 -0
  12. package/dist/cjs/credentialResolver.d.ts +278 -0
  13. package/dist/cjs/credentialResolver.js +423 -0
  14. package/dist/cjs/daemonPair.d.ts +172 -0
  15. package/dist/cjs/daemonPair.js +495 -0
  16. package/dist/cjs/daemonScopes.d.ts +74 -0
  17. package/dist/cjs/daemonScopes.js +84 -0
  18. package/dist/cjs/deviceIdentityBridge.d.ts +113 -0
  19. package/dist/cjs/deviceIdentityBridge.js +591 -0
  20. package/dist/cjs/deviceKey.d.ts +167 -0
  21. package/dist/cjs/deviceKey.js +332 -0
  22. package/dist/cjs/fdToken.d.ts +17 -0
  23. package/dist/cjs/fdToken.js +238 -0
  24. package/dist/cjs/harnessTrust.d.ts +72 -0
  25. package/dist/cjs/harnessTrust.js +103 -0
  26. package/dist/cjs/headers-helper.d.ts +25 -0
  27. package/dist/cjs/headers-helper.js +323 -0
  28. package/dist/cjs/index.d.ts +37 -0
  29. package/dist/cjs/index.js +305 -0
  30. package/dist/cjs/jwtUtils.d.ts +35 -0
  31. package/dist/cjs/jwtUtils.js +61 -0
  32. package/dist/cjs/kek/index.d.ts +89 -0
  33. package/dist/cjs/kek/index.js +208 -0
  34. package/dist/cjs/kek/linux.d.ts +92 -0
  35. package/dist/cjs/kek/linux.js +596 -0
  36. package/dist/cjs/kek/macos.d.ts +112 -0
  37. package/dist/cjs/kek/macos.js +599 -0
  38. package/dist/cjs/kek/types.d.ts +111 -0
  39. package/dist/cjs/kek/types.js +43 -0
  40. package/dist/cjs/kek/windows.d.ts +71 -0
  41. package/dist/cjs/kek/windows.js +350 -0
  42. package/dist/cjs/kek/zeroize-registry.d.ts +44 -0
  43. package/dist/cjs/kek/zeroize-registry.js +63 -0
  44. package/dist/cjs/legacyStatePreflight.d.ts +67 -0
  45. package/dist/cjs/legacyStatePreflight.js +78 -0
  46. package/dist/cjs/localIdentity.d.ts +54 -0
  47. package/dist/cjs/localIdentity.js +57 -0
  48. package/dist/cjs/loginLocalhost.d.ts +115 -0
  49. package/dist/cjs/loginLocalhost.js +368 -0
  50. package/dist/cjs/loginWithLocalhost.d.ts +131 -0
  51. package/dist/cjs/loginWithLocalhost.js +359 -0
  52. package/dist/cjs/machineId.d.ts +35 -0
  53. package/dist/cjs/machineId.js +239 -0
  54. package/dist/cjs/messages.d.ts +9 -0
  55. package/dist/cjs/messages.js +44 -0
  56. package/dist/cjs/package.json +3 -0
  57. package/dist/cjs/pkce.d.ts +62 -0
  58. package/dist/cjs/pkce.js +158 -0
  59. package/dist/cjs/recoveryCode.d.ts +61 -0
  60. package/dist/cjs/recoveryCode.js +213 -0
  61. package/dist/cjs/refresh.d.ts +215 -0
  62. package/dist/cjs/refresh.js +877 -0
  63. package/dist/cjs/refreshClassification.d.ts +53 -0
  64. package/dist/cjs/refreshClassification.js +105 -0
  65. package/dist/cjs/refreshScheduler.d.ts +53 -0
  66. package/dist/cjs/refreshScheduler.js +332 -0
  67. package/dist/cjs/runtime.d.ts +149 -0
  68. package/dist/cjs/runtime.js +136 -0
  69. package/dist/cjs/spawnEnv.d.ts +76 -0
  70. package/dist/cjs/spawnEnv.js +153 -0
  71. package/dist/cjs/ttlParser.d.ts +54 -0
  72. package/dist/cjs/ttlParser.js +87 -0
  73. package/dist/cjs/types.d.ts +91 -0
  74. package/dist/cjs/types.js +26 -0
  75. package/dist/esm/aead.d.ts +24 -0
  76. package/dist/esm/aead.js +57 -0
  77. package/dist/esm/authExpiredDetector.d.ts +65 -0
  78. package/dist/esm/authExpiredDetector.js +85 -0
  79. package/dist/esm/authHelper.d.ts +51 -0
  80. package/dist/esm/authHelper.js +311 -0
  81. package/dist/esm/credentialEnvelope.d.ts +85 -0
  82. package/dist/esm/credentialEnvelope.js +213 -0
  83. package/dist/esm/credentialEnvelopeBridge.d.ts +116 -0
  84. package/dist/esm/credentialEnvelopeBridge.js +620 -0
  85. package/dist/esm/credentialResolver.d.ts +278 -0
  86. package/dist/esm/credentialResolver.js +414 -0
  87. package/dist/esm/daemonPair.d.ts +172 -0
  88. package/dist/esm/daemonPair.js +476 -0
  89. package/dist/esm/daemonScopes.d.ts +74 -0
  90. package/dist/esm/daemonScopes.js +80 -0
  91. package/dist/esm/deviceIdentityBridge.d.ts +113 -0
  92. package/dist/esm/deviceIdentityBridge.js +572 -0
  93. package/dist/esm/deviceKey.d.ts +167 -0
  94. package/dist/esm/deviceKey.js +320 -0
  95. package/dist/esm/fdToken.d.ts +17 -0
  96. package/dist/esm/fdToken.js +231 -0
  97. package/dist/esm/harnessTrust.d.ts +72 -0
  98. package/dist/esm/harnessTrust.js +97 -0
  99. package/dist/esm/headers-helper.d.ts +25 -0
  100. package/dist/esm/headers-helper.js +316 -0
  101. package/dist/esm/index.d.ts +37 -0
  102. package/dist/esm/index.js +144 -0
  103. package/dist/esm/jwtUtils.d.ts +35 -0
  104. package/dist/esm/jwtUtils.js +57 -0
  105. package/dist/esm/kek/index.d.ts +89 -0
  106. package/dist/esm/kek/index.js +162 -0
  107. package/dist/esm/kek/linux.d.ts +92 -0
  108. package/dist/esm/kek/linux.js +585 -0
  109. package/dist/esm/kek/macos.d.ts +112 -0
  110. package/dist/esm/kek/macos.js +586 -0
  111. package/dist/esm/kek/types.d.ts +111 -0
  112. package/dist/esm/kek/types.js +39 -0
  113. package/dist/esm/kek/windows.d.ts +71 -0
  114. package/dist/esm/kek/windows.js +344 -0
  115. package/dist/esm/kek/zeroize-registry.d.ts +44 -0
  116. package/dist/esm/kek/zeroize-registry.js +58 -0
  117. package/dist/esm/legacyStatePreflight.d.ts +67 -0
  118. package/dist/esm/legacyStatePreflight.js +71 -0
  119. package/dist/esm/localIdentity.d.ts +54 -0
  120. package/dist/esm/localIdentity.js +54 -0
  121. package/dist/esm/loginLocalhost.d.ts +115 -0
  122. package/dist/esm/loginLocalhost.js +355 -0
  123. package/dist/esm/loginWithLocalhost.d.ts +131 -0
  124. package/dist/esm/loginWithLocalhost.js +353 -0
  125. package/dist/esm/machineId.d.ts +35 -0
  126. package/dist/esm/machineId.js +231 -0
  127. package/dist/esm/messages.d.ts +9 -0
  128. package/dist/esm/messages.js +40 -0
  129. package/dist/esm/pkce.d.ts +62 -0
  130. package/dist/esm/pkce.js +148 -0
  131. package/dist/esm/recoveryCode.d.ts +61 -0
  132. package/dist/esm/recoveryCode.js +207 -0
  133. package/dist/esm/refresh.d.ts +215 -0
  134. package/dist/esm/refresh.js +863 -0
  135. package/dist/esm/refreshClassification.d.ts +53 -0
  136. package/dist/esm/refreshClassification.js +106 -0
  137. package/dist/esm/refreshScheduler.d.ts +53 -0
  138. package/dist/esm/refreshScheduler.js +329 -0
  139. package/dist/esm/runtime.d.ts +149 -0
  140. package/dist/esm/runtime.js +121 -0
  141. package/dist/esm/spawnEnv.d.ts +76 -0
  142. package/dist/esm/spawnEnv.js +149 -0
  143. package/dist/esm/ttlParser.d.ts +54 -0
  144. package/dist/esm/ttlParser.js +83 -0
  145. package/dist/esm/types.d.ts +91 -0
  146. package/dist/esm/types.js +21 -0
  147. package/package.json +82 -0
@@ -0,0 +1,112 @@
1
+ import type { KekStrategy } from './types.js';
2
+ /**
3
+ * Stable telemetry kind string — fleet dashboards size the macOS cohort
4
+ * by this value. Only one backend ships in this module today.
5
+ */
6
+ declare const KIND_SHELLOUT = "macos-keychain-shellout";
7
+ /**
8
+ * @internal Test seam — inject a mock execFile for hermetic tests so the
9
+ * suite never touches the real Keychain. Reset to `null` to restore the
10
+ * real `child_process.execFile`.
11
+ */
12
+ type ExecFileLike = (file: string, args: readonly string[], options?: {
13
+ encoding?: BufferEncoding;
14
+ stdio?: unknown;
15
+ }) => Promise<{
16
+ stdout: string;
17
+ stderr: string;
18
+ }>;
19
+ export declare function __setExecFileForTest(fn: ExecFileLike | null): void;
20
+ /** @internal Test seam — clear the security-binary probe cache. */
21
+ export declare function __resetSecurityProbeCacheForTest(): void;
22
+ /** @internal Test seam — clear the resolved-keychain cache. */
23
+ export declare function __resetResolvedKeychainCacheForTest(): void;
24
+ /**
25
+ * Zero out and drop every cached master-KEK buffer.
26
+ *
27
+ * Iterates the cache map, fills each buffer with zeroes (so any
28
+ * residual reference held by a caller observes the wipe), then clears
29
+ * the map. The buffer-fill happens before the map clear so the typed
30
+ * test seam (`__getKekCacheForTest`) can prove the wipe targeted the
31
+ * actual cached bytes rather than a copy.
32
+ *
33
+ * Must be called on:
34
+ * - Daemon shutdown (SIGTERM / SIGINT) so the KEK does not linger in
35
+ * memory across the process exit window where coredumps could land.
36
+ * - KEK rotation, after the new KEK has been resolved and the wrapped
37
+ * DEK re-issued, so the OLD KEK does not stay resident.
38
+ * - Logout flows that wipe at-rest credentials, so there is no useful
39
+ * KEK left to wrap a re-enrolled DEK under the previous identity.
40
+ *
41
+ * Idempotent — safe to call when the cache is already empty.
42
+ */
43
+ export declare function zeroizeMacosKekCache(): void;
44
+ /** @internal Test seam — clear the in-process master-KEK cache. Internally
45
+ * routes through the production zeroize helper so the test-reset path
46
+ * exercises the same buffer-fill that ships in production. */
47
+ export declare function __resetKekCacheForTest(): void;
48
+ /**
49
+ * @internal Test seam — return the live cache buffer for the given
50
+ * `service`/`account` pair so the zeroize test can hold a reference,
51
+ * run zeroize, and verify the underlying bytes went to all-zero
52
+ * (proving the fill was on the actual buffer rather than a copy).
53
+ * Returns null when no entry is cached for that pair.
54
+ *
55
+ * Defaults to the canonical production keys so existing tests that
56
+ * call `__getKekCacheForTest()` keep working without args.
57
+ */
58
+ export declare function __getKekCacheForTest(service?: string, account?: string): Buffer | null;
59
+ export declare class MacosKek implements KekStrategy {
60
+ readonly id = "macos-secure-enclave";
61
+ /** Telemetry kind of the backend that satisfied the most recent call.
62
+ * Public so the daemon's `cred_envelope` events can include it. */
63
+ private _lastKind;
64
+ /** Keychain `service` (the `-s` arg) this instance reads/writes. */
65
+ private readonly service;
66
+ /** Keychain `account` (the `-a` arg) this instance reads/writes. */
67
+ private readonly account;
68
+ /**
69
+ * @param opts.service Optional override for the keychain `-s` value.
70
+ * Defaults to `ai.skrr.daemon.kek` — the canonical production
71
+ * pair. Override only for hermetic multi-tenant tests or for the
72
+ * real-keychain smoke test, which generates a unique service per
73
+ * run so its `delete-generic-password` teardown cannot clobber the
74
+ * developer's actual master KEK. Production callers MUST pass
75
+ * nothing so fleet telemetry stays sized against one keychain
76
+ * entry per host.
77
+ * @param opts.account Optional override for the keychain `-a` value.
78
+ * Defaults to `master-kek-v1`. Same caveat as `service`: an
79
+ * override that points at a non-default entry must be paired with
80
+ * explicit cleanup if the entry should not persist past the
81
+ * caller's lifetime — `MacosKek` itself never deletes keychain
82
+ * items.
83
+ */
84
+ constructor(opts?: {
85
+ service?: string;
86
+ account?: string;
87
+ });
88
+ /**
89
+ * Telemetry kind of the most recent successful wrap/unwrap. `null`
90
+ * before any call. Stable string `'macos-keychain-shellout'` after the
91
+ * first successful wrap or unwrap. The kind does not vary with
92
+ * `service`/`account` overrides — the backend is the same.
93
+ */
94
+ get kind(): typeof KIND_SHELLOUT | null;
95
+ /**
96
+ * `available()` is true on darwin when (a) `security` is on PATH AND
97
+ * (b) a user login keychain can be resolved. Both checks are required
98
+ * because shelling out without a resolvable keychain triggers a
99
+ * system-modal `Keychain Not Found` dialog from the daemon — which
100
+ * blocks the process and offers a destructive `Reset To Defaults`
101
+ * action. When the keychain resolution fails, we honestly return
102
+ * `false` so `credEnvelope.ts` reports `disabled.kek_unavailable`
103
+ * cleanly. Cached results — the probe spawns at most one
104
+ * `security help` and one `security default-keychain` per process.
105
+ */
106
+ available(): Promise<boolean>;
107
+ wrap(dek: Buffer, aad?: Buffer): Promise<Buffer>;
108
+ unwrap(wrapped: Buffer, aad?: Buffer): Promise<Buffer>;
109
+ unwrapExisting(wrapped: Buffer, aad?: Buffer): Promise<Buffer>;
110
+ describe(): string;
111
+ }
112
+ export {};