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::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
51pub(crate) mod primitives;
52
53mod credential_type;
54pub use credential_type::CredentialType;
55
56/// Contains error outputs from `WalletKit`
57pub mod error;
58
59/// Contains logging functionality that can be integrated with foreign language bindings.
60pub mod logger;
61
62mod u256;
63pub use u256::U256Wrapper;
64
65/// Credential storage primitives for World ID v4.
66#[cfg(feature = "storage")]
67pub mod storage;
68
69#[cfg(feature = "v4")]
70mod authenticator;
71#[cfg(feature = "v4")]
72pub use authenticator::{Authenticator, InitializingAuthenticator, RegistrationStatus};
73
74#[cfg(feature = "v4")]
75pub(crate) mod defaults;
76
77////////////////////////////////////////////////////////////////////////////////
78// Legacy modules
79////////////////////////////////////////////////////////////////////////////////
80
81/// Contains all components to interact and use a World ID
82pub mod world_id;
83
84/// This module handles World ID proof generation
85pub mod proof;
86
87/// This module exposes helper functions to interact with common apps & contracts related to the World ID Protocol.
88#[cfg(feature = "common-apps")]
89pub mod common_apps;
90
91////////////////////////////////////////////////////////////////////////////////
92// Private modules
93////////////////////////////////////////////////////////////////////////////////
94
95mod merkle_tree;
96mod request;
97
98uniffi::setup_scaffolding!("walletkit_core");