|
33 | 33 | import tempfile |
34 | 34 | import urllib.request |
35 | 35 | from concurrent.futures import ProcessPoolExecutor |
36 | | -from dataclasses import dataclass |
37 | 36 | from functools import cache, partial |
38 | 37 | from pathlib import Path |
39 | | -from typing import TYPE_CHECKING, Iterator, Self |
| 38 | +from typing import TYPE_CHECKING, Iterator |
40 | 39 |
|
41 | 40 | from lean_spec.config import LEAN_ENV |
42 | 41 | from lean_spec.subspecs.containers import AttestationData |
|
46 | 45 | AttestationSignatures, |
47 | 46 | ) |
48 | 47 | from lean_spec.subspecs.containers.slot import Slot |
49 | | -from lean_spec.subspecs.xmss.containers import PublicKey, SecretKey, Signature |
| 48 | +from lean_spec.subspecs.xmss.containers import KeyPair, PublicKey, Signature |
50 | 49 | from lean_spec.subspecs.xmss.interface import ( |
51 | 50 | PROD_SIGNATURE_SCHEME, |
52 | 51 | TEST_SIGNATURE_SCHEME, |
@@ -120,39 +119,6 @@ def get_shared_key_manager(max_slot: Slot = _DEFAULT_MAX_SLOT) -> XmssKeyManager |
120 | 119 | """Key lifetime in epochs (derived from DEFAULT_MAX_SLOT).""" |
121 | 120 |
|
122 | 121 |
|
123 | | -@dataclass(frozen=True, slots=True) |
124 | | -class KeyPair: |
125 | | - """ |
126 | | - Immutable XMSS key pair for a validator. |
127 | | -
|
128 | | - Attributes: |
129 | | - public: Public key for signature verification. |
130 | | - secret: Secret key containing Merkle tree structures. |
131 | | - """ |
132 | | - |
133 | | - public: PublicKey |
134 | | - secret: SecretKey |
135 | | - |
136 | | - @classmethod |
137 | | - def from_dict(cls, data: Mapping[str, str]) -> Self: |
138 | | - """Deserialize from JSON-compatible dict with hex-encoded SSZ.""" |
139 | | - return cls( |
140 | | - public=PublicKey.decode_bytes(bytes.fromhex(data["public"])), |
141 | | - secret=SecretKey.decode_bytes(bytes.fromhex(data["secret"])), |
142 | | - ) |
143 | | - |
144 | | - def to_dict(self) -> dict[str, str]: |
145 | | - """Serialize to JSON-compatible dict with hex-encoded SSZ.""" |
146 | | - return { |
147 | | - "public": self.public.encode_bytes().hex(), |
148 | | - "secret": self.secret.encode_bytes().hex(), |
149 | | - } |
150 | | - |
151 | | - def with_secret(self, secret: SecretKey) -> KeyPair: |
152 | | - """Return a new KeyPair with updated secret key (for state advancement).""" |
153 | | - return KeyPair(public=self.public, secret=secret) |
154 | | - |
155 | | - |
156 | 122 | def _get_keys_dir(scheme_name: str) -> Path: |
157 | 123 | """Get the keys directory path for the given scheme.""" |
158 | 124 | return Path(__file__).parent / "test_keys" / f"{scheme_name}_scheme" |
@@ -298,7 +264,7 @@ def sign_attestation_data( |
298 | 264 | prepared = self.scheme.get_prepared_interval(sk) |
299 | 265 |
|
300 | 266 | # Cache advanced state |
301 | | - self._state[validator_id] = kp.with_secret(sk) |
| 267 | + self._state[validator_id] = kp._replace(secret=sk) |
302 | 268 |
|
303 | 269 | # Sign hash tree root of the attestation data |
304 | 270 | message = attestation_data.data_root_bytes() |
|
0 commit comments