pub struct SessionId {
pub commitment: FieldElement,
pub oprf_seed: FieldElement,
}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.
Fields§
§commitment: FieldElementThe actual commitment being verified in the ZK-circuit.
It is computed as H(DS_C || leaf_index || session_id_r_seed), see
signal computed_id_commitment in oprf_nullifier.circom.
oprf_seed: FieldElementA random seed generated by the authenticator in the initial Uniqueness Proof.
This seed is the input to the OPRF Query to derive session_id_r_seed (r). It
is part of the session_id so the RP can provide it when requesting a Session Proof.
§Important: Prefix
To ensure there are no collisions between the generated rs and the nullifiers
for Uniqueness Proofs (as they use the same OPRF Key and query structure), the
oprf_seeds, which are plugged as action in the Query Proof (see QueryProofCircuitInput),
MUST be prefixed with an explicit byte of 0x01. All other actions have a 0x00 byte prefix. This
collision avoidance is important because it ensures that any requests for nullifiers meant
for Uniqueness Proofs are always signed by the RP (otherwise, an RP signature for a Session Proof
could be used for requesting computation of any nullifier).
§Re-derivation
The Authenticator can deterministically re-derive r from the OPRF nodes without
needing to cache r locally as:
r = OPRF(pk_rpId, DS_C || leafIndex || oprf_seed)Implementations§
Source§impl SessionId
impl SessionId
Sourcepub fn new(
commitment: FieldElement,
oprf_seed: FieldElement,
) -> Result<Self, PrimitiveError>
pub fn new( commitment: FieldElement, oprf_seed: FieldElement, ) -> Result<Self, PrimitiveError>
Creates a new session id. Most uses should default to from_r_seed instead.
§Errors
If the provided oprf_seed is not prefixed properly.
Sourcepub fn from_r_seed(
leaf_index: u64,
session_id_r_seed: FieldElement,
oprf_seed: FieldElement,
) -> Result<Self, PrimitiveError>
pub fn from_r_seed( leaf_index: u64, session_id_r_seed: FieldElement, oprf_seed: FieldElement, ) -> Result<Self, PrimitiveError>
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 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 fn generate_oprf_seed<R: CryptoRng + RngCore>(rng: &mut R) -> FieldElement
pub fn generate_oprf_seed<R: CryptoRng + RngCore>(rng: &mut R) -> FieldElement
Generates a new Self::oprf_seed to initialize a new Session.
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