Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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()
})
})
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())
})
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)
}
}