@oari/jose 0.0.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.
Files changed (88) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +150 -0
  3. package/dist/types/index.d.ts +55 -0
  4. package/dist/types/jwe/compact/decrypt.d.ts +43 -0
  5. package/dist/types/jwe/compact/encrypt.d.ts +76 -0
  6. package/dist/types/jwe/flattened/decrypt.d.ts +53 -0
  7. package/dist/types/jwe/flattened/encrypt.d.ts +95 -0
  8. package/dist/types/jwe/general/decrypt.d.ts +64 -0
  9. package/dist/types/jwe/general/encrypt.d.ts +89 -0
  10. package/dist/types/jwk/embedded.d.ts +31 -0
  11. package/dist/types/jwk/thumbprint.d.ts +60 -0
  12. package/dist/types/jwks/local.d.ts +90 -0
  13. package/dist/types/jwks/remote.d.ts +306 -0
  14. package/dist/types/jws/compact/sign.d.ts +47 -0
  15. package/dist/types/jws/compact/verify.d.ts +45 -0
  16. package/dist/types/jws/flattened/sign.d.ts +53 -0
  17. package/dist/types/jws/flattened/verify.d.ts +50 -0
  18. package/dist/types/jws/general/sign.d.ts +67 -0
  19. package/dist/types/jws/general/verify.d.ts +61 -0
  20. package/dist/types/jwt/decrypt.d.ts +51 -0
  21. package/dist/types/jwt/encrypt.d.ts +105 -0
  22. package/dist/types/jwt/sign.d.ts +140 -0
  23. package/dist/types/jwt/unsecured.d.ts +70 -0
  24. package/dist/types/jwt/verify.d.ts +124 -0
  25. package/dist/types/key/export.d.ts +59 -0
  26. package/dist/types/key/generate_key_pair.d.ts +64 -0
  27. package/dist/types/key/generate_secret.d.ts +42 -0
  28. package/dist/types/key/import.d.ts +146 -0
  29. package/dist/types/types.d.ts +869 -0
  30. package/dist/types/util/base64url.d.ts +9 -0
  31. package/dist/types/util/decode_jwt.d.ts +25 -0
  32. package/dist/types/util/decode_protected_header.d.ts +24 -0
  33. package/dist/types/util/errors.d.ts +488 -0
  34. package/dist/webapi/index.js +32 -0
  35. package/dist/webapi/jwe/compact/decrypt.js +27 -0
  36. package/dist/webapi/jwe/compact/encrypt.js +27 -0
  37. package/dist/webapi/jwe/flattened/decrypt.js +159 -0
  38. package/dist/webapi/jwe/flattened/encrypt.js +167 -0
  39. package/dist/webapi/jwe/general/decrypt.js +31 -0
  40. package/dist/webapi/jwe/general/encrypt.js +182 -0
  41. package/dist/webapi/jwk/embedded.js +17 -0
  42. package/dist/webapi/jwk/thumbprint.js +68 -0
  43. package/dist/webapi/jwks/local.js +119 -0
  44. package/dist/webapi/jwks/remote.js +179 -0
  45. package/dist/webapi/jws/compact/sign.js +18 -0
  46. package/dist/webapi/jws/compact/verify.js +21 -0
  47. package/dist/webapi/jws/flattened/sign.js +87 -0
  48. package/dist/webapi/jws/flattened/verify.js +110 -0
  49. package/dist/webapi/jws/general/sign.js +70 -0
  50. package/dist/webapi/jws/general/verify.js +24 -0
  51. package/dist/webapi/jwt/decrypt.js +23 -0
  52. package/dist/webapi/jwt/encrypt.js +101 -0
  53. package/dist/webapi/jwt/sign.js +52 -0
  54. package/dist/webapi/jwt/unsecured.js +63 -0
  55. package/dist/webapi/jwt/verify.js +15 -0
  56. package/dist/webapi/key/export.js +11 -0
  57. package/dist/webapi/key/generate_key_pair.js +97 -0
  58. package/dist/webapi/key/generate_secret.js +40 -0
  59. package/dist/webapi/key/import.js +57 -0
  60. package/dist/webapi/lib/aesgcmkw.js +15 -0
  61. package/dist/webapi/lib/aeskw.js +25 -0
  62. package/dist/webapi/lib/asn1.js +243 -0
  63. package/dist/webapi/lib/base64.js +22 -0
  64. package/dist/webapi/lib/buffer_utils.js +43 -0
  65. package/dist/webapi/lib/check_key_type.js +127 -0
  66. package/dist/webapi/lib/content_encryption.js +217 -0
  67. package/dist/webapi/lib/crypto_key.js +136 -0
  68. package/dist/webapi/lib/deflate.js +44 -0
  69. package/dist/webapi/lib/ecdhes.js +52 -0
  70. package/dist/webapi/lib/helpers.js +19 -0
  71. package/dist/webapi/lib/invalid_key_input.js +27 -0
  72. package/dist/webapi/lib/is_key_like.js +17 -0
  73. package/dist/webapi/lib/jwk_to_key.js +107 -0
  74. package/dist/webapi/lib/jwt_claims_set.js +238 -0
  75. package/dist/webapi/lib/key_management.js +186 -0
  76. package/dist/webapi/lib/key_to_jwk.js +31 -0
  77. package/dist/webapi/lib/normalize_key.js +166 -0
  78. package/dist/webapi/lib/pbes2kw.js +42 -0
  79. package/dist/webapi/lib/rsaes.js +24 -0
  80. package/dist/webapi/lib/signing.js +74 -0
  81. package/dist/webapi/lib/type_checks.js +41 -0
  82. package/dist/webapi/lib/validate_algorithms.js +10 -0
  83. package/dist/webapi/lib/validate_crit.js +33 -0
  84. package/dist/webapi/util/base64url.js +30 -0
  85. package/dist/webapi/util/decode_jwt.js +32 -0
  86. package/dist/webapi/util/decode_protected_header.js +34 -0
  87. package/dist/webapi/util/errors.js +99 -0
  88. package/package.json +195 -0
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Filip Skokan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,150 @@
1
+ # jose
2
+
3
+ `jose` is a JavaScript module for JSON Object Signing and Encryption, providing support for JSON Web Tokens (JWT), JSON Web Signature (JWS), JSON Web Encryption (JWE), JSON Web Key (JWK), JSON Web Key Set (JWKS), and more. The module is designed to work across various Web-interoperable runtimes including Node.js, browsers, Cloudflare Workers, Deno, Bun, and others.
4
+
5
+ ## Sponsor
6
+
7
+ <picture>
8
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/panva/jose/HEAD/sponsor/Auth0byOkta_dark.png">
9
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/panva/jose/HEAD/sponsor/Auth0byOkta_light.png">
10
+ <img height="65" align="left" alt="Auth0 by Okta" src="https://raw.githubusercontent.com/panva/jose/HEAD/sponsor/Auth0byOkta_light.png">
11
+ </picture>
12
+
13
+ If you want to quickly add JWT authentication to JavaScript apps, feel free to check out Auth0's JavaScript SDK and free plan. [Create an Auth0 account; it's free!][sponsor-auth0]<br><br>
14
+
15
+ ## [💗 Help the project](https://github.com/sponsors/panva)
16
+
17
+ Support from the community to continue maintaining and improving this module is welcome. If you find the module useful, please consider supporting the project by [becoming a sponsor](https://github.com/sponsors/panva).
18
+
19
+ ## Dependencies: 0
20
+
21
+ `jose` has no dependencies and it exports tree-shakeable ESM[^cjs].
22
+
23
+ ## Documentation
24
+
25
+ `jose` is distributed via [npmjs.com](https://www.npmjs.com/package/jose), [jsr.io](https://jsr.io/@panva/jose), [jsdelivr.com](https://www.jsdelivr.com/package/npm/jose), and [github.com](https://github.com/panva/jose).
26
+
27
+ **`example`** ESM import[^cjs]
28
+
29
+ ```js
30
+ import * as jose from 'jose'
31
+ ```
32
+
33
+ ### JSON Web Tokens (JWT)
34
+
35
+ The `jose` module supports JSON Web Tokens (JWT) and provides functionality for signing and verifying tokens, as well as their JWT Claims Set validation.
36
+
37
+ - [JWT Claims Set Validation & Signature Verification](docs/jwt/verify/functions/jwtVerify.md) using the `jwtVerify` function
38
+ - [Using a remote JSON Web Key Set (JWKS)](docs/jwks/remote/functions/createRemoteJWKSet.md)
39
+ - [Using a local JSON Web Key Set (JWKS)](docs/jwks/local/functions/createLocalJWKSet.md)
40
+ - [Signing](docs/jwt/sign/classes/SignJWT.md) using the `SignJWT` class
41
+ - Utility functions
42
+ - [Decoding Token's Protected Header](docs/util/decode_protected_header/functions/decodeProtectedHeader.md)
43
+ - [Decoding JWT Claims Set](docs/util/decode_jwt/functions/decodeJwt.md) prior to its validation
44
+
45
+ ### Encrypted JSON Web Tokens
46
+
47
+ The `jose` module supports encrypted JSON Web Tokens and provides functionality for encrypting and decrypting tokens, as well as their JWT Claims Set validation.
48
+
49
+ - [Decryption & JWT Claims Set Validation](docs/jwt/decrypt/functions/jwtDecrypt.md) using the `jwtDecrypt` function
50
+ - [Encryption](docs/jwt/encrypt/classes/EncryptJWT.md) using the `EncryptJWT` class
51
+ - Utility functions
52
+ - [Decoding Token's Protected Header](docs/util/decode_protected_header/functions/decodeProtectedHeader.md)
53
+
54
+ ### Key Utilities
55
+
56
+ The `jose` module supports importing, exporting, and generating keys and secrets in various formats, including PEM formats like SPKI, X.509 certificate, and PKCS #8, as well as JSON Web Key (JWK).
57
+
58
+ - Key Import Functions
59
+ - [JWK Import](docs/key/import/functions/importJWK.md)
60
+ - [Public Key Import (SPKI)](docs/key/import/functions/importSPKI.md)
61
+ - [Public Key Import (X.509 Certificate)](docs/key/import/functions/importX509.md)
62
+ - [Private Key Import (PKCS #8)](docs/key/import/functions/importPKCS8.md)
63
+ - Key and Secret Generation Functions
64
+ - [Asymmetric Key Pair Generation](docs/key/generate_key_pair/functions/generateKeyPair.md)
65
+ - [Symmetric Secret Generation](docs/key/generate_secret/functions/generateSecret.md)
66
+ - Key Export Functions
67
+ - [JWK Export](docs/key/export/functions/exportJWK.md)
68
+ - [Private Key Export](docs/key/export/functions/exportPKCS8.md)
69
+ - [Public Key Export](docs/key/export/functions/exportSPKI.md)
70
+
71
+ ### JSON Web Signature (JWS)
72
+
73
+ The `jose` module supports signing and verification of JWS messages with arbitrary payloads in Compact, Flattened JSON, and General JSON serialization syntaxes.
74
+
75
+ - Signing - [Compact](docs/jws/compact/sign/classes/CompactSign.md), [Flattened JSON](docs/jws/flattened/sign/classes/FlattenedSign.md), [General JSON](docs/jws/general/sign/classes/GeneralSign.md)
76
+ - Verification - [Compact](docs/jws/compact/verify/functions/compactVerify.md), [Flattened JSON](docs/jws/flattened/verify/functions/flattenedVerify.md), [General JSON](docs/jws/general/verify/functions/generalVerify.md)
77
+ - [Using a remote JSON Web Key Set (JWKS)](docs/jwks/remote/functions/createRemoteJWKSet.md)
78
+ - [Using a local JSON Web Key Set (JWKS)](docs/jwks/local/functions/createLocalJWKSet.md)
79
+ - Utility functions
80
+ - [Decoding Token's Protected Header](docs/util/decode_protected_header/functions/decodeProtectedHeader.md)
81
+
82
+ ### JSON Web Encryption (JWE)
83
+
84
+ The `jose` module supports encryption and decryption of JWE messages with arbitrary plaintext in Compact, Flattened JSON, and General JSON serialization syntaxes.
85
+
86
+ - Encryption - [Compact](docs/jwe/compact/encrypt/classes/CompactEncrypt.md), [Flattened JSON](docs/jwe/flattened/encrypt/classes/FlattenedEncrypt.md), [General JSON](docs/jwe/general/encrypt/classes/GeneralEncrypt.md)
87
+ - Decryption - [Compact](docs/jwe/compact/decrypt/functions/compactDecrypt.md), [Flattened JSON](docs/jwe/flattened/decrypt/functions/flattenedDecrypt.md), [General JSON](docs/jwe/general/decrypt/functions/generalDecrypt.md)
88
+ - Utility functions
89
+ - [Decoding Token's Protected Header](docs/util/decode_protected_header/functions/decodeProtectedHeader.md)
90
+
91
+ ### Other
92
+
93
+ The following are additional features and utilities provided by the `jose` module:
94
+
95
+ - [Calculating JWK Thumbprint](docs/jwk/thumbprint/functions/calculateJwkThumbprint.md)
96
+ - [Calculating JWK Thumbprint URI](docs/jwk/thumbprint/functions/calculateJwkThumbprintUri.md)
97
+ - [Verification using a JWK Embedded in a JWS Header](docs/jwk/embedded/functions/EmbeddedJWK.md)
98
+ - [Unsecured JWT](docs/jwt/unsecured/classes/UnsecuredJWT.md)
99
+ - [JOSE Errors](docs/util/errors/README.md)
100
+
101
+ ## Supported Runtimes
102
+
103
+ The `jose` module is compatible with JavaScript runtimes that support the utilized Web API globals and standard built-in objects or are Node.js.
104
+
105
+ The following runtimes are supported _(this is not an exhaustive list)_:
106
+
107
+ - [Bun](https://github.com/panva/jose/issues/471)
108
+ - [Browsers](https://github.com/panva/jose/issues/263)
109
+ - [Cloudflare Workers](https://github.com/panva/jose/issues/265)
110
+ - [Deno](https://github.com/panva/jose/issues/266)
111
+ - [Electron](https://github.com/panva/jose/issues/264)
112
+ - [Node.js](https://github.com/panva/jose/issues/262)
113
+
114
+ Please note that certain algorithms may not be available depending on the runtime used. You can find a list of available algorithms for each runtime in the specific issue links provided above.
115
+
116
+ ## Supported Versions
117
+
118
+ | Version | Security Fixes 🔑 | Other Bug Fixes 🐞 | New Features ⭐ | Runtime and Module type |
119
+ | ----------------------------------------------- | ----------------- | ------------------ | --------------- | ------------------------------- |
120
+ | [v6.x](https://github.com/panva/jose/tree/v6.x) | [Security Policy] | ✅ | ✅ | Universal[^universal] ESM[^cjs] |
121
+
122
+ ## Specifications
123
+
124
+ <details>
125
+ <summary>Details</summary>
126
+
127
+ - JSON Web Signature (JWS) - [RFC7515](https://www.rfc-editor.org/rfc/rfc7515)
128
+ - JSON Web Encryption (JWE) - [RFC7516](https://www.rfc-editor.org/rfc/rfc7516)
129
+ - JSON Web Key (JWK) - [RFC7517](https://www.rfc-editor.org/rfc/rfc7517)
130
+ - JSON Web Algorithms (JWA) - [RFC7518](https://www.rfc-editor.org/rfc/rfc7518)
131
+ - JSON Web Token (JWT) - [RFC7519](https://www.rfc-editor.org/rfc/rfc7519)
132
+ - JSON Web Key Thumbprint - [RFC7638](https://www.rfc-editor.org/rfc/rfc7638)
133
+ - JSON Web Key Thumbprint URI - [RFC9278](https://www.rfc-editor.org/rfc/rfc9278)
134
+ - JWS Unencoded Payload Option - [RFC7797](https://www.rfc-editor.org/rfc/rfc7797)
135
+ - CFRG Elliptic Curve ECDH and Signatures - [RFC8037](https://www.rfc-editor.org/rfc/rfc8037)
136
+ - Fully-Specified Algorithms for JOSE - [RFC9864](https://www.rfc-editor.org/rfc/rfc9864.html)
137
+ - ML-DSA for JOSE - [RFC9964](https://www.rfc-editor.org/rfc/rfc9964.html)
138
+
139
+ The algorithm implementations in `jose` have been tested using test vectors from their respective specifications as well as [RFC7520](https://www.rfc-editor.org/rfc/rfc7520).
140
+
141
+ </details>
142
+
143
+ [sponsor-auth0]: https://a0.to/signup/panva
144
+ [WebCryptoAPI]: https://w3c.github.io/webcrypto/
145
+ [Fetch API]: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
146
+ [Security Policy]: https://github.com/panva/jose/security/policy
147
+
148
+ [^cjs]: CJS style `let jose = require('jose')` is possible in Node.js versions where the `require(esm)` feature is enabled by default (^20.19.0 || ^22.12.0 || >= 23.0.0).
149
+
150
+ [^universal]: Assumes runtime support of [WebCryptoAPI][] and [Fetch API][]
@@ -0,0 +1,55 @@
1
+ export { compactDecrypt } from './jwe/compact/decrypt.js';
2
+ export type { CompactDecryptGetKey } from './jwe/compact/decrypt.js';
3
+ export { flattenedDecrypt } from './jwe/flattened/decrypt.js';
4
+ export type { FlattenedDecryptGetKey } from './jwe/flattened/decrypt.js';
5
+ export { generalDecrypt } from './jwe/general/decrypt.js';
6
+ export type { GeneralDecryptGetKey } from './jwe/general/decrypt.js';
7
+ export { GeneralEncrypt } from './jwe/general/encrypt.js';
8
+ export type { Recipient } from './jwe/general/encrypt.js';
9
+ export { compactVerify } from './jws/compact/verify.js';
10
+ export type { CompactVerifyGetKey } from './jws/compact/verify.js';
11
+ export { flattenedVerify } from './jws/flattened/verify.js';
12
+ export type { FlattenedVerifyGetKey } from './jws/flattened/verify.js';
13
+ export { generalVerify } from './jws/general/verify.js';
14
+ export type { GeneralVerifyGetKey } from './jws/general/verify.js';
15
+ export { jwtVerify } from './jwt/verify.js';
16
+ export type { JWTVerifyOptions, JWTVerifyGetKey } from './jwt/verify.js';
17
+ export { jwtDecrypt } from './jwt/decrypt.js';
18
+ export type { JWTDecryptOptions, JWTDecryptGetKey } from './jwt/decrypt.js';
19
+ export { CompactEncrypt } from './jwe/compact/encrypt.js';
20
+ export { FlattenedEncrypt } from './jwe/flattened/encrypt.js';
21
+ export { CompactSign } from './jws/compact/sign.js';
22
+ export { FlattenedSign } from './jws/flattened/sign.js';
23
+ export { GeneralSign } from './jws/general/sign.js';
24
+ export type { Signature } from './jws/general/sign.js';
25
+ export { SignJWT } from './jwt/sign.js';
26
+ export { EncryptJWT } from './jwt/encrypt.js';
27
+ export { calculateJwkThumbprint, calculateJwkThumbprintUri } from './jwk/thumbprint.js';
28
+ export { EmbeddedJWK } from './jwk/embedded.js';
29
+ export { createLocalJWKSet } from './jwks/local.js';
30
+ export { createRemoteJWKSet, jwksCache, customFetch } from './jwks/remote.js';
31
+ export type { RemoteJWKSetOptions, JWKSCacheInput, ExportedJWKSCache, FetchImplementation, } from './jwks/remote.js';
32
+ export { UnsecuredJWT } from './jwt/unsecured.js';
33
+ export type { UnsecuredResult } from './jwt/unsecured.js';
34
+ export { exportPKCS8, exportSPKI, exportJWK } from './key/export.js';
35
+ export { importSPKI, importPKCS8, importX509, importJWK } from './key/import.js';
36
+ export type { KeyImportOptions } from './key/import.js';
37
+ export { decodeProtectedHeader } from './util/decode_protected_header.js';
38
+ export { decodeJwt } from './util/decode_jwt.js';
39
+ export type { ProtectedHeaderParameters } from './util/decode_protected_header.js';
40
+ import * as errors from './util/errors.js';
41
+ export { errors };
42
+ export { generateKeyPair } from './key/generate_key_pair.js';
43
+ export type { GenerateKeyPairResult, GenerateKeyPairOptions } from './key/generate_key_pair.js';
44
+ export { generateSecret } from './key/generate_secret.js';
45
+ export type { GenerateSecretOptions } from './key/generate_secret.js';
46
+ import * as base64url from './util/base64url.js';
47
+ export { base64url };
48
+ export type { CompactDecryptResult, CompactJWEHeaderParameters, CompactJWSHeaderParameters, CompactVerifyResult, CritOption, CryptoKey, DecryptOptions, EncryptOptions, FlattenedDecryptResult, FlattenedJWE, FlattenedJWS, FlattenedJWSInput, FlattenedVerifyResult, GeneralDecryptResult, GeneralJWE, GeneralJWS, GeneralJWSInput, GeneralVerifyResult, GetKeyFunction, JoseHeaderParameters, JSONWebKeySet, JWEHeaderParameters, JWEKeyManagementHeaderParameters, JWK_EC_Private, JWK_EC_Public, JWK_oct, JWK_OKP_Private, JWK_OKP_Public, JWK_RSA_Private, JWK_RSA_Public, JWK, JWKParameters, JWSHeaderParameters, JWTClaimVerificationOptions, JWTDecryptResult, JWTHeaderParameters, JWTPayload, JWTVerifyResult, KeyObject, ProduceJWT, ResolvedKey, SignOptions, VerifyOptions, } from './types.d.ts';
49
+ /**
50
+ * In prior releases this indicated whether a Node.js-specific build was loaded, this is now fixed
51
+ * to `"WebCryptoAPI"`
52
+ *
53
+ * @deprecated
54
+ */
55
+ export declare const cryptoRuntime = "WebCryptoAPI";
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Decrypting JSON Web Encryption (JWE) in Compact Serialization
3
+ *
4
+ * @module
5
+ */
6
+ import type * as types from '../../types.d.ts';
7
+ /**
8
+ * Interface for Compact JWE Decryption dynamic key resolution. No token components have been
9
+ * verified at the time of this function call.
10
+ */
11
+ export interface CompactDecryptGetKey extends types.GetKeyFunction<types.CompactJWEHeaderParameters, types.FlattenedJWE> {
12
+ }
13
+ /**
14
+ * Decrypts a Compact JWE.
15
+ *
16
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
17
+ * as from its subpath export `'jose/jwe/compact/decrypt'`.
18
+ *
19
+ * @example
20
+ *
21
+ * ```js
22
+ * const jwe =
23
+ * 'eyJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOiJBMjU2R0NNIn0.nyQ19eq9ogh9wA7fFtnI2oouzy5_8b5DeLkoRMfi2yijgfTs2zEnayCEofz_qhnL-nwszabd9qUeHv0-IwvhhJJS7GUJOU3ikiIe42qcIAFme1A_Fo9CTxw4XTOy-I5qanl8So91u6hwfyN1VxAqVLsSE7_23EC-gfGEg_5znew9PyXXsOIE-K_HH7IQowRrlZ1X_bM_Liu53RzDpLDvRz59mp3S8L56YqpM8FexFGTGpEaoTcEIst375qncYt3-79IVR7gZN1RWsWgjPatfvVbnh74PglQcATSf3UUhaW0OAKn6q7r3PDx6DIKQ35bgHQg5QopuN00eIfLQL2trGw.W3grIVj5HVuAb76X.6PcuDe5D6ttWFYyv0oqqdDXfI2R8wBg1F2Q80UUA_Gv8eEimNWfxIWdLxrjzgQGSvIhxmFKuLM0.a93_Ug3uZHuczj70Zavx8Q'
24
+ *
25
+ * const { plaintext, protectedHeader } = await jose.compactDecrypt(jwe, privateKey)
26
+ *
27
+ * console.log(protectedHeader)
28
+ * console.log(new TextDecoder().decode(plaintext))
29
+ * ```
30
+ *
31
+ * @param jwe Compact JWE.
32
+ * @param key Private Key or Secret to decrypt the JWE with. See
33
+ * {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
34
+ * @param options JWE Decryption options.
35
+ */
36
+ export declare function compactDecrypt(jwe: string | Uint8Array, key: types.CryptoKey | types.KeyObject | types.JWK | Uint8Array, options?: types.DecryptOptions): Promise<types.CompactDecryptResult>;
37
+ /**
38
+ * @param jwe Compact JWE.
39
+ * @param getKey Function resolving Private Key or Secret to decrypt the JWE with. See
40
+ * {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
41
+ * @param options JWE Decryption options.
42
+ */
43
+ export declare function compactDecrypt(jwe: string | Uint8Array, getKey: CompactDecryptGetKey, options?: types.DecryptOptions): Promise<types.CompactDecryptResult & types.ResolvedKey>;
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Encrypting JSON Web Encryption (JWE) in Compact Serialization
3
+ *
4
+ * @module
5
+ */
6
+ import type * as types from '../../types.d.ts';
7
+ /**
8
+ * The CompactEncrypt class is used to build and encrypt Compact JWE strings.
9
+ *
10
+ * This class is exported (as a named export) from the main `'jose'` module entry point as well as
11
+ * from its subpath export `'jose/jwe/compact/encrypt'`.
12
+ *
13
+ * @example
14
+ *
15
+ * ```js
16
+ * const jwe = await new jose.CompactEncrypt(
17
+ * new TextEncoder().encode('It’s a dangerous business, Frodo, going out your door.'),
18
+ * )
19
+ * .setProtectedHeader({ alg: 'RSA-OAEP-256', enc: 'A256GCM' })
20
+ * .encrypt(publicKey)
21
+ *
22
+ * console.log(jwe)
23
+ * ```
24
+ */
25
+ export declare class CompactEncrypt {
26
+ #private;
27
+ /**
28
+ * {@link CompactEncrypt} constructor
29
+ *
30
+ * @param plaintext Binary representation of the plaintext to encrypt.
31
+ */
32
+ constructor(plaintext: Uint8Array);
33
+ /**
34
+ * Sets a content encryption key to use, by default a random suitable one is generated for the JWE
35
+ * enc" (Encryption Algorithm) Header Parameter.
36
+ *
37
+ * @deprecated You should not use this method. It is only really intended for test and vector
38
+ * validation purposes.
39
+ *
40
+ * @param cek JWE Content Encryption Key.
41
+ */
42
+ setContentEncryptionKey(cek: Uint8Array): this;
43
+ /**
44
+ * Sets the JWE Initialization Vector to use for content encryption, by default a random suitable
45
+ * one is generated for the JWE enc" (Encryption Algorithm) Header Parameter.
46
+ *
47
+ * @deprecated You should not use this method. It is only really intended for test and vector
48
+ * validation purposes.
49
+ *
50
+ * @param iv JWE Initialization Vector.
51
+ */
52
+ setInitializationVector(iv: Uint8Array): this;
53
+ /**
54
+ * Sets the JWE Protected Header on the CompactEncrypt object.
55
+ *
56
+ * @param protectedHeader JWE Protected Header object.
57
+ */
58
+ setProtectedHeader(protectedHeader: types.CompactJWEHeaderParameters): this;
59
+ /**
60
+ * Sets the JWE Key Management parameters to be used when encrypting.
61
+ *
62
+ * (ECDH-ES) Use of this method is needed for ECDH based algorithms to set the "apu" (Agreement
63
+ * PartyUInfo) or "apv" (Agreement PartyVInfo) parameters.
64
+ *
65
+ * @param parameters JWE Key Management parameters.
66
+ */
67
+ setKeyManagementParameters(parameters: types.JWEKeyManagementHeaderParameters): this;
68
+ /**
69
+ * Encrypts and resolves the value of the Compact JWE string.
70
+ *
71
+ * @param key Public Key or Secret to encrypt the JWE with. See
72
+ * {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
73
+ * @param options JWE Encryption options.
74
+ */
75
+ encrypt(key: types.CryptoKey | types.KeyObject | types.JWK | Uint8Array, options?: types.EncryptOptions): Promise<string>;
76
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Decrypting JSON Web Encryption (JWE) in Flattened JSON Serialization
3
+ *
4
+ * @module
5
+ */
6
+ import type * as types from '../../types.d.ts';
7
+ /**
8
+ * Interface for Flattened JWE Decryption dynamic key resolution. No token components have been
9
+ * verified at the time of this function call.
10
+ */
11
+ export interface FlattenedDecryptGetKey extends types.GetKeyFunction<types.JWEHeaderParameters | undefined, types.FlattenedJWE> {
12
+ }
13
+ /**
14
+ * Decrypts a Flattened JWE.
15
+ *
16
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
17
+ * as from its subpath export `'jose/jwe/flattened/decrypt'`.
18
+ *
19
+ * @example
20
+ *
21
+ * ```js
22
+ * const jwe = {
23
+ * ciphertext: '9EzjFISUyoG-ifC2mSihfP0DPC80yeyrxhTzKt1C_VJBkxeBG0MI4Te61Pk45RAGubUvBpU9jm4',
24
+ * iv: '8Fy7A_IuoX5VXG9s',
25
+ * tag: 'W76IYV6arGRuDSaSyWrQNg',
26
+ * encrypted_key:
27
+ * 'Z6eD4UK_yFb5ZoKvKkGAdqywEG_m0e4IYo0x8Vf30LAMJcsc-_zSgIeiF82teZyYi2YYduHKoqImk7MRnoPZOlEs0Q5BNK1OgBmSOhCE8DFyqh9Zh48TCTP6lmBQ52naqoUJFMtHzu-0LwZH26hxos0GP3Dt19O379MJB837TdKKa87skq0zHaVLAquRHOBF77GI54Bc7O49d8aOrSu1VEFGMThlW2caspPRiTSePDMDPq7_WGk50izRhB3Asl9wmP9wEeaTrkJKRnQj5ips1SAZ1hDBsqEQKKukxP1HtdcopHV5_qgwU8Hjm5EwSLMluMQuiE6hwlkXGOujZLVizA',
28
+ * aad: 'VGhlIEZlbGxvd3NoaXAgb2YgdGhlIFJpbmc',
29
+ * protected: 'eyJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOiJBMjU2R0NNIn0',
30
+ * }
31
+ *
32
+ * const { plaintext, protectedHeader, additionalAuthenticatedData } =
33
+ * await jose.flattenedDecrypt(jwe, privateKey)
34
+ *
35
+ * console.log(protectedHeader)
36
+ * const decoder = new TextDecoder()
37
+ * console.log(decoder.decode(plaintext))
38
+ * console.log(decoder.decode(additionalAuthenticatedData))
39
+ * ```
40
+ *
41
+ * @param jwe Flattened JWE.
42
+ * @param key Private Key or Secret to decrypt the JWE with. See
43
+ * {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
44
+ * @param options JWE Decryption options.
45
+ */
46
+ export declare function flattenedDecrypt(jwe: types.FlattenedJWE, key: types.CryptoKey | types.KeyObject | types.JWK | Uint8Array, options?: types.DecryptOptions): Promise<types.FlattenedDecryptResult>;
47
+ /**
48
+ * @param jwe Flattened JWE.
49
+ * @param getKey Function resolving Private Key or Secret to decrypt the JWE with. See
50
+ * {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
51
+ * @param options JWE Decryption options.
52
+ */
53
+ export declare function flattenedDecrypt(jwe: types.FlattenedJWE, getKey: FlattenedDecryptGetKey, options?: types.DecryptOptions): Promise<types.FlattenedDecryptResult & types.ResolvedKey>;
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Encrypting JSON Web Encryption (JWE) in Flattened JSON Serialization
3
+ *
4
+ * @module
5
+ */
6
+ import type * as types from '../../types.d.ts';
7
+ /**
8
+ * The FlattenedEncrypt class is used to build and encrypt Flattened JWE objects.
9
+ *
10
+ * This class is exported (as a named export) from the main `'jose'` module entry point as well as
11
+ * from its subpath export `'jose/jwe/flattened/encrypt'`.
12
+ *
13
+ * @example
14
+ *
15
+ * ```js
16
+ * const jwe = await new jose.FlattenedEncrypt(
17
+ * new TextEncoder().encode('It’s a dangerous business, Frodo, going out your door.'),
18
+ * )
19
+ * .setProtectedHeader({ alg: 'RSA-OAEP-256', enc: 'A256GCM' })
20
+ * .setAdditionalAuthenticatedData(encoder.encode('The Fellowship of the Ring'))
21
+ * .encrypt(publicKey)
22
+ *
23
+ * console.log(jwe)
24
+ * ```
25
+ */
26
+ export declare class FlattenedEncrypt {
27
+ #private;
28
+ /**
29
+ * {@link FlattenedEncrypt} constructor
30
+ *
31
+ * @param plaintext Binary representation of the plaintext to encrypt.
32
+ */
33
+ constructor(plaintext: Uint8Array);
34
+ /**
35
+ * Sets the JWE Key Management parameters to be used when encrypting.
36
+ *
37
+ * (ECDH-ES) Use of this method is needed for ECDH based algorithms to set the "apu" (Agreement
38
+ * PartyUInfo) or "apv" (Agreement PartyVInfo) parameters.
39
+ *
40
+ * @param parameters JWE Key Management parameters.
41
+ */
42
+ setKeyManagementParameters(parameters: types.JWEKeyManagementHeaderParameters): this;
43
+ /**
44
+ * Sets the JWE Protected Header on the FlattenedEncrypt object.
45
+ *
46
+ * @param protectedHeader JWE Protected Header.
47
+ */
48
+ setProtectedHeader(protectedHeader: types.JWEHeaderParameters): this;
49
+ /**
50
+ * Sets the JWE Shared Unprotected Header on the FlattenedEncrypt object.
51
+ *
52
+ * @param sharedUnprotectedHeader JWE Shared Unprotected Header.
53
+ */
54
+ setSharedUnprotectedHeader(sharedUnprotectedHeader: types.JWEHeaderParameters): this;
55
+ /**
56
+ * Sets the JWE Per-Recipient Unprotected Header on the FlattenedEncrypt object.
57
+ *
58
+ * @param unprotectedHeader JWE Per-Recipient Unprotected Header.
59
+ */
60
+ setUnprotectedHeader(unprotectedHeader: types.JWEHeaderParameters): this;
61
+ /**
62
+ * Sets the Additional Authenticated Data on the FlattenedEncrypt object.
63
+ *
64
+ * @param aad Additional Authenticated Data.
65
+ */
66
+ setAdditionalAuthenticatedData(aad: Uint8Array): this;
67
+ /**
68
+ * Sets a content encryption key to use, by default a random suitable one is generated for the JWE
69
+ * enc" (Encryption Algorithm) Header Parameter.
70
+ *
71
+ * @deprecated You should not use this method. It is only really intended for test and vector
72
+ * validation purposes.
73
+ *
74
+ * @param cek JWE Content Encryption Key.
75
+ */
76
+ setContentEncryptionKey(cek: Uint8Array): this;
77
+ /**
78
+ * Sets the JWE Initialization Vector to use for content encryption, by default a random suitable
79
+ * one is generated for the JWE enc" (Encryption Algorithm) Header Parameter.
80
+ *
81
+ * @deprecated You should not use this method. It is only really intended for test and vector
82
+ * validation purposes.
83
+ *
84
+ * @param iv JWE Initialization Vector.
85
+ */
86
+ setInitializationVector(iv: Uint8Array): this;
87
+ /**
88
+ * Encrypts and resolves the value of the Flattened JWE object.
89
+ *
90
+ * @param key Public Key or Secret to encrypt the JWE with. See
91
+ * {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
92
+ * @param options JWE Encryption options.
93
+ */
94
+ encrypt(key: types.CryptoKey | types.KeyObject | types.JWK | Uint8Array, options?: types.EncryptOptions): Promise<types.FlattenedJWE>;
95
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Decrypting JSON Web Encryption (JWE) in General JSON Serialization
3
+ *
4
+ * @module
5
+ */
6
+ import type * as types from '../../types.d.ts';
7
+ /**
8
+ * Interface for General JWE Decryption dynamic key resolution. No token components have been
9
+ * verified at the time of this function call.
10
+ */
11
+ export interface GeneralDecryptGetKey extends types.GetKeyFunction<types.JWEHeaderParameters, types.FlattenedJWE> {
12
+ }
13
+ /**
14
+ * Decrypts a General JWE.
15
+ *
16
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
17
+ * as from its subpath export `'jose/jwe/general/decrypt'`.
18
+ *
19
+ * > [!NOTE]\
20
+ * > The function iterates over the `recipients` array in the General JWE and returns the decryption
21
+ * > result of the first recipient entry that can be successfully decrypted. The result only contains
22
+ * > the plaintext and headers of that successfully decrypted recipient entry. Other recipient entries
23
+ * > in the General JWE are not validated, and their headers are not included in the returned result.
24
+ * > Recipients of a General JWE should only rely on the returned (decrypted) data.
25
+ *
26
+ * @example
27
+ *
28
+ * ```js
29
+ * const jwe = {
30
+ * ciphertext: '9EzjFISUyoG-ifC2mSihfP0DPC80yeyrxhTzKt1C_VJBkxeBG0MI4Te61Pk45RAGubUvBpU9jm4',
31
+ * iv: '8Fy7A_IuoX5VXG9s',
32
+ * tag: 'W76IYV6arGRuDSaSyWrQNg',
33
+ * aad: 'VGhlIEZlbGxvd3NoaXAgb2YgdGhlIFJpbmc',
34
+ * protected: 'eyJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOiJBMjU2R0NNIn0',
35
+ * recipients: [
36
+ * {
37
+ * encrypted_key:
38
+ * 'Z6eD4UK_yFb5ZoKvKkGAdqywEG_m0e4IYo0x8Vf30LAMJcsc-_zSgIeiF82teZyYi2YYduHKoqImk7MRnoPZOlEs0Q5BNK1OgBmSOhCE8DFyqh9Zh48TCTP6lmBQ52naqoUJFMtHzu-0LwZH26hxos0GP3Dt19O379MJB837TdKKa87skq0zHaVLAquRHOBF77GI54Bc7O49d8aOrSu1VEFGMThlW2caspPRiTSePDMDPq7_WGk50izRhB3Asl9wmP9wEeaTrkJKRnQj5ips1SAZ1hDBsqEQKKukxP1HtdcopHV5_qgwU8Hjm5EwSLMluMQuiE6hwlkXGOujZLVizA',
39
+ * },
40
+ * ],
41
+ * }
42
+ *
43
+ * const { plaintext, protectedHeader, additionalAuthenticatedData } =
44
+ * await jose.generalDecrypt(jwe, privateKey)
45
+ *
46
+ * console.log(protectedHeader)
47
+ * const decoder = new TextDecoder()
48
+ * console.log(decoder.decode(plaintext))
49
+ * console.log(decoder.decode(additionalAuthenticatedData))
50
+ * ```
51
+ *
52
+ * @param jwe General JWE.
53
+ * @param key Private Key or Secret to decrypt the JWE with. See
54
+ * {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
55
+ * @param options JWE Decryption options.
56
+ */
57
+ export declare function generalDecrypt(jwe: types.GeneralJWE, key: types.CryptoKey | types.KeyObject | types.JWK | Uint8Array, options?: types.DecryptOptions): Promise<types.GeneralDecryptResult>;
58
+ /**
59
+ * @param jwe General JWE.
60
+ * @param getKey Function resolving Private Key or Secret to decrypt the JWE with. See
61
+ * {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
62
+ * @param options JWE Decryption options.
63
+ */
64
+ export declare function generalDecrypt(jwe: types.GeneralJWE, getKey: GeneralDecryptGetKey, options?: types.DecryptOptions): Promise<types.GeneralDecryptResult & types.ResolvedKey>;
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Encrypting JSON Web Encryption (JWE) in General JSON Serialization
3
+ *
4
+ * @module
5
+ */
6
+ import type * as types from '../../types.d.ts';
7
+ /** Used to build General JWE object's individual recipients. */
8
+ export interface Recipient {
9
+ /**
10
+ * Sets the JWE Per-Recipient Unprotected Header on the Recipient object.
11
+ *
12
+ * @param unprotectedHeader JWE Per-Recipient Unprotected Header.
13
+ */
14
+ setUnprotectedHeader(unprotectedHeader: types.JWEHeaderParameters): Recipient;
15
+ /**
16
+ * Sets the JWE Key Management parameters to be used when encrypting.
17
+ *
18
+ * (ECDH-ES) Use of this method is needed for ECDH based algorithms to set the "apu" (Agreement
19
+ * PartyUInfo) or "apv" (Agreement PartyVInfo) parameters.
20
+ *
21
+ * @param parameters JWE Key Management parameters.
22
+ */
23
+ setKeyManagementParameters(parameters: types.JWEKeyManagementHeaderParameters): Recipient;
24
+ /** A shorthand for calling addRecipient() on the enclosing {@link GeneralEncrypt} instance */
25
+ addRecipient(...args: Parameters<GeneralEncrypt['addRecipient']>): Recipient;
26
+ /** A shorthand for calling encrypt() on the enclosing {@link GeneralEncrypt} instance */
27
+ encrypt(...args: Parameters<GeneralEncrypt['encrypt']>): Promise<types.GeneralJWE>;
28
+ /** Returns the enclosing {@link GeneralEncrypt} instance */
29
+ done(): GeneralEncrypt;
30
+ }
31
+ /**
32
+ * The GeneralEncrypt class is used to build and encrypt General JWE objects.
33
+ *
34
+ * This class is exported (as a named export) from the main `'jose'` module entry point as well as
35
+ * from its subpath export `'jose/jwe/general/encrypt'`.
36
+ *
37
+ * @example
38
+ *
39
+ * ```js
40
+ * const jwe = await new jose.GeneralEncrypt(
41
+ * new TextEncoder().encode('It’s a dangerous business, Frodo, going out your door.'),
42
+ * )
43
+ * .setProtectedHeader({ enc: 'A256GCM' })
44
+ * .addRecipient(ecPublicKey)
45
+ * .setUnprotectedHeader({ alg: 'ECDH-ES+A256KW' })
46
+ * .addRecipient(rsaPublicKey)
47
+ * .setUnprotectedHeader({ alg: 'RSA-OAEP-384' })
48
+ * .encrypt()
49
+ *
50
+ * console.log(jwe)
51
+ * ```
52
+ */
53
+ export declare class GeneralEncrypt {
54
+ #private;
55
+ /**
56
+ * {@link GeneralEncrypt} constructor
57
+ *
58
+ * @param plaintext Binary representation of the plaintext to encrypt.
59
+ */
60
+ constructor(plaintext: Uint8Array);
61
+ /**
62
+ * Adds an additional recipient for the General JWE object.
63
+ *
64
+ * @param key Public Key or Secret to encrypt the Content Encryption Key for the recipient with.
65
+ * See {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
66
+ * @param options JWE Encryption options.
67
+ */
68
+ addRecipient(key: types.CryptoKey | types.KeyObject | types.JWK | Uint8Array, options?: types.CritOption): Recipient;
69
+ /**
70
+ * Sets the JWE Protected Header on the GeneralEncrypt object.
71
+ *
72
+ * @param protectedHeader JWE Protected Header object.
73
+ */
74
+ setProtectedHeader(protectedHeader: types.JWEHeaderParameters): this;
75
+ /**
76
+ * Sets the JWE Shared Unprotected Header on the GeneralEncrypt object.
77
+ *
78
+ * @param sharedUnprotectedHeader JWE Shared Unprotected Header object.
79
+ */
80
+ setSharedUnprotectedHeader(sharedUnprotectedHeader: types.JWEHeaderParameters): this;
81
+ /**
82
+ * Sets the Additional Authenticated Data on the GeneralEncrypt object.
83
+ *
84
+ * @param aad Additional Authenticated Data.
85
+ */
86
+ setAdditionalAuthenticatedData(aad: Uint8Array): this;
87
+ /** Encrypts and resolves the value of the General JWE object. */
88
+ encrypt(): Promise<types.GeneralJWE>;
89
+ }