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 (
82 nextRevision?: number,
83 customNetworkSeed?: string
86 ship: _point, //ship to configure keys
92 (await deriveNetworkSeedFromUrbitWallet(urbitWallet, nextRevision || 1));
94 // TODO: do something here?
95 if (Nothing.hasInstance(networkSeed)) {
96 console.log("Network key Error: couldn't derive network keys");
97 // throw new Error("Network key Error: couldn't derive network keys");
100 const seed = Just.hasInstance(networkSeed)
104 const pair = deriveNetworkKeys(seed);
107 encrypt: addHexPrefix(pair.crypt.public),
108 auth: addHexPrefix(pair.auth.public),
109 cryptoSuite: String(CRYPTO_SUITE_VERSION),
113 const hash = await api.hashTransaction(nonce, from, 'configureKeys', data);
114 const sig = signTransactionHash(hash, _wallet.privateKey);
115 return api.configureKeys(sig, from, _wallet.address, data);
118export const transferPointRequest = async (
128 ship: _point, // ship to transfer
134 reset: reset || false,
136 const hash = await api.hashTransaction(nonce, from, 'transferPoint', data);
137 const sig = signTransactionHash(hash, _wallet.privateKey);
138 return api.transferPoint(sig, from, _wallet.address, data);
141const proxyType = (proxy: Proxy) => {
144 return 'setManagementProxy';
146 return 'setSpawnProxy';
148 return 'setTransferProxy';
150 throw new Error(`Unknown proxyType ${proxy}`);
154export const registerProxyAddress = async (
159 proxyAddressType: string,
167 const managementData = { address };
168 const managementHash = await api.hashTransaction(
171 proxyType(proxyAddressType),
177 signTransactionHash(managementHash, _wallet.privateKey),
184const setProxy = async (
186 proxyAddressType: string,
192 switch (proxyAddressType) {
194 return await api.setManagementProxy(sig, from, address, data);
196 return await api.setSpawnProxy(sig, from, address, data);
198 return await api.setTrasferProxy(sig, from, address, data);
200 throw new Error(`Unknown proxyType ${proxyAddressType}`);
204export const hasPoint = (point: number) => (invite: Invite) =>
205 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