@salamandradevs/core 0.1.3 → 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/infra/database/database-provider.js +3 -1
- package/dist/infra/database/mongo/mongo-db-connection.js +14 -2
- package/dist/infra/database/mysql/mysql-db-connection.js +16 -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/infra/database/contracts.d.ts +9 -1
- package/types/infra/database/contracts.d.ts.map +1 -1
- package/types/infra/database/database-provider.d.ts +2 -0
- package/types/infra/database/database-provider.d.ts.map +1 -1
- package/types/infra/database/mongo/mongo-db-connection.d.ts +2 -0
- package/types/infra/database/mongo/mongo-db-connection.d.ts.map +1 -1
- package/types/infra/database/mysql/mysql-db-connection.d.ts +2 -0
- package/types/infra/database/mysql/mysql-db-connection.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,175 @@
|
|
|
1
|
+
import type { CryptoKey } from 'jose';
|
|
2
|
+
import type { IKeysProvider } from '../contracts.js';
|
|
3
|
+
import type { PublicJwk, SigningKeyHandle } from '../types.js';
|
|
4
|
+
import type { OpenBaoSigningKeysConfig } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Durable OpenBao-backed keys provider that signs with Transit and verifies locally.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Private signing keys never enter this process. OpenBao holds the private material and
|
|
10
|
+
* performs signatures; the signing keys document records which key is active and which
|
|
11
|
+
* retired keys are still verifiable. An operator owns that document and the signing keys it
|
|
12
|
+
* names.
|
|
13
|
+
*
|
|
14
|
+
* It hands a consumer a signer bound to the active key, resolves a public key by `kid` for
|
|
15
|
+
* verification, and lists the public keys eligible for JWKS publication. Its token needs
|
|
16
|
+
* only `read` on the document path and `update` on the signing path; see
|
|
17
|
+
* `docs/en/howto/openbao/README.md` for how keys are provisioned and rotated.
|
|
18
|
+
*
|
|
19
|
+
* Operationally: every signature costs one OpenBao call, so an unreachable or sealed
|
|
20
|
+
* OpenBao stops all issuance. Verification of already-signed credentials is served from the
|
|
21
|
+
* in-process snapshot with no network call, so they survive an outage that blocks new
|
|
22
|
+
* ones.
|
|
23
|
+
* @group Keys
|
|
24
|
+
* @category Key Providers
|
|
25
|
+
*/
|
|
26
|
+
export declare class OpenBaoKeysProvider implements IKeysProvider {
|
|
27
|
+
private readonly config;
|
|
28
|
+
private readonly algorithm;
|
|
29
|
+
private readonly refreshCooldownSecs;
|
|
30
|
+
/** Last validated signing key state, projected for verification and JWKS reads. */
|
|
31
|
+
private snapshot;
|
|
32
|
+
/** Single-flight wrapper over refreshSnapshot; concurrent callers share one document read. */
|
|
33
|
+
private readonly synchronize;
|
|
34
|
+
/** OpenBao origin read from `BAO_ADDR`. */
|
|
35
|
+
private readonly baseUrl;
|
|
36
|
+
/** Runtime OpenBao token read from `BAO_TOKEN`. */
|
|
37
|
+
private readonly token;
|
|
38
|
+
/**
|
|
39
|
+
* @param config - Validated OpenBao key namespace and request policy configuration.
|
|
40
|
+
* @param algorithm - JOSE algorithm enforced for all signing keys.
|
|
41
|
+
* @param refreshCooldownSecs - Minimum time between two re-reads of the lifecycle
|
|
42
|
+
* document triggered by an unknown `kid`; it bounds how often a verification miss may
|
|
43
|
+
* synchronize the snapshot from OpenBao.
|
|
44
|
+
* @throws {CustomError} ENV_VAR_ERROR when `BAO_ADDR` or `BAO_TOKEN` is missing, blank,
|
|
45
|
+
* or malformed.
|
|
46
|
+
*/
|
|
47
|
+
constructor(config: OpenBaoSigningKeysConfig, algorithm: 'ES256', refreshCooldownSecs: number);
|
|
48
|
+
/**
|
|
49
|
+
* Loads the signing keys document and publishes the first snapshot.
|
|
50
|
+
*
|
|
51
|
+
* @group Keys
|
|
52
|
+
* @category Key Providers
|
|
53
|
+
* @returns Completed provider initialization.
|
|
54
|
+
* @throws {CustomError} KEYS_PROVIDER_ERROR when no signing keys document exists or it
|
|
55
|
+
* violates its invariants.
|
|
56
|
+
* @throws {CustomError} EXTERNAL_API_ERROR when OpenBao is unreachable or answers
|
|
57
|
+
* unusably.
|
|
58
|
+
*/
|
|
59
|
+
initialize(): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Selects the active key and returns a signer bound to that key.
|
|
62
|
+
*
|
|
63
|
+
* @group Keys
|
|
64
|
+
* @category Key Providers
|
|
65
|
+
* @returns Provider-neutral signing capability.
|
|
66
|
+
* @throws {CustomError} KEYS_PROVIDER_ERROR when durable state has no usable active key.
|
|
67
|
+
*/
|
|
68
|
+
getCurrentSigner(): Promise<SigningKeyHandle>;
|
|
69
|
+
/**
|
|
70
|
+
* Resolves one eligible public key by exact key identifier.
|
|
71
|
+
*
|
|
72
|
+
* @group Keys
|
|
73
|
+
* @category Key Providers
|
|
74
|
+
* @param kid - Key identifier carried with the signature.
|
|
75
|
+
* @returns Public verification key, or null for an unknown or expired key.
|
|
76
|
+
* @throws {CustomError} EXTERNAL_API_ERROR when a synchronize is due but OpenBao prevents
|
|
77
|
+
* it, so an outage is never reported as an unknown key.
|
|
78
|
+
*/
|
|
79
|
+
getPublicKey(kid: string): Promise<CryptoKey | null>;
|
|
80
|
+
/**
|
|
81
|
+
* Synchronizes, then lists the keys currently eligible for JWKS publication.
|
|
82
|
+
*
|
|
83
|
+
* @group Keys
|
|
84
|
+
* @category Key Providers
|
|
85
|
+
* @returns Retained public JSON Web Keys.
|
|
86
|
+
* @throws {CustomError} EXTERNAL_API_ERROR when OpenBao prevents the synchronize, so a
|
|
87
|
+
* stale snapshot is never served as though it had succeeded.
|
|
88
|
+
*/
|
|
89
|
+
listPublicKeys(): Promise<readonly PublicJwk[]>;
|
|
90
|
+
/**
|
|
91
|
+
* Returns the published snapshot, synchronizing once if none has been built yet.
|
|
92
|
+
*
|
|
93
|
+
* @returns The most recently published projection of durable signing key state.
|
|
94
|
+
* @throws {CustomError} KEYS_PROVIDER_ERROR when a synchronize completed without
|
|
95
|
+
* publishing.
|
|
96
|
+
*/
|
|
97
|
+
private currentSnapshot;
|
|
98
|
+
/**
|
|
99
|
+
* Reads the signing keys document and rebuilds the published snapshot; the work each
|
|
100
|
+
* synchronize performs.
|
|
101
|
+
*
|
|
102
|
+
* @returns Completed synchronize with a freshly published snapshot.
|
|
103
|
+
* @throws {CustomError} KEYS_PROVIDER_ERROR when no signing keys document exists.
|
|
104
|
+
*/
|
|
105
|
+
private refreshSnapshot;
|
|
106
|
+
/**
|
|
107
|
+
* Signs one exact JWS signing input with a captured signing key.
|
|
108
|
+
*
|
|
109
|
+
* @param providerKeyId - Signing key name captured when the signer was selected.
|
|
110
|
+
* @param input - Exact JWS signing input bytes to sign.
|
|
111
|
+
* @returns Raw 64-byte ES256 signature.
|
|
112
|
+
* @throws {CustomError} EXTERNAL_API_ERROR when OpenBao signs with an unpublished version
|
|
113
|
+
* or returns a signature of the wrong length.
|
|
114
|
+
*/
|
|
115
|
+
private signWithTransit;
|
|
116
|
+
/**
|
|
117
|
+
* Reads and validates the signing keys document, or reports its absence.
|
|
118
|
+
*
|
|
119
|
+
* @returns Validated state, or null when no document exists.
|
|
120
|
+
* @throws {CustomError} KEYS_PROVIDER_ERROR when the document exists but is not a signing
|
|
121
|
+
* keys document, or violates a signing key invariant.
|
|
122
|
+
*/
|
|
123
|
+
private readSigningKeyState;
|
|
124
|
+
/**
|
|
125
|
+
* Projects validated state into the in-memory snapshot that serves verification and JWKS.
|
|
126
|
+
*
|
|
127
|
+
* @param state - Validated signing key state to project.
|
|
128
|
+
* @returns Completed snapshot publication.
|
|
129
|
+
* @throws {CustomError} KEYS_PROVIDER_ERROR when an entry holds a non-public JWK.
|
|
130
|
+
*/
|
|
131
|
+
private publishSnapshot;
|
|
132
|
+
/**
|
|
133
|
+
* Parses a Transit sign response into the raw ES256 signature bytes.
|
|
134
|
+
*
|
|
135
|
+
* @param marshaledSignature - Raw `signature` string returned by Transit's sign endpoint.
|
|
136
|
+
* @param providerKeyId - Transit key name, named in the error when the version is
|
|
137
|
+
* unexpected.
|
|
138
|
+
* @returns Raw 64-byte ES256 signature.
|
|
139
|
+
* @throws {CustomError} EXTERNAL_API_ERROR when Transit signed with an unpublished key
|
|
140
|
+
* version or returned a signature of the wrong length.
|
|
141
|
+
*/
|
|
142
|
+
private parseTransitSignature;
|
|
143
|
+
/**
|
|
144
|
+
* Performs one OpenBao HTTP call and converts every failure into a classified
|
|
145
|
+
* `CustomError`.
|
|
146
|
+
*
|
|
147
|
+
* @param operation - Short label naming the step, retained in the error cause.
|
|
148
|
+
* @param path - Absolute OpenBao API path, including the `/v1` prefix.
|
|
149
|
+
* @param init - Method and body for the request.
|
|
150
|
+
* @param schema - Optional response schema; the body is validated when one is supplied.
|
|
151
|
+
* @param schema.parse - Validator applied to the parsed response body.
|
|
152
|
+
* @returns The validated response body, or the raw body when no schema is supplied.
|
|
153
|
+
* @throws {CustomError} EXTERNAL_API_ERROR on any transport failure, timeout, or
|
|
154
|
+
* non-success status.
|
|
155
|
+
*/
|
|
156
|
+
private request;
|
|
157
|
+
/**
|
|
158
|
+
* Classifies one non-success OpenBao status into an actionable error.
|
|
159
|
+
*
|
|
160
|
+
* @param operation - Short label naming the step.
|
|
161
|
+
* @param path - Absolute OpenBao API path that failed.
|
|
162
|
+
* @param status - HTTP status OpenBao returned.
|
|
163
|
+
* @param raw - Parsed response body, consulted only for its sanitized error list.
|
|
164
|
+
* @returns The classified error, for the caller to throw.
|
|
165
|
+
*/
|
|
166
|
+
private failure;
|
|
167
|
+
/**
|
|
168
|
+
* Narrows an unknown error to the structured cause this class attaches to its failures.
|
|
169
|
+
*
|
|
170
|
+
* @param error - Error to inspect.
|
|
171
|
+
* @returns The cause when the error came from this provider's transport, else undefined.
|
|
172
|
+
*/
|
|
173
|
+
private failureCause;
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=openbao-keys-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openbao-keys-provider.d.ts","sourceRoot":"","sources":["../../../src/keys/openbao/openbao-keys-provider.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAOtC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAK/D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAO3D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,mBAAoB,YAAW,aAAa;IAuBrD,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IAxBtC,mFAAmF;IACnF,OAAO,CAAC,QAAQ,CAAmC;IAEnD,8FAA8F;IAC9F,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA8C;IAE1E,2CAA2C;IAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC,mDAAmD;IACnD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAE/B;;;;;;;;OAQG;gBAEgB,MAAM,EAAE,wBAAwB,EAChC,SAAS,EAAE,OAAO,EAClB,mBAAmB,EAAE,MAAM;IAU9C;;;;;;;;;;OAUG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAOjC;;;;;;;OAOG;IACG,gBAAgB,IAAI,OAAO,CAAC,gBAAgB,CAAC;IA8BnD;;;;;;;;;OASG;IACG,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IA+B1D;;;;;;;;OAQG;IACG,cAAc,IAAI,OAAO,CAAC,SAAS,SAAS,EAAE,CAAC;IAUrD;;;;;;OAMG;YACW,eAAe;IAiB7B;;;;;;OAMG;YACW,eAAe;IAkB7B;;;;;;;;OAQG;YACW,eAAe;IAyB7B;;;;;;OAMG;YACW,mBAAmB;IAsDjC;;;;;;OAMG;YACW,eAAe;IAwC7B;;;;;;;;;OASG;IACH,OAAO,CAAC,qBAAqB;IAqC7B;;;;;;;;;;;;OAYG;YACW,OAAO;IAoDrB;;;;;;;;OAQG;IACH,OAAO,CAAC,OAAO;IAoCf;;;;;OAKG;IACH,OAAO,CAAC,YAAY;CAWrB"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* OpenBao key namespace, request policy, and connection schema.
|
|
4
|
+
*
|
|
5
|
+
* - TransitMount: Transit secrets-engine mount.
|
|
6
|
+
* - KvMount: KV v2 secrets-engine mount.
|
|
7
|
+
* - StatePath: KV path containing lifecycle state.
|
|
8
|
+
* - KeyNamePrefix: Prefix for provider-managed Transit keys.
|
|
9
|
+
* - RequestTimeoutMs: Deadline applied to every OpenBao HTTP request.
|
|
10
|
+
* - RefreshCooldownSecs: Minimum time between two re-reads of the lifecycle document
|
|
11
|
+
* triggered by an unknown `kid`.
|
|
12
|
+
* - BaoAddr: OpenBao origin without embedded credentials; read from `BAO_ADDR`.
|
|
13
|
+
* - BaoToken: Runtime OpenBao token; a secret, read from `BAO_TOKEN`.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* `baoAddr` and `baoToken` are marked `.meta({ env })`, so `loadEnvVariables` resolves them
|
|
17
|
+
* from `BAO_ADDR` and `BAO_TOKEN` and hands the values to the provider; the configuration
|
|
18
|
+
* file holds only placeholders, so the token never appears in the config object.
|
|
19
|
+
*/
|
|
20
|
+
export declare const openBaoSigningKeysConfigSchema: z.ZodObject<{
|
|
21
|
+
transitMount: z.ZodString;
|
|
22
|
+
kvMount: z.ZodString;
|
|
23
|
+
statePath: z.ZodString;
|
|
24
|
+
keyNamePrefix: z.ZodString;
|
|
25
|
+
requestTimeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
26
|
+
refreshCooldownSecs: z.ZodNumber;
|
|
27
|
+
baoAddr: z.ZodURL;
|
|
28
|
+
baoToken: z.ZodString;
|
|
29
|
+
}, z.core.$strict>;
|
|
30
|
+
/**
|
|
31
|
+
* KV v2 lifecycle-state read response schema.
|
|
32
|
+
*
|
|
33
|
+
* - Data: KV envelope carrying the stored document and its version metadata.
|
|
34
|
+
*
|
|
35
|
+
* @remarks
|
|
36
|
+
* OpenBao wraps every logical response in an envelope carrying `request_id`, `lease_id`,
|
|
37
|
+
* `lease_duration`, `renewable`, `warnings`, `wrap_info`, `auth` and `mount_type`, and the
|
|
38
|
+
* version metadata adds `created_time`, `custom_metadata`, `deletion_time` and `destroyed`.
|
|
39
|
+
* None of these response schemas may be `strict`, because those unmodelled fields are
|
|
40
|
+
* always present. Verified against OpenBao 2.7.0.
|
|
41
|
+
*/
|
|
42
|
+
export declare const openBaoKvReadResponseSchema: z.ZodObject<{
|
|
43
|
+
data: z.ZodObject<{
|
|
44
|
+
data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
45
|
+
metadata: z.ZodObject<{
|
|
46
|
+
version: z.ZodNumber;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
}, z.core.$strip>;
|
|
50
|
+
/**
|
|
51
|
+
* Transit signing response schema.
|
|
52
|
+
*
|
|
53
|
+
* - Data: JWS-formatted signature returned by Transit.
|
|
54
|
+
*/
|
|
55
|
+
export declare const openBaoTransitSignResponseSchema: z.ZodObject<{
|
|
56
|
+
data: z.ZodObject<{
|
|
57
|
+
signature: z.ZodString;
|
|
58
|
+
}, z.core.$strip>;
|
|
59
|
+
}, z.core.$strip>;
|
|
60
|
+
/**
|
|
61
|
+
* OpenBao error response schema.
|
|
62
|
+
*
|
|
63
|
+
* - Errors: Sanitized error messages returned by OpenBao.
|
|
64
|
+
*/
|
|
65
|
+
export declare const openBaoErrorResponseSchema: z.ZodObject<{
|
|
66
|
+
errors: z.ZodArray<z.ZodString>;
|
|
67
|
+
}, z.core.$strip>;
|
|
68
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/keys/openbao/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,8BAA8B;;;;;;;;;kBAchC,CAAC;AAEZ;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,2BAA2B;;;;;;;iBAKtC,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,gCAAgC;;;;iBAE3C,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,0BAA0B;;iBAA4C,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { CryptoKey } from 'jose';
|
|
2
|
+
import type { z } from 'zod';
|
|
3
|
+
import type { PublicJwk } from '../types.js';
|
|
4
|
+
import type { SigningKeyEntry, SigningKeyState } from '../types.js';
|
|
5
|
+
import type { openBaoKvReadResponseSchema } from './schema.js';
|
|
6
|
+
import type { openBaoSigningKeysConfigSchema } from './schema.js';
|
|
7
|
+
import type { openBaoTransitSignResponseSchema } from './schema.js';
|
|
8
|
+
/** OpenBao key namespace, request policy, and connection configuration. */
|
|
9
|
+
export type OpenBaoSigningKeysConfig = z.infer<typeof openBaoSigningKeysConfigSchema>;
|
|
10
|
+
/** KV v2 read response containing the lifecycle state document. */
|
|
11
|
+
export type OpenBaoKvReadResponse = z.infer<typeof openBaoKvReadResponseSchema>;
|
|
12
|
+
/** Transit response containing a JWS-formatted signature. */
|
|
13
|
+
export type OpenBaoTransitSignResponse = z.infer<typeof openBaoTransitSignResponseSchema>;
|
|
14
|
+
/**
|
|
15
|
+
* Structured cause attached to every OpenBao transport failure.
|
|
16
|
+
*
|
|
17
|
+
* - Operation: Short label naming the lifecycle step that failed.
|
|
18
|
+
* - Path: OpenBao API path that was requested.
|
|
19
|
+
* - Status: HTTP status returned, absent when the request never completed.
|
|
20
|
+
*/
|
|
21
|
+
export type OpenBaoFailureCause = Readonly<{
|
|
22
|
+
operation: string;
|
|
23
|
+
path: string;
|
|
24
|
+
status?: number;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Imported public key and lifecycle metadata retained in the local snapshot.
|
|
28
|
+
*
|
|
29
|
+
* - Key: Imported public Web Crypto verification key.
|
|
30
|
+
* - Status: Durable lifecycle status.
|
|
31
|
+
* - VerifyUntil: Retirement verification deadline, if applicable.
|
|
32
|
+
*/
|
|
33
|
+
export type CachedKey = Readonly<{
|
|
34
|
+
key: CryptoKey;
|
|
35
|
+
status: SigningKeyEntry['status'];
|
|
36
|
+
verifyUntil: string | null;
|
|
37
|
+
}>;
|
|
38
|
+
/**
|
|
39
|
+
* Atomic in-process projection of the last validated lifecycle state.
|
|
40
|
+
*
|
|
41
|
+
* - LoadedAt: Local timestamp when the snapshot was built.
|
|
42
|
+
* - State: Durable state represented by the snapshot.
|
|
43
|
+
* - Keys: Public JWK values eligible for publication.
|
|
44
|
+
* - ByKid: Imported verification keys indexed by exact key identifier.
|
|
45
|
+
*/
|
|
46
|
+
export type SigningKeySnapshot = Readonly<{
|
|
47
|
+
loadedAt: number;
|
|
48
|
+
state: SigningKeyState;
|
|
49
|
+
keys: readonly PublicJwk[];
|
|
50
|
+
byKid: ReadonlyMap<string, CachedKey>;
|
|
51
|
+
}>;
|
|
52
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/keys/openbao/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,aAAa,CAAC;AAEpE,2EAA2E;AAC3E,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAC;AAEtF,mEAAmE;AACnE,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEhF,6DAA6D;AAC7D,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gCAAgC,CAAC,CAAC;AAE1F;;;;;;GAMG;AACH,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,GAAG,QAAQ,CAAC;IAC/B,GAAG,EAAE,SAAS,CAAC;IACf,MAAM,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC;IAClC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,CAAC,CAAC;AAEH;;;;;;;GAOG;AACH,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,eAAe,CAAC;IACvB,IAAI,EAAE,SAAS,SAAS,EAAE,CAAC;IAC3B,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;CACvC,CAAC,CAAC"}
|
|
@@ -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
|