Skip to content
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

Open
wants to merge 5 commits into
base: graphite-base/5685
Choose a base branch
from

Conversation

dirtycajunrice
Copy link
Contributor

@dirtycajunrice dirtycajunrice commented Dec 10, 2024

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 the keccak256 algorithm. Additionally, it adds a test suite for this function to ensure its correctness.

Detailed summary

  • Added roleBytes function in role-bytes.ts to hash role strings.
  • The roleBytes function returns a 256-bit hash formatted as 0x${string}.
  • Created a test suite in role-bytes.test.ts to validate the roleBytes function.
  • Added a test case for the LISTER_ROLE.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Copy link

changeset-bot bot commented Dec 10, 2024

⚠️ No Changeset found

Latest commit: 1a19ea8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

graphite-app bot commented Dec 10, 2024

Your org has enabled the Graphite merge queue for merging into main

Add 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.

Copy link

vercel bot commented Dec 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2024 11:04pm
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2024 11:04pm
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2024 11:04pm
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2024 11:04pm

@dirtycajunrice dirtycajunrice marked this pull request as ready for review December 10, 2024 22:25
@github-actions github-actions bot added packages SDK Involves changes to the thirdweb SDK labels Dec 10, 2024
Copy link
Contributor Author

dirtycajunrice commented Dec 10, 2024


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

Copy link
Contributor

github-actions bot commented Dec 10, 2024

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 44.93 KB (0%) 899 ms (0%) 4 s (+39.85% 🔺) 4.9 s
thirdweb (cjs) 110.71 KB (0%) 2.3 s (0%) 7 s (+3.03% 🔺) 9.2 s
thirdweb (minimal + tree-shaking) 5.58 KB (0%) 112 ms (0%) 544 ms (+172.9% 🔺) 656 ms
thirdweb/chains (tree-shaking) 506 B (0%) 10 ms (0%) 81 ms (+10.42% 🔺) 91 ms
thirdweb/react (minimal + tree-shaking) 19.01 KB (0%) 381 ms (0%) 883 ms (+11.64% 🔺) 1.3 s

Copy link

codecov bot commented Dec 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 51.24%. Comparing base (9760615) to head (1a19ea8).

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           
Flag Coverage Δ *Carryforward flag
legacy_packages 65.68% <ø> (ø) Carriedforward from 0eaab37
packages 47.85% <100.00%> (+<0.01%) ⬆️

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
.../thirdweb/src/utils/encoding/helpers/role-bytes.ts 100.00% <100.00%> (ø)

@joaquim-verges joaquim-verges changed the base branch from 12-10-fix_ignore_of_mimetime_set_in_mediarenderer to graphite-base/5685 December 11, 2024 00:42
Copy link
Member

@joaquim-verges joaquim-verges left a 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}` => {
Copy link
Member

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.
Copy link
Member

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)

Copy link
Member

@joaquim-verges joaquim-verges left a 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

@gregfromstl gregfromstl added the DO NOT MERGE This pull request is still in progress and is not ready to be merged. label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DO NOT MERGE This pull request is still in progress and is not ready to be merged. packages SDK Involves changes to the thirdweb SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants