{"id":13566864,"url":"https://github.com/decentralized-identity/did-jwt","last_synced_at":"2025-05-14T13:02:28.450Z","repository":{"id":38359872,"uuid":"122692861","full_name":"decentralized-identity/did-jwt","owner":"decentralized-identity","description":"Create and verify DID verifiable JWT's in Javascript","archived":false,"fork":false,"pushed_at":"2025-05-12T07:34:40.000Z","size":5691,"stargazers_count":354,"open_issues_count":7,"forks_count":75,"subscribers_count":38,"default_branch":"master","last_synced_at":"2025-05-12T08:53:38.721Z","etag":null,"topics":["wg-id"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/decentralized-identity.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"Contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-02-24T02:00:53.000Z","updated_at":"2025-05-08T17:29:11.000Z","dependencies_parsed_at":"2023-12-26T17:11:45.837Z","dependency_job_id":"c602ac76-20a0-4f41-80fd-5af4f145284b","html_url":"https://github.com/decentralized-identity/did-jwt","commit_stats":{"total_commits":567,"total_committers":40,"mean_commits":14.175,"dds":0.6966490299823633,"last_synced_commit":"582740ea75dfe4cb5ddb490e183bd11ff3b1d2b3"},"previous_names":[],"tags_count":139,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decentralized-identity%2Fdid-jwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decentralized-identity%2Fdid-jwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decentralized-identity%2Fdid-jwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decentralized-identity%2Fdid-jwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/decentralized-identity","download_url":"https://codeload.github.com/decentralized-identity/did-jwt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253708793,"owners_count":21951057,"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":["wg-id"],"created_at":"2024-08-01T13:02:18.327Z","updated_at":"2025-05-14T13:02:28.413Z","avatar_url":"https://github.com/decentralized-identity.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"[![npm](https://img.shields.io/npm/dt/did-jwt.svg)](https://www.npmjs.com/package/did-jwt)\n[![npm](https://img.shields.io/npm/v/did-jwt.svg)](https://www.npmjs.com/package/did-jwt)\n[![Twitter Follow](https://img.shields.io/twitter/follow/veramolabs.svg?style=social\u0026label=Follow)](https://twitter.com/veramolabs)\n[![codecov](https://codecov.io/gh/decentralized-identity/did-jwt/branch/master/graph/badge.svg)](https://codecov.io/gh/decentralized-identity/did-jwt)\n\n# did-jwt\n\nThe did-JWT library allows you to sign and verify [JSON Web Tokens (JWT)](https://tools.ietf.org/html/rfc7519)\nusing `ES256K` and `EdDSA` algorithms. The non-standard `ES256K-R` is also supported for backward compatibility\nreasons, as well as the `Ed25519` legacy name for `EdDSA`.\n\nPublic keys are resolved using the [Decentralized ID (DID)](https://w3c.github.io/did-core/#identifier) of the signing\nidentity of the token, which is passed as the `iss` attribute of the JWT payload.\n\n## DID methods\n\nAll DID methods that can be resolved using the [`did-resolver`](https://github.com/decentralized-identity/did-resolver)\ninterface are supported for verification.\n\nIf your DID method requires a different signing algorithm than what is already supported, please create an issue.\n\n## Installation\n\n```bash\nnpm install did-jwt\n```\n\nor if you use `yarn`\n\n```bash\nyarn add did-jwt\n```\n\n## Example\n\n### 1. Create a did-JWT\n\nIn practice, you must secure the key passed to `ES256KSigner`. The key provided in code below is for informational\npurposes only.\n\n```ts\nimport didJWT from 'did-jwt';\n\nconst signer = didJWT.ES256KSigner(didJWT.hexToBytes('278a5de700e29faae8e40e366ec5012b5ec63d36ec77e8a2417154cc1d25383f'))\n\nlet jwt = await didJWT.createJWT(\n  { aud: 'did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74', iat: undefined, name: 'uPort Developer' },\n  { issuer: 'did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74', signer },\n  { alg: 'ES256K' }\n)\nconsole.log(jwt)\n```\n\n### 2. Decode a did-JWT\n\nTry decoding the JWT. You can also do this using [jwt.io](https://jwt.io)\n\n```js\n//pass the jwt from step 1\nlet decoded = didJWT.decodeJWT(jwt)\nconsole.log(decoded)\n```\n\nOnce decoded a did-JWT will resemble:\n\n```ts\nexpect(decoded).toEqual({\n  header: { alg: 'ES256K', typ: 'JWT' },\n  payload: {\n    aud: 'did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74',\n    name: 'uPort Developer',\n    iss: 'did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74'\n  },\n  signature: 'mAhpAnw-9u57hyAaDufj2GPMbmuZyPDlU7aYSUMKk7P_9_cF3iLk-hFjFhb5xaUQB5nXYrciw6ZJ2RSAZI-IDQ',\n  data: 'eyJhbGciOiJFUzI1NksiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJkaWQ6ZXRocjoweGYzYmVhYzMwYzQ5OGQ5ZTI2ODY1ZjM0ZmNhYTU3ZGJiOTM1YjBkNzQiLCJuYW1lIjoidVBvcnQgRGV2ZWxvcGVyIiwiaXNzIjoiZGlkOmV0aHI6MHhmM2JlYWMzMGM0OThkOWUyNjg2NWYzNGZjYWE1N2RiYjkzNWIwZDc0In0'\n})\n```\n\n### 3. Verify a did-JWT\n\nYou need to provide a did-resolver for the verify function. For this example we will use `did:ethr`, but there are other\nmethods available. For more information on configuring the Resolver object please\nsee [did-resolver](https://github.com/decentralized-identity/did-resolver#configure-resolver-object)\n\n```bash\nnpm install ethr-did-resolver\n```\n\n```js\nimport {Resolver} from 'did-resolver';\nimport {getResolver} from 'ethr-did-resolver'\n\nlet resolver = new Resolver({...getResolver({infuraProjectId: '\u003cget a free ID from infura.io\u003e'})});\n\n// use the JWT from step 1\nlet verificationResponse = await didJWT.verifyJWT(jwt, {\n  resolver,\n  audience: 'did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74'\n})\nconsole.log(verificationResponse)\n```\n\nA verification response is an object resembling:\n\n```typescript\nexpect(verificationResponse).toEqual({\n  payload: {\n    aud: 'did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74',\n    name: 'uPort Developer',\n    iss: 'did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74'\n  },\n  didResolutionResult: {\n    didDocumentMetadata: {},\n    didResolutionMetadata: { contentType: 'application/did+ld+json' },\n    didDocument: {\n      '@context': [\n        'https://www.w3.org/ns/did/v1',\n        'https://w3id.org/security/suites/secp256k1recovery-2020/v2'\n      ],\n      id: 'did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74',\n      verificationMethod: [\n        {\n          id: 'did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74#controller',\n          type: 'EcdsaSecp256k1RecoveryMethod2020',\n          controller: 'did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74',\n          blockchainAccountId: 'eip155:1:0xF3beAC30C498D9E26865F34fCAa57dBB935b0D74'\n        }\n      ],\n      authentication: [\n        'did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74#controller'\n      ],\n      assertionMethod: [\n        'did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74#controller'\n      ]\n    }\n  },\n  issuer: 'did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74',\n  signer: {\n    id: 'did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74#controller',\n    type: 'EcdsaSecp256k1RecoveryMethod2020',\n    controller: 'did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74',\n    blockchainAccountId: 'eip155:1:0xF3beAC30C498D9E26865F34fCAa57dBB935b0D74'\n  },\n  jwt: 'eyJhbGciOiJFUzI1NksiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJkaWQ6ZXRocjoweGYzYmVhYzMwYzQ5OGQ5ZTI2ODY1ZjM0ZmNhYTU3ZGJiOTM1YjBkNzQiLCJuYW1lIjoidVBvcnQgRGV2ZWxvcGVyIiwiaXNzIjoiZGlkOmV0aHI6MHhmM2JlYWMzMGM0OThkOWUyNjg2NWYzNGZjYWE1N2RiYjkzNWIwZDc0In0.mAhpAnw-9u57hyAaDufj2GPMbmuZyPDlU7aYSUMKk7P_9_cF3iLk-hFjFhb5xaUQB5nXYrciw6ZJ2RSAZI-IDQ',\n  policies: {}\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdecentralized-identity%2Fdid-jwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdecentralized-identity%2Fdid-jwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdecentralized-identity%2Fdid-jwt/lists"}