1import React, { useCallback, useEffect, 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,
27import { formatDotsWithTime } from 'lib/dateFormat';
28import useEthereumTransaction from 'lib/useEthereumTransaction';
29import { GAS_LIMITS, ZERO_KEY, CRYPTO_SUITE_VERSION } from 'lib/constants';
30import { addHexPrefix } from 'lib/wallet';
32import ViewHeader from 'components/ViewHeader';
33import MiniBackButton from 'components/MiniBackButton';
34import { BootArvoButton } from 'components/Buttons';
35import FooterButton from 'components/FooterButton';
36import DownloadKeyfileButton from 'components/DownloadKeyfileButton';
37import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
38import NoticeBox from 'components/NoticeBox';
39import { useHexInput, useCheckboxInput } from 'lib/useInputs';
41const chainKeyProp = name => d =>
42 d[name] === ZERO_KEY ? Nothing() : Just(d[name]);
44const renderNetworkKey = key => {
45 const segments = segmentNetworkKey(key);
51 return segments.join('\n');
54function useSetKeys() {
55 const { urbitWallet, wallet, authMnemonic } = useWallet();
56 const { pointCursor } = usePointCursor();
57 const { syncOwnedPoint, getDetails } = usePointCache();
58 const { contracts } = useNetwork();
59 const _point = need.point(pointCursor);
60 const _contracts = need.contracts(contracts);
62 const [ndNetworkSeed, setNdNetworkSeed] = useState();
66 construct: _construct,
71 } = useEthereumTransaction(GAS_LIMITS.CONFIGURE_KEYS);
73 // sync point details after success
76 syncOwnedPoint(_point);
78 }, [_point, confirmed, syncOwnedPoint]);
80 const getSeed = useCallback(
82 const details = need.details(getDetails(_point));
83 const networkRevision = parseInt(details.keyRevisionNumber, 10);
85 if (manualSeed !== undefined) {
86 setNdNetworkSeed(manualSeed);
89 const networkSeed = await attemptNetworkSeedDerivation({
94 revision: networkRevision + 1,
97 return networkSeed.matchWith({
99 const ndSeed = randomHex(64);
100 setNdNetworkSeed(ndSeed);
107 [_point, authMnemonic, getDetails, urbitWallet, wallet]
110 const construct = useCallback(
111 async (manualSeed, isDiscontinuity) => {
112 const seed = await getSeed(manualSeed);
113 const pair = deriveNetworkKeys(seed);
115 const txn = azimuth.ecliptic.configureKeys(
118 addHexPrefix(pair.crypt.public),
119 addHexPrefix(pair.auth.public),
120 CRYPTO_SUITE_VERSION,
121 isDiscontinuity ? 1 : 0
126 [_construct, _contracts, _point, getSeed]
140export default function AdminNetworkingKeys() {
141 const { push, names, pop } = useLocalRouter();
142 const { pointCursor } = usePointCursor();
143 const { getDetails, getRekeyDate } = usePointCache();
145 const point = need.point(pointCursor);
146 const details = getDetails(point);
148 const hasKeys = details.matchWith({
149 Nothing: () => false,
150 Just: ({ value: details }) => parseInt(details.keyRevisionNumber, 10) > 0,
163 const [showNetworkSeedInput, { data: showNetworkSeed }] = useCheckboxInput({
164 name: 'shownetworkseed',
165 label: 'Use Custom Network Seed',
166 inverseLabel: 'Back to Derived Network Seed',
168 disabled: inputsLocked,
173 { pass: validNetworkSeed, data: networkSeed },
174 { setValue: setNetworkSeed },
177 label: 'Network Seed (64 bytes)',
178 length: 32, // 64 bytes
179 disabled: inputsLocked,
184 { pass: validDiscontinuity, data: isDiscontinuity },
185 ] = useCheckboxInput({
186 name: 'discontinuity',
187 label: 'Trigger New Continuity Era',
189 disabled: inputsLocked,
194 (!showNetworkSeed || (showNetworkSeed && validNetworkSeed)) &&
197 construct(networkSeed, isDiscontinuity);
209 if (!showNetworkSeed) {
212 }, [setNetworkSeed, showNetworkSeed]);
214 const goRelocate = useCallback(() => push(names.RELOCATE), [push, names]);
216 const renderTitle = () => {
218 return 'Networking keys are now set. Download your Keyfile to authenticate Arvo.';
222 return 'Setting Network Keys...';
226 return 'Networking keys have not yet been set.';
232 const renderNetworkKeySection = (title, key) => (
234 <Grid.Item full as={H5} className="mt3 gray4">
239 <Grid.Item full as="code" className="f5 gray4">
243 Just: ({ value: key }) => (
245 <Grid.Item full as="code" className="f5 wrap">
248 <Grid.Item full as="code" className="f5 wrap">
249 {renderNetworkKey(key)}
257 const renderDetail = (title, value) => (
258 <Flex.Item as={Flex} col>
259 <Flex.Item as={H5} className="gray4">
264 <Flex.Item as={Text} className="f5 gray4">
268 Just: ({ value }) => <Flex.Item as={Text}>{value}</Flex.Item>,
273 const renderDetails = () => {
276 {renderNetworkKeySection(
278 details.chain(chainKeyProp('authenticationKey'))
280 {renderNetworkKeySection(
282 details.chain(chainKeyProp('encryptionKey'))
284 <Grid.Item full as={Flex} row justify="between" className="mt3">
285 {renderDetail('Revision', details.map(d => d.keyRevisionNumber))}
286 {renderDetail('Continuity Era', details.map(d => d.continuityNumber))}
289 details.map(d => d.cryptoSuiteVersion)
293 <Grid.Item full as={Flex} row justify="between" className="mt3">
296 getRekeyDate(point).map(date =>
298 Ok: r => formatDotsWithTime(r.value),
299 Error: () => Nothing(),
312 <Grid.Item full as={MiniBackButton} onClick={() => pop()} />
314 <Grid.Item full as={ViewHeader}>
318 <Grid.Item full as={Text} className="mb3">
320 ? 'Here are your public keys that authenticate your Arvo.'
321 : 'Set your networking keys to authenticate with Arvo.'}
326 <Grid.Item full as={NoticeBox} className="mb3">
327 You need this keyfile to authenticate with Arvo.
331 as={DownloadKeyfileButton}
333 networkSeed={ndNetworkSeed}
340 <Grid.Item full as={ToggleInput} {...showNetworkSeedInput} />
341 {showNetworkSeed && (
343 <Grid.Item full as={NoticeBox} className="mb2">
344 When using a custom network seed, you'll need to download your
345 Arvo keyfile immediately after this transaction is
346 confirmed—Multipass does not store your seed.
348 <Grid.Item full as={Input} {...networkSeedInput} />
351 <Grid.Item full as={CheckboxInput} {...discontinuityInput} />
357 as={InlineEthereumTransaction}
359 label={`${hasKeys ? 'Reset' : 'Set'} Networking Keys`}
360 onReturn={() => pop()}
363 {isDefaultState && renderDetails()}
367 <Grid.Item full as={BootArvoButton} disabled />
374 <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