1import React, { useCallback, useEffect, useRef, useState } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
12import * as azimuth from 'azimuth-js';
13import { randomHex } from 'web3-utils';
15import { usePointCursor } from 'store/pointCursor';
16import { usePointCache } from 'store/pointCache';
17import { useNetwork } from 'store/network';
18import { useWallet } from 'store/wallet';
20import { useLocalRouter } from 'lib/LocalRouter';
21import * as need from 'lib/need';
24 attemptNetworkSeedDerivation,
29import { formatDotsWithTime } from 'lib/dateFormat';
30import useEthereumTransaction from 'lib/useEthereumTransaction';
31import { GAS_LIMITS } from 'lib/constants';
32import { addHexPrefix } from 'lib/wallet';
34import ViewHeader from 'components/ViewHeader';
35import MiniBackButton from 'components/MiniBackButton';
36import { BootArvoButton } from 'components/Buttons';
37import FooterButton from 'components/FooterButton';
38import DownloadKeyfileButton from 'components/DownloadKeyfileButton';
39import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
40import NoticeBox from 'components/NoticeBox';
41import { useHexInput, useCheckboxInput } from 'lib/useInputs';
42import useKeyfileGenerator from 'lib/useKeyfileGenerator';
44const chainKeyProp = name => d =>
45 d[name] === CURVE_ZERO_ADDR ? Nothing() : Just(d[name]);
47const renderNetworkKey = key => {
48 const segments = segmentNetworkKey(key);
54 return segments.join('\n');
57function useSetKeys() {
58 const { urbitWallet, wallet, authMnemonic } = useWallet();
59 const { pointCursor } = usePointCursor();
60 const { syncOwnedPoint, getDetails } = usePointCache();
61 const { contracts } = useNetwork();
62 const _point = need.point(pointCursor);
63 const _contracts = need.contracts(contracts);
65 const randomSeed = useRef();
67 // NOTE: nd = 'nondeterministic' (can also be a 'manual' seed)
68 const [ndNetworkSeed, setNdNetworkSeed] = useState();
71 available: keyfileAvailable,
73 } = useKeyfileGenerator(ndNetworkSeed);
77 construct: _construct,
80 confirmed: _confirmed,
83 } = useEthereumTransaction(GAS_LIMITS.CONFIGURE_KEYS);
85 // only treat the transaction as confirmed once we also have keys to download
86 const confirmed = _confirmed && keyfileAvailable;
88 // sync point details after success
91 syncOwnedPoint(_point);
93 }, [_point, confirmed, syncOwnedPoint]);
95 const getSeed = useCallback(
97 const details = need.details(getDetails(_point));
98 const networkRevision = parseInt(details.keyRevisionNumber, 10);
100 if (manualSeed !== undefined) {
101 setNdNetworkSeed(manualSeed);
104 const networkSeed = await attemptNetworkSeedDerivation({
109 revision: networkRevision + 1,
112 if (Just.hasInstance(networkSeed)) {
113 return networkSeed.value;
116 randomSeed.current = randomSeed.current || randomHex(64);
117 setNdNetworkSeed(randomSeed.current);
119 return randomSeed.current;
122 [_point, authMnemonic, getDetails, urbitWallet, wallet]
125 const construct = useCallback(
126 async (manualSeed, isDiscontinuity) => {
127 const seed = await getSeed(manualSeed);
128 const pair = deriveNetworkKeys(seed);
130 const txn = azimuth.ecliptic.configureKeys(
133 addHexPrefix(pair.crypt.public),
134 addHexPrefix(pair.auth.public),
135 CRYPTO_SUITE_VERSION,
141 [_construct, _contracts, _point, getSeed]
157export default function AdminNetworkingKeys() {
158 const { push, names, pop } = useLocalRouter();
159 const { pointCursor } = usePointCursor();
160 const { getDetails, getRekeyDate } = usePointCache();
162 const point = need.point(pointCursor);
163 const details = getDetails(point);
165 const hasKeys = details.matchWith({
166 Nothing: () => false,
167 Just: ({ value: details }) => parseInt(details.keyRevisionNumber, 10) > 0,
181 const [showNetworkSeedInput, { data: showNetworkSeed }] = useCheckboxInput({
182 name: 'shownetworkseed',
183 label: 'Use Custom Network Seed',
184 inverseLabel: 'Back to Derived Network Seed',
186 disabled: inputsLocked,
191 { pass: validNetworkSeed, data: networkSeed },
192 { reset: resetNetworkSeed },
195 label: 'Network Seed (64 bytes)',
196 length: 32, // 64 bytes
197 disabled: inputsLocked,
202 { pass: validDiscontinuity, data: isDiscontinuity },
203 ] = useCheckboxInput({
204 name: 'discontinuity',
205 label: 'Trigger New Continuity Era',
207 disabled: inputsLocked,
211 const nothingOrValidSeed =
212 !showNetworkSeed || (showNetworkSeed && validNetworkSeed);
213 if (nothingOrValidSeed && validDiscontinuity) {
214 construct(networkSeed, isDiscontinuity);
229 if (!showNetworkSeed) {
232 }, [resetNetworkSeed, showNetworkSeed]);
234 const goRelocate = useCallback(() => push(names.RELOCATE), [push, names]);
236 const renderTitle = () => {
238 return 'Networking keys are now set. Download your Keyfile to authenticate Arvo.';
242 return 'Setting Network Keys...';
246 return 'Networking keys have not yet been set.';
252 const renderNetworkKeySection = (title, key) => (
254 <Grid.Item full as={H5} className="mt3 gray4">
259 <Grid.Item full as="code" className="f5 gray4">
263 Just: ({ value: key }) => (
265 <Grid.Item full as="code" className="f5 wrap">
268 <Grid.Item full as="code" className="f5 wrap">
269 {renderNetworkKey(key)}
277 const renderDetail = (title, value) => (
278 <Flex.Item as={Flex} col>
279 <Flex.Item as={H5} className="gray4">
284 <Flex.Item as={Text} className="f5 gray4">
288 Just: ({ value }) => <Flex.Item as={Text}>{value}</Flex.Item>,
293 const renderDetails = () => {
296 {renderNetworkKeySection(
298 details.chain(chainKeyProp('authenticationKey'))
300 {renderNetworkKeySection(
302 details.chain(chainKeyProp('encryptionKey'))
304 <Grid.Item full as={Flex} row justify="between" className="mt3">
305 {renderDetail('Revision', details.map(d => d.keyRevisionNumber))}
306 {renderDetail('Continuity Era', details.map(d => d.continuityNumber))}
309 details.map(d => d.cryptoSuiteVersion)
313 <Grid.Item full as={Flex} row justify="between" className="mt3">
316 getRekeyDate(point).map(date =>
318 Ok: r => formatDotsWithTime(r.value),
319 Error: () => Nothing(),
332 <Grid.Item full as={MiniBackButton} onClick={() => pop()} />
334 <Grid.Item full as={ViewHeader}>
338 <Grid.Item full as={Text} className="mb3">
340 ? 'Here are your public keys that authenticate your Arvo.'
341 : 'Set your networking keys to authenticate with Arvo.'}
346 <Grid.Item full as={NoticeBox} className="mb3">
347 You need this keyfile to authenticate with Arvo.
349 <Grid.Item full as={DownloadKeyfileButton} solid {...keyfileBind} />
355 <Grid.Item full as={ToggleInput} {...showNetworkSeedInput} />
356 {showNetworkSeed && (
358 <Grid.Item full as={NoticeBox} className="mb2">
359 When using a custom network seed, you'll need to download your
360 Arvo keyfile immediately after this transaction is
361 confirmed—Multipass does not store your seed.
363 <Grid.Item full as={Input} {...networkSeedInput} />
366 <Grid.Item full as={CheckboxInput} {...discontinuityInput} />
372 as={InlineEthereumTransaction}
374 label={`${hasKeys ? 'Reset' : 'Set'} Networking Keys`}
375 onReturn={() => pop()}
378 {isDefaultState && renderDetails()}
382 <Grid.Item full as={BootArvoButton} disabled />
389 <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