Implementation of Connection protection management via a shared secret
Connection protection management for libp2p leveraging PSK encryption via XSalsa20.
import { createLibp2p } from 'libp2p'
import { preSharedKey, generateKey } from '@libp2p/pnet'
// Create a Uint8Array and write the swarm key to it
const swarmKey = new Uint8Array(95)
generateKey(swarmKey)
const node = await createLibp2p({
// ...other options
connectionProtector: preSharedKey({
psk: swarmKey
})
})
Private Shared Keys are expected to be in the following format:
/key/swarm/psk/1.0.0/
/base16/
dffb7e3135399a8b1612b2aaca1c36a3a8ac2cd0cca51ceeb2ced87d308cac6d
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.
If you have a module locally that depends on libp2p, you can run the following from that project, assuming the node_modules are installed.
node -e "import('@libp2p/pnet').then(({ generateKey }) => generateKey(process.stdout))" > swarm.key
import fs from 'fs'
import { generateKey } from '@libp2p/pnet'
const swarmKey = new Uint8Array(95)
generateKey(swarmKey)
fs.writeFileSync('swarm.key', swarmKey)
$ npm i @libp2p/pnet
<script>
tagLoading this module through a script tag will make its exports available as Libp2pPnet
in the global namespace.
<script src="https://unpkg.com/@libp2p/pnet/dist/index.min.js"></script>
Licensed under either of
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.
Connection protection management for libp2p leveraging PSK encryption via XSalsa20.
Example
Private Shared Keys
Private Shared Keys are expected to be in the following format:
PSK Generation
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.
From a module using libp2p
If you have a module locally that depends on libp2p, you can run the following from that project, assuming the node_modules are installed.
Programmatically