@@ -1,431 +0,0 @@
1−import React, { useCallback, useMemo, useRef, useState } from 'react';
2−import { Just, Nothing } from 'folktale/maybe';
3−import { Grid, Text, H5, Flex, ToggleInput, CheckboxInput } from 'indigo-react';
4−import * as azimuth from 'azimuth-js';
5−import ob from 'urbit-ob';
6−import { randomHex } from 'web3-utils';
8−import { usePointCursor } from 'store/pointCursor';
9−import { usePointCache } from 'store/pointCache';
10−import { useNetwork } from 'store/network';
11−import { useWallet } from 'store/wallet';
13−import { useLocalRouter } from 'lib/LocalRouter';
14−import * as need from 'lib/need';
17− attemptNetworkSeedDerivation,
19− CRYPTO_SUITE_VERSION,
22−import { formatDotsWithTime } from 'lib/dateFormat';
23−import useEthereumTransaction from 'lib/useEthereumTransaction';
24−import { GAS_LIMITS } from 'lib/constants';
25−import { addHexPrefix } from 'lib/wallet';
26−import useKeyfileGenerator from 'lib/useKeyfileGenerator';
28−import ViewHeader from 'components/ViewHeader';
29−import FooterButton from 'components/FooterButton';
30−import DownloadKeyfileButton from 'components/DownloadKeyfileButton';
31−import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
32−import NoticeBox from 'components/NoticeBox';
34−import { HexInput } from 'form/Inputs';
37− buildCheckboxValidator,
39−} from 'form/validators';
40−import BridgeForm from 'form/BridgeForm';
41−import Condition from 'form/Condition';
42−import FormError from 'form/FormError';
43−import convertToInt from 'lib/convertToInt';
45−const chainKeyProp = name => d =>
46− d[name] === CURVE_ZERO_ADDR ? Nothing() : Just(d[name]);
48−const renderNetworkKey = key => {
49− const segments = segmentNetworkKey(key);
55− return segments.join('\n');
58−function useSetKeys() {
59− const { urbitWallet, wallet, authMnemonic } = useWallet();
60− const { pointCursor } = usePointCursor();
61− const { syncDetails, syncRekeyDate, getDetails } = usePointCache();
62− const { contracts } = useNetwork();
64− const _point = need.point(pointCursor);
65− const _contracts = need.contracts(contracts);
66− const _details = need.details(getDetails(_point));
68− const networkRevision = convertToInt(_details.keyRevisionNumber, 10);
69− const randomSeed = useRef();
71− // NOTE: nd = 'nondeterministic' (can also be a 'manual' seed)
72− const [ndNetworkSeed, setNdNetworkSeed] = useState();
75− available: keyfileAvailable,
78− } = useKeyfileGenerator(ndNetworkSeed);
80− const buildNetworkSeed = useCallback(
81− async manualSeed => {
82− if (manualSeed !== undefined) {
83− setNdNetworkSeed(manualSeed);
86− const newNetworkRevision = networkRevision + 1;
87− console.log(`deriving seed with revision ${newNetworkRevision}`);
89− const networkSeed = await attemptNetworkSeedDerivation({
94− revision: newNetworkRevision,
97− if (Just.hasInstance(networkSeed)) {
98− return networkSeed.value;
101− randomSeed.current = randomSeed.current || randomHex(32); // 32 bytes
102− setNdNetworkSeed(randomSeed.current);
104− return randomSeed.current;
107− [_details, authMnemonic, networkRevision, urbitWallet, wallet]
110− const { completed: _completed, ...rest } = useEthereumTransaction(
112− async (manualSeed, isDiscontinuity) => {
113− const seed = await buildNetworkSeed(manualSeed);
114− const pair = deriveNetworkKeys(seed);
116− return azimuth.ecliptic.configureKeys(
119− addHexPrefix(pair.crypt.public),
120− addHexPrefix(pair.auth.public),
121− CRYPTO_SUITE_VERSION,
125− [_contracts, _point, buildNetworkSeed]
128− () => Promise.all([syncDetails(_point), syncRekeyDate(_point)]),
129− [_point, syncDetails, syncRekeyDate]
131− GAS_LIMITS.CONFIGURE_KEYS
134− // only treat the transaction as completed once we also have keys to download
135− const completed = _completed && keyfileAvailable;
146−export default function AdminNetworkingKeys() {
147− const { push, names, pop } = useLocalRouter();
148− const { pointCursor } = usePointCursor();
149− const { getDetails, getRekeyDate } = usePointCache();
151− const point = need.point(pointCursor);
152− const details = getDetails(point);
154− const hasKeys = details.matchWith({
155− Nothing: () => false,
156− Just: ({ value: details }) => parseInt(details.keyRevisionNumber, 10) > 0,
157− // we actually don't mind the default NaN behavior of parseInt here,
158− // since NaN > 0 === false and that's a reasonable result
161− const [usedDiscontinuity, setUsedDiscontinuity] = useState(false);
175− const validateForm = useCallback((values, errors) => {
176− if (values.useNetworkSeed && errors.networkSeed) {
181− const validate = useMemo(
185− useNetworkSeed: buildCheckboxValidator(),
186− networkSeed: buildHexValidator(64), // 64 chars
187− useDiscontinuity: buildCheckboxValidator(),
194− const onValues = useCallback(
195− ({ valid, values, form }) => {
198− values.useNetworkSeed ? values.networkSeed : undefined,
199− values.useDiscontinuity
201− setUsedDiscontinuity(values.useDiscontinuity);
206− if (!values.useNetworkSeed && values.networkSeed) {
207− form.change('networkSeed', '');
210− [construct, unconstruct, setUsedDiscontinuity]
213− const initialValues = useMemo(
215− useNetworkSeed: false,
216− useDiscontinuity: false,
221− const goRelocate = useCallback(() => push(names.RELOCATE), [push, names]);
223− const usageMessage = useMemo(() => {
224− const need = 'You need this keyfile to authenticate with Arvo.';
227− boot fresh with{' '}
229− urbit -w {ob.patp(point).slice(1)} -k {filename}
233− if (usedDiscontinuity) {
236− {need} Since you broke continuity, (re)move your old files, and {boot}
242− {need} If you have already booted Arvo, run{' '}
243− <code>|rekey '0wkeyfile.contents'</code>. Otherwise, {boot}
247− }, [usedDiscontinuity, filename, point]);
249− const renderTitle = () => {
251− return 'Networking keys are now set. Download your Keyfile to authenticate Arvo.';
255− return 'Setting Network Keys...';
259− return 'Networking keys have not yet been set.';
262− return 'Networking';
265− const renderNetworkKeySection = (title, key) => (
267− <Grid.Item full as={H5} className="mt3 gray4">
272− <Grid.Item full as="code" className="f5 mono gray4">
276− Just: ({ value: key }) => (
278− <Grid.Item full as="code" className="f5 mono wrap">
281− <Grid.Item full as="code" className="f5 mono wrap">
282− {renderNetworkKey(key)}
290− const renderDetail = (title, value) => (
291− <Flex.Item as={Flex} col>
292− <Flex.Item as={H5} className="gray4">
297− <Flex.Item as={Text} className="f5 gray4">
301− Just: ({ value }) => <Flex.Item as={Text}>{value}</Flex.Item>,
306− const renderDetails = () => {
309− {renderNetworkKeySection(
311− details.chain(chainKeyProp('authenticationKey'))
313− {renderNetworkKeySection(
315− details.chain(chainKeyProp('encryptionKey'))
317− <Grid.Item full as={Flex} row justify="between" className="mt3">
318− {renderDetail('Revision', details.map(d => d.keyRevisionNumber))}
319− {renderDetail('Continuity Era', details.map(d => d.continuityNumber))}
321− 'Crypto Suite Ver.',
322− details.map(d => d.cryptoSuiteVersion)
326− <Grid.Item full as={Flex} row justify="between" className="mt3">
329− getRekeyDate(point).map(date =>
331− Ok: r => formatDotsWithTime(r.value),
332− Error: () => Nothing(),
345− <Grid.Item full as={ViewHeader}>
349− <Grid.Item full as={Text} className="mb3">
351− ? 'Here are your public keys that authenticate your Arvo.'
352− : 'Set your networking keys to authenticate with Arvo.'}
357− <Grid.Item full as={NoticeBox} className="mb3">
360− <Grid.Item full as={DownloadKeyfileButton} solid {...keyfileBind} />
368− initialValues={initialValues}>
374− name="useNetworkSeed"
375− label="Use Custom Network Seed"
376− inverseLabel="Back to Derived Network Seed"
377− disabled={inputsLocked}
379− <Condition when="useNetworkSeed" is={true}>
380− <Grid.Item full as={NoticeBox} className="mb2">
381− When using a custom network seed, you'll need to download
382− your Arvo keyfile immediately after this transaction is
383− Bridge does not store your seed.
389− label="Network Seed (32 bytes)"
390− disabled={inputsLocked}
396− name="useDiscontinuity"
397− label="Breach Continuity"
398− disabled={inputsLocked}
401− <Grid.Item full as={FormError} />
405− as={InlineEthereumTransaction}
407− label={`${hasKeys ? 'Reset' : 'Set'} Networking Keys`}
408− onReturn={() => pop()}
415− {isDefaultState && renderDetails()}
424− {isDefaultState && (
425− <FooterButton onClick={goRelocate} disabled>