Skip to content

Commit

Permalink
work
Browse files Browse the repository at this point in the history
  • Loading branch information
nsjames committed Sep 28, 2019
1 parent a41de09 commit d952695
Show file tree
Hide file tree
Showing 12 changed files with 851 additions and 235 deletions.
8 changes: 6 additions & 2 deletions electron/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ const storage = require('./services/storage');
const files = require('./services/files');
const windows = require('./services/windows');

wallet.setStorage(storage);
wallet.init();


let multipartPromises = {};

Expand Down Expand Up @@ -250,11 +253,11 @@ global.wallet = {
/************************************/
utility:{
openTools:(windowId = null) => {
console.log('opening tools', windowId);
(windowId ? BrowserWindow.fromId(windowId) : mainWindow).webContents.send('openTools');
},
closeWindow:(windowId = null) => {
const w = windowId ? BrowserWindow.fromId(windowId) : mainWindow;
w.close()
(windowId ? BrowserWindow.fromId(windowId) : mainWindow).close()
},
flashWindow:() => console.error('flashing not implemented'),
openLink:(link, filepath = false) => {
Expand All @@ -279,6 +282,7 @@ global.wallet = {
delete multipartPromises[original.id];
},
socketResponse:() => {},
pushNotification:NotificationService.pushNotification
},

sockets:HighLevelSockets,
Expand Down
18 changes: 9 additions & 9 deletions electron/hardware/LedgerWallet.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
const bippath = require('bip32-path');
const {Blockchains} = require('@walletpack/core/models/Blockchains');

const Blockchains = {
EOSIO:'eos',
ETH:'eth',
}

const asn1 = require('asn1-ber');
const ecc = require('eosjs-ecc');
const { Serialize } = require('eosjs');
const { Serialize, Api } = require('eosjs');

const EthTx = require('ethereumjs-tx')
const Eth = require("@ledgerhq/hw-app-eth");
Expand Down Expand Up @@ -38,19 +42,15 @@ const LEDGER_PATHS = {
[Blockchains.ETH]:(index = 0) => `44'/60'/0'/0/${index}`,
}



let encoderOptions, eosjsUtil;

class LedgerWallet {

static setup(){
LedgerTransport.setup();

const EosPlugin = require('@walletpack/eosio');
if(EosPlugin){
encoderOptions = EosPlugin.encoderOptions;
eosjsUtil = EosPlugin.eosjsUtil;
}
encoderOptions = TextEncoder ? {textEncoder:new require('util').TextEncoder(), textDecoder:new require('util').TextDecoder()} : {};
eosjsUtil = new Api(encoderOptions);
}

constructor(blockchain){
Expand Down
4 changes: 0 additions & 4 deletions electron/services/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ let getSeed;
const getSeedSetter = (seeder) => getSeed = seeder;

const AES = require("aes-oop").default;
const HistoricTransfer = require('@walletpack/core/models/histories/HistoricTransfer').default;
const HistoricExchange = require('@walletpack/core/models/histories/HistoricTransfer').default;
const HistoricAction = require('@walletpack/core/models/histories/HistoricTransfer').default;
const {HISTORY_TYPES} = require('@walletpack/core/models/histories/History');

const cacheABI = (contractName, chainId, abi) =>{
return abiStorage().set(`abis.${contractName}_${chainId}`, abi);
Expand Down
26 changes: 14 additions & 12 deletions electron/services/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ const {ipcMain} = require("electron");
const bip39 = require('bip39');
const scrypt = require('scrypt-async');
const AES = require("aes-oop").default;
const storage = require('./storage')
const path = require('path')
const Scatter = require('@walletpack/core/models/Scatter').default;
const Error = require('@walletpack/core/models/errors/Error').default;
const IdGenerator = require('@walletpack/core/util/IdGenerator').default;
const Hasher = require('@walletpack/core/util/Hasher').default;
const Keypair = require('@walletpack/core/models/Keypair').default;
const Crypto = require('@walletpack/core/util/Crypto').default;


// TODO: Changing to curve-based
const EOSIO = require('@walletpack/eosio').default;
const TRON = require('@walletpack/tron').default;
const BITCOIN = require('@walletpack/bitcoin').default;
Expand All @@ -30,12 +26,17 @@ const plugins = {
}


let seed, salt;
let scatter = storage.getScatter();
let seed, salt, scatter, storage;

salt = storage.getSalt();
// Storage is not set by default, this allows
// changing the storage mechanism for testing purposes.
const setStorage = _s => storage = _s;

storage.getSeedSetter(() => seed);
const init = () => {
scatter = storage.getScatter();
salt = storage.getSalt();
storage.getSeedSetter(() => seed);
}


const setScatter = (_s) => scatter = JSON.parse(JSON.stringify(_s));
Expand Down Expand Up @@ -100,8 +101,9 @@ const changePassword = async (newPassword) => {
});

await updateScatter(clone);
resolve(true);
return true;

// TODO:! need to reseed other storages as well
// await StoreService.get().dispatch(Actions.SET_SCATTER, scatter);
// await StorageService.swapHistory(StoreService.get().state.history);
// await StorageService.setTranslation(Locale.fromJson(StoreService.get().state.language.json));
Expand Down Expand Up @@ -143,8 +145,6 @@ const getPrivateKey = async (keypairId, blockchain) => {
let keypair = scatter.keychain.keypairs.find(x => x.id === keypairId);
if(!keypair) return;

keypair = Keypair.fromJson(keypair);

const encryptedKey = JSON.parse(JSON.stringify(keypair.privateKey));
const decryptedKey = AES.decrypt(encryptedKey, seed);

Expand Down Expand Up @@ -269,6 +269,8 @@ const decrypt = data => AES.decrypt(data, seed);
const getSeed = () => seed;

module.exports = {
setStorage,
init,
exists,
updateScatter,
setScatter,
Expand Down
112 changes: 73 additions & 39 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,20 @@
</head>
<body>


<!------------------------------------>
<!-- FAKE MENU OVERLAY FOR POPOUTS --->
<!------------------------------------>
<!-- Enables moving the window --->
<!------------------------------------>
<figure id="popout-menu"></figure>
<section id="menu-bar">

<section id="actions" class="actions">

<!------------------------------------>
<!----------- TOP BAR MENU ----------->
<!------------------------------------>
<section id="menu-bar">
<section id="actions" class="actions">
<!-- MINIMIZE -->
<section class="action" onclick="minimize()">
<section class="action-inner">
Expand All @@ -158,23 +167,32 @@
</section>
</section>











<!------------------------------------>
<!-------- WEBVIEW CONTAINER --------->
<!------------------------------------>
<section id="webviewer"></section>









<script>
const path = require('path');
const {remote, ipcRenderer} = window.require('electron');


const isPopOut = location.hash.replace("#/", '') === 'popout';


/***************************************/
/** TOP BAR MENU DISPLAY **/
/***************************************/
if(isPopOut){
document.getElementById('menu-bar').remove();
document.getElementById('webviewer').className = 'full';
Expand All @@ -183,54 +201,70 @@
if(remote.process.platform === 'darwin'){
document.getElementById('actions').remove();
}

}


/***************************************/
/** WEBVIEW INSTANTIATOR **/
/***************************************/

let webview;
const createWebview = () => {
webview = document.createElement('webview');
webview.preload = `file://${path.join(remote.app.getAppPath(), 'preload.js')}`;
console.log('webview.preload', webview.preload);
webview.src = `http://localhost:8081/${isPopOut ? '#/popout' : ''}`;
document.getElementById('webviewer').appendChild(webview);
const webview = document.createElement('webview');
webview.preload = `file://${path.join(remote.app.getAppPath(), 'preload.js')}`;
webview.src = `http://localhost:8081/${isPopOut ? '#/popout' : ''}`;
document.getElementById('webviewer').appendChild(webview);

// webview.addEventListener('dom-ready', () => {
// webview.openDevTools();
// })
}
// TODO: Remove / comment out
webview.addEventListener('dom-ready', () => {
webview.openDevTools();
});

if(!isPopOut){
createWebview();
ipcRenderer.on('socketResponse', (event, payload) => {
webview.send('socketResponse', payload);
})
} else {
createWebview();
ipcRenderer.on('popout', (event, popOut) => {
webview.send('popout', popOut);
})
}

ipcRenderer.on('openTools', (event, payload) => {


/***************************************/
/** CONSOLE FORWARDERS **/
/***************************************/
// const log = console.log;
// console.log = (...params) => {
// if(mainWindow) webview.send('console', params);
// log(...params);
// };
//
// const logerr = console.error;
// console.error = (...params) => {
// if(mainWindow) webview.send('console', params);
// logerr(...params);
// };


/***************************************/
/** IPC MESSAGES **/
/***************************************/
ipcRenderer.on('openTools', () => {
console.log('opening webview tools')
webview.openDevTools();
})
ipcRenderer.on('socketResponse', (event, payload) => webview.send('socketResponse', payload));
ipcRenderer.on('popout', (event, popOut) => webview.send('popout', popOut));
ipcRenderer.on('error', (e, x) => webview.send('error', x));
ipcRenderer.on('console', (e, x) => webview.send('console', x));



window.minimize = () => {
remote.BrowserWindow.getFocusedWindow().hide();

}

/***************************************/
/** TOP MENU METHODS **/
/***************************************/
window.quit = () => setTimeout(() => remote.app.quit(), 1);
window.minimize = () => remote.BrowserWindow.getFocusedWindow().hide();
window.maximize = () => {
const win = remote.BrowserWindow.getFocusedWindow();
win.isMaximized() ? win.unmaximize() : win.maximize();
}

window.quit = () => {
setTimeout(() => remote.app.quit(), 1);
}


</script>
</body>
Expand Down
17 changes: 12 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,24 @@
"release-linux": "electron-builder --linux",
"release-mac": "electron-builder --mac",
"release-win": "electron-builder --win",
"release-web": "node package_web.js"
"release-web": "node package_web.js",
"testfile": "electron-mocha --exit --timeout 1000000",
"test": "npm run testfile \"test/**/*.spec.js\" --timeout 1000000"
},
"dependencies": {
"@ledgerhq/hw-app-eth": "^4.68.4",
"@ledgerhq/hw-transport-node-hid": "^4.55.0",
"@walletpack/bitcoin": "^1.0.24",
"@walletpack/bitcoin": "^1.0.26",
"@walletpack/core": "^1.0.22",
"@walletpack/eosio": "^0.0.24",
"@walletpack/ethereum": "^0.0.24",
"@walletpack/tron": "^0.0.24",
"@walletpack/eosio": "^0.0.27",
"@walletpack/ethereum": "^0.0.26",
"@walletpack/tron": "^0.0.26",
"aes-oop": "^1.0.4",
"asn1-ber": "^1.0.9",
"bip32-path": "^0.4.2",
"bip39": "^2.6.0",
"electron-store": "^3.2.0",
"elliptic": "^6.5.1",
"eosjs": "^20.0.0",
"eosjs-ecc": "^4.0.7",
"ethereumjs-tx": "^2.1.0",
Expand All @@ -39,9 +42,13 @@
"ws": "^7.0.0"
},
"devDependencies": {
"chai": "^4.2.0",
"cross-env": "^6.0.0",
"electron": "^5.0.6",
"electron-builder": "^21.0.15",
"electron-mocha": "^8.1.2",
"electron-rebuild": "^1.8.5",
"mocha": "^6.2.0",
"secp256k1": "^3.6.2",
"web3": "^1.0.0-beta.55"
},
Expand Down
24 changes: 13 additions & 11 deletions preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@ if(!window.wallet) window.wallet = {};
ipc.on('scatter', (event, data) => window.wallet.received(data));
ipc.on('socketResponse', (event, data) => window.wallet.socketResponse(data));
ipc.on('popout', (event, data) => window.wallet.popout(data));
ipc.on('error', (event, data) => console.error('Error from client: ', ...data));
ipc.on('console', (event, data) => console.log('Console from client: ', ...data));

window.wallet = Object.assign(window.wallet, wallet);
window.wallet.windowId = remote.getCurrentWindow().id;

// window.wallet.send = send;


const log = console.log;
console.log = (...params) => {
sendLog(params);
return log(...params);
}

const logerr = console.error;
console.error = (...params) => {
sendLog(params);
return logerr(...params);
}
// const log = console.log;
// console.log = (...params) => {
// sendLog(params);
// return log(...params);
// }
//
// const logerr = console.error;
// console.error = (...params) => {
// sendLog(params);
// return logerr(...params);
// }
1 change: 1 addition & 0 deletions test/mock.password.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'test';
Loading

0 comments on commit d952695

Please sign in to comment.