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';
7export interface Points {
11export enum PointField {
15 authenticationKey = 'authenticationKey',
16 continuityNumber = 'continuityNumber',
17 cryptoSuiteVersion = 'cryptoSuiteVersion',
18 encryptionKey = 'encryptionKey',
19 escapeRequested = 'escapeRequested',
20 escapeRequestedTo = 'escapeRequestedTo',
21 hasSponsor = 'hasSponsor',
22 keyRevisionNumber = 'keyRevisionNumber',
23 managementProxy = 'managementProxy',
25 spawnProxy = 'spawnProxy',
27 transferProxy = 'transferProxy',
28 votingProxy = 'votingProxy',
30 isL2Spawn = 'isL2Spawn',
32 isGalaxy = 'isGalaxy',
34 isPlanet = 'isPlanet',
35 isParent = 'isParent',
36 canMigrate = 'canMigrate',
37 networkKeysSet = 'networkKeysSet',
39 isActiveOwner = 'isActiveOwner',
40 isManagementProxy = 'isManagementProxy',
41 isSpawnProxy = 'isSpawnProxy',
42 isVotingProxy = 'isVotingProxy',
43 isTransferProxy = 'isTransferProxy',
44 isManagementProxySet = 'isManagementProxySet',
45 isSpawnProxySet = 'isSpawnProxySet',
46 isVotingProxySet = 'isVotingProxySet',
47 isTransferProxySet = 'isTransferProxySet',
48 canManage = 'canManage',
49 canSpawn = 'canSpawn',
50 canTransfer = 'canTransfer',
52 showInvites = 'showInvites',
55interface PointConstructorParams {
60 isPlaceholder?: boolean;
63export default class Point {
69 authenticationKey: string;
70 continuityNumber: string;
71 cryptoSuiteVersion: string;
72 encryptionKey: string;
73 escapeRequested: boolean;
74 escapeRequestedTo: string;
76 keyRevisionNumber: string;
77 managementProxy: string;
81 transferProxy: string;
92 networkKeysSet: boolean;
93 // usePermissionsForPoint details
95 isActiveOwner: boolean;
96 isManagementProxy: boolean;
97 isSpawnProxy: boolean;
98 isVotingProxy: boolean;
99 isTransferProxy: boolean;
100 isManagementProxySet: boolean;
101 isSpawnProxySet: boolean;
102 isVotingProxySet: boolean;
103 isTransferProxySet: boolean;
107 canTransfer: boolean;
109 showInvites: boolean;
111 isPlaceholder: boolean;
112 ownManageSpawn: boolean;
113 shouldDisplay: boolean;
121 isPlaceholder = false,
122 }: PointConstructorParams) {
124 this.patp = value < 0 ? 'null' : ob.patp(value);
126 this.layer = details.layer || 1;
127 this.l2Quota = l2Quota;
128 this.isL2Spawn = Boolean(details.isL2Spawn);
129 this.active = details.active;
130 this.authenticationKey = details.authenticationKey;
131 this.continuityNumber = details.continuityNumber;
132 this.cryptoSuiteVersion = details.cryptoSuiteVersion;
133 this.encryptionKey = details.encryptionKey;
134 this.escapeRequested = details.escapeRequested;
135 this.escapeRequestedTo = details.escapeRequestedTo;
136 this.hasSponsor = details.hasSponsor;
137 this.keyRevisionNumber = details.keyRevisionNumber;
138 this.managementProxy = details.managementProxy;
139 this.owner = details.owner;
140 this.spawnProxy = details.spawnProxy;
141 this.sponsor = details.sponsor;
142 this.transferProxy = details.transferProxy;
143 this.votingProxy = details.votingProxy;
144 // Derived details here
145 this.isL2 = this.layer === 2;
146 this.isL1 = this.layer === 1;
147 this.isGalaxy = isGalaxy(value);
148 this.isStar = isStar(value);
149 this.isPlanet = isPlanet(value);
150 this.isParent = !this.isPlanet;
151 this.networkKeysSet = Number(this.keyRevisionNumber) > 0;
152 // usePermissionsForPoint
153 this.isOwner = eqAddr(address, this.owner);
154 this.isActiveOwner = this.isOwner && this.active;
155 this.isManagementProxy = eqAddr(address, this.managementProxy);
156 this.isSpawnProxy = eqAddr(address, this.spawnProxy);
157 this.isVotingProxy = eqAddr(address, this.votingProxy);
158 this.isTransferProxy = eqAddr(address, this.transferProxy);
159 this.isManagementProxySet = !isZeroAddress(this.managementProxy);
160 this.isSpawnProxySet = !isZeroAddress(this.spawnProxy);
161 this.isVotingProxySet = !isZeroAddress(this.votingProxy);
162 this.isTransferProxySet = !isZeroAddress(this.transferProxy);
163 this.canManage = this.isOwner || this.isManagementProxy;
164 this.canTransfer = this.isOwner || this.isTransferProxy;
165 this.couldSpawn = this.isParent && (this.isOwner || this.isSpawnProxy);
168 (this.isOwner || this.isSpawnProxy) &&
171 this.isGalaxy && this.active && (this.isOwner || this.isVotingProxy);
175 ((this.isGalaxy && !this.isL2Spawn) || this.isStar || this.isPlanet);
176 this.showInvites = this.canManage || this.canSpawn;
177 this.isDefault = value === -1;
178 this.isPlaceholder = isPlaceholder;
179 this.ownManageSpawn =
180 !this.isPlaceholder &&
182 (this.isOwner || this.isSpawnProxy || this.isManagementProxy);
183 this.shouldDisplay = this.ownManageSpawn || this.isTransferProxy;
185 this.isTransferProxySet && this.isTransferProxy && this.canManage;
188 equals = (point: Point) => {
189 return Object.values(PointField).reduce(
190 (acc, field) => acc && this[field] === point[field],
195 getChangedField = (point: Point, targetField?: PointField) =>
197 ? this[targetField] !== point[targetField] && targetField
198 : Object.values(PointField).find(field => this[field] !== point[field]);
200 getAddressProxy = (proxyType: Proxy) =>
203 : proxyType === 'manage' && this.isManagementProxy
205 : proxyType === 'spawn' && this.isSpawnProxy
207 : proxyType === 'transfer' && this.isTransferProxy
211 getManagerProxy = () =>
212 this.isOwner ? 'own' : this.isManagementProxy ? 'manage' : undefined;
214 getSpawnProxy = () =>
215 this.isOwner ? 'own' : this.isSpawnProxy ? 'spawn' : undefined;
217 getTransferProxy = () =>
218 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