1import Transport from '@ledgerhq/hw-transport-u2f';
2import Eth from '@ledgerhq/hw-app-eth';
5export const LEDGER_LEGACY_PATH = "m/44'/60'/0'/x";
6export const LEDGER_LIVE_PATH = "m/44'/60'/x'/0/0";
8export const chopHdPrefix = str =>
9 str.slice(0, 2) === 'm/' ? str.slice(2) : str;
10export const addHdPrefix = str => (str.slice(0, 2) === 'm/' ? str : 'm/' + str);
12export const ledgerSignTransaction = async (txn, hdPath) => {
13 const transport = await Transport.create();
14 const eth = new Eth(transport);
16 const path = chopHdPrefix(hdPath);
17 const serializedTx = txn.serialize().toString('hex');
18 const sig = await eth.signTransaction(path, serializedTx);
20 txn.v = new BN(sig.v, 'hex');
21 txn.r = new BN(sig.r, 'hex');
22 txn.s = new BN(sig.s, 'hex');
27export const ledgerSignMessage = async (message, hdPath) => {
28 const transport = await Transport.create();
29 const eth = new Eth(transport);
31 const path = chopHdPrefix(hdPath);
32 const { r, s, v } = await eth.signPersonalMessage(
34 Buffer.from(message).toString('hex')
36 const ethSignature = new Uint8Array(65);
37 ethSignature.set(Buffer.from(r, 'hex'));
38 ethSignature.set(Buffer.from(s, 'hex'), 32);
41 return `0x${Buffer.from(ethSignature).toString('hex')}`;
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list