Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async signTypedData(address: Buffer, typedData: any): Promise {
const privateKey = await this._getLocalAccountPrivateKey(address);
return ethSigUtil.signTypedData_v4(privateKey, {
data: typedData
});
}
signTypedData_v4 (withAccount, typedData, opts = {}) {
const privKey = this.getPrivateKeyFor(withAccount, opts);
const sig = sigUtil.signTypedData_v4(privKey, { data: typedData })
return Promise.resolve(sig)
}
async signTypedMessage(messageParams: TypedMessageParams, version: string) {
try {
const address = sigUtil.normalize(messageParams.from);
const password = privates.get(this).keyring.password;
const privateKey = await this.exportAccount(password, address);
const privateKeyBuffer = ethUtil.toBuffer(ethUtil.addHexPrefix(privateKey));
switch (version) {
case 'V1':
return sigUtil.signTypedDataLegacy(privateKeyBuffer, { data: messageParams.data });
case 'V3':
return sigUtil.signTypedData(privateKeyBuffer, { data: JSON.parse(messageParams.data as string) });
case 'V4':
return sigUtil.signTypedData_v4(privateKeyBuffer, {
data: JSON.parse(messageParams.data as string)
});
}
} catch (error) {
throw new Error('Keyring Controller signTypedMessage: ' + error);
}
}
const [address, data] = params;
if (address !== undefined) {
if (data === undefined) {
throw new BuidlerError(ERRORS.NETWORK.ETHSIGN_MISSING_DATA_PARAM);
}
const privateKey = getPrivateKey(address);
if (privateKey === undefined) {
throw new BuidlerError(ERRORS.NETWORK.NOT_LOCAL_ACCOUNT, {
account: address
});
}
return ethSigUtil.signTypedData_v4(privateKey, {
data
});
}
}
if (method === "eth_sendTransaction" && params.length > 0) {
const tx: JsonRpcTransactionData = params[0];
if (tx.gas === undefined) {
throw new BuidlerError(
ERRORS.NETWORK.MISSING_TX_PARAM_TO_SIGN_LOCALLY,
{ param: "gas" }
);
}
if (tx.gasPrice === undefined) {