@libp2p/pnet 1.0.0-01e9a5fe4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,4 @@
1
+ This project is dual licensed under MIT and Apache-2.0.
2
+
3
+ MIT: https://www.opensource.org/licenses/mit
4
+ Apache-2.0: https://www.apache.org/licenses/license-2.0
package/README.md ADDED
@@ -0,0 +1,93 @@
1
+ > Connection protection management for libp2p leveraging PSK encryption via XSalsa20.
2
+
3
+ [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
4
+ [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
5
+ [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p)
6
+ [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/main.yml?branch=main\&style=flat-square)](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amain)
7
+
8
+ > Implementation of Connection protection management via a shared secret
9
+
10
+ # About
11
+
12
+ Connection protection management for libp2p leveraging PSK encryption via XSalsa20.
13
+
14
+ ## Example
15
+
16
+ ```typescript
17
+ import { createLibp2p } from 'libp2p'
18
+ import { preSharedKey, generateKey } from '@libp2p/pnet'
19
+
20
+ // Create a Uint8Array and write the swarm key to it
21
+ const swarmKey = new Uint8Array(95)
22
+ generateKey(swarmKey)
23
+
24
+ const node = await createLibp2p({
25
+ // ...other options
26
+ connectionProtector: preSharedKey({
27
+ psk: swarmKey
28
+ })
29
+ })
30
+ ```
31
+
32
+ ## Private Shared Keys
33
+
34
+ Private Shared Keys are expected to be in the following format:
35
+
36
+ ```
37
+ /key/swarm/psk/1.0.0/
38
+ /base16/
39
+ dffb7e3135399a8b1612b2aaca1c36a3a8ac2cd0cca51ceeb2ced87d308cac6d
40
+ ```
41
+
42
+ ## PSK Generation
43
+
44
+ A utility method has been created to generate a key for your private network. You can use one of the methods below to generate your key.
45
+
46
+ ### From a module using libp2p
47
+
48
+ If you have a module locally that depends on libp2p, you can run the following from that project, assuming the node\_modules are installed.
49
+
50
+ ```console
51
+ node -e "import('@libp2p/pnet').then(({ generateKey }) => generateKey(process.stdout))" > swarm.key
52
+ ```
53
+
54
+ ### Programmatically
55
+
56
+ ```js
57
+ import fs from 'fs'
58
+ import { generateKey } from '@libp2p/pnet'
59
+
60
+ const swarmKey = new Uint8Array(95)
61
+ generateKey(swarmKey)
62
+
63
+ fs.writeFileSync('swarm.key', swarmKey)
64
+ ```
65
+
66
+ # Install
67
+
68
+ ```console
69
+ $ npm i @libp2p/pnet
70
+ ```
71
+
72
+ ## Browser `<script>` tag
73
+
74
+ Loading this module through a script tag will make it's exports available as `Libp2pPnet` in the global namespace.
75
+
76
+ ```html
77
+ <script src="https://unpkg.com/@libp2p/pnet/dist/index.min.js"></script>
78
+ ```
79
+
80
+ # API Docs
81
+
82
+ - <https://libp2p.github.io/js-libp2p/modules/_libp2p_pnet.html>
83
+
84
+ # License
85
+
86
+ Licensed under either of
87
+
88
+ - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
89
+ - MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
90
+
91
+ # Contribution
92
+
93
+ Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.