Fixed auto-address and signing with Metamask and Web3Provicder.

This commit is contained in:
Richard Moore 2018-01-17 16:23:01 -05:00
parent c550f2eb07
commit c4690f9e7b
No known key found for this signature in database
GPG Key ID: 525F70A6FCABC295
3 changed files with 16 additions and 5 deletions

@ -11,7 +11,7 @@ Complete Ethereum wallet implementation and utilities in JavaScript.
- Import and export **JSON wallets** (Geth, Parity and crowdsale) and brain wallets
- Import and export BIP 39 **mnemonic phrases** (12 word backup phrases) and **HD Wallets**
- Meta-classes create JavaScript objects from any contract ABI
- Connect to Ethereum nodes over [JSON-RPC](https://github.com/ethereum/wiki/wiki/JSON-RPC), [INFURA](https://infura.io) or [Etherscan](https://etherscan.io)
- Connect to Ethereum nodes over [JSON-RPC](https://github.com/ethereum/wiki/wiki/JSON-RPC), [INFURA](https://infura.io), [Etherscan](https://etherscan.io), or [MetaMask](https://metamask.io)
- ENS names are first-class citizens; they can almost always used instead of Ethereum addresses
- **Tiny** (~77kb compressed; 227kb uncompressed)
- **Complete** functionality for all your Ethereum needs

@ -1,6 +1,6 @@
{
"name": "ethers-providers",
"version": "2.1.17",
"version": "2.1.18",
"description": "Service provider for Ethereum wallet library.",
"bugs": {
"url": "http://github.com/ethers-io/ethers.js/issues",

@ -20,8 +20,7 @@ function Web3Signer(provider, address) {
enumerable: true,
get: function() {
throw new Error('unsupported sync operation; use getAddress');
},
writable: false
}
});
utils.defineProperty(this, '_syncAddress', false);
}
@ -79,7 +78,19 @@ utils.defineProperty(Web3Signer.prototype, 'signMessage', function(message) {
var data = ((typeof(message) === 'string') ? utils.toUtf8Bytes(message): message);
return this.getAddress().then(function(address) {
return provider.send('eth_sign', [ address, utils.hexlify(data) ]);
// https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
var method = 'eth_sign';
var params = [ address, utils.hexlify(data) ];
// Metamask complains about eth_sign (and on some versions hangs)
if (provider.isMetamask) {
// https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_sign
method = 'personal_sign';
params = [ utils.hexlify(data), address ];
}
return provider.send(method, params);
});
});