-
Notifications
You must be signed in to change notification settings - Fork 400
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 roleBytes utility for contract role usage #5685
add roleBytes utility for contract role usage #5685
Conversation
|
Your org has enabled the Graphite merge queue for merging into mainAdd the label “merge-queue” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix. You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
size-limit report 📦
|
packages/thirdweb/src/utils/encoding/helpers/role-bytes.test.ts
Outdated
Show resolved
Hide resolved
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## graphite-base/5685 #5685 +/- ##
===================================================
Coverage 51.23% 51.24%
===================================================
Files 1092 1093 +1
Lines 57346 57350 +4
Branches 4677 4676 -1
===================================================
+ Hits 29383 29387 +4
Misses 27247 27247
Partials 716 716
*This pull request uses carry forward flags. Click here to find out more.
|
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.
can you add a changeset for this one?
pnpm changeset from the root of the repo - make it a patch
* @example | ||
* const AdminRole = roleBytes("ADMIN_ROLE"); | ||
*/ | ||
export const roleBytes = (role: string): `0x${string}` => { |
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.
need to export it publicly, you can do that by exporting it from /exports
likely under /exports/extensions/common.ts where the other role stuff is
/** | ||
* Generates a 256-bit hash of a given role string in bytes form using the keccak256 algorithm. | ||
* | ||
* @param {string} role - The role string to be converted into bytes and hashed. |
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.
how about a union type for this of 'known' role strings + | ({} & string) to allow for others:
type KnownRoles = "ADMIN_ROLE" | "MINTER_ROLE" ...
type Role = KnownRoles | ({} & string)
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.
ugh, just realized we already have a getRoleHash
function that's already exported and does the same thing
Thats great. Ill close this then. |
Problem solved
CNCT-2631
Short description of the bug fixed or feature added
PR-Codex overview
This PR introduces a new utility function
roleBytes
that generates a 256-bit hash for role strings using thekeccak256
algorithm. Additionally, it adds a test suite for this function to ensure its correctness.Detailed summary
roleBytes
function inrole-bytes.ts
to hash role strings.roleBytes
function returns a 256-bit hash formatted as0x${string}
.role-bytes.test.ts
to validate theroleBytes
function.LISTER_ROLE
.