From 20af9ba81d25c1f61bd902d3e23e5f416ae345e9 Mon Sep 17 00:00:00 2001 From: Felipe Forbeck Date: Thu, 28 Oct 2021 13:54:20 -0300 Subject: [PATCH] fix: recoverPubKey function --- src/util/signature-utils.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/util/signature-utils.ts b/src/util/signature-utils.ts index 9e70555..b93d6d7 100644 --- a/src/util/signature-utils.ts +++ b/src/util/signature-utils.ts @@ -6,8 +6,19 @@ import { typedSignatureHash, TypedDataUtils, } from "@metamask/eth-sig-util"; -import { recoverPublicKey } from "@metamask/eth-sig-util/dist/utils"; -import { bufferToHex, publicToAddress } from "ethereumjs-util"; +import { bufferToHex, publicToAddress, fromRpcSig, ecrecover } from "ethereumjs-util"; + +/** + * Recover the public key from the given signature and message hash. + * + * @param messageHash - The hash of the signed message. + * @param signature - The signature. + * @returns The public key of the signer. + */ +export function recoverPublicKey(messageHash, signature) { + const sigParams = fromRpcSig(signature); + return ecrecover(messageHash, sigParams.v, sigParams.r, sigParams.s); +} /** * Validate that the given value is a valid version string.