1import { signTransactionHash } from 'lib/authToken';
2import { Invite } from 'lib/types/Invite';
3import { Just, Nothing } from 'folktale/maybe';
4import { randomHex } from 'web3-utils';
13} from '@urbit/roller-api';
15import { deriveNetworkKeys, CRYPTO_SUITE_VERSION } from 'lib/keys';
16import { addHexPrefix } from 'lib/utils/address';
17import { makeDeterministicTicket, generateWallet } from 'lib/walletgen';
19export const SECOND = 1000;
20export const MINUTE = SECOND * 60;
21export const HOUR = MINUTE * 60;
23export const padZero = (amount: number) =>
24 `${amount < 10 && amount > 0 ? '0' : ''}${amount}`;
26export const getTimeToNextBatch = (nextBatch: number, now: number) => {
27 const toNext = nextBatch - now;
28 const hours = Math.floor(toNext / HOUR);
29 const minutes = Math.floor((toNext - hours * HOUR) / MINUTE);
30 const seconds = Math.floor(
31 (toNext - hours * HOUR - minutes * MINUTE) / SECOND
34 return `${padZero(hours)}h ${padZero(minutes)}m ${padZero(seconds)}s`;
37export const isL2 = (dom?: string) => dom === 'l2' || dom === 'spawn';
39export const isL2Spawn = (dom?: string) => dom === 'spawn';
41export const generateInviteWallet = async (point: number, seed: string) => {
42 const ticket = makeDeterministicTicket(point, seed);
43 const inviteWallet = await generateWallet(point, ticket, true);
45 return { ticket, inviteWallet };
48export const spawn = async (
57 ship: _point, //ship that is spawning the planet
62 address: _wallet.address,
63 ship: planet, // ship to spawn
66 const hash = await api.hashTransaction(nonce, from, 'spawn', data);
67 const sSig = signTransactionHash(hash, _wallet.privateKey);
68 return api.spawn(sSig, from, _wallet.address, data);
71export const configureKeys = async (
81 ship: point, //ship to configure keys
85 // TODO: do something here?
86 if (Nothing.hasInstance(networkSeed)) {
87 console.log("Network key Error: couldn't derive network keys");
88 // throw new Error("Network key Error: couldn't derive network keys");
91 const seed = Just.hasInstance(networkSeed)
95 const pair = deriveNetworkKeys(seed);
98 encrypt: addHexPrefix(pair.crypt.public),
99 auth: addHexPrefix(pair.auth.public),
100 cryptoSuite: String(CRYPTO_SUITE_VERSION),
104 const hash = await api.hashTransaction(nonce, from, 'configureKeys', data);
105 const sig = signTransactionHash(hash, wallet.privateKey);
106 return api.configureKeys(sig, from, wallet.address, data);
109export const transferPointRequest = async (
119 ship: _point, // ship to transfer
125 reset: reset || false,
127 const hash = await api.hashTransaction(nonce, from, 'transferPoint', data);
128 const sig = signTransactionHash(hash, _wallet.privateKey);
129 return api.transferPoint(sig, from, _wallet.address, data);
132const proxyType = (proxy: Proxy) => {
135 return 'setManagementProxy';
137 return 'setSpawnProxy';
139 return 'setTransferProxy';
141 throw new Error(`Unknown proxyType ${proxy}`);
145export const registerProxyAddress = async (
150 proxyAddressType: string,
158 const managementData = { address };
159 const managementHash = await api.hashTransaction(
162 proxyType(proxyAddressType),
168 signTransactionHash(managementHash, _wallet.privateKey),
175const setProxy = async (
177 proxyAddressType: string,
183 switch (proxyAddressType) {
185 return await api.setManagementProxy(sig, from, address, data);
187 return await api.setSpawnProxy(sig, from, address, data);
189 return await api.setTrasferProxy(sig, from, address, data);
191 throw new Error(`Unknown proxyType ${proxyAddressType}`);
195export const hasPoint = (point: number) => (invite: Invite) =>
196 invite.planet === point;
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list