# noise-secret-stream

> Secret stream backed by Noise and libsodium's secretstream

Latest version **4.2.0** (published 2021-09-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install noise-secret-stream
pnpm add noise-secret-stream
yarn add noise-secret-stream
bun add noise-secret-stream
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 4.2.0 |
| Published | 2021-09-28 |
| First published | 2021-02-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 25.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 40 |
| Author | Mathias Buus |
| Maintainers | mafintosh |

## Links

- npm: https://www.npmjs.com/package/noise-secret-stream
- Repository: https://github.com/mafintosh/noise-secret-stream
- Issues: https://github.com/mafintosh/noise-secret-stream/issues
- npm.io page: https://npm.io/package/noise-secret-stream

## Dependencies (5)

- [streamx](https://npm.io/package/streamx.md) ^2.10.2
- [noise-curve-ed](https://npm.io/package/noise-curve-ed.md) ^1.0.2
- [noise-handshake](https://npm.io/package/noise-handshake.md) ^2.1.0
- [sodium-universal](https://npm.io/package/sodium-universal.md) ^3.0.4
- [sodium-secretstream](https://npm.io/package/sodium-secretstream.md) ^1.0.0

## Recent versions

- 4.2.0 (latest) — 2021-09-28
- 4.1.2 — 2021-09-23
- 4.1.1 — 2021-09-22
- 4.1.0 — 2021-09-22
- 4.0.0 — 2021-09-22
- 3.1.1 — 2021-06-18
- 3.1.0 — 2021-06-16
- 3.0.2 — 2021-06-11
- 3.0.1 — 2021-06-07
- 3.0.0 — 2021-06-07
- 2.0.2 — 2021-04-15
- 2.0.1 — 2021-04-15
- 2.0.0 — 2021-04-15
- 1.0.0 — 2021-02-21

## README

# noise-secret-stream

Secret stream backed by Noise and libsodium's secretstream

```
npm install noise-secret-stream
```

## Usage

You can either make a secret stream from an existing transport stream.

``` js
const NoiseSecretStream = require('noise-secret-stream')

const a = new NoiseSecretStream(true, tcpClientStream)
const b = new NoiseSecretStream(false, tcpServerStream)

// pipe the underlying rawstreams together

a.write(Buffer.from('hello encrypted!'))

b.on('data', function (data) {
  console.log(data) // <Buffer hello encrypted!>
})
```

Or by making your own pipeline

``` js
const a = new NoiseSecretStream(true)
const b = new NoiseSecretStream(false)

// pipe the underlying rawstreams together
a.rawStream.pipe(b.rawStream).pipe(a.rawStream)

a.write(Buffer.from('hello encrypted!'))

b.on('data', function (data) {
  console.log(data) // <Buffer hello encrypted!>
})
```

## API

#### `const s = new NoiseSecretStream(isInitiator, [rawStream], [options])`

Make a new stream. `isInitiator` is a boolean indication whether you are the client or the server.
`rawStream` can be set to an underlying transport stream you want to run the noise stream over.

Options include:

```js
{
  pattern: 'XX', // which noise pattern to use
  remotePublicKey, // set if your handshake requires it
  keyPair: { publicKey, secretKey },
  handshake: { // if you want to use an handshake performed elsewhere pass it here
    tx,
    rx,
    handshakeHash,
    publicKey,
    remotePublicKey
  }
}
```

The NoiseSecretStream returned is a Duplex stream that you use as as normal stream, to write/read data from,
except it's payloads are encrypted using the libsodium secretstream.

Note that this uses ed25519 for the handshakes per default.

#### `s.start(rawStream, [options])`

Start a NoiseSecretStream from a rawStream asynchrously.

``` js
const s = new NoiseSecretStream({
  autoStart: false // call start manually
})

// ... do async stuff or destroy the stream

s.start(rawStream, {
  ... options from above
})
```

#### `keyPair = NoiseSecretStream.keyPair([seed])`

Generate a ed25519 key pair.

#### `s.publicKey`

Get the local public key.

#### `s.remotePublicKey`

Get the remote's public key.
Populated after `open` is emitted.

#### `s.handshakeHash`

Get the unique hash of this handshake.
Populated after `open` is emitted.

## License

MIT

---
_Source: https://npm.io/package/noise-secret-stream · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
