@salamandradevs/core 0.1.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/index.js +4 -2
- package/dist/keys/config/index.js +3 -0
- package/dist/keys/config/schema.js +51 -0
- package/dist/keys/config/types.js +2 -0
- package/dist/keys/contracts.js +2 -0
- package/dist/keys/factory.js +61 -0
- package/dist/keys/index.js +10 -0
- package/dist/keys/jose/index.js +3 -0
- package/dist/keys/jose/jose-keyfile.js +97 -0
- package/dist/keys/jose/jose-keys-provider.js +256 -0
- package/dist/keys/jose/schema.js +68 -0
- package/dist/keys/jose/types.js +2 -0
- package/dist/keys/jwks/index.js +2 -0
- package/dist/keys/jwks/jwks-verification-key-provider.js +43 -0
- package/dist/keys/openbao/index.js +3 -0
- package/dist/keys/openbao/openbao-keys-provider.js +461 -0
- package/dist/keys/openbao/schema.js +67 -0
- package/dist/keys/openbao/types.js +2 -0
- package/dist/keys/schema.js +65 -0
- package/dist/keys/types.js +2 -0
- package/dist/keys/validation.js +100 -0
- package/dist/runtime/context.js +42 -0
- package/dist/runtime/index.js +2 -0
- package/dist/storage/records-handler.js +2 -2
- package/dist/tokens/access-token-verifier.js +75 -0
- package/dist/tokens/contracts.js +2 -0
- package/dist/tokens/index.js +5 -0
- package/dist/tokens/schema.js +36 -0
- package/dist/tokens/types.js +2 -0
- package/package.json +2 -1
- package/types/index.d.ts +3 -1
- package/types/index.d.ts.map +1 -1
- package/types/keys/config/index.d.ts +3 -0
- package/types/keys/config/index.d.ts.map +1 -0
- package/types/keys/config/schema.d.ts +66 -0
- package/types/keys/config/schema.d.ts.map +1 -0
- package/types/keys/config/types.d.ts +8 -0
- package/types/keys/config/types.d.ts.map +1 -0
- package/types/keys/contracts.d.ts +52 -0
- package/types/keys/contracts.d.ts.map +1 -0
- package/types/keys/factory.d.ts +22 -0
- package/types/keys/factory.d.ts.map +1 -0
- package/types/keys/index.d.ts +10 -0
- package/types/keys/index.d.ts.map +1 -0
- package/types/keys/jose/index.d.ts +3 -0
- package/types/keys/jose/index.d.ts.map +1 -0
- package/types/keys/jose/jose-keyfile.d.ts +35 -0
- package/types/keys/jose/jose-keyfile.d.ts.map +1 -0
- package/types/keys/jose/jose-keys-provider.d.ts +112 -0
- package/types/keys/jose/jose-keys-provider.d.ts.map +1 -0
- package/types/keys/jose/schema.d.ts +91 -0
- package/types/keys/jose/schema.d.ts.map +1 -0
- package/types/keys/jose/types.d.ts +35 -0
- package/types/keys/jose/types.d.ts.map +1 -0
- package/types/keys/jwks/index.d.ts +2 -0
- package/types/keys/jwks/index.d.ts.map +1 -0
- package/types/keys/jwks/jwks-verification-key-provider.d.ts +27 -0
- package/types/keys/jwks/jwks-verification-key-provider.d.ts.map +1 -0
- package/types/keys/openbao/index.d.ts +3 -0
- package/types/keys/openbao/index.d.ts.map +1 -0
- package/types/keys/openbao/openbao-keys-provider.d.ts +175 -0
- package/types/keys/openbao/openbao-keys-provider.d.ts.map +1 -0
- package/types/keys/openbao/schema.d.ts +68 -0
- package/types/keys/openbao/schema.d.ts.map +1 -0
- package/types/keys/openbao/types.d.ts +52 -0
- package/types/keys/openbao/types.d.ts.map +1 -0
- package/types/keys/schema.d.ts +73 -0
- package/types/keys/schema.d.ts.map +1 -0
- package/types/keys/types.d.ts +53 -0
- package/types/keys/types.d.ts.map +1 -0
- package/types/keys/validation.d.ts +19 -0
- package/types/keys/validation.d.ts.map +1 -0
- package/types/runtime/context.d.ts +67 -0
- package/types/runtime/context.d.ts.map +1 -0
- package/types/runtime/index.d.ts +2 -0
- package/types/runtime/index.d.ts.map +1 -0
- package/types/tokens/access-token-verifier.d.ts +36 -0
- package/types/tokens/access-token-verifier.d.ts.map +1 -0
- package/types/tokens/contracts.d.ts +21 -0
- package/types/tokens/contracts.d.ts.map +1 -0
- package/types/tokens/index.d.ts +5 -0
- package/types/tokens/index.d.ts.map +1 -0
- package/types/tokens/schema.d.ts +34 -0
- package/types/tokens/schema.d.ts.map +1 -0
- package/types/tokens/types.d.ts +20 -0
- package/types/tokens/types.d.ts.map +1 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Public JSON Web Key material schema.
|
|
4
|
+
*
|
|
5
|
+
* - Kty: Key type.
|
|
6
|
+
* - Kid: Public key identifier.
|
|
7
|
+
* - Use: Optional intended key use.
|
|
8
|
+
* - Alg: Optional JOSE algorithm.
|
|
9
|
+
* - Crv: Optional elliptic curve name.
|
|
10
|
+
* - X: Optional elliptic-curve or RSA coordinate.
|
|
11
|
+
* - Y: Optional elliptic-curve coordinate.
|
|
12
|
+
* - N: Optional RSA modulus.
|
|
13
|
+
* - E: Optional RSA exponent.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* Provider-neutral: this is the public key as served to every key consumer, so it carries
|
|
17
|
+
* no provider-specific fields. Shared across every signing-key provider so each validates
|
|
18
|
+
* the lifecycle document against one definition.
|
|
19
|
+
* @group Keys
|
|
20
|
+
* @category Key Providers
|
|
21
|
+
*/
|
|
22
|
+
export declare const publicJwkSchema: z.ZodObject<{
|
|
23
|
+
kty: z.ZodString;
|
|
24
|
+
kid: z.ZodString;
|
|
25
|
+
use: z.ZodOptional<z.ZodString>;
|
|
26
|
+
alg: z.ZodOptional<z.ZodString>;
|
|
27
|
+
crv: z.ZodOptional<z.ZodString>;
|
|
28
|
+
x: z.ZodOptional<z.ZodString>;
|
|
29
|
+
y: z.ZodOptional<z.ZodString>;
|
|
30
|
+
n: z.ZodOptional<z.ZodString>;
|
|
31
|
+
e: z.ZodOptional<z.ZodString>;
|
|
32
|
+
}, z.core.$strict>;
|
|
33
|
+
/**
|
|
34
|
+
* Durable signing-key lifecycle document schema.
|
|
35
|
+
*
|
|
36
|
+
* - CurrentKid: Identifier of the sole active key.
|
|
37
|
+
* - Keys: Complete provider-managed key lifecycle.
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* The neutral contract every provider's durable store must satisfy. Behavioural invariants
|
|
41
|
+
* beyond this shape (exactly one active key, status-consistent timestamps) live in
|
|
42
|
+
* {@link validateSigningKeyState}.
|
|
43
|
+
* @group Keys
|
|
44
|
+
* @category Key Providers
|
|
45
|
+
*/
|
|
46
|
+
export declare const signingKeyStateSchema: z.ZodObject<{
|
|
47
|
+
currentKid: z.ZodNullable<z.ZodString>;
|
|
48
|
+
keys: z.ZodArray<z.ZodObject<{
|
|
49
|
+
kid: z.ZodString;
|
|
50
|
+
providerKeyId: z.ZodString;
|
|
51
|
+
status: z.ZodEnum<{
|
|
52
|
+
pending: "pending";
|
|
53
|
+
active: "active";
|
|
54
|
+
retired: "retired";
|
|
55
|
+
}>;
|
|
56
|
+
publicJwk: z.ZodObject<{
|
|
57
|
+
kty: z.ZodString;
|
|
58
|
+
kid: z.ZodString;
|
|
59
|
+
use: z.ZodOptional<z.ZodString>;
|
|
60
|
+
alg: z.ZodOptional<z.ZodString>;
|
|
61
|
+
crv: z.ZodOptional<z.ZodString>;
|
|
62
|
+
x: z.ZodOptional<z.ZodString>;
|
|
63
|
+
y: z.ZodOptional<z.ZodString>;
|
|
64
|
+
n: z.ZodOptional<z.ZodString>;
|
|
65
|
+
e: z.ZodOptional<z.ZodString>;
|
|
66
|
+
}, z.core.$strict>;
|
|
67
|
+
activateAfter: z.ZodPipe<z.ZodString, z.ZodISODateTime>;
|
|
68
|
+
activatedAt: z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodISODateTime>>;
|
|
69
|
+
retiredAt: z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodISODateTime>>;
|
|
70
|
+
verifyUntil: z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodISODateTime>>;
|
|
71
|
+
}, z.core.$strict>>;
|
|
72
|
+
}, z.core.$strict>;
|
|
73
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/keys/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;kBAYjB,CAAC;AAEZ;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;kBAkBvB,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Public JSON Web Key material. */
|
|
2
|
+
export type PublicJwk = Readonly<{
|
|
3
|
+
kty: string;
|
|
4
|
+
kid: string;
|
|
5
|
+
use?: string;
|
|
6
|
+
alg?: string;
|
|
7
|
+
crv?: string;
|
|
8
|
+
x?: string;
|
|
9
|
+
y?: string;
|
|
10
|
+
n?: string;
|
|
11
|
+
e?: string;
|
|
12
|
+
}>;
|
|
13
|
+
/** Signing capability bound to one provider-managed key. */
|
|
14
|
+
export type SigningKeyHandle = Readonly<{
|
|
15
|
+
kid: string;
|
|
16
|
+
algorithm: 'ES256';
|
|
17
|
+
sign: (input: Uint8Array) => Promise<Uint8Array>;
|
|
18
|
+
}>;
|
|
19
|
+
/** Lifecycle state of a provider-managed signing key. */
|
|
20
|
+
export type SigningKeyStatus = 'pending' | 'active' | 'retired';
|
|
21
|
+
/**
|
|
22
|
+
* Durable metadata for one provider-managed signing key.
|
|
23
|
+
*
|
|
24
|
+
* - Kid: Public identifier carried with each signature.
|
|
25
|
+
* - ProviderKeyId: Opaque provider-owned key identifier.
|
|
26
|
+
* - Status: Current lifecycle status.
|
|
27
|
+
* - PublicJwk: Public verification key published through JWKS.
|
|
28
|
+
* - ActivateAfter: Earliest time when a pending key may become active.
|
|
29
|
+
* - ActivatedAt: Activation time, or null while pending.
|
|
30
|
+
* - RetiredAt: Retirement time, or null while active or pending.
|
|
31
|
+
* - VerifyUntil: Verification end time, or null while not retired.
|
|
32
|
+
*/
|
|
33
|
+
export type SigningKeyEntry = Readonly<{
|
|
34
|
+
kid: string;
|
|
35
|
+
providerKeyId: string;
|
|
36
|
+
status: SigningKeyStatus;
|
|
37
|
+
publicJwk: PublicJwk;
|
|
38
|
+
activateAfter: string;
|
|
39
|
+
activatedAt: string | null;
|
|
40
|
+
retiredAt: string | null;
|
|
41
|
+
verifyUntil: string | null;
|
|
42
|
+
}>;
|
|
43
|
+
/**
|
|
44
|
+
* Durable lifecycle state shared by the replicas that own one key set.
|
|
45
|
+
*
|
|
46
|
+
* - CurrentKid: Identifier of the sole active key.
|
|
47
|
+
* - Keys: Complete provider-managed key lifecycle.
|
|
48
|
+
*/
|
|
49
|
+
export type SigningKeyState = Readonly<{
|
|
50
|
+
currentKid: string | null;
|
|
51
|
+
keys: readonly SigningKeyEntry[];
|
|
52
|
+
}>;
|
|
53
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/keys/types.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,MAAM,MAAM,SAAS,GAAG,QAAQ,CAAC;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;CACZ,CAAC,CAAC;AAEH,4DAA4D;AAC5D,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC;IACtC,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;CAClD,CAAC,CAAC;AAEH,yDAAyD;AACzD,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEhE;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,gBAAgB,CAAC;IACzB,SAAS,EAAE,SAAS,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC;IACrC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,IAAI,EAAE,SAAS,eAAe,EAAE,CAAC;CAClC,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { SigningKeyState } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parses the signing-key lifecycle document and enforces every invariant providers rely on.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Shared by every signing-key provider so the lifecycle invariants have one definition:
|
|
7
|
+
* unique identifiers, an ES256 P-256 public JWK per entry whose `kid` matches its entry,
|
|
8
|
+
* status-consistent timestamps, exactly one active key, at most one pending key, and a
|
|
9
|
+
* `currentKid` that names the active key. Nothing downstream re-checks any of this, so a
|
|
10
|
+
* failure here is fatal on purpose.
|
|
11
|
+
* @group Keys
|
|
12
|
+
* @category Key Providers
|
|
13
|
+
* @param value - Raw lifecycle document read from a provider's durable store.
|
|
14
|
+
* @param algorithm - JOSE algorithm every published key must declare.
|
|
15
|
+
* @returns Validated signing-key state.
|
|
16
|
+
* @throws {CustomError} KEYS_PROVIDER_ERROR when any signing-key invariant fails.
|
|
17
|
+
*/
|
|
18
|
+
export declare function validateSigningKeyState(value: unknown, algorithm: 'ES256'): SigningKeyState;
|
|
19
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/keys/validation.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAmB,eAAe,EAAE,MAAM,YAAY,CAAC;AAEnE;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,OAAO,GACjB,eAAe,CA8DjB"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trusted authenticated request identity.
|
|
3
|
+
*
|
|
4
|
+
* - ActorId: Authenticated actor attributed as the author of record mutations.
|
|
5
|
+
* - TenantId: Tenant boundary scoping every record operation.
|
|
6
|
+
*
|
|
7
|
+
* @group Utils
|
|
8
|
+
* @category Execution Context
|
|
9
|
+
*/
|
|
10
|
+
export type AuthenticatedContext = Readonly<{
|
|
11
|
+
actorId: string;
|
|
12
|
+
tenantId: string;
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* Per-request tracing metadata.
|
|
16
|
+
*
|
|
17
|
+
* - RequestId: Correlation identifier carried through logs for one request or job.
|
|
18
|
+
*
|
|
19
|
+
* @group Utils
|
|
20
|
+
* @category Execution Context
|
|
21
|
+
*/
|
|
22
|
+
export type RequestContext = Readonly<{
|
|
23
|
+
requestId: string;
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* Request-scoped execution metadata established by transport middleware.
|
|
27
|
+
*
|
|
28
|
+
* - Authenticated: Trusted identity for the current request or job.
|
|
29
|
+
* - Request: Tracing metadata for the current request or job.
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* Bound to the async scope by {@link runWithExecutionCtx} and retrieved by
|
|
33
|
+
* {@link getExecutionCtx}, so downstream policy code such as {@link RecordsHandler} reads the
|
|
34
|
+
* caller's tenant and actor without threading them through every call.
|
|
35
|
+
* @group Utils
|
|
36
|
+
* @category Execution Context
|
|
37
|
+
*/
|
|
38
|
+
export type ExecutionContext = Readonly<{
|
|
39
|
+
authenticated: AuthenticatedContext;
|
|
40
|
+
request: RequestContext;
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* Runs one callback with the supplied execution context bound to the current async scope.
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* The context is visible to every asynchronous operation started within `callback` and is
|
|
47
|
+
* torn down when it returns, so nested calls to {@link getExecutionCtx} resolve the same
|
|
48
|
+
* identity without explicit propagation. Transport middleware wraps request handling in
|
|
49
|
+
* this call.
|
|
50
|
+
* @group Utils
|
|
51
|
+
* @category Execution Context
|
|
52
|
+
* @param context - Execution context for the current request or job.
|
|
53
|
+
* @param callback - Work executed while the context is available.
|
|
54
|
+
* @returns The callback return value.
|
|
55
|
+
*/
|
|
56
|
+
export declare function runWithExecutionCtx<T>(context: ExecutionContext, callback: () => T): T;
|
|
57
|
+
/**
|
|
58
|
+
* Reads the current execution context.
|
|
59
|
+
*
|
|
60
|
+
* @group Utils
|
|
61
|
+
* @category Execution Context
|
|
62
|
+
* @returns The active {@link ExecutionContext} for the current async scope.
|
|
63
|
+
* @throws {CustomError} RESOURCE_NOT_FOUND when called outside a {@link runWithExecutionCtx}
|
|
64
|
+
* scope, so no context is bound.
|
|
65
|
+
*/
|
|
66
|
+
export declare function getExecutionCtx(): ExecutionContext;
|
|
67
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/runtime/context.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AACH,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CAAC;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC,CAAC;AAEH;;;;;;;GAOG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC;IACpC,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC,CAAC;AAEH;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC;IACtC,aAAa,EAAE,oBAAoB,CAAC;IACpC,OAAO,EAAE,cAAc,CAAC;CACzB,CAAC,CAAC;AAMH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,CAEtF;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,IAAI,gBAAgB,CAYlD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { IAccessTokenVerifier } from './contracts.js';
|
|
2
|
+
import type { AccessTokenVerifyConfig } from './types.js';
|
|
3
|
+
import type { BearerToken } from './types.js';
|
|
4
|
+
import type { SessionGrant } from './types.js';
|
|
5
|
+
import type { IVerificationKeyProvider } from '../keys/contracts.js';
|
|
6
|
+
/**
|
|
7
|
+
* Verifies platform access tokens and reconstructs their session grant.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* Checks the protected header, resolves the public key by `kid` through the injected
|
|
11
|
+
* {@link IVerificationKeyProvider}, verifies signature, issuer, audience, and expiry with
|
|
12
|
+
* `jose`, then parses the claims with {@link accessTokenClaimsSchema}.
|
|
13
|
+
* @group Tokens
|
|
14
|
+
* @category Access Tokens
|
|
15
|
+
*/
|
|
16
|
+
export declare class AccessTokenVerifier implements IAccessTokenVerifier {
|
|
17
|
+
private readonly config;
|
|
18
|
+
private readonly keys;
|
|
19
|
+
/**
|
|
20
|
+
* @param config - Issuer, audience, and clock tolerance every token must satisfy.
|
|
21
|
+
* @param keys - Source of public verification keys by `kid`.
|
|
22
|
+
*/
|
|
23
|
+
constructor(config: AccessTokenVerifyConfig, keys: IVerificationKeyProvider);
|
|
24
|
+
/**
|
|
25
|
+
* Verifies one bearer access token.
|
|
26
|
+
*
|
|
27
|
+
* @param credential - Bearer credential selected by the transport layer.
|
|
28
|
+
* @returns Trusted session grant read from the token claims.
|
|
29
|
+
* @throws {CustomError} AUTHENTICATION_FAILED when the token is malformed, signed by an
|
|
30
|
+
* unknown key, expired, or carries incomplete claims.
|
|
31
|
+
* @throws {CustomError} EXTERNAL_API_ERROR or CONFIG_ERROR when the key provider fails;
|
|
32
|
+
* propagated unchanged.
|
|
33
|
+
*/
|
|
34
|
+
verify(credential: BearerToken): Promise<SessionGrant>;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=access-token-verifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access-token-verifier.d.ts","sourceRoot":"","sources":["../../src/tokens/access-token-verifier.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAE3D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAErE;;;;;;;;;GASG;AACH,qBAAa,mBAAoB,YAAW,oBAAoB;IAM5D,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,IAAI;IANvB;;;OAGG;gBAEgB,MAAM,EAAE,uBAAuB,EAC/B,IAAI,EAAE,wBAAwB;IAGjD;;;;;;;;;OASG;IACG,MAAM,CAAC,UAAU,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CA8C7D"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { BearerToken, SessionGrant } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Access-token verification boundary.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* {@link AccessTokenVerifier} is the shipped implementation. A consumer injects it behind
|
|
7
|
+
* this contract, so where the verification keys come from (an owned key set or a remote
|
|
8
|
+
* JWKS) is chosen at the composition root, not by the consumer.
|
|
9
|
+
* @group Tokens
|
|
10
|
+
* @category Access Tokens
|
|
11
|
+
*/
|
|
12
|
+
export interface IAccessTokenVerifier {
|
|
13
|
+
/**
|
|
14
|
+
* Verifies one bearer access credential.
|
|
15
|
+
*
|
|
16
|
+
* @param credential - Bearer credential selected by the route transport policy.
|
|
17
|
+
* @returns Trusted session grant reconstructed from the credential.
|
|
18
|
+
*/
|
|
19
|
+
verify(credential: BearerToken): Promise<SessionGrant>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=contracts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../src/tokens/contracts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE5D;;;;;;;;;GASG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,MAAM,CAAC,UAAU,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CACxD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tokens/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Access-token verification policy every verifier shares with the issuer.
|
|
4
|
+
*
|
|
5
|
+
* - Issuer: Required `iss`, the issuing service's base URL.
|
|
6
|
+
* - Audience: Required `aud`.
|
|
7
|
+
* - ClockToleranceSecs: Allowed clock skew when checking `exp` and `iat`.
|
|
8
|
+
*/
|
|
9
|
+
export declare const accessTokenVerifyConfigSchema: z.ZodObject<{
|
|
10
|
+
issuer: z.ZodURL;
|
|
11
|
+
audience: z.ZodString;
|
|
12
|
+
clockToleranceSecs: z.ZodNumber;
|
|
13
|
+
}, z.core.$strict>;
|
|
14
|
+
/**
|
|
15
|
+
* Platform claims carried by every access token.
|
|
16
|
+
*
|
|
17
|
+
* - Sid: Server-side session identifier.
|
|
18
|
+
* - Sub: Authenticated subject.
|
|
19
|
+
* - ActorId: Local actor represented by the session.
|
|
20
|
+
* - TenantId: Tenant the session belongs to.
|
|
21
|
+
* - Roles: Roles granted to the session.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* Not strict: `jwtVerify` already checks the registered claims (`iss`, `aud`, `iat`,
|
|
25
|
+
* `exp`), and parsing strips them.
|
|
26
|
+
*/
|
|
27
|
+
export declare const accessTokenClaimsSchema: z.ZodObject<{
|
|
28
|
+
sid: z.ZodString;
|
|
29
|
+
sub: z.ZodString;
|
|
30
|
+
actorId: z.ZodString;
|
|
31
|
+
tenantId: z.ZodString;
|
|
32
|
+
roles: z.ZodArray<z.ZodString>;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/tokens/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;GAMG;AACH,eAAO,MAAM,6BAA6B;;;;kBAM/B,CAAC;AAEZ;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,uBAAuB;;;;;;iBAMlC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { accessTokenClaimsSchema } from './schema.js';
|
|
3
|
+
import type { accessTokenVerifyConfigSchema } from './schema.js';
|
|
4
|
+
/** Trusted identity reconstructed from a verified access token. */
|
|
5
|
+
export type SessionGrant = Readonly<{
|
|
6
|
+
sessionId: string;
|
|
7
|
+
actorId: string;
|
|
8
|
+
tenantId: string;
|
|
9
|
+
subject: string;
|
|
10
|
+
roles: readonly string[];
|
|
11
|
+
}>;
|
|
12
|
+
/** Bearer credential extracted from the HTTP transport. */
|
|
13
|
+
export type BearerToken = Readonly<{
|
|
14
|
+
token: string;
|
|
15
|
+
}>;
|
|
16
|
+
/** Access-token verification policy every verifier shares with the issuer. */
|
|
17
|
+
export type AccessTokenVerifyConfig = z.infer<typeof accessTokenVerifyConfigSchema>;
|
|
18
|
+
/** Platform claims carried by every access token. */
|
|
19
|
+
export type AccessTokenClaims = z.infer<typeof accessTokenClaimsSchema>;
|
|
20
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tokens/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC;AAEjE,mEAAmE;AACnE,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1B,CAAC,CAAC;AAEH,2DAA2D;AAC3D,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAEtD,8EAA8E;AAC9E,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,6BAA6B,CAAC,CAAC;AAEpF,qDAAqD;AACrD,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC"}
|