Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add addressValidator function to eliminate hubAddress type error afte… #257

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@circles/core",
"version": "4.10.0",
"version": "4.11.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not create a new version in a PR.
Do it with a testing version:
with git describe you get the new tag name, and you use it for creating a new npm package (Follow step 6 and continue...

"description": "Common methods to interact with the Circles ecosystem",
"main": "lib/index.js",
"contributors": [
Expand Down
14 changes: 14 additions & 0 deletions src/common/checkOptions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import CoreError, { ErrorCodes } from '~/common/error';
import web3 from 'web3';

const DEFAULT_TYPE = 'string';

Expand Down Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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',
Expand Down
Loading