Class: BIP151

net.BIP151

new BIP151(cipher)

Represents a BIP151 input and output stream. Holds state for peer communication.

Parameters:
Name Type Description
cipher Number
Properties:
Name Type Description
input BIP151Stream
output BIP151Stream
initReceived Boolean
ackReceived Boolean
initSent Boolean
ackSent Boolean
timeout Object
job Job
completed Boolean
handshake Boolean
Source:

Members

(static) ciphers :Number

Cipher list.

Type:
  • Number
Properties:
Name Type Description
CHACHAPOLY Number
Source:

(static, constant) MAX_MESSAGE :Number

Max message size.

Type:
  • Number
Source:

Methods

(private) _wait(timeout, resolve, reject)

Set a timeout and wait for handshake to complete.

Parameters:
Name Type Description
timeout Number
resolve function
reject function
Source:

cleanup() → {Job}

Cleanup handshake job.

Source:
Returns:
Type
Job

destroy()

Destroy BIP151 state and streams.

Source:

encack(data)

Handle encack from remote peer.

Parameters:
Name Type Description
data Buffer
Source:

encinit(publicKey)

Handle encinit from remote peer.

Parameters:
Name Type Description
publicKey Buffer
Source:

error(…msg)

Emit an error.

Parameters:
Name Type Attributes Description
msg String <repeatable>
Source:

feed(data)

Feed ciphertext payload chunk to the input stream. Potentially emits a packet event.

Parameters:
Name Type Description
data Buffer
Source:

isReady() → {Boolean}

Test whether handshake has completed.

Source:
Returns:
Type
Boolean

maybeRekey(packet)

Add buffer size to processed, check whether we need to rekey.

Parameters:
Name Type Description
packet Buffer
Source:

packet(cmd, body) → {Buffer}

Frame plaintext payload for the output stream.

Parameters:
Name Type Description
cmd String
body Buffer
Source:
Returns:

Ciphertext payload

Type
Buffer

packetSize(cmd, body) → {Number}

Calculate packet size.

Parameters:
Name Type Description
cmd String
body Buffer
Source:
Returns:
Type
Number

parse(data)

Parse a ciphertext payload chunk. Potentially emits a packet event.

Parameters:
Name Type Description
data Buffer
Source:

read(size) → {Buffer}

Read and consume a number of bytes from the buffered stream.

Parameters:
Name Type Description
size Number
Source:
Returns:
Type
Buffer

reject(err)

Complete the timeout for handshake with error.

Parameters:
Name Type Description
err Error
Source:

resolve(result)

Complete the timeout for handshake.

Parameters:
Name Type Description
result Object
Source:

toEncack() → {Buffer}

Render encack packet. Contains the output stream public key.

Source:
Returns:
Type
Buffer

toEncinit() → {Buffer}

Render an encinit packet. Contains the input public key and cipher number.

Source:
Returns:
Type
Buffer

toRekey() → {Buffer}

Render encack packet with an all zero public key, notifying of a rekey for the output stream.

Source:
Returns:
Type
Buffer

wait(timeout) → {Promise}

Set a timeout and wait for handshake to complete.

Parameters:
Name Type Description
timeout Number

Timeout in ms.

Source:
Returns:
Type
Promise