1import * as bip32 from 'bip32'
2import React from 'react'
3import Maybe from 'folktale/maybe'
4import { Button } from '../components/Base'
5import { Row, Col, H1, P, H2 } from '../components/Base'
6import { Input, InnerLabel } from '../components/Base'
7import Transport from '@ledgerhq/hw-transport-u2f'
8import Eth from '@ledgerhq/hw-app-eth'
9import * as secp256k1 from 'secp256k1'
11import { LEDGER_BASE_PATH } from '../lib/ledger'
12import { ROUTE_NAMES } from '../lib/router'
14const chopHdPrefix = str =>
15 str.slice(0, 2) === "m/"
19const addHdPrefix = str =>
20 str.slice(0, 2) === "m/"
24class Ledger extends React.Component {
29 hdpath: LEDGER_BASE_PATH
32 this.pollDevice = this.pollDevice.bind(this)
33 this.handleHdPathInput = this.handleHdPathInput.bind(this)
36 handleHdPathInput(hdpath) {
37 this.setState({ hdpath })
41 const { setWallet, setWalletHdPath } = this.props
42 const { hdpath } = this.state
44 const transport = await Transport.create()
45 const eth = new Eth(transport)
46 const path = chopHdPrefix(hdpath)
48 eth.getAddress(path, false, true)
50 const publicKey = Buffer.from(info.publicKey, 'hex')
51 const chainCode = Buffer.from(info.chainCode, 'hex')
52 const pub = secp256k1.publicKeyConvert(publicKey, true)
53 const hd = bip32.fromPublicKey(pub, chainCode)
54 setWallet(Maybe.Just(hd))
55 setWalletHdPath(addHdPrefix(hdpath))
57 setWallet(Maybe.Nothing())
62 const { pushRoute, popRoute, wallet } = this.props
63 const { hdpath } = this.state
68 <Col className={'measure-md'}>
69 <H1>{ 'Authenticate With Your Ledger' }</H1>
71 <H2>{'Running on HTTPS?'}</H2>
74 { `Connect and authenticate to your Ledger, and then open the
75 "Ethereum" application. If you're running on older firmware,
76 make sure the "browser support" option is turned on. To sign
77 transactions, you'll also need to enable the "contract data"
82 { `If you'd like to use a custom derivation path, you may enter
87 <H2>{'Running on HTTP?'}</H2>
89 <P>{`To authenticate and sign transactions with a Ledger, Bridge
90 must be serving over HTTPS on localhost. You can do this via the
93 <ol className={'measure-md'}>
94 <li className={'mt-4'}>{'Install'} <a target={'_blank'} href={'https://github.com/FiloSottile/mkcert'}>{'mkcert'}</a></li>
95 <li className={'mt-4'}>{'Install a local certificate authority via '}<code>{'mkcert -install'}</code></li>
96 <li className={'mt-4'}>{'In your '}<code>{'bridge'}</code>{' directory, generate a certificate valid for localhost via '} <code>{'mkcert localhost'}</code>{'.'}
97 {'This will produce two files: '}<code>{'localhost.pem'}</code> {', the local certificate, and '}<code>{'localhost-key.pem'}</code>{', its corresponding private key.'}
99 <li className={'mt-4'}>{'Run '}<code>{'python bridge-https.py'}</code></li>
103 className='pt-8 mt-8 text-mono'
105 prop-format='innerLabel'
107 value={ addHdPrefix(hdpath) }
109 onChange={ this.handleHdPathInput }>
110 <InnerLabel>{'HD Path'}</InnerLabel>
114 prop-size={'wide lg'}
116 onClick={ this.pollDevice }>
122 prop-size={'wide lg'}
123 disabled={ Maybe.Nothing.hasInstance(wallet) }
127 pushRoute(ROUTE_NAMES.SHIPS)
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