Socket
Socket
Sign inDemoInstall

peer-id

Package Overview
Dependencies
Maintainers
1
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

peer-id - npm Package Compare versions

Comparing version 0.6.3 to 0.6.4

2

package.json
{
"name": "peer-id",
"version": "0.6.3",
"version": "0.6.4",
"description": "IPFS Peer Id implementation in Node.js",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -1,3 +0,2 @@

peer-id JavaScript implementation
=================================
# peer-id

@@ -7,13 +6,38 @@ [![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)

[![Build Status](https://travis-ci.org/diasdavid/js-peer-id.svg?style=flat-square)](https://travis-ci.org/diasdavid/js-peer-id)
![](https://img.shields.io/badge/coverage-95%25-yellow.svg?style=flat-square)
![](https://img.shields.io/badge/coverage-100%25-brightgreen.svg?style=flat-square)
[![Dependency Status](https://david-dm.org/diasdavid/js-peer-id.svg?style=flat-square)](https://david-dm.org/diasdavid/js-peer-id)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
> IPFS Peer Id implementation in JavaScript
> [IPFS](https://github.com/ipfs/ipfs) Peer ID implementation in JavaScript.
# Description
An IPFS Peer Id is based on a sha256 hash of the peer public key, using [multihash](https://github.com/jbenet/multihash)
Generate, import, and export PeerIDs, for use with [IPFS](https://github.com/ipfs/ipfs).
The public key is a base64 encoded string of a protobuf containing an RSA DER buffer. This uses a node buffer to pass the base64 encoded public key protobuf to the multihash for ID generation.
*A Peer ID is the SHA-256 [multihash](https://github.com/jbenet/multihash) of a
public key.*
*The public key is a base64 encoded string of a protobuf containing an RSA DER
buffer. This uses a node buffer to pass the base64 encoded public key protobuf
to the multihash for ID generation.*
# Example
```js
var PeerId = require('peer-id')
var bs58 = require('bs58')
var id = PeerId.create({ bits: 32 })
console.log('id ', id.toB58String())
console.log('priv key ', bs58.encode(id.privKey))
console.log('pub key ', bs58.encode(id.pubKey))
```
```
id QmeeLFb92nkZJGj3gXLqXrEMzCMYs6uBgQLVNbrcXEvYXk
priv key 6ibrcPAbevzvPpkq6EA6XmLyuhmUrJrEvUfgQDtEiSEPzGnGU8Ejwf6b11DVm6opnFGo
pub key 2BeBZVKJ9RQs4i4LbGv4ReEeuBA5dck2Gje3wt67e44XuyyPq5jE
```
# Installation

@@ -27,4 +51,6 @@

## Use in Node.js
# Setup
## Node.js
```JavaScript

@@ -34,5 +60,8 @@ var PeerId = require('peer-id')

## Use in a browser with browserify, webpack or any other bundler
## Browser: Browserify, Webpack, other bundlers
The code published to npm that gets loaded on require is in fact a ES5 transpiled version with the right shims added. This means that you can require it and use with your favourite bundler without having to adjust asset management process.
The code published to npm that gets loaded on require is in fact a ES5
transpiled version with the right shims added. This means that you can require
it and use with your favourite bundler without having to adjust asset management
process.

@@ -43,5 +72,6 @@ ```JavaScript

## Use in a browser Using a script tag
## Browser: `<script>` Tag
Loading this module through a script tag will make the `PeerId` obj available in the global namespace.
Loading this module through a script tag will make the `PeerId` obj available in
the global namespace.

@@ -54,50 +84,79 @@ ```html

# Usage
# API
### Creating a new Id
```js
const PeerId = require('peer-id')
```
const PeerId = require('ipfs-peer')
// Create a new Id
const id = PeerId.create()
## Create
// Recreate an Id from Hex string
const id = PeerId.createFromHexString(str)
### PeerId.create()
// Recreate an Id from a Buffer
const id = PeerId.createFromBytes(buf)
Generates a new Peer ID, complete with public/private keypair. A Peer ID has the
following properties:
// Recreate an B58 String
const id = PeerId.createFromB58String(str)
- `pubKey` - Buffer containing the public key bytes
- `privKey` - Buffer containing the private key bytes
- `id` - Buffer containing the multihash bytes
// Recreate from a Public Key
const id = PeerId.createFromPubKey(pubKey)
## Import
// Recreate from a Private Key
const id = PeerId.createFromPrivKey(privKey)
### PeerId.createFromHexString(str)
Creates a Peer ID from hex string representing the key's multihash.
### PeerId.createFromBytes(buf)
Creates a Peer ID from a buffer representing the key's multihash.
### PeerId.createFromB58String(str)
Creates a Peer ID from a Base58 string representing the key's multihash.
### PeerId.createFromPubKey(pubKey)
Creates a Peer ID from a buffer containing a public key.
### PeerId.createFromPrivKey(privKey)
Creates a Peer ID from a buffer containing a private key.
## Export
### id.toPrint()
Returns an object with the ID's properties in hex format:
```js
{
id: 'QmckZzdVd72h9QUFuJJpQqhsZqGLwjhh81qSvZ9BhB2FQi',
privKey: '080012a609308204a20201000282010100a608889914da08959d3a3db0734cee812c96...',
pubKey: '080012a60230820122300d06092a864886f70d01010105000382010f003082010a0282010...'
}
```
### Exporting an Id
### id.toHexString()
Returns the Peer ID's `id` as a hex string.
```js
1220d6243998f2fc56343ad7ed0342ab7886a4eb18d736f1b67d44b37fcc81e0f39f```
### id.toBytes()
Returns the Peer ID's `id` as a buffer.
```js
<Buffer 12 20 d6 24 39 98 f2 fc 56 34 3a d7 ed 03 42 ab 78 86 a4 eb 18 d7 36 f1 b6 7d 44 b3 7f cc 81 e0 f3 9f>
```
// Print friendly format
id.toPrint() // returns an object with id, privKey and pubKey in hex format
// Export to an hex string
id.toHexString()
### id.toB58String()
// Export to Buffer
id.toBytes() (same as id.id)
Returns the Peer ID's `id` as a base58 string.
// Export to a B58 string
id.toB58String()
```js
QmckZzdVd72h9QUFuJJpQqhsZqGLwjhh81qSvZ9BhB2FQi
```
### Id format
# License
```
id.pubKey // Buffer containing the Public Key
id.privKey // Buffer containing the Private Key
id.id // Buffer containing the multihash
```
MIT

@@ -22,2 +22,7 @@ /* eslint-env mocha */

it('create an id without \'new\'', (done) => {
expect(PeerId).to.throw(Error)
done()
})
it('create a new id', (done) => {

@@ -72,2 +77,22 @@ const id = PeerId.create()

})
it('Pretty printing', (done) => {
const id = PeerId.createFromPrivKey(testId.privKey)
var out = id.toPrint()
var expected = {
id: 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A',
privKey: 'CAASpgkwggSiAgEAAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1M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vw4Hf46B+82SvOrSbmnMa+PYqKYIvUzR4gg34rL/7AhwnbEyD5hXq4dHwMNsIDq+l2elPjwm/U9V0gdAl2+r50HAoGALtsKqMvhv8HucAMBPrLikhXP/8um8mMKFMrzfqZ+otxfHzlhI0L08Bo3jQrb0Z7ByNY6M8epOmbCKADsbWcVre/AAY0ZkuSZK/CaOXNX/AhMKmKJh8qAOPRY02LIJRBCpfS4czEdnfUhYV/TYiFNnKRj57PPYZdTzUsxa/yVTmECgYBr7slQEjb5Onn5mZnGDh+72BxLNdgwBkhO0OCdpdISqk0F0Pxby22DFOKXZEpiyI9XYP1C8wPiJsShGm2yEwBPWXnrrZNWczaVuCbXHrZkWQogBDG3HGXNdU4MAWCyiYlyinIBpPpoAJZSzpGLmWbMWh28+RJS6AQX6KHrK1o2uw==',
pubKey: '080012a60230820122300d06092a864886f70d01010105000382010f003082010a0282010100b648aa3f1cc1597819a5d401775e28f3af1adf417749ce378f05901b771a8a47531cea3b911d78a3e875d83e3940934d41845d52dcb9782f08b47001e18207f8e7bb0c839e545b278629e52fd2e720bc2a41c25479710d36d22d0c8338cf58e2d6ab5aedbd26cd7008b6644567ebe43611c1e8df052f591b4b78acfe0d94997f0d8f1030be0c63c93e5edff20ef3979e98ca69a6cc7f658992cdaf383faa2768914bf9bb5a5d1ab7292ee3cd79338393472a281f8e51bb8a8fd1928581020848dac9b24397ddbbea86a52fd82106d49e12fdb492e81ab53bd8cb9f74c05949924bf297e9cfc481f410460c28af5745696ef57627a127dba22c1cbfc3374a5b230203010001'
}
expect(out.id).to.equal(expected.id)
expect(out.privKey).to.equal(expected.privKey)
expect(out.pubKey).to.equal(expected.pubKey)
done()
})
it('toBytes', (done) => {
const id = PeerId.createFromHexString(testIdHex)
expect(id.toBytes().toString('hex')).to.equal(testIdBytes.toString('hex'))
done()
})
})
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