-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add constant padding to random hexes, hashes and addresses #494
Changes from 4 commits
a81a665
593aaef
61fb5ec
c1aa644
0125384
0d2a7af
0c66d69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,10 +19,11 @@ export function CheckedAddress(value: string): CheckedAddress { | |
* Generates a random address. Tries to represent desired ascii prefix as hex value. Helps to identify transactions in the logs. | ||
*/ | ||
CheckedAddress.random = (asciiPrefix = ''): CheckedAddress => { | ||
const constantAddressPrefix = '0000' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i thought about this more: i think a good prefix is deadbeef as it's obviously not random. Or simply make the prefix longer - for example: 8 chars instead of 4. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed to |
||
const hexPrefix = asciiToHex(asciiPrefix) | ||
const postfixLength = 40 - hexPrefix.length | ||
const postfixLength = 40 - hexPrefix.length - constantAddressPrefix.length | ||
assert(postfixLength >= 0, `Prefix too long: ${asciiPrefix}`) | ||
const address = hexPrefix + randomPartialHex(postfixLength) | ||
const address = `${constantAddressPrefix}${hexPrefix}${randomPartialHex(postfixLength)}` | ||
|
||
return CheckedAddress(`0x${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.
I guess it will be
infix
now, since it's not first part of the address anymore.I'm curious, why this change was needed in the first place?
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 don't know if we need to be that precise to rename that to
infix
- both of these parts are stillpre
randomPart 😛