Skip to main content

Getting Started

Generate a key and begin signing in under a minute with the Sodot Unity SDK.

Key Generation

First, we must generate a public key and key shares so that we can later sign messages. You will need your API_KEY.

We show example code for a 2-of-3 threshold signing scenario. (Note that Sodot MPC SDK allows any t-of-n threshold signing setting)

To generate a key we use the objects defined in the SDK:

Feature

BIP-340 (for Bitcoin Taproot), ECDSA and ED25519 are all supported through the Unity SDK.

using SodotSDK;
using SodotSDK.Ecdsa;

// Your server side creates a room for 3 parties using its API_KEY
// Creating a room uuid should always happen on the server side using your API_KEY
// so that the API_KEY is never exposed to the client side
ushort N = 3;
ushort T = 2;
var myApiKey = "MY_API_KEY";
var hostUrl = "demo.sodot.dev"; // Your Relay URL

// Create the Ecdsa instance with your relay server hostURL
var ecdsa = new Ecdsa(hostUrl);

// Create a room for key generation
var keygenRoomUuid = await ecdsa.CreateRoom(N, myApiKey);

// All parties call initKeygen to get initialization data that contains a public key and private key
var (keygenId, keygenSecret) = ecdsa.InitKeygen();

// All parties receive the keygenIds from all other parties
var keygenIds = new KeygenId[] { new KeygenId("keygenId1"), new KeygenId("keygenId3") };

// All parties join the keygen room
var (pubkey, secretShare) = await ecdsa.Keygen(keygenRoomUuid, N, T, keygenSecret, keygenIds);

// Pick the derivation path of the public key you want to sign for
var derivationPath = new uint[] { 44, 60, 0, 0, 0 };

// Get the public key for the derivation path
var derivedPubkey = await ecdsa.DerivePubkey(secretShare, derivationPath);

// Store secretShare securely for later use in signing

Behind the scenes this is the rough flow of communication that occurs:

Signing

Now that we have key shares on all the devices/servers of the potential signers, we can sign by running:

using SodotSDK;
using static SodotSDK.SodotUtils;
using SodotSDK.Ecdsa;

// To sign a message, create a signing room on the server side, using your API_KEY
ushort T = 2; // We only need T signers (of our N total parties)
var myApiKey = "MY_API_KEY";
var hostUrl = "demo.sodot.dev"; // Your Relay URL

// Create the Ecdsa instance with your relay server hostURL
var ecdsa = new Ecdsa(hostUrl);

// Create a room for signing
var signingRoomUuid = await ecdsa.CreateRoom(T, myApiKey);

// Each participating party uses their secret share from key generation
var (_, secretShare) = await ecdsa.Keygen(/*...*/);

// The derivation path to use for signing (same as used to generate the pubkey)
var derivationPath = new uint[] { 44, 60, 0, 0, 0 };

// Hash the message and convert to MessageHash
var message = new byte[] { 0xca, 0xfe, 0xca, 0xfe, 0xca, 0xfe, 0xca, 0xfe };
var msgHash = MessageHash.FromKeccak256(message);

// T parties join the signing room and perform the signing
var signature = await ecdsa.Sign(signingRoomUuid, secretShare, msgHash, derivationPath);

// The signature can be verified against the derived public key

Additional Features

The Sodot Unity SDK provides additional advanced features, such as key refresh, key reshare, key import and export, etc. For more information on those features, please visit the Key Lifecycle page.

API Reference

For full details on all available methods, refer to the SDK API Reference, also linked in the sidebar.