Added verifyMessage helper.

This commit is contained in:
Richard Moore 2023-01-15 07:54:49 -05:00
parent 453d2357b1
commit f13a7c64b3
3 changed files with 11 additions and 2 deletions

@ -49,7 +49,7 @@ export {
export {
id,
isValidName, namehash, dnsEncode,
hashMessage,
hashMessage, verifyMessage,
solidityPacked, solidityPackedKeccak256, solidityPackedSha256,
TypedDataEncoder
} from "./hash/index.js";
@ -59,6 +59,8 @@ export {
Block, FeeData, Log, TransactionReceipt, TransactionResponse,
AbstractSigner, VoidSigner,
AbstractProvider,
FallbackProvider,

@ -6,7 +6,7 @@
export { id } from "./id.js"
export { isValidName, namehash, dnsEncode } from "./namehash.js";
export { hashMessage } from "./message.js";
export { hashMessage, verifyMessage } from "./message.js";
export {
solidityPacked, solidityPackedKeccak256, solidityPackedSha256
} from "./solidity.js";

@ -1,7 +1,9 @@
import { keccak256 } from "../crypto/index.js";
import { MessagePrefix } from "../constants/index.js";
import { recoverAddress } from "../transaction/index.js";
import { concat, toUtf8Bytes } from "../utils/index.js";
import type { SignatureLike } from "../crypto/index.js";
/**
* Computes the [[link-eip-191]] personal-sign message digest to sign.
*
@ -38,3 +40,8 @@ export function hashMessage(message: Uint8Array | string): string {
message
]));
}
export function verifyMessage(message: Uint8Array | string, sig: SignatureLike): string {
const digest = hashMessage(message);
return recoverAddress(digest, sig);
}