pub struct SessionId { /* private fields */ }Expand description
An identifier for a session (can be re-used).
A session allows RPs to ensure that it’s still the same World ID interacting with them across multiple interactions.
A SessionId is obtained after creating an initial session.
See the diagram below on how Session Proofs work, the SessionId and the r seed
Note that the action stored here is unrelated to the randomized action used
internally by SessionNullifiers — that randomized action exists only to ensure
the circuit’s nullifier output is unique per Session Proof.
Implementations§
Source§impl SessionId
impl SessionId
Sourcepub fn new(commitment: FieldElement, oprf_seed: FieldElement) -> Self
pub fn new(commitment: FieldElement, oprf_seed: FieldElement) -> Self
Creates a new session id. Most uses should default to from_r_seed instead.
§Panics
If the provided oprf_seed is not prefixed with a 0x01 byte.
Sourcepub fn from_r_seed<R: CryptoRng + RngCore>(
leaf_index: u64,
session_id_r_seed: FieldElement,
oprf_seed: Option<FieldElement>,
rng: &mut R,
) -> Result<Self, &str>
pub fn from_r_seed<R: CryptoRng + RngCore>( leaf_index: u64, session_id_r_seed: FieldElement, oprf_seed: Option<FieldElement>, rng: &mut R, ) -> Result<Self, &str>
Initializes a SessionId from the OPRF-output seed (r), and the oprf_seed
used as input for the OPRF computation.
This matches the logic in oprf_nullifier.circom for computing the commitment from the OPRF seed.
§Seed (session_id_r_seed)
- The seed is and MUST be computationally indistinguishable from random, i.e. uniformly distributed because it uses OPRF.
- When computed, the OPRF nodes will use the same
oprfKeyIdfor the RP, with a different domain separator. - Requesting this seed requires a properly signed request from the RP and a complete query proof.
- The seed generation is based on a randomly generated seed used as an “action” in a Query Proof. Note
this
actionis different than the randomized action used internally bySessionNullifiers.
Sourcepub const fn commitment(&self) -> FieldElement
pub const fn commitment(&self) -> FieldElement
Returns the commitment value.
Sourcepub const fn oprf_seed(&self) -> FieldElement
pub const fn oprf_seed(&self) -> FieldElement
Returns the oprf_seed value.
Sourcepub fn to_compressed_bytes(&self) -> [u8; 64]
pub fn to_compressed_bytes(&self) -> [u8; 64]
Returns the 64-byte big-endian representation (2 x 32-byte field elements).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for SessionId
impl<'de> Deserialize<'de> for SessionId
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>,
impl Copy for SessionId
impl Eq for SessionId
impl StructuralPartialEq for SessionId
Auto Trait Implementations§
impl Freeze for SessionId
impl RefUnwindSafe for SessionId
impl Send for SessionId
impl Sync for SessionId
impl Unpin for SessionId
impl UnsafeUnpin for SessionId
impl UnwindSafe for SessionId
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