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';
33import { useHexInput, useCheckboxInput } from 'lib/useInputs';
34import useKeyfileGenerator from 'lib/useKeyfileGenerator';
36import ViewHeader from 'components/ViewHeader';
37import { BootArvoButton } from 'components/Buttons';
38import FooterButton from 'components/FooterButton';
39import DownloadKeyfileButton from 'components/DownloadKeyfileButton';
40import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
41import NoticeBox from 'components/NoticeBox';
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 [showNetworkSeedInput, { data: showNetworkSeed }] = useCheckboxInput({
167 name: 'shownetworkseed',
168 label: 'Use Custom Network Seed',
169 inverseLabel: 'Back to Derived Network Seed',
171 disabled: inputsLocked,
176 { pass: validNetworkSeed, data: networkSeed },
177 { reset: resetNetworkSeed },
180 label: 'Network Seed (64 bytes)',
181 length: 32, // 64 bytes
182 disabled: inputsLocked,
187 { pass: validDiscontinuity, data: isDiscontinuity },
188 ] = useCheckboxInput({
189 name: 'discontinuity',
190 label: 'Trigger New Continuity Era',
192 disabled: inputsLocked,
196 const nothingOrValidSeed =
197 !showNetworkSeed || (showNetworkSeed && validNetworkSeed);
198 if (nothingOrValidSeed && validDiscontinuity) {
199 construct(networkSeed, isDiscontinuity);
214 if (!showNetworkSeed) {
217 }, [resetNetworkSeed, showNetworkSeed]);
219 const goRelocate = useCallback(() => push(names.RELOCATE), [push, names]);
221 const renderTitle = () => {
223 return 'Networking keys are now set. Download your Keyfile to authenticate Arvo.';
227 return 'Setting Network Keys...';
231 return 'Networking keys have not yet been set.';
237 const renderNetworkKeySection = (title, key) => (
239 <Grid.Item full as={H5} className="mt3 gray4">
244 <Grid.Item full as="code" className="f5 gray4">
248 Just: ({ value: key }) => (
250 <Grid.Item full as="code" className="f5 wrap">
253 <Grid.Item full as="code" className="f5 wrap">
254 {renderNetworkKey(key)}
262 const renderDetail = (title, value) => (
263 <Flex.Item as={Flex} col>
264 <Flex.Item as={H5} className="gray4">
269 <Flex.Item as={Text} className="f5 gray4">
273 Just: ({ value }) => <Flex.Item as={Text}>{value}</Flex.Item>,
278 const renderDetails = () => {
281 {renderNetworkKeySection(
283 details.chain(chainKeyProp('authenticationKey'))
285 {renderNetworkKeySection(
287 details.chain(chainKeyProp('encryptionKey'))
289 <Grid.Item full as={Flex} row justify="between" className="mt3">
290 {renderDetail('Revision', details.map(d => d.keyRevisionNumber))}
291 {renderDetail('Continuity Era', details.map(d => d.continuityNumber))}
294 details.map(d => d.cryptoSuiteVersion)
298 <Grid.Item full as={Flex} row justify="between" className="mt3">
301 getRekeyDate(point).map(date =>
303 Ok: r => formatDotsWithTime(r.value),
304 Error: () => Nothing(),
317 <Grid.Item full as={ViewHeader}>
321 <Grid.Item full as={Text} className="mb3">
323 ? 'Here are your public keys that authenticate your Arvo.'
324 : 'Set your networking keys to authenticate with Arvo.'}
329 <Grid.Item full as={NoticeBox} className="mb3">
330 You need this keyfile to authenticate with Arvo. If you have
331 already booted Arvo, run <code>|rekey '0wkeyfile.contents'</code>
333 <Grid.Item full as={DownloadKeyfileButton} solid {...keyfileBind} />
339 <Grid.Item full as={ToggleInput} {...showNetworkSeedInput} />
340 {showNetworkSeed && (
342 <Grid.Item full as={NoticeBox} className="mb2">
343 When using a custom network seed, you'll need to download your
344 Arvo keyfile immediately after this transaction is completed —
345 Bridge does not store your seed.
347 <Grid.Item full as={Input} {...networkSeedInput} />
350 <Grid.Item full as={CheckboxInput} {...discontinuityInput} />
356 as={InlineEthereumTransaction}
358 label={`${hasKeys ? 'Reset' : 'Set'} Networking Keys`}
359 onReturn={() => pop()}
362 {isDefaultState && renderDetails()}
366 <Grid.Item full as={BootArvoButton} disabled />
373 <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