unjwt 0.8.1 → 0.8.2
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 -4
- package/dist/THIRD-PARTY-LICENSES.md.gz +0 -0
- package/dist/_chunks/_codec-jwe.d.mts +105 -22
- package/dist/_chunks/_codec-jws.mjs +306 -232
- package/dist/_chunks/_cookie-attributes.d.mts +12 -0
- package/dist/_chunks/digest.d.mts +8 -0
- package/dist/_chunks/{algorithms.mjs → digest.mjs} +78 -8
- package/dist/_chunks/index.d.mts +311 -268
- package/dist/_chunks/index2.d.mts +2 -1
- package/dist/_chunks/index3.d.mts +1 -0
- package/dist/_chunks/jwe.d.mts +4 -4
- package/dist/_chunks/jwe.mjs +21 -3
- package/dist/_chunks/jwk.mjs +219 -173
- package/dist/_chunks/jws.d.mts +10 -10
- package/dist/_chunks/jws.mjs +18 -6
- package/dist/_chunks/libs/cookie-es.mjs +255 -0
- package/dist/adapters/elysia/index.d.mts +32 -15
- package/dist/adapters/elysia/index.mjs +46 -67
- package/dist/adapters/h3/index.d.mts +135 -0
- package/dist/adapters/h3/index.mjs +119 -0
- package/dist/adapters/h3v1/index.d.mts +100 -27
- package/dist/adapters/h3v1/index.mjs +59 -76
- package/dist/core/jwe.d.mts +2 -2
- package/dist/core/jwk.d.mts +22 -14
- package/dist/core/jwk.mjs +2 -2
- package/dist/core/jws.d.mts +2 -2
- package/dist/core/utils/index.d.mts +2 -1
- package/dist/core/utils/index.mjs +2 -2
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +3 -3
- package/dist/session/index.d.mts +44 -0
- package/dist/session/index.mjs +111 -0
- package/package.json +37 -18
- package/dist/adapters/h3v2/index.d.mts +0 -65
- package/dist/adapters/h3v2/index.mjs +0 -139
|
@@ -1,89 +1,64 @@
|
|
|
1
|
-
import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM, thumbprint } from "../../_chunks/jwk.mjs";
|
|
2
|
-
import { bindSession, createJWECodec, createJWSCodec, dropSession, encodeSession, issueSession, loadSession, openSessionToken,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
function eventCookieStore(event) {
|
|
6
|
-
return responseCookieStore({
|
|
7
|
-
request: (name) => getCookie(event, name),
|
|
8
|
-
response: () => responseSetCookies(event),
|
|
9
|
-
write: (name, value, attrs) => setCookie(event, name, value, attrs)
|
|
10
|
-
});
|
|
11
|
-
}
|
|
1
|
+
import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM, thumbprint, toPublicJWK } from "../../_chunks/jwk.mjs";
|
|
2
|
+
import { bindSession, createJWECodec, createJWSCodec, defineSession, dropSession, encodeSession, issueSession, loadSession, openSessionToken, sessionActions, setCookieValues } from "../../_chunks/_codec-jws.mjs";
|
|
3
|
+
import { parse } from "../../_chunks/libs/cookie-es.mjs";
|
|
4
|
+
import { getCookie, getRequestHeader, getResponseHeader, isEvent, setCookie } from "h3";
|
|
12
5
|
function responseSetCookies(event) {
|
|
13
|
-
const value = event
|
|
6
|
+
const value = getResponseHeader(event, "set-cookie");
|
|
14
7
|
if (Array.isArray(value)) return value;
|
|
15
8
|
return typeof value === "string" ? [value] : [];
|
|
16
9
|
}
|
|
17
10
|
const PREFIX = "[unjwt/h3]";
|
|
18
|
-
const
|
|
11
|
+
const h3SessionDriver = {
|
|
19
12
|
prefix: PREFIX,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
writable: hasWritableResponse,
|
|
25
|
-
setCookie: (event, sessionName, token, { attrs, chunkMaxLength }) => {
|
|
26
|
-
writeChunked(eventCookieStore(cookieEvent(event)), sessionName, token, {
|
|
27
|
-
attrs,
|
|
28
|
-
chunkMaxLength,
|
|
29
|
-
prefix: PREFIX
|
|
30
|
-
});
|
|
31
|
-
},
|
|
32
|
-
deleteCookie: (event, sessionName, { attrs }) => {
|
|
33
|
-
removeChunked(eventCookieStore(cookieEvent(event)), sessionName, { attrs });
|
|
34
|
-
}
|
|
13
|
+
state: (event) => event.context.sessions ||= Object.create(null),
|
|
14
|
+
header: (event, name) => isEvent(event) ? requestHeader(event, name) : compatHeaders(event).get(name),
|
|
15
|
+
cookies: (event) => isEvent(event) ? eventJar(event) : compatJar(event),
|
|
16
|
+
writable: (event) => !isEvent(event) || !event.handled
|
|
35
17
|
};
|
|
36
|
-
function
|
|
37
|
-
return
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
return (("request" in event ? event.request?.headers : void 0) ?? ("headers" in event ? event.headers : void 0))?.get(name) ?? void 0;
|
|
60
|
-
}
|
|
61
|
-
function getRequestCookies(event) {
|
|
62
|
-
const header = getRequestHeader(event, "cookie");
|
|
18
|
+
function eventJar(event) {
|
|
19
|
+
return {
|
|
20
|
+
read: (name) => getCookie(event, name),
|
|
21
|
+
written: (name) => setCookieValues(responseSetCookies(event))[name],
|
|
22
|
+
write: (name, value, attrs) => {
|
|
23
|
+
setCookie(event, name, value, attrs);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function compatJar(event) {
|
|
28
|
+
let cookies;
|
|
29
|
+
return { read: (name) => (cookies ||= compatCookies(event))[name] };
|
|
30
|
+
}
|
|
31
|
+
function requestHeader(event, name) {
|
|
32
|
+
const value = getRequestHeader(event, name);
|
|
33
|
+
return Array.isArray(value) ? value[0] : value;
|
|
34
|
+
}
|
|
35
|
+
function compatHeaders(event) {
|
|
36
|
+
return "request" in event ? event.request.headers : event.headers;
|
|
37
|
+
}
|
|
38
|
+
function compatCookies(event) {
|
|
39
|
+
const header = compatHeaders(event).get("cookie");
|
|
63
40
|
return header ? parse(header) : Object.create(null);
|
|
64
41
|
}
|
|
65
|
-
function getResponseSetCookie(event) {
|
|
66
|
-
if ("node" in event && event.node) return responseSetCookies(event);
|
|
67
|
-
const response = "response" in event ? event.response : void 0;
|
|
68
|
-
return hasHeaders(response) ? response.headers.getSetCookie() : [];
|
|
69
|
-
}
|
|
70
|
-
function hasHeaders(response) {
|
|
71
|
-
return typeof response === "object" && response !== null && "headers" in response && Boolean(response.headers);
|
|
72
|
-
}
|
|
73
42
|
const codec$1 = createJWECodec({
|
|
74
43
|
prefix: PREFIX,
|
|
75
44
|
defaultName: "h3-jwe"
|
|
76
45
|
});
|
|
46
|
+
const hookArgs$1 = (event) => ({ event });
|
|
47
|
+
function defineJWESession(config) {
|
|
48
|
+
return defineSession(config, {
|
|
49
|
+
driver: h3SessionDriver,
|
|
50
|
+
hookArgs: hookArgs$1,
|
|
51
|
+
codec: codec$1
|
|
52
|
+
});
|
|
53
|
+
}
|
|
77
54
|
async function useJWESession(event, config) {
|
|
78
|
-
|
|
79
|
-
await loadSession(binding);
|
|
80
|
-
return sessionManager(binding);
|
|
55
|
+
return defineJWESession(config).use(event);
|
|
81
56
|
}
|
|
82
57
|
async function getJWESession(event, config) {
|
|
83
58
|
return loadSession(bind$1(event, config));
|
|
84
59
|
}
|
|
85
60
|
function getJWESessionToken(event, config) {
|
|
86
|
-
return
|
|
61
|
+
return defineJWESession(config).token(event);
|
|
87
62
|
}
|
|
88
63
|
async function updateJWESession(event, config, update, options) {
|
|
89
64
|
return issueSession(bind$1(event, config), update, options);
|
|
@@ -94,7 +69,7 @@ async function sealJWESession(event, config) {
|
|
|
94
69
|
async function unsealJWESession(event, config, sealed) {
|
|
95
70
|
return openSessionToken(codec$1, config, {
|
|
96
71
|
token: sealed,
|
|
97
|
-
|
|
72
|
+
args: { event }
|
|
98
73
|
});
|
|
99
74
|
}
|
|
100
75
|
async function clearJWESession(event, config) {
|
|
@@ -102,7 +77,8 @@ async function clearJWESession(event, config) {
|
|
|
102
77
|
}
|
|
103
78
|
function bind$1(event, config) {
|
|
104
79
|
return bindSession(event, config, {
|
|
105
|
-
|
|
80
|
+
driver: h3SessionDriver,
|
|
81
|
+
hookArgs: hookArgs$1,
|
|
106
82
|
codec: codec$1,
|
|
107
83
|
actions: sessionActions()
|
|
108
84
|
});
|
|
@@ -111,16 +87,22 @@ const codec = createJWSCodec({
|
|
|
111
87
|
prefix: PREFIX,
|
|
112
88
|
defaultName: "h3-jws"
|
|
113
89
|
});
|
|
90
|
+
const hookArgs = (event) => ({ event });
|
|
91
|
+
function defineJWSSession(config) {
|
|
92
|
+
return defineSession(config, {
|
|
93
|
+
driver: h3SessionDriver,
|
|
94
|
+
hookArgs,
|
|
95
|
+
codec
|
|
96
|
+
});
|
|
97
|
+
}
|
|
114
98
|
async function useJWSSession(event, config) {
|
|
115
|
-
|
|
116
|
-
await loadSession(binding);
|
|
117
|
-
return sessionManager(binding);
|
|
99
|
+
return defineJWSSession(config).use(event);
|
|
118
100
|
}
|
|
119
101
|
async function getJWSSession(event, config) {
|
|
120
102
|
return loadSession(bind(event, config));
|
|
121
103
|
}
|
|
122
104
|
function getJWSSessionToken(event, config) {
|
|
123
|
-
return
|
|
105
|
+
return defineJWSSession(config).token(event);
|
|
124
106
|
}
|
|
125
107
|
async function updateJWSSession(event, config, update, options) {
|
|
126
108
|
return issueSession(bind(event, config), update, options);
|
|
@@ -131,7 +113,7 @@ async function signJWSSession(event, config) {
|
|
|
131
113
|
async function verifyJWSSession(event, config, token) {
|
|
132
114
|
return openSessionToken(codec, config, {
|
|
133
115
|
token,
|
|
134
|
-
|
|
116
|
+
args: { event }
|
|
135
117
|
});
|
|
136
118
|
}
|
|
137
119
|
async function clearJWSSession(event, config) {
|
|
@@ -139,9 +121,10 @@ async function clearJWSSession(event, config) {
|
|
|
139
121
|
}
|
|
140
122
|
function bind(event, config) {
|
|
141
123
|
return bindSession(event, config, {
|
|
142
|
-
|
|
124
|
+
driver: h3SessionDriver,
|
|
125
|
+
hookArgs,
|
|
143
126
|
codec,
|
|
144
127
|
actions: sessionActions()
|
|
145
128
|
});
|
|
146
129
|
}
|
|
147
|
-
export { clearJWESession, clearJWSSession, deriveJWKFromPassword, exportPEM, generateJWK, getJWESession, getJWESessionToken, getJWSSession, getJWSSessionToken, importPEM, sealJWESession, signJWSSession, thumbprint, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession };
|
|
130
|
+
export { clearJWESession, clearJWSSession, defineJWESession, defineJWSSession, deriveJWKFromPassword, exportPEM, generateJWK, getJWESession, getJWESessionToken, getJWSSession, getJWSSessionToken, importPEM, sealJWESession, signJWSSession, thumbprint, toPublicJWK, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession };
|
package/dist/core/jwe.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UnsecureError, UnsecureErrorCode } from "../_chunks/libs/unsecure.mjs";
|
|
2
|
-
import { JOSEPayloadMode, JOSEPayloadTypeMap, JWEAsymmetricPrivateJWK, JWEAsymmetricPublicJWK, JWEDecryptJWK, JWEDecryptOptions, JWEDecryptResult, JWEEncryptJWK, JWEEncryptOptions, JWEFlattenedSerialization, JWEGeneralRecipient, JWEGeneralSerialization, JWEHeaderParameters, JWEKeyManagementHeaderParameters, JWELibraryHeaderName, JWEMultiDecryptKey, JWEMultiDecryptOptions, JWEMultiDecryptResult, JWEMultiEncryptOptions, JWEMultiRecipient, JWEProtectedHeader, JWTError, JWTErrorCauseMap, JWTErrorCode, KnownJWTErrorCode, PayloadOf, isJWTError, isUnsecureError } from "../_chunks/index.mjs";
|
|
2
|
+
import { JOSEPayloadMode, JOSEPayloadTypeMap, JWEAsymmetricPrivateJWK, JWEAsymmetricPublicJWK, JWEDecryptJWK, JWEDecryptOptions, JWEDecryptResult, JWEEncryptJWK, JWEEncryptOptions, JWEFlattenedSerialization, JWEGeneralRecipient, JWEGeneralSerialization, JWEHeaderParameters, JWEKeyLookup, JWEKeyManagementHeaderParameters, JWELibraryHeaderName, JWEMultiDecryptKey, JWEMultiDecryptOptions, JWEMultiDecryptResult, JWEMultiEncryptOptions, JWEMultiRecipient, JWEProtectedHeader, JWTError, JWTErrorCauseMap, JWTErrorCode, KnownJWTErrorCode, PayloadOf, isJWTError, isUnsecureError } from "../_chunks/index.mjs";
|
|
3
3
|
import { decrypt, decryptMulti, encrypt, encryptMulti, generalToFlattened } from "../_chunks/jwe.mjs";
|
|
4
4
|
import { DEFAULT_JOSE_LIMITS } from "../_chunks/_internal.mjs";
|
|
5
|
-
export { DEFAULT_JOSE_LIMITS, type JOSEPayloadMode, type JOSEPayloadTypeMap, type JWEAsymmetricPrivateJWK, type JWEAsymmetricPublicJWK, type JWEDecryptJWK, type JWEDecryptOptions, type JWEDecryptResult, type JWEEncryptJWK, type JWEEncryptOptions, type JWEFlattenedSerialization, type JWEGeneralRecipient, type JWEGeneralSerialization, type JWEHeaderParameters, type JWEKeyManagementHeaderParameters, type JWELibraryHeaderName, type JWEMultiDecryptKey, type JWEMultiDecryptOptions, type JWEMultiDecryptResult, type JWEMultiEncryptOptions, type JWEMultiRecipient, type JWEProtectedHeader, JWTError, type JWTErrorCauseMap, type JWTErrorCode, type KnownJWTErrorCode, type PayloadOf, UnsecureError, type UnsecureErrorCode, decrypt, decryptMulti, encrypt, encryptMulti, generalToFlattened, isJWTError, isUnsecureError };
|
|
5
|
+
export { DEFAULT_JOSE_LIMITS, type JOSEPayloadMode, type JOSEPayloadTypeMap, type JWEAsymmetricPrivateJWK, type JWEAsymmetricPublicJWK, type JWEDecryptJWK, type JWEDecryptOptions, type JWEDecryptResult, type JWEEncryptJWK, type JWEEncryptOptions, type JWEFlattenedSerialization, type JWEGeneralRecipient, type JWEGeneralSerialization, type JWEHeaderParameters, type JWEKeyLookup, type JWEKeyManagementHeaderParameters, type JWELibraryHeaderName, type JWEMultiDecryptKey, type JWEMultiDecryptOptions, type JWEMultiDecryptResult, type JWEMultiEncryptOptions, type JWEMultiRecipient, type JWEProtectedHeader, JWTError, type JWTErrorCauseMap, type JWTErrorCode, type KnownJWTErrorCode, type PayloadOf, UnsecureError, type UnsecureErrorCode, decrypt, decryptMulti, encrypt, encryptMulti, generalToFlattened, isJWTError, isUnsecureError };
|
package/dist/core/jwk.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UnsecureError, UnsecureErrorCode } from "../_chunks/libs/unsecure.mjs";
|
|
2
|
-
import { CompositeKey, ContentEncryptionAlgorithm, DeriveKeyOptions, DeriveKeyReturn, ECDHEphemeralKeyInput, GenerateJWKOptions, GenerateJWKReturn, GenerateKeyAlgorithm, GenerateKeyOptions, GenerateKeyReturn, GeneratedJWKMap, GeneratedKeyMap, ImportedKey, ImportedKeyMap, JWK, JWKAlgorithm, JWKCacheAdapter, JWKLookupFunction, JWKLookupFunctionHeader, JWKMetadata, JWKPEMAlgorithm, JWKParameters, JWKSet, JWK_AES_CBC_HMAC, JWK_AES_GCM, JWK_AES_GCM_KW, JWK_AES_KW, JWK_Asymmetric, JWK_Asymmetric_Algorithm, JWK_EC, JWK_ECDH_ES, JWK_ECDSA, JWK_EC_Private, JWK_EC_Public, JWK_HMAC, JWK_OKP, JWK_OKP_Private, JWK_OKP_Public, JWK_OKP_SIGN, JWK_PBES2, JWK_Pair, JWK_Private, JWK_Public, JWK_RSA, JWK_RSA_ENC, JWK_RSA_PSS, JWK_RSA_Private, JWK_RSA_Public, JWK_RSA_SIGN, JWK_Symmetric, JWK_Symmetric_Algorithm, JWK_oct, JWTError, JWTErrorCauseMap, JWTErrorCode, KeyManagementAlgorithm, KnownJWTErrorCode, UnwrapKeyOptions, UnwrapKeyResult, UnwrappingKeyFor, WrapKeyOptions, WrapKeyResult, WrappingKeyFor, isJWTError, isUnsecureError } from "../_chunks/index.mjs";
|
|
2
|
+
import { CompositeKey, ContentEncryptionAlgorithm, DeriveJWKOptions, DeriveJWKReturn, DeriveKeyOptions, DeriveKeyReturn, ECDHEphemeralKeyInput, GenerateJWKOptions, GenerateJWKReturn, GenerateKeyAlgorithm, GenerateKeyOptions, GenerateKeyReturn, GeneratedJWKMap, GeneratedKeyMap, ImportedKey, ImportedKeyMap, ImportedPEMJWK, JWK, JWKAlgorithm, JWKCacheAdapter, JWKLookupFunction, JWKLookupFunctionHeader, JWKMetadata, JWKPEMAlgorithm, JWKParameters, JWKSet, JWK_AES_Algorithm, JWK_AES_CBC_HMAC, JWK_AES_GCM, JWK_AES_GCM_KW, JWK_AES_KW, JWK_Asymmetric, JWK_Asymmetric_Algorithm, JWK_EC, JWK_ECDH_ES, JWK_ECDSA, JWK_EC_Private, JWK_EC_Public, JWK_HMAC, JWK_OKP, JWK_OKP_Private, JWK_OKP_Public, JWK_OKP_SIGN, JWK_PBES2, JWK_Pair, JWK_Private, JWK_Public, JWK_RSA, JWK_RSA_ENC, JWK_RSA_PSS, JWK_RSA_Private, JWK_RSA_Public, JWK_RSA_SIGN, JWK_Symmetric, JWK_Symmetric_Algorithm, JWK_oct, JWTError, JWTErrorCauseMap, JWTErrorCode, KeyManagementAlgorithm, KeyWrapAlgorithmOf, KeyWrappingAlgorithm, KnownJWTErrorCode, PEMType, ToPublicJWKReturn, UnwrapKeyOptions, UnwrapKeyResult, UnwrappingKeyFor, WrapKeyOptions, WrapKeyResult, WrappingKeyFor, isJWTError, isUnsecureError } from "../_chunks/index.mjs";
|
|
3
3
|
import { ThumbprintHash, thumbprint } from "../_chunks/index2.mjs";
|
|
4
4
|
/**
|
|
5
5
|
* Generates a key for a JWA algorithm: a `CryptoKey` for symmetric algorithms, raw bytes for
|
|
@@ -58,17 +58,15 @@ export declare function deriveKeyFromPassword<TOptions extends DeriveKeyOptions>
|
|
|
58
58
|
* - JWK metadata (`use`, `x5c`, `x5t`, `x5t#S256`, `x5u`) is merged onto the result;
|
|
59
59
|
* `alg`, `kty`, `key_ops`, `ext` and key-material members are reserved (`ERR_INVALID_OPTION`).
|
|
60
60
|
*/
|
|
61
|
-
export declare function deriveJWKFromPassword(password: string | Uint8Array<ArrayBuffer>, options:
|
|
62
|
-
kid?: string | false;
|
|
63
|
-
}): Promise<JWK_oct>;
|
|
61
|
+
export declare function deriveJWKFromPassword<TAlg extends JWK_PBES2, Kid extends string | false = string>(password: string | Uint8Array<ArrayBuffer>, options: DeriveJWKOptions<TAlg, Kid> & Omit<JWKMetadata, "kid">): Promise<DeriveJWKReturn<TAlg, Kid>>;
|
|
64
62
|
/**
|
|
65
63
|
* Default JWK import cache, keyed by JWK object identity: a copied JWK misses it, and a JWK
|
|
66
64
|
* mutated in place keeps serving the old `CryptoKey`. Rotate by replacing the object.
|
|
67
65
|
*/
|
|
68
66
|
export declare class WeakMapJWKCache implements JWKCacheAdapter {
|
|
69
67
|
private readonly _map;
|
|
70
|
-
get(jwk: JWK, alg:
|
|
71
|
-
set(jwk: JWK, alg:
|
|
68
|
+
get(jwk: JWK, alg: JWKAlgorithm): CryptoKey | undefined;
|
|
69
|
+
set(jwk: JWK, alg: JWKAlgorithm, key: CryptoKey): void;
|
|
72
70
|
}
|
|
73
71
|
/**
|
|
74
72
|
* Replaces the JWK import cache used by `importKey`, or disables it with `false`.
|
|
@@ -79,7 +77,7 @@ export declare class WeakMapJWKCache implements JWKCacheAdapter {
|
|
|
79
77
|
*
|
|
80
78
|
* @example
|
|
81
79
|
* ```ts
|
|
82
|
-
* const cacheKey = async (jwk: JWK, alg:
|
|
80
|
+
* const cacheKey = async (jwk: JWK, alg: JWKAlgorithm) =>
|
|
83
81
|
* `${await thumbprint(jwk)}:${"d" in jwk ? "private" : "public"}:${alg}`;
|
|
84
82
|
* const map = new Map<string, CryptoKey>();
|
|
85
83
|
* configureJWKCache({
|
|
@@ -112,9 +110,9 @@ export declare function importKey(key: JWK_oct, options: {
|
|
|
112
110
|
* `alg` throws `ERR_JWK_INVALID`, except an `oct` JWK declaring a content encryption `alg` under
|
|
113
111
|
* `"dir"`.
|
|
114
112
|
*/
|
|
115
|
-
export declare function importKey<K extends CryptoKey | JWK | Uint8Array<ArrayBuffer>>(key: K, options?:
|
|
113
|
+
export declare function importKey<K extends CryptoKey | JWK | Uint8Array<ArrayBuffer>>(key: K, options?: JWKAlgorithm | {
|
|
116
114
|
/** Algorithm hint. Required when `key.alg` is absent on an asymmetric JWK. */
|
|
117
|
-
alg?:
|
|
115
|
+
alg?: JWKAlgorithm;
|
|
118
116
|
/** Reject on shape mismatch instead of silently importing. */
|
|
119
117
|
expect?: "public" | "private";
|
|
120
118
|
/** Defaults to `false` for private, `true` for public material; JWK `ext: false` wins. */
|
|
@@ -129,7 +127,17 @@ export declare function importKey<K extends CryptoKey | JWK | Uint8Array<ArrayBu
|
|
|
129
127
|
* @throws `ERR_INVALID_OPTION` if `key` is not a `CryptoKey` or `jwkParams` sets a reserved member
|
|
130
128
|
* (`alg`, `kty`, `key_ops`, `ext`, key material); `ERR_JWK_INVALID` for a non-extractable key.
|
|
131
129
|
*/
|
|
130
|
+
export declare function exportJWK<T extends JWK = JWK>(key: CryptoKey, jwkParams?: JWKMetadata): Promise<T>;
|
|
131
|
+
/** @deprecated Use `exportJWK`; removed in 0.9.0. */
|
|
132
132
|
export declare function exportKey<T extends JWK = JWK>(key: CryptoKey, jwkParams?: JWKMetadata): Promise<T>;
|
|
133
|
+
/**
|
|
134
|
+
* Utility to derive the public half of an asymmetric JWK, or throw if the input is not asymmetric.
|
|
135
|
+
*
|
|
136
|
+
* @param jwk An asymmetric JWK (EC, OKP, RSA) with a private scalar (`d`).
|
|
137
|
+
* @throws `ERR_JWK_INVALID` if the input is not an asymmetric JWK.
|
|
138
|
+
* @returns A JWK with the same public members, without the private scalar.
|
|
139
|
+
*/
|
|
140
|
+
export declare function toPublicJWK<T extends JWK_Asymmetric>(jwk: T): ToPublicJWKReturn<T>;
|
|
133
141
|
/**
|
|
134
142
|
* Wraps a CEK under a JWA key management algorithm; the result shape follows `alg`.
|
|
135
143
|
*
|
|
@@ -157,12 +165,12 @@ export declare function unwrapKey<TOptions extends UnwrapKeyOptions>(wrappedKey:
|
|
|
157
165
|
* `ERR_JWK_UNSUPPORTED` for an unknown `pemType`; `ERR_INVALID_OPTION` if `jwkParams` sets
|
|
158
166
|
* `alg`, `kty`, `key_ops`, `ext` or a key-material member.
|
|
159
167
|
*/
|
|
160
|
-
export declare function importPEM<
|
|
161
|
-
/** PEM type. Inferred from the PEM label when omitted. */
|
|
162
|
-
pemType?:
|
|
168
|
+
export declare function importPEM<A extends JWKPEMAlgorithm, Type extends PEMType | undefined = undefined>(pem: string, alg: A, options?: {
|
|
169
|
+
/** PEM type. Inferred from the PEM label when omitted, which leaves the result public or private. */
|
|
170
|
+
pemType?: Type;
|
|
163
171
|
/** Additional JWK properties merged into the exported key (e.g. `kid`). */
|
|
164
172
|
jwkParams?: JWKMetadata;
|
|
165
|
-
}): Promise<
|
|
173
|
+
}): Promise<ImportedPEMJWK<A, Type>>;
|
|
166
174
|
/**
|
|
167
175
|
* Exports an asymmetric JWK as PEM: PKCS#8 when it carries `d`, SPKI otherwise.
|
|
168
176
|
*
|
|
@@ -196,4 +204,4 @@ export declare function deriveSharedSecret(publicKey: CryptoKey | JWK_EC_Public,
|
|
|
196
204
|
* An invalid set throws `ERR_JWK_INVALID`.
|
|
197
205
|
*/
|
|
198
206
|
export declare function getJWKsFromSet(jwkSet: JWKSet, filter?: (jwk: JWK) => boolean): JWK[];
|
|
199
|
-
export { type CompositeKey, type ContentEncryptionAlgorithm, type DeriveKeyOptions, type DeriveKeyReturn, type ECDHEphemeralKeyInput, type GenerateJWKOptions, type GenerateJWKReturn, type GenerateKeyAlgorithm, type GenerateKeyOptions, type GenerateKeyReturn, type GeneratedJWKMap, type GeneratedKeyMap, type ImportedKey, type ImportedKeyMap, type JWK, type JWKAlgorithm, type JWKCacheAdapter, type JWKLookupFunction, type JWKLookupFunctionHeader, type JWKMetadata, type JWKPEMAlgorithm, type JWKParameters, type JWKSet, type JWK_AES_CBC_HMAC, type JWK_AES_GCM, type JWK_AES_GCM_KW, type JWK_AES_KW, type JWK_Asymmetric, type JWK_Asymmetric_Algorithm, type JWK_EC, type JWK_ECDH_ES, type JWK_ECDSA, type JWK_EC_Private, type JWK_EC_Public, type JWK_HMAC, type JWK_OKP, type JWK_OKP_Private, type JWK_OKP_Public, type JWK_OKP_SIGN, type JWK_PBES2, type JWK_Pair, type JWK_Private, type JWK_Public, type JWK_RSA, type JWK_RSA_ENC, type JWK_RSA_PSS, type JWK_RSA_Private, type JWK_RSA_Public, type JWK_RSA_SIGN, type JWK_Symmetric, type JWK_Symmetric_Algorithm, type JWK_oct, JWTError, type JWTErrorCauseMap, type JWTErrorCode, type KeyManagementAlgorithm, type KnownJWTErrorCode, type ThumbprintHash, UnsecureError, type UnsecureErrorCode, type UnwrapKeyOptions, type UnwrapKeyResult, type UnwrappingKeyFor, type WrapKeyOptions, type WrapKeyResult, type WrappingKeyFor, isJWTError, isUnsecureError, thumbprint };
|
|
207
|
+
export { type CompositeKey, type ContentEncryptionAlgorithm, type DeriveJWKOptions, type DeriveJWKReturn, type DeriveKeyOptions, type DeriveKeyReturn, type ECDHEphemeralKeyInput, type GenerateJWKOptions, type GenerateJWKReturn, type GenerateKeyAlgorithm, type GenerateKeyOptions, type GenerateKeyReturn, type GeneratedJWKMap, type GeneratedKeyMap, type ImportedKey, type ImportedKeyMap, type ImportedPEMJWK, type JWK, type JWKAlgorithm, type JWKCacheAdapter, type JWKLookupFunction, type JWKLookupFunctionHeader, type JWKMetadata, type JWKPEMAlgorithm, type JWKParameters, type JWKSet, type JWK_AES_Algorithm, type JWK_AES_CBC_HMAC, type JWK_AES_GCM, type JWK_AES_GCM_KW, type JWK_AES_KW, type JWK_Asymmetric, type JWK_Asymmetric_Algorithm, type JWK_EC, type JWK_ECDH_ES, type JWK_ECDSA, type JWK_EC_Private, type JWK_EC_Public, type JWK_HMAC, type JWK_OKP, type JWK_OKP_Private, type JWK_OKP_Public, type JWK_OKP_SIGN, type JWK_PBES2, type JWK_Pair, type JWK_Private, type JWK_Public, type JWK_RSA, type JWK_RSA_ENC, type JWK_RSA_PSS, type JWK_RSA_Private, type JWK_RSA_Public, type JWK_RSA_SIGN, type JWK_Symmetric, type JWK_Symmetric_Algorithm, type JWK_oct, JWTError, type JWTErrorCauseMap, type JWTErrorCode, type KeyManagementAlgorithm, type KeyWrapAlgorithmOf, type KeyWrappingAlgorithm, type KnownJWTErrorCode, type PEMType, type ThumbprintHash, type ToPublicJWKReturn, UnsecureError, type UnsecureErrorCode, type UnwrapKeyOptions, type UnwrapKeyResult, type UnwrappingKeyFor, type WrapKeyOptions, type WrapKeyResult, type WrappingKeyFor, isJWTError, isUnsecureError, thumbprint };
|
package/dist/core/jwk.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { UnsecureError } from "../_chunks/libs/unsecure.mjs";
|
|
2
2
|
import { JWTError, isJWTError, isUnsecureError } from "../_chunks/_jwt-internal.mjs";
|
|
3
|
-
import { WeakMapJWKCache, clearJWKCache, configureJWKCache, deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, exportKey, exportPEM, generateJWK, generateKey, getJWKsFromSet, importKey, importPEM, thumbprint, unwrapKey, wrapKey } from "../_chunks/jwk.mjs";
|
|
4
|
-
export { JWTError, UnsecureError, WeakMapJWKCache, clearJWKCache, configureJWKCache, deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, exportKey, exportPEM, generateJWK, generateKey, getJWKsFromSet, importKey, importPEM, isJWTError, isUnsecureError, thumbprint, unwrapKey, wrapKey };
|
|
3
|
+
import { WeakMapJWKCache, clearJWKCache, configureJWKCache, deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, exportJWK, exportKey, exportPEM, generateJWK, generateKey, getJWKsFromSet, importKey, importPEM, thumbprint, toPublicJWK, unwrapKey, wrapKey } from "../_chunks/jwk.mjs";
|
|
4
|
+
export { JWTError, UnsecureError, WeakMapJWKCache, clearJWKCache, configureJWKCache, deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, exportJWK, exportKey, exportPEM, generateJWK, generateKey, getJWKsFromSet, importKey, importPEM, isJWTError, isUnsecureError, thumbprint, toPublicJWK, unwrapKey, wrapKey };
|
package/dist/core/jws.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UnsecureError, UnsecureErrorCode } from "../_chunks/libs/unsecure.mjs";
|
|
2
|
-
import { JOSEPayloadMode, JOSEPayloadTypeMap, JWSAlgorithm, JWSAsymmetricPrivateJWK, JWSAsymmetricPublicJWK, JWSFlattenedSerialization, JWSGeneralSerialization, JWSGeneralSignature, JWSHeaderParameters, JWSMultiSignOptions, JWSMultiSigner, JWSMultiVerifyAllOptions, JWSMultiVerifyOptions, JWSMultiVerifyOutcome, JWSMultiVerifyResult, JWSProtectedHeader, JWSSignJWK, JWSSignOptions, JWSVerifyJWK, JWSVerifyOptions, JWSVerifyResult, JWTError, JWTErrorCauseMap, JWTErrorCode, KnownJWTErrorCode, PayloadOf, isJWTError, isUnsecureError } from "../_chunks/index.mjs";
|
|
2
|
+
import { JOSEPayloadMode, JOSEPayloadTypeMap, JWSAlgorithm, JWSAsymmetricPrivateJWK, JWSAsymmetricPublicJWK, JWSFlattenedSerialization, JWSGeneralSerialization, JWSGeneralSignature, JWSHashedAlgorithm, JWSHeaderParameters, JWSKeyLookup, JWSMultiSignOptions, JWSMultiSigner, JWSMultiVerifyAllOptions, JWSMultiVerifyOptions, JWSMultiVerifyOutcome, JWSMultiVerifyResult, JWSProtectedHeader, JWSSignJWK, JWSSignOptions, JWSVerifyJWK, JWSVerifyOptions, JWSVerifyResult, JWTError, JWTErrorCauseMap, JWTErrorCode, KnownJWTErrorCode, PayloadOf, isJWTError, isUnsecureError } from "../_chunks/index.mjs";
|
|
3
3
|
import { DEFAULT_JOSE_LIMITS } from "../_chunks/_internal.mjs";
|
|
4
4
|
import { generalToFlattenedJWS, sign, signMulti, verify, verifyMulti, verifyMultiAll } from "../_chunks/jws.mjs";
|
|
5
|
-
export { DEFAULT_JOSE_LIMITS, type JOSEPayloadMode, type JOSEPayloadTypeMap, type JWSAlgorithm, type JWSAsymmetricPrivateJWK, type JWSAsymmetricPublicJWK, type JWSFlattenedSerialization, type JWSGeneralSerialization, type JWSGeneralSignature, type JWSHeaderParameters, type JWSMultiSignOptions, type JWSMultiSigner, type JWSMultiVerifyAllOptions, type JWSMultiVerifyOptions, type JWSMultiVerifyOutcome, type JWSMultiVerifyResult, type JWSProtectedHeader, type JWSSignJWK, type JWSSignOptions, type JWSVerifyJWK, type JWSVerifyOptions, type JWSVerifyResult, JWTError, type JWTErrorCauseMap, type JWTErrorCode, type KnownJWTErrorCode, type PayloadOf, UnsecureError, type UnsecureErrorCode, generalToFlattenedJWS, isJWTError, isUnsecureError, sign, signMulti, verify, verifyMulti, verifyMultiAll };
|
|
5
|
+
export { DEFAULT_JOSE_LIMITS, type JOSEPayloadMode, type JOSEPayloadTypeMap, type JWSAlgorithm, type JWSAsymmetricPrivateJWK, type JWSAsymmetricPublicJWK, type JWSFlattenedSerialization, type JWSGeneralSerialization, type JWSGeneralSignature, type JWSHashedAlgorithm, type JWSHeaderParameters, type JWSKeyLookup, type JWSMultiSignOptions, type JWSMultiSigner, type JWSMultiVerifyAllOptions, type JWSMultiVerifyOptions, type JWSMultiVerifyOutcome, type JWSMultiVerifyResult, type JWSProtectedHeader, type JWSSignJWK, type JWSSignOptions, type JWSVerifyJWK, type JWSVerifyOptions, type JWSVerifyResult, JWTError, type JWTErrorCauseMap, type JWTErrorCode, type KnownJWTErrorCode, type PayloadOf, UnsecureError, type UnsecureErrorCode, generalToFlattenedJWS, isJWTError, isUnsecureError, sign, signMulti, verify, verifyMulti, verifyMultiAll };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BytesSource, DecodeOptions, DecodeReturnAs, UnsecureError, UnsecureErrorCode, safeJsonParse, sanitizeObject, sanitizeObjectCopy, secureRandomBytes, textDecoder, textEncoder } from "../../_chunks/libs/unsecure.mjs";
|
|
2
2
|
import { StrictOmit, isUnsecureError } from "../../_chunks/index.mjs";
|
|
3
|
+
import { DigestHash, digestUrl } from "../../_chunks/digest.mjs";
|
|
3
4
|
import { computeDurationInSeconds, isJWTContent, validateJwtClaims } from "../../_chunks/jwt.mjs";
|
|
4
5
|
import { ComputeJwtTimeClaimsOptions, DecodePayloadOptions, InferAlgorithmsOptions, applyTypCtyDefaults, assertCritShape, assertCryptoKey, base64Decode, base64Encode, base64Parse, base64Stringify, base64UrlDecode, base64UrlEncode, base64UrlParse, base64UrlStringify, computeJwtTimeClaims, concatUint8Arrays, decodePayloadFromB64UrlSegment, decodePayloadFromBytes, getPlaintextBytes, inferJWEAllowedAlgorithms, inferJWSAllowedAlgorithms, isAsymmetricJWK, isCryptoKey, isCryptoKeyPair, isJWK, isJWKSet, isPrivateJWK, isPublicJWK, isSymmetricJWK, maybeArray, validateCriticalHeadersJWE, validateCriticalHeadersJWS } from "../../_chunks/index3.mjs";
|
|
5
|
-
export { type BytesSource, ComputeJwtTimeClaimsOptions, type DecodeOptions, DecodePayloadOptions, type DecodeReturnAs, type InferAlgorithmsOptions, type StrictOmit, UnsecureError, type UnsecureErrorCode, applyTypCtyDefaults, assertCritShape, assertCryptoKey, base64Decode, base64Encode, base64Parse, base64Stringify, base64UrlDecode, base64UrlEncode, base64UrlParse, base64UrlStringify, computeDurationInSeconds, computeJwtTimeClaims, concatUint8Arrays, decodePayloadFromB64UrlSegment, decodePayloadFromBytes, getPlaintextBytes, inferJWEAllowedAlgorithms, inferJWSAllowedAlgorithms, isAsymmetricJWK, isCryptoKey, isCryptoKeyPair, isJWK, isJWKSet, isJWTContent, isPrivateJWK, isPublicJWK, isSymmetricJWK, isUnsecureError, maybeArray, safeJsonParse, sanitizeObject, sanitizeObjectCopy, secureRandomBytes, textDecoder, textEncoder, validateCriticalHeadersJWE, validateCriticalHeadersJWS, validateJwtClaims };
|
|
6
|
+
export { type BytesSource, ComputeJwtTimeClaimsOptions, type DecodeOptions, DecodePayloadOptions, type DecodeReturnAs, type DigestHash, type InferAlgorithmsOptions, type StrictOmit, UnsecureError, type UnsecureErrorCode, applyTypCtyDefaults, assertCritShape, assertCryptoKey, base64Decode, base64Encode, base64Parse, base64Stringify, base64UrlDecode, base64UrlEncode, base64UrlParse, base64UrlStringify, computeDurationInSeconds, computeJwtTimeClaims, concatUint8Arrays, decodePayloadFromB64UrlSegment, decodePayloadFromBytes, digestUrl, getPlaintextBytes, inferJWEAllowedAlgorithms, inferJWSAllowedAlgorithms, isAsymmetricJWK, isCryptoKey, isCryptoKeyPair, isJWK, isJWKSet, isJWTContent, isPrivateJWK, isPublicJWK, isSymmetricJWK, isUnsecureError, maybeArray, safeJsonParse, sanitizeObject, sanitizeObjectCopy, secureRandomBytes, textDecoder, textEncoder, validateCriticalHeadersJWE, validateCriticalHeadersJWS, validateJwtClaims };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UnsecureError, safeJsonParse, sanitizeObject, sanitizeObjectCopy, secureRandomBytes, textDecoder, textEncoder } from "../../_chunks/libs/unsecure.mjs";
|
|
2
2
|
import { applyTypDefault, assertCritShape as assertCritShape$1, assertCryptoKey, base64Decode, base64Encode, base64Parse, base64Stringify, base64UrlDecode, base64UrlEncode, base64UrlParse, base64UrlStringify, computeDurationInSeconds, computeJwtTimeClaims as computeJwtTimeClaims$1, concatUint8Arrays, getPlaintextBytes as getPlaintextBytes$1, isAsymmetricJWK, isCryptoKey, isCryptoKeyPair, isJWK, isJWKSet, isJWTContent, isPrivateJWK, isPublicJWK, isSymmetricJWK, isUnsecureError, maybeArray, parsePayloadBytes, parsePayloadSegment, validateCriticalHeadersJWE as validateCriticalHeadersJWE$1, validateCriticalHeadersJWS as validateCriticalHeadersJWS$1, validateJwtClaims } from "../../_chunks/_jwt-internal.mjs";
|
|
3
|
-
import { inferJWEAllowedAlgorithms, inferJWSAllowedAlgorithms } from "../../_chunks/
|
|
3
|
+
import { digestUrl, inferJWEAllowedAlgorithms, inferJWSAllowedAlgorithms } from "../../_chunks/digest.mjs";
|
|
4
4
|
const applyTypCtyDefaults = applyTypDefault;
|
|
5
5
|
const decodePayloadFromBytes = parsePayloadBytes;
|
|
6
6
|
const decodePayloadFromB64UrlSegment = parsePayloadSegment;
|
|
@@ -9,4 +9,4 @@ const computeJwtTimeClaims = computeJwtTimeClaims$1;
|
|
|
9
9
|
const validateCriticalHeadersJWS = validateCriticalHeadersJWS$1;
|
|
10
10
|
const validateCriticalHeadersJWE = validateCriticalHeadersJWE$1;
|
|
11
11
|
const assertCritShape = assertCritShape$1;
|
|
12
|
-
export { UnsecureError, applyTypCtyDefaults, assertCritShape, assertCryptoKey, base64Decode, base64Encode, base64Parse, base64Stringify, base64UrlDecode, base64UrlEncode, base64UrlParse, base64UrlStringify, computeDurationInSeconds, computeJwtTimeClaims, concatUint8Arrays, decodePayloadFromB64UrlSegment, decodePayloadFromBytes, getPlaintextBytes, inferJWEAllowedAlgorithms, inferJWSAllowedAlgorithms, isAsymmetricJWK, isCryptoKey, isCryptoKeyPair, isJWK, isJWKSet, isJWTContent, isPrivateJWK, isPublicJWK, isSymmetricJWK, isUnsecureError, maybeArray, safeJsonParse, sanitizeObject, sanitizeObjectCopy, secureRandomBytes, textDecoder, textEncoder, validateCriticalHeadersJWE, validateCriticalHeadersJWS, validateJwtClaims };
|
|
12
|
+
export { UnsecureError, applyTypCtyDefaults, assertCritShape, assertCryptoKey, base64Decode, base64Encode, base64Parse, base64Stringify, base64UrlDecode, base64UrlEncode, base64UrlParse, base64UrlStringify, computeDurationInSeconds, computeJwtTimeClaims, concatUint8Arrays, decodePayloadFromB64UrlSegment, decodePayloadFromBytes, digestUrl, getPlaintextBytes, inferJWEAllowedAlgorithms, inferJWSAllowedAlgorithms, isAsymmetricJWK, isCryptoKey, isCryptoKeyPair, isJWK, isJWKSet, isJWTContent, isPrivateJWK, isPublicJWK, isSymmetricJWK, isUnsecureError, maybeArray, safeJsonParse, sanitizeObject, sanitizeObjectCopy, secureRandomBytes, textDecoder, textEncoder, validateCriticalHeadersJWE, validateCriticalHeadersJWS, validateJwtClaims };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { BytesSource, DecodeOptions, DecodeReturnAs, UnsecureError, UnsecureErrorCode, safeJsonParse, sanitizeObject, sanitizeObjectCopy, secureRandomBytes, textDecoder, textEncoder } from "./_chunks/libs/unsecure.mjs";
|
|
2
|
-
import { CompositeKey, ContentEncryptionAlgorithm, DeriveKeyOptions, DeriveKeyReturn, Duration, ECDHEphemeralKeyInput, ExpiresIn, GenerateJWKOptions, GenerateJWKReturn, GenerateKeyAlgorithm, GenerateKeyOptions, GenerateKeyReturn, GeneratedJWKMap, GeneratedKeyMap, ImportedKey, ImportedKeyMap, JOSEConsumerOptions, JOSELimits, JOSEPayload, JOSEPayloadMode, JOSEPayloadTypeMap, JWEAsymmetricPrivateJWK, JWEAsymmetricPublicJWK, JWEDecryptJWK, JWEDecryptOptions, JWEDecryptResult, JWEEncryptJWK, JWEEncryptOptions, JWEFlattenedSerialization, JWEGeneralRecipient, JWEGeneralSerialization, JWEHeaderParameters, JWEKeyManagementHeaderParameters, JWELibraryHeaderName, JWEMultiDecryptKey, JWEMultiDecryptOptions, JWEMultiDecryptResult, JWEMultiEncryptOptions, JWEMultiRecipient, JWEProtectedHeader, JWK, JWKAlgorithm, JWKCacheAdapter, JWKLookupFunction, JWKLookupFunctionHeader, JWKMetadata, JWKPEMAlgorithm, JWKParameters, JWKSet, JWK_AES_CBC_HMAC, JWK_AES_GCM, JWK_AES_GCM_KW, JWK_AES_KW, JWK_Asymmetric, JWK_Asymmetric_Algorithm, JWK_EC, JWK_ECDH_ES, JWK_ECDSA, JWK_EC_Private, JWK_EC_Public, JWK_HMAC, JWK_OKP, JWK_OKP_Private, JWK_OKP_Public, JWK_OKP_SIGN, JWK_PBES2, JWK_Pair, JWK_Private, JWK_Public, JWK_RSA, JWK_RSA_ENC, JWK_RSA_PSS, JWK_RSA_Private, JWK_RSA_Public, JWK_RSA_SIGN, JWK_Symmetric, JWK_Symmetric_Algorithm, JWK_oct, JWSAlgorithm, JWSAsymmetricPrivateJWK, JWSAsymmetricPublicJWK, JWSFlattenedSerialization, JWSGeneralSerialization, JWSGeneralSignature, JWSHeaderParameters, JWSMultiSignOptions, JWSMultiSigner, JWSMultiVerifyAllOptions, JWSMultiVerifyOptions, JWSMultiVerifyOutcome, JWSMultiVerifyResult, JWSProtectedHeader, JWSSignJWK, JWSSignOptions, JWSVerifyJWK, JWSVerifyOptions, JWSVerifyResult, JWT, JWTClaimValidationOptions, JWTClaims, JWTError, JWTErrorCauseMap, JWTErrorCode, JWTTimeClaimOptions, JoseHeaderParameters, KeyManagementAlgorithm, KnownJWTErrorCode, MaxTokenAge, NotBeforeIn, PayloadOf, StrictOmit, UnwrapKeyOptions, UnwrapKeyResult, UnwrappingKeyFor, WrapKeyOptions, WrapKeyResult, WrappingKeyFor, isJWTError, isUnsecureError } from "./_chunks/index.mjs";
|
|
2
|
+
import { CompositeKey, ContentEncryptionAlgorithm, DeriveJWKOptions, DeriveJWKReturn, DeriveKeyOptions, DeriveKeyReturn, Duration, ECDHEphemeralKeyInput, ExpiresIn, GenerateJWKOptions, GenerateJWKReturn, GenerateKeyAlgorithm, GenerateKeyOptions, GenerateKeyReturn, GeneratedJWKMap, GeneratedKeyMap, ImportedKey, ImportedKeyMap, ImportedPEMJWK, JOSEConsumerOptions, JOSELimits, JOSEPayload, JOSEPayloadMode, JOSEPayloadTypeMap, JWEAsymmetricPrivateJWK, JWEAsymmetricPublicJWK, JWEDecryptJWK, JWEDecryptOptions, JWEDecryptResult, JWEEncryptJWK, JWEEncryptOptions, JWEFlattenedSerialization, JWEGeneralRecipient, JWEGeneralSerialization, JWEHeaderParameters, JWEKeyLookup, JWEKeyManagementHeaderParameters, JWELibraryHeaderName, JWEMultiDecryptKey, JWEMultiDecryptOptions, JWEMultiDecryptResult, JWEMultiEncryptOptions, JWEMultiRecipient, JWEProtectedHeader, JWK, JWKAlgorithm, JWKCacheAdapter, JWKLookupFunction, JWKLookupFunctionHeader, JWKMetadata, JWKPEMAlgorithm, JWKParameters, JWKSet, JWK_AES_Algorithm, JWK_AES_CBC_HMAC, JWK_AES_GCM, JWK_AES_GCM_KW, JWK_AES_KW, JWK_Asymmetric, JWK_Asymmetric_Algorithm, JWK_EC, JWK_ECDH_ES, JWK_ECDSA, JWK_EC_Private, JWK_EC_Public, JWK_HMAC, JWK_OKP, JWK_OKP_Private, JWK_OKP_Public, JWK_OKP_SIGN, JWK_PBES2, JWK_Pair, JWK_Private, JWK_Public, JWK_RSA, JWK_RSA_ENC, JWK_RSA_PSS, JWK_RSA_Private, JWK_RSA_Public, JWK_RSA_SIGN, JWK_Symmetric, JWK_Symmetric_Algorithm, JWK_oct, JWSAlgorithm, JWSAsymmetricPrivateJWK, JWSAsymmetricPublicJWK, JWSFlattenedSerialization, JWSGeneralSerialization, JWSGeneralSignature, JWSHashedAlgorithm, JWSHeaderParameters, JWSKeyLookup, JWSMultiSignOptions, JWSMultiSigner, JWSMultiVerifyAllOptions, JWSMultiVerifyOptions, JWSMultiVerifyOutcome, JWSMultiVerifyResult, JWSProtectedHeader, JWSSignJWK, JWSSignOptions, JWSVerifyJWK, JWSVerifyOptions, JWSVerifyResult, JWT, JWTClaimValidationOptions, JWTClaims, JWTConfirmation, JWTError, JWTErrorCauseMap, JWTErrorCode, JWTTimeClaimOptions, JoseHeaderParameters, KeyManagementAlgorithm, KeyWrapAlgorithmOf, KeyWrappingAlgorithm, KnownJWTErrorCode, MaxTokenAge, NotBeforeIn, PEMType, PayloadOf, StrictOmit, ToPublicJWKReturn, UnwrapKeyOptions, UnwrapKeyResult, UnwrappingKeyFor, WrapKeyOptions, WrapKeyResult, WrappingKeyFor, isJWTError, isUnsecureError } from "./_chunks/index.mjs";
|
|
3
3
|
import { thumbprint } from "./_chunks/index2.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { DigestHash, digestUrl } from "./_chunks/digest.mjs";
|
|
5
|
+
import { WeakMapJWKCache, clearJWKCache, configureJWKCache, deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, exportJWK, exportKey, exportPEM, generateJWK, generateKey, getJWKsFromSet, importKey, importPEM, toPublicJWK, unwrapKey, wrapKey } from "./core/jwk.mjs";
|
|
5
6
|
import { computeDurationInSeconds, isJWTContent, validateJwtClaims } from "./_chunks/jwt.mjs";
|
|
6
7
|
import { decrypt, decryptMulti, encrypt, encryptMulti, generalToFlattened } from "./_chunks/jwe.mjs";
|
|
7
8
|
import { DEFAULT_JOSE_LIMITS } from "./_chunks/_internal.mjs";
|
|
8
9
|
import { generalToFlattenedJWS, sign, signMulti, verify, verifyMulti, verifyMultiAll } from "./_chunks/jws.mjs";
|
|
9
10
|
import { ComputeJwtTimeClaimsOptions, DecodePayloadOptions, InferAlgorithmsOptions, applyTypCtyDefaults, assertCritShape, assertCryptoKey, base64Decode, base64Encode, base64Parse, base64Stringify, base64UrlDecode, base64UrlEncode, base64UrlParse, base64UrlStringify, computeJwtTimeClaims, concatUint8Arrays, decodePayloadFromB64UrlSegment, decodePayloadFromBytes, getPlaintextBytes, inferJWEAllowedAlgorithms, inferJWSAllowedAlgorithms, isAsymmetricJWK, isCryptoKey, isCryptoKeyPair, isJWK, isJWKSet, isPrivateJWK, isPublicJWK, isSymmetricJWK, maybeArray, validateCriticalHeadersJWE, validateCriticalHeadersJWS } from "./_chunks/index3.mjs";
|
|
10
|
-
export { type BytesSource, type CompositeKey, ComputeJwtTimeClaimsOptions, type ContentEncryptionAlgorithm, DEFAULT_JOSE_LIMITS, type DecodeOptions, DecodePayloadOptions, type DecodeReturnAs, type DeriveKeyOptions, type DeriveKeyReturn, type Duration, type ECDHEphemeralKeyInput, type ExpiresIn, type GenerateJWKOptions, type GenerateJWKReturn, type GenerateKeyAlgorithm, type GenerateKeyOptions, type GenerateKeyReturn, type GeneratedJWKMap, type GeneratedKeyMap, type ImportedKey, type ImportedKeyMap, type InferAlgorithmsOptions, type JOSEConsumerOptions, type JOSELimits, type JOSEPayload, type JOSEPayloadMode, type JOSEPayloadTypeMap, type JWEAsymmetricPrivateJWK, type JWEAsymmetricPublicJWK, type JWEDecryptJWK, type JWEDecryptOptions, type JWEDecryptResult, type JWEEncryptJWK, type JWEEncryptOptions, type JWEFlattenedSerialization, type JWEGeneralRecipient, type JWEGeneralSerialization, type JWEHeaderParameters, type JWEKeyManagementHeaderParameters, type JWELibraryHeaderName, type JWEMultiDecryptKey, type JWEMultiDecryptOptions, type JWEMultiDecryptResult, type JWEMultiEncryptOptions, type JWEMultiRecipient, type JWEProtectedHeader, type JWK, type JWKAlgorithm, type JWKCacheAdapter, type JWKLookupFunction, type JWKLookupFunctionHeader, type JWKMetadata, type JWKPEMAlgorithm, type JWKParameters, type JWKSet, type JWK_AES_CBC_HMAC, type JWK_AES_GCM, type JWK_AES_GCM_KW, type JWK_AES_KW, type JWK_Asymmetric, type JWK_Asymmetric_Algorithm, type JWK_EC, type JWK_ECDH_ES, type JWK_ECDSA, type JWK_EC_Private, type JWK_EC_Public, type JWK_HMAC, type JWK_OKP, type JWK_OKP_Private, type JWK_OKP_Public, type JWK_OKP_SIGN, type JWK_PBES2, type JWK_Pair, type JWK_Private, type JWK_Public, type JWK_RSA, type JWK_RSA_ENC, type JWK_RSA_PSS, type JWK_RSA_Private, type JWK_RSA_Public, type JWK_RSA_SIGN, type JWK_Symmetric, type JWK_Symmetric_Algorithm, type JWK_oct, type JWSAlgorithm, type JWSAsymmetricPrivateJWK, type JWSAsymmetricPublicJWK, type JWSFlattenedSerialization, type JWSGeneralSerialization, type JWSGeneralSignature, type JWSHeaderParameters, type JWSMultiSignOptions, type JWSMultiSigner, type JWSMultiVerifyAllOptions, type JWSMultiVerifyOptions, type JWSMultiVerifyOutcome, type JWSMultiVerifyResult, type JWSProtectedHeader, type JWSSignJWK, type JWSSignOptions, type JWSVerifyJWK, type JWSVerifyOptions, type JWSVerifyResult, type JWT, type JWTClaimValidationOptions, type JWTClaims, JWTError, type JWTErrorCauseMap, type JWTErrorCode, type JWTTimeClaimOptions, type JoseHeaderParameters, type KeyManagementAlgorithm, type KnownJWTErrorCode, type MaxTokenAge, type NotBeforeIn, type PayloadOf, type StrictOmit, UnsecureError, type UnsecureErrorCode, type UnwrapKeyOptions, type UnwrapKeyResult, type UnwrappingKeyFor, WeakMapJWKCache, type WrapKeyOptions, type WrapKeyResult, type WrappingKeyFor, applyTypCtyDefaults, assertCritShape, assertCryptoKey, base64Decode, base64Encode, base64Parse, base64Stringify, base64UrlDecode, base64UrlEncode, base64UrlParse, base64UrlStringify, clearJWKCache, computeDurationInSeconds, computeJwtTimeClaims, concatUint8Arrays, configureJWKCache, decodePayloadFromB64UrlSegment, decodePayloadFromBytes, decrypt, decryptMulti, deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, encrypt, encryptMulti, exportKey, exportPEM, generalToFlattened, generalToFlattenedJWS, generateJWK, generateKey, getJWKsFromSet, getPlaintextBytes, importKey, importPEM, inferJWEAllowedAlgorithms, inferJWSAllowedAlgorithms, isAsymmetricJWK, isCryptoKey, isCryptoKeyPair, isJWK, isJWKSet, isJWTContent, isJWTError, isPrivateJWK, isPublicJWK, isSymmetricJWK, isUnsecureError, maybeArray, safeJsonParse, sanitizeObject, sanitizeObjectCopy, secureRandomBytes, sign, signMulti, textDecoder, textEncoder, thumbprint, unwrapKey, validateCriticalHeadersJWE, validateCriticalHeadersJWS, validateJwtClaims, verify, verifyMulti, verifyMultiAll, wrapKey };
|
|
11
|
+
export { type BytesSource, type CompositeKey, ComputeJwtTimeClaimsOptions, type ContentEncryptionAlgorithm, DEFAULT_JOSE_LIMITS, type DecodeOptions, DecodePayloadOptions, type DecodeReturnAs, type DeriveJWKOptions, type DeriveJWKReturn, type DeriveKeyOptions, type DeriveKeyReturn, type DigestHash, type Duration, type ECDHEphemeralKeyInput, type ExpiresIn, type GenerateJWKOptions, type GenerateJWKReturn, type GenerateKeyAlgorithm, type GenerateKeyOptions, type GenerateKeyReturn, type GeneratedJWKMap, type GeneratedKeyMap, type ImportedKey, type ImportedKeyMap, type ImportedPEMJWK, type InferAlgorithmsOptions, type JOSEConsumerOptions, type JOSELimits, type JOSEPayload, type JOSEPayloadMode, type JOSEPayloadTypeMap, type JWEAsymmetricPrivateJWK, type JWEAsymmetricPublicJWK, type JWEDecryptJWK, type JWEDecryptOptions, type JWEDecryptResult, type JWEEncryptJWK, type JWEEncryptOptions, type JWEFlattenedSerialization, type JWEGeneralRecipient, type JWEGeneralSerialization, type JWEHeaderParameters, type JWEKeyLookup, type JWEKeyManagementHeaderParameters, type JWELibraryHeaderName, type JWEMultiDecryptKey, type JWEMultiDecryptOptions, type JWEMultiDecryptResult, type JWEMultiEncryptOptions, type JWEMultiRecipient, type JWEProtectedHeader, type JWK, type JWKAlgorithm, type JWKCacheAdapter, type JWKLookupFunction, type JWKLookupFunctionHeader, type JWKMetadata, type JWKPEMAlgorithm, type JWKParameters, type JWKSet, type JWK_AES_Algorithm, type JWK_AES_CBC_HMAC, type JWK_AES_GCM, type JWK_AES_GCM_KW, type JWK_AES_KW, type JWK_Asymmetric, type JWK_Asymmetric_Algorithm, type JWK_EC, type JWK_ECDH_ES, type JWK_ECDSA, type JWK_EC_Private, type JWK_EC_Public, type JWK_HMAC, type JWK_OKP, type JWK_OKP_Private, type JWK_OKP_Public, type JWK_OKP_SIGN, type JWK_PBES2, type JWK_Pair, type JWK_Private, type JWK_Public, type JWK_RSA, type JWK_RSA_ENC, type JWK_RSA_PSS, type JWK_RSA_Private, type JWK_RSA_Public, type JWK_RSA_SIGN, type JWK_Symmetric, type JWK_Symmetric_Algorithm, type JWK_oct, type JWSAlgorithm, type JWSAsymmetricPrivateJWK, type JWSAsymmetricPublicJWK, type JWSFlattenedSerialization, type JWSGeneralSerialization, type JWSGeneralSignature, type JWSHashedAlgorithm, type JWSHeaderParameters, type JWSKeyLookup, type JWSMultiSignOptions, type JWSMultiSigner, type JWSMultiVerifyAllOptions, type JWSMultiVerifyOptions, type JWSMultiVerifyOutcome, type JWSMultiVerifyResult, type JWSProtectedHeader, type JWSSignJWK, type JWSSignOptions, type JWSVerifyJWK, type JWSVerifyOptions, type JWSVerifyResult, type JWT, type JWTClaimValidationOptions, type JWTClaims, type JWTConfirmation, JWTError, type JWTErrorCauseMap, type JWTErrorCode, type JWTTimeClaimOptions, type JoseHeaderParameters, type KeyManagementAlgorithm, type KeyWrapAlgorithmOf, type KeyWrappingAlgorithm, type KnownJWTErrorCode, type MaxTokenAge, type NotBeforeIn, type PEMType, type PayloadOf, type StrictOmit, type ToPublicJWKReturn, UnsecureError, type UnsecureErrorCode, type UnwrapKeyOptions, type UnwrapKeyResult, type UnwrappingKeyFor, WeakMapJWKCache, type WrapKeyOptions, type WrapKeyResult, type WrappingKeyFor, applyTypCtyDefaults, assertCritShape, assertCryptoKey, base64Decode, base64Encode, base64Parse, base64Stringify, base64UrlDecode, base64UrlEncode, base64UrlParse, base64UrlStringify, clearJWKCache, computeDurationInSeconds, computeJwtTimeClaims, concatUint8Arrays, configureJWKCache, decodePayloadFromB64UrlSegment, decodePayloadFromBytes, decrypt, decryptMulti, deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, digestUrl, encrypt, encryptMulti, exportJWK, exportKey, exportPEM, generalToFlattened, generalToFlattenedJWS, generateJWK, generateKey, getJWKsFromSet, getPlaintextBytes, importKey, importPEM, inferJWEAllowedAlgorithms, inferJWSAllowedAlgorithms, isAsymmetricJWK, isCryptoKey, isCryptoKeyPair, isJWK, isJWKSet, isJWTContent, isJWTError, isPrivateJWK, isPublicJWK, isSymmetricJWK, isUnsecureError, maybeArray, safeJsonParse, sanitizeObject, sanitizeObjectCopy, secureRandomBytes, sign, signMulti, textDecoder, textEncoder, thumbprint, toPublicJWK, unwrapKey, validateCriticalHeadersJWE, validateCriticalHeadersJWS, validateJwtClaims, verify, verifyMulti, verifyMultiAll, wrapKey };
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { UnsecureError, safeJsonParse, sanitizeObject, sanitizeObjectCopy, secureRandomBytes, textDecoder, textEncoder } from "./_chunks/libs/unsecure.mjs";
|
|
2
2
|
import { JWTError, assertCryptoKey, base64Decode, base64Encode, base64Parse, base64Stringify, base64UrlDecode, base64UrlEncode, base64UrlParse, base64UrlStringify, computeDurationInSeconds, concatUint8Arrays, isAsymmetricJWK, isCryptoKey, isCryptoKeyPair, isJWK, isJWKSet, isJWTContent, isJWTError, isPrivateJWK, isPublicJWK, isSymmetricJWK, isUnsecureError, maybeArray, validateJwtClaims } from "./_chunks/_jwt-internal.mjs";
|
|
3
|
-
import { inferJWEAllowedAlgorithms, inferJWSAllowedAlgorithms } from "./_chunks/
|
|
4
|
-
import { DEFAULT_JOSE_LIMITS, WeakMapJWKCache, clearJWKCache, configureJWKCache, deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, exportKey, exportPEM, generateJWK, generateKey, getJWKsFromSet, importKey, importPEM, thumbprint, unwrapKey, wrapKey } from "./_chunks/jwk.mjs";
|
|
3
|
+
import { digestUrl, inferJWEAllowedAlgorithms, inferJWSAllowedAlgorithms } from "./_chunks/digest.mjs";
|
|
4
|
+
import { DEFAULT_JOSE_LIMITS, WeakMapJWKCache, clearJWKCache, configureJWKCache, deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, exportJWK, exportKey, exportPEM, generateJWK, generateKey, getJWKsFromSet, importKey, importPEM, thumbprint, toPublicJWK, unwrapKey, wrapKey } from "./_chunks/jwk.mjs";
|
|
5
5
|
import { generalToFlattenedJWS, sign, signMulti, verify, verifyMulti, verifyMultiAll } from "./_chunks/jws.mjs";
|
|
6
6
|
import { decrypt, decryptMulti, encrypt, encryptMulti, generalToFlattened } from "./_chunks/jwe.mjs";
|
|
7
7
|
import { applyTypCtyDefaults, assertCritShape, computeJwtTimeClaims, decodePayloadFromB64UrlSegment, decodePayloadFromBytes, getPlaintextBytes, validateCriticalHeadersJWE, validateCriticalHeadersJWS } from "./core/utils/index.mjs";
|
|
8
|
-
export { DEFAULT_JOSE_LIMITS, JWTError, UnsecureError, WeakMapJWKCache, applyTypCtyDefaults, assertCritShape, assertCryptoKey, base64Decode, base64Encode, base64Parse, base64Stringify, base64UrlDecode, base64UrlEncode, base64UrlParse, base64UrlStringify, clearJWKCache, computeDurationInSeconds, computeJwtTimeClaims, concatUint8Arrays, configureJWKCache, decodePayloadFromB64UrlSegment, decodePayloadFromBytes, decrypt, decryptMulti, deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, encrypt, encryptMulti, exportKey, exportPEM, generalToFlattened, generalToFlattenedJWS, generateJWK, generateKey, getJWKsFromSet, getPlaintextBytes, importKey, importPEM, inferJWEAllowedAlgorithms, inferJWSAllowedAlgorithms, isAsymmetricJWK, isCryptoKey, isCryptoKeyPair, isJWK, isJWKSet, isJWTContent, isJWTError, isPrivateJWK, isPublicJWK, isSymmetricJWK, isUnsecureError, maybeArray, safeJsonParse, sanitizeObject, sanitizeObjectCopy, secureRandomBytes, sign, signMulti, textDecoder, textEncoder, thumbprint, unwrapKey, validateCriticalHeadersJWE, validateCriticalHeadersJWS, validateJwtClaims, verify, verifyMulti, verifyMultiAll, wrapKey };
|
|
8
|
+
export { DEFAULT_JOSE_LIMITS, JWTError, UnsecureError, WeakMapJWKCache, applyTypCtyDefaults, assertCritShape, assertCryptoKey, base64Decode, base64Encode, base64Parse, base64Stringify, base64UrlDecode, base64UrlEncode, base64UrlParse, base64UrlStringify, clearJWKCache, computeDurationInSeconds, computeJwtTimeClaims, concatUint8Arrays, configureJWKCache, decodePayloadFromB64UrlSegment, decodePayloadFromBytes, decrypt, decryptMulti, deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, digestUrl, encrypt, encryptMulti, exportJWK, exportKey, exportPEM, generalToFlattened, generalToFlattenedJWS, generateJWK, generateKey, getJWKsFromSet, getPlaintextBytes, importKey, importPEM, inferJWEAllowedAlgorithms, inferJWSAllowedAlgorithms, isAsymmetricJWK, isCryptoKey, isCryptoKeyPair, isJWK, isJWKSet, isJWTContent, isJWTError, isPrivateJWK, isPublicJWK, isSymmetricJWK, isUnsecureError, maybeArray, safeJsonParse, sanitizeObject, sanitizeObjectCopy, secureRandomBytes, sign, signMulti, textDecoder, textEncoder, thumbprint, toPublicJWK, unwrapKey, validateCriticalHeadersJWE, validateCriticalHeadersJWS, validateJwtClaims, verify, verifyMulti, verifyMultiAll, wrapKey };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { CookieJar, JWESessionConfig, JWESessionHooks, JWSSessionConfig, JWSSessionHooks, OpenedSessionState, SessionClaims, SessionContext, SessionData, SessionDecryptOptions, SessionDefinition, SessionDriver, SessionEncryptOptions, SessionIssueOptions, SessionManager, SessionRecord, SessionRequestEvent, SessionRequestHeaders, SessionSignOptions, SessionState, SessionToken, SessionUpdate, SessionUpdateTrigger, SessionVerifyOptions } from "../_chunks/_codec-jwe.mjs";
|
|
2
|
+
import { CookieAttributes } from "../_chunks/_cookie-attributes.mjs";
|
|
3
|
+
import { CompositeKey, ContentEncryptionAlgorithm, DeriveJWKOptions, DeriveJWKReturn, DeriveKeyOptions, DeriveKeyReturn, Duration, ECDHEphemeralKeyInput, ExpiresIn, GenerateJWKOptions, GenerateJWKReturn, GenerateKeyAlgorithm, GenerateKeyOptions, GenerateKeyReturn, GeneratedJWKMap, GeneratedKeyMap, ImportedKey, ImportedKeyMap, ImportedPEMJWK, JOSEConsumerOptions, JOSELimits, JOSEPayload, JOSEPayloadMode, JOSEPayloadTypeMap, JWEAsymmetricPrivateJWK, JWEAsymmetricPublicJWK, JWEDecryptJWK, JWEDecryptOptions, JWEDecryptResult, JWEEncryptJWK, JWEEncryptOptions, JWEFlattenedSerialization, JWEGeneralRecipient, JWEGeneralSerialization, JWEHeaderParameters, JWEKeyLookup, JWEKeyManagementHeaderParameters, JWELibraryHeaderName, JWEMultiDecryptKey, JWEMultiDecryptOptions, JWEMultiDecryptResult, JWEMultiEncryptOptions, JWEMultiRecipient, JWEProtectedHeader, JWK, JWKAlgorithm, JWKCacheAdapter, JWKLookupFunction, JWKLookupFunctionHeader, JWKMetadata, JWKPEMAlgorithm, JWKParameters, JWKSet, JWK_AES_Algorithm, JWK_AES_CBC_HMAC, JWK_AES_GCM, JWK_AES_GCM_KW, JWK_AES_KW, JWK_Asymmetric, JWK_Asymmetric_Algorithm, JWK_EC, JWK_ECDH_ES, JWK_ECDSA, JWK_EC_Private, JWK_EC_Public, JWK_HMAC, JWK_OKP, JWK_OKP_Private, JWK_OKP_Public, JWK_OKP_SIGN, JWK_PBES2, JWK_Pair, JWK_Private, JWK_Public, JWK_RSA, JWK_RSA_ENC, JWK_RSA_PSS, JWK_RSA_Private, JWK_RSA_Public, JWK_RSA_SIGN, JWK_Symmetric, JWK_Symmetric_Algorithm, JWK_oct, JWSAlgorithm, JWSAsymmetricPrivateJWK, JWSAsymmetricPublicJWK, JWSFlattenedSerialization, JWSGeneralSerialization, JWSGeneralSignature, JWSHashedAlgorithm, JWSHeaderParameters, JWSKeyLookup, JWSMultiSignOptions, JWSMultiSigner, JWSMultiVerifyAllOptions, JWSMultiVerifyOptions, JWSMultiVerifyOutcome, JWSMultiVerifyResult, JWSProtectedHeader, JWSSignJWK, JWSSignOptions, JWSVerifyJWK, JWSVerifyOptions, JWSVerifyResult, JWT, JWTClaimValidationOptions, JWTClaims, JWTConfirmation, JWTTimeClaimOptions, JoseHeaderParameters, KeyManagementAlgorithm, KeyWrapAlgorithmOf, KeyWrappingAlgorithm, MaxTokenAge, NotBeforeIn, PEMType, PayloadOf, ToPublicJWKReturn, UnwrapKeyOptions, UnwrapKeyResult, UnwrappingKeyFor, WrapKeyOptions, WrapKeyResult, WrappingKeyFor } from "../_chunks/index.mjs";
|
|
4
|
+
import { thumbprint } from "../_chunks/index2.mjs";
|
|
5
|
+
import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM, toPublicJWK } from "../core/jwk.mjs";
|
|
6
|
+
/** Session state for the current request, mirroring the claims of its JWS token. */
|
|
7
|
+
interface SessionJWS<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> extends SessionState<T, MaxAge> {}
|
|
8
|
+
/** JWS session hooks; `onRead`, `onExpire` and `onError` are mutually exclusive per token. */
|
|
9
|
+
interface SessionHooksJWS<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TContext = SessionContext> extends JWSSessionHooks<SessionJWS<T, MaxAge>, SessionManager<T, MaxAge>, {
|
|
10
|
+
context: TContext;
|
|
11
|
+
}, SessionConfigJWS<T, MaxAge, TContext>> {}
|
|
12
|
+
/** Configuration for a JWS-backed (signed, not encrypted) session. */
|
|
13
|
+
interface SessionConfigJWS<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TContext = SessionContext> extends JWSSessionConfig<MaxAge, CookieAttributes> {
|
|
14
|
+
/** Cookie and session-header name. Default `"unjwt-jws"`; a `.<digits>` suffix throws `ERR_SESSION_CONFIG_INVALID`. */
|
|
15
|
+
name?: string;
|
|
16
|
+
hooks?: SessionHooksJWS<T, MaxAge, TContext>;
|
|
17
|
+
}
|
|
18
|
+
/** Defines a JWS (signed, not encrypted) session once, its data readable by clients; `use`, `token`, `issue` and `open` serve every request. */
|
|
19
|
+
export declare function defineJWSSession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TContext extends SessionContext = SessionContext>(config: SessionConfigJWS<T, MaxAge, TContext>): SessionDefinition<T, MaxAge, TContext>;
|
|
20
|
+
/** Defines a JWS (signed, not encrypted) session over a framework driver of your own. */
|
|
21
|
+
export declare function defineJWSSession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TContext = SessionContext>(config: SessionConfigJWS<T, MaxAge, TContext>, options: {
|
|
22
|
+
driver: SessionDriver<TContext>;
|
|
23
|
+
}): SessionDefinition<T, MaxAge, TContext>;
|
|
24
|
+
/** Session state for the current request, mirroring the claims of its JWE token. */
|
|
25
|
+
interface SessionJWE<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> extends SessionState<T, MaxAge> {}
|
|
26
|
+
/** JWE session hooks; `onRead`, `onExpire` and `onError` are mutually exclusive per token. */
|
|
27
|
+
interface SessionHooksJWE<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TContext = SessionContext> extends JWESessionHooks<SessionJWE<T, MaxAge>, SessionManager<T, MaxAge>, {
|
|
28
|
+
context: TContext;
|
|
29
|
+
}, SessionConfigJWE<T, MaxAge, TContext>> {}
|
|
30
|
+
/** Configuration for a JWE-backed (encrypted) session. */
|
|
31
|
+
interface SessionConfigJWE<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TContext = SessionContext> extends JWESessionConfig<MaxAge, CookieAttributes> {
|
|
32
|
+
/** Cookie and session-header name. Default `"unjwt-jwe"`; a `.<digits>` suffix throws `ERR_SESSION_CONFIG_INVALID`. */
|
|
33
|
+
name?: string;
|
|
34
|
+
hooks?: SessionHooksJWE<T, MaxAge, TContext>;
|
|
35
|
+
}
|
|
36
|
+
/** Defines a JWE (encrypted) session once; `use`, `token`, `issue` and `open` serve every request. */
|
|
37
|
+
export declare function defineJWESession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TContext extends SessionContext = SessionContext>(config: SessionConfigJWE<T, MaxAge, TContext>): SessionDefinition<T, MaxAge, TContext>;
|
|
38
|
+
/** Defines a JWE (encrypted) session over a framework driver of your own. */
|
|
39
|
+
export declare function defineJWESession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TContext = SessionContext>(config: SessionConfigJWE<T, MaxAge, TContext>, options: {
|
|
40
|
+
driver: SessionDriver<TContext>;
|
|
41
|
+
}): SessionDefinition<T, MaxAge, TContext>;
|
|
42
|
+
/** Types a session driver for a framework; pass it to `defineJWSSession` / `defineJWESession` as `{ driver }`. */
|
|
43
|
+
export declare function defineSessionDriver<TContext>(driver: SessionDriver<TContext>): SessionDriver<TContext>;
|
|
44
|
+
export { type CompositeKey, type ContentEncryptionAlgorithm, type CookieAttributes, type CookieJar, type DeriveJWKOptions, type DeriveJWKReturn, type DeriveKeyOptions, type DeriveKeyReturn, type Duration, type ECDHEphemeralKeyInput, type ExpiresIn, type GenerateJWKOptions, type GenerateJWKReturn, type GenerateKeyAlgorithm, type GenerateKeyOptions, type GenerateKeyReturn, type GeneratedJWKMap, type GeneratedKeyMap, type ImportedKey, type ImportedKeyMap, type ImportedPEMJWK, type JOSEConsumerOptions, type JOSELimits, type JOSEPayload, type JOSEPayloadMode, type JOSEPayloadTypeMap, type JWEAsymmetricPrivateJWK, type JWEAsymmetricPublicJWK, type JWEDecryptJWK, type JWEDecryptOptions, type JWEDecryptResult, type JWEEncryptJWK, type JWEEncryptOptions, type JWEFlattenedSerialization, type JWEGeneralRecipient, type JWEGeneralSerialization, type JWEHeaderParameters, type JWEKeyLookup, type JWEKeyManagementHeaderParameters, type JWELibraryHeaderName, type JWEMultiDecryptKey, type JWEMultiDecryptOptions, type JWEMultiDecryptResult, type JWEMultiEncryptOptions, type JWEMultiRecipient, type JWEProtectedHeader, type JWK, type JWKAlgorithm, type JWKCacheAdapter, type JWKLookupFunction, type JWKLookupFunctionHeader, type JWKMetadata, type JWKPEMAlgorithm, type JWKParameters, type JWKSet, type JWK_AES_Algorithm, type JWK_AES_CBC_HMAC, type JWK_AES_GCM, type JWK_AES_GCM_KW, type JWK_AES_KW, type JWK_Asymmetric, type JWK_Asymmetric_Algorithm, type JWK_EC, type JWK_ECDH_ES, type JWK_ECDSA, type JWK_EC_Private, type JWK_EC_Public, type JWK_HMAC, type JWK_OKP, type JWK_OKP_Private, type JWK_OKP_Public, type JWK_OKP_SIGN, type JWK_PBES2, type JWK_Pair, type JWK_Private, type JWK_Public, type JWK_RSA, type JWK_RSA_ENC, type JWK_RSA_PSS, type JWK_RSA_Private, type JWK_RSA_Public, type JWK_RSA_SIGN, type JWK_Symmetric, type JWK_Symmetric_Algorithm, type JWK_oct, type JWSAlgorithm, type JWSAsymmetricPrivateJWK, type JWSAsymmetricPublicJWK, type JWSFlattenedSerialization, type JWSGeneralSerialization, type JWSGeneralSignature, type JWSHashedAlgorithm, type JWSHeaderParameters, type JWSKeyLookup, type JWSMultiSignOptions, type JWSMultiSigner, type JWSMultiVerifyAllOptions, type JWSMultiVerifyOptions, type JWSMultiVerifyOutcome, type JWSMultiVerifyResult, type JWSProtectedHeader, type JWSSignJWK, type JWSSignOptions, type JWSVerifyJWK, type JWSVerifyOptions, type JWSVerifyResult, type JWT, type JWTClaimValidationOptions, type JWTClaims, type JWTConfirmation, type JWTTimeClaimOptions, type JoseHeaderParameters, type KeyManagementAlgorithm, type KeyWrapAlgorithmOf, type KeyWrappingAlgorithm, type MaxTokenAge, type NotBeforeIn, type OpenedSessionState, type PEMType, type PayloadOf, type SessionClaims, type SessionConfigJWE, type SessionConfigJWS, type SessionContext, type SessionData, type SessionDecryptOptions, type SessionDefinition, type SessionDriver, type SessionEncryptOptions, type SessionHooksJWE, type SessionHooksJWS, type SessionIssueOptions, type SessionJWE, type SessionJWS, type SessionManager, type SessionRequestEvent, type SessionRequestHeaders, type SessionSignOptions, type SessionToken, type SessionUpdate, type SessionUpdateTrigger, type SessionVerifyOptions, type ToPublicJWKReturn, type UnwrapKeyOptions, type UnwrapKeyResult, type UnwrappingKeyFor, type WrapKeyOptions, type WrapKeyResult, type WrappingKeyFor, deriveJWKFromPassword, exportPEM, generateJWK, importPEM, thumbprint, toPublicJWK };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM, thumbprint, toPublicJWK } from "../_chunks/jwk.mjs";
|
|
2
|
+
import { createJWECodec, createJWSCodec, defineSession, invalidConfigError, setCookieName, setCookieValues } from "../_chunks/_codec-jws.mjs";
|
|
3
|
+
import { parse, parseSetCookie, serialize } from "../_chunks/libs/cookie-es.mjs";
|
|
4
|
+
function webCookieJar(request, headers) {
|
|
5
|
+
let cookies;
|
|
6
|
+
const jar = { read: (name) => (cookies ||= requestCookies(request))[name] };
|
|
7
|
+
if (headers) {
|
|
8
|
+
jar.written = (name) => setCookieValues(headers.getSetCookie())[name];
|
|
9
|
+
jar.write = (name, value, attrs) => {
|
|
10
|
+
setCookie(headers, {
|
|
11
|
+
name,
|
|
12
|
+
value,
|
|
13
|
+
...attrs
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return jar;
|
|
18
|
+
}
|
|
19
|
+
function requestCookies(request) {
|
|
20
|
+
const header = request.get("cookie");
|
|
21
|
+
return header ? parse(header) : Object.create(null);
|
|
22
|
+
}
|
|
23
|
+
function setCookie(headers, cookie) {
|
|
24
|
+
const line = serialize({
|
|
25
|
+
path: "/",
|
|
26
|
+
...cookie
|
|
27
|
+
});
|
|
28
|
+
const key = cookieKey(cookie);
|
|
29
|
+
const kept = headers.getSetCookie().filter((existing) => {
|
|
30
|
+
const parsed = parseSetCookie(existing);
|
|
31
|
+
return parsed ? cookieKey(parsed) !== key : setCookieName(existing) !== cookie.name;
|
|
32
|
+
});
|
|
33
|
+
headers.delete("set-cookie");
|
|
34
|
+
for (const existing of kept) headers.append("set-cookie", existing);
|
|
35
|
+
headers.append("set-cookie", line);
|
|
36
|
+
}
|
|
37
|
+
function cookieKey(cookie) {
|
|
38
|
+
const domain = (cookie.domain || "").replace(/^\./, "").toLowerCase();
|
|
39
|
+
return [
|
|
40
|
+
cookie.name,
|
|
41
|
+
domain,
|
|
42
|
+
cookie.path || "/",
|
|
43
|
+
cookie.partitioned ? "1" : "0"
|
|
44
|
+
].join(";");
|
|
45
|
+
}
|
|
46
|
+
const PREFIX = "[unjwt/session]";
|
|
47
|
+
const SESSIONS = /* @__PURE__ */ new WeakMap();
|
|
48
|
+
const webSessionDriver = {
|
|
49
|
+
prefix: PREFIX,
|
|
50
|
+
state: (context) => {
|
|
51
|
+
if (isHanded(context)) return sessionsOf(context);
|
|
52
|
+
if (context.context) return contextSessions(context.context);
|
|
53
|
+
return sessionsOf("req" in context ? webRequest(context) : context);
|
|
54
|
+
},
|
|
55
|
+
header: (context, name) => isHanded(context) ? void 0 : requestHeaders(context).get(name),
|
|
56
|
+
cookies: (context) => isHanded(context) ? { read: () => void 0 } : webCookieJar(requestHeaders(context), context.res?.headers),
|
|
57
|
+
handed: (context) => isHanded(context) ? { token: context.token } : void 0
|
|
58
|
+
};
|
|
59
|
+
function isHanded(context) {
|
|
60
|
+
if ("req" in context || "headers" in context) return false;
|
|
61
|
+
if ("token" in context) return true;
|
|
62
|
+
throw invalidConfigError(`${PREFIX} use() got neither a request event, a request's headers, nor a token.`);
|
|
63
|
+
}
|
|
64
|
+
function requestHeaders(context) {
|
|
65
|
+
return "req" in context ? webRequest(context).headers : context.headers;
|
|
66
|
+
}
|
|
67
|
+
function webRequest(context) {
|
|
68
|
+
const headers = context.req.headers;
|
|
69
|
+
if (typeof headers === "object" && headers !== null && "get" in headers) return context.req;
|
|
70
|
+
throw invalidConfigError(`${PREFIX} use() got an event whose "req" is not a web Request.`);
|
|
71
|
+
}
|
|
72
|
+
function contextSessions(context) {
|
|
73
|
+
const existing = context.sessions;
|
|
74
|
+
if (typeof existing === "object" && existing !== null) return existing;
|
|
75
|
+
const created = Object.create(null);
|
|
76
|
+
context.sessions = created;
|
|
77
|
+
return created;
|
|
78
|
+
}
|
|
79
|
+
function sessionsOf(key) {
|
|
80
|
+
const existing = SESSIONS.get(key);
|
|
81
|
+
if (existing) return existing;
|
|
82
|
+
const created = Object.create(null);
|
|
83
|
+
SESSIONS.set(key, created);
|
|
84
|
+
return created;
|
|
85
|
+
}
|
|
86
|
+
function defineJWSSession(config, options) {
|
|
87
|
+
const driver = options?.driver ?? webSessionDriver;
|
|
88
|
+
return defineSession(config, {
|
|
89
|
+
driver,
|
|
90
|
+
hookArgs: (context) => ({ context }),
|
|
91
|
+
codec: createJWSCodec({
|
|
92
|
+
prefix: driver.prefix,
|
|
93
|
+
defaultName: "unjwt-jws"
|
|
94
|
+
})
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function defineJWESession(config, options) {
|
|
98
|
+
const driver = options?.driver ?? webSessionDriver;
|
|
99
|
+
return defineSession(config, {
|
|
100
|
+
driver,
|
|
101
|
+
hookArgs: (context) => ({ context }),
|
|
102
|
+
codec: createJWECodec({
|
|
103
|
+
prefix: driver.prefix,
|
|
104
|
+
defaultName: "unjwt-jwe"
|
|
105
|
+
})
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function defineSessionDriver(driver) {
|
|
109
|
+
return driver;
|
|
110
|
+
}
|
|
111
|
+
export { defineJWESession, defineJWSSession, defineSessionDriver, deriveJWKFromPassword, exportPEM, generateJWK, importPEM, thumbprint, toPublicJWK };
|