Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
IPFS Peer ID implementation in JavaScript.
Generate, import, and export PeerIDs, for use with IPFS.
A Peer ID is the SHA-256 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.
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
> npm i peer-id
var PeerId = require('peer-id')
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.
var PeerId = require('peer-id')
<script>
TagLoading this module through a script tag will make the PeerId
obj available in
the global namespace.
<script src="https://npmcdn.com/peer-id/dist/index.min.js"></script>
<!-- OR -->
<script src="https://npmcdn.com/peer-id/dist/index.js"></script>
const PeerId = require('peer-id')
Generates a new Peer ID, complete with public/private keypair. A Peer ID has the following properties:
pubKey
- Buffer containing the public key bytesprivKey
- Buffer containing the private key bytesid
- Buffer containing the multihash bytesCreates a Peer ID from hex string representing the key's multihash.
Creates a Peer ID from a buffer representing the key's multihash.
Creates a Peer ID from a Base58 string representing the key's multihash.
Creates a Peer ID from a buffer containing a public key.
Creates a Peer ID from a buffer containing a private key.
Returns an object with the ID's properties in hex format:
{
id: 'QmckZzdVd72h9QUFuJJpQqhsZqGLwjhh81qSvZ9BhB2FQi',
privKey: '080012a609308204a20201000282010100a608889914da08959d3a3db0734cee812c96...',
pubKey: '080012a60230820122300d06092a864886f70d01010105000382010f003082010a0282010...'
}
Returns the Peer ID's id
as a hex string.
1220d6243998f2fc56343ad7ed0342ab7886a4eb18d736f1b67d44b37fcc81e0f39f
Returns the Peer ID's id
as a buffer.
<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>
Returns the Peer ID's id
as a base58 string.
QmckZzdVd72h9QUFuJJpQqhsZqGLwjhh81qSvZ9BhB2FQi
MIT
0.6.7 (2016-05-23)
<a name="0.6.6"></a>
FAQs
IPFS Peer Id implementation in Node.js
The npm package peer-id receives a total of 20,122 weekly downloads. As such, peer-id popularity was classified as popular.
We found that peer-id demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.