unjwt 0.7.2 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/THIRD-PARTY-LICENSES.md.gz +0 -0
- package/dist/_chunks/_codec-jwe.d.mts +170 -0
- package/dist/_chunks/_codec-jws.mjs +878 -0
- package/dist/_chunks/_internal.d.mts +7 -0
- package/dist/_chunks/_jwt-internal.mjs +388 -0
- package/dist/_chunks/algorithms.mjs +186 -0
- package/dist/_chunks/index.d.mts +512 -818
- package/dist/_chunks/index2.d.mts +11 -0
- package/dist/_chunks/index3.d.mts +108 -0
- package/dist/_chunks/jwe.d.mts +43 -66
- package/dist/_chunks/jwe.mjs +384 -252
- package/dist/_chunks/jwk.mjs +1390 -622
- package/dist/_chunks/jws.d.mts +48 -103
- package/dist/_chunks/jws.mjs +372 -184
- package/dist/_chunks/jwt.d.mts +56 -0
- package/dist/_chunks/libs/unsecure.d.mts +164 -85
- package/dist/_chunks/libs/unsecure.mjs +390 -123
- package/dist/adapters/elysia/index.d.mts +33 -171
- package/dist/adapters/elysia/index.mjs +106 -575
- package/dist/adapters/h3v1/index.d.mts +59 -344
- package/dist/adapters/h3v1/index.mjs +114 -619
- package/dist/adapters/h3v2/index.d.mts +58 -326
- package/dist/adapters/h3v2/index.mjs +108 -611
- package/dist/core/internal.d.mts +2 -0
- package/dist/core/internal.mjs +1 -0
- package/dist/core/jwe.d.mts +4 -2
- package/dist/core/jwe.mjs +4 -2
- package/dist/core/jwk.d.mts +183 -371
- package/dist/core/jwk.mjs +4 -3
- package/dist/core/jws.d.mts +4 -2
- package/dist/core/jws.mjs +4 -2
- package/dist/core/utils/index.d.mts +5 -155
- package/dist/core/utils/index.mjs +12 -3
- package/dist/index.d.mts +8 -4
- package/dist/index.mjs +6 -3
- package/package.json +39 -36
- package/dist/_chunks/_internal.mjs +0 -88
- package/dist/_chunks/utils.mjs +0 -390
package/dist/_chunks/jws.d.mts
CHANGED
|
@@ -1,111 +1,56 @@
|
|
|
1
|
-
import { JOSEPayload, JWKLookupFunction, JWKSet, JWSAlgorithm, JWSFlattenedSerialization, JWSGeneralSerialization, JWSMultiSignOptions, JWSMultiSigner, JWSMultiVerifyAllOptions, JWSMultiVerifyOptions, JWSMultiVerifyOutcome, JWSMultiVerifyResult, JWSSignJWK, JWSSignOptions, JWSVerifyJWK, JWSVerifyOptions, JWSVerifyResult } from "./index.mjs";
|
|
1
|
+
import { JOSEPayload, JOSEPayloadMode, JWKLookupFunction, JWKSet, JWSAlgorithm, JWSFlattenedSerialization, JWSGeneralSerialization, JWSMultiSignOptions, JWSMultiSigner, JWSMultiVerifyAllOptions, JWSMultiVerifyOptions, JWSMultiVerifyOutcome, JWSMultiVerifyResult, JWSSignJWK, JWSSignOptions, JWSVerifyJWK, JWSVerifyOptions, JWSVerifyResult, JWTClaims, PayloadOf } from "./index.mjs";
|
|
2
|
+
import "./_internal.mjs";
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* using its own key-declared algorithm. Per-signer `alg` is read from
|
|
9
|
-
* `key.alg` and throws `ERR_JWS_SIGNER_ALG_INFERENCE` when absent.
|
|
10
|
-
*
|
|
11
|
-
* Per RFC 7797 §3, `b64` MUST be consistent across every signer. If one
|
|
12
|
-
* signer sets `b64: false` in its protected header, every other signer
|
|
13
|
-
* must match or this function throws `ERR_JWS_B64_INCONSISTENT`.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* const jws = await signMulti({ sub: "u1" }, [
|
|
17
|
-
* { key: alicePrivateJwk },
|
|
18
|
-
* { key: bobPrivateJwk, protectedHeader: { typ: "vc+jwt" } },
|
|
19
|
-
* ], { expiresIn: "1h" });
|
|
20
|
-
*/
|
|
21
|
-
declare function signMulti(payload: JOSEPayload, signers: JWSMultiSigner[], options?: JWSMultiSignOptions): Promise<JWSGeneralSerialization>;
|
|
4
|
+
* Signs a payload with multiple signers as a JWS General JSON Serialization (RFC 7515 §7.2.1).
|
|
5
|
+
* Each signer's `alg` is inferred from its key when omitted (`ERR_JWS_SIGNER_ALG_INFERENCE`);
|
|
6
|
+
* `b64` must match across signers (RFC 7797 §3, `ERR_JWS_B64_INCONSISTENT`).
|
|
7
|
+
*/
|
|
8
|
+
export declare function signMulti(payload: JOSEPayload, signers: JWSMultiSigner[], options?: JWSMultiSignOptions): Promise<JWSGeneralSerialization>;
|
|
22
9
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
* Verify every signature in a JWS independently and return a per-signature
|
|
36
|
-
* outcome array — the caller applies their own policy (all-must-verify,
|
|
37
|
-
* M-of-N quorum, specific-signer checks, audit logs, etc.).
|
|
38
|
-
*
|
|
39
|
-
* Unlike {@link verifyMulti}, this function never throws on an individual
|
|
40
|
-
* signature's failure — malformed protected headers, disallowed `alg`s,
|
|
41
|
-
* `typ` mismatches, key-resolver errors, bad signatures, critical header
|
|
42
|
-
* violations, and JWT claim failures are all collected into
|
|
43
|
-
* {@link JWSMultiVerifyOutcome} entries with `verified: false`.
|
|
44
|
-
*
|
|
45
|
-
* Structural errors in the envelope itself (non-object input, missing
|
|
46
|
-
* `payload` / `signatures[]`) still throw `ERR_JWS_INVALID_SERIALIZATION`
|
|
47
|
-
* — there's no per-signature outcome to return in that case.
|
|
48
|
-
*
|
|
49
|
-
* Requires a {@link JWKLookupFunction} because different signatures almost
|
|
50
|
-
* always need different keys. Wrap a static `JWKSet` as `(header) => mySet`
|
|
51
|
-
* if that's all you have.
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* // All signatures must verify
|
|
55
|
-
* const outcomes = await verifyMultiAll(jws, myKeyResolver);
|
|
56
|
-
* if (!outcomes.every((o) => o.verified)) {
|
|
57
|
-
* throw new Error("not all signatures verified");
|
|
58
|
-
* }
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* // Quorum — at least 2 valid signatures from a recognised signer set
|
|
62
|
-
* const outcomes = await verifyMultiAll(jws, myKeyResolver);
|
|
63
|
-
* const validKids = outcomes
|
|
64
|
-
* .filter((o) => o.verified)
|
|
65
|
-
* .map((o) => o.protectedHeader.kid);
|
|
66
|
-
* if (new Set(validKids).size < 2) {
|
|
67
|
-
* throw new Error("quorum not met");
|
|
68
|
-
* }
|
|
69
|
-
*/
|
|
70
|
-
declare function verifyMultiAll<T extends JOSEPayload = JOSEPayload>(jws: JWSGeneralSerialization | JWSFlattenedSerialization, keyResolver: JWKLookupFunction, options?: JWSMultiVerifyAllOptions): Promise<JWSMultiVerifyOutcome<T>[]>;
|
|
71
|
-
/**
|
|
72
|
-
* Convert a {@link JWSGeneralSerialization} with exactly one signature into
|
|
73
|
-
* the {@link JWSFlattenedSerialization} form (RFC 7515 §7.2.2). Throws
|
|
74
|
-
* `ERR_JWS_INVALID_SERIALIZATION` when the input has zero or multiple
|
|
75
|
-
* signatures — Flattened is strictly single-signature.
|
|
76
|
-
*
|
|
77
|
-
* `signMulti` never emits Flattened itself (stable return shape across
|
|
78
|
-
* signer counts); this is the canonical post-processing step when
|
|
79
|
-
* interoperating with a strict Flattened-only consumer.
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* const general = await signMulti(payload, [signer], opts);
|
|
83
|
-
* const flattened = generalToFlattenedJWS(general);
|
|
84
|
-
*/
|
|
85
|
-
declare function generalToFlattenedJWS(jws: JWSGeneralSerialization): JWSFlattenedSerialization;
|
|
10
|
+
* Verifies a JWS General or Flattened JSON Serialization (RFC 7515 §7.2) and returns the first signature that verifies.
|
|
11
|
+
* Per-signature failures are collected and the last one is thrown when none verifies.
|
|
12
|
+
* The payload type follows `options.payload`, as in `verify`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function verifyMulti<T extends Record<string, unknown> = JWTClaims>(jws: JWSGeneralSerialization | JWSFlattenedSerialization, keyOrLookup: CryptoKey | JWKSet | JWSVerifyJWK | Uint8Array<ArrayBuffer> | JWKLookupFunction, options?: JWSMultiVerifyOptions<"json"> & {
|
|
15
|
+
forceUint8Array?: false;
|
|
16
|
+
}): Promise<JWSMultiVerifyResult<T>>;
|
|
17
|
+
/** @deprecated `forceUint8Array` is replaced by `payload: "bytes"`; removed in v0.9.0. */
|
|
18
|
+
export declare function verifyMulti(jws: JWSGeneralSerialization | JWSFlattenedSerialization, keyOrLookup: CryptoKey | JWKSet | JWSVerifyJWK | Uint8Array<ArrayBuffer> | JWKLookupFunction, options: JWSMultiVerifyOptions & {
|
|
19
|
+
forceUint8Array: true;
|
|
20
|
+
}): Promise<JWSMultiVerifyResult<Uint8Array<ArrayBuffer>>>;
|
|
21
|
+
export declare function verifyMulti<Mode extends JOSEPayloadMode = JOSEPayloadMode>(jws: JWSGeneralSerialization | JWSFlattenedSerialization, keyOrLookup: CryptoKey | JWKSet | JWSVerifyJWK | Uint8Array<ArrayBuffer> | JWKLookupFunction, options?: JWSMultiVerifyOptions<Mode>): Promise<JWSMultiVerifyResult<PayloadOf<Mode>>>;
|
|
86
22
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* @
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*/
|
|
94
|
-
declare function
|
|
95
|
-
|
|
23
|
+
* Verifies every signature independently and returns one outcome per signature; only
|
|
24
|
+
* a malformed envelope throws (`ERR_JWS_INVALID_SERIALIZATION`). The payload type follows `options.payload`.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const outcomes = await verifyMultiAll(jws, (header) => jwkSet);
|
|
28
|
+
* if (!outcomes.every((o) => o.verified)) throw new Error("not all signatures verified");
|
|
29
|
+
*/
|
|
30
|
+
export declare function verifyMultiAll<T extends Record<string, unknown> = JWTClaims>(jws: JWSGeneralSerialization | JWSFlattenedSerialization, keyResolver: JWKLookupFunction, options?: JWSMultiVerifyAllOptions<"json"> & {
|
|
31
|
+
forceUint8Array?: false;
|
|
32
|
+
}): Promise<JWSMultiVerifyOutcome<T>[]>;
|
|
33
|
+
/** @deprecated `forceUint8Array` is replaced by `payload: "bytes"`; removed in v0.9.0. */
|
|
34
|
+
export declare function verifyMultiAll(jws: JWSGeneralSerialization | JWSFlattenedSerialization, keyResolver: JWKLookupFunction, options: JWSMultiVerifyAllOptions & {
|
|
35
|
+
forceUint8Array: true;
|
|
36
|
+
}): Promise<JWSMultiVerifyOutcome<Uint8Array<ArrayBuffer>>[]>;
|
|
37
|
+
export declare function verifyMultiAll<Mode extends JOSEPayloadMode = JOSEPayloadMode>(jws: JWSGeneralSerialization | JWSFlattenedSerialization, keyResolver: JWKLookupFunction, options?: JWSMultiVerifyAllOptions<Mode>): Promise<JWSMultiVerifyOutcome<PayloadOf<Mode>>[]>;
|
|
38
|
+
/** Converts a single-signature General JWS to Flattened form (RFC 7515 §7.2.2); otherwise `ERR_JWS_INVALID_SERIALIZATION`. */
|
|
39
|
+
export declare function generalToFlattenedJWS(jws: JWSGeneralSerialization): JWSFlattenedSerialization;
|
|
40
|
+
/** Creates a JWS Compact Serialization; an object payload is JSON-serialized, `alg` is required unless the JWK carries one. */
|
|
41
|
+
export declare function sign(payload: JOSEPayload, key: JWSSignJWK, options?: JWSSignOptions): Promise<string>;
|
|
42
|
+
export declare function sign(payload: JOSEPayload, key: CryptoKey | Uint8Array<ArrayBuffer>, options: JWSSignOptions & {
|
|
96
43
|
alg: JWSAlgorithm;
|
|
97
44
|
}): Promise<string>;
|
|
98
45
|
/**
|
|
99
|
-
* Verifies a JWS
|
|
100
|
-
*
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
declare function verify<T extends JOSEPayload>(jws: string, key: CryptoKey | JWKSet | JWSVerifyJWK | Uint8Array<ArrayBuffer> | JWKLookupFunction, options?: JWSVerifyOptions): Promise<JWSVerifyResult<T>>;
|
|
108
|
-
declare function verify(jws: string, key: CryptoKey | JWKSet | JWSVerifyJWK | Uint8Array<ArrayBuffer> | JWKLookupFunction, options: JWSVerifyOptions & {
|
|
46
|
+
* Verifies a JWS Compact Serialization against a key, JWK Set or key resolver.
|
|
47
|
+
* The payload type follows `options.payload`: claims `T` for `"json"` (default), `string`, or `Uint8Array`.
|
|
48
|
+
*/
|
|
49
|
+
export declare function verify<T extends Record<string, unknown> = JWTClaims>(jws: string, key: CryptoKey | JWKSet | JWSVerifyJWK | Uint8Array<ArrayBuffer> | JWKLookupFunction, options?: JWSVerifyOptions<"json"> & {
|
|
50
|
+
forceUint8Array?: false;
|
|
51
|
+
}): Promise<JWSVerifyResult<T>>;
|
|
52
|
+
/** @deprecated `forceUint8Array` is replaced by `payload: "bytes"`; removed in v0.9.0. */
|
|
53
|
+
export declare function verify(jws: string, key: CryptoKey | JWKSet | JWSVerifyJWK | Uint8Array<ArrayBuffer> | JWKLookupFunction, options: JWSVerifyOptions & {
|
|
109
54
|
forceUint8Array: true;
|
|
110
55
|
}): Promise<JWSVerifyResult<Uint8Array<ArrayBuffer>>>;
|
|
111
|
-
export
|
|
56
|
+
export declare function verify<Mode extends JOSEPayloadMode = JOSEPayloadMode>(jws: string, key: CryptoKey | JWKSet | JWSVerifyJWK | Uint8Array<ArrayBuffer> | JWKLookupFunction, options?: JWSVerifyOptions<Mode>): Promise<JWSVerifyResult<PayloadOf<Mode>>>;
|