From e9101516e7265778a2aa190b9612422a558413c5 Mon Sep 17 00:00:00 2001 From: Will O'Beirne Date: Mon, 30 Apr 2018 13:17:17 -0400 Subject: [PATCH] Check in trezor work --- electron-app/main/index.ts | 1 + package.json | 1 + shared/enclave/client/preload.ts | 1 + shared/enclave/server/index.ts | 19 +++++++++++++++++++ shared/enclave/server/wallets/trezor.ts | 13 ++++++++++++- webpack_config/webpack.electron-dev.js | 2 +- 6 files changed, 35 insertions(+), 2 deletions(-) diff --git a/electron-app/main/index.ts b/electron-app/main/index.ts index 098dac6b..587601a5 100644 --- a/electron-app/main/index.ts +++ b/electron-app/main/index.ts @@ -1,3 +1,4 @@ +import 'babel-polyfill'; import { app } from 'electron'; import { registerServer } from 'shared/enclave/server'; import getWindow from './window'; diff --git a/package.json b/package.json index 676ddfd0..1c1e5144 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "redux-logger": "3.0.6", "redux-saga": "0.16.0", "scryptsy": "2.0.0", + "trezor.js-node": "6.11.3", "uuid": "3.2.1", "wallet-address-validator": "0.1.6", "whatwg-fetch": "2.0.3", diff --git a/shared/enclave/client/preload.ts b/shared/enclave/client/preload.ts index 7eeb081a..252b4271 100644 --- a/shared/enclave/client/preload.ts +++ b/shared/enclave/client/preload.ts @@ -2,5 +2,6 @@ import { webFrame } from 'electron'; import { PROTOCOL_NAME } from 'shared/enclave/utils'; export function setupClient() { + // Whitelist custom protocol webFrame.registerURLSchemeAsPrivileged(PROTOCOL_NAME); } diff --git a/shared/enclave/server/index.ts b/shared/enclave/server/index.ts index da575093..7796f72d 100644 --- a/shared/enclave/server/index.ts +++ b/shared/enclave/server/index.ts @@ -4,9 +4,11 @@ import { PROTOCOL_NAME, isValidEventType } from 'shared/enclave/utils'; import { EnclaveMethods, EnclaveMethodParams, EnclaveResponse } from 'shared/enclave/types'; export function registerServer(app: App) { + // Register protocol scheme protocol.registerStandardSchemes([PROTOCOL_NAME]); app.on('ready', () => { + // Register custom protocol behavior protocol.registerStringProtocol(PROTOCOL_NAME, async (req, cb) => { let res: EnclaveResponse; @@ -29,6 +31,23 @@ export function registerServer(app: App) { cb(JSON.stringify(res)); }); }); + + // Fix trezord requests for every new browser window + app.on('web-contents-created', (_, webContents) => { + const { session } = webContents; + if (!session.webRequest) { + return; + } + session.webRequest.onBeforeSendHeaders((details: any, callback: any) => { + const url = details.url; + if (url.startsWith('https://localback.net:21324')) { + if (details.requestHeaders.Origin === 'null') { + delete details.requestHeaders.Origin; + } + } + callback({ cancel: false, requestHeaders: details.requestHeaders }); + }); + }); } function getMethod(req: Electron.RegisterStringProtocolRequest): EnclaveMethods { diff --git a/shared/enclave/server/wallets/trezor.ts b/shared/enclave/server/wallets/trezor.ts index d744e8e4..ad9479e6 100644 --- a/shared/enclave/server/wallets/trezor.ts +++ b/shared/enclave/server/wallets/trezor.ts @@ -1,8 +1,19 @@ import { WalletLib } from 'shared/enclave/types'; +// TODO: Trezor not working right now, come back later +// TODO: Type trezor lib +// import { DeviceList } from 'trezor.js-node'; +// const deviceList = new DeviceList({ debug: true }); const Trezor: WalletLib = { async getChainCode() { - throw new Error('Not yet supported'); + throw new Error('Not yet implemented'); + // const device = await deviceList.acquireFirstDevice(true); + // console.log(device); + // device.run((session: any) => { + // return session.signMessage([1,2], "message", "bitcoin"); + // }); + // + // return { chainCode: 'test', publicKey: 'test' }; } }; diff --git a/webpack_config/webpack.electron-dev.js b/webpack_config/webpack.electron-dev.js index 5e5da3c5..7104007c 100644 --- a/webpack_config/webpack.electron-dev.js +++ b/webpack_config/webpack.electron-dev.js @@ -31,7 +31,7 @@ const electronConfig = { ], externals: { 'node-hid': 'commonjs node-hid', - '@ledger/hw-transport-hid': 'commonjs @ledger/hw-transport-hid' + 'trezor.js-node': 'require("trezor.js-node")' }, node: { __dirname: false,