Skip to content
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
7,106 changes: 5,997 additions & 1,109 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,32 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
solana-sdk = "1.18"
angry-purple-tiger = { version = "1", features = ["helium_crypto"]}
anyhow = "1.0.71"
async-trait = "0.1"
dialoguer = "0.10.2"
clap = { version = "4.2.7", features = ["derive", "env"] }
futures = "0.3.28"
helium-crypto = "0.6.9"
helium-crypto = "0.8.4"
helium-proto = { git = "https://github.com/helium/proto", branch="master", features=["services"]}
helium-lib = { git = "https://github.com/helium/helium-wallet-rs", branch = "master" }
helium-anchor-gen = { git = "https://github.com/helium/helium-anchor-gen.git" }
h3o = "0"
ipnet = "2.7.2"
prost = "0.11.9"
rand = "0.8.5"
serde = { version = "1.0.162", features = ["derive"] }
serde_json = "1.0.96"
serde_test = "1.0.162"
serde_with = "1.14"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
serde_with = "1.14"

leftover dep

thiserror = "1.0"
tokio = { version = "1.28.0", features = ["macros", "rt-multi-thread"] }
tokio-stream = "0.1.14"
tonic = { version = "0.9.2", features = ["tls", "tls-roots"] }
tonic = { version = "0.10", features = ["tls", "tls-roots"] }
prost = "0.12"
tracing = "0.1.37"
tracing-subscriber = "0.3.17"

[dev-dependencies]
pretty_assertions = "1.3.0"
temp-dir = "0.1.11"
temp-dir = "0.1.11"
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,53 @@ Cli tool to interact with [Helium Config Service](https://github.com/helium/orac

## Installation


Download the latest binary for your platform here from
[Releases](https://github.com/helium/helium-config-service-cli/releases/latest). Unpack
the zip file and place the `helium-config-service-cli` binary in your `$PATH`
somewhere.

### Org sol commands

Commands that interact direclty with the block chain dont require `HELIUM_CONFIG_HOST` or `HELIUM_CONFIG_PUBKEY` to be executed. However all read/writes of the db commands do so its convient to just have them included.

```
❯ helium-config-service-cli org create-helium --owner <owner pubkey> --net-id <net id type> --solana-url <solana rpc url> --solana-keypair <solanawallet.json> --commit
== Helium Organization Created: 2242 ==
== Call `org get --oui 2242 to see its details` ==
```

```
❯ helium-config-service-cli org approve --oui 2242 --solana-url <solana rpc url> --solana-keypair <solanawallet.json> --commit
== Organization Approved: 2242 ==
```

```
❯ HELIUM_CONFIG_HOST=<config host> HELIUM_CONFIG_PUBKEY=<config pubkey> HELIUM_KEYPAIR_BIN=<keypair bin> helium-config-service-cli org enable --oui 2242 --commit
OUI 2242 enabled
```

```
❯ helium-config-service-cli org update devaddr-constraint-add --oui 2245 --num-blocks 3 --solana-url <solana rpc url> --solana-keypair <solanawallet.json> --commit
== Organization Updated ==
== Call `org get --oui 2242 to see its details ==

❯ HELIUM_CONFIG_HOST=<config host> HELIUM_CONFIG_PUBKEY=<config pubkey> HELIUM_KEYPAIR_BIN=<keypair bin> helium-config-service-cli org get --oui 2242
{
"org": {
"oui": 2242,
"address": <solana address>,
"owner": <owner pubkey>,
"escrow_key": "OUI_2242",
"delegate_keys": [],
"approved": true,
"locked": false
},
"net_id": "00003C",
"devaddr_constraints": [
{
"start_addr": "780001B9",
"end_addr": "780001D1"
}
]
}
```
93 changes: 93 additions & 0 deletions src/clients/admin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
use crate::{
clients::utils::{MsgSign, MsgVerify},
impl_sign, impl_verify,
region::Region,
region_params::RegionParams,
KeyType, Result,
};
use helium_crypto::{Keypair, PublicKey};
use helium_proto::{
services::iot_config::{
admin_client, AdminAddKeyReqV1, AdminKeyResV1, AdminLoadRegionReqV1, AdminLoadRegionResV1,
AdminRemoveKeyReqV1,
},
Message,
};
use std::str::FromStr;

pub struct AdminClient {
client: admin_client::AdminClient<helium_proto::services::Channel>,
server_pubkey: PublicKey,
}

impl AdminClient {
pub async fn new(host: &str, server_pubkey: &str) -> Result<Self> {
Ok(Self {
client: admin_client::AdminClient::connect(host.to_owned()).await?,
server_pubkey: helium_crypto::PublicKey::from_str(server_pubkey)?,
})
}

pub async fn add_key(
&mut self,
pubkey: &PublicKey,
key_type: KeyType,
keypair: &Keypair,
) -> Result {
let mut request = AdminAddKeyReqV1 {
pubkey: pubkey.into(),
key_type: key_type.into(),
signer: keypair.public_key().into(),
signature: vec![],
};
request.signature = request.sign(keypair)?;
self.client
.add_key(request)
.await?
.into_inner()
.verify(&self.server_pubkey)
}

pub async fn remove_key(&mut self, pubkey: &PublicKey, keypair: &Keypair) -> Result {
let mut request = AdminRemoveKeyReqV1 {
pubkey: pubkey.into(),
signer: keypair.public_key().into(),
signature: vec![],
};
request.signature = request.sign(keypair)?;
self.client
.remove_key(request)
.await?
.into_inner()
.verify(&self.server_pubkey)
}

pub async fn load_region(
&mut self,
region: Region,
params: RegionParams,
indexes: Vec<u8>,
keypair: &Keypair,
) -> Result {
let mut request = AdminLoadRegionReqV1 {
region: region.into(),
params: Some(params.into()),
hex_indexes: indexes,
signer: keypair.public_key().into(),
signature: vec![],
};
request.signature = request.sign(keypair)?;
self.client
.load_region(request)
.await?
.into_inner()
.verify(&self.server_pubkey)
}
}

impl_sign!(AdminAddKeyReqV1, signature);
impl_sign!(AdminRemoveKeyReqV1, signature);
impl_sign!(AdminLoadRegionReqV1, signature);

impl_verify!(AdminKeyResV1, signature);
impl_verify!(AdminLoadRegionResV1, signature);
64 changes: 64 additions & 0 deletions src/clients/gateway.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use crate::{
clients::utils::{MsgSign, MsgVerify},
cmds::gateway::GatewayInfo,
impl_sign, impl_verify, Result,
};
use anyhow::anyhow;
use helium_crypto::{Keypair, PublicKey};
use helium_proto::{
services::iot_config::{
gateway_client, GatewayInfoReqV1, GatewayInfoResV1, GatewayLocationReqV1,
GatewayLocationResV1,
},
Message,
};
use std::str::FromStr;

pub struct GatewayClient {
client: gateway_client::GatewayClient<helium_proto::services::Channel>,
server_pubkey: PublicKey,
}

impl GatewayClient {
pub async fn new(host: &str, server_pubkey: &str) -> Result<Self> {
Ok(Self {
client: gateway_client::GatewayClient::connect(host.to_owned()).await?,
server_pubkey: helium_crypto::PublicKey::from_str(server_pubkey)?,
})
}

pub async fn location(
&mut self,
hotspot: &PublicKey,
keypair: &Keypair,
) -> Result<GatewayLocationResV1> {
let mut request = GatewayLocationReqV1 {
gateway: hotspot.into(),
signer: keypair.public_key().into(),
signature: vec![],
};
request.signature = request.sign(keypair)?;
let response = self.client.location(request).await?.into_inner();
response.verify(&self.server_pubkey)?;
Ok(response)
}

pub async fn info(&mut self, hotspot: &PublicKey, keypair: &Keypair) -> Result<GatewayInfo> {
let mut request = GatewayInfoReqV1 {
address: hotspot.into(),
signer: keypair.public_key().into(),
signature: vec![],
};
request.signature = request.sign(keypair)?;
let response = self.client.info(request).await?.into_inner();
response.verify(&self.server_pubkey)?;
let info = response.info.ok_or_else(|| anyhow!("No hotspot found"))?;
info.try_into()
}
}

impl_sign!(GatewayLocationReqV1, signature);
impl_sign!(GatewayInfoReqV1, signature);

impl_verify!(GatewayLocationResV1, signature);
impl_verify!(GatewayInfoResV1, signature);
11 changes: 11 additions & 0 deletions src/clients/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
mod admin;
mod gateway;
mod org;
mod route;
mod utils;

pub use admin::AdminClient;
pub use gateway::GatewayClient;
pub use helium_lib::client::SolanaClient;
pub use org::*;
pub use route::*;
Loading