2024-01-25 09:04:55 +00:00
|
|
|
import asyncio
|
|
|
|
|
2024-02-05 08:04:02 +00:00
|
|
|
from cryptography.hazmat.primitives.asymmetric.x25519 import X25519PrivateKey
|
|
|
|
|
|
|
|
from mixnet.bls import generate_bls
|
2024-02-08 06:39:50 +00:00
|
|
|
from mixnet.config import (
|
|
|
|
MixClientConfig,
|
|
|
|
MixNodeConfig,
|
|
|
|
MixnetConfig,
|
|
|
|
MixNodeInfo,
|
|
|
|
MixnetTopology,
|
|
|
|
MixnetTopologyConfig,
|
|
|
|
MixnetTopologySize,
|
|
|
|
)
|
2024-02-05 08:04:02 +00:00
|
|
|
from mixnet.utils import random_bytes
|
|
|
|
|
2024-01-25 09:04:55 +00:00
|
|
|
|
|
|
|
def with_test_timeout(t):
|
|
|
|
def wrapper(coroutine):
|
|
|
|
async def run(*args, **kwargs):
|
|
|
|
async with asyncio.timeout(t):
|
|
|
|
return await coroutine(*args, **kwargs)
|
|
|
|
|
|
|
|
return run
|
|
|
|
|
|
|
|
return wrapper
|
2024-02-05 08:04:02 +00:00
|
|
|
|
|
|
|
|
2024-02-08 06:39:50 +00:00
|
|
|
def init_mixnet_config() -> MixnetConfig:
|
|
|
|
topology_config = MixnetTopologyConfig(
|
|
|
|
[
|
|
|
|
MixNodeInfo(
|
|
|
|
generate_bls(),
|
|
|
|
X25519PrivateKey.generate(),
|
|
|
|
random_bytes(32),
|
|
|
|
)
|
|
|
|
for _ in range(12)
|
|
|
|
],
|
|
|
|
MixnetTopologySize(3, 3),
|
|
|
|
b"entropy",
|
2024-02-05 08:04:02 +00:00
|
|
|
)
|
2024-02-08 06:39:50 +00:00
|
|
|
mixclient_config = MixClientConfig(30, 3, MixnetTopology(topology_config))
|
|
|
|
mixnode_config = MixNodeConfig(
|
|
|
|
topology_config.mixnode_candidates[0].encryption_private_key, 30
|
2024-02-05 08:04:02 +00:00
|
|
|
)
|
2024-02-08 06:39:50 +00:00
|
|
|
return MixnetConfig(topology_config, mixclient_config, mixnode_config)
|