-
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
Closed
dirtycajunrice
wants to merge
5
commits into
graphite-base/5685
from
12-10-add_rolebytes_utility_for_contract_role_usage
+24
−0
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ffeacf5
add roleBytes utility for contract role usage
dirtycajunrice 1b99887
add file
dirtycajunrice c5e0374
remove redundant spacing
dirtycajunrice 0eaab37
add return type and add test
dirtycajunrice 1a19ea8
biome format
dirtycajunrice File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
packages/thirdweb/src/utils/encoding/helpers/role-bytes.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { roleBytes } from "./role-bytes.js"; | ||
|
||
describe("roleBytes", () => { | ||
it("should calculate the value of lister role", () => { | ||
expect(roleBytes("LISTER_ROLE")).toBe( | ||
"0xf94103142c1baabe9ac2b5d1487bf783de9e69cfeea9a72f5c9c94afd7877b8c", | ||
); | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
packages/thirdweb/src/utils/encoding/helpers/role-bytes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { keccak256 } from "../../hashing/keccak256.js"; | ||
import { toBytes } from "../to-bytes.js"; | ||
|
||
/** | ||
* 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. | ||
* @returns {`0x${string}`} A 256-bit hash of the input role as a byte array. | ||
* @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 commentThe 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 |
||
return keccak256(toBytes(role)); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: