2022-07-16 21:45:41 +00:00
|
|
|
use thiserror::Error;
|
2023-11-06 17:26:32 -05:00
|
|
|
use eyre::{eyre, Result};
|
|
|
|
|
|
|
|
|
|
use ethers_providers::{Provider, Http};
|
2023-11-08 07:52:32 -05:00
|
|
|
use ethers_contract::abigen;
|
2023-11-06 17:26:32 -05:00
|
|
|
|
|
|
|
|
use crate::crypto::ProcessedSignature;
|
2022-07-16 21:45:41 +00:00
|
|
|
|
|
|
|
|
#[derive(Error, Debug)]
|
|
|
|
|
pub enum EthereumError {
|
|
|
|
|
#[error("failed to verify Schnorr signature")]
|
|
|
|
|
VerificationError,
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-06 18:12:53 -05:00
|
|
|
abigen!(Schnorr, "./artifacts/Schnorr.sol/Schnorr.json");
|
2022-07-16 21:45:41 +00:00
|
|
|
|
|
|
|
|
pub async fn call_verify(
|
2023-11-08 07:52:32 -05:00
|
|
|
contract: &Schnorr<Provider<Http>>,
|
2022-07-16 21:45:41 +00:00
|
|
|
params: &ProcessedSignature,
|
|
|
|
|
) -> Result<()> {
|
2022-07-22 02:34:36 -04:00
|
|
|
if contract
|
2022-07-16 21:45:41 +00:00
|
|
|
.verify(
|
|
|
|
|
params.parity + 27,
|
|
|
|
|
params.px.to_bytes().into(),
|
2022-07-22 02:34:36 -04:00
|
|
|
params.message,
|
2022-07-16 21:45:41 +00:00
|
|
|
params.s.to_bytes().into(),
|
|
|
|
|
params.e.to_bytes().into(),
|
|
|
|
|
)
|
|
|
|
|
.call()
|
2022-07-22 02:34:36 -04:00
|
|
|
.await?
|
|
|
|
|
{
|
2022-07-16 21:45:41 +00:00
|
|
|
Ok(())
|
|
|
|
|
} else {
|
|
|
|
|
Err(eyre!(EthereumError::VerificationError))
|
|
|
|
|
}
|
|
|
|
|
}
|