ed25519_lib
Helper library for ed25519 point encoding/decoding, which cannot be done with pynacl APIs. Encode/Decode operations copied from: https://github.com/warner/python-pure25519/blob/master/pure25519/basic.py
- int_decode(int_bytes: bytes) int
Decode int from bytes.
- Parameters:
int_bytes (bytes) – Integer bytes
- Returns:
Decoded integer
- Return type:
int
- int_encode(int_val: int) bytes
Encode int to bytes.
- Parameters:
int_val (int) – Integer value
- Returns:
Encoded integer
- Return type:
bytes
- point_is_decoded_bytes(point_bytes: bytes) bool
Get if point bytes are in decoded format.
- Parameters:
point_bytes (bytes) – Point bytes
- Returns:
True if in decoded format, false otherwise
- Return type:
bool
- point_is_encoded_bytes(point_bytes: bytes) bool
Get if point bytes are in encoded format.
- Parameters:
point_bytes (bytes) – Point bytes
- Returns:
True if in encoded format, false otherwise
- Return type:
bool
- point_is_valid_bytes(point_bytes: bytes) bool
Get if point bytes are valid.
- Parameters:
point_bytes (bytes) – Point bytes
- Returns:
True if valid, false otherwise
- Return type:
bool
- point_bytes_to_coord(point_bytes: bytes) Tuple[int, int]
Convert point bytes to coordinates.
- Parameters:
point_bytes (bytes) – Point bytes
- Returns:
Point coordinates
- Return type:
tuple[int, int]
- Raises:
ValueError – If point bytes are not valid
- point_coord_to_bytes(point_coord: Tuple[int, int]) bytes
Convert point coordinates to bytes.
- Parameters:
point_coord (tuple[int, int]) – Point coordinates
- Returns:
Point bytes
- Return type:
bytes
- point_decode_no_check(point_bytes: bytes) Tuple[int, int]
Decode point bytes to coordinates without checking if it lies on the ed25519 curve.
- Parameters:
point_bytes (bytes) – Point bytes
- Returns:
Point coordinates
- Return type:
tuple[int, int]
- Raises:
ValueError – If point bytes are not valid
- point_decode(point_bytes: bytes) Tuple[int, int]
Decode point bytes to coordinates by checking if it lies on the ed25519 curve.
- Parameters:
point_bytes (bytes) – Point bytes
- Returns:
Point coordinates
- Return type:
tuple[int, int]
- Raises:
ValueError – If the point bytes are not valid or the decoded point doesn’t lie on the curve
- point_encode(point_coord: Tuple[int, int]) bytes
Encode point coordinates to bytes.
- Parameters:
point_coord (tuple[int, int]) – Point coordinates
- Returns:
Point bytes
- Return type:
bytes
- point_is_generator(point: Union[bytes, Tuple[int, int]]) bool
Get if the point is the generator of the ed25519 curve.
- Parameters:
point (bytes or tuple[int, int]) – Point
- Returns:
True if generator, false otherwise
- Return type:
bool
- Raises:
ValueError – If point bytes are not valid
- point_is_on_curve(point: Union[bytes, Tuple[int, int]]) bool
Get if the point lies on the ed25519 curve. This method is used because nacl.bindings.crypto_core_ed25519_is_valid_point performs more strict checks, which results in points (i.e. public keys) that are considered not valid even if they are accepted by wallets.
- Parameters:
point (bytes or tuple[int, int]) – Point
- Returns:
True if it lies on the curve, false otherwise
- Return type:
bool
- Raises:
ValueError – If point bytes are not valid
- point_add(point_1: Union[bytes, Tuple[int, int]], point_2: Union[bytes, Tuple[int, int]]) bytes
Add two points on the ed25519 curve.
- Parameters:
point_1 (bytes or tuple[int, int]) – Point 1
point_2 (bytes or tuple[int, int]) – Point 2
- Returns:
New point resulting from the addition
- Return type:
bytes
- point_scalar_mul(scalar: Union[bytes, int], point: Union[bytes, Tuple[int, int]]) bytes
Multiply a point on the ed25519 curve with a scalar.
- Parameters:
scalar (bytes or int) – Scalar
point (bytes or tuple[int, int]) – Point
- Returns:
New point resulting from the multiplication
- Return type:
bytes
- point_scalar_mul_base(scalar: Union[bytes, int]) bytes
Multiply the base (i.e. generator) point of the ed25519 curve with a scalar.
- Parameters:
scalar (bytes or int) – Scalar
- Returns:
New point resulting from the multiplication
- Return type:
bytes
- scalar_reduce(scalar: Union[bytes, int]) bytes
Convert the specified bytes to integer and return its lowest 32-bytes modulo ed25519 curve order.
- Parameters:
scalar (bytes or int) – Scalar
- Returns:
Lowest 32-bytes modulo ed25519-order
- Return type:
bytes
- scalar_is_valid(scalar: Union[bytes, int]) bool
Get if the specified scalar is valid (i.e. less than the ed25519 curve order).
- Parameters:
scalar (bytes or int) – Scalar
- Returns:
True if lower, false otherwise
- Return type:
bool