Skip to content

Commit

Permalink
Fix readme usage example
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDaub committed Nov 29, 2022
1 parent 309ec0f commit 2b273ee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 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
8 changes: 8 additions & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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')
Expand Down

0 comments on commit 2b273ee

Please sign in to comment.