|
| 1 | +# Smile ID Rust Client |
| 2 | + |
| 3 | +A Rust client library for Smile ID's identity verification services across Africa. This library provides a simple interface to verify identities, prevent fraud, and comply with KYC regulations. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Basic KYC**: Verify identity information against government databases |
| 8 | +- **Enhanced KYC**: More comprehensive identity verification with additional data points |
| 9 | +- **Biometric KYC**: Identity verification with biometric data (selfie) |
| 10 | +- **Document Verification**: Verify identity documents like passports, ID cards, etc. |
| 11 | +- **SmartSelfie™ Authentication**: Authenticate users with facial biometrics |
| 12 | +- **Business Verification**: Verify business registration information |
| 13 | +- **Job Status Tracking**: Track the progress and outcome of verification jobs |
| 14 | + |
| 15 | +## Installation |
| 16 | + |
| 17 | +Add this to your `Cargo.toml`: |
| 18 | + |
| 19 | +```toml |
| 20 | +[dependencies] |
| 21 | +smile_id = "0.1.0" |
| 22 | +``` |
| 23 | + |
| 24 | +## Usage |
| 25 | + |
| 26 | +### Configuration |
| 27 | + |
| 28 | +```rust |
| 29 | +use smile_id::Config; |
| 30 | +use smile_id::ApiClient; |
| 31 | + |
| 32 | +// Create a configuration |
| 33 | +let config = Config::new("your-api-key", "your-partner-id") |
| 34 | + .with_timeout(60); // Optional: Set a custom timeout in seconds |
| 35 | + |
| 36 | +// Create an API client |
| 37 | +let client = ApiClient::new(config).expect("Failed to create API client"); |
| 38 | +``` |
| 39 | + |
| 40 | +### Basic KYC |
| 41 | + |
| 42 | +```rust |
| 43 | +use smile_id::products::BasicKyc; |
| 44 | + |
| 45 | +// Create a Basic KYC instance |
| 46 | +let basic_kyc = BasicKyc::new(client.clone()); |
| 47 | + |
| 48 | +// Submit a Basic KYC verification request |
| 49 | +let job_id = basic_kyc.verify( |
| 50 | + "PASSPORT", // ID type |
| 51 | + "AB123456", // ID number |
| 52 | + "NG", // Country code (ISO 3166-1 alpha-2) |
| 53 | + Some("John".to_string()), // First name (optional) |
| 54 | + Some("Doe".to_string()), // Last name (optional) |
| 55 | + Some("1990-01-01".to_string()), // Date of birth (optional) |
| 56 | +).await.expect("Failed to submit Basic KYC verification"); |
| 57 | + |
| 58 | +println!("Job ID: {}", job_id); |
| 59 | +``` |
| 60 | + |
| 61 | +### Enhanced KYC |
| 62 | + |
| 63 | +```rust |
| 64 | +use smile_id::products::EnhancedKyc; |
| 65 | + |
| 66 | +// Create an Enhanced KYC instance |
| 67 | +let enhanced_kyc = EnhancedKyc::new(client.clone()); |
| 68 | + |
| 69 | +// Submit an Enhanced KYC verification request |
| 70 | +let job_id = enhanced_kyc.verify( |
| 71 | + "PASSPORT", // ID type |
| 72 | + "AB123456", // ID number |
| 73 | + "NG", // Country code |
| 74 | + "John", // First name |
| 75 | + "Doe", // Last name |
| 76 | + "1990-01-01", // Date of birth |
| 77 | +).await.expect("Failed to submit Enhanced KYC verification"); |
| 78 | + |
| 79 | +println!("Job ID: {}", job_id); |
| 80 | +``` |
| 81 | + |
| 82 | +### Biometric KYC |
| 83 | + |
| 84 | +```rust |
| 85 | +use smile_id::products::BiometricKyc; |
| 86 | +use smile_id::utils; |
| 87 | + |
| 88 | +// Create a Biometric KYC instance |
| 89 | +let biometric_kyc = BiometricKyc::new(client.clone()); |
| 90 | + |
| 91 | +// Encode a selfie image as base64 |
| 92 | +let selfie_image = utils::encode_image_file("path/to/selfie.jpg") |
| 93 | + .expect("Failed to encode selfie image"); |
| 94 | + |
| 95 | +// Submit a Biometric KYC verification request |
| 96 | +let job_id = biometric_kyc.verify( |
| 97 | + "PASSPORT", // ID type |
| 98 | + "AB123456", // ID number |
| 99 | + "NG", // Country code |
| 100 | + "John", // First name |
| 101 | + "Doe", // Last name |
| 102 | + "1990-01-01", // Date of birth |
| 103 | + selfie_image, // Selfie image (base64 encoded) |
| 104 | +).await.expect("Failed to submit Biometric KYC verification"); |
| 105 | + |
| 106 | +println!("Job ID: {}", job_id); |
| 107 | +``` |
| 108 | + |
| 109 | +### Document Verification |
| 110 | + |
| 111 | +```rust |
| 112 | +use smile_id::products::DocumentVerification; |
| 113 | +use smile_id::utils; |
| 114 | + |
| 115 | +// Create a Document Verification instance |
| 116 | +let document_verification = DocumentVerification::new(client.clone()); |
| 117 | + |
| 118 | +// Encode document images as base64 |
| 119 | +let front_image = utils::encode_image_file("path/to/front.jpg") |
| 120 | + .expect("Failed to encode front image"); |
| 121 | +let back_image = utils::encode_image_file("path/to/back.jpg") |
| 122 | + .expect("Failed to encode back image"); |
| 123 | + |
| 124 | +// Submit a Document Verification request |
| 125 | +let job_id = document_verification.verify( |
| 126 | + "PASSPORT", // Document type |
| 127 | + "NG", // Country code |
| 128 | + vec![front_image, back_image], // Document images (base64 encoded) |
| 129 | +).await.expect("Failed to submit Document Verification"); |
| 130 | + |
| 131 | +println!("Job ID: {}", job_id); |
| 132 | +``` |
| 133 | + |
| 134 | +### SmartSelfie™ Authentication |
| 135 | + |
| 136 | +```rust |
| 137 | +use smile_id::products::SmartSelfieAuth; |
| 138 | +use smile_id::utils; |
| 139 | + |
| 140 | +// Create a SmartSelfie™ Authentication instance |
| 141 | +let smartselfie_auth = SmartSelfieAuth::new(client.clone()); |
| 142 | + |
| 143 | +// Encode a selfie image as base64 |
| 144 | +let selfie_image = utils::encode_image_file("path/to/selfie.jpg") |
| 145 | + .expect("Failed to encode selfie image"); |
| 146 | + |
| 147 | +// Submit a SmartSelfie™ Authentication request |
| 148 | +let job_id = smartselfie_auth.authenticate( |
| 149 | + "user-123", // User ID |
| 150 | + "job-456", // Job ID (from a previous verification) |
| 151 | + selfie_image, // Selfie image (base64 encoded) |
| 152 | +).await.expect("Failed to submit SmartSelfie™ Authentication"); |
| 153 | + |
| 154 | +println!("Job ID: {}", job_id); |
| 155 | +``` |
| 156 | + |
| 157 | +### Business Verification |
| 158 | + |
| 159 | +```rust |
| 160 | +use smile_id::products::BusinessVerification; |
| 161 | + |
| 162 | +// Create a Business Verification instance |
| 163 | +let business_verification = BusinessVerification::new(client.clone()); |
| 164 | + |
| 165 | +// Submit a Business Verification request |
| 166 | +let job_id = business_verification.verify( |
| 167 | + "Acme Inc", // Business name |
| 168 | + "RC123456", // Registration number |
| 169 | + "NG", // Country code |
| 170 | +).await.expect("Failed to submit Business Verification"); |
| 171 | + |
| 172 | +println!("Job ID: {}", job_id); |
| 173 | +``` |
| 174 | + |
| 175 | +### Job Status |
| 176 | + |
| 177 | +```rust |
| 178 | +// Get the status of a job |
| 179 | +let job_status = client.get_job_status( |
| 180 | + "user-123", // User ID |
| 181 | + "job-456", // Job ID |
| 182 | + Some(true), // Include history (optional) |
| 183 | + Some(true), // Include image links (optional) |
| 184 | +).await.expect("Failed to get job status"); |
| 185 | + |
| 186 | +println!("Job status: {:?}", job_status.job_status); |
| 187 | +println!("Job complete: {}", job_status.job_complete); |
| 188 | +println!("Job success: {}", job_status.job_success); |
| 189 | +``` |
| 190 | + |
| 191 | +### Blocking API |
| 192 | + |
| 193 | +The library also provides a blocking API for use in synchronous contexts: |
| 194 | + |
| 195 | +```rust |
| 196 | +use smile_id::config::Config; |
| 197 | +use smile_id::api::blocking::ApiClient; |
| 198 | +use smile_id::products::basic_kyc::blocking::BasicKyc; |
| 199 | + |
| 200 | +// Create a configuration |
| 201 | +let config = Config::new("your-api-key", "your-partner-id"); |
| 202 | + |
| 203 | +// Create a blocking API client |
| 204 | +let client = ApiClient::new(config).expect("Failed to create API client"); |
| 205 | + |
| 206 | +// Create a blocking Basic KYC instance |
| 207 | +let basic_kyc = BasicKyc::new(client.clone()); |
| 208 | + |
| 209 | +// Submit a Basic KYC verification request |
| 210 | +let job_id = basic_kyc.verify( |
| 211 | + "PASSPORT", // ID type |
| 212 | + "AB123456", // ID number |
| 213 | + "NG", // Country code |
| 214 | + Some("John".to_string()), // First name (optional) |
| 215 | + Some("Doe".to_string()), // Last name (optional) |
| 216 | + Some("1990-01-01".to_string()), // Date of birth (optional) |
| 217 | +).expect("Failed to submit Basic KYC verification"); |
| 218 | + |
| 219 | +println!("Job ID: {}", job_id); |
| 220 | +``` |
| 221 | + |
| 222 | +## License |
| 223 | + |
| 224 | +This project is licensed under the MIT License - see the LICENSE file for details. |
| 225 | + |
| 226 | +## Acknowledgments |
| 227 | + |
| 228 | +- [Smile ID](https://usesmileid.com) for their identity verification services |
| 229 | +- [Smile Identity Core JS](https://github.com/smileidentity/smile-identity-core-js) for the reference implementation |
0 commit comments