Esempio n. 1
0
def new_enr_manager():
    enr_db = QueryableENRDB(sqlite3.connect(":memory:"))
    private_key = PrivateKeyFactory()
    base_enr = ENRFactory(
        private_key=private_key.to_bytes(),
        sequence_number=secrets.randbelow(100) + 1,
    )
    enr_db.set_enr(base_enr)
    return ENRManager(private_key, enr_db)
Esempio n. 2
0
 def node(
     self,
     private_key: Optional[keys.PrivateKey] = None,
     endpoint: Optional[Endpoint] = None,
     enr_db: Optional[ENRDatabaseAPI] = None,
     events: Optional[EventsAPI] = None,
 ) -> Node:
     if private_key is None:
         private_key = PrivateKeyFactory()
     if endpoint is None:
         endpoint = EndpointFactory.localhost()
     if enr_db is None:
         enr_db = ENRDB({})
     return Node(private_key=private_key,
                 endpoint=endpoint,
                 enr_db=enr_db,
                 events=events)
Esempio n. 3
0
 def node(
     self,
     private_key: Optional[keys.PrivateKey] = None,
     endpoint: Optional[Endpoint] = None,
     enr_db: Optional[QueryableENRDatabaseAPI] = None,
     events: Optional[EventsAPI] = None,
     name: Optional[str] = None,
 ) -> Node:
     if private_key is None:
         private_key = PrivateKeyFactory()
     if endpoint is None:
         endpoint = EndpointFactory.localhost()
     if enr_db is None:
         enr_db = QueryableENRDB(sqlite3.connect(":memory:"))
     node = Node(private_key=private_key,
                 endpoint=endpoint,
                 enr_db=enr_db,
                 events=events)
     self.logger.info("Tester[Node]: name=%s  node_id=%s", name,
                      node.node_id.hex())
     return node
Esempio n. 4
0
def test_advertisement_creation():
    private_key = PrivateKeyFactory()
    content_key = b"\x01testkey"
    hash_tree_root = b"\x12" * 32
    ad = Advertisement.create(content_key, hash_tree_root, private_key)

    assert ad.content_id == content_key_to_content_id(content_key)

    signature = ad.signature

    assert signature.v == ad.signature_v
    assert signature.r == ad.signature_r
    assert signature.s == ad.signature_s

    assert ad.public_key == private_key.public_key

    assert ad.is_valid
    ad.verify()

    expected_node_id = keccak(private_key.public_key.to_bytes())
    assert ad.node_id == expected_node_id
Esempio n. 5
0
def remote_private_key():
    return PrivateKeyFactory().to_bytes()