Home > Engineering > Infrastructure > P2P building blocks > secret-stream

secret-stream

secret-stream is the end-to-end encryption layer: a Noise-encrypted Duplex that wraps any raw duplex stream (a UDX stream, or a TCP socket). The key thing for an integrator: in the Holepunch stack you rarely instantiate it yourselfHyperDHT embeds it, so Hyperswarm/HyperDHT connections are already secret-streams. You reach for it standalone only to encrypt a transport you brought yourself (e.g. TCP). Backed by Noise + libsodium’s secretstream.


Core API

See the README for exhaustive detail.


Gotchas

You usually don’t new it yourself. HyperDHT/Hyperswarm connection sockets are already secret-streams — don’t wrap them again. Standalone use is for a BYO transport.

Default pattern is XX — mutual authentication with no prior knowledge of the remote key; identity is exchanged during the handshake. (HyperDHT’s connect-by-key path uses an IK-style handshake instead, because there you already know the remote public key.)

remotePublicKey is not trustworthy until 'connect' fires — don’t act on it before then.

handshakeHash is the channel-binding primitive — identical on both sides, so it is how you verify “we’re both on the same session.”

Identity keys are Ed25519 — the same key type that is the connectable address at the DHT layer.


Version

@hyperswarm/secret-stream@6 — a single latest dist-tag, stable. Check the npm registry before pinning.

Sources