pub struct Bip340 {
host_url: String,
}Expand description
A threshold BIP-340 (Schnorr signature) implementation.
BIP-340 provides Schnorr signatures for Bitcoin, offering advantages over ECDSA including simplified verification logic, better security properties, and support for key aggregation.
Fields§
§host_url: StringImplementations§
Source§impl Bip340
impl Bip340
Sourcepub fn new(host_url: String) -> Self
pub fn new(host_url: String) -> Self
Creates a new BIP340 instance with the specified host URL.
Sourcepub fn with_default_host() -> Self
pub fn with_default_host() -> Self
Creates a new BIP340 instance using the default production host URL.
Sourcepub fn init_keygen(&self) -> Result<(KeygenId, KeygenPrivateKey), SodotError>
pub fn init_keygen(&self) -> Result<(KeygenId, KeygenPrivateKey), SodotError>
Initializes the key generation process by creating a keygen ID and private key.
Sourcepub async fn create_room(
&self,
num_parties: NonZeroU16,
api_key: &str,
) -> Result<RoomUUID, SodotError>
pub async fn create_room( &self, num_parties: NonZeroU16, api_key: &str, ) -> Result<RoomUUID, SodotError>
Creates a room for coordinating multi-party computation protocols.
Sourcepub async fn keygen(
&self,
room_uuid: &RoomUUID,
num_parties: NonZeroU16,
threshold: NonZeroU16,
keygen_init_keypair: &KeygenPrivateKey,
keygen_ids: &[KeygenId],
) -> Result<(Bip340PublicKey, Bip340SecretShare), SodotError>
pub async fn keygen( &self, room_uuid: &RoomUUID, num_parties: NonZeroU16, threshold: NonZeroU16, keygen_init_keypair: &KeygenPrivateKey, keygen_ids: &[KeygenId], ) -> Result<(Bip340PublicKey, Bip340SecretShare), SodotError>
Generates a threshold BIP-340 key using distributed key generation.
Multiple parties collaborate to create a shared public key and individual secret shares. The resulting public key can be used for verification, while the secret shares are required for threshold signing.
Sourcepub async fn sign(
&self,
room_uuid: &RoomUUID,
secret_share: &Bip340SecretShare,
message: &[u8],
derivation_path: &[u32],
tweak: Option<&Bip340Tweak>,
) -> Result<[u8; 64], SodotError>
pub async fn sign( &self, room_uuid: &RoomUUID, secret_share: &Bip340SecretShare, message: &[u8], derivation_path: &[u32], tweak: Option<&Bip340Tweak>, ) -> Result<[u8; 64], SodotError>
Signs a message using the threshold BIP-340 scheme with optional Taproot tweaking.
This method performs threshold signing where a subset of parties (at least the threshold) collaborate to generate a valid BIP-340 Schnorr signature for a given message.
Sourcepub fn derive_tweak_pubkey(
&self,
secret_share: &Bip340SecretShare,
derivation_path: &[u32],
tweak: Option<&Bip340Tweak>,
) -> Result<Bip340PublicKey, SodotError>
pub fn derive_tweak_pubkey( &self, secret_share: &Bip340SecretShare, derivation_path: &[u32], tweak: Option<&Bip340Tweak>, ) -> Result<Bip340PublicKey, SodotError>
Derives a BIP-340 public key with optional Taproot tweaking from a secret share.
Sourcepub fn get_xpub(
&self,
secret_share: &Bip340SecretShare,
) -> Result<Bip340ExtendedPublicKey, SodotError>
pub fn get_xpub( &self, secret_share: &Bip340SecretShare, ) -> Result<Bip340ExtendedPublicKey, SodotError>
Returns a base58-encoded extended public key (Xpub) derived from a secret share.
Sourcepub fn derive_pubkey_from_xpub(
&self,
xpub: &Bip340ExtendedPublicKey,
derivation_path: &[u32],
tweak: Option<&Bip340Tweak>,
) -> Result<Bip340PublicKey, SodotError>
pub fn derive_pubkey_from_xpub( &self, xpub: &Bip340ExtendedPublicKey, derivation_path: &[u32], tweak: Option<&Bip340Tweak>, ) -> Result<Bip340PublicKey, SodotError>
Derives a BIP-340 public key from an extended public key (Xpub) with optional Taproot tweaking.
Sourcepub fn derive_private_key_from_xpriv(
&self,
xpriv: &Bip340ExtendedPrivateKey,
derivation_path: &[u32],
) -> Result<[u8; 32], SodotError>
pub fn derive_private_key_from_xpriv( &self, xpriv: &Bip340ExtendedPrivateKey, derivation_path: &[u32], ) -> Result<[u8; 32], SodotError>
Derives a private key from an extended private key (xpriv) using a BIP-32 derivation path.
Sourcepub async fn refresh(
&self,
room_uuid: &RoomUUID,
secret_share: &Bip340SecretShare,
) -> Result<(Bip340PublicKey, Bip340SecretShare), SodotError>
pub async fn refresh( &self, room_uuid: &RoomUUID, secret_share: &Bip340SecretShare, ) -> Result<(Bip340PublicKey, Bip340SecretShare), SodotError>
Refreshes the secret material of all parties without changing the public key.
Sourcepub fn export_id(
&self,
secret_share: &Bip340SecretShare,
) -> Result<KeygenId, SodotError>
pub fn export_id( &self, secret_share: &Bip340SecretShare, ) -> Result<KeygenId, SodotError>
Extracts the KeygenID from a secret share.
Sourcepub async fn export_full_private_key(
&self,
room_uuid: &RoomUUID,
secret_share: &Bip340SecretShare,
export_to: &KeygenId,
) -> Result<Option<Bip340ExtendedPrivateKey>, SodotError>
pub async fn export_full_private_key( &self, room_uuid: &RoomUUID, secret_share: &Bip340SecretShare, export_to: &KeygenId, ) -> Result<Option<Bip340ExtendedPrivateKey>, SodotError>
Combines threshold secret shares and exports the full private key to a single party.
Requires a threshold number of parties to participate. The export_to parameter specifies
the KeygenID of the party that should receive the private key. The designated party will
receive the full xpriv, while others receive None.
Sourcepub fn offline_export_full_private_key(
&self,
secret_shares: &[Bip340SecretShare],
) -> Result<Bip340ExtendedPrivateKey, SodotError>
pub fn offline_export_full_private_key( &self, secret_shares: &[Bip340SecretShare], ) -> Result<Bip340ExtendedPrivateKey, SodotError>
Locally reconstructs the full private key from a threshold number of secret shares.
Sourcepub async fn import_private_key_recipient(
&self,
room_uuid: &RoomUUID,
threshold: NonZeroU16,
keygen_init_keypair: &KeygenPrivateKey,
keygen_ids: &[KeygenId],
) -> Result<(Bip340PublicKey, Bip340SecretShare), SodotError>
pub async fn import_private_key_recipient( &self, room_uuid: &RoomUUID, threshold: NonZeroU16, keygen_init_keypair: &KeygenPrivateKey, keygen_ids: &[KeygenId], ) -> Result<(Bip340PublicKey, Bip340SecretShare), SodotError>
Participates as a recipient in a private key import operation.
Sourcepub async fn import_private_key_importer(
&self,
room_uuid: &RoomUUID,
threshold: NonZeroU16,
private_key: &[u8; 32],
keygen_init_keypair: &KeygenPrivateKey,
keygen_ids: &[KeygenId],
) -> Result<(Bip340PublicKey, Bip340SecretShare), SodotError>
pub async fn import_private_key_importer( &self, room_uuid: &RoomUUID, threshold: NonZeroU16, private_key: &[u8; 32], keygen_init_keypair: &KeygenPrivateKey, keygen_ids: &[KeygenId], ) -> Result<(Bip340PublicKey, Bip340SecretShare), SodotError>
Participates as the importer in a private key import operation.
Participates as a new party in a resharing operation.
Participates as a remaining party in a resharing operation.