Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 69 additions & 4 deletions core/Cargo.lock

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

5 changes: 5 additions & 0 deletions core/domain-http/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v1.5.3

### Features
- Set gateway mac addres to request header

## v1.5.2

### Features
Expand Down
3 changes: 2 additions & 1 deletion core/domain-http/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "posemesh-domain-http"
version = "1.5.2"
version = "1.5.3"
edition = "2024"
repository = "https://github.com/aukilabs/posemesh/tree/main/core"
description = "HTTP client library for interacting with AukiLabs domain data services, supporting both native and WebAssembly targets."
Expand All @@ -19,6 +19,7 @@ bytes = "1.10.1"
thiserror.workspace = true

[target.'cfg(not(target_family="wasm"))'.dependencies]
default-net = "0.22.0"
tokio = { workspace = true, features = ["full"] }
uniffi = { workspace = true, optional = true }

Expand Down
37 changes: 37 additions & 0 deletions core/domain-http/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,25 @@ pub struct CreateDomainRequest {
domain_server_url: String,
}

/// Returns the gateway MAC address on native targets. On WASM/browser this always returns
/// empty string — browsers cannot access network interfaces, gateway, or MAC addresses.
fn get_mac_address() -> Result<String, DomainError> {
#[cfg(not(target_family = "wasm"))]
{
match default_net::get_default_gateway() {
Ok(gateway) => Ok(gateway.mac_addr.to_string()),
Err(_) => Err(DomainError::InvalidRequest("No gateway found")),
}
}

#[cfg(target_family = "wasm")]
{
// Browsers cannot access network interfaces, gateway IP, or MAC addresses.
// Return empty string so auth still works; server may use other identifiers.
Ok(String::new())
}
}

impl DiscoveryService {
pub fn new(api_url: &str, dds_url: &str, client_id: &str) -> Self {
let api_client = AuthClient::new(api_url, client_id);
Expand Down Expand Up @@ -134,6 +153,10 @@ impl DiscoveryService {
.header("Content-Type", "application/json")
.header("posemesh-client-id", self.api_client.client_id.clone())
.header("posemesh-sdk-version", crate::VERSION)
.header(
"posemesh-gateway-mac",
get_mac_address().unwrap_or_default(),
)
.send()
.await?;

Expand Down Expand Up @@ -260,12 +283,14 @@ impl DiscoveryService {
let dds_url = self.dds_url.clone();
let client_id = self.api_client.client_id.clone();
async move {
let mac_address = get_mac_address().unwrap_or_default();
let response = client
.post(format!("{}/api/v1/domains/{}/auth", dds_url, domain_id))
.bearer_auth(access_token)
.header("Content-Type", "application/json")
.header("posemesh-client-id", client_id)
.header("posemesh-sdk-version", crate::VERSION)
.header("posemesh-gateway-mac", mac_address)
.send()
.await?;

Expand Down Expand Up @@ -321,6 +346,10 @@ impl DiscoveryService {
.header("Content-Type", "application/json")
.header("posemesh-client-id", self.api_client.client_id.clone())
.header("posemesh-sdk-version", crate::VERSION)
.header(
"posemesh-gateway-mac",
get_mac_address().unwrap_or_default(),
)
.json(&CreateDomainRequest {
name: name.to_string(),
domain_server_id: domain_server_id.to_string(),
Expand Down Expand Up @@ -384,6 +413,10 @@ impl DiscoveryService {
.header("Content-Type", "application/json")
.header("posemesh-client-id", self.api_client.client_id.clone())
.header("posemesh-sdk-version", crate::VERSION)
.header(
"posemesh-gateway-mac",
get_mac_address().unwrap_or_default(),
)
.send()
.await?;
if response.status().is_success() {
Expand Down Expand Up @@ -415,6 +448,10 @@ impl DiscoveryService {
.header("Content-Type", "application/json")
.header("posemesh-client-id", self.api_client.client_id.clone())
.header("posemesh-sdk-version", crate::VERSION)
.header(
"posemesh-gateway-mac",
get_mac_address().unwrap_or_default(),
)
.send()
.await?;
if response.status().is_success() {
Expand Down
Loading