This repository contains TypeScript implementation of noise protocol, an encryption protocol used in libp2p.
Formerly published as @chainsafe/libp2p-noise.
@chainsafe/libp2p-noise
Install with npm i @libp2p/noise.
npm i @libp2p/noise
Example of using default noise configuration and passing it to the libp2p config:
import { createLibp2p } from 'libp2p'import { noise } from '@libp2p/noise'const libp2p = await createLibp2p({ connectionEncrypters: [noise()], // ... other options}) Copy
import { createLibp2p } from 'libp2p'import { noise } from '@libp2p/noise'const libp2p = await createLibp2p({ connectionEncrypters: [noise()], // ... other options})
See the NoiseInit interface for noise configuration options.
To use a fixed x25519 static key instead of generating one per session, pass it as staticNoiseKey:
staticNoiseKey
import { createLibp2p } from 'libp2p'import { noise, pureJsCrypto } from '@libp2p/noise'const staticNoiseKey = pureJsCrypto.generateX25519KeyPair().privateKeyconst node = await createLibp2p({ connectionEncrypters: [noise({ staticNoiseKey })]}) Copy
import { createLibp2p } from 'libp2p'import { noise, pureJsCrypto } from '@libp2p/noise'const staticNoiseKey = pureJsCrypto.generateX25519KeyPair().privateKeyconst node = await createLibp2p({ connectionEncrypters: [noise({ staticNoiseKey })]})
This module exposes an implementation of the ConnectionEncrypter interface.
You can provide a custom crypto implementation (instead of the default, based on @noble) by adding a crypto field to the init argument passed to the Noise factory.
crypto
Noise
The implementation must conform to the ICryptoInterface, defined in https://github.com/libp2p/js-libp2p/blob/main/packages/connection-encrypter-noise/src/crypto.ts
ICryptoInterface
This repository contains TypeScript implementation of noise protocol, an encryption protocol used in libp2p.
Formerly published as
@chainsafe/libp2p-noise.Usage
Install with
npm i @libp2p/noise.Example of using default noise configuration and passing it to the libp2p config:
See the NoiseInit interface for noise configuration options.
To use a fixed x25519 static key instead of generating one per session, pass it as
staticNoiseKey:API
This module exposes an implementation of the ConnectionEncrypter interface.
Bring your own crypto
You can provide a custom crypto implementation (instead of the default, based on @noble) by adding a
cryptofield to the init argument passed to theNoisefactory.The implementation must conform to the
ICryptoInterface, defined in https://github.com/libp2p/js-libp2p/blob/main/packages/connection-encrypter-noise/src/crypto.ts