How to use did-jwt - 10 common examples

To help you get started, we’ve selected a few did-jwt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 3box / muport-core-js / src / muport.js View on Github external
async signJWT (payload) {
    const settings = {
      signer: this.keyring.getJWTSigner(),
      issuer: this.did
      // TODO - should we have an expiry?
    }
    return didJWT.createJWT(payload, settings)
  }
github 3box / muport-core-js / lib / muport.js View on Github external
return _regenerator2.default.wrap(function _callee5$(_context5) {
          while (1) {
            switch (_context5.prev = _context5.next) {
              case 0:
                settings = {
                  signer: this.keyring.getJWTSigner(),
                  issuer: this.did
                  // TODO - should we have an expiry?
                };
                return _context5.abrupt('return', didJWT.createJWT(payload, settings));

              case 2:
              case 'end':
                return _context5.stop();
            }
          }
        }, _callee5, this);
      }));
github gluon-project / gluon-rxp / src / Sagas / ClaimsSaga.ts View on Github external
forEach(json.claims, (jwt: string) => {
        try {
          const decodedClaim = decodeJWT(jwt)
          if (decodedClaim) {
            const signedClaim: VerifiableClaim = {
              ...decodedClaim.payload,
              jwt,
              source: {
                type: 'matrix',
                id: roomId,
              },
            }
            result.push(signedClaim)
          }
        } catch (e) {
          // invalid jwt
        }

      })
github uport-project / uport-connect / src / Connect.js View on Github external
const parseResponse = (res) => {
      if (res.error) return Promise.reject(Object.assign({id}, res))
      if (message.util.isJWT(res.payload)) {
        const jwt = res.payload
        const decoded = decodeJWT(jwt)
        if (decoded.payload.claim){
          return Promise.resolve(Object.assign({id}, res))
        }
        return this.verifyResponse(jwt).then(parsedRes => {
          // Set identifiers present in the response
          // TODO maybe just change name in uport-js
          if (parsedRes.boxPub) parsedRes.publicEncKey = parsedRes.boxPub
          this.setState(parsedRes)
          return {id, payload: parsedRes, data: res.data}
        })
      } else {
        return Promise.resolve(Object.assign({id}, res))
      }
    }
github uport-project / uport-connect / src / Connect.js View on Github external
const parseResponse = (res) => {
      if (res.error) return Promise.reject(Object.assign({id}, res))
      if (message.util.isJWT(res.payload)) {
        const jwt = res.payload
        const decoded = decodeJWT(jwt)
        if (decoded.payload.claim){
          return Promise.resolve(Object.assign({id}, res))
        }
        return this.verifyResponse(jwt).then(parsedRes => {
          // Set identifiers present in the response
          // TODO maybe just change name in uport-js
          if (parsedRes.boxPub) parsedRes.publicEncKey = parsedRes.boxPub
          this.setState(parsedRes)
          return {id, payload: parsedRes, data: res.data}
        })
      } else {
        return Promise.resolve(Object.assign({id}, res))
      }
    }
github uport-project / uport-connect / test / unit / Connect.js View on Github external
const transport = (uri, opts) => {
        const jwt = message.util.getURLJWT(uri)
        const decoded = didjwt.decodeJWT(jwt)
        expect(/chasqui/.test(decoded.payload.callback)).to.be.true
        done()
      }
      const uport = new Connect('testApp', { transport, vc })
github uport-project / uport-connect / test / unit / Connect.js View on Github external
const send = (uri) => {
        const jwt = getURLJWT(uri)
        const decoded = didjwt.decodeJWT(jwt)
        expect(decoded.payload.to).to.equal('2ooE3vLGYi9vHmfYSc3ZxABfN5p8756sgi6')
        done()
      }
      const uport = new Connect('testApp', { vc })
github gluon-project / gluon-rxp / src / Selectors / ContactsSelectors.ts View on Github external
const claims = _.map(encodedClaims, (jwt: string) => {
    let result: VerifiableClaim = null
    try {
      const decodedClaim = decodeJWT(jwt)
      result = {
        ...decodedClaim.payload,
        jwt,
      }
    } catch (e) {
      console.log(e)
    }
    return result
  })
github 3box / 3box-js / src / utils / verifier.js View on Github external
export async function verifyTwitter (did, claim) {
  if (!claim) return null
  const verified = await didJWT.verifyJWT(claim)
  if (verified.payload.sub !== did) {
    throw new Error('Verification not valid for given user')
  }
  const claimData = verified.payload.claim
  if (!claimData.twitter_handle || !claimData.twitter_proof) {
    throw new Error('The claim for your twitter is not correct')
  }
  return {
    username: claimData.twitter_handle,
    proof: claimData.twitter_proof,
    verifiedBy: verified.payload.iss
  }
}

did-jwt

Library for Signing and Verifying JWTs that use DIDs as issuers and JWEs that use DIDs as recipients

Apache-2.0
Latest version published 8 months ago

Package Health Score

77 / 100
Full package analysis

Similar packages