|
Nostrduino
|
A nostr-tools inspired Nostr library for Arduino ESP32.
This was created using arduino-nostr as starting point, most of the code was rewritten and the library was expanded to include more features.
This library supports ESP32 boards using the Arduino framework.
This library is built with a DIY philosophy in mind, similar to nostr-tools, this library provides helpers to create, sign and verify messages and to use some of the NIPs features (see the src/Nip* files).
In addition to that, the library provides some "managed" services (in src/services folder) that you can use in your sketches without worrying about the details and complexity of the nostr protocol.
Check the platformio registry page for instructions.
This library depends on the following libraries for the ESP32 platform:
uBitcoin is the only elliptic-curve backend. Version 0.2.0 is pinned as the src/uBitcoin git submodule.
When building from a git checkout, initialize the pinned source with:
Registry packages already contain the required submodule sources.
ESP32Platform::initNostr(bool withLogger, bool initializeRngWithoutRadio = false)
when initializing the library, leave the second argument at false when the application uses or will start Wi-Fi or Bluetooth.
Firmware that does not use and will not start Wi-Fi or Bluetooth must enable the explicit offline mode:
With this option, Nostrduino calls bootloader_random_enable() before the normal initialization so esp_fill_random has the offline entropy source needed by cryptographic operations.
This is a radio-free/offline mode only, when using Wi-Fi or Bluetooth the entropy source is provided by the ESP32 radio and the second argument must be false.
Do not start Wi-Fi, Bluetooth, ADC or I2S after enabling it without first calling bootloader_random_disable() and handling the transition required by the installed ESP-IDF; that lifecycle remains the application's responsibility.
The default ESP32 transport accepts TLS connections without certificate validation to keep CA provisioning optional on constrained ESP32 deployments. For certificate validation, provide a PEM CA and require it:
See the example scripts in examples/ for simple examples of how to use this library.
[!IMPORTANT]
NostrPooldeliberately accepts structurally valid relay events without cryptographic verification by default. Applications that use author identity or event contents as a security boundary should enable automatic verification with
pool.setVerifyIncomingEvents(true) or call SignedNostrEvent::verify() explicitly.
Managed NWC responses are verified explicitly regardless of this pool setting.
NostrPool does not keep a list of received event IDs by default. This avoids reserving memory for an application-specific cache on constrained devices. A relay may therefore deliver the same event more than once, especially when a subscription uses multiple relays.
Use setSeenTracker() to provide a tracking policy suited to the device. The callback must return true for an event that should be discarded. When it returns false, the pool delivers the event to the subscription callback. Calls to the tracking callback are serialized by the pool.
The application chooses the cache size, lookup strategy and eviction policy. Calling pool.setSeenTracker(nullptr) restores the default pass-through behavior.
The following commands only build the example firmware; they are not the unit-test gate.
Edit examples/ESP32TestNip01/ESP32TestNip01.cpp and set the WIFI_SSID, WIFI_PASS and WIFI_CHANNEL.
Then compile with:
Compile with:
Edit examples/ESP32TestNWC/ESP32TestNWC.cpp and set the WIFI_SSID, WIFI_PASS , WIFI_CHANNEL and NWC_URL. NB: you can get a nwc url from https://nwc.getalby.com/ or https://app.mutinywallet.com/settings/connections.
Then compile with: