How to use the libp2p-interfaces/src/crypto/errors.InvalidCryptoExchangeError function in libp2p-interfaces

To help you get started, we’ve selected a few libp2p-interfaces 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 libp2p / js-libp2p / src / insecure / plaintext.js View on Github external

  log('write pubkey exchange to peer %j', remoteId)

  // Get the Exchange message
  const response = (await lp.decode.fromReader(shake.reader).next()).value
  const id = Exchange.decode(response.slice())
  log('read pubkey exchange from peer %j', remoteId)

  let peerId
  try {
    peerId = await PeerId.createFromPubKey(id.pubkey.Data)
  } catch (err) {
    throw new InvalidCryptoExchangeError('Remote did not provide its public key')

  if (remoteId && !peerId.isEqual(remoteId)) {
    throw new UnexpectedPeerError()

  log('plaintext key exchange completed successfully with peer %j', peerId)
  return {
    remotePeer: peerId