diff --git a/.gitignore b/.gitignore index 0018651f3..b71d059ba 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,4 @@ main.js.map .idea .vscode +/config/tsconfig.tslint.json diff --git a/app/lib/crypto/pbkdf2.ts b/app/lib/crypto/pbkdf2.ts deleted file mode 100644 index 2b17c7974..000000000 --- a/app/lib/crypto/pbkdf2.ts +++ /dev/null @@ -1,61 +0,0 @@ -import {Errors} from "./errors" - -const assert = require("assert") -const crypto = require("crypto") - -/** - * PBKDF2 - * https://github.com/stayradiated/pbkdf2-sha512 - * @param {string | Buffer} key - * @param {string | Buffer} salt - * @param {number} iterations - * @param {number} dkLen - * @returns {Buffer} - */ -export const pbkdf2 = - (key: string | Buffer, salt: string | Buffer, iterations: number, dkLen: number) => { - const hLen = 64 // SHA512 Mac length - const validKeyLength = dkLen <= (Math.pow(2, 32) - 1) * hLen - assert(validKeyLength, Errors.INVALID_KEY_LENGTH) - - const saltBuffer = (typeof salt === "string") ? Buffer.from(salt) : salt - const keyBuffer = (typeof key === "string") ? Buffer.from(key) : key - - const DK = Buffer.alloc(dkLen) - const T = Buffer.alloc(hLen) - - const block1 = Buffer.alloc(saltBuffer.length + 4) - - const l = Math.ceil(dkLen / hLen) - const r = dkLen - (l - 1) * hLen - - saltBuffer.copy(block1, 0, 0, saltBuffer.length) - for (let i = 1; i <= l; i++) { - block1[saltBuffer.length + 0] = (i >> 24 & 0xFF) - block1[saltBuffer.length + 1] = (i >> 16 & 0xFF) - block1[saltBuffer.length + 2] = (i >> 8 & 0xFF) - block1[saltBuffer.length + 3] = (i >> 0 & 0xFF) - - let U = crypto.createHmac("sha512", keyBuffer) - .update(block1) - .digest() - - U.copy(T, 0, 0, hLen) - - for (let j = 1; j < iterations; j++) { - U = crypto.createHmac("sha512", keyBuffer) - .update(U) - .digest() - - for (let k = 0; k < hLen; k++) { - T[k] ^= U[k] - } - } - - const destPos = (i - 1) * hLen - const len = (i === l ? r : hLen) - T.copy(DK, destPos, 0, len) - } - - return DK -} \ No newline at end of file diff --git a/app/lib/chain/chainType.ts b/app/main/chain/chainType.ts similarity index 100% rename from app/lib/chain/chainType.ts rename to app/main/chain/chainType.ts diff --git a/app/lib/crypto/address/p2pkh.ts b/app/main/crypto/address/p2pkh.ts similarity index 100% rename from app/lib/crypto/address/p2pkh.ts rename to app/main/crypto/address/p2pkh.ts diff --git a/app/lib/crypto/constants.ts b/app/main/crypto/constants.ts similarity index 100% rename from app/lib/crypto/constants.ts rename to app/main/crypto/constants.ts diff --git a/app/lib/crypto/errors.ts b/app/main/crypto/errors.ts similarity index 100% rename from app/lib/crypto/errors.ts rename to app/main/crypto/errors.ts diff --git a/app/lib/crypto/hash.ts b/app/main/crypto/hash.ts similarity index 100% rename from app/lib/crypto/hash.ts rename to app/main/crypto/hash.ts diff --git a/app/lib/crypto/key/key.ts b/app/main/crypto/key/key.ts similarity index 100% rename from app/lib/crypto/key/key.ts rename to app/main/crypto/key/key.ts diff --git a/app/lib/crypto/key/privateKey.ts b/app/main/crypto/key/privateKey.ts similarity index 100% rename from app/lib/crypto/key/privateKey.ts rename to app/main/crypto/key/privateKey.ts diff --git a/app/lib/crypto/key/publicKey.ts b/app/main/crypto/key/publicKey.ts similarity index 100% rename from app/lib/crypto/key/publicKey.ts rename to app/main/crypto/key/publicKey.ts diff --git a/app/lib/crypto/keyPath.ts b/app/main/crypto/keyPath.ts similarity index 96% rename from app/lib/crypto/keyPath.ts rename to app/main/crypto/keyPath.ts index 2925c45f4..f5f2c9f7b 100644 --- a/app/lib/crypto/keyPath.ts +++ b/app/main/crypto/keyPath.ts @@ -1,5 +1,5 @@ -import {HARDENED_KEY_INDEX} from "./constants" -import {Errors} from "./errors" +import { HARDENED_KEY_INDEX } from "./constants" +import { Errors } from "./errors" export type KeyPath = Array diff --git a/app/lib/crypto/mnemonic.ts b/app/main/crypto/mnemonic.ts similarity index 100% rename from app/lib/crypto/mnemonic.ts rename to app/main/crypto/mnemonic.ts diff --git a/app/main/crypto/pbkdf2.ts b/app/main/crypto/pbkdf2.ts new file mode 100644 index 000000000..16ef9ccbe --- /dev/null +++ b/app/main/crypto/pbkdf2.ts @@ -0,0 +1,61 @@ +import { Errors } from "./errors" + +const assert = require("assert") +const crypto = require("crypto") + +/** + * PBKDF2 + * https://github.com/stayradiated/pbkdf2-sha512 + * @param {string | Buffer} key + * @param {string | Buffer} salt + * @param {number} iterations + * @param {number} dkLen + * @returns {Buffer} + */ +export const pbkdf2 = + (key: string | Buffer, salt: string | Buffer, iterations: number, dkLen: number) => { + const hLen = 64 // SHA512 Mac length + const validKeyLength = dkLen <= (Math.pow(2, 32) - 1) * hLen + assert(validKeyLength, Errors.INVALID_KEY_LENGTH) + + const saltBuffer = (typeof salt === "string") ? Buffer.from(salt) : salt + const keyBuffer = (typeof key === "string") ? Buffer.from(key) : key + + const DK = Buffer.alloc(dkLen) + const T = Buffer.alloc(hLen) + + const block1 = Buffer.alloc(saltBuffer.length + 4) + + const l = Math.ceil(dkLen / hLen) + const r = dkLen - (l - 1) * hLen + + saltBuffer.copy(block1, 0, 0, saltBuffer.length) + for (let i = 1; i <= l; i++) { + block1[saltBuffer.length + 0] = (i >> 24 & 0xFF) + block1[saltBuffer.length + 1] = (i >> 16 & 0xFF) + block1[saltBuffer.length + 2] = (i >> 8 & 0xFF) + block1[saltBuffer.length + 3] = (i >> 0 & 0xFF) + + let U = crypto.createHmac("sha512", keyBuffer) + .update(block1) + .digest() + + U.copy(T, 0, 0, hLen) + + for (let j = 1; j < iterations; j++) { + U = crypto.createHmac("sha512", keyBuffer) + .update(U) + .digest() + + for (let k = 0; k < hLen; k++) { + T[k] ^= U[k] + } + } + + const destPos = (i - 1) * hLen + const len = (i === l ? r : hLen) + T.copy(DK, destPos, 0, len) + } + + return DK + } \ No newline at end of file diff --git a/app/lib/crypto/seed.ts b/app/main/crypto/seed.ts similarity index 95% rename from app/lib/crypto/seed.ts rename to app/main/crypto/seed.ts index 64c0039c1..ec4ad18f9 100644 --- a/app/lib/crypto/seed.ts +++ b/app/main/crypto/seed.ts @@ -2,7 +2,7 @@ import * as Mnemonic from "./mnemonic" import * as Hash from "./hash" import * as assert from "assert" import * as bip39 from "bip39" -import {Errors} from "./errors" +import { Errors } from "./errors" export type Seed = { masterSecret: Buffer diff --git a/app/lib/encoding/.gitkeep b/app/main/encoding/.gitkeep similarity index 100% rename from app/lib/encoding/.gitkeep rename to app/main/encoding/.gitkeep diff --git a/app/lib/encoding/slip32.ts b/app/main/encoding/slip32.ts similarity index 91% rename from app/lib/encoding/slip32.ts rename to app/main/encoding/slip32.ts index 33098e6c0..c0b1f507c 100644 --- a/app/lib/encoding/slip32.ts +++ b/app/main/encoding/slip32.ts @@ -2,8 +2,8 @@ import * as KeyPath from "../crypto/keyPath" import * as Key from "../crypto/key/key" import * as PrivateKey from "../crypto/key/privateKey" import * as PublicKey from "../crypto/key/publicKey" -import {integerAsBuffer} from "../utils/conversions" -import {privateKeyVerify, publicKeyVerify} from "secp256k1" +import { integerAsBuffer } from "../utils/conversions" +import { privateKeyVerify, publicKeyVerify } from "secp256k1" import * as Bech32 from "bech32" /* @@ -35,9 +35,9 @@ type PrefixedBuffer = { * @returns {PrefixedBuffer} */ export const decode = (encodedBech32: string): PrefixedBuffer => { - const {prefix: hrp, words} = Bech32.decode(encodedBech32, BECH32_LIMIT) + const { prefix: hrp, words } = Bech32.decode(encodedBech32, BECH32_LIMIT) - return {hrp, words} + return { hrp, words } } /** @@ -46,7 +46,7 @@ export const decode = (encodedBech32: string): PrefixedBuffer => { * @param {Buffer} words * @returns {string} */ -export const encode = ({hrp, words}: PrefixedBuffer): string => { +export const encode = ({ hrp, words }: PrefixedBuffer): string => { return Bech32.encode(hrp, Buffer.from(words), BECH32_LIMIT) } @@ -72,9 +72,9 @@ export const exportKeyToSlip32 = (keyPath: KeyPath.KeyPath, extKey: // Encode hrp + words (5-bit) const words = Bech32.toWords(Buffer.concat(data)) if (extKey.key.type === "private") { - return encode({hrp: "xprv", words}) + return encode({ hrp: "xprv", words }) } else { - return encode({hrp: "xpub", words}) + return encode({ hrp: "xpub", words }) } } @@ -88,7 +88,7 @@ export const importKeyFromSlip32 = (slip32: string): { extendedKey: Key.ExtendedKey | Key.ExtendedKey } => { // Decode slip32 - const {hrp, words}: { hrp: string, words: Buffer } = decode(slip32) + const { hrp, words }: { hrp: string, words: Buffer } = decode(slip32) // Check hrp if ((hrp !== "xprv") && (hrp !== "xpub")) { throw Error("Malformed slip32 serialized key: invalid hrp") diff --git a/app/main.electron.js b/app/main/index.js similarity index 100% rename from app/main.electron.js rename to app/main/index.js diff --git a/app/lib/storage/encryptedStorage.ts b/app/main/storage/encryptedStorage.ts similarity index 100% rename from app/lib/storage/encryptedStorage.ts rename to app/main/storage/encryptedStorage.ts diff --git a/app/lib/storage/encryption.ts b/app/main/storage/encryption.ts similarity index 98% rename from app/lib/storage/encryption.ts rename to app/main/storage/encryption.ts index 52aa68bba..8798c40a8 100644 --- a/app/lib/storage/encryption.ts +++ b/app/main/storage/encryption.ts @@ -42,7 +42,7 @@ export const defaultSettings: Settings = { const serialize = (buffers: Array): Buffer => { const parts: Array = [] - buffers.forEach( (part: Buffer) => { + buffers.forEach((part: Buffer) => { const dataLength = Buffer.alloc(4) dataLength.writeUInt32BE(part.length, 0) parts.push(dataLength) @@ -148,4 +148,4 @@ export const decrypt = (data: Buffer, settings: Settings): Buffer => { const plaintext = decipher.update(ciphertext) return Buffer.concat([plaintext, decipher.final()]) -} \ No newline at end of file +} diff --git a/app/lib/storage/levelBackend.ts b/app/main/storage/levelBackend.ts similarity index 93% rename from app/lib/storage/levelBackend.ts rename to app/main/storage/levelBackend.ts index 9b3bb36d9..4bb1d538f 100644 --- a/app/lib/storage/levelBackend.ts +++ b/app/main/storage/levelBackend.ts @@ -1,4 +1,4 @@ -import {LevelUp} from "levelup" +import { LevelUp } from "levelup" import IStorageBackend from "./storageBackend" /** @@ -10,7 +10,7 @@ export default class LevelBackend implements IStorageBackend { * The LevelBackend constructor takes a reference to a LevelUp backend. * @param {levelup.LevelUp} connection */ - constructor(private connection: LevelUp) {} + constructor(private connection: LevelUp) { } /** * Database closing method implementation for LevelDB. diff --git a/app/lib/storage/levelEncryptedStorage.ts b/app/main/storage/levelEncryptedStorage.ts similarity index 91% rename from app/lib/storage/levelEncryptedStorage.ts rename to app/main/storage/levelEncryptedStorage.ts index 70389d317..5768e6f0d 100644 --- a/app/lib/storage/levelEncryptedStorage.ts +++ b/app/main/storage/levelEncryptedStorage.ts @@ -1,7 +1,7 @@ import EncryptedStorage from "./encryptedStorage" import * as Encryption from "./encryption" import * as path from "path" -import {homedir} from "os" +import { homedir } from "os" import LevelBackend from "./levelBackend" import * as level from "level" @@ -24,4 +24,4 @@ const levelEncryptedStorageFactory = async ( return new EncryptedStorage(database, encryptionSettings) } -export {levelEncryptedStorageFactory} \ No newline at end of file +export { levelEncryptedStorageFactory } \ No newline at end of file diff --git a/app/lib/storage/mockedBackend.ts b/app/main/storage/mockedBackend.ts similarity index 100% rename from app/lib/storage/mockedBackend.ts rename to app/main/storage/mockedBackend.ts diff --git a/app/lib/storage/storageBackend.ts b/app/main/storage/storageBackend.ts similarity index 100% rename from app/lib/storage/storageBackend.ts rename to app/main/storage/storageBackend.ts diff --git a/app/lib/storage/utils.ts b/app/main/storage/utils.ts similarity index 100% rename from app/lib/storage/utils.ts rename to app/main/storage/utils.ts diff --git a/app/lib/utils/conversions.ts b/app/main/utils/conversions.ts similarity index 100% rename from app/lib/utils/conversions.ts rename to app/main/utils/conversions.ts diff --git a/app/lib/utils/utils.ts b/app/main/utils/utils.ts similarity index 93% rename from app/lib/utils/utils.ts rename to app/main/utils/utils.ts index 0db24c590..a1d6cd180 100644 --- a/app/lib/utils/utils.ts +++ b/app/main/utils/utils.ts @@ -14,6 +14,6 @@ export function kvSwap(obj: stringToNumber | numberToString | stringToString): a return Object .entries(obj) .reduce((acc, [key, value]) => { - return {...acc, [value]: key} + return { ...acc, [value]: key } }, {}) } \ No newline at end of file diff --git a/app/actions/counter.ts b/app/renderer/actions/counter.ts similarity index 100% rename from app/actions/counter.ts rename to app/renderer/actions/counter.ts diff --git a/app/actions/helpers.ts b/app/renderer/actions/helpers.ts similarity index 100% rename from app/actions/helpers.ts rename to app/renderer/actions/helpers.ts diff --git a/app/components/Counter.scss b/app/renderer/components/Counter.scss similarity index 100% rename from app/components/Counter.scss rename to app/renderer/components/Counter.scss diff --git a/app/components/Counter.tsx b/app/renderer/components/Counter.tsx similarity index 100% rename from app/components/Counter.tsx rename to app/renderer/components/Counter.tsx diff --git a/app/components/Home.scss b/app/renderer/components/Home.scss similarity index 100% rename from app/components/Home.scss rename to app/renderer/components/Home.scss diff --git a/app/components/Home.tsx b/app/renderer/components/Home.tsx similarity index 100% rename from app/components/Home.tsx rename to app/renderer/components/Home.tsx diff --git a/app/containers/App.tsx b/app/renderer/containers/App.tsx similarity index 100% rename from app/containers/App.tsx rename to app/renderer/containers/App.tsx diff --git a/app/containers/CounterPage.tsx b/app/renderer/containers/CounterPage.tsx similarity index 100% rename from app/containers/CounterPage.tsx rename to app/renderer/containers/CounterPage.tsx diff --git a/app/containers/HomePage.tsx b/app/renderer/containers/HomePage.tsx similarity index 100% rename from app/containers/HomePage.tsx rename to app/renderer/containers/HomePage.tsx diff --git a/app/containers/Root.tsx b/app/renderer/containers/Root.tsx similarity index 100% rename from app/containers/Root.tsx rename to app/renderer/containers/Root.tsx diff --git a/app/index.tsx b/app/renderer/index.tsx similarity index 95% rename from app/index.tsx rename to app/renderer/index.tsx index d176433ca..ca5873a26 100644 --- a/app/index.tsx +++ b/app/renderer/index.tsx @@ -2,7 +2,7 @@ import * as React from "react" import { render } from "react-dom" import { AppContainer } from "react-hot-loader" import Root from "./containers/Root" -import "./app.global.scss" +import "./ui/app.global.scss" const { configureStore, history } = require("./store/configureStore") const store = configureStore() diff --git a/app/reducers/counter.ts b/app/renderer/reducers/counter.ts similarity index 100% rename from app/reducers/counter.ts rename to app/renderer/reducers/counter.ts diff --git a/app/reducers/index.ts b/app/renderer/reducers/index.ts similarity index 100% rename from app/reducers/index.ts rename to app/renderer/reducers/index.ts diff --git a/app/routes.tsx b/app/renderer/routes.tsx similarity index 100% rename from app/routes.tsx rename to app/renderer/routes.tsx diff --git a/app/store/configureStore.development.ts b/app/renderer/store/configureStore.development.ts similarity index 100% rename from app/store/configureStore.development.ts rename to app/renderer/store/configureStore.development.ts diff --git a/app/store/configureStore.production.ts b/app/renderer/store/configureStore.production.ts similarity index 100% rename from app/store/configureStore.production.ts rename to app/renderer/store/configureStore.production.ts diff --git a/app/store/configureStore.ts b/app/renderer/store/configureStore.ts similarity index 100% rename from app/store/configureStore.ts rename to app/renderer/store/configureStore.ts diff --git a/app/app.global.scss b/app/renderer/ui/app.global.scss similarity index 100% rename from app/app.global.scss rename to app/renderer/ui/app.global.scss diff --git a/app/app.html b/app/renderer/ui/app.html similarity index 77% rename from app/app.html rename to app/renderer/ui/app.html index f9b291901..eb19b9f55 100644 --- a/app/app.html +++ b/app/renderer/ui/app.html @@ -8,8 +8,7 @@ if (!process.env.HOT) { const link = document.createElement('link'); link.rel = 'stylesheet'; - link.href = './style.css'; - // HACK: Writing the script path should be done with webpack + link.href = '<%= htmlWebpackPlugin.options.styleFilename %>'; document.getElementsByTagName('head')[0].appendChild(link); } }()); @@ -23,8 +22,7 @@ const port = process.env.PORT || 3000; script.src = (process.env.HOT) ? 'http://localhost:' + port + '/dist/bundle.js' - : './bundle.js'; - // HACK: Writing the script path should be done with webpack + : '<%= htmlWebpackPlugin.options.bundleFilename %>'; document.body.appendChild(script); } diff --git a/app/app.icns b/app/renderer/ui/app.icns similarity index 100% rename from app/app.icns rename to app/renderer/ui/app.icns diff --git a/app/utils/.gitkeep b/app/renderer/utils/.gitkeep similarity index 100% rename from app/utils/.gitkeep rename to app/renderer/utils/.gitkeep diff --git a/config/jest.js b/config/jest.js index b25d0f7f8..b92dffbbf 100644 --- a/config/jest.js +++ b/config/jest.js @@ -6,10 +6,13 @@ module.exports = { "roots": ["/.."], "globals": { "ts-jest": { - "tsConfigFile": "../config/tsconfig.json" + "tsConfigFile": "../config/tsconfig.test.json" } }, "moduleNameMapper": { + "appCommon\/(.*)$": "/../app/common/$1", + "appMain\/(.*)$": "/../app/main/$1", + "appRenderer\/(.*)$": "/../app/renderer/$1", "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "/../test/__mocks__/fileMock.js", "\\.(css|less|sass|scss)$": "identity-obj-proxy" }, @@ -20,7 +23,7 @@ module.exports = { ], "moduleDirectories": [ "/../node_modules", - "/../app/node_modules" + "/../app/lib" ], "transform": { "^.+\\.(ts|tsx)$": "ts-jest" diff --git a/config/tsconfig.json b/config/tsconfig.json index 7fcf0bc46..7574bb1ad 100644 --- a/config/tsconfig.json +++ b/config/tsconfig.json @@ -28,13 +28,11 @@ "outDir": "dist" }, "files": [ - "../app/index.tsx" + "../app/renderer/index.tsx" ], "include": [ "../app/**/*.ts", "../app/**/*.tsx", - "../test/**/*.ts", - "../test/**/*.tsx", "../node_modules/@types/**/*.d.ts", "../typings/**/*.d.ts" ], diff --git a/config/tsconfig.test.json b/config/tsconfig.test.json new file mode 100644 index 000000000..b566582c4 --- /dev/null +++ b/config/tsconfig.test.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig", + "include": [ + "../test/**/*.ts", + "../test/**/*.tsx" + ] +} diff --git a/config/webpack.main.js b/config/webpack.main.js index 5fcad4a12..f0da7ad21 100644 --- a/config/webpack.main.js +++ b/config/webpack.main.js @@ -5,7 +5,7 @@ const path = require("path"); const webpack = require("webpack"); const webpackMergeConfigs = require("webpack-merge"); -const HtmlWebpackPlugin = require("html-webpack-plugin"); +const webpackRenderer = require("./webpack.renderer"); const port = process.env.PORT || 3000; const forProduction = process.env.NODE_ENV === "production"; @@ -14,7 +14,7 @@ const baseConfig = { devtool: "source-map", target: "electron-main", - entry: [path.resolve(__dirname, "../app/main.electron")], + entry: [path.resolve(__dirname, "../app/main/index.js")], resolve: { extensions: [".js", ".ts", ".json"] @@ -34,20 +34,8 @@ const baseConfig = { }, plugins: [ - // Add source map support for stack traces in node - // https://github.com/evanw/node-source-map-support - new webpack.BannerPlugin( - { banner: "require(\"source-map-support\").install();", raw: true, entryOnly: false } - ), - new webpack.DefinePlugin({ "process.env.NODE_ENV": JSON.stringify(forProduction ? "production" : "development") - }), - - new HtmlWebpackPlugin({ - filename: path.resolve(__dirname, "../dist/app.html"), - template: path.resolve(__dirname, "../app/app.html"), - inject: false }) ], @@ -65,7 +53,14 @@ const productionConfig = { }; const developmentConfig = { - mode: "development" + mode: "development", + plugins: [ + // Add source map support for stack traces in node + // https://github.com/evanw/node-source-map-support + new webpack.BannerPlugin( + { banner: "require(\"source-map-support\").install();", raw: true, entryOnly: false } + ) + ] }; if (forProduction) { diff --git a/config/webpack.renderer.js b/config/webpack.renderer.js index 65710f17e..468e5c564 100644 --- a/config/webpack.renderer.js +++ b/config/webpack.renderer.js @@ -11,9 +11,12 @@ const HtmlWebpackPlugin = require("html-webpack-plugin"); const port = process.env.PORT || 3000; const forProduction = process.env.NODE_ENV === "production"; +const bundleFilename = "bundle.js"; +const styleFilename = "style.css"; + const typeScriptLoader = { loader: "ts-loader", - options: { configFile: path.resolve(__dirname, "tsconfig.json") } + options: { configFile: path.resolve(__dirname, process.env.TSCONFIG || "tsconfig.json") } }; const uiComponentLoader = { @@ -33,17 +36,18 @@ const baseConfig = { resolve: { extensions: [".js", ".ts", ".tsx"], alias: { - app: path.resolve(__dirname, "../app") + appCommon: path.resolve(__dirname, "../app/common"), + appRenderer: path.resolve(__dirname, "../app/renderer") }, modules: [ - path.resolve(__dirname, "../app"), path.resolve(__dirname, "../node_modules"), + path.resolve(__dirname, "../lib"), ] }, output: { path: path.resolve(__dirname, "../dist"), - filename: "bundle.js", + filename: bundleFilename, // https://github.com/webpack/webpack/issues/1114 libraryTarget: "commonjs2" }, @@ -134,6 +138,14 @@ const baseConfig = { new webpack.DefinePlugin({ "process.env.NODE_ENV": JSON.stringify(forProduction ? "production" : "development") + }), + + new HtmlWebpackPlugin({ + filename: path.resolve(__dirname, "../dist/app.html"), + template: path.resolve(__dirname, "../app/renderer/ui/app.html"), + inject: false, + bundleFilename, + styleFilename }) ] }; @@ -141,7 +153,7 @@ const baseConfig = { const productionConfig = { mode: "production", devtool: "cheap-module-source-map", - entry: ["app/index"], + entry: path.resolve(__dirname, "../app/renderer/index.tsx"), output: { publicPath: path.resolve(__dirname, "../dist/") // the last slash is important! ------------^ @@ -192,7 +204,7 @@ const productionConfig = { ] }, - plugins: [new ExtractTextPlugin("style.css")] + plugins: [new ExtractTextPlugin(styleFilename)] }; const developmentConfig = { @@ -201,7 +213,7 @@ const developmentConfig = { entry: [ "react-hot-loader/patch", `webpack-hot-middleware/client?path=http://localhost:${port}/__webpack_hmr&reload=true`, - "app/index" + path.resolve(__dirname, "../app/renderer/index.tsx") ], output: { publicPath: `http://localhost:${port}/dist/` diff --git a/package.json b/package.json index 1d46b3a8a..492bec25d 100644 --- a/package.json +++ b/package.json @@ -23,16 +23,18 @@ "package-dev": "yarn build-dev && build --publish never", "travis": "yarn lint && yarn fmt-verify && yarn test-all && yarn package", "travisp": "concurrently --names LINT,FMT,TEST,PACK -c bgBlue,bgMagenta,yellow,bgCyan 'yarn lint' 'yarn fmt-verify' 'yarn test-all' 'yarn package'", - "lint": "tslint --project config/tsconfig.json --config config/tslint.json", + "prelint": "node scripts/json-merge config/tsconfig.json config/tsconfig.test.json > config/tsconfig.tslint.json", + "lint": "tslint --project config/tsconfig.tslint.json --config config/tslint.json", + "json-merge": "node scripts/json-merge", "clean": "rimraf release dist", "clean-deps": "rimraf node_modules", "reinstall": "yarn clean-deps; yarn install", "commit": "git-cz", "precommit": "lint-staged", "commitmsg": "commitlint -g config/commitlint.config.js -e $GIT_PARAMS", - "fmt-verify": "tsfmt --useTsfmt tsfmt.json --verify app/**/*.ts test/**/*.ts", - "fmt": "tsfmt --useTsfmt tsfmt.json app/**/*.ts test/**/*.ts", - "fmt!": "tsfmt --useTsfmt tsfmt.json -r app/**/*.ts test/**/*.ts" + "fmt-verify": "tsfmt --useTsfmt tsfmt.json --verify app/**/**/*.ts test/**/*.ts", + "fmt": "tsfmt --useTsfmt tsfmt.json app/**/**/*.ts test/**/*.ts", + "fmt!": "tsfmt --useTsfmt tsfmt.json -r app/**/**/*.ts test/**/*.ts" }, "lint-staged": { "*.ts": [ @@ -137,6 +139,7 @@ "css-loader": "^0.28.11", "css-modules-require-hook": "^4.2.3", "cz-conventional-changelog": "^2.1.0", + "deepmerge": "^2.1.1", "devtron": "^1.4.0", "electron": "1.8.6", "electron-builder": "^19.8.0", diff --git a/scripts/json-merge.js b/scripts/json-merge.js new file mode 100644 index 000000000..027e53aff --- /dev/null +++ b/scripts/json-merge.js @@ -0,0 +1,7 @@ +var path = require('path'); +var merge = require('deepmerge'); + +console.log(JSON.stringify(merge.apply(null, process.argv.slice(2).map(function(p) { + var rootPath = path.join(__dirname, "..", p) + return require(rootPath); +})))); diff --git a/setup.js b/setup.js deleted file mode 100644 index 9ffc6dd02..000000000 --- a/setup.js +++ /dev/null @@ -1,69 +0,0 @@ -// Note: this file is the configuration file *only* for -// use by the boiler-room-custodian utility. the point -// of the boiler-room-custodian is to clean sample code -// from the boilerplate from initial state so that you -// can start custom development on a "blank project" -// -// For more information or to report issues please go -// to https://github.com/tstringer/boiler-room-custodian -// -// This file should remain unmodified by end users and -// should only be invoked by running `npm run cleanup` -module.exports = { - // remove the following files as they are mostly - // related to the sample counter page and functionality - remove: [ - { file: 'app/actions/counter.ts' }, - { file: 'app/components/Counter.scss' }, - { file: 'app/components/Counter.tsx' }, - { file: 'app/containers/CounterPage.tsx' }, - { file: 'app/reducers/counter.ts' }, - { file: 'test/actions/counter.spec.ts' }, - { file: 'test/components/Counter.spec.tsx' }, - { file: 'test/containers/CounterPage.spec.tsx' }, - { file: 'test/reducers/counter.spec.ts' }, - { file: 'erb-logo.png' } - ], - // clean the following files by either clearing them - // (by specifying {clear: true}) or by removing lines - // that match a regex pattern - clean: [ - { - file: 'app/reducers/index.ts', - pattern: /counter/ - }, - { - file: 'app/store/configureStore.development.ts', - pattern: /counterActions/ - }, - { - file: 'app/app.global.scss', - clear: true - }, - { - file: 'app/routes.tsx', - pattern: /CounterPage/ - }, - { - file: 'test/e2e.ts', - clear: true - }, - { - file: 'README.md', - clear: true - }, - { - file: 'app/components/Home.tsx', - pattern: /(h2|Link)/ - } - ], - // add the following files to the project, mostly - // related to .gitkeep for version control - add: [ - { file: 'app/actions/.gitkeep' }, - { file: 'test/actions/.gitkeep' }, - { file: 'test/components/.gitkeep' }, - { file: 'test/containers/.gitkeep' }, - { file: 'test/reducers/.gitkeep' } - ] -}; diff --git a/test/app/lib/crypto/address.spec.ts b/test/app/main/crypto/address.spec.ts similarity index 72% rename from test/app/lib/crypto/address.spec.ts rename to test/app/main/crypto/address.spec.ts index 4ec1e8e04..876a36bce 100644 --- a/test/app/lib/crypto/address.spec.ts +++ b/test/app/main/crypto/address.spec.ts @@ -1,8 +1,8 @@ import {getMasterKey} from "./helpers" -import * as PublicKey from "../../../../app/lib/crypto/key/publicKey" -import {decode, encode} from "../../../../app/lib/crypto/address/p2pkh" -import {ChainType} from "../../../../app/lib/chain/chainType" -import {sha256} from "../../../../app/lib/crypto/hash" +import * as PublicKey from "appMain/crypto/key/publicKey" +import {decode, encode} from "appMain/crypto/address/p2pkh" +import {ChainType} from "appMain/chain/chainType" +import {sha256} from "appMain/crypto/hash" describe("p2pkh", () => { const masterKey = getMasterKey("000102030405060708090a0b0c0d0e0f", "Bitcoin seed") diff --git a/test/app/lib/crypto/hash.spec.ts b/test/app/main/crypto/hash.spec.ts similarity index 88% rename from test/app/lib/crypto/hash.spec.ts rename to test/app/main/crypto/hash.spec.ts index 2dae04cc8..ebf273d18 100644 --- a/test/app/lib/crypto/hash.spec.ts +++ b/test/app/main/crypto/hash.spec.ts @@ -1,4 +1,4 @@ -import {sha512hmac} from "../../../../app/lib/crypto/hash" +import {sha512hmac} from "appMain/crypto/hash" describe("hmac 512", () => { it("should encrypt using hmacSha512", () => { @@ -9,4 +9,4 @@ describe("hmac 512", () => { .toEqual("e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35873df" + "f81c02f525623fd1fe5167eac3a55a049de3d314bb42ee227ffed37d508") }) -}) \ No newline at end of file +}) diff --git a/test/app/lib/crypto/helpers.ts b/test/app/main/crypto/helpers.ts similarity index 72% rename from test/app/lib/crypto/helpers.ts rename to test/app/main/crypto/helpers.ts index 98ba2ede0..dd486cf27 100644 --- a/test/app/lib/crypto/helpers.ts +++ b/test/app/main/crypto/helpers.ts @@ -1,6 +1,6 @@ -import {ExtendedKey} from "../../../../app/lib/crypto/key/key" -import {fromEntropy} from "../../../../app/lib/crypto/seed" -import * as PrivateKey from "../../../../app/lib/crypto/key/privateKey" +import {ExtendedKey} from "appMain/crypto/key/key" +import {fromEntropy} from "appMain/crypto/seed" +import * as PrivateKey from "appMain/crypto/key/privateKey" /** * Helper for testing @@ -17,4 +17,4 @@ export function getMasterKey(seedEntropy: string, passPhrase = "Witnet seed"): PrivateKey.extend(PrivateKey.fromBytes(masterSecret), chainCode) return masterKey -} \ No newline at end of file +} diff --git a/test/app/lib/crypto/key.spec.ts b/test/app/main/crypto/key.spec.ts similarity index 98% rename from test/app/lib/crypto/key.spec.ts rename to test/app/main/crypto/key.spec.ts index 760f10f3d..4c348bc89 100644 --- a/test/app/lib/crypto/key.spec.ts +++ b/test/app/main/crypto/key.spec.ts @@ -1,6 +1,6 @@ -import * as PrivateKey from "../../../../app/lib/crypto/key/privateKey" -import {hardened} from "../../../../app/lib/crypto/keyPath" -import * as PublicKey from "../../../../app/lib/crypto/key/publicKey" +import * as PrivateKey from "appMain/crypto/key/privateKey" +import {hardened} from "appMain/crypto/keyPath" +import * as PublicKey from "appMain/crypto/key/publicKey" import {getMasterKey} from "./helpers" /** diff --git a/test/app/lib/crypto/keypath.spec.ts b/test/app/main/crypto/keypath.spec.ts similarity index 96% rename from test/app/lib/crypto/keypath.spec.ts rename to test/app/main/crypto/keypath.spec.ts index 474c6fb09..711a0a374 100644 --- a/test/app/lib/crypto/keypath.spec.ts +++ b/test/app/main/crypto/keypath.spec.ts @@ -1,4 +1,4 @@ -import * as KeyPath from "app/lib/crypto/keyPath" +import * as KeyPath from "appMain/crypto/keyPath" describe("key path", () => { const hardened = KeyPath.hardened @@ -28,4 +28,4 @@ describe("key path", () => { expect(KeyPath.toString([44, hardened(0), hardened(0), 0])) .toBe( "m/44/0'/0'/0") }) -}) \ No newline at end of file +}) diff --git a/test/app/lib/crypto/pbkdf2.spec.ts b/test/app/main/crypto/pbkdf2.spec.ts similarity index 97% rename from test/app/lib/crypto/pbkdf2.spec.ts rename to test/app/main/crypto/pbkdf2.spec.ts index 6353ba697..7eab39102 100644 --- a/test/app/lib/crypto/pbkdf2.spec.ts +++ b/test/app/main/crypto/pbkdf2.spec.ts @@ -1,4 +1,4 @@ -import { pbkdf2 } from "app/lib/crypto/pbkdf2" +import { pbkdf2 } from "appMain/crypto/pbkdf2" /* All these test vectors come from RFC 6070: @@ -60,4 +60,4 @@ describe("pbkdf2", () => { expect(pbkdf2(password, salt, iterations, length)).toEqual(expected) }) -}) \ No newline at end of file +}) diff --git a/test/app/lib/crypto/seed.spec.ts b/test/app/main/crypto/seed.spec.ts similarity index 94% rename from test/app/lib/crypto/seed.spec.ts rename to test/app/main/crypto/seed.spec.ts index 67f41ad5c..d71ca5daa 100644 --- a/test/app/lib/crypto/seed.spec.ts +++ b/test/app/main/crypto/seed.spec.ts @@ -1,4 +1,4 @@ -import * as Seed from "app/lib/crypto/seed" +import * as Seed from "appMain/crypto/seed" import * as _ from "lodash" describe("seed", () => { diff --git a/test/app/lib/encoding/fixtures.ts b/test/app/main/encoding/fixtures.ts similarity index 100% rename from test/app/lib/encoding/fixtures.ts rename to test/app/main/encoding/fixtures.ts diff --git a/test/app/lib/encoding/slip32.spec.ts b/test/app/main/encoding/slip32.spec.ts similarity index 94% rename from test/app/lib/encoding/slip32.spec.ts rename to test/app/main/encoding/slip32.spec.ts index d26f54e49..9efc4082d 100644 --- a/test/app/lib/encoding/slip32.spec.ts +++ b/test/app/main/encoding/slip32.spec.ts @@ -1,8 +1,8 @@ -import * as exchange from "../../../../app/lib/encoding/slip32" -import * as KeyPath from "../../../../app/lib/crypto/keyPath" -import * as PrivateKey from "../../../../app/lib/crypto/key/privateKey" -import * as PublicKey from "../../../../app/lib/crypto/key/publicKey" -import * as Key from "../../../../app/lib/crypto/key/key" +import * as exchange from "appMain/encoding/slip32" +import * as KeyPath from "appMain/crypto/keyPath" +import * as PrivateKey from "appMain/crypto/key/privateKey" +import * as PublicKey from "appMain/crypto/key/publicKey" +import * as Key from "appMain/crypto/key/key" import * as fixtures from "./fixtures" @@ -138,4 +138,4 @@ function cropString(text: string, limit: number, end?: boolean) { } else { return text.length > limit ? "...".concat(text.substr(text.length - limit, text.length)) : text } -} \ No newline at end of file +} diff --git a/test/app/lib/storage/encryptedStorage.spec.ts b/test/app/main/storage/encryptedStorage.spec.ts similarity index 87% rename from test/app/lib/storage/encryptedStorage.spec.ts rename to test/app/main/storage/encryptedStorage.spec.ts index a5eb7b220..e157e6120 100644 --- a/test/app/lib/storage/encryptedStorage.spec.ts +++ b/test/app/main/storage/encryptedStorage.spec.ts @@ -1,6 +1,6 @@ -import * as Encryption from "app/lib/storage/encryption" -import EncryptedStorage from "app/lib/storage/encryptedStorage" -import MockedBackend from "app/lib/storage/mockedBackend" +import * as Encryption from "appMain/storage/encryption" +import EncryptedStorage from "appMain/storage/encryptedStorage" +import MockedBackend from "appMain/storage/mockedBackend" const mockedBackend = new MockedBackend() const password = "password" @@ -46,4 +46,4 @@ describe("EncryptedStorage", () => { const res = await localStorage.get("foo") expect(res).toEqual("bar") }) -}) \ No newline at end of file +}) diff --git a/test/app/lib/storage/encryption.spec.ts b/test/app/main/storage/encryption.spec.ts similarity index 96% rename from test/app/lib/storage/encryption.spec.ts rename to test/app/main/storage/encryption.spec.ts index 9e696067a..aa69955b6 100644 --- a/test/app/lib/storage/encryption.spec.ts +++ b/test/app/main/storage/encryption.spec.ts @@ -1,4 +1,4 @@ -import * as Encryption from "app/lib/storage/encryption" +import * as Encryption from "appMain/storage/encryption" const password = "password" const encryptionSettings = {...Encryption.defaultSettings, password} @@ -39,4 +39,4 @@ describe("Encryption", () => { const decrypted = Encryption.decrypt(encrypted, encryptionSettings) expect(decrypted).toMatchObject(anotherPlaintext) }) -}) \ No newline at end of file +}) diff --git a/test/app/lib/utils/utils.spec.ts b/test/app/main/utils/utils.spec.ts similarity index 71% rename from test/app/lib/utils/utils.spec.ts rename to test/app/main/utils/utils.spec.ts index 48d4db848..605b0cfe4 100644 --- a/test/app/lib/utils/utils.spec.ts +++ b/test/app/main/utils/utils.spec.ts @@ -1,5 +1,5 @@ -import {kvSwap} from "../../../../app/lib/utils/utils" -import {ChainType} from "../../../../app/lib/chain/chainType" +import {kvSwap} from "appMain/utils/utils" +import {ChainType} from "appMain/chain/chainType" describe("Utils", () => { const prefixToChainType = { @@ -12,4 +12,4 @@ describe("Utils", () => { expect(swapped[ChainType.main]).toEqual("wit") expect(swapped[ChainType.test]).toEqual("twit") }) -}) \ No newline at end of file +}) diff --git a/test/app/actions/__snapshots__/counter.spec.ts.snap b/test/app/renderer/actions/__snapshots__/counter.spec.ts.snap similarity index 100% rename from test/app/actions/__snapshots__/counter.spec.ts.snap rename to test/app/renderer/actions/__snapshots__/counter.spec.ts.snap diff --git a/test/app/actions/counter.spec.ts b/test/app/renderer/actions/counter.spec.ts similarity index 95% rename from test/app/actions/counter.spec.ts rename to test/app/renderer/actions/counter.spec.ts index aa9dae8bc..735595134 100644 --- a/test/app/actions/counter.spec.ts +++ b/test/app/renderer/actions/counter.spec.ts @@ -1,5 +1,5 @@ import { spy } from "sinon" -import * as actions from "app/actions/counter" +import * as actions from "appRenderer/actions/counter" describe("actions", () => { it("should increment should create increment action", () => { diff --git a/test/app/components/Counter.spec.tsx b/test/app/renderer/components/Counter.spec.tsx similarity index 96% rename from test/app/components/Counter.spec.tsx rename to test/app/renderer/components/Counter.spec.tsx index bd764a80d..eaec73e85 100644 --- a/test/app/components/Counter.spec.tsx +++ b/test/app/renderer/components/Counter.spec.tsx @@ -1,7 +1,7 @@ import { spy } from "sinon" import * as React from "react" import { shallow } from "enzyme" -import Counter from "app/components/Counter" +import Counter from "appRenderer/components/Counter" const CounterAny = Counter as any diff --git a/test/app/containers/CounterPage.spec.tsx b/test/app/renderer/containers/CounterPage.spec.tsx similarity index 88% rename from test/app/containers/CounterPage.spec.tsx rename to test/app/renderer/containers/CounterPage.spec.tsx index 8e3d9c2bd..d732e1c42 100644 --- a/test/app/containers/CounterPage.spec.tsx +++ b/test/app/renderer/containers/CounterPage.spec.tsx @@ -2,11 +2,11 @@ import * as React from "react" import { mount } from "enzyme" import { Provider } from "react-redux" import { ConnectedRouter } from "react-router-redux" -import CounterPage from "app/containers/CounterPage" -import { IState } from "app/reducers" +import CounterPage from "appRenderer/containers/CounterPage" +import { IState } from "appRenderer/reducers" const CounterPageAny = CounterPage as any -const { configureStore, history } = require("app/store/configureStore") +const { configureStore, history } = require("appRenderer/store/configureStore") const setup = (initialState?: IState) => { const store = configureStore(initialState) diff --git a/test/app/reducers/counter.spec.ts b/test/app/renderer/reducers/counter.spec.ts similarity index 81% rename from test/app/reducers/counter.spec.ts rename to test/app/renderer/reducers/counter.spec.ts index 6635d1966..f18542e7e 100644 --- a/test/app/reducers/counter.spec.ts +++ b/test/app/renderer/reducers/counter.spec.ts @@ -1,5 +1,5 @@ -import counter from "app/reducers/counter" -import { increment, decrement } from "app/actions/counter" +import counter from "appRenderer/reducers/counter" +import { increment, decrement } from "appRenderer/actions/counter" describe("reducers", () => { describe("counter", () => { diff --git a/yarn.lock b/yarn.lock index 873253685..af5d43dc0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3342,6 +3342,10 @@ deep-is@~0.1.3: version "0.1.3" resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34" +deepmerge@^2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-2.1.1.tgz#e862b4e45ea0555072bf51e7fd0d9845170ae768" + deepmerge@~2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-2.0.1.tgz#25c1c24f110fb914f80001b925264dd77f3f4312"