Sila Banking API for Rust
This crate is intended to reduce the effort necessary by Rust developers to integrate their applications with the Sila Banking API.
This is an early work-in-progress. Work is currently focused on establishing the framework for interacting with the API and beginning to build modules specific to functionality provided by the Sila endpoints.
Please note that this crate is not an official Sila project. I (Justin) am affiliated with Sila, but I'm building this for my own purposes (I like Rust and want to use it to interact with our platform). Resolution to any issues should be sought via the project's GitHub repository.
Example
A call to Sila's check_handle endpoint can be accomplished in the following way.
All of the silamoney:: functions are async so you'll need to use an appropriate runtime like tokio.
async
This section defines the addresses used in the call to Sila's API.
// you'll need your registered application's address and key; we define those here with these
// variable names to streamline the KeyParams constructor further down
let address = "0x...".to_string;
let private_key = Optionfrom;
These fn references in silamoney::* build the JSON object that will be sent to Sila based on Sila's API expectations.
let message = to_string.unwrap;
This function prepares the data to be signed by whatever Signer you're using. We'll use default_sign.
Because check_handle does not require a usersignature, Option::None is provided to the function to skip the creation of that Signature. For KeyParams we only need to specify the variable names previously defined because they match the expectations of the struct.
let sdp = from;
Provisions exist in the silamoney crate to specify a custom signer. This default_sign function builds a Signer that requires the application to have direct access to customer private keys.
let signatures = default_sign.await;
This struct is is in silamoney::SignedMessageParams. It is used to send the request to the check_handle endpoint.
let smp = SignedMessageParams ;
The check_handle function is in silamoney::* and executes the request to the Sila API and waits for a response.
let response = check_handle.await;
println!;
}
Authentication
The Sila API uses an authentication mechanism that leverages key generation and message signing standards established by the Ethereum project. This crate has a number of structs and functions to enable you to use user private keys to sign messages and use the API in that way.
You can also choose to define your own Signer and provide it a closure to produce the signatures needed to execute that authentication. For example, you might have a separate service that provides a /sign endpoint where you can provide a user address and a message to be signed and have that service handle the sensitive operations necessary to produce that signature. Here is an example of how that could be accomplished
let app_address = H160from_str.unwrap;
let mut app_data = SignData ;
let signer = new;
let signature = signer.sign.await;
In that way you can establish some sensible architectural security boundaries around your services.