@astram/core 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.
- package/LICENSE +21 -0
- package/README.md +47 -0
- package/dist/admin/admin-service.d.ts +221 -0
- package/dist/admin/admin-service.d.ts.map +1 -0
- package/dist/admin/admin-service.js +155 -0
- package/dist/admin/admin-service.js.map +1 -0
- package/dist/admin/command/grants.d.ts +40 -0
- package/dist/admin/command/grants.d.ts.map +1 -0
- package/dist/admin/command/grants.js +196 -0
- package/dist/admin/command/grants.js.map +1 -0
- package/dist/admin/command/index.d.ts +23 -0
- package/dist/admin/command/index.d.ts.map +1 -0
- package/dist/admin/command/index.js +23 -0
- package/dist/admin/command/index.js.map +1 -0
- package/dist/admin/command/invitations.d.ts +72 -0
- package/dist/admin/command/invitations.d.ts.map +1 -0
- package/dist/admin/command/invitations.js +241 -0
- package/dist/admin/command/invitations.js.map +1 -0
- package/dist/admin/command/permissions.d.ts +33 -0
- package/dist/admin/command/permissions.d.ts.map +1 -0
- package/dist/admin/command/permissions.js +67 -0
- package/dist/admin/command/permissions.js.map +1 -0
- package/dist/admin/command/pipeline.d.ts +79 -0
- package/dist/admin/command/pipeline.d.ts.map +1 -0
- package/dist/admin/command/pipeline.js +106 -0
- package/dist/admin/command/pipeline.js.map +1 -0
- package/dist/admin/command/policies.d.ts +50 -0
- package/dist/admin/command/policies.d.ts.map +1 -0
- package/dist/admin/command/policies.js +219 -0
- package/dist/admin/command/policies.js.map +1 -0
- package/dist/admin/command/service-accounts.d.ts +58 -0
- package/dist/admin/command/service-accounts.d.ts.map +1 -0
- package/dist/admin/command/service-accounts.js +272 -0
- package/dist/admin/command/service-accounts.js.map +1 -0
- package/dist/admin/command/service.d.ts +65 -0
- package/dist/admin/command/service.d.ts.map +1 -0
- package/dist/admin/command/service.js +128 -0
- package/dist/admin/command/service.js.map +1 -0
- package/dist/admin/command/tiers.d.ts +40 -0
- package/dist/admin/command/tiers.d.ts.map +1 -0
- package/dist/admin/command/tiers.js +79 -0
- package/dist/admin/command/tiers.js.map +1 -0
- package/dist/admin/index.d.ts +36 -0
- package/dist/admin/index.d.ts.map +1 -0
- package/dist/admin/index.js +63 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/admin/ports.d.ts +288 -0
- package/dist/admin/ports.d.ts.map +1 -0
- package/dist/admin/ports.js +39 -0
- package/dist/admin/ports.js.map +1 -0
- package/dist/admin/query/audit-view.d.ts +52 -0
- package/dist/admin/query/audit-view.d.ts.map +1 -0
- package/dist/admin/query/audit-view.js +84 -0
- package/dist/admin/query/audit-view.js.map +1 -0
- package/dist/admin/query/catalog.d.ts +70 -0
- package/dist/admin/query/catalog.d.ts.map +1 -0
- package/dist/admin/query/catalog.js +169 -0
- package/dist/admin/query/catalog.js.map +1 -0
- package/dist/admin/query/explain.d.ts +52 -0
- package/dist/admin/query/explain.d.ts.map +1 -0
- package/dist/admin/query/explain.js +145 -0
- package/dist/admin/query/explain.js.map +1 -0
- package/dist/admin/query/index.d.ts +45 -0
- package/dist/admin/query/index.d.ts.map +1 -0
- package/dist/admin/query/index.js +58 -0
- package/dist/admin/query/index.js.map +1 -0
- package/dist/admin/query/simulate.d.ts +42 -0
- package/dist/admin/query/simulate.d.ts.map +1 -0
- package/dist/admin/query/simulate.js +91 -0
- package/dist/admin/query/simulate.js.map +1 -0
- package/dist/admin/safeguards-impl.d.ts +67 -0
- package/dist/admin/safeguards-impl.d.ts.map +1 -0
- package/dist/admin/safeguards-impl.js +318 -0
- package/dist/admin/safeguards-impl.js.map +1 -0
- package/dist/admin/safeguards.d.ts +89 -0
- package/dist/admin/safeguards.d.ts.map +1 -0
- package/dist/admin/safeguards.js +91 -0
- package/dist/admin/safeguards.js.map +1 -0
- package/dist/admin/types.d.ts +485 -0
- package/dist/admin/types.d.ts.map +1 -0
- package/dist/admin/types.js +38 -0
- package/dist/admin/types.js.map +1 -0
- package/dist/audit/audit-recorder.d.ts +129 -0
- package/dist/audit/audit-recorder.d.ts.map +1 -0
- package/dist/audit/audit-recorder.js +265 -0
- package/dist/audit/audit-recorder.js.map +1 -0
- package/dist/audit/canonicalize.d.ts +38 -0
- package/dist/audit/canonicalize.d.ts.map +1 -0
- package/dist/audit/canonicalize.js +174 -0
- package/dist/audit/canonicalize.js.map +1 -0
- package/dist/audit/errors.d.ts +56 -0
- package/dist/audit/errors.d.ts.map +1 -0
- package/dist/audit/errors.js +41 -0
- package/dist/audit/errors.js.map +1 -0
- package/dist/audit/index.d.ts +45 -0
- package/dist/audit/index.d.ts.map +1 -0
- package/dist/audit/index.js +24 -0
- package/dist/audit/index.js.map +1 -0
- package/dist/audit/ports.d.ts +131 -0
- package/dist/audit/ports.d.ts.map +1 -0
- package/dist/audit/ports.js +27 -0
- package/dist/audit/ports.js.map +1 -0
- package/dist/audit/sensitive.d.ts +68 -0
- package/dist/audit/sensitive.d.ts.map +1 -0
- package/dist/audit/sensitive.js +159 -0
- package/dist/audit/sensitive.js.map +1 -0
- package/dist/audit/walk.d.ts +109 -0
- package/dist/audit/walk.d.ts.map +1 -0
- package/dist/audit/walk.js +117 -0
- package/dist/audit/walk.js.map +1 -0
- package/dist/authentication/authenticator.d.ts +74 -0
- package/dist/authentication/authenticator.d.ts.map +1 -0
- package/dist/authentication/authenticator.js +208 -0
- package/dist/authentication/authenticator.js.map +1 -0
- package/dist/authentication/credential-resolver.d.ts +76 -0
- package/dist/authentication/credential-resolver.d.ts.map +1 -0
- package/dist/authentication/credential-resolver.js +21 -0
- package/dist/authentication/credential-resolver.js.map +1 -0
- package/dist/authentication/index.d.ts +52 -0
- package/dist/authentication/index.d.ts.map +1 -0
- package/dist/authentication/index.js +27 -0
- package/dist/authentication/index.js.map +1 -0
- package/dist/authentication/password-hasher.d.ts +41 -0
- package/dist/authentication/password-hasher.d.ts.map +1 -0
- package/dist/authentication/password-hasher.js +21 -0
- package/dist/authentication/password-hasher.js.map +1 -0
- package/dist/authentication/totp.d.ts +101 -0
- package/dist/authentication/totp.d.ts.map +1 -0
- package/dist/authentication/totp.js +151 -0
- package/dist/authentication/totp.js.map +1 -0
- package/dist/authorization/cross-tenant/grant-evaluator.d.ts +90 -0
- package/dist/authorization/cross-tenant/grant-evaluator.d.ts.map +1 -0
- package/dist/authorization/cross-tenant/grant-evaluator.js +165 -0
- package/dist/authorization/cross-tenant/grant-evaluator.js.map +1 -0
- package/dist/authorization/decision-authority.d.ts +212 -0
- package/dist/authorization/decision-authority.d.ts.map +1 -0
- package/dist/authorization/decision-authority.js +200 -0
- package/dist/authorization/decision-authority.js.map +1 -0
- package/dist/authorization/default-gates.d.ts +41 -0
- package/dist/authorization/default-gates.d.ts.map +1 -0
- package/dist/authorization/default-gates.js +47 -0
- package/dist/authorization/default-gates.js.map +1 -0
- package/dist/authorization/delegation/operation-identity.d.ts +132 -0
- package/dist/authorization/delegation/operation-identity.d.ts.map +1 -0
- package/dist/authorization/delegation/operation-identity.js +220 -0
- package/dist/authorization/delegation/operation-identity.js.map +1 -0
- package/dist/authorization/errors.d.ts +54 -0
- package/dist/authorization/errors.d.ts.map +1 -0
- package/dist/authorization/errors.js +63 -0
- package/dist/authorization/errors.js.map +1 -0
- package/dist/authorization/gates/object-type.d.ts +63 -0
- package/dist/authorization/gates/object-type.d.ts.map +1 -0
- package/dist/authorization/gates/object-type.js +177 -0
- package/dist/authorization/gates/object-type.js.map +1 -0
- package/dist/authorization/gates/tenant.d.ts +50 -0
- package/dist/authorization/gates/tenant.d.ts.map +1 -0
- package/dist/authorization/gates/tenant.js +87 -0
- package/dist/authorization/gates/tenant.js.map +1 -0
- package/dist/authorization/gates/wiring.d.ts +57 -0
- package/dist/authorization/gates/wiring.d.ts.map +1 -0
- package/dist/authorization/gates/wiring.js +56 -0
- package/dist/authorization/gates/wiring.js.map +1 -0
- package/dist/authorization/index.d.ts +136 -0
- package/dist/authorization/index.d.ts.map +1 -0
- package/dist/authorization/index.js +82 -0
- package/dist/authorization/index.js.map +1 -0
- package/dist/authorization/ports.d.ts +271 -0
- package/dist/authorization/ports.d.ts.map +1 -0
- package/dist/authorization/ports.js +36 -0
- package/dist/authorization/ports.js.map +1 -0
- package/dist/authorization/reason-codes.d.ts +75 -0
- package/dist/authorization/reason-codes.d.ts.map +1 -0
- package/dist/authorization/reason-codes.js +98 -0
- package/dist/authorization/reason-codes.js.map +1 -0
- package/dist/authorization/record/permit-tier.d.ts +57 -0
- package/dist/authorization/record/permit-tier.d.ts.map +1 -0
- package/dist/authorization/record/permit-tier.js +79 -0
- package/dist/authorization/record/permit-tier.js.map +1 -0
- package/dist/authorization/record/rule-evaluator.d.ts +116 -0
- package/dist/authorization/record/rule-evaluator.d.ts.map +1 -0
- package/dist/authorization/record/rule-evaluator.js +125 -0
- package/dist/authorization/record/rule-evaluator.js.map +1 -0
- package/dist/authorization/record/shares.d.ts +70 -0
- package/dist/authorization/record/shares.d.ts.map +1 -0
- package/dist/authorization/record/shares.js +107 -0
- package/dist/authorization/record/shares.js.map +1 -0
- package/dist/identity/broker.d.ts +59 -0
- package/dist/identity/broker.d.ts.map +1 -0
- package/dist/identity/broker.js +135 -0
- package/dist/identity/broker.js.map +1 -0
- package/dist/identity/claim-mapper.d.ts +84 -0
- package/dist/identity/claim-mapper.d.ts.map +1 -0
- package/dist/identity/claim-mapper.js +48 -0
- package/dist/identity/claim-mapper.js.map +1 -0
- package/dist/identity/index.d.ts +60 -0
- package/dist/identity/index.d.ts.map +1 -0
- package/dist/identity/index.js +24 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/identity/internal-adapter.d.ts +54 -0
- package/dist/identity/internal-adapter.d.ts.map +1 -0
- package/dist/identity/internal-adapter.js +88 -0
- package/dist/identity/internal-adapter.js.map +1 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/metadata/completeness.d.ts +136 -0
- package/dist/metadata/completeness.d.ts.map +1 -0
- package/dist/metadata/completeness.js +106 -0
- package/dist/metadata/completeness.js.map +1 -0
- package/dist/metadata/dependencies.d.ts +114 -0
- package/dist/metadata/dependencies.d.ts.map +1 -0
- package/dist/metadata/dependencies.js +105 -0
- package/dist/metadata/dependencies.js.map +1 -0
- package/dist/metadata/index.d.ts +153 -0
- package/dist/metadata/index.d.ts.map +1 -0
- package/dist/metadata/index.js +51 -0
- package/dist/metadata/index.js.map +1 -0
- package/dist/metadata/registry.d.ts +23 -0
- package/dist/metadata/registry.d.ts.map +1 -0
- package/dist/metadata/registry.js +204 -0
- package/dist/metadata/registry.js.map +1 -0
- package/dist/risk/evaluator.d.ts +76 -0
- package/dist/risk/evaluator.d.ts.map +1 -0
- package/dist/risk/evaluator.js +59 -0
- package/dist/risk/evaluator.js.map +1 -0
- package/dist/risk/index.d.ts +40 -0
- package/dist/risk/index.d.ts.map +1 -0
- package/dist/risk/index.js +20 -0
- package/dist/risk/index.js.map +1 -0
- package/dist/risk/risk-engine.d.ts +76 -0
- package/dist/risk/risk-engine.d.ts.map +1 -0
- package/dist/risk/risk-engine.js +287 -0
- package/dist/risk/risk-engine.js.map +1 -0
- package/dist/risk/signals.d.ts +60 -0
- package/dist/risk/signals.d.ts.map +1 -0
- package/dist/risk/signals.js +104 -0
- package/dist/risk/signals.js.map +1 -0
- package/dist/risk/thresholds.d.ts +54 -0
- package/dist/risk/thresholds.d.ts.map +1 -0
- package/dist/risk/thresholds.js +60 -0
- package/dist/risk/thresholds.js.map +1 -0
- package/dist/session/index.d.ts +47 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +20 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/lifetimes.d.ts +50 -0
- package/dist/session/lifetimes.d.ts.map +1 -0
- package/dist/session/lifetimes.js +67 -0
- package/dist/session/lifetimes.js.map +1 -0
- package/dist/session/ports.d.ts +266 -0
- package/dist/session/ports.d.ts.map +1 -0
- package/dist/session/ports.js +23 -0
- package/dist/session/ports.js.map +1 -0
- package/dist/session/session-authority.d.ts +97 -0
- package/dist/session/session-authority.d.ts.map +1 -0
- package/dist/session/session-authority.js +393 -0
- package/dist/session/session-authority.js.map +1 -0
- package/package.json +32 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Engine seam: **Authentication** — proves the identity.
|
|
3
|
+
*
|
|
4
|
+
* Establishes that the caller is who the {@link Principal} claims to be (Argon2id,
|
|
5
|
+
* MFA, WebAuthn — 010_Architecture §2). This seam names the contract only; the
|
|
6
|
+
* factor implementations are a later layer.
|
|
7
|
+
*
|
|
8
|
+
* The FROZEN public types below (ADR-0023, semver) are the seam — DO NOT change
|
|
9
|
+
* them. The ENGINE that implements this seam (the password-hasher + credential-
|
|
10
|
+
* resolver + factor-verifier PORTs, the reference TOTP verifier, and the
|
|
11
|
+
* `createAuthenticator` factory) lives in the sibling files re-exported at the
|
|
12
|
+
* bottom of this barrel (flows out through `src/index.ts`).
|
|
13
|
+
*
|
|
14
|
+
* ADR-0003: framework-agnostic.
|
|
15
|
+
*/
|
|
16
|
+
import type { Principal } from '../identity/index.js';
|
|
17
|
+
/** Authentication factor classes the platform may require/step up to. */
|
|
18
|
+
export type AuthFactor = 'password' | 'totp' | 'webauthn' | 'recovery_code';
|
|
19
|
+
/** A credential presented for verification (opaque payload by factor). */
|
|
20
|
+
export interface Credential {
|
|
21
|
+
readonly factor: AuthFactor;
|
|
22
|
+
/** Factor-specific material — never logged, never rendered. */
|
|
23
|
+
readonly payload: Readonly<Record<string, unknown>>;
|
|
24
|
+
}
|
|
25
|
+
/** Outcome of an authentication attempt. */
|
|
26
|
+
export type AuthenticationOutcome = 'authenticated' | 'mfa_required' | 'rejected';
|
|
27
|
+
/** Result of verifying one or more credentials. */
|
|
28
|
+
export interface AuthenticationResult {
|
|
29
|
+
readonly outcome: AuthenticationOutcome;
|
|
30
|
+
/** Present only when `outcome === 'authenticated'`. */
|
|
31
|
+
readonly principal?: Principal;
|
|
32
|
+
/** Factors already satisfied in this attempt (for step-up decisions). */
|
|
33
|
+
readonly satisfiedFactors: readonly AuthFactor[];
|
|
34
|
+
/** Machine reason for a rejection/step-up (never leaks resource existence). */
|
|
35
|
+
readonly reason?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Authenticator seam — verifies presented credentials for a claimed principal.
|
|
39
|
+
* Implementation (hashing, MFA challenge/verify) is a later layer.
|
|
40
|
+
*/
|
|
41
|
+
export interface Authenticator {
|
|
42
|
+
/**
|
|
43
|
+
* Verify credentials for the identity referenced by `identityHint`
|
|
44
|
+
* (e.g. username/email — resolved to a principal internally).
|
|
45
|
+
*/
|
|
46
|
+
authenticate(identityHint: string, credentials: readonly Credential[]): Promise<AuthenticationResult>;
|
|
47
|
+
}
|
|
48
|
+
export * from './password-hasher.js';
|
|
49
|
+
export * from './credential-resolver.js';
|
|
50
|
+
export * from './totp.js';
|
|
51
|
+
export * from './authenticator.js';
|
|
52
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/authentication/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,yEAAyE;AACzE,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,eAAe,CAAC;AAE5E,0EAA0E;AAC1E,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,+DAA+D;IAC/D,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACrD;AAED,4CAA4C;AAC5C,MAAM,MAAM,qBAAqB,GAAG,eAAe,GAAG,cAAc,GAAG,UAAU,CAAC;AAElF,mDAAmD;AACnD,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,OAAO,EAAE,qBAAqB,CAAC;IACxC,uDAAuD;IACvD,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC;IAC/B,yEAAyE;IACzE,QAAQ,CAAC,gBAAgB,EAAE,SAAS,UAAU,EAAE,CAAC;IACjD,+EAA+E;IAC/E,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,YAAY,CACV,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,SAAS,UAAU,EAAE,GACjC,OAAO,CAAC,oBAAoB,CAAC,CAAC;CAClC;AAKD,cAAc,sBAAsB,CAAC;AAGrC,cAAc,0BAA0B,CAAC;AAEzC,cAAc,WAAW,CAAC;AAE1B,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Engine seam: **Authentication** — proves the identity.
|
|
3
|
+
*
|
|
4
|
+
* Establishes that the caller is who the {@link Principal} claims to be (Argon2id,
|
|
5
|
+
* MFA, WebAuthn — 010_Architecture §2). This seam names the contract only; the
|
|
6
|
+
* factor implementations are a later layer.
|
|
7
|
+
*
|
|
8
|
+
* The FROZEN public types below (ADR-0023, semver) are the seam — DO NOT change
|
|
9
|
+
* them. The ENGINE that implements this seam (the password-hasher + credential-
|
|
10
|
+
* resolver + factor-verifier PORTs, the reference TOTP verifier, and the
|
|
11
|
+
* `createAuthenticator` factory) lives in the sibling files re-exported at the
|
|
12
|
+
* bottom of this barrel (flows out through `src/index.ts`).
|
|
13
|
+
*
|
|
14
|
+
* ADR-0003: framework-agnostic.
|
|
15
|
+
*/
|
|
16
|
+
// --- Engine implementation behind the FROZEN seam above (this layer) ----------
|
|
17
|
+
// The PasswordHasher PORT (concrete Argon2id ships in @astram/guard — Core stays
|
|
18
|
+
// zero-dep):
|
|
19
|
+
export * from './password-hasher.js';
|
|
20
|
+
// The CredentialResolver PORT (hint → stored credential + claims; null = unknown,
|
|
21
|
+
// anti-enumeration):
|
|
22
|
+
export * from './credential-resolver.js';
|
|
23
|
+
// The factor-verifier CONTRACT + registry + reference TOTP verifier (HMAC injected):
|
|
24
|
+
export * from './totp.js';
|
|
25
|
+
// The Authentication engine + the `createAuthenticator` factory:
|
|
26
|
+
export * from './authenticator.js';
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/authentication/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA2CH,iFAAiF;AACjF,iFAAiF;AACjF,aAAa;AACb,cAAc,sBAAsB,CAAC;AACrC,kFAAkF;AAClF,qBAAqB;AACrB,cAAc,0BAA0B,CAAC;AACzC,qFAAqF;AACrF,cAAc,WAAW,CAAC;AAC1B,iEAAiE;AACjE,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The **PasswordHasher PORT** — the framework-agnostic contract the
|
|
3
|
+
* Authentication engine uses to verify a password credential, WITHOUT the engine
|
|
4
|
+
* ever knowing which algorithm backs it.
|
|
5
|
+
*
|
|
6
|
+
* ADR-0003 (zero-dep Core): the concrete hasher is a real dependency (Argon2id
|
|
7
|
+
* needs the `argon2` npm package + native bindings), so it CANNOT live here. The
|
|
8
|
+
* Core defines only this interface; `@astram/guard` ships
|
|
9
|
+
* `Argon2idPasswordHasher implements PasswordHasher` and INJECTS it into
|
|
10
|
+
* `createAuthenticator`. This keeps `@astram/core` at ZERO runtime dependencies
|
|
11
|
+
* (the load-bearing invariant) while the algorithm stays swappable.
|
|
12
|
+
*
|
|
13
|
+
* SECURITY — the engine NEVER logs, renders, or returns the hash or the
|
|
14
|
+
* plaintext. Both are transient inputs to `verify`; neither is ever surfaced in
|
|
15
|
+
* an `AuthenticationResult`, a `reason`, or a log line. A `PasswordHasher`
|
|
16
|
+
* implementation MUST likewise not log its arguments.
|
|
17
|
+
*
|
|
18
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB imports.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Verifies (and can produce) password hashes. Deliberately minimal (ADR-0023 §7
|
|
22
|
+
* Rule of Three): two operations, no algorithm parameters leaking across the
|
|
23
|
+
* seam — tuning lives in the concrete adapter, not this contract.
|
|
24
|
+
*/
|
|
25
|
+
export interface PasswordHasher {
|
|
26
|
+
/**
|
|
27
|
+
* Hash a plaintext password into an encoded, self-describing hash string
|
|
28
|
+
* (algorithm + params + salt + digest). Used at credential-set time.
|
|
29
|
+
* MUST NOT log the plaintext.
|
|
30
|
+
*/
|
|
31
|
+
hash(plaintext: string): Promise<string>;
|
|
32
|
+
/**
|
|
33
|
+
* Verify a plaintext against a previously-produced `hash`. Returns `true` iff
|
|
34
|
+
* they match. MUST run in (near-)constant time w.r.t. the secret and MUST NOT
|
|
35
|
+
* log either argument. A malformed/unparseable `hash` MUST resolve `false`
|
|
36
|
+
* (never throw a leak) OR reject — the engine treats a rejection as
|
|
37
|
+
* fail-closed either way.
|
|
38
|
+
*/
|
|
39
|
+
verify(hash: string, plaintext: string): Promise<boolean>;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=password-hasher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password-hasher.d.ts","sourceRoot":"","sources":["../../src/authentication/password-hasher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEzC;;;;;;OAMG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC3D"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The **PasswordHasher PORT** — the framework-agnostic contract the
|
|
3
|
+
* Authentication engine uses to verify a password credential, WITHOUT the engine
|
|
4
|
+
* ever knowing which algorithm backs it.
|
|
5
|
+
*
|
|
6
|
+
* ADR-0003 (zero-dep Core): the concrete hasher is a real dependency (Argon2id
|
|
7
|
+
* needs the `argon2` npm package + native bindings), so it CANNOT live here. The
|
|
8
|
+
* Core defines only this interface; `@astram/guard` ships
|
|
9
|
+
* `Argon2idPasswordHasher implements PasswordHasher` and INJECTS it into
|
|
10
|
+
* `createAuthenticator`. This keeps `@astram/core` at ZERO runtime dependencies
|
|
11
|
+
* (the load-bearing invariant) while the algorithm stays swappable.
|
|
12
|
+
*
|
|
13
|
+
* SECURITY — the engine NEVER logs, renders, or returns the hash or the
|
|
14
|
+
* plaintext. Both are transient inputs to `verify`; neither is ever surfaced in
|
|
15
|
+
* an `AuthenticationResult`, a `reason`, or a log line. A `PasswordHasher`
|
|
16
|
+
* implementation MUST likewise not log its arguments.
|
|
17
|
+
*
|
|
18
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB imports.
|
|
19
|
+
*/
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=password-hasher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password-hasher.js","sourceRoot":"","sources":["../../src/authentication/password-hasher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The **factor-verifier CONTRACT** + a **reference TOTP verifier** (RFC 6238).
|
|
3
|
+
*
|
|
4
|
+
* `FactorVerifier` is the extension seam for second factors: one verifier per
|
|
5
|
+
* `AuthFactor`, registered in a `FactorVerifierRegistry`, driven by the
|
|
6
|
+
* Authentication engine when a `RequiredFactor` is outstanding. This is
|
|
7
|
+
* deliberately MINIMAL (ADR-0023 §7 Rule of Three): the contract + ONE concrete
|
|
8
|
+
* verifier (TOTP) that exercises the `mfa_required` mechanism. The WebAuthn /
|
|
9
|
+
* recovery-code factors are named in `AuthFactor` but only their CONTRACT slot
|
|
10
|
+
* exists here — no ceremony this layer.
|
|
11
|
+
*
|
|
12
|
+
* ZERO-DEP + NODE-TYPE-FREE (ADR-0003): TOTP needs HMAC-SHA1, but `@astram/core`
|
|
13
|
+
* has neither a runtime dependency NOR `@types/node` (its tsconfig sets
|
|
14
|
+
* `types: []`). So HMAC is itself an INJECTED port (`HmacSha1`): the pure RFC-6238
|
|
15
|
+
* arithmetic (time-step counter, dynamic truncation, modulo) lives here; the one
|
|
16
|
+
* crypto primitive is supplied by the caller (a `node:crypto` one-liner in the
|
|
17
|
+
* app / tests). Core stays dependency-free and never imports a node builtin.
|
|
18
|
+
*
|
|
19
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
|
|
20
|
+
*/
|
|
21
|
+
import type { AuthFactor, Credential } from './index.js';
|
|
22
|
+
/**
|
|
23
|
+
* The verification verdict for one factor. `satisfied` is the ONLY thing the
|
|
24
|
+
* engine acts on; `reason` is a machine string for logging that MUST stay generic
|
|
25
|
+
* (never leaks which secret / which user).
|
|
26
|
+
*/
|
|
27
|
+
export interface FactorVerdict {
|
|
28
|
+
readonly satisfied: boolean;
|
|
29
|
+
readonly reason?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A single second-factor verifier. PURE per call (the engine supplies the
|
|
33
|
+
* presented `credential` + the server-side `secret` from the resolved
|
|
34
|
+
* credential). One verifier per `AuthFactor`; registered in a
|
|
35
|
+
* {@link FactorVerifierRegistry}.
|
|
36
|
+
*
|
|
37
|
+
* SECURITY — a verifier MUST NOT log the credential payload or the secret, and
|
|
38
|
+
* MUST return `satisfied: false` (not throw) for a malformed presented code, so
|
|
39
|
+
* an outstanding factor is never silently treated as satisfied.
|
|
40
|
+
*/
|
|
41
|
+
export interface FactorVerifier {
|
|
42
|
+
/** The factor this verifier handles (matched exactly against a RequiredFactor). */
|
|
43
|
+
readonly factor: AuthFactor;
|
|
44
|
+
/**
|
|
45
|
+
* Verify the presented `credential` for this factor against the server-side
|
|
46
|
+
* `secret`. Async to allow verifiers that do I/O later (WebAuthn); the TOTP
|
|
47
|
+
* reference is synchronous under the hood but returns a Promise for a uniform
|
|
48
|
+
* contract.
|
|
49
|
+
*/
|
|
50
|
+
verify(credential: Credential, secret: string): Promise<FactorVerdict>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A tiny registry of {@link FactorVerifier}s, keyed by `factor`. The engine
|
|
54
|
+
* resolves the verifier for each outstanding `RequiredFactor`; a MISS means no
|
|
55
|
+
* verifier is wired for a required factor → the engine fail-closes (that factor
|
|
56
|
+
* can never be satisfied, so the attempt cannot authenticate). Fail-closed on
|
|
57
|
+
* empty/duplicate registration, mirroring `IdentityClaimMapperRegistry`.
|
|
58
|
+
*/
|
|
59
|
+
export declare class FactorVerifierRegistry {
|
|
60
|
+
private readonly verifiers;
|
|
61
|
+
/** Register a verifier for its `factor`. Duplicate → throws LOUD. */
|
|
62
|
+
register(verifier: FactorVerifier): void;
|
|
63
|
+
/** Look up the verifier for a factor, or `undefined` if none is registered. */
|
|
64
|
+
resolve(factor: AuthFactor): FactorVerifier | undefined;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The injected HMAC-SHA1 primitive (see file header — keeps Core zero-dep +
|
|
68
|
+
* node-type-free). Given the raw key bytes and message bytes, return the 20-byte
|
|
69
|
+
* HMAC-SHA1 digest. A `node:crypto`-backed implementation is a one-liner supplied
|
|
70
|
+
* by the caller.
|
|
71
|
+
*/
|
|
72
|
+
export type HmacSha1 = (key: Uint8Array, message: Uint8Array) => Uint8Array;
|
|
73
|
+
/** Options for {@link createTotpFactorVerifier}. */
|
|
74
|
+
export interface TotpVerifierOptions {
|
|
75
|
+
/** The injected HMAC-SHA1 primitive (required — Core provides none). */
|
|
76
|
+
readonly hmacSha1: HmacSha1;
|
|
77
|
+
/** Digits in the code (RFC 6238 default 6). */
|
|
78
|
+
readonly digits?: number;
|
|
79
|
+
/** Time step in seconds (RFC 6238 default 30). */
|
|
80
|
+
readonly stepSeconds?: number;
|
|
81
|
+
/**
|
|
82
|
+
* How many steps of clock skew to accept on EACH side of "now" (default 1 ⇒
|
|
83
|
+
* accepts the previous, current, and next code). Bounded to keep the window
|
|
84
|
+
* tight; a larger value trades security for tolerance.
|
|
85
|
+
*/
|
|
86
|
+
readonly window?: number;
|
|
87
|
+
/**
|
|
88
|
+
* Clock source (UTC epoch milliseconds). Injectable for deterministic tests;
|
|
89
|
+
* defaults to `Date.now` (a pure JS global — allowed in Core, not a node dep).
|
|
90
|
+
*/
|
|
91
|
+
readonly now?: () => number;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Build the reference **TOTP** {@link FactorVerifier} (RFC 6238). The presented
|
|
95
|
+
* `credential.payload.code` (a string of digits) is checked against codes derived
|
|
96
|
+
* from the base32 `secret` across the accepted skew window. PURE apart from the
|
|
97
|
+
* injected HMAC + clock. Fail-closed: a malformed secret or a non-string /
|
|
98
|
+
* wrong-length code → `satisfied: false` (never throws, never logs the code).
|
|
99
|
+
*/
|
|
100
|
+
export declare function createTotpFactorVerifier(options: TotpVerifierOptions): FactorVerifier;
|
|
101
|
+
//# sourceMappingURL=totp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"totp.d.ts","sourceRoot":"","sources":["../../src/authentication/totp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEzD;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,cAAc;IAC7B,mFAAmF;IACnF,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B;;;;;OAKG;IACH,MAAM,CAAC,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;CACxE;AAED;;;;;;GAMG;AACH,qBAAa,sBAAsB;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAyC;IAEnE,qEAAqE;IACrE,QAAQ,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI;IASxC,+EAA+E;IAC/E,OAAO,CAAC,MAAM,EAAE,UAAU,GAAG,cAAc,GAAG,SAAS;CAGxD;AAED;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,KAAK,UAAU,CAAC;AAE5E,oDAAoD;AACpD,MAAM,WAAW,mBAAmB;IAClC,wEAAwE;IACxE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,+CAA+C;IAC/C,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,kDAAkD;IAClD,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CAC7B;AAmFD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,mBAAmB,GAC3B,cAAc,CA6BhB"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The **factor-verifier CONTRACT** + a **reference TOTP verifier** (RFC 6238).
|
|
3
|
+
*
|
|
4
|
+
* `FactorVerifier` is the extension seam for second factors: one verifier per
|
|
5
|
+
* `AuthFactor`, registered in a `FactorVerifierRegistry`, driven by the
|
|
6
|
+
* Authentication engine when a `RequiredFactor` is outstanding. This is
|
|
7
|
+
* deliberately MINIMAL (ADR-0023 §7 Rule of Three): the contract + ONE concrete
|
|
8
|
+
* verifier (TOTP) that exercises the `mfa_required` mechanism. The WebAuthn /
|
|
9
|
+
* recovery-code factors are named in `AuthFactor` but only their CONTRACT slot
|
|
10
|
+
* exists here — no ceremony this layer.
|
|
11
|
+
*
|
|
12
|
+
* ZERO-DEP + NODE-TYPE-FREE (ADR-0003): TOTP needs HMAC-SHA1, but `@astram/core`
|
|
13
|
+
* has neither a runtime dependency NOR `@types/node` (its tsconfig sets
|
|
14
|
+
* `types: []`). So HMAC is itself an INJECTED port (`HmacSha1`): the pure RFC-6238
|
|
15
|
+
* arithmetic (time-step counter, dynamic truncation, modulo) lives here; the one
|
|
16
|
+
* crypto primitive is supplied by the caller (a `node:crypto` one-liner in the
|
|
17
|
+
* app / tests). Core stays dependency-free and never imports a node builtin.
|
|
18
|
+
*
|
|
19
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* A tiny registry of {@link FactorVerifier}s, keyed by `factor`. The engine
|
|
23
|
+
* resolves the verifier for each outstanding `RequiredFactor`; a MISS means no
|
|
24
|
+
* verifier is wired for a required factor → the engine fail-closes (that factor
|
|
25
|
+
* can never be satisfied, so the attempt cannot authenticate). Fail-closed on
|
|
26
|
+
* empty/duplicate registration, mirroring `IdentityClaimMapperRegistry`.
|
|
27
|
+
*/
|
|
28
|
+
export class FactorVerifierRegistry {
|
|
29
|
+
verifiers = new Map();
|
|
30
|
+
/** Register a verifier for its `factor`. Duplicate → throws LOUD. */
|
|
31
|
+
register(verifier) {
|
|
32
|
+
if (this.verifiers.has(verifier.factor)) {
|
|
33
|
+
throw new Error(`FactorVerifierRegistry.register: factor "${verifier.factor}" is already registered (duplicate verifier)`);
|
|
34
|
+
}
|
|
35
|
+
this.verifiers.set(verifier.factor, verifier);
|
|
36
|
+
}
|
|
37
|
+
/** Look up the verifier for a factor, or `undefined` if none is registered. */
|
|
38
|
+
resolve(factor) {
|
|
39
|
+
return this.verifiers.get(factor);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const BASE32_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
|
|
43
|
+
/**
|
|
44
|
+
* Decode an RFC 4648 base32 string (the standard TOTP secret encoding) into
|
|
45
|
+
* bytes. Case-insensitive; ignores padding (`=`) and whitespace. Returns `null`
|
|
46
|
+
* for any non-alphabet character so the verifier fail-closes on a malformed
|
|
47
|
+
* secret rather than authenticating against garbage.
|
|
48
|
+
*/
|
|
49
|
+
function base32Decode(input) {
|
|
50
|
+
const clean = input.replace(/=+$/u, '').replace(/\s+/gu, '').toUpperCase();
|
|
51
|
+
if (clean.length === 0)
|
|
52
|
+
return null;
|
|
53
|
+
let bits = 0;
|
|
54
|
+
let value = 0;
|
|
55
|
+
const out = [];
|
|
56
|
+
for (const ch of clean) {
|
|
57
|
+
const idx = BASE32_ALPHABET.indexOf(ch);
|
|
58
|
+
if (idx === -1)
|
|
59
|
+
return null;
|
|
60
|
+
value = (value << 5) | idx;
|
|
61
|
+
bits += 5;
|
|
62
|
+
if (bits >= 8) {
|
|
63
|
+
bits -= 8;
|
|
64
|
+
out.push((value >>> bits) & 0xff);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return Uint8Array.from(out);
|
|
68
|
+
}
|
|
69
|
+
/** Encode a 64-bit counter (big-endian) into an 8-byte buffer (RFC 4226). */
|
|
70
|
+
function counterToBytes(counter) {
|
|
71
|
+
const buf = new Uint8Array(8);
|
|
72
|
+
// JS bitwise is 32-bit; split into high/low 32-bit halves to fill all 8 bytes.
|
|
73
|
+
let high = Math.floor(counter / 0x1_0000_0000);
|
|
74
|
+
let low = counter >>> 0;
|
|
75
|
+
for (let i = 7; i >= 4; i--) {
|
|
76
|
+
buf[i] = low & 0xff;
|
|
77
|
+
low = Math.floor(low / 256);
|
|
78
|
+
}
|
|
79
|
+
for (let i = 3; i >= 0; i--) {
|
|
80
|
+
buf[i] = high & 0xff;
|
|
81
|
+
high = Math.floor(high / 256);
|
|
82
|
+
}
|
|
83
|
+
return buf;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Compute the RFC 6238 TOTP code for a given time-step counter. Pure arithmetic
|
|
87
|
+
* over the injected HMAC-SHA1: dynamic truncation (RFC 4226 §5.3) → modulo
|
|
88
|
+
* 10^digits, zero-padded.
|
|
89
|
+
*/
|
|
90
|
+
function computeCode(hmacSha1, key, counter, digits) {
|
|
91
|
+
const digest = hmacSha1(key, counterToBytes(counter));
|
|
92
|
+
// Dynamic truncation: low 4 bits of the last byte select the offset.
|
|
93
|
+
const offset = (digest[digest.length - 1] ?? 0) & 0x0f;
|
|
94
|
+
const binary = (((digest[offset] ?? 0) & 0x7f) << 24) |
|
|
95
|
+
(((digest[offset + 1] ?? 0) & 0xff) << 16) |
|
|
96
|
+
(((digest[offset + 2] ?? 0) & 0xff) << 8) |
|
|
97
|
+
((digest[offset + 3] ?? 0) & 0xff);
|
|
98
|
+
const code = binary % 10 ** digits;
|
|
99
|
+
return code.toString().padStart(digits, '0');
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Constant-time string comparison (both operands are short numeric codes). Avoids
|
|
103
|
+
* an early-return timing signal on the presented code. Not a substitute for the
|
|
104
|
+
* password's algorithmic constant-time verify, but keeps the factor tidy.
|
|
105
|
+
*/
|
|
106
|
+
function timingSafeEqual(a, b) {
|
|
107
|
+
if (a.length !== b.length)
|
|
108
|
+
return false;
|
|
109
|
+
let diff = 0;
|
|
110
|
+
for (let i = 0; i < a.length; i++) {
|
|
111
|
+
diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
112
|
+
}
|
|
113
|
+
return diff === 0;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Build the reference **TOTP** {@link FactorVerifier} (RFC 6238). The presented
|
|
117
|
+
* `credential.payload.code` (a string of digits) is checked against codes derived
|
|
118
|
+
* from the base32 `secret` across the accepted skew window. PURE apart from the
|
|
119
|
+
* injected HMAC + clock. Fail-closed: a malformed secret or a non-string /
|
|
120
|
+
* wrong-length code → `satisfied: false` (never throws, never logs the code).
|
|
121
|
+
*/
|
|
122
|
+
export function createTotpFactorVerifier(options) {
|
|
123
|
+
const { hmacSha1 } = options;
|
|
124
|
+
const digits = options.digits ?? 6;
|
|
125
|
+
const stepSeconds = options.stepSeconds ?? 30;
|
|
126
|
+
const window = Math.max(0, options.window ?? 1);
|
|
127
|
+
const now = options.now ?? Date.now;
|
|
128
|
+
return {
|
|
129
|
+
factor: 'totp',
|
|
130
|
+
verify(credential, secret) {
|
|
131
|
+
const presented = credential.payload?.code;
|
|
132
|
+
if (typeof presented !== 'string' || presented.length === 0) {
|
|
133
|
+
return Promise.resolve({ satisfied: false, reason: 'factor_rejected' });
|
|
134
|
+
}
|
|
135
|
+
const key = base32Decode(secret);
|
|
136
|
+
if (key === null || key.length === 0) {
|
|
137
|
+
// Malformed server-side secret — fail-closed, never authenticate.
|
|
138
|
+
return Promise.resolve({ satisfied: false, reason: 'factor_rejected' });
|
|
139
|
+
}
|
|
140
|
+
const counter = Math.floor(now() / 1000 / stepSeconds);
|
|
141
|
+
for (let offset = -window; offset <= window; offset++) {
|
|
142
|
+
const candidate = computeCode(hmacSha1, key, counter + offset, digits);
|
|
143
|
+
if (timingSafeEqual(candidate, presented)) {
|
|
144
|
+
return Promise.resolve({ satisfied: true });
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return Promise.resolve({ satisfied: false, reason: 'factor_rejected' });
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=totp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"totp.js","sourceRoot":"","sources":["../../src/authentication/totp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAoCH;;;;;;GAMG;AACH,MAAM,OAAO,sBAAsB;IAChB,SAAS,GAAG,IAAI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AC;YACD,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAC,CAAC;QAC1E,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-tenant consented GRANT evaluator (ADR-0009 / §10bis) — the single, reusable
|
|
3
|
+
* "does an active cross-tenant grant permit THIS action on THIS resource?" helper
|
|
4
|
+
* consulted by gate 3 (tenant, TEAM A), gate 5 (object-type, TEAM A), AND gate 6's
|
|
5
|
+
* share-half (per-record permit, TEAM C — this file's owner).
|
|
6
|
+
*
|
|
7
|
+
* A cross-tenant grant is the ONLY sanctioned way (short of a platform superuser) a
|
|
8
|
+
* principal reaches a resource owned by a DIFFERENT tenant. It is NEVER a superuser
|
|
9
|
+
* bypass: it is a HARD action-ceiling (ADR-0009). This helper enforces AC 13 — the
|
|
10
|
+
* two hard bounds a grant may never exceed:
|
|
11
|
+
*
|
|
12
|
+
* 1. **Action ceiling** — the attempted action key MUST be a member of the grant's
|
|
13
|
+
* `allowedActions` set (STRICT membership). A `view`+`edit` grant DENIES `delete`.
|
|
14
|
+
* 2. **Scope coverage** — the grant must cover THIS resource: same object type, and
|
|
15
|
+
* for a `record`-scoped grant the exact record id. A grant scoped to one record
|
|
16
|
+
* (or one object type) DENIES every other record / object type.
|
|
17
|
+
*
|
|
18
|
+
* ── FAIL-CLOSED on ANY ambiguity. Any condition that is not affirmatively satisfied
|
|
19
|
+
* yields `applicable: false` — never a permit. An UNKNOWN scope shape is treated as
|
|
20
|
+
* "does not apply" (a hostile/garbage `scope` can never open access). Expiry is
|
|
21
|
+
* re-checked defensively even though the port is contracted to return only ACTIVE
|
|
22
|
+
* grants (defense-in-depth, per the {@link CrossTenantGrantPort.findActiveGrant}
|
|
23
|
+
* contract — "the engine additionally re-checks the returned grant's allowedActions
|
|
24
|
+
* + expiresAtMs").
|
|
25
|
+
*
|
|
26
|
+
* ── TRANSIENT-vs-DENY (ADR-0016). This helper NEVER catches. A `null` grant from the
|
|
27
|
+
* port is a normal data-absence → `applicable: false`. A transient
|
|
28
|
+
* {@link AuthorizationUnavailableError} (or any other throw) from the port
|
|
29
|
+
* PROPAGATES unchanged so `decide()` can re-throw it (503-retryable). We never
|
|
30
|
+
* swallow a transient into a "not applicable" — that would silently downgrade an
|
|
31
|
+
* outage to a Deny.
|
|
32
|
+
*
|
|
33
|
+
* ── PURE + zero-dep. No I/O of its own beyond the injected port; no framework / DB /
|
|
34
|
+
* node imports (ADR-0003). The `now` clock is injectable for deterministic tests;
|
|
35
|
+
* it defaults to `Date.now`, matching the port contract ("the clock is the
|
|
36
|
+
* engine's").
|
|
37
|
+
*/
|
|
38
|
+
import type { Principal } from '../../identity/index.js';
|
|
39
|
+
import type { Action, Resource } from '../index.js';
|
|
40
|
+
import type { CrossTenantGrant, CrossTenantGrantPort } from '../ports.js';
|
|
41
|
+
/**
|
|
42
|
+
* The subject of a cross-tenant applicability question: who is asking, what action,
|
|
43
|
+
* and which resource. Mirrors the fields the pipeline already holds on its
|
|
44
|
+
* `GateContext`, kept as a minimal explicit shape so this helper stays pure and
|
|
45
|
+
* consumable identically by gates 3, 5, and 6.
|
|
46
|
+
*/
|
|
47
|
+
export interface CrossTenantGrantSubject {
|
|
48
|
+
readonly principal: Principal;
|
|
49
|
+
readonly action: Action;
|
|
50
|
+
readonly resource: Resource;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The verdict of {@link isCrossTenantGrantApplicable}. `applicable` is `true` ONLY
|
|
54
|
+
* when an active grant was found AND it clears the action ceiling AND its scope
|
|
55
|
+
* covers the resource. `grant` carries the grant that was consulted (for the
|
|
56
|
+
* consumer's downstream use / logging) — it is present when the port returned one,
|
|
57
|
+
* `null` when the port returned none. A non-null `grant` with `applicable: false`
|
|
58
|
+
* means "a grant exists but it does NOT permit this action/resource" (out of
|
|
59
|
+
* ceiling or out of scope).
|
|
60
|
+
*/
|
|
61
|
+
export interface CrossTenantGrantVerdict {
|
|
62
|
+
readonly applicable: boolean;
|
|
63
|
+
readonly grant: CrossTenantGrant | null;
|
|
64
|
+
}
|
|
65
|
+
/** Optional injectables (deterministic clock for tests). */
|
|
66
|
+
export interface CrossTenantGrantEvalOptions {
|
|
67
|
+
/** UTC epoch-ms clock; defaults to {@link Date.now}. */
|
|
68
|
+
readonly now?: () => number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Resolve whether an ACTIVE, consented cross-tenant grant permits `subject.action`
|
|
72
|
+
* on `subject.resource` for `subject.principal` — the single-source AC-13 ceiling +
|
|
73
|
+
* scope evaluator shared across gates 3/5/6.
|
|
74
|
+
*
|
|
75
|
+
* Sequence (all conditions must hold, else `applicable:false`):
|
|
76
|
+
* 1. Ask {@link CrossTenantGrantPort.findActiveGrant} for a grant covering the
|
|
77
|
+
* resource's owning tenant + object type + action (+ record id for record-scoped).
|
|
78
|
+
* `null` ⇒ no consent ⇒ not applicable.
|
|
79
|
+
* 2. **Action ceiling** — `action.key` ∈ `grant.allowedActions` (strict membership).
|
|
80
|
+
* 3. **Scope coverage** — `object_type`-scoped covers every record of that type;
|
|
81
|
+
* `record`-scoped covers ONLY its `recordId`. Object type must match. Unknown
|
|
82
|
+
* scope shape ⇒ not applicable.
|
|
83
|
+
* 4. **Expiry (defensive)** — `grant.expiresAtMs > now`, even though the port
|
|
84
|
+
* should only return active grants.
|
|
85
|
+
*
|
|
86
|
+
* @throws propagates any {@link AuthorizationUnavailableError} (or other error) the
|
|
87
|
+
* port throws — a transient must NOT be swallowed into "not applicable".
|
|
88
|
+
*/
|
|
89
|
+
export declare function isCrossTenantGrantApplicable(port: CrossTenantGrantPort, subject: CrossTenantGrantSubject, options?: CrossTenantGrantEvalOptions): Promise<CrossTenantGrantVerdict>;
|
|
90
|
+
//# sourceMappingURL=grant-evaluator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grant-evaluator.d.ts","sourceRoot":"","sources":["../../../src/authorization/cross-tenant/grant-evaluator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEpD,OAAO,KAAK,EACV,gBAAgB,EAChB,oBAAoB,EAErB,MAAM,aAAa,CAAC;AAErB;;;;;GAKG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAC7B;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAAC;CACzC;AAOD,4DAA4D;AAC5D,MAAM,WAAW,2BAA2B;IAC1C,wDAAwD;IACxD,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,4BAA4B,CAChD,IAAI,EAAE,oBAAoB,EAC1B,OAAO,EAAE,uBAAuB,EAChC,OAAO,GAAE,2BAAgC,GACxC,OAAO,CAAC,uBAAuB,CAAC,CA2ClC"}
|