did-jwt
Algorithms supported | DID Public Key Types | Claim Specification
The did-JWT library allows you to sign and verify JSON Web Tokens (JWT) using ES256K or ES256K-R algorithms.
Public keys are resolved using the Decentralized ID (DID) of the signing identity of the claim, which is passed as the iss
attribute of the encoded JWT.
Installation
npm install did-jwt
or if you use yarn
yarn add did-jwt
Example
1. Create a did-JWT
In practice you should secure the key passed to SimpleSigner. The key provided in code below is for informational purposes; you will need to create an application identity at My Apps or use our uport-credentials library to generate an ethereum key pair.
const didJWT = const signer = didJWT; let jwt = '';didJWT; console;
2. Decode a did-JWT
Try decoding the JWT. You can also do this using jwt.io
didJWT
Once decoded a did-JWT will resemble:
header: typ: 'JWT' alg: 'ES256K' payload: iat: 1525927517 aud: 'did:uport:2osnfJ4Wy7LBAm2nPBXire1WfQn75RrV6Ts' exp: 1557463421 name: 'uPort Developer' iss: 'did:uport:2osnfJ4Wy7LBAm2nPBXire1WfQn75RrV6Ts' signature: 'R7owbvNZoL4ti5ec-Kpktb0datw9Y-FshHsF5R7cXuKaiGlQz1dcOOXbXTOb-wg7-30CDfchFERR6Yc8F61ymw' data: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJpYXQiOjE1MjU5Mjc1MTcsImF1ZCI6ImRpZDp1cG9ydDoyb3NuZko0V3k3TEJBbTJuUEJYaXJlMVdmUW43NVJyVjZUcyIsImV4cCI6MTU1NzQ2MzQyMSwibmFtZSI6InVQb3J0IERldmVsb3BlciIsImlzcyI6ImRpZDp1cG9ydDoyb3NuZko0V3k3TEJBbTJuUEJYaXJlMVdmUW43NVJyVjZUcyJ9'
2. Verify a did-JWT
// pass the JWT from step 1 & 2let verifiedRespone = {};didJWT; console;
A verified did-JWT returns an object resembling:
payload: iat: 1525927517 aud: 'did:uport:2osnfJ4Wy7LBAm2nPBXire1WfQn75RrV6Ts' exp: 1557463421 name: 'uPort Developer' iss: 'did:uport:2osnfJ4Wy7LBAm2nPBXire1WfQn75RrV6Ts' doc: '@context': 'https://w3id.org/did/v1' id: 'did:uport:2osnfJ4Wy7LBAm2nPBXire1WfQn75RrV6Ts' publicKey: Object uportProfile: '@context': 'http://schema.org' '@type': 'App' name: 'Uport Developer Splash Demo' description: 'This app demonstrates basic login functionality' url: 'https://developer.uport.me' issuer: 'did:uport:2osnfJ4Wy7LBAm2nPBXire1WfQn75RrV6Ts' signer: id: 'did:uport:2osnfJ4Wy7LBAm2nPBXire1WfQn75RrV6Ts#keys-1' type: 'EcdsaPublicKeySecp256k1' owner: 'did:uport:2osnfJ4Wy7LBAm2nPBXire1WfQn75RrV6Ts' publicKeyHex: '04c74d8a9154bbf48ce4b259b703c420e10aba42d03fa592ccf9dea60c83cd9ca81d3e08b859d4dc5a6dee30da2600e50ace688201b6f5a1e0938d135ec4b442ad' jwt: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJpYXQiOjE1MjU5Mjc1MTcsImF1ZCI6ImRpZDp1cG9ydDoyb3NuZko0V3k3TEJBbTJuUEJYaXJlMVdmUW43NVJyVjZUcyIsImV4cCI6MTU1NzQ2MzQyMSwibmFtZSI6InVQb3J0IERldmVsb3BlciIsImlzcyI6ImRpZDp1cG9ydDoyb3NuZko0V3k3TEJBbTJuUEJYaXJlMVdmUW43NVJyVjZUcyJ9.R7owbvNZoL4ti5ec-Kpktb0datw9Y-FshHsF5R7cXuKaiGlQz1dcOOXbXTOb-wg7-30CDfchFERR6Yc8F61ymw'