Credential

Struct Credential 

Source
pub struct Credential {
    pub version: CredentialVersion,
    pub issuer_schema_id: u64,
    pub sub: u64,
    pub genesis_issued_at: u64,
    pub expires_at: u64,
    pub claims: Vec<FieldElement>,
    pub associated_data_hash: FieldElement,
    pub signature: Option<EdDSASignature>,
    pub issuer: EdDSAPublicKey,
}
Expand description

Base representation of a Credential in the World ID Protocol.

A credential is generally a verifiable digital statement about a subject. It is the canonical object: everything a verifier needs for proofs and authorization.

In the case of World ID these statements are about humans, with the most common credentials being Orb verification or document verification.

Design Principles:

  • A credential clearly separates:
    • Assertion (the claim being made)
    • Issuer (who attests to it / vouches for it)
    • Subject (who it is about)
    • Presenter binding (who can present it)
  • Credentials are usable across authenticators without leaking correlate-able identifiers to RPs.
  • Revocation, expiry, and re-issuance are first-class lifecycle properties.
  • Flexibility: credentials may take different formats but share common metadata (validity, issuer, trust, type).

All credentials have an issuer and schema, identified with the issuer_schema_id field. This identifier is registered in the CredentialSchemaIssuerRegistry contract. It represents a particular schema issued by a particular issuer. Some schemas are intended to be global (e.g. representing an ICAO-compliant passport) and some issuer-specific. Schemas should be registered in the CredentialSchemaIssuerRegistry contract and should be publicly accessible.

We want to encourage schemas to be widely distributed and adopted. If everyone uses the same passport schema, for example, the Protocol will have better interoperability across passport credential issuers, reducing the burden on holders (to make sense of which passport they have), and similarly, RPs.

Fields§

§version: CredentialVersion

Version representation of this structure

§issuer_schema_id: u64

Unique credential type id that is used to lookup of verifying information

§sub: u64

The subject (World ID) to which the credential is issued.

This ID comes from the AccountRegistry and it’s the leaf_index of the World ID on the Merkle tree.

§genesis_issued_at: u64

Timestamp of first issuance of this credential (unix seconds), i.e. this represents when the holder first obtained the credential. Even if the credential has been issued multiple times (e.g. because of a renewal), this timestamp should stay constant.

§expires_at: u64

Expiration timestamp (unix seconds)

§claims: Vec<FieldElement>

These are concrete statements that the issuer attests about the receiver. Could be just commitments to data (e.g. passport image) or the value directly (e.g. date of birth)

§associated_data_hash: FieldElement

If needed, can be used as commitment to the underlying data. This can be useful to tie multiple proofs about the same data together.

§signature: Option<EdDSASignature>

The signature of the credential (signed by the issuer’s key)

§issuer: EdDSAPublicKey

The issuer’s public key of the credential.

Implementations§

Source§

impl Credential

Source

pub const MAX_CLAIMS: usize = 16usize

The maximum number of claims that can be included in a credential.

Source

pub fn new() -> Credential

Initializes a new credential.

Note default fields occupy a sentinel value of BaseField::zero()

Source

pub const fn version(self, version: CredentialVersion) -> Credential

Set the version of the credential.

Source

pub const fn issuer_schema_id(self, issuer_schema_id: u64) -> Credential

Set the issuerSchemaId of the credential.

Source

pub const fn sub(self, sub: u64) -> Credential

Set the sub of the credential.

Source

pub const fn genesis_issued_at(self, genesis_issued_at: u64) -> Credential

Set the genesis issued at of the credential.

Source

pub const fn expires_at(self, expires_at: u64) -> Credential

Set the expires at of the credential.

Source

pub fn claim( self, index: usize, claim: Uint<256, 4>, ) -> Result<Credential, PrimitiveError>

Set a claim for the credential at an index.

§Errors

Will error if the index is out of bounds.

Source

pub fn associated_data_hash( self, associated_data_hash: Uint<256, 4>, ) -> Result<Credential, PrimitiveError>

Set the associated data hash of the credential.

§Errors

Will error if the provided hash cannot be lowered into the field.

Source

pub fn get_cred_ds(&self) -> FieldElement

Get the credential domain separator for the given version.

Trait Implementations§

Source§

impl Clone for Credential

Source§

fn clone(&self) -> Credential

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Credential

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Credential

Source§

fn default() -> Credential

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Credential

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Credential, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl HashableCredential for Credential

Source§

fn claims_hash(&self) -> Result<FieldElement, Error>

Get the claims hash of the credential. Read more
Source§

fn hash(&self) -> Result<FieldElement, Error>

The hash is signed by the issuer to provide authenticity for the credential. Read more
Source§

fn verify_signature( &self, expected_issuer_pubkey: &EdDSAPublicKey, ) -> Result<bool, Error>

Verify the signature of the credential against the issuer public key and expected hash. Read more
Source§

impl Serialize for Credential

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<'de, T> BorrowedRpcObject<'de> for T
where T: RpcBorrow<'de> + RpcSend,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<'de, T> RpcBorrow<'de> for T
where T: Deserialize<'de> + Debug + Send + Sync + Unpin,

Source§

impl<T> RpcObject for T
where T: RpcSend + RpcRecv,

Source§

impl<T> RpcRecv for T
where T: DeserializeOwned + Debug + Send + Sync + Unpin + 'static,

Source§

impl<T> RpcSend for T
where T: Serialize + Clone + Debug + Send + Sync + Unpin,