How to use the did-jwt/lib/Digest.toEthereumAddress function in did-jwt

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 uport-project / uport-credentials / src / Credentials.js View on Github external
} else if (privateKey) {
      this.signer = SimpleSigner(privateKey)
    }

    if (did) {
      this.did = did
    } else if (address) {
      if (isMNID(address)) {
        this.did = `did:uport:${address}`
      }
      if (address.match('^0x[0-9a-fA-F]{40}$')) {
        this.did = `did:ethr:${address}`
      }
    } else if (privateKey) {
      const kp = secp256k1.keyFromPrivate(privateKey)
      const address = toEthereumAddress(kp.getPublic('hex'))
      this.did = `did:ethr:${address}`
    }

    this.signJWT = (payload, expiresIn) =>
      createJWT(payload, {
        issuer: this.did,
        signer: this.signer,
        alg: this.did.match('^did:uport:') || isMNID(this.did) ? 'ES256K' : 'ES256K-R',
        expiresIn,
      })

    UportDIDResolver(registry || UportLite({ networks: networks ? configNetworks(networks) : {} }))
    EthrDIDResolver(ethrConfig || {})
    HttpsDIDResolver()
  }
github uport-project / uport-credentials / src / Credentials.js View on Github external
static createIdentity() {
    const kp = secp256k1.genKeyPair()
    const publicKey = kp.getPublic('hex')
    const privateKey = kp.getPrivate('hex')
    const address = toEthereumAddress(publicKey)
    const did = `did:ethr:${address}`
    return { did, privateKey }
  }

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

80 / 100
Full package analysis

Similar packages