diff --git a/packages/cli/src/util/feeRecipient.ts b/packages/cli/src/util/feeRecipient.ts index 4d6d1f3e5833..4b3d147ce95f 100644 --- a/packages/cli/src/util/feeRecipient.ts +++ b/packages/cli/src/util/feeRecipient.ts @@ -1,16 +1,9 @@ import {ExecutionAddress} from "@chainsafe/lodestar-types"; import {fromHex} from "@chainsafe/lodestar-utils"; -export function parseFeeRecipientHex(feeRecipientHexString: string): string { - const hexPattern = new RegExp(/^(0x|0X)(?[a-fA-F0-9]{40})$/, "g"); - const feeRecipientStringMatch = hexPattern.exec(feeRecipientHexString); - const feeRecipientString = feeRecipientStringMatch?.groups?.feeRecipientString; - if (feeRecipientString === undefined) - throw Error(`Invalid feeRecipient= ${feeRecipientHexString}, expected format: ^0x[a-fA-F0-9]{40}$`); - return feeRecipientString; -} - -export function parseFeeRecipient(feeRecipientHexString: string): ExecutionAddress { - const feeRecipientHex = parseFeeRecipientHex(feeRecipientHexString); - return fromHex(feeRecipientHex); +export function parseFeeRecipient(feeRecipientHex: string): ExecutionAddress { + if (!/^0x[a-fA-F0-9]{40}$/i.test(feeRecipientHex)) { + throw Error(`Invalid feeRecipient= ${feeRecipientHex}, expected format: ^0x[a-fA-F0-9]{40}$`); + } + return fromHex(feeRecipientHex.toLowerCase()); } diff --git a/packages/cli/test/unit/validator/options.test.ts b/packages/cli/test/unit/validator/options.test.ts index 7c2211c5dcd1..5d20d22cc11a 100644 --- a/packages/cli/test/unit/validator/options.test.ts +++ b/packages/cli/test/unit/validator/options.test.ts @@ -4,7 +4,7 @@ import {parseFeeRecipient} from "../../../src/util"; const feeRecipient = Buffer.from(Array.from({length: 20}, () => Math.round(Math.random() * 255))); const feeRecipientString = feeRecipient.toString("hex"); -describe("parseFeeRecipient", () => { +describe("validator / parseFeeRecipient", () => { const testCases: string[] = [`0x${feeRecipientString}`, `0X${feeRecipientString}`]; for (const testCase of testCases) { it(`parse ${testCase}`, () => { @@ -13,7 +13,7 @@ describe("parseFeeRecipient", () => { } }); -describe("invalid feeRecipient", () => { +describe("validator / invalid feeRecipient", () => { const testCases: string[] = [ feeRecipientString, `X0${feeRecipientString}`,