14 lines
442 B
TypeScript
14 lines
442 B
TypeScript
import { keccak256 } from "../crypto/index.js";
|
|
import { MessagePrefix } from "../constants/index.js";
|
|
import { concat, toUtf8Bytes } from "../utils/index.js";
|
|
|
|
|
|
export function hashMessage(message: Uint8Array | string): string {
|
|
if (typeof(message) === "string") { message = toUtf8Bytes(message); }
|
|
return keccak256(concat([
|
|
toUtf8Bytes(MessagePrefix),
|
|
toUtf8Bytes(String(message.length)),
|
|
message
|
|
]));
|
|
}
|