Commit dd5f8d7
authored
Dev (#2)
* Add initial Cargo.toml for Smile ID Rust client with dependencies and metadata
* Feat: Implement Basic KYC Service
This commit introduces the basic_kyc module, providing functionality to perform basic Know Your Customer (KYC) verifications via the Smile ID API.
Key features include:
BasicKyc struct: Encapsulates the API client for interacting with the Basic KYC endpoint.
verify method (asynchronous):
Takes id_type, id_number, country, and optional first_name, last_name, dob as input.
Constructs a BasicKycRequest object.
Sends a POST request to the /basic_kyc endpoint.
Deserializes the API response into a VerifyResponse.
Returns the job_id from the successful verification.
VerifyResponse struct: A private struct to capture the job_id from the API response.
blocking module (feature-gated):
Provides a synchronous counterpart to the BasicKyc service and its verify method.
Allows users to perform Basic KYC verification without requiring async/await in their application logic when the blocking feature is enabled.
This implementation enables seamless integration with Smile ID's basic KYC capabilities, allowing for direct verification requests and retrieval of the associated job ID.
* Feat: Implement Authentication Signature Generation and Verification
This commit introduces the auth module, providing core functionality for generating and verifying HMAC-SHA256 signatures used to secure communications with the Smile ID API.
Key features include:
Auth struct: Stores the api_key and partner_id necessary for authentication.
new constructor: Initializes a new Auth instance.
generate_signature method:
Takes a chrono::DateTime<Utc> timestamp and a payload string.
Constructs the message string by concatenating partner_id, RFC3339-formatted timestamp, and the payload.
Computes an HMAC-SHA256 hash using the api_key as the secret.
Encodes the resulting hash in standard Base64.
Returns the generated Base64-encoded signature string.
verify_signature method:
Takes a provided signature string, timestamp, and payload.
Generates an expected signature using its internal generate_signature method.
Compares the provided signature with the expected one to verify authenticity.
Returns true if signatures match, false otherwise.
partner_id getter: Provides read-only access to the stored partner_id.
This module is fundamental for ensuring the integrity and authenticity of requests and responses within the Smile ID SDK.
* Feat: Implement API Client with Authentication and Job Status
This commit introduces the ApiClient structure, serving as the central HTTP client for interacting with the Smile ID API. It incorporates authentication mechanisms and provides a method for retrieving job statuses.
Key features and components:
ApiClient struct:
Holds a reqwest::Client for making HTTP requests, an Auth instance for signature generation, and the Config for base URL and other settings.
The new constructor initializes reqwest::Client with a configurable timeout and sets up the Auth component using the provided API key and partner ID.
get_job_status method (asynchronous):
Constructs a JobStatusRequest with user_id, job_id, and optional flags for include_history and include_image_links.
Builds the full API endpoint URL for job status.
Delegates the actual HTTP POST request to the generic post method.
post method (asynchronous and generic):
Handles the common logic for sending POST requests to the Smile ID API.
Generates a UTC timestamp.
Serializes the payload into a JSON string.
Generates an HMAC-SHA256 signature using the Auth module and the serialized payload.
Sets essential HTTP headers: Content-Type, X-Smile-Partner-ID, X-Smile-Signature, and X-Smile-Timestamp.
Sends the POST request and handles potential HTTP errors (network issues, non-success status codes).
Deserializes the response body into a generic ApiResponse<R>, performing an additional check for application-level API errors indicated by ApiResponse.status_code >= 400.
Returns the data field of the successful ApiResponse.
base_url method: A helper to construct the full base URL including the API version.
blocking module (feature-gated):
Provides a synchronous version of the ApiClient and its methods, useful for applications that do not use an asynchronous runtime.
Mirrors the asynchronous functionality using reqwest::blocking::Client.
This ApiClient forms the backbone of the SDK, centralizing request signing, error handling, and basic API interactions.
* Feat: Implement SDK Configuration Structure
This commit introduces the Config struct, which centralizes the configuration parameters for the Smile ID Rust SDK.
Key features and components:
Config struct:
api_key: Stores the API key for authentication.
partner_id: Stores the Partner ID for authentication.
base_url: Defines the base URL for Smile ID API requests, with a default of "https://api.usesmileid.com".
version: Specifies the API version, with a default of "1.0".
timeout: Sets the HTTP request timeout in seconds, with a default of 30 seconds.
new method:
A constructor that takes api_key and partner_id as mandatory arguments.
Initializes base_url, version, and timeout with sensible default values.
Builder methods (with_base_url, with_version, with_timeout):
These methods implement a fluent API (builder pattern) to allow for optional customization of the Config parameters.
They consume self and return Self, enabling method chaining for easy configuration.
This Config struct provides a flexible and idiomatic way for users to set up their Smile ID client, allowing for both quick defaults and fine-grained control over connection parameters.
* Feat: Introduce Comprehensive Error Handling
This commit establishes a robust error handling system for the SDK by defining a custom Error enum using the thiserror crate. This approach centralizes error types and provides clear, user-friendly messages.
Key features:
Error Enum: A top-level enum categorizing various types of errors that can occur during SDK operations:
Http(reqwest::Error): For underlying HTTP client errors, with automatic conversion using #[from].
Json(serde_json::Error): For JSON serialization/deserialization errors, with automatic conversion using #[from].
Api { status_code: u16, message: String }: For errors returned directly by the Smile ID API, including the HTTP status code and an API-specific message.
Auth(String): For issues related to authentication (e.g., failed HMAC creation).
Config(String): For problems with SDK configuration.
SignatureVerification(String): Specifically for errors encountered during signature validation.
InvalidParameter(String): For cases where provided input parameters are invalid.
Other(String): A generic fallback for any unhandled or miscellaneous errors.
Result<T> Type Alias: Defines a convenient type alias pub type Result<T> = std::result::Result<T, Error>; to simplify function signatures across the SDK.
This structured error handling improves the maintainability, readability, and usability of the SDK by providing distinct error types that can be pattern-matched and handled appropriately by consumers.
* Feat: Initial Rust SDK Module Structure and Public API
This commit lays the foundation for the Smile ID Rust SDK by defining its top-level module structure and publicly exposing key components.
Changes include:
Module Declarations: Declares all sub-modules (api, auth, config, error, models, products, utils) within the lib.rs file, establishing the overall organization of the SDK.
Public Re-exports: Uses pub use to make essential structs, enums, and traits from internal modules directly accessible at the top level of the smileid crate. This simplifies imports for users, allowing them to write use smileid::Config; instead of use smileid::config::Config;.
api::ApiClient
auth::Auth
config::Config
error::{Error, Result}
models::* (all public items from models)
products::* (all public items from products)
prelude Module: Introduces a pub mod prelude to offer a convenient, opinionated set of common imports. Users can use smileid::prelude::*; to bring commonly used items into scope with a single line, following a common Rust library pattern.
Basic Test Setup: Includes a basic #[cfg(test)] block with an it_works test, indicating the initial setup for unit testing within the library.
This commit sets up the ergonomic and organized structure for the Smile ID Rust SDK, making it easier for developers to consume and integrate.
* Feat: Define API Request and Response Models
This commit introduces the models module, centralizing the data structures (structs and enums) used for serializing requests to and deserializing responses from the Smile ID API. These models are annotated with serde attributes for automatic JSON conversion.
Key models included:
ApiResponse<T>: A generic top-level response wrapper that handles common API response fields like status_code and message, while using #[serde(flatten)] to embed the specific data payload for each endpoint.
JobStatusResponse: Details the comprehensive response for a job status query, including job_id, job_status, job_complete, job_success, and optional fields like history and image_links.
JobStatus Enum: Represents the various states a Smile ID job can be in (Pending, InProgress, Completed, Failed), using #[serde(rename_all = "SCREAMING_SNAKE_CASE")] for correct JSON mapping.
JobHistoryItem: A sub-model for entries within a job's history.
Request Models: Specific structs for various API requests, ensuring correct data formatting:
BasicKycRequest
EnhancedKycRequest
BiometricKycRequest
DocumentVerificationRequest
SmartSelfieAuthRequest
BusinessVerificationRequest
JobStatusRequest
These request structs utilize #[serde(skip_serializing_if = "Option::is_none")] for optional fields, preventing them from being included in the JSON payload if they are None.
This module provides a strongly typed and consistent interface for interacting with the Smile ID API, leveraging serde for efficient and reliable data serialization and deserialization.
* Feat: Implement Utility Functions for Image Encoding and Date Formatting
This commit introduces the utils module, providing helpful utility functions for common tasks within the SDK, specifically for handling images and formatting dates.
Key functions included:
encode_image_file(path: impl AsRef<Path>) -> Result<String>:
Reads an image file from the given path.
Encodes the file's content into a Base64 string using base64::engine::general_purpose::STANDARD.
Returns a Result containing the Base64 string or an Error if the file cannot be opened or read.
encode_image_bytes(bytes: &[u8]) -> String:
Encodes a raw byte slice directly into a Base64 string.
This is useful when image data is already in memory.
format_date(year: u16, month: u8, day: u8) -> String:
Formats a given year, month, and day into a YYYY-MM-DD string format.
Ensures two-digit padding for month and day for consistent output.
These utilities streamline common data preparation steps required for interacting with the Smile ID API, improving convenience and reducing boilerplate code for SDK users.
* Feat: Implement Biometric KYC Service
This commit introduces the biometric_kyc module, providing functionality to perform biometric Know Your Customer (KYC) verifications via the Smile ID API. This type of KYC typically involves verifying a user's identity against their biometric data (e.g., a selfie) in addition to provided identity document details.
Key features include:
BiometricKyc struct: Encapsulates the API client (ApiClient) specific to this service.
new constructor: Initializes a new BiometricKyc instance with a given ApiClient.
verify method (asynchronous):
Takes id_type, id_number, country, first_name, last_name, dob, and selfie_image (Base64 encoded) as input. These fields are all mandatory for a biometric KYC request.
Constructs a BiometricKycRequest object from the provided parameters.
Sends an HTTP POST request to the /biometric_kyc endpoint using the internal ApiClient.
Expects and deserializes the API response into an ApiResponse<VerifyResponse>.
Returns the job_id from the successful verification, which can then be used to query the status of the job.
VerifyResponse struct: A private helper struct used to parse the immediate response from the /biometric_kyc endpoint, primarily to extract the job_id.
blocking module (feature-gated):
Provides a synchronous variant of the BiometricKyc service and its verify method.
This allows users to integrate biometric KYC functionality in applications that do not use an asynchronous runtime, when the blocking feature is enabled.
This implementation enables seamless integration with Smile ID's biometric KYC capabilities, facilitating robust identity verification processes that leverage both document data and biometrics.
* Feat: Implement Business Verification Service
This commit introduces the business_verification module, providing functionality to perform business verification checks through the Smile ID API. This service allows for verifying business entities against official registries.
Key features include:
BusinessVerification struct: Encapsulates the ApiClient necessary to interact with the Business Verification endpoint.
new constructor: Initializes a new BusinessVerification instance.
verify method (asynchronous):
Accepts business_name, registration_number, and country as required parameters.
Constructs a BusinessVerificationRequest with the provided details.
Sends a POST request to the /business_verification API endpoint.
Parses the API response, extracting and returning the job_id for tracking the verification process.
VerifyResponse struct: A private struct to specifically handle the immediate response from the /business_verification endpoint, primarily used to retrieve the job_id.
blocking module (feature-gated):
Includes a synchronous version of the BusinessVerification service and its verify method.
This enables usage in contexts that do not require or support async/await, provided the blocking feature is enabled.
This implementation allows the SDK to seamlessly integrate with Smile ID's Business Verification product, facilitating automated checks of business credentials.
* Feat: Implement Document Verification Service
This commit introduces the document_verification module, providing functionality to perform document verification through the Smile ID API. This service allows for the submission and processing of identity document images for verification.
Key features include:
DocumentVerification struct: Encapsulates the ApiClient to interact specifically with the Document Verification endpoint.
new constructor: Initializes a new DocumentVerification instance.
verify method (asynchronous):
Accepts document_type, country, and a Vec<String> of Base64-encoded document_images as parameters.
Constructs a DocumentVerificationRequest using these inputs.
Sends an HTTP POST request to the /document_verification API endpoint.
Parses the API response, extracting and returning the job_id for subsequent status tracking.
VerifyResponse struct: A private helper struct to deserialize the immediate response from the API, specifically to capture the job_id.
blocking module (feature-gated):
Provides a synchronous counterpart to the DocumentVerification service and its verify method.
Enables use in contexts that do not utilize async/await when the blocking feature is enabled.
This implementation allows the SDK to integrate seamlessly with Smile ID's Document Verification product, facilitating automated validation of identity documents
* Feat: Implement Enhanced KYC Service
This commit introduces the enhanced_kyc module, providing functionality to perform more rigorous Know Your Customer (KYC) verifications via the Smile ID API. Enhanced KYC typically involves gathering more detailed information and performing deeper checks compared to basic KYC, often for higher-risk individuals or transactions.
Key features include:
EnhancedKyc struct: Encapsulates the ApiClient necessary to interact with the Enhanced KYC endpoint.
new constructor: Initializes a new EnhancedKyc instance.
verify method (asynchronous):
Takes id_type, id_number, country, first_name, last_name, and dob as mandatory parameters. This reflects the more comprehensive data requirements of Enhanced KYC.
Constructs an EnhancedKycRequest with the provided details.
Sends an HTTP POST request to the /enhanced_kyc API endpoint.
Parses the API response, extracting and returning the job_id for subsequent status tracking.
VerifyResponse struct: A private helper struct to deserialize the immediate response from the API, specifically to capture the job_id.
blocking module (feature-gated):
Provides a synchronous counterpart to the EnhancedKyc service and its verify method.
Enables use in contexts that do not utilize async/await when the blocking feature is enabled.
This implementation allows the SDK to integrate seamlessly with Smile ID's Enhanced KYC product, facilitating robust and detailed identity verification processes.
* Feat: Implement SmartSelfie Authentication Service
This commit introduces the smartselfie_auth module, providing functionality to authenticate users using their SmartSelfie against a previously verified identity via the Smile ID API.
Key features include:
SmartSelfieAuth struct: Encapsulates the ApiClient for interacting with the SmartSelfie Authentication endpoint.
new constructor: Initializes a new SmartSelfieAuth instance.
authenticate method (asynchronous):
Takes user_id, job_id (referencing a previous verification job), and selfie_image (Base64 encoded) as parameters.
Constructs a SmartSelfieAuthRequest with these details.
Sends an HTTP POST request to the /smartselfie_auth API endpoint.
Parses the API response, extracting and returning the job_id for status tracking of the authentication attempt.
AuthResponse struct: A private helper struct to deserialize the immediate response from the API, specifically to capture the job_id.
blocking module (feature-gated):
Provides a synchronous counterpart to the SmartSelfieAuth service and its authenticate method.
Enables use in contexts that do not utilize async/await when the blocking feature is enabled.
This implementation allows the SDK to integrate seamlessly with Smile ID's SmartSelfie Authentication product, facilitating secure re-authentication or verification against existing user profiles.
* Feat: Organize Product Services
This commit introduces the products module, which serves as a central hub for all Smile ID verification and authentication product services.
Key changes:
Module Declarations: Declares individual sub-modules for each Smile ID product (basic_kyc, enhanced_kyc, biometric_kyc, document_verification, smartselfie_auth, business_verification).
Public Re-exports: Uses pub use to make the main service structs from each product module directly accessible from the products module. This simplifies the import paths for SDK users, allowing them to access these services directly (e.g., products::BasicKyc).
This organization improves the modularity and discoverability of the different verification and authentication services offered by the SDK.
* removed autobuild build mode changed to none1 parent a8f1feb commit dd5f8d7
File tree
17 files changed
+1053
-2
lines changed- .github/workflows
- src
- products
17 files changed
+1053
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
0 commit comments