pub struct Authenticator {
pub config: Config,
pub packed_account_data: U256,
/* private fields */
}Expand description
An Authenticator is the base layer with which a user interacts with the Protocol.
Fields§
§config: ConfigGeneral configuration for the Authenticator.
packed_account_data: U256The packed account data for the holder’s World ID is a uint256 defined in the WorldIDRegistry contract as:
recovery_counter (32 bits) | pubkey_id (commitment to all off-chain public keys) (32 bits) | leaf_index (192 bits)
Implementations§
Source§impl Authenticator
impl Authenticator
Sourcepub async fn init(
seed: &[u8],
config: Config,
) -> Result<Self, AuthenticatorError>
pub async fn init( seed: &[u8], config: Config, ) -> Result<Self, AuthenticatorError>
Initialize an Authenticator from a seed and config.
This method will error if the World ID account does not exist on the registry.
§Errors
- Will error if the provided seed is invalid (not 32 bytes).
- Will error if the RPC URL is invalid.
- Will error if there are contract call failures.
- Will error if the account does not exist (
AccountDoesNotExist).
Sourcepub async fn register(
seed: &[u8],
config: Config,
recovery_address: Option<Address>,
) -> Result<InitializingAuthenticator, AuthenticatorError>
pub async fn register( seed: &[u8], config: Config, recovery_address: Option<Address>, ) -> Result<InitializingAuthenticator, AuthenticatorError>
Registers a new World ID in the WorldIDRegistry.
Given the registration process is asynchronous, this method will return a InitializingAuthenticator
object.
§Errors
- See
initfor additional error details.
Sourcepub async fn init_or_register(
seed: &[u8],
config: Config,
recovery_address: Option<Address>,
) -> Result<Self, AuthenticatorError>
pub async fn init_or_register( seed: &[u8], config: Config, recovery_address: Option<Address>, ) -> Result<Self, AuthenticatorError>
Initializes (if the World ID already exists in the registry) or registers a new World ID.
The registration process is asynchronous and may take some time. This method will block the thread until the registration is in a final state (success or terminal error). For better user experience in end authenticator clients, it is recommended to implement custom polling logic.
Explicit init or register calls are also recommended as the authenticator should know
if a new World ID should be truly created. For example, an authenticator may have been revoked
access to an existing World ID.
§Errors
- See
initfor additional error details.
Sourcepub async fn get_packed_account_data(
onchain_signer_address: Address,
registry: Option<&WorldIdRegistryInstance<DynProvider>>,
config: &Config,
http_client: &Client,
) -> Result<U256, AuthenticatorError>
pub async fn get_packed_account_data( onchain_signer_address: Address, registry: Option<&WorldIdRegistryInstance<DynProvider>>, config: &Config, http_client: &Client, ) -> Result<U256, AuthenticatorError>
Returns the packed account data for the holder’s World ID.
The packed account data is a 256 bit integer which includes the World ID’s leaf index, their recovery counter, and their pubkey id/commitment.
§Errors
Will error if the network call fails or if the account does not exist.
Sourcepub const fn onchain_address(&self) -> Address
pub const fn onchain_address(&self) -> Address
Returns the k256 public key of the Authenticator signer which is used to verify on-chain operations,
chiefly with the WorldIdRegistry contract.
Sourcepub fn offchain_pubkey(&self) -> EdDSAPublicKey
pub fn offchain_pubkey(&self) -> EdDSAPublicKey
Returns the EdDSA public key of the Authenticator signer which is used to verify off-chain operations. For example,
the Nullifier Oracle uses it to verify requests for nullifiers.
Sourcepub fn offchain_pubkey_compressed(&self) -> Result<U256, AuthenticatorError>
pub fn offchain_pubkey_compressed(&self) -> Result<U256, AuthenticatorError>
Returns the compressed EdDSA public key of the Authenticator signer which is used to verify off-chain operations.
For example, the Nullifier Oracle uses it to verify requests for nullifiers.
§Errors
Will error if the public key cannot be serialized.
Sourcepub fn registry(&self) -> Option<Arc<WorldIdRegistryInstance<DynProvider>>>
pub fn registry(&self) -> Option<Arc<WorldIdRegistryInstance<DynProvider>>>
Returns a reference to the WorldIdRegistry contract instance.
Sourcepub fn leaf_index(&self) -> U256
pub fn leaf_index(&self) -> U256
Returns the account index for the holder’s World ID.
This is the index at the Merkle tree where the holder’s World ID account is registered.
Sourcepub fn recovery_counter(&self) -> U256
pub fn recovery_counter(&self) -> U256
Returns the recovery counter for the holder’s World ID.
The recovery counter is used to efficiently invalidate all the old keys when an account is recovered.
Sourcepub fn pubkey_id(&self) -> U256
pub fn pubkey_id(&self) -> U256
Returns the pubkey id (or commitment) for the holder’s World ID.
This is a commitment to all the off-chain public keys that are authorized to act on behalf of the holder.
Sourcepub async fn fetch_inclusion_proof(
&self,
) -> Result<(MerkleInclusionProof<TREE_DEPTH>, AuthenticatorPublicKeySet), AuthenticatorError>
pub async fn fetch_inclusion_proof( &self, ) -> Result<(MerkleInclusionProof<TREE_DEPTH>, AuthenticatorPublicKeySet), AuthenticatorError>
Fetches a Merkle inclusion proof for the holder’s World ID given their account index.
§Errors
- Will error if the provided indexer URL is not valid or if there are HTTP call failures.
- Will error if the user is not registered on the registry.
Sourcepub async fn signing_nonce(&self) -> Result<U256, AuthenticatorError>
pub async fn signing_nonce(&self) -> Result<U256, AuthenticatorError>
Returns the signing nonce for the holder’s World ID.
§Errors
Will return an error if the registry contract call fails.
Sourcepub async fn generate_proof(
&self,
proof_request: ProofRequest,
credential: Credential,
credential_sub_blinding_factor: FieldElement,
) -> Result<(Proof<Bn254>, FieldElement), AuthenticatorError>
pub async fn generate_proof( &self, proof_request: ProofRequest, credential: Credential, credential_sub_blinding_factor: FieldElement, ) -> Result<(Proof<Bn254>, FieldElement), AuthenticatorError>
Generates a single World ID Proof from a provided [ProofRequest] and [Credential].
This assumes the Authenticator has already parsed the [ProofRequest] and determined
which [Credential] is appropriate for the request.
§Errors
- Will error if the any of the provided parameters are not valid.
- Will error if any of the required network requests fail.
- Will error if the user does not have a registered World ID.
Sourcepub async fn insert_authenticator(
&mut self,
new_authenticator_pubkey: EdDSAPublicKey,
new_authenticator_address: Address,
) -> Result<String, AuthenticatorError>
pub async fn insert_authenticator( &mut self, new_authenticator_pubkey: EdDSAPublicKey, new_authenticator_address: Address, ) -> Result<String, AuthenticatorError>
Sourcepub async fn update_authenticator(
&mut self,
old_authenticator_address: Address,
new_authenticator_address: Address,
new_authenticator_pubkey: EdDSAPublicKey,
index: u32,
) -> Result<String, AuthenticatorError>
pub async fn update_authenticator( &mut self, old_authenticator_address: Address, new_authenticator_address: Address, new_authenticator_pubkey: EdDSAPublicKey, index: u32, ) -> Result<String, AuthenticatorError>
Updates an existing authenticator slot with a new authenticator.
§Errors
Returns an error if the gateway rejects the request or a network error occurs.
§Note
TODO: After successfully updating an authenticator, the packed_account_data should be
refreshed from the registry to reflect the new pubkey_id commitment.
Sourcepub async fn remove_authenticator(
&mut self,
authenticator_address: Address,
index: u32,
) -> Result<String, AuthenticatorError>
pub async fn remove_authenticator( &mut self, authenticator_address: Address, index: u32, ) -> Result<String, AuthenticatorError>
Trait Implementations§
Source§impl Debug for Authenticator
impl Debug for Authenticator
Source§impl ProtocolSigner for Authenticator
impl ProtocolSigner for Authenticator
Source§fn sign(&self, message: FieldElement) -> EdDSASignature
fn sign(&self, message: FieldElement) -> EdDSASignature
EdDSA scheme (off-chain signer), for use
with the Protocol ZK circuits.Auto Trait Implementations§
impl Freeze for Authenticator
impl !RefUnwindSafe for Authenticator
impl Send for Authenticator
impl Sync for Authenticator
impl Unpin for Authenticator
impl !UnwindSafe for Authenticator
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> 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