Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

basic-noise

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

basic-noise

## Usage ```js const Noise = require('basic-noise') const initiator = new Noise('IK ', true) const responder = new Noise('IK', false)

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

basic-noise

Usage

const Noise = require('basic-noise')
const initiator = new Noise('IK ', true)
const responder = new Noise('IK', false)

const prologue = Buffer.alloc(0)

// preshared key
initiator.initialise(prologue, responder.s.pub)
responder.initialise(prologue)

// -> e, es, s, ss
const message = initiator.send()
responder.recv(message)

// <- e, ee, se
const reply = responder.send()
initiator.recv(reply)

console.log(initiator.handshakeComplete) // true

const msg = Buffer.from('hello, world')

const enc = initiator.rx.encrypt(msg)
console.log(responder.tx.decrypt(enc)) // hello, world

API

const peer = new Noise(pattern, initiator, staticKeypair)

Create a new handshake state for a given pattern. Initiator should be either true or false depending on the role. A preexisting keypair may be passed as staticKeypair

peer.initialise(prologue, remoteStatic)

Initialise the handshake state with a prologue and any preshared keys.

const buf = send([payload])

Send the next message in the handshake, add an optional payload buffer to be included in the message, payload is a zero length buffer by default.

const payload = peer.recv(buf)

Receive a handshake message from the peer and return the encrypted payload.

peer.handshakeComplete

true or false. Indicates whether rx and tx have been created yet.

const ciphertext = peer.rx.encrypt(plaintext, [ad])

Encrypt a message to the remote peer with an optional authenticated data passed in as ad.

const plaintext = peer.tx.decrypt(ciphertext, [ad])

Decrypt a ciphertext from the remote peer. Note initiator.rx is decrypted by responder.tx and vice versa. If the message was encrypted with authenticated data, this must be passed in as ad otherwise decryption shall fail

FAQs

Package last updated on 24 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc