Use personal_sign instead of eth_sign for message signing with JsonRpcSigner; added _legacySignMessage for legacy support (#1542, #1840).

This commit is contained in:
Richard Moore 2021-10-16 01:11:53 -04:00
parent cb43a99405
commit 8947fd405e
No known key found for this signature in database
GPG Key ID: 665176BE8E9DC651
2 changed files with 7 additions and 16 deletions

@ -249,6 +249,13 @@ export class JsonRpcSigner extends Signer implements TypedDataSigner {
const data = ((typeof(message) === "string") ? toUtf8Bytes(message): message);
const address = await this.getAddress();
return await this.provider.send("personal_sign", [ hexlify(data), address.toLowerCase() ]);
}
async _legacySignMessage(message: Bytes | string): Promise<string> {
const data = ((typeof(message) === "string") ? toUtf8Bytes(message): message);
const address = await this.getAddress();
// https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
return await this.provider.send("eth_sign", [ address.toLowerCase(), hexlify(data) ]);
}
@ -611,7 +618,6 @@ export class JsonRpcProvider extends BaseProvider {
super._stopEvent(event);
}
// Convert an ethers.js transaction into a JSON-RPC transaction
// - gasLimit => gas
// - All values hexlified

@ -30,14 +30,6 @@ function buildWeb3LegacyFetcher(provider: ExternalProvider, sendFunc: Web3Legacy
const fetcher = "Web3LegacyFetcher";
return function(method: string, params: Array<any>): Promise<any> {
// Metamask complains about eth_sign (and on some versions hangs)
if (method == "eth_sign" && (provider.isMetaMask || provider.isStatus)) {
// https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_sign
method = "personal_sign";
params = [ params[1], params[0] ];
}
const request = {
method: method,
params: params,
@ -92,13 +84,6 @@ function buildEip1193Fetcher(provider: ExternalProvider): JsonRpcFetchFunc {
return function(method: string, params: Array<any>): Promise<any> {
if (params == null) { params = [ ]; }
// Metamask complains about eth_sign (and on some versions hangs)
if (method == "eth_sign" && (provider.isMetaMask || provider.isStatus)) {
// https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_sign
method = "personal_sign";
params = [ params[1], params[0] ];
}
const request = { method, params };
this.emit("debug", {