MyCrypto/shared/enclave/server/wallets/ledger.ts

27 lines
685 B
TypeScript
Raw Normal View History

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 {
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);
throw new Error('Failed to connect to Ledger');
2018-04-27 20:49:17 +00:00
}
}
};
export default Ledger;