22
22
- [ Browser: Browserify, Webpack, other bundlers] ( #browser-browserify-webpack-other-bundlers )
23
23
- [ Browser: ` <script> ` Tag] ( #browser-script-tag )
24
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
25
- [ License] ( #license )
42
26
43
27
# Description
@@ -55,7 +39,6 @@ to the multihash for ID generation.*
55
39
56
40
``` js
57
41
var PeerId = require (' peer-id' )
58
- var bs58 = require (' bs58' )
59
42
60
43
PeerId .create ({ bits: 1024 }, (err , id ) => {
61
44
console .log (JSON .stringify (id .toJSON (), null , 2 )
@@ -110,100 +93,6 @@ the global namespace.
110
93
111
94
# API
112
95
113
- ` ` ` js
114
- const PeerId = require (' peer-id' )
115
- ` ` `
116
-
117
- ## Create
118
-
119
- ### ` new PeerId (id[, privKey, pubKey])`
120
-
121
- - ` id: Buffer` - The multihash of the publick key as ` Buffer`
122
- - ` privKey: RsaPrivateKey` - The private key
123
- - ` pubKey: RsaPublicKey` - The public key
124
-
125
- The key format is detailed in [libp2p-crypto](https://github.com/libp2p/js-libp2p-crypto).
126
-
127
- ### ` create ([opts], callback)`
128
-
129
- Generates a new Peer ID, complete with public/private keypair.
130
-
131
- - ` opts: Object ` : Default: ` {bits: 2048 }`
132
- - ` callback: Function `
133
-
134
- Calls back ` callback` with ` err, id` .
135
-
136
- ## Import
137
-
138
- ### ` createFromHexString (str)`
139
-
140
- Creates a Peer ID from hex string representing the key's multihash.
141
-
142
- ### ` createFromBytes (buf)`
143
-
144
- Creates a Peer ID from a buffer representing the key's multihash.
145
-
146
- ### ` createFromB58String (str)`
147
- Creates a Peer ID from a Base58 string representing the key's multihash.
148
-
149
- ### ` createFromPubKey (pubKey)`
150
-
151
- - ` publicKey: Buffer`
152
-
153
- Creates a Peer ID from a buffer containing a public key.
154
-
155
- ### ` createFromPrivKey (privKey)`
156
-
157
- - ` privKey: Buffer`
158
-
159
- Creates a Peer ID from a buffer containing a private key.
160
-
161
- ### ` createFromJSON (obj)`
162
-
163
- - ` obj .id : String ` - The multihash encoded in ` base58`
164
- - ` obj .pubKey : String ` - The public key in protobuf format, encoded in 'base64'
165
- - ` obj .privKey : String ` - The private key in protobuf format, encoded in 'base 64'
166
-
167
- ## Export
168
-
169
- ### ` toHexString ()`
170
-
171
- Returns the Peer ID's ` id` as a hex string.
172
-
173
- ` ` `
174
- 1220d6243998f2fc56343ad7ed0342ab7886a4eb18d736f1b67d44b37fcc81e0f39f
175
- ` ` `
176
-
177
- ### ` toBytes ()`
178
-
179
- Returns the Peer ID's ` id` as a buffer.
180
-
181
- ` ` `
182
- < 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 >
183
- ` ` `
184
-
185
- ### ` toB58String ()`
186
-
187
- Returns the Peer ID's ` id` as a base58 string.
188
-
189
- ` ` `
190
- QmckZzdVd72h9QUFuJJpQqhsZqGLwjhh81qSvZ9BhB2FQi
191
- ` ` `
192
-
193
- ### ` toJSON ()`
194
-
195
- Returns an ` obj` of the form
196
-
197
- - ` obj .id : String ` - The multihash encoded in ` base58`
198
- - ` obj .pubKey : String ` - The public key in protobuf format, encoded in 'base64'
199
- - ` obj .privKey : String ` - The private key in protobuf format, encoded in 'base 64'
200
-
201
-
202
- ### ` toPrint ()`
203
-
204
- Alias for ` .toJSON ()` .
205
-
206
-
207
96
# License
208
97
209
98
MIT
0 commit comments