Skip to content

Commit 01957fa

Browse files
docs: Add jsdoc api docs
1 parent 06f93cd commit 01957fa

File tree

6 files changed

+217
-138
lines changed

6 files changed

+217
-138
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ build/Release
2727
node_modules
2828

2929
dist
30+
docs

README.md

Lines changed: 0 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,6 @@
2222
- [Browser: Browserify, Webpack, other bundlers](#browser-browserify-webpack-other-bundlers)
2323
- [Browser: `<script>` Tag](#browser-script-tag)
2424
- [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)
4125
- [License](#license)
4226

4327
# Description
@@ -55,7 +39,6 @@ to the multihash for ID generation.*
5539

5640
```js
5741
var PeerId = require('peer-id')
58-
var bs58 = require('bs58')
5942

6043
PeerId.create({ bits: 1024 }, (err, id) => {
6144
console.log(JSON.stringify(id.toJSON(), null, 2)
@@ -110,100 +93,6 @@ the global namespace.
11093
11194
# API
11295
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-
20796
# License
20897
20998
MIT

documentation.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
toc:
2+
- name: Introduction
3+
file: intro.md
4+
- PeerId
5+
- PeerIdJson

intro.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
Generate, import, and export PeerIDs, for use with [IPFS](https://github.com/ipfs/ipfs).
2+
3+
*A Peer ID is the SHA-256 [multihash](https://github.com/multiformats/multihash) of a
4+
public key.*
5+
6+
*The public key is a base64 encoded string of a protobuf containing an RSA DER
7+
buffer. This uses a node buffer to pass the base64 encoded public key protobuf
8+
to the multihash for ID generation.*
9+
10+
## Example
11+
12+
```js
13+
var PeerId = require('peer-id')
14+
15+
PeerId.create({ bits: 1024 }, (err, id) => {
16+
console.log(JSON.stringify(id.toJSON(), null, 2)
17+
})
18+
```
19+
20+
```
21+
{
22+
"id": "Qma9T5YraSnpRDZqRR4krcSJabThc8nwZuJV3LercPHufi",
23+
"privKey": "CAAS4AQwggJcAgEAAoGBAMBgbIqyOL26oV3nGPBYrdpbv..",
24+
"pubKey": "CAASogEwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMBgbIqyOL26oV3nGPBYrdpbvzCY..."
25+
}
26+
```
27+
28+
## Installation
29+
30+
### npm
31+
32+
```sh
33+
> npm i peer-id
34+
```
35+
36+
## Setup
37+
38+
### Node.js
39+
40+
```js
41+
var PeerId = require('peer-id')
42+
```
43+
44+
### Browser: Browserify, Webpack, other bundlers
45+
46+
The code published to npm that gets loaded on require is in fact a ES5
47+
transpiled version with the right shims added. This means that you can require
48+
it and use with your favourite bundler without having to adjust asset management
49+
process.
50+
51+
```js
52+
var PeerId = require('peer-id')
53+
```
54+
55+
### Browser: `<script>` Tag
56+
57+
Loading this module through a script tag will make the `PeerId` obj available in
58+
the global namespace.
59+
60+
```html
61+
<script src="https://unpkg.com/peer-id/dist/index.min.js"></script>
62+
<!-- OR -->
63+
<script src="https://unpkg.com/peer-id/dist/index.js"></script>
64+
```

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"release-minor": "aegir-release --type minor",
1515
"release-major": "aegir-release --type major",
1616
"coverage": "aegir-coverage",
17-
"coverage-publish": "aegir-coverage publish"
17+
"coverage-publish": "aegir-coverage publish",
18+
"docs": "aegir-docs"
1819
},
1920
"keywords": [
2021
"IPFS"
@@ -56,4 +57,4 @@
5657
"nginnever <[email protected]>",
5758
"npmcdn-to-unpkg-bot <[email protected]>"
5859
]
59-
}
60+
}

0 commit comments

Comments
 (0)