Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

libp2p-pubsub

Package Overview
Dependencies
Maintainers
3
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libp2p-pubsub - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

dist/src/errors.d.ts

148

package.json
{
"name": "libp2p-pubsub",
"version": "0.6.0",
"description": "Pubsub base protocol for libp2p pubsub routers",
"leadMaintainer": "Vasco Santos <santos.vasco10@gmail.com>",
"main": "src/index.js",
"scripts": {
"lint": "aegir lint",
"test": "aegir test",
"test:node": "aegir test -t node",
"test:browser": "aegir test -t browser",
"build": "aegir build",
"docs": "aegir-docs",
"release": "aegir release --target node --docs",
"release-minor": "aegir release --type minor --docs",
"release-major": "aegir release --type major --docs",
"coverage": "aegir coverage",
"coverage-publish": "aegir coverage --provider coveralls"
},
"version": "0.7.0",
"description": "libp2p pubsub base class",
"type": "module",
"files": [

@@ -24,55 +10,99 @@ "src",

],
"pre-push": [
"lint"
],
"types": "dist/src/index.d.ts",
"typesVersions": {
"*": {
"*": [
"dist/src/*",
"dist/src/*/index"
]
}
},
"eslintConfig": {
"extends": "ipfs",
"ignorePatterns": [
"src/message/*.d.ts",
"src/message/*.js"
]
},
"scripts": {
"lint": "aegir lint",
"dep-check": "aegir dep-check dist/src/**/*.js",
"build": "npm run build:types && npm run build:copy-proto-files",
"build:types": "tsc",
"build:proto": "npm run build:proto:rpc && npm run build:proto:topic-descriptor",
"build:proto:rpc": "pbjs -t static-module -w es6 -r libp2p-pubsub-rpc --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/message/rpc.js ./src/message/rpc.proto",
"build:proto:topic-descriptor": "pbjs -t static-module -w es6 -r libp2p-pubsub-topic-descriptor --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/message/topic-descriptor.js ./src/message/topic-descriptor.proto",
"build:proto-types": "npm run build:proto-types:rpc && npm run build:proto-types:topic-descriptor",
"build:proto-types:rpc": "pbts -o src/message/rpc.d.ts src/message/rpc.js",
"build:proto-types:topic-descriptor": "pbts -o src/message/topic-descriptor.d.ts src/message/topic-descriptor.js",
"build:copy-proto-files": "cp src/message/*.js dist/src/message && cp src/message/*.d.ts dist/src/message",
"pretest": "npm run build",
"test": "aegir test -f ./dist/test/*.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/libp2p/js-libp2p-pubsub.git"
"url": "git+https://github.com/libp2p/js-libp2p-interfaces.git"
},
"keywords": [
"IPFS",
"libp2p",
"pubsub",
"gossip",
"flood",
"flooding"
"interface"
],
"license": "MIT",
"author": "",
"license": "(Apache-2.0 OR MIT)",
"bugs": {
"url": "https://github.com/libp2p/js-libp2p-pubsub/issues"
"url": "https://github.com/libp2p/js-libp2p-interfaces/issues"
},
"homepage": "https://github.com/libp2p/js-libp2p-pubsub#readme",
"homepage": "https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/libp2p-pubsub#readme",
"dependencies": {
"debug": "^4.3.2",
"err-code": "^3.0.1",
"iso-random-stream": "^2.0.0",
"it-length-prefixed": "^5.0.3",
"it-pipe": "^1.1.0",
"libp2p-interfaces": "^2.0.0",
"libp2p-topology": "^0.1.0",
"multiaddr": "^10.0.1",
"multiformats": "^9.4.10",
"p-queue": "^7.1.0",
"peer-id": "^0.15.3",
"uint8arrays": "^3.0.0"
},
"devDependencies": {
"aegir": "^25.0.0",
"benchmark": "^2.1.4",
"chai": "^4.2.0",
"chai-spies": "^1.0.0",
"dirty-chai": "^2.0.1",
"it-pair": "^1.0.0",
"multiaddr": "^8.0.0",
"sinon": "^9.0.0"
"@types/bl": "^5.0.2",
"@types/debug": "^4.1.7",
"aegir": "^36.0.0",
"protobufjs": "^6.10.2",
"util": "^0.12.4"
},
"dependencies": {
"debug": "^4.1.1",
"err-code": "^2.0.0",
"it-length-prefixed": "^3.0.0",
"it-pipe": "^1.0.1",
"it-pushable": "^1.3.2",
"libp2p-crypto": "^0.18.0",
"libp2p-interfaces": "^0.4.0",
"multibase": "^3.0.0",
"peer-id": "^0.14.0",
"protons": "^2.0.0",
"uint8arrays": "^1.1.0"
"exports": {
".": {
"import": "./dist/src/index.js",
"types": "./dist/src/index.d.ts"
},
"./errors": {
"import": "./dist/src/errors.js",
"types": "./dist/src/errors.d.ts"
},
"./peer-streams": {
"import": "./dist/src/peer-streams.js",
"types": "./dist/src/peer-streams.d.ts"
},
"./signature-policy": {
"import": "./dist/src/signature-policy.js",
"types": "./dist/src/signature-policy.d.ts"
},
"./utils": {
"import": "./dist/src/utils.js",
"types": "./dist/src/utils.d.ts"
},
"./message/rpc": {
"import": "./dist/src/message/rpc.js",
"types": "./dist/src/message/rpc.d.ts"
},
"./message/topic-descriptor": {
"import": "./dist/src/message/topic-descriptor.js",
"types": "./dist/src/message/topic-descriptor.d.ts"
}
},
"contributors": [
"Vasco Santos <vasco.santos@moxy.studio>",
"Jacob Heun <jacobheun@gmail.com>",
"Mikerah <mikerahqc@protonmail.com>",
"Cayman <caymannava@gmail.com>",
"Topper Bowers <topper@toppingdesign.com>",
"Alex Potsides <alex@achingbrain.net>",
"Hugo Dias <hugomrdias@gmail.com>",
"Alan Shaw <alan.shaw@protocol.ai>"
]
"gitHead": "045f7d77535ee61562af0b0e2a7dfd168b214430"
}

@@ -1,221 +0,35 @@

js-libp2p-pubsub
==================
# libp2p-pubsub <!-- omit in toc -->
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://libp2p.io/)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
[![Discourse posts](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg)](https://discuss.libp2p.io)
[![Coverage Status](https://coveralls.io/repos/github/libp2p/js-libp2p-pubsub/badge.svg?branch=master)](https://coveralls.io/github/libp2p/js-libp2p-pubsub?branch=master)
[![Travis CI](https://travis-ci.org/libp2p/js-libp2p-pubsub.svg?branch=master)](https://travis-ci.org/libp2p/js-libp2p-pubsub)
[![Circle CI](https://circleci.com/gh/libp2p/js-libp2p-pubsub.svg?style=svg)](https://circleci.com/gh/libp2p/js-libp2p-pubsub)
[![Dependency Status](https://david-dm.org/libp2p/js-libp2p-pubsub.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-pubsub) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
[![](https://img.shields.io/badge/pm-waffle-yellow.svg?style=flat-square)](https://waffle.io/libp2p/js-libp2p-pubsub)
> Contains an implementation of the [Pubsub](https://github.com/libp2p/js-libp2p-interfaces/blob/master/packages/libp2p-interfaces/src/pubsub/index.ts) interface
> libp2p-pubsub is the base protocol for libp2p pubsub implementations. This module is responsible for registering the protocol with libp2p, as well as managing the logic regarding pubsub connections with other peers.
## Table of contents <!-- omit in toc -->
## Lead Maintainer
[Vasco Santos](https://github.com/vasco-santos).
## Table of Contents
- [Install](#install)
- [Usage](#usage)
- [API](#api)
- [Contribute](#contribute)
- [License](#license)
## Install
## Usage
```sh
> npm install libp2p-pubsub
```console
npm i libp2p-pubsub
```
## Usage
```javascript
import { PubsubBaseProtocol } from 'libp2p-pubsub'
`libp2p-pubsub` abstracts the implementation protocol registration within `libp2p` and takes care of all the protocol connections. This way, a pubsub implementation can focus on its routing algorithm, instead of also needing to create the setup for it.
A pubsub implementation **MUST** override the `_processMessages`, `publish`, `subscribe`, `unsubscribe` and `getTopics` functions.
Other functions, such as `_onPeerConnected`, `_onPeerDisconnected`, `_addPeer`, `_removePeer`, `start` and `stop` may be overwritten if the pubsub implementation needs to customize their logic. Implementations overriding `start` and `stop` **MUST** call `super`. The `start` function is responsible for registering the pubsub protocol with libp2p, while the `stop` function is responsible for unregistering the pubsub protocol and closing pubsub connections.
All the remaining functions **MUST NOT** be overwritten.
The following example aims to show how to create your pubsub implementation extending this base protocol. The pubsub implementation will handle the subscriptions logic.
TODO: add explanation for registrar!
```JavaScript
const Pubsub = require('libp2p-pubsub')
class PubsubImplementation extends Pubsub {
constructor({ peerId, registrar, ...options })
super({
debugName: 'libp2p:pubsub',
multicodecs: '/pubsub-implementation/1.0.0',
peerId: peerId,
registrar: registrar,
signMessages: options.signMessages,
strictSigning: options.strictSigning
})
}
_processMessages(idB58Str, conn, peer) {
// Required to be implemented by the subclass
// Process each message accordingly
}
publish() {
// Required to be implemented by the subclass
}
subscribe() {
// Required to be implemented by the subclass
}
unsubscribe() {
// Required to be implemented by the subclass
}
getTopics() {
// Required to be implemented by the subclass
}
class MyPubsubImplementation extends PubsubBaseProtocol {
// .. extra methods here
}
```
## API
The following specified API should be the base API for a pubsub implementation on top of `libp2p`.
### Start
Starts the pubsub subsystem. The protocol will be registered to `libp2p`, which will result in pubsub being notified when peers who support the protocol connect/disconnect to `libp2p`.
#### `pubsub.start()`
##### Returns
| Type | Description |
|------|-------------|
| `Promise<void>` | resolves once pubsub starts |
### Stop
Stops the pubsub subsystem. The protocol will be unregistered from `libp2p`, which will remove all listeners for the protocol and the established connections will be closed.
#### `pubsub.stop()`
##### Returns
| Type | Description |
|------|-------------|
| `Promise<void>` | resolves once pubsub stops |
### Publish
Publish data messages to pubsub topics.
#### `pubsub.publish(topics, messages)`
##### Parameters
| Name | Type | Description |
|------|------|-------------|
| topics | `Array<string>|string` | set of pubsub topics |
| messages | `Array<any>|any` | set of messages to publish |
##### Returns
| Type | Description |
|------|-------------|
| `Promise<void>` | resolves once messages are published to the network |
### Subscribe
Subscribe to the given topic(s).
#### `pubsub.subscribe(topics)`
##### Parameters
| Name | Type | Description |
|------|------|-------------|
| topics | `Array<string>|string` | set of pubsub topics |
### Unsubscribe
Unsubscribe from the given topic(s).
#### `pubsub.unsubscribe(topics)`
##### Parameters
| Name | Type | Description |
|------|------|-------------|
| topics | `Array<string>|string` | set of pubsub topics |
### Get Topics
Get the list of topics which the peer is subscribed to.
#### `pubsub.getTopics()`
##### Returns
| Type | Description |
|------|-------------|
| `Array<String>` | Array of subscribed topics |
### Get Peers Subscribed to a topic
Get a list of the [PeerId](https://github.com/libp2p/js-peer-id) strings that are subscribed to one topic.
#### `pubsub.getSubscribers(topic)`
##### Parameters
| Name | Type | Description |
|------|------|-------------|
| topic | `string` | pubsub topic |
##### Returns
| Type | Description |
|------|-------------|
| `Array<string>` | Array of base-58 PeerId's |
### Validate
Validates the signature of a message.
#### `pubsub.validate(message)`
##### Parameters
| Name | Type | Description |
|------|------|-------------|
| message | `Message` | a pubsub message |
#### Returns
| Type | Description |
|------|-------------|
| `Promise<Boolean>` | resolves to true if the message is valid |
## Implementations using this base protocol
You can use the following implementations as examples for building your own pubsub implementation.
- [libp2p/js-libp2p-floodsub](https://github.com/libp2p/js-libp2p-floodsub)
- [ChainSafe/js-libp2p-gossipsub](https://github.com/ChainSafe/js-libp2p-gossipsub)
## Contribute
Feel free to join in. All welcome. Open an [issue](https://github.com/libp2p/js-libp2p-pubsub/issues)!
The libp2p implementation in JavaScript is a work in progress. As such, there are a few things you can do right now to help out:
This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).
- Go through the modules and **check out existing issues**. This would be especially useful for modules in active development. Some knowledge of IPFS/libp2p may be required, as well as the infrastructure behind it - for instance, you may need to read up on p2p and more complex operations like muxing to be able to help technically.
- **Perform code reviews**. More eyes will help a) speed the project along b) ensure quality and c) reduce possible future bugs.
- **Add tests**. There can never be enough tests.
## License
Copyright (c) Protocol Labs, Inc. under the **MIT License**. See [LICENSE file](./LICENSE) for details.
[Apache-2.0](LICENSE-APACHE) or [MIT](LICENSE-MIT) © Protocol Labs

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc