{"id":13566865,"url":"https://github.com/decentralized-identity/did-jwt-vc","last_synced_at":"2025-05-15T08:07:37.546Z","repository":{"id":37664403,"uuid":"198296304","full_name":"decentralized-identity/did-jwt-vc","owner":"decentralized-identity","description":"Create and verify W3C Verifiable Credentials and Presentations in JWT format","archived":false,"fork":false,"pushed_at":"2025-04-05T02:35:32.000Z","size":2161,"stargazers_count":189,"open_issues_count":3,"forks_count":47,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-04-07T02:20:34.703Z","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}},"created_at":"2019-07-22T20:20:06.000Z","updated_at":"2025-03-19T11:10:08.000Z","dependencies_parsed_at":"2023-09-25T15:49:10.138Z","dependency_job_id":"7c26353c-5ee8-450e-b33f-282a6d99d690","html_url":"https://github.com/decentralized-identity/did-jwt-vc","commit_stats":{"total_commits":354,"total_committers":21,"mean_commits":"16.857142857142858","dds":0.576271186440678,"last_synced_commit":"92f424c011f66f92f1d67c6ab6dd2382350094fc"},"previous_names":[],"tags_count":66,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decentralized-identity%2Fdid-jwt-vc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decentralized-identity%2Fdid-jwt-vc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decentralized-identity%2Fdid-jwt-vc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decentralized-identity%2Fdid-jwt-vc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/decentralized-identity","download_url":"https://codeload.github.com/decentralized-identity/did-jwt-vc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248870970,"owners_count":21175127,"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.367Z","updated_at":"2025-04-14T11:27:41.599Z","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-vc.svg)](https://www.npmjs.com/package/did-jwt-vc)\n[![npm](https://img.shields.io/npm/v/did-jwt-vc.svg)](https://www.npmjs.com/package/did-jwt-vc)\n[![codecov](https://codecov.io/gh/decentralized-identity/did-jwt-vc/branch/master/graph/badge.svg)](https://codecov.io/gh/decentralized-identity/did-jwt-vc)\n\n# did-jwt-vc\n\nCreate and verify W3C Verifiable Credentials and Presentations in JWT format\n\n## Installation\n\n```\nnpm install did-jwt-vc\n```\n\n## Usage\n\n### Creating JWTs\n\n#### Prerequisites\n\nCreate an `Issuer` object to sign JWTs using, for example [ethr-did](https://github.com/uport-project/ethr-did)\n\n```typescript\nimport { EthrDID } from 'ethr-did'\nimport { Issuer } from 'did-jwt-vc'\n\nconst issuer = new EthrDID({\n  identifier: '0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198',\n  privateKey: 'd8b595680851765f38ea5405129244ba3cbad84467d190859f4c8b20c1ff6c75'\n}) as Issuer\n```\n\nThe `Issuer` object must contain a `did` attribute, an `alg` property that is used in the JWT header and a `signer`\nfunction to generate the signature.\n\n#### Creating a Verifiable Credential\n\nSpecify a `payload` matching the `CredentialPayload` or `JwtCredentialPayload` interfaces. Create a JWT by signing it\nwith the previously configured `issuer` using the `createVerifiableCredentialJwt` function:\n\n```typescript\nimport { JwtCredentialPayload, createVerifiableCredentialJwt } from 'did-jwt-vc'\n\nconst vcPayload: JwtCredentialPayload = {\n  sub: 'did:ethr:0x435df3eda57154cf8cf7926079881f2912f54db4',\n  nbf: 1562950282,\n  vc: {\n    '@context': ['https://www.w3.org/2018/credentials/v1'],\n    type: ['VerifiableCredential'],\n    credentialSubject: {\n      degree: {\n        type: 'BachelorDegree',\n        name: 'Baccalauréat en musiques numériques'\n      }\n    }\n  }\n}\n\nconst vcJwt = await createVerifiableCredentialJwt(vcPayload, issuer)\nconsole.log(vcJwt)\n// eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQi...0CQmqB14NnN5XxD0d_glLRs1Myc_LBJjnuNwE\n```\n\n#### Creating a Verifiable Presentation\n\nSpecify a `payload` matching the `PresentationPayload` or `JwtPresentationPayload` interfaces, including the VC JWTs to\nbe presented in the `vp.verifiableCredential` array. Create a JWT by signing it with the previously configured `issuer`\nusing the `createVerifiablePresentationJwt` function:\n\n```typescript\nimport { JwtPresentationPayload, createVerifiablePresentationJwt } from 'did-jwt-vc'\n\nconst vpPayload: JwtPresentationPayload = {\n  vp: {\n    '@context': ['https://www.w3.org/2018/credentials/v1'],\n    type: ['VerifiablePresentation'],\n    verifiableCredential: [vcJwt]\n  }\n}\n\nconst vpJwt = await createVerifiablePresentationJwt(vpPayload, issuer)\nconsole.log(vpJwt)\n// eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1ODI1NDc...JNMUzZ6naacuWNGdZGuU0ZDwmgpUMUqIzMqFFRmge0R8QA\n```\n\n### Verifying JWTs\n\n#### Prerequisites\n\nCreate a `Resolver` using [did-resolver](https://github.com/decentralized-identity/did-resolver) and register the\n[ethr-did-resolver](https://github.com/decentralized-identity/ethr-did-resolver). When verifying a JWT signed by a DID,\nit is necessary to resolve its DID Document to check for keys that can validate the signature.\n\n```typescript\nimport { Resolver } from 'did-resolver'\nimport { getResolver } from 'ethr-did-resolver'\n\n// see also https://github.com/decentralized-identity/ethr-did-resolver#multi-network-configuration\nconst providerConfig = {\n  rpcUrl: 'https://mainnet.infura.io/v3/\u003cYOUR infura.io PROJECT ID\u003e',\n  registry: '0xdca7ef03e98e0dc2b855be647c39abe984fcf21b'\n}\nconst resolver = new Resolver(getResolver(providerConfig))\n```\n\n#### Verifying a Verifiable Credential\n\nPass in a VC JWT along with the resolver to verify using the `verifyCredential` function:\n\n```typescript\nimport { verifyCredential } from 'did-jwt-vc'\n\nconst verifiedVC = await verifyCredential(vcJwt, resolver)\nconsole.log(verifiedVC)\n/*\n{\n  \"payload\": {\n    // the original payload of the signed credential\n  },\n  \"doc\": {\n    // the DID document of the credential issuer (as returned by the `resolver`)\n  },\n  \"issuer\": \"did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198\", //the credential issuer\n  \"signer\": {\n    //the publicKey entry of the `doc` that has signed the credential\n  },\n  \"jwt\": \"eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1NjY...Sx3Y2IdWaUpatJQA\", // the original credential\n  \n  //parsed payload aligned to the W3C data model\n  \"verifiableCredential\": {\n    \"@context\": [Array],\n    \"type\": [ \"VerifiableCredential\", \"UniversityDegreeCredential\" ],\n    \"issuer\": {\n      \"id\": \"did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198\"\n    },\n    \"issuanceDate\": \"2019-07-12T16:51:22.000Z\",\n    \"credentialSubject\": {\n      \"id\": \"did:ethr:0x435df3eda57154cf8cf7926079881f2912f54db4\"\n      \"degree\": {\n        \"type\": \"BachelorDegree\",\n        \"name\": \"Baccalauréat en musiques numériques\"\n      },\n    },\n    \"proof\": {\n      //  proof type for internal use, NOT a registered vc-data-model type\n      \"type\": \"JwtProof2020\",\n      \"jwt\": \"eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1NjY...Sx3Y2IdWaUpatJQA\"\n    }\n  }\n}\n*/\n```\n\n#### Verifying a Verifiable Presentation\n\nPass in a VP JWT along with the resolver to verify using the `verifyPresentation` function:\n\n```typescript\nimport { verifyPresentation } from 'did-jwt-vc'\n\nconst verifiedVP = await verifyPresentation(vpJwt, resolver)\nconsole.log(verifiedVP)\n/*\n{\n  //original JWT payload\n  payload: {\n    iat: 1568045263,\n    vp: {\n      '@context': [Array],\n      type: ['VerifiablePresentation'],\n      verifiableCredential: [\n        'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1NjY5...lpNm51cqSx3Y2IdWaUpatJQA'\n      ]\n    },\n    iss: 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198'\n  },\n  \n  doc: {\n    // the DID document of the presentation issuer (as returned by the `resolver`)\n  },\n  \n  signer: {\n    //the publicKey entry of the `doc` that has signed the presentation\n  },\n  \n  issuer: 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198',\n\n  jwt: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1NjgwNDUyNjMsInZwIjp7...ViNNCvoTQ-swSHwbELW7-EGPAcHLOMiIwE',\n\n  // parsed payload aligned to the W3C data model\n  verifiablePresentation: {\n    verifiableCredential: [\n      {\n        iat: 1566923269,\n        credentialSubject: {\n          degree: { type: 'BachelorDegree', name: 'Baccalauréat en musiques numériques' },\n          id: 'did:ethr:0x435df3eda57154cf8cf7926079881f2912f54db4'\n        },\n        issuer: { id: 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198' },\n        type: ['VerifiableCredential', 'UniversityDegreeCredential'],\n        '@context': [Array],\n        issuanceDate: '2019-07-12T16:51:22.000Z',\n        proof: {\n          type: 'JwtProof2020',\n          jwt: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1NjY5...lpNm51cqSx3Y2IdWaUpatJQA'\n        }\n      }\n    ],\n    holder: 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198',\n    type: ['VerifiablePresentation'],\n    '@context': [Array],\n    issuanceDate: '2019-09-09T16:07:43.000Z',\n    proof: {\n      // proof type for internal use, NOT a registered W3C vc-data-model proof type\n      type: 'JwtProof2020',\n      jwt: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1NjgwNDUyNjMsInZwI...ViNNCvoTQ-swSHwbELW7-EGPAcHLOMiIwE'\n    }\n  }\n}\n*/\n```\n\n#### Notes on verification and proof properties\n\nThe result of the verification methods, when successful, also conveniently contain the decoded and parsed payloads, in a\nformat that closely matches the [W3C data model](https://www.w3.org/TR/vc-data-model/) for verifiable credentials and\npresentations. This makes it easier to work with both credential encodings in the same system. This parsed payload also\nshows a `proof` property that lists the full JWT credential or presentation.\n\nThe `JwtProof2020` is a synthetic proof type, usable for differentiating credentials by type. It is not a registered W3C\nVC Data Model algorithm and should not be treated as such.\n\nAlso note that the `@context` fields that appear in this parsed payload are the same as the ones in the incoming JWT.\nThis means that the parsed payload will probably not be suitable for an LD-processor.\n\nPlease see #54 for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdecentralized-identity%2Fdid-jwt-vc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdecentralized-identity%2Fdid-jwt-vc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdecentralized-identity%2Fdid-jwt-vc/lists"}