unjwt 0.8.2 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/core/jws.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { UnsecureError } from "../_chunks/libs/unsecure.mjs";
2
2
  import { JWTError, isJWTError, isUnsecureError } from "../_chunks/_jwt-internal.mjs";
3
- import { DEFAULT_JOSE_LIMITS } from "../_chunks/jwk.mjs";
3
+ import { DEFAULT_JOSE_LIMITS } from "../_chunks/_import-key.mjs";
4
4
  import { generalToFlattenedJWS, sign, signMulti, verify, verifyMulti, verifyMultiAll } from "../_chunks/jws.mjs";
5
5
  export { DEFAULT_JOSE_LIMITS, JWTError, UnsecureError, generalToFlattenedJWS, isJWTError, isUnsecureError, sign, signMulti, verify, verifyMulti, verifyMultiAll };
package/dist/index.d.mts CHANGED
@@ -2,7 +2,7 @@ import { BytesSource, DecodeOptions, DecodeReturnAs, UnsecureError, UnsecureErro
2
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
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
+ import { WeakMapJWKCache, clearJWKCache, configureJWKCache, deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, exportJWK, exportKey, exportPEM, generateJWK, generateKey, getJWKsFromSet, importKey, importPEM, toPublicJWK, unwrapKey, wrapKey } from "./_chunks/jwk.mjs";
6
6
  import { computeDurationInSeconds, isJWTContent, validateJwtClaims } from "./_chunks/jwt.mjs";
7
7
  import { decrypt, decryptMulti, encrypt, encryptMulti, generalToFlattened } from "./_chunks/jwe.mjs";
8
8
  import { DEFAULT_JOSE_LIMITS } from "./_chunks/_internal.mjs";
package/dist/index.mjs CHANGED
@@ -1,8 +1,9 @@
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
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";
4
+ import { DEFAULT_JOSE_LIMITS, WeakMapJWKCache, clearJWKCache, configureJWKCache, getJWKsFromSet, importKey, thumbprint } from "./_chunks/_import-key.mjs";
5
5
  import { generalToFlattenedJWS, sign, signMulti, verify, verifyMulti, verifyMultiAll } from "./_chunks/jws.mjs";
6
+ import { deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, exportJWK, exportKey, exportPEM, generateJWK, generateKey, importPEM, toPublicJWK, unwrapKey, wrapKey } from "./core/jwk.mjs";
6
7
  import { decrypt, decryptMulti, encrypt, encryptMulti, generalToFlattened } from "./_chunks/jwe.mjs";
7
8
  import { applyTypCtyDefaults, assertCritShape, computeJwtTimeClaims, decodePayloadFromB64UrlSegment, decodePayloadFromBytes, getPlaintextBytes, validateCriticalHeadersJWE, validateCriticalHeadersJWS } from "./core/utils/index.mjs";
8
9
  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 };
@@ -1,44 +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";
1
+ import { CookieJar, JWESessionConfig, JWESessionHooks, JWSSessionConfig, JWSSessionHooks, OpenedSessionState, SessionClaims, SessionData, SessionDecryptOptions, SessionDefinition, SessionDriver, SessionEncryptOptions, SessionHandedToken, SessionIssueOptions, SessionManager, SessionRecord, SessionRequestEvent, SessionSignOptions, SessionState, SessionUpdate, SessionUpdateTrigger, SessionVerifyOptions, WebSessionEvent } from "../_chunks/_codec-jwe.mjs";
2
2
  import { CookieAttributes } from "../_chunks/_cookie-attributes.mjs";
3
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
4
  import { thumbprint } from "../_chunks/index2.mjs";
5
- import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM, toPublicJWK } from "../core/jwk.mjs";
5
+ import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM, toPublicJWK } from "../_chunks/jwk.mjs";
6
6
  /** Session state for the current request, mirroring the claims of its JWS token. */
7
7
  interface SessionJWS<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> extends SessionState<T, MaxAge> {}
8
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>> {}
9
+ interface SessionHooksJWS<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent = WebSessionEvent> extends JWSSessionHooks<SessionJWS<T, MaxAge>, SessionManager<T, MaxAge>, {
10
+ event: TEvent;
11
+ }, SessionConfigJWS<T, MaxAge, TEvent>> {}
12
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> {
13
+ interface SessionConfigJWS<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent = WebSessionEvent> extends JWSSessionConfig<MaxAge, CookieAttributes> {
14
14
  /** Cookie and session-header name. Default `"unjwt-jws"`; a `.<digits>` suffix throws `ERR_SESSION_CONFIG_INVALID`. */
15
15
  name?: string;
16
- hooks?: SessionHooksJWS<T, MaxAge, TContext>;
16
+ hooks?: SessionHooksJWS<T, MaxAge, TEvent>;
17
17
  }
18
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>;
19
+ export declare function defineJWSSession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends WebSessionEvent = WebSessionEvent>(config: SessionConfigJWS<T, MaxAge, TEvent>): SessionDefinition<T, MaxAge, TEvent>;
20
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>;
21
+ export declare function defineJWSSession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent = WebSessionEvent>(config: SessionConfigJWS<T, MaxAge, TEvent>, options: {
22
+ driver: SessionDriver<TEvent>;
23
+ }): SessionDefinition<T, MaxAge, TEvent>;
24
24
  /** Session state for the current request, mirroring the claims of its JWE token. */
25
25
  interface SessionJWE<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> extends SessionState<T, MaxAge> {}
26
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>> {}
27
+ interface SessionHooksJWE<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent = WebSessionEvent> extends JWESessionHooks<SessionJWE<T, MaxAge>, SessionManager<T, MaxAge>, {
28
+ event: TEvent;
29
+ }, SessionConfigJWE<T, MaxAge, TEvent>> {}
30
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> {
31
+ interface SessionConfigJWE<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent = WebSessionEvent> extends JWESessionConfig<MaxAge, CookieAttributes> {
32
32
  /** Cookie and session-header name. Default `"unjwt-jwe"`; a `.<digits>` suffix throws `ERR_SESSION_CONFIG_INVALID`. */
33
33
  name?: string;
34
- hooks?: SessionHooksJWE<T, MaxAge, TContext>;
34
+ hooks?: SessionHooksJWE<T, MaxAge, TEvent>;
35
35
  }
36
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>;
37
+ export declare function defineJWESession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends WebSessionEvent = WebSessionEvent>(config: SessionConfigJWE<T, MaxAge, TEvent>): SessionDefinition<T, MaxAge, TEvent>;
38
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>;
39
+ export declare function defineJWESession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent = WebSessionEvent>(config: SessionConfigJWE<T, MaxAge, TEvent>, options: {
40
+ driver: SessionDriver<TEvent>;
41
+ }): SessionDefinition<T, MaxAge, TEvent>;
42
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 };
43
+ export declare function defineSessionDriver<TEvent>(driver: SessionDriver<TEvent>): SessionDriver<TEvent>;
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 SessionData, type SessionDecryptOptions, type SessionDefinition, type SessionDriver, type SessionEncryptOptions, type SessionHandedToken, type SessionHooksJWE, type SessionHooksJWS, type SessionIssueOptions, type SessionJWE, type SessionJWS, type SessionManager, type SessionRequestEvent, type SessionSignOptions, type SessionUpdate, type SessionUpdateTrigger, type SessionVerifyOptions, type ToPublicJWKReturn, type UnwrapKeyOptions, type UnwrapKeyResult, type UnwrappingKeyFor, type WebSessionEvent, type WrapKeyOptions, type WrapKeyResult, type WrappingKeyFor, deriveJWKFromPassword, exportPEM, generateJWK, importPEM, thumbprint, toPublicJWK };
@@ -1,4 +1,5 @@
1
- import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM, thumbprint, toPublicJWK } from "../_chunks/jwk.mjs";
1
+ import { thumbprint } from "../_chunks/_import-key.mjs";
2
+ import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM, toPublicJWK } from "../core/jwk.mjs";
2
3
  import { createJWECodec, createJWSCodec, defineSession, invalidConfigError, setCookieName, setCookieValues } from "../_chunks/_codec-jws.mjs";
3
4
  import { parse, parseSetCookie, serialize } from "../_chunks/libs/cookie-es.mjs";
4
5
  function webCookieJar(request, headers) {
@@ -47,26 +48,28 @@ const PREFIX = "[unjwt/session]";
47
48
  const SESSIONS = /* @__PURE__ */ new WeakMap();
48
49
  const webSessionDriver = {
49
50
  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);
51
+ state: (event) => {
52
+ if (isHanded(event)) return sessionsOf(event);
53
+ if (event.context) return contextSessions(event.context);
54
+ return sessionsOf(event.req ? webRequest(event.req) : event);
54
55
  },
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
56
+ header: (event, name) => isHanded(event) ? void 0 : requestHeaders(event).get(name),
57
+ cookies: (event) => isHanded(event) ? { read: () => void 0 } : webCookieJar(requestHeaders(event), event.res?.headers),
58
+ handed: (event) => isHanded(event) ? { token: event.token } : void 0
58
59
  };
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.`);
60
+ function isHanded(event) {
61
+ if ("req" in event || "headers" in event) return false;
62
+ if ("token" in event) return true;
63
+ throw invalidConfigError(`${PREFIX} use() got neither a request event nor a token.`);
63
64
  }
64
- function requestHeaders(context) {
65
- return "req" in context ? webRequest(context).headers : context.headers;
65
+ function requestHeaders(event) {
66
+ if (event.req) return webRequest(event.req).headers;
67
+ if (event.headers) return event.headers;
68
+ throw invalidConfigError(`${PREFIX} use() got a request event with neither "req" nor "headers".`);
66
69
  }
67
- function webRequest(context) {
68
- const headers = context.req.headers;
69
- if (typeof headers === "object" && headers !== null && "get" in headers) return context.req;
70
+ function webRequest(req) {
71
+ const headers = req.headers;
72
+ if (typeof headers === "object" && headers !== null && "get" in headers) return req;
70
73
  throw invalidConfigError(`${PREFIX} use() got an event whose "req" is not a web Request.`);
71
74
  }
72
75
  function contextSessions(context) {
@@ -87,7 +90,7 @@ function defineJWSSession(config, options) {
87
90
  const driver = options?.driver ?? webSessionDriver;
88
91
  return defineSession(config, {
89
92
  driver,
90
- hookArgs: (context) => ({ context }),
93
+ hookArgs: (event) => ({ event }),
91
94
  codec: createJWSCodec({
92
95
  prefix: driver.prefix,
93
96
  defaultName: "unjwt-jws"
@@ -98,7 +101,7 @@ function defineJWESession(config, options) {
98
101
  const driver = options?.driver ?? webSessionDriver;
99
102
  return defineSession(config, {
100
103
  driver,
101
- hookArgs: (context) => ({ context }),
104
+ hookArgs: (event) => ({ event }),
102
105
  codec: createJWECodec({
103
106
  prefix: driver.prefix,
104
107
  defaultName: "unjwt-jwe"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unjwt",
3
- "version": "0.8.2",
3
+ "version": "0.8.4",
4
4
  "description": "A collection of JWT utilities based on the Web Crypto API.",
5
5
  "keywords": [
6
6
  "auth",
@@ -105,7 +105,7 @@
105
105
  "simple-git-hooks": "^2.14.0",
106
106
  "supertest": "^7.3.1",
107
107
  "typescript": "^7.0.2",
108
- "unsecure": "^0.3.2",
108
+ "unsecure": "^0.3.3",
109
109
  "vitest": "^5.0.4"
110
110
  },
111
111
  "peerDependencies": {
@@ -142,6 +142,7 @@
142
142
  "dev:nitro": "pnpm --dir playgrounds/nitro dev",
143
143
  "dev:prepare": "obuild --stub && pnpm --dir playgrounds/nuxt-4 prepare && pnpm simple-git-hooks",
144
144
  "lint": "oxlint --deny-warnings . && oxfmt --check .",
145
+ "size": "vitest run test/bundle.test.ts --reporter=./test/_size-reporter.ts",
145
146
  "fmt": "automd && oxlint --fix . && oxfmt .",
146
147
  "test": "vitest run --slowTestThreshold=1000",
147
148
  "test:coverage": "vitest run --coverage --slowTestThreshold=1000",