# Keep data available with blind peering



<Callout type="info">
  **This guide focuses on the Pear/Bare logic.** It shows the [`blind-peering`](https://www.npmjs.com/package/blind-peering) client on its own—no Electron, no UI. For the same capability wired into a full desktop app with a chat front end, see the worked example [`pear-chat-blind-peering`](https://github.com/holepunchto/pear-docs/tree/preview/examples/how-to/blind-peering/add-blind-peering-to-a-chat-app) and its walkthrough, [Add blind peering to a chat app](/p2p/how-to/blind-peering/add-blind-peering-to-a-chat-app).
</Callout>

A peer-to-peer core is only available while a peer that has it is online. [Blind peering](/p2p/explanation/blind-peering) closes that gap: a **blind peer** is an always-on server that replicates and seeds your [Hypercore](/p2p/reference/building-blocks/hypercore) or [Autobase](/p2p/reference/building-blocks/autobase) **without holding the read capability**—it stores and forwards encrypted blocks it cannot decrypt. Your data stays reachable even when none of its writers are connected.

This is purely Pear-end logic: it lives in a [Bare](/bare/reference/bare/modules) worker (or any Bare/Node process) and never touches a UI.

<Callout type="info">
  **Pear-end logic—start from a boilerplate.** The code in this guide lives in the Bare [worker](/pear/explanation/workers): peer-to-peer logic, no UI. The same worker runs unchanged on desktop, terminal, and mobile—only the shell differs (see [Runtime and languages](/pear/explanation/runtime-and-languages)). Start from a boilerplate in [Start from a template](/p2p/getting-started/from-a-template)—desktop ([`hello-pear-electron`](/p2p/getting-started/from-a-template/start-from-hello-pear-electron)) or terminal ([`hello-pear-bare`](/p2p/getting-started/from-a-template/start-from-hello-pear-bare))—and add this capability on top.
</Callout>

## Two roles [#two-roles]

| Role           | What it runs                                                                                                                                                                                                                                                                                                                                      | Holds read key? |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------- |
| **Blind peer** | An always-on server with its own key pair. Run it with [`pear blind-peer start`](/pear/reference/pear/cli#pear-blind-peer) (since Pear 3.4.0) or the standalone [`blind-peer-cli`](https://github.com/holepunchto/blind-peer-cli) package—both wrap the [`blind-peer`](/p2p/reference/helpers/blind-peer) library. Seeds whatever it is asked to. | No              |
| **Client**     | Your app, using the `blind-peering` module to ask one or more blind peers (by public key) to keep specific cores available.                                                                                                                                                                                                                       | Yes             |

You point the client at the **public keys** of the blind peers you want to mirror to. Those can be blind peers you run yourself, or shared ones.

## Add the dependency [#add-the-dependency]

```sh skip="install-instruction"
npm install blind-peering
```

## Wire the client [#wire-the-client]

Create the `BlindPeering` client against your swarm's [HyperDHT](/p2p/reference/building-blocks/hyperdht) instance ([`swarm.dht`](/p2p/reference/building-blocks/hyperswarm#swarmdht)) and a [Corestore](/p2p/reference/helpers/corestore) namespace, passing the blind peers' public keys as `keys`. Then register the cores or Autobases you want kept available:

```js skip="snippet-illustration"
import Hyperswarm from 'hyperswarm'
import Corestore from 'corestore'
import BlindPeering from 'blind-peering'

const swarm = new Hyperswarm()
const store = new Corestore('./store')
swarm.on('connection', (conn) => store.replicate(conn))

// Public keys of the blind peers to mirror to (z32 or hex).
const blindPeerKeys = [/* 'a1b2c3…' */]

const blinds = new BlindPeering(swarm.dht, store.namespace('blind-peering'), {
  keys: blindPeerKeys
})

// Ask the blind peers to keep a single Hypercore available…
await blinds.addCore(core)

// …or a whole Autobase (all of its writer and view cores).
await blinds.addAutobase(base)
```

`addCore` / `addAutobase` connect to the closest configured blind peers and request that they replicate and seed the given cores. The blind peer downloads the encrypted blocks and serves them to other peers on demand—without ever being able to read them.

## Tear it down [#tear-it-down]

Close the client before the swarm and store so its connections release cleanly:

```js skip="snippet-illustration"
await blinds.close()
await swarm.destroy()
await store.close()
```

## Run your own blind peer [#run-your-own-blind-peer]

To control availability yourself rather than relying on shared blind peers, run a server on an always-on machine—either [`pear blind-peer start`](/pear/reference/pear/cli#pear-blind-peer) (since Pear 3.4.0, no separate install) or the standalone [`blind-peer-cli`](https://github.com/holepunchto/blind-peer-cli) package (`npm i -g blind-peer-cli`, then `blind-peer`). Either way it prints a public key—pass that key in the client's `keys` array. See [Blind peering](/p2p/explanation/blind-peering) for the full setup, including a systemd unit.

For the single-drive case—no custom client code, just keep one seed session's drive available—[`pear seed <link> --blind-peer <key>`](/pear/reference/pear/cli#pear-seed) does the client side of this too, in place of the "Wire the client" section above.

## See also [#see-also]

* [blind-peering reference](/p2p/reference/helpers/blind-peering)—every client option and method, including priority, announce and push notifications.
* [blind-peer reference](/p2p/reference/helpers/blind-peer)—the server library, for embedding a blind peer or reading its events and limits.
* [Blind peering](/p2p/explanation/blind-peering)—the threat model: why a blind peer never needs to be trusted with your data.
* [Add blind peering to a chat app](/p2p/how-to/blind-peering/add-blind-peering-to-a-chat-app)—the same client wired into a full desktop app with a UI.
* [Work with many Hypercores using Corestore](/p2p/how-to/store-and-replicate/work-with-many-hypercores-using-corestore)—the store the client namespaces into.
* [Autobase reference](/p2p/reference/building-blocks/autobase)—the multi-writer log `addAutobase` keeps available.
