Skip to content

Commit 1b99887

Browse files
add file
1 parent ffeacf5 commit 1b99887

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
import { type Hex, isHex } from "../hex.js";
1+
import { keccak256 } from "../../hashing/keccak256.js";
2+
import { toBytes } from "../to-bytes.js";
23

4+
5+
///
36
/**
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.
811
* @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");
1413
*/
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));
2016
}

0 commit comments

Comments
 (0)