{"_id":"@boxcolli/cloudflare-jwt-lib","_rev":"2-5e4a3bacf907868849d138551fd8f9bb","name":"@boxcolli/cloudflare-jwt-lib","dist-tags":{"latest":"0.0.3"},"versions":{"0.0.1":{"name":"@boxcolli/cloudflare-jwt-lib","version":"0.0.1","description":"A lightweight JWT implementation","type":"module","exports":"./index.js","types":"index.d.ts","engines":{"node":">=16.0.0"},"scripts":{"build":"tsc & esbuild --bundle --target=esnext --platform=neutral --outfile=index.js src/index.ts & wait","test":"vitest"},"repository":{"type":"git","url":"git+https://https://github.com/boxcolli/cloudflare-jwt-lib.git"},"keywords":["jwt","cloudflare"],"author":{"name":"boxcolli"},"license":"MIT","bugs":{"url":"https://https://github.com/boxcolli/cloudflare-jwt-lib/issues"},"homepage":"https://https://github.com/boxcolli/cloudflare-jwt-lib#readme","devDependencies":{"@cloudflare/workers-types":"^4.20240222.0","@edge-runtime/vm":"^3.2.0","typescript":"^5.3.3","vitest":"^1.3.1"},"_id":"@boxcolli/cloudflare-jwt-lib@0.0.1","gitHead":"ff9d6c603f0fc38841d459c67ea89ffe0e2a9e21","_nodeVersion":"21.6.2","_npmVersion":"10.2.4","dist":{"integrity":"sha512-/YHZWvKWwD6g7dIL34GOopl1NJruZrzTmkoAXzGz80z4nKK3WpSPrbXQRHYk1j7IBfCtdnN/gdwpZV/zeB/ofw==","shasum":"da0ea970b6c13e188af65e30709f329433bfecb9","tarball":"https://registry.npmjs.org/@boxcolli/cloudflare-jwt-lib/-/cloudflare-jwt-lib-0.0.1.tgz","fileCount":3,"unpackedSize":6561,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICjVuDsXQmvBAw6MPmTpeTsYY/XeA9qNNJ/tcU+1apobAiAUnX28dyvM7RdfWnaeR520RVhO6o0tA1B3oeTLXi7TbA=="}]},"_npmUser":{"name":"boxcolli","email":"dmg04158@gmail.com"},"directories":{},"maintainers":[{"name":"boxcolli","email":"dmg04158@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cloudflare-jwt-lib_0.0.1_1709203478229_0.9157951958544419"},"_hasShrinkwrap":false},"0.0.2":{"name":"@boxcolli/cloudflare-jwt-lib","version":"0.0.2","description":"A lightweight JWT implementation","type":"module","exports":"./index.js","types":"index.d.ts","engines":{"node":">=16.0.0"},"scripts":{"build":"tsc & esbuild --bundle --target=esnext --platform=neutral --outfile=index.js src/index.ts & wait","test":"vitest"},"repository":{"type":"git","url":"git+https://https://github.com/boxcolli/cloudflare-jwt-lib.git"},"keywords":["jwt","cloudflare"],"author":{"name":"boxcolli"},"license":"MIT","bugs":{"url":"https://https://github.com/boxcolli/cloudflare-jwt-lib/issues"},"homepage":"https://https://github.com/boxcolli/cloudflare-jwt-lib#readme","devDependencies":{"@cloudflare/workers-types":"^4.20240222.0","@edge-runtime/vm":"^3.2.0","typescript":"^5.3.3","vitest":"^1.3.1"},"_id":"@boxcolli/cloudflare-jwt-lib@0.0.2","gitHead":"50bb9229e2113a79990a64c0fe798a112174fbb8","_nodeVersion":"21.6.2","_npmVersion":"10.2.4","dist":{"integrity":"sha512-CyeN7xBJ4XWlWMRYdktw6x9UT9wvpQ7IP2NUlhYVAcK+BNaKLU/4sYMFmNk3aNIzDV/WGyRtPaZt5KkfjCitQg==","shasum":"164fd41bf333c19a1360efdc4d8f4bca2f4aa020","tarball":"https://registry.npmjs.org/@boxcolli/cloudflare-jwt-lib/-/cloudflare-jwt-lib-0.0.2.tgz","fileCount":6,"unpackedSize":8447,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCmKIysEG/8gJelEqrF+52tt14QVIUETa/xKkWknLazQwIgXSBtoX8IpDmGesb6VQq2k1xeOjPU9U1+N+TMNldhZWU="}]},"_npmUser":{"name":"boxcolli","email":"dmg04158@gmail.com"},"directories":{},"maintainers":[{"name":"boxcolli","email":"dmg04158@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cloudflare-jwt-lib_0.0.2_1709207207336_0.7851949008340056"},"_hasShrinkwrap":false},"0.0.3":{"name":"@boxcolli/cloudflare-jwt-lib","version":"0.0.3","description":"A lightweight JWT implementation","type":"module","exports":"./index.js","types":"index.d.ts","engines":{"node":">=16.0.0"},"scripts":{"build":"tsc & esbuild --bundle --target=esnext --platform=neutral --outfile=index.js src/index.ts & wait","test":"vitest"},"repository":{"type":"git","url":"https://https://github.com/boxcolli/cloudflare-jwt-lib.git"},"keywords":["jwt","cloudflare"],"author":{"name":"boxcolli"},"license":"MIT","bugs":{"url":"https://https://github.com/boxcolli/cloudflare-jwt-lib/issues"},"homepage":"https://github.com/boxcolli/cloudflare-jwt-lib","devDependencies":{"@cloudflare/workers-types":"^4.20240222.0","@edge-runtime/vm":"^3.2.0","typescript":"^5.3.3","vitest":"^1.3.1"},"_id":"@boxcolli/cloudflare-jwt-lib@0.0.3","gitHead":"50bb9229e2113a79990a64c0fe798a112174fbb8","_nodeVersion":"21.6.2","_npmVersion":"10.2.4","dist":{"integrity":"sha512-XiFxHc4HTE6MZ73tU2FNr/BTlvgeR4vIOAWOTy1L95OZxmwOLgc5Jyl+0rEM3UWIbuf0rr++WsRWJTHoQozUxQ==","shasum":"9b63f720b882c78a70ad7e7490187f7a9baaab80","tarball":"https://registry.npmjs.org/@boxcolli/cloudflare-jwt-lib/-/cloudflare-jwt-lib-0.0.3.tgz","fileCount":6,"unpackedSize":6070,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIG4K8+TAcpki88Kc8Gix2lu9aDptScvoNtZOpLLGzWoKAiEA4Mg7CX7eyzinRzzqljhN8Gw3f8Lf6rnZD52ambJzV1g="}]},"_npmUser":{"name":"boxcolli","email":"dmg04158@gmail.com"},"directories":{},"maintainers":[{"name":"boxcolli","email":"dmg04158@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cloudflare-jwt-lib_0.0.3_1709288122502_0.2646503391905599"},"_hasShrinkwrap":false}},"time":{"created":"2024-02-29T10:44:38.150Z","0.0.1":"2024-02-29T10:44:38.396Z","modified":"2024-03-01T10:15:23.609Z","0.0.2":"2024-02-29T11:46:47.489Z","0.0.3":"2024-03-01T10:15:22.700Z"},"maintainers":[{"name":"boxcolli","email":"dmg04158@gmail.com"}],"description":"A lightweight JWT implementation","homepage":"https://github.com/boxcolli/cloudflare-jwt-lib","keywords":["jwt","cloudflare"],"repository":{"type":"git","url":"https://https://github.com/boxcolli/cloudflare-jwt-lib.git"},"author":{"name":"boxcolli"},"bugs":{"url":"https://https://github.com/boxcolli/cloudflare-jwt-lib/issues"},"license":"MIT","readme":"# Cloudflare Worker JWT\n\nA simple library to generate JWT in cloudflare.\n\nThere is not much to show off. This package might provide a hint how to do JWT tasks in Cloudflare. You may skip install and copy the codes.\n\n## Explain\n\nThose functions are intended to make & verify JWT with given cryptography algorithm.\n\n### getToken\n```typescript\nexport async function getToken<H = Header, P = Payload>(    // (1)\n    header: H,                                              // (2)\n    payload: P,\n    sign: (data: string) => Promise<string>,                // (3)\n): Promise<string> {                                        // (4)\n    const h = base64UrlEncode(JSON.stringify(header))\n    const p = base64UrlEncode(JSON.stringify(payload))\n    const part = h + \".\" + p\n    const s = await sign(part)\n\n    return part + \".\" + s\n}\n```\n1. You can provide custom Header and Payload type.\n2. You must set `alg` and other fields manually. There is no autofill.\n3. Provide your desired cryptography algorithm.\n4. This function returns a complete JWT.\n\n### verifyToken\n```typescript\nexport async function verifyToken<H = Header, P = Payload>(     // (1)\n    token: string,                                              // (2)\n    verifyPayload: (p: P) => Promise<boolean>,                  // (3)\n    signByHeader: (h: H, data: string) => Promise<string>,      // (4)\n): Promise<[boolean, P]> {                                      // (5)\n    const parts = token.split(\".\")\n    const h: H = JSON.parse(base64UrlDecode(parts[0]))\n    const p: P = JSON.parse(base64UrlDecode(parts[1]))\n\n    if (! await verifyPayload(p)) return [false, p]             // (6)\n\n    const s = await signByHeader(h, parts[0] + \".\" + parts[1])\n\n    return [parts[2] == s, p]\n}\n```\n1. You can provide custom Header and Payload type.\n2. Provide JWT directly.\n3. Provide a complete payload verification function.\n4. Provide a function that reads the Header and generates appropriate signature.\n5. This function returns a verification result and the parsed Payload.\n6. The payload verfication function will be applied before comparing the signatures.\n","readmeFilename":"README.md"}