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 enum PointField {
16 authenticationKey = 'authenticationKey',
17 continuityNumber = 'continuityNumber',
18 cryptoSuiteVersion = 'cryptoSuiteVersion',
19 encryptionKey = 'encryptionKey',
20 escapeRequested = 'escapeRequested',
21 escapeRequestedTo = 'escapeRequestedTo',
22 hasSponsor = 'hasSponsor',
23 keyRevisionNumber = 'keyRevisionNumber',
24 managementProxy = 'managementProxy',
26 spawnProxy = 'spawnProxy',
28 transferProxy = 'transferProxy',
29 votingProxy = 'votingProxy',
31 isL2Spawn = 'isL2Spawn',
33 isGalaxy = 'isGalaxy',
35 isPlanet = 'isPlanet',
36 isParent = 'isParent',
37 canMigrate = 'canMigrate',
38 networkKeysSet = 'networkKeysSet',
40 isActiveOwner = 'isActiveOwner',
41 isManagementProxy = 'isManagementProxy',
42 isSpawnProxy = 'isSpawnProxy',
43 isVotingProxy = 'isVotingProxy',
44 isTransferProxy = 'isTransferProxy',
45 isManagementProxySet = 'isManagementProxySet',
46 isSpawnProxySet = 'isSpawnProxySet',
47 isVotingProxySet = 'isVotingProxySet',
48 isTransferProxySet = 'isTransferProxySet',
49 canManage = 'canManage',
50 canSpawn = 'canSpawn',
51 canTransfer = 'canTransfer',
53 showInvites = 'showInvites',
56interface PointConstructorParams {
61 isPlaceholder?: boolean;
64export default class Point {
70 authenticationKey: string;
71 continuityNumber: string;
72 cryptoSuiteVersion: string;
73 encryptionKey: string;
74 escapeRequested: boolean;
75 escapeRequestedTo: string;
77 keyRevisionNumber: string;
78 managementProxy: string;
82 transferProxy: string;
93 networkKeysSet: boolean;
94 // usePermissionsForPoint details
96 isActiveOwner: boolean;
97 isManagementProxy: boolean;
98 isSpawnProxy: boolean;
99 isVotingProxy: boolean;
100 isTransferProxy: boolean;
101 isManagementProxySet: boolean;
102 isSpawnProxySet: boolean;
103 isVotingProxySet: boolean;
104 isTransferProxySet: boolean;
108 canTransfer: boolean;
110 showInvites: boolean;
112 isPlaceholder: boolean;
113 ownManageSpawn: boolean;
114 shouldDisplay: boolean;
122 isPlaceholder = false,
123 }: PointConstructorParams) {
125 this.patp = value < 0 ? 'null' : ob.patp(value);
127 this.layer = details.layer || 1;
128 this.l2Quota = l2Quota;
129 this.isL2Spawn = Boolean(details.isL2Spawn);
130 this.active = details.active;
131 this.authenticationKey = details.authenticationKey;
132 this.continuityNumber = details.continuityNumber;
133 this.cryptoSuiteVersion = details.cryptoSuiteVersion;
134 this.encryptionKey = details.encryptionKey;
135 this.escapeRequested = details.escapeRequested;
136 this.escapeRequestedTo = details.escapeRequestedTo;
137 this.hasSponsor = details.hasSponsor;
138 this.keyRevisionNumber = details.keyRevisionNumber;
139 this.managementProxy = details.managementProxy;
140 this.owner = details.owner;
141 this.spawnProxy = details.spawnProxy;
142 this.sponsor = details.sponsor;
143 this.transferProxy = details.transferProxy;
144 this.votingProxy = details.votingProxy;
145 // Derived details here
146 this.isL2 = this.layer === 2;
147 this.isL1 = this.layer === 1;
148 this.isGalaxy = isGalaxy(value);
149 this.isStar = isStar(value);
150 this.isPlanet = isPlanet(value);
151 this.isParent = !this.isPlanet;
152 this.networkKeysSet = Number(this.keyRevisionNumber) > 0;
153 // usePermissionsForPoint
154 this.isOwner = eqAddr(address, this.owner);
155 this.isActiveOwner = this.isOwner && this.active;
156 this.isManagementProxy = eqAddr(address, this.managementProxy);
157 this.isSpawnProxy = eqAddr(address, this.spawnProxy);
158 this.isVotingProxy = eqAddr(address, this.votingProxy);
159 this.isTransferProxy = eqAddr(address, this.transferProxy);
160 this.isManagementProxySet = !isZeroAddress(this.managementProxy);
161 this.isSpawnProxySet = !isZeroAddress(this.spawnProxy);
162 this.isVotingProxySet = !isZeroAddress(this.votingProxy);
163 this.isTransferProxySet = !isZeroAddress(this.transferProxy);
164 this.canManage = this.isOwner || this.isManagementProxy;
165 this.canTransfer = this.isOwner || this.isTransferProxy;
166 this.couldSpawn = this.isParent && (this.isOwner || this.isSpawnProxy);
169 (this.isOwner || this.isSpawnProxy) &&
172 this.isGalaxy && this.active && (this.isOwner || this.isVotingProxy);
176 ((this.isGalaxy && !this.isL2Spawn) || this.isStar || this.isPlanet);
177 this.showInvites = this.canManage || this.canSpawn;
178 this.isDefault = value === -1;
179 this.isPlaceholder = isPlaceholder;
180 this.ownManageSpawn =
181 !this.isPlaceholder &&
183 (this.isOwner || this.isSpawnProxy || this.isManagementProxy);
184 this.shouldDisplay = this.ownManageSpawn || this.isTransferProxy;
186 this.isTransferProxySet &&
187 !this.isTransferProxy &&
189 this.transferProxy !== DUMMY_L2_ADDRESS;
192 equals = (point: Point) => {
193 return Object.values(PointField).reduce(
194 (acc, field) => acc && this[field] === point[field],
199 getChangedField = (point: Point, targetField?: PointField) =>
201 ? this[targetField] !== point[targetField] && targetField
202 : Object.values(PointField).find(field => this[field] !== point[field]);
204 getAddressProxy = (proxyType: Proxy) =>
207 : proxyType === 'manage' && this.isManagementProxy
209 : proxyType === 'spawn' && this.isSpawnProxy
211 : proxyType === 'transfer' && this.isTransferProxy
215 getManagerProxy = () =>
216 this.isOwner ? 'own' : this.isManagementProxy ? 'manage' : undefined;
218 getSpawnProxy = () =>
219 this.isOwner ? 'own' : this.isSpawnProxy ? 'spawn' : undefined;
221 getTransferProxy = () =>
222 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