Skip to content

Commit

Permalink
adapter - rename error for signing messages
Browse files Browse the repository at this point in the history
Signed-off-by: Lachezar Lechev <lachezar@ambire.com>
  • Loading branch information
elpiel committed Nov 25, 2022
1 parent 49f12c9 commit f6af18d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
8 changes: 4 additions & 4 deletions adapter/src/ethereum/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -275,14 +275,14 @@ impl<S: WalletState> Locked for Ethereum<S> {
#[async_trait]
impl Unlocked for Ethereum<UnlockedWallet> {
fn sign(&self, state_root: &str) -> Result<String, Error> {
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())))
}
Expand All @@ -297,7 +297,7 @@ impl Unlocked for Ethereum<UnlockedWallet> {
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())
}
Expand Down
19 changes: 11 additions & 8 deletions adapter/src/ethereum/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::Error as AdapterError;
use hex::FromHexError;
use primitives::{
address::Error as AddressError, big_num::ParseBigIntError, ChainId, ChannelId, ValidatorId,
};
Expand All @@ -17,12 +18,12 @@ impl From<Error> 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)
}
Expand Down Expand Up @@ -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}")]
Expand All @@ -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)]
Expand Down Expand Up @@ -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)]
Expand All @@ -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),
}

Expand Down

0 comments on commit f6af18d

Please sign in to comment.