From 5515d74910ba9c3311e27d748a362bf096e72bc2 Mon Sep 17 00:00:00 2001 From: mikozet Date: Wed, 7 Aug 2024 10:40:12 +0200 Subject: [PATCH] Add addressValidator function to eliminate hubAddress type error after node 20 update --- package.json | 2 +- src/common/checkOptions.js | 14 ++++++++++++++ src/index.js | 10 +++++----- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index ef883d89..2e0c4d8b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@circles/core", - "version": "4.10.0", + "version": "4.11.0", "description": "Common methods to interact with the Circles ecosystem", "main": "lib/index.js", "contributors": [ diff --git a/src/common/checkOptions.js b/src/common/checkOptions.js index 82a8735c..d26c23b0 100644 --- a/src/common/checkOptions.js +++ b/src/common/checkOptions.js @@ -1,4 +1,5 @@ import CoreError, { ErrorCodes } from '~/common/error'; +import web3 from 'web3'; const DEFAULT_TYPE = 'string'; @@ -34,6 +35,19 @@ function safelyValidate(validatorFn, value) { } } +/** + * Validate a given Ethereum address by checking its format and checksum. + * + * @access public + * + * @param {String} address - The Ethereum address to validate. + */ +export function addressValidator(address) { + return ( + web3.utils.isAddress(address) && web3.utils.checkAddressChecksum(address) + ); +} + /** * Check for required option fields, validate them and use fallback value when * default is given. diff --git a/src/index.js b/src/index.js index f20d8e9d..94aeec69 100644 --- a/src/index.js +++ b/src/index.js @@ -4,7 +4,7 @@ import CoreError, { TransferError, } from '~/common/error'; -import checkOptions from '~/common/checkOptions'; +import checkOptions, { addressValidator } from '~/common/checkOptions'; import getContracts from '~/common/getContracts'; import createActivityModule from '~/activity'; @@ -50,16 +50,16 @@ export default class CirclesCore { /** @type {Object} - global core options */ this.options = checkOptions(options, { hubAddress: { - type: web3.utils.checkAddressChecksum, + type: addressValidator, }, proxyFactoryAddress: { - type: web3.utils.checkAddressChecksum, + type: addressValidator, }, safeMasterAddress: { - type: web3.utils.checkAddressChecksum, + type: addressValidator, }, fallbackHandlerAddress: { - type: web3.utils.checkAddressChecksum, + type: addressValidator, }, graphNodeEndpoint: { type: 'string',