Universal Bitcoin Identity Layer
A production-focused Flask service that bridges OAuth2/OpenID Connect with Lightning Network authentication. The project couples hardened security defaults, Redis-backed rate limiting, RS256 JWT issuance, and Postgres persistence so Bitcoin-enabled applications can expose standards-compliant identity endpoints.
π Highlights
- Security-first OAuth2/OIDC core β RS256 tokens with on-disk JWKS rotation, PKCE validation, HTTPS enforcement through
app.security, and Redis-powered rate limiting with production fail-closed behavior and explicit non-production in-memory fallback warnings. - Lightning-aware identity workflows β LNURL-auth challenge storage, Bitcoin signature verification helpers, and adapters that keep the legacy authorization views working while the storage layer matured.
- Persistent storage β SQLAlchemy models for OAuth clients/codes/tokens, sessions, LNURL challenges, proof-of-funds requests, and audit logs backed by Postgres with Redis coordination for ephemeral state.
- Operational tooling β
/metrics/prometheusendpoint, structured JSON logging, and a reusablecreate_app()factory (app/factory.py) for factory-based deployments. - Typed configuration surface β Environment-driven configuration validated by
app.config, including production guardrails for secrets, Redis, and database connectivity.
ποΈ Architecture at a Glance
| Layer | Key Modules | Responsibilities |
|---|---|---|
| Web application | app/app.py, app/factory.py | Flask application, OAuth2/LNURL routes, Prometheus metrics, Socket.IO events, plus the factory-based app initialization |
| Security | app/security.py | Proxy/header fixes, HTTPS enforcement, Flask-Limiter setup, logging defaults |
| Identity tokens | app/tokens.py, app/jwks.py | RS256 JWT issuance, keypair persistence, JWKS publication |
| Storage | app/db_storage.py, app/database.py, app/storage.py | Postgres session helpers, Redis utilities, and in-memory parity for tests |
| Configuration | app/config.py | Typed env loader, production validation helpers |
| Observability | app/app.py, deployment/README.md | Prometheus counter wiring and deployment guidance |
Further documentation lives in the app/ directory and supporting deployment guides under deployment/.
π§° Prerequisites
- Python 3.10+
- Postgres 13+
- Redis 6+
- Bitcoin Core 24+ (for RPC-backed features)
For local development you can omit Postgres/Redis by exporting DATABASE_URL and REDIS_URL pointing to ephemeral services (e.g. docker-compose) or by relying on the in-memory storage adapter for tests.
π Quick Start
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
export FLASK_APP=app.app:app
export FLASK_ENV=development
export RPC_USER=bitcoinrpc
export RPC_PASSWORD=change-me
flask run
The service exposes:
/.well-known/openid-configuration,/oauth/token,/oauth/authorize
For third-party login setup, see Sign in with HODLXXI Integration Guide.
/.well-known/agent.json,/agent/capabilities,/agent/capabilities/schema/agent/skills,/agent/marketplace/listing,/agent/reputation,/agent/attestations/lnurl/authLNURL challenge endpoints/metrics/prometheusfor Prometheus scrapers/healthbasic liveness probe
Docker Compose quick start
If you want a production-like stack without installing Postgres/Redis/Bitcoin Core locally, use the bundled Compose file:
cp env.example .env
docker compose up --build
The Postgres, Redis, and Bitcoin services wait for health checks before the Flask app starts. Mounts for ./app, ./logs, and ./keys ensure code edits and generated keys persist on the host. See docs/DEV_ONBOARDING_CHECKLIST.md for the full onboarding flow and smoke tests.
See TESTING.md for pytest, mypy, and linting guidance.
βοΈ Configuration Reference
app/config.py documents every supported environment variable. Highlights include:
JWT_ALGORITHM=RS256to force asymmetric signing; JWKS files are stored inJWKS_DIR.RATE_LIMIT_ENABLED/RATE_LIMIT_DEFAULTfor limiter tuning.DATABASE_URLor discreteDB_*variables for SQLAlchemy.REDIS_URL/REDIS_*for rate limiting and challenge/session TTL handling.SOCKETIO_ASYNC_MODEto pick a compatible backend (defaults toeventletwhen available, otherwise falls back tothreading).FORCE_HTTPS,SECURE_COOKIES, andCSRF_ENABLEDfor deployment hardening.
Run python -m app.config (or import validate_config) inside your deployment pipeline to fail fast on insecure production settings.
π§ͺ Testing
pytest
Unit tests cover configuration parsing/validation along with storage adapters. Integration tests spin up the in-memory backend to exercise OAuth and LNURL flows without external services.
Product Positioning
- Runtime Product Positioning - current product framing: HODLXXI as a Bitcoin-native trust runtime for public-key agents and services.
Agent Readiness
- HODLXXI Readiness Evaluation - current external evaluation path for public agent/runtime readiness.
- HODLXXI External Reviewer Packet - canonical public review packet for live reviewers, developers, investors, agent marketplace reviewers, and technical evaluators.
- Agent Readiness Report v1 - contract for public agent/service readiness reports backed by receipts and attestations.
GET /agent/readiness/self-scan- public machine-readable self-scan report for the current HODLXXI runtime. It returnsschema,summary,checks,verification,report_sha256, and currentreceipt/attestationstatus.
Developer Quickstarts
- Agent Receipt Quickstart β external developer flow: discovery, paid job request, polling, receipt verification, attestations, and reputation.
π€ Agent, Skills, and Marketplace Discovery
The repository now exposes a coherent machine-readable agent surface:
/.well-known/agent.jsonfor the public identity/discovery document/agent/capabilitiesfor the signed capabilities handshake/agent/capabilities/schemafor the canonical JSON Schema of that handshake/agent/skillsfor first-class skill discovery sourced fromskills/public//agent/marketplace/listingfor normalized directory/marketplace ingestion
For the protocol and trust model, see:
docs/DOCUMENTATION_MAP.mdexplains which docs are current, historical, experimental, or archive candidates.AGENT_PROTOCOL.mdfor the signed discovery and job protocolTRUST_MODEL.mdfor the normative trust language and verification boundariesdocs/AGENT_SURFACES.mdfor how the runtime discovery endpoints expose those claims
The current agent surface is intentionally conservative: it exposes public-key identity, declared operator metadata, paid execution, signed receipts, and observable history, while treating time-locked capital and on-chain backing as optional trust anchors rather than verified runtime facts.
Python SDK for agents
Developers can start from the SDK index:
docs/sdk/README.md
The SDK covers:
- public discovery and agent job requests
- Bitcoin-message auth challenge flow
- Nostr auth challenge flow
- receipt helpers
- signing helpers with caller-provided signers
Examples:
examples/python/ping_agent.pyexamples/python/auth_challenge_flow.pyexamples/python/nostr_auth_challenge_flow.py
The SDK does not hold private keys. Applications bring their own wallet, hardware, Bitcoin Core, Nostr, or agent-runtime signer.
π€ Contributing
- Fork the repository and create a virtual environment.
- Install dev dependencies with
pip install -r requirements-dev.txt. - Run
pytestbefore opening a pull request. - Follow the code of conduct and contribution guidelines.
Bug reports and feature proposals are welcome via GitHub Issues.
π License
Released under the MIT License.
Production readiness artifact storage
Persisted readiness self-scan reports are runtime artifacts, not source files. For hardened production deployments, set:
AGENT_READINESS_REPORT_DIR=/srv/ubid/runtime/agent_readiness_reports
For hodlxxi.service, this path should live under the writable runtime area and be owned by the service user.