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: CredentialVersionVersion representation of this structure
issuer_schema_id: u64Unique credential type id that is used to lookup of verifying information
sub: u64The 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: u64Timestamp 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: u64Expiration 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: FieldElementIf 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: EdDSAPublicKeyThe issuer’s public key of the credential.
Implementations§
Source§impl Credential
impl Credential
Sourcepub const MAX_CLAIMS: usize = 16usize
pub const MAX_CLAIMS: usize = 16usize
The maximum number of claims that can be included in a credential.
Sourcepub fn new() -> Credential
pub fn new() -> Credential
Initializes a new credential.
Note default fields occupy a sentinel value of BaseField::zero()
Sourcepub const fn version(self, version: CredentialVersion) -> Credential
pub const fn version(self, version: CredentialVersion) -> Credential
Set the version of the credential.
Sourcepub const fn issuer_schema_id(self, issuer_schema_id: u64) -> Credential
pub const fn issuer_schema_id(self, issuer_schema_id: u64) -> Credential
Set the issuerSchemaId of the credential.
Sourcepub const fn sub(self, sub: u64) -> Credential
pub const fn sub(self, sub: u64) -> Credential
Set the sub of the credential.
Sourcepub const fn genesis_issued_at(self, genesis_issued_at: u64) -> Credential
pub const fn genesis_issued_at(self, genesis_issued_at: u64) -> Credential
Set the genesis issued at of the credential.
Sourcepub const fn expires_at(self, expires_at: u64) -> Credential
pub const fn expires_at(self, expires_at: u64) -> Credential
Set the expires at of the credential.
Sourcepub fn claim(
self,
index: usize,
claim: Uint<256, 4>,
) -> Result<Credential, PrimitiveError>
pub fn claim( self, index: usize, claim: Uint<256, 4>, ) -> Result<Credential, PrimitiveError>
Sourcepub fn associated_data_hash(
self,
associated_data_hash: Uint<256, 4>,
) -> Result<Credential, PrimitiveError>
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.
Sourcepub fn get_cred_ds(&self) -> FieldElement
pub fn get_cred_ds(&self) -> FieldElement
Get the credential domain separator for the given version.
Trait Implementations§
Source§impl Clone for Credential
impl Clone for Credential
Source§fn clone(&self) -> Credential
fn clone(&self) -> Credential
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Credential
impl Debug for Credential
Source§impl Default for Credential
impl Default for Credential
Source§fn default() -> Credential
fn default() -> Credential
Source§impl<'de> Deserialize<'de> for Credential
impl<'de> Deserialize<'de> for Credential
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Credential, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Credential, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl HashableCredential for Credential
impl HashableCredential for Credential
Source§fn claims_hash(&self) -> Result<FieldElement, Error>
fn claims_hash(&self) -> Result<FieldElement, Error>
Source§fn hash(&self) -> Result<FieldElement, Error>
fn hash(&self) -> Result<FieldElement, Error>
Source§fn verify_signature(
&self,
expected_issuer_pubkey: &EdDSAPublicKey,
) -> Result<bool, Error>
fn verify_signature( &self, expected_issuer_pubkey: &EdDSAPublicKey, ) -> Result<bool, Error>
Source§impl Serialize for Credential
impl Serialize for Credential
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for Credential
impl RefUnwindSafe for Credential
impl Send for Credential
impl Sync for Credential
impl Unpin for Credential
impl UnwindSafe for Credential
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<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