open-index/open-npm huggingface dataset:
npm package: @peerbit/proxy
Description: Peerbit proxy host/server
Author: dao.xyz
Latest version: 5.4.14

# Peerbit Proxy
## WIP 🚧
A client you can connect to another client remotely, example use-cases
- Running a proxy client in an Iframe and talk to the parent window that runs a real client
- Running a client in a frontend that talks with a real client on a server.
npm package: @peerbit/pubsub
Description: Direct streaming for libp2p
Author: dao.xyz
Latest version: 5.1.6

# PubSub Transport

This package contains two related building blocks that both run on top of
[`@peerbit/stream`](../stream/README.md):

## `TopicControlPlane` (`/peerbit/topic-control-plane/1.0.0`)

A DirectStream-based topic membership and forwarding layer.

This is useful for small to medium overlays and targeted messaging (explicit receiver
lists) where you can tolerate subscription gossip and do not need the strict fanout
economics of a tree.

## `FanoutTree` (`/peerbit/fanout-tree/0.5.0`)

A scalable fanout tree for 1 writer to many subscribers (and tree-local unicast using
route tokens).

This is the intended mechanism for very large audiences where you must cap per-node
upload and avoid gossip-style explosion.

`FanoutChannel` is a small convenience wrapper around `FanoutTree` for channel-scoped
usage.

## `TopicRootControlPlane`

A small helper to resolve a topic root from:

- An explicit mapping (topic -> root)
- A set of default candidates (deterministic choice per topic)
- Optional trackers (if configured by the application)
npm package: @peerbit/rpc
Description: RPC calls for peers
Author: dao.xyz
Latest version: 6.0.21

# RPC

This module contains a communication protocol for  generic request-and-response communication. This module can be used as a component in other modules. [Documents](./../../data/document), [DString](./../../data/string) for examples



## How it works

```typescript
@variant("hello")
class Hello {
    
    // add payload properties here
    constructor() {
       
    }
}

@variant("world")
class World {
    
    // add payload properties here
    constructor() {
       
    }
}

@variant("rpc-test")
class RPCTest extends Program {

    @field({ type: RPC })
    rpc: RPC<Hello, World>;

    async setup(): Promise<void> {
        await this.rpc.setup({
            responseType: Hello,
            queryType: World,
            context: this,
            responseHandler: (resp, from) => {
                return resp;
            },
        });
    }
}

// later (assume that some other peers also opens the RPCTest program)
const peer = await Peerbit.create ()
const rpcTest = peer.open(new RPCTest());

await rpcTest.rpc.request( new Hello(), (resp) => { console.log(resp)  })
```

### Visualized 

<p align="center">
    <img width="400" src="./documentation/rpc1.png"  alt="p1">
</p>



<p align="center">
    <img width="400" src="./documentation/rpc2.png"  alt="p1">
</p>

See [Document store](./../data/document) and [Clock Service](./../clock-service) as implementation examples.
npm package: @peerbit/stream
Description: A building block for direct streaming protocols
Author: dao.xyz
Latest version: 5.0.9

# Direct stream
Data streaming protocol for delivering messages efficiently to peers with redundancy and failure recovery modes. 

## Features
- Packet prioritization. Data packages can be sent with different priority. That allows some traffic to pass through the traffic faster than other. This is useful in case of congestion
- Mode'd delivery. Packages can be sent with different delivery mode 'Acknowledge' (wait for acknowledgement from all known subscribers), 'Seek' (find new subscribers for a topic), 'Silent' (just deliver).
- Redundancy in data delivery. Data packages can be sent with different redundancy. This means that you can choose to send some packages only in one path (the fastest) or send a package in the 'N' fastest paths (this gives you a redundancy degree of 'N'). This feature is useful when you want to adapt delivery for unstable networks or when you want to make sure that some messages are delivered with high probability (without waiting for Acknowledgemts and retry)


Protocol specification (TODO)

Currently the protocol itself is not specificed more than as in this implementation with messages types found [here](https://github.com/dao-xyz/peerbit/blob/master/packages/transport/stream-interface/src/messages.ts) and [here](https://github.com/dao-xyz/peerbit/blob/aa577a5e5b2b4920662de5e0efb92fb97a5dc63c/packages/transport/stream/src/index.ts#L1057).
npm package: @peerbit/trusted-network
Description: Access controller that operates on a DB
Author: dao.xyz
Latest version: 6.0.24

# Trusted network
## 🚧 Experimental state 🚧

A store that lets you build trusted networks of identities.

The store is defined by the "root trust" which has the responsibility in the beginning to trust additional identities. Later, these identities can add more identities to the network. 
Trusted identities can also be revoked.

Distributing content among untrusted peers will be unreliable, and not resilient to malicious parties that start to participate in the replication process with large amount (>> min replicas) of nodes followed by shutting them down simultaneously (no way for the original peers recover all lost data). To mitigate this, you can launch your program in a "Network", which is basically a list of nodes that trust each other. Symbolically you could thing of this as a VPC.

To do this, you only have to implement the "Network" interface: 
```typescript
import { Peerbit, Network } from 'peerbit'
import { Log } from '@peerbit/log'
import { Program } from '@peerbit/program' 
import { TrustedNetwork } from '@peerbit/trusted-network' 
import { field, variant } from '@dao-xyz/borst-ts' 

@variant("string_store") 
@network({property: 'network'})
class StringStore extends Program
{
    @field({type: Store})
    log: Log<Uint8Array>

    @field({type: TrustedNetwork}) 
    network: TrustedNetwork // this is a database storing all peers. Peers that are trusted can add new peers

    constructor(properties:{ log: Store<any>, network: TrustedNetwork }) {
       
		this.log = properties.store
		this.network = properties.network;
        
    }

    async setup() 
    {
        await store.setup({ encoding: ... , canPerform: ..., index: {... canRead ...}})
        await trustedNetwork.setup()
    }
}


// Later 
const peer1 = await Peerbit.create(LIBP2P_CLIENT, {... options ...})
const peer2 = await Peerbit.create(LIBP2P_CLIENT_2, {... options ...})

const programPeer1 = await peer1.open(new StringStore({log: new Log(), network: new TrustedNetwork()}), {... options ...})

// add trust to another peer
await program.network.add(peer2.identity.publicKey) 


// peer2 also has to "join" the network, in practice this means that peer2 adds a record telling that its Peer ID trusts its libp2p Id
const programPeer2 = await peer2.open(programPeer1.address, {... options ...})
await peer2.join(programPeer2) // This might fail with "AccessError" if you do this too quickly after "open", because it has not yet received the full trust graph from peer1 yet
```

See [this test(s)](./src/__tests__/network.test.ts) for working examples
npm package: @peerboard/core
Description: peerboard.com frontend components
Author: Vladislav Lebedev
Latest version: 0.0.25

### Peerboard core

See [detailed tutorial in our community](https://community.peerboard.com/post/1162435747)

```bash
yarn add @peerboard/core
```
or
```bash
npm install @peerboard/core 
```
npm package: @peerboard/node-api
Description: Deprecated use https://community.peerboard.com/post/183197627
Author: Vladislav Lebedev
Latest version: 0.0.19
Deprecated: use our guide instead https://community.peerboard.com/post/183197627

## Deprecated

[You can just generate the token for your own](https://community.peerboard.com/post/183197627?category=2097967386)

## Usage

See [more detailed guides in our community](https://community.peerboard.com/category/2097967386) 

```bash
yarn add @peerboard/node-api
```
or
```bash
npm install @peerboard/node-api
```

```js
const { generateBearerToken } = require('@peerboard/node-api');

// Don't forget to protect your endpoint with auth
router.post('/generate-bearer-token', auth.required, async (req, res, next) => {
  const user = await User.findById(req.payload.id);
  const redirect = req.redirect || "/";

  const payload = {
    user_id: user.id, // Required unique user id - should not change(email is bad identifier)
    email: user.email, // Email is required
    name: user.username, // If empty user will be asked to enter her name
    last_name: user.last_name, // You can also specify last name and enable require last name in community settings
    avatar_url: user.image, // Optional url to photo
    bio: user.bio, // Optional
    tagline: user.tagline, // Optional
    // It is possible to use custom profile url into your app.
    // We will substitute all urls to user profile with this.
    // Optional
    profile_url: '<ABSOLUTE_URL_TO_USER_PROFILE>',
    role: "admin"|"member"|"banned", // Is optional by default member on creation
  };
  const token =	generateBearerToken(
    '<YOUR_AUTH_TOKEN>',
    payload,
    redirect,
  );
  return res.json({
    token,
  });
});
```
npm package: @peerboard/peerboard-react
Description: peerboard.io react components
Author: Vladislav Lebedev
Latest version: 0.0.7
Deprecated: wrong naming

### Usage

```bash
yarn add @peerboard/peerboard-react 
```
or
```bash
npm install @peerboard/peerboard-react 
``` 

```jsx
import { PeerboardForum } from '@peerboard/peerboard-react';

// ...

<PeerboardForum
  style={{
    // Style the wrapper
  }}
  boardId={432432432} // Your Board id from settings 
  prefix='community' // Relative path at which the forum is rendered yourcustomdomain.com/community
  jwtToken={'...'} // Your integration bearer token from backend
  hideMenu={false} // Whether to hide standard menu or not
  onLoadFailed={() => {
    // Show error
  }}
  onLoadSuccess={() => {
    // Show forum. Note that in order to initialize forum should be rendered with 'display: none' for example. 
  }}
  onTitleChanged={title => window.document.title = "Forum: " + title} // Change your title accordingly
  onPathChanged={path => {
    // Browser counts iframe state changes.
    history.replaceState(null, '', path) // Update address bar. Provided prefix included.
  }}
/>
```

## Real world mvp example of page component
```jsx
class Forum extends React.Component {
  constructor(props) {
    super(props);
    this.jwtToken = null;
    this.prefix = 'community'; // assuming that this page rendered at yourcustomdomain.com/community
    this.state = {
      authReady: false,
      forumReady: false,
      error: null,
    };
  }

  componentWillMount() {
    this.props.onLoad();
  }

  componentWillUnmount() {
    this.props.onUnload();
  }

  componentDidMount() {
    const redirect = (document.location.pathname || "/").replace(`/${this.prefix}`, '');
    http.post('/generate-bearer-token', {
      redirect, // Pass requested sub path here
    }).then((result) => {
      this.jwtToken = result.token;
      this.setState({
        authReady: true, // Now we can render the forum component
      });
    });
  }

  renderForum() {
    return <div>
      {!(this.state.authReady && this.state.forumReady) && 'Loading forum... You can place your spinner here.'}
      {this.state.authReady && (
        <PeerboardForum
          style={{
            // Render component to start initialization but hide it until it finishes loading.
            display: this.state.forumReady ? 'block' : 'none'
          }}
          boardId={1024681946} // Replace with your Board id
          prefix={this.prefix}
          jwtToken={this.jwtToken}
          hideMenu={false}
          onLoadFailed={() => {
            this.setState({
              error: "Failed to load forum",
            });
          }}
          onLoadSuccess={() => {
            this.setState({
              forumReady: true,
            });
          }}
          onTitleChanged={title => window.document.title = "Forum: " + title}
          onPathChanged={location => window.history.replaceState(null, '', location)}
        />
      )}
    </div>
  }
  render() {
    return (
      <div className="container">
        {this.state.error ? (this.state.error) : (this.renderForum())}
      </div>
    );
  }
}
```