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';
10import { useLocalRouter } from 'lib/LocalRouter';
11import * as need from 'lib/need';
14 attemptNetworkSeedDerivation,
17import { formatDotsWithTime } from 'lib/dateFormat';
19import ViewHeader from 'components/ViewHeader';
20import MiniBackButton from 'components/MiniBackButton';
21import { BootArvoButton, ForwardButton } from 'components/Buttons';
22import FooterButton from 'components/FooterButton';
23import WarningBox from 'components/WarningBox';
24import DownloadKeyfileButton from 'components/DownloadKeyfileButton';
25import useEthereumTransaction from 'lib/useEthereumTransaction';
26import { GAS_LIMITS, ZERO_KEY } from 'lib/constants';
27import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
28import { addHexPrefix } from 'lib/wallet';
29import { useNetwork } from 'store/network';
30import { useWallet } from 'store/wallet';
32const CRYPTO_SUITE_VERSION = 1;
34const chainKeyProp = name => d =>
35 d[name] === ZERO_KEY ? Nothing() : Just(d[name]);
37const renderNetworkKey = key => {
38 const segments = segmentNetworkKey(key);
44 return segments.join('\n');
47function useSetKeys() {
48 const { urbitWallet, wallet, authMnemonic } = useWallet();
49 const { pointCursor } = usePointCursor();
50 const { syncOwnedPoint, getDetails } = usePointCache();
51 const { contracts } = useNetwork();
52 const _point = need.point(pointCursor);
53 const _contracts = need.contracts(contracts);
55 const [isDiscontinuity] = useState(false);
56 // TODO: set discontinuity with radio check?
57 const [ndNetworkSeed, setNdNetworkSeed] = useState();
59 const { construct, broadcasting, confirmed, bind } = useEthereumTransaction(
60 GAS_LIMITS.CONFIGURE_KEYS
63 // sync point details after success
66 syncOwnedPoint(_point);
68 }, [_point, confirmed, syncOwnedPoint]);
70 const setKeys = useCallback(async () => {
71 const details = need.details(getDetails(_point));
72 const networkRevision = parseInt(details.keyRevisionNumber, 10);
74 console.log('setting revision to ', networkRevision + 1);
76 const seed = await attemptNetworkSeedDerivation({
81 revision: networkRevision + 1,
84 const _networkSeed = seed.matchWith({
86 const ndSeed = randomHex(64);
87 setNdNetworkSeed(ndSeed);
93 const pair = deriveNetworkKeys(_networkSeed);
95 const txn = azimuth.ecliptic.configureKeys(
98 addHexPrefix(pair.crypt.public),
99 addHexPrefix(pair.auth.public),
100 CRYPTO_SUITE_VERSION,
126export default function AdminNetworkingKeys() {
127 const { push, names, pop } = useLocalRouter();
128 const { pointCursor } = usePointCursor();
129 const { getDetails, getRekeyDate } = usePointCache();
131 const point = need.point(pointCursor);
132 const details = getDetails(point);
134 const hasKeys = details.matchWith({
135 Nothing: () => false,
136 Just: ({ value: details }) => parseInt(details.keyRevisionNumber, 10) > 0,
139 const [didRequestSetKeys, _setDidRequestSetKeys] = useState(false);
148 const setDidRequestSetKeys = useCallback(() => {
150 _setDidRequestSetKeys(true);
151 }, [setKeys, _setDidRequestSetKeys]);
153 const goRelocate = useCallback(() => push(names.RELOCATE), [push, names]);
155 const renderTitle = () => {
157 return 'Networking keys are now set. Download your Keyfile to authenticate Arvo.';
161 return 'Setting Network Keys...';
165 return 'Networking keys have not yet been set.';
171 const renderButton = () => {
172 if (!didRequestSetKeys) {
178 onClick={() => setDidRequestSetKeys(true)}>
179 {hasKeys ? 'Reset' : 'Set'} Networking Keys
188 as={DownloadKeyfileButton}
190 networkSeed={ndNetworkSeed}
198 const renderNetworkKeySection = (title, key) => (
200 <Grid.Item full as={H5} className="mt3 gray4">
205 <Grid.Item full as="code" className="f5 gray4">
209 Just: ({ value: key }) => (
211 <Grid.Item full as="code" className="f5 wrap">
214 <Grid.Item full as="code" className="f5 wrap">
215 {renderNetworkKey(key)}
223 const renderDetail = (title, value) => (
224 <Flex.Item as={Flex} col>
225 <Flex.Item as={H5} className="gray4">
230 <Flex.Item as={Text} className="f5 gray4">
234 Just: ({ value }) => <Flex.Item as={Text}>{value}</Flex.Item>,
239 const renderDetails = () => {
242 {renderNetworkKeySection(
244 details.chain(chainKeyProp('authenticationKey'))
246 {renderNetworkKeySection(
248 details.chain(chainKeyProp('encryptionKey'))
250 <Grid.Item full as={Flex} row justify="between" className="mt3">
251 {renderDetail('Revision', details.map(d => d.keyRevisionNumber))}
252 {renderDetail('Continuity Era', details.map(d => d.continuityNumber))}
255 details.map(d => d.cryptoSuiteVersion)
259 <Grid.Item full as={Flex} row justify="between" className="mt3">
262 getRekeyDate(point).map(date =>
264 Ok: r => formatDotsWithTime(r.value),
265 Error: () => Nothing(),
278 <Grid.Item full as={MiniBackButton} onClick={() => pop()} />
280 <Grid.Item full as={ViewHeader}>
284 {!didRequestSetKeys && (
285 <Grid.Item full as={Text} className="mb3">
287 ? 'Here are your public keys that authenticate your Arvo.'
288 : 'Set your networking keys to authenticate with Arvo.'}
293 <Grid.Item full as={WarningBox} className="mb3">
294 You need this keyfile to authenticate with Arvo.
300 {didRequestSetKeys && (
303 as={InlineEthereumTransaction}
305 onReturn={() => pop()}
309 {!didRequestSetKeys && renderDetails()}
313 <Grid.Item full as={BootArvoButton} disabled />
319 {!didRequestSetKeys && (
320 <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