Developer Guide
This guide covers building, running, and extending the Shamwari Network node (shamwariQKP v2.2.6). The Shamwari codebase is a fork of the Nxt blockchain platform, written in Java and built with shell scripts (no Maven or Gradle). It uses a hybrid post-quantum cryptography scheme (Kyber + Dilithium).
Development Prerequisites
| Tool | Version | Notes |
|---|---|---|
| Java JDK | 21 LTS | Required — compile.sh uses -source 21 -target 21 |
| JavaFX SDK | 11+ | Needed only for the desktop wallet (javafx-sdk/lib/*) |
| Git | 2.40+ | Source control |
| Docker | 24+ | Containerized deployment |
The project does not use Maven or Gradle. All compilation is done through shell scripts that invoke javac directly against the lib/ and classes/ directories.
Project Layout
shamwariQKP/
├── compile.sh # Compile all Java sources
├── jar.sh # Generate JAR files (shamwari.jar, shamwariservice.jar)
├── package.sh # Build distributable ZIP
├── run.sh # Start the node (--desktop | --daemon | --authbind)
├── start.sh # [DEPRECATED] Use run.sh --daemon
├── stop.sh # Stop a running node (reads PID from ~/.shamwari/nxt.pid)
├── run-desktop.sh # [DEPRECATED] Use run.sh --desktop
├── compact.sh # Compact the H2 database (nxt.tools.CompactDatabase)
├── sign.sh # Sign transaction JSON (nxt.tools.SignTransactionJSON)
├── mint.sh # Run currency mint worker
├── generate-passphrase.sh # Generate passphrases (same flags as run.sh)
├── passphraseRecovery.sh # Search for a lost passphrase
├── contractManager.sh # Manage on-chain contracts (Java security manager + policy)
├── generateAPICalls.sh # Regenerate typed API callers/responses from source
├── constants-export.sh # Export blockchain constants to JS
├── javadoc.sh # Generate Javadoc
├── tests/run-tests.sh # Run non-live unit tests
├── src/java/nxt/ # Core source tree
│ ├── Nxt.java # Main entry point
│ ├── Constants.java # Blockchain constants
│ ├── http/ # REST API layer
│ │ ├── API.java # API server bootstrap (Jetty)
│ │ ├── APIServlet.java # HTTP servlet + APIRequestHandler base class
│ │ ├── APIEnum.java # All API endpoint registrations
│ │ ├── APITag.java # API category tags
│ │ ├── ParameterParser.java # Request parameter parsing
│ │ ├── JSONData.java # Response JSON builders
│ │ ├── JSONResponses.java # Error response constants
│ │ ├── APICall.java # Client-side API call builder
│ │ ├── callers/ # Auto-generated typed clients (ApiSpec, *Call)
│ │ ├── responses/ # Auto-generated typed response wrappers
│ │ ├── proxy/ # API proxy support
│ │ ├── [handler classes] # Individual requestType handlers
│ ├── account/ # Account model & ledger
│ ├── blockchain/ # Block & transaction processing, Generator, Binder
│ │ ├── contracts/ # On-chain Java contract framework
│ │ ├── chaincontrol/ # Permissioned chain controls
│ ├── crypto/ # Post-quantum cryptography
│ │ ├── ShamwariQKP.java # Hybrid Kyber-512 + Dilithium key pair
│ │ ├── ShamwariPrivateKey.java
│ │ ├── ShamwariPublicKey.java
│ │ ├── kyber/ # Kyber KEM
│ │ └── dilithium/ # Dilithium signatures
│ ├── ae/ # Asset Exchange (Totems)
│ ├── ms/ # Monetary System (currencies)
│ ├── peer/ # Peer-to-peer networking
│ ├── voting/ # Phasing & voting
│ ├── subscriptions/ # Subscription services
│ ├── apps/ # Application listings
│ ├── digitalcertificates/ # Digital certificates
│ ├── shuffling/ # Transaction shuffling (privacy)
│ ├── freeze/ # Freeze functionality
│ ├── addons/ # Add-on framework
│ ├── db/ # Database layer
│ ├── dbschema/ # Schema definitions
│ ├── configuration/ # Config parsing
│ ├── env/ # Runtime environment (daemon, dir provider)
│ ├── tools/ # CLI utilities
│ ├── util/ # Utilities (logging, crypto helpers)
│ └── migration/ # Data migration
├── src/java/shamwari/ # Shamwari-specific extensions (ShamwariIQ, agent gateway)
├── src/java/nxt/addons/ # Built-in add-ons (forging, binding, shuffling configs)
├── conf/
│ ├── nxt-default.properties # Default configuration (do not modify)
│ ├── nxt.properties # Local overrides (create this)
│ └── examples/ # Example configs (testnet, light client, desktop)
├── lib/ # JAR dependencies
├── html/ # Web UI + API developer console
├── logs/ # Log files (shamwari.log, rotated shamwari.*.log)
├── shamwari_db/ # Mainnet database (created at runtime)
├── shamwari_test_db/ # Testnet database
├── addons/ # Add-on classes & libs
└── docker/docker_start.sh # Docker entrypoint
Building
# Compile core, desktop, add-ons, and tests
./compile.sh
# Compile without the JavaFX desktop wallet
./compile.sh --skip-desktop
# Package into distributable JARs (shamwari.jar, shamwariservice.jar)
./jar.sh
# Build the full distributable ZIP
./package.sh
# Generate Javadoc
./javadoc.sh
Regenerating the API Client Library
The typed Java clients in callers/ and response wrappers in responses/ are auto-generated from the handler source files:
./generateAPICalls.sh
This reads src/java/nxt/http/*.java and emits src/java/nxt/http/callers/ and src/java/nxt/http/responses/ into the source tree.
Running the Node
# Interactive mode (foreground)
./run.sh
# Background daemon (stores PID in ~/.shamwari/nxt.pid)
./run.sh --daemon
# Stop a daemon
./stop.sh
# Desktop wallet mode (requires JavaFX)
./run.sh --desktop
# Use authbind for privileged ports
./run.sh --authbind
Configuration lives in conf/nxt.properties (which overrides conf/nxt-default.properties). The default configuration runs on testnet (nxt.isTestnet=true).
Default Ports
| Protocol | Testnet | Mainnet | Purpose |
|---|---|---|---|
| API (HTTP) | 22024 | 22025 | REST API at /nxt |
| API (HTTPS) | 22024 | 22025 | SSL API (nxt.apiSSL=true) |
| Peer | 22022 | 22022 | P2P networking |
API Architecture
All REST endpoints are served from a single servlet mapped at /nxt. Each API is a handler class in nxt.http that extends APIServlet.APIRequestHandler. Endpoints are registered centrally in APIEnum.java and tagged with APITag categories.
Adding a New API Endpoint
- Create a handler class extending
APIServlet.APIRequestHandlerinsrc/java/nxt/http/. - Register it in
APIEnum.java(add an enum constant at the end). - Call
./generateAPICalls.shto generate the typed client and response classes. - Implement
processRequest(HttpServletRequest).
public final class MyNewApi extends APIServlet.APIRequestHandler {
static final MyNewApi instance = new MyNewApi();
private MyNewApi() {
super(new APITag[] {APITag.ACCOUNTS}, "account", "param1");
}
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
JSONObject response = new JSONObject();
// ... implementation ...
return response;
}
}
API Tags
The APITag enum (APITag.java:22) defines endpoint categories:
| Tag | Display name |
|---|---|
ACCOUNTS | Accounts |
ACCOUNT_CONTROL | Account Ctrl |
ADDONS | Add-ons |
AE | Asset Exchange |
MS | Banking |
BETA_CHAIN_CONTROL | Chain Control |
BIP32 | Bip32 |
BLOCKS | Blocks |
CERTIFICATE | Certificates |
CONTRACTS | Contracts |
DEBUG | Debug |
FORGING | Forging |
INFO | Server Info |
MESSAGES | Messages |
NETWORK | Networking |
PAYMENTS | Payments |
PHASING | Phasing |
SEARCH | Search |
SHUFFLING | Shuffling |
SUBSCRIPTIONS | Subscriptions |
TOKENS | Tokens |
TRANSACTIONS | Transactions |
UTILS | Utils |
VS | Voting And Polling |
AGENT_ATTESTATION | Agents |
Authentication
Two authentication mechanisms are used:
- Secret Phrase / Private Key: For transaction-signing APIs, pass
secretPhrase, or the hybrid key componentsshamwariPrivateKeyandshamwariPublicKey(hex-encoded). Multi-sig variants usesharedPieceandsharedPieceAccount. - Admin Password: For administrative APIs, pass
adminPasswordwhennxt.adminPasswordis set and the API server listens on non-loopback addresses. Admin password is automatically disabled on localhost.
Smart Contracts
Shamwari supports Java-based on-chain contracts. See Smart Contracts for full details.
Testing
# Compile first
./compile.sh
# Run non-live unit tests (crypto, account, blockchain)
./tests/run-tests.sh
The test suite uses JUnit 5 via lib/junit-platform-console-standalone-1.5.2.jar. Tests do not start a node or connect to a database.
Add-ons
Add-ons are custom extensions loaded via nxt.addOns in nxt-default.properties. Built-in add-ons include BindingEncryptedConfig, ForgingEncryptedConfig, FundingMonitorsEncryptedConfig, and StandbyShufflingEncryptedConfig. Custom add-ons can be placed in addons/classes/ or addons/lib/.