diff --git a/README.md b/README.md index 82e37ac..06f57fc 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Find the path to your `riscv32-esp-elf-gcc` binary within the `.embuild` dir: ### flash release -`espflash target/riscv32imc-esp-espidf/release/sphinx-key` +`espflash target/riscv32imc-esp-espidf/release/sphinx-key --monitor` ### monitor @@ -88,4 +88,6 @@ espflash save-image esp32-c3 target/riscv32imc-esp-espidf/debug/sphinx-key ./asd espflash save-image esp32-c3 target/riscv32imc-esp-espidf/release/sphinx-key ./test-flash -espflash board-info \ No newline at end of file +espflash board-info + +export CC=$PWD/.embuild/espressif/tools/riscv32-esp-elf/esp-2021r2-8.4.0/riscv32-esp-elf/bin/riscv32-esp-elf-gcc \ No newline at end of file diff --git a/signer/src/lib.rs b/signer/src/lib.rs index 40adba9..e02af9b 100644 --- a/signer/src/lib.rs +++ b/signer/src/lib.rs @@ -3,11 +3,10 @@ use lightning_signer::Arc; use sphinx_key_parser::MsgDriver; use vls_protocol::msgs::{self, read_serial_request_header, write_serial_response_header, Message}; use vls_protocol::serde_bolt::WireString; -use vls_protocol_signer::lightning_signer; -use vls_protocol_signer::vls_protocol; - -pub use vls_protocol::model::PubKey; -pub use vls_protocol_signer::handler::{Handler, RootHandler}; +pub use vls_protocol_signer::lightning_signer; +pub use vls_protocol_signer::vls_protocol; +use vls_protocol::model::PubKey; +use vls_protocol_signer::handler::{Handler, RootHandler}; pub struct InitResponse { pub root_handler: RootHandler, diff --git a/sphinx-key/.cargo/config.toml b/sphinx-key/.cargo/config.toml index ff90964..3103fef 100644 --- a/sphinx-key/.cargo/config.toml +++ b/sphinx-key/.cargo/config.toml @@ -24,11 +24,11 @@ rustflags = ["-C", "default-linker-libraries"] [unstable] build-std = ["std", "panic_abort"] -#build-std-features = ["panic_immediate_abort"] # Required for older ESP-IDF versions without a realpath implementation +build-std-features = ["panic_immediate_abort"] # Required for older ESP-IDF versions without a realpath implementation [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 = "branch:release/v4.4" } +#ESP_IDF_VERSION = { value = "branch:release/v4.4" } # 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/sphinx-key/.gitignore b/sphinx-key/.gitignore new file mode 100644 index 0000000..73a638b --- /dev/null +++ b/sphinx-key/.gitignore @@ -0,0 +1,4 @@ +/.vscode +/.embuild +/target +/Cargo.lock diff --git a/sphinx-key/Cargo.toml b/sphinx-key/Cargo.toml index 181cdf6..c2f4b95 100644 --- a/sphinx-key/Cargo.toml +++ b/sphinx-key/Cargo.toml @@ -19,8 +19,8 @@ pio = ["esp-idf-sys/pio"] pingpong = [] [dependencies] -sphinx-key-signer = { path = "../signer", optional = true } esp-idf-sys = { version = "0.31.5", features = ["binstart"] } +sphinx-key-signer = { path = "../signer", optional = true } embedded-svc = { version = "0.21.2" } esp-idf-svc = "0.41" esp-idf-hal = "0.37" @@ -39,3 +39,4 @@ anyhow = "1" [[bin]] name = "clear" path = "src/clear.rs" + diff --git a/sphinx-key/config.html b/sphinx-key/config.html deleted file mode 100644 index 07b0daa..0000000 --- a/sphinx-key/config.html +++ /dev/null @@ -1,191 +0,0 @@ - - - - - - - - - Sphinx Key - - - - - - - - - -

- Enter your WiFi credentials and MQTT Broker to connect you Sphinx Key -

- - - - - - - - - -

- - - - \ No newline at end of file diff --git a/sphinx-key/docs/README.md b/sphinx-key/docs/README.md new file mode 100644 index 0000000..c97a7de --- /dev/null +++ b/sphinx-key/docs/README.md @@ -0,0 +1,115 @@ +# sphinx_key + +## Dev Containers +This repository offers Dev Containers supports for: +- [Gitpod](https://gitpod.io/) + - ["Open in Gitpod" button](https://www.gitpod.io/docs/getting-started#open-in-gitpod-button) +- [VS Code Dev Containers](https://code.visualstudio.com/docs/remote/containers#_quick-start-open-an-existing-folder-in-a-container) +- [GitHub Codespaces](https://docs.github.com/en/codespaces/developing-in-codespaces/creating-a-codespace) +> **Note** +> +> In order to use Gitpod the project needs to be published in a GitLab, GitHub, +> or Bitbucket repository. +> +> In [order to use GitHub Codespaces](https://github.com/features/codespaces#faq) +> the project needs to be published in a GitHub repository and the user needs +> to be part of the Codespaces beta or have the project under an organization. + +If using VS Code or GitHub Codespaces, you can pull the image instead of building it +from the Dockerfile by selecting the `image` property instead of `build` in +`.devcontainer/devcontainer.json`. + +When using Dev Containers, some tooling to facilitate building, flashing and +simulating in Wokwi is also added. +### Build +- Terminal approach: + + ``` + scripts/build.sh [debug | release] + ``` + > If no argument is passed, `release` will be used as default + + +- UI approach: + + The default build task is already set to build the project, and it can be used + in VS Code and Gitpod: + - From the [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette) (`Ctrl-Shift-P` or `Cmd-Shift-P`) run the `Tasks: Run Build Task` command. + - `Terminal`-> `Run Build Task` in the menu. + - With `Ctrl-Shift-B` or `Cmd-Shift-B`. + - From the [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette) (`Ctrl-Shift-P` or `Cmd-Shift-P`) run the `Tasks: Run Task` command and + select `Build`. + - From UI: Press `Build` on the left side of the Status Bar. + +### Flash + +> **Note** +> +> When using GitHub Codespaces, we need to make the ports +> public, [see instructions](https://docs.github.com/en/codespaces/developing-in-codespaces/forwarding-ports-in-your-codespace#sharing-a-port). + +- Terminal approach: + - Using `flash.sh` script: + + ``` + scripts/flash.sh [debug | release] + ``` + > If no argument is passed, `release` will be used as default + +- UI approach: + - From the [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette) (`Ctrl-Shift-P` or `Cmd-Shift-P`) run the `Tasks: Run Task` command and + select `Build & Flash`. + - From UI: Press `Build & Flash` on the left side of the Status Bar. +- Any alternative flashing method from host machine. + + +### Wokwi Simulation +When using a custom Wokwi project, please change the `WOKWI_PROJECT_ID` in +`run-wokwi.sh`. If no project id is specified, a DevKit for esp32c3 will be +used. +> **Warning** +> +> ESP32-S3 is not available in Wokwi + +- Terminal approach: + + ``` + scripts/run-wokwi.sh [debug | release] + ``` + > If no argument is passed, `release` will be used as default + +- UI approach: + + The default test task is already set to build the project, and it can be used + in VS Code and Gitpod: + - From the [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette) (`Ctrl-Shift-P` or `Cmd-Shift-P`) run the `Tasks: Run Test Task` command + - With `Ctrl-Shift-,` or `Cmd-Shift-,` + > **Note** + > + > This Shortcut is not available in Gitpod by default. + - From the [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette) (`Ctrl-Shift-P` or `Cmd-Shift-P`) run the `Tasks: Run Task` command and + select `Build & Run Wokwi`. + - From UI: Press `Build & Run Wokwi` on the left side of the Status Bar. + +> **Warning** +> +> The simulation will pause if the browser tab is in the background.This may +> affect the execution, specially when debuging. + +#### Debuging with Wokwi + +Wokwi offers debugging with GDB. + +- Terminal approach: + ``` + $HOME/.espressif/tools/riscv32-esp-elf/esp-2021r2-patch3-8.4.0/riscv32-esp-elf/bin/riscv32-esp-elf-gdb target/riscv32imc-esp-espidf/debug/sphinx_key -ex "target remote localhost:9333" + ``` + + > [Wokwi Blog: List of common GDB commands for debugging.](https://blog.wokwi.com/gdb-avr-arduino-cheatsheet/?utm_source=urish&utm_medium=blog) +- UI approach: + 1. Run the Wokwi Simulation in `debug` profile + 2. Go to `Run and Debug` section of the IDE (`Ctrl-Shift-D or Cmd-Shift-D`) + 3. Start Debugging by pressing the Play Button or pressing `F5` + 4. Choose the proper user: + - `esp` when using VS Code or GitHub Codespaces + - `gitpod` when using Gitpod diff --git a/sphinx-key/hmq.html b/sphinx-key/hmq.html deleted file mode 100644 index fa5cc8b..0000000 --- a/sphinx-key/hmq.html +++ /dev/null @@ -1,212 +0,0 @@ - - - - - - - HMQ CLIENT - - - - - -
-
-
-

Connection - {{ connection.state }} - ({{ connection.error }}) - -

-
-

- -

-

- -

-

- -

-

- -

-
-
-
- -
-
-

Subscriptions

-
-

- -

-

- -

-

- -

-
-
    -
  • -
    -
    - QoS - {{ info.qos }} -
    -
    -
    -
    - Topic - {{ filter }} -
    -
    - -
  • -
-
-
- -
-
-

Messages

-
-

- -

-

- -

-

- -

-
-
    -
  • - {{ message.topic }}: - {{ message.payload }} -
  • -
-
-
-
- - - - - - - \ No newline at end of file diff --git a/sphinx-key/run.sh b/sphinx-key/run.sh deleted file mode 100755 index a2c7530..0000000 --- a/sphinx-key/run.sh +++ /dev/null @@ -1,3 +0,0 @@ -cargo build --features pingpong -espflash target/riscv32imc-esp-espidf/debug/sphinx-key -espmonitor /dev/tty.usbserial-1420 \ No newline at end of file diff --git a/sphinx-key/scripts/build.sh b/sphinx-key/scripts/build.sh new file mode 100755 index 0000000..a22e3c6 --- /dev/null +++ b/sphinx-key/scripts/build.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Gitpod and VsCode Codespaces tasks do not source the user environment +if [ "${USER}" == "gitpod" ]; then + which idf.py >/dev/null || { + source ~/export-esp.sh > /dev/null 2>&1 + } +elif [ "${CODESPACE_NAME}" != "" ]; then + which idf.py >/dev/null || { + source ~/export-esp.sh > /dev/null 2>&1 + } +fi + +case "$1" in + ""|"release") + cargo build --release + ;; + "debug") + cargo build + ;; + *) + echo "Wrong argument. Only \"debug\"/\"release\" arguments are supported" + exit 1;; +esac \ No newline at end of file diff --git a/sphinx-key/scripts/flash.sh b/sphinx-key/scripts/flash.sh new file mode 100755 index 0000000..9f74348 --- /dev/null +++ b/sphinx-key/scripts/flash.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +set -e + +BUILD_MODE="" +case "$1" in + ""|"release") + bash scripts/build.sh + BUILD_MODE="release" + ;; + "debug") + bash scripts/build.sh debug + BUILD_MODE="debug" + ;; + *) + echo "Wrong argument. Only \"debug\"/\"release\" arguments are supported" + exit 1;; +esac + +export ESP_ARCH=riscv32imc-esp-espidf + +web-flash --chip esp32c3 target/${ESP_ARCH}/${BUILD_MODE}/sphinx-key diff --git a/sphinx-key/scripts/run-wokwi.sh b/sphinx-key/scripts/run-wokwi.sh new file mode 100755 index 0000000..03f62b1 --- /dev/null +++ b/sphinx-key/scripts/run-wokwi.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +set -e + +BUILD_MODE="" +case "$1" in + ""|"release") + bash scripts/build.sh + BUILD_MODE="release" + ;; + "debug") + bash scripts/build.sh debug + BUILD_MODE="debug" + ;; + *) + echo "Wrong argument. Only \"debug\"/\"release\" arguments are supported" + exit 1;; +esac + +if [ "${USER}" == "gitpod" ];then + gp_url=$(gp url 9012) + echo "gp_url=${gp_url}" + export WOKWI_HOST=${gp_url:8} +elif [ "${CODESPACE_NAME}" != "" ];then + export WOKWI_HOST=${CODESPACE_NAME}-9012.githubpreview.dev +fi + +export ESP_ARCH=riscv32imc-esp-espidf + +# TODO: Update with your Wokwi Project +export WOKWI_PROJECT_ID="" +if [ "${WOKWI_PROJECT_ID}" == "" ]; then + wokwi-server --chip esp32c3 target/${ESP_ARCH}/${BUILD_MODE}/sphinx-key +else + wokwi-server --chip esp32c3 --id ${WOKWI_PROJECT_ID} target/${ESP_ARCH}/${BUILD_MODE}/sphinx-key +fi \ No newline at end of file diff --git a/sphinx-key/sdkconfig.defaults b/sphinx-key/sdkconfig.defaults index 0ac9af4..3ca3b5d 100644 --- a/sphinx-key/sdkconfig.defaults +++ b/sphinx-key/sdkconfig.defaults @@ -6,5 +6,5 @@ CONFIG_ESP_MAIN_TASK_STACK_SIZE=7000 #CONFIG_FREERTOS_HZ=1000 # Workaround for https://github.com/espressif/esp-idf/issues/7631 -CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=n -CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL=n +#CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=n +#CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL=n diff --git a/sphinx-key/src/core/events.rs b/sphinx-key/src/core/events.rs index 607e997..30f5803 100644 --- a/sphinx-key/src/core/events.rs +++ b/sphinx-key/src/core/events.rs @@ -1,5 +1,6 @@ use crate::conn::mqtt::{RETURN_TOPIC, TOPIC, QOS}; -use sphinx_key_signer::{self, InitResponse, PubKey}; +use sphinx_key_signer::{self, InitResponse}; +use sphinx_key_signer::vls_protocol::model::PubKey; use std::sync::mpsc; use esp_idf_sys; diff --git a/sphinx-key/src/test.rs b/sphinx-key/src/test.rs new file mode 100644 index 0000000..2d3bfaf --- /dev/null +++ b/sphinx-key/src/test.rs @@ -0,0 +1,9 @@ +use esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported + +fn main() { + // Temporary. Will disappear once ESP-IDF 4.4 is released, but for now it is necessary to call this function once, + // or else some patches to the runtime implemented by esp-idf-sys might not link properly. + esp_idf_sys::link_patches(); + + println!("Hello, world!"); +}