|
| 1 | +# @chainsafe/libp2p-noise |
| 2 | + |
| 3 | + |
| 4 | +[](https://github.com/ChainSafe/js-libp2p-noise/actions) |
| 5 | +[](https://libp2p.io/) |
| 6 | + |
| 7 | +[](https://opensource.org/licenses/Apache-2.0) |
| 8 | +[](https://opensource.org/licenses/MIT) |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | +[](https://twitter.com/ChainSafeth) |
| 13 | +[](https://discord.gg/Q6A3YA2) |
| 14 | + |
| 15 | +> Noise libp2p handshake for js-libp2p |
| 16 | +
|
| 17 | +# About |
| 18 | + |
| 19 | +<!-- |
| 20 | +
|
| 21 | +!IMPORTANT! |
| 22 | +
|
| 23 | +Everything in this README between "# About" and "# Install" is automatically |
| 24 | +generated and will be overwritten the next time the doc generator is run. |
| 25 | +
|
| 26 | +To make changes to this section, please update the @packageDocumentation section |
| 27 | +of src/index.js or src/index.ts |
| 28 | +
|
| 29 | +To experiment with formatting, please run "npm run docs" from the root of this |
| 30 | +repo and examine the changes made. |
| 31 | +
|
| 32 | +--> |
| 33 | + |
| 34 | +This repository contains TypeScript implementation of noise protocol, an encryption protocol used in libp2p. |
| 35 | + |
| 36 | +## Usage |
| 37 | + |
| 38 | +Install with `yarn add @chainsafe/libp2p-noise` or `npm i @chainsafe/libp2p-noise`. |
| 39 | + |
| 40 | +Example of using default noise configuration and passing it to the libp2p config: |
| 41 | + |
| 42 | +```ts |
| 43 | +import {createLibp2p} from "libp2p" |
| 44 | +import {noise} from "@libp2p/noise" |
| 45 | + |
| 46 | +//custom noise configuration, pass it instead of `noise()` |
| 47 | +//x25519 private key |
| 48 | +const n = noise({ staticNoiseKey }); |
| 49 | + |
| 50 | +const libp2p = await createLibp2p({ |
| 51 | + connectionEncrypters: [noise()], |
| 52 | + //... other options |
| 53 | +}) |
| 54 | +``` |
| 55 | + |
| 56 | +See the [NoiseInit](https://github.com/ChainSafe/js-libp2p-noise/blob/master/src/noise.ts#L22-L30) interface for noise configuration options. |
| 57 | + |
| 58 | +## API |
| 59 | + |
| 60 | +This module exposes an implementation of the [ConnectionEncrypter](https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface.ConnectionEncrypter.html) interface. |
| 61 | + |
| 62 | +## Bring your own crypto |
| 63 | + |
| 64 | +You can provide a custom crypto implementation (instead of the default, based on [@noble](https://paulmillr.com/noble/)) by adding a `crypto` field to the init argument passed to the `Noise` factory. |
| 65 | + |
| 66 | +The implementation must conform to the `ICryptoInterface`, defined in <https://github.com/ChainSafe/js-libp2p-noise/blob/master/src/crypto.ts> |
| 67 | + |
| 68 | +# Install |
| 69 | + |
| 70 | +```console |
| 71 | +$ npm i @chainsafe/libp2p-noise |
| 72 | +``` |
| 73 | + |
| 74 | +## Browser `<script>` tag |
| 75 | + |
| 76 | +Loading this module through a script tag will make its exports available as `ChainsafeLibp2pNoise` in the global namespace. |
| 77 | + |
| 78 | +```html |
| 79 | +<script src="https://unpkg.com/@chainsafe/libp2p-noise/dist/index.min.js"></script> |
| 80 | +``` |
| 81 | + |
| 82 | +# API Docs |
| 83 | + |
| 84 | +- <https://ChainSafe.github.io/js-libp2p-noise> |
| 85 | + |
| 86 | +# License |
| 87 | + |
| 88 | +Licensed under either of |
| 89 | + |
| 90 | +- Apache 2.0, ([LICENSE-APACHE](https://github.com/ChainSafe/js-libp2p-noise/LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>) |
| 91 | +- MIT ([LICENSE-MIT](https://github.com/ChainSafe/js-libp2p-noise/LICENSE-MIT) / <http://opensource.org/licenses/MIT>) |
| 92 | + |
| 93 | +# Contribution |
| 94 | + |
| 95 | +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. |
0 commit comments