1import React, { useEffect } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import * as bip32 from 'bip32';
4import { times } from 'lodash';
5import TrezorConnect from 'trezor-connect';
6import * as secp256k1 from 'secp256k1';
16import { useWallet } from 'store/wallet';
18import { TREZOR_PATH } from 'lib/trezor';
19import { WALLET_TYPES } from 'lib/wallet';
20import useLoginView from 'lib/useLoginView';
25} from 'lib/useInputs';
27import { ForwardButton } from 'components/Buttons';
29const ACCOUNT_OPTIONS = times(20, i => ({
30 text: `Account #${i + 1}`,
34// see Ledger.js for context — Trezor is basicaly Ledger with less complexity
35export default function Trezor({ className }) {
36 useLoginView(WALLET_TYPES.TREZOR);
38 const { setWallet, setWalletHdPath } = useWallet();
41 const [customPathInput, { data: useCustomPath }] = useCheckboxInput({
43 label: 'Custom HD Path',
49 const [accountInput, { data: accountIndex }] = useSelectInput({
52 placeholder: 'Choose account...',
53 options: ACCOUNT_OPTIONS,
60 { setValue: setHdPath },
64 initialValue: TREZOR_PATH.replace(/x/g, 0),
67 const pollDevice = async () => {
68 TrezorConnect.manifest({
69 email: 'bridge-trezor@urbit.org',
70 appUrl: 'https://github.com/urbit/bridge',
73 const info = await TrezorConnect.getPublicKey({
77 if (info.success === true) {
78 const payload = info.payload;
79 const publicKey = Buffer.from(payload.publicKey, 'hex');
80 const chainCode = Buffer.from(payload.chainCode, 'hex');
81 const pub = secp256k1.publicKeyConvert(publicKey, true);
82 const hd = bip32.fromPublicKey(pub, chainCode);
84 setWalletHdPath(hdPath);
94 setHdPath(TREZOR_PATH.replace(/x/g, accountIndex));
96 }, [useCustomPath, setHdPath, accountIndex]);
99 <Grid className={className}>
100 <Grid.Item full as={H5}>
101 Authenticate With Your Trezor
104 <Grid.Item full as={Text} className="f6 mb3">
105 Connect and authenticate to your Trezor. If you'd like to use a custom
106 derivation path, you may enter it below.
109 {useCustomPath && <Grid.Item full as={Input} {...hdPathInput} />}
111 {!useCustomPath && <Grid.Item full as={SelectInput} {...accountInput} />}
113 <Grid.Item full as={CheckboxInput} className="mv3" {...customPathInput} />
120 onClick={pollDevice}>
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