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';
16 deriveNetworkSeedFromUrbitWallet,
20import { addHexPrefix } from 'lib/utils/address';
21import { makeDeterministicTicket, generateWallet } from 'lib/walletgen';
23export const SECOND = 1000;
24export const MINUTE = SECOND * 60;
25export const HOUR = MINUTE * 60;
27export const padZero = (amount: number) =>
28 `${amount < 10 && amount > 0 ? '0' : ''}${amount}`;
30export const getTimeToNextBatch = (nextBatch: number, now: number) => {
31 const toNext = nextBatch - now;
32 const hours = Math.floor(toNext / HOUR);
33 const minutes = Math.floor((toNext - hours * HOUR) / MINUTE);
34 const seconds = Math.floor(
35 (toNext - hours * HOUR - minutes * MINUTE) / SECOND
38 return `${padZero(hours)}h ${padZero(minutes)}m ${padZero(seconds)}s`;
41export const isL2 = (dom?: string) => dom === 'l2' || dom === 'spawn';
43export const generateInviteWallet = async (point: number, seed: string) => {
44 const ticket = makeDeterministicTicket(point, seed);
45 const inviteWallet = await generateWallet(point, ticket, true);
47 return { ticket, inviteWallet };
50export const spawn = async (
59 ship: _point, //ship that is spawning the planet
64 address: _wallet.address,
65 ship: planet, // ship to spawn
68 const hash = await api.hashTransaction(nonce, from, 'spawn', data);
69 const sSig = signTransactionHash(hash, _wallet.privateKey);
70 return api.spawn(sSig, from, _wallet.address, data);
73export const configureKeys = async (
82 ship: _point, //ship to configure keys
86 const networkSeed = await deriveNetworkSeedFromUrbitWallet(urbitWallet, 1);
87 // TODO: do something here?
88 if (Nothing.hasInstance(networkSeed)) {
89 console.log("Network key Error: couldn't derive network keys");
90 // throw new Error("Network key Error: couldn't derive network keys");
93 const seed = Just.hasInstance(networkSeed)
97 const pair = deriveNetworkKeys(seed);
100 encrypt: addHexPrefix(pair.crypt.public),
101 auth: addHexPrefix(pair.auth.public),
102 cryptoSuite: String(CRYPTO_SUITE_VERSION),
106 const hash = await api.hashTransaction(nonce, from, 'configureKeys', data);
107 const sig = signTransactionHash(hash, _wallet.privateKey);
108 return api.configureKeys(sig, from, _wallet.address, data);
111export const transferPoint = async (
120 ship: _point, // ship to transfer
129 const hash = await api.hashTransaction(nonce, from, 'transferPoint', data);
130 const sig = signTransactionHash(hash, _wallet.privateKey);
131 return api.transferPoint(sig, from, _wallet.address, data);
134const proxyType = (proxy: Proxy) => {
137 return 'setManagementProxy';
139 return 'setSpawnProxy';
141 return 'setTransferProxy';
143 throw new Error(`Unknown proxyType ${proxy}`);
147export const registerProxyAddress = async (
152 proxyAddressType: string,
160 const managementData = { address };
161 const managementHash = await api.hashTransaction(
164 proxyType(proxyAddressType),
170 signTransactionHash(managementHash, _wallet.privateKey),
177const setProxy = async (
179 proxyAddressType: string,
185 switch (proxyAddressType) {
187 return await api.setManagementProxy(sig, from, address, data);
189 return await api.setSpawnProxy(sig, from, address, data);
191 return await api.setTrasferProxy(sig, from, address, data);
193 throw new Error(`Unknown proxyType ${proxyAddressType}`);
197export const hasPoint = (point: number) => (invite: Invite) =>
198 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