How to use the safe-buffer.Buffer.concat function in safe-buffer

To help you get started, we’ve selected a few safe-buffer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ethereumjs / ethereumjs-devp2p / src / rlpx / ecies.js View on Github external
_encryptMessage (data, sharedMacData = null) {
    const privateKey = util.genPrivateKey()
    const x = ecdhX(this._remotePublicKey, privateKey)
    const key = concatKDF(x, 32)
    const ekey = key.slice(0, 16) // encryption key
    const mkey = crypto.createHash('sha256').update(key.slice(16, 32)).digest() // MAC key

    // encrypt
    const IV = crypto.randomBytes(16)
    const cipher = crypto.createCipheriv('aes-128-ctr', ekey, IV)
    const encryptedData = cipher.update(data)
    const dataIV = Buffer.concat([ IV, encryptedData ])

    // create tag
    if (!sharedMacData) {
      sharedMacData = Buffer.from([])
    }
    const tag = crypto.createHmac('sha256', mkey).update(Buffer.concat([dataIV, sharedMacData])).digest()

    const publicKey = secp256k1.publicKeyCreate(privateKey, false)
    return Buffer.concat([ publicKey, dataIV, tag ])
  }
github ioBroker / ioBroker.mqtt / lib / writeToStream.js View on Github external
var buffer = Buffer.concat([
    // Header
    protocol.PUBLISH_HEADER[qos][opts.dup ? 1 : 0][retain ? 1 : 0],
    // Remaining length
    genBufLengthCached(length),
    // Topic length
    numCache[byteLength(topic)],
    // Topic text
    new Buffer(topic)])

  // Message ID
  if (qos > 0) buffer = Buffer.concat([buffer, numCache[id]])

  // payload
  buffer = Buffer.concat([buffer, new Buffer(payload)])

  return stream.write(buffer)
}
github LayerXcom / plasma-mvp-vyper / test / helpers / transaction.js View on Github external
merkleHash() {
        return utils.sha3(Buffer.concat([this.hash(false), this.sig1, this.sig2]))
    }
github particle-iot / particle-cli / src / lib / serial-batch-parser.js View on Github external
_transform(chunk, encoding, cb) {
		this.buffer = Buffer.concat([this.buffer, chunk]);
		this.updateTimer();
		cb();
	}
github ethereumjs / ethereumjs-devp2p / src / util.js View on Github external
function keccak256 (...buffers) {
  const buffer = Buffer.concat(buffers)
  return createKeccakHash('keccak256').update(buffer).digest()
}
github voltairelabs / plasma / src / chain / txpool.js View on Github external
keyForTx(tx) {
    return Buffer.concat([config.prefixes.txpool, tx.merkleHash()])
  }
}
github voltairelabs / plasma / src / chain / block.js View on Github external
getMerkleProof(txIndex) {
    if (txIndex < 0 || txIndex >= this.transactions.length) {
      return null
    }

    const merkleHashes = this.transactions.map(tx => tx.merkleHash())
    const tree = new FixedMerkleTree(16, merkleHashes)
    return {
      root: tree.getRoot(),
      leaf: this.transactions[txIndex].merkleHash(),
      proof: Buffer.concat(
        tree.getPlasmaProof(this.transactions[txIndex].merkleHash())
      )
    }
  }
}
github hazelcast / hazelcast-nodejs-client / src / invocation / ClientConnection.ts View on Github external
private readFrameSize(): number {
        if (this.chunks[0].length >= BitsUtil.INT_SIZE_IN_BYTES) {
            return this.chunks[0].readInt32LE(0);
        }
        let readChunksSize = 0;
        for (let i = 0; i < this.chunks.length; i++) {
            readChunksSize += this.chunks[i].length;
            if (readChunksSize >= BitsUtil.INT_SIZE_IN_BYTES) {
                const merged = Buffer.concat(this.chunks.slice(0, i + 1), readChunksSize);
                return merged.readInt32LE(0);
            }
        }
        throw new Error('Detected illegal internal call in FrameReader!');
    }
}
github libp2p / js-iprs-record / src / record.js View on Github external
blobForSignature () {
    return Buffer.concat([
      Buffer.from(this.key),
      this.value,
      this.author.id
    ])
  }