Switch curve_name from string to NamedTuple
py_ecc/fields/__init__.py has a lot of duplications and is at high risk of typos (like importing the coeffs or field modulus from the wrong curve).
Let's think about alternatives to this setup. Maybe something like:
class Curve(NamedTuple):
field_modulus: int
fq12_modulus_coeffs: Tuple[int, ...]
fq2_modulus_coeffs: Tuple[int, int]
bls12_381 = Curve(
field_modulus = 21888242871839275222246405745257275088696311157297823662689037894645226208583,
fq2_modulus_coeffs = (1, 0),
fq12_modulus_coeffs = (2, 0, 0, 0, 0, 0, -2, 0, 0, 0, 0, 0), # Implied + [1]
)
^ This still doesn't feel quite right, but it's a starting point.
The end goal is to be able to create bn128_FQ2 with a reference to a single thing (like this new NamedTuple)
Of course, this approach comes at the downside of having to import the curve to create an FQ. Maybe a little more annoying at the REPL. But for the caller in a file, it means fewer magic strings and less likelihood for a typo with a confusing error. For the library, hopefully better readability.
_Originally posted by @carver in https://github.com/render_node/MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI0OTIyNTg5NQ==/comments/review_comment
This would happen in the second phase of the ~refactoring~ upgrading process where, even the curves would be generalized and all their properties would be encapsulated as a NamedTuple.