1import { useCallback, useEffect, useState } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import saveAs from 'file-saver';
4import ob from 'urbit-ob';
6import { usePointCache } from 'store/pointCache';
7import { useWallet } from 'store/wallet';
8import { usePointCursor } from 'store/pointCursor';
10import * as need from 'lib/need';
13 attemptNetworkSeedDerivation,
18import useCurrentPermissions from './useCurrentPermissions';
19import convertToInt from './convertToInt';
21export default function useKeyfileGenerator(manualNetworkSeed) {
22 const { urbitWallet, wallet, authMnemonic } = useWallet();
23 const { pointCursor } = usePointCursor();
24 const { getDetails } = usePointCache();
26 const [notice, setNotice] = useState('Deriving networking keys...');
27 const [downloaded, setDownloaded] = useState(false);
28 const [generating, setGenerating] = useState(true);
29 const [keyfile, setKeyfile] = useState(false);
31 const _point = need.point(pointCursor);
32 const _details = need.details(getDetails(_point));
34 const networkRevision = convertToInt(_details.keyRevisionNumber, 10);
35 const { isOwner, isManagementProxy } = useCurrentPermissions();
37 const hasNetworkingKeys = networkRevision > 0;
39 (isOwner || isManagementProxy) && hasNetworkingKeys && !!keyfile;
41 const generate = useCallback(async () => {
42 if (!hasNetworkingKeys) {
44 setNotice('Networking keys not yet set.');
46 `no networking keys available for revision ${networkRevision}`
51 const networkSeed = manualNetworkSeed
52 ? Just(manualNetworkSeed)
53 : await attemptNetworkSeedDerivation({
58 revision: networkRevision,
61 if (Nothing.hasInstance(networkSeed)) {
64 'Custom or nondeterministic networking keys cannot be re-downloaded.'
66 console.log(`seed is nondeterminable for revision ${networkRevision}`);
70 const _networkSeed = networkSeed.value;
72 const pair = deriveNetworkKeys(_networkSeed);
74 if (!keysMatchChain(pair, _details)) {
76 setNotice('Derived networking keys do not match on-chain details.');
77 console.log(`keys do not match details for revision ${networkRevision}`);
82 setKeyfile(compileNetworkingKey(pair, _point, networkRevision));
95 const download = useCallback(() => {
98 type: 'text/plain;charset=utf-8',
100 `${ob.patp(_point).slice(1)}-${networkRevision}.key`
101 // TODO: ^ unifiy "remove tilde" calls
104 }, [_point, keyfile, networkRevision]);
118 return { ...values, bind: values };
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