mirror of
https://github.com/fluencelabs/js-peer-id
synced 2025-04-24 22:32:29 +00:00
ipfs-peer-id Node.js implementation
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
Usage
Installing
$ npm install ipfs-peer-id
Creating a new Id
var PeerId = require('ipfs-peer')
// Create a new Id
var id = new Id.create()
// Recreate an Id from Hex string
var id = new Id.createFromHexString(str)
// Recreate an Id from a Buffer
var id = new Id.createFromBytes(buf)
// Recreate an B58 String
var id = new Id.createFromB58String(str)
// Recreate from a Public Key
var id = new Id.createFromPubKey(pubKey)
// Recreate from a Private Key
var id = new Id.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
Languages
JavaScript
100%