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,
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';
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 { syncOwnedPoint, getDetails } = usePointCache();
60 const { contracts } = useNetwork();
61 const _point = need.point(pointCursor);
62 const _contracts = need.contracts(contracts);
64 // NOTE: nd = 'nondeterministic' (can also be a 'manual' seed)
65 const [ndNetworkSeed, setNdNetworkSeed] = useState();
69 construct: _construct,
75 } = useEthereumTransaction(GAS_LIMITS.CONFIGURE_KEYS);
77 // sync point details after success
80 syncOwnedPoint(_point);
82 }, [_point, confirmed, syncOwnedPoint]);
84 const getSeed = useCallback(
86 const details = need.details(getDetails(_point));
87 const networkRevision = parseInt(details.keyRevisionNumber, 10);
89 if (manualSeed !== undefined) {
90 setNdNetworkSeed(manualSeed);
93 const networkSeed = await attemptNetworkSeedDerivation({
98 revision: networkRevision + 1,
101 return networkSeed.matchWith({
103 const ndSeed = randomHex(64);
104 setNdNetworkSeed(ndSeed);
111 [_point, authMnemonic, getDetails, urbitWallet, wallet]
114 const construct = useCallback(
115 async (manualSeed, isDiscontinuity) => {
116 const seed = await getSeed(manualSeed);
117 const pair = deriveNetworkKeys(seed);
119 const txn = azimuth.ecliptic.configureKeys(
122 addHexPrefix(pair.crypt.public),
123 addHexPrefix(pair.auth.public),
124 CRYPTO_SUITE_VERSION,
130 [_construct, _contracts, _point, getSeed]
145export default function AdminNetworkingKeys() {
146 const { push, names, pop } = useLocalRouter();
147 const { pointCursor } = usePointCursor();
148 const { getDetails, getRekeyDate } = usePointCache();
150 const point = need.point(pointCursor);
151 const details = getDetails(point);
153 const hasKeys = details.matchWith({
154 Nothing: () => false,
155 Just: ({ value: details }) => parseInt(details.keyRevisionNumber, 10) > 0,
169 const [showNetworkSeedInput, { data: showNetworkSeed }] = useCheckboxInput({
170 name: 'shownetworkseed',
171 label: 'Use Custom Network Seed',
172 inverseLabel: 'Back to Derived Network Seed',
174 disabled: inputsLocked,
179 { pass: validNetworkSeed, data: networkSeed },
180 { reset: resetNetworkSeed },
183 label: 'Network Seed (64 bytes)',
184 length: 32, // 64 bytes
185 disabled: inputsLocked,
190 { pass: validDiscontinuity, data: isDiscontinuity },
191 ] = useCheckboxInput({
192 name: 'discontinuity',
193 label: 'Trigger New Continuity Era',
195 disabled: inputsLocked,
199 const nothingOrValidSeed =
200 !showNetworkSeed || (showNetworkSeed && validNetworkSeed);
201 if (nothingOrValidSeed && validDiscontinuity) {
202 construct(networkSeed, isDiscontinuity);
217 if (!showNetworkSeed) {
220 }, [resetNetworkSeed, showNetworkSeed]);
222 const goRelocate = useCallback(() => push(names.RELOCATE), [push, names]);
224 const renderTitle = () => {
226 return 'Networking keys are now set. Download your Keyfile to authenticate Arvo.';
230 return 'Setting Network Keys...';
234 return 'Networking keys have not yet been set.';
240 const renderNetworkKeySection = (title, key) => (
242 <Grid.Item full as={H5} className="mt3 gray4">
247 <Grid.Item full as="code" className="f5 gray4">
251 Just: ({ value: key }) => (
253 <Grid.Item full as="code" className="f5 wrap">
256 <Grid.Item full as="code" className="f5 wrap">
257 {renderNetworkKey(key)}
265 const renderDetail = (title, value) => (
266 <Flex.Item as={Flex} col>
267 <Flex.Item as={H5} className="gray4">
272 <Flex.Item as={Text} className="f5 gray4">
276 Just: ({ value }) => <Flex.Item as={Text}>{value}</Flex.Item>,
281 const renderDetails = () => {
284 {renderNetworkKeySection(
286 details.chain(chainKeyProp('authenticationKey'))
288 {renderNetworkKeySection(
290 details.chain(chainKeyProp('encryptionKey'))
292 <Grid.Item full as={Flex} row justify="between" className="mt3">
293 {renderDetail('Revision', details.map(d => d.keyRevisionNumber))}
294 {renderDetail('Continuity Era', details.map(d => d.continuityNumber))}
297 details.map(d => d.cryptoSuiteVersion)
301 <Grid.Item full as={Flex} row justify="between" className="mt3">
304 getRekeyDate(point).map(date =>
306 Ok: r => formatDotsWithTime(r.value),
307 Error: () => Nothing(),
320 <Grid.Item full as={MiniBackButton} onClick={() => pop()} />
322 <Grid.Item full as={ViewHeader}>
326 <Grid.Item full as={Text} className="mb3">
328 ? 'Here are your public keys that authenticate your Arvo.'
329 : 'Set your networking keys to authenticate with Arvo.'}
334 <Grid.Item full as={NoticeBox} className="mb3">
335 You need this keyfile to authenticate with Arvo.
339 as={DownloadKeyfileButton}
341 networkSeed={ndNetworkSeed}
348 <Grid.Item full as={ToggleInput} {...showNetworkSeedInput} />
349 {showNetworkSeed && (
351 <Grid.Item full as={NoticeBox} className="mb2">
352 When using a custom network seed, you'll need to download your
353 Arvo keyfile immediately after this transaction is
354 confirmed—Multipass does not store your seed.
356 <Grid.Item full as={Input} {...networkSeedInput} />
359 <Grid.Item full as={CheckboxInput} {...discontinuityInput} />
365 as={InlineEthereumTransaction}
367 label={`${hasKeys ? 'Reset' : 'Set'} Networking Keys`}
368 onReturn={() => pop()}
371 {isDefaultState && renderDetails()}
375 <Grid.Item full as={BootArvoButton} disabled />
382 <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