Harbor
RustWalrusSealSuiAsync
The Harbor SDK provides a native Rust client to interface with the Harbor, a decentralized file storage layer built on top of Walrus. Harbor SDK integrates seamlessly with Seal, allowing you to transparently encrypt your data client-side before storing it, ensuring complete privacy and cryptographic access control.
With harbor-rs, you can easily build applications that create storage buckets, manage files, and securely retrieve data.
Concepts
- Buckets: Logical containers for your files. Buckets are reserved, bound to a Seal policy for access control, and then finalized.
- Service Signer: An Ed25519 Sui Keypair used to authenticate your requests.
- End-to-End Encryption: The SDK works alongside the Seal SDK. Files are encrypted locally using decryption shares managed by KeyServers before ever leaving your machine.
Installation
Add the dependencies to your Cargo.toml:
Code
[dependencies]
harbor-core = "0.1.0"
seal-sdk-rs = "0.1.0"
fastcrypto = "0.1"
tokio = { version = "1", features = ["full"] }Quick Start
Here is a complete example showing how to initialize the client, reserve a bucket, encrypt a file, and upload it to Harbor.
Code
use std::sync::Arc;
use harbor_core::{
HarborClient, HarborClientOptions, seal::SealReqwestClient, utils::SimpleSigner,
};
use seal_sdk_rs::{policy::PolicyInfo, SealClient};
use fastcrypto::ed25519::Ed25519KeyPair;
use fastcrypto::traits::KeyPair;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = "hbr_YOUR_API_KEY".to_string();
let service_privkey = "suiprivkey...".to_string();
// 1. Initialize the signer and Harbor client
let keypair = Ed25519KeyPair::from_suiprivkey(&service_privkey)?;
let mut signer = SimpleSigner(keypair);
let harbor = HarborClient::new(HarborClientOptions {
api_key: api_key.clone(),
..Default::default()
});
// 2. Initialize the Seal encryption client
let seal_http = Arc::new(SealReqwestClient::new());
let mut seal_client = SealClient::new(seal_http);
let seal_policy = PolicyInfo { /* your policy details */ };
// 3. Reserve and finalize a storage bucket
let reserve_res = harbor.reserve_bucket("my-secure-bucket").await?;
let bucket_id = reserve_res.data.id;
// Bind the bucket to your Seal policy
harbor.finalize_bucket(&bucket_id, &seal_policy.id).await?;
// 4. Encrypt your file client-side
let plaintext = b"Hello, Harbor! This is completely private.";
let ciphertext = seal_client.encrypt(
plaintext,
seal_policy.clone(),
"my-file",
&mut signer
).await?;
// 5. Upload the encrypted data to Harbor
let upload_res = harbor.upload(&bucket_id, &ciphertext, "my-file").await?;
println!("File securely uploaded with ID: {}", upload_res.data.id);
// 6. Download and Decrypt
let downloaded = harbor.download(&upload_res.data.id).await?;
let decrypted = seal_client.decrypt(
&downloaded,
"my-file",
seal_policy.clone(),
&mut signer
).await?;
assert_eq!(plaintext.as_slice(), decrypted);
println!("File successfully downloaded and decrypted!");
Ok(())
}