Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Commit

Permalink
dev(Webpack): 🚀 (#329)
Browse files Browse the repository at this point in the history
* dev(Webpack): basic webpack configuration working

* dev(Webpack): string replacement plugin for optimizing hdnode

* dev(Webpack): optimizations when building for dist

* dev(Webpack): remove Gruntfile and grunt deps

* dev(Webpack): update readme and makefile

* dev(Build): reduce bundle size by selectively importing from ramda

* dep(Node): from 5.8 to 7.5

* build(Coveralls): run without grunt

* build(Travis): cache node_modules
  • Loading branch information
jtormey authored and Sjors committed Feb 14, 2017
1 parent ae04119 commit 55e5206
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 197 deletions.
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
language: node_js
node_js:
- 5.8
- 7.5
cache:
- node_modules
before_install:
- npm install -g snazzy
before_script:
- node_modules/.bin/semistandard --verbose | snazzy
script: node_modules/karma/bin/karma start karma.conf.js --single-run && grunt coveralls
script:
- node_modules/karma/bin/karma start karma.conf.js --single-run
- cat ./coverage-lcov/lcov.info | node_modules/coveralls/bin/coveralls.js
notifications:
slack:
secure: QknuKmAVfKhlGjFoJVXbKaWh6ee/rph/gldqWcxCHnoXHtCQ+v02Q2WrEL9YiQtOIXQoPjqtMptjjVlBgoFYaAnXmQEpBa5IYwbTvm0T7A+fJaojr8bOi6HHohr8nrDuldtTSNLDVP135zJyzl/gpz0oUPyHCgJx02lQ3j5sVUmx99OxTFzPHAdHoRS+vj5AiCjRhalzkCrQBXq41UrJXmY4xdub4+attdQJf4lr5RMd1ZB1PNj4z94rTHSuYtvBxXrYNkiyPs58861JRCT7P+1dy5beS5OG0OeF+iN+tj9XUNBrqCiWnu3i4vKYmHr7xVyxLXOmo7DvR8o55qY9PhB1OkCmt5qHpoSB7r39f/Y2tg6mwwXz7dnnnnwnIMsKzQ1eVNXF4dqbf12iaJTQNOb4t69s6kn/ybeD3h7SGLTPl6Z1xQHWcTk4GrzfWNRK12cvMAULWOS7uyZlhJnNneyoIm7cLoBJKdsaQmSV998ZAu4qHjozKeHRi08UdNtyrsQ6KqUxof8haPU1L/p+enSCLJfYDBnYVspwtQVRIlFsmCqowM6JEl1Doc+be5/CVisQ7/IEROoNSz2Z7uNXIMgaiK+K3sB+3PFNWSuBT2Z35HtnCCNy2kwE5sAGxyGs/DUYe4uIQmE44ec7dtQRn4N8NaM/LlSclJaMlq/jVTk=
156 changes: 0 additions & 156 deletions Gruntfile.js

This file was deleted.

6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ node_modules:
npm install

build:
grunt build
npm run build

test: build
./node_modules/karma/bin/karma start karma.conf.js --single-run

dist/application.min.js:
grunt dist
npm run dist
npm shrinkwrap --dev

semistandard:
Expand All @@ -29,5 +29,5 @@ changelog: node_modules
node_modules/git-changelog/tasks/command.js $(TAG_ARG)

clean:
rm -rf build dist node_modules npm-shrinkwrap.json Changelog.md
rm -rf dist node_modules npm-shrinkwrap.json Changelog.md
npm cache clean
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ JavaScript Model for Blockchain.info wallet.

```sh
npm install
grunt build
npm run build
```

## Tests
Expand All @@ -20,7 +20,7 @@ npm test
Watch files and re-build

```sh
grunt
npm run build:watch
```

## Clean
Expand Down
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,5 @@ module.exports = {
BigInteger: require('bigi/lib'),
BIP39: require('bip39'),
Networks: require('bitcoinjs-lib/src/networks'),
ECDSA: require('bitcoinjs-lib/src/ecdsa'),
R: require('ramda')
ECDSA: require('bitcoinjs-lib/src/ecdsa')
};
29 changes: 12 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
},
"scripts": {
"postinstall": "cd node_modules/sjcl || cd ../sjcl && ./configure --with-sha1 && make",
"disc": "browserify --full-paths index.js | discify --open",
"disc:min": "browserify --full-paths index.js | uglifyjs | discify --open",
"dist": "NODE_ENV=\"prod\" ./node_modules/.bin/webpack",
"build": "./node_modules/.bin/webpack --progress",
"build:watch": "./node_modules/.bin/webpack -w",
"clean": "rm -rf dist/ coverage/ coverage-lcov/",
"test": "./node_modules/karma/bin/karma start karma.conf.js"
},
"browser": {
Expand All @@ -48,31 +50,21 @@
"sjcl": "1.0.3",
"unorm": "^1.4.1",
"ws": "2.0.*",
"pbkdf2": "3.0.4",
"bitcoin-coinify-client": "0.3.*",
"bitcoin-sfox-client": "0.1.*"
},
"devDependencies": {
"babel-loader": "6.2.10",
"babel-polyfill": "6.16.*",
"babel-preset-es2015": "6.16.*",
"babel-preset-es2015": "~6.16.0",
"babelify": "7.3.*",
"browserify": "13.*",
"browserify-istanbul": "2.0.*",
"bs58check": "^1.0.5",
"coveralls": "^2.11.16",
"eslint": "2.*",
"fetch-mock": "^5.1.2",
"git-changelog": "1.0.*",
"grunt": "^0.4.5",
"grunt-browserify": "5.0.*",
"grunt-cli": "^0.1.13",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-uglify": "^0.8.0",
"grunt-contrib-watch": "^0.6.1",
"grunt-env": "^0.4.4",
"grunt-karma-coveralls": "^2.5.4",
"grunt-preprocess": "^4.1.0",
"grunt-text-replace": "^0.4.0",
"istanbul": "~0.4.5",
"jasmine-core": "^2.2.0",
"jasmine-es6-promise-matchers": "^2.0.1",
Expand All @@ -84,7 +76,10 @@
"karma-phantomjs-launcher": "1.0.*",
"phantomjs-prebuilt": "2.1.*",
"proxyquireify": "3.2.*",
"semistandard": "8.*"
"semistandard": "8.*",
"string-replace-webpack-plugin": "0.0.5",
"watchify": "~3.9.0",
"webpack": "2.2.1"
},
"semistandard": {
"ignore": [],
Expand All @@ -108,6 +103,6 @@
]
},
"engines": {
"node": "5.8"
"node": "7.5"
}
}
33 changes: 19 additions & 14 deletions src/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ var Bitcoin = require('bitcoinjs-lib');
var API = require('./api');
var Helpers = require('./helpers');
var constants = require('./constants');
var R = require('ramda');

// individual imports to reduce bundle size
var assoc = require('ramda/src/assoc');
var curry = require('ramda/src/curry');
var compose = require('ramda/src/compose');
var prop = require('ramda/src/prop');

class Metadata {
constructor (ecPair, encKeyBuffer, typeId) {
Expand Down Expand Up @@ -60,15 +65,15 @@ Metadata.read = (address) => Metadata.request('GET', address)
.then(Metadata.extractResponse(null));

// //////////////////////////////////////////////////////////////////////////////
Metadata.encrypt = R.curry((key, data) => WalletCrypto.encryptDataWithKey(data, key));
Metadata.decrypt = R.curry((key, data) => WalletCrypto.decryptDataWithKey(data, key));
Metadata.encrypt = curry((key, data) => WalletCrypto.encryptDataWithKey(data, key));
Metadata.decrypt = curry((key, data) => WalletCrypto.decryptDataWithKey(data, key));
Metadata.B64ToBuffer = (base64) => Buffer.from(base64, 'base64');
Metadata.BufferToB64 = (buff) => buff.toString('base64');
Metadata.StringToBuffer = (base64) => Buffer.from(base64);
Metadata.BufferToString = (buff) => buff.toString();

// Metadata.message :: Buffer -> Buffer -> Base64String
Metadata.message = R.curry(
Metadata.message = curry(
function (payload, prevMagic) {
if (prevMagic) {
const hash = WalletCrypto.sha256(payload);
Expand All @@ -81,7 +86,7 @@ Metadata.message = R.curry(
);

// Metadata.magic :: Buffer -> Buffer -> Buffer
Metadata.magic = R.curry(
Metadata.magic = curry(
function (payload, prevMagic) {
const msg = this.message(payload, prevMagic);
return Bitcoin.message.magicHash(msg, constants.getNetwork());
Expand All @@ -98,37 +103,37 @@ Metadata.sign = (keyPair, msg) => Bitcoin.message.sign(keyPair, msg, Bitcoin.net
Metadata.computeSignature = (key, payloadBuff, magicHash) =>
Metadata.sign(key, Metadata.message(payloadBuff, magicHash));

Metadata.verifyResponse = R.curry((address, res) => {
Metadata.verifyResponse = curry((address, res) => {
if (res === null) return res;
const M = Metadata;
const sB = res.signature ? Buffer.from(res.signature, 'base64') : undefined;
const pB = res.payload ? Buffer.from(res.payload, 'base64') : undefined;
const mB = res.prev_magic_hash ? Buffer.from(res.prev_magic_hash, 'hex') : undefined;
const verified = Metadata.verify(address, sB, M.message(pB, mB));
if (!verified) throw new Error('METADATA_SIGNATURE_VERIFICATION_ERROR');
return R.assoc('compute_new_magic_hash', M.magic(pB, mB), res);
return assoc('compute_new_magic_hash', M.magic(pB, mB), res);
});

Metadata.extractResponse = R.curry((encKey, res) => {
Metadata.extractResponse = curry((encKey, res) => {
const M = Metadata;
if (res === null) {
return res;
} else {
return encKey
? R.compose(JSON.parse, M.decrypt(encKey), R.prop('payload'))(res)
: R.compose(JSON.parse, M.BufferToString, M.B64ToBuffer, R.prop('payload'))(res);
? compose(JSON.parse, M.decrypt(encKey), prop('payload'))(res)
: compose(JSON.parse, M.BufferToString, M.B64ToBuffer, prop('payload'))(res);
}
});

Metadata.toImmutable = R.compose(Object.freeze, JSON.parse, JSON.stringify);
Metadata.toImmutable = compose(Object.freeze, JSON.parse, JSON.stringify);

Metadata.prototype.create = function (payload) {
const M = Metadata;
payload = M.toImmutable(payload);
return this.next(() => {
const encPayloadBuffer = this._encKeyBuffer
? R.compose(M.B64ToBuffer, M.encrypt(this._encKeyBuffer), JSON.stringify)(payload)
: R.compose(M.StringToBuffer, JSON.stringify)(payload);
? compose(M.B64ToBuffer, M.encrypt(this._encKeyBuffer), JSON.stringify)(payload)
: compose(M.StringToBuffer, JSON.stringify)(payload);
const signatureBuffer = M.computeSignature(this._signKey, encPayloadBuffer, this._magicHash);
const body = {
'version': this.VERSION,
Expand Down Expand Up @@ -160,7 +165,7 @@ Metadata.prototype.fetch = function () {
const M = Metadata;
const saveMagicHash = (res) => {
if (res === null) return res;
this._magicHash = R.prop('compute_new_magic_hash', res);
this._magicHash = prop('compute_new_magic_hash', res);
return res;
};
const saveValue = (res) => {
Expand Down
1 change: 0 additions & 1 deletion src/ws-browser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

var global = (function () { return this; })();
var WebSocket = global.WebSocket || global.MozWebSocket;

function ws (uri, protocols, opts) {
Expand Down
Loading

0 comments on commit 55e5206

Please sign in to comment.