on master help sign in
network-keys: use attemptSeedDerivation
commit2d3487f03364bc3e5913a60570544ff9ca50c802 authoryosoyubik <yosoyubik@gmail.com> dateWed 29 Sep 2021, 07:28 (5 years ago) parentdd13e79
4 files changed+48−41
src/lib/useRoller.ts+30−21 src/lib/utils/roller.ts+9−18 src/views/UrbitOS/Home.tsx+1−1 src/views/UrbitOS/NetworkingKeys.js+8−1
src/lib/useRoller.ts+30−21
@@ -7,11 +7,9 @@ import { Just } from 'folktale/maybe';
77
88import { Invite } from 'lib/types/Invite';
99import { convertToInt } from './convertToInt';
10−import { ensureHexPrefix } from 'form/formatters';
1110import { isDevelopment, isRopsten } from './flags';
1211import { hasPoint, generateInviteWallet } from './utils/roller';
1312import { ROLLER_HOSTS } from './constants';
14−import { signTransactionHash } from './authToken';
1513
1614import { useNetwork } from 'store/network';
1715import { usePointCursor } from 'store/pointCursor';
@@ -33,9 +31,8 @@ import {
3331import { isPlanet } from './utils/point';
3432
3533import {
36− deriveNetworkKeys,
37− CRYPTO_SUITE_VERSION,
3834 deriveNetworkSeedFromUrbitWallet,
35+ attemptNetworkSeedDerivation,
3936} from 'lib/keys';
4037
4138import {
@@ -46,8 +43,6 @@ import {
4643 Options,
4744 EthAddress,
4845 UnspawnedPoints,
49− From,
50− Hash,
5146 SpawnParams,
5247 L2Data,
5348} from '@urbit/roller-api';
@@ -69,7 +64,7 @@ function isShipNumber(ship: number | string | undefined): ship is number {
6964}
7065
7166export default function useRoller() {
72− const { wallet, authToken, authMnemonic }: any = useWallet();
67+ const { wallet, authToken, authMnemonic, urbitWallet }: any = useWallet();
7368 const { pointCursor }: any = usePointCursor();
7469 const { web3, contracts }: any = useNetwork();
7570 const allPoints: any = usePointCache();
@@ -201,13 +196,17 @@ export default function useRoller() {
201196 );
202197 increaseNonce(_point, operator.proxy!);
203198
199+ const networkSeed = await deriveNetworkSeedFromUrbitWallet(
200+ inviteWallet,
201+ 1
202+ );
204203 const configureKeysRequest = await configureKeys(
205204 api,
206205 _wallet,
207206 planet,
208207 operator.proxy!,
209208 0,
210− inviteWallet
209+ networkSeed
211210 );
212211
213212 const setManagementProxyRequest = await registerProxyAddress(
@@ -423,32 +422,41 @@ export default function useRoller() {
423422 customNetworkSeed,
424423 }: ConfigureKeysParams) => {
425424 const _point = need.point(pointCursor);
425+ const azimuthPoint = await api.getPoint(_point);
426426 const _wallet = wallet.getOrElse(null);
427− console.log(_point, _wallet);
428− if (!_wallet) {
427+ const _details = getDetails(_point);
428+ if (!_wallet || !_details) {
429429 // 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');
431431 }
432432
433433 const pointDetails = nonces[_point];
434434 const operator =
435435 getManagementNonce(pointDetails, _wallet.address) ||
436436 getOwnerNonce(pointDetails, _wallet.address);
437−
438437 if (operator === undefined)
439438 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);
441440 const nextRevision = networkRevision + 1;
442− console.log('nextRevision', nextRevision);
441+ const networkSeed = customNetworkSeed
442+ ? customNetworkSeed
443+ : await attemptNetworkSeedDerivation({
444+ urbitWallet,
445+ wallet,
446+ authMnemonic,
447+ details: _details,
448+ point: _point,
449+ authToken,
450+ revision: nextRevision,
451+ });
443452 const txHash = await configureKeys(
444453 api,
445454 _wallet,
446455 _point,
447456 operator.proxy!,
448457 operator.nonce!,
449− _wallet,
450− nextRevision,
451− customNetworkSeed
458+ networkSeed,
459+ breach
452460 );
453461 const pendingTx = await api.getPendingTx(txHash);
454462
@@ -484,18 +492,19 @@ export default function useRoller() {
484492 const nonce = operator.nonce!;
485493
486494 // 1. Update networking keys
487− // TODO: extract this to a useRoller#configureKeys function?
488495 const networkRevision = convertToInt(azimuthPoint.network.keys.life, 10);
489496 const nextRevision = networkRevision + 1;
490−
497+ const networkSeed = await deriveNetworkSeedFromUrbitWallet(
498+ toWallet,
499+ nextRevision
500+ );
491501 const configureKeysRequest = await configureKeys(
492502 api,
493503 fromWallet,
494504 point,
495505 operator.proxy!,
496506 nonce,
497− toWallet,
498− nextRevision
507+ networkSeed
499508 );
500509
501510 // 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 {
1212 Ship,
1313} from '@urbit/roller-api';
1414
15−import {
16− deriveNetworkSeedFromUrbitWallet,
17− deriveNetworkKeys,
18− CRYPTO_SUITE_VERSION,
19−} from 'lib/keys';
15+import { deriveNetworkKeys, CRYPTO_SUITE_VERSION } from 'lib/keys';
2016import { addHexPrefix } from 'lib/utils/address';
2117import { makeDeterministicTicket, generateWallet } from 'lib/walletgen';
2218
@@ -74,23 +70,18 @@ export const spawn = async (
7470
7571export const configureKeys = async (
7672 api: any,
77− _wallet: any,
78− _point: Ship,
73+ wallet: any,
74+ point: Ship,
7975 proxy: string,
8076 nonce: number,
81− urbitWallet: any,
82− nextRevision?: number,
83− customNetworkSeed?: string
77+ networkSeed: any,
78+ breach?: boolean
8479) => {
8580 const from = {
86− ship: _point, //ship to configure keys
81+ ship: point, //ship to configure keys
8782 proxy,
8883 };
8984
90− const networkSeed =
91− customNetworkSeed ||
92− (await deriveNetworkSeedFromUrbitWallet(urbitWallet, nextRevision || 1));
93−
9485 // TODO: do something here?
9586 if (Nothing.hasInstance(networkSeed)) {
9687 console.log("Network key Error: couldn't derive network keys");
@@ -107,12 +98,12 @@ export const configureKeys = async (
10798 encrypt: addHexPrefix(pair.crypt.public),
10899 auth: addHexPrefix(pair.auth.public),
109100 cryptoSuite: String(CRYPTO_SUITE_VERSION),
110− breach: false,
101+ breach,
111102 };
112103
113104 const hash = await api.hashTransaction(nonce, from, 'configureKeys', data);
114− const sig = signTransactionHash(hash, _wallet.privateKey);
115− return api.configureKeys(sig, from, _wallet.address, data);
105+ const sig = signTransactionHash(hash, wallet.privateKey);
106+ return api.configureKeys(sig, from, wallet.address, data);
116107};
117108
118109export const transferPointRequest = async (
src/views/UrbitOS/Home.tsx+1−1
@@ -12,7 +12,7 @@ import { ForwardButton } from 'components/Buttons';
1212import NetworkingKeys from 'components/NetworkingKeys';
1313
1414import { useLocalRouter } from 'lib/LocalRouter';
15−import { L1Point } from 'types/L1Point';
15+import { L1Point } from 'lib/types/L1Point';
1616import AlertBox from 'components/AlertBox';
1717import DownloadKeyfileButton from 'components/DownloadKeyfileButton';
1818import useKeyfileGenerator from 'lib/useKeyfileGenerator';
src/views/UrbitOS/NetworkingKeys.js+8−1
@@ -52,7 +52,7 @@ function useSetKeys(manualNetworkSeed, setManualNetworkSeed) {
5252
5353 const networkRevision = convertToInt(_details.keyRevisionNumber, 10);
5454 const randomSeed = useRef();
55− console.log(manualNetworkSeed);
55+
5656 const {
5757 available: keyfileAvailable,
5858 generating: keyfileGenerating,
@@ -217,6 +217,13 @@ export default function UrbitOSNetworkingKeys({
217217 });
218218 // TODO: just use the tx hash instead?
219219 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+ //
220227 pop();
221228 } catch (error) {
222229 // setError(error);