|
cryptnox-sdk-esp32 1.0.0
ESP32 SDK for Cryptnox Hardware Wallet
|
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <inttypes.h>#include "freertos/FreeRTOS.h"#include "freertos/task.h"#include "driver/spi_master.h"#include "driver/gpio.h"#include "esp_log.h"#include "nvs_flash.h"#include "CryptnoxWallet.h"#include "CW_Utils.h"#include "Pn532NfcTransport.h"#include "ESP32Logger.h"#include "esp32_crypto_provider.h"#include "ESP32Platform.h"#include "pn532.h"#include "keccak256.h"#include "eth_rlp.h"#include "eth_rpc.h"#include "config.h"Go to the source code of this file.
Macros | |
| #define | SPI_ENABLED 1 |
| #define | I2C_ENABLED 0 |
| #define | SPI_MOSI 11 |
| #define | SPI_MISO 13 |
| #define | SPI_SCLK 12 |
| #define | SPI_MAX_TRANSFER_SZ 4096 |
| #define | SPI_PIN_UNUSED (-1) |
| #define | NFC_CS 10 |
| #define | TX_BUF_SIZE 300U |
Functions | |
| static void | parse_address (const char *hex, uint8_t out[20]) |
| Parse a hex string into a 20-byte Ethereum address. | |
| static void | build_usdc_calldata (uint8_t out[68], const char *to_hex, uint64_t amount) |
Build the 68-byte ABI-encoded calldata for a USDC transfer call. | |
| static void | signing_loop (CryptnoxWallet &wallet) |
| Main application loop: sign and broadcast a USDC transfer each card tap. | |
| void | app_main (void) |
| ESP-IDF application entry point. | |
Variables | |
| static const char *const | TAG = "usdc_signing" |
| static const uint8_t | TRANSFER_SELECTOR [4] = { 0xa9U, 0x05U, 0x9cU, 0xbbU } |
| #define TX_BUF_SIZE 300U |
Definition at line 92 of file main.cpp.
Referenced by signing_loop().
| void app_main | ( | void | ) |
ESP-IDF application entry point.
Initialises NVS, brings up the PN532 reader (I²C or SPI), connects to Wi-Fi and the Ethereum RPC endpoint, then enters signing_loop.
Definition at line 319 of file main.cpp.
References ADDR_FROM, ESP32Logger::begin(), eth_rpc_init(), eth_rpc_set_auth(), eth_rpc_wifi_connect(), pn532_config_t::i2c_clock_hz, pn532_config_t::i2c_port, NFC_CS, pn532_config_t::pin_cs, pn532_config_t::pin_irq, pn532_config_t::pin_rst, pn532_config_t::pin_scl, pn532_config_t::pin_sda, pn532_init(), PN532_TRANSPORT_I2C, PN532_TRANSPORT_SPI, RPC_URL, signing_loop(), pn532_config_t::skip_bus_init, pn532_config_t::spi_host, SPI_MAX_TRANSFER_SZ, SPI_MISO, SPI_MOSI, SPI_PIN_UNUSED, SPI_SCLK, TAG, pn532_config_t::transport, WIFI_PASSWORD, and WIFI_SSID.
|
static |
Build the 68-byte ABI-encoded calldata for a USDC transfer call.
Encodes the ERC-20 transfer(address,uint256) selector followed by the ABI-encoded arguments:
| [out] | out | 68-byte output buffer for the calldata. |
| [in] | to_hex | Recipient address as a hex string (with or without 0x). |
| [in] | amount | Transfer amount in USDC base units (6 decimals). |
Definition at line 140 of file main.cpp.
References parse_address(), and TRANSFER_SELECTOR.
Referenced by signing_loop().
|
static |
Parse a hex string into a 20-byte Ethereum address.
Accepts an optional 0x or 0X prefix. If the source is shorter than 20 bytes the remaining output bytes are zeroed; if longer, the excess is silently discarded.
| [in] | hex | Hex string (with or without 0x prefix). |
| [out] | out | 20-byte output buffer for the decoded address. |
Definition at line 108 of file main.cpp.
Referenced by build_usdc_calldata(), and signing_loop().
|
static |
Main application loop: sign and broadcast a USDC transfer each card tap.
Each iteration waits for a card, fetches the current nonce, builds and hashes an EIP-1559 USDC transfer transaction, signs it on the card via CryptnoxWallet::sign, recovers the v parity, and broadcasts the signed transaction via eth_rpc_send_raw_tx.
| [in] | wallet | Initialised wallet instance. |
Definition at line 173 of file main.cpp.
References ADDR_TO, ADDR_USDC, AMOUNT_USDC, build_usdc_calldata(), eth_tx_t::calldata, eth_tx_t::calldata_len, CARD_PIN, CARD_PIN_LEN, eth_tx_t::chain_id, CHAIN_ID_SEPOLIA, eth_rlp_encode_signed(), eth_rlp_encode_unsigned(), eth_rpc_ecrecover_parity(), eth_rpc_get_nonce(), eth_rpc_send_raw_tx(), eth_tx_t::eth_value, eth_tx_t::gas_limit, GAS_LIMIT_ERC20, keccak256(), MAX_FEE, eth_tx_t::max_fee, MAX_PRIORITY_FEE, eth_tx_t::max_priority_fee, eth_tx_t::nonce, parse_address(), TAG, eth_tx_t::to, and TX_BUF_SIZE.
Referenced by app_main().
|
static |
Definition at line 89 of file main.cpp.
Referenced by build_usdc_calldata().