async fn verify_eth_signature(
    request: &VerifyTxSignatureRequest,
    eth_watch_req: mpsc::Sender<EthWatchRequest>,
) -> Result<(), TxAddError> {
    // Check if the tx is a `ChangePubKey` operation without an Ethereum signature.
    if let FranklinTx::ChangePubKey(change_pk) = &request.tx {
        if change_pk.eth_signature.is_none() {
            // Check that user is allowed to perform this operation.
            let eth_watch_resp = oneshot::channel();
            eth_watch_req
                .clone()
                .send(EthWatchRequest::IsPubkeyChangeAuthorized {
                    address: change_pk.account,
                    nonce: change_pk.nonce,
                    pubkey_hash: change_pk.new_pk_hash.clone(),
                    resp: eth_watch_resp.0,
                })
                .await
                .expect("ETH watch req receiver dropped");

            let is_authorized = eth_watch_resp.1.await.expect("Err response from eth watch");
            if !is_authorized {
                return Err(TxAddError::ChangePkNotAuthorized);
            }
        }
    }

    // Check the signature.
    if let Some(sign_data) = &request.eth_sign_data {
        match &sign_data.signature {
            TxEthSignature::EthereumSignature(packed_signature) => {
                let signer_account = packed_signature
                    .signature_recover_signer(sign_data.message.as_bytes())
                    .or(Err(TxAddError::IncorrectEthSignature))?;

                if signer_account != request.tx.account() {
                    return Err(TxAddError::IncorrectEthSignature);
                }
            }
            TxEthSignature::EIP1271Signature(signature) => {
                let message = format!(
                    "\x19Ethereum Signed Message:\n{}{}",
                    sign_data.message.len(),
                    &sign_data.message
                );

                let eth_watch_resp = oneshot::channel();
                eth_watch_req
                    .clone()
                    .send(EthWatchRequest::CheckEIP1271Signature {
                        address: request.tx.account(),
                        message: message.into_bytes(),
                        signature: signature.clone(),
                        resp: eth_watch_resp.0,
                    })
                    .await
                    .expect("ETH watch req receiver dropped");

                let signature_correct = eth_watch_resp
                    .1
                    .await
                    .expect("Failed receiving response from eth watch")
                    .map_err(|e| warn!("Err in eth watch: {}", e))
                    .or(Err(TxAddError::EIP1271SignatureVerificationFail))?;

                if !signature_correct {
                    return Err(TxAddError::IncorrectTx);
                }
            }
        };
    }

    Ok(())
}
/// Verifies the Ethereum signature of the transaction.
Verifies the Ethereum signature of the transaction.
Verifies the Ethereum signature of the transaction .
async fn verify_eth_signature(
    request: &VerifyTxSignatureRequest,
    eth_watch_req: mpsc::Sender<EthWatchRequest>,
) -> Result<(), TxAddError> {
    // Check if the tx is a `ChangePubKey` operation without an Ethereum signature.
    if let FranklinTx::ChangePubKey(change_pk) = &request.tx {
        if change_pk.eth_signature.is_none() {
            // Check that user is allowed to perform this operation.
            let eth_watch_resp = oneshot::channel();
            eth_watch_req
                .clone()
                .send(EthWatchRequest::IsPubkeyChangeAuthorized {
                    address: change_pk.account,
                    nonce: change_pk.nonce,
                    pubkey_hash: change_pk.new_pk_hash.clone(),
                    resp: eth_watch_resp.0,
                })
                .await
                .expect("ETH watch req receiver dropped");
            let is_authorized = eth_watch_resp.1.await.expect("Err response from eth watch");
            if !is_authorized {
                return Err(TxAddError::ChangePkNotAuthorized);
            }
        }
    }
    // Check the signature.
    if let Some(sign_data) = &request.eth_sign_data {
        match &sign_data.signature {
            TxEthSignature::EthereumSignature(packed_signature) => {
                let signer_account = packed_signature
                    .signature_recover_signer(sign_data.message.as_bytes())
                    .or(Err(TxAddError::IncorrectEthSignature))?;
                if signer_account != request.tx.account() {
                    return Err(TxAddError::IncorrectEthSignature);
                }
            }
            TxEthSignature::EIP1271Signature(signature) => {
                let message = format!(
                    "\x19Ethereum Signed Message:\n{}{}",
                    sign_data.message.len(),
                    &sign_data.message
                );
                let eth_watch_resp = oneshot::channel();
                eth_watch_req
                    .clone()
                    .send(EthWatchRequest::CheckEIP1271Signature {
                        address: request.tx.account(),
                        message: message.into_bytes(),
                        signature: signature.clone(),
                        resp: eth_watch_resp.0,
                    })
                    .await
                    .expect("ETH watch req receiver dropped");
                let signature_correct = eth_watch_resp
                    .1
                    .await
                    .expect("Failed receiving response from eth watch")
                    .map_err(|e| warn!("Err in eth watch: {}", e))
                    .or(Err(TxAddError::EIP1271SignatureVerificationFail))?;
                if !signature_correct {
                    return Err(TxAddError::IncorrectTx);
                }
            }
        };
    }
    Ok(())
}
async fn verify_eth_signature ( request : & VerifyTxSignatureRequest , eth_watch_req : mpsc :: Sender < EthWatchRequest > , ) -> Result < ( ) , TxAddError > { // Check if the tx is a `ChangePubKey` operation without an Ethereum signature. if let FranklinTx :: ChangePubKey ( change_pk ) = & request . tx { if change_pk . eth_signature . is_none ( ) { // Check that user is allowed to perform this operation. let eth_watch_resp = oneshot :: channel ( ) ; eth_watch_req . clone ( ) . send ( EthWatchRequest :: IsPubkeyChangeAuthorized { address : change_pk . account , nonce : change_pk . nonce , pubkey_hash : change_pk . new_pk_hash . clone ( ) , resp : eth_watch_resp . 0 , } ) . await . expect ( " " ) ; let is_authorized = eth_watch_resp . 1 . await . expect ( " " ) ; if ! is_authorized { return Err ( TxAddError :: ChangePkNotAuthorized ) ; } } } // Check the signature. if let Some ( sign_data ) = & request . eth_sign_data { match & sign_data . signature { TxEthSignature :: EthereumSignature ( packed_signature ) => { let signer_account = packed_signature . signature_recover_signer ( sign_data . message . as_bytes ( ) ) . or ( Err ( TxAddError :: IncorrectEthSignature ) ) ? ; if signer_account != request . tx . account ( ) { return Err ( TxAddError :: IncorrectEthSignature ) ; } } TxEthSignature :: EIP1271Signature ( signature ) => { let message = format ! ( " \x19 \n " sign_data message len ( ) sign_data message ) ; let eth_watch_resp = oneshot :: channel ( ) ; eth_watch_req . clone ( ) . send ( EthWatchRequest :: CheckEIP1271Signature { address : request . tx . account ( ) , message : message . into_bytes ( ) , signature : signature . clone ( ) , resp : eth_watch_resp . 0 , } ) . await . expect ( " " ) ; let signature_correct = eth_watch_resp . 1 . await . expect ( " " ) . map_err ( | e | warn ! ( " " e ) ) . or ( Err ( TxAddError :: EIP1271SignatureVerificationFail ) ) ? ; if ! signature_correct { return Err ( TxAddError :: IncorrectTx ) ; } } } ; } Ok ( ( ) ) }
Verifies the Ethereum signature of the transaction.
Verifies the Ethereum signature of the transaction .
request
&VerifyTxSignatureRequest
eth_watch_req
mpsc::Sender<EthWatchRequest>