cryptnox-sdk-esp32 1.0.0
ESP32 SDK for Cryptnox Hardware Wallet
Loading...
Searching...
No Matches
eth_rpc.h
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: LGPL-3.0-or-later
3 * Copyright (c) 2026 Cryptnox SA
4 */
5
6#pragma once
7
8#include <stdint.h>
9#include <stddef.h>
10#include <stdbool.h>
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16/*
17 * Set the RPC URL and the from-address used for nonce queries and
18 * ecrecover comparison. Must be called before any other eth_rpc_* function.
19 * from_addr must be a "0x..."-prefixed 40-hex-char string.
20 */
21void eth_rpc_init(const char *rpc_url, const char *from_addr);
22
23/*
24 * Optional: set the Infura API secret for HTTP Basic Auth.
25 * Pass NULL or empty string to disable. Must be called before any
26 * eth_rpc_* function that makes network requests.
27 * The Project ID is used as the username; api_secret is the password.
28 */
29void eth_rpc_set_auth(const char *project_id, const char *api_secret);
30
31/*
32 * Connect to a WiFi network and block until an IP is obtained (up to 30 s).
33 * Returns true on success.
34 */
35bool eth_rpc_wifi_connect(const char *ssid, const char *password);
36
37/*
38 * Fetch the pending transaction count (nonce) for from_addr.
39 * Returns true and writes the nonce into *nonce_out on success.
40 */
41bool eth_rpc_get_nonce(uint64_t *nonce_out);
42
43/*
44 * Determine the signature parity bit (v = 0 or 1) by calling the ecrecover
45 * precompile (address 0x01) via eth_call and matching the recovered address
46 * against from_addr. Returns 0 or 1; defaults to 0 on RPC failure.
47 */
48uint8_t eth_rpc_ecrecover_parity(const uint8_t hash[32],
49 const uint8_t r[32],
50 const uint8_t s[32]);
51
52/*
53 * Broadcast a raw signed transaction (type-prefixed RLP bytes).
54 * On success writes the "0x..."-prefixed tx hash into tx_hash_out and
55 * returns true. tx_hash_out must be at least 68 bytes (2 + 64 + NUL).
56 */
57bool eth_rpc_send_raw_tx(const uint8_t *tx, size_t tx_len,
58 char *tx_hash_out, size_t tx_hash_max);
59
60#ifdef __cplusplus
61}
62#endif
bool eth_rpc_send_raw_tx(const uint8_t *tx, size_t tx_len, char *tx_hash_out, size_t tx_hash_max)
Definition eth_rpc.cpp:332
bool eth_rpc_wifi_connect(const char *ssid, const char *password)
Definition eth_rpc.cpp:181
bool eth_rpc_get_nonce(uint64_t *nonce_out)
Definition eth_rpc.cpp:231
void eth_rpc_init(const char *rpc_url, const char *from_addr)
Definition eth_rpc.cpp:169
void eth_rpc_set_auth(const char *project_id, const char *api_secret)
Definition eth_rpc.cpp:175
uint8_t eth_rpc_ecrecover_parity(const uint8_t hash[32], const uint8_t r[32], const uint8_t s[32])
Definition eth_rpc.cpp:257