Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(error: Error, signature: string) => {
try {
/*
* Validate that the signature is in the correct format
*/
hexSequenceValidator(signature);
const recoveredPublicKey: string = recoverPublicKeyHelper({
message: PUBLICKEY_RECOVERY_MESSAGE,
signature,
});
/*
* Add the `0x` prefix to the recovered public key
*/
const normalizedPublicKey: string = hexSequenceNormalizer(
recoveredPublicKey,
);
/*
* Also set the internal public key
*/
internalPublicKey = normalizedPublicKey;
return resolve(normalizedPublicKey);
} catch (caughtError) {
try {
if (error) {
/*
* If the user cancels signing the transaction we still throw,
* but we customize the message.
*/
if (error.message.includes(STD_ERRORS.CANCEL_TX_SIGN)) {
throw new Error(messages.cancelTransactionSign);
}
throw new Error(error.message);
}
/*
* Validate that the signature hash is in the correct format
*/
hexSequenceValidator(transactionHash);
/*
* Add the `0x` prefix to the signed transaction hash
*/
const normalizedTransactionHash: string = hexSequenceNormalizer(
transactionHash,
);
/*
* Get signed transaction object with transaction hash using Web3
* Include signature + any values MetaMask may have changed.
*/
const {
gas,
gasPrice: signedGasPrice,
input: signedData,
nonce,
r,
try {
if (error) {
/*
* If the user cancels signing the message we still throw,
* but we customize the message
*/
if (error.message.includes(STD_ERRORS.CANCEL_MSG_SIGN)) {
throw new Error(messages.cancelMessageSign);
}
throw new Error(error.message);
}
/*
* Validate that the signature is in the correct format
*/
hexSequenceValidator(messageSignature);
/*
* Add the `0x` prefix to the message's signature
*/
const normalizedSignature: string = hexSequenceNormalizer(
messageSignature,
);
return resolve(normalizedSignature);
} catch (caughtError) {
return reject(caughtError);
}
};
constructor(ethersInstance: WalletArgumentsType = {}) {
const {
address,
privateKey,
password,
originalMnemonic: mnemonic,
keystore,
chainId,
sign: ethersSign,
signMessage: ethersSignMessage,
} = ethersInstance;
/*
* Validate the private key and address that's coming in from ethers.
*/
addressValidator(address);
hexSequenceValidator(privateKey);
/*
* If we have a keystore JSON string and encryption password, set them
* to the internal variables.
*/
internalEncryptionPassword = password;
internalKeystoreJson = keystore;
/*
* Set the private key to a "internal" variable since we only allow
* access to it through a getter and not directly via a prop.
*/
Object.defineProperties(this, {
address: Object.assign({}, { value: address }, WALLET_PROPS),
type: Object.assign({}, { value: TYPE_SOFTWARE }, WALLET_PROPS),
subtype: Object.assign({}, { value: SUBTYPE_ETHERS }, WALLET_PROPS),
chainId: Object.assign({}, { value: chainId }, WALLET_PROPS),
/*
return (async () => {
const privateKey: string = await this.privateKey;
const reversedPublicKey: string = privateToPublic(privateKey).toString(
HEX_HASH_TYPE,
);
/*
* Validate the reversed public key
*/
hexSequenceValidator(reversedPublicKey);
/*
* Then normalize it to ensure it has the `0x` prefix
*/
const normalizedPublicKey: string = hexSequenceNormalizer(
reversedPublicKey,
);
/*
* Memoizing the getter
*
* While this is not an expensive operation, it's still a good idea
* to memoize it so it returns a tiny bit faster.
*/
Object.defineProperty(
(this: any),
'publicKey',
Object.assign({}, GETTERS, {
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),