2016-02-13 13:46:33 -08:00
2016-02-10 13:55:59 -08:00
2015-11-05 18:46:02 +00:00
2016-02-12 19:55:44 -08:00
2016-02-13 13:46:33 -08:00
2016-02-13 07:49:51 -08:00
2015-07-08 14:50:37 -07:00
2015-07-08 15:34:34 -07:00
2015-07-08 15:34:34 -07:00
2016-02-12 16:38:29 -08:00
2015-11-05 18:46:02 +00:00
2016-02-12 16:13:09 -08:00
2015-07-08 14:50:37 -07:00
2016-02-12 20:09:42 -08:00
2016-02-13 07:49:51 -08:00

peer-id JavaScript implementation

[ Build Status](https://travis-ci.org/diasdavid/js-peer-id) 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
var PeerId = require('peer-id')

In the Browser through browserify

Same as in Node.js, you just have to browserify the code before serving it. See the browserify repo for how to do that.

In the Browser through <script> tag

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

var PeerId = window.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

var PeerId = require('ipfs-peer')

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

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

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

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

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

// Recreate from a Private Key
var 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
Description
No description provided
Readme 2.4 MiB
Languages
JavaScript 100%