on 23dbfee help sign in
bridge/src/lib/ledger.js
29 lines 683 B history raw
1import Transport from '@ledgerhq/hw-transport-u2f'
2import Eth from '@ledgerhq/hw-app-eth'
4const LEDGER_BASE_PATH = "44'/60'/0'/0/0"
6const chopHdPrefix = str =>
7 str.slice(0, 2) === "m/"
8 ? str.slice(2)
9 : str
11const 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')
23 return txn
26export {
27 LEDGER_BASE_PATH,
28 ledgerSignTransaction