@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 +4 -0
- package/README.md +93 -0
- package/dist/index.min.js +23 -0
- package/dist/src/crypto.d.ts +19 -0
- package/dist/src/crypto.d.ts.map +1 -0
- package/dist/src/crypto.js +56 -0
- package/dist/src/crypto.js.map +1 -0
- package/dist/src/errors.d.ts +7 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.js +7 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/index.d.ts +76 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +124 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/key-generator.d.ts +11 -0
- package/dist/src/key-generator.d.ts.map +1 -0
- package/dist/src/key-generator.js +22 -0
- package/dist/src/key-generator.js.map +1 -0
- package/package.json +72 -0
- package/src/crypto.ts +63 -0
- package/src/errors.ts +6 -0
- package/src/index.ts +167 -0
- package/src/key-generator.ts +23 -0
package/LICENSE
ADDED
package/README.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
> Connection protection management for libp2p leveraging PSK encryption via XSalsa20.
|
2
|
+
|
3
|
+
[](http://libp2p.io/)
|
4
|
+
[](https://discuss.libp2p.io)
|
5
|
+
[](https://codecov.io/gh/libp2p/js-libp2p)
|
6
|
+
[](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.
|