Socket
Socket
Sign inDemoInstall

ethers

Package Overview
Dependencies
Maintainers
1
Versions
319
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ethers - npm Package Compare versions

Comparing version 3.0.10 to 3.0.11

providers/ipc-provider.js

2

index.js

@@ -7,2 +7,3 @@ 'use strict';

var providers = require('./providers');
var errors = require('./utils/errors');
var utils = require('./utils');

@@ -23,2 +24,3 @@ var wallet = require('./wallet');

errors: errors,
utils: utils,

@@ -25,0 +27,0 @@

3

package.json
{
"name": "ethers",
"version": "3.0.10",
"version": "3.0.11",
"description": "Ethereum wallet library.",

@@ -39,2 +39,3 @@ "main": "index.js",

"./utils/random-bytes.js": "./utils/browser-random-bytes.js",
"./providers/ipc-provider.js": "./utils/empty.js",
"xmlhttprequest": "./providers/browser-xmlhttprequest.js"

@@ -41,0 +42,0 @@ },

'use strict';
var Provider = require('./provider.js');
var Provider = require('./provider');
var EtherscanProvider = require('./etherscan-provider.js');
var FallbackProvider = require('./fallback-provider.js');
var InfuraProvider = require('./infura-provider.js');
var JsonRpcProvider = require('./json-rpc-provider.js');
var Web3Provider = require('./web3-provider.js');
var EtherscanProvider = require('./etherscan-provider');
var FallbackProvider = require('./fallback-provider');
var IpcProvider = require('./ipc-provider');
var InfuraProvider = require('./infura-provider');
var JsonRpcProvider = require('./json-rpc-provider');
var Web3Provider = require('./web3-provider');

@@ -18,3 +19,3 @@ function getDefaultProvider(network) {

module.exports = {
var exports = {
EtherscanProvider: EtherscanProvider,

@@ -34,1 +35,8 @@ FallbackProvider: FallbackProvider,

}
// Only available in node, so we do not include it in browsers
if (IpcProvider) {
exports.IpcProvider = IpcProvider;
}
module.exports = exports;

@@ -8,8 +8,10 @@ 'use strict';

return {
defineProperty: require('../utils/properties.js').defineProperty
defineProperty: require('../utils/properties').defineProperty
}
})();
var errors = require('../utils/errors');
function InfuraProvider(network, apiAccessToken) {
if (!(this instanceof InfuraProvider)) { throw new Error('missing new'); }
errors.checkNew(this, InfuraProvider);

@@ -51,2 +53,10 @@ network = Provider.getNetwork(network);

utils.defineProperty(InfuraProvider.prototype, 'getSigner', function(address) {
errors.throwError('INFURA does not support signing', errors.UNSUPPORTED_OPERATION, { operation: 'getSigner' });
});
utils.defineProperty(InfuraProvider.prototype, 'listAccounts', function() {
return Promise.resolve([]);
});
module.exports = InfuraProvider;

@@ -15,5 +15,11 @@ 'use strict';

hexStripZeros: convert.hexStripZeros,
toUtf8Bytes: require('../utils/utf8').toUtf8Bytes,
getAddress: require('../utils/address').getAddress,
}
})();
var errors = require('../utils/errors');
function timer(timeout) {

@@ -60,4 +66,92 @@ return new Promise(function(resolve) {

function JsonRpcSigner(provider, address) {
errors.checkNew(this, JsonRpcSigner);
utils.defineProperty(this, 'provider', provider);
// Statically attach to a given address
if (address) {
utils.defineProperty(this, 'address', address);
utils.defineProperty(this, '_syncAddress', true);
} else {
Object.defineProperty(this, 'address', {
enumerable: true,
get: function() {
errors.throwError('no sync sync address available; use getAddress', errors.UNSUPPORTED_OPERATION, { operation: 'address' });
}
});
utils.defineProperty(this, '_syncAddress', false);
}
}
utils.defineProperty(JsonRpcSigner.prototype, 'getAddress', function() {
if (this._syncAddress) { return Promise.resolve(this.address); }
return this.provider.send('eth_accounts', []).then(function(accounts) {
if (accounts.length === 0) {
errors.throwError('no accounts', errors.UNSUPPORTED_OPERATION, { operation: 'getAddress' });
}
return utils.getAddress(accounts[0]);
});
});
utils.defineProperty(JsonRpcSigner.prototype, 'getBalance', function(blockTag) {
var provider = this.provider;
return this.getAddress().then(function(address) {
return provider.getBalance(address, blockTag);
});
});
utils.defineProperty(JsonRpcSigner.prototype, 'getTransactionCount', function(blockTag) {
var provider = this.provider;
return this.getAddress().then(function(address) {
return provider.getTransactionCount(address, blockTag);
});
});
utils.defineProperty(JsonRpcSigner.prototype, 'sendTransaction', function(transaction) {
var provider = this.provider;
transaction = getTransaction(transaction);
return this.getAddress().then(function(address) {
transaction.from = address.toLowerCase();
return provider.send('eth_sendTransaction', [ transaction ]).then(function(hash) {
return new Promise(function(resolve, reject) {
function check() {
provider.getTransaction(hash).then(function(transaction) {
if (!transaction) {
setTimeout(check, 1000);
return;
}
resolve(transaction);
});
}
check();
});
});
});
});
utils.defineProperty(JsonRpcSigner.prototype, 'signMessage', function(message) {
var provider = this.provider;
var data = ((typeof(message) === 'string') ? utils.toUtf8Bytes(message): message);
return this.getAddress().then(function(address) {
// https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
return provider.send('eth_sign', [ address.toLowerCase(), utils.hexlify(data) ]);
});
});
utils.defineProperty(JsonRpcSigner.prototype, 'unlock', function(password) {
var provider = this.provider;
return this.getAddress().then(function(address) {
return provider.send('personal_unlockAccount', [ address.toLowerCase(), password, null ]);
});
});
function JsonRpcProvider(url, network) {
if (!(this instanceof JsonRpcProvider)) { throw new Error('missing new'); }
errors.checkNew(this, JsonRpcProvider);

@@ -84,2 +178,15 @@ if (arguments.length == 1) {

utils.defineProperty(JsonRpcProvider.prototype, 'getSigner', function(address) {
return new JsonRpcSigner(this, address);
});
utils.defineProperty(JsonRpcProvider.prototype, 'listAccounts', function() {
return this.send('eth_accounts', []).then(function(accounts) {
accounts.forEach(function(address, index) {
accounts[index] = utils.getAddress(address);
});
return accounts;
});
});
utils.defineProperty(JsonRpcProvider.prototype, 'send', function(method, params) {

@@ -86,0 +193,0 @@ var request = {

@@ -9,107 +9,7 @@ 'use strict';

defineProperty: require('../utils/properties').defineProperty,
getAddress: require('../utils/address').getAddress,
toUtf8Bytes: require('../utils/utf8').toUtf8Bytes,
hexlify: require('../utils/convert').hexlify
}
})();
function Web3Signer(provider, address) {
if (!(this instanceof Web3Signer)) { throw new Error('missing new'); }
utils.defineProperty(this, 'provider', provider);
var errors = require('../utils/errors');
// Statically attach to a given address
if (address) {
utils.defineProperty(this, 'address', address);
utils.defineProperty(this, '_syncAddress', true);
} else {
Object.defineProperty(this, 'address', {
enumerable: true,
get: function() {
throw new Error('unsupported sync operation; use getAddress');
}
});
utils.defineProperty(this, '_syncAddress', false);
}
}
utils.defineProperty(Web3Signer.prototype, 'getAddress', function() {
if (this._syncAddress) { return Promise.resolve(this.address); }
return this.provider.send('eth_accounts', []).then(function(accounts) {
if (accounts.length === 0) {
throw new Error('no account');
}
return utils.getAddress(accounts[0]);
});
});
utils.defineProperty(Web3Signer.prototype, 'getBalance', function(blockTag) {
var provider = this.provider;
return this.getAddress().then(function(address) {
return provider.getBalance(address, blockTag);
});
});
utils.defineProperty(Web3Signer.prototype, 'getTransactionCount', function(blockTag) {
var provider = this.provider;
return this.getAddress().then(function(address) {
return provider.getTransactionCount(address, blockTag);
});
});
utils.defineProperty(Web3Signer.prototype, 'sendTransaction', function(transaction) {
var provider = this.provider;
transaction = JsonRpcProvider._hexlifyTransaction(transaction);
return this.getAddress().then(function(address) {
transaction.from = address.toLowerCase();
return provider.send('eth_sendTransaction', [ transaction ]).then(function(hash) {
return new Promise(function(resolve, reject) {
function check() {
provider.getTransaction(hash).then(function(transaction) {
if (!transaction) {
setTimeout(check, 1000);
return;
}
resolve(transaction);
});
}
check();
});
});
});
});
utils.defineProperty(Web3Signer.prototype, 'signMessage', function(message) {
var provider = this.provider;
var data = ((typeof(message) === 'string') ? utils.toUtf8Bytes(message): message);
return this.getAddress().then(function(address) {
// https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
var method = 'eth_sign';
var params = [ address.toLowerCase(), utils.hexlify(data) ];
// Metamask complains about eth_sign (and on some versions hangs)
if (provider._web3Provider.isMetaMask) {
// https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_sign
method = 'personal_sign';
params = [ utils.hexlify(data), address.toLowerCase() ];
}
return provider.send(method, params);
});
});
utils.defineProperty(Web3Signer.prototype, 'unlock', function(password) {
var provider = this.provider;
return this.getAddress().then(function(address) {
return provider.send('personal_unlockAccount', [ address.toLowerCase(), password, null ]);
});
});
/*

@@ -123,3 +23,3 @@ @TODO

function Web3Provider(web3Provider, network) {
if (!(this instanceof Web3Provider)) { throw new Error('missing new'); }
errors.checkNew(this, Web3Provider);

@@ -129,2 +29,4 @@ // HTTP has a host; IPC has a path.

if (network == null) { network = 'homestead'; }
JsonRpcProvider.call(this, url, network);

@@ -135,16 +37,11 @@ utils.defineProperty(this, '_web3Provider', web3Provider);

utils.defineProperty(Web3Provider.prototype, 'getSigner', function(address) {
return new Web3Signer(this, address);
});
utils.defineProperty(Web3Provider.prototype, 'send', function(method, params) {
utils.defineProperty(Web3Provider.prototype, 'listAccounts', function() {
return this.send('eth_accounts', []).then(function(accounts) {
accounts.forEach(function(address, index) {
accounts[index] = utils.getAddress(address);
});
return accounts;
});
});
// Metamask complains about eth_sign (and on some versions hangs)
if (method == 'eth_sign' && this._web3Provider.isMetaMask) {
// https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_sign
method = 'personal_sign';
params = [ params[1], params[0] ];
}
utils.defineProperty(Web3Provider.prototype, 'send', function(method, params) {
var provider = this._web3Provider;

@@ -151,0 +48,0 @@ return new Promise(function(resolve, reject) {

@@ -11,2 +11,5 @@ 'use strict';

// Not implemented
'NOT_IMPLEMENTED',
// Missing new operator to an object

@@ -16,6 +19,20 @@ // - name: The name of the class

// Invalid argument to a function:
// Invalid argument (e.g. type) to a function:
// - arg: The argument name that was invalid
'INVALID_ARGUMENT'
'INVALID_ARGUMENT',
// Missing argument to a function:
// - arg: The argument name that is required
'MISSING_ARGUMENT',
// Too many arguments
'UNEXPECTED_ARGUMENT',
// Unsupported operation
// - operation
'UNSUPPORTED_OPERATION',
].forEach(function(code) {

@@ -22,0 +39,0 @@ defineProperty(codes, code, code);

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc