From 7eca3a4bcb12c223b0eee6ca975e2648bb0d48a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Tue, 29 Nov 2022 07:22:29 -0500 Subject: [PATCH] fix: readme usage example (#253) * Fix readme usage example - Fixes #252 * fix: lint Co-authored-by: Marin Petrunic --- README.md | 7 ++++--- test/index.spec.ts | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-) 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..35427a7 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -3,6 +3,7 @@ import { expect } from 'aegir/chai' import { duplexPair } from 'it-pair/duplex' import { pbStream } from 'it-pb-stream' import sinon from 'sinon' +import { noise } from '../src/index.js' import { Noise } from '../src/noise.js' import { createPeerIdsFromFixtures } from './fixtures/peer.js' @@ -15,10 +16,10 @@ function createCounterSpy () { describe('Index', () => { it('should expose class with tag and required functions', () => { - const noise = new Noise() - expect(noise.protocol).to.equal('/noise') - expect(typeof (noise.secureInbound)).to.equal('function') - expect(typeof (noise.secureOutbound)).to.equal('function') + const noiseInstance = noise()() + expect(noiseInstance.protocol).to.equal('/noise') + expect(typeof (noiseInstance.secureInbound)).to.equal('function') + expect(typeof (noiseInstance.secureOutbound)).to.equal('function') }) it('should collect metrics', async () => {