unjwt 0.8.0 → 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 +308 -234
- package/dist/_chunks/_cookie-attributes.d.mts +12 -0
- package/dist/_chunks/_jwt-internal.mjs +1 -1
- 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 +5 -4
- package/dist/_chunks/jwe.d.mts +5 -5
- package/dist/_chunks/jwe.mjs +21 -3
- package/dist/_chunks/jwk.mjs +220 -177
- package/dist/_chunks/jws.d.mts +10 -10
- package/dist/_chunks/jws.mjs +18 -6
- package/dist/_chunks/jwt.d.mts +2 -2
- 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 +38 -18
- package/dist/adapters/h3v2/index.d.mts +0 -65
- package/dist/adapters/h3v2/index.mjs +0 -139
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { JWK } from "./index.mjs";
|
|
2
|
+
import { DigestHash } from "./digest.mjs";
|
|
2
3
|
/** Hash functions RFC 7638 §3.4 leaves open to the application. */
|
|
3
|
-
export type ThumbprintHash =
|
|
4
|
+
export type ThumbprintHash = DigestHash;
|
|
4
5
|
/**
|
|
5
6
|
* The base64url JWK Thumbprint of a key (RFC 7638), over its required members only, so a
|
|
6
7
|
* public key and its private counterpart share one. `hash` defaults to `"SHA-256"`
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BytesSource, DecodeOptions, DecodeReturnAs } from "./libs/unsecure.mjs";
|
|
2
2
|
import { JWK, JWKSet, JWK_EC_Private, JWK_EC_Public, JWK_OKP_Private, JWK_OKP_Public, JWK_Private, JWK_Public, JWK_RSA_Private, JWK_RSA_Public, JWK_oct, JWSAlgorithm, KeyManagementAlgorithm } from "./index.mjs";
|
|
3
|
+
import "./digest.mjs";
|
|
3
4
|
import { ComputeJwtTimeClaimsOptions as ComputeJwtTimeClaimsOptions$1, ParsePayloadOptions, applyTypDefault, assertCritShape as assertCritShape$1, computeJwtTimeClaims as computeJwtTimeClaims$1, getPlaintextBytes as getPlaintextBytes$1, parsePayloadBytes, parsePayloadSegment, validateCriticalHeadersJWE as validateCriticalHeadersJWE$1, validateCriticalHeadersJWS as validateCriticalHeadersJWS$1 } from "./jwt.mjs";
|
|
4
5
|
/**
|
|
5
6
|
* Encode bytes or a UTF-8 string as base64url the way JOSE defines it
|
|
@@ -57,19 +58,19 @@ export declare function isCryptoKey(key: unknown): key is CryptoKey;
|
|
|
57
58
|
/** Whether `key` is a `CryptoKeyPair` of two CryptoKeys. */
|
|
58
59
|
export declare const isCryptoKeyPair: (key: unknown) => key is CryptoKeyPair;
|
|
59
60
|
/** Whether the JWK is symmetric (`oct`); its `k` is always secret. */
|
|
60
|
-
export declare function isSymmetricJWK<T>(key: T): key is Extract<T, JWK_oct>;
|
|
61
|
+
export declare function isSymmetricJWK<T extends JWK>(key: T): key is Extract<T, JWK_oct>;
|
|
61
62
|
export declare function isSymmetricJWK(key: unknown): key is JWK_oct;
|
|
62
63
|
/** Whether the JWK is asymmetric (RSA, EC, OKP). */
|
|
63
|
-
export declare function isAsymmetricJWK<T>(key: T): key is Exclude<T, JWK_oct>;
|
|
64
|
+
export declare function isAsymmetricJWK<T extends JWK>(key: T): key is Exclude<T, JWK_oct>;
|
|
64
65
|
export declare function isAsymmetricJWK(key: unknown): key is Exclude<JWK, JWK_oct>;
|
|
65
66
|
/**
|
|
66
67
|
* Whether the JWK holds asymmetric private material (`d`). It is `false` for `oct` keys,
|
|
67
68
|
* so `!isPrivateJWK(key)` is not a "safe to publish" check; use `isPublicJWK`.
|
|
68
69
|
*/
|
|
69
|
-
export declare function isPrivateJWK<T>(key: T): key is Extract<T, JWK_EC_Private | JWK_OKP_Private | JWK_RSA_Private>;
|
|
70
|
+
export declare function isPrivateJWK<T extends JWK>(key: T): key is Extract<T, JWK_EC_Private | JWK_OKP_Private | JWK_RSA_Private>;
|
|
70
71
|
export declare function isPrivateJWK(key: unknown): key is JWK_Private;
|
|
71
72
|
/** Whether the JWK is an asymmetric public key without `d`: the "safe to publish" check. */
|
|
72
|
-
export declare function isPublicJWK<T>(key: T): key is Exclude<Extract<T, JWK_EC_Public | JWK_OKP_Public | JWK_RSA_Public>, JWK_Private>;
|
|
73
|
+
export declare function isPublicJWK<T extends JWK>(key: T): key is Exclude<Extract<T, JWK_EC_Public | JWK_OKP_Public | JWK_RSA_Public>, JWK_Private>;
|
|
73
74
|
export declare function isPublicJWK(key: unknown): key is JWK_Public;
|
|
74
75
|
/** How a JWK Set's entries are read during algorithm inference. */
|
|
75
76
|
export interface InferAlgorithmsOptions {
|
package/dist/_chunks/jwe.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ContentEncryptionAlgorithm, JOSEPayload, JOSEPayloadMode, JWEDecryptJWK, JWEDecryptOptions, JWEDecryptResult, JWEEncryptJWK, JWEEncryptOptions, JWEFlattenedSerialization, JWEGeneralSerialization, JWEMultiDecryptKey, JWEMultiDecryptOptions, JWEMultiDecryptResult, JWEMultiEncryptOptions, JWEMultiRecipient,
|
|
1
|
+
import { ContentEncryptionAlgorithm, JOSEPayload, JOSEPayloadMode, JWEDecryptJWK, JWEDecryptOptions, JWEDecryptResult, JWEEncryptJWK, JWEEncryptOptions, JWEFlattenedSerialization, JWEGeneralSerialization, JWEKeyLookup, JWEMultiDecryptKey, JWEMultiDecryptOptions, JWEMultiDecryptResult, JWEMultiEncryptOptions, JWEMultiRecipient, JWKSet, JWTClaims, KeyManagementAlgorithm, PayloadOf } from "./index.mjs";
|
|
2
2
|
import "./_internal.mjs";
|
|
3
3
|
/**
|
|
4
4
|
* Encrypt a payload to multiple recipients as JWE General JSON Serialization (RFC 7516 §7.2.1).
|
|
@@ -13,7 +13,7 @@ export declare function encryptMulti(payload: JOSEPayload, recipients: JWEMultiR
|
|
|
13
13
|
* `ERR_JWE_NO_MATCHING_RECIPIENT` when none qualifies; a JWK Set with no `kid` candidate
|
|
14
14
|
* throws `ERR_JWK_KEY_NOT_FOUND`. The payload type follows `options.payload`.
|
|
15
15
|
*/
|
|
16
|
-
export declare function decryptMulti<T extends
|
|
16
|
+
export declare function decryptMulti<T extends object = JWTClaims>(jwe: JWEGeneralSerialization | JWEFlattenedSerialization, keyOrLookup: JWEMultiDecryptKey, options?: JWEMultiDecryptOptions<"json"> & {
|
|
17
17
|
forceUint8Array?: false;
|
|
18
18
|
}): Promise<JWEMultiDecryptResult<T>>;
|
|
19
19
|
/** @deprecated `forceUint8Array` is replaced by `payload: "bytes"`; removed in v0.9.0. */
|
|
@@ -50,12 +50,12 @@ export declare function encrypt(payload: JOSEPayload, key: CryptoKey | JWEEncryp
|
|
|
50
50
|
* Decrypt a JWE Compact Serialization string; `key` may be a lookup function.
|
|
51
51
|
* The payload type follows `options.payload` (claims `T` by default).
|
|
52
52
|
*/
|
|
53
|
-
export declare function decrypt<T extends
|
|
53
|
+
export declare function decrypt<T extends object = JWTClaims>(jwe: string, key: CryptoKey | JWKSet | JWEDecryptJWK | string | Uint8Array<ArrayBuffer> | JWEKeyLookup, options?: JWEDecryptOptions<"json"> & {
|
|
54
54
|
forceUint8Array?: false;
|
|
55
55
|
}): Promise<JWEDecryptResult<T>>;
|
|
56
56
|
/** @deprecated `forceUint8Array` is replaced by `payload: "bytes"`; removed in v0.9.0. */
|
|
57
|
-
export declare function decrypt(jwe: string, key: CryptoKey | JWKSet | JWEDecryptJWK | string | Uint8Array<ArrayBuffer> |
|
|
57
|
+
export declare function decrypt(jwe: string, key: CryptoKey | JWKSet | JWEDecryptJWK | string | Uint8Array<ArrayBuffer> | JWEKeyLookup, options: JWEDecryptOptions & {
|
|
58
58
|
forceUint8Array: true;
|
|
59
59
|
}): Promise<JWEDecryptResult<Uint8Array<ArrayBuffer>>>;
|
|
60
60
|
/** Decrypts a compact JWE whose plaintext decodes under `options.payload`; see {@link PayloadOf}. */
|
|
61
|
-
export declare function decrypt<Mode extends JOSEPayloadMode = JOSEPayloadMode>(jwe: string, key: CryptoKey | JWKSet | JWEDecryptJWK | string | Uint8Array<ArrayBuffer> |
|
|
61
|
+
export declare function decrypt<Mode extends JOSEPayloadMode = JOSEPayloadMode>(jwe: string, key: CryptoKey | JWKSet | JWEDecryptJWK | string | Uint8Array<ArrayBuffer> | JWEKeyLookup, options?: JWEDecryptOptions<Mode>): Promise<JWEDecryptResult<PayloadOf<Mode>>>;
|
package/dist/_chunks/jwe.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { sanitizeObjectCopy, secureRandomBytes, textEncoder } from "./libs/unsecure.mjs";
|
|
2
2
|
import { JWTError, applyTypDefault, base64UrlStringify, computeJwtTimeClaims, getPlaintextBytes, isJWK, isJWKSet, validateCriticalHeadersJWE } from "./_jwt-internal.mjs";
|
|
3
|
-
import { isContentEncryptionAlgorithm } from "./
|
|
4
|
-
import { DEFAULT_PBES2_ITERATIONS, JWE_ALG_CTX, JWE_DIRECT_ALGS, asDecryptionError, asKeyLookupError, assertCompactToken, assertConsumerOptions, assertDirectKeyRole, assertEntryLimit, assertJWEAlgSupported, assertJWEEncSupported, assertJWKSetCandidates, assertNoZipOption, assertOptionEntry, assertPBES2Params, assertProducerCEK, assertProducerCrit, assertProducerIV, assertProtectedOnlyOption, assertSerializationObject, buildECDHAgreementParams, buildJWKSetFilter, buildUnwrapKeyOptions, checkAlgAllowed, checkJWEAlgSupported, checkJWEContentSegments, checkJWEDirectEncryptedKey, checkJWEEncAllowed, checkJWEEncSupported, checkJWEUnprotectedCrit, checkJWEZip, checkProtectedTyp, checkSerializationEntry, createPBES2Budget, decodeJWEPayload, decodeProtectedHeader, decodeSegment, decrypt as decrypt$1, encrypt as encrypt$1, encryptKey, exportReturnedCek, generateCEK, generateIV, getJWKsFromSet, importKey, isJWEAlgSupported, keyMatchesHeader, resolveKeyInput, resolveLimit, resolvePasswordKey, resolvePayloadMode, serializeProtectedHeader, unwrapKey, validateClaimsIfJson } from "./jwk.mjs";
|
|
3
|
+
import { isContentEncryptionAlgorithm, isPBES2Algorithm } from "./digest.mjs";
|
|
4
|
+
import { DEFAULT_PBES2_ITERATIONS, JWE_ALG_CTX, JWE_DIRECT_ALGS, asDecryptionError, asKeyLookupError, assertCompactToken, assertConsumerOptions, assertDirectKeyRole, assertEntryLimit, assertJWEAlgSupported, assertJWEEncSupported, assertJWKSetCandidates, assertNoZipOption, assertOptionEntry, assertPBES2Params, assertProducerCEK, assertProducerConfirmation, assertProducerCrit, assertProducerIV, assertProducerKeyHeaders, assertProtectedOnlyOption, assertSerializationObject, buildECDHAgreementParams, buildJWKSetFilter, buildUnwrapKeyOptions, checkAlgAllowed, checkJWEAlgSupported, checkJWEContentSegments, checkJWEDirectEncryptedKey, checkJWEEncAllowed, checkJWEEncSupported, checkJWEUnprotectedCrit, checkJWEZip, checkProtectedTyp, checkSerializationEntry, createPBES2Budget, decodeJWEPayload, decodeProtectedHeader, decodeSegment, decrypt as decrypt$1, encrypt as encrypt$1, encryptKey, exportReturnedCek, generateCEK, generateIV, getJWKsFromSet, importKey, isJWEAlgSupported, keyMatchesHeader, resolveKeyInput, resolveLimit, resolvePasswordKey, resolvePayloadMode, serializeProtectedHeader, unwrapKey, validateClaimsIfJson } from "./jwk.mjs";
|
|
5
5
|
function buildKeyManagementParams(alg, source) {
|
|
6
6
|
const { keyManagementIV, p2s, p2c, ecdh } = source;
|
|
7
7
|
const isPBES2 = alg.startsWith("PBES2");
|
|
@@ -74,6 +74,15 @@ async function encryptMulti(payload, recipients, options = {}) {
|
|
|
74
74
|
tier: "shared unprotected",
|
|
75
75
|
family: "JWE"
|
|
76
76
|
});
|
|
77
|
+
assertProducerKeyHeaders(options.protectedHeader, {
|
|
78
|
+
tier: "protected",
|
|
79
|
+
family: "JWE"
|
|
80
|
+
});
|
|
81
|
+
assertProducerKeyHeaders(options.sharedUnprotectedHeader, {
|
|
82
|
+
tier: "shared unprotected",
|
|
83
|
+
family: "JWE"
|
|
84
|
+
});
|
|
85
|
+
assertProducerConfirmation(payload);
|
|
77
86
|
for (const [index, recipient] of recipients.entries()) {
|
|
78
87
|
assertOptionEntry(recipient, {
|
|
79
88
|
label: `recipients[${index}]`,
|
|
@@ -84,6 +93,10 @@ async function encryptMulti(payload, recipients, options = {}) {
|
|
|
84
93
|
tier: "per-recipient",
|
|
85
94
|
family: "JWE"
|
|
86
95
|
});
|
|
96
|
+
assertProducerKeyHeaders(recipient.header, {
|
|
97
|
+
tier: "per-recipient",
|
|
98
|
+
family: "JWE"
|
|
99
|
+
});
|
|
87
100
|
}
|
|
88
101
|
const resolvedAlgs = recipients.map((r, i) => _resolveRecipientAlg(r.key, i));
|
|
89
102
|
const enc = options.enc ?? "A256GCM";
|
|
@@ -388,6 +401,11 @@ async function encrypt(payload, key, options = {}) {
|
|
|
388
401
|
label: "options",
|
|
389
402
|
objects: ["protectedHeader"]
|
|
390
403
|
});
|
|
404
|
+
assertProducerKeyHeaders(options.protectedHeader, {
|
|
405
|
+
tier: "protected",
|
|
406
|
+
family: "JWE"
|
|
407
|
+
});
|
|
408
|
+
assertProducerConfirmation(payload);
|
|
391
409
|
const { protectedHeader: userHeader, cek: providedCek, contentEncryptionIV: providedContentIV, keyManagementIV, p2s, p2c, ecdh } = options;
|
|
392
410
|
let alg = options.alg;
|
|
393
411
|
let enc = options.enc;
|
|
@@ -409,7 +427,7 @@ async function encrypt(payload, key, options = {}) {
|
|
|
409
427
|
assertJWEEncSupported(enc);
|
|
410
428
|
assertProducerCEK(providedCek, enc);
|
|
411
429
|
assertProducerIV(providedContentIV, enc);
|
|
412
|
-
if (alg
|
|
430
|
+
if (isPBES2Algorithm(alg)) assertPBES2Params({
|
|
413
431
|
p2s,
|
|
414
432
|
p2c
|
|
415
433
|
});
|