Table of Contents

Class Bip340

Namespace
SodotSDK.Bip340
Assembly
Unity.Temp.dll

Class providing the functionality for the BIP340 protocol the implementing FROST MPC protocol.

public class Bip340 : Scheme
Inheritance
MonoBehaviour
Bip340
Inherited Members

Constructors

Bip340(string)

Initializes a new instance of the Bip340 class.

public Bip340(string hostUrl)

Parameters

hostUrl string

The host URL for the Relay server.

Methods

DerivePrivateKeyFromXpriv(string, uint[])

Derives a private key from an xpriv according to BIP-32 non-hardened using for a given BIP-32 non-hardened derivation path. xpriv must be a valid secp256k1 xpriv string.

public Task<PrivateKey> DerivePrivateKeyFromXpriv(string xpriv, uint[] derivationPath)

Parameters

xpriv string

The XPRV as a hex string.

derivationPath uint[]

The derivation path for the key.

Returns

Task<PrivateKey>

The derived private key.

DeriveTweakPubkey(Bip340SecretShare, uint[], Bip340Tweak?)

Derives a (optionally)derived and (optionally)tweaked public key for a Bip340SecretShare for a given BIP-32 non-hardened derivation path and an optional BIP-341 tweak The tweak is used to tweak a public key with a BIP-341 Taproot tweaking, by supplying the T value from the BIP-341 Taproot specification(https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#script-validation-rules): Let t = hash_{TapTweak}(p || km). If t ≥ 0xFFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE BAAEDCE6 AF48A03B BFD25E8C D0364141 (order of secp256k1), fail. Let Q = P + int(t)G.

public Task<Bip340PublicKey> DeriveTweakPubkey(Bip340SecretShare secretShare, uint[] derivationPath, Bip340Tweak? optTweak)

Parameters

secretShare Bip340SecretShare

The secret share.

derivationPath uint[]

The derivation path for the key.

optTweak Bip340Tweak?

Optional tweak for the derivation.

Returns

Task<Bip340PublicKey>

The derived tweaked public key.

DeriveTweakPubkeyFromXpub(string, uint[], Bip340Tweak?)

Derives a tweaked public key from an XPUB (extended public key) using a derivation path and an optional tweak.

public Task<Bip340PublicKey> DeriveTweakPubkeyFromXpub(string xpub, uint[] derivationPath, Bip340Tweak? optTweak)

Parameters

xpub string

The XPUB as a hex string.

derivationPath uint[]

The derivation path for the key.

optTweak Bip340Tweak?

Optional tweak for the derivation.

Returns

Task<Bip340PublicKey>

The derived tweaked public key.

ExportFullPrivateKey(Uuid, Bip340SecretShare, KeygenId)

Exports the full private key to a single party by combining all of the secret shares.

public Task<string> ExportFullPrivateKey(Uuid uuid, Bip340SecretShare secretShare, KeygenId keygenId)

Parameters

uuid Uuid

The room UUID.

secretShare Bip340SecretShare

The secret share.

keygenId KeygenId

The export target keygen ID.

Returns

Task<string>

The exported private key as a hex string.

GetExportId(Bip340SecretShare)

Gets the export ID from a secret share. The party that expects to receive the private key needs to call this function before ExportFullPrivateKey(Uuid, Bip340SecretShare, KeygenId). It must then transmit the ID to threshold-1 parties, this can be done in an untrusted channel (as if the parties use different keys this will break) Once the parties have the exportID of the party they want to export the private key to, the party and the threshold-1 participants need to call exportFullPrivatekey with that ID.

public Task<KeygenId> GetExportId(Bip340SecretShare secretShare)

Parameters

secretShare Bip340SecretShare

The secret share.

Returns

Task<KeygenId>

The export ID as a KeygenId.

GetXpub(Bip340SecretShare)

Gets the XPUB (base58 encoded extended public key) from a BIP340SecretShare. The Xpub can be used either via third party libraries or via DeriveTweakPubkeyFromXpub(string, uint[], Bip340Tweak?) [BIP-32]: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#serialization-format

public Task<Bip340SecretShare> GetXpub(Bip340SecretShare secretShare)

Parameters

secretShare Bip340SecretShare

The secret share.

Returns

Task<Bip340SecretShare>

The XPUB as a Bip340SecretShare.

ImportPrivateKeyImporter(Uuid, ushort, string, KeygenSecret, KeygenId[])

Imports a private key as an importer in the key generation process. WARNING: Private key import is an advanced feature of the SDK. We strongly advise consulting with the Sodot team before using it, due to a full private key being imported from a different system. Secret shares generated from imported private keys will always have the risk of the private key having been compromised in the past or in the future in case the private key is not deleted after the import operation. Importing a full private key, and sharing into a T-of-N sharing, the resultant key shares will be of the exact same public key as the full private key. This is the method that an importing party (meaning one the party in possesion of the private key) should use for receiving a key share in the new T-of-N quorum.

public Task<(Bip340PublicKey, Bip340SecretShare)> ImportPrivateKeyImporter(Uuid uuid, ushort threshold, string privateKeyHex, KeygenSecret keygenSecret, KeygenId[] keygenIds)

Parameters

uuid Uuid

The room UUID.

threshold ushort

The threshold for the key generation.

privateKeyHex string

The private key as a hex string.

keygenSecret KeygenSecret

A KeygenSecret returned from InitKeygen.

keygenIds KeygenId[]

Array of keygen IDs.

Returns

Task<(Bip340PublicKey, Bip340SecretShare)>

The public key and secret share.

ImportPrivateKeyRecipient(Uuid, ushort, KeygenSecret, KeygenId[])

Imports a private key as a recipient in the key generation process. WARNING: Private key import is an advanced feature of the SDK. We strongly advise consulting with the Sodot team before using it, due to a full private key being imported from a different system. Secret shares generated from imported private keys will always have the risk of the private key having been compromised in the past or in the future in case the private key is not deleted after the import operation. Importing a full private key, and sharing into a T-of-N sharing, the resultant key shares will be of the exact same public key as the full private key. This is the method that a new party (meaning one that does not currently have the private key) should use for receiving a key share in the new T-of-N quorum. The method takes the same input parameters as keygen since for a new party joining the quorum the import operation is very similar to a keygen operation.

public Task<(Bip340PublicKey, Bip340SecretShare)> ImportPrivateKeyRecipient(Uuid uuid, ushort threshold, KeygenSecret keygenSecret, KeygenId[] keygenIds)

Parameters

uuid Uuid

The room UUID.

threshold ushort

The threshold for the key generation.

keygenSecret KeygenSecret

A KeygenSecret returned from InitKeygen.

keygenIds KeygenId[]

Array of keygen IDs.

Returns

Task<(Bip340PublicKey, Bip340SecretShare)>

The public key and secret share.

Keygen(Uuid, ushort, ushort, KeygenSecret, KeygenId[])

Starts a distributed key generation for BIP340 for a given number of parties and threshold.

public Task<(Bip340PublicKey, Bip340SecretShare)> Keygen(Uuid uuid, ushort numParties, ushort threshold, KeygenSecret keygenSecret, KeygenId[] keygenIds)

Parameters

uuid Uuid

The room UUID.

numParties ushort

Number of parties.

threshold ushort

Threshold value.

keygenSecret KeygenSecret

A KeygenSecret returned from InitKeygen.

keygenIds KeygenId[]

Array of keygen IDs.

Returns

Task<(Bip340PublicKey, Bip340SecretShare)>

The public key and secret share.

OfflineExportFullPrivateKey(Bip340SecretShare[])

Exports the full private key offline for a set of secret shares. Requires a threshold amount of parties to participate.

public Task<string> OfflineExportFullPrivateKey(Bip340SecretShare[] secretShares)

Parameters

secretShares Bip340SecretShare[]

The array of secret shares.

Returns

Task<string>

The exported private key as a hex string.

Refresh(Uuid, Bip340SecretShare)

Refreshes the key pair by generating a new public key and secret share. Takes an BIP340SecretShare as input and returns a new one for the same public key but with fresh key material. Be careful to delete the Bip340SecretShare given as input before it is certain that all devices have properly stored the fresh BIP340SecretShare that is output. Note that the new BIP340SecretShare-s may only be used with each other, attempting to use older BIP340SecretShare-s with newer ones for signing will result in failure.

public Task<(Bip340PublicKey, Bip340SecretShare)> Refresh(Uuid uuid, Bip340SecretShare secretShare)

Parameters

uuid Uuid

The room UUID.

secretShare Bip340SecretShare

The current secret share.

Returns

Task<(Bip340PublicKey, Bip340SecretShare)>

The new public key and secret share.

ReshareNewParty(Uuid, ushort, KeygenSecret, KeygenId[])

Reshares the secret share to a new party with a new threshold. WARNING: Key resharing is an advanced feature of the SDK. We strongly advise consulting with the Sodot team before using it, as incorrect usage might lead to the detriment of the private key security. To use the feature correctly, developers using this feature must make sure that at least n - t + 1 parties of the t-of-n signing quorum delete their current shares before using the resharing of the private key. Also, after resharing, the resharing operation must not be considered complete until such deletion has occurred. Since deleting a share cannot be guaranteed cryptographically, it must be guaranteed by the software architecture (hence, by the developers using the SDK).

public Task<(Bip340PublicKey, Bip340SecretShare)> ReshareNewParty(Uuid uuid, ushort newThreshold, KeygenSecret keygenSecret, KeygenId[] keygenIds)

Parameters

uuid Uuid

The room UUID.

newThreshold ushort

The new threshold value.

keygenSecret KeygenSecret

A KeygenSecret returned from InitKeygen.

keygenIds KeygenId[]

Array of keygen IDs for the new party.

Returns

Task<(Bip340PublicKey, Bip340SecretShare)>

The public key and secret share for the new party.

ReshareRemainingParty(Uuid, ushort, Bip340SecretShare, KeygenId[])

Reshares the remaining party's secret share to a new threshold. WARNING: Key resharing is an advanced feature of the SDK. We strongly advise consulting with the Sodot team before using it, as incorrect usage might lead to the detriment of the private key security. To use the feature correctly, developers using this feature must make sure that at least n - t + 1 parties of the t-of-n signing quorum delete their current shares before using the resharing of the private key. Also, after resharing, the resharing operation must not be considered complete until such deletion has occurred. Since deleting a share cannot be guaranteed cryptographically, it must be guaranteed by the software architecture (hence, by the developers using the SDK).

public Task<(Bip340PublicKey, Bip340SecretShare)> ReshareRemainingParty(Uuid uuid, ushort newThreshold, Bip340SecretShare secretShare, KeygenId[] keygenIds)

Parameters

uuid Uuid

The room UUID.

newThreshold ushort

The new threshold value.

secretShare Bip340SecretShare

The current secret share of the party.

keygenIds KeygenId[]

Array of keygen IDs for the remaining party.

Returns

Task<(Bip340PublicKey, Bip340SecretShare)>

The public key and secret share for the remaining party.

Sign(Uuid, Bip340SecretShare, byte[], uint[], Bip340Tweak?)

Sign a message with the secret share contained in an BIP340KeygenResult. Notice that unlike ECDSA, in BIP340 there's no need to hash the message before signing it. This supports BIP-341 Taproot tweaking by supplying the T value from the BIP-341 Taproot specification(https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#script-validation-rules): Let t = hash_{ TapTweak} (p || km). If t ≥ 0xFFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE BAAEDCE6 AF48A03B BFD25E8C D0364141(order of secp256k1), fail. Let Q = P + int(t)G.

public Task<Bip340Signature> Sign(Uuid uuid, Bip340SecretShare secretShare, byte[] msg, uint[] derivationPath, Bip340Tweak? optTweak = null)

Parameters

uuid Uuid

The room UUID.

secretShare Bip340SecretShare

The secret share.

msg byte[]

The message to be signed.

derivationPath uint[]

The derivation path for the key.

optTweak Bip340Tweak?

Optional tweak for the signing.

Returns

Task<Bip340Signature>

The BIP340 signature.