@allodium/auth 0.0.1 → 0.1.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.
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Session-cookie triple: access token, refresh token, and a readable expiry timestamp.
3
+ *
4
+ * Every setter AND deleter must use the same attributes: a cookie set with a Domain can
5
+ * only be cleared by a deletion carrying the same Domain, which is why deletion is
6
+ * set-empty-with-maxAge-0 rather than a delete() call.
7
+ *
8
+ * Framework-free: anything with a `set(name, value, options)` method works — both
9
+ * Next.js cookie stores (`await cookies()` and `NextResponse.cookies`) already do.
10
+ */
11
+ export interface SessionCookieNames {
12
+ access: string;
13
+ refresh: string;
14
+ expires: string;
15
+ }
16
+ export type SessionCookieBase = {
17
+ httpOnly: true;
18
+ secure: boolean;
19
+ sameSite: 'lax';
20
+ path: '/';
21
+ maxAge: number;
22
+ domain?: string;
23
+ };
24
+ export interface CookieSetter {
25
+ set(name: string, value: string, options: Record<string, unknown>): unknown;
26
+ }
27
+ export interface SessionCookies {
28
+ names: SessionCookieNames;
29
+ /** The shared attribute base — evaluated per call so env-driven config stays live. */
30
+ base(): SessionCookieBase;
31
+ /** Write the three session cookies (login, oauth callback, refresh). */
32
+ set(store: CookieSetter, tokens: {
33
+ accessToken: string;
34
+ refreshToken: string;
35
+ expiresAtMs: number;
36
+ }): void;
37
+ /** Clear the cookies with matching attributes (works with or without Domain). */
38
+ clear(store: CookieSetter): void;
39
+ }
40
+ /**
41
+ * `secure` and `domain` take thunks so deployments that read them from env keep
42
+ * call-time semantics (e.g. `() => process.env.NODE_ENV === 'production'`).
43
+ * `maxAgeSec` should equal the refresh-token TTL — one config value, not three copies.
44
+ */
45
+ export declare function createSessionCookies(opts: {
46
+ names: SessionCookieNames;
47
+ maxAgeSec: number;
48
+ secure: boolean | (() => boolean);
49
+ domain?: string | (() => string | undefined);
50
+ }): SessionCookies;
51
+ //# sourceMappingURL=cookies.d.ts.map
@@ -0,0 +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;CAC9C,GAAG,cAAc,CAgCjB"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Session-cookie triple: access token, refresh token, and a readable expiry timestamp.
3
+ *
4
+ * Every setter AND deleter must use the same attributes: a cookie set with a Domain can
5
+ * only be cleared by a deletion carrying the same Domain, which is why deletion is
6
+ * set-empty-with-maxAge-0 rather than a delete() call.
7
+ *
8
+ * Framework-free: anything with a `set(name, value, options)` method works — both
9
+ * Next.js cookie stores (`await cookies()` and `NextResponse.cookies`) already do.
10
+ */
11
+ /**
12
+ * `secure` and `domain` take thunks so deployments that read them from env keep
13
+ * call-time semantics (e.g. `() => process.env.NODE_ENV === 'production'`).
14
+ * `maxAgeSec` should equal the refresh-token TTL — one config value, not three copies.
15
+ */
16
+ export function createSessionCookies(opts) {
17
+ const secure = typeof opts.secure === 'function' ? opts.secure : () => opts.secure;
18
+ const domain = typeof opts.domain === 'function' ? opts.domain : () => opts.domain;
19
+ const base = () => {
20
+ const d = domain();
21
+ return {
22
+ httpOnly: true,
23
+ secure: secure(),
24
+ sameSite: 'lax',
25
+ path: '/',
26
+ maxAge: opts.maxAgeSec,
27
+ ...(d ? { domain: d } : {}),
28
+ };
29
+ };
30
+ return {
31
+ names: opts.names,
32
+ base,
33
+ set(store, tokens) {
34
+ const b = base();
35
+ store.set(opts.names.access, tokens.accessToken, b);
36
+ store.set(opts.names.refresh, tokens.refreshToken, b);
37
+ store.set(opts.names.expires, String(tokens.expiresAtMs), b);
38
+ },
39
+ clear(store) {
40
+ const b = { ...base(), maxAge: 0 };
41
+ for (const name of [opts.names.access, opts.names.refresh, opts.names.expires]) {
42
+ store.set(name, '', b);
43
+ }
44
+ },
45
+ };
46
+ }
47
+ //# sourceMappingURL=cookies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookies.js","sourceRoot":"","sources":["../src/cookies.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAiCH;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAKpC;I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EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;YACnC,KAAK,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC/E,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,32 +1,20 @@
1
1
  /**
2
2
  * @allodium/auth — first-party authentication you own outright.
3
3
  *
4
- * Being extracted from a production Next.js SaaS (custom WebAuthn passkeys, Google OIDC,
5
- * argon2 password sessions, rotating refresh tokens) as its Directus migration proceeds.
6
- * The design contract, so consumers can build against it today:
4
+ * Extracted from a production Next.js SaaS as its headless-CMS migration completed:
5
+ * argon2id passwords (Directus-hash compatible — zero password resets), a session store
6
+ * with single-use atomic refresh rotation and cross-surface origin scoping, stateless
7
+ * HMAC reset tokens that self-invalidate on password change, sliding-window rate
8
+ * limiting, and the session-cookie triple with Domain-correct clearing.
7
9
  *
8
- * - Passwords: argon2id via `node-argon2`. Directus-compatible: hashes produced by
9
- * Directus verify unchanged (parameters are read from the hash string), so migrations
10
- * require zero password resets.
11
- * - Sessions: server-side session rows (id, user_id, token hash, device label, expiry),
12
- * httpOnly cookies, multiple concurrent sessions per user.
13
- * - Refresh: short-lived access + rotating single-use refresh, with single-flight
14
- * middleware guidance for the rotation race (or sliding sessions — your choice).
15
- * - OIDC: provider-agnostic authorization-code flow (Google first), same-domain
16
- * callbacks, one-identity-per-provider policy hooks.
17
- * - Passkeys: @simplewebauthn-based ceremonies; credentials in your Postgres.
18
- * - Reset: single-use hashed tokens + your SMTP; anti-enumeration (always-200) contract.
19
- * - Tenancy: membership/role helpers for the org-per-row multi-tenant pattern.
10
+ * Everything is a factory taking explicit config — no env vars are read in here, no
11
+ * framework imports. Your app binds names, secrets, and tables once and re-exports;
12
+ * OIDC and WebAuthn ceremony helpers arrive in a later minor.
20
13
  */
21
- export declare const AUTH_PACKAGE_STATUS: "scaffolding";
22
- /** The session shape consumers can rely on across versions. */
23
- export interface AllodiumSession {
24
- id: string;
25
- userId: string;
26
- createdAt: Date;
27
- expiresAt: Date;
28
- deviceLabel?: string | null;
29
- }
30
- /** Placeholder to keep the package importable while extraction proceeds. */
31
- export declare function version(): string;
14
+ export { hashPassword, verifyPassword, DUMMY_ARGON2ID_HASH } from './passwords.js';
15
+ export { createRateLimiter, type RateLimiter } from './rateLimit.js';
16
+ export { signPayload, verifySignedPayload, createResetTokens, makeStateToken, readStateToken, type ResetTokenPayload, type ResetTokens, } from './signedTokens.js';
17
+ export { createSessionCookies, type SessionCookieNames, type SessionCookieBase, type CookieSetter, type SessionCookies, } from './cookies.js';
18
+ export { createSessionStore, type SessionStore, type MintedSession, type OriginScope, } from './sessions.js';
19
+ export { firstForwardedIp } from './ip.js';
32
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,eAAO,MAAM,mBAAmB,EAAG,aAAsB,CAAC;AAE1D,+DAA+D;AAC/D,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,4EAA4E;AAC5E,wBAAgB,OAAO,IAAI,MAAM,CAEhC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,KAAK,iBAAiB,EACtB,KAAK,WAAW,GACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,oBAAoB,EACpB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,cAAc,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,kBAAkB,EAClB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,WAAW,GACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1,26 +1,20 @@
1
1
  /**
2
2
  * @allodium/auth — first-party authentication you own outright.
3
3
  *
4
- * Being extracted from a production Next.js SaaS (custom WebAuthn passkeys, Google OIDC,
5
- * argon2 password sessions, rotating refresh tokens) as its Directus migration proceeds.
6
- * The design contract, so consumers can build against it today:
4
+ * Extracted from a production Next.js SaaS as its headless-CMS migration completed:
5
+ * argon2id passwords (Directus-hash compatible — zero password resets), a session store
6
+ * with single-use atomic refresh rotation and cross-surface origin scoping, stateless
7
+ * HMAC reset tokens that self-invalidate on password change, sliding-window rate
8
+ * limiting, and the session-cookie triple with Domain-correct clearing.
7
9
  *
8
- * - Passwords: argon2id via `node-argon2`. Directus-compatible: hashes produced by
9
- * Directus verify unchanged (parameters are read from the hash string), so migrations
10
- * require zero password resets.
11
- * - Sessions: server-side session rows (id, user_id, token hash, device label, expiry),
12
- * httpOnly cookies, multiple concurrent sessions per user.
13
- * - Refresh: short-lived access + rotating single-use refresh, with single-flight
14
- * middleware guidance for the rotation race (or sliding sessions — your choice).
15
- * - OIDC: provider-agnostic authorization-code flow (Google first), same-domain
16
- * callbacks, one-identity-per-provider policy hooks.
17
- * - Passkeys: @simplewebauthn-based ceremonies; credentials in your Postgres.
18
- * - Reset: single-use hashed tokens + your SMTP; anti-enumeration (always-200) contract.
19
- * - Tenancy: membership/role helpers for the org-per-row multi-tenant pattern.
10
+ * Everything is a factory taking explicit config — no env vars are read in here, no
11
+ * framework imports. Your app binds names, secrets, and tables once and re-exports;
12
+ * OIDC and WebAuthn ceremony helpers arrive in a later minor.
20
13
  */
21
- export const AUTH_PACKAGE_STATUS = 'scaffolding';
22
- /** Placeholder to keep the package importable while extraction proceeds. */
23
- export function version() {
24
- return '0.0.1';
25
- }
14
+ export { hashPassword, verifyPassword, DUMMY_ARGON2ID_HASH } from './passwords.js';
15
+ export { createRateLimiter } from './rateLimit.js';
16
+ export { signPayload, verifySignedPayload, createResetTokens, makeStateToken, readStateToken, } from './signedTokens.js';
17
+ export { createSessionCookies, } from './cookies.js';
18
+ export { createSessionStore, } from './sessions.js';
19
+ export { firstForwardedIp } from './ip.js';
26
20
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG,aAAsB,CAAC;AAW1D,4EAA4E;AAC5E,MAAM,UAAU,OAAO;IACrB,OAAO,OAAO,CAAC;AACjB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAoB,MAAM,gBAAgB,CAAC;AACrE,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,cAAc,EACd,cAAc,GAGf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,oBAAoB,GAKrB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,kBAAkB,GAInB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC"}
package/dist/ip.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * First-hop client IP from an `x-forwarded-for` header value (the leftmost entry is the
3
+ * original client when your proxy chain appends). Null when the header is absent/empty —
4
+ * callers pick their own fallback ('unknown', null, …).
5
+ */
6
+ export declare function firstForwardedIp(headerValue: string | null | undefined): string | null;
7
+ //# sourceMappingURL=ip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ip.d.ts","sourceRoot":"","sources":["../src/ip.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAGtF"}
package/dist/ip.js ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * First-hop client IP from an `x-forwarded-for` header value (the leftmost entry is the
3
+ * original client when your proxy chain appends). Null when the header is absent/empty —
4
+ * callers pick their own fallback ('unknown', null, …).
5
+ */
6
+ export function firstForwardedIp(headerValue) {
7
+ const first = headerValue?.split(',')[0]?.trim();
8
+ return first || null;
9
+ }
10
+ //# sourceMappingURL=ip.js.map
package/dist/ip.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ip.js","sourceRoot":"","sources":["../src/ip.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,WAAsC;IACrE,MAAM,KAAK,GAAG,WAAW,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;IACjD,OAAO,KAAK,IAAI,IAAI,CAAC;AACvB,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Password hashing: argon2id via node-argon2's defaults (m=65536, t=3, p=4).
3
+ *
4
+ * These parameters are deliberately the same ones Directus uses, in both directions:
5
+ * hashes produced by a Directus deployment verify here unchanged (parameters are read
6
+ * from the hash string), and hashes created here verify in Directus during a parallel
7
+ * run — so a migration needs zero password resets. Audited in production during the
8
+ * reference deployment's cutover: 21/21 users verified.
9
+ */
10
+ export declare function hashPassword(password: string): Promise<string>;
11
+ /** False on mismatch, malformed hash, or null hash — never throws on the login path. */
12
+ export declare function verifyPassword(hash: string | null | undefined, password: string): Promise<boolean>;
13
+ /**
14
+ * A real argon2id hash of a random throwaway string, for timing equalization: when the
15
+ * looked-up user doesn't exist (or is ineligible), verify the submitted password against
16
+ * this instead of skipping the verify, so response timing can't distinguish "no such
17
+ * account" from "wrong password".
18
+ */
19
+ export declare const DUMMY_ARGON2ID_HASH = "$argon2id$v=19$m=65536,p=4,t=3$r5/l4lj1fHcz+2n6zW5Hqw$Mbkf6TySpCkDsNHd4UqC6jloSlRnLBgnJT82XC/ChHA";
20
+ //# sourceMappingURL=passwords.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"passwords.d.ts","sourceRoot":"","sources":["../src/passwords.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH,wBAAsB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAEpE;AAED,wFAAwF;AACxF,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAOxG;AAED;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,sGACqE,CAAC"}
@@ -0,0 +1,32 @@
1
+ import argon2 from 'argon2';
2
+ /**
3
+ * Password hashing: argon2id via node-argon2's defaults (m=65536, t=3, p=4).
4
+ *
5
+ * These parameters are deliberately the same ones Directus uses, in both directions:
6
+ * hashes produced by a Directus deployment verify here unchanged (parameters are read
7
+ * from the hash string), and hashes created here verify in Directus during a parallel
8
+ * run — so a migration needs zero password resets. Audited in production during the
9
+ * reference deployment's cutover: 21/21 users verified.
10
+ */
11
+ export async function hashPassword(password) {
12
+ return argon2.hash(password);
13
+ }
14
+ /** False on mismatch, malformed hash, or null hash — never throws on the login path. */
15
+ export async function verifyPassword(hash, password) {
16
+ if (!hash || !hash.startsWith('$argon2'))
17
+ return false;
18
+ try {
19
+ return await argon2.verify(hash, password);
20
+ }
21
+ catch {
22
+ return false;
23
+ }
24
+ }
25
+ /**
26
+ * A real argon2id hash of a random throwaway string, for timing equalization: when the
27
+ * looked-up user doesn't exist (or is ineligible), verify the submitted password against
28
+ * this instead of skipping the verify, so response timing can't distinguish "no such
29
+ * account" from "wrong password".
30
+ */
31
+ export const DUMMY_ARGON2ID_HASH = '$argon2id$v=19$m=65536,p=4,t=3$r5/l4lj1fHcz+2n6zW5Hqw$Mbkf6TySpCkDsNHd4UqC6jloSlRnLBgnJT82XC/ChHA';
32
+ //# sourceMappingURL=passwords.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"passwords.js","sourceRoot":"","sources":["../src/passwords.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B;;;;;;;;GAQG;AAEH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,QAAgB;IACjD,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC/B,CAAC;AAED,wFAAwF;AACxF,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,IAA+B,EAAE,QAAgB;IACpF,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;QAAE,OAAO,KAAK,CAAC;IACvD,IAAI,CAAC;QACH,OAAO,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAC9B,mGAAmG,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * In-memory sliding-window rate limiter for auth endpoints.
3
+ *
4
+ * SINGLE-PROCESS ASSUMPTION: a process-local Map only sees this process's requests.
5
+ * Counters reset on restart or deploy (fail-open) and are NOT shared across instances —
6
+ * correct for the one-Next-process-per-box deployment shape; if you scale past one
7
+ * instance, put a shared store (Postgres/Redis) behind the same signature.
8
+ *
9
+ * Callers pick their own key namespace (e.g. 'login:ip:1.2.3.4', 'pwreq:email:a@b.c')
10
+ * and limits; the limiter itself is policy-free.
11
+ */
12
+ export type RateLimiter = (key: string, max: number, windowMs: number) => boolean;
13
+ /**
14
+ * Create a limiter. The returned function is a sliding-window check: it returns true
15
+ * and RECORDS the hit when `key` has had fewer than `max` recorded hits in the trailing
16
+ * `windowMs`; it returns false (nothing recorded) when the key is over the limit — so a
17
+ * hammering client still gets at most `max` accepted attempts per window, and backing
18
+ * off actually helps.
19
+ */
20
+ export declare function createRateLimiter(opts?: {
21
+ sweepIntervalMs?: number;
22
+ }): RateLimiter;
23
+ //# sourceMappingURL=rateLimit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rateLimit.d.ts","sourceRoot":"","sources":["../src/rateLimit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AASH,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;AAElF;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,GAAE;IAAE,eAAe,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,WAAW,CA+BtF"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * In-memory sliding-window rate limiter for auth endpoints.
3
+ *
4
+ * SINGLE-PROCESS ASSUMPTION: a process-local Map only sees this process's requests.
5
+ * Counters reset on restart or deploy (fail-open) and are NOT shared across instances —
6
+ * correct for the one-Next-process-per-box deployment shape; if you scale past one
7
+ * instance, put a shared store (Postgres/Redis) behind the same signature.
8
+ *
9
+ * Callers pick their own key namespace (e.g. 'login:ip:1.2.3.4', 'pwreq:email:a@b.c')
10
+ * and limits; the limiter itself is policy-free.
11
+ */
12
+ /**
13
+ * Create a limiter. The returned function is a sliding-window check: it returns true
14
+ * and RECORDS the hit when `key` has had fewer than `max` recorded hits in the trailing
15
+ * `windowMs`; it returns false (nothing recorded) when the key is over the limit — so a
16
+ * hammering client still gets at most `max` accepted attempts per window, and backing
17
+ * off actually helps.
18
+ */
19
+ export function createRateLimiter(opts = {}) {
20
+ const sweepIntervalMs = opts.sweepIntervalMs ?? 5 * 60_000;
21
+ const buckets = new Map();
22
+ let lastSweep = Date.now();
23
+ /** Opportunistic prune: drop buckets whose newest hit fell out of their own window. */
24
+ function sweep(now) {
25
+ if (now - lastSweep < sweepIntervalMs)
26
+ return;
27
+ lastSweep = now;
28
+ for (const [key, bucket] of buckets) {
29
+ const newest = bucket.times[bucket.times.length - 1];
30
+ if (newest === undefined || newest <= now - bucket.windowMs)
31
+ buckets.delete(key);
32
+ }
33
+ }
34
+ return function limit(key, max, windowMs) {
35
+ const now = Date.now();
36
+ sweep(now);
37
+ const cutoff = now - windowMs;
38
+ const times = (buckets.get(key)?.times ?? []).filter((t) => t > cutoff);
39
+ if (times.length >= max) {
40
+ buckets.set(key, { windowMs, times });
41
+ return false;
42
+ }
43
+ times.push(now);
44
+ buckets.set(key, { windowMs, times });
45
+ return true;
46
+ };
47
+ }
48
+ //# sourceMappingURL=rateLimit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rateLimit.js","sourceRoot":"","sources":["../src/rateLimit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAWH;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAqC,EAAE;IACvE,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,IAAI,CAAC,GAAG,MAAM,CAAC;IAC3D,MAAM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C;QACtC,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,92 @@
1
+ import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
2
+ import type { PgTable } from 'drizzle-orm/pg-core';
3
+ /**
4
+ * First-party session store: short-lived access token + single-use rotating refresh
5
+ * token, both opaque (prefix + 32 random bytes base64url). Tokens live only in httpOnly
6
+ * cookies; the database stores sha256 hex digests. The prefixes are how middleware and
7
+ * read paths recognize these tokens without any flag column — pick ones unique to your
8
+ * app (they also namespace tokens during a migration's parallel-run).
9
+ *
10
+ * Required `sessions` table shape (drizzle property names, string-mode timestamptz):
11
+ * id, userId, accessHash (char 64), refreshHash (char 64), accessExpiresAt,
12
+ * refreshExpiresAt, lastUsedAt, ip (varchar 64), userAgent (varchar 255),
13
+ * origin (varchar) — with UNIQUE indexes on both hash columns.
14
+ * Required `users` table shape: an `id` property the sessions.userId FK points at.
15
+ */
16
+ export interface MintedSession {
17
+ accessToken: string;
18
+ refreshToken: string;
19
+ /** Access-token TTL in ms — the `expires` value auth endpoints put on the wire. */
20
+ expires: number;
21
+ }
22
+ /** Origin scoping for resolveUser — see the note on cross-surface token isolation. */
23
+ export type OriginScope = {
24
+ equals: string;
25
+ } | {
26
+ not: string;
27
+ };
28
+ export interface SessionStore {
29
+ accessTtlMs: number;
30
+ refreshTtlMs: number;
31
+ /**
32
+ * Plain booleans on purpose (not type predicates): a predicate would narrow
33
+ * `string | undefined` to `never` in callers' else-branches (legacy token paths).
34
+ */
35
+ isAccessToken(t: unknown): boolean;
36
+ isRefreshToken(t: unknown): boolean;
37
+ /**
38
+ * Create a session for a user. Caller has already authenticated them. ttlMs overrides
39
+ * the access TTL for fixed-length sessions with no refresh cycle (admin surfaces);
40
+ * the returned `expires` is always the store's standard TTL, matching what refresh
41
+ * endpoints advertise.
42
+ */
43
+ mint(args: {
44
+ userId: string;
45
+ origin: string;
46
+ ip?: string | null;
47
+ userAgent?: string | null;
48
+ ttlMs?: number;
49
+ }): Promise<MintedSession>;
50
+ /**
51
+ * Single-use refresh rotation. Atomic: the UPDATE's WHERE consumes the old refresh
52
+ * hash, so of two concurrent refreshes with the same token exactly one wins (the loser
53
+ * gets null → 401 → single-flight middleware forgiveness keeps the winner's cookies).
54
+ * Sliding window: each rotation extends the refresh expiry by refreshTtlMs.
55
+ */
56
+ rotate(refreshToken: string): Promise<MintedSession | null>;
57
+ /**
58
+ * Resolve an access token to its raw user row (drizzle camelCase properties — map to
59
+ * your wire shape and strip credential columns in YOUR binding). Null on unknown or
60
+ * expired token, or when isUserActive rejects the row.
61
+ *
62
+ * Origin scoping is real security logic when two surfaces share the store (an app and
63
+ * an admin console): scope each surface so a cookie value manually moved across
64
+ * origins resolves to nothing.
65
+ */
66
+ resolveUser(accessToken: string, opts?: {
67
+ origin?: OriginScope;
68
+ }): Promise<Record<string, unknown> | null>;
69
+ /** Logout: revoke by whichever token the cookie jar still has. Best-effort, never throws. */
70
+ revoke(tokens: {
71
+ accessToken?: string;
72
+ refreshToken?: string;
73
+ }): Promise<void>;
74
+ /** Revoke all of a user's sessions (password reset), optionally sparing one access token. */
75
+ revokeAllForUser(userId: string, opts?: {
76
+ exceptAccessToken?: string;
77
+ }): Promise<void>;
78
+ }
79
+ export declare function createSessionStore(opts: {
80
+ db: NodePgDatabase<any>;
81
+ sessions: PgTable;
82
+ users: PgTable;
83
+ accessPrefix: string;
84
+ refreshPrefix: string;
85
+ accessTtlMs?: number;
86
+ refreshTtlMs?: number;
87
+ /** Gate on the joined user row (e.g. status === 'active'). Default: allow all. */
88
+ isUserActive?: (row: Record<string, unknown>) => boolean;
89
+ /** Rotation lazily deletes sessions dead longer than this. Default 24 h. */
90
+ sweepGraceMs?: number;
91
+ }): SessionStore;
92
+ //# sourceMappingURL=sessions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sessions.d.ts","sourceRoot":"","sources":["../src/sessions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,E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AAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/E,6FAA6F;IAC7F,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,iBAAiB,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxF;AAOD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE;IAEvC,EAAE,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC;IACxB,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kFAAkF;IAClF,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC;IACzD,4EAA4E;IAC5E,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,YAAY,CAuHf"}
@@ -0,0 +1,109 @@
1
+ import { createHash, randomBytes } from 'node:crypto';
2
+ import { and, eq, getTableColumns, gt, lt, ne } from 'drizzle-orm';
3
+ const sha256 = (t) => createHash('sha256').update(t).digest('hex');
4
+ /* The drizzle call sites cast through `any`: typing a caller-supplied table pair
5
+ * generically against drizzle's builder generics costs far more than it buys at this
6
+ * layer, and the column-property contract is documented above. */
7
+ export function createSessionStore(opts) {
8
+ const { db, accessPrefix, refreshPrefix, accessTtlMs = 15 * 60_000, refreshTtlMs = 7 * 24 * 3_600_000, isUserActive = () => true, sweepGraceMs = 24 * 3_600_000, } = opts;
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ const sessions = opts.sessions;
11
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
+ const users = opts.users;
13
+ const isAccessToken = (t) => typeof t === 'string' && t.startsWith(accessPrefix);
14
+ const isRefreshToken = (t) => typeof t === 'string' && t.startsWith(refreshPrefix);
15
+ const newToken = (prefix) => prefix + randomBytes(32).toString('base64url');
16
+ return {
17
+ accessTtlMs,
18
+ refreshTtlMs,
19
+ isAccessToken,
20
+ isRefreshToken,
21
+ async mint(args) {
22
+ const accessToken = newToken(accessPrefix);
23
+ const refreshToken = newToken(refreshPrefix);
24
+ const now = Date.now();
25
+ await db.insert(sessions).values({
26
+ userId: args.userId,
27
+ accessHash: sha256(accessToken),
28
+ refreshHash: sha256(refreshToken),
29
+ accessExpiresAt: new Date(now + (args.ttlMs ?? accessTtlMs)).toISOString(),
30
+ refreshExpiresAt: new Date(now + refreshTtlMs).toISOString(),
31
+ ip: args.ip ? args.ip.slice(0, 64) : null,
32
+ userAgent: args.userAgent ? args.userAgent.slice(0, 255) : null,
33
+ origin: args.origin,
34
+ });
35
+ return { accessToken, refreshToken, expires: accessTtlMs };
36
+ },
37
+ async rotate(refreshToken) {
38
+ if (!isRefreshToken(refreshToken))
39
+ return null;
40
+ const accessToken = newToken(accessPrefix);
41
+ const nextRefreshToken = newToken(refreshPrefix);
42
+ const now = Date.now();
43
+ const nowIso = new Date(now).toISOString();
44
+ const rotated = await db
45
+ .update(sessions)
46
+ .set({
47
+ accessHash: sha256(accessToken),
48
+ refreshHash: sha256(nextRefreshToken),
49
+ accessExpiresAt: new Date(now + accessTtlMs).toISOString(),
50
+ refreshExpiresAt: new Date(now + refreshTtlMs).toISOString(),
51
+ lastUsedAt: nowIso,
52
+ })
53
+ .where(and(eq(sessions.refreshHash, sha256(refreshToken)), gt(sessions.refreshExpiresAt, nowIso)))
54
+ .returning({ id: sessions.id });
55
+ if (!rotated.length)
56
+ return null;
57
+ // Lazy sweep: drop long-dead sessions on the way through.
58
+ try {
59
+ await db.delete(sessions).where(lt(sessions.refreshExpiresAt, new Date(now - sweepGraceMs).toISOString()));
60
+ }
61
+ catch {
62
+ /* housekeeping only */
63
+ }
64
+ return { accessToken, refreshToken: nextRefreshToken, expires: accessTtlMs };
65
+ },
66
+ async resolveUser(accessToken, callOpts = {}) {
67
+ if (!isAccessToken(accessToken))
68
+ return null;
69
+ const scope = callOpts.origin;
70
+ const originCond = scope === undefined
71
+ ? undefined
72
+ : 'equals' in scope
73
+ ? eq(sessions.origin, scope.equals)
74
+ : ne(sessions.origin, scope.not);
75
+ const rows = await db
76
+ .select({ u: getTableColumns(users) })
77
+ .from(sessions)
78
+ .innerJoin(users, eq(sessions.userId, users.id))
79
+ .where(and(eq(sessions.accessHash, sha256(accessToken)), gt(sessions.accessExpiresAt, new Date().toISOString()), ...(originCond ? [originCond] : [])))
80
+ .limit(1);
81
+ const u = rows[0]?.u;
82
+ if (!u || !isUserActive(u))
83
+ return null;
84
+ return u;
85
+ },
86
+ async revoke(tokens) {
87
+ try {
88
+ if (tokens.accessToken && isAccessToken(tokens.accessToken)) {
89
+ await db.delete(sessions).where(eq(sessions.accessHash, sha256(tokens.accessToken)));
90
+ }
91
+ else if (tokens.refreshToken && isRefreshToken(tokens.refreshToken)) {
92
+ await db.delete(sessions).where(eq(sessions.refreshHash, sha256(tokens.refreshToken)));
93
+ }
94
+ }
95
+ catch (e) {
96
+ console.error('session revoke failed:', e);
97
+ }
98
+ },
99
+ async revokeAllForUser(userId, callOpts = {}) {
100
+ const except = callOpts.exceptAccessToken && isAccessToken(callOpts.exceptAccessToken)
101
+ ? sha256(callOpts.exceptAccessToken)
102
+ : null;
103
+ await db
104
+ .delete(sessions)
105
+ .where(except ? and(eq(sessions.userId, userId), ne(sessions.accessHash, except)) : eq(sessions.userId, userId));
106
+ },
107
+ };
108
+ }
109
+ //# sourceMappingURL=sessions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sessions.js","sourceRoot":"","sources":["../src/sessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,GAAG,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,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;gBACvF,CAAC;qBAAM,IAAI,MAAM,CAAC,YAAY,IAAI,cAAc,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;oBACtE,MAAM,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;gBACzF,CAAC;YACH,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,CAAC,CAAC,CAAC;YAC7C,CAAC;QACH,CAAC;QAED,KAAK,CAAC,gBAAgB,CAAC,MAAM,EAAE,QAAQ,GAAG,EAAE;YAC1C,MAAM,MAAM,GACV,QAAQ,CAAC,iBAAiB,IAAI,aAAa,CAAC,QAAQ,CAAC,iBAAiB,CAAC;gBACrE,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC;gBACpC,CAAC,CAAC,IAAI,CAAC;YACX,MAAM,EAAE;iBACL,MAAM,CAAC,QAAQ,CAAC;iBAChB,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;QACrH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,45 @@
1
+ /** `${b64url(JSON payload)}.${hmac}` — the signing primitive behind every token here. */
2
+ export declare function signPayload(key: string, payload: unknown): string;
3
+ /**
4
+ * Verify a signed token's HMAC (timing-safe) and return its decoded payload, or null.
5
+ * Expiry is the caller's concern — payload shapes differ.
6
+ */
7
+ export declare function verifySignedPayload(key: string, token: string): unknown | null;
8
+ export interface ResetTokenPayload {
9
+ /** User id the token was issued for. */
10
+ u: string;
11
+ /** Expiry, ms since epoch. */
12
+ exp: number;
13
+ }
14
+ export interface ResetTokens {
15
+ /** Issue a token for a user. Throws when the secret is unset (callers guard). */
16
+ make(user: {
17
+ id: string;
18
+ password: string | null;
19
+ }): string;
20
+ /**
21
+ * Structure-only decode (NO verification) so the reset route can learn which user to
22
+ * load before verifying. Never trust the result without verify().
23
+ */
24
+ decode(token: string): ResetTokenPayload | null;
25
+ /**
26
+ * Verify against the user's CURRENT password hash: HMAC (timing-safe) + expiry.
27
+ * False on any mismatch, expiry, malformed token, or missing secret.
28
+ */
29
+ verify(token: string, user: {
30
+ password: string | null;
31
+ }): boolean;
32
+ }
33
+ /**
34
+ * Reset-token factory. `secret` is read per call (pass `() => process.env.AUTH_SECRET`)
35
+ * so an unset secret degrades per-request rather than at module load.
36
+ */
37
+ export declare function createResetTokens(opts: {
38
+ secret: () => string | undefined;
39
+ ttlMs?: number;
40
+ }): ResetTokens;
41
+ /** Sign an opaque state string with an expiry — store it in an httpOnly cookie. */
42
+ export declare function makeStateToken(secret: string, state: string, ttlMs: number): string;
43
+ /** Verify + unwrap a state token: the stored state, or null on any failure/expiry. */
44
+ export declare function readStateToken(secret: string, token: string): string | null;
45
+ //# sourceMappingURL=signedTokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signedTokens.d.ts","sourceRoot":"","sources":["../src/signedTokens.ts"],"names":[],"mappings":"AAkBA,yFAAyF;AACzF,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAGjE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI,CAgB9E;AAMD,MAAM,WAAW,iBAAiB;IAChC,wCAAwC;IACxC,CAAC,EAAE,MAAM,CAAC;IACV,8BAA8B;IAC9B,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,WAAW;IAC1B,iFAAiF;IACjF,IAAI,CAAC,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,MAAM,CAAC;IAC5D;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI,CAAC;IAChD;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,OAAO,CAAC;CACnE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE;IACtC,MAAM,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,GAAG,WAAW,CA0Cd;AAMD,mFAAmF;AACnF,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnF;AAED,sFAAsF;AACtF,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAK3E"}
@@ -0,0 +1,111 @@
1
+ import { createHmac, timingSafeEqual } from 'node:crypto';
2
+ /**
3
+ * Stateless HMAC-signed auth artifacts: `${payloadB64url}.${hmacB64url}`, verified with
4
+ * timingSafeEqual — no server-side token store. Payloads are unencrypted b64url JSON:
5
+ * they carry only ids and expiries, nothing secret; the HMAC is what makes them
6
+ * unforgeable.
7
+ *
8
+ * The password-reset variant additionally mixes the user's CURRENT password hash into
9
+ * the HMAC key (`secret + ':' + passwordHash`). A successful reset changes the hash, so
10
+ * every outstanding token for that user stops verifying — single-use without any
11
+ * bookkeeping. This trick is the reason to use these over random-token-in-a-table.
12
+ */
13
+ function hmacB64url(key, data) {
14
+ return createHmac('sha256', key).update(data).digest('base64url');
15
+ }
16
+ /** `${b64url(JSON payload)}.${hmac}` — the signing primitive behind every token here. */
17
+ export function signPayload(key, payload) {
18
+ const payloadB64url = Buffer.from(JSON.stringify(payload), 'utf8').toString('base64url');
19
+ return `${payloadB64url}.${hmacB64url(key, payloadB64url)}`;
20
+ }
21
+ /**
22
+ * Verify a signed token's HMAC (timing-safe) and return its decoded payload, or null.
23
+ * Expiry is the caller's concern — payload shapes differ.
24
+ */
25
+ export function verifySignedPayload(key, token) {
26
+ const dot = token.indexOf('.');
27
+ if (dot <= 0)
28
+ return null;
29
+ const payloadB64url = token.slice(0, dot);
30
+ const mac = token.slice(dot + 1);
31
+ const macBuf = Buffer.from(mac);
32
+ const expectedBuf = Buffer.from(hmacB64url(key, payloadB64url));
33
+ if (macBuf.length !== expectedBuf.length || !timingSafeEqual(macBuf, expectedBuf)) {
34
+ return null;
35
+ }
36
+ try {
37
+ return JSON.parse(Buffer.from(payloadB64url, 'base64url').toString('utf8'));
38
+ }
39
+ catch {
40
+ return null;
41
+ }
42
+ }
43
+ /**
44
+ * Reset-token factory. `secret` is read per call (pass `() => process.env.AUTH_SECRET`)
45
+ * so an unset secret degrades per-request rather than at module load.
46
+ */
47
+ export function createResetTokens(opts) {
48
+ const ttlMs = opts.ttlMs ?? 3_600_000; // 1 hour
49
+ const resetKey = (passwordHash) => {
50
+ const secret = opts.secret();
51
+ if (!secret)
52
+ throw new Error('auth secret is not set — password-reset tokens are not configured');
53
+ return `${secret}:${passwordHash ?? ''}`;
54
+ };
55
+ const decode = (token) => {
56
+ const dot = token.indexOf('.');
57
+ if (dot <= 0)
58
+ return null;
59
+ let payload;
60
+ try {
61
+ payload = JSON.parse(Buffer.from(token.slice(0, dot), 'base64url').toString('utf8'));
62
+ }
63
+ catch {
64
+ return null;
65
+ }
66
+ if (typeof payload?.u !== 'string' || !payload.u)
67
+ return null;
68
+ if (typeof payload.exp !== 'number')
69
+ return null;
70
+ return { u: payload.u, exp: payload.exp };
71
+ };
72
+ return {
73
+ make(user) {
74
+ const payload = { u: user.id, exp: Date.now() + ttlMs };
75
+ return signPayload(resetKey(user.password), payload);
76
+ },
77
+ decode,
78
+ verify(token, user) {
79
+ if (!opts.secret())
80
+ return false;
81
+ let key;
82
+ try {
83
+ key = resetKey(user.password);
84
+ }
85
+ catch {
86
+ return false;
87
+ }
88
+ if (verifySignedPayload(key, token) === null)
89
+ return false;
90
+ const payload = decode(token);
91
+ return payload !== null && Date.now() < payload.exp;
92
+ },
93
+ };
94
+ }
95
+ // ---------------------------------------------------------------------------
96
+ // One-shot state tokens (OAuth `state` CSRF binding, and similar)
97
+ // ---------------------------------------------------------------------------
98
+ /** Sign an opaque state string with an expiry — store it in an httpOnly cookie. */
99
+ export function makeStateToken(secret, state, ttlMs) {
100
+ return signPayload(secret, { s: state, exp: Date.now() + ttlMs });
101
+ }
102
+ /** Verify + unwrap a state token: the stored state, or null on any failure/expiry. */
103
+ export function readStateToken(secret, token) {
104
+ const payload = verifySignedPayload(secret, token);
105
+ if (!payload || typeof payload.s !== 'string' || !payload.s)
106
+ return null;
107
+ if (typeof payload.exp !== 'number' || Date.now() > payload.exp)
108
+ return null;
109
+ return payload.s;
110
+ }
111
+ //# sourceMappingURL=signedTokens.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signedTokens.js","sourceRoot":"","sources":["../src/signedTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE1D;;;;;;;;;;GAUG;AAEH,SAAS,UAAU,CAAC,GAAW,EAAE,IAAY;IAC3C,OAAO,UAAU,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AACpE,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,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AC,GAAG;QAAE,OAAO,IAAI,CAAC;IAC7E,OAAO,OAAO,CAAC,CAAC,CAAC;AACnB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allodium/auth",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "description": "First-party auth you own: argon2 passwords, session store, rotating refresh, OIDC, WebAuthn passkeys, reset emails, tenant membership.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -12,10 +12,23 @@
12
12
  "import": "./dist/index.js"
13
13
  }
14
14
  },
15
- "files": ["dist"],
15
+ "files": [
16
+ "dist"
17
+ ],
16
18
  "scripts": {
17
19
  "build": "tsc -p tsconfig.json",
18
20
  "typecheck": "tsc -p tsconfig.json --noEmit"
19
21
  },
20
- "engines": { "node": ">=20" }
22
+ "engines": {
23
+ "node": ">=20"
24
+ },
25
+ "peerDependencies": {
26
+ "argon2": ">=0.31.0",
27
+ "drizzle-orm": ">=0.38.0"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "^22.0.0",
31
+ "argon2": "^0.44.0",
32
+ "drizzle-orm": "^0.45.0"
33
+ }
21
34
  }