Session creation
High level flow of the SDK
- Setup the websocket client to connect and communicate with the cloud node
- Setup the storage provider for mobile keyshare persistence and sync capabilities
- Create a message signer for secure message exchange between mobile and cloud node
- Start a new mpc session
- Perform MPC actions
Create a new React Native project
Skip this section if you already have a React Native project.
npx @react-native-community/cli@latest init SilentMPC
After the project is created, install @silencelaboratories/silent-shard-sdk using the instructions from the Installation Guide
Start a new session
- ECDSA
- EdDSA
import {
CloudWebSocketClient,
createEcdsaTrioSession,
InMemoryStorageProvider,
type MessageSigner,
} from '@silencelaboratories/silent-shard-sdk';
const CLOUD_NODE_URI = 'localhost:8080';
const cloudVerifyingKey = 'SERVER_PUBLIC_KEY_HEX';
const cloudClient = new CloudWebSocketClient(CLOUD_NODE_URI, false);
const storage = new InMemoryStorageProvider();
export const initSession = async () => {
const messageSigner: MessageSigner = {
publicKeyB64: 'YOUR_PUBLIC_KEY',
sign: async (message: string) => {
// Implement your signing logic here
// For example, using a cryptographic library to sign the message or in the TEE
console.log('Signing message:', message);
return '';
},
keyType: 'ED25519', // your key type
};
const session = await createEcdsaTrioSession({
client: cloudClient,
cloudVerifyingKey: cloudVerifyingKey,
storage: storage,
messageSigner,
});
console.log('Session created successfully');
return session;
};
import {
CloudWebSocketClient,
createEddsaTrioSession,
InMemoryStorageProvider,
type MessageSigner,
} from '@silencelaboratories/silent-shard-sdk';
const CLOUD_NODE_URI = 'localhost:8080';
const cloudVerifyingKey = 'SERVER_PUBLIC_KEY_HEX';
const cloudClient = new CloudWebSocketClient(CLOUD_NODE_URI, false);
const storage = new InMemoryStorageProvider();
export const initSession = async () => {
const messageSigner: MessageSigner = {
publicKeyB64: 'YOUR_PUBLIC_KEY',
sign: async (message: string) => {
// Implement your signing logic here
// For example, using a cryptographic library to sign the message or in the TEE
console.log('Signing message:', message);
return '';
},
keyType: 'ED25519', // your key type
};
const session = await createEddsaTrioSession({
client: cloudClient,
cloudVerifyingKey: cloudVerifyingKey,
storage: storage,
messageSigner,
});
console.log('Session created successfully');
return session;
};
-
CloudWebSocketClient: is a class that handles the WebSocket communication with the cloud node.
-
IStorageProvider: is a class manager for storing and retrieving MPC keyshares through a standardized interface.
-
MessageSigner: is a class that handles the signing of messages for secure communication between mobile and cloud node.
-
EcdsaSession: is the class that facilitates all actions for ECDSA wallets.
-
SessionConfig: is a configuration object that contains the necessary information for the session.
-
CLOUD_NODE_URIis the URI of the cloud node. -
cloudVerifyingKeyis the Hex encoded cloud verifying key (Ed25519 public key).- This public key is used to verify the server's signature on each message
- See example here
You have now successfully set up the session and are ready to start performing MPC actions! 🎉