Socket
Socket
Sign inDemoInstall

@metamask/ethjs-rpc

Package Overview
Dependencies
Maintainers
12
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@metamask/ethjs-rpc - npm Package Compare versions

Comparing version 0.3.2 to 0.4.0

9

CHANGELOG.md

@@ -9,2 +9,8 @@ # Changelog

## [0.4.0]
### Changed
- **BREAKING**: `@babel/runtime@^7.0.0` is now a peerDependency ([#34](https://github.com/MetaMask/ethjs-rpc/pull/34))
- Update babel from `6.18.2` to `7.2` ([#34](https://github.com/MetaMask/ethjs-rpc/pull/34))
- This change was previously prematurely released in `0.3.1` and reverted in `0.3.2`, in order to keep latest `0.3.x` non-breaking.
## [0.3.2]

@@ -69,3 +75,4 @@ ### Fixed

[Unreleased]: https://github.com/MetaMask/ethjs-rpc/compare/v0.3.2...HEAD
[Unreleased]: https://github.com/MetaMask/ethjs-rpc/compare/v0.4.0...HEAD
[0.4.0]: https://github.com/MetaMask/ethjs-rpc/compare/v0.3.2...v0.4.0
[0.3.2]: https://github.com/MetaMask/ethjs-rpc/compare/v0.3.1...v0.3.2

@@ -72,0 +79,0 @@ [0.3.1]: https://github.com/MetaMask/ethjs-rpc/compare/v0.3.0...v0.3.1

15

dist/ethjs-rpc.js

@@ -1,2 +0,2 @@

/* eslint-disable */
/* eslint-disable */
(function webpackUniversalModuleDefinition(root, factory) {

@@ -112,3 +112,2 @@ if(typeof exports === 'object' && typeof module === 'object')

var promiseToCallback = __webpack_require__(2);
module.exports = EthRPC;

@@ -127,7 +126,5 @@

var optionsObject = options || {};
if (!(this instanceof EthRPC)) {
throw new Error('[ethjs-rpc] the EthRPC object requires the "new" flag in order to function normally (i.e. `const eth = new EthRPC(provider);`).');
}
self.options = Object.assign({

@@ -140,5 +137,4 @@ jsonSpace: optionsObject.jsonSpace || 0,

if (typeof provider !== 'object') {
throw new Error('[ethjs-rpc] the EthRPC object requires that the first input \'provider\' must be an object, got \'' + typeof provider + '\' (i.e. \'const eth = new EthRPC(provider);\')');
throw new Error("[ethjs-rpc] the EthRPC object requires that the first input 'provider' must be an object, got '" + typeof provider + "' (i.e. 'const eth = new EthRPC(provider);')");
}
self.currentProvider = provider;

@@ -161,9 +157,7 @@ };

var parsedPayload = createPayload(payload, self.idCounter++);
var promise = new Promise(function (resolve, reject) {
self.currentProvider.sendAsync(parsedPayload, function (err, response) {
var responseObject = response || {};
if (err || responseObject.error) {
var payloadErrorMessage = '[ethjs-rpc] ' + (responseObject.error && 'rpc' || '') + ' error with payload ' + JSON.stringify(parsedPayload, null, self.options.jsonSpace) + ' ' + (err ? String(err) : JSON.stringify(responseObject.error, null, self.options.jsonSpace));
var payloadErrorMessage = "[ethjs-rpc] " + (responseObject.error && 'rpc' || '') + " error with payload " + JSON.stringify(parsedPayload, null, self.options.jsonSpace) + " " + (err ? String(err) : JSON.stringify(responseObject.error, null, self.options.jsonSpace));
var payloadError = new Error(payloadErrorMessage);

@@ -174,8 +168,5 @@ payloadError.value = err || responseObject.error;

}
resolve(responseObject.result);
return;
});
});
if (callback) {

@@ -182,0 +173,0 @@ // connect promise resolve handlers to callback

@@ -17,3 +17,3 @@ const path = require('path');

test: /\.json$/,
loader: 'json-loader',
loaders: ['json-loader'],
},

@@ -31,3 +31,3 @@ ],

plugins: [
new webpack.BannerPlugin({ banner: ' /* eslint-disable */ ', raw: true, entryOnly: true }),
new webpack.BannerPlugin({ banner: '/* eslint-disable */', raw: true, entryOnly: true }),
new webpack.optimize.OccurrenceOrderPlugin(),

@@ -43,19 +43,19 @@ new webpack.DefinePlugin({

config.plugins
.push(new webpack.optimize.UglifyJsPlugin({
compressor: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
warnings: false,
screw_ie8: false,
},
mangle: {
screw_ie8: false,
},
output: {
screw_ie8: false,
},
}));
.push(new webpack.optimize.UglifyJsPlugin({
compressor: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
warnings: false,
screw_ie8: false,
},
mangle: {
screw_ie8: false,
},
output: {
screw_ie8: false,
},
}));
}
module.exports = config;

@@ -1,5 +0,4 @@

'use strict';
"use strict";
var promiseToCallback = require('promise-to-callback');
module.exports = EthRPC;

@@ -18,7 +17,5 @@

var optionsObject = options || {};
if (!(this instanceof EthRPC)) {
throw new Error('[ethjs-rpc] the EthRPC object requires the "new" flag in order to function normally (i.e. `const eth = new EthRPC(provider);`).');
}
self.options = Object.assign({

@@ -31,5 +28,4 @@ jsonSpace: optionsObject.jsonSpace || 0,

if (typeof provider !== 'object') {
throw new Error('[ethjs-rpc] the EthRPC object requires that the first input \'provider\' must be an object, got \'' + typeof provider + '\' (i.e. \'const eth = new EthRPC(provider);\')');
throw new Error("[ethjs-rpc] the EthRPC object requires that the first input 'provider' must be an object, got '" + typeof provider + "' (i.e. 'const eth = new EthRPC(provider);')");
}
self.currentProvider = provider;

@@ -52,9 +48,7 @@ };

var parsedPayload = createPayload(payload, self.idCounter++);
var promise = new Promise(function (resolve, reject) {
self.currentProvider.sendAsync(parsedPayload, function (err, response) {
var responseObject = response || {};
if (err || responseObject.error) {
var payloadErrorMessage = '[ethjs-rpc] ' + (responseObject.error && 'rpc' || '') + ' error with payload ' + JSON.stringify(parsedPayload, null, self.options.jsonSpace) + ' ' + (err ? String(err) : JSON.stringify(responseObject.error, null, self.options.jsonSpace));
var payloadErrorMessage = "[ethjs-rpc] " + (responseObject.error && 'rpc' || '') + " error with payload " + JSON.stringify(parsedPayload, null, self.options.jsonSpace) + " " + (err ? String(err) : JSON.stringify(responseObject.error, null, self.options.jsonSpace));
var payloadError = new Error(payloadErrorMessage);

@@ -65,8 +59,5 @@ payloadError.value = err || responseObject.error;

}
resolve(responseObject.result);
return;
});
});
if (callback) {

@@ -73,0 +64,0 @@ // connect promise resolve handlers to callback

@@ -1,10 +0,10 @@

'use strict';
"use strict";
var EthRPC = require('../index.js');
var assert = require('chai').assert;
var _require = require('chai'),
assert = _require.assert;
var TestRPC = require('ganache-cli');
var HTTPProvider = require('@metamask/ethjs-provider-http');
var EthRPC = require('../index.js');
var provider = TestRPC.provider({});
var provider2 = TestRPC.provider({});
describe('ethjs-rpc', function () {

@@ -14,3 +14,2 @@ describe('construction', function () {

var eth = new EthRPC(provider);
assert.equal(typeof eth, 'object');

@@ -20,5 +19,4 @@ assert.equal(typeof eth.currentProvider, 'object');

});
it('should throw when invalid construction params', function () {
assert.throws(function () {
assert["throws"](function () {
return EthRPC(provider);

@@ -32,14 +30,18 @@ }, Error); // eslint-disable-line

var eth = new EthRPC(provider);
eth.sendAsync({ method: 'eth_accounts' }, function (err, accounts1) {
eth.sendAsync({
method: 'eth_accounts'
}, function (err, accounts1) {
assert.equal(err, null);
eth.setProvider(provider2);
eth.sendAsync({ method: 'eth_accounts' }, function (err2, accounts2) {
eth.sendAsync({
method: 'eth_accounts'
}, function (err2, accounts2) {
assert.equal(err2, null);
assert.notDeepEqual(accounts1, accounts2);
eth.sendAsync({ method: 'eth_accounts' }).then(function (accounts3) {
eth.sendAsync({
method: 'eth_accounts'
}).then(function (accounts3) {
assert.deepEqual(accounts3, accounts2);
done();
})['catch'](function (error) {
})["catch"](function (error) {
return console.log(error);

@@ -52,3 +54,3 @@ }); // eslint-disable-line

it('should handle invalid provider', function () {
assert.throws(function () {
assert["throws"](function () {
return new EthRPC(23423);

@@ -58,7 +60,8 @@ }, Error);

});
describe('sendAsync', function () {
it('should handle normal calls', function (done) {
var eth = new EthRPC(provider);
eth.sendAsync({ method: 'eth_accounts' }, function (err, accounts1) {
eth.sendAsync({
method: 'eth_accounts'
}, function (err, accounts1) {
assert.equal(err, null);

@@ -70,8 +73,13 @@ assert.equal(Array.isArray(accounts1), true);

});
it('should handle invalid response', function (done) {
var eth = new EthRPC({ sendAsync: function sendAsync(payload, cb) {
cb(null, { error: 'Some Error!!' });
} });
eth.sendAsync({ method: 'eth_accounts' }, function (err, accounts1) {
var eth = new EthRPC({
sendAsync: function sendAsync(payload, cb) {
cb(null, {
error: 'Some Error!!'
});
}
});
eth.sendAsync({
method: 'eth_accounts'
}, function (err, accounts1) {
assert.equal(typeof err, 'object');

@@ -82,3 +90,2 @@ assert.equal(accounts1, null);

});
it('should handle invalid response from infura ropsten geth/parity nodes', function (done) {

@@ -91,7 +98,13 @@ var infuraProvider = new HTTPProvider('https://ropsten.infura.io');

params: [{
'gas': '0x2dc6c0', // eslint-disable-line
'value': '0x00', // eslint-disable-line
'from': '0x70ad465e0bab6504002ad58c744ed89c7da38524', // eslint-disable-line
'to': '0xad7d27bc87dba2f5ebcaeb1e7670a1d18104087b', // eslint-disable-line
'data': '0xd89b73d00000000000000000000000000000000000000000000000000000000000000000' }, 'latest'], // eslint-disable-line
'gas': '0x2dc6c0',
// eslint-disable-line
'value': '0x00',
// eslint-disable-line
'from': '0x70ad465e0bab6504002ad58c744ed89c7da38524',
// eslint-disable-line
'to': '0xad7d27bc87dba2f5ebcaeb1e7670a1d18104087b',
// eslint-disable-line
'data': '0xd89b73d00000000000000000000000000000000000000000000000000000000000000000'
}, 'latest'],
// eslint-disable-line
'method': 'eth_call' // eslint-disable-line

@@ -104,8 +117,11 @@ }, function (err, accounts1) {

});
it('should handle invalid errors', function (done) {
var eth = new EthRPC({ sendAsync: function sendAsync(payload, cb) {
var eth = new EthRPC({
sendAsync: function sendAsync(payload, cb) {
cb('Some error!');
} });
eth.sendAsync({ method: 'eth_accounts' }, function (err, accounts1) {
}
});
eth.sendAsync({
method: 'eth_accounts'
}, function (err, accounts1) {
assert.equal(typeof err, 'object');

@@ -117,3 +133,2 @@ assert.equal(accounts1, null);

});
describe('sendAsync - error handling', function () {

@@ -123,4 +138,3 @@ // this test relies on disabling mocha's default handling of "uncaughtException"

var uncaughtExceptionListeners = void 0;
var uncaughtExceptionListeners;
before(function () {

@@ -131,3 +145,2 @@ // Stop Mocha from handling uncaughtExceptions.

});
after(function () {

@@ -139,3 +152,2 @@ // Resume normal Mocha handling of uncaughtExceptions.

});
it('should call the callback only once', function (done) {

@@ -145,12 +157,12 @@ var eth = new EthRPC(provider);

var callbackCalled = 0;
var uncaughtException = void 0;
var uncaughtException;
process.prependOnceListener('uncaughtException', function (err) {
uncaughtException = err;
});
eth.sendAsync({ method: 'eth_accounts' }, function () {
eth.sendAsync({
method: 'eth_accounts'
}, function () {
callbackCalled++;
throw new Error(errorMessage);
});
setTimeout(function () {

@@ -157,0 +169,0 @@ assert.equal(callbackCalled, 1, 'callback called only once.');

{
"name": "@metamask/ethjs-rpc",
"version": "0.3.2",
"version": "0.4.0",
"description": "A super simple module for querying the Ethereum RPC layer without formatting.",

@@ -26,3 +26,2 @@ "main": "lib/index.js",

"lint:js": "npm run lint:eslint -- . ",
"lint:staged": "lint-staged",
"test:clean": "rimraf ./coverage",

@@ -56,3 +55,3 @@ "test": "mocha ./src/tests/**/*.js -R spec --timeout 2000000",

[
"transform-es2015-template-literals",
"@babel/plugin-transform-template-literals",
{

@@ -62,8 +61,8 @@ "loose": true

],
"transform-es2015-literals",
"transform-es2015-function-name",
"transform-es2015-arrow-functions",
"transform-es2015-block-scoped-functions",
"@babel/plugin-transform-literals",
"@babel/plugin-transform-function-name",
"@babel/plugin-transform-arrow-functions",
"@babel/plugin-transform-block-scoped-functions",
[
"transform-es2015-classes",
"@babel/plugin-transform-classes",
{

@@ -73,6 +72,6 @@ "loose": true

],
"transform-es2015-object-super",
"transform-es2015-shorthand-properties",
"@babel/plugin-transform-object-super",
"@babel/plugin-transform-shorthand-properties",
[
"transform-es2015-computed-properties",
"@babel/plugin-transform-computed-properties",
{

@@ -83,3 +82,3 @@ "loose": true

[
"transform-es2015-for-of",
"@babel/plugin-transform-for-of",
{

@@ -89,7 +88,6 @@ "loose": true

],
"transform-es2015-sticky-regex",
"transform-es2015-unicode-regex",
"check-es2015-constants",
"@babel/plugin-transform-sticky-regex",
"@babel/plugin-transform-unicode-regex",
[
"transform-es2015-spread",
"@babel/plugin-transform-spread",
{

@@ -99,5 +97,5 @@ "loose": true

],
"transform-es2015-parameters",
"@babel/plugin-transform-parameters",
[
"transform-es2015-destructuring",
"@babel/plugin-transform-destructuring",
{

@@ -107,6 +105,6 @@ "loose": true

],
"transform-es2015-block-scoping",
"transform-object-rest-spread",
"transform-es3-member-expression-literals",
"transform-es3-property-literals"
"@babel/plugin-transform-block-scoping",
"@babel/plugin-transform-object-rest-spread",
"@babel/plugin-transform-member-expression-literals",
"@babel/plugin-transform-property-literals"
],

@@ -117,3 +115,3 @@ "env": {

[
"transform-es2015-modules-commonjs",
"@babel/plugin-transform-modules-commonjs",
{

@@ -131,52 +129,47 @@ "loose": true

"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/eslint-parser": "^7.0.0",
"@babel/plugin-transform-arrow-functions": "^7.0.0",
"@babel/plugin-transform-block-scoped-functions": "^7.0.0",
"@babel/plugin-transform-block-scoping": "^7.0.0",
"@babel/plugin-transform-classes": "^7.0.0",
"@babel/plugin-transform-computed-properties": "^7.0.0",
"@babel/plugin-transform-destructuring": "^7.0.0",
"@babel/plugin-transform-for-of": "^7.0.0",
"@babel/plugin-transform-function-name": "^7.0.0",
"@babel/plugin-transform-literals": "^7.0.0",
"@babel/plugin-transform-modules-commonjs": "^7.0.0",
"@babel/plugin-transform-object-super": "^7.0.0",
"@babel/plugin-transform-parameters": "^7.0.0",
"@babel/plugin-transform-shorthand-properties": "^7.0.0",
"@babel/plugin-transform-spread": "^7.0.0",
"@babel/plugin-transform-sticky-regex": "^7.0.0",
"@babel/plugin-transform-template-literals": "^7.0.0",
"@babel/plugin-transform-unicode-regex": "^7.0.0",
"@babel/plugin-transform-member-expression-literals": "^7.0.0",
"@babel/plugin-transform-property-literals": "^7.0.0",
"@babel/plugin-transform-object-rest-spread": "^7.0.0",
"@babel/register": "^7.0.0",
"@metamask/ethjs-provider-http": "^0.2.0",
"babel-cli": "6.18.0",
"babel-core": "6.18.2",
"babel-eslint": "7.1.0",
"babel-loader": "6.2.8",
"babel-plugin-check-es2015-constants": "6.8.0",
"babel-plugin-transform-es2015-arrow-functions": "6.8.0",
"babel-plugin-transform-es2015-block-scoped-functions": "6.8.0",
"babel-plugin-transform-es2015-block-scoping": "6.18.0",
"babel-plugin-transform-es2015-classes": "6.18.0",
"babel-plugin-transform-es2015-computed-properties": "6.8.0",
"babel-plugin-transform-es2015-destructuring": "6.19.0",
"babel-plugin-transform-es2015-for-of": "6.18.0",
"babel-plugin-transform-es2015-function-name": "6.9.0",
"babel-plugin-transform-es2015-literals": "6.8.0",
"babel-plugin-transform-es2015-modules-commonjs": "6.18.0",
"babel-plugin-transform-es2015-object-super": "6.8.0",
"babel-plugin-transform-es2015-parameters": "6.18.0",
"babel-plugin-transform-es2015-shorthand-properties": "6.18.0",
"babel-plugin-transform-es2015-spread": "6.8.0",
"babel-plugin-transform-es2015-sticky-regex": "6.8.0",
"babel-plugin-transform-es2015-template-literals": "6.8.0",
"babel-plugin-transform-es2015-unicode-regex": "6.11.0",
"babel-plugin-transform-es3-member-expression-literals": "6.5.0",
"babel-plugin-transform-es3-property-literals": "6.5.0",
"babel-plugin-transform-object-rest-spread": "6.19.0",
"babel-register": "6.18.0",
"bignumber.js": "3.0.1",
"chai": "3.5.0",
"cross-env": "6.0.3",
"eslint": "2.10.1",
"eslint-config-airbnb": "9.0.1",
"eslint-import-resolver-webpack": "0.2.4",
"eslint-plugin-import": "1.8.0",
"eslint-plugin-jsx-a11y": "1.2.0",
"eslint-plugin-react": "5.1.1",
"babel-loader": "^8.0.0",
"bignumber.js": "^9.1.2",
"chai": "^4.3.10",
"cross-env": "^6.0.3",
"eslint": "^5.4.0",
"eslint-config-airbnb": "^17.1.1",
"eslint-import-resolver-webpack": "^0.2.4",
"eslint-plugin-import": "^2.18.0",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.14.2",
"ganache-cli": "6.12.2",
"istanbul": "0.4.5",
"json-loader": "^0.5.7",
"lint-staged": "1.0.1",
"mocha": "^5.1.1",
"pre-commit": "1.1.3",
"rimraf": "2.3.4",
"mocha": "^7.1.2",
"pre-commit": "^1.2.2",
"rimraf": "^3.0.2",
"webpack": "^3.12.0"
},
"lint-staged": {
"lint:eslint": "*.js"
},
"eslintConfig": {
"parser": "babel-eslint",
"parser": "@babel/eslint-parser",
"extends": "airbnb",

@@ -188,4 +181,16 @@ "env": {

},
"overrides": [
{
"files": [
"src/tests/**.js"
],
"rules": {
"import/extensions": 0,
"import/no-extraneous-dependencies": 0
}
}
],
"parserOptions": {
"ecmaVersion": 6,
"requireConfigFile": false,
"sourceType": "module"

@@ -206,2 +211,5 @@ },

],
"operator-assignment": 0,
"no-plusplus": 0,
"no-mixed-operators": 0,
"no-console": 1,

@@ -218,2 +226,5 @@ "max-len": 0,

},
"peerDependencies": {
"@babel/runtime": "^7.0.0"
},
"publishConfig": {

@@ -220,0 +231,0 @@ "access": "public",

@@ -58,3 +58,2 @@ const promiseToCallback = require('promise-to-callback');

resolve(responseObject.result);
return;
});

@@ -61,0 +60,0 @@ });

@@ -1,5 +0,6 @@

const EthRPC = require('../index.js');
const assert = require('chai').assert;
const { assert } = require('chai');
const TestRPC = require('ganache-cli');
const HTTPProvider = require('@metamask/ethjs-provider-http');
const EthRPC = require('../index.js');
const provider = TestRPC.provider({});

@@ -35,6 +36,6 @@ const provider2 = TestRPC.provider({});

eth.sendAsync({ method: 'eth_accounts' })
.then((accounts3) => {
assert.deepEqual(accounts3, accounts2);
done();
})
.then((accounts3) => {
assert.deepEqual(accounts3, accounts2);
done();
})
.catch((error) => console.log(error)); // eslint-disable-line

@@ -62,5 +63,7 @@ });

it('should handle invalid response', (done) => {
const eth = new EthRPC({ sendAsync: (payload, cb) => {
cb(null, { error: 'Some Error!!' });
} });
const eth = new EthRPC({
sendAsync: (payload, cb) => {
cb(null, { error: 'Some Error!!' });
},
});
eth.sendAsync({ method: 'eth_accounts' }, (err, accounts1) => {

@@ -94,5 +97,7 @@ assert.equal(typeof err, 'object');

it('should handle invalid errors', (done) => {
const eth = new EthRPC({ sendAsync: (payload, cb) => {
cb('Some error!');
} });
const eth = new EthRPC({
sendAsync: (payload, cb) => {
cb('Some error!');
},
});
eth.sendAsync({ method: 'eth_accounts' }, (err, accounts1) => {

@@ -99,0 +104,0 @@ assert.equal(typeof err, 'object');

Sorry, the diff of this file is not supported yet

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