Skip to main content

Session creation

High level flow of TrioSession

TrioSession is the main object which will be used to perform all of the MPC operations supported. To create TrioSession please follow the steps below.

Step 1 : Add library to your Project


Step 2 : Create new session


  1. Provide websocket client by using any of the below options :
  2. Provide cloud/server public key.
  3. Provide storage client. (You need to implement the interface StorageClient).
  4. Provide Message Signer (You need to implement the interface MessageSigner).

Example


MainActivity.kt
 object Constants {
//Replace with your own
const val CLOUD_NODE_URI = "trio-server.demo.silencelaboratories.com"
//Replace with your own
//const val PORT = "8080"
}

//Other party verifying-key/public-key. Replace with your own Verifying Key.
val cloudPublicKey = "019c4c79e942bbc3ff1d6ace7256404d701498056978cc4638c35832acdf821b1e"

//Create websocketConfig to let SilentShard use default WebsocketClient.
//We can specify port or for Test Environment or Local Server you can configure like the following
//websocketConfig = WebsocketConfig(url = CLOUD_NODE_URI, port = PORT, isSecure = false)
val websocketConfig = WebsocketConfig(CLOUD_NODE_URI)

//Create storageClient instance to manage keyshare states
val storageClient = object : StorageClient {
/**
* Representing in-memory database. In real world it should be some SQL based DB or
* secure storage or custom hardware. It's up to the implementation app's use-case.
* */
private val keyshareDaoSet = mutableSetOf<ReconcileStoreDao>()

override suspend fun write(
dao: StorageDao,
) {
if (dao !is ReconcileStoreDao) {
throw IllegalArgumentException("Expected ReconcileStoreDao")
}
if (!keyshareDaoSet.add(dao)) {
keyshareDaoSet.remove(dao)
keyshareDaoSet.add(dao)
}
}

override suspend fun read(
key: String,
): ReconcileStoreDao? {
return keyshareDaoSet.find { it.keyId == key }
}
}

//Create messageSigner instance to sign message key
val messageSigner = object : MessageSigner {

override val verifyingKey: ByteArray
get() = TODO("Public key of secure key(Secure Environment - TEE)")
override val keyType: MessageSigner.KeyType
get() = TODO("Type of secure key(Secure Environment - TEE)")

override fun sign(data: ByteArray): ByteArray {
TODO("Sign data using secure key(Secure Environment - TEE) and return signature")
}
}

//For quick-start we can use test message signer. Do not use this in production
val testMessageSigner = SilentShard.ECDSA.TestMessageSigner

//Create trioSession for ECDSA algorithm
val trioSession: TrioSession = SilentShard.ECDSA.createTrioSession(
//pass your message signer instance i.e., messageSigner; do not use testMessageSigner in production
testMessageSigner, cloudPublicKey, websocketConfig, storageClient
)

//Create trioSession for ECDSA algorithm by providing custom network client
/* val trioSession: TrioSession = SilentShard.ECDSA.createTrioSession(
//pass your message signer instance i.e., messageSigner; do not use testMessageSigner in production
testMessageSigner, cloudPublicKey, CustomNetworkClient(), storageClient
)*/
  • CLOUD_NODE_URI is the URI of the cloud node.
  • cloudPublicKey is the cloud verifying key (Ed25519 public key).
    • This public key is used to verify the server's signature on each message
    • See example here
  • SilentShard Provides API for creating MPC TrioSession (Three-Party) using ECDSA algorithm.
  • ECDSA Provides factory methods for creating MPC session using ECDSA algorithm.
  • TrioSession Represents a two-party computation session that lets you perform MPC operations using SilentShard protocol.

You have now successfully set up the session and are ready to start performing MPC actions! 🎉