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;
118 isPlaceholder = false,
119 }: PointConstructorParams) {
121 this.patp = value < 0 ? 'null' : ob.patp(value);
123 this.layer = details.layer || 1;
124 this.l2Quota = l2Quota;
125 this.isL2Spawn = Boolean(details.isL2Spawn);
126 this.active = details.active;
127 this.authenticationKey = details.authenticationKey;
128 this.continuityNumber = details.continuityNumber;
129 this.cryptoSuiteVersion = details.cryptoSuiteVersion;
130 this.encryptionKey = details.encryptionKey;
131 this.escapeRequested = details.escapeRequested;
132 this.escapeRequestedTo = details.escapeRequestedTo;
133 this.hasSponsor = details.hasSponsor;
134 this.keyRevisionNumber = details.keyRevisionNumber;
135 this.managementProxy = details.managementProxy;
136 this.owner = details.owner;
137 this.spawnProxy = details.spawnProxy;
138 this.sponsor = details.sponsor;
139 this.transferProxy = details.transferProxy;
140 this.votingProxy = details.votingProxy;
141 // Derived details here
142 this.isL2 = this.layer === 2;
143 this.isL1 = this.layer === 1;
144 this.isGalaxy = isGalaxy(value);
145 this.isStar = isStar(value);
146 this.isPlanet = isPlanet(value);
147 this.isParent = !this.isPlanet;
148 this.networkKeysSet = Number(this.keyRevisionNumber) > 0;
149 // usePermissionsForPoint
150 this.isOwner = eqAddr(address, this.owner);
151 this.isActiveOwner = this.isOwner && this.active;
152 this.isManagementProxy = eqAddr(address, this.managementProxy);
153 this.isSpawnProxy = eqAddr(address, this.spawnProxy);
154 this.isVotingProxy = eqAddr(address, this.votingProxy);
155 this.isTransferProxy = eqAddr(address, this.transferProxy);
156 this.isManagementProxySet = !isZeroAddress(this.managementProxy);
157 this.isSpawnProxySet = !isZeroAddress(this.spawnProxy);
158 this.isVotingProxySet = !isZeroAddress(this.votingProxy);
159 this.isTransferProxySet = !isZeroAddress(this.transferProxy);
160 this.canManage = this.isOwner || this.isManagementProxy;
161 this.canTransfer = this.isOwner || this.isTransferProxy;
162 this.couldSpawn = this.isParent && (this.isOwner || this.isSpawnProxy);
165 (this.isOwner || this.isSpawnProxy) &&
168 this.isGalaxy && this.active && (this.isOwner || this.isVotingProxy);
172 ((this.isGalaxy && !this.isL2Spawn) || this.isStar || this.isPlanet);
173 this.showInvites = this.canManage || this.canSpawn;
174 this.isDefault = value === -1;
175 this.isPlaceholder = isPlaceholder;
178 equals = (point: Point) => {
179 return Object.values(PointField).reduce(
180 (acc, field) => acc && this[field] === point[field],
185 getChangedField = (point: Point, targetField?: PointField) =>
187 ? this[targetField] !== point[targetField] && targetField
188 : Object.values(PointField).find(field => this[field] !== point[field]);
190 getAddressProxy = (proxyType: Proxy) =>
193 : proxyType === 'manage' && this.isManagementProxy
195 : proxyType === 'spawn' && this.isSpawnProxy
197 : proxyType === 'transfer' && this.isTransferProxy
201 getManagerProxy = () =>
202 this.isOwner ? 'own' : this.isManagementProxy ? 'manage' : undefined;
204 getSpawnProxy = () =>
205 this.isOwner ? 'own' : this.isSpawnProxy ? 'spawn' : undefined;
207 getTransferProxy = () =>
208 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