fix: remove use of assert module (#561)

* fix: remove use of assert module

The polyfill is big, we can simulate it by throwing an Error and it doesn't work under React Native.

* chore: fix linting

* chore: export invalid param code

Co-authored-by: Jacob Heun <jacobheun@gmail.com>
This commit is contained in:
Alex Potsides
2020-02-14 13:42:23 +00:00
committed by GitHub
parent 0882dcea3b
commit a8984c6cd3
5 changed files with 53 additions and 20 deletions

View File

@ -1,10 +1,13 @@
'use strict'
const pipe = require('it-pipe')
const assert = require('assert')
const errcode = require('err-code')
const duplexPair = require('it-pair/duplex')
const crypto = require('libp2p-crypto')
const Errors = require('./errors')
const {
ERR_INVALID_PARAMETERS
} = require('../errors')
const {
createBoxStream,
createUnboxStream,
@ -40,7 +43,9 @@ class Protector {
* @returns {*} A protected duplex iterable
*/
async protect (connection) {
assert(connection, Errors.NO_HANDSHAKE_CONNECTION)
if (!connection) {
throw errcode(new Error(Errors.NO_HANDSHAKE_CONNECTION), ERR_INVALID_PARAMETERS)
}
// Exchange nonces
log('protecting the connection')