6
6
[ ![ 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 )
7
7
[ ![ Dependency Status] ( https://david-dm.org/libp2p/js-peer-id.svg?style=flat-square )] ( https://david-dm.org/libp2p/js-peer-id )
8
8
[ ![ 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 )
9
13
10
14
> [ IPFS] ( https://github.com/ipfs/ipfs ) Peer ID implementation in JavaScript.
11
15
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
+
12
43
# Description
13
44
14
45
Generate, import, and export PeerIDs, for use with [ IPFS] ( https://github.com/ipfs/ipfs ) .
@@ -26,17 +57,17 @@ to the multihash for ID generation.*
26
57
var PeerId = require (' peer-id' )
27
58
var bs58 = require (' bs58' )
28
59
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
+ })
34
63
` ` `
35
64
36
65
` ` `
37
- id QmeeLFb92nkZJGj3gXLqXrEMzCMYs6uBgQLVNbrcXEvYXk
38
- priv key 6ibrcPAbevzvPpkq6EA6XmLyuhmUrJrEvUfgQDtEiSEPzGnGU8Ejwf6b11DVm6opnFGo
39
- pub key 2BeBZVKJ9RQs4i4LbGv4ReEeuBA5dck2Gje3wt67e44XuyyPq5jE
66
+ {
67
+ " id" : " Qma9T5YraSnpRDZqRR4krcSJabThc8nwZuJV3LercPHufi" ,
68
+ " privKey" : " CAAS4AQwggJcAgEAAoGBAMBgbIqyOL26oV3nGPBYrdpbv.." ,
69
+ " pubKey" : " CAASogEwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMBgbIqyOL26oV3nGPBYrdpbvzCY..."
70
+ }
40
71
` ` `
41
72
42
73
# Installation
@@ -93,11 +124,14 @@ const PeerId = require('peer-id')
93
124
94
125
The key format is detailed in [libp2p-crypto](https://github.com/libp2p/js-libp2p-crypto).
95
126
96
- ### ` create([opts]) `
127
+ ### ` create ([opts], callback )`
97
128
98
129
Generates a new Peer ID, complete with public/private keypair.
99
130
100
131
- ` opts: Object ` : Default: ` {bits: 2048 }`
132
+ - ` callback: Function `
133
+
134
+ Calls back ` callback` with ` err, id` .
101
135
102
136
## Import
103
137
@@ -114,10 +148,14 @@ Creates a Peer ID from a Base58 string representing the key's multihash.
114
148
115
149
### ` createFromPubKey (pubKey)`
116
150
151
+ - ` publicKey: Buffer`
152
+
117
153
Creates a Peer ID from a buffer containing a public key.
118
154
119
155
### ` createFromPrivKey (privKey)`
120
156
157
+ - ` privKey: Buffer`
158
+
121
159
Creates a Peer ID from a buffer containing a private key.
122
160
123
161
### ` createFromJSON (obj)`
@@ -126,7 +164,6 @@ Creates a Peer ID from a buffer containing a private key.
126
164
- ` obj .pubKey : String ` - The public key in protobuf format, encoded in 'base64'
127
165
- ` obj .privKey : String ` - The private key in protobuf format, encoded in 'base 64'
128
166
129
-
130
167
## Export
131
168
132
169
### ` toHexString ()`
0 commit comments