mirror of
https://github.com/stakwork/sphinx-key.git
synced 2026-02-06 16:24:37 +01:00
Merge pull request #69 from stakwork/feat/tester-config
Feat/tester config
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -8,4 +8,5 @@ Cargo.lock
|
||||
notes.md
|
||||
test-flash
|
||||
.env
|
||||
teststore
|
||||
teststore
|
||||
teststore2
|
||||
14
README.md
14
README.md
@@ -2,20 +2,16 @@
|
||||
|
||||
A Lightning Hardware Wallet based on [Validating Lightning Signer](https://gitlab.com/lightning-signer/validating-lightning-signer)
|
||||
|
||||
### set CFLAGS
|
||||
### build factory
|
||||
|
||||
Before building the sphinx-key esp software, run this:
|
||||
`cd factory`
|
||||
|
||||
`export CFLAGS=-fno-pic`
|
||||
|
||||
### find your esp GCC
|
||||
|
||||
Find the path to your `riscv32-esp-elf-gcc` binary within the `.embuild` dir:
|
||||
|
||||
`export CC=$PWD/.embuild/espressif/tools/riscv32-esp-elf/esp-2021r2-patch3-8.4.0/riscv32-esp-elf/bin/riscv32-esp-elf-gcc`
|
||||
`cargo build --release`
|
||||
|
||||
### build
|
||||
|
||||
`cd ../sphinx-key`
|
||||
|
||||
The wifi SSID and password needs to be in env to build the firmware. SSID must be at least 6 characters, and PASS must be at least 8 characters.
|
||||
|
||||
`SSID=sphinx-1 PASS=sphinx-1234 cargo build`
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
[build]
|
||||
# Uncomment the relevant target for your chip here (ESP32, ESP32-S2, ESP32-S3 or ESP32-C3)
|
||||
#target = "xtensa-esp32-espidf"
|
||||
#target = "xtensa-esp32s2-espidf"
|
||||
#target = "xtensa-esp32s3-espidf"
|
||||
target = "riscv32imc-esp-espidf"
|
||||
|
||||
[target.xtensa-esp32-espidf]
|
||||
@@ -29,6 +25,6 @@ build-std-features = ["panic_immediate_abort"] # Required for older ESP-IDF vers
|
||||
[env]
|
||||
# Note: these variables are not used when using pio builder
|
||||
# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF stable (v4.4)
|
||||
ESP_IDF_VERSION = { value = "release/v4.4" }
|
||||
ESP_IDF_VERSION = { value = "tag:v4.4.2" }
|
||||
# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF master (mainline)
|
||||
#ESP_IDF_VERSION = { value = "master" }
|
||||
|
||||
@@ -9,7 +9,7 @@ serde = { version = "1.0", default-features = false }
|
||||
rmp-serde = "1.1.0"
|
||||
serde_bolt = { version = "0.2", default-features = false }
|
||||
sphinx-auther = "0.1.12"
|
||||
sphinx-glyph = "0.1.0"
|
||||
sphinx-glyph = "0.1.1"
|
||||
anyhow = "1"
|
||||
|
||||
[features]
|
||||
|
||||
@@ -29,8 +29,8 @@ build-std-features = ["panic_immediate_abort"] # Required for older ESP-IDF vers
|
||||
[env]
|
||||
# Note: these variables are not used when using pio builder
|
||||
# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF stable (v4.4)
|
||||
ESP_IDF_VERSION = { value = "release/v4.4" }
|
||||
ESP_IDF_VERSION = { value = "tag:v4.4.2" }
|
||||
# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF master (mainline)
|
||||
#ESP_IDF_VERSION = { value = "master" }
|
||||
CC = { value = "../factory/.embuild/espressif/tools/riscv32-esp-elf/esp-2021r2-patch4-8.4.0/riscv32-esp-elf/bin/riscv32-esp-elf-gcc", relative = true }
|
||||
CC = { value = "../factory/.embuild/espressif/tools/riscv32-esp-elf/esp-2021r2-patch3-8.4.0/riscv32-esp-elf/bin/riscv32-esp-elf-gcc", relative = true }
|
||||
CFLAGS = { value = "-fno-pic" }
|
||||
|
||||
9
sphinx-key/Cargo.lock
generated
9
sphinx-key/Cargo.lock
generated
@@ -1885,9 +1885,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.85"
|
||||
version = "1.0.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44"
|
||||
checksum = "41feea4228a6f1cd09ec7a3593a682276702cd67b5273544757dae23c096f074"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
@@ -1989,13 +1989,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "sphinx-glyph"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf0527b300544e9fe193611f1be1f76e3b25f5ceab4217347429c2912b60093e"
|
||||
checksum = "dbab7d4a5119f6040006784cee5117aabf8654588620e58a01b66732bb307671"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"rmp-serde",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sphinx-auther",
|
||||
]
|
||||
|
||||
|
||||
@@ -9,6 +9,17 @@ cargo run -- --test
|
||||
|
||||
cargo run --bin ctrl
|
||||
|
||||
#### sample cmd.json file
|
||||
```json
|
||||
{
|
||||
"type": "Ota",
|
||||
"content": {
|
||||
"url": "http://192.168.1.10/sphinx-update-",
|
||||
"version": 0
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### sample .env file
|
||||
|
||||
```
|
||||
@@ -17,7 +28,5 @@ PASS="bar"
|
||||
BROKER="44.198.193.18:1883"
|
||||
BROKER_URL="http://44.198.193.18:30000/api"
|
||||
SEED=c7629e0f2edf1be66f01c0824022c5d30756ffa0f17213d2be463a458d200803
|
||||
NONCE="3"
|
||||
VERSION="3"
|
||||
OTA_URL="http://192.168.1.10/sphinx-update-"
|
||||
NONCE="0"
|
||||
```
|
||||
|
||||
7
tester/cmd.json
Normal file
7
tester/cmd.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "Ota",
|
||||
"content": {
|
||||
"url": "http://192.168.1.10/sphinx-update-",
|
||||
"version": 0
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
use dotenv::dotenv;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sphinx_key_parser::control::{ControlMessage, Controller, OtaParams};
|
||||
use sphinx_key_parser::control::{ControlMessage, Controller};
|
||||
use sphinx_key_signer::lightning_signer::bitcoin::Network;
|
||||
use std::env;
|
||||
use std::time::Duration;
|
||||
@@ -25,16 +25,16 @@ async fn main() -> anyhow::Result<()> {
|
||||
let seed = hex::decode(seed_string).expect("yo");
|
||||
let mut ctrl = controller_from_seed(&Network::Regtest, &seed, nonce);
|
||||
|
||||
let version_string: String = env::var("VERSION").unwrap_or("0".to_string());
|
||||
let version: u64 = version_string.parse::<u64>().expect("failed to parse version");
|
||||
let ota_url: String = env::var("OTA_URL").unwrap_or("http://192.168.1.10/sphinx-update-".to_string());
|
||||
let control_message = ControlMessage::Ota(OtaParams {
|
||||
version: version,
|
||||
url: ota_url
|
||||
});
|
||||
let mut command = ControlMessage::Nonce;
|
||||
if let Ok(cmd_content) = std::fs::read_to_string("./tester/cmd.json") {
|
||||
if let Ok(cmd) = serde_json::from_str::<ControlMessage>(&cmd_content) {
|
||||
command = cmd;
|
||||
}
|
||||
}
|
||||
|
||||
//let msg = ctrl.build_msg(control_message)?;
|
||||
let msg = ctrl.build_msg(ControlMessage::Nonce)?;
|
||||
println!("COMMAND! {:?}", command);
|
||||
|
||||
let msg = ctrl.build_msg(command)?;
|
||||
let msg_hex = hex::encode(&msg);
|
||||
|
||||
let client = reqwest::Client::builder()
|
||||
|
||||
@@ -49,8 +49,12 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
} else {
|
||||
"sphinx-1"
|
||||
};
|
||||
let broker: String = env::var("BROKER").unwrap_or("localhost:1883".to_string());
|
||||
let broker_: Vec<&str> = broker.split(":").collect();
|
||||
let broker_port = broker_[1].parse::<u16>().expect("NaN");
|
||||
let (client, eventloop) = loop {
|
||||
let mut mqttoptions = MqttOptions::new(client_id, "localhost", 1883);
|
||||
println!("connect to {}:{}", broker_[0], broker_port);
|
||||
let mut mqttoptions = MqttOptions::new(client_id, broker_[0], broker_port);
|
||||
mqttoptions.set_credentials(pubkey.clone(), token.clone());
|
||||
mqttoptions.set_keep_alive(Duration::from_secs(5));
|
||||
let (client, mut eventloop) = AsyncClient::new(mqttoptions, 10);
|
||||
@@ -87,13 +91,16 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
}
|
||||
|
||||
async fn run_main(mut eventloop: EventLoop, client: &AsyncClient, mut ctrlr: Controller, is_log: bool, seed: &[u8], network: Network) {
|
||||
|
||||
let store_path = env::var("STORE_PATH").unwrap_or(ROOT_STORE.to_string());
|
||||
|
||||
let seed32: [u8; 32] = seed.try_into().expect("wrong seed");
|
||||
let init_msg =
|
||||
sphinx_key_signer::make_init_msg(network, seed32).expect("failed to make init msg");
|
||||
let InitResponse {
|
||||
root_handler,
|
||||
init_reply: _,
|
||||
} = sphinx_key_signer::init(init_msg, network, &Default::default(), ROOT_STORE)
|
||||
} = sphinx_key_signer::init(init_msg, network, &Default::default(), &store_path)
|
||||
.expect("failed to init signer");
|
||||
// the actual handler loop
|
||||
loop {
|
||||
|
||||
Reference in New Issue
Block a user