1import { Just, Nothing } from 'folktale/maybe';
2import { Invite } from 'lib/types/Invite';
3import { signTransactionHash } from 'lib/authToken';
4import { randomHex } from 'web3-utils';
16} from '@urbit/roller-api';
18import { deriveNetworkKeys, CRYPTO_SUITE_VERSION } from 'lib/keys';
19import { addHexPrefix } from 'lib/utils/address';
20import { makeDeterministicTicket, generateWallet } from 'lib/walletgen';
22export const SECOND = 1000;
23export const MINUTE = SECOND * 60;
24export const HOUR = MINUTE * 60;
26export const padZero = (amount: number) =>
27 `${amount < 10 && amount > 0 ? '0' : ''}${amount}`;
29export const hasPoint = (point: number) => (invite: Invite) =>
30 invite.planet === point;
32export const getTimeToNextBatch = (nextBatch: number, now: number) => {
33 const toNext = Math.max(nextBatch - now, 0);
34 const hours = Math.floor(toNext / HOUR);
35 const minutes = Math.floor((toNext - hours * HOUR) / MINUTE);
36 const seconds = Math.floor(
37 (toNext - hours * HOUR - minutes * MINUTE) / SECOND
40 return `${padZero(hours)}h ${padZero(minutes)}m ${padZero(seconds)}s`;
43export const isL2 = (dom?: string) => dom === 'l2' || dom === 'spawn';
45export const isL2Spawn = (dom?: string) => dom === 'spawn';
47export const generateInviteWallet = async (point: number, seed: string) => {
48 const ticket = makeDeterministicTicket(point, seed);
49 const inviteWallet = await generateWallet(point, ticket, true);
51 return { ticket, inviteWallet };
54export const spawn = async (
63 ship: _point, //ship that is spawning the planet
68 address: _wallet.address,
69 ship: planet, // ship to spawn
72 const hash = await api.hashTransaction(nonce, from, 'spawn', data);
73 const sSig = signTransactionHash(hash, _wallet.privateKey);
74 return api.spawn(sSig, from, _wallet.address, data);
77export const configureKeys = async (
87 ship: point, //ship to configure keys
91 // TODO: do something here?
92 if (Nothing.hasInstance(networkSeed)) {
93 console.log("Network key Error: couldn't derive network keys");
94 // throw new Error("Network key Error: couldn't derive network keys");
97 const seed = Just.hasInstance(networkSeed)
101 const pair = deriveNetworkKeys(seed);
104 encrypt: addHexPrefix(pair.crypt.public),
105 auth: addHexPrefix(pair.auth.public),
106 cryptoSuite: String(CRYPTO_SUITE_VERSION),
107 breach: breach || false,
110 const hash = await api.hashTransaction(nonce, from, 'configureKeys', data);
111 const sig = signTransactionHash(hash, wallet.privateKey);
112 return api.configureKeys(sig, from, wallet.address, data);
115export const transferPointRequest = async (
118 pointToTransfer: Ship,
125 ship: pointToTransfer,
131 reset: reset || false,
133 const hash = await api.hashTransaction(nonce, from, 'transferPoint', data);
134 const sig = signTransactionHash(hash, _wallet.privateKey);
135 return api.transferPoint(sig, from, _wallet.address, data);
138const proxyType = (proxy: Proxy) => {
141 return 'setManagementProxy';
143 return 'setSpawnProxy';
145 return 'setTransferProxy';
147 throw new Error(`Unknown proxyType ${proxy}`);
151const setProxy = async (
153 proxyAddressType: string,
159 switch (proxyAddressType) {
161 return await api.setManagementProxy(sig, from, address, data);
163 return await api.setSpawnProxy(sig, from, address, data);
165 return await api.setTransferProxy(sig, from, address, data);
167 throw new Error(`Unknown proxyType ${proxyAddressType}`);
171export const registerProxyAddress = async (
176 proxyAddressType: string,
184 const proxyData = { address };
185 const proxyHash = await api.hashTransaction(
188 proxyType(proxyAddressType),
195 signTransactionHash(proxyHash, _wallet.privateKey),
202export const reticketL2Point = async () => {};
204export const hasInvite = (point: number) => (invite: Invite) =>
205 invite.planet === point && invite.ticket.length > 0;
207function isSpawn(tx: L2Data | undefined): tx is SpawnParams {
208 return (tx as SpawnParams) !== undefined;
211function isShipNumber(ship: number | string | undefined): ship is number {
212 return (ship as number) !== undefined;
215export const getPendingSpawns = (pendingTxs: PendingTransaction[]) =>
216 pendingTxs.reduce((acc, pending) => {
217 return isSpawn(pending.rawTx?.tx) &&
218 isShipNumber(pending.rawTx?.tx.data.ship)
219 ? acc.add(pending.rawTx?.tx.data.ship!)
221 }, new Set<number>());
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