From 4e5b6bb597b85f6371a685b510e8bbd96ef3168e Mon Sep 17 00:00:00 2001 From: Hayden Young Date: Sun, 18 Jun 2023 19:33:48 +0100 Subject: [PATCH] chore: Simplify error checking. --- src/identities/identity.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/identities/identity.js b/src/identities/identity.js index 32db82b..fcf52e6 100644 --- a/src/identities/identity.js +++ b/src/identities/identity.js @@ -33,12 +33,12 @@ const hashStringEncoding = base58btc * @instance */ const Identity = async ({ id, publicKey, signatures, type, sign, verify } = {}) => { - if (id == null) throw new Error('Identity id is required') - if (publicKey == null) throw new Error('Invalid public key') - if (signatures == null) throw new Error('Signatures object is required') - if (signatures.id == null) throw new Error('Signature of id is required') - if (signatures.publicKey == null) throw new Error('Signature of publicKey+id is required') - if (type == null) throw new Error('Identity type is required') + if (!id) throw new Error('Identity id is required') + if (!publicKey) throw new Error('Invalid public key') + if (!signatures) throw new Error('Signatures object is required') + if (!signatures.id) throw new Error('Signature of id is required') + if (!signatures.publicKey) throw new Error('Signature of publicKey+id is required') + if (!type) throw new Error('Identity type is required') signatures = Object.assign({}, signatures) @@ -90,14 +90,14 @@ const decodeIdentity = async (bytes) => { * @static */ const isIdentity = (identity) => { - return identity.id != null && - identity.hash != null && - identity.bytes != null && - identity.publicKey != null && - identity.signatures != null && - identity.signatures.id != null && - identity.signatures.publicKey != null && - identity.type != null + return Boolean(identity.id && + identity.hash && + identity.bytes && + identity.publicKey && + identity.signatures && + identity.signatures.id && + identity.signatures.publicKey && + identity.type) } /**