2015-09-15 17:14:48 +01:00
|
|
|
peer-id Node.js implementation
|
|
|
|
==============================
|
2015-07-08 15:34:34 -07:00
|
|
|
|
2015-09-15 17:14:48 +01:00
|
|
|
[](http://ipn.io) [[](http://webchat.freenode.net/?channels=%23ipfs) ](https://travis-ci.org/diasdavid/node-peer-id)  [](https://david-dm.org/diasdavid/node-peer-id) [](https://github.com/feross/standard)
|
2015-07-08 15:34:34 -07:00
|
|
|
|
|
|
|
> IPFS Peer Id implementation in Node.js
|
|
|
|
|
|
|
|
# Description
|
|
|
|
|
|
|
|
A IPFS Peer Id is based on a sha256 has of the peer public key, using [multihash](https://github.com/jbenet/multihash)
|
|
|
|
|
|
|
|
# Usage
|
|
|
|
|
|
|
|
### Installing
|
|
|
|
|
|
|
|
```
|
2015-09-15 17:14:48 +01:00
|
|
|
$ npm install peer-id
|
2015-07-08 15:34:34 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
### Creating a new Id
|
|
|
|
|
|
|
|
```
|
|
|
|
var PeerId = require('ipfs-peer')
|
|
|
|
|
|
|
|
// Create a new Id
|
2015-09-15 17:17:50 +01:00
|
|
|
var id = new PeerId.create()
|
2015-07-08 15:34:34 -07:00
|
|
|
|
|
|
|
// Recreate an Id from Hex string
|
2015-09-15 17:17:50 +01:00
|
|
|
var id = new PeerId.createFromHexString(str)
|
2015-07-08 15:34:34 -07:00
|
|
|
|
|
|
|
// Recreate an Id from a Buffer
|
2015-09-15 17:17:50 +01:00
|
|
|
var id = new PeerId.createFromBytes(buf)
|
2015-07-08 15:34:34 -07:00
|
|
|
|
|
|
|
// Recreate an B58 String
|
2015-09-15 17:17:50 +01:00
|
|
|
var id = new PeerId.createFromB58String(str)
|
2015-07-08 15:34:34 -07:00
|
|
|
|
|
|
|
// Recreate from a Public Key
|
2015-09-15 17:17:50 +01:00
|
|
|
var id = new PeerId.createFromPubKey(pubKey)
|
2015-07-08 15:34:34 -07:00
|
|
|
|
|
|
|
// Recreate from a Private Key
|
2015-09-15 17:17:50 +01:00
|
|
|
var id = new PeerId.createFromPrivKey(privKey)
|
2015-07-08 15:34:34 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
### 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
|
|
|
|
```
|