pub struct Credential {
pub id: u64,
pub version: CredentialVersion,
pub issuer_schema_id: u64,
pub sub: FieldElement,
pub genesis_issued_at: u64,
pub expires_at: u64,
pub claims: Vec<FieldElement>,
pub associated_data_commitment: 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.
§Credential Lifecycle
The following official terminology is defined for the lifecycle of a Credential.
- Issuance (can also be called Enrollment): Process by which a credential is initially issued to a user.
- Renewal: Process by which a user requests a new Credential from a previously existing active or expired Credential. This usually happens close to Credential expiration. It is analogous to when you request a renewal of your passport, you get a new passport with a new expiration date.
- Re-Issuance: Process by which a user obtains a copy of their existing Credential. The copy does not need to be exact, but the original expiration date MUST be preserved. This usually occurs when a user accidentally lost their Credential (e.g. disk failure, authenticator loss) and needs to recover for an existing period.
§Associated Data
Credentials have a pre-defined strict structure, which is determined by their version. Issuers may opt to include additional arbitrary data with the Credential (Associated Data). This arbitrary data can be used to support the issuer in the operation of their Credential (for example it may contain an identifier to allow credential refresh).
- Associated data is stored by Authenticators with the Credential.
- Introducing associated data is a decision by the issuer. Its structure and content is solely determined by the issuer and the data will not be exposed to RPs or others.
- An example of associated data use is supporting data to re-issue a credential (e.g. a sign up number).
- Associated data is never exposed to RPs or others. It only lives in the Authenticator and may be provided to issuers.
- Associated data is authenticated in the Credential through the
associated_data_commitmentfield. The issuer MUST determine how this commitment is computed. Issuers may opt to use theCredential::associated_data_commitment_from_raw_byteshelper to ensure their raw data is committed, but other commitment mechanisms may make sense depending on the structure of the associated data.
+------------------------------------+
| Credential |
| |
| - associated_data_commitment <----+
| - signature |
+------------------------------------+
^
|
Commitment(associated_data)
|
Associated Data
+------------------------------------+
| Optional arbitrary data |
+------------------------------------+§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§
§id: u64A reference identifier for the credential. This can be used by issuers to manage credential lifecycle.
- This ID is never exposed or used outside of issuer scope. It is never part of proofs or exposed to RPs.
- Generally, it is recommended to maintain the default of a random identifier.
§Example Uses
- Track issued credentials to later support revocation after refreshing.
version: CredentialVersionThe version of the Credential determines its structure.
issuer_schema_id: u64Unique issuer schema id represents the unique combination of the credential’s schema and the issuer.
The issuer_schema_id is registered in the CredentialSchemaIssuerRegistry. With this
identifier, the RPs lookup the authorized keys that can sign the credential.
sub: FieldElementThe blinded subject (World ID) for which the credential is issued.
The underlying identifier comes from the WorldIDRegistry and is
the leaf_index of the World ID on the Merkle tree. However, this is blinded
for each issuer_schema_id with a blinding factor to prevent correlation of credentials
by malicious issuers. See Self::compute_sub for details on how the credential blinding factor
is computed.
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.
This timestamp can be queried (only as a minimum value) by RPs.
expires_at: u64Expiration timestamp (unix seconds)
claims: Vec<FieldElement>For Future Use. Concrete statements that the issuer attests about the receiver.
They can be just commitments to data (e.g. passport image) or the value directly (e.g. date of birth).
Currently these statements are not in use in the Proofs yet.
associated_data_commitment: FieldElementThe commitment to the Associated Data issued with the Credential.
This may use a common hashing algorithm from the raw bytes of the
asscociated data and one function is exposed for this convenience,
hash_bytes_to_field_element. Each issuer however determines how
best to construct this value to establish the integrity of their Associated Data.
This commitment is only for issuer use.
signature: Option<EdDSASignature>The signature of the credential (signed by the issuer’s key)
issuer: EdDSAPublicKeyThe public component of the issuer’s key which signed the Credential.
Implementations§
Source§impl Credential
impl Credential
Sourcepub const MAX_CLAIMS: usize = 16
pub const MAX_CLAIMS: usize = 16
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 id(self, id: u64) -> Credential
pub const fn id(self, id: u64) -> Credential
Set the id of the credential.
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 subject(self, sub: FieldElement) -> Credential
pub const fn subject(self, sub: FieldElement) -> Credential
Set the sub for 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_hash(
self,
index: usize,
claim: Uint<256, 4>,
) -> Result<Credential, PrimitiveError>
pub fn claim_hash( self, index: usize, claim: Uint<256, 4>, ) -> Result<Credential, PrimitiveError>
Sourcepub fn claim(
self,
index: usize,
claim: &[u8],
) -> Result<Credential, PrimitiveError>
pub fn claim( self, index: usize, claim: &[u8], ) -> Result<Credential, PrimitiveError>
Set the claim hash at specific index by hashing arbitrary bytes using Poseidon2.
This method accepts arbitrary bytes, converts them to field elements, applies a Poseidon2 hash, and stores the result as claim at the provided index.
§Arguments
claim- Arbitrary bytes to hash (any length).
§Errors
Will error if the data is empty and if the index is out of bounds.
Sourcepub fn associated_data_commitment(
self,
associated_data_commitment: Uint<256, 4>,
) -> Result<Credential, PrimitiveError>
pub fn associated_data_commitment( self, associated_data_commitment: Uint<256, 4>, ) -> Result<Credential, PrimitiveError>
Set the associated data commitment of the credential.
§Errors
Will error if the provided hash cannot be lowered into the field.
Sourcepub fn associated_data_commitment_from_raw_bytes(
self,
data: &[u8],
) -> Result<Credential, PrimitiveError>
pub fn associated_data_commitment_from_raw_bytes( self, data: &[u8], ) -> Result<Credential, PrimitiveError>
Set the associated data commitment from arbitrary bytes. This can be used to construct the associated data commitment in a canonical way.
This method takes arbitrary bytes, converts them to field elements, applies a Poseidon2 hash, and stores the result as the associated data commitment.
§Arguments
data- Arbitrary bytes to be committed (any length).
§Errors
Will error if the data is empty.
Sourcepub fn get_cred_ds(&self) -> FieldElement
pub fn get_cred_ds(&self) -> FieldElement
Get the credential domain separator for the given version.
Sourcepub fn claims_hash(&self) -> Result<FieldElement, Report>
pub fn claims_hash(&self) -> Result<FieldElement, Report>
Get the claims hash of the credential.
§Errors
Will error if there are more claims than the maximum allowed. Will error if the claims cannot be lowered into the field. Should not occur in practice.
Sourcepub fn hash(&self) -> Result<FieldElement, Report>
pub fn hash(&self) -> Result<FieldElement, Report>
Computes the canonical hash of the Credential.
The hash is signed by the issuer to provide authenticity for the credential.
§Errors
- Will error if there are more claims than the maximum allowed.
- Will error if the claims cannot be lowered into the field. Should not occur in practice.
Sourcepub fn sign(self, signer: &EdDSAPrivateKey) -> Result<Credential, Report>
pub fn sign(self, signer: &EdDSAPrivateKey) -> Result<Credential, Report>
Sourcepub fn verify_signature(
&self,
expected_issuer_pubkey: &EdDSAPublicKey,
) -> Result<bool, Report>
pub fn verify_signature( &self, expected_issuer_pubkey: &EdDSAPublicKey, ) -> Result<bool, Report>
Verify the signature of the credential against the issuer public key and expected hash.
§Errors
Will error if the credential is not signed. Will error if the credential cannot be hashed.
Sourcepub fn compute_sub(
leaf_index: u64,
blinding_factor: FieldElement,
) -> FieldElement
pub fn compute_sub( leaf_index: u64, blinding_factor: FieldElement, ) -> FieldElement
Compute the sub for a credential computed from leaf_index and a blinding_factor.
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 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 UnsafeUnpin 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