1import { useCallback, useState } from 'react';
2import saveAs from 'file-saver';
3import * as ob from 'urbit-ob';
5import { usePointCache } from 'store/pointCache';
6import { useWallet } from 'store/wallet';
8import * as need from 'lib/need';
11 attemptNetworkSeedDerivation,
16import usePermissionsForPoint from './usePermissionsForPoint';
18export default function useKeyfileGenerator(point) {
19 const { getDetails } = usePointCache();
20 const { urbitWallet, wallet, authMnemonic } = useWallet();
22 const [downloaded, setDownloaded] = useState(false);
23 const [generating, setGenerating] = useState(false);
24 const [keyfile, setKeyfile] = useState();
26 const details = need.details(getDetails(point));
27 const networkRevision = parseInt(details.keyRevisionNumber, 10);
29 const { isOwner, isManagementProxy } = usePermissionsForPoint(point);
30 const hasNetworkingKeys = networkRevision > 0;
31 const available = (isOwner || isManagementProxy) && hasNetworkingKeys;
33 const generate = useCallback(async () => {
36 const networkSeed = await attemptNetworkSeedDerivation({
41 revision: networkRevision,
44 const _networkSeed = need.value(networkSeed, () => {
46 throw new Error('Could not derive networking seed.');
49 const pair = deriveNetworkKeys(_networkSeed);
51 if (!keysMatchChain(pair, details)) {
54 'Derived networking keys do not match public keys on chain.'
58 setKeyfile(compileNetworkingKey(pair, point, networkRevision));
71 const download = useCallback(() => {
74 type: 'text/plain;charset=utf-8',
76 `${ob.patp(point).slice(1)}-${networkRevision}.key`
77 // TODO: ^ unifiy "remove tilde" calls
80 }, [point, keyfile, networkRevision, setDownloaded]);
82 const generateAndDownload = useCallback(async () => {
85 }, [generate, download]);
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