From f6af18df04af42a107076a8c7f8585bd75247a58 Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Fri, 25 Nov 2022 11:33:16 +0200 Subject: [PATCH] adapter - rename error for signing messages Signed-off-by: Lachezar Lechev --- adapter/src/ethereum/client.rs | 8 ++++---- adapter/src/ethereum/error.rs | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/adapter/src/ethereum/client.rs b/adapter/src/ethereum/client.rs index 4034e9178..6ede76817 100644 --- a/adapter/src/ethereum/client.rs +++ b/adapter/src/ethereum/client.rs @@ -10,7 +10,7 @@ use ethsign::{KeyFile, Signature}; use primitives::{Address, BigNum, Chain, ChainId, ChainOf, Channel, Config, ValidatorId}; use super::{ - error::{Error, KeystoreError, OutpaceError, VerifyError}, + error::{Error, KeystoreError, SigningError, VerifyError}, ewt::{self, Payload}, to_ethereum_signed, Electrum, LockedWallet, UnlockedWallet, WalletState, IDENTITY_ABI, OUTPACE_ABI, @@ -275,14 +275,14 @@ impl Locked for Ethereum { #[async_trait] impl Unlocked for Ethereum { fn sign(&self, state_root: &str) -> Result { - let state_root = hex::decode(state_root).map_err(VerifyError::StateRootDecoding)?; + let state_root = hex::decode(state_root).map_err(SigningError::StateRootDecoding)?; let message = to_ethereum_signed(&state_root); let wallet_sign = self .state .wallet .sign(&message) - .map_err(|err| OutpaceError::SignStateroot(err.to_string()))?; + .map_err(|err| SigningError::SignStateRoot(err.to_string()))?; Ok(format!("0x{}", hex::encode(wallet_sign.to_electrum()))) } @@ -297,7 +297,7 @@ impl Unlocked for Ethereum { chain_id: for_chain, }; - let token = ewt::Token::sign(&self.state.wallet, payload).map_err(Error::SignMessage)?; + let token = ewt::Token::sign(&self.state.wallet, payload).map_err(Error::TokenSign)?; Ok(token.to_string()) } diff --git a/adapter/src/ethereum/error.rs b/adapter/src/ethereum/error.rs index b15245d3f..78494aeea 100644 --- a/adapter/src/ethereum/error.rs +++ b/adapter/src/ethereum/error.rs @@ -1,4 +1,5 @@ use crate::Error as AdapterError; +use hex::FromHexError; use primitives::{ address::Error as AddressError, big_num::ParseBigIntError, ChainId, ChannelId, ValidatorId, }; @@ -17,12 +18,12 @@ impl From for AdapterError { err @ Error::ChainNotWhitelisted(..) => AdapterError::adapter(err), err @ Error::InvalidDepositAsset(..) => AdapterError::adapter(err), err @ Error::BigNumParsing(..) => AdapterError::adapter(err), - err @ Error::SignMessage(..) => AdapterError::adapter(err), + err @ Error::TokenSign(..) => AdapterError::adapter(err), err @ Error::VerifyMessage(..) => AdapterError::adapter(err), err @ Error::ContractInitialization(..) => AdapterError::adapter(err), err @ Error::ContractQuerying(..) => AdapterError::adapter(err), err @ Error::VerifyAddress(..) => AdapterError::adapter(err), - err @ Error::OutpaceError(..) => AdapterError::adapter(err), + err @ Error::SigningMessage(..) => AdapterError::adapter(err), err @ Error::AuthenticationTokenNotIntendedForUs { .. } => { AdapterError::authentication(err) } @@ -52,7 +53,7 @@ pub enum Error { ChannelInactive(ChannelId), /// Signing of the message failed #[error("Signing message: {0}")] - SignMessage(#[from] EwtSigningError), + TokenSign(#[from] EwtSigningError), #[error("Verifying message: {0}")] VerifyMessage(#[from] EwtVerifyError), #[error("Contract initialization: {0}")] @@ -76,7 +77,7 @@ pub enum Error { #[error("Insufficient privilege")] InsufficientAuthorizationPrivilege, #[error("Outpace contract error: {0}")] - OutpaceError(#[from] OutpaceError), + SigningMessage(#[from] SigningError), } #[derive(Debug, Error)] @@ -127,9 +128,11 @@ pub enum EwtSigningError { } #[derive(Debug, Error)] -pub enum OutpaceError { - #[error("Error while signing outpace contract: {0}")] - SignStateroot(String), +pub enum SigningError { + #[error("Error while signing message: {0}")] + SignStateRoot(String), + #[error("Error while decoding StateRoot from hex")] + StateRootDecoding(#[from] FromHexError), } #[derive(Debug, Error)] @@ -151,7 +154,7 @@ pub enum EwtVerifyError { /// or if Signature V component is not in "Electrum" notation (`< 27`). #[error("Error when decoding token signature")] InvalidSignature, - #[error("Payload error: {0}")] + #[error(transparent)] Payload(#[from] PayloadError), }