Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
D

did-jwt

> 编程语言
Open source

Create and verify DID verifiable JWT's in Javascript

372 stars0 likes1 views
WebsiteGitHub

About

Create and verify DID verifiable JWT's in Javascript

did-jwt

The did-JWT library allows you to sign and verify JSON Web Tokens (JWT) using ES256K and EdDSA algorithms. The non-standard ES256K-R is also supported for backward compatibility reasons, as well as the Ed25519 legacy name for EdDSA.

Public keys are resolved using the Decentralized ID (DID) of the signing identity of the token, which is passed as the iss attribute of the JWT payload.

DID methods

All DID methods that can be resolved using the did-resolver interface are supported for verification.

If your DID method requires a different signing algorithm than what is already supported, please create an issue.

Installation

bash
npm install did-jwt

or if you use yarn

bash
yarn add did-jwt

Example

1. Create a did-JWT

In practice, you must secure the key passed to ES256KSigner. The key provided in code below is for informational purposes only.

typescript
import didJWT from 'did-jwt';

const signer = didJWT.ES256KSigner(didJWT.hexToBytes('278a5de700e29faae8e40e366ec5012b5ec63d36ec77e8a2417154cc1d25383f'))

let jwt = await didJWT.createJWT(
  { aud: 'did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74', iat: undefined, name: 'uPort Developer' },
  { issuer: 'did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74', signer },
  { alg: 'ES256K' }
)
console.log(jwt)

2. Decode a did-JWT

Try decoding the JWT. You can also do this using jwt.io

javascript
//pass the jwt from step 1
let decoded = didJWT.decodeJWT(jwt)
console.log(decoded)

Once decoded a did-JWT will resemble:

…

3. Verify a did-JWT

You need to provide a did-resolver for the verify function. For this example we will use did:ethr, but there are other methods available. For more information on configuring the Resolver object please see did-resolver

bash
npm install ethr-did-resolver
javascript
import {Resolver} from 'did-resolver';
import {getResolver} from 'ethr-did-resolver'

let resolver = new Resolver({...getResolver({infuraProjectId: ''})});

// use the JWT from step 1
let verificationResponse = await didJWT.verifyJWT(jwt, {
  resolver,
  audience: 'did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74'
})
console.log(verificationResponse)

A verification response is an object resembling:

…

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptwg-id

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言