src/net/bip151.js
function BIP151Stream(cipher) {
  if (!(this instanceof BIP151Stream))
    return new BIP151Stream(cipher);

  this.cipher = BIP151.ciphers.CHACHAPOLY;
  this.privateKey = secp256k1.generatePrivateKey();
  this.publicKey = null;
  this.k1 = null;
  this.k2 = null;
  this.sid = null;

  if (cipher != null) {
    assert(cipher === BIP151.ciphers.CHACHAPOLY, 'Unknown cipher type.');
    this.cipher = cipher;
  }

  this.chacha = new ChaCha20();
  this.aead = new AEAD();
  this.tag = null;
  this.seq = 0;
  this.iv = Buffer.allocUnsafe(8);
  this.iv.fill(0);

  this.processed = 0;
  this.lastRekey = 0;
}
function BIP151Stream(cipher) {
  if (!(this instanceof BIP151Stream))
    return new BIP151Stream(cipher);

  this.cipher = BIP151.ciphers.CHACHAPOLY;
  this.privateKey = secp256k1.generatePrivateKey();
  this.publicKey = null;
  this.k1 = null;
  this.k2 = null;
  this.sid = null;

  if (cipher != null) {
    assert(cipher === BIP151.ciphers.CHACHAPOLY, 'Unknown cipher type.');
    this.cipher = cipher;
  }

  this.chacha = new ChaCha20();
  this.aead = new AEAD();
  this.tag = null;
  this.seq = 0;
  this.iv = Buffer.allocUnsafe(8);
  this.iv.fill(0);

  this.processed = 0;
  this.lastRekey = 0;
}
function BIP151Stream ( cipher ) { if ( ! ( this instanceof BIP151Stream ) ) return new BIP151Stream ( cipher ) ; this . cipher = BIP151 . ciphers . CHACHAPOLY ; this . privateKey = secp256k1 . generatePrivateKey ( ) ; this . publicKey = null ; this . k1 = null ; this . k2 = null ; this . sid = null ; if ( cipher != null ) { assert ( cipher === BIP151 . ciphers . CHACHAPOLY , 'Unknown cipher type.' ) ; this . cipher = cipher ; } this . chacha = new ChaCha20 ( ) ; this . aead = new AEAD ( ) ; this . tag = null ; this . seq = 0 ; this . iv = Buffer . allocUnsafe ( 8 ) ; this . iv . fill ( 0 ) ; this . processed = 0 ; this . lastRekey = 0 ; }
Represents a BIP151 input or output stream.
@alias module:net.BIP151Stream
@constructor
@param {Number} cipher
@property {Buffer} publicKey
@property {Buffer} privateKey
@property {Number} cipher
@property {Buffer} k1
@property {Buffer} k2
@property {Buffer} sid
@property {ChaCha20} chacha
@property {AEAD} aead
@property {Buffer} tag
@property {Number} seq
@property {Number} processed
@property {Number} lastKey
Represents a BIP151 input or output stream .