pub struct Client { /* private fields */ }Expand description
Represents a client of the REST API
Implementations§
Source§impl Client
impl Client
Sourcepub fn from_parts(
url: String,
key: String,
risc0_version: &str,
) -> Result<Self, SdkErr>
pub fn from_parts( url: String, key: String, risc0_version: &str, ) -> Result<Self, SdkErr>
Construct a Client from url, api key, and zkvm version
§Example (blocking):
use bonsai_sdk;
let url = "http://api.bonsai.xyz".to_string();
let api_key = "my_secret_key".to_string();
bonsai_sdk::blocking::Client::from_parts(url, api_key, risc0_zkvm::VERSION)
.expect("Failed to construct sdk client");§Example (non-blocking):
use bonsai_sdk;
let url = "http://api.bonsai.xyz".to_string();
let api_key = "my_secret_key".to_string();
bonsai_sdk::non_blocking::Client::from_parts(url, api_key, risc0_zkvm::VERSION)
.expect("Failed to construct sdk client");Sourcepub fn from_env(risc0_version: &str) -> Result<Self, SdkErr>
pub fn from_env(risc0_version: &str) -> Result<Self, SdkErr>
Construct a Client from env vars
Uses the BONSAI_API_URL and BONSAI_API_KEY environment variables to construct a client. The risc0_version should be the crate version of the risc0-zkvm crate
§Example (blocking):
use bonsai_sdk;
bonsai_sdk::blocking::Client::from_env(risc0_zkvm::VERSION)
.expect("Failed to construct sdk client");§Example (non-blocking):
use bonsai_sdk;
bonsai_sdk::non_blocking::Client::from_env(risc0_zkvm::VERSION)
.expect("Failed to construct sdk client");Sourcepub async fn has_img(&self, image_id: &str) -> Result<bool, SdkErr>
pub async fn has_img(&self, image_id: &str) -> Result<bool, SdkErr>
Check if a image with the given image_id exists in bonsai
The boolean return indicates if the image already exists
Sourcepub async fn upload_img(
&self,
image_id: &str,
buf: Vec<u8>,
) -> Result<bool, SdkErr>
pub async fn upload_img( &self, image_id: &str, buf: Vec<u8>, ) -> Result<bool, SdkErr>
Upload a image buffer to the /images/ route
The boolean return indicates if the image already exists in bonsai
The image data can be either:
- ELF file bytes
- bincode encoded MemoryImage
Sourcepub async fn upload_img_file(
&self,
image_id: &str,
path: &Path,
) -> Result<bool, SdkErr>
pub async fn upload_img_file( &self, image_id: &str, path: &Path, ) -> Result<bool, SdkErr>
Upload a image file to the /images/ route
The boolean return indicates if the image already exists in bonsai
The image data can be either:
- ELF file bytes
- bincode encoded MemoryImage
Sourcepub async fn upload_input(&self, buf: Vec<u8>) -> Result<String, SdkErr>
pub async fn upload_input(&self, buf: Vec<u8>) -> Result<String, SdkErr>
Upload a input buffer to the /inputs/ route
Sourcepub async fn upload_input_file(&self, path: &Path) -> Result<String, SdkErr>
pub async fn upload_input_file(&self, path: &Path) -> Result<String, SdkErr>
Upload a input file to the /inputs/ route
Sourcepub async fn upload_receipt(&self, buf: Vec<u8>) -> Result<String, SdkErr>
pub async fn upload_receipt(&self, buf: Vec<u8>) -> Result<String, SdkErr>
Upload a receipt buffer to the /receipts/ route
Sourcepub async fn upload_receipt_file(&self, path: &Path) -> Result<String, SdkErr>
pub async fn upload_receipt_file(&self, path: &Path) -> Result<String, SdkErr>
Upload a receipt file to the /receipts/ route
Sourcepub async fn receipt_download(
&self,
session_id: &SessionId,
) -> Result<Vec<u8>, SdkErr>
pub async fn receipt_download( &self, session_id: &SessionId, ) -> Result<Vec<u8>, SdkErr>
Download a existing receipt
Allows download of older receipts without checking the current session status.
Sourcepub async fn image_delete(&self, image_id: &str) -> Result<(), SdkErr>
pub async fn image_delete(&self, image_id: &str) -> Result<(), SdkErr>
Delete an existing image
Allows deletion of a specified image_id.
Sourcepub async fn input_delete(&self, input_uuid: &str) -> Result<(), SdkErr>
pub async fn input_delete(&self, input_uuid: &str) -> Result<(), SdkErr>
Delete an existing input
Allows deletion of a specified input Uuid.
Sourcepub async fn create_session_with_limit(
&self,
img_id: String,
input_id: String,
assumptions: Vec<String>,
execute_only: bool,
exec_cycle_limit: Option<u64>,
) -> Result<SessionId, SdkErr>
pub async fn create_session_with_limit( &self, img_id: String, input_id: String, assumptions: Vec<String>, execute_only: bool, exec_cycle_limit: Option<u64>, ) -> Result<SessionId, SdkErr>
Create a new proof request Session with executor cycle limit
Supply the image_id and input_id created from uploading those files in previous steps
Sourcepub async fn create_session(
&self,
img_id: String,
input_id: String,
assumptions: Vec<String>,
execute_only: bool,
) -> Result<SessionId, SdkErr>
pub async fn create_session( &self, img_id: String, input_id: String, assumptions: Vec<String>, execute_only: bool, ) -> Result<SessionId, SdkErr>
Create a new proof request Session
Supply the image_id and input_id created from uploading those files in previous steps
Sourcepub async fn download(&self, url: &str) -> Result<Vec<u8>, SdkErr>
pub async fn download(&self, url: &str) -> Result<Vec<u8>, SdkErr>
Download a given url to a buffer
Useful to download a SessionId receipt_url
Sourcepub async fn create_snark(&self, session_id: String) -> Result<SnarkId, SdkErr>
pub async fn create_snark(&self, session_id: String) -> Result<SnarkId, SdkErr>
Requests a SNARK proof be created from a existing sessionId
Supply a completed sessionId to convert the risc0 STARK proof into a SNARK proof that can be validated on ethereum-like blockchains
Sourcepub async fn version(&self) -> Result<VersionInfo, SdkErr>
pub async fn version(&self) -> Result<VersionInfo, SdkErr>
Fetches the current component versions from bonsai
Fetches the risc0 zkvm supported versions as well as other sub-components of bonsai