def create_auth_message(remote_pubkey, ephemeral_privkey=nil, nonce=nil)
      raise RLPxSessionError, 'must be initiator' unless initiator?
      raise InvalidKeyError, 'invalid remote pubkey' unless Crypto::ECCx.valid_key?(remote_pubkey)

      @remote_pubkey = remote_pubkey

      token = @ecc.get_ecdh_key remote_pubkey
      flag = 0x0

      @initiator_nonce = nonce || Crypto.keccak256(Utils.int_to_big_endian(SecureRandom.random_number(TT256)))
      raise RLPxSessionError, 'invalid nonce length' unless @initiator_nonce.size == 32

      token_xor_nonce = Utils.sxor token, @initiator_nonce
      raise RLPxSessionError, 'invalid token xor nonce length' unless token_xor_nonce.size == 32

      ephemeral_pubkey = @ephemeral_ecc.raw_pubkey
      raise InvalidKeyError, 'invalid ephemeral pubkey' unless ephemeral_pubkey.size == 512 / 8 && Crypto::ECCx.valid_key?(ephemeral_pubkey)

      sig = @ephemeral_ecc.sign token_xor_nonce
      raise RLPxSessionError, 'invalid signature' unless sig.size == 65

      auth_message = "#{sig}#{Crypto.keccak256(ephemeral_pubkey)}#{@ecc.raw_pubkey}#{@initiator_nonce}#{flag.chr}"
      raise RLPxSessionError, 'invalid auth message length' unless auth_message.size == 194

      auth_message
    end
def create_auth_message(remote_pubkey, ephemeral_privkey=nil, nonce=nil)
      raise RLPxSessionError, 'must be initiator' unless initiator?
      raise InvalidKeyError, 'invalid remote pubkey' unless Crypto::ECCx.valid_key?(remote_pubkey)

      @remote_pubkey = remote_pubkey

      token = @ecc.get_ecdh_key remote_pubkey
      flag = 0x0

      @initiator_nonce = nonce || Crypto.keccak256(Utils.int_to_big_endian(SecureRandom.random_number(TT256)))
      raise RLPxSessionError, 'invalid nonce length' unless @initiator_nonce.size == 32

      token_xor_nonce = Utils.sxor token, @initiator_nonce
      raise RLPxSessionError, 'invalid token xor nonce length' unless token_xor_nonce.size == 32

      ephemeral_pubkey = @ephemeral_ecc.raw_pubkey
      raise InvalidKeyError, 'invalid ephemeral pubkey' unless ephemeral_pubkey.size == 512 / 8 && Crypto::ECCx.valid_key?(ephemeral_pubkey)

      sig = @ephemeral_ecc.sign token_xor_nonce
      raise RLPxSessionError, 'invalid signature' unless sig.size == 65

      auth_message = "#{sig}#{Crypto.keccak256(ephemeral_pubkey)}#{@ecc.raw_pubkey}#{@initiator_nonce}#{flag.chr}"
      raise RLPxSessionError, 'invalid auth message length' unless auth_message.size == 194

      auth_message
    end
Handshake Auth Message Handling

 1. initiator generates ecdhe-random and nonce and creates auth
 2. initiator connects to remote and sends auth

 New:

   E(remote-pubk,
     S(ephemeral-privk, ecdh-shared-secret ^ nonce) ||
     H(ephemeral-pubk) || pubk || nonce || 0x0
   )

 Known:

   E(remote-pubk,
     S(ephemeral-privk, token ^ nonce) ||
     H(ephemeral-pubk) || pubk || nonce || 0x1
   )