2018-04-27 20:49:17 +00:00
|
|
|
import { WalletLib } from 'shared/enclave/types';
|
|
|
|
import TransportNodeHid from '@ledgerhq/hw-transport-node-hid';
|
|
|
|
import LedgerEth from '@ledgerhq/hw-app-eth';
|
|
|
|
|
|
|
|
async function getEthApp() {
|
|
|
|
const transport = await TransportNodeHid.create();
|
|
|
|
return new LedgerEth(transport);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Ledger: WalletLib = {
|
|
|
|
async getChainCode(dpath: string) {
|
|
|
|
const app = await getEthApp();
|
|
|
|
try {
|
2018-04-29 21:18:39 +00:00
|
|
|
const res = await app.getAddress(dpath, false, true);
|
2018-04-27 20:49:17 +00:00
|
|
|
return {
|
|
|
|
publicKey: res.publicKey,
|
|
|
|
chainCode: res.chainCode
|
|
|
|
};
|
|
|
|
} catch (err) {
|
|
|
|
console.log('wtf', err);
|
2018-04-29 21:18:39 +00:00
|
|
|
throw new Error('Failed to connect to Ledger');
|
2018-04-27 20:49:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Ledger;
|