From 7e506cdf751275a0f8569ea64bee94a976c09f77 Mon Sep 17 00:00:00 2001 From: Davirain Date: Sat, 26 Aug 2023 11:07:36 +0800 Subject: [PATCH] Refactor key pair implementations This commit refactors the key pair implementations, adding a `KeyFile` type for each one. --- crates/relayer/src/keyring/ed25519_key_pair.rs | 1 + crates/relayer/src/keyring/secp256k1_key_pair.rs | 1 + crates/relayer/src/keyring/signing_key_pair.rs | 5 +++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/relayer/src/keyring/ed25519_key_pair.rs b/crates/relayer/src/keyring/ed25519_key_pair.rs index 8287ef5575..5e4c218ad7 100644 --- a/crates/relayer/src/keyring/ed25519_key_pair.rs +++ b/crates/relayer/src/keyring/ed25519_key_pair.rs @@ -83,6 +83,7 @@ impl Ed25519KeyPair { impl SigningKeyPair for Ed25519KeyPair { const KEY_TYPE: KeyType = KeyType::Ed25519; + type KeyFile = KeyFile; fn from_key_file(key_file: KeyFile, hd_path: &StandardHDPath) -> Result { use ed25519_dalek::PUBLIC_KEY_LENGTH; diff --git a/crates/relayer/src/keyring/secp256k1_key_pair.rs b/crates/relayer/src/keyring/secp256k1_key_pair.rs index 866608d96d..3e3ab7fd17 100644 --- a/crates/relayer/src/keyring/secp256k1_key_pair.rs +++ b/crates/relayer/src/keyring/secp256k1_key_pair.rs @@ -233,6 +233,7 @@ impl Secp256k1KeyPair { impl SigningKeyPair for Secp256k1KeyPair { const KEY_TYPE: KeyType = KeyType::Secp256k1; + type KeyFile = KeyFile; fn from_key_file(key_file: KeyFile, hd_path: &StandardHDPath) -> Result { // Decode the Bech32-encoded address from the key file diff --git a/crates/relayer/src/keyring/signing_key_pair.rs b/crates/relayer/src/keyring/signing_key_pair.rs index 048b6f0aee..4609840f01 100644 --- a/crates/relayer/src/keyring/signing_key_pair.rs +++ b/crates/relayer/src/keyring/signing_key_pair.rs @@ -3,13 +3,14 @@ use core::any::Any; use hdpath::StandardHDPath; use serde::{de::DeserializeOwned, Serialize}; -use super::{errors::Error, KeyFile, KeyType}; +use super::{errors::Error, KeyType}; use crate::config::AddressType; pub trait SigningKeyPair { const KEY_TYPE: KeyType; + type KeyFile: DeserializeOwned; - fn from_key_file(key_file: KeyFile, hd_path: &StandardHDPath) -> Result + fn from_key_file(key_file: Self::KeyFile, hd_path: &StandardHDPath) -> Result where Self: Sized;