66[ ![ 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 )
77[ ![ Dependency Status] ( https://david-dm.org/libp2p/js-peer-id.svg?style=flat-square )] ( https://david-dm.org/libp2p/js-peer-id )
88[ ![ js-standard-style] ( https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square )] ( https://github.com/feross/standard )
9+ ![ ] ( https://img.shields.io/badge/npm-%3E%3D3.0.0-orange.svg?style=flat-square )
10+ ![ ] ( https://img.shields.io/badge/Node.js-%3E%3D4.0.0-orange.svg?style=flat-square )
11+
12+ [ ![ Sauce Test Status] ( https://saucelabs.com/browser-matrix/ipfs-js-peer-id.svg )] ( https://saucelabs.com/u/ipfs-js-peer-id )
913
1014> [ IPFS] ( https://github.com/ipfs/ipfs ) Peer ID implementation in JavaScript.
1115
16+ - [ Description] ( #description )
17+ - [ Example] ( #example )
18+ - [ Installation] ( #installation )
19+ - [ npm] ( #npm )
20+ - [ Setup] ( #setup )
21+ - [ Node.js] ( #nodejs )
22+ - [ Browser: Browserify, Webpack, other bundlers] ( #browser-browserify-webpack-other-bundlers )
23+ - [ Browser: ` <script> ` Tag] ( #browser-script-tag )
24+ - [ API] ( #api )
25+ - [ Create] ( #create )
26+ - [ ` new PeerId(id[, privKey, pubKey]) ` ] ( #new-peeridid-privkey-pubkey )
27+ - [ ` create([opts], callback) ` ] ( #createopts-callback )
28+ - [ Import] ( #import )
29+ - [ ` createFromHexString(str) ` ] ( #createfromhexstringstr )
30+ - [ ` createFromBytes(buf) ` ] ( #createfrombytesbuf )
31+ - [ ` createFromB58String(str) ` ] ( #createfromb58stringstr )
32+ - [ ` createFromPubKey(pubKey) ` ] ( #createfrompubkeypubkey )
33+ - [ ` createFromPrivKey(privKey) ` ] ( #createfromprivkeyprivkey )
34+ - [ ` createFromJSON(obj) ` ] ( #createfromjsonobj )
35+ - [ Export] ( #export )
36+ - [ ` toHexString() ` ] ( #tohexstring )
37+ - [ ` toBytes() ` ] ( #tobytes )
38+ - [ ` toB58String() ` ] ( #tob58string )
39+ - [ ` toJSON() ` ] ( #tojson )
40+ - [ ` toPrint() ` ] ( #toprint )
41+ - [ License] ( #license )
42+
1243# Description
1344
1445Generate, import, and export PeerIDs, for use with [ IPFS] ( https://github.com/ipfs/ipfs ) .
@@ -26,17 +57,17 @@ to the multihash for ID generation.*
2657var PeerId = require (' peer-id' )
2758var bs58 = require (' bs58' )
2859
29- var id = PeerId .create ({ bits: 32 })
30-
31- console .log (' id ' , id .toB58String ())
32- console .log (' priv key ' , bs58 .encode (id .privKey .bytes ))
33- console .log (' pub key ' , bs58 .encode (id .pubKey .bytes ))
60+ PeerId .create ({ bits: 1024 }, (err , id ) => {
61+ console .log (JSON .stringify (id .toJSON (), null , 2 )
62+ })
3463` ` `
3564
3665` ` `
37- id QmeeLFb92nkZJGj3gXLqXrEMzCMYs6uBgQLVNbrcXEvYXk
38- priv key 6ibrcPAbevzvPpkq6EA6XmLyuhmUrJrEvUfgQDtEiSEPzGnGU8Ejwf6b11DVm6opnFGo
39- pub key 2BeBZVKJ9RQs4i4LbGv4ReEeuBA5dck2Gje3wt67e44XuyyPq5jE
66+ {
67+ " id" : " Qma9T5YraSnpRDZqRR4krcSJabThc8nwZuJV3LercPHufi" ,
68+ " privKey" : " CAAS4AQwggJcAgEAAoGBAMBgbIqyOL26oV3nGPBYrdpbv.." ,
69+ " pubKey" : " CAASogEwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMBgbIqyOL26oV3nGPBYrdpbvzCY..."
70+ }
4071` ` `
4172
4273# Installation
@@ -93,11 +124,14 @@ const PeerId = require('peer-id')
93124
94125The key format is detailed in [libp2p-crypto](https://github.com/libp2p/js-libp2p-crypto).
95126
96- ### ` create([opts]) `
127+ ### ` create ([opts], callback )`
97128
98129Generates a new Peer ID, complete with public/private keypair.
99130
100131- ` opts: Object ` : Default: ` {bits: 2048 }`
132+ - ` callback: Function `
133+
134+ Calls back ` callback` with ` err, id` .
101135
102136## Import
103137
@@ -114,10 +148,14 @@ Creates a Peer ID from a Base58 string representing the key's multihash.
114148
115149### ` createFromPubKey (pubKey)`
116150
151+ - ` publicKey: Buffer`
152+
117153Creates a Peer ID from a buffer containing a public key.
118154
119155### ` createFromPrivKey (privKey)`
120156
157+ - ` privKey: Buffer`
158+
121159Creates a Peer ID from a buffer containing a private key.
122160
123161### ` createFromJSON (obj)`
@@ -126,7 +164,6 @@ Creates a Peer ID from a buffer containing a private key.
126164- ` obj .pubKey : String ` - The public key in protobuf format, encoded in 'base64'
127165- ` obj .privKey : String ` - The private key in protobuf format, encoded in 'base 64'
128166
129-
130167## Export
131168
132169### ` toHexString ()`
0 commit comments