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 {
72 isPlaceholder?: boolean;
75export default class Point {
81 authenticationKey: string;
82 continuityNumber: string;
83 cryptoSuiteVersion: string;
84 encryptionKey: string;
85 escapeRequested: boolean;
86 escapeRequestedTo: string;
88 keyRevisionNumber: number;
89 managementProxy: string;
93 transferProxy: string;
104 networkKeysSet: boolean;
105 // usePermissionsForPoint details
107 isActiveOwner: boolean;
108 isManagementProxy: boolean;
109 isSpawnProxy: boolean;
110 isVotingProxy: boolean;
111 isTransferProxy: boolean;
112 isManagementProxySet: boolean;
113 isSpawnProxySet: boolean;
114 isVotingProxySet: boolean;
115 isTransferProxySet: boolean;
119 canTransfer: boolean;
121 showInvites: boolean;
123 isPlaceholder: boolean;
124 ownManageSpawn: boolean;
125 shouldDisplay: boolean;
127 permissionLevel: PermissionLevel;
128 displayPermission: boolean;
135 isPlaceholder = false,
136 }: PointConstructorParams) {
138 this.patp = value < 0 ? 'null' : ob.patp(value);
140 this.layer = details.layer || 1;
141 this.l2Quota = l2Quota;
142 this.isL2Spawn = Boolean(details.isL2Spawn);
143 this.active = details.active;
144 this.authenticationKey = details.authenticationKey;
145 this.continuityNumber = details.continuityNumber;
146 this.cryptoSuiteVersion = details.cryptoSuiteVersion;
147 this.encryptionKey = details.encryptionKey;
148 this.escapeRequested = details.escapeRequested;
149 this.escapeRequestedTo = details.escapeRequestedTo;
150 this.hasSponsor = details.hasSponsor;
151 this.keyRevisionNumber = Number(details.keyRevisionNumber);
152 this.managementProxy = details.managementProxy;
153 this.owner = details.owner;
154 this.spawnProxy = details.spawnProxy;
155 this.sponsor = details.sponsor;
156 this.transferProxy = details.transferProxy;
157 this.votingProxy = details.votingProxy;
158 // Derived details here
159 this.isL2 = this.layer === 2;
160 this.isL1 = this.layer === 1;
161 this.isGalaxy = isGalaxy(value);
162 this.isStar = isStar(value);
163 this.isPlanet = isPlanet(value);
164 this.isParent = !this.isPlanet;
165 this.networkKeysSet = Number(this.keyRevisionNumber) > 0;
166 // usePermissionsForPoint
167 this.isOwner = eqAddr(address, this.owner);
168 this.isActiveOwner = this.isOwner && this.active;
169 this.isManagementProxy = eqAddr(address, this.managementProxy);
170 this.isSpawnProxy = eqAddr(address, this.spawnProxy);
171 this.isVotingProxy = eqAddr(address, this.votingProxy);
172 this.isTransferProxy = eqAddr(address, this.transferProxy);
173 this.permissionLevel = this.isOwner
175 : this.isManagementProxy
181 : this.isTransferProxy
184 this.displayPermission = shouldDisplayPermissionLevel(this.permissionLevel);
185 this.isManagementProxySet = !isZeroAddress(this.managementProxy);
186 this.isSpawnProxySet = !isZeroAddress(this.spawnProxy);
187 this.isVotingProxySet = !isZeroAddress(this.votingProxy);
188 this.isTransferProxySet = !isZeroAddress(this.transferProxy);
189 this.canManage = this.isOwner || this.isManagementProxy;
190 this.canTransfer = this.isOwner || this.isTransferProxy;
191 this.couldSpawn = this.isParent && (this.isOwner || this.isSpawnProxy);
194 (this.isOwner || this.isSpawnProxy) &&
197 this.isGalaxy && this.active && (this.isOwner || this.isVotingProxy);
201 ((this.isGalaxy && !this.isL2Spawn) || this.isStar || this.isPlanet);
202 this.showInvites = this.canManage || this.canSpawn;
203 this.isDefault = value === -1;
204 this.isPlaceholder = isPlaceholder;
205 this.ownManageSpawn =
206 !this.isPlaceholder &&
208 (this.isOwner || this.isSpawnProxy || this.isManagementProxy);
209 this.shouldDisplay = this.ownManageSpawn || this.isTransferProxy;
211 this.isTransferProxySet &&
212 !this.isTransferProxy &&
214 this.transferProxy !== DUMMY_L2_ADDRESS;
217 equals = (point: Point) => {
218 return Object.values(PointField).reduce(
219 (acc, field) => acc && this[field] === point[field],
224 getChangedField = (point: Point, targetField?: PointField) =>
226 ? this[targetField] !== point[targetField] && targetField
227 : Object.values(PointField).find(field => this[field] !== point[field]);
229 getAddressProxy = (proxyType: Proxy) =>
232 : proxyType === 'manage' && this.isManagementProxy
234 : proxyType === 'spawn' && this.isSpawnProxy
236 : proxyType === 'transfer' && this.isTransferProxy
240 getManagerProxy = () =>
241 this.isOwner ? 'own' : this.isManagementProxy ? 'manage' : undefined;
243 getSpawnProxy = () =>
244 this.isOwner ? 'own' : this.isSpawnProxy ? 'spawn' : undefined;
246 getTransferProxy = () =>
247 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