@suveren/gateway 0.7.6 → 0.8.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/content/integrations/mollie.json +103 -28
- package/dist/mcp-server/http.mjs +228 -118
- package/dist/ui/assets/{index-CsrM6RQr.js → index-BFnSVa9N.js} +22 -22
- package/dist/ui/index.html +1 -1
- package/node_modules/@hap/core/dist/index.d.mts +29 -6
- package/node_modules/@hap/core/dist/index.d.ts +29 -6
- package/node_modules/@hap/core/dist/index.js +54 -8
- package/node_modules/@hap/core/dist/index.mjs +53 -8
- package/node_modules/@hap/core/package.json +2 -1
- package/node_modules/@hap/core/src/frame.ts +115 -14
- package/node_modules/@hap/core/src/gatekeeper.ts +26 -0
- package/node_modules/@hap/core/src/types.ts +7 -1
- package/node_modules/@types/node/README.md +1 -1
- package/node_modules/@types/node/buffer.buffer.d.ts +5 -0
- package/node_modules/@types/node/crypto.d.ts +0 -2
- package/node_modules/@types/node/dgram.d.ts +119 -4
- package/node_modules/@types/node/ffi.d.ts +1 -1
- package/node_modules/@types/node/fs/promises.d.ts +61 -65
- package/node_modules/@types/node/fs.d.ts +86 -76
- package/node_modules/@types/node/http.d.ts +1 -1
- package/node_modules/@types/node/http2.d.ts +2 -2
- package/node_modules/@types/node/index.d.ts +1 -0
- package/node_modules/@types/node/inspector.d.ts +2 -1
- package/node_modules/@types/node/net.d.ts +108 -16
- package/node_modules/@types/node/package.json +2 -2
- package/node_modules/@types/node/quic.d.ts +37 -11
- package/node_modules/@types/node/stream/iter.d.ts +4 -4
- package/node_modules/@types/node/tls.d.ts +24 -0
- package/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +5 -0
- package/node_modules/@types/node/ts5.6/index.d.ts +1 -0
- package/node_modules/@types/node/ts5.7/index.d.ts +1 -0
- package/node_modules/@types/node/tty.d.ts +4 -3
- package/node_modules/@types/node/vfs.d.ts +210 -0
- package/node_modules/@types/node/vm.d.ts +1 -1
- package/node_modules/express-rate-limit/dist/index.cjs +6 -3
- package/node_modules/express-rate-limit/dist/index.d.cts +11 -0
- package/node_modules/express-rate-limit/dist/index.d.mts +11 -0
- package/node_modules/express-rate-limit/dist/index.d.ts +11 -0
- package/node_modules/express-rate-limit/dist/index.mjs +6 -3
- package/node_modules/express-rate-limit/{license.md → license} +7 -6
- package/node_modules/express-rate-limit/package.json +5 -5
- package/node_modules/express-rate-limit/readme.md +1 -0
- package/node_modules/fast-uri/index.js +20 -5
- package/node_modules/fast-uri/lib/utils.js +8 -1
- package/node_modules/fast-uri/package.json +1 -1
- package/node_modules/fast-uri/test/component-safe-serialization.test.js +58 -0
- package/node_modules/fast-uri/test/ipv6-validation.test.js +34 -0
- package/node_modules/ip-address/README.md +92 -82
- package/node_modules/ip-address/dist/common.d.ts +20 -0
- package/node_modules/ip-address/dist/common.js +36 -0
- package/node_modules/ip-address/dist/common.js.map +1 -1
- package/node_modules/ip-address/dist/ipv4.d.ts +50 -0
- package/node_modules/ip-address/dist/ipv4.js +75 -0
- package/node_modules/ip-address/dist/ipv4.js.map +1 -1
- package/node_modules/ip-address/dist/ipv6.d.ts +79 -10
- package/node_modules/ip-address/dist/ipv6.js +120 -30
- package/node_modules/ip-address/dist/ipv6.js.map +1 -1
- package/node_modules/ip-address/dist/v4/constants.d.ts +12 -0
- package/node_modules/ip-address/dist/v4/constants.js +40 -1
- package/node_modules/ip-address/dist/v4/constants.js.map +1 -1
- package/node_modules/ip-address/dist/v6/constants.d.ts +14 -0
- package/node_modules/ip-address/dist/v6/constants.js +47 -1
- package/node_modules/ip-address/dist/v6/constants.js.map +1 -1
- package/node_modules/ip-address/package.json +1 -1
- package/node_modules/jose/dist/types/jwe/compact/decrypt.d.ts +7 -16
- package/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +6 -17
- package/node_modules/jose/dist/types/jwe/flattened/decrypt.d.ts +7 -16
- package/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +11 -34
- package/node_modules/jose/dist/types/jwe/general/decrypt.d.ts +7 -16
- package/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +15 -35
- package/node_modules/jose/dist/types/jwk/embedded.d.ts +3 -8
- package/node_modules/jose/dist/types/jwk/thumbprint.d.ts +5 -5
- package/node_modules/jose/dist/types/jwks/local.d.ts +6 -10
- package/node_modules/jose/dist/types/jwks/remote.d.ts +13 -24
- package/node_modules/jose/dist/types/jws/compact/sign.d.ts +5 -10
- package/node_modules/jose/dist/types/jws/compact/verify.d.ts +9 -18
- package/node_modules/jose/dist/types/jws/flattened/sign.d.ts +7 -16
- package/node_modules/jose/dist/types/jws/flattened/verify.d.ts +9 -18
- package/node_modules/jose/dist/types/jws/general/sign.d.ts +11 -21
- package/node_modules/jose/dist/types/jws/general/verify.d.ts +9 -18
- package/node_modules/jose/dist/types/jwt/decrypt.d.ts +10 -20
- package/node_modules/jose/dist/types/jwt/encrypt.d.ts +6 -13
- package/node_modules/jose/dist/types/jwt/sign.d.ts +5 -6
- package/node_modules/jose/dist/types/jwt/unsecured.d.ts +9 -14
- package/node_modules/jose/dist/types/jwt/verify.d.ts +9 -19
- package/node_modules/jose/dist/types/key/export.d.ts +4 -4
- package/node_modules/jose/dist/types/key/generate_key_pair.d.ts +6 -8
- package/node_modules/jose/dist/types/key/generate_secret.d.ts +4 -11
- package/node_modules/jose/dist/types/key/import.d.ts +10 -17
- package/node_modules/jose/dist/types/types.d.ts +44 -84
- package/node_modules/jose/dist/types/util/base64url.d.ts +2 -2
- package/node_modules/jose/dist/types/util/decode_jwt.d.ts +3 -10
- package/node_modules/jose/dist/types/util/decode_protected_header.d.ts +4 -4
- package/node_modules/jose/dist/types/util/errors.d.ts +26 -53
- package/node_modules/jose/dist/webapi/index.js +70 -32
- package/node_modules/jose/dist/webapi/jwe/compact/decrypt.js +7 -8
- package/node_modules/jose/dist/webapi/jwe/compact/encrypt.js +42 -48
- package/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js +14 -14
- package/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js +53 -64
- package/node_modules/jose/dist/webapi/jwe/general/decrypt.js +38 -49
- package/node_modules/jose/dist/webapi/jwe/general/encrypt.js +121 -169
- package/node_modules/jose/dist/webapi/jwk/embedded.js +30 -32
- package/node_modules/jose/dist/webapi/jwk/thumbprint.js +54 -70
- package/node_modules/jose/dist/webapi/jwks/local.js +47 -64
- package/node_modules/jose/dist/webapi/jwks/remote.js +88 -136
- package/node_modules/jose/dist/webapi/jws/compact/sign.js +21 -21
- package/node_modules/jose/dist/webapi/jws/compact/verify.js +7 -8
- package/node_modules/jose/dist/webapi/jws/flattened/sign.js +29 -31
- package/node_modules/jose/dist/webapi/jws/flattened/verify.js +21 -24
- package/node_modules/jose/dist/webapi/jws/general/sign.js +61 -72
- package/node_modules/jose/dist/webapi/jws/general/verify.js +45 -69
- package/node_modules/jose/dist/webapi/jwt/decrypt.js +13 -20
- package/node_modules/jose/dist/webapi/jwt/encrypt.js +57 -70
- package/node_modules/jose/dist/webapi/jwt/sign.js +17 -16
- package/node_modules/jose/dist/webapi/jwt/unsecured.js +32 -40
- package/node_modules/jose/dist/webapi/jwt/verify.js +12 -14
- package/node_modules/jose/dist/webapi/key/export.js +32 -37
- package/node_modules/jose/dist/webapi/key/generate_key_pair.js +40 -48
- package/node_modules/jose/dist/webapi/key/generate_secret.js +35 -40
- package/node_modules/jose/dist/webapi/key/import.js +52 -56
- package/node_modules/jose/dist/webapi/lib/asn1.js +130 -169
- package/node_modules/jose/dist/webapi/lib/base64.js +18 -20
- package/node_modules/jose/dist/webapi/lib/buffer_utils.js +34 -38
- package/node_modules/jose/dist/webapi/lib/content_encryption.js +79 -115
- package/node_modules/jose/dist/webapi/lib/crypto_key.js +24 -25
- package/node_modules/jose/dist/webapi/lib/deflate.js +45 -47
- package/node_modules/jose/dist/webapi/lib/helpers.js +40 -37
- package/node_modules/jose/dist/webapi/lib/invalid_key_input.js +10 -24
- package/node_modules/jose/dist/webapi/lib/is_key_like.js +17 -15
- package/node_modules/jose/dist/webapi/lib/jwe_algorithms.js +106 -93
- package/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +207 -230
- package/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +104 -138
- package/node_modules/jose/dist/webapi/lib/jwk_metadata.js +17 -18
- package/node_modules/jose/dist/webapi/lib/jwk_to_key.js +9 -16
- package/node_modules/jose/dist/webapi/lib/jws_algorithms.js +62 -61
- package/node_modules/jose/dist/webapi/lib/jws_sign.js +50 -75
- package/node_modules/jose/dist/webapi/lib/jws_verify.js +80 -125
- package/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +123 -209
- package/node_modules/jose/dist/webapi/lib/key.js +84 -136
- package/node_modules/jose/dist/webapi/lib/key_algorithm.js +13 -8
- package/node_modules/jose/dist/webapi/lib/key_descriptor.js +8 -6
- package/node_modules/jose/dist/webapi/lib/key_management.js +200 -231
- package/node_modules/jose/dist/webapi/lib/key_options.js +7 -5
- package/node_modules/jose/dist/webapi/lib/options.js +55 -68
- package/node_modules/jose/dist/webapi/lib/signing.js +18 -22
- package/node_modules/jose/dist/webapi/lib/type_checks.js +26 -29
- package/node_modules/jose/dist/webapi/util/base64url.js +26 -35
- package/node_modules/jose/dist/webapi/util/decode_jwt.js +32 -31
- package/node_modules/jose/dist/webapi/util/decode_protected_header.js +18 -23
- package/node_modules/jose/dist/webapi/util/errors.js +94 -84
- package/node_modules/jose/package.json +17 -81
- package/package.json +2 -2
- package/profiles/calendar/0.5.profile.json +190 -0
- package/profiles/charge/0.5.profile.json +210 -0
- package/profiles/customers/0.7.profile.json +157 -0
- package/profiles/deploy/0.9.profile.json +176 -0
- package/profiles/email/0.6.profile.json +208 -0
- package/profiles/index.json +9 -1
- package/profiles/publish/0.5.profile.json +186 -0
- package/profiles/purchase/0.5.profile.json +231 -0
- package/profiles/records/0.5.profile.json +117 -0
|
@@ -1,70 +1,53 @@
|
|
|
1
|
-
import { jwkToKey } from
|
|
2
|
-
import { JWS } from
|
|
3
|
-
import { JWKSInvalid, JOSENotSupported, JWKSNoMatchingKey, JWKSMultipleMatchingKeys
|
|
4
|
-
import { isJwkSet } from
|
|
5
|
-
import { snapshotJwk } from
|
|
1
|
+
import { jwkToKey } from "../lib/jwk_to_key.js";
|
|
2
|
+
import { JWS } from "../lib/jws_algorithms.js";
|
|
3
|
+
import { JWKSInvalid, JOSENotSupported, JWKSNoMatchingKey, JWKSMultipleMatchingKeys } from "../util/errors.js";
|
|
4
|
+
import { isJwkSet } from "../lib/type_checks.js";
|
|
5
|
+
import { snapshotJwk } from "../lib/jwk_metadata.js";
|
|
6
6
|
function isUsableJWK(jwk, entry, alg, kid) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return ((ext === undefined || typeof ext === 'boolean') &&
|
|
10
|
-
(keyOps === undefined ||
|
|
11
|
-
(Array.isArray(keyOps) &&
|
|
12
|
-
keyOps.every((operation, index) => typeof operation === 'string' && keyOps.indexOf(operation) === index) &&
|
|
13
|
-
keyOps.includes('verify'))) &&
|
|
14
|
-
entry.kty.includes(kty) &&
|
|
15
|
-
(kid === undefined || (typeof kid === 'string' && kid === jwkKid)) &&
|
|
16
|
-
(jwkAlg === undefined ? kty !== 'AKP' : alg === jwkAlg) &&
|
|
17
|
-
(use === undefined || use === 'sig') &&
|
|
18
|
-
(!entry.crv || crv === entry.crv));
|
|
7
|
+
const { kty, key_ops, ext, kid: jwkKid, alg: jwkAlg, use, crv } = snapshotJwk(jwk), keyOps = Array.isArray(key_ops) ? [...key_ops] : key_ops;
|
|
8
|
+
return (ext === void 0 || typeof ext == "boolean") && (keyOps === void 0 || Array.isArray(keyOps) && keyOps.every((operation, index) => typeof operation == "string" && keyOps.indexOf(operation) === index) && keyOps.includes("verify")) && entry.kty.includes(kty) && (kid === void 0 || typeof kid == "string" && kid === jwkKid) && (jwkAlg === void 0 ? kty !== "AKP" : alg === jwkAlg) && (use === void 0 || use === "sig") && (!entry.crv || crv === entry.crv);
|
|
19
9
|
}
|
|
20
10
|
async function importWithAlgCache(cache, jwk, entry) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
return cached[alg];
|
|
11
|
+
const cached = cache.get(jwk) || cache.set(jwk, {}).get(jwk), { alg } = entry;
|
|
12
|
+
if (cached[alg] === void 0) {
|
|
13
|
+
const key = await jwkToKey(entry, { ...jwk, alg, ext: !0 });
|
|
14
|
+
if (key.type !== "public")
|
|
15
|
+
throw new JWKSInvalid("JSON Web Key Set members must be public keys");
|
|
16
|
+
cached[alg] = key;
|
|
17
|
+
}
|
|
18
|
+
return cached[alg];
|
|
31
19
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
20
|
+
function createLocalJWKSet(jwks) {
|
|
21
|
+
let snapshot;
|
|
22
|
+
try {
|
|
23
|
+
snapshot = structuredClone(jwks);
|
|
24
|
+
} catch {
|
|
25
|
+
}
|
|
26
|
+
if (!isJwkSet(snapshot))
|
|
27
|
+
throw new JWKSInvalid("JSON Web Key Set malformed");
|
|
28
|
+
const cached = /* @__PURE__ */ new WeakMap();
|
|
29
|
+
return Object.defineProperty(async (protectedHeader, token) => {
|
|
30
|
+
const { alg, kid } = { ...protectedHeader, ...token?.header }, entry = typeof alg == "string" ? JWS[alg] : void 0;
|
|
31
|
+
if (!entry || entry.secret)
|
|
32
|
+
throw new JOSENotSupported('Unsupported "alg" value for a JSON Web Key Set');
|
|
33
|
+
const candidates = snapshot.keys.filter((jwk2) => isUsableJWK(jwk2, entry, alg, kid)), { 0: jwk, length } = candidates;
|
|
34
|
+
if (!length)
|
|
35
|
+
throw new JWKSNoMatchingKey();
|
|
36
|
+
if (length !== 1) {
|
|
37
|
+
const error = new JWKSMultipleMatchingKeys();
|
|
38
|
+
throw error[Symbol.asyncIterator] = async function* () {
|
|
39
|
+
for (const jwk2 of candidates)
|
|
40
|
+
try {
|
|
41
|
+
yield await importWithAlgCache(cached, jwk2, entry);
|
|
42
|
+
} catch {
|
|
43
|
+
}
|
|
44
|
+
}, error;
|
|
40
45
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (!entry || entry.secret) {
|
|
46
|
-
throw new JOSENotSupported('Unsupported "alg" value for a JSON Web Key Set');
|
|
47
|
-
}
|
|
48
|
-
const candidates = snapshot.keys.filter((jwk) => isUsableJWK(jwk, entry, alg, kid));
|
|
49
|
-
const { 0: jwk, length } = candidates;
|
|
50
|
-
if (!length) {
|
|
51
|
-
throw new JWKSNoMatchingKey();
|
|
52
|
-
}
|
|
53
|
-
if (length !== 1) {
|
|
54
|
-
const error = new JWKSMultipleMatchingKeys();
|
|
55
|
-
error[Symbol.asyncIterator] = async function* () {
|
|
56
|
-
for (const jwk of candidates) {
|
|
57
|
-
try {
|
|
58
|
-
yield await importWithAlgCache(cached, jwk, entry);
|
|
59
|
-
}
|
|
60
|
-
catch { }
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
throw error;
|
|
64
|
-
}
|
|
65
|
-
return importWithAlgCache(cached, jwk, entry);
|
|
66
|
-
};
|
|
67
|
-
return Object.defineProperty(localJWKSet, 'jwks', {
|
|
68
|
-
value: () => structuredClone(snapshot),
|
|
69
|
-
});
|
|
46
|
+
return importWithAlgCache(cached, jwk, entry);
|
|
47
|
+
}, "jwks", {
|
|
48
|
+
value: () => structuredClone(snapshot)
|
|
49
|
+
});
|
|
70
50
|
}
|
|
51
|
+
export {
|
|
52
|
+
createLocalJWKSet
|
|
53
|
+
};
|
|
@@ -1,149 +1,101 @@
|
|
|
1
|
-
import { JOSEError, JWKSNoMatchingKey, JWKSTimeout } from
|
|
2
|
-
import { createLocalJWKSet } from
|
|
3
|
-
import { isJwkSet } from
|
|
1
|
+
import { JOSEError, JWKSNoMatchingKey, JWKSTimeout } from "../util/errors.js";
|
|
2
|
+
import { createLocalJWKSet } from "./local.js";
|
|
3
|
+
import { isJwkSet } from "../lib/type_checks.js";
|
|
4
4
|
function isCloudflareWorkers() {
|
|
5
|
-
|
|
6
|
-
(typeof navigator !== 'undefined' && navigator.userAgent === 'Cloudflare-Workers') ||
|
|
7
|
-
(typeof EdgeRuntime !== 'undefined' && EdgeRuntime === 'vercel'));
|
|
5
|
+
return typeof WebSocketPair < "u" || typeof navigator < "u" && navigator.userAgent === "Cloudflare-Workers" || typeof EdgeRuntime < "u" && EdgeRuntime === "vercel";
|
|
8
6
|
}
|
|
9
7
|
let USER_AGENT;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const VERSION = 'v6.2.10';
|
|
13
|
-
USER_AGENT = `${NAME}/${VERSION}`;
|
|
14
|
-
}
|
|
15
|
-
export const customFetch = Symbol();
|
|
8
|
+
(typeof navigator > "u" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) && (USER_AGENT = "jose/v6.2.11");
|
|
9
|
+
const customFetch = /* @__PURE__ */ Symbol();
|
|
16
10
|
async function fetchJwks(url, headers, signal, fetchImpl = fetch) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return await response.json();
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
throw new JOSEError('Failed to parse the JSON Web Key Set HTTP response as JSON');
|
|
36
|
-
}
|
|
11
|
+
const response = await fetchImpl(url, {
|
|
12
|
+
method: "GET",
|
|
13
|
+
signal,
|
|
14
|
+
redirect: "manual",
|
|
15
|
+
headers
|
|
16
|
+
}).catch((err) => {
|
|
17
|
+
throw err.name === "TimeoutError" ? new JWKSTimeout() : err;
|
|
18
|
+
});
|
|
19
|
+
if (response.status !== 200)
|
|
20
|
+
throw new JOSEError("Expected 200 OK from the JSON Web Key Set HTTP response");
|
|
21
|
+
try {
|
|
22
|
+
return await response.json();
|
|
23
|
+
} catch {
|
|
24
|
+
throw new JOSEError("Failed to parse the JSON Web Key Set HTTP response as JSON");
|
|
25
|
+
}
|
|
37
26
|
}
|
|
38
|
-
|
|
27
|
+
const jwksCache = /* @__PURE__ */ Symbol();
|
|
39
28
|
function isFreshFor(timestamp, duration) {
|
|
40
|
-
|
|
29
|
+
return Number.isFinite(timestamp) && Date.now() < timestamp + duration;
|
|
41
30
|
}
|
|
42
31
|
function validateDuration(value, fallback, option) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return typeof value === 'number' ? value : fallback;
|
|
32
|
+
if (Number.isNaN(value))
|
|
33
|
+
throw new TypeError(`"${option}" option must not be NaN`);
|
|
34
|
+
return typeof value == "number" ? value : fallback;
|
|
47
35
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
36
|
+
function createRemoteJWKSet(url, options) {
|
|
37
|
+
if (!(url instanceof URL))
|
|
38
|
+
throw new TypeError("url must be an instance of URL");
|
|
39
|
+
const href = new URL(url.href).href, opts = options ?? {}, timeoutOption = opts.timeoutDuration;
|
|
40
|
+
if (typeof timeoutOption == "number" && (!Number.isInteger(timeoutOption) || timeoutOption < 0))
|
|
41
|
+
throw new TypeError('"timeoutDuration" option must be a non-negative integer');
|
|
42
|
+
const timeoutDuration = typeof timeoutOption == "number" ? timeoutOption : 5e3, cooldownDuration = validateDuration(opts.cooldownDuration, 3e4, "cooldownDuration"), cacheMaxAge = validateDuration(opts.cacheMaxAge, 6e5, "cacheMaxAge"), headers = new Headers(opts.headers);
|
|
43
|
+
USER_AGENT && !headers.has("User-Agent") && headers.set("User-Agent", USER_AGENT), headers.has("accept") || headers.set("accept", "application/json, application/jwk-set+json");
|
|
44
|
+
const fetchImpl = opts[customFetch], cache = opts[jwksCache];
|
|
45
|
+
let jwksTimestamp, pendingFetch, reloadSequence = 0, appliedSequence = 0, local;
|
|
46
|
+
if (cache && typeof cache == "object") {
|
|
47
|
+
const { uat, jwks } = cache;
|
|
48
|
+
isFreshFor(uat, cacheMaxAge) && isJwkSet(jwks) && (jwksTimestamp = uat, local = createLocalJWKSet(jwks));
|
|
49
|
+
}
|
|
50
|
+
const reload = async () => {
|
|
51
|
+
if (pendingFetch && isCloudflareWorkers() && (pendingFetch = void 0), !pendingFetch) {
|
|
52
|
+
const sequence = ++reloadSequence, current = pendingFetch = fetchJwks(href, headers, AbortSignal.timeout(timeoutDuration), fetchImpl).then((json) => {
|
|
53
|
+
const next = createLocalJWKSet(json);
|
|
54
|
+
if (sequence <= appliedSequence)
|
|
55
|
+
return;
|
|
56
|
+
local = next;
|
|
57
|
+
const updatedAt = Date.now();
|
|
58
|
+
cache && (cache.uat = updatedAt, cache.jwks = json), jwksTimestamp = updatedAt, appliedSequence = sequence;
|
|
59
|
+
}).finally(() => {
|
|
60
|
+
pendingFetch === current && (pendingFetch = void 0);
|
|
61
|
+
});
|
|
58
62
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
await pendingFetch;
|
|
64
|
+
};
|
|
65
|
+
return Object.defineProperties(async (protectedHeader, token) => {
|
|
66
|
+
(!local || !isFreshFor(jwksTimestamp, cacheMaxAge)) && await reload();
|
|
67
|
+
try {
|
|
68
|
+
return await local(protectedHeader, token);
|
|
69
|
+
} catch (err) {
|
|
70
|
+
if (err instanceof JWKSNoMatchingKey && !isFreshFor(jwksTimestamp, cooldownDuration))
|
|
71
|
+
return await reload(), local(protectedHeader, token);
|
|
72
|
+
throw err;
|
|
68
73
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
74
|
+
}, {
|
|
75
|
+
coolingDown: {
|
|
76
|
+
get: () => isFreshFor(jwksTimestamp, cooldownDuration),
|
|
77
|
+
enumerable: !0
|
|
78
|
+
},
|
|
79
|
+
fresh: {
|
|
80
|
+
get: () => isFreshFor(jwksTimestamp, cacheMaxAge),
|
|
81
|
+
enumerable: !0
|
|
82
|
+
},
|
|
83
|
+
reload: {
|
|
84
|
+
value: reload,
|
|
85
|
+
enumerable: !0
|
|
86
|
+
},
|
|
87
|
+
reloading: {
|
|
88
|
+
get: () => !!pendingFetch,
|
|
89
|
+
enumerable: !0
|
|
90
|
+
},
|
|
91
|
+
jwks: {
|
|
92
|
+
value: () => local?.jwks(),
|
|
93
|
+
enumerable: !0
|
|
82
94
|
}
|
|
83
|
-
|
|
84
|
-
if (pendingFetch && isCloudflareWorkers()) {
|
|
85
|
-
pendingFetch = undefined;
|
|
86
|
-
}
|
|
87
|
-
if (!pendingFetch) {
|
|
88
|
-
const sequence = ++reloadSequence;
|
|
89
|
-
const current = (pendingFetch = fetchJwks(href, headers, AbortSignal.timeout(timeoutDuration), fetchImpl)
|
|
90
|
-
.then((json) => {
|
|
91
|
-
const next = createLocalJWKSet(json);
|
|
92
|
-
if (sequence <= appliedSequence) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
local = next;
|
|
96
|
-
const updatedAt = Date.now();
|
|
97
|
-
if (cache) {
|
|
98
|
-
cache.uat = updatedAt;
|
|
99
|
-
cache.jwks = json;
|
|
100
|
-
}
|
|
101
|
-
jwksTimestamp = updatedAt;
|
|
102
|
-
appliedSequence = sequence;
|
|
103
|
-
})
|
|
104
|
-
.finally(() => {
|
|
105
|
-
if (pendingFetch === current) {
|
|
106
|
-
pendingFetch = undefined;
|
|
107
|
-
}
|
|
108
|
-
}));
|
|
109
|
-
}
|
|
110
|
-
await pendingFetch;
|
|
111
|
-
};
|
|
112
|
-
const remoteJWKSet = async (protectedHeader, token) => {
|
|
113
|
-
if (!local || !isFreshFor(jwksTimestamp, cacheMaxAge)) {
|
|
114
|
-
await reload();
|
|
115
|
-
}
|
|
116
|
-
try {
|
|
117
|
-
return await local(protectedHeader, token);
|
|
118
|
-
}
|
|
119
|
-
catch (err) {
|
|
120
|
-
if (err instanceof JWKSNoMatchingKey && !isFreshFor(jwksTimestamp, cooldownDuration)) {
|
|
121
|
-
await reload();
|
|
122
|
-
return local(protectedHeader, token);
|
|
123
|
-
}
|
|
124
|
-
throw err;
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
return Object.defineProperties(remoteJWKSet, {
|
|
128
|
-
coolingDown: {
|
|
129
|
-
get: () => isFreshFor(jwksTimestamp, cooldownDuration),
|
|
130
|
-
enumerable: true,
|
|
131
|
-
},
|
|
132
|
-
fresh: {
|
|
133
|
-
get: () => isFreshFor(jwksTimestamp, cacheMaxAge),
|
|
134
|
-
enumerable: true,
|
|
135
|
-
},
|
|
136
|
-
reload: {
|
|
137
|
-
value: reload,
|
|
138
|
-
enumerable: true,
|
|
139
|
-
},
|
|
140
|
-
reloading: {
|
|
141
|
-
get: () => !!pendingFetch,
|
|
142
|
-
enumerable: true,
|
|
143
|
-
},
|
|
144
|
-
jwks: {
|
|
145
|
-
value: () => local?.jwks(),
|
|
146
|
-
enumerable: true,
|
|
147
|
-
},
|
|
148
|
-
});
|
|
95
|
+
});
|
|
149
96
|
}
|
|
97
|
+
export {
|
|
98
|
+
createRemoteJWKSet,
|
|
99
|
+
customFetch,
|
|
100
|
+
jwksCache
|
|
101
|
+
};
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { createCompactSignature } from
|
|
2
|
-
import { assertNotSet } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
throw new TypeError('use the flattened module for creating JWS with b64: false');
|
|
20
|
-
});
|
|
21
|
-
}
|
|
1
|
+
import { createCompactSignature } from "../../lib/jws_sign.js";
|
|
2
|
+
import { assertNotSet } from "../../lib/helpers.js";
|
|
3
|
+
class CompactSign {
|
|
4
|
+
#payload;
|
|
5
|
+
#protectedHeader;
|
|
6
|
+
constructor(payload) {
|
|
7
|
+
if (!(payload instanceof Uint8Array))
|
|
8
|
+
throw new TypeError("payload must be an instance of Uint8Array");
|
|
9
|
+
this.#payload = payload;
|
|
10
|
+
}
|
|
11
|
+
setProtectedHeader(protectedHeader) {
|
|
12
|
+
return assertNotSet(this.#protectedHeader, "setProtectedHeader"), this.#protectedHeader = protectedHeader, this;
|
|
13
|
+
}
|
|
14
|
+
async sign(key, options) {
|
|
15
|
+
return createCompactSignature(this.#payload, this.#protectedHeader, options?.crit, key, () => {
|
|
16
|
+
throw new TypeError("use the flattened module for creating JWS with b64: false");
|
|
17
|
+
});
|
|
18
|
+
}
|
|
22
19
|
}
|
|
20
|
+
export {
|
|
21
|
+
CompactSign
|
|
22
|
+
};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { prepareVerify, verifyCompact } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (typeof key === 'function') {
|
|
6
|
-
return { ...result, key: verified[3] };
|
|
7
|
-
}
|
|
8
|
-
return result;
|
|
1
|
+
import { prepareVerify, verifyCompact } from "../../lib/jws_verify.js";
|
|
2
|
+
async function compactVerify(jws, key, options) {
|
|
3
|
+
const verified = await verifyCompact(jws, prepareVerify(options), key), result = { payload: verified[0], protectedHeader: verified[1] };
|
|
4
|
+
return typeof key == "function" ? { ...result, key: verified[3] } : result;
|
|
9
5
|
}
|
|
6
|
+
export {
|
|
7
|
+
compactVerify
|
|
8
|
+
};
|
|
@@ -1,32 +1,30 @@
|
|
|
1
|
-
import { createSignature } from
|
|
2
|
-
import { assertNotSet } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
unprotectedHeader: this.#unprotectedHeader,
|
|
28
|
-
crit: options?.crit,
|
|
29
|
-
}, key);
|
|
30
|
-
return jws;
|
|
31
|
-
}
|
|
1
|
+
import { createSignature } from "../../lib/jws_sign.js";
|
|
2
|
+
import { assertNotSet } from "../../lib/helpers.js";
|
|
3
|
+
class FlattenedSign {
|
|
4
|
+
#payload;
|
|
5
|
+
#protectedHeader;
|
|
6
|
+
#unprotectedHeader;
|
|
7
|
+
constructor(payload) {
|
|
8
|
+
if (!(payload instanceof Uint8Array))
|
|
9
|
+
throw new TypeError("payload must be an instance of Uint8Array");
|
|
10
|
+
this.#payload = payload;
|
|
11
|
+
}
|
|
12
|
+
setProtectedHeader(protectedHeader) {
|
|
13
|
+
return assertNotSet(this.#protectedHeader, "setProtectedHeader"), this.#protectedHeader = protectedHeader, this;
|
|
14
|
+
}
|
|
15
|
+
setUnprotectedHeader(unprotectedHeader) {
|
|
16
|
+
return assertNotSet(this.#unprotectedHeader, "setUnprotectedHeader"), this.#unprotectedHeader = unprotectedHeader, this;
|
|
17
|
+
}
|
|
18
|
+
async sign(key, options) {
|
|
19
|
+
const [jws] = await createSignature({
|
|
20
|
+
payload: this.#payload,
|
|
21
|
+
protectedHeader: this.#protectedHeader,
|
|
22
|
+
unprotectedHeader: this.#unprotectedHeader,
|
|
23
|
+
crit: options?.crit
|
|
24
|
+
}, key);
|
|
25
|
+
return jws;
|
|
26
|
+
}
|
|
32
27
|
}
|
|
28
|
+
export {
|
|
29
|
+
FlattenedSign
|
|
30
|
+
};
|
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
import { JWSInvalid } from
|
|
2
|
-
import { isObject } from
|
|
3
|
-
import { encodeJsonUnencodedPayload, prepareVerify, snapshotJws, verifySignature, verifyResult
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
throw new JWSInvalid('JWS Signature missing or incorrect type');
|
|
20
|
-
}
|
|
21
|
-
if (snapshot.header !== undefined && !isObject(snapshot.header)) {
|
|
22
|
-
throw new JWSInvalid('JWS Unprotected Header incorrect type');
|
|
23
|
-
}
|
|
24
|
-
return verifyResult(snapshot, await verifySignature(snapshot, prepareVerify(options), key, encodeJsonUnencodedPayload));
|
|
1
|
+
import { JWSInvalid } from "../../util/errors.js";
|
|
2
|
+
import { isObject } from "../../lib/type_checks.js";
|
|
3
|
+
import { encodeJsonUnencodedPayload, prepareVerify, snapshotJws, verifySignature, verifyResult } from "../../lib/jws_verify.js";
|
|
4
|
+
async function flattenedVerify(jws, key, options) {
|
|
5
|
+
if (!isObject(jws))
|
|
6
|
+
throw new JWSInvalid("Flattened JWS must be an object");
|
|
7
|
+
const snapshot = snapshotJws(jws);
|
|
8
|
+
if (snapshot.protected === void 0 && snapshot.header === void 0)
|
|
9
|
+
throw new JWSInvalid('Flattened JWS must have either of the "protected" or "header" members');
|
|
10
|
+
if (snapshot.protected !== void 0 && typeof snapshot.protected != "string")
|
|
11
|
+
throw new JWSInvalid("JWS Protected Header incorrect type");
|
|
12
|
+
if (snapshot.payload === void 0)
|
|
13
|
+
throw new JWSInvalid("JWS Payload missing");
|
|
14
|
+
if (typeof snapshot.signature != "string")
|
|
15
|
+
throw new JWSInvalid("JWS Signature missing or incorrect type");
|
|
16
|
+
if (snapshot.header !== void 0 && !isObject(snapshot.header))
|
|
17
|
+
throw new JWSInvalid("JWS Unprotected Header incorrect type");
|
|
18
|
+
return verifyResult(snapshot, await verifySignature(snapshot, prepareVerify(options), key, encodeJsonUnencodedPayload));
|
|
25
19
|
}
|
|
20
|
+
export {
|
|
21
|
+
flattenedVerify
|
|
22
|
+
};
|