mirror of
https://github.com/fluencelabs/js-peer-id
synced 2025-04-29 10:32:35 +00:00
99 lines
2.9 KiB
Markdown
99 lines
2.9 KiB
Markdown
# peer-id
|
|
|
|
[](http://ipn.io)
|
|
[](http://webchat.freenode.net/?channels=%23ipfs)
|
|
[](https://travis-ci.org/libp2p/js-peer-id)
|
|
[](https://coveralls.io/github/libp2p/js-peer-id?branch=master)
|
|
[](https://david-dm.org/libp2p/js-peer-id)
|
|
[](https://github.com/feross/standard)
|
|

|
|

|
|
|
|
[](https://saucelabs.com/u/ipfs-js-peer-id)
|
|
|
|
> [IPFS](https://github.com/ipfs/ipfs) Peer ID implementation in JavaScript.
|
|
|
|
- [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)
|
|
|
|
# Description
|
|
|
|
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
|
|
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)
|
|
})
|
|
```
|
|
|
|
```
|
|
{
|
|
"id": "Qma9T5YraSnpRDZqRR4krcSJabThc8nwZuJV3LercPHufi",
|
|
"privKey": "CAAS4AQwggJcAgEAAoGBAMBgbIqyOL26oV3nGPBYrdpbv..",
|
|
"pubKey": "CAASogEwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMBgbIqyOL26oV3nGPBYrdpbvzCY..."
|
|
}
|
|
```
|
|
|
|
# Installation
|
|
|
|
## npm
|
|
|
|
```sh
|
|
> npm i peer-id
|
|
```
|
|
|
|
# Setup
|
|
|
|
## Node.js
|
|
|
|
```js
|
|
var PeerId = require('peer-id')
|
|
```
|
|
|
|
## Browser: Browserify, Webpack, other bundlers
|
|
|
|
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.
|
|
|
|
```js
|
|
var PeerId = require('peer-id')
|
|
```
|
|
|
|
## Browser: `<script>` Tag
|
|
|
|
Loading this module through a script tag will make the `PeerId` obj available in
|
|
the global namespace.
|
|
|
|
```html
|
|
<script src="https://unpkg.com/peer-id/dist/index.min.js"></script>
|
|
<!-- OR -->
|
|
<script src="https://unpkg.com/peer-id/dist/index.js"></script>
|
|
```
|
|
|
|
# API
|
|
|
|
# License
|
|
|
|
MIT
|