1import Transport from '@ledgerhq/hw-transport-u2f';
2import Eth from '@ledgerhq/hw-app-eth';
4export const LEDGER_LEGACY_PATH = "m/44'/60'/0'/x";
5export const LEDGER_LIVE_PATH = "m/44'/60'/x'/0/0";
7export const chopHdPrefix = str =>
8 str.slice(0, 2) === 'm/' ? str.slice(2) : str;
9export const addHdPrefix = str => (str.slice(0, 2) === 'm/' ? str : 'm/' + str);
11export const ledgerSignTransaction = async (txn, hdPath) => {
12 const transport = await Transport.create();
13 const eth = new Eth(transport);
15 const path = chopHdPrefix(hdPath);
16 const serializedTx = txn.serialize().toString('hex');
17 const sig = await eth.signTransaction(path, serializedTx);
19 txn.v = Buffer.from(sig.v, 'hex');
20 txn.r = Buffer.from(sig.r, 'hex');
21 txn.s = Buffer.from(sig.s, 'hex');
26export const ledgerSignMessage = async (message, hdPath) => {
27 const transport = await Transport.create();
28 const eth = new Eth(transport);
30 const path = chopHdPrefix(hdPath);
31 const { r, s, v } = await eth.signPersonalMessage(
33 Buffer.from(message).toString('hex')
35 const ethSignature = new Uint8Array(65);
36 ethSignature.set(Buffer.from(r, 'hex'));
37 ethSignature.set(Buffer.from(s, 'hex'), 32);
40 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