1
- js-libp2p-pnet
1
+ js-libp2p-pnet <!-- omit in toc -->
2
2
==================
3
3
4
4
> Connection protection management for libp2p leveraging PSK encryption via XSalsa20.
5
5
6
6
** Note** : git history prior to merging into js-libp2p can be found in the original repository, https://github.com/libp2p/js-libp2p-pnet .
7
7
8
- ## Table of Contents
8
+ ## Table of Contents <!-- omit in toc -->
9
9
10
- - [ js-libp2p-pnet] ( #js-libp2p-pnet )
11
- - [ Table of Contents] ( #table-of-contents )
12
- - [ Usage] ( #usage )
13
- - [ Examples] ( #examples )
14
- - [ Private Shared Keys] ( #private-shared-keys )
15
- - [ PSK Generation] ( #psk-generation )
16
- - [ From libp2p-pnet] ( #from-libp2p-pnet )
17
- - [ From a module using libp2p] ( #from-a-module-using-libp2p )
18
- - [ Programmatically] ( #programmatically )
10
+ - [ Usage] ( #usage )
11
+ - [ Examples] ( #examples )
12
+ - [ Private Shared Keys] ( #private-shared-keys )
13
+ - [ PSK Generation] ( #psk-generation )
14
+ - [ From a module using libp2p] ( #from-a-module-using-libp2p )
15
+ - [ Programmatically] ( #programmatically )
19
16
20
17
## Usage
21
18
22
19
``` js
23
- const Protector from 'libp2p -pnet ')
24
- const protector = new Protector (swarmKeyBuffer)
25
- const privateConnection = protector .protect (myPublicConnection, (err ) => { })
20
+ import { createLibp2p } from ' libp2p'
21
+ import { preSharedKey , generateKey } from ' libp2p/pnet'
22
+
23
+ // Create a Uint8Array and write the swarm key to it
24
+ const swarmKey = new Uint8Array (95 )
25
+ generateKey (swarmKey)
26
+
27
+ const node = await createLibp2p ({
28
+ // ...other options
29
+ connectionProtector: preSharedKey ({
30
+ psk: swarmKey
31
+ })
32
+ })
26
33
```
27
34
28
- ### Examples
35
+ ## Examples
29
36
[ Private Networks with IPFS] ( ../../examples/pnet-ipfs )
30
37
31
- ### Private Shared Keys
38
+ ## Private Shared Keys
32
39
33
40
Private Shared Keys are expected to be in the following format:
34
41
@@ -38,33 +45,28 @@ Private Shared Keys are expected to be in the following format:
38
45
dffb7e3135399a8b1612b2aaca1c36a3a8ac2cd0cca51ceeb2ced87d308cac6d
39
46
```
40
47
41
- ### PSK Generation
48
+ ## PSK Generation
42
49
43
50
A utility method has been created to generate a key for your private network. You can
44
51
use one of the methods below to generate your key.
45
52
46
- #### From libp2p-pnet
47
-
48
- If you have libp2p locally, you can run the following from the projects root.
49
-
50
- ``` sh
51
- node ./src/pnet/key-generator.js > swarm.key
52
- ```
53
-
54
53
#### From a module using libp2p
55
54
56
55
If you have a module locally that depends on libp2p, you can run the following from
57
56
that project, assuming the node_modules are installed.
58
57
59
- ``` sh
60
- node -e " require ('libp2p/src/ pnet').generate( process.stdout)" > swarm.key
58
+ ``` console
59
+ node -e "import ('libp2p/pnet').then(({ generateKey }) => generateKey( process.stdout) )" > swarm.key
61
60
```
62
61
63
62
#### Programmatically
64
63
65
64
``` js
66
- const writeKey from 'libp2p /src /pnet ').generate
65
+ import fs from ' fs'
66
+ import { generateKey } from ' libp2p/pnet'
67
+
67
68
const swarmKey = new Uint8Array (95 )
68
- writeKey (swarmKey)
69
+ generateKey (swarmKey)
70
+
69
71
fs .writeFileSync (' swarm.key' , swarmKey)
70
72
```
0 commit comments