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 const [ndNetworkSeed, setNdNetworkSeed] = useState();
68 construct: _construct,
73 } = useEthereumTransaction(GAS_LIMITS.CONFIGURE_KEYS);
75 // sync point details after success
78 syncOwnedPoint(_point);
80 }, [_point, confirmed, syncOwnedPoint]);
82 const getSeed = useCallback(
84 const details = need.details(getDetails(_point));
85 const networkRevision = parseInt(details.keyRevisionNumber, 10);
87 if (manualSeed !== undefined) {
88 setNdNetworkSeed(manualSeed);
91 const networkSeed = await attemptNetworkSeedDerivation({
96 revision: networkRevision + 1,
99 return networkSeed.matchWith({
101 const ndSeed = randomHex(64);
102 setNdNetworkSeed(ndSeed);
109 [_point, authMnemonic, getDetails, urbitWallet, wallet]
112 const construct = useCallback(
113 async (manualSeed, isDiscontinuity) => {
114 const seed = await getSeed(manualSeed);
115 const pair = deriveNetworkKeys(seed);
117 const txn = azimuth.ecliptic.configureKeys(
120 addHexPrefix(pair.crypt.public),
121 addHexPrefix(pair.auth.public),
122 CRYPTO_SUITE_VERSION,
123 isDiscontinuity ? 1 : 0
128 [_construct, _contracts, _point, getSeed]
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,
165 const [showNetworkSeedInput, { data: showNetworkSeed }] = useCheckboxInput({
166 name: 'shownetworkseed',
167 label: 'Use Custom Network Seed',
168 inverseLabel: 'Back to Derived Network Seed',
170 disabled: inputsLocked,
175 { pass: validNetworkSeed, data: networkSeed },
176 { setValue: setNetworkSeed },
179 label: 'Network Seed (64 bytes)',
180 length: 32, // 64 bytes
181 disabled: inputsLocked,
186 { pass: validDiscontinuity, data: isDiscontinuity },
187 ] = useCheckboxInput({
188 name: 'discontinuity',
189 label: 'Trigger New Continuity Era',
191 disabled: inputsLocked,
196 (!showNetworkSeed || (showNetworkSeed && validNetworkSeed)) &&
199 construct(networkSeed, isDiscontinuity);
211 if (!showNetworkSeed) {
214 }, [setNetworkSeed, showNetworkSeed]);
216 const goRelocate = useCallback(() => push(names.RELOCATE), [push, names]);
218 const renderTitle = () => {
220 return 'Networking keys are now set. Download your Keyfile to authenticate Arvo.';
224 return 'Setting Network Keys...';
228 return 'Networking keys have not yet been set.';
234 const renderNetworkKeySection = (title, key) => (
236 <Grid.Item full as={H5} className="mt3 gray4">
241 <Grid.Item full as="code" className="f5 gray4">
245 Just: ({ value: key }) => (
247 <Grid.Item full as="code" className="f5 wrap">
250 <Grid.Item full as="code" className="f5 wrap">
251 {renderNetworkKey(key)}
259 const renderDetail = (title, value) => (
260 <Flex.Item as={Flex} col>
261 <Flex.Item as={H5} className="gray4">
266 <Flex.Item as={Text} className="f5 gray4">
270 Just: ({ value }) => <Flex.Item as={Text}>{value}</Flex.Item>,
275 const renderDetails = () => {
278 {renderNetworkKeySection(
280 details.chain(chainKeyProp('authenticationKey'))
282 {renderNetworkKeySection(
284 details.chain(chainKeyProp('encryptionKey'))
286 <Grid.Item full as={Flex} row justify="between" className="mt3">
287 {renderDetail('Revision', details.map(d => d.keyRevisionNumber))}
288 {renderDetail('Continuity Era', details.map(d => d.continuityNumber))}
291 details.map(d => d.cryptoSuiteVersion)
295 <Grid.Item full as={Flex} row justify="between" className="mt3">
298 getRekeyDate(point).map(date =>
300 Ok: r => formatDotsWithTime(r.value),
301 Error: () => Nothing(),
314 <Grid.Item full as={MiniBackButton} onClick={() => pop()} />
316 <Grid.Item full as={ViewHeader}>
320 <Grid.Item full as={Text} className="mb3">
322 ? 'Here are your public keys that authenticate your Arvo.'
323 : 'Set your networking keys to authenticate with Arvo.'}
328 <Grid.Item full as={NoticeBox} className="mb3">
329 You need this keyfile to authenticate with Arvo.
333 as={DownloadKeyfileButton}
335 networkSeed={ndNetworkSeed}
342 <Grid.Item full as={ToggleInput} {...showNetworkSeedInput} />
343 {showNetworkSeed && (
345 <Grid.Item full as={NoticeBox} className="mb2">
346 When using a custom network seed, you'll need to download your
347 Arvo keyfile immediately after this transaction is
348 confirmed—Multipass does not store your seed.
350 <Grid.Item full as={Input} {...networkSeedInput} />
353 <Grid.Item full as={CheckboxInput} {...discontinuityInput} />
359 as={InlineEthereumTransaction}
361 label={`${hasKeys ? 'Reset' : 'Set'} Networking Keys`}
362 onReturn={() => pop()}
365 {isDefaultState && renderDetails()}
369 <Grid.Item full as={BootArvoButton} disabled />
376 <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