Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async _putRecordToRouting (record, peerId) {
if (!(PeerId.isPeerId(peerId))) {
const errMsg = 'peerId received is not valid'
log.error(errMsg)
throw errcode(new Error(errMsg), 'ERR_INVALID_PEER_ID')
}
const publicKey = peerId._pubKey
const embedPublicKeyRecord = await ipns.embedPublicKey(publicKey, record)
const keys = ipns.getIdKeys(peerId.toBytes())
await this._publishEntry(keys.routingKey, embedPublicKeyRecord || record, peerId)
// Publish the public key to support old go-ipfs nodes that are looking for it in the routing
// We will be able to deprecate this part in the future, since the public keys will be only
// in IPNS record and the peerId.
await this._publishPublicKey(keys.routingPubKey, publicKey)
return embedPublicKeyRecord || record
}