mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +00:00
35 lines
1.0 KiB
Rust
35 lines
1.0 KiB
Rust
use ciphersuite::{group::GroupEncoding, Ciphersuite};
|
|
use dkg::{ThresholdKeys, Curves, Secp256k1};
|
|
|
|
use crate::{primitives::x_coord_to_even_point, scan::scanner};
|
|
|
|
pub(crate) struct KeyGenParams;
|
|
impl key_gen::KeyGenParams for KeyGenParams {
|
|
const ID: &'static str = "Bitcoin";
|
|
|
|
type ExternalNetworkCiphersuite = Secp256k1;
|
|
|
|
fn tweak_keys(
|
|
keys: &mut ThresholdKeys<<Self::ExternalNetworkCiphersuite as Curves>::ToweringCurve>,
|
|
) {
|
|
*keys = bitcoin_serai::wallet::tweak_keys(keys.clone());
|
|
// Also create a scanner to assert these keys, and all expected paths, are usable
|
|
scanner(keys.group_key());
|
|
}
|
|
|
|
fn encode_key(
|
|
key: <<Self::ExternalNetworkCiphersuite as Curves>::ToweringCurve as Ciphersuite>::G,
|
|
) -> Vec<u8> {
|
|
let key = key.to_bytes();
|
|
let key: &[u8] = key.as_ref();
|
|
// Skip the parity encoding as we know this key is even
|
|
key[1 ..].to_vec()
|
|
}
|
|
|
|
fn decode_key(
|
|
key: &[u8],
|
|
) -> Option<<<Self::ExternalNetworkCiphersuite as Curves>::ToweringCurve as Ciphersuite>::G> {
|
|
x_coord_to_even_point(key)
|
|
}
|
|
}
|