1import * as bip32 from 'bip32';
2import React from 'react';
3import Maybe from 'folktale/maybe';
4import { Button } from '../components/old/Base';
5import { H1, P } from '../components/old/Base';
6import { InnerLabel, Input, InnerLabelDropdown } from '../components/old/Base';
7import TrezorConnect from 'trezor-connect';
8import * as secp256k1 from 'secp256k1';
10import { TREZOR_PATH } from '../lib/trezor';
11import { ROUTE_NAMES } from '../lib/routeNames';
12import { withHistory } from '../store/history';
13import { compose } from '../lib/lib';
14import { withWallet } from '../store/wallet';
15import View from 'components/View';
17class Trezor extends React.Component {
22 hdpath: TREZOR_PATH.replace(/x/g, 0),
26 this.handleAccountSelection = this.handleAccountSelection.bind(this);
27 this.handleHdPathInput = this.handleHdPathInput.bind(this);
28 this.pollDevice = this.pollDevice.bind(this);
31 handleAccountSelection(account) {
32 let hdpath = this.state.hdpath;
33 if (account !== 'custom') {
34 hdpath = TREZOR_PATH.replace(/x/g, account);
36 this.setState({ account, hdpath });
39 handleHdPathInput(hdpath) {
40 this.setState({ hdpath });
44 const { setWallet, setWalletHdPath } = this.props;
45 const { hdpath } = this.state;
47 TrezorConnect.manifest({
48 email: 'bridge-trezor@urbit.org',
49 appUrl: 'https://github.com/urbit/bridge',
51 TrezorConnect.getPublicKey({ path: hdpath }).then(info => {
52 if (info.success === true) {
53 const payload = info.payload;
54 const publicKey = Buffer.from(payload.publicKey, 'hex');
55 const chainCode = Buffer.from(payload.chainCode, 'hex');
56 const pub = secp256k1.publicKeyConvert(publicKey, true);
57 const hd = bip32.fromPublicKey(pub, chainCode);
58 setWallet(Maybe.Just(hd));
59 setWalletHdPath(hdpath);
61 setWallet(Maybe.Nothing());
67 const { history, wallet } = this.props;
68 const { hdpath, account } = this.state;
69 const { handleAccountSelection } = this;
71 let accountOptions = [
77 for (let i = 0; i < 20; i++) {
79 title: 'Account #' + (i + 1),
83 let accountTitle = accountOptions.find(o => o.value === account).title;
85 const accountSelection = (
89 prop-format="innerLabel"
90 options={accountOptions}
91 handleUpdate={handleAccountSelection}
93 currentSelectionTitle={accountTitle}
99 account !== 'custom' ? null : (
101 className="mt-8 pt-8 text-mono"
103 prop-format="innerLabel"
107 onChange={this.handleHdPathInput}>
108 <InnerLabel>{'HD Path'}</InnerLabel>
114 <H1>{'Authenticate With Your Trezor'}</H1>
117 {`Connect and authenticate to your Trezor. If you'd like
118 to use a custom derivation path, you may enter it below.`}
126 prop-size={'wide lg'}
127 onClick={this.pollDevice}>
133 prop-size={'wide lg'}
134 disabled={Maybe.Nothing.hasInstance(wallet)}
135 onClick={() => history.popAndPush(ROUTE_NAMES.POINTS)}>
143export default compose(
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