@aura-stack/jose 0.1.0 → 0.2.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.
@@ -1,33 +0,0 @@
1
- import {
2
- createSecret
3
- } from "./chunk-M4WAOCIJ.js";
4
-
5
- // src/encrypt.ts
6
- import crypto from "crypto";
7
- import { EncryptJWT, jwtDecrypt } from "jose";
8
- var encryptJWE = async (payload, secret) => {
9
- const secretKey = createSecret(secret);
10
- const jti = crypto.randomBytes(32).toString("base64");
11
- return new EncryptJWT({ token: payload }).setProtectedHeader({ alg: "dir", enc: "A256GCM", typ: "JWT", cty: "JWT" }).setIssuedAt().setNotBefore("0s").setExpirationTime("15d").setJti(jti).encrypt(secretKey);
12
- };
13
- var decryptJWE = async (token, secret) => {
14
- try {
15
- const secretKey = createSecret(secret);
16
- const { payload } = await jwtDecrypt(token, secretKey);
17
- return payload.token;
18
- } catch (error) {
19
- throw new Error("Invalid JWE", { cause: error });
20
- }
21
- };
22
- var createJWE = (secret) => {
23
- return {
24
- encryptJWE: (payload) => encryptJWE(payload, secret),
25
- decryptJWE: (payload) => decryptJWE(payload, secret)
26
- };
27
- };
28
-
29
- export {
30
- encryptJWE,
31
- decryptJWE,
32
- createJWE
33
- };