zitejs 0.10.0-start.26 → 0.10.0-start.27
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/dist/esm/signin/index.d.ts +1 -1
- package/dist/esm/signin/index.js +1 -1
- package/dist/esm/signin/keys.d.ts +10 -15
- package/dist/esm/signin/keys.js +30 -20
- package/dist/esm/signin/verify.d.ts +2 -2
- package/dist/esm/signin/verify.js +3 -6
- package/dist/esm/start/localSignIn.d.ts +1 -1
- package/dist/esm/start/localSignIn.js +1 -1
- package/dist/esm/start/version.d.ts +1 -1
- package/dist/esm/start/version.js +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { createSignIn, isSignInPath, PREVIEW_IDENTITY_HEADER, PREVIEW_IDENTITY_PARAM, type Resolution, type SignIn, type SignInConfig } from "./signin.js";
|
|
2
2
|
export { createIdentityVerifier, DEFAULT_MAX_LIFETIME_S, IDENTITY_TOKEN_TYPE, type IdentityClaims, type IdentityMode, type IdentityVerifier, type Refusal, type RefusalReport, type Verdict, type VerifyExpectations, } from "./verify.js";
|
|
3
|
-
export {
|
|
3
|
+
export { identityKeys, remoteIdentityKeys, staticIdentityKeys, type IdentityKeys, type IdentityKeySource, } from "./keys.js";
|
|
4
4
|
export { clearCookie, cookieName, isModuleCookie, MODULE_COOKIES, type CookieContext, type ModuleCookie } from "./cookies.js";
|
|
5
5
|
export { aesGcmSealer, type Sealer } from "./seal.js";
|
|
6
6
|
export { httpTransport, type ClientAuth, type HttpTransportOptions } from "./http.js";
|
package/dist/esm/signin/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// bundle, in an app's Worker and on Node alike.
|
|
3
3
|
export { createSignIn, isSignInPath, PREVIEW_IDENTITY_HEADER, PREVIEW_IDENTITY_PARAM } from "./signin.js";
|
|
4
4
|
export { createIdentityVerifier, DEFAULT_MAX_LIFETIME_S, IDENTITY_TOKEN_TYPE, } from "./verify.js";
|
|
5
|
-
export {
|
|
5
|
+
export { identityKeys, remoteIdentityKeys, staticIdentityKeys, } from "./keys.js";
|
|
6
6
|
export { clearCookie, cookieName, isModuleCookie, MODULE_COOKIES } from "./cookies.js";
|
|
7
7
|
export { aesGcmSealer } from "./seal.js";
|
|
8
8
|
export { httpTransport } from "./http.js";
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
/** The only kind of key an identity token may be signed with. App-token keys share the map under other kinds. */
|
|
2
|
-
export declare const IDENTITY_KEY_KIND = "zite-identity";
|
|
3
1
|
/**
|
|
4
|
-
* The
|
|
5
|
-
*
|
|
6
|
-
* another kind's key is refused by name.
|
|
2
|
+
* The identity issuer's public keys by `kid`, each its raw Ed25519 key (base64url), as read from the issuer's JWK Set
|
|
3
|
+
* (RFC 7517): the dispatcher's `ZITE_IDENTITY_JWKS`, or the backend's `jwks_uri` off Zite.
|
|
7
4
|
*/
|
|
8
|
-
export type IdentityKeys = Readonly<Record<string,
|
|
9
|
-
kind: string;
|
|
10
|
-
key: string;
|
|
11
|
-
}>>;
|
|
5
|
+
export type IdentityKeys = Readonly<Record<string, string>>;
|
|
12
6
|
/** Where a verifier finds keys: what it holds now, and a refetch for a `kid` it doesn't know. */
|
|
13
7
|
export type IdentityKeySource = {
|
|
14
8
|
current(): IdentityKeys;
|
|
@@ -16,17 +10,18 @@ export type IdentityKeySource = {
|
|
|
16
10
|
refresh(): Promise<IdentityKeys | undefined>;
|
|
17
11
|
};
|
|
18
12
|
/**
|
|
19
|
-
* Parses the
|
|
20
|
-
*
|
|
13
|
+
* Parses the identity issuer's JWK Set. A document that isn't one, or a `kid` two usable keys share, throws, so a bad
|
|
14
|
+
* deploy fails at once. A key it can't verify with (another key type or curve, another `alg` or `use`, no `kid`) is
|
|
15
|
+
* skipped, so a key type the issuer adds later doesn't break an older zitejs.
|
|
21
16
|
*/
|
|
22
17
|
export declare const identityKeys: (json: string) => IdentityKeys;
|
|
23
|
-
/** Keys that never change: the dispatcher's configured
|
|
18
|
+
/** Keys that never change: the dispatcher's configured set. */
|
|
24
19
|
export declare const staticIdentityKeys: (keys: IdentityKeys) => IdentityKeySource;
|
|
25
|
-
/** For tests: forget every fetched key
|
|
20
|
+
/** For tests: forget every fetched key set. */
|
|
26
21
|
export declare const resetFetchedIdentityKeys: () => void;
|
|
27
22
|
/**
|
|
28
|
-
* Keys from `url` (the backend's
|
|
29
|
-
* one per request; concurrent refreshes on it share one fetch.
|
|
23
|
+
* Keys from `url` (the backend's identity JWK Set), refetched on an unknown `kid` at most once a minute per process.
|
|
24
|
+
* Make one per request; concurrent refreshes on it share one fetch.
|
|
30
25
|
*/
|
|
31
26
|
export declare const remoteIdentityKeys: (url: string, options?: {
|
|
32
27
|
initial?: IdentityKeys;
|
package/dist/esm/signin/keys.js
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import { fromBase64Url, isRecord } from "./encoding.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
const KEY_SET_NAME = "the identity JWK Set";
|
|
3
|
+
const usableKey = (jwk) => isRecord(jwk) &&
|
|
4
|
+
jwk.kty === "OKP" &&
|
|
5
|
+
jwk.crv === "Ed25519" &&
|
|
6
|
+
(jwk.alg === undefined || jwk.alg === "EdDSA") &&
|
|
7
|
+
(jwk.use === undefined || jwk.use === "sig") &&
|
|
8
|
+
typeof jwk.kid === "string" &&
|
|
9
|
+
/^[A-Za-z0-9_-]{1,64}$/.test(jwk.kid) &&
|
|
10
|
+
typeof jwk.x === "string" &&
|
|
11
|
+
fromBase64Url(jwk.x)?.length === 32
|
|
12
|
+
? { kid: jwk.kid, x: jwk.x }
|
|
13
|
+
: undefined;
|
|
5
14
|
/**
|
|
6
|
-
* Parses the
|
|
7
|
-
*
|
|
15
|
+
* Parses the identity issuer's JWK Set. A document that isn't one, or a `kid` two usable keys share, throws, so a bad
|
|
16
|
+
* deploy fails at once. A key it can't verify with (another key type or curve, another `alg` or `use`, no `kid`) is
|
|
17
|
+
* skipped, so a key type the issuer adds later doesn't break an older zitejs.
|
|
8
18
|
*/
|
|
9
19
|
export const identityKeys = (json) => {
|
|
10
20
|
let parsed;
|
|
@@ -14,21 +24,21 @@ export const identityKeys = (json) => {
|
|
|
14
24
|
catch {
|
|
15
25
|
parsed = undefined;
|
|
16
26
|
}
|
|
17
|
-
if (!isRecord(parsed))
|
|
18
|
-
throw new Error(`${
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (
|
|
26
|
-
throw new Error(`${
|
|
27
|
-
keys[kid] =
|
|
27
|
+
if (!isRecord(parsed) || !Array.isArray(parsed.keys))
|
|
28
|
+
throw new Error(`${KEY_SET_NAME} must be a JSON object with a keys array`);
|
|
29
|
+
// No prototype, so a `kid` of `__proto__` is a key like any other.
|
|
30
|
+
const keys = Object.create(null);
|
|
31
|
+
for (const jwk of parsed.keys) {
|
|
32
|
+
const key = usableKey(jwk);
|
|
33
|
+
if (!key)
|
|
34
|
+
continue;
|
|
35
|
+
if (Object.hasOwn(keys, key.kid))
|
|
36
|
+
throw new Error(`${KEY_SET_NAME}: key ${key.kid} is in it twice`);
|
|
37
|
+
keys[key.kid] = key.x;
|
|
28
38
|
}
|
|
29
39
|
return keys;
|
|
30
40
|
};
|
|
31
|
-
/** Keys that never change: the dispatcher's configured
|
|
41
|
+
/** Keys that never change: the dispatcher's configured set. */
|
|
32
42
|
export const staticIdentityKeys = (keys) => ({
|
|
33
43
|
current: () => keys,
|
|
34
44
|
refresh: async () => undefined,
|
|
@@ -38,11 +48,11 @@ const FETCH_TIMEOUT_MS = 5_000;
|
|
|
38
48
|
// Per process, only fetched keys and when a fetch last started: Workers ties a fetch to the request that made it, so a
|
|
39
49
|
// pending one is never shared across requests. Another request inside the minute keeps the keys it has.
|
|
40
50
|
const fetched = new Map();
|
|
41
|
-
/** For tests: forget every fetched key
|
|
51
|
+
/** For tests: forget every fetched key set. */
|
|
42
52
|
export const resetFetchedIdentityKeys = () => fetched.clear();
|
|
43
53
|
/**
|
|
44
|
-
* Keys from `url` (the backend's
|
|
45
|
-
* one per request; concurrent refreshes on it share one fetch.
|
|
54
|
+
* Keys from `url` (the backend's identity JWK Set), refetched on an unknown `kid` at most once a minute per process.
|
|
55
|
+
* Make one per request; concurrent refreshes on it share one fetch.
|
|
46
56
|
*/
|
|
47
57
|
export const remoteIdentityKeys = (url, options = {}) => {
|
|
48
58
|
const now = options.now ?? Date.now;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { IdentityKeySource } from "./keys.js";
|
|
2
2
|
export type IdentityMode = "live" | "preview" | "demo" | "dev";
|
|
3
3
|
/** The `typ` every identity token carries in its header, and nothing else does. */
|
|
4
4
|
export declare const IDENTITY_TOKEN_TYPE = "zite-id+jwt";
|
|
@@ -33,7 +33,7 @@ export type IdentityClaims = {
|
|
|
33
33
|
};
|
|
34
34
|
};
|
|
35
35
|
/** Why a token was refused. Each is a forgery, a token from somewhere else, or a bug; never a lapse of time. */
|
|
36
|
-
export type Refusal = "malformed" | "alg" | "typ" | "kid" | "
|
|
36
|
+
export type Refusal = "malformed" | "alg" | "typ" | "kid" | "signature" | "iss" | "aud" | "azp" | "iat" | "lifetime" | "sub" | "mode" | "claims" | "preview" | "nonce";
|
|
37
37
|
/**
|
|
38
38
|
* `expired` and `stale` (issued under another org settings version) are genuine and renewable; `refused` is not and
|
|
39
39
|
* clears the cookie.
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// The identity token's verifier (T5 design §6.1), the same rules as restly's `identityToken.ts` on the front and the
|
|
2
2
|
// dispatcher. Web Crypto only.
|
|
3
3
|
import { fromBase64Url, isRecord, jsonOf, utf8 } from "./encoding.js";
|
|
4
|
-
import { IDENTITY_KEY_KIND } from "./keys.js";
|
|
5
4
|
/** The `typ` every identity token carries in its header, and nothing else does. */
|
|
6
5
|
export const IDENTITY_TOKEN_TYPE = "zite-id+jwt";
|
|
7
6
|
export const DEFAULT_MAX_LIFETIME_S = 300;
|
|
@@ -112,12 +111,10 @@ export const createIdentityVerifier = (keys, options = {}) => async (token, expe
|
|
|
112
111
|
if (kid === undefined)
|
|
113
112
|
return refuse("kid");
|
|
114
113
|
const own = (map) => (map && Object.hasOwn(map, kid) ? map[kid] : undefined);
|
|
115
|
-
const
|
|
116
|
-
if (!
|
|
114
|
+
const raw = own(keys.current()) ?? own(await keys.refresh());
|
|
115
|
+
if (!raw)
|
|
117
116
|
return refuse("kid", kid);
|
|
118
|
-
|
|
119
|
-
return refuse("key kind", kid);
|
|
120
|
-
const key = await publicKey(entry.key);
|
|
117
|
+
const key = await publicKey(raw);
|
|
121
118
|
const genuine = !!key && (await crypto.subtle.verify({ name: "Ed25519" }, key, signature, utf8(`${headerPart}.${payloadPart}`)));
|
|
122
119
|
if (!genuine)
|
|
123
120
|
return refuse("signature", kid);
|
|
@@ -6,7 +6,7 @@ export declare const LOCAL_SIGNIN_ENV: {
|
|
|
6
6
|
readonly secret: "ZITE_AUTH_SECRET";
|
|
7
7
|
};
|
|
8
8
|
type Env = Record<string, string | undefined>;
|
|
9
|
-
/** Where the backend serves the
|
|
9
|
+
/** Where the backend serves the identity issuer's JWK Set, for an unknown `kid`. */
|
|
10
10
|
export declare const SIGNING_KEYS_PATH = "/v1/zite/public/start/signing-keys";
|
|
11
11
|
/**
|
|
12
12
|
* The module for this request, when the env names an issuer; undefined otherwise, and whenever `ZITE_DEV_USER` is
|
|
@@ -20,7 +20,7 @@ const configOf = (raw) => {
|
|
|
20
20
|
}
|
|
21
21
|
return config;
|
|
22
22
|
};
|
|
23
|
-
/** Where the backend serves the
|
|
23
|
+
/** Where the backend serves the identity issuer's JWK Set, for an unknown `kid`. */
|
|
24
24
|
export const SIGNING_KEYS_PATH = "/v1/zite/public/start/signing-keys";
|
|
25
25
|
const send = (request) => platformFetch(request);
|
|
26
26
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const ZITEJS_VERSION = "0.10.0-start.
|
|
1
|
+
export declare const ZITEJS_VERSION = "0.10.0-start.27";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Written by scripts/write-version.mjs from package.json.
|
|
2
|
-
export const ZITEJS_VERSION = "0.10.0-start.
|
|
2
|
+
export const ZITEJS_VERSION = "0.10.0-start.27";
|