Commit 379e41e1 authored by SilentCicero's avatar SilentCicero

version 0.1.2 -- new builds, less deps, more docs

parent 5cb82f7f
......@@ -76,9 +76,9 @@ included in the project:
```bash
# Clone your fork of the repo into the current directory
git clone https://github.com/<your-username>/default.git
git clone https://github.com/<your-username>/ethjs-provider-signer.git
# Navigate to the newly cloned directory
cd default
cd ethjs-provider-signer
# Assign the original repo to a remote called "upstream"
git remote add upstream https://github.com/ethjs/ethjs-provider-http.git
```
......@@ -113,7 +113,7 @@ included in the project:
7. [Open a Pull Request](https://help.github.com/articles/using-pull-requests/)
with a clear title and description.
**DESIGN NOTE**: default follows the UNIX programming philosophy. Please consider this before contributing, keep your commits/modules concise and to the point.
**DESIGN NOTE**: ethjs-provider-signer follows the UNIX programming philosophy. Please consider this before contributing, keep your commits/modules concise and to the point.
Read more here:
http://www.catb.org/esr/writings/taoup/html/ch01s06.html
......
# 0.1.2 -- remove deps
1. Remove `ethereumjs-tx` and `ethereumjs-util`
2. Uses `ethjs-signer` for signing now, no need to include it in the module
# 0.1.1 -- config fixes
1. webpack config updates
2. build config updates
# 0.0.1 -- ethjs-provider-signer
1. Basic testing
......
......@@ -35,7 +35,7 @@ This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community.
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project maintainer at [email protected]. All
reported by contacting the project maintainer at [email protected]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. Maintainers are
obligated to maintain confidentiality with regard to the reporter of an
......
......@@ -49,9 +49,10 @@ npm install --save ethjs-provider-signer
```js
const SignerProvider = require('ethjs-provider-signer');
const sign = require('ethjs-signer').sign;
const Eth = require('ethjs-query');
const provider = new SignerProvider('http://ropsten.infura.io', {
signTransaction: (rawTx, cb) => cb(null, SignerProvider.sign(rawTx, '0x...privateKey...')),
signTransaction: (rawTx, cb) => cb(null, sign(rawTx, '0x...privateKey...')),
});
const eth = new Eth(provider);
......@@ -70,13 +71,11 @@ A simple wrapper module for `ethjs-provider-http` which allows you to sign sendT
The `signTransaction` method is called everytime a payload must be signed. It provides the raw transaction data, a handy raw transaction signing method and a callback to be fired. The callback must return a single signed alphanumeric hex data payload of the signed raw transaction.
The optionally required signing method `SignerProvider.sign` will sign the raw transaction with your specified private key.
The provided `SignerProvider.sign` method intakes the `rawTx` transaction data and the `privateKey` hex for signing. It returns the hexified string data of the signed transaction.
`ethjs-provider-signer` works well with `ethjs-signer`, a simple module for signing raw transactions. You may also bring your own signer from packages like `ethereumjs-signer`.
## Contributing
Please help better the ecosystem by submitting issues and pull requests to default. We need all the help we can get to build the absolute best linting standards and utilities. We follow the AirBNB linting standard and the unix philosophy.
Please help better the ecosystem by submitting issues and pull requests to `ethjs-provider-signer`. We need all the help we can get to build the absolute best linting standards and utilities. We follow the AirBNB linting standard and the unix philosophy.
## Guides
......
This diff is collapsed.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -90,6 +90,13 @@ After build staging it is the `lib` folder which actually gets published to NPM.
This is a requirement to run, test, lint and build this module.
## Webpack
`ethjs` uses webpack across all its browser focused repos. Webpack is used to package down project files into distribution builds for the browser. You can see the builds it produces by going to the [dist](dist) folder.
Read more about webpack here:
https://github.com/webpack/docs
## Changelog
All relevant changes are notated in the `CHANGELOG.md` file, moniter this file for changes to this repository.
......
......@@ -12,9 +12,10 @@ npm install --save ethjs-provider-signer
```js
const SignerProvider = require('ethjs-provider-signer');
const sign = require('ethjs-signer').sign;
const Eth = require('ethjs-query');
const provider = new SignerProvider('http://ropsten.infura.io', {
signTransaction: (rawTx, cb) => cb(null, SignerProvider.sign(rawTx, '0x...privateKey...')),
const provider = new SignerProvider('https://ropsten.infura.io', {
signTransaction: (rawTx, cb) => cb(null, sign(rawTx, '0x...privateKey...')),
});
const eth = new Eth(provider);
......@@ -46,7 +47,7 @@ Example options **Object**:
const options = {
signTransaction: (rawTx, cb) => {
if (rawTx.from === '0x...') {
cb(null, SignerProvider.sign(rawTx, '0x...privateKey...'));
cb(null, sign(rawTx, '0x...privateKey...'));
} else {
cb('some error');
}
......@@ -73,31 +74,6 @@ eth.sendTransaction({
// results null 0x... (transaction hash)
```
### SignerProvider.sign
[index.js:ethjs-provider-signer](../../../blob/master/src/index.js "Source code on GitHub")
Intakes an Ethereum RPC standard raw transaction object and Ethereum standard private key as a hexified alphanumeric string. Outputs signed transaction data as a hex string.
**Parameters**
- `rawTx` **Object** the raw transaction object (i.e. `{ from: '0x..', to: '0x..', data: '0x', gas: 300000 }`)
- `privateKey` **String** the options object where the `signTransaction` method and `timeout` property is specified.
Result signed transaction data **String**
```js
const SignerProvider = require('ethjs-provider-signer');
const signedHexData = SignerProvider.sign({
from: '0x407d73d8a49eeb85d32cf465507dd71d507100c1',
gas: 300000,
data: '0x',
}, '0xd35c58355a1sc095c7074837467382924180748768s2258ef5f7fa384e6fcb3s');
// result '0xbd685c98ec39490f50d15c67ba2a8e9b5b1d6d7601fca80b295e7d717446bd8b7127ea4871e996cdc8cae7690408b4e800f60ddac49d2ad34180e68f1da0aaf001';
```
## Browser Builds
`ethjs` provides production distributions for all of its modules that are ready for use in the browser right away. Simply include either `dist/ethjs-provider-signer.js` or `dist/ethjs-provider-signer.min.js` directly into an HTML file to start using this module. Note, an `SignerProvider` object is made available globally.
......@@ -114,6 +90,28 @@ Note, even though `ethjs` should have transformed and polyfilled most of the req
Use a polyfill service such as `Polyfill.io` to ensure complete cross-browser support:
https://polyfill.io/
## Webpack Figures
```
Hash: f8ea69e4b882307e0d88
Version: webpack 2.1.0-beta.15
Time: 144ms
Asset Size Chunks Chunk Names
ethjs-provider-signer.js 7.99 kB 0 [emitted] main
ethjs-provider-signer.js.map 9.27 kB 0 [emitted] main
[0] ./lib/index.js 2.45 kB {0} [built]
[3] multi main 28 bytes {0} [built]
+ 2 hidden modules
Asset Size Chunks Chunk Names
ethjs-provider-signer.min.js 3.42 kB 0 [emitted] main
[0] ./lib/index.js 2.45 kB {0} [built]
[3] 1ms -> factory:16ms building:38ms = 55ms
[3] multi main 28 bytes {0} [built]
factory:0ms building:1ms = 1ms
+ 2 hidden modules
```
## Other Awesome Modules, Tools and Frameworks
- [web3.js](https://github.com/ethereum/web3.js) -- the original Ethereum swiss army knife **Ethereum Foundation**
......
......@@ -6,7 +6,6 @@ var filename = 'ethjs-provider-signer'; // eslint-disable-line
var library = 'SignerProvider'; // eslint-disable-line
var config = { // eslint-disable-line
entry: [
'babel-polyfill',
'./lib/index.js',
],
module: {
......@@ -14,7 +13,7 @@ var config = { // eslint-disable-line
{
test: /\.js$/,
loaders: ['babel-loader'],
include: /src|node_modules\/ethereumjs-tx/,
include: /src/,
},
{
test: /\.json$/,
......
{
"name": "ethjs-provider-signer",
"version": "0.1.0",
"version": "0.1.2",
"description": "A simple web3 standard provider object that signs raw transactions.",
"main": "lib/index.js",
"browser": "dist/ethjs-provider-signer.js",
"files": [
"dist",
"internals",
......@@ -20,6 +19,7 @@
"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 --progress",
"build:umd:min": "cross-env BABEL_ENV=commonjs NODE_ENV=production webpack --config ./internals/webpack/webpack.config.js --progress --profile",
"build:umd:stats": "cross-env BABEL_ENV=commonjs NODE_ENV=production webpack --config ./internals/webpack/webpack.config.js --progress --profile --json > dist/stats.json",
"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 --ignore-pattern **/**.min.js",
......@@ -102,12 +102,11 @@
}
},
"dependencies": {
"ethereumjs-tx": "1.1.4",
"ethjs-provider-http": "^0.1.2",
"ethjs-util": "^0.1.1"
"ethjs-provider-http": "0.1.3"
},
"devDependencies": {
"babel-core": "6.18.2",
"ethjs-signer": "0.1.0",
"babel-cli": "6.18.0",
"babel-eslint": "7.1.0",
"babel-loader": "6.2.8",
......
const Tx = require('ethereumjs-tx');
const ethUtil = require('ethjs-util');
const HTTPProvider = require('ethjs-provider-http');
module.exports = SignerProvider;
/**
* Signer provider constructor
*
* @method SignerProvider
* @param {String} path the input data payload
* @param {Object} options the send async callback
* @returns {Object} provider instance
*/
function SignerProvider(path, options) {
if (!(this instanceof SignerProvider)) { throw new Error('[ethjs-provider-signer] the SignerProvider instance requires the "new" flag in order to function normally (e.g. `const eth = new Eth(new SignerProvider(...));`).'); }
if (typeof options !== 'object') { throw new Error(`[ethjs-provider-signer] the SignerProvider requires an options object be provided with the 'privateKey' property specified, you provided type ${typeof options}.`); }
......@@ -15,32 +21,14 @@ function SignerProvider(path, options) {
self.provider = new HTTPProvider(path, self.timeout);
}
// fix ethereumjs-tx rawTx object
function shimEthereumJSTxObject(rawTx) {
const rawTxMutation = Object.assign({}, rawTx);
// fix rawTx gaslimit
if (typeof rawTxMutation.gas === 'string') {
rawTxMutation.gasLimit = rawTxMutation.gas;
delete rawTxMutation.gas;
}
// return new mutated raw tx object
return rawTxMutation;
}
SignerProvider.sign = function signTx(rawTx, privateKey) {
// format raw tx data
const shimmedRawTx = Object.assign({}, shimEthereumJSTxObject(rawTx));
// sign tx object, serilize, convert to hex, privateKey not stored in temp data
const signedHexPayload = new Tx(shimmedRawTx);
signedHexPayload.sign(new Buffer(ethUtil.stripHexPrefix(privateKey), 'hex'));
// ensure hex is prefixed
return `0x${signedHexPayload.serialize().toString('hex')}`;
};
/**
* Send async override
*
* @method sendAsync
* @param {payload} payload the input data payload
* @param {Function} callback the send async callback
* @callback {Object} output the XMLHttpRequest payload
*/
SignerProvider.prototype.sendAsync = function (payload, callback) { // eslint-disable-line
const self = this;
if (payload.method === 'eth_sendTransaction') {
......
......@@ -4,6 +4,7 @@ const SignerProvider = require('../index.js'); // eslint-disable-line
const Eth = require('ethjs-query'); // eslint-disable-line
const Web3 = require('web3'); // eslint-disable-line
const TestRPC = require('ethereumjs-testrpc');
const sign = require('ethjs-signer').sign;
const server = TestRPC.server({
accounts: [{
secretKey: '0xc55c58355a32c095c7074837467382924180748768422589f5f75a384e6f3b33',
......@@ -16,11 +17,11 @@ describe('SignerProvider', () => {
describe('constructor', () => {
it('should construct properly', (done) => {
const provider = new SignerProvider('http://localhost:5001', {
signTransaction: (rawTx, cb) => cb(null, SignerProvider.sign(rawTx, '0xc55c58355a32c095c7074837467382924180748768422589f5f75a384e6f3b33')),
signTransaction: (rawTx, cb) => cb(null, sign(rawTx, '0xc55c58355a32c095c7074837467382924180748768422589f5f75a384e6f3b33')),
});
assert.equal(typeof provider, 'object');
assert.equal(typeof SignerProvider.sign, 'function');
assert.equal(typeof sign, 'function');
assert.equal(typeof provider.options, 'object');
assert.equal(typeof provider.options.signTransaction, 'function');
assert.equal(provider.timeout, 0);
......@@ -41,7 +42,7 @@ describe('SignerProvider', () => {
describe('functionality', () => {
it('should perform normally for calls', (done) => {
const provider = new SignerProvider('http://localhost:5001', {
signTransaction: (rawTx, cb) => cb(null, SignerProvider.sign(rawTx, '0xc55c58355a32c095c7074837467382924180748768422589f5f75a384e6f3b33')),
signTransaction: (rawTx, cb) => cb(null, sign(rawTx, '0xc55c58355a32c095c7074837467382924180748768422589f5f75a384e6f3b33')),
});
const eth = new Eth(provider);
......@@ -61,7 +62,7 @@ describe('SignerProvider', () => {
it('should reconstruct sendTransaction as sendRawTransaction', (done) => {
const provider = new SignerProvider('http://localhost:5001', {
signTransaction: (rawTx, cb) => cb(null, SignerProvider.sign(rawTx, '0xc55c58355a32c095c7074837467382924180748768422589f5f75a384e6f3b33')),
signTransaction: (rawTx, cb) => cb(null, sign(rawTx, '0xc55c58355a32c095c7074837467382924180748768422589f5f75a384e6f3b33')),
});
const eth = new Eth(provider);
......@@ -94,7 +95,7 @@ describe('SignerProvider', () => {
it('should throw an error when key is invalid', (done) => {
const provider = new SignerProvider('http://localhost:5001', {
signTransaction: (rawTx, cb) => cb(null, SignerProvider.sign(rawTx, '0xc55c58355a32c095c70748s746738d92d180748768422589f5f75a384e6f3b33')),
signTransaction: (rawTx, cb) => cb(null, sign(rawTx, '0xc55c58355a32c095c70748s746738d92d180748768422589f5f75a384e6f3b33')),
});
const eth = new Eth(provider);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment