on master help sign in
api: cherry-pick ~fabnev-himnur's invite tweaks
9e302d6tomholford
src/lib/useRoller.ts+8−100
@@ -4,16 +4,11 @@ import * as need from 'lib/need';
4import * as ob from 'urbit-ob';
4import * as ob from 'urbit-ob';
5import * as wg from 'lib/walletgen';
5import * as wg from 'lib/walletgen';
6
6
7−import { addHexPrefix } from 'lib/utils/address';
8import { convertToInt } from './convertToInt';
7import { convertToInt } from './convertToInt';
9import { ensureHexPrefix } from 'form/formatters';
8import { ensureHexPrefix } from 'form/formatters';
10import { getOutgoingPoints, maybeGetResult } from 'views/Points';
9import { getOutgoingPoints, maybeGetResult } from 'views/Points';
11−import { getTimeToNextBatch } from './utils/roller';
12−import { Invite } from 'types/Invite';
13import { isDevelopment, isRopsten } from './flags';
10import { isDevelopment, isRopsten } from './flags';
14import { isPlanet } from './utils/point';
11import { isPlanet } from './utils/point';
15−import { Just } from 'folktale/maybe';
16−import { randomHex } from 'web3-utils';
17import { ROLLER_HOSTS } from './constants';
12import { ROLLER_HOSTS } from './constants';
18import { signTransactionHash } from './authToken';
13import { signTransactionHash } from './authToken';
19import { useNetwork } from 'store/network';
14import { useNetwork } from 'store/network';
@@ -23,7 +18,6 @@ import { useRollerStore } from 'store/roller';
23import { useWallet } from 'store/wallet';
18import { useWallet } from 'store/wallet';
24
19
25import {
20import {
26− attemptNetworkSeedDerivation,
27 deriveNetworkKeys,
21 deriveNetworkKeys,
28 CRYPTO_SUITE_VERSION,
22 CRYPTO_SUITE_VERSION,
29 deriveNetworkSeedFromUrbitWallet,
23 deriveNetworkSeedFromUrbitWallet,
@@ -42,105 +36,19 @@ import {
42 Hash,
36 Hash,
43} from '@urbit/roller-api';
37} from '@urbit/roller-api';
44
38
39+import {
40+ configureKeys,
41+ getTimeToNextBatch,
42+ spawn,
43+ transferPoint,
44+} from './utils/roller';
45+
45import {
46import {
46 getStoredInvites,
47 getStoredInvites,
47 setPendingInvites,
48 setPendingInvites,
48 setStoredInvites,
49 setStoredInvites,
49} from 'store/storage/roller';
50} from 'store/storage/roller';
50
51
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−
144const getProxyAndNonce = (
52const getProxyAndNonce = (
145 point: L2Point,
53 point: L2Point,
146 address: string
54 address: string
@@ -277,7 +185,7 @@ export default function useRoller() {
277 const transferPointRequest = await transferPoint(
185 const transferPointRequest = await transferPoint(
278 api,
186 api,
279 _wallet,
187 _wallet,
280− _point,
188+ planet,
281 proxy,
189 proxy,
282 nonceInc + 2,
190 nonceInc + 2,
283 owner.keys.address
191 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+
1export const SECOND = 1000;
12export const SECOND = 1000;
2export const MINUTE = SECOND * 60;
13export const MINUTE = SECOND * 60;
3export const HOUR = MINUTE * 60;
14export const HOUR = MINUTE * 60;
@@ -17,3 +28,97 @@ export const getTimeToNextBatch = (nextBatch: number, now: number) => {
17};
28};
18
29
19export const isL2 = (dom?: string) => dom === 'l2' || dom === 'spawn';
30export 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() {
53 azimuth.azimuth.getSpawningFor(_contracts, address),
53 azimuth.azimuth.getSpawningFor(_contracts, address),
54 ]);
54 ]);
55
55
56− console.log(1)
57 const pointsWithLayers = await Promise.all(
56 const pointsWithLayers = await Promise.all(
58 ownedPoints.map(async ship => {
57 ownedPoints.map(async ship => {
59− console.log(2)
60 try {
58 try {
61 const pointInfo = await api.getPoint(Number(ship));
59 const pointInfo = await api.getPoint(Number(ship));
62 return {
60 return {