pub struct Nullifier {
pub inner: FieldElement,
}Expand description
A nullifier is a unique, one-time identifier derived from (user, rpId, action) that lets RPs detect
duplicate actions without learning who the user is. Used with the contract’s verify() function.
Internally, this is a thin wrapper to identify explicitly a single nullifier. This wrapper is used to expose explicit canonical serialization which is critical for uniqueness.
Fields§
§inner: FieldElementThe FieldElement representing the nullifier.
Implementations§
Source§impl Nullifier
impl Nullifier
Sourcepub const fn new(nullifier: FieldElement) -> Self
pub const fn new(nullifier: FieldElement) -> Self
Initializes a new Nullifier from a FieldElement
Sourcepub fn as_number(&self) -> U256
pub fn as_number(&self) -> U256
Outputs the nullifier as a number. This is the recommended way of enforcing nullifier uniqueness.
Store this number directly to enforce uniqueness.
Sourcepub fn to_canonical_string(&self) -> String
pub fn to_canonical_string(&self) -> String
Serializes a nullifier in a canonical string representation.
It is generally safe to do uniqueness on nullifiers treating them as strings if you always serialize them with this method. However, storing nullifiers as numbers instead is recommended.
§Warning
Using a canonical representation is particularly important for nullifiers. Otherwise, different strings may actually represent the same field elements, which could result in a compromise of uniqueness.
§Details
In particular, this method adds an explicit prefix, serializes the field element to a 32-byte hex padded string with only lowercase characters.
Sourcepub fn from_canonical_string(nullifier: String) -> Result<Self, PrimitiveError>
pub fn from_canonical_string(nullifier: String) -> Result<Self, PrimitiveError>
Deserializes a nullifier from a canonical string representation. In particular, this method will enforce all the required rules to ensure the value was canonically serialized.
For example, the following string representations are equivalently the same field element: 0xa, 0xA, 0x0A,
this method will ensure a single representation exists for each field element.
§Errors
Will return an error if any of the encoding conditions failed (e.g. invalid characters, invalid length, etc.)
Methods from Deref<Target = FieldElement>§
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Nullifier
impl<'de> Deserialize<'de> for Nullifier
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 From<FieldElement> for Nullifier
impl From<FieldElement> for Nullifier
Source§fn from(value: FieldElement) -> Self
fn from(value: FieldElement) -> Self
Source§impl From<Nullifier> for FieldElement
impl From<Nullifier> for FieldElement
impl Copy for Nullifier
impl Eq for Nullifier
impl StructuralPartialEq for Nullifier
Auto Trait Implementations§
impl Freeze for Nullifier
impl RefUnwindSafe for Nullifier
impl Send for Nullifier
impl Sync for Nullifier
impl Unpin for Nullifier
impl UnsafeUnpin for Nullifier
impl UnwindSafe for Nullifier
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> 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