ethjs-format
Advanced tools
Comparing version 0.0.9 to 0.1.0
@@ -0,1 +1,5 @@ | ||
# 0.1.0 -- better coverage | ||
1. better coverage testing | ||
# 0.0.9 -- more schema details for adding | ||
@@ -2,0 +6,0 @@ |
148
package.json
{ | ||
"name": "ethjs-format", | ||
"version": "0.0.9", | ||
"version": "0.1.0", | ||
"description": "A payload formatter for the Ethereum RPC layer.", | ||
"main": "./src/index.js", | ||
"main": "lib/index.js", | ||
"browser": "dist/ethjs-format.js", | ||
"files": [ | ||
"dist", | ||
"internals", | ||
"lib", | ||
"src" | ||
], | ||
"scripts": { | ||
"start": "npm test", | ||
"test": "mocha src/tests/**/*.js -R spec --timeout 2000000", | ||
"release": "npmpub", | ||
"pretest": "npm run lint", | ||
"prepublish": "npm run build", | ||
"prebuild": "npm run build:clean && npm run test", | ||
"build:clean": "npm run test:clean && rimraf ./dist", | ||
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib --copy-files", | ||
"build:umd": "cross-env BABEL_ENV=commonjs NODE_ENV=development webpack --config ./internals/webpack/webpack.config.js ./lib/index.js --progress", | ||
"build:umd:min": "cross-env BABEL_ENV=commonjs NODE_ENV=production webpack --config ./internals/webpack/webpack.config.js ./lib/index.js --progress", | ||
"build": "npm run build:commonjs && npm run test:lib && npm run build:umd && npm run build:umd:min", | ||
"lint": "npm run lint:js", | ||
"lint:eslint": "eslint --ignore-path .gitignore", | ||
"lint:eslint": "eslint --ignore-path .gitignore --ignore-pattern **/**.min.js", | ||
"lint:js": "npm run lint:eslint -- . ", | ||
"lint:staged": "lint-staged", | ||
"test:clean": "rimraf ./coverage", | ||
"test": "mocha ./src/tests/**/*.js -R spec --timeout 2000000", | ||
"test:lib": "mocha ./lib/tests/**/*.js -R spec --timeout 2000000", | ||
"test-travis": "node ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- src/tests/**/*.js -R spec --timeout 2000000", | ||
@@ -39,9 +55,105 @@ "coveralls": "npm run test-travis && cat ./coverage/lcov.info | coveralls" | ||
}, | ||
"engines": { | ||
"npm": ">=3", | ||
"node": ">=6.5.0" | ||
"homepage": "https://github.com/ethjs/ethjs-format#readme", | ||
"babel": { | ||
"plugins": [ | ||
[ | ||
"transform-es2015-template-literals", | ||
{ | ||
"loose": true | ||
} | ||
], | ||
"transform-es2015-literals", | ||
"transform-es2015-function-name", | ||
"transform-es2015-arrow-functions", | ||
"transform-es2015-block-scoped-functions", | ||
[ | ||
"transform-es2015-classes", | ||
{ | ||
"loose": true | ||
} | ||
], | ||
"transform-es2015-object-super", | ||
"transform-es2015-shorthand-properties", | ||
[ | ||
"transform-es2015-computed-properties", | ||
{ | ||
"loose": true | ||
} | ||
], | ||
[ | ||
"transform-es2015-for-of", | ||
{ | ||
"loose": true | ||
} | ||
], | ||
"transform-es2015-sticky-regex", | ||
"transform-es2015-unicode-regex", | ||
"check-es2015-constants", | ||
[ | ||
"transform-es2015-spread", | ||
{ | ||
"loose": true | ||
} | ||
], | ||
"transform-es2015-parameters", | ||
[ | ||
"transform-es2015-destructuring", | ||
{ | ||
"loose": true | ||
} | ||
], | ||
"transform-es2015-block-scoping", | ||
"transform-object-rest-spread", | ||
"transform-es3-member-expression-literals", | ||
"transform-es3-property-literals" | ||
], | ||
"env": { | ||
"commonjs": { | ||
"plugins": [ | ||
[ | ||
"transform-es2015-modules-commonjs", | ||
{ | ||
"loose": true | ||
} | ||
] | ||
] | ||
} | ||
} | ||
}, | ||
"homepage": "https://github.com/ethjs/ethjs-format#readme", | ||
"dependencies": { | ||
"bignumber.js": "3.0.1", | ||
"ethjs-util": "0.1.1" | ||
}, | ||
"devDependencies": { | ||
"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", | ||
"check-es3-syntax-cli": "0.1.3", | ||
"webpack": "2.1.0-beta.15", | ||
"json-loader": "0.5.4", | ||
"rimraf": "2.3.4", | ||
"cross-env": "1.0.7", | ||
"chai": "3.5.0", | ||
@@ -65,22 +177,2 @@ "coveralls": "2.11.9", | ||
}, | ||
"dependencies": { | ||
"ethjs-util": "0.0.3", | ||
"assert": "1.4.1", | ||
"bignumber.js": "3.0.1" | ||
}, | ||
"babel": { | ||
"presets": [ | ||
"es2015" | ||
], | ||
"plugins": [ | ||
[ | ||
"module-resolver", | ||
{ | ||
"root": [ | ||
"./src" | ||
] | ||
} | ||
] | ||
] | ||
}, | ||
"lint-staged": { | ||
@@ -87,0 +179,0 @@ "lint:eslint": "*.js" |
@@ -67,49 +67,4 @@ ## ethjs-format | ||
## Encoding/Decoding | ||
## Supported RPC Methods | ||
`ethjs-format` mainly helps in the process of handling and encoding things like quantities (i.e numbers) either before or after payload transport. | ||
### Quantities | ||
Will encode quantities such as: `BigNumber`, `'string nums'`, `numbers` into hex. Decodes hex numbers into `BigNumber` objects. Very much like web3.js. | ||
### Data | ||
Will very carefully prefix unprefixed data such as `{data: ''}` to `{data: '0x'}` for encoding. Otherwise does nothing to DATA typed fields in or out. 32 and 20 byte data requirements are enforced across all incoming and outgoing payloads, however `0x` empty data is allowed. | ||
### Objects | ||
Will encode complex RPC objects like the `eth_sendTransaction` input object structure `{from: ..., data: ..., gas: ...}` for RPC payloads. For complex objects, it also enforces by `throw` required fields such as `from` and `data` for the `eth_sendTransaction` input object. | ||
```js | ||
const format = require('ethjs-format'); | ||
const inputPayload = format.formatInputs('eth_sendTransaction', [{ | ||
"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155", | ||
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567", | ||
"gas": new BigNumber("30400"), // 30400, | ||
"gasPrice": "10000000000000", // 10000000000000 | ||
"value": 2441406250, // 2441406250 | ||
"data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675" | ||
}]); | ||
/* result | ||
[{ | ||
from: '0xb60e8dd61c5d32be8058bb8eb970870f07233155', | ||
to: '0xd46e8dd67c5d32be8058bb8eb970870f07244567', | ||
gas: '0x76c0', | ||
gasPrice: '0x9184e72a000', | ||
value: '0x9184e72a', | ||
data: '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675' | ||
}] | ||
*/ | ||
const outputPayload = format.formatOutputs('eth_sendTransaction', "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331"); | ||
// result "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331" | ||
``` | ||
## Methods Supported | ||
``` | ||
@@ -184,10 +139,8 @@ web3_clientVersion | ||
<!-- | ||
## Guides | ||
You'll find more detailed information on using default and tailoring it to your needs in our guides: | ||
You'll find more detailed information on using `ethjs-format` and tailoring it to your needs in our guides: | ||
- [User guide](docs/user-guide.md) - Usage, configuration, FAQ and complementary tools. | ||
- [Developer guide](docs/developer-guide.md) - Contributing to wafr and writing your own plugins & formatters. | ||
--> | ||
- [Developer guide](docs/developer-guide.md) - Contributing to `ethjs-format` and writing your own code and coverage. | ||
@@ -198,8 +151,8 @@ ## Help out | ||
<!-- - Create, enhance, and debug rules (see our guide to ["Working on rules"](./github/CONTRIBUTING.md)). --> | ||
- Create, enhance, and debug ethjs rules (see our guide to ["Working on rules"](./github/CONTRIBUTING.md)). | ||
- Improve documentation. | ||
- Chime in on any open issue or pull request. | ||
- Open new issues about your ideas for making stylelint better, and pull requests to show us how your idea works. | ||
- Open new issues about your ideas for making `ethjs-format` better, and pull requests to show us how your idea works. | ||
- Add new tests to *absolutely anything*. | ||
- Create or contribute to ecosystem tools, like the plugins for Atom and Sublime Text. | ||
- Create or contribute to ecosystem tools, like modules for encoding or contracts. | ||
- Spread the word. | ||
@@ -206,0 +159,0 @@ |
@@ -77,3 +77,3 @@ const schema = require('./schema.json'); | ||
* @param {String|Array} formatter the unit to convert to, default ether | ||
* @param {Object} value of the unit (in Wei) | ||
* @param {Object} value the object value | ||
* @param {Boolean} encode encode to hex or decode to BigNumber | ||
@@ -116,3 +116,3 @@ * @returns {Object} output object | ||
* @param {String|Array} formatter the unit to convert to, default ether | ||
* @param {Object} value of the unit (in Wei) | ||
* @param {Object} value the value in question | ||
* @param {Boolean} encode encode to hex or decode to BigNumber | ||
@@ -175,2 +175,3 @@ * @param {Number} lengthRequirement the required minimum array length | ||
var output = value; // eslint-disable-line | ||
var outputByteLength = 0; // eslint-disable-line | ||
@@ -184,3 +185,5 @@ // prefix only under strict conditions, else bypass | ||
const outputByteLength = getBinarySize(output); | ||
if (typeof value === 'string') { | ||
outputByteLength = getBinarySize(output); | ||
} | ||
@@ -187,0 +190,0 @@ // throw if bytelength is not correct |
@@ -40,2 +40,35 @@ /* eslint-disable */ | ||
it('test format object EthSyncing', () => { | ||
const objEth = { | ||
startingBlock: "0x57840CC2C", | ||
currentBlock: "0x57840CC2C", | ||
highestBlock: "0x57840CC2C", | ||
}; | ||
assert.deepEqual(format.formatObject('Boolean|EthSyncing', objEth).startingBlock.toNumber(10) > 0, true); | ||
}); | ||
it('test is required keys are filled, should throw', () => { | ||
const encodedSendTransactionObject = { | ||
'to': '0xd46e8dd67c5d32be8058bb8eb970870f07244567', | ||
'gas': '0x76c0', // 30400, | ||
'gasPrice': '0x9184e72a000', // 10000000000000 | ||
'value': '0x9184e72a', // 2441406250 | ||
'data': '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675' | ||
}; | ||
assert.throws(() => { | ||
format.formatObject('SendTransaction', encodedSendTransactionObject); | ||
}, Error); | ||
}); | ||
it('test format array', () => { | ||
assert.deepEqual(format.formatArray('Array|DATA', ['0x']), ['0x']); | ||
}); | ||
it('test format array', () => { | ||
assert.deepEqual(format.formatArray('FilterChange', ['0xdf829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf55']), ['0xdf829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf55']); | ||
}); | ||
it('should decode normally', () => { | ||
@@ -42,0 +75,0 @@ const prefixHexNumber = '0x57840CC2C'; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
616023
2
7923
48
14
194
1
1
+ Addedethjs-util@0.1.1(transitive)
- Removedassert@1.4.1
- Removedassert@1.4.1(transitive)
- Removedethjs-filter@0.0.1(transitive)
- Removedethjs-util@0.0.3(transitive)
- Removedinherits@2.0.1(transitive)
- Removedutil@0.10.3(transitive)
Updatedethjs-util@0.1.1