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
Improve isValidAddress validation #4440
Conversation
Performance Report✔️ no performance regression detected Full benchmark results
|
@@ -1,3 +1,3 @@ | |||
export function isValidAddress(address: string): boolean { | |||
return !!address && address.startsWith("0x") && address.length === 42; | |||
return /^0x[0-9a-fA-F]{40}$/.test(address); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure how much this is used, I think it may be faster to create a singleton regex object, so it can be reused each time isValidAddress is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NodeJS should cache those when interpreting the code (in theory)
Motivation
Properly validate hex address
Description
Improve isValidAddress validation