latest.ipv8.attestation.wallet.primitives.value

Module Contents

Classes

FP2Value

Defines a rational value (a + bx + cx^2)/(aC + bCx + cCx^2)(mod 1 + x + x^2, mod p).

Functions

format_polynomial(→ str)

Formats a polynomial cx^2 + bx + a into non-zero/non-one form.

latest.ipv8.attestation.wallet.primitives.value.format_polynomial(a: int, b: int, c: int) str

Formats a polynomial cx^2 + bx + a into non-zero/non-one form.

Ex. ‘0x^2 + 1x + 2’ becomes ‘x + 2’

Parameters:
  • a – x^0 coefficient

  • b – x^1 coefficient

  • c – x^2 coefficient

Returns:

pretty format of polynomial

class latest.ipv8.attestation.wallet.primitives.value.FP2Value(mod: int, a: int = 0, b: int = 0, c: int = 0, aC: int = 1, bC: int = 0, cC: int = 0)

Defines a rational value (a + bx + cx^2)/(aC + bCx + cCx^2)(mod 1 + x + x^2, mod p).

__str__() str

Format this value as a string.

__add__(other: FP2Value) FP2Value

Add this value to another value and return a new FP2Value.

__sub__(other: FP2Value) FP2Value

Subtract another value from this value and return a new FP2Value.

__mul__(other: FP2Value) FP2Value

Multiply this value with another value and return a new FP2Value.

__floordiv__(other: FP2Value) FP2Value

Divide this value by another value and return a new FP2Value.

__eq__(other: object) bool

Check equality with another value.

__hash__() int

Equality is not trivial. We hash everything to 0 for the full equality check.

intpow(power: int) FP2Value

Raise this value by a given power (int).

Parameters:

power (int) – the power to raise this value by

normalize() FP2Value

Normalize to aC = 1: this is the best human-readable form.

Ex. ‘20/4’ becomes ‘5’

‘4 + 4x/2 + 2x’ becomes ‘2 + 2x/1 + x’

inverse() FP2Value

Return the inverse of this value.

wp_nominator() FP2Value

Return the ‘1’ and ‘x’ coefficients as a new value.

wp_denom_inverse() FP2Value

Return the ‘1^-1’ and ‘x^-1’ coefficients modular inverse.

wp_compress() FP2Value

Compress this FP2 value into an FP2Value only containing a and b values.

This is an expensive operation.