Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
signTypedData_v1 (withAccount, typedData, opts = {}) {
const privKey = this.getPrivateKeyFor(withAccount, opts);
const sig = sigUtil.signTypedDataLegacy(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);
}
}