1import React, { useCallback, useMemo, useRef, useState } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import { Grid, Text, H5, Flex, ToggleInput, CheckboxInput } 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,
21import { formatDotsWithTime } from 'lib/dateFormat';
22import useEthereumTransaction from 'lib/useEthereumTransaction';
23import { GAS_LIMITS } from 'lib/constants';
24import { addHexPrefix } from 'lib/wallet';
25import useKeyfileGenerator from 'lib/useKeyfileGenerator';
27import ViewHeader from 'components/ViewHeader';
28import { BootArvoButton } from 'components/Buttons';
29import FooterButton from 'components/FooterButton';
30import DownloadKeyfileButton from 'components/DownloadKeyfileButton';
31import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
32import NoticeBox from 'components/NoticeBox';
36 buildCheckboxValidator,
40import BridgeForm from 'form/BridgeForm';
41import Condition from 'form/Condition';
43const chainKeyProp = name => d =>
44 d[name] === CURVE_ZERO_ADDR ? Nothing() : Just(d[name]);
46const renderNetworkKey = key => {
47 const segments = segmentNetworkKey(key);
53 return segments.join('\n');
56function useSetKeys() {
57 const { urbitWallet, wallet, authMnemonic } = useWallet();
58 const { pointCursor } = usePointCursor();
59 const { syncDetails, syncRekeyDate, getDetails } = usePointCache();
60 const { contracts } = useNetwork();
62 const _point = need.point(pointCursor);
63 const _contracts = need.contracts(contracts);
64 const _details = need.details(getDetails(_point));
66 const networkRevision = parseInt(_details.keyRevisionNumber, 10);
67 const randomSeed = useRef();
69 // NOTE: nd = 'nondeterministic' (can also be a 'manual' seed)
70 const [ndNetworkSeed, setNdNetworkSeed] = useState();
73 available: keyfileAvailable,
75 } = useKeyfileGenerator(ndNetworkSeed);
77 const buildNetworkSeed = useCallback(
79 if (manualSeed !== undefined) {
80 setNdNetworkSeed(manualSeed);
83 const newNetworkRevision = networkRevision + 1;
84 console.log(`deriving seed with revision ${newNetworkRevision}`);
86 const networkSeed = await attemptNetworkSeedDerivation({
91 revision: newNetworkRevision,
94 if (Just.hasInstance(networkSeed)) {
95 return networkSeed.value;
98 randomSeed.current = randomSeed.current || randomHex(64);
99 setNdNetworkSeed(randomSeed.current);
101 return randomSeed.current;
104 [_details, authMnemonic, networkRevision, urbitWallet, wallet]
107 const { completed: _completed, ...rest } = useEthereumTransaction(
109 async (manualSeed, isDiscontinuity) => {
110 const seed = await buildNetworkSeed(manualSeed);
111 const pair = deriveNetworkKeys(seed);
113 return azimuth.ecliptic.configureKeys(
116 addHexPrefix(pair.crypt.public),
117 addHexPrefix(pair.auth.public),
118 CRYPTO_SUITE_VERSION,
122 [_contracts, _point, buildNetworkSeed]
125 () => Promise.all([syncDetails(_point), syncRekeyDate(_point)]),
126 [_point, syncDetails, syncRekeyDate]
128 GAS_LIMITS.CONFIGURE_KEYS
131 // only treat the transaction as completed once we also have keys to download
132 const completed = _completed && keyfileAvailable;
142export default function AdminNetworkingKeys() {
143 const { push, names, pop } = useLocalRouter();
144 const { pointCursor } = usePointCursor();
145 const { getDetails, getRekeyDate } = usePointCache();
147 const point = need.point(pointCursor);
148 const details = getDetails(point);
150 const hasKeys = details.matchWith({
151 Nothing: () => false,
152 Just: ({ value: details }) => parseInt(details.keyRevisionNumber, 10) > 0,
166 const validateForm = useCallback((values, errors) => {
167 if (values.useNetworkSeed && errors.networkSeed) {
174 const validate = useMemo(
178 useNetworkSeed: buildCheckboxValidator(),
179 networkSeed: buildHexValidator(32),
180 useDiscontinuity: buildCheckboxValidator(),
187 const onValues = useCallback(
188 ({ valid, values, form }) => {
191 values.useNetworkSeed ? values.networkSeed : undefined,
192 values.useDiscontinuity
198 if (!values.useNetworkSeed && values.networkSeed) {
199 form.change('networkSeed', '');
202 [construct, unconstruct]
205 const goRelocate = useCallback(() => push(names.RELOCATE), [push, names]);
207 const renderTitle = () => {
209 return 'Networking keys are now set. Download your Keyfile to authenticate Arvo.';
213 return 'Setting Network Keys...';
217 return 'Networking keys have not yet been set.';
223 const renderNetworkKeySection = (title, key) => (
225 <Grid.Item full as={H5} className="mt3 gray4">
230 <Grid.Item full as="code" className="f5 gray4">
234 Just: ({ value: key }) => (
236 <Grid.Item full as="code" className="f5 wrap">
239 <Grid.Item full as="code" className="f5 wrap">
240 {renderNetworkKey(key)}
248 const renderDetail = (title, value) => (
249 <Flex.Item as={Flex} col>
250 <Flex.Item as={H5} className="gray4">
255 <Flex.Item as={Text} className="f5 gray4">
259 Just: ({ value }) => <Flex.Item as={Text}>{value}</Flex.Item>,
264 const renderDetails = () => {
267 {renderNetworkKeySection(
269 details.chain(chainKeyProp('authenticationKey'))
271 {renderNetworkKeySection(
273 details.chain(chainKeyProp('encryptionKey'))
275 <Grid.Item full as={Flex} row justify="between" className="mt3">
276 {renderDetail('Revision', details.map(d => d.keyRevisionNumber))}
277 {renderDetail('Continuity Era', details.map(d => d.continuityNumber))}
280 details.map(d => d.cryptoSuiteVersion)
284 <Grid.Item full as={Flex} row justify="between" className="mt3">
287 getRekeyDate(point).map(date =>
289 Ok: r => formatDotsWithTime(r.value),
290 Error: () => Nothing(),
303 <Grid.Item full as={ViewHeader}>
307 <Grid.Item full as={Text} className="mb3">
309 ? 'Here are your public keys that authenticate your Arvo.'
310 : 'Set your networking keys to authenticate with Arvo.'}
315 <Grid.Item full as={NoticeBox} className="mb3">
316 You need this keyfile to authenticate with Arvo. If you have
317 already booted Arvo, run <code>|rekey '0wkeyfile.contents'</code>
319 <Grid.Item full as={DownloadKeyfileButton} solid {...keyfileBind} />
329 useNetworkSeed: false,
330 useDiscontinuity: false,
332 {({ handleSubmit }) => (
337 name="useNetworkSeed"
338 label="Use Custom Network Seed"
339 inverseLabel="Back to Derived Network Seed"
340 disabled={inputsLocked}
342 <Condition when="useNetworkSeed" is={true}>
343 <Grid.Item full as={NoticeBox} className="mb2">
344 When using a custom network seed, you'll need to download
345 your Arvo keyfile immediately after this transaction is
346 completed—Multipass does not store your seed.
352 label="Network Seed (64 bytes)"
353 disabled={inputsLocked}
359 name="useDiscontinuity"
360 label="Trigger New Continuity Era"
361 disabled={inputsLocked}
370 as={InlineEthereumTransaction}
372 label={`${hasKeys ? 'Reset' : 'Set'} Networking Keys`}
373 onReturn={() => pop()}
376 {isDefaultState && renderDetails()}
380 <Grid.Item full as={BootArvoButton} disabled />
387 <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