Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const verifyMessage = async ({
currentAddress,
...messageVerificationObject
}: Object = {}) => {
/*
* Validate the current address
*/
addressValidator(currentAddress);
/*
* Validate the rest of the pros using the core helper
*/
const { message, signature } = messageVerificationObjectValidator(
messageVerificationObject,
);
/*
* We must check for the Metamask injected in-page proxy every time we
* try to access it. This is because something can change it from the time
* of last detection until now.
*/
return methodCaller(
/*
* @TODO Move into own (non-anonymous) method
* This way we could better test it
*/
() =>
new Promise((resolve, reject) => {
/*
* Verify the message
export const verifyMessage = async ({
publicKey,
...signatureMessage
}: Object): Promise => {
/*
* Validate the public key locally
*/
hexSequenceValidator(publicKey);
/*
* Validate the rest of the pros using the core helper
*/
const { message, signature } = messageVerificationObjectValidator(
signatureMessage,
);
return verifyMessageSignature({
/*
* Ensure the public key has the hex `0x` prefix
*/
publicKey: hexSequenceNormalizer(publicKey),
message,
/*
* Ensure the signature has the hex `0x` prefix
*/
signature: hexSequenceNormalizer(signature),
});
};
export const verifyMessage = async ({
address,
...signatureMessage
}: Object = {}): Promise => {
/*
* Validate the address locally
*/
addressValidator(address);
/*
* Validate the rest of the pros using the core helper
*/
const { message, signature } = messageVerificationObjectValidator(
signatureMessage,
);
warning(messages.messageSignatureOnlyTrezor);
try {
const { success: isMessageValid } = await payloadListener({
payload: Object.assign({}, PAYLOAD_VERIFYMSG, {
/*
* Trezor service requires the prefix from the address to be stripped
*/
address: addressNormalizer(address, false),
message,
/*
* Trezor service requires the prefix from the signature to be stripped
*/
signature: hexSequenceNormalizer(signature, false),
}),
export const verifyMessage = async ({
address,
...signatureMessage
}: Object = {}): Promise => {
/*
* Validate the address locally
*/
addressValidator(address);
/*
* Validate the rest of the pros using the core helper
*/
const { message, signature } = messageVerificationObjectValidator(
signatureMessage,
);
try {
const recoveredAddress: string = verifyEthersMessage(
message,
signature,
);
/*
* Validate the recovered address
*/
addressValidator(recoveredAddress);
return address === recoveredAddress;
} catch (caughtError) {
throw new Error(
`${messages.cannotVerifySignature} ${objectToErrorString(
signatureMessage,