Uh oh!
There was an error while loading. Please reload this page.
Add address related utils - #112
Conversation
432aad3 to
4d8a802CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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?
Gudahtt
commented
Jul 6, 2023
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. |
Mrtenz
commented
Jul 6, 2023
Validating the checksum if the address has uppercase characters makes sense to me. |
mcmire
commented
Jul 6, 2023
Sorry if I'm missing something, but why can't we validate the checksum if the address has lowercase characters? |
Gudahtt
commented
Jul 6, 2023
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
3245089CompareNo top level dependency changes detected. Learn more about Socket for GitHub ↗︎ |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…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>
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Mark Stacey <markjstacey@gmail.com>
Uh oh!
There was an error while loading. Please reload this page.
| * @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.
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.
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