Skip to content

Commit

Permalink
fix: recoverPubKey function
Browse files Browse the repository at this point in the history
  • Loading branch information
fforbeck committed Oct 28, 2021
1 parent 41b1a94 commit 20af9ba
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/util/signature-utils.ts
Expand Up @@ -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.
Expand Down

0 comments on commit 20af9ba

Please sign in to comment.