@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,66 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Supported signing-key provider identifiers; grows as new providers are added.
|
|
4
|
+
*
|
|
5
|
+
* @group Keys
|
|
6
|
+
* @category Key Providers
|
|
7
|
+
*/
|
|
8
|
+
export declare const signingKeyProviderSchema: z.ZodEnum<{
|
|
9
|
+
jose: "jose";
|
|
10
|
+
openbao: "openbao";
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Signing-key provider selector resolved from the environment.
|
|
14
|
+
*
|
|
15
|
+
* - Provider: Active signing-key provider; read from `SIGNING_KEY_PROVIDER`.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* `provider` is marked `.meta({ env })`, so `loadEnvVariables` resolves it from
|
|
19
|
+
* `SIGNING_KEY_PROVIDER`; the active provider is chosen at runtime, never baked into the
|
|
20
|
+
* configuration file.
|
|
21
|
+
* @group Keys
|
|
22
|
+
* @category Key Providers
|
|
23
|
+
*/
|
|
24
|
+
export declare const signingKeyProviderSelectorSchema: z.ZodObject<{
|
|
25
|
+
provider: z.ZodEnum<{
|
|
26
|
+
jose: "jose";
|
|
27
|
+
openbao: "openbao";
|
|
28
|
+
}>;
|
|
29
|
+
}, z.core.$strict>;
|
|
30
|
+
/**
|
|
31
|
+
* Provider-neutral signing lifecycle schema.
|
|
32
|
+
*
|
|
33
|
+
* - Algorithm: JOSE algorithm supported by this key set.
|
|
34
|
+
* - Jose: Jose provider configuration, present when the deployment may select `jose`.
|
|
35
|
+
* - Openbao: OpenBao provider configuration, present when the deployment may select
|
|
36
|
+
* `openbao`.
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* Each provider block is optional so a deployment configures only the providers it uses;
|
|
40
|
+
* the active one is chosen at runtime by `SIGNING_KEY_PROVIDER` and must have its block
|
|
41
|
+
* present. Composed into each service's own `serviceConfigSchema` and validated there; core
|
|
42
|
+
* never reads a configuration file.
|
|
43
|
+
* @group Keys
|
|
44
|
+
* @category Key Providers
|
|
45
|
+
*/
|
|
46
|
+
export declare const signingKeysConfigSchema: z.ZodObject<{
|
|
47
|
+
algorithm: z.ZodLiteral<"ES256">;
|
|
48
|
+
jose: z.ZodOptional<z.ZodObject<{
|
|
49
|
+
keyNamePrefix: z.ZodString;
|
|
50
|
+
storage: z.ZodObject<{
|
|
51
|
+
filePath: z.ZodString;
|
|
52
|
+
passphrase: z.ZodString;
|
|
53
|
+
}, z.core.$strict>;
|
|
54
|
+
}, z.core.$strict>>;
|
|
55
|
+
openbao: z.ZodOptional<z.ZodObject<{
|
|
56
|
+
transitMount: z.ZodString;
|
|
57
|
+
kvMount: z.ZodString;
|
|
58
|
+
statePath: z.ZodString;
|
|
59
|
+
keyNamePrefix: z.ZodString;
|
|
60
|
+
requestTimeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
61
|
+
refreshCooldownSecs: z.ZodNumber;
|
|
62
|
+
baoAddr: z.ZodURL;
|
|
63
|
+
baoToken: z.ZodString;
|
|
64
|
+
}, z.core.$strict>>;
|
|
65
|
+
}, z.core.$strict>;
|
|
66
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/keys/config/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB;;;EAA8B,CAAC;AAEpE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gCAAgC;;;;;kBAIlC,CAAC;AAEZ;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;kBAMzB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { signingKeyProviderSchema } from './schema.js';
|
|
3
|
+
import type { signingKeysConfigSchema } from './schema.js';
|
|
4
|
+
/** Durable signing lifecycle and per-provider configuration. */
|
|
5
|
+
export type SigningKeysConfig = z.infer<typeof signingKeysConfigSchema>;
|
|
6
|
+
/** Signing-key provider selected at runtime by `SIGNING_KEY_PROVIDER`. */
|
|
7
|
+
export type SigningKeyProvider = z.infer<typeof signingKeyProviderSchema>;
|
|
8
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/keys/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE3D,gEAAgE;AAChE,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAExE,0EAA0E;AAC1E,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { CryptoKey } from 'jose';
|
|
2
|
+
import type { PublicJwk, SigningKeyHandle } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Owner of a key set that signs with it and lists its public keys.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* {@link JoseKeysProvider} and {@link OpenBaoKeysProvider} are the shipped implementations,
|
|
8
|
+
* each over the key set it owns. A consumer that only issues signatures depends on this
|
|
9
|
+
* role, never on {@link IVerificationKeyProvider} or {@link IKeysProvider}.
|
|
10
|
+
* @group Keys
|
|
11
|
+
* @category Key Providers
|
|
12
|
+
*/
|
|
13
|
+
export interface ISigningKeyProvider {
|
|
14
|
+
/** Loads durable state and ensures that an active key exists. */
|
|
15
|
+
initialize(): Promise<void>;
|
|
16
|
+
/** Returns a signer bound to the active key. */
|
|
17
|
+
getCurrentSigner(): Promise<SigningKeyHandle>;
|
|
18
|
+
/** Lists public keys eligible for JWKS publication. */
|
|
19
|
+
listPublicKeys(): Promise<readonly PublicJwk[]>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Source of public keys that verify signatures, looked up by key identifier.
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* {@link JoseKeysProvider} and {@link OpenBaoKeysProvider} implement it over the key set they
|
|
26
|
+
* own, next to {@link ISigningKeyProvider}; {@link JwksVerificationKeyProvider} implements it
|
|
27
|
+
* over a remote JWKS.
|
|
28
|
+
* @group Keys
|
|
29
|
+
* @category Key Providers
|
|
30
|
+
*/
|
|
31
|
+
export interface IVerificationKeyProvider {
|
|
32
|
+
/**
|
|
33
|
+
* Resolves an eligible public verification key by exact key identifier.
|
|
34
|
+
*
|
|
35
|
+
* @param kid - Key identifier carried with the signature.
|
|
36
|
+
* @returns The public key, or null when no eligible key has that identifier.
|
|
37
|
+
*/
|
|
38
|
+
getPublicKey(kid: string): Promise<CryptoKey | null>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Owner of a key set, which signs with it and verifies against it.
|
|
42
|
+
*
|
|
43
|
+
* @remarks
|
|
44
|
+
* Adds no members: it names the class the composition root builds once, which then hands
|
|
45
|
+
* each consumer only {@link ISigningKeyProvider} or {@link IVerificationKeyProvider}.
|
|
46
|
+
* {@link JoseKeysProvider} and {@link OpenBaoKeysProvider} are the shipped implementations.
|
|
47
|
+
* @group Keys
|
|
48
|
+
* @category Key Providers
|
|
49
|
+
*/
|
|
50
|
+
export interface IKeysProvider extends ISigningKeyProvider, IVerificationKeyProvider {
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=contracts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../src/keys/contracts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEtC,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9D;;;;;;;;;GASG;AACH,MAAM,WAAW,mBAAmB;IAClC,iEAAiE;IACjE,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5B,gDAAgD;IAChD,gBAAgB,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAE9C,uDAAuD;IACvD,cAAc,IAAI,OAAO,CAAC,SAAS,SAAS,EAAE,CAAC,CAAC;CACjD;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,wBAAwB;IACvC;;;;;OAKG;IACH,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;CACtD;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,aAAc,SAAQ,mBAAmB,EAAE,wBAAwB;CAAG"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { IKeysProvider } from './contracts.js';
|
|
2
|
+
import type { SigningKeysConfig } from './config/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Selects and constructs the keys provider named by `SIGNING_KEY_PROVIDER`.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Construction only: each provider resolves its own environment as it is constructed but
|
|
8
|
+
* performs no input or output, so all network and file work is deferred to `initialize()`.
|
|
9
|
+
* The `switch` is the single extension point; a new provider is a new enum member, a new
|
|
10
|
+
* `case`, and its own configuration block, with no change to the bootstrap step or the
|
|
11
|
+
* services that consume the provider. Returns the owner of the key set as
|
|
12
|
+
* {@link IKeysProvider}; the composition root hands each consumer only the role it uses.
|
|
13
|
+
* @group Keys
|
|
14
|
+
* @category Key Providers
|
|
15
|
+
* @param config - Signing lifecycle and per-provider configuration.
|
|
16
|
+
* @returns The keys provider named by `SIGNING_KEY_PROVIDER`, ready for `initialize()`.
|
|
17
|
+
* @throws {CustomError} ENV_VAR_ERROR when `SIGNING_KEY_PROVIDER` is missing or not a
|
|
18
|
+
* recognized provider, or (for OpenBao) when the provider's own variables are missing.
|
|
19
|
+
* @throws {CustomError} CONFIG_ERROR when the selected provider has no configuration block.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createKeysProvider(config: SigningKeysConfig): IKeysProvider;
|
|
22
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/keys/factory.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE3D;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,iBAAiB,GAAG,aAAa,CAiD3E"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './config/index.js';
|
|
2
|
+
export * from './contracts.js';
|
|
3
|
+
export * from './factory.js';
|
|
4
|
+
export * from './jose/index.js';
|
|
5
|
+
export * from './jwks/index.js';
|
|
6
|
+
export * from './openbao/index.js';
|
|
7
|
+
export * from './schema.js';
|
|
8
|
+
export * from './types.js';
|
|
9
|
+
export * from './validation.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/keys/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/keys/jose/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { KeyFilePayload } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Reads and decrypts the encrypted key file, or reports its absence.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* A decrypt or parse failure is reported, never swallowed: a wrong passphrase must fail
|
|
7
|
+
* loudly rather than be mistaken for an absent file, so a typo cannot discard the keys.
|
|
8
|
+
* @group Keys
|
|
9
|
+
* @category Key Providers
|
|
10
|
+
* @param filePath - Path to the encrypted key file.
|
|
11
|
+
* @param secret - Passphrase that decrypts the compact JWE.
|
|
12
|
+
* @returns Validated key-file payload, or null when no file exists.
|
|
13
|
+
* @throws {CustomError} KEYS_PROVIDER_ERROR when the file exists but cannot be read,
|
|
14
|
+
* decrypted, or parsed into a valid key-file payload.
|
|
15
|
+
*/
|
|
16
|
+
export declare function readKeyFile(filePath: string, secret: string): Promise<KeyFilePayload | null>;
|
|
17
|
+
/**
|
|
18
|
+
* Encrypts and writes the key file, creating it only when none already exists.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* The `wx` flag makes the create exclusive and `0o600` restricts it to the owner, so two
|
|
22
|
+
* processes racing on one host resolve to one winner; the loser sees the file already
|
|
23
|
+
* exists, is told so by the false return, and reads the winner's key instead of minting a
|
|
24
|
+
* second.
|
|
25
|
+
* @group Keys
|
|
26
|
+
* @category Key Providers
|
|
27
|
+
* @param filePath - Path to the encrypted key file.
|
|
28
|
+
* @param secret - Passphrase that encrypts the compact JWE.
|
|
29
|
+
* @param payload - Key-file payload to persist.
|
|
30
|
+
* @returns True when this call created the file, false when one already existed.
|
|
31
|
+
* @throws {CustomError} KEYS_PROVIDER_ERROR when encryption or the write fails for any
|
|
32
|
+
* reason other than the file already existing.
|
|
33
|
+
*/
|
|
34
|
+
export declare function writeKeyFile(filePath: string, secret: string, payload: KeyFilePayload): Promise<boolean>;
|
|
35
|
+
//# sourceMappingURL=jose-keyfile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jose-keyfile.d.ts","sourceRoot":"","sources":["../../../src/keys/jose/jose-keyfile.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AASjD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAqChC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,YAAY,CAChC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,OAAO,CAAC,CAqBlB"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { CryptoKey } from 'jose';
|
|
2
|
+
import type { IKeysProvider } from '../contracts.js';
|
|
3
|
+
import type { PublicJwk, SigningKeyHandle } from '../types.js';
|
|
4
|
+
import type { JoseSigningKeysConfig } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Node.js-native keys provider that keeps its key set in an encrypted local file.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Generates its own ES256 key on first run and keeps the private material in an encrypted
|
|
10
|
+
* file keyed from the environment, then signs and verifies against that one key set. It
|
|
11
|
+
* fits a small deployment: a single host, or replicas sharing one key file, with the file
|
|
12
|
+
* on a persistent volume and the file and `JOSE_KEYFILE_PASSPHRASE` backed up separately.
|
|
13
|
+
* Compared with {@link OpenBaoKeysProvider}, it accepts that the private key lives in
|
|
14
|
+
* process memory, that replacing the key file reissues every credential it signed, and that
|
|
15
|
+
* no policy layer limits key use; OpenBao is the choice when those costs are not
|
|
16
|
+
* acceptable. It serves one active key and never rotates.
|
|
17
|
+
* @group Keys
|
|
18
|
+
* @category Key Providers
|
|
19
|
+
*/
|
|
20
|
+
export declare class JoseKeysProvider implements IKeysProvider {
|
|
21
|
+
private readonly config;
|
|
22
|
+
private readonly algorithm;
|
|
23
|
+
/** Built once in initialize(); no rotation means no refresh machinery. */
|
|
24
|
+
private snapshot;
|
|
25
|
+
/**
|
|
26
|
+
* @param config - Validated Jose provider configuration.
|
|
27
|
+
* @param algorithm - JOSE algorithm enforced for the generated key.
|
|
28
|
+
*/
|
|
29
|
+
constructor(config: JoseSigningKeysConfig, algorithm: 'ES256');
|
|
30
|
+
/**
|
|
31
|
+
* Loads the encrypted key file and publishes the first snapshot, generating a key on
|
|
32
|
+
* first run when the file is absent.
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* Hard reset: delete the key file and restart. An absent file re-enters the
|
|
36
|
+
* generate-on-empty path and mints a fresh key, so there is no separate reset operation.
|
|
37
|
+
* The file is read once here, so deleting it while the process runs takes effect only on
|
|
38
|
+
* the next initialize(); the running provider keeps serving the key already in memory.
|
|
39
|
+
* This is a hard reset, not a rotation: the previous kid leaves the published key set at
|
|
40
|
+
* once and every credential it signed stops verifying. A decrypt failure fails loudly and
|
|
41
|
+
* is never treated as an empty file, so a wrong passphrase cannot discard the keys.
|
|
42
|
+
* @group Keys
|
|
43
|
+
* @category Key Providers
|
|
44
|
+
* @returns Completed provider initialization.
|
|
45
|
+
* @throws {CustomError} ENV_VAR_ERROR when the passphrase env variable is unset or blank.
|
|
46
|
+
* @throws {CustomError} KEYS_PROVIDER_ERROR when the file cannot be decrypted or violates
|
|
47
|
+
* a signing-key invariant.
|
|
48
|
+
*/
|
|
49
|
+
initialize(): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Returns a signer bound to the active key.
|
|
52
|
+
*
|
|
53
|
+
* @group Keys
|
|
54
|
+
* @category Key Providers
|
|
55
|
+
* @returns Provider-neutral signing capability.
|
|
56
|
+
* @throws {CustomError} KEYS_PROVIDER_ERROR when initialize() has not completed.
|
|
57
|
+
*/
|
|
58
|
+
getCurrentSigner(): Promise<SigningKeyHandle>;
|
|
59
|
+
/**
|
|
60
|
+
* Resolves one eligible public key by exact key identifier.
|
|
61
|
+
*
|
|
62
|
+
* @group Keys
|
|
63
|
+
* @category Key Providers
|
|
64
|
+
* @param kid - Key identifier carried with the signature.
|
|
65
|
+
* @returns Public verification key, or null for an unknown key.
|
|
66
|
+
* @throws {CustomError} KEYS_PROVIDER_ERROR when initialize() has not completed.
|
|
67
|
+
*/
|
|
68
|
+
getPublicKey(kid: string): Promise<CryptoKey | null>;
|
|
69
|
+
/**
|
|
70
|
+
* Lists the public keys eligible for JWKS publication.
|
|
71
|
+
*
|
|
72
|
+
* @group Keys
|
|
73
|
+
* @category Key Providers
|
|
74
|
+
* @returns Retained public JSON Web Keys.
|
|
75
|
+
* @throws {CustomError} KEYS_PROVIDER_ERROR when initialize() has not completed.
|
|
76
|
+
*/
|
|
77
|
+
listPublicKeys(): Promise<readonly PublicJwk[]>;
|
|
78
|
+
/**
|
|
79
|
+
* Generates the first key and writes it, adopting an existing file when a concurrent
|
|
80
|
+
* start won the race.
|
|
81
|
+
*
|
|
82
|
+
* @param secret - Passphrase that encrypts the key file.
|
|
83
|
+
* @returns The persisted key-file payload.
|
|
84
|
+
* @throws {CustomError} KEYS_PROVIDER_ERROR when the file cannot be written or re-read.
|
|
85
|
+
*/
|
|
86
|
+
private createKeyFile;
|
|
87
|
+
/**
|
|
88
|
+
* Generates one active ES256 key and the key-file payload that persists it.
|
|
89
|
+
*
|
|
90
|
+
* @returns Key-file payload with a single active key and its private material.
|
|
91
|
+
* @throws {CustomError} KEYS_PROVIDER_ERROR when the generated key is missing JWK
|
|
92
|
+
* coordinates.
|
|
93
|
+
*/
|
|
94
|
+
private generatePayload;
|
|
95
|
+
/**
|
|
96
|
+
* Validates the payload and publishes the in-process snapshot.
|
|
97
|
+
*
|
|
98
|
+
* @param payload - Key-file payload to project.
|
|
99
|
+
* @returns Completed snapshot publication.
|
|
100
|
+
* @throws {CustomError} KEYS_PROVIDER_ERROR when the state is invalid or a JWK cannot be
|
|
101
|
+
* imported as an asymmetric key.
|
|
102
|
+
*/
|
|
103
|
+
private publishSnapshot;
|
|
104
|
+
/**
|
|
105
|
+
* Returns the snapshot published by initialize().
|
|
106
|
+
*
|
|
107
|
+
* @returns The in-process projection of the signing-key state.
|
|
108
|
+
* @throws {CustomError} KEYS_PROVIDER_ERROR when initialize() has not completed.
|
|
109
|
+
*/
|
|
110
|
+
private currentSnapshot;
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=jose-keys-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jose-keys-provider.d.ts","sourceRoot":"","sources":["../../../src/keys/jose/jose-keys-provider.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAO,MAAM,MAAM,CAAC;AAK3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAIxD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,gBAAiB,YAAW,aAAa;IASlD,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAT5B,0EAA0E;IAC1E,OAAO,CAAC,QAAQ,CAAmC;IAEnD;;;OAGG;gBAEgB,MAAM,EAAE,qBAAqB,EAC7B,SAAS,EAAE,OAAO;IAGrC;;;;;;;;;;;;;;;;;;OAkBG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAcjC;;;;;;;OAOG;IACH,gBAAgB,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAsB7C;;;;;;;;OAQG;IACH,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IAIpD;;;;;;;OAOG;IACH,cAAc,IAAI,OAAO,CAAC,SAAS,SAAS,EAAE,CAAC;IAI/C;;;;;;;OAOG;YACW,aAAa;IA4B3B;;;;;;OAMG;YACW,eAAe;IAuD7B;;;;;;;OAOG;YACW,eAAe;IAsD7B;;;;;OAKG;IACH,OAAO,CAAC,eAAe;CAYxB"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Jose key-file storage schema.
|
|
4
|
+
*
|
|
5
|
+
* - FilePath: Path to the encrypted key file; must be listed in `.gitignore`.
|
|
6
|
+
* - Passphrase: Encrypted key-file passphrase; a secret, read from `JOSE_KEYFILE_PASSPHRASE`.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* `passphrase` is marked `.meta({ env })`, so `loadEnvVariables` resolves it from
|
|
10
|
+
* `JOSE_KEYFILE_PASSPHRASE`; the configuration file holds only a placeholder.
|
|
11
|
+
*/
|
|
12
|
+
export declare const joseStorageConfigSchema: z.ZodObject<{
|
|
13
|
+
filePath: z.ZodString;
|
|
14
|
+
passphrase: z.ZodString;
|
|
15
|
+
}, z.core.$strict>;
|
|
16
|
+
/**
|
|
17
|
+
* Jose provider configuration and local-storage schema.
|
|
18
|
+
*
|
|
19
|
+
* - KeyNamePrefix: Prefix for the generated `kid` and provider key identifier.
|
|
20
|
+
* - Storage: Encrypted key-file location and passphrase source.
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* Self-contained so the provider directory owns its whole storage story without the factory
|
|
24
|
+
* ever handling a file path or a secret.
|
|
25
|
+
*/
|
|
26
|
+
export declare const joseSigningKeysConfigSchema: z.ZodObject<{
|
|
27
|
+
keyNamePrefix: z.ZodString;
|
|
28
|
+
storage: z.ZodObject<{
|
|
29
|
+
filePath: z.ZodString;
|
|
30
|
+
passphrase: z.ZodString;
|
|
31
|
+
}, z.core.$strict>;
|
|
32
|
+
}, z.core.$strict>;
|
|
33
|
+
/**
|
|
34
|
+
* EC P-256 private JWK persisted in the encrypted key file.
|
|
35
|
+
*
|
|
36
|
+
* - Kty: Key type, always `EC`.
|
|
37
|
+
* - Crv: Curve, always `P-256`.
|
|
38
|
+
* - X: Public x coordinate.
|
|
39
|
+
* - Y: Public y coordinate.
|
|
40
|
+
* - D: Private scalar; the secret half, which is why the file is encrypted at rest.
|
|
41
|
+
*/
|
|
42
|
+
export declare const privateJwkSchema: z.ZodObject<{
|
|
43
|
+
kty: z.ZodLiteral<"EC">;
|
|
44
|
+
crv: z.ZodLiteral<"P-256">;
|
|
45
|
+
x: z.ZodString;
|
|
46
|
+
y: z.ZodString;
|
|
47
|
+
d: z.ZodString;
|
|
48
|
+
}, z.core.$strict>;
|
|
49
|
+
/**
|
|
50
|
+
* Decrypted key-file payload.
|
|
51
|
+
*
|
|
52
|
+
* - State: Signing-key lifecycle document shared with every provider.
|
|
53
|
+
* - PrivateJwks: Private signing material indexed by `kid`.
|
|
54
|
+
*/
|
|
55
|
+
export declare const keyFilePayloadSchema: z.ZodObject<{
|
|
56
|
+
state: z.ZodObject<{
|
|
57
|
+
currentKid: z.ZodNullable<z.ZodString>;
|
|
58
|
+
keys: z.ZodArray<z.ZodObject<{
|
|
59
|
+
kid: z.ZodString;
|
|
60
|
+
providerKeyId: z.ZodString;
|
|
61
|
+
status: z.ZodEnum<{
|
|
62
|
+
pending: "pending";
|
|
63
|
+
active: "active";
|
|
64
|
+
retired: "retired";
|
|
65
|
+
}>;
|
|
66
|
+
publicJwk: z.ZodObject<{
|
|
67
|
+
kty: z.ZodString;
|
|
68
|
+
kid: z.ZodString;
|
|
69
|
+
use: z.ZodOptional<z.ZodString>;
|
|
70
|
+
alg: z.ZodOptional<z.ZodString>;
|
|
71
|
+
crv: z.ZodOptional<z.ZodString>;
|
|
72
|
+
x: z.ZodOptional<z.ZodString>;
|
|
73
|
+
y: z.ZodOptional<z.ZodString>;
|
|
74
|
+
n: z.ZodOptional<z.ZodString>;
|
|
75
|
+
e: z.ZodOptional<z.ZodString>;
|
|
76
|
+
}, z.core.$strict>;
|
|
77
|
+
activateAfter: z.ZodPipe<z.ZodString, z.ZodISODateTime>;
|
|
78
|
+
activatedAt: z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodISODateTime>>;
|
|
79
|
+
retiredAt: z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodISODateTime>>;
|
|
80
|
+
verifyUntil: z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodISODateTime>>;
|
|
81
|
+
}, z.core.$strict>>;
|
|
82
|
+
}, z.core.$strict>;
|
|
83
|
+
privateJwks: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
84
|
+
kty: z.ZodLiteral<"EC">;
|
|
85
|
+
crv: z.ZodLiteral<"P-256">;
|
|
86
|
+
x: z.ZodString;
|
|
87
|
+
y: z.ZodString;
|
|
88
|
+
d: z.ZodString;
|
|
89
|
+
}, z.core.$strict>>;
|
|
90
|
+
}, z.core.$strict>;
|
|
91
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/keys/jose/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;;;;;;;;GASG;AACH,eAAO,MAAM,uBAAuB;;;kBAQzB,CAAC;AAEZ;;;;;;;;;GASG;AACH,eAAO,MAAM,2BAA2B;;;;;;kBAK7B,CAAC;AAEZ;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB;;;;;;kBAQlB,CAAC;AAEZ;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAKtB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { CryptoKey } from 'jose';
|
|
2
|
+
import type { z } from 'zod';
|
|
3
|
+
import type { PublicJwk } from '../types.js';
|
|
4
|
+
import type { SigningKeyState } from '../types.js';
|
|
5
|
+
import type { joseSigningKeysConfigSchema } from './schema.js';
|
|
6
|
+
import type { keyFilePayloadSchema } from './schema.js';
|
|
7
|
+
import type { privateJwkSchema } from './schema.js';
|
|
8
|
+
/** Validated Jose provider configuration and local-storage policy. */
|
|
9
|
+
export type JoseSigningKeysConfig = z.infer<typeof joseSigningKeysConfigSchema>;
|
|
10
|
+
/** Decrypted key-file payload persisted by the Jose provider. */
|
|
11
|
+
export type KeyFilePayload = z.infer<typeof keyFilePayloadSchema>;
|
|
12
|
+
/** EC P-256 private JWK persisted in the encrypted key file. */
|
|
13
|
+
export type PrivateJwk = z.infer<typeof privateJwkSchema>;
|
|
14
|
+
/**
|
|
15
|
+
* In-process projection of the Jose provider's signing-key state.
|
|
16
|
+
*
|
|
17
|
+
* - State: Validated lifecycle document the snapshot was built from.
|
|
18
|
+
* - Keys: Public JWK values eligible for JWKS publication.
|
|
19
|
+
* - ByKid: Imported public verification keys indexed by exact key identifier.
|
|
20
|
+
* - ActiveSigner: Active key identifier and its imported private signing key.
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* Named to match the OpenBao provider's equivalent projection. Built once in `initialize`
|
|
24
|
+
* and never refreshed, because the Jose provider serves one active key and never rotates.
|
|
25
|
+
*/
|
|
26
|
+
export type SigningKeySnapshot = Readonly<{
|
|
27
|
+
state: SigningKeyState;
|
|
28
|
+
keys: readonly PublicJwk[];
|
|
29
|
+
byKid: ReadonlyMap<string, CryptoKey>;
|
|
30
|
+
activeSigner: Readonly<{
|
|
31
|
+
kid: string;
|
|
32
|
+
privateKey: CryptoKey;
|
|
33
|
+
}>;
|
|
34
|
+
}>;
|
|
35
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/keys/jose/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,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,sEAAsE;AACtE,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEhF,iEAAiE;AACjE,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE,gEAAgE;AAChE,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC;IACxC,KAAK,EAAE,eAAe,CAAC;IACvB,IAAI,EAAE,SAAS,SAAS,EAAE,CAAC;IAC3B,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACtC,YAAY,EAAE,QAAQ,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,SAAS,CAAA;KAAE,CAAC,CAAC;CAChE,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/keys/jwks/index.ts"],"names":[],"mappings":"AAAA,cAAc,qCAAqC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CryptoKey } from 'jose';
|
|
2
|
+
import type { IVerificationKeyProvider } from '../contracts.js';
|
|
3
|
+
/**
|
|
4
|
+
* Verification keys read from a remote JWKS, such as auth's published key set.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Delegates fetching and caching to `jose`'s remote key set, which refetches on an unknown
|
|
8
|
+
* `kid` after its cooldown. A `kid` the set does not hold resolves to null; a key set that
|
|
9
|
+
* cannot be fetched or parsed is an infrastructure fault.
|
|
10
|
+
* @group Keys
|
|
11
|
+
* @category Key Providers
|
|
12
|
+
*/
|
|
13
|
+
export declare class JwksVerificationKeyProvider implements IVerificationKeyProvider {
|
|
14
|
+
private readonly jwks;
|
|
15
|
+
/** @param jwksUrl - Absolute URL of the JWKS document. */
|
|
16
|
+
constructor(jwksUrl: string);
|
|
17
|
+
/**
|
|
18
|
+
* Resolves an ES256 public key from the remote key set.
|
|
19
|
+
*
|
|
20
|
+
* @param kid - Key identifier carried with the signature.
|
|
21
|
+
* @returns The public key, or null when the key set has no key with that identifier.
|
|
22
|
+
* @throws {CustomError} EXTERNAL_API_ERROR when the key set cannot be fetched or is
|
|
23
|
+
* invalid.
|
|
24
|
+
*/
|
|
25
|
+
getPublicKey(kid: string): Promise<CryptoKey | null>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=jwks-verification-key-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwks-verification-key-provider.d.ts","sourceRoot":"","sources":["../../../src/keys/jwks/jwks-verification-key-provider.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEtC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAEhE;;;;;;;;;GASG;AACH,qBAAa,2BAA4B,YAAW,wBAAwB;IAC1E,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAwC;IAE7D,0DAA0D;gBAC9C,OAAO,EAAE,MAAM;IAI3B;;;;;;;OAOG;IACG,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;CAe3D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/keys/openbao/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,aAAa,CAAC"}
|