1import * as ob from 'urbit-ob';
2import { isGalaxy, isPlanet, isStar } from 'lib/utils/point';
3import { eqAddr, isZeroAddress } from 'lib/utils/address';
4import { L1Point } from './L1Point';
5import { Proxy } from '@urbit/roller-api';
6import { DUMMY_L2_ADDRESS } from 'lib/constants';
8export interface Points {
12export type PermissionLevel =
20export const shouldDisplayPermissionLevel = (level: PermissionLevel) =>
21 level === 'manage' || level === 'spawn' || level === 'vote';
23export enum PointField {
27 authenticationKey = 'authenticationKey',
28 continuityNumber = 'continuityNumber',
29 cryptoSuiteVersion = 'cryptoSuiteVersion',
30 encryptionKey = 'encryptionKey',
31 escapeRequested = 'escapeRequested',
32 escapeRequestedTo = 'escapeRequestedTo',
33 hasSponsor = 'hasSponsor',
34 keyRevisionNumber = 'keyRevisionNumber',
35 managementProxy = 'managementProxy',
37 spawnProxy = 'spawnProxy',
39 transferProxy = 'transferProxy',
40 votingProxy = 'votingProxy',
42 isL2Spawn = 'isL2Spawn',
44 isGalaxy = 'isGalaxy',
46 isPlanet = 'isPlanet',
47 isParent = 'isParent',
48 canMigrate = 'canMigrate',
49 networkKeysSet = 'networkKeysSet',
51 isActiveOwner = 'isActiveOwner',
52 isManagementProxy = 'isManagementProxy',
53 isSpawnProxy = 'isSpawnProxy',
54 isVotingProxy = 'isVotingProxy',
55 isTransferProxy = 'isTransferProxy',
56 isManagementProxySet = 'isManagementProxySet',
57 isSpawnProxySet = 'isSpawnProxySet',
58 isVotingProxySet = 'isVotingProxySet',
59 isTransferProxySet = 'isTransferProxySet',
60 canManage = 'canManage',
61 canSpawn = 'canSpawn',
62 canTransfer = 'canTransfer',
64 showInvites = 'showInvites',
67interface PointConstructorParams {
73 isPlaceholder?: boolean;
76export default class Point {
83 authenticationKey: string;
84 continuityNumber: string;
85 cryptoSuiteVersion: string;
86 encryptionKey: string;
87 escapeRequested: boolean;
88 escapeRequestedTo: string;
90 keyRevisionNumber: number;
91 managementProxy: string;
95 transferProxy: string;
106 networkKeysSet: boolean;
107 // usePermissionsForPoint details
109 isActiveOwner: boolean;
110 isManagementProxy: boolean;
111 isSpawnProxy: boolean;
112 isVotingProxy: boolean;
113 isTransferProxy: boolean;
114 isManagementProxySet: boolean;
115 isSpawnProxySet: boolean;
116 isVotingProxySet: boolean;
117 isTransferProxySet: boolean;
121 canTransfer: boolean;
123 showInvites: boolean;
125 isPlaceholder: boolean;
126 ownManageSpawnVote: boolean;
127 shouldDisplay: boolean;
129 permissionLevel: PermissionLevel;
130 displayPermission: boolean;
138 isPlaceholder = false,
139 }: PointConstructorParams) {
141 this.patp = value < 0 ? 'null' : ob.patp(value);
143 this.layer = details.layer || 1;
144 this.l2Quota = l2Quota;
145 this.l2Allowance = l2Allowance;
146 this.isL2Spawn = Boolean(details.isL2Spawn);
147 this.active = details.active;
148 this.authenticationKey = details.authenticationKey;
149 this.continuityNumber = details.continuityNumber;
150 this.cryptoSuiteVersion = details.cryptoSuiteVersion;
151 this.encryptionKey = details.encryptionKey;
152 this.escapeRequested = details.escapeRequested;
153 this.escapeRequestedTo = details.escapeRequestedTo;
154 this.hasSponsor = details.hasSponsor;
155 this.keyRevisionNumber = Number(details.keyRevisionNumber);
156 this.managementProxy = details.managementProxy;
157 this.owner = details.owner;
158 this.spawnProxy = details.spawnProxy;
159 this.sponsor = details.sponsor;
160 this.transferProxy = details.transferProxy;
161 this.votingProxy = details.votingProxy;
162 // Derived details here
163 this.isL2 = this.layer === 2;
164 this.isL1 = this.layer === 1;
165 this.isGalaxy = isGalaxy(value);
166 this.isStar = isStar(value);
167 this.isPlanet = isPlanet(value);
168 this.isParent = !this.isPlanet;
169 this.networkKeysSet = Number(this.keyRevisionNumber) > 0;
170 // usePermissionsForPoint
171 this.isOwner = eqAddr(address, this.owner);
172 this.isActiveOwner = this.isOwner && this.active;
173 this.isManagementProxy = eqAddr(address, this.managementProxy);
174 this.isSpawnProxy = eqAddr(address, this.spawnProxy);
175 this.isVotingProxy = eqAddr(address, this.votingProxy);
176 this.isTransferProxy = eqAddr(address, this.transferProxy);
177 this.permissionLevel = this.isOwner
179 : this.isManagementProxy
185 : this.isTransferProxy
188 this.displayPermission = shouldDisplayPermissionLevel(this.permissionLevel);
189 this.isManagementProxySet = !isZeroAddress(this.managementProxy);
190 this.isSpawnProxySet = !isZeroAddress(this.spawnProxy);
191 this.isVotingProxySet = !isZeroAddress(this.votingProxy);
192 this.isTransferProxySet = !isZeroAddress(this.transferProxy);
193 this.canManage = this.isOwner || this.isManagementProxy;
194 this.canTransfer = this.isOwner || this.isTransferProxy;
195 this.couldSpawn = this.isParent && (this.isOwner || this.isSpawnProxy);
198 (this.isOwner || this.isSpawnProxy) &&
201 this.isGalaxy && this.active && (this.isOwner || this.isVotingProxy);
205 ((this.isGalaxy && !this.isL2Spawn) || this.isStar || this.isPlanet);
206 this.showInvites = this.canManage || this.canSpawn;
207 this.isDefault = value === -1;
208 this.isPlaceholder = isPlaceholder;
209 this.ownManageSpawnVote =
210 !this.isPlaceholder &&
214 this.isManagementProxy ||
216 this.shouldDisplay = this.ownManageSpawnVote || this.isTransferProxy;
218 this.isTransferProxySet &&
219 !this.isTransferProxy &&
221 this.transferProxy !== DUMMY_L2_ADDRESS;
224 equals = (point: Point) => {
225 return Object.values(PointField).reduce(
226 (acc, field) => acc && this[field] === point[field],
231 getChangedField = (point: Point, targetField?: PointField) =>
233 ? this[targetField] !== point[targetField] && targetField
234 : Object.values(PointField).find(field => this[field] !== point[field]);
236 getAddressProxy = (proxyType: Proxy) =>
239 : proxyType === 'manage' && this.isManagementProxy
241 : proxyType === 'spawn' && this.isSpawnProxy
243 : proxyType === 'transfer' && this.isTransferProxy
247 getManagerProxy = () =>
248 this.isOwner ? 'own' : this.isManagementProxy ? 'manage' : undefined;
250 getSpawnProxy = () =>
251 this.isOwner ? 'own' : this.isSpawnProxy ? 'spawn' : undefined;
253 getTransferProxy = () =>
254 this.isOwner ? 'own' : this.isTransferProxy ? 'transfer' : undefined;
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