Sr25519

class Sr25519(hostUrl: String = SODOT_RELAY_URL) : Scheme

Sr25519 scheme implementation providing functionality for the FROST MPC protocol.

This class handles cryptographic operations using Sr25519 keys, including:

  • Key generation via multi-party computation (MPC)

  • Distributed signing of messages

  • Secret share refreshing

  • Key resharing

  • Key import/export

  • Key derivation

Example Usage

/// Server side creates a room for 3 parties using API_KEY
/// Creating a room UUID should always happen on the server side
val numParties = 3
val threshold = 2
val apiKey = "MY_API_KEY"
val keygenRoomUuid = createRoom(numParties, apiKey)

/// All parties call initKeygen to get key generation IDs
val keygenInitResult = initKeygen()

/// All parties receive keygenIds from other parties
val keygenIds = listOf("keygenId1", "keygenId2")

/// All parties join the keygen room
val keygenResult = keygen(
keygenRoomUuid,
numParties,
threshold,
keygenInitResult.keygenSecret,
keygenIds
)

/// Pick the derivation path for the public key you want to sign for
val derivationPath = arrayOf("this", "is", "a", "derivation", "path")

/// Option 1: Derive public key using the secret share from keygenResult
val pubkey = derivePubkey(keygenResult.secretShare, derivationPath)

/// Option 2: Derive public key using Spub for more flexibility
val pubKey = getPubkey(keygenResult.secretShare)
val derivedPubkey = derivePubkeyFromPubkey(pubKey, derivationPath)

/// To sign a message, create a signing room on the server side
val signingRoomUuid = createRoom(threshold, apiKey)
/// Your message in hex
val message = "deadbeef"

/// Threshold parties join the signing room
val signature = sign(signingRoomUuid, keygenResult.secretShare, message, derivationPath)
/// This signature can now be verified against pubkey

/// Refreshing the secret key material
val refreshRoomUuid = createRoom(numParties, apiKey)
/// All parties join the refresh room
val refreshResult = refresh(refreshRoomUuid, keygenResult.secretShare)
/// Note: refreshResult.pubkey == keygenResult.pubkey

/// Signing using the new secret key material
val signingRoomUuid2 = createRoom(threshold, apiKey)
val message2 = "deadbeefcafebabe"
val signature2 = sign(signingRoomUuid2, refreshResult.secretShare, message2, derivationPath)
/// This signature can now be verified against pubkey

Constructors

Link copied to clipboard
constructor(hostUrl: String = SODOT_RELAY_URL)

Functions

Link copied to clipboard
suspend fun createRoom(numParties: Int, apiKey: String): RoomUUID

Creates a room for multi-party computation.

Link copied to clipboard
fun derivePrivateKeyFromPrivateKey(privkey: String, derivationPath: Array<String>, isPrivateKeyRaw: Boolean): Sr25519KeyPair

Derives a private key from a private key.

Link copied to clipboard
fun derivePubkey(secretShare: Sr25519SecretShare, derivationPath: Array<String>): Sr25519PublicKey

Derives a public key from an Sr25519 secret share.

Link copied to clipboard

Derives a public key from a public key.

Link copied to clipboard
suspend fun exportFullPrivateKey(roomUuid: String, secretShare: Sr25519SecretShare, toExportID: String): Sr25519KeyPair?

Exports a full Sr25519 private key.

Link copied to clipboard

Gets an export ID from an Sr25519 secret share.

Link copied to clipboard

Gets a public key from an Sr25519 secret share.

Link copied to clipboard
suspend fun importPrivateKeyImporter(roomUuid: RoomUUID, threshold: Int, privateKey: PrivateKey, keygenInitKeypair: KeygenPrivateKey, keygenIds: Array<KeygenID>, isPrivateKeyRaw: Boolean): Pair<Sr25519PublicKey, Sr25519SecretShare>

Imports an Sr25519 private key (importer).

Link copied to clipboard
suspend fun importPrivateKeyRecipient(roomUuid: RoomUUID, threshold: Int, keygenInitKeypair: KeygenPrivateKey, keygenIds: Array<KeygenID>): Pair<Sr25519PublicKey, Sr25519SecretShare>

Imports an Sr25519 private key (recipient).

Link copied to clipboard

Initializes key generation for MPC protocols.

Link copied to clipboard
suspend fun keygen(roomUuid: RoomUUID, numParties: Int, threshold: Int, keygenInitKeypair: KeygenPrivateKey, keygenIds: Array<KeygenID>): Pair<Sr25519PublicKey, Sr25519SecretShare>

Generates Sr25519 keys using multi-party computation.

Link copied to clipboard

Exports a full Sr25519 private key offline.

Link copied to clipboard

Refreshes the Sr25519 secret share.

Link copied to clipboard
suspend fun reshareNewParty(roomUuid: RoomUUID, oldThreshold: Int, newThreshold: Int, keygenInitKeypair: KeygenPrivateKey, keygenIds: Array<KeygenID>): Pair<Sr25519PublicKey, Sr25519SecretShare>

Reshares an Sr25519 key for a new party.

Link copied to clipboard
suspend fun reshareRemainingParty(roomUuid: RoomUUID, newThreshold: Int, secretShare: Sr25519SecretShare, keygenIds: Array<KeygenID>): Pair<Sr25519PublicKey, Sr25519SecretShare>

Reshares an Sr25519 key for a remaining party.

Link copied to clipboard
suspend fun sign(roomUuid: RoomUUID, secretShare: Sr25519SecretShare, msg: ByteArray, derivationPath: Array<String>): Sr25519Signature

Signs a message using Sr25519 and multi-party computation.