Pp2pbuilders
learn › Holepunch walkthroughs

8 min read · also at #/learn/hp-hypercore

Hypercore: the signed append-only log

Hypercore is the primitive
everything else builds on: an append-only list of binary blocks, signed by a
single writer, replicable by anyone.

const Hypercore = require('hypercore')

const core = new Hypercore('./storage')       // creates or reopens
await core.ready()

console.log(core.key.toString('hex'))         // public identity of this log
console.log(core.length)                      // blocks so far

await core.append(Buffer.from('hello'))       // only the key holder can do this
const b = await core.get(0)                   // anyone with a replica can read

The things to internalize:

extend it. Multi-writer is a different layer
(Autobase).

from any connected peer and verifies it against the author's signature
before handing it to you. Mirrors need zero trust.

can index a 10k-entry log while fetching a fraction of it.

Wiring two peers

Replication runs over any duplex stream; in practice you get streams from
Hyperswarm:

swarm.on('connection', (socket) => core.replicate(socket))
core.on('append', () => console.log('log grew to', core.length))

How p2pbuilders uses it

Each user = one Hypercore. Every action (post, comment, vote, profile…) is one
encoded op appended to their own core. Nobody ever writes to anyone else's
log — the "shared" board is a fold over many single-writer logs
(Everything is a signed log).

Start here before Hyperbee/Hyperdrive: both are *just interpretations of a
Hypercore*, and the whole stack makes sense once that clicks.

« Bare: the small JS runtime Hyperbee: a database on a log »