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#[cfg(feature = "v4")]
66mod authenticator;
67#[cfg(feature = "v4")]
68pub use authenticator::{Authenticator, InitializingAuthenticator, RegistrationStatus};
69
70#[cfg(feature = "v4")]
71pub(crate) mod defaults;
72
73////////////////////////////////////////////////////////////////////////////////
74// Legacy modules
75////////////////////////////////////////////////////////////////////////////////
76
77/// Contains all components to interact and use a World ID
78pub mod world_id;
79
80/// This module handles World ID proof generation
81pub mod proof;
82
83/// This module exposes helper functions to interact with common apps & contracts related to the World ID Protocol.
84#[cfg(feature = "common-apps")]
85pub mod common_apps;
86
87////////////////////////////////////////////////////////////////////////////////
88// Private modules
89////////////////////////////////////////////////////////////////////////////////
90
91mod merkle_tree;
92mod request;
93
94uniffi::setup_scaffolding!("walletkit_core");