@sodot/sodot-react-native-sdk • Docs
@sodot/sodot-react-native-sdk / BIP340
Class: BIP340
Class providing the functionality for the BIP340 protocol the FROST MPC protocol.
Example
// 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
const N = 3;
const T = 2;
const bip340 = new BIP340();
const API_KEY = 'MY_API_KEY';
const keygenRoomUuid = await bip340.createRoom(N, API_KEY);
// All parties call initKeygen to get an BIP340InitKeygenResult, that contains a keygenId
const keygenInitResult = await bip340.initKeygen();
// All parties receive the keygenIds from all other parties
const keygenIds = [keygenId1, keygenId2];
// All parties join the keygen room
const keygenResult = await bip340.keygen(keygenRoomUuid, N, T, keygenInitResult, keygenIds);
// Pick the derivation path of the public key you want to sign for
const derivationPath = new Uint32Array([44,60,0,0,0]);
// Get the public key for the derivation path
const pubkey = await bip340.deriveTweakPubkey(keygenResult, derivationPath);
// To sign a message, create a signing room on the server side, using your API_KEY
const signingRoomUuid = await bip340.createRoom(T, API_KEY);
// your message in hex
const message = 'deadbeef';
// 2 parties join the signing room
const signature = await bip340.sign(signingRoomUuid, keygenResult, message, derivationPath);
// This signature can now be verified against pubkey
// Refreshing the secret key material
// Your server creates a room for 3 parties
const refreshRoomUuid = await bip340.createRoom(N, API_KEY);
// All parties join the refresh room
const refreshResult = await bip340.refresh(refreshRoomUuid, keygenResult);
// Note: refreshResult.pubkey == keygenResult.pubkey
// Signing using the new secret key material
// The room is again created by the server
const signingRoomUuid2 = await bip340.createRoom(T, API_KEY);
const message2 = 'deadbeefcafebabe';
const signature2 = await bip340.sign(signingRoomUuid2, refreshResult, message2, derivationPath);
// This signature can now be verified against pubkey
Extends
BIP340
Constructors
new BIP340()
new BIP340(
hostUrl
?):BIP340
Constructs a new BIP340 instance.
Parameters
• hostUrl?: string