on master help sign in
Provide context-aware Arvo-side rekey instructions
a4618e2Fang
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';
2import { Just, Nothing } from 'folktale/maybe';
2import { Just, Nothing } from 'folktale/maybe';
3import saveAs from 'file-saver';
3import saveAs from 'file-saver';
4import ob from 'urbit-ob';
4import ob from 'urbit-ob';
@@ -102,16 +102,20 @@ export default function useKeyfileGenerator(manualNetworkSeed) {
102 _point,
102 _point,
103 ]);
103 ]);
104
104
105+ const filename = useMemo(() => {
106+ return `${ob.patp(_point).slice(1)}-${networkRevision}.key`;
107+ // TODO: ^ unifiy "remove tilde" calls
108+ }, [_point, networkRevision]);
109+
105 const download = useCallback(() => {
110 const download = useCallback(() => {
106 saveAs(
111 saveAs(
107 new Blob([keyfile], {
112 new Blob([keyfile], {
108 type: 'text/plain;charset=utf-8',
113 type: 'text/plain;charset=utf-8',
109 }),
114 }),
110− `${ob.patp(_point).slice(1)}-${networkRevision}.key`
115+ filename
111− // TODO: ^ unifiy "remove tilde" calls
112 );
116 );
113 setDownloaded(true);
117 setDownloaded(true);
114− }, [_point, keyfile, networkRevision]);
118+ }, [filename, keyfile]);
115
119
116 useEffect(() => {
120 useEffect(() => {
117 generate();
121 generate();
@@ -122,6 +126,7 @@ export default function useKeyfileGenerator(manualNetworkSeed) {
122 available,
126 available,
123 downloaded,
127 downloaded,
124 download,
128 download,
129+ filename,
125 notice,
130 notice,
126 code,
131 code,
127 };
132 };
src/views/Admin/AdminNetworkingKeys.js+35−3
@@ -2,6 +2,7 @@ import React, { useCallback, useMemo, useRef, useState } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
2import { Just, Nothing } from 'folktale/maybe';
3import { Grid, Text, H5, Flex, ToggleInput, CheckboxInput } from 'indigo-react';
3import { Grid, Text, H5, Flex, ToggleInput, CheckboxInput } from 'indigo-react';
4import * as azimuth from 'azimuth-js';
4import * as azimuth from 'azimuth-js';
5+import ob from 'urbit-ob';
5import { randomHex } from 'web3-utils';
6import { randomHex } from 'web3-utils';
6
7
7import { usePointCursor } from 'store/pointCursor';
8import { usePointCursor } from 'store/pointCursor';
@@ -73,6 +74,7 @@ function useSetKeys() {
73
74
74 const {
75 const {
75 available: keyfileAvailable,
76 available: keyfileAvailable,
77+ filename,
76 bind: keyfileBind,
78 bind: keyfileBind,
77 } = useKeyfileGenerator(ndNetworkSeed);
79 } = useKeyfileGenerator(ndNetworkSeed);
78
80
@@ -136,6 +138,7 @@ function useSetKeys() {
136 return {
138 return {
137 completed,
139 completed,
138 ndNetworkSeed,
140 ndNetworkSeed,
141+ filename,
139 keyfileBind,
142 keyfileBind,
140 ...rest,
143 ...rest,
141 };
144 };
@@ -156,6 +159,8 @@ export default function AdminNetworkingKeys() {
156 // since NaN > 0 === false and that's a reasonable result
159 // since NaN > 0 === false and that's a reasonable result
157 });
160 });
158
161
162+ const [usedDiscontinuity, setUsedDiscontinuity] = useState(false);
163+
159 const {
164 const {
160 isDefaultState,
165 isDefaultState,
161 construct,
166 construct,
@@ -163,6 +168,7 @@ export default function AdminNetworkingKeys() {
163 broadcasting,
168 broadcasting,
164 completed,
169 completed,
165 inputsLocked,
170 inputsLocked,
171+ filename,
166 bind,
172 bind,
167 keyfileBind,
173 keyfileBind,
168 } = useSetKeys();
174 } = useSetKeys();
@@ -193,6 +199,7 @@ export default function AdminNetworkingKeys() {
193 values.useNetworkSeed ? values.networkSeed : undefined,
199 values.useNetworkSeed ? values.networkSeed : undefined,
194 values.useDiscontinuity
200 values.useDiscontinuity
195 );
201 );
202+ setUsedDiscontinuity(values.useDiscontinuity);
196 } else {
203 } else {
197 unconstruct();
204 unconstruct();
198 }
205 }
@@ -201,7 +208,7 @@ export default function AdminNetworkingKeys() {
201 form.change('networkSeed', '');
208 form.change('networkSeed', '');
202 }
209 }
203 },
210 },
204− [construct, unconstruct]
211+ [construct, unconstruct, setUsedDiscontinuity]
205 );
212 );
206
213
207 const initialValues = useMemo(
214 const initialValues = useMemo(
@@ -214,6 +221,32 @@ export default function AdminNetworkingKeys() {
214
221
215 const goRelocate = useCallback(() => push(names.RELOCATE), [push, names]);
222 const goRelocate = useCallback(() => push(names.RELOCATE), [push, names]);
216
223
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+
217 const renderTitle = () => {
250 const renderTitle = () => {
218 if (completed) {
251 if (completed) {
219 return 'Networking keys are now set. Download your Keyfile to authenticate Arvo.';
252 return 'Networking keys are now set. Download your Keyfile to authenticate Arvo.';
@@ -323,8 +356,7 @@ export default function AdminNetworkingKeys() {
323 {completed && (
356 {completed && (
324 <>
357 <>
325 <Grid.Item full as={NoticeBox} className="mb3">
358 <Grid.Item full as={NoticeBox} className="mb3">
326− You need this keyfile to authenticate with Arvo. If you have
359+ {usageMessage}
327− already booted Arvo, run <code>|rekey '0wkeyfile.contents'</code>
328 </Grid.Item>
360 </Grid.Item>
329 <Grid.Item full as={DownloadKeyfileButton} solid {...keyfileBind} />
361 <Grid.Item full as={DownloadKeyfileButton} solid {...keyfileBind} />
330 </>
362 </>