Skip to main content

walletkit_core/
lib.rs

1//! `walletkit-core` contains the basic primitives for using a World ID.
2//! It enables basic usage of a World ID to generate ZKPs using different credentials.
3//!
4//! # Examples
5//! ```rust
6//! use walletkit_core::{proof::ProofContext, CredentialType, Environment, world_id::WorldId};
7//! async fn example() {
8//!     let world_id = WorldId::new(b"not_a_real_secret", &Environment::Staging);
9//!     let context = ProofContext::new("app_ce4cb73cb75fc3b73b71ffb4de178410", Some("my_action".to_string()), None, CredentialType::Orb);
10//!     let proof = world_id.generate_proof(&context).await.unwrap();
11//!     println!("{}", proof.to_json().unwrap()); // the JSON output can be passed to the Developer Portal, World ID contracts, etc. for verification
12//! }
13//! ```
14#![deny(
15    clippy::all,
16    clippy::pedantic,
17    clippy::nursery,
18    missing_docs,
19    dead_code
20)]
21
22use strum::{Display, EnumString};
23
24/// Library initialization function called automatically on load.
25///
26/// Installs the ring crypto provider as the default for rustls.
27/// Uses the `ctor` crate to ensure this runs when the dynamic library loads,
28/// before any user code executes.
29#[cfg(not(test))]
30#[ctor::ctor]
31fn init() {
32    rustls::crypto::ring::default_provider()
33        .install_default()
34        .expect("Failed to install default crypto provider");
35}
36
37/// Represents the environment in which a World ID is being presented and used.
38///
39/// Each environment uses different sources of truth for the World ID credentials.
40///
41/// More information on testing for the World ID Protocol can be found in: `https://docs.world.org/world-id/quick-start/testing`
42#[derive(Debug, Clone, PartialEq, Eq, EnumString, uniffi::Enum)]
43#[strum(serialize_all = "lowercase")]
44pub enum Environment {
45    /// For testing purposes ONLY.
46    Staging,
47    /// Live production environment. World ID Tree: `id.worldcoin.eth`
48    Production,
49}
50
51/// Region for node selection.
52#[derive(
53    Debug, Clone, Copy, PartialEq, Eq, Default, uniffi::Enum, EnumString, Display,
54)]
55#[strum(serialize_all = "lowercase")]
56pub enum Region {
57    /// United States
58    Us,
59    /// Europe (default)
60    #[default]
61    Eu,
62    /// Asia-Pacific
63    Ap,
64}
65
66pub(crate) mod primitives;
67
68mod credential_type;
69pub use credential_type::CredentialType;
70
71/// Contains error outputs from `WalletKit`
72pub mod error;
73
74/// Contains logging functionality that can be integrated with foreign language bindings.
75pub mod logger;
76
77mod u256;
78pub use u256::U256Wrapper;
79
80mod field_element;
81pub use field_element::FieldElement;
82
83mod credential;
84pub use credential::Credential;
85
86/// Credential storage primitives for World ID v4.
87#[cfg(feature = "storage")]
88pub mod storage;
89
90mod authenticator;
91pub use authenticator::{Authenticator, InitializingAuthenticator, RegistrationStatus};
92
93/// Default configuration values for each [`Environment`].
94pub mod defaults;
95
96pub mod requests;
97
98////////////////////////////////////////////////////////////////////////////////
99// Legacy modules
100////////////////////////////////////////////////////////////////////////////////
101
102/// Contains all components to interact and use a World ID
103pub mod world_id;
104
105/// This module handles World ID proof generation
106pub mod proof;
107
108/// This module exposes helper functions to interact with common apps & contracts related to the World ID Protocol.
109#[cfg(feature = "common-apps")]
110pub mod common_apps;
111
112/// Credential issuers for World ID (NFC, etc.)
113#[cfg(feature = "issuers")]
114pub mod issuers;
115
116////////////////////////////////////////////////////////////////////////////////
117// Private modules
118////////////////////////////////////////////////////////////////////////////////
119
120mod http_request;
121mod merkle_tree;
122
123uniffi::setup_scaffolding!("walletkit_core");