1import { useCallback, useEffect, useState } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import saveAs from 'file-saver';
4import * as 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';
20export default function useKeyfileGenerator(manualNetworkSeed) {
21 const { getDetails } = usePointCache();
22 const { urbitWallet, wallet, authMnemonic } = useWallet();
23 const { pointCursor } = usePointCursor();
25 const [downloaded, setDownloaded] = useState(false);
26 const [generating, setGenerating] = useState(true);
27 const [keyfile, setKeyfile] = useState(false);
29 const _point = need.point(pointCursor);
30 const _details = need.details(getDetails(_point));
32 const networkRevision = parseInt(_details.keyRevisionNumber, 10);
33 const { isOwner, isManagementProxy } = useCurrentPermissions();
35 const hasNetworkingKeys = networkRevision > 0;
37 (isOwner || isManagementProxy) && hasNetworkingKeys && !!keyfile;
40 `keyfile available (${available}) for revision ${networkRevision}`
43 const generate = useCallback(async () => {
44 console.log('generating for network revision', networkRevision);
46 const networkSeed = manualNetworkSeed
47 ? Just(manualNetworkSeed)
48 : await attemptNetworkSeedDerivation({
53 revision: networkRevision,
56 if (Nothing.hasInstance(networkSeed)) {
58 console.log('manual network seed not provided and key not derivable');
62 const _networkSeed = networkSeed.value;
64 const pair = deriveNetworkKeys(_networkSeed);
66 if (!keysMatchChain(pair, _details)) {
68 console.log('derived network keys do not match on-chain details');
72 setKeyfile(compileNetworkingKey(pair, _point, networkRevision));
84 const download = useCallback(() => {
87 type: 'text/plain;charset=utf-8',
89 `${ob.patp(_point).slice(1)}-${networkRevision}.key`
90 // TODO: ^ unifiy "remove tilde" calls
93 }, [_point, keyfile, networkRevision]);
106 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