{"id":19123108,"url":"https://github.com/digitalbazaar/minimal-jwt","last_synced_at":"2025-07-17T20:39:55.732Z","repository":{"id":57108361,"uuid":"297205132","full_name":"digitalbazaar/minimal-jwt","owner":"digitalbazaar","description":"Minimal signature/verification JWT library","archived":false,"fork":false,"pushed_at":"2023-02-08T18:24:38.000Z","size":29,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-04-18T13:19:06.817Z","etag":null,"topics":["jose","jsonwebtoken","jwt","sign","verify"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/digitalbazaar.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-09-21T02:12:39.000Z","updated_at":"2024-01-05T02:08:25.000Z","dependencies_parsed_at":"2023-02-17T11:16:09.005Z","dependency_job_id":null,"html_url":"https://github.com/digitalbazaar/minimal-jwt","commit_stats":{"total_commits":49,"total_committers":5,"mean_commits":9.8,"dds":0.6326530612244898,"last_synced_commit":"2e9497c8d5792817c93964b195a7bc0f24b4e81d"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalbazaar%2Fminimal-jwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalbazaar%2Fminimal-jwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalbazaar%2Fminimal-jwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalbazaar%2Fminimal-jwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/digitalbazaar","download_url":"https://codeload.github.com/digitalbazaar/minimal-jwt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252553136,"owners_count":21766835,"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":["jose","jsonwebtoken","jwt","sign","verify"],"created_at":"2024-11-09T05:24:20.900Z","updated_at":"2025-05-05T18:33:37.729Z","avatar_url":"https://github.com/digitalbazaar.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Minimal JWT _(minimal-jwt)_\n\n\u003e Minimal signature/verification [JWT](https://tools.ietf.org/html/rfc7519) library\n\n## Table of Contents\n\n- [Security](#security)\n- [Install](#install)\n- [Usage](#usage)\n- [Contribute](#contribute)\n- [Commercial Support](#commercial-support)\n- [License](#license)\n\n## Security\n\nTBD\n\n## Install\n\nTo install locally (for development):\n\n```\ngit clone https://github.com/digitalbazaar/minimal-jwt.git\ncd minimal-jwt\nnpm install\n```\n\n## Usage\n\n### Sign\n\n```js\nimport * as JWT from '@digitalbazaar/minimal-jwt';\nimport crypto from 'node:crypto';\n\nconst SECRET = '\u003cthe-best-kept-secret\u003e';\n\n// create a sign function\nasync function signFn({data}) {\n  return crypto.createHmac('sha256', Buffer.from(SECRET)).update(data).digest();\n}\n\n(async function() {\n  const header = {alg: 'HS256', kid: '194B72684'};\n  const payload = {'example-claim': 'it was all a dream'};\n\n  const jwt = await JWT.sign({payload, header, signFn});\n\n  // eyJhbGciOiJIUzI1NiIsImtpZCI6IjE5NEI3MjY4NCIsInR5cCI6IkpXVCJ9.eyJleGFtcGxlLWNsYWltIjoiaXQgd2FzIGFsbCBhIGRyZWFtIn0.rVh61q6ZJCeS4vj-d8OmFFWnAbt4vcWcoMqHtGlSQ18\n  console.log(jwt);\n})();\n\n```\n\n### Verify\n\n\n```js\nimport * as JWT from '@digitalbazaar/minimal-jwt';\nimport crypto from 'node:crypto';\n\nconst EXPECTED_ALGS = new Set(['HS256']);\nconst EXPECTED_KID = '194B72684';\nconst SECRET = '\u003cthe-best-kept-secret\u003e';\n\n(async function() {\n  const jwt = 'eyJhbGciOiJIUzI1NiIsImtpZCI6IjE5NEI3MjY4NCIsInR5cCI6IkpXVCJ9.eyJleGFtcGxlLWNsYWltIjoiaXQgd2FzIGFsbCBhIGRyZWFtIn0.rVh61q6ZJCeS4vj-d8OmFFWnAbt4vcWcoMqHtGlSQ18';\n\n  const response = await JWT.verify({jwt, verifyFn});\n\n  /*\n    {\n      header: { alg: 'HS256', kid: '194B72684', typ: 'JWT' },\n      payload: { 'example-claim': 'it was all a dream' }\n    }\n  */\n  console.log(response);\n})();\n\n// create a verify function\nasync function verifyFn({alg, kid, data, signature}) {\n  if(!EXPECTED_ALGS.has(alg)) {\n    throw new Error(`\"${alg}\" is not supported.`);\n  }\n\n  if(alg === 'HS256' \u0026\u0026 kid === EXPECTED_KID) {\n    const expectedSignature = await signFn({data});\n\n    return crypto.timingSafeEqual(\n      Buffer.from(signature),\n      Buffer.from(expectedSignature)\n    );\n  } else {\n    throw new Error(`Key \"${kid}\" is not supported.`);\n  }\n}\nasync function signFn({data}) {\n  return crypto.createHmac('sha256', Buffer.from(SECRET)).update(data).digest();\n}\n```\n\n## Contribute\n\nSee [the contribute file](https://github.com/digitalbazaar/bedrock/blob/master/CONTRIBUTING.md)!\n\nPRs accepted.\n\nSmall note: If editing the README, please conform to the\n[standard-readme](https://github.com/RichardLitt/standard-readme) specification.\n\n## Commercial Support\n\nCommercial support for this library is available upon request from\nDigital Bazaar: support@digitalbazaar.com\n\n## License\n\n[New BSD License (3-clause)](LICENSE) © Digital Bazaar\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigitalbazaar%2Fminimal-jwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdigitalbazaar%2Fminimal-jwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigitalbazaar%2Fminimal-jwt/lists"}