diff --git a/.gitignore b/.gitignore index d600d54..e57113e 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ Cargo.lock notes.md test-flash .env -teststore \ No newline at end of file +teststore +teststore2 \ No newline at end of file diff --git a/README.md b/README.md index 508ca31..1ef9175 100644 --- a/README.md +++ b/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` diff --git a/factory/.cargo/config.toml b/factory/.cargo/config.toml index 33f5399..548a46d 100644 --- a/factory/.cargo/config.toml +++ b/factory/.cargo/config.toml @@ -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" } diff --git a/parser/Cargo.toml b/parser/Cargo.toml index 1b9706d..002c019 100644 --- a/parser/Cargo.toml +++ b/parser/Cargo.toml @@ -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] diff --git a/sphinx-key/.cargo/config.toml b/sphinx-key/.cargo/config.toml index 564686d..6d4c078 100644 --- a/sphinx-key/.cargo/config.toml +++ b/sphinx-key/.cargo/config.toml @@ -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" } diff --git a/sphinx-key/Cargo.lock b/sphinx-key/Cargo.lock index 0ed5ee9..47ff1be 100644 --- a/sphinx-key/Cargo.lock +++ b/sphinx-key/Cargo.lock @@ -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", ] diff --git a/tester/README.md b/tester/README.md index 5255c4f..172fc25 100644 --- a/tester/README.md +++ b/tester/README.md @@ -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" ``` diff --git a/tester/cmd.json b/tester/cmd.json new file mode 100644 index 0000000..8a99e7d --- /dev/null +++ b/tester/cmd.json @@ -0,0 +1,7 @@ +{ + "type": "Ota", + "content": { + "url": "http://192.168.1.10/sphinx-update-", + "version": 0 + } +} diff --git a/tester/src/ctrl.rs b/tester/src/ctrl.rs index e7f97f3..f1cc9f1 100644 --- a/tester/src/ctrl.rs +++ b/tester/src/ctrl.rs @@ -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::().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::(&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() diff --git a/tester/src/main.rs b/tester/src/main.rs index e9edc4a..4991f09 100644 --- a/tester/src/main.rs +++ b/tester/src/main.rs @@ -49,8 +49,12 @@ async fn main() -> Result<(), Box> { } 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::().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> { } 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 {