@@ -3,7 +3,8 @@ package io.iohk.ethereum.network.discovery.codecs
3
3
import org .scalatest .matchers .should .Matchers
4
4
import org .scalatest .flatspec .AnyFlatSpec
5
5
import io .iohk .scalanet .discovery .ethereum .{Node , EthereumNodeRecord }
6
- import io .iohk .scalanet .discovery .crypto .{SigAlg , PrivateKey , PublicKey }
6
+ import io .iohk .scalanet .discovery .crypto .{SigAlg , PrivateKey }
7
+ import io .iohk .scalanet .discovery .hash .{Hash , Keccak256 }
7
8
import io .iohk .ethereum .network .discovery .crypto .Secp256k1SigAlg
8
9
import io .iohk .ethereum .rlp
9
10
import io .iohk .ethereum .rlp .{RLPList , RLPEncoder }
@@ -25,8 +26,9 @@ class ENRCodecsSpec extends AnyFlatSpec with Matchers {
25
26
behavior of " RLPCodecs with ENR"
26
27
27
28
// https://github.com/ethereum/devp2p/blob/master/enr.md#test-vectors
28
- val nodeId = hex " a448f24c6d18e575453db13171562b71999873db5b286df957af199ec94617f7 "
29
- val privateKey = hex " b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291 "
29
+ val nodeId = Hash (hex " a448f24c6d18e575453db13171562b71999873db5b286df957af199ec94617f7 " .toBitVector)
30
+ val privateKey = PrivateKey (hex " b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291 " .toBitVector)
31
+ val publicKey = sigalg.toPublicKey(privateKey)
30
32
val enrString =
31
33
" enr:-IS4QHCYrYZbAKWCBRlAy5zzaDZXJBGkcnh4MHcBFZntXNFrdvJjX04jRzjzCBOonrkTfj499SZuOh8R33Ls8RRcy5wBgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQPKY0yuDUmstAHYpMa2_oxVtw0RW_QAdpzBQA8yWM0xOIN1ZHCCdl8"
32
34
@@ -54,11 +56,11 @@ class ENRCodecsSpec extends AnyFlatSpec with Matchers {
54
56
// Construct a Node which should give us the same results.
55
57
// Unfortunately there's no option to omit the TCP port from it :(
56
58
val node = Node (
57
- id = PublicKey (nodeId.toBitVector) ,
59
+ id = publicKey ,
58
60
address = Node .Address (localhost, udpPort = 30303 , tcpPort = 0 )
59
61
)
60
62
61
- val enr = EthereumNodeRecord .fromNode(node, PrivateKey ( privateKey.toBitVector) , seq = 1 ).require
63
+ val enr = EthereumNodeRecord .fromNode(node, privateKey, seq = 1 ).require
62
64
63
65
val rlpStructureFromNode = RLPEncoder .encode(enr)
64
66
@@ -117,8 +119,14 @@ class ENRCodecsSpec extends AnyFlatSpec with Matchers {
117
119
}
118
120
119
121
it should " verify the signature of the example ENR" in {
120
- val publicKey = sigalg.toPublicKey(PrivateKey ( privateKey.toBitVector) )
122
+ val publicKey = sigalg.toPublicKey(privateKey)
121
123
val enr = RLPDecoder .decode[EthereumNodeRecord ](enrRLP)
122
124
EthereumNodeRecord .validateSignature(enr, publicKey).require shouldBe true
123
125
}
126
+
127
+ it should " verify that the node ID in the example is the hash of the public key" in {
128
+ // This is what we use in Kademlia, but the node ID in the wire protocol
129
+ // should be the 64 byte public key, at least I thought so based on the spec.
130
+ Keccak256 (publicKey) shouldBe nodeId
131
+ }
124
132
}
0 commit comments