Skip to content

Commit 7eca3a4

Browse files
TimDaubmpetrunic
andauthored
fix: readme usage example (#253)
* Fix readme usage example - Fixes #252 * fix: lint Co-authored-by: Marin Petrunic <marin.petrunic@gmail.com>
1 parent 309ec0f commit 7eca3a4

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ Install with `yarn add @chainsafe/libp2p-noise` or `npm i @chainsafe/libp2p-nois
2525
Example of using default noise configuration and passing it to the libp2p config:
2626

2727
```js
28-
import {Noise} from "@chainsafe/libp2p-noise"
28+
import {noise} from "@chainsafe/libp2p-noise"
2929

3030
//custom noise configuration, pass it instead of `new Noise()`
31-
const noise = new Noise(privateKey, Buffer.alloc(x));
31+
//x25519 private key
32+
const n = noise(privateKey);
3233

3334
const libp2p = new Libp2p({
3435
modules: {
35-
connEncryption: [new Noise()],
36+
connEncryption: [noise()],
3637
},
3738
});
3839
```

test/index.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { expect } from 'aegir/chai'
33
import { duplexPair } from 'it-pair/duplex'
44
import { pbStream } from 'it-pb-stream'
55
import sinon from 'sinon'
6+
import { noise } from '../src/index.js'
67
import { Noise } from '../src/noise.js'
78
import { createPeerIdsFromFixtures } from './fixtures/peer.js'
89

@@ -15,10 +16,10 @@ function createCounterSpy () {
1516

1617
describe('Index', () => {
1718
it('should expose class with tag and required functions', () => {
18-
const noise = new Noise()
19-
expect(noise.protocol).to.equal('/noise')
20-
expect(typeof (noise.secureInbound)).to.equal('function')
21-
expect(typeof (noise.secureOutbound)).to.equal('function')
19+
const noiseInstance = noise()()
20+
expect(noiseInstance.protocol).to.equal('/noise')
21+
expect(typeof (noiseInstance.secureInbound)).to.equal('function')
22+
expect(typeof (noiseInstance.secureOutbound)).to.equal('function')
2223
})
2324

2425
it('should collect metrics', async () => {

0 commit comments

Comments
 (0)