BIP340
BIP340 scheme implementation providing functionality for the FROST MPC protocol.
This class handles cryptographic operations using BIP340 keys, including:
Key generation via multi-party computation (MPC)
Distributed signing of messages
Secret share refreshing
Key resharing
Key import/export
Key derivation
Support for BIP-341 Taproot tweaking
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 = intArrayOf(44, 60, 0, 0, 0)
/// Option 1: Derive tweaked public key using the secret share from keygenResult
val pubkey = deriveTweakPubkey(keygenResult.secretShare, derivationPath, "")
/// Option 2: Derive tweaked public key using Xpub for more flexibility
val xpub = getXpub(keygenResult.secretShare)
val pubkeyFromXpub = deriveTweakPubkeyFromXpub(xpub, 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 pubkeyFunctions
Creates a room for multi-party computation.
Derives a private key from an extended private key (Xpriv).
Derives a public key from an ECDSA secret share.
Derives a public key from an extended public key (Xpub).
Exports the full BIP340 private key.
Gets an export ID from an ECDSA secret share.
Gets an extended public key (Xpub) from an ECDSA secret share.
Imports a BIP340 private key (importer).
Imports a BIP340 private key (recipient).
Initializes key generation for MPC protocols.
Generates BIP340 keys using multi-party computation.
Exports a full BIP340 private key offline.
Refreshes the BIP340 secret share.
Reshares a BIP340 key for a new party.
Reshares a BIP340 key for a remaining party.
Signs a message using BIP340 and multi-party computation.