1.6 KiB
1.6 KiB
Circle WebSocket Client
A Rust library for connecting to Circle WebSocket servers with authentication support.
Features
- Cross-platform WebSocket client (native and WASM)
- secp256k1 cryptographic authentication
- JSON-RPC 2.0 protocol support
- Async/await interface with Tokio
- Built on tokio-tungstenite for reliable WebSocket connections
Usage
Add this to your Cargo.toml
:
[dependencies]
circle_client_ws = { path = "../client_ws" }
Basic Example
use circle_client_ws::CircleWsClientBuilder;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create client with private key
let private_key = "your_private_key_hex";
let client = CircleWsClientBuilder::new()
.with_private_key(private_key)?
.build();
// Connect and authenticate
client.connect("ws://localhost:8080").await?;
// Use the authenticated client...
Ok(())
}
Authentication Flow
The client automatically handles the secp256k1 authentication flow:
- Connects to WebSocket server
- Receives authentication challenge
- Signs challenge with private key
- Sends signed response
- Receives authentication confirmation
Binary Tool
A command-line binary is also available for interactive use and script execution. See cmd/README.md
for details.
Platform Support
- Native: Full support on all Rust-supported platforms
- WASM: Browser support with web-sys bindings
Dependencies
tokio-tungstenite
: WebSocket implementationsecp256k1
: Cryptographic operationsserde
: JSON serializationuuid
: Request ID generation