Skip to content

Commit 8947fd4

Browse files
committed
Use personal_sign instead of eth_sign for message signing with JsonRpcSigner; added _legacySignMessage for legacy support (#1542, #1840).
1 parent cb43a99 commit 8947fd4

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

packages/providers/src.ts/json-rpc-provider.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,13 @@ export class JsonRpcSigner extends Signer implements TypedDataSigner {
249249
const data = ((typeof(message) === "string") ? toUtf8Bytes(message): message);
250250
const address = await this.getAddress();
251251

252+
return await this.provider.send("personal_sign", [ hexlify(data), address.toLowerCase() ]);
253+
}
254+
255+
async _legacySignMessage(message: Bytes | string): Promise<string> {
256+
const data = ((typeof(message) === "string") ? toUtf8Bytes(message): message);
257+
const address = await this.getAddress();
258+
252259
// https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
253260
return await this.provider.send("eth_sign", [ address.toLowerCase(), hexlify(data) ]);
254261
}
@@ -611,7 +618,6 @@ export class JsonRpcProvider extends BaseProvider {
611618
super._stopEvent(event);
612619
}
613620

614-
615621
// Convert an ethers.js transaction into a JSON-RPC transaction
616622
// - gasLimit => gas
617623
// - All values hexlified

packages/providers/src.ts/web3-provider.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@ function buildWeb3LegacyFetcher(provider: ExternalProvider, sendFunc: Web3Legacy
3030
const fetcher = "Web3LegacyFetcher";
3131

3232
return function(method: string, params: Array<any>): Promise<any> {
33-
34-
// Metamask complains about eth_sign (and on some versions hangs)
35-
if (method == "eth_sign" && (provider.isMetaMask || provider.isStatus)) {
36-
// https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_sign
37-
method = "personal_sign";
38-
params = [ params[1], params[0] ];
39-
}
40-
4133
const request = {
4234
method: method,
4335
params: params,
@@ -92,13 +84,6 @@ function buildEip1193Fetcher(provider: ExternalProvider): JsonRpcFetchFunc {
9284
return function(method: string, params: Array<any>): Promise<any> {
9385
if (params == null) { params = [ ]; }
9486

95-
// Metamask complains about eth_sign (and on some versions hangs)
96-
if (method == "eth_sign" && (provider.isMetaMask || provider.isStatus)) {
97-
// https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_sign
98-
method = "personal_sign";
99-
params = [ params[1], params[0] ];
100-
}
101-
10287
const request = { method, params };
10388

10489
this.emit("debug", {

0 commit comments

Comments
 (0)