on master help sign in
network-keys: use attemptSeedDerivation
2d3487fyosoyubik
src/lib/useRoller.ts+30−21
@@ -7,11 +7,9 @@ import { Just } from 'folktale/maybe';
7
7
8import { Invite } from 'lib/types/Invite';
8import { Invite } from 'lib/types/Invite';
9import { convertToInt } from './convertToInt';
9import { convertToInt } from './convertToInt';
10−import { ensureHexPrefix } from 'form/formatters';
11import { isDevelopment, isRopsten } from './flags';
10import { isDevelopment, isRopsten } from './flags';
12import { hasPoint, generateInviteWallet } from './utils/roller';
11import { hasPoint, generateInviteWallet } from './utils/roller';
13import { ROLLER_HOSTS } from './constants';
12import { ROLLER_HOSTS } from './constants';
14−import { signTransactionHash } from './authToken';
15
13
16import { useNetwork } from 'store/network';
14import { useNetwork } from 'store/network';
17import { usePointCursor } from 'store/pointCursor';
15import { usePointCursor } from 'store/pointCursor';
@@ -33,9 +31,8 @@ import {
33import { isPlanet } from './utils/point';
31import { isPlanet } from './utils/point';
34
32
35import {
33import {
36− deriveNetworkKeys,
37− CRYPTO_SUITE_VERSION,
38 deriveNetworkSeedFromUrbitWallet,
34 deriveNetworkSeedFromUrbitWallet,
35+ attemptNetworkSeedDerivation,
39} from 'lib/keys';
36} from 'lib/keys';
40
37
41import {
38import {
@@ -46,8 +43,6 @@ import {
46 Options,
43 Options,
47 EthAddress,
44 EthAddress,
48 UnspawnedPoints,
45 UnspawnedPoints,
49− From,
50− Hash,
51 SpawnParams,
46 SpawnParams,
52 L2Data,
47 L2Data,
53} from '@urbit/roller-api';
48} from '@urbit/roller-api';
@@ -69,7 +64,7 @@ function isShipNumber(ship: number | string | undefined): ship is number {
69}
64}
70
65
71export default function useRoller() {
66export default function useRoller() {
72− const { wallet, authToken, authMnemonic }: any = useWallet();
67+ const { wallet, authToken, authMnemonic, urbitWallet }: any = useWallet();
73 const { pointCursor }: any = usePointCursor();
68 const { pointCursor }: any = usePointCursor();
74 const { web3, contracts }: any = useNetwork();
69 const { web3, contracts }: any = useNetwork();
75 const allPoints: any = usePointCache();
70 const allPoints: any = usePointCache();
@@ -201,13 +196,17 @@ export default function useRoller() {
201 );
196 );
202 increaseNonce(_point, operator.proxy!);
197 increaseNonce(_point, operator.proxy!);
203
198
199+ const networkSeed = await deriveNetworkSeedFromUrbitWallet(
200+ inviteWallet,
201+ 1
202+ );
204 const configureKeysRequest = await configureKeys(
203 const configureKeysRequest = await configureKeys(
205 api,
204 api,
206 _wallet,
205 _wallet,
207 planet,
206 planet,
208 operator.proxy!,
207 operator.proxy!,
209 0,
208 0,
210− inviteWallet
209+ networkSeed
211 );
210 );
212
211
213 const setManagementProxyRequest = await registerProxyAddress(
212 const setManagementProxyRequest = await registerProxyAddress(
@@ -423,32 +422,41 @@ export default function useRoller() {
423 customNetworkSeed,
422 customNetworkSeed,
424 }: ConfigureKeysParams) => {
423 }: ConfigureKeysParams) => {
425 const _point = need.point(pointCursor);
424 const _point = need.point(pointCursor);
425+ const azimuthPoint = await api.getPoint(_point);
426 const _wallet = wallet.getOrElse(null);
426 const _wallet = wallet.getOrElse(null);
427− console.log(_point, _wallet);
427+ const _details = getDetails(_point);
428− if (!_wallet) {
428+ if (!_wallet || !_details) {
429 // not using need because we want a custom error
429 // not using need because we want a custom error
430− throw new Error('Internal Error: Missing Wallet');
430+ throw new Error('Internal Error: Missing Wallet/Details');
431 }
431 }
432
432
433 const pointDetails = nonces[_point];
433 const pointDetails = nonces[_point];
434 const operator =
434 const operator =
435 getManagementNonce(pointDetails, _wallet.address) ||
435 getManagementNonce(pointDetails, _wallet.address) ||
436 getOwnerNonce(pointDetails, _wallet.address);
436 getOwnerNonce(pointDetails, _wallet.address);
437−
438 if (operator === undefined)
437 if (operator === undefined)
439 throw new Error("Error: Address doesn't match proxy");
438 throw new Error("Error: Address doesn't match proxy");
440− const networkRevision = convertToInt(pointDetails.network.keys.life, 10);
439+ const networkRevision = convertToInt(azimuthPoint.network.keys.life, 10);
441 const nextRevision = networkRevision + 1;
440 const nextRevision = networkRevision + 1;
441+ const networkSeed = customNetworkSeed
442+ ? customNetworkSeed
443+ : await attemptNetworkSeedDerivation({
444+ urbitWallet,
445+ wallet,
446+ authMnemonic,
447+ details: _details,
448+ point: _point,
449+ authToken,
442− console.log('nextRevision', nextRevision);
450+ revision: nextRevision,
451+ });
443 const txHash = await configureKeys(
452 const txHash = await configureKeys(
444 api,
453 api,
445 _wallet,
454 _wallet,
446 _point,
455 _point,
447 operator.proxy!,
456 operator.proxy!,
448 operator.nonce!,
457 operator.nonce!,
449− _wallet,
458+ networkSeed,
450− nextRevision,
459+ breach
451− customNetworkSeed
452 );
460 );
453 const pendingTx = await api.getPendingTx(txHash);
461 const pendingTx = await api.getPendingTx(txHash);
454
462
@@ -484,18 +492,19 @@ export default function useRoller() {
484 const nonce = operator.nonce!;
492 const nonce = operator.nonce!;
485
493
486 // 1. Update networking keys
494 // 1. Update networking keys
487− // TODO: extract this to a useRoller#configureKeys function?
488 const networkRevision = convertToInt(azimuthPoint.network.keys.life, 10);
495 const networkRevision = convertToInt(azimuthPoint.network.keys.life, 10);
489 const nextRevision = networkRevision + 1;
496 const nextRevision = networkRevision + 1;
490−
497+ const networkSeed = await deriveNetworkSeedFromUrbitWallet(
498+ toWallet,
499+ nextRevision
500+ );
491 const configureKeysRequest = await configureKeys(
501 const configureKeysRequest = await configureKeys(
492 api,
502 api,
493 fromWallet,
503 fromWallet,
494 point,
504 point,
495 operator.proxy!,
505 operator.proxy!,
496 nonce,
506 nonce,
497− toWallet,
507+ networkSeed
498− nextRevision
499 );
508 );
500
509
501 // TODO: not needed? next time we operate with this point we will login, and get
510 // TODO: not needed? next time we operate with this point we will login, and get
src/lib/utils/roller.ts+9−18
@@ -12,11 +12,7 @@ import {
12 Ship,
12 Ship,
13} from '@urbit/roller-api';
13} from '@urbit/roller-api';
14
14
15−import {
16− deriveNetworkSeedFromUrbitWallet,
17− deriveNetworkKeys,
18− CRYPTO_SUITE_VERSION,
15+import { deriveNetworkKeys, CRYPTO_SUITE_VERSION } from 'lib/keys';
19−} from 'lib/keys';
20import { addHexPrefix } from 'lib/utils/address';
16import { addHexPrefix } from 'lib/utils/address';
21import { makeDeterministicTicket, generateWallet } from 'lib/walletgen';
17import { makeDeterministicTicket, generateWallet } from 'lib/walletgen';
22
18
@@ -74,23 +70,18 @@ export const spawn = async (
74
70
75export const configureKeys = async (
71export const configureKeys = async (
76 api: any,
72 api: any,
77− _wallet: any,
73+ wallet: any,
78− _point: Ship,
74+ point: Ship,
79 proxy: string,
75 proxy: string,
80 nonce: number,
76 nonce: number,
81− urbitWallet: any,
77+ networkSeed: any,
82− nextRevision?: number,
78+ breach?: boolean
83− customNetworkSeed?: string
84) => {
79) => {
85 const from = {
80 const from = {
86− ship: _point, //ship to configure keys
81+ ship: point, //ship to configure keys
87 proxy,
82 proxy,
88 };
83 };
89
84
90− const networkSeed =
91− customNetworkSeed ||
92− (await deriveNetworkSeedFromUrbitWallet(urbitWallet, nextRevision || 1));
93−
94 // TODO: do something here?
85 // TODO: do something here?
95 if (Nothing.hasInstance(networkSeed)) {
86 if (Nothing.hasInstance(networkSeed)) {
96 console.log("Network key Error: couldn't derive network keys");
87 console.log("Network key Error: couldn't derive network keys");
@@ -107,12 +98,12 @@ export const configureKeys = async (
107 encrypt: addHexPrefix(pair.crypt.public),
98 encrypt: addHexPrefix(pair.crypt.public),
108 auth: addHexPrefix(pair.auth.public),
99 auth: addHexPrefix(pair.auth.public),
109 cryptoSuite: String(CRYPTO_SUITE_VERSION),
100 cryptoSuite: String(CRYPTO_SUITE_VERSION),
110− breach: false,
101+ breach,
111 };
102 };
112
103
113 const hash = await api.hashTransaction(nonce, from, 'configureKeys', data);
104 const hash = await api.hashTransaction(nonce, from, 'configureKeys', data);
114− const sig = signTransactionHash(hash, _wallet.privateKey);
105+ const sig = signTransactionHash(hash, wallet.privateKey);
115− return api.configureKeys(sig, from, _wallet.address, data);
106+ return api.configureKeys(sig, from, wallet.address, data);
116};
107};
117
108
118export const transferPointRequest = async (
109export const transferPointRequest = async (
src/views/UrbitOS/Home.tsx+1−1
@@ -12,7 +12,7 @@ import { ForwardButton } from 'components/Buttons';
12import NetworkingKeys from 'components/NetworkingKeys';
12import NetworkingKeys from 'components/NetworkingKeys';
13
13
14import { useLocalRouter } from 'lib/LocalRouter';
14import { useLocalRouter } from 'lib/LocalRouter';
15−import { L1Point } from 'types/L1Point';
15+import { L1Point } from 'lib/types/L1Point';
16import AlertBox from 'components/AlertBox';
16import AlertBox from 'components/AlertBox';
17import DownloadKeyfileButton from 'components/DownloadKeyfileButton';
17import DownloadKeyfileButton from 'components/DownloadKeyfileButton';
18import useKeyfileGenerator from 'lib/useKeyfileGenerator';
18import useKeyfileGenerator from 'lib/useKeyfileGenerator';
src/views/UrbitOS/NetworkingKeys.js+8−1
@@ -52,7 +52,7 @@ function useSetKeys(manualNetworkSeed, setManualNetworkSeed) {
52
52
53 const networkRevision = convertToInt(_details.keyRevisionNumber, 10);
53 const networkRevision = convertToInt(_details.keyRevisionNumber, 10);
54 const randomSeed = useRef();
54 const randomSeed = useRef();
55− console.log(manualNetworkSeed);
55+
56 const {
56 const {
57 available: keyfileAvailable,
57 available: keyfileAvailable,
58 generating: keyfileGenerating,
58 generating: keyfileGenerating,
@@ -217,6 +217,13 @@ export default function UrbitOSNetworkingKeys({
217 });
217 });
218 // TODO: just use the tx hash instead?
218 // TODO: just use the tx hash instead?
219 getPendingTransactions(point);
219 getPendingTransactions(point);
220+ // TODO: this is just so we get visual feedback that the tx has gone through
221+ // but this should be addressed with the new UI flow (-> download keyfile)
222+ //
223+ // A question here is how to deal with the modals/messages about the keys not being
224+ // set since they are in pending in the Roller...
225+ // we could inspect if there's a changeKeys in the local list of pending txs,...
226+ //
220 pop();
227 pop();
221 } catch (error) {
228 } catch (error) {
222 // setError(error);
229 // setError(error);