Class: BIP151Stream

net.BIP151Stream

new BIP151Stream(cipher)

Represents a BIP151 input or output stream.

Parameters:
Name Type Description
cipher Number
Properties:
Name Type Description
publicKey Buffer
privateKey Buffer
cipher Number
prk Buffer
k1 Buffer
k2 Buffer
sid Buffer
chacha ChaCha20
aead AEAD
tag Buffer
seq Number
processed Number
lastKey Number
Source:

Methods

auth(data) → {Buffer}

Authenticate payload with AEAD (update mac only).

Parameters:
Name Type Description
data Buffer
Source:
Returns:

data

Type
Buffer

decrypt(data) → {Buffer}

Decrypt payload with AEAD (update cipher only).

Parameters:
Name Type Description
data Buffer
Source:
Returns:

data

Type
Buffer

decryptSize(data) → {Number}

Decrypt payload size with k1.

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

encrypt(data) → {Buffer}

Encrypt payload with AEAD (update cipher and mac).

Parameters:
Name Type Description
data Buffer
Source:
Returns:

data

Type
Buffer

encryptSize(data) → {Buffer}

Encrypt a payload size with k1.

Parameters:
Name Type Description
data Buffer
Source:
Returns:
Type
Buffer

finish() → {Buffer}

Finalize AEAD and compute MAC.

Source:
Returns:
Type
Buffer

getPublicKey() → {Buffer}

Get public key tied to private key (not the same as BIP151Stream#publicKey).

Source:
Returns:
Type
Buffer

init(publicKey)

Initialize the stream with peer's public key. Computes ecdh secret and chacha keys.

Parameters:
Name Type Description
publicKey Buffer
Source:

rekey()

Generate new chacha keys with key = HASH256(sid | key). This will reinitialize the state of both ciphers.

Source:

sequence()

Increment packet sequence number and update IVs (note, sequence number overflows after 2^64-1). The IV will be updated without reinitializing cipher state.

Source:

shouldRekey(packet) → {Boolean}

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

Parameters:
Name Type Description
packet Buffer
Source:
Returns:
Type
Boolean

update() → {Buffer}

Render the IV necessary for cipher streams.

Source:
Returns:
Type
Buffer

verify(tag) → {Boolean}

Verify tag against mac in constant time.

Parameters:
Name Type Description
tag Buffer
Source:
Returns:
Type
Boolean