secp256k1 Python

Searchโฆ

Representing a point

We call a **.**

`Point`

an element of the elliptic curve group, which we can represent with its coordinates. Let's define a `Point`

class to encapsulate the $x$

and $y$

coordinates in the generalised curve equation of $y^2 = x^3 + ax + b$

@dataclass

class Point:

x: int

y: int

โ

curve: EllipticCurve

โ

def __post_init__(self):

# Ignore validation for I

if self.x is None and self.y is None:

return

โ

# Encapsulate int coordinates in FieldElement

self.x = FieldElement(self.x, self.curve.field)

self.y = FieldElement(self.y, self.curve.field)

โ

# Verify if the point satisfies the curve equation

if self not in self.curve:

raise ValueError

`x `

coordinate. It is then possible to reconstruct the `y`

by calculating `sign * sqrt(x^3+a*x+b).`

Last modified 2yr ago

Copy link