Skip to main content
Platform

Customize the WebSocket client

Overview

CloudWebSocketClient is the default transport: it carries MPC (Multi-Party Computation) protocol messages to the cloud node over a WebSocket. It is what a session uses unless you pass your own.

1. CloudWebSocketClient

  • Role: The WebSocket transport shipped with the SDK
  • Responsibility:
    • MPC-specific URL construction
    • Operation routing (keygen/sign/refresh)
    • Raw WebSocket connection management, message queueing and binary/text I/O
  • Customization Use Cases:
    • Add authentication headers (subclass it, as shown below)

2. NetworkClient

  • Role: The interface CloudWebSocketClient implements
  • Responsibility: defines the rhythm a session drives — connect to open a channel for one protocol step, send/read to exchange messages, close when the step is done, plus reset
  • Customization Use Cases:
    • Route protocol traffic over a different transport entirely, then pass your implementation as ShardSessionConfig.client

Example adding authentication headers to WebSocket connection

App.tsx
import { CloudWebSocketClient } from '@silencelaboratories/silent-shard-sdk';
import { createEcdsaDuoSession } from '@silencelaboratories/silent-shard-sdk/ecdsa';
import type { WebSocketAction } from '@/silent-shard-sdk/src/network/WebSocketAction';

class CustomCloudClient extends CloudWebSocketClient {
connect(opt: WebSocketAction): Promise<void> {
// You can read your client ID and access token from environment variables or a secure store.
const token = 'client-access-token-here';
const headers = {
'client-id': 'your-client-id-here',
'access-token': token,
};
return super.connect(opt, { headers });
}
}

// Then you can use the CustomCloudClient in Session objects
const customClient = new CustomCloudClient('CLOUD_NODE_URL', true); // true for WSS, false for WS

createEcdsaDuoSession({
client: customClient,
cloudVerifyingKey: '',
});