Elliptic Curves

Module Contents

Classes

EllipticCurve

Superclass for integers modulo a prime. Not intended to be used

Functions

secp256k1_recover

Recovers the public key from a given signature.

Attributes

SECP256K1N

F

T

Module Details

SECP256K1N

SECP256K1N
SECP256K1N = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141

F

F
F = TypeVar("F", bound=Field)

T

T
T = TypeVar("T", bound="EllipticCurve")

secp256k1_recover

secp256k1_recover(r: ethereum.base_types.U256, s: ethereum.base_types.U256, v: ethereum.base_types.U256, msg_hash: ethereum.crypto.hash.Hash32)ethereum.base_types.Bytes

Recovers the public key from a given signature.

Parameters
  • r – TODO

  • s – TODO

  • v – TODO

  • msg_hash – Hash of the message being recovered.

Returns

public_key – Recovered public key.

Return type

ethereum.base_types.Bytes

def secp256k1_recover(r: U256, s: U256, v: U256, msg_hash: Hash32) -> Bytes:
    r_bytes = r.to_be_bytes32()
    s_bytes = s.to_be_bytes32()

    signature = bytearray([0] * 65)
    signature[32 - len(r_bytes) : 32] = r_bytes
    signature[64 - len(s_bytes) : 64] = s_bytes
    signature[64] = v
    public_key = coincurve.PublicKey.from_signature_and_message(
        bytes(signature), msg_hash, hasher=None
    )
    public_key = public_key.format(compressed=False)[1:]
    return public_key

EllipticCurve

Superclass for integers modulo a prime. Not intended to be used directly, but rather to be subclassed.

class EllipticCurve(x: F, y: F)

Bases: Generic[F]

__slots__ = ['x', 'y']
FIELD :Type[F]
A :F
B :F
x :F
y :F
__eq__(other: object)bool

Test two points for equality.

__str__()str

Stringify a point as its coordinates.

classmethod point_at_infinity()T

Return the point at infinity. This is the identity element of the group operation.

The point at infinity doesn’t actually have coordinates so we use (0, 0) (which isn’t on the curve) to represent it.

double()T

Add a point to itself.

__add__(other: T)T

Add two points together.

mul_by(n: int)T

Multiply self by n using the double and add algorithm.