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();
63 const _point = need.point(pointCursor);
64 const _contracts = need.contracts(contracts);
65 const _details = need.details(getDetails(_point));
67 const networkRevision = parseInt(_details.keyRevisionNumber, 10);
68 const randomSeed = useRef();
70 // NOTE: nd = 'nondeterministic' (can also be a 'manual' seed)
71 const [ndNetworkSeed, setNdNetworkSeed] = useState();
74 available: keyfileAvailable,
76 } = useKeyfileGenerator(ndNetworkSeed);
80 construct: _construct,
83 confirmed: _confirmed,
86 } = useEthereumTransaction(GAS_LIMITS.CONFIGURE_KEYS);
88 // only treat the transaction as confirmed once we also have keys to download
89 const confirmed = _confirmed && keyfileAvailable;
91 // sync point details after success
94 syncOwnedPoint(_point);
96 }, [_point, confirmed, syncOwnedPoint]);
98 const buildNetworkSeed = useCallback(
100 if (manualSeed !== undefined) {
101 setNdNetworkSeed(manualSeed);
104 const newNetworkRevision = networkRevision + 1;
105 console.log(`deriving seed with revision ${newNetworkRevision}`);
107 const networkSeed = await attemptNetworkSeedDerivation({
112 revision: newNetworkRevision,
115 if (Just.hasInstance(networkSeed)) {
116 return networkSeed.value;
119 randomSeed.current = randomSeed.current || randomHex(64);
120 setNdNetworkSeed(randomSeed.current);
122 return randomSeed.current;
125 [_details, authMnemonic, networkRevision, urbitWallet, wallet]
128 const construct = useCallback(
129 async (manualSeed, isDiscontinuity) => {
130 const seed = await buildNetworkSeed(manualSeed);
131 const pair = deriveNetworkKeys(seed);
133 const txn = azimuth.ecliptic.configureKeys(
136 addHexPrefix(pair.crypt.public),
137 addHexPrefix(pair.auth.public),
138 CRYPTO_SUITE_VERSION,
144 [_construct, _contracts, _point, buildNetworkSeed]
160export default function AdminNetworkingKeys() {
161 const { push, names, pop } = useLocalRouter();
162 const { pointCursor } = usePointCursor();
163 const { getDetails, getRekeyDate } = usePointCache();
165 const point = need.point(pointCursor);
166 const details = getDetails(point);
168 const hasKeys = details.matchWith({
169 Nothing: () => false,
170 Just: ({ value: details }) => parseInt(details.keyRevisionNumber, 10) > 0,
184 const [showNetworkSeedInput, { data: showNetworkSeed }] = useCheckboxInput({
185 name: 'shownetworkseed',
186 label: 'Use Custom Network Seed',
187 inverseLabel: 'Back to Derived Network Seed',
189 disabled: inputsLocked,
194 { pass: validNetworkSeed, data: networkSeed },
195 { reset: resetNetworkSeed },
198 label: 'Network Seed (64 bytes)',
199 length: 32, // 64 bytes
200 disabled: inputsLocked,
205 { pass: validDiscontinuity, data: isDiscontinuity },
206 ] = useCheckboxInput({
207 name: 'discontinuity',
208 label: 'Trigger New Continuity Era',
210 disabled: inputsLocked,
214 const nothingOrValidSeed =
215 !showNetworkSeed || (showNetworkSeed && validNetworkSeed);
216 if (nothingOrValidSeed && validDiscontinuity) {
217 construct(networkSeed, isDiscontinuity);
232 if (!showNetworkSeed) {
235 }, [resetNetworkSeed, showNetworkSeed]);
237 const goRelocate = useCallback(() => push(names.RELOCATE), [push, names]);
239 const renderTitle = () => {
241 return 'Networking keys are now set. Download your Keyfile to authenticate Arvo.';
245 return 'Setting Network Keys...';
249 return 'Networking keys have not yet been set.';
255 const renderNetworkKeySection = (title, key) => (
257 <Grid.Item full as={H5} className="mt3 gray4">
262 <Grid.Item full as="code" className="f5 gray4">
266 Just: ({ value: key }) => (
268 <Grid.Item full as="code" className="f5 wrap">
271 <Grid.Item full as="code" className="f5 wrap">
272 {renderNetworkKey(key)}
280 const renderDetail = (title, value) => (
281 <Flex.Item as={Flex} col>
282 <Flex.Item as={H5} className="gray4">
287 <Flex.Item as={Text} className="f5 gray4">
291 Just: ({ value }) => <Flex.Item as={Text}>{value}</Flex.Item>,
296 const renderDetails = () => {
299 {renderNetworkKeySection(
301 details.chain(chainKeyProp('authenticationKey'))
303 {renderNetworkKeySection(
305 details.chain(chainKeyProp('encryptionKey'))
307 <Grid.Item full as={Flex} row justify="between" className="mt3">
308 {renderDetail('Revision', details.map(d => d.keyRevisionNumber))}
309 {renderDetail('Continuity Era', details.map(d => d.continuityNumber))}
312 details.map(d => d.cryptoSuiteVersion)
316 <Grid.Item full as={Flex} row justify="between" className="mt3">
319 getRekeyDate(point).map(date =>
321 Ok: r => formatDotsWithTime(r.value),
322 Error: () => Nothing(),
335 <Grid.Item full as={MiniBackButton} onClick={() => pop()} />
337 <Grid.Item full as={ViewHeader}>
341 <Grid.Item full as={Text} className="mb3">
343 ? 'Here are your public keys that authenticate your Arvo.'
344 : 'Set your networking keys to authenticate with Arvo.'}
349 <Grid.Item full as={NoticeBox} className="mb3">
350 You need this keyfile to authenticate with Arvo.
352 <Grid.Item full as={DownloadKeyfileButton} solid {...keyfileBind} />
358 <Grid.Item full as={ToggleInput} {...showNetworkSeedInput} />
359 {showNetworkSeed && (
361 <Grid.Item full as={NoticeBox} className="mb2">
362 When using a custom network seed, you'll need to download your
363 Arvo keyfile immediately after this transaction is
364 confirmed—Multipass does not store your seed.
366 <Grid.Item full as={Input} {...networkSeedInput} />
369 <Grid.Item full as={CheckboxInput} {...discontinuityInput} />
375 as={InlineEthereumTransaction}
377 label={`${hasKeys ? 'Reset' : 'Set'} Networking Keys`}
378 onReturn={() => pop()}
381 {isDefaultState && renderDetails()}
385 <Grid.Item full as={BootArvoButton} disabled />
392 <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