Skip to content

Commit

Permalink
Signature working
Browse files Browse the repository at this point in the history
  • Loading branch information
naps62 committed Aug 26, 2024
1 parent 5983d23 commit 2aed984
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 12 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

# web
axum = "0.7.2"
axum = { version = "0.7.2", features = ["tracing"] }
tower = "0.4.13"
tower-http = { version = "0.5.0", features = ["cors"] }
tower-http = { version = "0.5.0", features = ["cors", "trace"] }
jsonwebtoken = "9.2.0"
serde_json = "1.0.108"
axum-extra = { version = "0.9.0", features = ["typed-header"] }
Expand Down
2 changes: 1 addition & 1 deletion eip712.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"domain": {
"name": "ethui-indexer",
"version": "1",
"chainId": 11155111,
"chainId": 1,
"verifyingContract": "0x0000000000000000000000000000000000000000"
},
"primaryType": "IndexerAuth",
Expand Down
23 changes: 21 additions & 2 deletions src/api/app.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::str::FromStr as _;

use axum::{
extract::State,
extract::{MatchedPath, State},
http::Request,
middleware::from_extractor,
response::IntoResponse,
routing::{get, post},
Expand All @@ -12,7 +13,8 @@ use ethers_core::types::{Address, Signature};
use jsonwebtoken::{encode, DecodingKey, EncodingKey, Header};
use serde::{Deserialize, Serialize};
use serde_json::json;
use tower_http::cors::CorsLayer;
use tower_http::{cors::CorsLayer, trace::TraceLayer};
use tracing::info_span;

use super::{
app_state::AppState,
Expand Down Expand Up @@ -41,6 +43,23 @@ pub fn app(jwt_secret: String, state: AppState) -> Router {
.layer(Extension(encoding_key))
.layer(Extension(decoding_key))
.with_state(state)
.layer(
TraceLayer::new_for_http().make_span_with(|req: &Request<_>| {
// Log the matched route's path (with placeholders not filled in).
// Use request.uri() or OriginalUri if you want the real path.
let matched_path = req
.extensions()
.get::<MatchedPath>()
.map(MatchedPath::as_str);

info_span!(
"http_request",
method = ?req.method(),
matched_path,
some_other_field = tracing::field::Empty,
)
}),
)
}

async fn health() -> impl IntoResponse {}
Expand Down
6 changes: 0 additions & 6 deletions src/api/auth/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,9 @@ impl IndexerAuth {
}

pub fn check(&self, signature: &Signature) -> Result<()> {
dbg!("here");
self.check_expiration()?;
dbg!("here2");
let hash = self.encode_eip712()?;
dbg!(self);
dbg!(&hash);
dbg!(signature.recover(hash)?);
signature.verify(hash, self.address)?;
dbg!("here3");

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use self::{app::app, app_state::AppState};
use crate::{config::Config, db::Db, sync::RethProviderFactory};

#[allow(clippy::async_yields_async)]
#[instrument(name = "api", skip(db, config), fields(port = config.http.clone().unwrap().port))]
#[instrument(name = "api", skip(db, config, provider_factory), fields(port = config.http.clone().unwrap().port))]
pub async fn start(
db: Db,
config: Config,
Expand Down

0 comments on commit 2aed984

Please sign in to comment.