nxt-sts
Purpose
nxt-sts is a stateless Spring Boot microservice that generates prepaid metering tokens compliant with IEC 62055-41 (STS). It exposes a small REST API consumed by backend integration layers in prepaid utility workflows.
Scope
- In scope:
- STS token issuance via
POST /tokenfor four supported token types. - Decoder-key based token generation using the Standard Transfer Algorithm (STA/EA07).
- Strategy-based dispatch from HTTP requests to token generator implementations.
- Self-describing API surface (OpenAPI/Swagger) and health endpoint for orchestration.
- STS token issuance via
- Out of scope:
- Customer payment UX and transaction orchestration (handled by other services/apps).
- Meter communication and post-issuance delivery channels.
- Token persistence, replay tracking, or meter state management (each request is a pure function).
What this service does in production
- Accepts token-issue requests at
POST /tokenand returns a 20-digit IEC 62055-41 token string. - Dispatches requests to a matching
TokenStrategyimplementation (TOP_UP,CLEAR_CREDIT,CLEAR_TAMPER,SET_POWER_LIMIT). - Validates input before generation (token type, required fields,
randomNumberrange 0–15, decoder key format, ISO 8601 issue date). - Returns structured JSON error responses with HTTP 400/500 status codes on failure.
- Exposes operational endpoints:
GET /(service index),GET /swagger(Swagger UI),GET /actuator/health.
Primary workflows
- Top-up token workflow: client submits
type=TOP_UPwithkwh, issue date, random number, and decoder key; service returns a generated 20-digit token. - Clear operation workflow: client submits
CLEAR_CREDITorCLEAR_TAMPER; service builds class-2 token structures and returns token. - Power-limit workflow: client submits
SET_POWER_LIMITwithpowerLimit; service generates corresponding class-2 control token. - Integration discovery workflow: client calls
GET /or opens/swaggerto inspect available endpoints and request schema before wiring backend callers.
Setup and run
- Repository: github.com/nxtgrid/nxt-sts
- Prerequisites: Java 17+ (local Maven not required — repository includes
./mvnw). - Build:
./mvnw clean package -DskipTests(producestarget/nxt-sts-*.jar). - Run locally (dev):
./mvnw spring-boot:run(default port 8080). - Run packaged JAR:
java -jar target/nxt-sts-*.jar(override port with--server.port=8084). - Docker:
docker build -t nxt-sts . && docker run -p 8080:8080 nxt-sts(multi-stage Dockerfile; no pre-built JAR required). - Released container image:
ghcr.io/nxtgrid/nxt-sts:latest(published on version tags such asv1.0.0).
Deployment
Platform-specific deployment guides live under this repository section:
- DigitalOcean App Platform — deploy from GHCR or build from the GitHub repository.
APIs and interfaces
POST /token— primary token generation endpoint (TokenController).- Request contract (
TokenRequest):type(TOP_UP,CLEAR_CREDIT,CLEAR_TAMPER,SET_POWER_LIMIT)issueDate(ISO 8601, e.g.2024-03-15T10:30:00)randomNumber(integer 0–15; STS 4-bit RND field)decoderKey(16-character hex string)kwh(required forTOP_UP)powerLimit(required forSET_POWER_LIMIT)
- Response contract:
{ "token": "<20-digit-token>" }. - Error contract: structured JSON with HTTP 400 (validation/unknown type) or 500 (unexpected generation failure).
- Canonical API reference: Swagger UI at
/swaggerafter starting the service.
Integrations and dependencies
- Core framework: Spring Boot 3.4 (web, validation, actuator).
- Cryptographic/token stack: Bouncy Castle + STS domain/generator classes under
co.nxtgrid.token.*. - Time/date parsing: Joda-Time for IEC 62055-41 date handling.
- API documentation: springdoc-openapi (Swagger UI + OpenAPI JSON).
- CI: GitHub Actions runs
./mvnw verifyon push/PR tomain. - Container releases: tagged versions publish to GHCR via
.github/workflows/release.yml. - Service lineage: derivative work from
NectarAPI/tokens-service(documented inNOTICE, AGPL-3.0).
Operations notes
- Default HTTP port is 8080; override via
SERVER_PORTenv var or--server.port. - Health check path for load balancers and orchestrators:
/actuator/health(returns{"status":"UP"}). - Decoder keys are meter-specific secrets — transmit only over HTTPS; do not log or persist in plaintext.
- Key failure modes to check first:
- invalid or missing token type / type-specific fields (
kwh,powerLimit), randomNumberoutside 0–15 (STS protocol constraint, not an arbitrary API limit),- malformed
decoderKey(must be exactly 16 hex characters), - unparseable
issueDateformat.
- invalid or missing token type / type-specific fields (
Source of truth
- Repository: github.com/nxtgrid/nxt-sts
- Application bootstrap:
src/main/java/co/nxtgrid/StsApplication.java - Token endpoint:
src/main/java/co/nxtgrid/api/TokenController.java - Request/response models:
src/main/java/co/nxtgrid/api/TokenRequest.java,TokenResponse.java - Strategy implementations:
src/main/java/co/nxtgrid/strategy/ - Runtime config:
src/main/resources/application.properties - Build/runtime dependencies:
pom.xml - Container packaging:
Dockerfile - Token capability matrix:
docs/capabilities.md - Operator runbook (build, test, Docker, API):
README.md