Skip to content

Commit

Permalink
Use personal_sign instead of eth_sign for message signing with JsonRp…
Browse files Browse the repository at this point in the history
…cSigner; added _legacySignMessage for legacy support (#1542, #1840).
  • Loading branch information
ricmoo committed Oct 16, 2021
1 parent cb43a99 commit 8947fd4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
8 changes: 7 additions & 1 deletion packages/providers/src.ts/json-rpc-provider.ts
Expand Up @@ -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) ]);
}
Expand Down Expand Up @@ -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
Expand Down
15 changes: 0 additions & 15 deletions packages/providers/src.ts/web3-provider.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -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", {
Expand Down

0 comments on commit 8947fd4

Please sign in to comment.