You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

peer-info

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.4.0 to 0.5.0

karma.conf.js

34

package.json
{
"name": "peer-info",
"version": "0.4.0",
"version": "0.5.0",
"description": "IPFS Peer abstraction JavaScript implementation",
"main": "src/index.js",
"scripts": {
"test:node": "node tests/*-test.js",
"lint": "standard",
"test": "npm run test:node",
"test:browser": "./node_modules/.bin/zuul --browser-version $BROWSER_VERSION --browser-name $BROWSER_NAME -- tests/peer-test.js",
"test:browser:q": "BROWSER_VERSION=46 BROWSER_NAME=chrome npm run test:browser",
"build": "./node_modules/.bin/browserify -s PeerInfo -e ./src/index.js | tee dist/peer-info.js | ./node_modules/.bin/uglifyjs -m > dist/peer-info.min.js"
"test": "npm run test:node && npm run test:browser",
"test:node": "mocha tests/*-test.js",
"test:browser": "karma start karma.conf.js",
"coverage": "istanbul cover --print both -- _mocha tests/*-test.js"
},

@@ -22,3 +21,3 @@ "repository": {

"engines": {
"node": "^4.2.0"
"node": "^4.3.0"
},

@@ -36,10 +35,21 @@ "author": "David Dias <daviddias@ipfs.io>",

"devDependencies": {
"buffer-loader": "0.0.1",
"chai": "^3.5.0",
"istanbul": "^0.4.2",
"json-loader": "^0.5.4",
"karma": "^0.13.19",
"karma-chrome-launcher": "^0.2.2",
"karma-cli": "^0.1.2",
"karma-firefox-launcher": "^0.1.7",
"karma-mocha": "^0.2.1",
"karma-spec-reporter": "0.0.24",
"karma-webpack": "^1.7.0",
"mocha": "^2.4.5",
"multiaddr": "^1.1.1",
"peer-id": "^0.4.0",
"pre-commit": "^1.1.1",
"standard": "^4.5.2",
"tape": "^4.2.2",
"zuul": "^3.7.2"
"peer-id": "^0.5.1",
"pre-commit": "^1.1.2",
"standard": "^6.0.7",
"webpack": "^1.12.14"
},
"dependencies": {}
}
peer-info JavaScript implementation
================================
===================================
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) [[![](https://img.shields.io/badge/freejs-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) ![Build Status](https://travis-ci.org/diasdavid/js-peer-info.svg?style=flat-square)](https://travis-ci.org/diasdavid/js-peer-info) ![](https://img.shields.io/badge/coverage-%3F-yellow.svg?style=flat-square) [![Dependency Status](https://david-dm.org/diasdavid/js-peer-info.svg?style=flat-square)](https://david-dm.org/diasdavid/js-peer-info) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) [[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
![Build Status](https://travis-ci.org/diasdavid/js-peer-info.svg?style=flat-square)](https://travis-ci.org/diasdavid/js-peer-info) ![](https://img.shields.io/badge/coverage-%3F-yellow.svg?style=flat-square)
[![Dependency Status](https://david-dm.org/diasdavid/js-peer-info.svg?style=flat-square)](https://david-dm.org/diasdavid/js-peer-info) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
> IPFS Peer abstraction JavaScript implementation
> Peer Info contains information about a peer Id and its multiaddrs. This module is used by IPFS and libp2p.
# Description
# Usage

@@ -15,13 +15,9 @@

```bash
$ npm install --save peer-info
> npm install --save peer-info
```
```javascript
var PeerInfo = require('peer-info')
const PeerInfo = require('peer-info')
```
### In the Browser through browserify
Same as in Node.js, you just have to [browserify](https://github.com/substack/node-browserify) the code before serving it. See the browserify repo for how to do that.
### In the Browser through `<script>` tag

@@ -32,8 +28,3 @@

```JavaScript
var PeerInfo = window.PeerInfo
const PeerInfo = window.PeerInfo
```
#### Gotchas
You will need to use Node.js `Buffer` API compatible, if you are running inside the browser, you can access it by `PeerInfo.Buffer` or you can install Feross's [Buffer](https://github.com/feross/buffer).

@@ -5,17 +5,61 @@ /*

const Id = require('peer-id')
exports = module.exports = Peer
function Peer (id, multiaddrs) {
var self = this
function Peer (peerId) {
if (!(this instanceof Peer)) {
return new Peer(peerId)
}
if (!(self instanceof Peer)) {
throw new Error('Peer must be called with new')
if (!peerId) {
this.id = Id.create()
} else {
this.id = peerId
}
if (!Array.isArray(multiaddrs)) {
multiaddrs = [multiaddrs]
this.multiaddrs = []
const observedMultiaddrs = []
this.multiaddr = {}
this.multiaddr.add = (multiaddr) => {
var exists = false
this.multiaddrs.some((m, i) => {
if (m.toString() === multiaddr.toString()) {
exists = true
return true
}
})
if (!exists) {
this.multiaddrs.push(multiaddr)
}
}
self.id = id
self.multiaddrs = multiaddrs
// to prevent multiaddr explosion
this.multiaddr.addSafe = (multiaddr) => {
var check = false
observedMultiaddrs.some((m, i) => {
if (m.toString() === multiaddr.toString()) {
this.multiaddr.add(multiaddr)
observedMultiaddrs.splice(i, 1)
check = true
}
})
if (!check) {
observedMultiaddrs.push(multiaddr)
}
}
this.multiaddr.rm = (multiaddr) => {
this.multiaddrs.some((m, i) => {
if (m.toString() === multiaddr.toString()) {
this.multiaddrs.splice(i, 1)
return true
}
})
}
// TODO: add features to fetch multiaddr using filters
// look at https://github.com/whyrusleeping/js-mafmt/blob/master/src/index.js
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc