2025-08-25 09:17:29 -04:00
|
|
|
use ciphersuite::Ciphersuite;
|
|
|
|
|
use dkg::{ThresholdKeys, Curves, Secp256k1};
|
2024-09-14 07:54:18 -04:00
|
|
|
|
2024-09-18 00:54:20 -04:00
|
|
|
use ethereum_schnorr::PublicKey;
|
2024-09-14 07:54:18 -04:00
|
|
|
|
|
|
|
|
pub(crate) struct KeyGenParams;
|
|
|
|
|
impl key_gen::KeyGenParams for KeyGenParams {
|
|
|
|
|
const ID: &'static str = "Ethereum";
|
|
|
|
|
|
|
|
|
|
type ExternalNetworkCiphersuite = Secp256k1;
|
|
|
|
|
|
2025-08-25 09:17:29 -04:00
|
|
|
fn tweak_keys(
|
|
|
|
|
keys: &mut ThresholdKeys<<Self::ExternalNetworkCiphersuite as Curves>::ToweringCurve>,
|
|
|
|
|
) {
|
2024-09-14 07:54:18 -04:00
|
|
|
while PublicKey::new(keys.group_key()).is_none() {
|
2025-08-25 09:17:29 -04:00
|
|
|
*keys = keys.clone().offset(<<Secp256k1 as Curves>::ToweringCurve as Ciphersuite>::F::ONE);
|
2024-09-14 07:54:18 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-25 09:17:29 -04:00
|
|
|
fn encode_key(
|
|
|
|
|
key: <<Self::ExternalNetworkCiphersuite as Curves>::ToweringCurve as Ciphersuite>::G,
|
|
|
|
|
) -> Vec<u8> {
|
2024-09-14 07:54:18 -04:00
|
|
|
PublicKey::new(key).unwrap().eth_repr().to_vec()
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-25 09:17:29 -04:00
|
|
|
fn decode_key(
|
|
|
|
|
key: &[u8],
|
|
|
|
|
) -> Option<<<Self::ExternalNetworkCiphersuite as Curves>::ToweringCurve as Ciphersuite>::G> {
|
2024-09-14 07:54:18 -04:00
|
|
|
PublicKey::from_eth_repr(key.try_into().ok()?).map(|key| key.point())
|
|
|
|
|
}
|
|
|
|
|
}
|