Skip to main content

MPC in minutes

Silent Shard Trio consists of:

There are 3 core MPC actions that you can perform:

  • Keygen: Generate a new MPC wallet.
  • Sign: Sign a message using the MPC wallet.
  • Refresh: Refresh your wallet's secret data, without changing your address!
info

For a list of all supported actions go to Supported Features


Quick Intuition

Requires access at https://github.com/silence-laboratories/dkls23-rs

Setup trio-c: Two cloud nodes and one client

From where you gh repo clone silence-laboratories/dkls23-rs run

  • ./scripts/run-trio-first.sh to launch first mpc node and
  • ./scripts/run-trio-second.sh for the second one.
  • To test the API from cli you can save locally the following script and have the two cloud nodes to run it.
Save it in run-test.sh and shell run-test.sh to run it
#!/bin/sh



set -e

cmd="cargo run -p trio-client -q --release -- "
vk1="cfa1ff5424d14eb60614d7ddf65a32243d26ddf7000d10007853d7336395efe4"

mkdir -p ./testdata/fs/client

# get master verifying key (public key) for the first mpc node. It is needed by client to verify
# messages
# vk1=$(vault \
# read \
# -format json \
# transit/keys/message-signer-party-0 | \
# jq -r '.data.keys."1".public_key' | base64 -d | xxd -ps -c 32)

# # get master verifying key (public key) for the second party
# vk2=$(vault \
# read \
# -format json \
# transit/keys/message-signer-party-1 | \
# jq -r '.data.keys."1".public_key' | base64 -d | xxd -ps -c 32)

# export RUST_LOG=debug

# run key generation 2x3
$cmd key-gen \
--sign-algo "ecdsa" \
--share ./testdata/fs/client/keygen.share \
--user-sk ./testdata/party_2_sk \
--server-vk ${vk1}

echo "DKG ok"

# run signature generation
$cmd sign-gen \
--sign-algo "ecdsa" \
--share ./testdata/fs/client/keygen.share \
--msg-to-sign cfa1ff5424d14eb60614d7ddf65a32243d26ddf7000d10007853d7336395efe4 \
--chain-path "m" \
--user-sk ./testdata/party_2_sk \
--server-vk ${vk1}

echo "DSG ok"

# run signature generation
$cmd pre-sign \
--sign-algo "ecdsa" \
--share ./testdata/fs/client/keygen.share \
--pre ./testdata/fs/client/presign.share \
--chain-path "m" \
--user-sk ./testdata/party_2_sk \
--server-vk ${vk1}

echo "pre-sign ok"

# run pre-sign -> sign
$cmd finish \
--sign-algo "ecdsa" \
--pre ./testdata/fs/client/presign.share \
--msg-to-sign cfa1ff5424d14eb60614d7ddf65a32243d26ddf7000d10007853d7336395efe4 \
--user-sk ./testdata/party_2_sk \
--server-vk ${vk1}

echo "finish ok"

# run key refresh 2x3
$cmd key-gen \
--sign-algo "ecdsa" \
--old-share ./testdata/fs/client/keygen.share \
--share ./testdata/fs/client/refresh.share \
--user-sk ./testdata/party_2_sk \
--server-vk ${vk1}

echo "key refresh ok"

# run signature generation
$cmd sign-gen \
--sign-algo "ecdsa" \
--share ./testdata/fs/client/refresh.share \
--msg-to-sign cfa1ff5424d14eb60614d7ddf65a32243d26ddf7000d10007853d7336395efe4 \
--chain-path "m" \
--user-sk ./testdata/party_2_sk \
--server-vk ${vk1}

echo "DSG with refreshed key ok"

pk=$($cmd key-share \
--sign-algo "ecdsa" \
--path ./testdata/fs/client/refresh.share \
--public-key)

echo PK ${pk}

# run key refresh 2x3
$cmd key-recovery \
--sign-algo "ecdsa" \
--public-key ${pk} \
--share ./testdata/fs/client/recovery.share \
--user-sk ./testdata/party_2_sk \
--server-vk ${vk1}

echo key recovery ok

# run signature generation
$cmd sign-gen \
--sign-algo "ecdsa" \
--share ./testdata/fs/client/recovery.share \
--msg-to-sign cfa1ff5424d14eb60614d7ddf65a32243d26ddf7000d10007853d7336395efe4 \
--chain-path "m" \
--user-sk ./testdata/party_2_sk \
--server-vk ${vk1}

echo DSG after key recovery

Setup the Mobile SDK (React Native)

Create a new React Native project

npx react-native init SilentMPC-Trio

After the project is created, configure the @silencelaboratories/silent-shard-sdk as the installation guide.

Our package heavily encodes and decodes the String using Buffer objects, so let's add to the project.

yarn add buffer

Run the MPC operations

Import and Setup the SDK

Copy the following code to the App.tsx file and paste the previously copied server public key in place of YOUR_SERVER_PUBLIC_KEY

App.tsx
import * as React from 'react';
import {
CloudWebSocketClient,
EcdsaSession,
MpcProtocols,
type SessionConfig,
} from '@silencelaboratories/silent-shard-sdk';
import { Buffer } from 'buffer';

global.Buffer = Buffer;

// Set the Server URL
const CLOUD_NODE_URI = 'localhost:8080';
// Set the Server's verifying key.
const cloudVerifyingKey = 'YOUR_SERVER_PUBLIC_KEY';

export default function App() {
React.useEffect(() => {
// We will MPC functions here
const test = async () => {
const cloudClient = new CloudWebSocketClient(CLOUD_NODE_URI, false);

// Create MPC session configuration
const config: SessionConfig = {
cloudVerifyingKey: cloudVerifyingKey,
client: cloudClient,
// Set the protocol to "trio" explicitly.
// If omitted, the session will default to the "duo" protocol.
protocol: MpcProtocols.trio,
};
// Initialize the session
const session = new EcdsaSession(config);

// Keygen
const keyshare = await session.keygen();
console.log('Generated keyshare: ', keyshare);

// Get public key of newly generated wallet
const publicKey = keyshare.publicKeyBase64;
console.log('Generated public key: ', publicKey);

// Keccak256 Hash("Trusted Third Parties are Security Holes")
const messageHash = '53c48e76b32d4fb862249a81f0fc95da2d3b16bf53771cc03fd512ef5d4e6ed9';

// Signature generation
const signature = await session.sign({
keyshare,
messageHash,
derivationPath: 'm',
});

console.log('Generated signature: ', signature);
};
test();
}, []);

return null;
}