on master help sign in
wip set networking keys
dd13e79yosoyubik
src/lib/useRoller.ts+46−29
@@ -413,14 +413,47 @@ export default function useRoller() {
413 ]
413 ]
414 );
414 );
415
415
416− // TODO: extract from #transferPoint
417− // interface ConfigureKeysParams {
416+ interface ConfigureKeysParams {
417+ breach: boolean;
418+ customNetworkSeed?: string;
419+ }
418
420
421+ const configureNetworkingKeys = async ({
422+ breach,
423+ customNetworkSeed,
424+ }: ConfigureKeysParams) => {
425+ const _point = need.point(pointCursor);
426+ const _wallet = wallet.getOrElse(null);
427+ console.log(_point, _wallet);
428+ if (!_wallet) {
429+ // not using need because we want a custom error
430+ throw new Error('Internal Error: Missing Wallet');
419− // }
431+ }
420
432
421− // const configureKeys = async () => {
433+ const pointDetails = nonces[_point];
434+ const operator =
435+ getManagementNonce(pointDetails, _wallet.address) ||
436+ getOwnerNonce(pointDetails, _wallet.address);
422
437
438+ if (operator === undefined)
439+ throw new Error("Error: Address doesn't match proxy");
440+ const networkRevision = convertToInt(pointDetails.network.keys.life, 10);
441+ const nextRevision = networkRevision + 1;
442+ console.log('nextRevision', nextRevision);
443+ const txHash = await configureKeys(
444+ api,
445+ _wallet,
446+ _point,
447+ operator.proxy!,
448+ operator.nonce!,
449+ _wallet,
450+ nextRevision,
451+ customNetworkSeed
452+ );
453+ const pendingTx = await api.getPendingTx(txHash);
454+
455+ return pendingTx;
423− // }
456+ };
424
457
425 interface AcceptInviteParams {
458 interface AcceptInviteParams {
426 point: Ship;
459 point: Ship;
@@ -454,34 +487,17 @@ export default function useRoller() {
454 // TODO: extract this to a useRoller#configureKeys function?
487 // TODO: extract this to a useRoller#configureKeys function?
455 const networkRevision = convertToInt(azimuthPoint.network.keys.life, 10);
488 const networkRevision = convertToInt(azimuthPoint.network.keys.life, 10);
456 const nextRevision = networkRevision + 1;
489 const nextRevision = networkRevision + 1;
457− const fromOwnerProxy: From = {
458− ship: point,
459− proxy: 'own',
460− };
461
490
462− const seed = await deriveNetworkSeedFromUrbitWallet(toWallet, nextRevision);
491+ const configureKeysRequest = await configureKeys(
463− const keys = deriveNetworkKeys(seed.value);
492+ api,
464− const keysData = {
493+ fromWallet,
465− auth: ensureHexPrefix(keys.auth.public),
494+ point,
466− breach: false,
495+ operator.proxy!,
467− cryptoSuite: CRYPTO_SUITE_VERSION.toString(),
468− encrypt: ensureHexPrefix(keys.crypt.public),
469− };
470−
471− const keysHash: Hash = await api.hashTransaction(
472 nonce,
496 nonce,
473− fromOwnerProxy,
497+ toWallet,
474− 'configureKeys',
498+ nextRevision
475− keysData
476 );
499 );
477
500
478− const keysSigningKey = fromWallet.privateKey;
479− const configureKeysRequest = await api.configureKeys(
480− signTransactionHash(keysHash, Buffer.from(keysSigningKey, 'hex')),
481− fromOwnerProxy,
482− ownerAddress,
483− keysData
484− );
485 // TODO: not needed? next time we operate with this point we will login, and get
501 // TODO: not needed? next time we operate with this point we will login, and get
486 // the latest nonce (updated with any nonce increase from possible pending txs)
502 // the latest nonce (updated with any nonce increase from possible pending txs)
487 // increaseNonce(point, operator.proxy!);
503 // increaseNonce(point, operator.proxy!);
@@ -619,5 +635,6 @@ export default function useRoller() {
619 generateInviteCodes,
635 generateInviteCodes,
620 transferPoint,
636 transferPoint,
621 setProxyAddress,
637 setProxyAddress,
638+ configureNetworkingKeys,
622 };
639 };
623}
640}
src/lib/utils/roller.ts+8−3
@@ -75,17 +75,22 @@ export const spawn = async (
75export const configureKeys = async (
75export const configureKeys = async (
76 api: any,
76 api: any,
77 _wallet: any,
77 _wallet: any,
78− _point: number,
78+ _point: Ship,
79 proxy: string,
79 proxy: string,
80 nonce: number,
80 nonce: number,
81− urbitWallet: any
81+ urbitWallet: any,
82+ nextRevision?: number,
83+ customNetworkSeed?: string
82) => {
84) => {
83 const from = {
85 const from = {
84 ship: _point, //ship to configure keys
86 ship: _point, //ship to configure keys
85 proxy,
87 proxy,
86 };
88 };
87
89
90+ const networkSeed =
91+ customNetworkSeed ||
88− const networkSeed = await deriveNetworkSeedFromUrbitWallet(urbitWallet, 1);
92+ (await deriveNetworkSeedFromUrbitWallet(urbitWallet, nextRevision || 1));
93+
89 // TODO: do something here?
94 // TODO: do something here?
90 if (Nothing.hasInstance(networkSeed)) {
95 if (Nothing.hasInstance(networkSeed)) {
91 console.log("Network key Error: couldn't derive network keys");
96 console.log("Network key Error: couldn't derive network keys");
src/views/UrbitOS/NetworkingKeys.js+57−11
@@ -1,6 +1,6 @@
1−import React, { useCallback, useMemo, useRef } from 'react';
1+import React, { useCallback, useMemo, useRef, useState } from 'react';
2import { Just } from 'folktale/maybe';
2import { Just } from 'folktale/maybe';
3−import { Grid, ToggleInput, CheckboxInput } from 'indigo-react';
3+import { Grid, ToggleInput, CheckboxInput, Button } from 'indigo-react';
4import * as azimuth from 'azimuth-js';
4import * as azimuth from 'azimuth-js';
5import { randomHex } from 'web3-utils';
5import { randomHex } from 'web3-utils';
6
6
@@ -8,7 +8,9 @@ import { usePointCursor } from 'store/pointCursor';
8import { usePointCache } from 'store/pointCache';
8import { usePointCache } from 'store/pointCache';
9import { useNetwork } from 'store/network';
9import { useNetwork } from 'store/network';
10import { useWallet } from 'store/wallet';
10import { useWallet } from 'store/wallet';
11+import { useRollerStore } from 'store/roller';
11
12
13+import useRoller from 'lib/useRoller';
12import { useLocalRouter } from 'lib/LocalRouter';
14import { useLocalRouter } from 'lib/LocalRouter';
13import * as need from 'lib/need';
15import * as need from 'lib/need';
14import {
16import {
@@ -50,7 +52,7 @@ function useSetKeys(manualNetworkSeed, setManualNetworkSeed) {
50
52
51 const networkRevision = convertToInt(_details.keyRevisionNumber, 10);
53 const networkRevision = convertToInt(_details.keyRevisionNumber, 10);
52 const randomSeed = useRef();
54 const randomSeed = useRef();
53−
55+ console.log(manualNetworkSeed);
54 const {
56 const {
55 available: keyfileAvailable,
57 available: keyfileAvailable,
56 generating: keyfileGenerating,
58 generating: keyfileGenerating,
@@ -141,6 +143,9 @@ export default function UrbitOSNetworkingKeys({
141 const { pop } = useLocalRouter();
143 const { pop } = useLocalRouter();
142 const { pointCursor } = usePointCursor();
144 const { pointCursor } = usePointCursor();
143 const { getDetails } = usePointCache();
145 const { getDetails } = usePointCache();
146+ const { currentL2 } = useRollerStore();
147+ const { configureNetworkingKeys, getPendingTransactions } = useRoller();
148+ const [breach, setBreach] = useState(false);
144
149
145 const point = need.point(pointCursor);
150 const point = need.point(pointCursor);
146 const details = getDetails(point);
151 const details = getDetails(point);
@@ -187,17 +192,46 @@ export default function UrbitOSNetworkingKeys({
187 values.useNetworkSeed ? values.networkSeed : undefined,
192 values.useNetworkSeed ? values.networkSeed : undefined,
188 values.useDiscontinuity
193 values.useDiscontinuity
189 );
194 );
195+ setBreach(values.useDiscontinuity);
196+ setManualNetworkSeed(values.useNetworkSeed);
190 } else {
197 } else {
191 unconstruct();
198 unconstruct();
192 }
199 }
193
200
194 if (!values.useNetworkSeed && values.networkSeed) {
201 if (!values.useNetworkSeed && values.networkSeed) {
195 form.change('networkSeed', '');
202 form.change('networkSeed', '');
203+ setBreach(false);
204+ setManualNetworkSeed('');
196 }
205 }
197 },
206 },
198− [construct, unconstruct]
207+ [construct, unconstruct, setManualNetworkSeed, setBreach]
199 );
208 );
200
209
210+ const setNetworkingKeys = useCallback(async () => {
211+ // setLoading(true);
212+ console.log(breach, manualNetworkSeed);
213+ try {
214+ const txHash = await configureNetworkingKeys({
215+ breach,
216+ manualNetworkSeed,
217+ });
218+ // TODO: just use the tx hash instead?
219+ getPendingTransactions(point);
220+ pop();
221+ } catch (error) {
222+ // setError(error);
223+ } finally {
224+ // setLoading(false);
225+ }
226+ }, [
227+ breach,
228+ manualNetworkSeed,
229+ getPendingTransactions,
230+ point,
231+ pop,
232+ configureNetworkingKeys,
233+ ]);
234+
201 const initialValues = useMemo(
235 const initialValues = useMemo(
202 () => ({
236 () => ({
203 useNetworkSeed: false,
237 useNetworkSeed: false,
@@ -280,13 +314,25 @@ export default function UrbitOSNetworkingKeys({
280 </>
314 </>
281 )}
315 )}
282
316
317+ {currentL2 ? (
283− <Grid.Item
318+ <Grid.Item
319+ as={Button}
284− full
320+ full
321+ className=""
322+ center
323+ solid
324+ onClick={setNetworkingKeys}>
325+ {'Sign Transaction'}
326+ </Grid.Item>
327+ ) : (
328+ <Grid.Item
329+ full
285− as={InlineEthereumTransaction}
330+ as={InlineEthereumTransaction}
286− {...bind}
331+ {...bind}
287− label={`${hasKeys ? 'Reset' : 'Set'} Networking Keys`}
332+ label={`${hasKeys ? 'Reset' : 'Set'} Networking Keys`}
288− onReturn={() => pop()}
333+ onReturn={() => pop()}
289− />
334+ />
335+ )}
290 </>
336 </>
291 )}
337 )}
292 </BridgeForm>
338 </BridgeForm>