Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: readme usage example #253

Merged
merged 2 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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