diff --git a/packages/web3-eth-accounts/src/account.ts b/packages/web3-eth-accounts/src/account.ts index 1991e1c14bf..16c9c985616 100644 --- a/packages/web3-eth-accounts/src/account.ts +++ b/packages/web3-eth-accounts/src/account.ts @@ -47,7 +47,6 @@ import { bytesToBuffer, bytesToHex, hexToBytes, - isHexStrict, numberToHex, randomBytes, sha3Raw, @@ -55,7 +54,7 @@ import { utf8ToHex, uuidV4, } from 'web3-utils'; -import { isBuffer, isNullish, isString, validator } from 'web3-validator'; +import { isBuffer, isNullish, isString, validator, isHexStrict } from 'web3-validator'; import { keyStoreSchema } from './schemas'; import { SignatureObject, SignResult, SignTransactionResult, Web3Account } from './types'; diff --git a/packages/web3-eth-accounts/test/integration/account.test.ts b/packages/web3-eth-accounts/test/integration/account.test.ts index c748db6ae63..33500068eae 100644 --- a/packages/web3-eth-accounts/test/integration/account.test.ts +++ b/packages/web3-eth-accounts/test/integration/account.test.ts @@ -17,8 +17,7 @@ along with web3.js. If not, see . import defaultImport, * as fullImport from '@ethereumjs/tx'; import { Address } from 'web3-types'; -import { isHexStrict } from 'web3-utils'; -import { Web3ValidatorError } from 'web3-validator'; +import { Web3ValidatorError, isHexStrict } from 'web3-validator'; import { create, decrypt, diff --git a/packages/web3-eth-accounts/test/unit/account.test.ts b/packages/web3-eth-accounts/test/unit/account.test.ts index 8ffa52d52cf..2e70ea33f60 100644 --- a/packages/web3-eth-accounts/test/unit/account.test.ts +++ b/packages/web3-eth-accounts/test/unit/account.test.ts @@ -17,8 +17,7 @@ along with web3.js. If not, see . import defaultImport, * as fullImport from '@ethereumjs/tx'; import { Address } from 'web3-types'; -import { isHexStrict } from 'web3-utils'; -import { Web3ValidatorError } from 'web3-validator'; +import { Web3ValidatorError, isHexStrict } from 'web3-validator'; import { create, decrypt, diff --git a/packages/web3-eth-ens/package.json b/packages/web3-eth-ens/package.json index 3310152dd3e..1134797cbcb 100644 --- a/packages/web3-eth-ens/package.json +++ b/packages/web3-eth-ens/package.json @@ -65,6 +65,7 @@ "web3-eth-contract": "^4.0.1-rc.0", "web3-net": "^4.0.1-rc.0", "web3-types": "^1.0.0-rc.0", - "web3-utils": "^4.0.1-rc.0" + "web3-utils": "^4.0.1-rc.0", + "web3-validator": "1.0.0-rc.0" } } diff --git a/packages/web3-eth-ens/src/registry.ts b/packages/web3-eth-ens/src/registry.ts index c4989ceafe7..cc24ba7f5a2 100644 --- a/packages/web3-eth-ens/src/registry.ts +++ b/packages/web3-eth-ens/src/registry.ts @@ -16,7 +16,8 @@ along with web3.js. If not, see . */ import { Contract, NonPayableCallOptions } from 'web3-eth-contract'; -import { DataFormat, DEFAULT_RETURN_FORMAT, format, isHexStrict, sha3Raw } from 'web3-utils'; +import { DataFormat, DEFAULT_RETURN_FORMAT, format, sha3Raw } from 'web3-utils'; +import { isHexStrict } from 'web3-validator'; import { Address } from 'web3-types'; import { Web3ContextObject } from 'web3-core'; import { ENSRegistryAbi } from './abi/ens/ENSRegistry'; diff --git a/packages/web3-eth-ens/src/resolver.ts b/packages/web3-eth-ens/src/resolver.ts index f204191f2af..7b669845f35 100644 --- a/packages/web3-eth-ens/src/resolver.ts +++ b/packages/web3-eth-ens/src/resolver.ts @@ -15,16 +15,10 @@ You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ -import { - sha3, - isHexStrict, - isNullish, - format, - DEFAULT_RETURN_FORMAT, - DataFormat, -} from 'web3-utils'; +import { sha3, isNullish, format, DEFAULT_RETURN_FORMAT, DataFormat } from 'web3-utils'; import { Contract, NonPayableCallOptions } from 'web3-eth-contract'; import { ResolverMethodMissingError } from 'web3-errors'; +import { isHexStrict } from 'web3-validator'; import { Address } from 'web3-types'; import { interfaceIds, methodsInInterface } from './config'; import { Registry } from './registry'; diff --git a/packages/web3-eth-iban/package.json b/packages/web3-eth-iban/package.json index 2865f67b17f..e9b4511d5d9 100644 --- a/packages/web3-eth-iban/package.json +++ b/packages/web3-eth-iban/package.json @@ -58,6 +58,7 @@ "dependencies": { "web3-errors": "^1.0.0-rc.0", "web3-types": "^1.0.0-rc.0", - "web3-utils": "^4.0.1-rc.0" + "web3-utils": "^4.0.1-rc.0", + "web3-validator": "1.0.0-rc.0" } } diff --git a/packages/web3-eth-iban/src/iban.ts b/packages/web3-eth-iban/src/iban.ts index 4aecddbed7c..86c90013878 100644 --- a/packages/web3-eth-iban/src/iban.ts +++ b/packages/web3-eth-iban/src/iban.ts @@ -16,7 +16,8 @@ along with web3.js. If not, see . */ import { HexString } from 'web3-types'; -import { toChecksumAddress, isAddress, leftPad, hexToNumber } from 'web3-utils'; +import { toChecksumAddress, leftPad, hexToNumber } from 'web3-utils'; +import { isAddress } from 'web3-validator'; import { InvalidAddressError } from 'web3-errors'; import { IbanOptions } from './types'; diff --git a/packages/web3-eth-personal/src/rpc_method_wrappers.ts b/packages/web3-eth-personal/src/rpc_method_wrappers.ts index 7545214fcce..ec15d963529 100644 --- a/packages/web3-eth-personal/src/rpc_method_wrappers.ts +++ b/packages/web3-eth-personal/src/rpc_method_wrappers.ts @@ -15,10 +15,10 @@ You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ import { Web3RequestManager } from 'web3-core'; -import { ETH_DATA_FORMAT, isHexStrict, toChecksumAddress, utf8ToHex } from 'web3-utils'; +import { ETH_DATA_FORMAT, toChecksumAddress, utf8ToHex } from 'web3-utils'; import { formatTransaction } from 'web3-eth'; import { Address, EthPersonalAPI, HexString, Transaction } from 'web3-types'; -import { validator } from 'web3-validator'; +import { validator, isHexStrict } from 'web3-validator'; import { personalRpcMethods } from 'web3-rpc-methods'; export const getAccounts = async (requestManager: Web3RequestManager) => { diff --git a/packages/web3-eth-personal/test/unit/eth_personal.test.ts b/packages/web3-eth-personal/test/unit/eth_personal.test.ts index 7e747a9b535..50bb9d3ab12 100644 --- a/packages/web3-eth-personal/test/unit/eth_personal.test.ts +++ b/packages/web3-eth-personal/test/unit/eth_personal.test.ts @@ -18,17 +18,16 @@ along with web3.js. If not, see . import { ETH_DATA_FORMAT } from 'web3-utils'; import * as utils from 'web3-utils'; import * as eth from 'web3-eth'; -import { validator } from 'web3-validator'; +import * as validator from 'web3-validator'; import { Personal } from '../../src/index'; jest.mock('web3-utils'); jest.mock('web3-eth'); - +jest.mock('web3-validator'); describe('Personal', () => { let personal: Personal; let sendSpy: jest.SpyInstance; let validateSpy: jest.SpyInstance; - beforeEach(() => { personal = new Personal('http://localhost:8545'); @@ -36,7 +35,7 @@ describe('Personal', () => { return Promise.resolve('0x0'); }); - validateSpy = jest.spyOn(validator, 'validate').mockReturnValue(undefined); + validateSpy = jest.spyOn(validator.validator, 'validate').mockReturnValue(undefined); jest.resetAllMocks(); }); @@ -224,7 +223,7 @@ describe('Personal', () => { it('should call the correct method for request manager', async () => { const data = '0x1234'; - jest.spyOn(utils, 'isHexStrict').mockReturnValue(true); + jest.spyOn(validator, 'isHexStrict').mockReturnValue(true); await personal.sign(data, '0x528ABBBa47c33600245066398072799A9b7e2d9E', 'password'); @@ -237,7 +236,7 @@ describe('Personal', () => { it('should convert input if not hex', async () => { const data = '0x1234'; - jest.spyOn(utils, 'isHexStrict').mockReturnValue(false); + jest.spyOn(validator, 'isHexStrict').mockReturnValue(false); jest.spyOn(utils, 'utf8ToHex').mockReturnValue(data); await personal.sign(data, '0x528ABBBa47c33600245066398072799A9b7e2d9E', 'password'); @@ -249,7 +248,7 @@ describe('Personal', () => { it('should not convert input if data is already hex', async () => { const data = '0x1234'; - jest.spyOn(utils, 'isHexStrict').mockReturnValue(true); + jest.spyOn(validator, 'isHexStrict').mockReturnValue(true); await personal.sign(data, '0x528ABBBa47c33600245066398072799A9b7e2d9E', 'password'); @@ -259,7 +258,7 @@ describe('Personal', () => { it('should validate user input', async () => { const data = '0x1234'; - jest.spyOn(utils, 'isHexStrict').mockReturnValue(true); + jest.spyOn(validator, 'isHexStrict').mockReturnValue(true); await personal.sign(data, '0x528ABBBa47c33600245066398072799A9b7e2d9E', 'password'); @@ -275,7 +274,7 @@ describe('Personal', () => { it('should call the correct method for request manager', async () => { const data = '0x1234'; - jest.spyOn(utils, 'isHexStrict').mockReturnValue(true); + jest.spyOn(validator, 'isHexStrict').mockReturnValue(true); await personal.ecRecover(data, '0x000000'); @@ -288,7 +287,7 @@ describe('Personal', () => { it('should convert input if not hex', async () => { const data = '0x1234'; - jest.spyOn(utils, 'isHexStrict').mockReturnValue(false); + jest.spyOn(validator, 'isHexStrict').mockReturnValue(false); jest.spyOn(utils, 'utf8ToHex').mockReturnValue(data); await personal.ecRecover(data, 'password'); @@ -300,7 +299,7 @@ describe('Personal', () => { it('should not convert input if data is already hex', async () => { const data = '0x1234'; - jest.spyOn(utils, 'isHexStrict').mockReturnValue(true); + jest.spyOn(validator, 'isHexStrict').mockReturnValue(true); await personal.ecRecover(data, 'password'); @@ -310,7 +309,7 @@ describe('Personal', () => { it('should validate user input', async () => { const data = '0x1234'; - jest.spyOn(utils, 'isHexStrict').mockReturnValue(true); + jest.spyOn(validator, 'isHexStrict').mockReturnValue(true); await personal.ecRecover(data, 'password'); diff --git a/packages/web3-eth/src/utils/transaction_builder.ts b/packages/web3-eth/src/utils/transaction_builder.ts index 324a8d07e1a..22069295f62 100644 --- a/packages/web3-eth/src/utils/transaction_builder.ts +++ b/packages/web3-eth/src/utils/transaction_builder.ts @@ -15,14 +15,7 @@ You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ -import { - DEFAULT_RETURN_FORMAT, - ETH_DATA_FORMAT, - FormatType, - format, - DataFormat, - isAddress, -} from 'web3-utils'; +import { DEFAULT_RETURN_FORMAT, ETH_DATA_FORMAT, FormatType, format, DataFormat } from 'web3-utils'; import { EthExecutionAPI, Address, @@ -40,7 +33,7 @@ import { import { Web3Context } from 'web3-core'; import { privateKeyToAddress } from 'web3-eth-accounts'; import { getId } from 'web3-net'; -import { isNullish, isNumber, isHexStrict } from 'web3-validator'; +import { isNullish, isNumber, isHexStrict, isAddress } from 'web3-validator'; import { InvalidTransactionWithSender, InvalidTransactionWithReceiver, diff --git a/tsconfig.base.json b/tsconfig.base.json index acdac558e23..89284cbdad8 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -10,7 +10,7 @@ "noUnusedLocals": true, "noUnusedParameters": true, "pretty": true, - "removeComments": true, + "removeComments": false, "sourceMap": true, "strict": true, "strictNullChecks": true,