{"id":23085212,"url":"https://github.com/z3ntl3/next-jwt","last_synced_at":"2026-05-05T21:34:43.457Z","repository":{"id":64718341,"uuid":"577726172","full_name":"Z3NTL3/next-jwt","owner":"Z3NTL3","description":"NPM library to manage \u0026 validate encrypted JSON Web Tokens within simplicity","archived":false,"fork":false,"pushed_at":"2023-01-08T12:34:53.000Z","size":35,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-02T20:05:19.153Z","etag":null,"topics":["api","encryption","json","jwt","npm","reference","token","web"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/nextjwt","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Z3NTL3.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-12-13T11:41:11.000Z","updated_at":"2024-01-29T10:36:49.000Z","dependencies_parsed_at":"2023-02-08T05:45:33.266Z","dependency_job_id":null,"html_url":"https://github.com/Z3NTL3/next-jwt","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Z3NTL3%2Fnext-jwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Z3NTL3%2Fnext-jwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Z3NTL3%2Fnext-jwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Z3NTL3%2Fnext-jwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Z3NTL3","download_url":"https://codeload.github.com/Z3NTL3/next-jwt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247025522,"owners_count":20871206,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","encryption","json","jwt","npm","reference","token","web"],"created_at":"2024-12-16T17:50:55.854Z","updated_at":"2026-05-05T21:34:43.414Z","avatar_url":"https://github.com/Z3NTL3.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# next-jwt\nNPM library to manage \u0026 validate encrypted JSON Web Tokens within simplicity\u003cbr\u003e\u003cbr\u003e\n**Built on top of:** ``jose`` package.\n\n##### API INFO\nPublic Key needs to be in ``PKCS8``\u003cbr\u003e\nPrivate Key needs to be in ``SPKI``\n\n**Used Algorithm:** ``RSA``\n**Encryption:** ``A256GCM``\n**Hash:** ``SHA512``\n\n#### Supports\n- Custom JWT Claims Object\n- Issuer\n- Audience\n- Expiration TimeStamp\n- Issued at timestamp\n- Encryption\n\n# Example\n```js\nconst { JWT } = require('nextjwt')\nconst { readFileSync } = require('node:fs')\n\nasync function test(){\n    let jwt = new JWT(\n        readFileSync('test/pub.pem','utf-8'),\n        readFileSync('test/priv.pem','utf-8')\n    )\n    await jwt.loadKey();\n\n    let jwtToken = await jwt.genToken({ uid: 1, name: \"efdal\" },2,'h','Pix4','api-access');\n    console.log(\"Enc Token:\\n\", jwtToken);\n\n    console.log(); // seperator line\n\n    let decrypted = await jwt.decrypt(jwtToken);\n    console.log(\"Decrypted:\\n\", decrypted);\n}test()\n```\n\n### API\n```js\n/*\n *  Programmed by Z3NTL3 (Efdal) GNU license see LICENSE file\n */\n\nimport jose = require(\"jose\");\n\ninterface Keys {\n  priv: jose.KeyLike;\n  pub: jose.KeyLike;\n}\n\ninterface User {\n  uid: number;\n  name: string;\n}\n\ntype validID = \"h\" | \"m\" | \"s\"\n\nclass JWT {\n  pub: any;\n  priv: any;\n  secret: any;\n\n  /**\n   * @author Z3NTL3 (Efdal) \u003cz3ntl3discord@gmail.com\u003e\n   * @param publicKey Public Key as String\n   * @param privateKey Private key as String\n   */\n  constructor(publicKey: string, privateKey: string) {\n    this.pub = publicKey;\n    this.priv = privateKey;\n  }\n\n  /**\n   * @author Z3NTL3 (Efdal) \u003cz3ntl3discord@gmail.com\u003e\n   * @description Initialization part\n   */\n  loadKey(): Promise\u003cKeys\u003e {\n    return new Promise(async (resolve) =\u003e {\n      this.secret = await jose.generateSecret(\"HS512\");\n      let privK = await jose.importPKCS8(String(this.priv), \"HS512\");\n      let pubK = await jose.importSPKI(String(this.pub), \"HS512\");\n\n      this.priv = privK;\n      this.pub = pubK;\n\n      return resolve({ priv: privK, pub: pubK });\n    });\n  }\n  /**\n   * @author Z3NTL3 (Efdal) \u003cz3ntl3discord@gmail.com\u003e\n   * @description Encrypted JWT token\n   */\n  genToken(claims: User, expiration: Number, expUnit: validID, issuer: string, audience: string): Promise\u003cstring\u003e {\n    return new Promise(async (resolve) =\u003e {\n      const jwt = await new jose.EncryptJWT({ claims })\n        .setProtectedHeader({ alg: \"RSA1_5\", enc: \"A256GCM\" })\n        .setIssuedAt()\n        .setIssuer(issuer)\n        .setAudience(audience)\n        .setExpirationTime(`${expiration}${expUnit}`)\n        .encrypt(this.priv, this.secret);\n\n      return resolve(jwt);\n    });\n  }\n\n  /**\n   * @author Z3NTL3 (Efdal) \u003cz3ntl3discord@gmail.com\u003e\n   * @param token JWT token\n   * @returns Decrypted JWT results\n   */\n  decrypt(token: string): Promise\u003cjose.JWTDecryptResult\u003e {\n    return new Promise(async (resolve) =\u003e {\n      const jwt = await jose.jwtDecrypt(token, this.priv, this.secret);\n      return resolve(jwt);\n    });\n  }\n}\n\nexport { JWT };\n```\n# NPM Lib\n``npm i nextjwt``\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fz3ntl3%2Fnext-jwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fz3ntl3%2Fnext-jwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fz3ntl3%2Fnext-jwt/lists"}