How to use the libp2p-crypto/src/keys/rsa-utils.pkixToJwk function in libp2p-crypto

To help you get started, we’ve selected a few libp2p-crypto 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 richardschneider / ipfs-encryption / test / peerid.js View on Github external
it('encoded public key with DER', (done) => {
    const jwk = rsaUtils.pkixToJwk(publicKeyDer)
    // console.log('jwk', jwk)
    const rsa = new rsaClass.RsaPublicKey(jwk)
    // console.log('rsa', rsa)
    rsa.hash((err, keyId) => {
      // console.log('err', err)
      // console.log('keyId', keyId)
      // console.log('id decoded', multihash.decode(keyId))
      const kids = multihash.toB58String(keyId)
      // console.log('id', kids)
      expect(kids).to.equal(peer.toB58String())
      done()
    })
  })
github libp2p / js-libp2p-keychain / test / peerid.js View on Github external
it('encoded public key with DER', async () => {
    const jwk = rsaUtils.pkixToJwk(publicKeyDer)
    const rsa = new rsaClass.RsaPublicKey(jwk)
    const keyId = await promisify(rsa.hash, {
      context: rsa
    })()
    const kids = multihash.toB58String(keyId)
    expect(kids).to.equal(peer.toB58String())
  })
github richardschneider / ipfs-encryption / src / util.js View on Github external
exports.keyId = (privateKey, callback) => {
  try {
    const publicKey = pki.setRsaPublicKey(privateKey.n, privateKey.e)
    const spki = pki.publicKeyToSubjectPublicKeyInfo(publicKey)
    const der = new Buffer(forge.asn1.toDer(spki).getBytes(), 'binary')
    const jwk = rsaUtils.pkixToJwk(der)
    const rsa = new rsaClass.RsaPublicKey(jwk)
    rsa.hash((err, kid) => {
      if (err) return callback(err)

      const kids = multihash.toB58String(kid)
      return callback(null, kids)
    })
  } catch (err) {
    callback(err)
  }
}