1import { Just, Nothing } from 'folktale/maybe';
2import { Invite } from 'lib/types/Invite';
3import { signTransactionHash } from 'lib/authToken';
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 hasPoint = (point: number) => (invite: Invite) =>
27 invite.planet === point;
29export const getTimeToNextBatch = (nextBatch: number, now: number) => {
30 const toNext = nextBatch - now;
31 const hours = Math.floor(toNext / HOUR);
32 const minutes = Math.floor((toNext - hours * HOUR) / MINUTE);
33 const seconds = Math.floor(
34 (toNext - hours * HOUR - minutes * MINUTE) / SECOND
37 return `${padZero(hours)}h ${padZero(minutes)}m ${padZero(seconds)}s`;
40export const isL2 = (dom?: string) => dom === 'l2' || dom === 'spawn';
42export const isL2Spawn = (dom?: string) => dom === 'spawn';
44export const generateInviteWallet = async (point: number, seed: string) => {
45 const ticket = makeDeterministicTicket(point, seed);
46 const inviteWallet = await generateWallet(point, ticket, true);
48 return { ticket, inviteWallet };
51export const spawn = async (
60 ship: _point, //ship that is spawning the planet
65 address: _wallet.address,
66 ship: planet, // ship to spawn
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);
74export const configureKeys = async (
84 ship: point, //ship to configure keys
88 // TODO: do something here?
89 if (Nothing.hasInstance(networkSeed)) {
90 console.log("Network key Error: couldn't derive network keys");
91 // throw new Error("Network key Error: couldn't derive network keys");
94 const seed = Just.hasInstance(networkSeed)
98 const pair = deriveNetworkKeys(seed);
101 encrypt: addHexPrefix(pair.crypt.public),
102 auth: addHexPrefix(pair.auth.public),
103 cryptoSuite: String(CRYPTO_SUITE_VERSION),
104 breach: breach || false,
107 const hash = await api.hashTransaction(nonce, from, 'configureKeys', data);
108 const sig = signTransactionHash(hash, wallet.privateKey);
109 return api.configureKeys(sig, from, wallet.address, data);
112export const transferPointRequest = async (
115 pointToTransfer: Ship,
122 ship: pointToTransfer,
128 reset: reset || false,
130 const hash = await api.hashTransaction(nonce, from, 'transferPoint', data);
131 const sig = signTransactionHash(hash, _wallet.privateKey);
132 return api.transferPoint(sig, from, _wallet.address, data);
135const proxyType = (proxy: Proxy) => {
138 return 'setManagementProxy';
140 return 'setSpawnProxy';
142 return 'setTransferProxy';
144 throw new Error(`Unknown proxyType ${proxy}`);
148const setProxy = async (
150 proxyAddressType: string,
156 switch (proxyAddressType) {
158 return await api.setManagementProxy(sig, from, address, data);
160 return await api.setSpawnProxy(sig, from, address, data);
162 return await api.setTransferProxy(sig, from, address, data);
164 throw new Error(`Unknown proxyType ${proxyAddressType}`);
168export const registerProxyAddress = async (
173 proxyAddressType: string,
181 const proxyData = { address };
182 const proxyHash = await api.hashTransaction(
185 proxyType(proxyAddressType),
192 signTransactionHash(proxyHash, _wallet.privateKey),
199export const reticketL2Point = async () => {};
201export const hasInvite = (point: number) => (invite: Invite) =>
202 invite.planet === point && invite.ticket.length > 0;
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