Skip to content

models

FQ2_Point

Bases: BaseModel

Source code in src/payment/crypto/models.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
class FQ2_Point(BaseModel):
    model_config = ConfigDict(frozen=True)

    c0: int
    c1: int

    @staticmethod
    def from_fq2(point: FQ2) -> "FQ2_Point":
        """Convert a py_ecc FQ2 element to serializable form.

        Args:
            point: FQ2 element from py_ecc.

        Returns:
            FQ2_Point with integer coefficients.
        """
        return FQ2_Point(c0=point.coeffs[0], c1=point.coeffs[1])

    def to_fq2(self) -> FQ2:
        """Convert back to a py_ecc FQ2 element.

        Returns:
            FQ2 element for use with py_ecc.
        """
        return FQ2((self.c0, self.c1))

from_fq2(point) staticmethod

Convert a py_ecc FQ2 element to serializable form.

Parameters:

Name Type Description Default
point FQ2

FQ2 element from py_ecc.

required

Returns:

Type Description
FQ2_Point

FQ2_Point with integer coefficients.

Source code in src/payment/crypto/models.py
39
40
41
42
43
44
45
46
47
48
49
@staticmethod
def from_fq2(point: FQ2) -> "FQ2_Point":
    """Convert a py_ecc FQ2 element to serializable form.

    Args:
        point: FQ2 element from py_ecc.

    Returns:
        FQ2_Point with integer coefficients.
    """
    return FQ2_Point(c0=point.coeffs[0], c1=point.coeffs[1])

to_fq2()

Convert back to a py_ecc FQ2 element.

Returns:

Type Description
FQ2

FQ2 element for use with py_ecc.

Source code in src/payment/crypto/models.py
51
52
53
54
55
56
57
def to_fq2(self) -> FQ2:
    """Convert back to a py_ecc FQ2 element.

    Returns:
        FQ2 element for use with py_ecc.
    """
    return FQ2((self.c0, self.c1))

G1_Point

Bases: BaseModel

Source code in src/payment/crypto/models.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class G1_Point(BaseModel):
    model_config = ConfigDict(frozen=True)
    x: int
    y: int

    @staticmethod
    def from_g1(point: Optimized_Point3D[Optimized_Field]) -> "G1_Point":
        """Convert a projective py_ecc G1 point to affine representation.

        Args:
            point: Projective G1 point from py_ecc.

        Returns:
            Affine G1_Point.
        """
        x, y = normalize(point)
        return G1_Point(x=x.n, y=y.n)

    def to_g1(self) -> Optimized_Point3D[Optimized_Field]:
        """Convert back to a projective py_ecc G1 point.

        Returns:
            Projective G1 point for use with py_ecc.
        """
        return (FQ(self.x), FQ(self.y), FQ.one())

from_g1(point) staticmethod

Convert a projective py_ecc G1 point to affine representation.

Parameters:

Name Type Description Default
point Optimized_Point3D[Optimized_Field]

Projective G1 point from py_ecc.

required

Returns:

Type Description
G1_Point

Affine G1_Point.

Source code in src/payment/crypto/models.py
11
12
13
14
15
16
17
18
19
20
21
22
@staticmethod
def from_g1(point: Optimized_Point3D[Optimized_Field]) -> "G1_Point":
    """Convert a projective py_ecc G1 point to affine representation.

    Args:
        point: Projective G1 point from py_ecc.

    Returns:
        Affine G1_Point.
    """
    x, y = normalize(point)
    return G1_Point(x=x.n, y=y.n)

to_g1()

Convert back to a projective py_ecc G1 point.

Returns:

Type Description
Optimized_Point3D[Optimized_Field]

Projective G1 point for use with py_ecc.

Source code in src/payment/crypto/models.py
24
25
26
27
28
29
30
def to_g1(self) -> Optimized_Point3D[Optimized_Field]:
    """Convert back to a projective py_ecc G1 point.

    Returns:
        Projective G1 point for use with py_ecc.
    """
    return (FQ(self.x), FQ(self.y), FQ.one())

G2_Point

Bases: BaseModel

Source code in src/payment/crypto/models.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
class G2_Point(BaseModel):
    model_config = ConfigDict(frozen=True)

    x: FQ2_Point
    y: FQ2_Point

    @staticmethod
    def from_g2(point: Optimized_Point3D[Optimized_Field]) -> "G2_Point":
        """Convert a projective py_ecc G2 point to affine representation.

        Args:
            point: Projective G2 point from py_ecc.

        Returns:
            Affine G2_Point.
        """
        x, y = normalize(point)
        return G2_Point(x=FQ2_Point.from_fq2(x), y=FQ2_Point.from_fq2(y))

    def to_g2(self) -> Optimized_Point3D[Optimized_Field]:
        """Convert back to a projective py_ecc G2 point.

        Returns:
            Projective G2 point for use with py_ecc.
        """
        return (self.x.to_fq2(), self.y.to_fq2(), FQ2.one())

from_g2(point) staticmethod

Convert a projective py_ecc G2 point to affine representation.

Parameters:

Name Type Description Default
point Optimized_Point3D[Optimized_Field]

Projective G2 point from py_ecc.

required

Returns:

Type Description
G2_Point

Affine G2_Point.

Source code in src/payment/crypto/models.py
66
67
68
69
70
71
72
73
74
75
76
77
@staticmethod
def from_g2(point: Optimized_Point3D[Optimized_Field]) -> "G2_Point":
    """Convert a projective py_ecc G2 point to affine representation.

    Args:
        point: Projective G2 point from py_ecc.

    Returns:
        Affine G2_Point.
    """
    x, y = normalize(point)
    return G2_Point(x=FQ2_Point.from_fq2(x), y=FQ2_Point.from_fq2(y))

to_g2()

Convert back to a projective py_ecc G2 point.

Returns:

Type Description
Optimized_Point3D[Optimized_Field]

Projective G2 point for use with py_ecc.

Source code in src/payment/crypto/models.py
79
80
81
82
83
84
85
def to_g2(self) -> Optimized_Point3D[Optimized_Field]:
    """Convert back to a projective py_ecc G2 point.

    Returns:
        Projective G2 point for use with py_ecc.
    """
    return (self.x.to_fq2(), self.y.to_fq2(), FQ2.one())