8import { Just } from 'folktale/maybe';
9import { Grid, ToggleInput, CheckboxInput, Button } from 'indigo-react';
10import * as azimuth from 'azimuth-js';
11import { randomHex } from 'web3-utils';
13import { usePointCursor } from 'store/pointCursor';
14import { usePointCache } from 'store/pointCache';
15import { useNetwork } from 'store/network';
16import { useWallet } from 'store/wallet';
17import { useRollerStore } from 'store/rollerStore';
19import useRoller from 'lib/useRoller';
20import { useLocalRouter } from 'lib/LocalRouter';
21import * as need from 'lib/need';
23 attemptNetworkSeedDerivation,
27import useEthereumTransaction from 'lib/useEthereumTransaction';
28import { GAS_LIMITS } from 'lib/constants';
29import { addHexPrefix } from 'lib/utils/address';
30import useKeyfileGenerator from 'lib/useKeyfileGenerator';
32import DownloadKeyfileButton from 'components/DownloadKeyfileButton';
33import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
34import NoticeBox from 'components/NoticeBox';
35import AlertBox from 'components/AlertBox';
37import { HexInput } from 'form/Inputs';
40 buildCheckboxValidator,
42} from 'form/validators';
43import BridgeForm from 'form/BridgeForm';
44import Condition from 'form/Condition';
45import FormError from 'form/FormError';
46import { convertToInt } from 'lib/convertToInt';
47import Window from 'components/L2/Window/Window';
48import HeaderPane from 'components/L2/Window/HeaderPane';
49import BodyPane from 'components/L2/Window/BodyPane';
50import { Box, Row } from '@tlon/indigo-react';
52function useSetKeys(manualNetworkSeed, setManualNetworkSeed) {
53 const { urbitWallet, wallet, authMnemonic, authToken } = useWallet();
54 const { pointCursor } = usePointCursor();
55 const { syncDetails, syncRekeyDate, getDetails } = usePointCache();
56 const { contracts } = useNetwork();
58 const _point = need.point(pointCursor);
59 const _contracts = need.contracts(contracts);
60 const _details = need.details(getDetails(_point));
62 const networkRevision = convertToInt(_details.keyRevisionNumber, 10);
63 const randomSeed = useRef();
66 available: keyfileAvailable,
67 generating: keyfileGenerating,
70 } = useKeyfileGenerator(manualNetworkSeed);
72 const buildNetworkSeed = useCallback(
74 if (manualSeed !== undefined) {
75 setManualNetworkSeed(manualSeed);
78 const newNetworkRevision = networkRevision + 1;
79 console.log(`deriving seed with revision ${newNetworkRevision}`);
81 const networkSeed = await attemptNetworkSeedDerivation({
88 revision: newNetworkRevision,
91 if (Just.hasInstance(networkSeed)) {
92 return networkSeed.value;
95 randomSeed.current = randomSeed.current || randomHex(32); // 32 bytes
96 setManualNetworkSeed(randomSeed.current);
98 return randomSeed.current;
104 setManualNetworkSeed,
113 const { completed: _completed, ...rest } = useEthereumTransaction(
115 async (manualSeed, isDiscontinuity) => {
116 const seed = await buildNetworkSeed(manualSeed);
117 const pair = deriveNetworkKeys(seed);
119 return azimuth.ecliptic.configureKeys(
122 addHexPrefix(pair.crypt.public),
123 addHexPrefix(pair.auth.public),
124 CRYPTO_SUITE_VERSION,
128 [_contracts, _point, buildNetworkSeed]
131 () => Promise.all([syncDetails(_point), syncRekeyDate(_point)]),
132 [_point, syncDetails, syncRekeyDate]
134 GAS_LIMITS.CONFIGURE_KEYS
137 // only treat the transaction as completed once we also have keys to download
138 const completed = _completed && keyfileAvailable && !keyfileGenerating;
148export default function UrbitOSNetworkingKeys({
150 setManualNetworkSeed,
152 const { pop } = useLocalRouter();
153 const { point, setLoading } = useRollerStore();
155 configureNetworkingKeys,
156 getPendingTransactions,
159 const [breach, setBreach] = useState(false);
161 const hasKeys = point.networkKeysSet;
170 } = useSetKeys(manualNetworkSeed, setManualNetworkSeed);
176 `${point.patp}'s Networking Keys have been set!`
179 }, [completed]); // eslint-disable-line react-hooks/exhaustive-deps
181 const validateForm = useCallback((values, errors) => {
182 if (values.useNetworkSeed && errors.networkSeed) {
187 const validate = useMemo(
191 useNetworkSeed: buildCheckboxValidator(),
192 networkSeed: buildHexValidator(64), // 64 chars
193 useDiscontinuity: buildCheckboxValidator(),
200 const onValues = useCallback(
201 ({ valid, values, form }) => {
204 values.useNetworkSeed ? values.networkSeed : undefined,
205 values.useDiscontinuity
207 setBreach(values.useDiscontinuity);
208 setManualNetworkSeed(values.useNetworkSeed);
213 if (!values.useNetworkSeed && values.networkSeed) {
214 form.change('networkSeed', '');
216 setManualNetworkSeed('');
219 [construct, unconstruct, setManualNetworkSeed, setBreach]
222 const setNetworkingKeys = useCallback(async () => {
225 await configureNetworkingKeys({
229 // TODO: just use the tx hash instead?
230 getPendingTransactions(point);
231 // TODO: this is just so we get visual feedback that the tx has gone through
232 // but this should be addressed with the new UI flow (-> download keyfile)
234 // A question here is how to deal with the modals/messages about the keys not being
235 // set since they are in pending in the Roller...
236 // we could inspect if there's a changeKeys in the local list of pending txs,...
240 `${point.patp}'s Networking Keys have been set!`
251 getPendingTransactions,
254 configureNetworkingKeys,
259 const initialValues = useMemo(
261 useNetworkSeed: false,
262 useDiscontinuity: false,
267 const viewTitle = completed
268 ? 'Network Keys are now set'
269 : 'Set Networking Keys';
272 'You need this keyfile to authenticate with your OS. Please Download.';
277 <Row className="header-row">
283 <Grid.Item className="gray4 f5 mv2 align-self-start" full>
284 Network Keys authenticate Urbit ID with Urbit OS.
292 as={DownloadKeyfileButton}
297 <Grid.Item full as={AlertBox} className="mb8">
305 initialValues={initialValues}>
313 name="useNetworkSeed"
314 label="Use Custom Network Seed"
315 inverseLabel="Back to Derived Network Seed"
316 disabled={inputsLocked}
318 <Condition when="useNetworkSeed" is={true}>
319 <Grid.Item full as={NoticeBox} className="mb2">
320 When using a custom network seed, you'll need to download
321 your Arvo keyfile immediately after this transaction as
322 Bridge does not store your seed.
328 label="Network Seed (32 bytes)"
329 disabled={inputsLocked}
336 name="useDiscontinuity"
337 label="Breach Continuity"
338 disabled={inputsLocked}
342 <Grid.Item full as={FormError} />
353 onClick={setNetworkingKeys}>
354 {'Reset Networking Keys'}
359 as={InlineEthereumTransaction}
361 label={`${hasKeys ? 'Reset' : 'Set'} Networking Keys`}
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