mirror of
https://github.com/uqbar-dao/nectar.git
synced 2025-01-02 21:55:41 +03:00
remove ethers dep
This commit is contained in:
parent
4e1a798011
commit
2449393ca6
@ -45,8 +45,6 @@ crossterm = { version = "0.26.1", features = ["event-stream", "bracketed-paste"]
|
||||
dashmap = "5.5.3"
|
||||
digest = "0.10"
|
||||
elliptic-curve = { version = "0.13.8", features = ["ecdh"] }
|
||||
ethers = "2.0.13"
|
||||
ethers-providers = "2.0.13"
|
||||
flate2 = "1.0"
|
||||
futures = "0.3"
|
||||
generic-array = "0.14"
|
||||
|
@ -1,8 +1,8 @@
|
||||
use anyhow::Result;
|
||||
use dashmap::DashMap;
|
||||
use ethers_providers::StreamExt;
|
||||
use futures::stream::{SplitSink, SplitStream};
|
||||
use futures::SinkExt;
|
||||
use futures::StreamExt;
|
||||
use http::header::{HeaderMap, HeaderName, HeaderValue};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
@ -24,7 +24,7 @@ mod state;
|
||||
mod terminal;
|
||||
mod timer;
|
||||
mod vfs;
|
||||
|
||||
//
|
||||
const EVENT_LOOP_CHANNEL_CAPACITY: usize = 10_000;
|
||||
const EVENT_LOOP_DEBUG_CHANNEL_CAPACITY: usize = 50;
|
||||
const TERMINAL_CHANNEL_CAPACITY: usize = 32;
|
||||
|
@ -273,10 +273,12 @@ pub fn validate_routing_request(
|
||||
&signature::ED25519,
|
||||
hex::decode(strip_0x(&their_id.networking_key))?,
|
||||
);
|
||||
their_networking_key.verify(
|
||||
[&routing_request.target, our_name].concat().as_bytes(),
|
||||
&routing_request.signature,
|
||||
)?;
|
||||
their_networking_key
|
||||
.verify(
|
||||
[&routing_request.target, our_name].concat().as_bytes(),
|
||||
&routing_request.signature,
|
||||
)
|
||||
.map_err(|e| anyhow!("their_networking_key.verify failed: {:?}", e))?;
|
||||
if routing_request.target == routing_request.source {
|
||||
return Err(anyhow!("can't route to self"));
|
||||
}
|
||||
@ -296,7 +298,9 @@ pub fn validate_handshake(
|
||||
&signature::ED25519,
|
||||
hex::decode(strip_0x(&their_id.networking_key))?,
|
||||
);
|
||||
their_networking_key.verify(their_static_key, &handshake.signature)?;
|
||||
their_networking_key
|
||||
.verify(their_static_key, &handshake.signature)
|
||||
.map_err(|e| anyhow!("their_networking_key.verify handshake failed: {:?}", e))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
use aes_gcm::aead::KeyInit;
|
||||
use ethers::prelude::{abigen, namehash, Address as EthAddress, Provider, U256};
|
||||
use ethers_providers::Ws;
|
||||
use hmac::Hmac;
|
||||
use jwt::SignWithKey;
|
||||
use ring::rand::SystemRandom;
|
||||
@ -21,14 +19,6 @@ use warp::{
|
||||
use crate::keygen;
|
||||
use lib::types::core::*;
|
||||
|
||||
// Human readable ABI
|
||||
abigen!(
|
||||
KNSRegistry,
|
||||
r"[
|
||||
function ws(uint256 node) external view returns (bytes32,uint32,uint16,bytes32[])
|
||||
]"
|
||||
);
|
||||
|
||||
type RegistrationSender = mpsc::Sender<(Identity, Keyfile, Vec<u8>)>;
|
||||
|
||||
pub const KNS_SEPOLIA_ADDRESS: &str = "0x3807fBD692Aa5c96F1D8D7c59a1346a885F40B1C";
|
||||
@ -557,61 +547,3 @@ async fn success_response(
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
async fn _networking_info_valid(rpc_url: String, ip: String, ws_port: u16, our: &Identity) -> bool {
|
||||
// check if Identity for this username has correct networking keys,
|
||||
// if not, prompt user to reset them.
|
||||
let Ok(ws_rpc) = Provider::<Ws>::connect(rpc_url.clone()).await else {
|
||||
return false;
|
||||
};
|
||||
let Ok(kns_address): Result<EthAddress, _> = KNS_SEPOLIA_ADDRESS.parse() else {
|
||||
return false;
|
||||
};
|
||||
let contract = KNSRegistry::new(kns_address, ws_rpc.into());
|
||||
let node_id: U256 = namehash(&our.name).as_bytes().into();
|
||||
let Ok((chain_pubkey, chain_ip, chain_port, chain_routers)) = contract.ws(node_id).call().await
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
|
||||
// double check that routers match on-chain information
|
||||
let namehashed_routers: Vec<[u8; 32]> = our
|
||||
.allowed_routers
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|name| {
|
||||
let hash = namehash(&name);
|
||||
let mut result = [0u8; 32];
|
||||
result.copy_from_slice(hash.as_bytes());
|
||||
result
|
||||
})
|
||||
.collect();
|
||||
|
||||
let current_ip = match _ip_to_number(&ip) {
|
||||
Ok(ip_num) => ip_num,
|
||||
Err(_) => {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
let Ok(networking_key_bytes) = _hex_string_to_u8_array(&our.networking_key) else {
|
||||
return false;
|
||||
};
|
||||
|
||||
let address_match = chain_ip == current_ip && chain_port == ws_port;
|
||||
let routers_match = chain_routers == namehashed_routers;
|
||||
|
||||
let routing_match = if chain_ip == 0 {
|
||||
routers_match
|
||||
} else {
|
||||
address_match
|
||||
};
|
||||
let pubkey_match = chain_pubkey == networking_key_bytes;
|
||||
|
||||
// double check that keys match on-chain information
|
||||
if !routing_match || !pubkey_match {
|
||||
return false;
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user