@@ -18,20 +18,35 @@ import {
18} from './keys';
18} from './keys';
19import useCurrentPermissions from './useCurrentPermissions';
19import useCurrentPermissions from './useCurrentPermissions';
20import { convertToInt } from './convertToInt';
20import { convertToInt } from './convertToInt';
21+import { stripSigPrefix } from 'form/formatters';
23+// overrideable defaults:
24+// seed - derived from wallet, mnemonic, or token (if posisble)
25+// point - the current pointCursor
26+interface useKeyfileGeneratorArgs {
22−export default function useKeyfileGenerator(manualNetworkSeed) {
31+export default function useKeyfileGenerator({
34+}: useKeyfileGeneratorArgs) {
23− const { urbitWallet, wallet, authMnemonic, authToken } = useWallet();
35+ const { urbitWallet, wallet, authMnemonic, authToken }: any = useWallet();
24− const { pointCursor } = usePointCursor();
36+ const { pointCursor }: any = usePointCursor();
25− const { getDetails } = usePointCache();
37+ const { syncDetails, getDetails }: any = usePointCache();
27 const [notice, setNotice] = useState('Deriving networking keys...');
39 const [notice, setNotice] = useState('Deriving networking keys...');
28 const [downloaded, setDownloaded] = useState(false);
40 const [downloaded, setDownloaded] = useState(false);
29 const [generating, setGenerating] = useState(true);
41 const [generating, setGenerating] = useState(true);
30− const [keyfile, setKeyfile] = useState(false);
42+ const [keyfile, setKeyfile] = useState<boolean | string>(false);
32 const [code, setCode] = useState(false);
43 const [code, setCode] = useState(false);
34− const _point = need.point(pointCursor);
45+ const _point = point || need.point(pointCursor);
48+ }, [_point, syncDetails]);
35 const details = getDetails(_point);
50 const details = getDetails(_point);
37 const networkRevision = details.matchWith({
52 const networkRevision = details.matchWith({
@@ -56,8 +71,8 @@ export default function useKeyfileGenerator(manualNetworkSeed) {
57 const _details = need.details(details);
72 const _details = need.details(details);
59− const networkSeed = manualNetworkSeed
74+ const networkSeed = seed
60− ? Just(manualNetworkSeed)
75+ ? Just(seed)
61 : await attemptNetworkSeedDerivation({
76 : await attemptNetworkSeedDerivation({
62 urbitWallet,
77 urbitWallet,
@@ -88,14 +103,14 @@ export default function useKeyfileGenerator(manualNetworkSeed) {
91− setNotice();
106+ setNotice('');
92 setCode(generateCode(pair));
107 setCode(generateCode(pair));
93 setKeyfile(compileNetworkKey(pair, _point, networkRevision));
108 setKeyfile(compileNetworkKey(pair, _point, networkRevision));
94 setGenerating(false);
109 setGenerating(false);
96 networkRevision,
111 networkRevision,
97 hasNetworkKeys,
112 hasNetworkKeys,
98− manualNetworkSeed,
113+ seed,
99 urbitWallet,
114 urbitWallet,
101 authMnemonic,
116 authMnemonic,
@@ -106,11 +121,14 @@ export default function useKeyfileGenerator(manualNetworkSeed) {
108 const filename = useMemo(() => {
123 const filename = useMemo(() => {
109− return `${ob.patp(_point).slice(1)}-${networkRevision}.key`;
124+ return `${stripSigPrefix(ob.patp(_point))}-${networkRevision}.key`;
110− // TODO: ^ unifiy "remove tilde" calls
111 }, [_point, networkRevision]);
125 }, [_point, networkRevision]);
113 const download = useCallback(() => {
127 const download = useCallback(() => {
128+ if (typeof keyfile !== 'string') {
115 new Blob([keyfile], {
133 new Blob([keyfile], {
116 type: 'text/plain;charset=utf-8',
134 type: 'text/plain;charset=utf-8',