nomos-specs/mixnet/test_utils.py

36 lines
1006 B
Python
Raw Normal View History

from cryptography.hazmat.primitives.asymmetric.x25519 import X25519PrivateKey
from mixnet.config import (
2024-06-27 17:32:22 +09:00
GlobalConfig,
2024-06-26 15:55:00 +09:00
MixMembership,
NodeConfig,
NodeInfo,
)
2024-01-25 18:04:55 +09:00
def init_mixnet_config(
num_nodes: int,
) -> tuple[GlobalConfig, list[NodeConfig], dict[bytes, X25519PrivateKey]]:
2024-06-26 15:55:00 +09:00
transmission_rate_per_sec = 3
2024-06-28 12:26:44 +09:00
peering_degree = 6
2024-06-27 17:32:22 +09:00
max_mix_path_length = 3
2024-06-26 15:55:00 +09:00
node_configs = [
2024-06-28 12:26:44 +09:00
NodeConfig(X25519PrivateKey.generate(), peering_degree, max_mix_path_length)
2024-06-26 15:55:00 +09:00
for _ in range(num_nodes)
]
2024-06-27 17:32:22 +09:00
global_config = GlobalConfig(
MixMembership(
[
NodeInfo(node_config.private_key.public_key())
for node_config in node_configs
]
2024-06-27 17:32:22 +09:00
),
transmission_rate_per_sec,
max_mix_path_length,
)
key_map = {
node_config.private_key.public_key().public_bytes_raw(): node_config.private_key
for node_config in node_configs
}
return (global_config, node_configs, key_map)