<>ts-stack
Get StartedArchitecturePackagesSpecsGuides
⌘K
Reference
Home
Get StartedOverviewInstallChoose your stackKey concepts
ArchitectureOverviewStack layersBEEF (BRC-62)BRC-100 Wallet InterfaceIdentity & AuthConformance pipeline
PackagesOverviewSDKWalletNetworkOverlaysMessagingMiddlewareHelpers
InfrastructureOverviewmessage-box-serveroverlay-serveruhrp-server-basicuhrp-server-cloud-bucketwabwallet-infrachaintracks-server
SpecsOverviewBRC-100 Wallet InterfaceOverlay HTTPMessage-box HTTPAuthsocket (WebSocket)BRC-31 Auth HandshakeBRC-29 Peer PaymentBRC-121 / HTTP 402ARC BroadcastMerkle ServiceStorage AdapterGASP SyncUHRPAir-Gap Optical (BRC-141)
ConformanceOverviewVector catalogTS runnerContributing vectors
GuidesOverviewBuild a wallet-aware appRun an overlay nodePeer-to-peer messagingHTTP 402 payments
ReferenceOverviewBRC indexRepository health
AboutVersioningContributingDoc agentDocumentation sources
Loading…
Edit this page on GitHub
© 2026 BSV Blockchain. ts-stack is open-source.
GitHubContributingVersioning

UHRP Server (Cloud Bucket)

A production-grade UHRP host server backed by Google Cloud Storage. Stores large files in cloud buckets with optional billing/micropayments and includes advertising infrastructure for overlay network discovery.

What it does

A TypeScript/Express server designed for Google Cloud Run that implements UHRP workflows backed by Google Cloud Storage. Static object retrieval is public; upload, list, find, and renewal require BRC-103 identity. A separate administrative advertisement endpoint uses a strong Bearer token.

Clients upload files with authentication, retrieve files via public GET, and server continuously advertises hosting capability.

When to deploy this

  • Production UHRP hosting on Google Cloud Run or equivalent
  • High-volume file storage with auto-scaling requirements
  • Multi-region replication and disaster recovery needed
  • Monetizing UHRP hosting via micropayments
  • Advertising UHRP services to overlay network

Dependencies

TypeRequirement
DatabaseNone; Google Cloud Storage is the object and metadata source of truth
External servicesGoogle Cloud Storage bucket, ARC API key, Wallet Storage, Bugsnag (optional)
ts-stack packages@bsv/sdk, @bsv/auth-express-middleware, @bsv/payment-express-middleware, @bsv/wallet-toolbox, @bsv/wallet-toolbox-client

HTTP endpoints

MethodPathPurpose
GET/HEADStatic object pathsRetrieve stored objects (public)
POST/advertiseAdministrative advertisement using Authorization: Bearer
POST/quotePublic storage-price quote
POST/uploadAuthenticated upload/payment workflow
GET/listList the authenticated uploader's objects
GET/findFind authenticated uploader metadata
POST/renewAuthenticated ownership/payment renewal
GET/health, /healthzPublic process liveness
GET/readyPublic initialization readiness

WebSocket endpoints

None; HTTP-only with background advertising worker.

Configuration (env vars)

VariableRequiredDescription
HTTP_PORTNoExpress server port (default: 8080, typically 8080 for Cloud Run)
NODE_ENVNodevelopment, staging, or production
SERVER_PRIVATE_KEYYes256-bit hex private key for server identity
HOSTING_DOMAINNoPublic HTTPS domain for advertising (e.g., https://uhrp-storage.example.com)
BSV_NETWORKNoTarget blockchain network (main, test, or regtest)
WALLET_STORAGE_URLNoWallet storage endpoint (e.g., https://store-us-1.bsvb.tech)
PRICE_PER_GB_MONoMonthly storage price per GB for billing
ENABLE_PAYMENT_MIDDLEWARENoSet to 'true' to require payment for uploads
GOOGLE_CLOUD_PROJECTNoGCP project ID (auto-detected from service account if available)
GOOGLE_CLOUD_BUCKETYesCloud Storage bucket name (e.g., uhrp-storage-prod)
GOOGLE_APPLICATION_CREDENTIALSNoPath to service account JSON key (for local/Cloud Run auth)
ARC_API_KEYNoARC API key for transaction broadcasting (advertising)
ADVERTISE_INTERVAL_MSNoInterval for re-advertising to overlay (default: 3600000ms = 1 hour)
BUGSNAG_API_KEYNoBugsnag error reporting API key (optional)
ADMIN_TOKENYesAt least 32 random characters for /advertise Bearer auth
UHRP_CORS_MODENopublic (default), allowlist, or disabled
UHRP_CORS_ALLOWED_ORIGINSNoExact comma-separated origins in allowlist mode
UHRP_CORS_ALLOWED_HEADERSNoStrict comma-separated browser request-header allowlist; omit for additive compatibility
UHRP_JSON_MAX_BODY_BYTESNoJSON body ceiling (default 262144)
TRUST_PROXY_HOPSNoExact trusted proxy hop count, 0 through 10

See Public Service Edge Security for full edge controls.

Run locally

bash
# Install dependencies
npm install

# Development with hot-reload
npm run dev

# Build TypeScript
npm run build

# Run production build
npm start

Requires GCP service account credentials or emulator for local testing.

Deploy to production

bash
# Multi-stage build: pinned Node 24 alpine builder → production runtime
docker build -t uhrp-storage:latest .

# Deploy to Google Cloud Run
gcloud run deploy uhrp-storage \
  --image uhrp-storage:latest \
  --platform managed \
  --region us-central1 \
  --set-env-vars SERVER_PRIVATE_KEY=<hex-key>,GOOGLE_CLOUD_BUCKET=uhrp-storage-prod,ENABLE_PAYMENT_MIDDLEWARE=true

# Or deploy with docker-compose (local testing only)
docker compose up -d

Follows GCP 12-factor patterns: stateless design, cloud bucket for file storage, Cloud SQL for optional metadata, Cloud Logging integration, Bugsnag for error tracking. Graceful shutdown via SIGTERM signal handling.

Migrations

No database migrations. Google Cloud Storage is the durable source of truth.

Health checks

  • GET /health and GET /healthz report process liveness.
  • GET /ready returns 200 only after wallet-backed authentication and payment middleware initialization completes; the container health check uses it.

Spec conformance

  • UHRP – Implements UHRP host protocol for file storage, retrieval, and metadata
  • BRC-103 – Mutual authentication on upload, list, find, and renewal workflows
  • BRC-100 – Payment verification for uploads (optional)
  • Google Cloud – Follows Cloud Run best practices (health checks, graceful shutdown, 12-factor)

Integration with ts-stack

  • UHRP clients upload/retrieve files using SERVER_PRIVATE_KEY and HOSTING_DOMAIN
  • Wallet Storage derives keys, validates payments, manages user accounts
  • Background worker advertises UHRP host via SHIP overlay protocol using ARC broadcaster
  • Optional Cloud SQL metadata database for query optimization
  • Bugsnag integration for production error tracking and monitoring

Common pitfalls

  • GCP credentials: GOOGLE_APPLICATION_CREDENTIALS must point to valid service account JSON; Cloud Run uses default service account if not set
  • Storage bucket policy: Ensure bucket exists and service account has storage.objects.create/get/delete permissions
  • Cost management: Monitor storage usage and pricing; use Cloud Storage lifecycle policies for archival
  • Payment enforcement: ENABLE_PAYMENT_MIDDLEWARE requires ARC_API_KEY and WALLET_STORAGE_URL; uploads fail if not configured
  • Advertising loop: ADVERTISE_INTERVAL_MS should balance frequent updates vs transaction costs; 1 hour is conservative default
  • Cloud Run and application request timeouts default to 60 seconds; use direct cloud upload workflows for large objects rather than unbounded application buffering
  • Graceful shutdown: Cloud Run sends SIGTERM; ensure all writes complete before exit (transaction broadcasts, metadata flushes)

Source

  • GitHub
  • npm package