1import React, { useCallback, useEffect, useState } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import { Grid, Text, H5, Flex } from 'indigo-react';
4import * as azimuth from 'azimuth-js';
5import { randomHex } from 'web3-utils';
7import { usePointCursor } from 'store/pointCursor';
8import { usePointCache } from 'store/pointCache';
9import { useNetwork } from 'store/network';
10import { useWallet } from 'store/wallet';
12import { useLocalRouter } from 'lib/LocalRouter';
13import * as need from 'lib/need';
16 attemptNetworkSeedDerivation,
19import { formatDotsWithTime } from 'lib/dateFormat';
20import useEthereumTransaction from 'lib/useEthereumTransaction';
21import { GAS_LIMITS, ZERO_KEY, CRYPTO_SUITE_VERSION } from 'lib/constants';
22import { addHexPrefix } from 'lib/wallet';
24import ViewHeader from 'components/ViewHeader';
25import MiniBackButton from 'components/MiniBackButton';
26import { BootArvoButton, ForwardButton } from 'components/Buttons';
27import FooterButton from 'components/FooterButton';
28import DownloadKeyfileButton from 'components/DownloadKeyfileButton';
29import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
30import NoticeBox from 'components/NoticeBox';
32const chainKeyProp = name => d =>
33 d[name] === ZERO_KEY ? Nothing() : Just(d[name]);
35const renderNetworkKey = key => {
36 const segments = segmentNetworkKey(key);
42 return segments.join('\n');
45function useSetKeys() {
46 const { urbitWallet, wallet, authMnemonic } = useWallet();
47 const { pointCursor } = usePointCursor();
48 const { syncOwnedPoint, getDetails } = usePointCache();
49 const { contracts } = useNetwork();
50 const _point = need.point(pointCursor);
51 const _contracts = need.contracts(contracts);
53 const [isDiscontinuity] = useState(false);
54 // TODO: set discontinuity with radio check?
55 const [ndNetworkSeed, setNdNetworkSeed] = useState();
57 const { construct, broadcasting, confirmed, bind } = useEthereumTransaction(
58 GAS_LIMITS.CONFIGURE_KEYS
61 // sync point details after success
64 syncOwnedPoint(_point);
66 }, [_point, confirmed, syncOwnedPoint]);
68 const setKeys = useCallback(async () => {
69 const details = need.details(getDetails(_point));
70 const networkRevision = parseInt(details.keyRevisionNumber, 10);
72 console.log('setting revision to ', networkRevision + 1);
74 const seed = await attemptNetworkSeedDerivation({
79 revision: networkRevision + 1,
82 const _networkSeed = seed.matchWith({
84 const ndSeed = randomHex(64);
85 setNdNetworkSeed(ndSeed);
91 const pair = deriveNetworkKeys(_networkSeed);
93 const txn = azimuth.ecliptic.configureKeys(
96 addHexPrefix(pair.crypt.public),
97 addHexPrefix(pair.auth.public),
124export default function AdminNetworkingKeys() {
125 const { push, names, pop } = useLocalRouter();
126 const { pointCursor } = usePointCursor();
127 const { getDetails, getRekeyDate } = usePointCache();
129 const point = need.point(pointCursor);
130 const details = getDetails(point);
132 const hasKeys = details.matchWith({
133 Nothing: () => false,
134 Just: ({ value: details }) => parseInt(details.keyRevisionNumber, 10) > 0,
137 const [didRequestSetKeys, _setDidRequestSetKeys] = useState(false);
146 const setDidRequestSetKeys = useCallback(() => {
148 _setDidRequestSetKeys(true);
149 }, [setKeys, _setDidRequestSetKeys]);
151 const goRelocate = useCallback(() => push(names.RELOCATE), [push, names]);
153 const renderTitle = () => {
155 return 'Networking keys are now set. Download your Keyfile to authenticate Arvo.';
159 return 'Setting Network Keys...';
163 return 'Networking keys have not yet been set.';
169 const renderButton = () => {
170 if (!didRequestSetKeys) {
176 onClick={() => setDidRequestSetKeys(true)}>
177 {hasKeys ? 'Reset' : 'Set'} Networking Keys
186 as={DownloadKeyfileButton}
188 networkSeed={ndNetworkSeed}
196 const renderNetworkKeySection = (title, key) => (
198 <Grid.Item full as={H5} className="mt3 gray4">
203 <Grid.Item full as="code" className="f5 gray4">
207 Just: ({ value: key }) => (
209 <Grid.Item full as="code" className="f5 wrap">
212 <Grid.Item full as="code" className="f5 wrap">
213 {renderNetworkKey(key)}
221 const renderDetail = (title, value) => (
222 <Flex.Item as={Flex} col>
223 <Flex.Item as={H5} className="gray4">
228 <Flex.Item as={Text} className="f5 gray4">
232 Just: ({ value }) => <Flex.Item as={Text}>{value}</Flex.Item>,
237 const renderDetails = () => {
240 {renderNetworkKeySection(
242 details.chain(chainKeyProp('authenticationKey'))
244 {renderNetworkKeySection(
246 details.chain(chainKeyProp('encryptionKey'))
248 <Grid.Item full as={Flex} row justify="between" className="mt3">
249 {renderDetail('Revision', details.map(d => d.keyRevisionNumber))}
250 {renderDetail('Continuity Era', details.map(d => d.continuityNumber))}
253 details.map(d => d.cryptoSuiteVersion)
257 <Grid.Item full as={Flex} row justify="between" className="mt3">
260 getRekeyDate(point).map(date =>
262 Ok: r => formatDotsWithTime(r.value),
263 Error: () => Nothing(),
276 <Grid.Item full as={MiniBackButton} onClick={() => pop()} />
278 <Grid.Item full as={ViewHeader}>
282 {!didRequestSetKeys && (
283 <Grid.Item full as={Text} className="mb3">
285 ? 'Here are your public keys that authenticate your Arvo.'
286 : 'Set your networking keys to authenticate with Arvo.'}
291 <Grid.Item full as={NoticeBox} className="mb3">
292 You need this keyfile to authenticate with Arvo.
298 {didRequestSetKeys && (
301 as={InlineEthereumTransaction}
303 onReturn={() => pop()}
307 {!didRequestSetKeys && renderDetails()}
311 <Grid.Item full as={BootArvoButton} disabled />
317 {!didRequestSetKeys && (
318 <FooterButton onClick={goRelocate} disabled>
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