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

IPFS Peer Id implementation in Node.js


Version published
Weekly downloads
22K
decreased by-12.85%
Maintainers
1
Weekly downloads
 
Created
Source

peer-id JavaScript implementation

Build Status Dependency Status js-standard-style

IPFS Peer Id implementation in JavaScript

Description

An IPFS Peer Id is based on a sha256 hash of the peer public key, using multihash

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.

Usage

In Node.js through npm

> npm install --save peer-id
const PeerId = require('peer-id')

In the Browser through Webpack

Follow our webpack config example.

In the Browser through browserify

WIP Doesn't work out yet

In the Browser through <script> tag

Make the peer-id.js available through your server and load it using a normal <script> tag, this will export the PeerId object, such that:

const Id = PeerId
Gotchas

You will need to use Node.js Buffer API compatible, if you are running inside the browser, you can access it by PeerId.Buffer or you can install Feross's Buffer.

Creating a new Id

const PeerId = require('ipfs-peer')

// Create a new Id
const id = PeerId.create()

// Recreate an Id from Hex string
const id = PeerId.createFromHexString(str)

// Recreate an Id from a Buffer
const id = PeerId.createFromBytes(buf)

// Recreate an B58 String
const id = PeerId.createFromB58String(str)

// Recreate from a Public Key
const id = PeerId.createFromPubKey(pubKey)

// Recreate from a Private Key
const id = PeerId.createFromPrivKey(privKey)

Exporting an Id

// Print friendly format
id.toPrint() // returns an object with id, privKey and pubKey in hex format

// Export to an hex string
id.toHexString()

// Export to Buffer
id.toBytes() (same as id.id)

// Export to a B58 string
id.toB58String()

Id format

id.pubKey   // Buffer containing the Public Key
id.privKey  // Buffer containing the Private Key
id.id       // Buffer containing the multihash

Keywords

FAQs

Package last updated on 07 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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