on master help sign in
api: cherry-pick ~fabnev-himnur's invite tweaks
commit9e302d69f7cd5c9ef1d68be207e2602bc760da20 authortomholford <tomholford@users.noreply.github.com> dateTue 21 Sep 2021, 00:12 (5 years ago) parente9f5193
3 files changed+113−102
src/lib/useRoller.ts+8−100 src/lib/utils/roller.ts+105 src/store/lib/useControlledPointsStore.js−2
src/lib/useRoller.ts+8−100
@@ -4,16 +4,11 @@ import * as need from 'lib/need';
44import * as ob from 'urbit-ob';
55import * as wg from 'lib/walletgen';
66
7−import { addHexPrefix } from 'lib/utils/address';
87import { convertToInt } from './convertToInt';
98import { ensureHexPrefix } from 'form/formatters';
109import { getOutgoingPoints, maybeGetResult } from 'views/Points';
11−import { getTimeToNextBatch } from './utils/roller';
12−import { Invite } from 'types/Invite';
1310import { isDevelopment, isRopsten } from './flags';
1411import { isPlanet } from './utils/point';
15−import { Just } from 'folktale/maybe';
16−import { randomHex } from 'web3-utils';
1712import { ROLLER_HOSTS } from './constants';
1813import { signTransactionHash } from './authToken';
1914import { useNetwork } from 'store/network';
@@ -23,7 +18,6 @@ import { useRollerStore } from 'store/roller';
2318import { useWallet } from 'store/wallet';
2419
2520import {
26− attemptNetworkSeedDerivation,
2721 deriveNetworkKeys,
2822 CRYPTO_SUITE_VERSION,
2923 deriveNetworkSeedFromUrbitWallet,
@@ -42,105 +36,19 @@ import {
4236 Hash,
4337} from '@urbit/roller-api';
4438
39+import {
40+ configureKeys,
41+ getTimeToNextBatch,
42+ spawn,
43+ transferPoint,
44+} from './utils/roller';
45+
4546import {
4647 getStoredInvites,
4748 setPendingInvites,
4849 setStoredInvites,
4950} from 'store/storage/roller';
5051
51−const spawn = async (
52− api: any,
53− _wallet: any,
54− _point: number,
55− proxy: string,
56− nonce: number,
57− planet: number
58−) => {
59− const from = {
60− ship: _point, //ship that is spawning the planet
61− proxy,
62− };
63−
64− const data = {
65− address: _wallet.address,
66− ship: planet, // ship to spawn
67− };
68−
69− const hash = await api.hashTransaction(nonce, from, 'spawn', data);
70− const sSig = signTransactionHash(hash, _wallet.privateKey);
71− return api.spawn(sSig, from, _wallet.address, data);
72−};
73−
74−const configureKeys = async (
75− api: any,
76− _wallet: any,
77− _point: number,
78− proxy: string,
79− nonce: number,
80− details: any,
81− authToken: string,
82− authMnemonic: string,
83− wallet: any,
84− urbitWallet: any
85−) => {
86− const from = {
87− ship: _point, //ship that is spawning the planet
88− proxy,
89− };
90−
91− const networkSeed = await attemptNetworkSeedDerivation({
92− urbitWallet,
93− wallet,
94− authMnemonic,
95− details,
96− point: _point,
97− authToken,
98− revision: 1,
99− });
100−
101− const seed = Just.hasInstance(networkSeed)
102− ? networkSeed.value
103− : randomHex(32);
104−
105− const pair = deriveNetworkKeys(seed);
106−
107− const data = {
108− encrypt: addHexPrefix(pair.crypt.public),
109− auth: addHexPrefix(pair.auth.public),
110− cryptoSuite: String(CRYPTO_SUITE_VERSION),
111− breach: false,
112− };
113−
114− const hash = await api.hashTransaction(nonce, from, 'configureKeys', data);
115− const sig = signTransactionHash(hash, _wallet.privateKey);
116− return api.configureKeys(sig, from, _wallet.address, data);
117−};
118−
119−const transferPoint = async (
120− api: any,
121− _wallet: any,
122− _point: number,
123− proxy: string,
124− nonce: number,
125− address: string
126−) => {
127− const from = {
128− ship: _point, //ship that is spawning the planet
129− proxy,
130− };
131−
132− const data = {
133− address,
134− reset: false,
135− };
136−
137− const hash = await api.hashTransaction(nonce, from, 'transferPoint', data);
138− const sig = signTransactionHash(hash, _wallet.privateKey);
139− return api.transferPoint(sig, from, _wallet.address, data);
140−};
141−
142−const hasPoint = (point: number) => (invite: Invite) => invite.planet === point;
143−
14452const getProxyAndNonce = (
14553 point: L2Point,
14654 address: string
@@ -277,7 +185,7 @@ export default function useRoller() {
277185 const transferPointRequest = await transferPoint(
278186 api,
279187 _wallet,
280− _point,
188+ planet,
281189 proxy,
282190 nonceInc + 2,
283191 owner.keys.address
src/lib/utils/roller.ts+105
@@ -1,3 +1,14 @@
1+import { signTransactionHash } from "lib/authToken";
2+import { Invite } from "lib/types/Invite";
3+import { Just } from 'folktale/maybe';
4+import { randomHex } from 'web3-utils';
5+import {
6+ attemptNetworkSeedDerivation,
7+ deriveNetworkKeys,
8+ CRYPTO_SUITE_VERSION,
9+} from 'lib/keys';
10+import { addHexPrefix } from 'lib/utils/address';
11+
112export const SECOND = 1000;
213export const MINUTE = SECOND * 60;
314export const HOUR = MINUTE * 60;
@@ -17,3 +28,97 @@ export const getTimeToNextBatch = (nextBatch: number, now: number) => {
1728};
1829
1930export const isL2 = (dom?: string) => dom === 'l2' || dom === 'spawn';
31+
32+export const spawn = async (
33+ api: any,
34+ _wallet: any,
35+ _point: number,
36+ proxy: string,
37+ nonce: number,
38+ planet: number
39+) => {
40+ const from = {
41+ ship: _point, //ship that is spawning the planet
42+ proxy,
43+ };
44+
45+ const data = {
46+ address: _wallet.address,
47+ ship: planet, // ship to spawn
48+ };
49+
50+ const hash = await api.hashTransaction(nonce, from, 'spawn', data);
51+ const sSig = signTransactionHash(hash, _wallet.privateKey);
52+ return api.spawn(sSig, from, _wallet.address, data);
53+};
54+
55+export const configureKeys = async (
56+ api: any,
57+ _wallet: any,
58+ _point: number,
59+ proxy: string,
60+ nonce: number,
61+ details: any,
62+ authToken: string,
63+ authMnemonic: string,
64+ wallet: any,
65+ urbitWallet: any
66+) => {
67+ const from = {
68+ ship: _point, //ship that is spawning the planet
69+ proxy,
70+ };
71+
72+ const networkSeed = await attemptNetworkSeedDerivation({
73+ urbitWallet,
74+ wallet,
75+ authMnemonic,
76+ details,
77+ point: _point,
78+ authToken,
79+ revision: 1,
80+ });
81+
82+ const seed = Just.hasInstance(networkSeed)
83+ ? networkSeed.value
84+ : randomHex(32);
85+
86+ const pair = deriveNetworkKeys(seed);
87+
88+ const data = {
89+ encrypt: addHexPrefix(pair.crypt.public),
90+ auth: addHexPrefix(pair.auth.public),
91+ cryptoSuite: String(CRYPTO_SUITE_VERSION),
92+ breach: false,
93+ };
94+
95+ const hash = await api.hashTransaction(nonce, from, 'configureKeys', data);
96+ const sig = signTransactionHash(hash, _wallet.privateKey);
97+ return api.configureKeys(sig, from, _wallet.address, data);
98+};
99+
100+export const transferPoint = async (
101+ api: any,
102+ _wallet: any,
103+ planet: number,
104+ proxy: string,
105+ nonce: number,
106+ address: string
107+) => {
108+ const from = {
109+ ship: planet, //planet to transfer
110+ proxy,
111+ };
112+
113+ const data = {
114+ address,
115+ reset: false,
116+ };
117+
118+ const hash = await api.hashTransaction(nonce, from, 'transferPoint', data);
119+ const sig = signTransactionHash(hash, _wallet.privateKey);
120+ return api.transferPoint(sig, from, _wallet.address, data);
121+};
122+
123+export const hasPoint = (point: number) => (invite: Invite) =>
124+ invite.planet === point;
src/store/lib/useControlledPointsStore.js−2
@@ -53,10 +53,8 @@ export default function useControlledPointsStore() {
5353 azimuth.azimuth.getSpawningFor(_contracts, address),
5454 ]);
5555
56− console.log(1)
5756 const pointsWithLayers = await Promise.all(
5857 ownedPoints.map(async ship => {
59− console.log(2)
6058 try {
6159 const pointInfo = await api.getPoint(Number(ship));
6260 return {