pub struct FieldElement(/* private fields */);Expand description
Represents a field element of the base field (Fq) in the World ID Protocol.
The World ID Protocol uses the BabyJubJub curve throughout. Note the
base field of BabyJubJub is the scalar field of the BN254 curve.
This wrapper ensures consistent serialization and deserialization of field elements, where string-based serialization is done with hex encoding and binary serialization is done with byte vectors.
Implementations§
Source§impl FieldElement
impl FieldElement
Sourcepub fn serialize_as_bytes<W: Write>(
&self,
writer: &mut W,
) -> Result<(), PrimitiveError>
pub fn serialize_as_bytes<W: Write>( &self, writer: &mut W, ) -> Result<(), PrimitiveError>
Serializes the field element into a byte vector.
§Errors
Will return an error if the serialization unexpectedly fails.
Sourcepub fn deserialize_from_bytes<R: Read>(
bytes: &mut R,
) -> Result<Self, PrimitiveError>
pub fn deserialize_from_bytes<R: Read>( bytes: &mut R, ) -> Result<Self, PrimitiveError>
Deserializes a field element from a byte vector.
§Errors
Will return an error if the provided input is not a valid field element (e.g. not on the curve).
Sourcepub fn from_be_bytes_mod_order(bytes: &[u8]) -> Self
pub fn from_be_bytes_mod_order(bytes: &[u8]) -> Self
Deserializes a field element from a big-endian byte slice.
Sourcepub fn from_arbitrary_raw_bytes(bytes: &[u8]) -> Self
pub fn from_arbitrary_raw_bytes(bytes: &[u8]) -> Self
Takes arbitrary raw bytes, hashes them with a byte-friendly gas-efficient hash function and reduces it to a field element.
Trait Implementations§
Source§impl Clone for FieldElement
impl Clone for FieldElement
Source§fn clone(&self) -> FieldElement
fn clone(&self) -> FieldElement
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FieldElement
impl Debug for FieldElement
Source§impl Default for FieldElement
impl Default for FieldElement
Source§fn default() -> FieldElement
fn default() -> FieldElement
Source§impl Deref for FieldElement
impl Deref for FieldElement
Source§impl DerefMut for FieldElement
impl DerefMut for FieldElement
Source§impl<'de> Deserialize<'de> for FieldElement
impl<'de> Deserialize<'de> for FieldElement
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Display for FieldElement
impl Display for FieldElement
Source§impl From<FieldElement> for U256
impl From<FieldElement> for U256
Source§fn from(value: FieldElement) -> Self
fn from(value: FieldElement) -> Self
Source§impl From<Fp<MontBackend<FrConfig, 4>, 4>> for FieldElement
impl From<Fp<MontBackend<FrConfig, 4>, 4>> for FieldElement
Source§impl From<RpId> for FieldElement
impl From<RpId> for FieldElement
Source§impl From<Uint<160, 3>> for FieldElement
impl From<Uint<160, 3>> for FieldElement
Source§impl From<u128> for FieldElement
impl From<u128> for FieldElement
Source§impl From<u64> for FieldElement
impl From<u64> for FieldElement
Source§impl FromStr for FieldElement
impl FromStr for FieldElement
Source§impl Hash for FieldElement
impl Hash for FieldElement
Source§impl Ord for FieldElement
impl Ord for FieldElement
Source§fn cmp(&self, other: &FieldElement) -> Ordering
fn cmp(&self, other: &FieldElement) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for FieldElement
impl PartialEq for FieldElement
Source§impl PartialOrd for FieldElement
impl PartialOrd for FieldElement
Source§impl Serialize for FieldElement
impl Serialize for FieldElement
Source§impl TryFrom<Uint<256, 4>> for FieldElement
impl TryFrom<Uint<256, 4>> for FieldElement
impl Copy for FieldElement
impl Eq for FieldElement
impl StructuralPartialEq for FieldElement
Auto Trait Implementations§
impl Freeze for FieldElement
impl RefUnwindSafe for FieldElement
impl Send for FieldElement
impl Sync for FieldElement
impl Unpin for FieldElement
impl UnwindSafe for FieldElement
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more