mirror of
https://github.com/hanzoai/bootnode.git
synced 2026-10-25 02:31:30 +00:00
Adds a Go subsystem alongside the existing Python FastAPI service so
bootnode can fold into `superbase` per HIP-0106. The Python service in
`api/bootnode/` stays untouched.
What landed:
- `schema/bootnode.zap` — public typed surface (chains, RPC, tokens,
NFTs, transfers, smart wallets, ERC-4337, gas, webhooks, fleets,
nodes, usage). No `.capnp` anywhere — ZAP only, per brand policy.
- `zap/gen/` — hand-rolled Go bindings that match what `zapc generate`
emits, so `go build` works without zapc installed locally.
- `api/mount.go` — the HIP-0106 contract:
func Mount(r chi.Router, deps Deps) error
mounts every FastAPI-parity route group through `api/handlers/`.
- `api/deps.go` — cross-subsystem ZAP client interfaces (IAM, KMS,
Base, O11y, Commerce). No business logic, no hard imports — keeps
the Bootnode module independent of sibling subsystems until they
ship their typed clients.
- `api/handlers/` — 149 chi routes mounted (Python has 150). Each
handler body is a 501 stub with a `TODO(bootnode-port)` pointing at
the Python file + symbol to port.
- `api/middleware/` — IAM-backed auth, OTEL-friendly telemetry,
per-org rate limit (stub).
- `api/store/` — per-tenant SQLite access via `deps.Base.Open(orgID,
"bootnode")` per HIP-0302.
- `api/web3/` — chain registry + RPC pool surface (production version
prefers luxfi/* over upstream go-ethereum).
- `cmd/bootnode/main.go` — standalone shim; same `api.Mount` superbase
calls in production.
- `docs/PYTHON_TO_GO_PORT.md` — endpoint-by-endpoint port map.
Build: `go build ./...` and `go vet ./...` clean. Standalone shim
smokes 200 on /health, /ready, /v1/chains; 401 on auth-required
endpoints with no JWT; 501 on every TODO route.
Out of scope (not in this commit):
- Handler bodies (Phase 2 — porting in RPC → tokens → NFTs → ...
priority order).
- superbase wiring (lands when the superbase repo opens its main).
- Python service removal (stays until handlers reach prod parity).
64 lines
2.1 KiB
Go
64 lines
2.1 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
bootnodezap "github.com/hanzoai/bootnode/zap/gen"
|
|
"github.com/hanzoai/bootnode/api/middleware"
|
|
)
|
|
|
|
// MountAuthKeys registers /v1/auth-keys/* — project + API key admin.
|
|
// The plaintext API key is returned ONCE on creation and never
|
|
// stored: deps.Service.CreateAPIKey is responsible for bcrypt'ing the
|
|
// secret before writing to deps.Base.
|
|
func MountAuthKeys(r chi.Router, d Deps) {
|
|
r.Route("/auth-keys", func(r chi.Router) {
|
|
r.Post("/projects", middleware.RequireAuth(func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/auth_keys.py:create_project
|
|
stub(w, "auth-keys/projects")
|
|
}))
|
|
r.Get("/projects/{project_id}", middleware.RequireAuth(func(w http.ResponseWriter, _ *http.Request) {
|
|
// TODO(bootnode-port): port from bootnode/api/auth_keys.py:get_project
|
|
stub(w, "auth-keys/projects/{id}")
|
|
}))
|
|
r.Post("/keys", middleware.RequireAuth(func(w http.ResponseWriter, r *http.Request) {
|
|
var req struct {
|
|
ProjectID string `json:"projectId"`
|
|
Name string `json:"name"`
|
|
Scopes []string `json:"scopes"`
|
|
}
|
|
if !readJSON(w, r, &req) {
|
|
return
|
|
}
|
|
res, err := d.Service.CreateAPIKey(r.Context(), middleware.OrgID(r.Context()), req.ProjectID, req.Name, req.Scopes)
|
|
if err != nil {
|
|
serviceErr(w, err, "auth-keys/keys POST")
|
|
return
|
|
}
|
|
writeJSON(w, http.StatusCreated, res)
|
|
}))
|
|
r.Get("/keys", middleware.RequireAuth(func(w http.ResponseWriter, r *http.Request) {
|
|
keys, err := d.Service.ListAPIKeys(r.Context(), middleware.OrgID(r.Context()))
|
|
if err != nil {
|
|
serviceErr(w, err, "auth-keys/keys GET")
|
|
return
|
|
}
|
|
if keys == nil {
|
|
keys = []bootnodezap.APIKey{}
|
|
}
|
|
writeJSON(w, http.StatusOK, keys)
|
|
}))
|
|
r.Delete("/keys/{key_id}", middleware.RequireAuth(func(w http.ResponseWriter, r *http.Request) {
|
|
id := chi.URLParam(r, "key_id")
|
|
ok, err := d.Service.RevokeAPIKey(r.Context(), middleware.OrgID(r.Context()), id)
|
|
if err != nil {
|
|
serviceErr(w, err, "auth-keys/keys/{id} DELETE")
|
|
return
|
|
}
|
|
writeJSON(w, http.StatusOK, map[string]bool{"ok": ok})
|
|
}))
|
|
})
|
|
}
|