Skip to content

The HyperBEAM Book (Pre-Release)

From Zero to Building Custom Devices

This book teaches you to build on HyperBEAM — the OS for the verifiable internet. Start with the foundation, learn Erlang, then work through the codebase from core resolution to device implementation. By the end, you'll understand every module and be ready to build.


Contents

  1. HyperBEAM
  2. Setup
  3. Erlang
  4. Project Structure
  5. Arweave Utils
  6. HyperBEAM Core
  7. Devices
  8. Building Your Own Devices

Prologue: HyperBEAM

The foundation of the AI era: the verifiable internet. AO-Core extends HTTP with verifiability. HyperBEAM is the OS. Learn the stack (messages, devices, processes, hashpath, attestation), then what you can build on top.


Chapter 1: Setup

Get HyperBEAM running on your machine.


Chapter 2: Erlang

HyperBEAM is written in Erlang. You cannot read the code without learning the language first.


Chapter 3: Project Structure

Before reading modules, understand how the codebase is organized.


Chapter 4: Arweave Utils

Arweave blockchain primitives. HyperBEAM stores everything on Arweave—these modules are the foundation.

ModuleDescription
rsa_pssRSA-PSS signature algorithm per RFC 3447, used by ar_wallet for all cryptographic operations
ar_walletGenerates RSA-4096 keypairs, loads JWK keyfiles, signs data, verifies signatures, derives addresses
ar_deep_hashComputes Arweave's recursive SHA-384 hash for transaction and data item ID generation
ar_bundlesCreates, signs, serializes, and deserializes ANS-104 data items and bundles
ar_txHandles Layer 1 Arweave transactions including creation, signing, and serialization
ar_timestampFetches current block height and timestamp from Arweave network for time synchronization
ar_rate_limiterToken bucket rate limiter to prevent overwhelming Arweave gateways with requests

Chapter 5: HyperBEAM Core

The runtime environment that devices execute in. Understanding these modules helps you write better devices and debug issues.

You'll start with pure utilities, then learn how data flows through the system — from configuration to storage to network to the protocol that ties everything together.


1. Utilities

Pure helper functions used throughout the codebase.

ModuleDescription
hb_utilBase64url encoding, unique ID generation, type coercion, and debug printing utilities
hb_jsonJSON encoding and decoding wrapper supporting maps, lists, binaries, and primitives
hb_escapeURI percent-encoding, path segment escaping, and safe string handling
hb_structured_fieldsRFC 9651 HTTP Structured Fields parser for dictionaries, lists, and typed values
hb_keccakKeccak-256 hashing via NIF, also derives Ethereum addresses from public keys
hb_cryptoMulti-algorithm signing helpers for RSA, ECDSA, Ed25519 with format conversion

2. Configuration

How HyperBEAM settings flow from defaults through node config to per-message overrides.

ModuleDescription
hb_optsHierarchical configuration resolving options from message to node config to defaults
hb_privateManages private keys and signing context, keeps secrets out of cached data
hb_featuresFeature flag system for enabling/disabling functionality and gradual rollouts
hb_pathParses paths into segments, matches patterns with wildcards, handles templates

3. Data Structures

Messages are maps. These modules define how they're created, signed, linked, and transformed.

ModuleDescription
hb_mapsEnhanced map operations with automatic link resolution and nested path traversal
hb_messageCreates messages, computes IDs, signs with attestations, verifies signatures
hb_linkContent-addressed references that resolve through cache with hashpath computation
hb_singletonConverts between flat path-based keys and nested hierarchical message formats

4. Storage

Persistent data storage with pluggable backends.

ModuleDescription
hb_storeAbstract storage interface defining read, write, list, delete operations
hb_store_optsParses store configuration and creates store instances with fallback chains
hb_store_fsFilesystem storage backend that stores data as files in directories
hb_store_lmdbLMDB backend via NIF—fast, reliable, default storage with concurrent readers
hb_store_rocksdbRocksDB LSM-tree backend via NIF for write-heavy workloads
hb_store_lruWraps any store with in-memory LRU cache for improved read performance

5. Caching

Content-addressed caching layer on top of storage.

ModuleDescription
hb_cacheStores messages by content hash, resolves links recursively, expands nested messages
hb_cache_controlParses HTTP Cache-Control headers and determines cacheability of responses

6. HTTP Client

Outbound HTTP requests to gateways and other nodes.

ModuleDescription
hb_http_clientHTTP client wrapper managing Gun connections with pooling and retries
hb_http_client_supSupervisor for HTTP client connection pools handling lifecycle and restarts
hb_http_multiSends parallel requests to multiple nodes and aggregates results
hb_httpConvenience GET/POST helpers with codec negotiation and response parsing
hb_gateway_clientArweave gateway API client for fetching transactions, data, and blocks
hb_clientHigh-level Arweave client combining gateway operations for common tasks
hb_routerSelects which nodes to contact based on health checks and routing preferences

7. Remote Storage

Storage backends that fetch data over the network.

ModuleDescription
hb_store_gatewayFetches data from Arweave gateway on cache miss, read-only remote storage
hb_store_remote_nodeFetches data from other HyperBEAM nodes enabling distributed storage

8. Protocol

The heart of HyperBEAM. Every request flows through hb_ao:resolve/3.

ModuleDescription
hb_aoCore protocol implementing resolve/3 that routes every request to devices
hb_ao_deviceLoads device modules by name, caches them, dispatches calls to handlers

9. HTTP Server

Inbound HTTP handling.

ModuleDescription
hb_http_serverCowboy handlers routing HTTP requests to hb_ao with codec negotiation

10. WASM

WebAssembly execution environment.

ModuleDescription
hb_beamrWASM runtime interface via WAMR, manages module loading and execution
hb_beamr_ioProvides I/O primitives to WASM modules including stdin/stdout and files

11. Application

OTP application structure and node lifecycle.

ModuleDescription
hb_nameRegisters and looks up Erlang processes by name within the node
hb_persistentStores process state durably to survive restarts with consistency guarantees
hb_supMain supervisor defining the supervision tree and restart strategies
hb_appOTP application behavior with start/stop callbacks and initialization
hbTop-level API for starting/stopping nodes and convenience functions

Supplemental

Volume

Storage partitions and data routing.

ModuleDescription
hb_volumeManages storage partitions, handles mounting/unmounting and data routing

Monitoring

Logging, tracing, debugging, and metrics.

ModuleDescription
hb_formatPretty-prints messages, stack traces, and binaries for debugging output
hb_eventDefines ?event macro for structured logging with levels and context
hb_loggerFormats log events and routes to console/file with rotation support
hb_tracerRecords message flow through devices with trace IDs and timing data
hb_debuggerInteractive step debugger for device execution with state inspection
hb_cache_renderGenerates DOT/GraphViz graphs showing cache contents and relationships
hb_metrics_collectorCollects and exposes Prometheus metrics for request counts and latencies
hb_process_monitorMonitors Erlang process health, detects failures, reports status

Testing

Test utilities and conformance tests.

ModuleDescription
hb_test_utilsCommon test fixtures, assertion helpers, and mock setup utilities
hb_ao_test_vectorsProtocol conformance test vectors ensuring hb_ao compatibility
hb_message_test_vectorsTest vectors for message creation, signing, and ID computation
hb_http_benchmark_testsPerformance benchmarks measuring throughput and latency distributions
hb_examplesUsage examples demonstrating common patterns and best practices

Chapter 6: Devices

Built-in devices implementing AO-Core protocol behaviors.


1. Messages & Composition

The foundational device and composition patterns.

ModuleDescription
dev_messageCore device implementing get, set, keys, remove—the foundation of all devices
dev_stackChains devices into ordered execution pipelines with Fold and Map modes
dev_multipassRuns message through stack multiple times until stable or limit
dev_applyDynamic path execution with base:/request: prefixes
dev_patchMoving data between message paths
dev_dedupPrevents duplicate message processing with configurable detection

2. Codecs

Message encoding, decoding, and cryptographic signing.

ModuleDescription
dev_codec_httpsigHTTP Message Signatures (RFC 9421)
dev_codec_httpsig_convConversions for signature components
dev_codec_httpsig_keyidKey ID management
dev_codec_httpsig_proxyProxy support for signature forwarding
dev_codec_httpsig_siginfoSignature metadata extraction
dev_codec_structuredRFC 9651 Structured Fields with ao-types annotations
dev_codec_jsonJSON encoding/decoding for HTTP APIs
dev_codec_flatPath-based flat map encoding for configuration

3. Infrastructure

Node configuration, routing, and lifecycle management.

ModuleDescription
dev_metaNode configuration, initialization, and request handling
dev_routerMessage routing with load balancing strategies
dev_relaySynchronous and asynchronous message relay between nodes
dev_node_processSingleton process management for node services
dev_hookLifecycle hooks for request/response processing
dev_manifestDefines process configuration—device stack, scheduler, compute limits

4. Process & Scheduling

Stateful computation units and deterministic message ordering.

ModuleDescription
dev_processCore AO process execution coordinator
dev_process_cacheCaches computed process states
dev_process_workerWorker pools for parallel execution
dev_schedulerMessage ordering and slot assignment
dev_scheduler_cacheCaches scheduler assignments
dev_scheduler_formatsFormat version handling
dev_scheduler_registryProcess registration and discovery
dev_scheduler_serverLong-running server process
dev_pushRecursive message delivery between processes
dev_cronTime-based scheduled execution with cron expressions

5. Storage & Naming

Data persistence and name resolution.

ModuleDescription
dev_cacheRead/write data with access control
dev_lookupRetrieve resources by ID with format negotiation
dev_local_nameRegister human-readable names for resources
dev_nameResolve names through configurable resolver chains

6. Runtimes

Code execution environments—WASM, Lua, delegated compute.

ModuleDescription
dev_wasmExecute WebAssembly with Memory-64 support
dev_wasiVirtual filesystem for WASM programs
dev_json_ifaceJSON interface for WASM modules
dev_genesis_wasmInitial WASM module configuration
dev_luaRun Lua scripts in sandboxed VMs
dev_lua_libHyperBEAM API bindings for Lua
dev_cuDelegate to external Compute Units
dev_delegated_computeRemote computation with verification

7. Payment

Pricing and payment in HyperBEAM.

ModuleDescription
dev_p4Core payment ledger and pricing orchestrator
dev_simple_payPer-request pricing with balance management
dev_faffAllow-list based access control

8. Authentication

Identity and signatures.

ModuleDescription
dev_auth_hookAutomatic request signing with node-hosted wallets
dev_codec_http_authHTTP Basic authentication with PBKDF2
dev_codec_cookieCookie management and storage
dev_codec_cookie_authCookie-based HMAC authentication
dev_secretSecret key management device

9. Arweave & Data

Permanent storage and data retrieval.

ModuleDescription
dev_arweaveArweave network interface
dev_arweave_block_cacheCaches Arweave blocks locally
dev_codec_ans104ANS-104 data item codec
dev_codec_ans104_fromDecode ANS-104 to messages
dev_codec_ans104_toEncode messages to ANS-104
dev_queryCache search and discovery
dev_query_arweaveArweave gateway GraphQL
dev_query_graphqlGraphQL query executor
dev_copycatMessage indexing from external sources
dev_copycat_arweaveReplicate from Arweave
dev_copycat_graphqlGraphQL-based discovery
dev_podaGenerates and verifies proofs that data exists on Arweave

Supplemental Devices

Security & TEE

ModuleDescription
dev_volumeVolume device for mounting, unmounting, and listing storage volumes
dev_snpAMD SEV-SNP attestation for TEE
dev_snp_nifNative C interface for SNP
dev_green_zoneDefines security boundaries for sensitive operations requiring TEE

Utilities & Debugging

ModuleDescription
dev_triePrefix tree implementation for efficient key lookup
dev_profileRecords execution timing and memory allocation
dev_hyperbuddyWeb-based interactive debugging UI
dev_cachevizGenerates visual representation of cache contents
dev_whoisLooks up node information by address
dev_monitorTracks system health with alerting
dev_testTest device with configurable responses

Test Vectors

ModuleDescription
dev_codec_cookie_test_vectorsCookie parsing conformance tests
dev_query_test_vectorsQuery device behavior tests
dev_lua_testLua runtime integration tests
dev_lua_test_ledgersLua ledger operation tests

Chapter 7: Building Your Own Devices

Now that you understand the codebase, build your own devices.

TutorialDescription
Custom Devices in ErlangNative Erlang devices with full HyperBEAM integration
Custom Devices in RustHigh-performance NIFs for compute-intensive operations
Custom Devices in C++Native implementations with direct memory access

Resources