Skip to content

Commit

Permalink
fix: readme usage example (#253)
Browse files Browse the repository at this point in the history
* Fix readme usage example

- Fixes #252

* fix: lint

Co-authored-by: Marin Petrunic <[email protected]>
  • Loading branch information
TimDaub and mpetrunic authored Nov 29, 2022
1 parent 309ec0f commit 7eca3a4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()],
},
});
```
Expand Down
9 changes: 5 additions & 4 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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 () => {
Expand Down

0 comments on commit 7eca3a4

Please sign in to comment.