js-peer-id/README.md

99 lines
2.9 KiB
Markdown
Raw Permalink Normal View History

2016-04-11 15:23:34 -07:00
# peer-id
2015-07-08 15:34:34 -07:00
2016-03-03 17:43:30 +00:00
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
2016-09-11 16:40:26 -04:00
[![Build Status](https://travis-ci.org/libp2p/js-peer-id.svg?style=flat-square)](https://travis-ci.org/libp2p/js-peer-id)
2016-09-11 16:40:09 -04:00
[![Coverage Status](https://coveralls.io/repos/github/libp2p/js-peer-id/badge.svg?branch=master)](https://coveralls.io/github/libp2p/js-peer-id?branch=master)
[![Dependency Status](https://david-dm.org/libp2p/js-peer-id.svg?style=flat-square)](https://david-dm.org/libp2p/js-peer-id)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
![](https://img.shields.io/badge/npm-%3E%3D3.0.0-orange.svg?style=flat-square)
![](https://img.shields.io/badge/Node.js-%3E%3D4.0.0-orange.svg?style=flat-square)
[![Sauce Test Status](https://saucelabs.com/browser-matrix/ipfs-js-peer-id.svg)](https://saucelabs.com/u/ipfs-js-peer-id)
2016-04-11 15:23:34 -07:00
> [IPFS](https://github.com/ipfs/ipfs) Peer ID implementation in JavaScript.
2015-07-08 15:34:34 -07:00
- [Description](#description)
- [Example](#example)
- [Installation](#installation)
- [npm](#npm)
- [Setup](#setup)
- [Node.js](#nodejs)
- [Browser: Browserify, Webpack, other bundlers](#browser-browserify-webpack-other-bundlers)
- [Browser: `<script>` Tag](#browser-script-tag)
- [API](#api)
- [License](#license)
2015-07-08 15:34:34 -07:00
# Description
2016-04-11 15:23:34 -07:00
Generate, import, and export PeerIDs, for use with [IPFS](https://github.com/ipfs/ipfs).
*A Peer ID is the SHA-256 [multihash](https://github.com/multiformats/multihash) of a
2016-04-11 15:23:34 -07:00
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.*
# Example
```js
var PeerId = require('peer-id')
PeerId.create({ bits: 1024 }, (err, id) => {
console.log(JSON.stringify(id.toJSON(), null, 2)
})
2016-04-11 15:23:34 -07:00
```
2016-04-11 15:23:34 -07:00
```
{
"id": "Qma9T5YraSnpRDZqRR4krcSJabThc8nwZuJV3LercPHufi",
"privKey": "CAAS4AQwggJcAgEAAoGBAMBgbIqyOL26oV3nGPBYrdpbv..",
"pubKey": "CAASogEwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMBgbIqyOL26oV3nGPBYrdpbvzCY..."
}
2016-04-11 15:23:34 -07:00
```
2016-04-07 19:45:21 -04:00
# Installation
2015-07-08 15:34:34 -07:00
2016-04-07 19:45:21 -04:00
## npm
2015-07-08 15:34:34 -07:00
2016-04-07 19:45:21 -04:00
```sh
> npm i peer-id
2015-07-08 15:34:34 -07:00
```
2015-11-05 17:47:44 +00:00
2016-04-11 15:23:34 -07:00
# Setup
## Node.js
2015-07-08 15:34:34 -07:00
```js
2016-04-07 19:45:21 -04:00
var PeerId = require('peer-id')
```
2016-03-10 19:36:47 +00:00
2016-04-12 09:04:02 -07:00
## Browser: Browserify, Webpack, other bundlers
2016-03-10 19:36:47 +00:00
2016-04-11 15:23:34 -07:00
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.
2015-11-05 17:47:44 +00:00
```js
2016-04-07 19:45:21 -04:00
var PeerId = require('peer-id')
```
2015-11-05 17:47:44 +00:00
2016-04-11 15:23:34 -07:00
## Browser: `<script>` Tag
2015-11-05 17:47:44 +00:00
2016-04-11 15:23:34 -07:00
Loading this module through a script tag will make the `PeerId` obj available in
the global namespace.
2015-11-05 17:47:44 +00:00
2016-04-07 19:45:21 -04:00
```html
2016-09-11 12:29:33 +01:00
<script src="https://unpkg.com/peer-id/dist/index.min.js"></script>
2016-04-07 19:45:21 -04:00
<!-- OR -->
2016-09-11 12:29:33 +01:00
<script src="https://unpkg.com/peer-id/dist/index.js"></script>
2015-11-05 17:47:44 +00:00
```
2016-04-11 15:23:34 -07:00
# API
2015-07-08 15:34:34 -07:00
2016-04-11 15:23:34 -07:00
# License
MIT