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';
9import * as need from 'lib/need';
12 attemptNetworkSeedDerivation,
17import usePermissionsForPoint from './usePermissionsForPoint';
19export default function useKeyfileGenerator(point, manualNetworkSeed) {
20 const { getDetails } = usePointCache();
21 const { urbitWallet, wallet, authMnemonic } = useWallet();
23 const [downloaded, setDownloaded] = useState(false);
24 const [generating, setGenerating] = useState(true);
25 const [keyfile, setKeyfile] = useState(false);
27 const _address = need.wallet(wallet).address;
28 const _details = need.details(getDetails(point));
30 const networkRevision = parseInt(_details.keyRevisionNumber, 10);
31 const { isOwner, isManagementProxy } = usePermissionsForPoint(
36 const hasNetworkingKeys = networkRevision > 0;
38 (isOwner || isManagementProxy) && hasNetworkingKeys && keyfile;
40 const generate = useCallback(async () => {
41 console.log('generating for network revision', networkRevision);
43 const networkSeed = manualNetworkSeed
44 ? Just(manualNetworkSeed)
45 : await attemptNetworkSeedDerivation({
50 revision: networkRevision,
53 if (Nothing.hasInstance(networkSeed)) {
55 console.log('nondeterministic seed!');
56 // TODO: tell user their seed is nondeterministic
60 const _networkSeed = networkSeed.value;
62 const pair = deriveNetworkKeys(_networkSeed);
64 if (!keysMatchChain(pair, _details)) {
66 console.log('Derived networking keys do not match public keys on chain.');
67 // TODO: tell usrs their seed is nondeterministic
70 setKeyfile(compileNetworkingKey(pair, point, networkRevision));
82 const download = useCallback(() => {
85 type: 'text/plain;charset=utf-8',
87 `${ob.patp(point).slice(1)}-${networkRevision}.key`
88 // TODO: ^ unifiy "remove tilde" calls
91 }, [keyfile, point, networkRevision]);
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