chore: Simplify error checking.

This commit is contained in:
Hayden Young 2023-06-18 19:33:48 +01:00
parent 7fafda8416
commit 4e5b6bb597

View File

@ -33,12 +33,12 @@ const hashStringEncoding = base58btc
* @instance * @instance
*/ */
const Identity = async ({ id, publicKey, signatures, type, sign, verify } = {}) => { const Identity = async ({ id, publicKey, signatures, type, sign, verify } = {}) => {
if (id == null) throw new Error('Identity id is required') if (!id) throw new Error('Identity id is required')
if (publicKey == null) throw new Error('Invalid public key') if (!publicKey) throw new Error('Invalid public key')
if (signatures == null) throw new Error('Signatures object is required') if (!signatures) throw new Error('Signatures object is required')
if (signatures.id == null) throw new Error('Signature of id is required') if (!signatures.id) throw new Error('Signature of id is required')
if (signatures.publicKey == null) throw new Error('Signature of publicKey+id is required') if (!signatures.publicKey) throw new Error('Signature of publicKey+id is required')
if (type == null) throw new Error('Identity type is required') if (!type) throw new Error('Identity type is required')
signatures = Object.assign({}, signatures) signatures = Object.assign({}, signatures)
@ -90,14 +90,14 @@ const decodeIdentity = async (bytes) => {
* @static * @static
*/ */
const isIdentity = (identity) => { const isIdentity = (identity) => {
return identity.id != null && return Boolean(identity.id &&
identity.hash != null && identity.hash &&
identity.bytes != null && identity.bytes &&
identity.publicKey != null && identity.publicKey &&
identity.signatures != null && identity.signatures &&
identity.signatures.id != null && identity.signatures.id &&
identity.signatures.publicKey != null && identity.signatures.publicKey &&
identity.type != null identity.type)
} }
/** /**