on master help sign in
Provide context-aware Arvo-side rekey instructions

Closes #315.

commita4618e242457efee588ed8427410bcec662e9a57 authorFang <git@fang.io> dateWed 18 Dec 2019, 23:48 (7 years ago) parent926a6d9
2 files changed+44−7
src/lib/useKeyfileGenerator.js+9−4 src/views/Admin/AdminNetworkingKeys.js+35−3
src/lib/useKeyfileGenerator.js+9−4
@@ -1,4 +1,4 @@
1−import { useCallback, useEffect, useState } from 'react';
1+import { useCallback, useMemo, useEffect, useState } from 'react';
22import { Just, Nothing } from 'folktale/maybe';
33import saveAs from 'file-saver';
44import ob from 'urbit-ob';
@@ -102,16 +102,20 @@ export default function useKeyfileGenerator(manualNetworkSeed) {
102102 _point,
103103 ]);
104104
105+ const filename = useMemo(() => {
106+ return `${ob.patp(_point).slice(1)}-${networkRevision}.key`;
107+ // TODO: ^ unifiy "remove tilde" calls
108+ }, [_point, networkRevision]);
109+
105110 const download = useCallback(() => {
106111 saveAs(
107112 new Blob([keyfile], {
108113 type: 'text/plain;charset=utf-8',
109114 }),
110− `${ob.patp(_point).slice(1)}-${networkRevision}.key`
111− // TODO: ^ unifiy "remove tilde" calls
115+ filename
112116 );
113117 setDownloaded(true);
114− }, [_point, keyfile, networkRevision]);
118+ }, [filename, keyfile]);
115119
116120 useEffect(() => {
117121 generate();
@@ -122,6 +126,7 @@ export default function useKeyfileGenerator(manualNetworkSeed) {
122126 available,
123127 downloaded,
124128 download,
129+ filename,
125130 notice,
126131 code,
127132 };
src/views/Admin/AdminNetworkingKeys.js+35−3
@@ -2,6 +2,7 @@ import React, { useCallback, useMemo, useRef, useState } from 'react';
22import { Just, Nothing } from 'folktale/maybe';
33import { Grid, Text, H5, Flex, ToggleInput, CheckboxInput } from 'indigo-react';
44import * as azimuth from 'azimuth-js';
5+import ob from 'urbit-ob';
56import { randomHex } from 'web3-utils';
67
78import { usePointCursor } from 'store/pointCursor';
@@ -73,6 +74,7 @@ function useSetKeys() {
7374
7475 const {
7576 available: keyfileAvailable,
77+ filename,
7678 bind: keyfileBind,
7779 } = useKeyfileGenerator(ndNetworkSeed);
7880
@@ -136,6 +138,7 @@ function useSetKeys() {
136138 return {
137139 completed,
138140 ndNetworkSeed,
141+ filename,
139142 keyfileBind,
140143 ...rest,
141144 };
@@ -156,6 +159,8 @@ export default function AdminNetworkingKeys() {
156159 // since NaN > 0 === false and that's a reasonable result
157160 });
158161
162+ const [usedDiscontinuity, setUsedDiscontinuity] = useState(false);
163+
159164 const {
160165 isDefaultState,
161166 construct,
@@ -163,6 +168,7 @@ export default function AdminNetworkingKeys() {
163168 broadcasting,
164169 completed,
165170 inputsLocked,
171+ filename,
166172 bind,
167173 keyfileBind,
168174 } = useSetKeys();
@@ -193,6 +199,7 @@ export default function AdminNetworkingKeys() {
193199 values.useNetworkSeed ? values.networkSeed : undefined,
194200 values.useDiscontinuity
195201 );
202+ setUsedDiscontinuity(values.useDiscontinuity);
196203 } else {
197204 unconstruct();
198205 }
@@ -201,7 +208,7 @@ export default function AdminNetworkingKeys() {
201208 form.change('networkSeed', '');
202209 }
203210 },
204− [construct, unconstruct]
211+ [construct, unconstruct, setUsedDiscontinuity]
205212 );
206213
207214 const initialValues = useMemo(
@@ -214,6 +221,32 @@ export default function AdminNetworkingKeys() {
214221
215222 const goRelocate = useCallback(() => push(names.RELOCATE), [push, names]);
216223
224+ const usageMessage = useMemo(() => {
225+ const need = 'You need this keyfile to authenticate with Arvo.';
226+ const boot = (
227+ <>
228+ boot fresh with{' '}
229+ <code>
230+ urbit -w {ob.patp(point).slice(1)} -k {filename}
231+ </code>
232+ </>
233+ );
234+ if (usedDiscontinuity) {
235+ return (
236+ <>
237+ {need} Since you broke continuity, (re)move your old files, and {boot}
238+ </>
239+ );
240+ } else {
241+ return (
242+ <>
243+ {need} If you have already booted Arvo, run{' '}
244+ <code>|rekey '0wkeyfile.contents'</code>. Otherwise, {boot}
245+ </>
246+ );
247+ }
248+ }, [usedDiscontinuity, filename, point]);
249+
217250 const renderTitle = () => {
218251 if (completed) {
219252 return 'Networking keys are now set. Download your Keyfile to authenticate Arvo.';
@@ -323,8 +356,7 @@ export default function AdminNetworkingKeys() {
323356 {completed && (
324357 <>
325358 <Grid.Item full as={NoticeBox} className="mb3">
326− You need this keyfile to authenticate with Arvo. If you have
327− already booted Arvo, run <code>|rekey '0wkeyfile.contents'</code>
359+ {usageMessage}
328360 </Grid.Item>
329361 <Grid.Item full as={DownloadKeyfileButton} solid {...keyfileBind} />
330362 </>