From f44645ef7e918ca0d5e160b28b9f2da71319f168 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Tue, 18 Feb 2020 08:42:39 -0500 Subject: [PATCH] fix: remove use of assert module (#117) The polyfill is big, we can simulate it by throwing an Error and it doesn't work under React Native. --- src/index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 6cb15d7..d7257b2 100644 --- a/src/index.js +++ b/src/index.js @@ -7,16 +7,17 @@ const mh = require('multihashes') const CID = require('cids') const cryptoKeys = require('libp2p-crypto/src/keys') -const assert = require('assert') const withIs = require('class-is') const { PeerIdProto } = require('./proto') class PeerId { constructor (id, privKey, pubKey) { - assert(Buffer.isBuffer(id), 'invalid id provided') + if (!Buffer.isBuffer(id)) { + throw new Error('invalid id provided') + } - if (privKey && pubKey) { - assert(privKey.public.bytes.equals(pubKey.bytes), 'inconsistent arguments') + if (privKey && pubKey && !privKey.public.bytes.equals(pubKey.bytes)) { + throw new Error('inconsistent arguments') } this._id = id