on master help sign in
rebase on roller
a5fcdb1tomholford
src/lib/useRoller.ts+38−44
@@ -1,17 +1,33 @@
1import { useCallback, useEffect, useMemo, useState } from 'react';
1import { useCallback, useEffect, useMemo, useState } from 'react';
2−import * as wg from 'lib/walletgen';
3−import * as need from 'lib/need';
4import * as azimuth from 'azimuth-js';
2import * as azimuth from 'azimuth-js';
3+import * as need from 'lib/need';
5import * as ob from 'urbit-ob';
4import * as ob from 'urbit-ob';
5+import * as wg from 'lib/walletgen';
6+
7+import { addHexPrefix } from 'lib/utils/address';
8+import { convertToInt } from './convertToInt';
9+import { ensureHexPrefix } from 'form/formatters';
10+import { getOutgoingPoints, maybeGetResult } from 'views/Points';
11+import { getTimeToNextBatch } from './utils/roller';
12+import { Invite } from 'types/Invite';
13+import { isDevelopment, isRopsten } from './flags';
14+import { isPlanet } from './utils/point';
6import { Just } from 'folktale/maybe';
15import { Just } from 'folktale/maybe';
7import { randomHex } from 'web3-utils';
16import { randomHex } from 'web3-utils';
17+import { ROLLER_HOSTS } from './constants';
18+import { signTransactionHash } from './authToken';
19+import { useNetwork } from 'store/network';
20+import { usePointCache } from 'store/pointCache';
21+import { usePointCursor } from 'store/pointCursor';
22+import { useRollerStore } from 'store/roller';
23+import { useWallet } from 'store/wallet';
8
24
9import {
25import {
10 attemptNetworkSeedDerivation,
26 attemptNetworkSeedDerivation,
11 deriveNetworkKeys,
27 deriveNetworkKeys,
12 CRYPTO_SUITE_VERSION,
28 CRYPTO_SUITE_VERSION,
29+ deriveNetworkSeedFromUrbitWallet,
13} from 'lib/keys';
30} from 'lib/keys';
14−import { addHexPrefix } from 'lib/utils/address';
15
31
16import {
32import {
17 Config,
33 Config,
@@ -26,30 +42,11 @@ import {
26 Hash,
42 Hash,
27} from '@urbit/roller-api';
43} from '@urbit/roller-api';
28
44
29−import { isDevelopment, isRopsten } from './flags';
30−import { ROLLER_HOSTS } from './constants';
31−import { useRollerStore } from 'store/roller';
32−import { getTimeToNextBatch } from './utils/roller';
33−import { useWallet } from 'store/wallet';
34−import { usePointCursor } from 'store/pointCursor';
35−import { useNetwork } from 'store/network';
36−import { signTransactionHash } from './authToken';
37−import { Invite } from 'lib/types/Invite';
38import {
45import {
39 getStoredInvites,
46 getStoredInvites,
40 setPendingInvites,
47 setPendingInvites,
41 setStoredInvites,
48 setStoredInvites,
42} from 'store/storage/roller';
49} from 'store/storage/roller';
43−import { usePointCache } from 'store/pointCache';
44−import { getOutgoingPoints, maybeGetResult } from 'views/Points';
45−import { isPlanet } from './utils/point';
46−import {
47− CRYPTO_SUITE_VERSION,
48− deriveNetworkKeys,
49− deriveNetworkSeedFromUrbitWallet,
50−} from './keys';
51−import { convertToInt } from './convertToInt';
52−import { ensureHexPrefix } from 'form/formatters';
53
50
54const spawn = async (
51const spawn = async (
55 api: any,
52 api: any,
@@ -216,7 +213,7 @@ export default function useRoller() {
216 .catch(err => {
213 .catch(err => {
217 // TODO: more elegant error handling
214 // TODO: more elegant error handling
218 console.warn(
215 console.warn(
219− '[fetchConfig:failed] is roller running on localhost?\n',
216+ '[fetchConfig:failed] check the roller connection?\n',
220 err
217 err
221 );
218 );
222 });
219 });
@@ -483,33 +480,38 @@ export default function useRoller() {
483
480
484 // }
481 // }
485
482
486− interface TransferPointParams {
483+ interface AcceptInviteParams {
487 point: Ship;
484 point: Ship;
488 to: EthAddress;
485 to: EthAddress;
489− ownerAddress: EthAddress;
490 fromWallet: any; // TODO: wallet type
486 fromWallet: any; // TODO: wallet type
491 toWallet: any; // TODO: wallet type
487 toWallet: any; // TODO: wallet type
492 }
488 }
493
489
494− const transferPoint = async ({
490+ const acceptInvite = async ({
495 point,
491 point,
496 to,
492 to,
497− ownerAddress,
498 fromWallet,
493 fromWallet,
499 toWallet,
494 toWallet,
500− }: TransferPointParams) => {
495+ }: AcceptInviteParams) => {
501− const patp = ob.patp(point);
502 const azimuthPoint = await api.getPoint(point);
496 const azimuthPoint = await api.getPoint(point);
497+ const spawnerPatp = ob.patp(azimuthPoint?.network?.sponsor?.who);
498+ console.log('azimuthPoint', azimuthPoint);
499+ const ownerAddress = azimuthPoint?.ownership?.owner?.address!;
503
500
504 const { nonce } = getProxyAndNonce(azimuthPoint, ownerAddress);
501 const { nonce } = getProxyAndNonce(azimuthPoint, ownerAddress);
505 if (nonce === undefined) {
502 if (nonce === undefined) {
506 throw new Error('Nonce unavailable');
503 throw new Error('Nonce unavailable');
507 }
504 }
508
505
509− // update networking keys
506+ // 1. Update networking keys
510 // TODO: extract this to a useRoller#configureKeys function?
507 // TODO: extract this to a useRoller#configureKeys function?
511 const networkRevision = convertToInt(azimuthPoint.network.keys.life, 10);
508 const networkRevision = convertToInt(azimuthPoint.network.keys.life, 10);
512 const nextRevision = networkRevision + 1;
509 const nextRevision = networkRevision + 1;
510+ const fromOwnerProxy: From = {
511+ ship: spawnerPatp,
512+ proxy: 'own',
513+ };
514+
513 const seed = await deriveNetworkSeedFromUrbitWallet(toWallet, nextRevision);
515 const seed = await deriveNetworkSeedFromUrbitWallet(toWallet, nextRevision);
514 const keys = deriveNetworkKeys(seed.value);
516 const keys = deriveNetworkKeys(seed.value);
515 const keysData = {
517 const keysData = {
@@ -518,14 +520,10 @@ export default function useRoller() {
518 cryptoSuite: CRYPTO_SUITE_VERSION.toString(),
520 cryptoSuite: CRYPTO_SUITE_VERSION.toString(),
519 encrypt: ensureHexPrefix(keys.crypt.public),
521 encrypt: ensureHexPrefix(keys.crypt.public),
520 };
522 };
521− const keysFrom: From = {
522− ship: patp,
523− proxy: 'own',
524− };
525
523
526 const keysHash: Hash = await api.hashTransaction(
524 const keysHash: Hash = await api.hashTransaction(
527 nonce,
525 nonce,
528− keysFrom,
526+ fromOwnerProxy,
529 'configureKeys',
527 'configureKeys',
530 keysData
528 keysData
531 );
529 );
@@ -533,21 +531,16 @@ export default function useRoller() {
533 const keysSigningKey = fromWallet.privateKey;
531 const keysSigningKey = fromWallet.privateKey;
534 await api.configureKeys(
532 await api.configureKeys(
535 signTransactionHash(keysHash, Buffer.from(keysSigningKey, 'hex')),
533 signTransactionHash(keysHash, Buffer.from(keysSigningKey, 'hex')),
536− keysFrom,
534+ fromOwnerProxy,
537 ownerAddress,
535 ownerAddress,
538 keysData
536 keysData
539 );
537 );
540
538
541− // transfer point
539+ // 2. Transfer point
542− const transferFrom: From = {
543− ship: patp,
544− proxy: 'transfer',
545− };
546−
547 const transferData = { address: ownerAddress, reset: false };
540 const transferData = { address: ownerAddress, reset: false };
548 const transferHash: Hash = await api.hashTransaction(
541 const transferHash: Hash = await api.hashTransaction(
549 nonce + 1,
542 nonce + 1,
550− transferFrom,
543+ fromOwnerProxy,
551 'transferPoint',
544 'transferPoint',
552 transferData
545 transferData
553 );
546 );
@@ -555,7 +548,7 @@ export default function useRoller() {
555 const transferSigningKey = toWallet.ownership.keys.private;
548 const transferSigningKey = toWallet.ownership.keys.private;
556 const transferTxHash = await api.transferPoint(
549 const transferTxHash = await api.transferPoint(
557 signTransactionHash(transferHash, Buffer.from(transferSigningKey, 'hex')),
550 signTransactionHash(transferHash, Buffer.from(transferSigningKey, 'hex')),
558− transferFrom,
551+ fromOwnerProxy,
559 to,
552 to,
560 transferData
553 transferData
561 );
554 );
@@ -591,6 +584,7 @@ export default function useRoller() {
591
584
592 return {
585 return {
593 api,
586 api,
587+ acceptInvite,
594 config,
588 config,
595 getPoints,
589 getPoints,
596 getInvites,
590 getInvites,
src/views/Activate/ActivateSteps.tsx+1−3
@@ -1,4 +1,4 @@
1−import { Box, SegmentedProgressBar } from '@tlon/indigo-react';
1+import { Box } from '@tlon/indigo-react';
2import withFadeable from './withFadeable';
2import withFadeable from './withFadeable';
3
3
4type ActivateStepsProps = {
4type ActivateStepsProps = {
@@ -41,8 +41,6 @@ export const ActivateSteps = ({
41 flexWrap={'nowrap'}
41 flexWrap={'nowrap'}
42 width={'100%'}
42 width={'100%'}
43 className={className}>
43 className={className}>
44− {/* TODO: Ask Jimmy: */}
45− {/* <SegmentedProgressBar current={currentStep} segments={totalSteps} /> */}
46 {renderSteps()}
44 {renderSteps()}
47 </Box>
45 </Box>
48 );
46 );
src/views/Activate/MasterKeyTransfer.tsx+10−7
@@ -14,7 +14,7 @@ import DangerBox from './DangerBox';
14import View from 'components/View';
14import View from 'components/View';
15
15
16const MasterKeyTransfer = () => {
16const MasterKeyTransfer = () => {
17− const { api, transferPoint } = useRoller();
17+ const { acceptInvite } = useRoller();
18 const {
18 const {
19 derivedPatp,
19 derivedPatp,
20 derivedPoint,
20 derivedPoint,
@@ -27,11 +27,9 @@ const MasterKeyTransfer = () => {
27 setError(undefined);
27 setError(undefined);
28
28
29 try {
29 try {
30− const l2point = await api.getPoint(derivedPoint.value);
30+ await acceptInvite({
31− await transferPoint({
32 point: derivedPoint.value,
31 point: derivedPoint.value,
33 to: derivedWallet.value.ownership.address,
32 to: derivedWallet.value.ownership.address,
34− ownerAddress: l2point.ownership?.owner?.address!,
35 toWallet: derivedWallet.value,
33 toWallet: derivedWallet.value,
36 fromWallet: inviteWallet.value,
34 fromWallet: inviteWallet.value,
37 });
35 });
@@ -39,7 +37,12 @@ const MasterKeyTransfer = () => {
39 console.error(error);
37 console.error(error);
40 setError(error);
38 setError(error);
41 }
39 }
40+ }, [
42− }, [api, derivedPoint.value, derivedWallet, inviteWallet, transferPoint]);
41+ derivedPoint.value,
42+ derivedWallet.value,
43+ inviteWallet.value,
44+ acceptInvite,
45+ ]);
43
46
44 useFadeIn();
47 useFadeIn();
45
48
@@ -89,14 +92,14 @@ const MasterKeyTransfer = () => {
89 flexDirection={'column'}
92 flexDirection={'column'}
90 flexWrap={'nowrap'}
93 flexWrap={'nowrap'}
91 justifyContent={'space-between'}>
94 justifyContent={'space-between'}>
92− {/* {error && <DangerBox>{error.toString()}</DangerBox>} */}
95+ {error && <DangerBox>{error.toString()}</DangerBox>}
93 <ActivateButton
96 <ActivateButton
94 onClick={() =>
97 onClick={() =>
95 window.open(
98 window.open(
96 'https://github.com/urbit/port/releases/latest/download/Port.dmg'
99 'https://github.com/urbit/port/releases/latest/download/Port.dmg'
97 )
100 )
98 }
101 }
99− // disabled={error}
102+ disabled={error}
100 success={true}>
103 success={true}>
101 Download the Client for Mac
104 Download the Client for Mac
102 </ActivateButton>
105 </ActivateButton>