better namehash, fix fakenet txs

This commit is contained in:
bitful-pannul 2024-07-05 23:14:41 +03:00
parent 93ffc18123
commit d87bdbfd52
4 changed files with 97 additions and 205 deletions

234
Cargo.lock generated
View File

@ -116,25 +116,6 @@ dependencies = [
"reqwest 0.12.5",
]
[[package]]
name = "alloy"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5bcb4400a1939e5633939a58500c67123ef5f2e8920e5009d6949552f191be7f"
dependencies = [
"alloy-consensus 0.1.1",
"alloy-core",
"alloy-eips 0.1.1",
"alloy-genesis 0.1.1",
"alloy-json-rpc 0.1.1",
"alloy-provider 0.1.1",
"alloy-rpc-client 0.1.1",
"alloy-rpc-types 0.1.1",
"alloy-serde 0.1.1",
"alloy-transport-http 0.1.1",
"reqwest 0.12.4",
]
[[package]]
name = "alloy-chains"
version = "0.1.23"
@ -181,9 +162,9 @@ checksum = "0c26b7d34cb76f826558e9409a010e25257f7bfb5aa5e3dd0042c564664ae159"
dependencies = [
"alloy-dyn-abi",
"alloy-json-abi",
"alloy-network 0.1.0",
"alloy-network",
"alloy-primitives",
"alloy-provider 0.1.0",
"alloy-provider",
"alloy-pubsub",
"alloy-rpc-types-eth",
"alloy-sol-types",
@ -308,19 +289,6 @@ dependencies = [
"tracing",
]
[[package]]
name = "alloy-json-rpc"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d06d33b79246313c4103ef9596c721674a926f1ddc8b605aa2bac4d8ba94ee34"
dependencies = [
"alloy-primitives",
"serde",
"serde_json",
"thiserror",
"tracing",
]
[[package]]
name = "alloy-network"
version = "0.1.3"
@ -397,38 +365,6 @@ dependencies = [
"url",
]
[[package]]
name = "alloy-provider"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "200b786259a17acf318b9c423afe9669bec24ce9cdf59de153ff9a4009914bb6"
dependencies = [
"alloy-chains",
"alloy-consensus 0.1.1",
"alloy-eips 0.1.1",
"alloy-json-rpc 0.1.1",
"alloy-network 0.1.1",
"alloy-primitives",
"alloy-rpc-client 0.1.1",
"alloy-rpc-types-eth",
"alloy-transport 0.1.1",
"alloy-transport-http 0.1.1",
"async-stream",
"async-trait",
"auto_impl",
"dashmap",
"futures",
"futures-utils-wasm",
"lru",
"pin-project",
"reqwest 0.12.4",
"serde",
"serde_json",
"tokio",
"tracing",
"url",
]
[[package]]
name = "alloy-pubsub"
version = "0.1.3"
@ -494,27 +430,6 @@ dependencies = [
"url",
]
[[package]]
name = "alloy-rpc-client"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "328a6a14aba6152ddf6d01bac5e17a70dbe9d6f343bf402b995c30bac63a1fbf"
dependencies = [
"alloy-json-rpc 0.1.1",
"alloy-transport 0.1.1",
"alloy-transport-http 0.1.1",
"futures",
"pin-project",
"reqwest 0.12.4",
"serde",
"serde_json",
"tokio",
"tokio-stream",
"tower",
"tracing",
"url",
]
[[package]]
name = "alloy-rpc-types"
version = "0.1.0"
@ -605,7 +520,7 @@ dependencies = [
"alloy-consensus 0.1.3",
"alloy-network",
"alloy-primitives",
"alloy-signer 0.1.0",
"alloy-signer",
"async-trait",
"k256",
"rand 0.8.5",
@ -720,24 +635,6 @@ dependencies = [
"url",
]
[[package]]
name = "alloy-transport"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3628d81530263fe837a09cd527022f5728202a669973f04270942f4d390b5f5"
dependencies = [
"alloy-json-rpc 0.1.1",
"base64 0.22.0",
"futures-util",
"futures-utils-wasm",
"serde",
"serde_json",
"thiserror",
"tokio",
"tower",
"url",
]
[[package]]
name = "alloy-transport-http"
version = "0.1.3"
@ -753,21 +650,6 @@ dependencies = [
"url",
]
[[package]]
name = "alloy-transport-http"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f35d34e7a51503c9ff267404a5850bd58f991b7ab524b892f364901e3576376"
dependencies = [
"alloy-json-rpc 0.1.1",
"alloy-transport 0.1.1",
"reqwest 0.12.4",
"serde_json",
"tower",
"tracing",
"url",
]
[[package]]
name = "alloy-transport-ws"
version = "0.1.3"
@ -1472,7 +1354,7 @@ dependencies = [
"js-sys",
"num-traits",
"wasm-bindgen",
"windows-targets 0.52.5",
"windows-targets 0.52.6",
]
[[package]]
@ -2897,9 +2779,9 @@ dependencies = [
[[package]]
name = "hyper"
version = "1.3.1"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe575dd17d0862a9a33781c8c4696a55c320909004a67a00fb286ba8b1bc496d"
checksum = "c4fe55fb7a772d59a5ff1dfbff4fe0258d19b89fec4b233e75d35d5d2316badc"
dependencies = [
"bytes",
"futures-channel",
@ -2923,7 +2805,7 @@ checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155"
dependencies = [
"futures-util",
"http 1.1.0",
"hyper 1.3.1",
"hyper 1.4.0",
"hyper-util",
"rustls",
"rustls-pki-types",
@ -2967,7 +2849,7 @@ checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0"
dependencies = [
"bytes",
"http-body-util",
"hyper 1.3.1",
"hyper 1.4.0",
"hyper-util",
"native-tls",
"tokio",
@ -2977,16 +2859,16 @@ dependencies = [
[[package]]
name = "hyper-util"
version = "0.1.5"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b875924a60b96e5d7b9ae7b066540b1dd1cbd90d1828f54c92e02a283351c56"
checksum = "3ab92f4f49ee4fb4f997c784b7a2e0fa70050211e0b6a287f898c3c9785ca956"
dependencies = [
"bytes",
"futures-channel",
"futures-util",
"http 1.1.0",
"http-body 1.0.0",
"hyper 1.3.1",
"hyper 1.4.0",
"pin-project-lite",
"socket2 0.5.7",
"tokio",
@ -3349,7 +3231,7 @@ name = "kinode"
version = "0.8.2"
dependencies = [
"aes-gcm",
"alloy 0.1.0",
"alloy",
"alloy-primitives",
"alloy-sol-macro",
"alloy-sol-types",
@ -3457,7 +3339,7 @@ name = "kinode_process_lib"
version = "0.8.3"
source = "git+https://github.com/kinode-dao/process_lib?rev=c8442ef#c8442ef6e0f6aefc1d8caa30b32a991303da8dd9"
dependencies = [
"alloy 0.1.1",
"alloy",
"alloy-primitives",
"alloy-sol-macro",
"alloy-sol-types",
@ -3479,7 +3361,7 @@ name = "kinode_process_lib"
version = "0.8.3"
source = "git+https://github.com/kinode-dao/process_lib?rev=f8500a6#f8500a62a07c0558145ee1583155331f83dfd018"
dependencies = [
"alloy 0.1.1",
"alloy",
"alloy-primitives",
"alloy-sol-macro",
"alloy-sol-types",
@ -3595,7 +3477,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e310b3a6b5907f99202fcdb4960ff45b93735d7c7d96b760fcff8db2dc0e103d"
dependencies = [
"cfg-if",
"windows-targets 0.52.5",
"windows-targets 0.52.6",
]
[[package]]
@ -4043,9 +3925,9 @@ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
[[package]]
name = "open"
version = "5.1.4"
version = "5.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5ca541f22b1c46d4bb9801014f234758ab4297e7870b904b6a8415b980a7388"
checksum = "9d2c909a3fce3bd80efef4cd1c6c056bd9376a8fe06fcfdbebaf32cb485a7e37"
dependencies = [
"is-wsl",
"libc",
@ -4185,7 +4067,7 @@ dependencies = [
"libc",
"redox_syscall 0.5.2",
"smallvec",
"windows-targets 0.52.5",
"windows-targets 0.52.6",
]
[[package]]
@ -4261,9 +4143,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
[[package]]
name = "pest"
version = "2.7.10"
version = "2.7.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "560131c633294438da9f7c4b08189194b20946c8274c6b9e38881a7874dc8ee8"
checksum = "cd53dff83f26735fdc1ca837098ccf133605d794cdae66acfc2bfac3ec809d95"
dependencies = [
"memchr",
"thiserror",
@ -4841,7 +4723,7 @@ dependencies = [
"http 1.1.0",
"http-body 1.0.0",
"http-body-util",
"hyper 1.3.1",
"hyper 1.4.0",
"hyper-rustls",
"hyper-tls 0.6.0",
"hyper-util",
@ -5078,9 +4960,9 @@ checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d"
[[package]]
name = "rustls-webpki"
version = "0.102.4"
version = "0.102.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff448f7e92e913c4b7d4c6d8e4540a1724b319b4152b8aef6d4cf8339712b33e"
checksum = "f9a6fccd794a42c2c105b513a2f62bc3fd8f3ba57a4593677ceb0bd035164d78"
dependencies = [
"ring",
"rustls-pki-types",
@ -5230,9 +5112,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.119"
version = "1.0.120"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8eddb61f0697cc3989c5d64b452f5488e2b8a60fd7d5076a3045076ffef8cb0"
checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5"
dependencies = [
"itoa",
"ryu",
@ -5782,9 +5664,9 @@ dependencies = [
[[package]]
name = "tinyvec"
version = "1.6.1"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c55115c6fbe2d2bef26eb09ad74bde02d8255476fc0c7b515ef09fbb35742d82"
checksum = "ce6b6a2fb3a985e99cebfaefa9faa3024743da73304ca1c683a36429613d3d22"
dependencies = [
"tinyvec_macros",
]
@ -7064,7 +6946,7 @@ version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
dependencies = [
"windows-targets 0.52.5",
"windows-targets 0.52.6",
]
[[package]]
@ -7082,7 +6964,7 @@ version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
"windows-targets 0.52.5",
"windows-targets 0.52.6",
]
[[package]]
@ -7102,18 +6984,18 @@ dependencies = [
[[package]]
name = "windows-targets"
version = "0.52.5"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm 0.52.5",
"windows_aarch64_msvc 0.52.5",
"windows_i686_gnu 0.52.5",
"windows_aarch64_gnullvm 0.52.6",
"windows_aarch64_msvc 0.52.6",
"windows_i686_gnu 0.52.6",
"windows_i686_gnullvm",
"windows_i686_msvc 0.52.5",
"windows_x86_64_gnu 0.52.5",
"windows_x86_64_gnullvm 0.52.5",
"windows_x86_64_msvc 0.52.5",
"windows_i686_msvc 0.52.6",
"windows_x86_64_gnu 0.52.6",
"windows_x86_64_gnullvm 0.52.6",
"windows_x86_64_msvc 0.52.6",
]
[[package]]
@ -7124,9 +7006,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.5"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
@ -7136,9 +7018,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.5"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
@ -7148,15 +7030,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
[[package]]
name = "windows_i686_gnu"
version = "0.52.5"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.5"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
@ -7166,9 +7048,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[package]]
name = "windows_i686_msvc"
version = "0.52.5"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
@ -7178,9 +7060,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.5"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
@ -7190,9 +7072,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.5"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
@ -7202,9 +7084,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.5"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "winnow"
@ -7408,18 +7290,18 @@ dependencies = [
[[package]]
name = "zerocopy"
version = "0.7.34"
version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087"
checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.7.34"
version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b"
checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
dependencies = [
"proc-macro2",
"quote",

View File

@ -1,9 +1,9 @@
use alloy::network::{eip2718::Encodable2718, EthereumSigner, TransactionBuilder};
use alloy::network::{eip2718::Encodable2718, EthereumWallet, TransactionBuilder};
use alloy::providers::{Provider, ProviderBuilder, RootProvider};
use alloy::pubsub::PubSubFrontend;
use alloy::rpc::client::WsConnect;
use alloy::rpc::types::eth::{TransactionInput, TransactionRequest};
use alloy::signers::wallet::LocalWallet;
use alloy::signers::local::PrivateKeySigner;
use alloy_primitives::{Address, Bytes, FixedBytes, U256};
use alloy_sol_types::SolCall;
use lib::core::{Identity, NodeRouting};
@ -32,13 +32,13 @@ pub async fn mint_local(
pubkey: &str,
fakechain_port: u16,
) -> Result<(), anyhow::Error> {
let wallet = LocalWallet::from_str(
let privkey_signer = PrivateKeySigner::from_str(
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
)?;
let wallet_address = wallet.address();
let wallet_address = privkey_signer.address();
let signer: EthereumSigner = wallet.into();
let wallet: EthereumWallet = privkey_signer.into();
let multicall_address = Address::from_str(MULTICALL)?;
let dotos = Address::from_str(FAKE_DOTOS_TBA)?;
@ -81,7 +81,7 @@ pub async fn mint_local(
.with_max_fee_per_gas(300_000_000_000);
// Build the transaction using the `EthereumSigner` with the provided signer.
let tx_envelope = tx.build(&signer).await?;
let tx_envelope = tx.build(&wallet).await?;
// Encode the transaction using EIP-2718 encoding.
let tx_encoded = tx_envelope.encoded_2718();
@ -170,7 +170,7 @@ pub async fn mint_local(
.with_max_priority_fee_per_gas(200_000_000_000)
.with_max_fee_per_gas(300_000_000_000);
let tx_envelope = tx.build(&signer).await?;
let tx_envelope = tx.build(&wallet).await?;
let tx_encoded = tx_envelope.encoded_2718();
let _tx_hash = provider.send_raw_transaction(&tx_encoded).await?;

View File

@ -2,17 +2,12 @@ use aes_gcm::{
aead::{Aead, AeadCore, KeyInit, OsRng},
Aes256Gcm, Key,
};
use alloy_primitives::Keccak256;
use alloy_primitives::{keccak256, B256};
use anyhow::Result;
use digest::generic_array::GenericArray;
use hmac::Hmac;
use jwt::SignWithKey;
use lib::types::core::Keyfile;
use ring::pbkdf2;
use ring::rand::SystemRandom;
use ring::signature::{self, KeyPair};
use ring::{digest as ring_digest, rand::SecureRandom};
use sha2::Sha256;
use std::{
net::{IpAddr, Ipv4Addr, Ipv6Addr},
num::NonZeroU32,
@ -152,25 +147,40 @@ pub fn get_username_and_routers(keyfile: &[u8]) -> Result<(String, Vec<String>),
/// kinohash
pub fn namehash(name: &str) -> [u8; 32] {
let mut node = [0u8; 32];
if name.is_empty() {
return node;
}
let mut labels: Vec<&str> = name.split('.').collect();
labels.reverse();
let mut node = B256::default();
for label in labels.iter() {
let mut hasher = Keccak256::new();
hasher.update(label.as_bytes());
let labelhash = hasher.finalize();
hasher = Keccak256::new();
hasher.update(&node);
hasher.update(labelhash);
node = hasher.finalize().into();
if name.is_empty() {
return node.into();
}
node
let mut labels: Vec<&str> = name.split(".").collect();
labels.reverse();
for label in labels.iter() {
let label_hash = keccak256(label.as_bytes());
node = keccak256([node, label_hash].concat());
}
node.into()
}
// pub fn namehash(name: &str) -> [u8; 32] {
// let mut node = [0u8; 32];
// if name.is_empty() {
// return node;
// }
// let mut labels: Vec<&str> = name.split('.').collect();
// labels.reverse();
// for label in labels.iter() {
// let mut hasher = Keccak256::new();
// hasher.update(label.as_bytes());
// let labelhash = hasher.finalize();
// hasher = Keccak256::new();
// hasher.update(&node);
// hasher.update(labelhash);
// node = hasher.finalize().into();
// }
// node
// }
pub fn bytes_to_ip(bytes: &[u8]) -> Result<IpAddr, String> {
match bytes.len() {
16 => {

View File

@ -15,7 +15,7 @@ use std::sync::Arc;
use tokio::sync::mpsc;
mod eth;
#[cfg(feature = "simulation-mode")]
//#[cfg(feature = "simulation-mode")]
mod fakenet;
mod http;
mod kernel;