@ibgib/space-gib 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -0
- package/dist/client/bootstrap.mjs +31 -31
- package/dist/client/bootstrap.mjs.map +3 -3
- package/dist/client/chunk-DBHMHCGD.mjs +2341 -0
- package/dist/client/{chunk-SMOZ2D5E.mjs.map → chunk-DBHMHCGD.mjs.map} +4 -4
- package/dist/client/chunk-SUQ5QJH4.mjs +42 -0
- package/dist/client/chunk-SUQ5QJH4.mjs.map +7 -0
- package/dist/client/index.mjs +1 -1
- package/dist/client/script.mjs +1 -1
- package/dist/server/server.mjs +1561 -179
- package/dist/server/server.mjs.map +4 -4
- package/package.json +5 -5
- package/space-gib.localhost-1783713259760.log +45 -0
- package/src/client/AUTO-GENERATED-version.mts +1 -1
- package/src/client/api/space-gib-api-bridge.mts +7 -2
- package/src/client/bootstrap.mts +9 -0
- package/src/client/components/identity-header/identity-header.mts +43 -26
- package/src/client/components/identity-manager/identity-manager.css +57 -392
- package/src/client/components/identity-manager/identity-manager.html +0 -114
- package/src/client/components/identity-manager/identity-manager.mts +356 -543
- package/src/client/components/keystone-creator/keystone-creator.mts +4 -3
- package/src/client/components/keystone-details/keystone-details.css +569 -0
- package/src/client/components/keystone-details/keystone-details.html +127 -0
- package/src/client/components/keystone-details/keystone-details.mts +1013 -0
- package/src/client/components/keystone-scrubber/SCRUBBER_IMPLEMENTATION.md +33 -0
- package/src/client/components/keystone-scrubber/keystone-scrubber.css +46 -0
- package/src/client/components/keystone-scrubber/keystone-scrubber.html +15 -0
- package/src/client/components/keystone-scrubber/keystone-scrubber.mts +356 -0
- package/src/client/ui/shell/space-gib-shell-service.mts +4 -0
- package/src/server/path-constants.mts +12 -0
- package/src/server/serve-gib/handlers/api/keystone/keystone-evolve.handler.mts +33 -0
- package/src/server/serve-gib/handlers/api/keystone/sso-config.handler.mts +66 -0
- package/src/server/serve-gib/handlers/api/keystone/sso-link.handler.mts +140 -0
- package/src/server/serve-gib/handlers/api/keystone/sso-login.handler.mts +190 -0
- package/src/server/server.mts +6 -0
- package/dist/client/chunk-734MMI4C.mjs +0 -42
- package/dist/client/chunk-734MMI4C.mjs.map +0 -7
- package/dist/client/chunk-SMOZ2D5E.mjs +0 -2049
|
@@ -0,0 +1,1013 @@
|
|
|
1
|
+
import styleCss from "../../style.css";
|
|
2
|
+
import thisCss from "./keystone-details.css";
|
|
3
|
+
import thisHtml from "./keystone-details.html";
|
|
4
|
+
|
|
5
|
+
import { extractErrorMsg, pretty } from "@ibgib/helper-gib/dist/helpers/utils-helper.mjs";
|
|
6
|
+
import { IbGibAddr } from "@ibgib/ts-gib/dist/types.mjs";
|
|
7
|
+
import { IbGib_V1 } from "@ibgib/ts-gib/dist/V1/types.mjs";
|
|
8
|
+
import { getIbAndGib, getIbGibAddr } from "@ibgib/ts-gib/dist/helper.mjs";
|
|
9
|
+
import { getGibInfo } from "@ibgib/ts-gib/dist/V1/transforms/transform-helper.mjs";
|
|
10
|
+
import { KeystoneService_V1 } from "@ibgib/core-gib/dist/keystone/keystone-service-v1.mjs";
|
|
11
|
+
import { KeystoneIbGib_V1 } from "@ibgib/core-gib/dist/keystone/keystone-types.mjs";
|
|
12
|
+
import {
|
|
13
|
+
IbGibDynamicComponentMetaBase, IbGibDynamicComponentInstanceBase,
|
|
14
|
+
} from "@ibgib/web-gib/dist/ui/component/ibgib-dynamic-component-bases.mjs";
|
|
15
|
+
import {
|
|
16
|
+
ElementsBase, IbGibDynamicComponentInstance,
|
|
17
|
+
IbGibDynamicComponentInstanceInitOpts,
|
|
18
|
+
} from "@ibgib/web-gib/dist/ui/component/component-types.mjs";
|
|
19
|
+
import { EVENT_IBGIB_IDENTITY_REQUEST_CHANGE, EVENT_IBGIB_IDENTITY_CHANGED } from "@ibgib/web-gib/dist/ui/ui-constants.mjs";
|
|
20
|
+
import { spaceGibApiBridge } from "../../api/space-gib-api-bridge.mjs";
|
|
21
|
+
import { updateSpecialIndex } from "@ibgib/core-gib/dist/timeline/timeline-api.mjs";
|
|
22
|
+
import { toDto } from "@ibgib/core-gib/dist/common/other/ibgib-helper.mjs";
|
|
23
|
+
|
|
24
|
+
import { GLOBAL_LOG_A_LOT, APP_CONFIG, } from "../../constants.mjs";
|
|
25
|
+
import { getComponentCtorArg, getIbGibGlobalThis_SpaceGib } from "../../helpers.web.mjs";
|
|
26
|
+
import { devLog } from "../../dev-tools.mjs";
|
|
27
|
+
import { promptForSecret } from "@ibgib/web-gib/dist/helpers.web.mjs";
|
|
28
|
+
import { isSsoProviderLinked } from "@ibgib/web-gib/dist/identity/sso/sso-helpers.mjs";
|
|
29
|
+
|
|
30
|
+
const logalot = GLOBAL_LOG_A_LOT || true;
|
|
31
|
+
|
|
32
|
+
export const KEYSTONE_DETAILS_COMPONENT_NAME = 'ibgib-keystone-details';
|
|
33
|
+
|
|
34
|
+
export class KeystoneDetailsComponentMeta extends IbGibDynamicComponentMetaBase {
|
|
35
|
+
protected override lc: string = `[KeystoneDetailsComponentMeta]`;
|
|
36
|
+
|
|
37
|
+
routeRegExp?: RegExp = new RegExp(`^${KEYSTONE_DETAILS_COMPONENT_NAME}$`);
|
|
38
|
+
componentName = KEYSTONE_DETAILS_COMPONENT_NAME;
|
|
39
|
+
|
|
40
|
+
constructor() {
|
|
41
|
+
super(getComponentCtorArg());
|
|
42
|
+
if (!customElements.get(this.componentName)) {
|
|
43
|
+
customElements.define(this.componentName, KeystoneDetailsComponentInstance);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async createInstance({
|
|
48
|
+
path,
|
|
49
|
+
ibGibAddr
|
|
50
|
+
}: {
|
|
51
|
+
path: string;
|
|
52
|
+
ibGibAddr: IbGibAddr;
|
|
53
|
+
}): Promise<IbGibDynamicComponentInstance> {
|
|
54
|
+
const lc = `${this.lc}[${this.createInstance.name}]`;
|
|
55
|
+
const component = document.createElement(this.componentName) as KeystoneDetailsComponentInstance;
|
|
56
|
+
await component.initialize({
|
|
57
|
+
ibGibAddr,
|
|
58
|
+
meta: this,
|
|
59
|
+
html: thisHtml,
|
|
60
|
+
css: [styleCss, thisCss],
|
|
61
|
+
});
|
|
62
|
+
return component;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
interface KeystoneDetailsElements extends ElementsBase {
|
|
67
|
+
identityDetailsViewEl: HTMLDivElement;
|
|
68
|
+
identityAddrEl: HTMLElement;
|
|
69
|
+
identityGenEl: HTMLElement;
|
|
70
|
+
identityTimestampEl: HTMLElement;
|
|
71
|
+
identityUuidEl: HTMLElement;
|
|
72
|
+
identityNameEl: HTMLElement;
|
|
73
|
+
identityDescriptionEl: HTMLElement;
|
|
74
|
+
identityFrameDetailsEl: HTMLPreElement;
|
|
75
|
+
identityAggrDetailsEl: HTMLPreElement;
|
|
76
|
+
|
|
77
|
+
poolsContainerEl: HTMLDivElement;
|
|
78
|
+
btnVerifyChainEl: HTMLButtonElement;
|
|
79
|
+
btnSetActiveEl: HTMLButtonElement;
|
|
80
|
+
verificationStatusEl: HTMLDivElement;
|
|
81
|
+
rawAccordionHeaderEl: HTMLDivElement;
|
|
82
|
+
rawAccordionContentEl: HTMLDivElement;
|
|
83
|
+
rawKeystoneJsonEl: HTMLPreElement;
|
|
84
|
+
delegatesCardEl: HTMLDivElement;
|
|
85
|
+
delegatesListEl: HTMLTableSectionElement;
|
|
86
|
+
historicalWarningBannerEl: HTMLDivElement;
|
|
87
|
+
containerEl: HTMLDivElement;
|
|
88
|
+
ssoLinkCardEl: HTMLDivElement;
|
|
89
|
+
btnLinkGoogleEl: HTMLDivElement;
|
|
90
|
+
btnLinkGithubEl: HTMLDivElement;
|
|
91
|
+
ssoStatusMsgEl: HTMLDivElement;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export class KeystoneDetailsComponentInstance
|
|
95
|
+
extends IbGibDynamicComponentInstanceBase<KeystoneIbGib_V1, KeystoneDetailsElements>
|
|
96
|
+
implements IbGibDynamicComponentInstance<KeystoneIbGib_V1, KeystoneDetailsElements> {
|
|
97
|
+
|
|
98
|
+
protected override lc: string = `[KeystoneDetailsComponentInstance]`;
|
|
99
|
+
|
|
100
|
+
private staticIbGib: KeystoneIbGib_V1 | undefined;
|
|
101
|
+
|
|
102
|
+
override get ibGib(): KeystoneIbGib_V1 | undefined {
|
|
103
|
+
return this.staticIbGib;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private globalActiveAddr: string | null = null;
|
|
107
|
+
private isHistoricalFrame: boolean = false;
|
|
108
|
+
private _onIdentityChanged: ((e: any) => void) | null = null;
|
|
109
|
+
private keystoneCache: Map<string, { username: string, description: string, isPrimary: boolean, n: number }> = new Map();
|
|
110
|
+
|
|
111
|
+
constructor() {
|
|
112
|
+
super();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
override async initialize(opts: IbGibDynamicComponentInstanceInitOpts): Promise<void> {
|
|
116
|
+
const lc = `${this.lc}[${this.initialize.name}]`;
|
|
117
|
+
try {
|
|
118
|
+
if (logalot) { console.log(`${lc} starting... (I: 4c9328643a18e56b56e57292c87bd226)`); }
|
|
119
|
+
|
|
120
|
+
await super.initialize(opts);
|
|
121
|
+
// await this.loadIbGib({ getLatest: false });
|
|
122
|
+
await this.loadIbGib({ getLatest: false });
|
|
123
|
+
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
126
|
+
throw error;
|
|
127
|
+
} finally {
|
|
128
|
+
if (logalot) { console.log(`${lc} complete.`); }
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private async getKeystoneDetails(addr: string): Promise<{ username: string, description: string, isPrimary: boolean, n: number }> {
|
|
133
|
+
const cached = this.keystoneCache.get(addr);
|
|
134
|
+
if (cached) return cached;
|
|
135
|
+
|
|
136
|
+
const metaspace = getIbGibGlobalThis_SpaceGib(APP_CONFIG).metaspace;
|
|
137
|
+
if (!metaspace) return { username: '', description: '', isPrimary: false, n: 0 };
|
|
138
|
+
const space = await metaspace.getLocalUserSpace({ lock: false });
|
|
139
|
+
if (!space) return { username: '', description: '', isPrimary: false, n: 0 };
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
const keystoneSvc = new KeystoneService_V1();
|
|
143
|
+
const info = await keystoneSvc.getKeystoneCommonInfo({
|
|
144
|
+
addr,
|
|
145
|
+
metaspace,
|
|
146
|
+
space
|
|
147
|
+
});
|
|
148
|
+
if (info) {
|
|
149
|
+
const details = {
|
|
150
|
+
username: info.name,
|
|
151
|
+
description: info.description,
|
|
152
|
+
isPrimary: info.isPrimary,
|
|
153
|
+
n: info.n
|
|
154
|
+
};
|
|
155
|
+
this.keystoneCache.set(addr, details);
|
|
156
|
+
return details;
|
|
157
|
+
}
|
|
158
|
+
} catch (err) {
|
|
159
|
+
console.warn(`Error getting details for keystone ${addr}: ${extractErrorMsg(err)}`);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return { username: '', description: '', isPrimary: false, n: 0 };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
override async created(): Promise<void> {
|
|
166
|
+
const lc = `${this.lc}[${this.created.name}]`;
|
|
167
|
+
try {
|
|
168
|
+
if (logalot) { console.log(`${lc} starting... (I: 0b2c6debcdac9db9b7928aa8695ed826)`); }
|
|
169
|
+
|
|
170
|
+
this.elements = {} as KeystoneDetailsElements;
|
|
171
|
+
|
|
172
|
+
const shadow = this.shadowRoot!;
|
|
173
|
+
this.elements.identityDetailsViewEl = shadow.getElementById('identity-details-view') as HTMLDivElement;
|
|
174
|
+
this.elements.identityAddrEl = shadow.getElementById('identity-addr') as HTMLElement;
|
|
175
|
+
this.elements.identityGenEl = shadow.getElementById('identity-gen') as HTMLSpanElement;
|
|
176
|
+
this.elements.identityTimestampEl = shadow.getElementById('identity-timestamp') as HTMLSpanElement;
|
|
177
|
+
this.elements.identityUuidEl = shadow.getElementById('identity-uuid') as HTMLSpanElement;
|
|
178
|
+
this.elements.identityNameEl = shadow.getElementById('identity-name') as HTMLElement;
|
|
179
|
+
this.elements.identityDescriptionEl = shadow.getElementById('identity-description') as HTMLElement;
|
|
180
|
+
this.elements.identityFrameDetailsEl = shadow.getElementById('identity-frame-details') as HTMLPreElement;
|
|
181
|
+
this.elements.identityAggrDetailsEl = shadow.getElementById('identity-aggr-details') as HTMLPreElement;
|
|
182
|
+
|
|
183
|
+
this.elements.poolsContainerEl = shadow.getElementById('pools-container') as HTMLDivElement;
|
|
184
|
+
this.elements.btnVerifyChainEl = shadow.getElementById('btn-verify-chain') as HTMLButtonElement;
|
|
185
|
+
this.elements.btnSetActiveEl = shadow.getElementById('btn-set-active') as HTMLButtonElement;
|
|
186
|
+
this.elements.verificationStatusEl = shadow.getElementById('verification-status') as HTMLDivElement;
|
|
187
|
+
this.elements.rawAccordionHeaderEl = shadow.getElementById('raw-accordion-header') as HTMLDivElement;
|
|
188
|
+
this.elements.rawAccordionContentEl = shadow.getElementById('raw-accordion-content') as HTMLDivElement;
|
|
189
|
+
this.elements.rawKeystoneJsonEl = shadow.getElementById('raw-keystone-json') as HTMLPreElement;
|
|
190
|
+
this.elements.delegatesCardEl = shadow.getElementById('delegates-card') as HTMLDivElement;
|
|
191
|
+
this.elements.delegatesListEl = shadow.getElementById('delegates-list') as HTMLTableSectionElement;
|
|
192
|
+
this.elements.containerEl = shadow.getElementById('container') as HTMLDivElement;
|
|
193
|
+
this.elements.historicalWarningBannerEl = shadow.getElementById('historical-warning-banner') as HTMLDivElement;
|
|
194
|
+
this.elements.ssoLinkCardEl = shadow.getElementById('sso-link-card') as HTMLDivElement;
|
|
195
|
+
this.elements.btnLinkGoogleEl = shadow.getElementById('btn-link-google') as HTMLDivElement;
|
|
196
|
+
this.elements.btnLinkGithubEl = shadow.getElementById('btn-link-github') as HTMLDivElement;
|
|
197
|
+
this.elements.ssoStatusMsgEl = shadow.getElementById('sso-status-msg') as HTMLDivElement;
|
|
198
|
+
|
|
199
|
+
// ElementBase requires contentEl
|
|
200
|
+
this.elements.contentEl = shadow.getElementById('identity-details-view') as HTMLDivElement;
|
|
201
|
+
|
|
202
|
+
this.initHandlers();
|
|
203
|
+
|
|
204
|
+
// Subscribe to global active identity changes
|
|
205
|
+
this._onIdentityChanged = (e: any) => {
|
|
206
|
+
this.globalActiveAddr = e.detail?.activeIdentityAddr || null;
|
|
207
|
+
this.updateActiveButtonState();
|
|
208
|
+
};
|
|
209
|
+
window.addEventListener(EVENT_IBGIB_IDENTITY_CHANGED, this._onIdentityChanged);
|
|
210
|
+
|
|
211
|
+
await this.resolveActiveIdentity();
|
|
212
|
+
await this.loadIbGib({ getLatest: false });
|
|
213
|
+
} catch (error) {
|
|
214
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
215
|
+
throw error;
|
|
216
|
+
} finally {
|
|
217
|
+
if (logalot) { console.log(`${lc} complete.`); }
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
override async disconnected(): Promise<void> {
|
|
222
|
+
if (this._onIdentityChanged) {
|
|
223
|
+
window.removeEventListener(EVENT_IBGIB_IDENTITY_CHANGED, this._onIdentityChanged);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private initHandlers() {
|
|
228
|
+
// Setup raw JSON accordion toggle
|
|
229
|
+
this.elements!.rawAccordionHeaderEl.addEventListener('click', () => this.toggleAccordion());
|
|
230
|
+
|
|
231
|
+
// Buttons
|
|
232
|
+
this.elements!.btnVerifyChainEl.addEventListener('click', () => this.handleVerifyIdentityChain());
|
|
233
|
+
this.elements!.btnSetActiveEl.addEventListener('click', () => this.handleSetActiveIdentity());
|
|
234
|
+
this.elements!.btnLinkGoogleEl.addEventListener('click', () => this.handleSSOClick('google'));
|
|
235
|
+
this.elements!.btnLinkGithubEl.addEventListener('click', () => this.handleSSOClick('github'));
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
private toggleAccordion() {
|
|
239
|
+
const header = this.elements!.rawAccordionHeaderEl;
|
|
240
|
+
const content = this.elements!.rawAccordionContentEl;
|
|
241
|
+
header.classList.toggle('expanded');
|
|
242
|
+
content.classList.toggle('expanded');
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
protected async handleVerifyIdentityChain() {
|
|
246
|
+
const lc = `${this.lc}[${this.handleVerifyIdentityChain.name}]`;
|
|
247
|
+
devLog(`${lc} Verifying identity keystone timeline...`);
|
|
248
|
+
this.setVerificationStatus("Verification request sent...", "info");
|
|
249
|
+
try {
|
|
250
|
+
this.setVerificationStatus("Verification complete. Root Keystone is verified (Genesis phase 1).", "success");
|
|
251
|
+
} catch (error) {
|
|
252
|
+
this.setVerificationStatus(`Verification failed: ${extractErrorMsg(error)}`, "error");
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
protected async handleSetActiveIdentity() {
|
|
257
|
+
if (!this.ibGibAddr) { return; }
|
|
258
|
+
window.dispatchEvent(new CustomEvent(EVENT_IBGIB_IDENTITY_REQUEST_CHANGE, {
|
|
259
|
+
detail: { activeIdentityAddr: this.ibGibAddr },
|
|
260
|
+
bubbles: true,
|
|
261
|
+
composed: true
|
|
262
|
+
}));
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
private setVerificationStatus(msg: string, type: 'info' | 'success' | 'error') {
|
|
266
|
+
const statusEl = this.elements!.verificationStatusEl;
|
|
267
|
+
statusEl.textContent = msg;
|
|
268
|
+
statusEl.className = `status-msg ${type}`;
|
|
269
|
+
statusEl.classList.remove('hidden');
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
private async resolveActiveIdentity() {
|
|
273
|
+
const lc = `${this.lc}[resolveActiveIdentity]`;
|
|
274
|
+
try {
|
|
275
|
+
const domainIdentity = getIbGibGlobalThis_SpaceGib(APP_CONFIG).identity?.domainIdentity;
|
|
276
|
+
this.globalActiveAddr = domainIdentity ? getIbGibAddr({ ibGib: domainIdentity }) : null;
|
|
277
|
+
} catch (error) {
|
|
278
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
279
|
+
this.globalActiveAddr = null;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
override async loadIbGib(opts?: { getLatest?: boolean }): Promise<void> {
|
|
284
|
+
const lc = `${this.lc}[${this.loadIbGib.name}]`;
|
|
285
|
+
try {
|
|
286
|
+
if (logalot) { console.log(`${lc} starting... (I: f0f7e8d52cbdc37bec844b2875996e26)`); }
|
|
287
|
+
|
|
288
|
+
if (!this.ibGibAddr) { return; }
|
|
289
|
+
|
|
290
|
+
const metaspace = getIbGibGlobalThis_SpaceGib(APP_CONFIG).metaspace;
|
|
291
|
+
if (!metaspace) {
|
|
292
|
+
throw new Error(`(UNEXPECTED) metaspace falsy? (E: a9864dbbaefc1082ce7bd228ebd67c26)`);
|
|
293
|
+
}
|
|
294
|
+
let space = await metaspace.getLocalUserSpace({ lock: false });
|
|
295
|
+
if (!space) {
|
|
296
|
+
throw new Error(`(UNEXPECTED) space falsy and we couldn't get default local user space from metaspace? (E: fa298edcecbda889cfd7b228fbd57c26)`);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const resGet = await metaspace.get({ addrs: [this.ibGibAddr], space });
|
|
300
|
+
|
|
301
|
+
if (resGet.success && resGet.ibGibs && resGet.ibGibs.length === 1) {
|
|
302
|
+
this.staticIbGib = resGet.ibGibs[0] as KeystoneIbGib_V1;
|
|
303
|
+
} else {
|
|
304
|
+
const resIbGib = resGet.rawResultIbGib as any;
|
|
305
|
+
const addrsNotFound = resIbGib?.data?.addrsNotFound ?? 'unknown';
|
|
306
|
+
throw new Error(`couldn't find address ${this.ibGibAddr}. addrsNotFound: ${addrsNotFound}? resGet.errorMsg: ${resGet.errorMsg} (E: e0e5c9b7de2837bc902fa88390cd9f26)`);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
await this.updateFrameDetailsView();
|
|
310
|
+
} catch (error) {
|
|
311
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
312
|
+
throw error;
|
|
313
|
+
} finally {
|
|
314
|
+
if (logalot) { console.log(`${lc} complete.`); }
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
protected override async renderUI(): Promise<void> {
|
|
318
|
+
const lc = `${this.lc}[${this.renderUI.name}]`;
|
|
319
|
+
try {
|
|
320
|
+
if (logalot) { console.log(`${lc} starting... (I: c8aa086352d8079708e00f78b6ac0826)`); }
|
|
321
|
+
await super.renderUI();
|
|
322
|
+
// await this.updateFrameDetailsView();
|
|
323
|
+
} catch (error) {
|
|
324
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
325
|
+
throw error;
|
|
326
|
+
} finally {
|
|
327
|
+
if (logalot) { console.log(`${lc} complete.`); }
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
private updateActiveButtonState() {
|
|
332
|
+
if (!this.elements) { return; }
|
|
333
|
+
|
|
334
|
+
const tjpGib = getGibInfo({ ibGibAddr: this.ibGibAddr }).tjpGib ?? getIbAndGib({ ibGibAddr: this.ibGibAddr }).gib;
|
|
335
|
+
const activeTjpGib = this.globalActiveAddr
|
|
336
|
+
? (getGibInfo({ ibGibAddr: this.globalActiveAddr }).tjpGib ?? getIbAndGib({ ibGibAddr: this.globalActiveAddr }).gib)
|
|
337
|
+
: null;
|
|
338
|
+
|
|
339
|
+
const isTimelineActive = !!(this.globalActiveAddr && tjpGib === activeTjpGib);
|
|
340
|
+
|
|
341
|
+
if (isTimelineActive) {
|
|
342
|
+
this.elements.btnSetActiveEl.textContent = "Active Identity";
|
|
343
|
+
this.elements.btnSetActiveEl.classList.add('active-primary');
|
|
344
|
+
} else {
|
|
345
|
+
this.elements.btnSetActiveEl.textContent = "Set as Active Identity";
|
|
346
|
+
this.elements.btnSetActiveEl.classList.remove('active-primary');
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// Disable buttons if historical
|
|
350
|
+
if (this.isHistoricalFrame) {
|
|
351
|
+
this.elements.btnSetActiveEl.disabled = true;
|
|
352
|
+
this.elements.btnVerifyChainEl.disabled = true;
|
|
353
|
+
this.elements.btnLinkGoogleEl.classList.add('disabled');
|
|
354
|
+
this.elements.btnLinkGithubEl.classList.add('disabled');
|
|
355
|
+
} else {
|
|
356
|
+
this.elements.btnVerifyChainEl.disabled = false;
|
|
357
|
+
this.elements.btnSetActiveEl.disabled = isTimelineActive;
|
|
358
|
+
this.elements.btnLinkGoogleEl.classList.remove('disabled');
|
|
359
|
+
this.elements.btnLinkGithubEl.classList.remove('disabled');
|
|
360
|
+
|
|
361
|
+
// Check if already linked
|
|
362
|
+
const isGoogleLinked = isSsoProviderLinked({ keystone: this.ibGib, providerId: 'google' });
|
|
363
|
+
const isGithubLinked = isSsoProviderLinked({ keystone: this.ibGib, providerId: 'github' });
|
|
364
|
+
|
|
365
|
+
// Google Card States
|
|
366
|
+
const googleCard = this.elements.btnLinkGoogleEl;
|
|
367
|
+
const googleLabel = googleCard.querySelector('.toggle-state-text')!;
|
|
368
|
+
if (isGoogleLinked) {
|
|
369
|
+
googleCard.classList.remove('unlinked');
|
|
370
|
+
googleCard.classList.add('linked');
|
|
371
|
+
googleLabel.textContent = "Google Linked ✅";
|
|
372
|
+
} else {
|
|
373
|
+
googleCard.classList.remove('linked');
|
|
374
|
+
googleCard.classList.add('unlinked');
|
|
375
|
+
googleLabel.textContent = "Unlinked";
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// GitHub Card States
|
|
379
|
+
const githubCard = this.elements.btnLinkGithubEl;
|
|
380
|
+
const githubLabel = githubCard.querySelector('.toggle-state-text')!;
|
|
381
|
+
if (isGithubLinked) {
|
|
382
|
+
githubCard.classList.remove('unlinked');
|
|
383
|
+
githubCard.classList.add('linked');
|
|
384
|
+
githubLabel.textContent = "GitHub Linked ✅";
|
|
385
|
+
} else {
|
|
386
|
+
githubCard.classList.remove('linked');
|
|
387
|
+
githubCard.classList.add('unlinked');
|
|
388
|
+
githubLabel.textContent = "Unlinked";
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
private async updateFrameDetailsView(): Promise<void> {
|
|
394
|
+
const lc = `${this.lc}[${this.updateFrameDetailsView.name}]`;
|
|
395
|
+
try {
|
|
396
|
+
if (logalot) { console.log(`${lc} starting... (I: 1fa9e66d2e78fb100874573e2db71d26)`); }
|
|
397
|
+
|
|
398
|
+
if (!this.elements) { return; }
|
|
399
|
+
|
|
400
|
+
const keystone = this.ibGib;
|
|
401
|
+
if (!keystone) {
|
|
402
|
+
this.clearActiveDetails();
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
const keystoneAddr = this.ibGibAddr;
|
|
406
|
+
|
|
407
|
+
// Update Verifiable Address
|
|
408
|
+
this.elements.identityAddrEl.textContent = keystoneAddr;
|
|
409
|
+
|
|
410
|
+
// Update Generation
|
|
411
|
+
this.elements.identityGenEl.textContent = keystone.data?.n !== undefined ? String(keystone.data.n) : '0 (Genesis)';
|
|
412
|
+
|
|
413
|
+
// Update Timestamp
|
|
414
|
+
const timestampStr = keystone.data?.timestamp;
|
|
415
|
+
let formattedTimestamp = 'N/A';
|
|
416
|
+
if (timestampStr) {
|
|
417
|
+
const parsed = parseInt(timestampStr);
|
|
418
|
+
if (!isNaN(parsed)) {
|
|
419
|
+
formattedTimestamp = new Date(parsed).toLocaleString();
|
|
420
|
+
} else {
|
|
421
|
+
formattedTimestamp = new Date(timestampStr).toLocaleString();
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
this.elements.identityTimestampEl.textContent = formattedTimestamp;
|
|
425
|
+
|
|
426
|
+
// Update UUID
|
|
427
|
+
this.elements.identityUuidEl.textContent = keystone.data?.uuid || 'N/A';
|
|
428
|
+
|
|
429
|
+
// Show Frame Details
|
|
430
|
+
const frameDetails = keystone.data?.frameDetails;
|
|
431
|
+
this.elements.identityFrameDetailsEl.textContent = frameDetails ? pretty(frameDetails) : '{}';
|
|
432
|
+
|
|
433
|
+
// Get and Show Aggregated details up to the scrolled-to frame
|
|
434
|
+
let isHistorical = false;
|
|
435
|
+
const metaspace = getIbGibGlobalThis_SpaceGib(APP_CONFIG).metaspace;
|
|
436
|
+
if (metaspace) {
|
|
437
|
+
const space = await metaspace.getLocalUserSpace({ lock: false });
|
|
438
|
+
if (space) {
|
|
439
|
+
try {
|
|
440
|
+
const latestAddr = await metaspace.getLatestAddr({ addr: this.ibGibAddr, space });
|
|
441
|
+
if (latestAddr && latestAddr !== this.ibGibAddr) {
|
|
442
|
+
isHistorical = true;
|
|
443
|
+
}
|
|
444
|
+
} catch (err) {
|
|
445
|
+
console.warn(`${lc} Error checking latest address: ${extractErrorMsg(err)}`);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
try {
|
|
449
|
+
const keystoneSvc = new KeystoneService_V1();
|
|
450
|
+
const aggregated = await keystoneSvc.getAggregateDetails({
|
|
451
|
+
latestKeystone: keystone,
|
|
452
|
+
metaspace,
|
|
453
|
+
space
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
this.elements.identityAggrDetailsEl.textContent = aggregated ? pretty(aggregated) : '{}';
|
|
457
|
+
|
|
458
|
+
// Update Username and Description fields
|
|
459
|
+
this.elements.identityNameEl.textContent = aggregated?.username || aggregated?.profile?.name || aggregated?.name || '-';
|
|
460
|
+
this.elements.identityDescriptionEl.textContent = aggregated?.description || aggregated?.profile?.description || '-';
|
|
461
|
+
} catch (err) {
|
|
462
|
+
console.warn(`${lc} Error aggregating details: ${extractErrorMsg(err)}`);
|
|
463
|
+
this.elements.identityAggrDetailsEl.textContent = '{}';
|
|
464
|
+
this.elements.identityNameEl.textContent = '-';
|
|
465
|
+
this.elements.identityDescriptionEl.textContent = '-';
|
|
466
|
+
}
|
|
467
|
+
} else {
|
|
468
|
+
this.elements.identityAggrDetailsEl.textContent = '{}';
|
|
469
|
+
this.elements.identityNameEl.textContent = '-';
|
|
470
|
+
this.elements.identityDescriptionEl.textContent = '-';
|
|
471
|
+
}
|
|
472
|
+
} else {
|
|
473
|
+
this.elements.identityAggrDetailsEl.textContent = '{}';
|
|
474
|
+
this.elements.identityNameEl.textContent = '-';
|
|
475
|
+
this.elements.identityDescriptionEl.textContent = '-';
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// Update historical warning state
|
|
479
|
+
this.isHistoricalFrame = isHistorical;
|
|
480
|
+
const banner = this.elements.historicalWarningBannerEl;
|
|
481
|
+
const container = this.elements.containerEl;
|
|
482
|
+
if (banner && container) {
|
|
483
|
+
if (isHistorical) {
|
|
484
|
+
banner.classList.remove('hidden');
|
|
485
|
+
container.classList.add('is-historical');
|
|
486
|
+
} else {
|
|
487
|
+
banner.classList.add('hidden');
|
|
488
|
+
container.classList.remove('is-historical');
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// Render Raw Timeline JSON
|
|
493
|
+
this.elements.rawKeystoneJsonEl.textContent = pretty(keystone);
|
|
494
|
+
|
|
495
|
+
// Render Challenge Pools
|
|
496
|
+
this.renderChallengePools(keystone.data?.challengePools || []);
|
|
497
|
+
|
|
498
|
+
// Render Delegates & SSO link card (only if this is a primary keystone, hide delegates table & SSO card for delegate/session keystones)
|
|
499
|
+
const details = await this.getKeystoneDetails(this.ibGibAddr);
|
|
500
|
+
if (details.isPrimary) {
|
|
501
|
+
this.elements.delegatesCardEl.classList.remove('hidden');
|
|
502
|
+
await this.renderDelegates(keystone.data?.delegates);
|
|
503
|
+
this.elements.ssoLinkCardEl.classList.remove('hidden');
|
|
504
|
+
} else {
|
|
505
|
+
this.elements.delegatesCardEl.classList.add('hidden');
|
|
506
|
+
this.elements.ssoLinkCardEl.classList.add('hidden');
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
this.updateActiveButtonState();
|
|
510
|
+
} catch (error) {
|
|
511
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
512
|
+
throw error;
|
|
513
|
+
} finally {
|
|
514
|
+
if (logalot) { console.log(`${lc} complete.`); }
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
private clearActiveDetails() {
|
|
519
|
+
if (!this.elements) { return; }
|
|
520
|
+
this.isHistoricalFrame = false;
|
|
521
|
+
if (this.elements.historicalWarningBannerEl) {
|
|
522
|
+
this.elements.historicalWarningBannerEl.classList.add('hidden');
|
|
523
|
+
}
|
|
524
|
+
if (this.elements.containerEl) {
|
|
525
|
+
this.elements.containerEl.classList.remove('is-historical');
|
|
526
|
+
}
|
|
527
|
+
this.elements.identityGenEl.textContent = '-';
|
|
528
|
+
this.elements.identityTimestampEl.textContent = '-';
|
|
529
|
+
this.elements.identityUuidEl.textContent = '-';
|
|
530
|
+
this.elements.identityNameEl.textContent = '-';
|
|
531
|
+
this.elements.identityDescriptionEl.textContent = '-';
|
|
532
|
+
this.elements.identityFrameDetailsEl.textContent = '{}';
|
|
533
|
+
this.elements.identityAggrDetailsEl.textContent = '{}';
|
|
534
|
+
this.elements.poolsContainerEl.innerHTML = '';
|
|
535
|
+
if (this.elements.delegatesListEl) {
|
|
536
|
+
this.elements.delegatesListEl.innerHTML = '';
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
private renderChallengePools(pools: any[]) {
|
|
541
|
+
if (!this.elements) { return; }
|
|
542
|
+
const container = this.elements.poolsContainerEl;
|
|
543
|
+
container.innerHTML = '';
|
|
544
|
+
|
|
545
|
+
if (!pools || pools.length === 0) {
|
|
546
|
+
container.innerHTML = `<p class="description">No challenge pools found in this keystone.</p>`;
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
for (const pool of pools) {
|
|
551
|
+
const card = document.createElement('div');
|
|
552
|
+
card.className = 'pool-card';
|
|
553
|
+
|
|
554
|
+
const config = pool.config || {};
|
|
555
|
+
const behavior = config.behavior || {};
|
|
556
|
+
const allowedVerbs = config.allowedVerbs || [];
|
|
557
|
+
const activeCount = pool.challenges ? Object.keys(pool.challenges).length : 0;
|
|
558
|
+
const isForeign = !!pool.isForeign;
|
|
559
|
+
|
|
560
|
+
// Generate HTML for the challenges list
|
|
561
|
+
const challenges = pool.challenges || {};
|
|
562
|
+
const challengeListHtml = Object.entries(challenges).map(([id, challenge]: [string, any]) => {
|
|
563
|
+
const truncatedHash = challenge.hash && challenge.hash.length > 20
|
|
564
|
+
? challenge.hash.substring(0, 10) + '...' + challenge.hash.substring(challenge.hash.length - 8)
|
|
565
|
+
: challenge.hash || 'N/A';
|
|
566
|
+
return `
|
|
567
|
+
<div class="pool-challenge-item">
|
|
568
|
+
<span class="challenge-id">${id}</span>
|
|
569
|
+
<span class="challenge-hash" title="${challenge.hash || ''}">${truncatedHash}</span>
|
|
570
|
+
</div>
|
|
571
|
+
`;
|
|
572
|
+
}).join('');
|
|
573
|
+
|
|
574
|
+
card.innerHTML = `
|
|
575
|
+
<div class="pool-header">
|
|
576
|
+
<span class="pool-title">${pool.id || 'Unnamed Pool'}</span>
|
|
577
|
+
<span class="pool-tag ${isForeign ? 'foreign' : 'native'}">${isForeign ? 'Foreign' : 'Native'}</span>
|
|
578
|
+
</div>
|
|
579
|
+
<div class="pool-grid">
|
|
580
|
+
<div class="pool-field">
|
|
581
|
+
<label>Verbs Allowed</label>
|
|
582
|
+
<span>${allowedVerbs.length > 0 ? allowedVerbs.join(', ') : 'Any'}</span>
|
|
583
|
+
</div>
|
|
584
|
+
<div class="pool-field">
|
|
585
|
+
<label>FIFO / Random cost</label>
|
|
586
|
+
<span>FIFO: ${behavior.selectSequentially ?? 0}, Rand: ${behavior.selectRandomly ?? 0}</span>
|
|
587
|
+
</div>
|
|
588
|
+
</div>
|
|
589
|
+
|
|
590
|
+
<!-- Collapsible Challenges List -->
|
|
591
|
+
<details class="pool-details">
|
|
592
|
+
<summary class="pool-details-summary">Challenges (${activeCount})</summary>
|
|
593
|
+
<div class="pool-challenges-list">
|
|
594
|
+
${challengeListHtml || '<p class="placeholder-text" style="padding: 0.5rem; text-align: center;">No challenges active.</p>'}
|
|
595
|
+
</div>
|
|
596
|
+
</details>
|
|
597
|
+
`;
|
|
598
|
+
container.appendChild(card);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
private async renderDelegates(delegates: Record<string, any> | undefined) {
|
|
603
|
+
if (!this.elements) { return; }
|
|
604
|
+
const listEl = this.elements.delegatesListEl;
|
|
605
|
+
listEl.innerHTML = '';
|
|
606
|
+
|
|
607
|
+
if (!delegates || Object.keys(delegates).length === 0) {
|
|
608
|
+
listEl.innerHTML = `
|
|
609
|
+
<tr>
|
|
610
|
+
<td colspan="4" style="text-align: center; color: var(--clr-text-secondary, #b3b3b3);">
|
|
611
|
+
No registered delegates.
|
|
612
|
+
</td>
|
|
613
|
+
</tr>
|
|
614
|
+
`;
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
for (const [delegateTjpAddr, info] of Object.entries(delegates)) {
|
|
619
|
+
const tr = document.createElement('tr');
|
|
620
|
+
|
|
621
|
+
const tdName = document.createElement('td');
|
|
622
|
+
tdName.textContent = 'Loading...';
|
|
623
|
+
|
|
624
|
+
const tdTjp = document.createElement('td');
|
|
625
|
+
tdTjp.textContent = delegateTjpAddr;
|
|
626
|
+
tdTjp.title = delegateTjpAddr;
|
|
627
|
+
|
|
628
|
+
const tdVerbs = document.createElement('td');
|
|
629
|
+
tdVerbs.textContent = info.allowedVerbs ? info.allowedVerbs.join(', ') : '-';
|
|
630
|
+
tdVerbs.title = tdVerbs.textContent;
|
|
631
|
+
|
|
632
|
+
const tdActions = document.createElement('td');
|
|
633
|
+
const btnView = document.createElement('button');
|
|
634
|
+
btnView.className = 'action-btn secondary small';
|
|
635
|
+
btnView.textContent = 'View Details';
|
|
636
|
+
btnView.addEventListener('click', () => {
|
|
637
|
+
if (info.delegateAddr) {
|
|
638
|
+
this.dispatchEvent(new CustomEvent('ibgib-view-keystone-details', {
|
|
639
|
+
detail: { addr: info.delegateAddr },
|
|
640
|
+
bubbles: true,
|
|
641
|
+
composed: true
|
|
642
|
+
}));
|
|
643
|
+
}
|
|
644
|
+
});
|
|
645
|
+
tdActions.appendChild(btnView);
|
|
646
|
+
|
|
647
|
+
tr.appendChild(tdName);
|
|
648
|
+
tr.appendChild(tdTjp);
|
|
649
|
+
tr.appendChild(tdVerbs);
|
|
650
|
+
tr.appendChild(tdActions);
|
|
651
|
+
listEl.appendChild(tr);
|
|
652
|
+
|
|
653
|
+
if (info.delegateAddr) {
|
|
654
|
+
this.getKeystoneDetails(info.delegateAddr).then(details => {
|
|
655
|
+
const textParts: string[] = [];
|
|
656
|
+
if (details.username) textParts.push(details.username);
|
|
657
|
+
if (details.description) textParts.push(details.description);
|
|
658
|
+
tdName.textContent = textParts.join(' / ') || 'Unnamed Delegate';
|
|
659
|
+
tdName.title = `Addr: ${info.delegateAddr}\n` + textParts.join('\n');
|
|
660
|
+
}).catch(err => {
|
|
661
|
+
tdName.textContent = 'Unknown Delegate';
|
|
662
|
+
});
|
|
663
|
+
} else {
|
|
664
|
+
tdName.textContent = 'No Address';
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
override async handleContextUpdated(): Promise<void> {
|
|
670
|
+
const lc = `${this.lc}[${this.handleContextUpdated.name}]`;
|
|
671
|
+
try {
|
|
672
|
+
if (logalot) { console.log(`${lc} starting... (I: 243a88c1d4689c779bbbf2a4abd5da26)`); }
|
|
673
|
+
|
|
674
|
+
// don't do anything when the context is updated?
|
|
675
|
+
|
|
676
|
+
// is this hit? no. leave this as a no-op
|
|
677
|
+
console.warn(`${lc} this component currently designed expecting that this does not hit (W: 95dc018b87027287e860de0826146826)`);
|
|
678
|
+
|
|
679
|
+
await super.handleContextUpdated();
|
|
680
|
+
} catch (error) {
|
|
681
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
682
|
+
throw error;
|
|
683
|
+
} finally {
|
|
684
|
+
if (logalot) { console.log(`${lc} complete.`); }
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
protected override async handleNewContextChild({ childIbGib }: { childIbGib: IbGib_V1; }): Promise<void> {
|
|
689
|
+
const lc = `${this.lc}[${this.handleNewContextChild.name}]`;
|
|
690
|
+
try {
|
|
691
|
+
if (logalot) { console.log(`${lc} starting... (I: b04dc63842f871658840233485659726)`); }
|
|
692
|
+
// is this hit? no
|
|
693
|
+
await super.handleNewContextChild({ childIbGib });
|
|
694
|
+
|
|
695
|
+
console.warn(`${lc} this component currently designed expecting that this does not hit (W: 95dc018b87027287e860de0826146826)`);
|
|
696
|
+
} catch (error) {
|
|
697
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
698
|
+
throw error;
|
|
699
|
+
} finally {
|
|
700
|
+
if (logalot) { console.log(`${lc} complete.`); }
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
protected async handleSSOLink(providerId: 'google' | 'github') {
|
|
705
|
+
const lc = `${this.lc}[${this.handleSSOLink.name}]`;
|
|
706
|
+
this.setSSOStatus(`Linking ${providerId}...`, "info");
|
|
707
|
+
|
|
708
|
+
try {
|
|
709
|
+
// 1. Fetch public SSO configs from server
|
|
710
|
+
const res = await fetch('/api/identity/sso/config');
|
|
711
|
+
if (!res.ok) {
|
|
712
|
+
throw new Error(`Failed to fetch SSO config from server: ${res.statusText}`);
|
|
713
|
+
}
|
|
714
|
+
const data = await res.json();
|
|
715
|
+
if (!data.success || !data.providers) {
|
|
716
|
+
throw new Error(`SSO configuration fetch failed: ${data.message || 'unknown error'}`);
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
const providerConfig = data.providers.find((p: any) => p.providerId === providerId);
|
|
720
|
+
if (!providerConfig) {
|
|
721
|
+
throw new Error(`SSO provider '${providerId}' is not configured on the server.`);
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
// 2. Generate a secure, high-entropy user nonce
|
|
725
|
+
const userNonce = (Math.random().toString(36).substring(2) + Math.random().toString(36).substring(2)).substring(0, 32);
|
|
726
|
+
|
|
727
|
+
// 3. Construct state payload
|
|
728
|
+
const stateObj = {
|
|
729
|
+
providerId,
|
|
730
|
+
parentTjpAddr: this.ibGibAddr,
|
|
731
|
+
userNonce
|
|
732
|
+
};
|
|
733
|
+
const state = btoa(JSON.stringify(stateObj));
|
|
734
|
+
|
|
735
|
+
// 4. Construct Auth URL
|
|
736
|
+
const authUrl = `${providerConfig.authUrl}?client_id=${providerConfig.clientId}&redirect_uri=${encodeURIComponent(providerConfig.redirectUri)}&response_type=code&scope=${encodeURIComponent(providerConfig.scope)}&state=${encodeURIComponent(state)}`;
|
|
737
|
+
|
|
738
|
+
// 5. Open popup window
|
|
739
|
+
const popup = window.open(
|
|
740
|
+
authUrl,
|
|
741
|
+
'sso-oauth-popup',
|
|
742
|
+
'width=600,height=700,status=yes,toolbar=no,menubar=no,location=yes'
|
|
743
|
+
);
|
|
744
|
+
if (!popup) {
|
|
745
|
+
throw new Error("Popup blocked by browser. Please enable popups for this site.");
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
// 6. Listen for callback from pop-up
|
|
749
|
+
let checkClosedInterval: any;
|
|
750
|
+
const messageListener = async (event: MessageEvent) => {
|
|
751
|
+
if (event.origin !== window.location.origin) return;
|
|
752
|
+
const callbackData = event.data;
|
|
753
|
+
if (callbackData && callbackData.type === 'sso-oauth-callback') {
|
|
754
|
+
window.removeEventListener('message', messageListener);
|
|
755
|
+
clearInterval(checkClosedInterval);
|
|
756
|
+
await this.handleSSOLinkCallback(callbackData.code, stateObj, providerConfig.redirectUri);
|
|
757
|
+
}
|
|
758
|
+
};
|
|
759
|
+
window.addEventListener('message', messageListener);
|
|
760
|
+
|
|
761
|
+
// 7. Poll for manual closure of the popup window
|
|
762
|
+
checkClosedInterval = setInterval(() => {
|
|
763
|
+
if (popup.closed) {
|
|
764
|
+
clearInterval(checkClosedInterval);
|
|
765
|
+
window.removeEventListener('message', messageListener);
|
|
766
|
+
const statusEl = this.elements!.ssoStatusMsgEl;
|
|
767
|
+
if (statusEl.textContent && statusEl.textContent.startsWith('Linking')) {
|
|
768
|
+
this.setSSOStatus('Linking cancelled (window closed).', 'error');
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
}, 500);
|
|
772
|
+
|
|
773
|
+
} catch (error) {
|
|
774
|
+
console.error(`${lc} SSO link initiation failed: ${extractErrorMsg(error)}`);
|
|
775
|
+
this.setSSOStatus(`Link failed: ${extractErrorMsg(error)}`, "error");
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
private setSSOStatus(msg: string, type: 'info' | 'success' | 'error') {
|
|
780
|
+
const statusEl = this.elements!.ssoStatusMsgEl;
|
|
781
|
+
statusEl.textContent = msg;
|
|
782
|
+
statusEl.className = `status-msg ${type}`;
|
|
783
|
+
statusEl.classList.remove('hidden');
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
protected async handleSSOLinkCallback(code: string, stateObj: any, redirectUri: string) {
|
|
787
|
+
const lc = `${this.lc}[${this.handleSSOLinkCallback.name}]`;
|
|
788
|
+
this.setSSOStatus("Retrieving challenge pool configuration from server...", "info");
|
|
789
|
+
|
|
790
|
+
try {
|
|
791
|
+
// 1. Exchange OAuth code for custodian public pool config
|
|
792
|
+
const res = await fetch('/api/identity/sso/link', {
|
|
793
|
+
method: 'POST',
|
|
794
|
+
headers: { 'Content-Type': 'application/json' },
|
|
795
|
+
body: JSON.stringify({
|
|
796
|
+
code,
|
|
797
|
+
providerId: stateObj.providerId,
|
|
798
|
+
parentTjpAddr: stateObj.parentTjpAddr,
|
|
799
|
+
userNonce: stateObj.userNonce,
|
|
800
|
+
redirectUri
|
|
801
|
+
})
|
|
802
|
+
});
|
|
803
|
+
if (!res.ok) {
|
|
804
|
+
const errBody = await res.json().catch(() => ({}));
|
|
805
|
+
throw new Error(`Server link exchange failed: ${errBody.message || res.statusText}`);
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
const linkData = await res.json();
|
|
809
|
+
if (!linkData.success || !linkData.custodianPool) {
|
|
810
|
+
throw new Error(`Failed to retrieve custodian challenge pool: ${linkData.message || 'unknown error'}`);
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
const custodianPool = linkData.custodianPool;
|
|
814
|
+
|
|
815
|
+
// 2. Prompt user for master secret and verify it
|
|
816
|
+
const keystoneService = new KeystoneService_V1();
|
|
817
|
+
let masterSecret: string | undefined;
|
|
818
|
+
let isCorrect = false;
|
|
819
|
+
let tries = 0;
|
|
820
|
+
const maxTries = 8;
|
|
821
|
+
|
|
822
|
+
while (tries < maxTries && !isCorrect) {
|
|
823
|
+
try {
|
|
824
|
+
const promptMsg = tries === 0
|
|
825
|
+
? "Link successful! Enter your local Master Secret (Passphrase) to sign and register the custodian pool"
|
|
826
|
+
: `Incorrect passphrase. Please try again (${maxTries - tries} tries remaining):`;
|
|
827
|
+
masterSecret = await promptForSecret({
|
|
828
|
+
msg: promptMsg,
|
|
829
|
+
confirm: false
|
|
830
|
+
});
|
|
831
|
+
} catch (error) {
|
|
832
|
+
// cancelled
|
|
833
|
+
if (logalot) { console.log(`${lc}[promptForSecret] user cancelled (I: 911ff1fb0234949228481968e9087626)`); }
|
|
834
|
+
masterSecret = undefined;
|
|
835
|
+
break;
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
if (!masterSecret) {
|
|
839
|
+
break;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
// Verify secret using verifySigningSecret (requires manage poolId)
|
|
843
|
+
isCorrect = await keystoneService.verifySigningSecret({
|
|
844
|
+
keystoneIbGib: this.ibGib!,
|
|
845
|
+
signingSecret: masterSecret,
|
|
846
|
+
poolId: 'manage'
|
|
847
|
+
});
|
|
848
|
+
|
|
849
|
+
if (!isCorrect) {
|
|
850
|
+
tries++;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
if (!isCorrect) {
|
|
855
|
+
this.setSSOStatus("Link cancelled or failed (incorrect passphrase).", "error");
|
|
856
|
+
return;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
this.setSSOStatus("Evolving identity locally and generating cryptographic signatures...", "info");
|
|
860
|
+
|
|
861
|
+
const metaspace = getIbGibGlobalThis_SpaceGib(APP_CONFIG).metaspace;
|
|
862
|
+
if (!metaspace) throw new Error("Metaspace not found");
|
|
863
|
+
const space = await metaspace.getLocalUserSpace({ lock: false });
|
|
864
|
+
if (!space) { throw new Error("Local space not found"); }
|
|
865
|
+
|
|
866
|
+
// 3. Evolve parent keystone to include the custodian pool
|
|
867
|
+
const evolvedParent = await keystoneService.addPools({
|
|
868
|
+
latestKeystone: this.ibGib!,
|
|
869
|
+
masterSecret: masterSecret!,
|
|
870
|
+
newPools: [custodianPool],
|
|
871
|
+
metaspace,
|
|
872
|
+
space
|
|
873
|
+
});
|
|
874
|
+
|
|
875
|
+
// 4. Sync evolved parent keystone back to server
|
|
876
|
+
this.setSSOStatus("Publishing evolved identity keystone to server...", "info");
|
|
877
|
+
const syncRes = await spaceGibApiBridge.putEvolveKeystone(
|
|
878
|
+
stateObj.parentTjpAddr,
|
|
879
|
+
evolvedParent,
|
|
880
|
+
[] // No outward delegate timelines
|
|
881
|
+
);
|
|
882
|
+
if (!syncRes.success) {
|
|
883
|
+
throw new Error(`Server synchronization rejected: ${syncRes.message}`);
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
// 5. Update index locally
|
|
887
|
+
await updateSpecialIndex({
|
|
888
|
+
type: "keystones",
|
|
889
|
+
rel8nInfos: [
|
|
890
|
+
{
|
|
891
|
+
rel8nName: "keystone",
|
|
892
|
+
ibGibs: [toDto({ ibGib: evolvedParent })]
|
|
893
|
+
}
|
|
894
|
+
],
|
|
895
|
+
metaspace,
|
|
896
|
+
space
|
|
897
|
+
});
|
|
898
|
+
|
|
899
|
+
this.setSSOStatus(`Successfully linked with ${stateObj.providerId}!`, "success");
|
|
900
|
+
await this.loadIbGib({ getLatest: false });
|
|
901
|
+
|
|
902
|
+
} catch (error) {
|
|
903
|
+
console.error(`${lc} SSO callback processing failed: ${extractErrorMsg(error)}`);
|
|
904
|
+
this.setSSOStatus(`Link failed: ${extractErrorMsg(error)}`, "error");
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
protected async handleSSOClick(providerId: 'google' | 'github') {
|
|
909
|
+
const isLinked = isSsoProviderLinked({ keystone: this.ibGib, providerId });
|
|
910
|
+
if (isLinked) {
|
|
911
|
+
await this.handleSSOUnlink(providerId);
|
|
912
|
+
} else {
|
|
913
|
+
await this.handleSSOLink(providerId);
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
protected async handleSSOUnlink(providerId: 'google' | 'github') {
|
|
918
|
+
const lc = `${this.lc}[${this.handleSSOUnlink.name}]`;
|
|
919
|
+
this.setSSOStatus(`Unlinking ${providerId}...`, "info");
|
|
920
|
+
|
|
921
|
+
try {
|
|
922
|
+
// 1. Prompt user for passphrase
|
|
923
|
+
const keystoneService = new KeystoneService_V1();
|
|
924
|
+
let masterSecret: string | undefined;
|
|
925
|
+
let isCorrect = false;
|
|
926
|
+
let tries = 0;
|
|
927
|
+
const maxTries = 8;
|
|
928
|
+
|
|
929
|
+
while (tries < maxTries && !isCorrect) {
|
|
930
|
+
try {
|
|
931
|
+
const promptMsg = tries === 0
|
|
932
|
+
? `Are you sure you want to unlink your ${providerId} account? If so, enter your local Master Secret (Passphrase) to authorize. Otherwise, click Cancel.`
|
|
933
|
+
: `Incorrect passphrase. Please try again (${maxTries - tries} tries remaining):`;
|
|
934
|
+
masterSecret = await promptForSecret({
|
|
935
|
+
msg: promptMsg,
|
|
936
|
+
confirm: false
|
|
937
|
+
});
|
|
938
|
+
} catch (error) {
|
|
939
|
+
masterSecret = undefined;
|
|
940
|
+
break;
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
if (!masterSecret) {
|
|
944
|
+
break;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
// Verify secret using verifySigningSecret (requires manage poolId)
|
|
948
|
+
isCorrect = await keystoneService.verifySigningSecret({
|
|
949
|
+
keystoneIbGib: this.ibGib!,
|
|
950
|
+
signingSecret: masterSecret,
|
|
951
|
+
poolId: 'manage'
|
|
952
|
+
});
|
|
953
|
+
|
|
954
|
+
if (!isCorrect) {
|
|
955
|
+
tries++;
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
if (!isCorrect) {
|
|
960
|
+
this.setSSOStatus("Unlink cancelled or failed (incorrect passphrase).", "error");
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
this.setSSOStatus("Evolving identity locally and removing custodian pool...", "info");
|
|
965
|
+
|
|
966
|
+
const metaspace = getIbGibGlobalThis_SpaceGib(APP_CONFIG).metaspace;
|
|
967
|
+
if (!metaspace) throw new Error("Metaspace not found");
|
|
968
|
+
const space = await metaspace.getLocalUserSpace({ lock: false });
|
|
969
|
+
if (!space) { throw new Error("Local space not found"); }
|
|
970
|
+
|
|
971
|
+
// 2. Evolve parent keystone to remove the custodian pool
|
|
972
|
+
const targetPoolId = `custodian-manage-${providerId}`;
|
|
973
|
+
const evolvedParent = await keystoneService.removePools({
|
|
974
|
+
latestKeystone: this.ibGib!,
|
|
975
|
+
masterSecret: masterSecret!,
|
|
976
|
+
poolIds: [targetPoolId],
|
|
977
|
+
metaspace,
|
|
978
|
+
space
|
|
979
|
+
});
|
|
980
|
+
|
|
981
|
+
// 3. Sync evolved parent keystone back to server
|
|
982
|
+
this.setSSOStatus("Publishing evolved identity keystone to server...", "info");
|
|
983
|
+
const syncRes = await spaceGibApiBridge.putEvolveKeystone(
|
|
984
|
+
getIbGibAddr({ ibGib: this.ibGib! }),
|
|
985
|
+
evolvedParent,
|
|
986
|
+
[] // No outward delegate timelines
|
|
987
|
+
);
|
|
988
|
+
if (!syncRes.success) {
|
|
989
|
+
throw new Error(`Server synchronization rejected: ${syncRes.message}`);
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
// 4. Update index locally
|
|
993
|
+
await updateSpecialIndex({
|
|
994
|
+
type: "keystones",
|
|
995
|
+
rel8nInfos: [
|
|
996
|
+
{
|
|
997
|
+
rel8nName: "keystone",
|
|
998
|
+
ibGibs: [toDto({ ibGib: evolvedParent })]
|
|
999
|
+
}
|
|
1000
|
+
],
|
|
1001
|
+
metaspace,
|
|
1002
|
+
space
|
|
1003
|
+
});
|
|
1004
|
+
|
|
1005
|
+
this.setSSOStatus(`Successfully unlinked ${providerId}!`, "success");
|
|
1006
|
+
await this.loadIbGib({ getLatest: false });
|
|
1007
|
+
|
|
1008
|
+
} catch (error) {
|
|
1009
|
+
console.error(`${lc} SSO unlink failed: ${extractErrorMsg(error)}`);
|
|
1010
|
+
this.setSSOStatus(`Unlink failed: ${extractErrorMsg(error)}`, "error");
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
}
|