<p>This RFC describes the usage of the ENR (Ethereum Node Records) format for <ahref="/specs/10">10/WAKU2</a> purposes.
The ENR format is defined in <ahref="https://eips.ethereum.org/EIPS/eip-778">EIP-778</a><ahref="#references">[3]</a>.</p>
<p>This RFC is an extension of EIP-778, ENR used in Waku v2 MUST adhere to both EIP-778 and 31/WAKU2-ENR.</p>
<h1id="motivation">
Motivation
<aclass="anchor"href="#motivation">#</a>
</h1>
<p>EIP-1459 with the usage of ENR has been implemented <ahref="#references">[1]</a><ahref="#references">[2]</a> as a discovery protocol for Waku v2.</p>
<p>EIP-778 specifies a number of pre-defined keys.
However, the usage of these keys alone does not allow for certain transport capabilities to be encoded,
such as Websocket.
Currently, Waku v2 nodes running in a Browser only support websocket transport protocol.
Hence, new ENR keys need to be defined to allow for the encoding of transport protocol other than raw TCP.</p>
SSL certificates are only valid for a given domain and ip, so an ENR containing the following information:</p>
<ul>
<li>secure websocket port</li>
<li>ipv4 fqdn</li>
<li>ipv4 address</li>
<li>ipv6 address</li>
</ul>
<p>Would carry some ambiguity: Is the certificate securing the websocket port valid for the ipv4 fqdn?
the ipv4 address?
the ipv6 address?</p>
<p>The <ahref="/specs/10">10/WAKU2</a> protocol family is built on the <ahref="https://github.com/libp2p/specs">libp2p</a> protocol stack.
Hence, it uses <ahref="https://github.com/multiformats/multiaddr">multiaddr</a> to format network addresses.</p>
<p>Directly storing one or several multiaddresses in the ENR would fix the issues listed above:</p>
<ul>
<li>multiaddr is self-describing and support addresses for any network protocol:
No new RFC would be needed to support encoding other transport protocols in an ENR.</li>
<li>multiaddr contains both the host and port information, allowing the ambiguity previously described to be resolved.</li>
</ul>
<h1id="multiaddrs-enr-key">
<code>multiaddrs</code> ENR key
<aclass="anchor"href="#multiaddrs-enr-key">#</a>
</h1>
<p>We define a <code>multiaddrs</code> key.</p>
<ul>
<li>The value MUST be a list of binary encoded multiaddr prefixed by their size.</li>
<li>The size of the multiaddr MUST be encoded in a Big Endian unsigned 16-bit integer.</li>
<li>The size of the multiaddr MUST be encoded in 2 bytes.</li>
<li>The <code>secp256k1</code> value MUST be present on the record;
<code>secp256k1</code> is defined in <ahref="https://eips.ethereum.org/EIPS/eip-778">EIP-778</a> and contains the compressed secp256k1 public key.</li>
<li>The node’s peer id SHOULD be deduced from the <code>secp256k1</code> value.</li>
<li>The multiaddresses SHOULD NOT contain a peer id.</li>
<li>For raw TCP & UDP connections details, <ahref="https://eips.ethereum.org/EIPS/eip-778">EIP-778</a> pre-defined keys SHOULD be used;
The keys <code>tcp</code>, <code>udp</code>, <code>ip</code> (and <code>tcp6</code>, <code>udp6</code>, <code>ip6</code> for IPv6) are enough to convey all necessary information;</li>
<li>To save space, <code>multiaddrs</code> key SHOULD only be used for connection details that cannot be represented using the <ahref="https://eips.ethereum.org/EIPS/eip-778">EIP-778</a> pre-defined keys.</li>
<li>The 300 bytes size limit as defined by <ahref="https://eips.ethereum.org/EIPS/eip-778">EIP-778</a> still applies;
In practice, it is possible to encode 3 multiaddresses in ENR, more or less could be encoded depending on the size of each multiaddress.</li>
<p>Alice is a node operator, she runs a node that supports inbound connection for the following protocols:</p>
<ul>
<li>TCP 10101 on <code>1.2.3.4</code></li>
<li>UDP 20202 on <code>1.2.3.4</code></li>
<li>TCP 30303 on <code>1234:5600:101:1::142</code></li>
<li>UDP 40404 on <code>1234:5600:101:1::142</code></li>
<li>Secure Websocket on <code>wss://example.com:443/</code></li>
<li>QUIC on <code>quic://quic.example.com:443/</code></li>
</ul>
<p>Alice SHOULD structure the ENR for her node as follows:</p>
<table>
<thead>
<tr>
<th>key</th>
<th>value</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>tcp</code></td>
<td><code>10101</code></td>
</tr>
<tr>
<td><code>udp</code></td>
<td><code>20202</code></td>
</tr>
<tr>
<td><code>tcp6</code></td>
<td><code>30303</code></td>
</tr>
<tr>
<td><code>udp6</code></td>
<td><code>40404</code></td>
</tr>
<tr>
<td><code>ip</code></td>
<td><code>1.2.3.4</code></td>
</tr>
<tr>
<td><code>ip6</code></td>
<td><code>1234:5600:101:1::142</code></td>
</tr>
<tr>
<td><code>secp256k1</code></td>
<td>Alice’s compressed secp256k1 public key, 33 bytes</td>
</tr>
<tr>
<td><code>multiaddrs</code></td>
<td><!-- raw HTML omitted -->len1 | /dns4/example.com/tcp/443/wss | len2 | /dns4/quic.examle.com/tcp/443/quic<!-- raw HTML omitted --></td>
</tr>
</tbody>
</table>
<p>Where:</p>
<ul>
<li><code>|</code> is the concatenation operator,</li>
<li><code>len1</code> is the length of <code>/dns4/example.com/tcp/443/wss</code> byte representation,</li>
<li><code>len2</code> is the length of <code>/dns4/quic.examle.com/tcp/443/quic</code> byte representation.</li>
</ul>
<h3id="raw-tcp-only">
Raw TCP only
<aclass="anchor"href="#raw-tcp-only">#</a>
</h3>
<p>Bob is a node operator, he runs a node that supports inbound connection for the following protocols:</p>
<ul>
<li>TCP 10101 on <code>1.2.3.4</code></li>
</ul>
<p>Bob SHOULD structure the ENR for her node as follows:</p>
<table>
<thead>
<tr>
<th>key</th>
<th>value</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>tcp</code></td>
<td><code>10101</code></td>
</tr>
<tr>
<td><code>ip</code></td>
<td><code>1.2.3.4</code></td>
</tr>
<tr>
<td><code>secp256k1</code></td>
<td>Bob’s compressed secp256k1 public key, 33 bytes</td>
</tr>
</tbody>
</table>
<p>Indeed, as Bob’s node’s connection details can be represented with EIP-778’s pre-defined keys only
then it is not needed to use the <code>multiaddrs</code> key.</p>
<h2id="limitations">
Limitations
<aclass="anchor"href="#limitations">#</a>
</h2>
<p>Supported key type is <code>secp256k1</code> only.</p>
<p>In the future, an extension of this RFC could be made to support other elliptic curve cryptography such as <code>ed25519</code>.</p>
<h1id="waku2-enr-key">
<code>waku2</code> ENR key
<aclass="anchor"href="#waku2-enr-key">#</a>
</h1>
<p>We define a <code>waku2</code> field key:</p>
<ul>
<li>The value MUST be an 8-bit flag field,
where bits set to <code>1</code> indicate <code>true</code> and bits set to <code>0</code> indicate <code>false</code> for the relevant flags.</li>
<li>The flag values already defined are set out below,
with <code>bit 7</code> the most significant bit and <code>bit 0</code> the least significant bit.</li>
</ul>
<table>
<thead>
<tr>
<th>bit 7</th>
<th>bit 6</th>
<th>bit 5</th>
<th>bit 4</th>
<th>bit 3</th>
<th>bit 2</th>
<th>bit 1</th>
<th>bit 0</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>undef</code></td>
<td><code>undef</code></td>
<td><code>undef</code></td>
<td><code>undef</code></td>
<td><code>lightpush</code></td>
<td><code>filter</code></td>
<td><code>store</code></td>
<td><code>relay</code></td>
</tr>
</tbody>
</table>
<ul>
<li>In the scheme above, the flags <code>lightpush</code>, <code>filter</code>, <code>store</code> and <code>relay</code> correlates with support for protocols with the same name.
If a protocol is not supported, the corresponding field MUST be set to <code>false</code>.
Indicating positive support for any specific protocol is OPTIONAL,
though it MAY be required by the relevant application or discovery process.</li>
<li>Flags marked as <code>undef</code> is not yet defined.
These SHOULD be set to <code>false</code> by default.</li>
</ul>
<h2id="usage-1">
Usage
<aclass="anchor"href="#usage-1">#</a>
</h2>
<ul>
<li>A Waku v2 node MAY choose to populate the <code>waku2</code> field for enhanced discovery capabilities,
such as indicating supported protocols.
Such a node MAY indicate support for any specific protocol by setting the corresponding flag to <code>true</code>.</li>
<li>Waku v2 nodes that want to participate in <ahref="https://github.com/ethereum/devp2p/blob/master/discv5/discv5.md">Node Discovery Protocol v5</a><ahref="#references">[4]</a>, however,
MUST implement the <code>waku2</code> key with at least one flag set to <code>true</code>.</li>
<li>Waku v2 nodes that discovered other participants using Discovery v5,
MUST filter out participant records that do not implement this field or do not have at least one flag set to <code>true</code>.</li>
<li>In addition, such nodes MAY choose to filter participants on specific flags (such as supported protocols),
or further interpret the <code>waku2</code> field as required by the application.</li>
</ul>
<h1id="copyright">
Copyright
<aclass="anchor"href="#copyright">#</a>
</h1>
<p>Copyright and related rights waived via <ahref="https://creativecommons.org/publicdomain/zero/1.0/">CC0</a>.</p>