-
-
Notifications
You must be signed in to change notification settings - Fork 14
Add address related utils #112
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
Conversation
432aad3 to
4d8a802
Compare
Gudahtt
left a comment
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.
LGTM!
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.
This does not validate the checksum validity of the address. Ideally that would be part of this function as well.
I wrote a function for this some time ago, that doesn't use ethereumjs or other libraries (except for a Keccak-256 library, of course), if that helps?
|
Hmm. Validating the checksum does seem valuable, though less so for lower-cased addresses. We still use lower-cased addresses in most places (though not all). Perhaps we could add a variant of this that includes checksum validation? Or we could update this one to only validate the checksum if upper-case characters are detected. |
|
Validating the checksum if the address has uppercase characters makes sense to me. |
|
Sorry if I'm missing something, but why can't we validate the checksum if the address has lowercase characters? |
|
The case of each character is the checksum; if the address is lower-cased, there is no checksum to validate. See here for further details: https://eips.ethereum.org/EIPS/eip-55 |
f2f5c16 to
3245089
Compare
|
No top level dependency changes detected. Learn more about Socket for GitHub ↗︎ |
…ion (#113) * feat: break out address checksum encoding to erc55EncodeAddress function * deps: ethereum-cryptography@2.0.0->2.1.0; dedupe @noble/hashes * Update jsdoc Co-authored-by: Maarten Zuidhoorn <maarten@zuidhoorn.com> * refactor: rename erc55EncodeAddress function * test: add test cases for getChecksumAddress --------- Co-authored-by: Maarten Zuidhoorn <maarten@zuidhoorn.com> Co-authored-by: Michele Esposito <michele@esposito.codes>
Gudahtt
left a comment
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.
LGTM!
Co-authored-by: Mark Stacey <markjstacey@gmail.com>
| * @returns The address encoded according to ERC-55. | ||
| * @see https://eips.ethereum.org/EIPS/eip-55 | ||
| */ | ||
| export function getChecksumAddress(address: Hex) { |
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.
I wonder if we should do more validation here, such as checking if the provided address is 20 bytes long.
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.
I just added an assertion to check the string we receive here
This PR ports the
isValidHexAddressfunction from@metamask/controller-utils, without using theethereumjs-utilspackage to check the string.The function can be used to check if a string is a valid prefixed hex address, all lower-cased or a valid checksum
Changes
ADDED:
isValidHexAddresshas been added to check the validity of an hex addressADDED:
getChecksumAddresshas been added to calculate the ERC-55 mixed-case checksum of an hex addressADDED:
isValidChecksumAddresshas been added to check the validity of an ERC-55 mixed-case checksum address