Skip to content

Commit

Permalink
Get coolwallet access to work
Browse files Browse the repository at this point in the history
  • Loading branch information
gamalielhere committed Mar 12, 2020
1 parent cca07b5 commit 2601da6
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import WalletOption from '../WalletOption';
import { Toast } from '@/helpers';
import { isSupported } from 'u2f-api';
import platform from 'platform';
import store from 'store';
import cwsTransportLib from '@coolwallets/transport-web-ble';
import {
KeepkeyWallet,
Expand Down Expand Up @@ -270,33 +271,37 @@ export default {
this.$refs.hardware.hide();
break;
case COOLWALLET_TYPE:
// this.$emit('hardwareRequiresPassword', {
// walletConstructor: CoolWallet,
// hardwareBrand: 'CoolWallet'
// });
// console.log('HELLO THERE?!?!?!', CoolWallet);
cwsTransportLib.listen(async (error, device) => {
if (device) {
const transport = await cwsTransportLib.connect(device);
CoolWallet(transport)
.then(_newWallet => {
if (_newWallet) {
this.$emit('hardwareWalletOpen', _newWallet);
} else {
// eslint-disable-next-line
const hasStoredPw = store.get('cwPass') || null;
if (hasStoredPw) {
cwsTransportLib.listen(async (error, device) => {
if (device) {
const transport = await cwsTransportLib.connect(device);
CoolWallet(transport, hasStoredPw)
.then(_newWallet => {
if (_newWallet) {
this.$emit('hardwareWalletOpen', _newWallet);
} else {
Toast.responseHandler(
new Error('No wallet instance!'),
Toast.ERROR
);
}
})
.catch(() => {
Toast.responseHandler(
new Error('No wallet instance!'),
new Error('Having issues with pairing cool wallet'),
Toast.ERROR
);
}
})
.catch(() => {
Toast.responseHandler(
new Error('Having issues with pairing cool wallet'),
Toast.ERROR
);
});
}
});
});
}
});
} else {
this.$emit('hardwareRequiresPassword', {
walletConstructor: CoolWallet,
hardwareBrand: 'CoolWallet'
});
}
break;
default:
Toast.responseHandler(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
</template>

<script>
import cwsTransportLib from '@coolwallets/transport-web-ble';
import store from 'store';
export default {
props: {
walletConstructor: {
Expand Down Expand Up @@ -78,12 +80,32 @@ export default {
this.password == '';
this.$refs.passwordInput.focus();
},
unlockWallet() {
this.walletConstructor('', this.password)
.then(_newWallet => {
this.$emit('hardwareWalletOpen', _newWallet);
})
.catch(this.walletConstructor.errorHandler);
async unlockWallet() {
if (this.hardwareBrand === 'CoolWallet') {
await cwsTransportLib.listen(async (error, device) => {
if (device) {
const transport = await cwsTransportLib.connect(device);
store.set('cwPass', this.password.toString());
this.walletConstructor(transport, this.password.toString())
.then(_newWallet => {
if (_newWallet) {
this.$emit('hardwareWalletOpen', _newWallet);
} else {
this.walletConstructor.errorHandler({
name: 'NoWalletInstance'
});
}
})
.catch(this.walletConstructor.errorHandler);
}
});
} else {
this.walletConstructor('', this.password)
.then(_newWallet => {
this.$emit('hardwareWalletOpen', _newWallet);
})
.catch(this.walletConstructor.errorHandler);
}
},
switchViewPassword() {
this.show = !this.show;
Expand Down
2 changes: 1 addition & 1 deletion src/partners/kyber/config/currenciesETH.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/partners/partnersConfig/EthereumTokens.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions src/translations/errors-coolwallet/en_US.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"wrong-password'": "Wrong password for app registration.",
"card-locked'": "Card locked! Please unlock through the app",
"already-registered": "App is already registered! If you're having trouble, please reregister the app by removing it from the wallet app."
"wrong-password": "Wrong password for app registration.",
"card-locked": "Card locked! Please unlock through the app",
"already-registered": "App is already registered! If you're having trouble, please reregister the app by removing it from the wallet app.",
"no-wallet-instance": "No wallet instance!"
}
2 changes: 2 additions & 0 deletions src/wallets/bip44/coolWalletPaths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { ethereum } from './paths';
export default [ethereum];
7 changes: 5 additions & 2 deletions src/wallets/bip44/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@ import {
BITBOX,
SECALOT,
KEEPKEY,
MNEMONIC
MNEMONIC,
COOLWALLET
} from './walletTypes';
import ledgerPaths from './ledgerPaths';
import trezorPaths from './trezorPaths';
import bitboxPaths from './bitboxPaths';
import secalotPaths from './secalotPaths';
import keepkeyPaths from './keepkeyPaths';
import mnemonicPaths from './mnemonicPaths';
import coolWalletPaths from './coolWalletPaths';

export default {
[LEDGER]: ledgerPaths,
[TREZOR]: trezorPaths,
[BITBOX]: bitboxPaths,
[SECALOT]: secalotPaths,
[KEEPKEY]: keepkeyPaths,
[MNEMONIC]: mnemonicPaths
[MNEMONIC]: mnemonicPaths,
[COOLWALLET]: coolWalletPaths
};
3 changes: 2 additions & 1 deletion src/wallets/hardware/coolwallet/errorHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import Vue from 'vue';
const ERRORS = {
WrongPassword: 'coolWalletError.wrong-password',
CardLocked: 'coolWalletError.card-locked',
AlreadyRegistered: 'coolWalletError.already-registered'
AlreadyRegistered: 'coolWalletError.already-registered',
NoWalletInstance: 'coolWalletError.no-wallet-instance'
};
const WARNING = {};

Expand Down
23 changes: 12 additions & 11 deletions src/wallets/hardware/coolwallet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import errorHandler from './errorHandler';
import cwsETH from '@coolwallets/eth';
import cwsWallet, { generateKeyPair } from '@coolwallets/wallet';
import locStore from 'store';
import bip44Paths from '../../bip44';

import store from '@/store';
import {
Expand All @@ -29,8 +30,9 @@ class CoolWallet {
this.appPublicKey = '';
this.transport = {};
this.deviceInstance = {};
this.supportedPaths = bip44Paths[coolWalletType];
}
async init(transport) {
async init(transport, password) {
this.transport = transport;
const hasKeys =
locStore.get('appPublicKey') && locStore.get('appPrivateKey');
Expand All @@ -54,7 +56,6 @@ class CoolWallet {
const coolWalletInstance = new cwsWallet(transport, this.appPrivateKey);

if (!hasAppId) {
const password = '12345678';
coolWalletInstance
.register(this.appPublicKey, password, APP_NAME)
.then(appId => {
Expand All @@ -77,14 +78,15 @@ class CoolWallet {
async getAccount(idx) {
const address = await this.deviceInstance.getAddress(idx);
this.selectedIdx = idx;
// console.log(deviceInstance, this.deviceInstance);
// const address = await deviceInstance.getAddress(idx);
const txSigner = async tx => {
tx = new Transaction(tx, {
common: commonGenerator(store.state.main.network)
});
const networkId = tx.getChainId();
const result = await cwsETH.signTransaction(tx, this.selectedIdx);
const result = await this.deviceInstance.signTransaction(
tx,
this.selectedIdx
);
if (result) {
const resultTx = new Transaction(tx);
tx.v = getBufferFromHex(sanitizeHex(resultTx.v.toString('hex')));
Expand All @@ -107,7 +109,7 @@ class CoolWallet {
return result;
};
const msgSigner = async msg => {
const result = await cwsETH.signMessage(msg, 0);
const result = await this.deviceInstance.signMessage(msg, 0);
if (result) {
const signature = result.substr(2);
const r = '0x' + signature.slice(0, 64);
Expand All @@ -134,17 +136,16 @@ class CoolWallet {
}

getCurrentPath() {
return "m/44'/60'/0'/0";
return this.supportedPaths[0].path;
}
getSupportedPaths() {
return ["m/44'/60'/0'/0"];
return this.supportedPaths;
}
}

const createWallet = async transport => {
const createWallet = async (transport, password) => {
const _coolWallet = new CoolWallet();
await _coolWallet.init(transport);
console.log(_coolWallet);
await _coolWallet.init(transport, password);
return _coolWallet;
};
createWallet.errorHandler = errorHandler;
Expand Down

1 comment on commit 2601da6

@mew-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.