nada_dsl.nada_types
function.py
Nada function definitions and utilities.
- class NadaFunctionArg(function_id: int, name: str, arg_type: T, source_ref: SourceRef)[source]
Bases:
Generic[T]Represents a Nada function argument.
- type: T
- __orig_bases__ = (typing.Generic[~T],)
- __parameters__ = (~T,)
- class NadaFunction(function_id: int, args: List[NadaFunctionArg], function: Callable[[T], R], return_type: R, source_ref: SourceRef, inner: NadaType)[source]
Bases:
Generic[T,R]Nada Function.
Represents a Nada Function. Nada functions are special types of functions that are used in map / reduce operations.
They are decorated using the @nada_fn decorator.
- args: List[NadaFunctionArg]
- return_type: R
- __orig_bases__ = (typing.Generic[~T, ~R],)
- __parameters__ = (~T, ~R)
- class NadaFunctionCall(nada_function, args, source_ref)[source]
Bases:
Generic[R]Represents a call to a Nada Function.
- __eq__(other)
Return self==value.
- __orig_bases__ = (typing.Generic[~R],)
- __parameters__ = (~R,)
- fn: NadaFunction
- nada_fn(fn, args_ty=None, return_ty=None) NadaFunction[T, R][source]
Can be used also for lambdas ```python array.map(
- nada_fn(
lambda x: x.cast(SecretInteger), args_ty={‘x’: SecretInteger}, return_ty=SecretInteger))
Generic type definitions for Nada.
The Nada Scalar type definitions.
- class ScalarType(inner: Addition | Subtraction | Multiplication | Division | Modulo | Power | RightShift | LeftShift | LessThan | GreaterThan | LessOrEqualThan | GreaterOrEqualThan | Equals | Input | Cast | Map | Zip | Reduce | Unzip | Literal, base_type: BaseType, mode: Mode)[source]
Bases:
NadaTypeThe Nada Scalar type. This is the super class for all scalar types in Nada. These are:
Boolean, PublicBoolean, SecretBoolean
Integer, PublicInteger, SecretInteger
UnsignedInteger, PublicUnsignedInteger, SecretUnsignedInteger
ScalarType provides common operation implementations for all the scalar types based on the typing rules of the Nada model.
- base_type: BaseType
- mode: Mode
- __eq__(other) Boolean | PublicBoolean | SecretBoolean[source]
Return self==value.
- __ne__(other) Boolean | PublicBoolean | SecretBoolean[source]
Return self!=value.
- equals_operation(operation, operator, left: ScalarType, right: ScalarType, f) Boolean | PublicBoolean | SecretBoolean[source]
This function is an abstraction for the equality operations
- register_scalar_type(mode: Mode, base_type: BaseType)[source]
Decorator used to register a new scalar type in the SCALAR_TYPES dictionary.
- new_scalar_type(mode: Mode, base_type: BaseType) type[Integer | UnsignedInteger | Boolean | PublicInteger | PublicUnsignedInteger | PublicBoolean | SecretInteger | SecretUnsignedInteger | SecretBoolean][source]
Returns the corresponding MIR Nada Type
- class NumericType(inner: Addition | Subtraction | Multiplication | Division | Modulo | Power | RightShift | LeftShift | LessThan | GreaterThan | LessOrEqualThan | GreaterOrEqualThan | Equals | Input | Cast | Map | Zip | Reduce | Unzip | Literal, base_type: BaseType, mode: Mode)[source]
Bases:
ScalarTypeThe superclass of all the numeric types in Nada: - Integer, PublicInteger, SecretInteger - UnsignedInteger, PublicUnsignedInteger, SecretUnsignedInteger It provides common operation implementations for all the numeric types based on the typing rules of the Nada model.
- __lt__(other) Boolean | PublicBoolean | SecretBoolean[source]
Return self<value.
- __gt__(other) Boolean | PublicBoolean | SecretBoolean[source]
Return self>value.
- __le__(other) Boolean | PublicBoolean | SecretBoolean[source]
Return self<=value.
- __ge__(other) Boolean | PublicBoolean | SecretBoolean[source]
Return self>=value.
- binary_arithmetic_operation(operation, operator, left: ScalarType, right: ScalarType, f) ScalarType[source]
This function is an abstraction for the binary arithmetic operations.
Arithmetic operations apply to Numeric types only in Nada.
- shift_operation(operation, operator, left: ScalarType, right: ScalarType, f) ScalarType[source]
This function is an abstraction for the shift operations
- binary_relational_operation(operation, operator, left: ScalarType, right: ScalarType, f) Boolean | PublicBoolean | SecretBoolean[source]
This function is an abstraction for the binary relational operations
- public_equals_operation(left: ScalarType, right: ScalarType) PublicBoolean[source]
This function is an abstraction for the public_equals operation for all types.
- class BooleanType(inner: Addition | Subtraction | Multiplication | Division | Modulo | Power | RightShift | LeftShift | LessThan | GreaterThan | LessOrEqualThan | GreaterOrEqualThan | Equals | Input | Cast | Map | Zip | Reduce | Unzip | Literal, base_type: BaseType, mode: Mode)[source]
Bases:
ScalarTypeThis abstraction represents all boolean types: - Boolean, PublicBoolean, SecretBoolean It provides common operation implementations for all the boolean types, defined above.
- binary_logical_operation(operation, operator, left: ScalarType, right: ScalarType, f) ScalarType[source]
This function is an abstraction for the logical operations.
- class Integer(value)[source]
Bases:
NumericTypeThe Nada Integer type.
Represents a constant (literal) integer.
- __eq__(other) Boolean | PublicBoolean | SecretBoolean[source]
Return self==value.
- base_type: BaseType = 2
- mode: Mode = 1
- class UnsignedInteger(value)[source]
Bases:
NumericTypeThe Nada Unsigned Integer type.
Represents a constant (literal) unsigned integer.
- __eq__(other) Boolean | PublicBoolean | SecretBoolean[source]
Return self==value.
- base_type: BaseType = 3
- mode: Mode = 1
- class Boolean(value)[source]
Bases:
BooleanTypeThe Nada Boolean type.
Represents a constant (literal) boolean.
- __eq__(other) Boolean | PublicBoolean | SecretBoolean[source]
Return self==value.
- base_type: BaseType = 1
- mode: Mode = 1
- class PublicInteger(inner: NadaType)[source]
Bases:
NumericTypeThe Nada Public Unsigned Integer type.
Represents a public unsigned integer in a program. This is a public variable evaluated at runtime.
- __eq__(other) Boolean | PublicBoolean | SecretBoolean[source]
Return self==value.
- public_equals(other: PublicInteger | SecretInteger) PublicBoolean[source]
Implementation of public equality for Public integer types.
- base_type: BaseType = 2
- mode: Mode = 2
- class PublicUnsignedInteger(inner: NadaType)[source]
Bases:
NumericTypeThe Nada Public Integer type.
Represents a public integer in a program. This is a public variable evaluated at runtime.
- __eq__(other) Boolean | PublicBoolean | SecretBoolean[source]
Return self==value.
- public_equals(other: PublicUnsignedInteger | SecretUnsignedInteger) PublicBoolean[source]
Implementation of public equality for Public unsigned integer types.
- base_type: BaseType = 3
- mode: Mode = 2
- class PublicBoolean(inner: NadaType)[source]
Bases:
BooleanTypeThe Nada Public Boolean type.
Represents a public boolean in a program. This is a public variable evaluated at runtime.
- __eq__(other) Boolean | PublicBoolean | SecretBoolean[source]
Return self==value.
- __invert__() PublicBoolean[source]
- public_equals(other: PublicUnsignedInteger | SecretUnsignedInteger) PublicBoolean[source]
Implementation of public equality for Public boolean types.
- base_type: BaseType = 1
- mode: Mode = 2
- class SecretInteger(inner: NadaType)[source]
Bases:
NumericTypeThe Nada secret integer type.
- __eq__(other) Boolean | PublicBoolean | SecretBoolean[source]
Return self==value.
- public_equals(other: PublicInteger | SecretInteger) PublicBoolean[source]
Implementation of public equality for secret integer types.
- trunc_pr(other: PublicUnsignedInteger | UnsignedInteger) SecretInteger[source]
Probabilistic truncation for secret integers.
- classmethod random() SecretInteger[source]
Random operation for Secret integers.
- to_public() PublicInteger[source]
Convert this secret integer into a public variable.
- base_type: BaseType = 2
- mode: Mode = 3
- class SecretUnsignedInteger(inner: NadaType)[source]
Bases:
NumericTypeThe Nada Secret Unsigned integer type.
- __eq__(other) Boolean | PublicBoolean | SecretBoolean[source]
Return self==value.
- public_equals(other: PublicUnsignedInteger | SecretUnsignedInteger) PublicBoolean[source]
The public equality operation.
- trunc_pr(other: PublicUnsignedInteger | UnsignedInteger) SecretUnsignedInteger[source]
Probabilistic truncation operation.
- classmethod random() SecretUnsignedInteger[source]
Generate a random secret unsigned integer.
- to_public() PublicUnsignedInteger[source]
Convert this secret into a public variable.
- base_type: BaseType = 3
- mode: Mode = 3
- class SecretBoolean(inner: NadaType)[source]
Bases:
BooleanTypeThe SecretBoolean Nada MIR type.
- __eq__(other) Boolean | PublicBoolean | SecretBoolean[source]
Return self==value.
- __invert__() SecretBoolean[source]
- to_public() PublicBoolean[source]
Convert this secret into a public variable.
- classmethod random() SecretBoolean[source]
Generate a random secret boolean.
- base_type: BaseType = 1
- mode: Mode = 3
- class EcdsaSignature(inner: Addition | Subtraction | Multiplication | Division | Modulo | Power | RightShift | LeftShift | LessThan | GreaterThan | LessOrEqualThan | GreaterOrEqualThan | Equals | Input | Cast | Map | Zip | Reduce | Unzip | Literal)[source]
Bases:
NadaTypeThe EcdsaSignature Nada MIR type.
- __eq__(other)
Return self==value.
- class EcdsaDigestMessage(inner: Addition | Subtraction | Multiplication | Division | Modulo | Power | RightShift | LeftShift | LessThan | GreaterThan | LessOrEqualThan | GreaterOrEqualThan | Equals | Input | Cast | Map | Zip | Reduce | Unzip | Literal)[source]
Bases:
NadaTypeThe EcdsaDigestMessage Nada MIR type.
- __eq__(other)
Return self==value.
- class EcdsaPrivateKey(inner: Addition | Subtraction | Multiplication | Division | Modulo | Power | RightShift | LeftShift | LessThan | GreaterThan | LessOrEqualThan | GreaterOrEqualThan | Equals | Input | Cast | Map | Zip | Reduce | Unzip | Literal)[source]
Bases:
NadaTypeThe EcdsaPrivateKey Nada MIR type.
- __eq__(other)
Return self==value.
- ecdsa_sign(digest: EcdsaDigestMessage) EcdsaSignature[source]
Random operation for Secret integers.