@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,91 @@
1
+ /**
2
+ * Shared types & error classes used across refresh, refreshScheduler, and
3
+ * fdToken modules. Lives in its own file so consumers can `import type` from
4
+ * the package without dragging in side-effecting modules.
5
+ */
6
+ export interface TokenPair {
7
+ /**
8
+ * Legacy daemon/cli/web access JWT. Null after Stage-E #1 step 4
9
+ * for daemon-scope refresh responses: the JWT-daemon substrate has
10
+ * been retired and only `opaqueAccessToken` is shipped. Non-daemon
11
+ * scopes (cli, web) still receive a non-null JWT here.
12
+ */
13
+ accessToken: string | null;
14
+ /** Epoch ms. */
15
+ accessExpiresAt: number;
16
+ refreshToken: string;
17
+ /** Epoch ms. */
18
+ refreshExpiresAt: number;
19
+ /**
20
+ * Stage-E #1 — opaque `osk_dmn_*` daemon access token co-issued
21
+ * with the JWT for daemon-scope sessions. Optional during the
22
+ * dark-ship migration window:
23
+ *
24
+ * - `undefined` / absent: server didn't co-issue (older API,
25
+ * non-daemon scope, or `OVERSKY_DMN_OPAQUE_DISABLED=1` set).
26
+ * Daemon authenticates with the JWT (legacy behavior).
27
+ * - `null`: server co-issued but the value is explicitly null
28
+ * (kill switch tripped mid-rotation, or write failed). Daemon
29
+ * callers MUST treat this as "clear any cached opaque slot
30
+ * so we don't keep using a stale opaque after its row was
31
+ * family-revoked".
32
+ * - `string`: opaque plaintext. Daemon stores in keychain and
33
+ * prefers over JWT for the next handshake (gated by
34
+ * `OVERSKY_PREFER_OPAQUE_DAEMON_TOKEN`, default on).
35
+ *
36
+ * Expires in lockstep with `accessExpiresAt` (server-side they're
37
+ * minted in the same transaction with identical TTL). The pair
38
+ * intentionally does NOT carry a separate `opaqueAccessExpiresAt`.
39
+ */
40
+ opaqueAccessToken?: string | null;
41
+ /**
42
+ * Production-hardening 2026-05-06 — soft backoff hint from the server
43
+ * indicating the fleet refresh-QPS is high and the daemon SHOULD
44
+ * defer its next proactive refresh by this many seconds (plus its
45
+ * own jitter). Distinct from a 429 Retry-After: this is advisory,
46
+ * the rotation already succeeded, and the daemon's correctness is
47
+ * not at risk if it ignores the hint. Honoring it lets a fleet
48
+ * stretch its refresh-cadence under load WITHOUT any rejected
49
+ * requests.
50
+ *
51
+ * Sourced from the response's `X-Refresh-Backoff` header (or
52
+ * `Retry-After` when present on a 200). Absent when the server
53
+ * isn't backpressuring or the header parser failed.
54
+ */
55
+ softBackoffSeconds?: number;
56
+ }
57
+ /**
58
+ * Server-emitted permanent-failure codes.
59
+ *
60
+ * Three groups, all permanent (no amount of retry helps):
61
+ * - REFRESH_* — refresh-token specific (most common path).
62
+ * - TOKEN_* — access-token specific (server pushes 4402 close;
63
+ * daemon classifies as TOKEN_INVALID/TOKEN_EXPIRED).
64
+ * - SESSION_REVOKED — admin/forensic revoke; whole family burned.
65
+ * - UNKNOWN_401 — server returned 401 with a code we don't
66
+ * recognize. Treated as permanent (better to prompt
67
+ * re-auth than to loop forever) but tagged
68
+ * distinctly so monitoring can surface server-side
69
+ * bugs separately from real expirations.
70
+ *
71
+ * Production-hardening 2026-05-06 — widened from the original 4-value
72
+ * union to include `TOKEN_INVALID`, `TOKEN_EXPIRED`, and `UNKNOWN_401`
73
+ * to match the codes the daemon and client UX actually emit/render.
74
+ * Without this, the client `describeAuthFailure` exhaustiveness check
75
+ * was silently broken for the non-REFRESH branches.
76
+ */
77
+ export type PermanentAuthReason = 'REFRESH_INVALID' | 'REFRESH_REUSED' | 'REFRESH_EXPIRED' | 'SESSION_REVOKED' | 'TOKEN_INVALID' | 'TOKEN_EXPIRED' | 'UNKNOWN_401';
78
+ export declare class PermanentAuthFailure extends Error {
79
+ readonly code: PermanentAuthReason;
80
+ constructor(code: PermanentAuthReason, message: string);
81
+ }
82
+ export declare class TransientAuthFailure extends Error {
83
+ readonly cause?: unknown;
84
+ constructor(message: string, cause?: unknown);
85
+ }
86
+ export interface ReauthState {
87
+ code: string;
88
+ message?: string;
89
+ /** Epoch ms. */
90
+ at: number;
91
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Shared types & error classes used across refresh, refreshScheduler, and
3
+ * fdToken modules. Lives in its own file so consumers can `import type` from
4
+ * the package without dragging in side-effecting modules.
5
+ */
6
+ export class PermanentAuthFailure extends Error {
7
+ code;
8
+ constructor(code, message) {
9
+ super(message);
10
+ this.name = 'PermanentAuthFailure';
11
+ this.code = code;
12
+ }
13
+ }
14
+ export class TransientAuthFailure extends Error {
15
+ cause;
16
+ constructor(message, cause) {
17
+ super(message);
18
+ this.name = 'TransientAuthFailure';
19
+ this.cause = cause;
20
+ }
21
+ }
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "@skrr-ai/auth-core",
3
+ "version": "0.1.2",
4
+ "description": "Shared auth substrate (token store, refresh, scheduler, fd handoff) for the OverSky daemon and CLI.",
5
+ "type": "module",
6
+ "main": "dist/cjs/index.js",
7
+ "module": "dist/esm/index.js",
8
+ "types": "dist/esm/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/esm/index.d.ts",
13
+ "default": "./dist/esm/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/cjs/index.d.ts",
17
+ "default": "./dist/cjs/index.js"
18
+ }
19
+ },
20
+ "./refresh-classification": {
21
+ "import": {
22
+ "types": "./dist/esm/refreshClassification.d.ts",
23
+ "default": "./dist/esm/refreshClassification.js"
24
+ },
25
+ "require": {
26
+ "types": "./dist/cjs/refreshClassification.d.ts",
27
+ "default": "./dist/cjs/refreshClassification.js"
28
+ }
29
+ }
30
+ },
31
+ "files": [
32
+ "dist/**/*.js",
33
+ "dist/**/*.d.ts",
34
+ "dist/cjs/package.json",
35
+ "README.md",
36
+ "package.json"
37
+ ],
38
+ "scripts": {
39
+ "build": "npm run clean && npm run build:esm && npm run build:cjs && node scripts/finalize-cjs.cjs",
40
+ "build:esm": "tsc -p tsconfig.json",
41
+ "build:cjs": "tsc -p tsconfig.cjs.json",
42
+ "clean": "rimraf dist",
43
+ "test": "node --import tsx --test 'src/**/*.test.ts' 'src/**/*.spec.ts'",
44
+ "test:smoke": "node --import tsx --test 'src/**/*.real-smoke.test.ts'",
45
+ "prepack": "npm run build"
46
+ },
47
+ "dependencies": {
48
+ "proper-lockfile": "^4.1.2",
49
+ "tweetnacl": "^1.0.3"
50
+ },
51
+ "devDependencies": {
52
+ "@types/node": "^20.17.12",
53
+ "@types/proper-lockfile": "^4.1.4",
54
+ "rimraf": "^5.0.5",
55
+ "tsx": "^4.19.2",
56
+ "typescript": "^5.7.3"
57
+ },
58
+ "engines": {
59
+ "node": ">=22.0.0"
60
+ },
61
+ "publishConfig": {
62
+ "access": "public"
63
+ },
64
+ "license": "UNLICENSED",
65
+ "author": "OverSky",
66
+ "homepage": "https://oversky.ai",
67
+ "bugs": {
68
+ "url": "https://github.com/dush1023/OverSky/issues"
69
+ },
70
+ "repository": {
71
+ "type": "git",
72
+ "url": "https://github.com/dush1023/OverSky.git",
73
+ "directory": "packages/auth-core"
74
+ },
75
+ "keywords": [
76
+ "oversky",
77
+ "auth",
78
+ "cli",
79
+ "daemon",
80
+ "token-refresh"
81
+ ]
82
+ }