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, getOptimisticDetails } = usePointCache();
20 const { urbitWallet, wallet, authMnemonic } = useWallet();
22 const [generating, setGenerating] = useState(false);
23 const [keyfile, setKeyfile] = useState();
25 const details = need.details(getDetails(point));
26 const optimisticDetails = getOptimisticDetails(point);
28 // use the optimistic key revision number if available
29 // (because we may have set networking keys earlier)
30 const networkRevision = optimisticDetails.keyRevisionNumber.matchWith({
31 Nothing: () => parseInt(details.keyRevisionNumber, 10),
35 const { isOwner, isManagementProxy } = usePermissionsForPoint(point);
36 const hasNetworkingKeys = networkRevision > 0;
37 const available = (isOwner || isManagementProxy) && hasNetworkingKeys;
39 const generate = useCallback(async () => {
42 const networkSeed = await attemptNetworkSeedDerivation({
47 revision: networkRevision,
50 const _networkSeed = need.value(networkSeed, () => {
52 throw new Error('Could not derive networking seed.');
55 const pair = deriveNetworkKeys(_networkSeed);
57 if (!keysMatchChain(pair, details)) {
60 'Derived networking keys do not match public keys on chain.'
64 setKeyfile(compileNetworkingKey(pair, point, networkRevision));
77 const download = useCallback(() => {
80 type: 'text/plain;charset=utf-8',
82 `${ob.patp(point).slice(1)}-${networkRevision}.key`
83 // TODO: ^ unifiy "remove tilde" calls
85 }, [point, keyfile, networkRevision]);
87 const generateAndDownload = useCallback(async () => {
90 }, [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