@Override
  public ByteBuf firstMessage() throws HandshakeException {
    checkState(initiator, "illegal invocation of firstMessage on non-initiator end of handshake");
    checkState(
        status.compareAndSet(
            Handshaker.HandshakeStatus.PREPARED, Handshaker.HandshakeStatus.IN_PROGRESS),
        "illegal invocation of firstMessage, handshake had already started");

    final Bytes32 staticSharedSecret = nodeKey.calculateECDHKeyAgreement(partyPubKey);
    if (version4) {
      initiatorMsg =
          InitiatorHandshakeMessageV4.create(
              nodeKey.getPublicKey(), ephKeyPair, staticSharedSecret, initiatorNonce);
    } else {
      initiatorMsg =
          InitiatorHandshakeMessageV1.create(
              nodeKey.getPublicKey(), ephKeyPair, staticSharedSecret, initiatorNonce, false);
    }
    try {
      if (version4) {
        initiatorMsgEnc = EncryptedMessage.encryptMsgEip8(initiatorMsg.encode(), partyPubKey);
      } else {
        initiatorMsgEnc = EncryptedMessage.encryptMsg(initiatorMsg.encode(), partyPubKey);
      }
    } catch (final InvalidCipherTextException e) {
      status.set(Handshaker.HandshakeStatus.FAILED);
      throw new HandshakeException("Encrypting the first handshake message failed", e);
    }

    LOG.trace("First ECIES handshake message under INITIATOR role: {}", initiatorMsg);

    return Unpooled.wrappedBuffer(initiatorMsgEnc.toArray());
  }
An Elliptic Curve Integrated Encryption Scheme implementation, following the handshake ceremony
of Ethereum.

@see <a href="https://github.com/ethereum/devp2p/blob/master/rlpx.md#encrypted-handshake">RLPx
    encrypted handshake</a>
ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/handshake/ecies/ECIESHandshaker.java