@@ -1,214 +0,0 @@
1−import * as need from 'lib/need';
2−import saveAs from 'file-saver';
3−import ob from 'urbit-ob';
4−import { Just, Nothing } from 'folktale/maybe';
6−import { useCallback, useEffect, useMemo, useState } from 'react';
7−import { usePointCache } from 'store/pointCache';
8−import { usePointCursor } from 'store/pointCursor';
9−import { useWallet } from 'store/wallet';
10−import { deriveNetworkKeys } from 'urbit-key-generation';
11−import { convertToInt } from './convertToInt';
13− attemptNetworkSeedDerivation,
17−import { generateCode } from './networkCode';
18−import { L1Point } from './types/L1Point';
19−import useCurrentPermissions from './useCurrentPermissions';
20−import { stripSigPrefix } from 'form/formatters';
21−import { useRollerStore } from 'store/rollerStore';
23−interface useMultikeyFileGeneratorArgs {
27− inviteMasterTicketWallet?: any;
32− * - seed: derived from wallet, mnemonic, or token (if posisble)
33− * - point: the current pointCursor
35−export default function useMultikeyFileGenerator({
39− inviteMasterTicketWallet,
40−}: useMultikeyFileGeneratorArgs) {
41− const { urbitWallet, wallet, authMnemonic, authToken }: any = useWallet();
42− const { pointCursor }: any = usePointCursor();
43− const { syncDetails, getDetails }: any = usePointCache();
44− const { isOwner, isManagementProxy } = useCurrentPermissions();
45− const rollerStore = useRollerStore();
47− const [notice, setNotice] = useState('Deriving networking keys...');
48− const [downloaded, setDownloaded] = useState(false);
49− const [generating, setGenerating] = useState(true);
50− const [keyfile, setKeyfile] = useState<boolean | string>(false);
51− const [code, setCode] = useState(false);
53− const _point = useMemo(() => point || need.point(pointCursor), [
57− const details = getDetails(_point);
58− const _details: L1Point | null = useMemo(
60− rollerStore?.point?.isL2
62− : details.matchWith({
63− Just: (d: any) => need.details(d),
66− [details, rollerStore.point]
69− const currentRevision: number = useMemo(
70− () => convertToInt(_details?.keyRevisionNumber || 0, 10),
73− const nextRevision = useMemo(() => currentRevision + 1, [currentRevision]);
75− const pairFromRevision = useCallback(
76− async (revision: number, useInviteMasterTicketWallet = false) => {
81− // During the activation flow, we pass in the
82− // inviteMasterTicketWallet to derive the multikey
83− const derivationWallet =
84− useInviteMasterTicketWallet && inviteMasterTicketWallet
85− ? inviteMasterTicketWallet
86− : seedWallet || urbitWallet;
88− const networkSeed = seed
90− : await attemptNetworkSeedDerivation({
91− urbitWallet: derivationWallet,
100− if (Nothing.hasInstance(networkSeed)) {
101− setGenerating(false);
103− 'Custom or nondeterministic networking keys cannot be re-downloaded.'
105− console.log(`seed is nondeterminable for revision ${revision}`);
109− const _networkSeed = networkSeed.value;
111− return deriveNetworkKeys(_networkSeed);
115− inviteMasterTicketWallet,
126− const hasNetworkKeys = currentRevision > 0;
128− (isOwner || isManagementProxy) && hasNetworkKeys && !!keyfile;
130− const generate = useCallback(async () => {
131− if (!hasNetworkKeys) {
132− setGenerating(false);
133− setNotice('Network keys not yet set.');
135− `no networking keys available for revision ${currentRevision}`
140− const currentPair = await pairFromRevision(currentRevision);
142− if (!currentPair || !keysMatchChain(currentPair, _details || {})) {
143− setGenerating(false);
144− setNotice('Derived networking keys do not match on-chain details.');
145− console.log(`keys do not match details for revision ${currentRevision}`);
149− // During the activation flow, we want to use the invite wallet for the next pair
150− const nextPair = await pairFromRevision(nextRevision, true);
153− setCode(generateCode(currentPair));
155− compileMultiKey(_point, [
157− revision: currentRevision,
161− revision: nextRevision,
166− setGenerating(false);
176− const filename = useMemo(() => {
177− return `${stripSigPrefix(ob.patp(_point))}-${currentRevision}.key`;
178− }, [_point, currentRevision]);
180− const download = useCallback(() => {
181− if (typeof keyfile !== 'string') {
186− new Blob([keyfile], {
187− type: 'text/plain;charset=utf-8',
191− setDownloaded(true);
192− }, [filename, keyfile]);
195− syncDetails(_point);
196− }, [_point, syncDetails]);
213− return { ...output, bind: output };