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 isL2Spawn = (dom?: string) => dom === 'spawn';
45export const generateInviteWallet = async (point: number, seed: string) => {
46 const ticket = makeDeterministicTicket(point, seed);
47 const inviteWallet = await generateWallet(point, ticket, true);
49 return { ticket, inviteWallet };
52export const spawn = async (
61 ship: _point, //ship that is spawning the planet
66 address: _wallet.address,
67 ship: planet, // ship to spawn
70 const hash = await api.hashTransaction(nonce, from, 'spawn', data);
71 const sSig = signTransactionHash(hash, _wallet.privateKey);
72 return api.spawn(sSig, from, _wallet.address, data);
75export const configureKeys = async (
84 ship: _point, //ship to configure keys
88 const networkSeed = await deriveNetworkSeedFromUrbitWallet(urbitWallet, 1);
89 // TODO: do something here?
90 if (Nothing.hasInstance(networkSeed)) {
91 console.log("Network key Error: couldn't derive network keys");
92 // throw new Error("Network key Error: couldn't derive network keys");
95 const seed = Just.hasInstance(networkSeed)
99 const pair = deriveNetworkKeys(seed);
102 encrypt: addHexPrefix(pair.crypt.public),
103 auth: addHexPrefix(pair.auth.public),
104 cryptoSuite: String(CRYPTO_SUITE_VERSION),
108 const hash = await api.hashTransaction(nonce, from, 'configureKeys', data);
109 const sig = signTransactionHash(hash, _wallet.privateKey);
110 return api.configureKeys(sig, from, _wallet.address, data);
113export const transferPoint = async (
122 ship: _point, // ship to transfer
131 const hash = await api.hashTransaction(nonce, from, 'transferPoint', data);
132 const sig = signTransactionHash(hash, _wallet.privateKey);
133 return api.transferPoint(sig, from, _wallet.address, data);
136const proxyType = (proxy: Proxy) => {
139 return 'setManagementProxy';
141 return 'setSpawnProxy';
143 return 'setTransferProxy';
145 throw new Error(`Unknown proxyType ${proxy}`);
149export const registerProxyAddress = async (
154 proxyAddressType: string,
162 const managementData = { address };
163 const managementHash = await api.hashTransaction(
166 proxyType(proxyAddressType),
172 signTransactionHash(managementHash, _wallet.privateKey),
179const setProxy = async (
181 proxyAddressType: string,
187 switch (proxyAddressType) {
189 return await api.setManagementProxy(sig, from, address, data);
191 return await api.setSpawnProxy(sig, from, address, data);
193 return await api.setTrasferProxy(sig, from, address, data);
195 throw new Error(`Unknown proxyType ${proxyAddressType}`);
199export const hasPoint = (point: number) => (invite: Invite) =>
200 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