File tree Expand file tree Collapse file tree 1 file changed +11
-15
lines changed
packages/thirdweb/src/utils/encoding/helpers Expand file tree Collapse file tree 1 file changed +11
-15
lines changed Original file line number Diff line number Diff line change 1
- import { type Hex , isHex } from "../hex.js" ;
1
+ import { keccak256 } from "../../hashing/keccak256.js" ;
2
+ import { toBytes } from "../to-bytes.js" ;
2
3
4
+
5
+ ///
3
6
/**
4
- * Calculates the byte size of a Hex string or Uint8Array .
5
- * If the value is a Hex string, it accounts for the leading "0x" prefix.
6
- * @param value The Hex string or Uint8Array .
7
- * @returns The byte size of the value .
7
+ * Generates a 256-bit hash of a given role string in bytes form using the keccak256 algorithm .
8
+ *
9
+ * @param { string } role - The role string to be converted into bytes and hashed .
10
+ * @returns { `0x${string}` } A 256-bit hash of the input role as a byte array .
8
11
* @example
9
- * ```ts
10
- * import { byteSize } from "thirdweb/utils";
11
- * const size = byteSize("0x1a4");
12
- * console.log(size); // 2
13
- * ```
12
+ * const AdminRole = roleBytes("ADMIN_ROLE");
14
13
*/
15
- export function byteSize ( value : Hex | Uint8Array ) {
16
- if ( isHex ( value , { strict : false } ) ) {
17
- return Math . ceil ( ( value . length - 2 ) / 2 ) ;
18
- }
19
- return value . length ;
14
+ export const roleBytes = ( role : string ) => {
15
+ return keccak256 ( toBytes ( role ) ) ;
20
16
}
You can’t perform that action at this time.
0 commit comments