diff --git a/README.md b/README.md index 1f0cbd9..237d12a 100644 --- a/README.md +++ b/README.md @@ -25,14 +25,15 @@ Install with `yarn add @chainsafe/libp2p-noise` or `npm i @chainsafe/libp2p-nois Example of using default noise configuration and passing it to the libp2p config: ```js -import {Noise} from "@chainsafe/libp2p-noise" +import {noise} from "@chainsafe/libp2p-noise" //custom noise configuration, pass it instead of `new Noise()` -const noise = new Noise(privateKey, Buffer.alloc(x)); +//x25519 private key +const n = noise(privateKey); const libp2p = new Libp2p({ modules: { - connEncryption: [new Noise()], + connEncryption: [noise()], }, }); ``` diff --git a/test/index.spec.ts b/test/index.spec.ts index 6158511..2e445d8 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -4,7 +4,9 @@ import { duplexPair } from 'it-pair/duplex' import { pbStream } from 'it-pb-stream' import sinon from 'sinon' import { Noise } from '../src/noise.js' +import { noise } from '../src/index.js' import { createPeerIdsFromFixtures } from './fixtures/peer.js' +import { stablelib } from '../src/crypto/stablelib.js' function createCounterSpy () { return sinon.spy({ @@ -14,6 +16,12 @@ function createCounterSpy () { } describe('Index', () => { + it('should run the readme.md example', () => { + const staticNoiseKey = stablelib.generateX25519KeyPair().privateKey; + noise({staticNoiseKey}); + noise(); + }) + it('should expose class with tag and required functions', () => { const noise = new Noise() expect(noise.protocol).to.equal('/noise')