-
Notifications
You must be signed in to change notification settings - Fork 542
add roleBytes utility for contract role usage #5685
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
Changes from 4 commits
ffeacf5
1b99887
c5e0374
0eaab37
1a19ea8
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
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" | ||
); | ||
}); | ||
}); | ||
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. | ||
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. how about a union type for this of 'known' role strings + | ({} & string) to allow for others:
|
||
* @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)); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.