@ibgib/space-gib 0.0.35 → 0.0.36

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.
@@ -0,0 +1,327 @@
1
+ /**
2
+ * tutorial.css — Styles for the Space-Gib Interactive Tutorial & Spotlight Tour
3
+ */
4
+
5
+ .tutorial-overlay-container {
6
+ position: fixed;
7
+ inset: 0;
8
+ z-index: 10000;
9
+ pointer-events: none;
10
+ overflow: hidden;
11
+ transition: opacity 0.3s ease;
12
+ }
13
+
14
+ /* Semi-transparent dimmer backdrop (active only when no spotlight target) */
15
+ .tutorial-backdrop {
16
+ position: absolute;
17
+ inset: 0;
18
+ background: rgba(8, 10, 15, 0.82);
19
+ backdrop-filter: blur(4px);
20
+ -webkit-backdrop-filter: blur(4px);
21
+ pointer-events: auto;
22
+ opacity: 0;
23
+ transition: opacity 0.3s ease;
24
+ }
25
+
26
+ .tutorial-backdrop.backdrop-active {
27
+ opacity: 1;
28
+ }
29
+
30
+ /* Glowing spotlight ring around the active target with 100% crystal-clear cutout */
31
+ .tutorial-spotlight-ring {
32
+ position: absolute;
33
+ border-radius: 8px;
34
+ background: transparent !important;
35
+ box-shadow: 0 0 0 9999px rgba(8, 10, 15, 0.82),
36
+ 0 0 0 3px rgba(255, 204, 0, 0.85),
37
+ 0 0 25px 6px rgba(255, 180, 0, 0.45);
38
+ pointer-events: none;
39
+ transition: top 0.35s cubic-bezier(0.2, 0.9, 0.3, 1),
40
+ left 0.35s cubic-bezier(0.2, 0.9, 0.3, 1),
41
+ width 0.35s cubic-bezier(0.2, 0.9, 0.3, 1),
42
+ height 0.35s cubic-bezier(0.2, 0.9, 0.3, 1),
43
+ opacity 0.25s ease;
44
+ z-index: 10001;
45
+ }
46
+
47
+ /* Animated Virtual Mouse Cursor */
48
+ .tutorial-cursor {
49
+ position: fixed;
50
+ top: 0;
51
+ left: 0;
52
+ width: 32px;
53
+ height: 32px;
54
+ z-index: 10006;
55
+ pointer-events: none;
56
+ opacity: 0;
57
+ transform: translate(-9999px, -9999px);
58
+ transition: opacity 0.25s ease;
59
+ }
60
+
61
+ .tutorial-cursor.visible {
62
+ opacity: 1;
63
+ }
64
+
65
+ .tutorial-cursor-pointer {
66
+ filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.7));
67
+ transition: transform 0.12s ease;
68
+ transform-origin: 0 0;
69
+ }
70
+
71
+ .tutorial-cursor.clicking .tutorial-cursor-pointer {
72
+ transform: scale(0.82);
73
+ }
74
+
75
+ .tutorial-cursor-ripple {
76
+ position: absolute;
77
+ top: 0;
78
+ left: 0;
79
+ width: 36px;
80
+ height: 36px;
81
+ border-radius: 50%;
82
+ border: 2px solid #ffd700;
83
+ background: rgba(255, 215, 0, 0.25);
84
+ box-shadow: 0 0 16px rgba(255, 215, 0, 0.85);
85
+ transform: translate(-18px, -18px) scale(0);
86
+ opacity: 0;
87
+ pointer-events: none;
88
+ }
89
+
90
+ .tutorial-cursor.clicking .tutorial-cursor-ripple {
91
+ animation: cursor-ripple-anim 0.55s cubic-bezier(0.1, 0.8, 0.3, 1) forwards;
92
+ }
93
+
94
+ @keyframes cursor-ripple-anim {
95
+ 0% {
96
+ transform: translate(-18px, -18px) scale(0.2);
97
+ opacity: 1;
98
+ }
99
+ 100% {
100
+ transform: translate(-18px, -18px) scale(2.5);
101
+ opacity: 0;
102
+ }
103
+ }
104
+
105
+ /* Movable Golden Beacon Button */
106
+ .tutorial-beacon {
107
+ position: absolute;
108
+ display: flex;
109
+ align-items: center;
110
+ gap: 8px;
111
+ padding: 8px 18px;
112
+ background: linear-gradient(135deg, #ffd700 0%, #ff9900 100%);
113
+ color: #121212;
114
+ font-family: inherit;
115
+ font-size: 0.95rem;
116
+ font-weight: 700;
117
+ border: 2px solid rgba(255, 255, 255, 0.8);
118
+ border-radius: 9999px;
119
+ box-shadow: 0 4px 20px rgba(255, 180, 0, 0.65), 0 0 30px rgba(255, 215, 0, 0.4);
120
+ cursor: pointer;
121
+ pointer-events: auto;
122
+ z-index: 10002;
123
+ transition: top 0.35s cubic-bezier(0.2, 0.9, 0.3, 1),
124
+ left 0.35s cubic-bezier(0.2, 0.9, 0.3, 1),
125
+ transform 0.2s ease,
126
+ box-shadow 0.2s ease,
127
+ opacity 0.25s ease;
128
+ animation: beacon-pulse 2s infinite ease-in-out;
129
+ }
130
+
131
+ .tutorial-beacon:hover {
132
+ transform: scale(1.06);
133
+ box-shadow: 0 6px 28px rgba(255, 190, 0, 0.85), 0 0 40px rgba(255, 230, 100, 0.6);
134
+ }
135
+
136
+ .tutorial-beacon:active {
137
+ transform: scale(0.96);
138
+ }
139
+
140
+ .tutorial-beacon-icon {
141
+ font-size: 1.15rem;
142
+ line-height: 1;
143
+ }
144
+
145
+ .tutorial-beacon-text {
146
+ letter-spacing: 0.02em;
147
+ }
148
+
149
+ @keyframes beacon-pulse {
150
+ 0%, 100% {
151
+ box-shadow: 0 4px 20px rgba(255, 180, 0, 0.65), 0 0 15px rgba(255, 215, 0, 0.4);
152
+ }
153
+ 50% {
154
+ box-shadow: 0 4px 30px rgba(255, 200, 0, 0.9), 0 0 35px rgba(255, 230, 50, 0.7);
155
+ }
156
+ }
157
+
158
+ /* Floating Glassmorphic Narration Card */
159
+ .tutorial-card {
160
+ position: absolute;
161
+ width: 440px;
162
+ max-width: calc(100vw - 32px);
163
+ background: rgba(18, 22, 34, 0.95);
164
+ backdrop-filter: blur(16px);
165
+ -webkit-backdrop-filter: blur(16px);
166
+ border: 1px solid rgba(255, 215, 0, 0.35);
167
+ border-radius: 14px;
168
+ box-shadow: 0 16px 40px rgba(0, 0, 0, 0.75), 0 0 20px rgba(255, 200, 0, 0.15);
169
+ padding: 22px 24px;
170
+ color: #e2e8f0;
171
+ pointer-events: auto;
172
+ z-index: 10002;
173
+ transition: top 0.35s cubic-bezier(0.2, 0.9, 0.3, 1),
174
+ left 0.35s cubic-bezier(0.2, 0.9, 0.3, 1),
175
+ opacity 0.25s ease;
176
+ }
177
+
178
+ .tutorial-card.placement-center {
179
+ top: 50% !important;
180
+ left: 50% !important;
181
+ transform: translate(-50%, -50%);
182
+ width: 620px;
183
+ border-color: rgba(255, 215, 0, 0.45);
184
+ box-shadow: 0 20px 60px rgba(0, 0, 0, 0.85), 0 0 40px rgba(255, 200, 0, 0.25);
185
+ }
186
+
187
+ .tutorial-card-header {
188
+ display: flex;
189
+ align-items: center;
190
+ justify-content: space-between;
191
+ margin-bottom: 12px;
192
+ }
193
+
194
+ .tutorial-step-badge {
195
+ font-size: 0.75rem;
196
+ font-weight: 700;
197
+ text-transform: uppercase;
198
+ letter-spacing: 0.08em;
199
+ color: #ffd700;
200
+ background: rgba(255, 215, 0, 0.12);
201
+ padding: 4px 10px;
202
+ border-radius: 9999px;
203
+ border: 1px solid rgba(255, 215, 0, 0.3);
204
+ }
205
+
206
+ .tutorial-card-close {
207
+ background: none;
208
+ border: none;
209
+ color: #94a3b8;
210
+ font-size: 1.25rem;
211
+ cursor: pointer;
212
+ padding: 4px 8px;
213
+ border-radius: 6px;
214
+ transition: color 0.15s ease, background 0.15s ease;
215
+ }
216
+
217
+ .tutorial-card-close:hover {
218
+ color: #ffffff;
219
+ background: rgba(255, 255, 255, 0.1);
220
+ }
221
+
222
+ .tutorial-card-title {
223
+ margin: 0 0 12px 0;
224
+ font-size: 1.25rem;
225
+ font-weight: 700;
226
+ color: #ffffff;
227
+ line-height: 1.35;
228
+ }
229
+
230
+ .tutorial-card-body {
231
+ font-size: 0.92rem;
232
+ line-height: 1.6;
233
+ color: #cbd5e1;
234
+ margin-bottom: 20px;
235
+ max-height: 55vh;
236
+ overflow-y: auto;
237
+ }
238
+
239
+ .tutorial-card-body p {
240
+ margin: 0 0 10px 0;
241
+ }
242
+
243
+ .tutorial-card-body p:last-child {
244
+ margin-bottom: 0;
245
+ }
246
+
247
+ .tutorial-card-body strong {
248
+ color: #f8fafc;
249
+ }
250
+
251
+ .tutorial-card-body em {
252
+ color: #ffd700;
253
+ font-style: normal;
254
+ }
255
+
256
+ .tutorial-card-footer {
257
+ display: flex;
258
+ align-items: center;
259
+ justify-content: space-between;
260
+ padding-top: 14px;
261
+ border-top: 1px solid rgba(255, 255, 255, 0.08);
262
+ }
263
+
264
+ .tutorial-progress-dots {
265
+ display: flex;
266
+ gap: 6px;
267
+ }
268
+
269
+ .tutorial-dot {
270
+ width: 8px;
271
+ height: 8px;
272
+ border-radius: 9999px;
273
+ background: rgba(255, 255, 255, 0.2);
274
+ transition: background 0.25s ease, transform 0.25s ease;
275
+ }
276
+
277
+ .tutorial-dot.active {
278
+ background: #ffd700;
279
+ transform: scale(1.25);
280
+ box-shadow: 0 0 8px #ffd700;
281
+ }
282
+
283
+ .tutorial-card-actions {
284
+ display: flex;
285
+ align-items: center;
286
+ gap: 10px;
287
+ }
288
+
289
+ .tutorial-btn-skip {
290
+ background: none;
291
+ border: none;
292
+ color: #94a3b8;
293
+ font-size: 0.85rem;
294
+ cursor: pointer;
295
+ padding: 6px 12px;
296
+ border-radius: 6px;
297
+ transition: color 0.15s ease;
298
+ }
299
+
300
+ .tutorial-btn-skip:hover {
301
+ color: #ffffff;
302
+ }
303
+
304
+ .tutorial-btn-next {
305
+ display: inline-flex;
306
+ align-items: center;
307
+ gap: 6px;
308
+ background: linear-gradient(135deg, #ffd700 0%, #ffaa00 100%);
309
+ color: #0f172a;
310
+ font-weight: 700;
311
+ font-size: 0.9rem;
312
+ padding: 8px 18px;
313
+ border: none;
314
+ border-radius: 8px;
315
+ cursor: pointer;
316
+ box-shadow: 0 4px 14px rgba(255, 180, 0, 0.4);
317
+ transition: transform 0.15s ease, box-shadow 0.15s ease;
318
+ }
319
+
320
+ .tutorial-btn-next:hover {
321
+ transform: translateY(-1px);
322
+ box-shadow: 0 6px 20px rgba(255, 180, 0, 0.6);
323
+ }
324
+
325
+ .tutorial-btn-next:active {
326
+ transform: translateY(1px);
327
+ }
@@ -1,4 +1,4 @@
1
- import{$d as Wt,A as Xe,Ad as le,Cd as Nt,Dd as Ae,Ea as gt,Eb as E,Ed as tt,G as D,Gb as Et,Hb as Ne,Hd as Pt,Id as Ot,La as yt,M as $e,Ma as St,Mb as ue,N as Le,Nb as It,Nc as Be,Od as xt,Pc as T,Pd as Dt,Qc as Ct,Qd as Oe,Ra as wt,Rb as ge,Rd as Vt,S as Re,Sb as Pe,Sc as Bt,Sd as Mt,Td as Ft,Ud as Kt,Vb as vt,Vd as Ut,Wb as Gt,Wd as xe,Xd as ye,Yb as Je,Yd as Se,Zd as we,_b as W,_d as jt,a as h,ae as Y,bc as se,be as Ht,c as Ge,ce as Yt,d as Ce,de as qt,e as fe,ee as Xt,f as Ye,fb as ee,fd as At,fe as zt,g as z,gb as _t,ge as Jt,h as qe,he as Zt,ia as ze,id as kt,ie as Qt,j as b,jd as Tt,p as u,pd as Ze,qd as Qe,sd as $t,t as M,td as Lt,ua as ft,va as ut,vd as Rt,zd as et}from"./chunk-XLQ3UCQY.mjs";var ea=!1,ce={COMMON:{ALGO:Ge.sha_256,TYPE:Et.hash_reveal_v1,ROUNDS:2,REPLENISH:Ne.topUp},CONNECT_POOL:{ID:ge,VERB:It,SIZE:10,SELECT_SEQUENTIALLY:2,SELECT_RANDOMLY:2,TARGET_BINDING_COUNT:0,SERVER_DEMAND_COUNT:3}};function De(r){let e=`[${De.name}]`;try{ea&&console.log(`${e} starting... (I: 3c791af2f978a00a087dfdde90884826)`);let t=(r.data?.challengePools??[]).find(i=>i.id===ce.CONNECT_POOL.ID);if(!t)throw new Error(`Keystone missing "${ce.CONNECT_POOL.ID}" pool (E: 6382e29260e4ddbac42ed18f49733526)`);let n=Object.keys(t.challenges).sort();if(n.length===0)throw new Error("Connect pool has no challenges (E: 1ef62fdbda182a790835c8c796475226)");let o=n[0],s=t.challenges[o];return{challengeId:o,challenge:s}}catch(t){throw console.error(`${e} ${b(t)}`),t}finally{ea&&console.log(`${e} complete.`)}}h(De,"getConnectChallenge");var In="auth-challenge-init",vn="auth-init",Gn="auth-challenge",Cn="auth-proof",Bn="auth-ok",An="auth-fail",kn="sync-frame",Tn="sync-frame-response",$n="sync-frame-authenticated",Ln="sync-frame-response-authenticated",Rn="domain-payload",Nn="sync-error",L={auth_challenge_init:In,auth_init:vn,auth_challenge:Gn,auth_proof:Cn,auth_ok:Bn,auth_fail:An,sync_frame:kn,sync_frame_response:Tn,sync_frame_authenticated:$n,sync_frame_response_authenticated:Ln,domain_payload:Rn,sync_error:Nn},Ve=Object.values(L);function at(r){return Ve.includes(r)}h(at,"isSyncWebSocketMsgType");function ta(r){throw new Error(`Unhandled message type: ${r} (E: e928a3f82cd7469a98ef1bc248a3f826)`)}h(ta,"assertUnreachable");var te=!1,_e=class r extends Ht{static{h(this,"SyncPeerWebSocketSender_V1")}lc=`[${r.name}]`;get classname(){return r.name}get isSocketOpen(){return this.ws!==void 0&&this.ws.readyState===WebSocket.OPEN}ws;activeResolve;activeReject;pendingPayloadsToSend=[];handshakeMessageListener;constructor(e,t){super(e,t)}async preConnectCheck(e){let t=`${this.lc}[${this.preConnectCheck.name}]`;if(!this.data?.wsUrl)throw new Error("Missing wsUrl in peer data (E: 144c6ddf53980554cf08fa0896bd9826)");if(!this.data?.httpEvolveUrl)throw new Error("Missing httpEvolveUrl in peer data (E: 53425c1a13f829b8e8a55c2cea3a4a26)")}async postEstablishToReceiver({newSenderIdentity:e,sessionIdentity:t}){let n=`${this.lc}[${this.postEstablishToReceiver.name}]`;try{if(te&&console.log(`${n} posting evolved keystones to ${this.data.httpEvolveUrl}...`),!this.data)throw new Error("(UNEXPECTED) this.data falsy? (E: d642e8a9af18b532c87c6f581aa53b26)");if(!this.data.httpEvolveUrl)throw new Error("(UNEXPECTED) this.data.httpEvolveUrl falsy? (E: 8589ddbb155914d85c09658881da2c26)");let o=await fetch(this.data.httpEvolveUrl,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({keystoneIbGib:e,relatedKeystoneIbGibs:[t]})});if(!o.ok){let s=await o.json().catch(()=>({})),i=s.message||s.error||"Unknown error";throw new Error(`HTTP ${o.status} evolution post rejected. errorMsg: ${i} (E: e8a478291b88d05c68cf6b385684b826)`)}te&&console.log(`${n} evolve post accepted by server.`)}catch(o){throw console.error(`${n} establish post failed: ${b(o)}`),o}}async connectImpl(e){let t=`${this.lc}[${this.connectImpl.name}]`;try{te&&console.log(`${t} starting...`);let{senderIdentity:n,fnSenderSecret:o,sagaId:s,localMetaspace:i,localSpace:c}=this.opts;if(!n||!o||!s)throw new Error("Missing identity parameters in peer options (E: ed49b6711ac82efcdb42b8a28c5b6826)");let l=await o(),d=await jt({senderSecret:l,sagaId:s}),p=u({ibGib:n}),f=u({ibGib:(n.rel8ns?.past,n)}),y=await i.getLatestAddr({ibGib:n,space:c});if(!y)throw new Error("senderIdentityLatestAddr falsy. we should have a latest addr that is different than the sender identity at this point (done in the peer establish phase) (E: 225607318bef485d7821f82de97b6826)");let w=((await i.get({addrs:[y],space:c})).ibGibs?.[0]).data.proofs.at(0)?.claim.target;if(!w)throw new Error("Could not locate session keystone target from identity (E: 5ec4882f7e5e4c33fbd00ab8b3166726)");let I=(await i.get({addrs:[w],space:c})).ibGibs?.[0];if(!I)throw new Error(`Session keystone not found in local space: ${w} (E: 9ba818e6622808bb4ae749be31f80b26)`);let A=(I.data?.challengePools??[]).find(K=>K.id===ce.CONNECT_POOL.ID);if(!A)throw new Error("Session keystone missing connect pool (E: f50968afca04b6d38ec19824ea201826)");let{challengeId:v}=De(I),G=Je.create({config:A.config}),k=await G.derivePoolSecret({masterSecret:d}),$=await G.generateSolution({poolSecret:k,poolId:ce.CONNECT_POOL.ID,challengeId:v}),P=`${this.data.wsUrl}?sAddr=${encodeURIComponent(w)}&solution=${encodeURIComponent($.value)}`;te&&console.log(`${t} connecting to WebSocket: ${P}`);let O=new WebSocket(P);return this.ws=O,new Promise((K,F)=>{let U=!1;O.addEventListener("open",()=>{te&&console.log(`${t} WebSocket opened. Awaiting challenge...`)}),this.handshakeMessageListener=async j=>{try{let H=JSON.parse(j.data);te&&console.log(`${t} received handshake frame: ${H.type}`);let Q=H.type;if(!at(Q)){let be=Ve.join(", ");throw new Error(`Unknown message type '${Q}' received during connection handshake. Valid types are: ${be} (E: e983271bc84f46928e4695be2409826)`)}switch(Q){case L.auth_challenge_init:await this.handleHandshakeAuthChallengeInit(O,w);break;case L.auth_challenge:await this.handleHandshakeAuthChallenge(O,H,I,d);break;case L.auth_ok:U=!0,this.handleHandshakeAuthOk(O,K);break;case L.auth_fail:this.handleHandshakeAuthFail(H,F);break;case L.sync_error:this.handleHandshakeSyncError(H,F);break;case L.auth_init:case L.auth_proof:case L.sync_frame:case L.sync_frame_response:case L.sync_frame_authenticated:case L.sync_frame_response_authenticated:case L.domain_payload:throw new Error(`Unexpected message type '${Q}' during connection handshake (E: e3f80c68ab2a46c2b1858c8a1e2f8926)`);default:ta(Q)}}catch(H){console.error(`${t} ${b(H)}`),F(H)}},O.addEventListener("message",this.handshakeMessageListener),O.addEventListener("close",j=>{U||(this.disconnect(),F(new Error(`WebSocket closed before connect completed (code: ${j.code})`)))}),O.addEventListener("error",j=>{U||(this.disconnect(),F(new Error("WebSocket connection error")))})})}catch(n){throw console.error(`${t} connect failed: ${b(n)}`),n}}disconnect(){let e=`${this.lc}[${this.disconnect.name}]`;try{if(te&&console.log(`${e} starting... (I: 35c4b85fca0c6e9d042f5ff87cde3826)`),this.ws){this.handshakeMessageListener&&(this.ws.removeEventListener("message",this.handshakeMessageListener),this.handshakeMessageListener=void 0);try{this.ws.close()}catch(t){console.error(`${e} failed to close websocket: ${b(t)}`)}this.ws=void 0}}catch(t){console.error(`${e} ${b(t)}`)}finally{te&&console.log(`${e} complete.`)}}async handleRuntimeMessage(e){let t=`${this.lc}[${this.handleRuntimeMessage.name}]`;try{let n=JSON.parse(e.data);te&&console.log(`${t} received runtime frame: ${n.type}`);let o=n.type;if(!at(o)){let s=Ve.join(", ");throw new Error(`Unknown message type '${o}' received during active sync saga loop. Valid types are: ${s} (E: e23a8d10b74d47fb90518f8e3f4b826)`)}switch(o){case L.sync_frame_response:await this.handleRuntimeSyncFrameResponse(n);break;case L.sync_frame_authenticated:this.handleRuntimeSyncFrameAuthenticated();break;case L.domain_payload:this.handleRuntimeDomainPayload(n);break;case L.sync_error:this.handleRuntimeSyncError(n);break;case L.auth_challenge_init:case L.auth_init:case L.auth_challenge:case L.auth_proof:case L.auth_ok:case L.auth_fail:case L.sync_frame:case L.sync_frame_response_authenticated:throw new Error(`Unexpected message type '${o}' during active sync saga loop (E: e982b12cf92c448bbad0e84b7263c826)`);default:ta(o)}}catch(n){if(console.error(`${t} failed parsing/handling runtime frame: ${b(n)}`),this.disconnect(),this.activeReject){let o=this.activeReject;this.activeResolve=void 0,this.activeReject=void 0,o(n)}}}async handleHandshakeAuthChallengeInit(e,t){e.send(JSON.stringify({type:L.auth_init,sAddr:t}))}async handleHandshakeAuthChallenge(e,t,n,o){let{challengeUuid:s,demandedIds:i}=t;te&&console.log(`${this.lc} solving demanded challenges: ${i.join(", ")}`);let c=await this.signContextConnect({challengeUuid:s,demandedIds:i});if(!c)throw new Error("Failed to sign connect challenge proof (E: e9807f28ae9248bbadd0a7f1a8e9826)");e.send(JSON.stringify({type:L.auth_proof,proofFrame:c}))}handleHandshakeAuthOk(e,t){te&&console.log(`${this.lc} WebSocket connect SUCCESS!`),this.handshakeMessageListener&&(e.removeEventListener("message",this.handshakeMessageListener),this.handshakeMessageListener=void 0),e.addEventListener("message",n=>this.handleRuntimeMessage(n)),t()}handleHandshakeAuthFail(e,t){this.disconnect(),t(new Error(`Handshake auth failed: ${e.message||"Unknown fail reason"} (E: f380b271a2be498db257bc8209fa8926)`))}handleHandshakeSyncError(e,t){this.disconnect(),t(new Error(`Handshake sync error: ${e.message||e.error||"Unknown sync error"} (E: f9208a01fe434cbbad83f210ea8f3426)`))}async handleRuntimeSyncFrameResponse(e){let t=e.context,n=await Wt({context:t});if(n.length>0)throw new Error(`Invalid response context received: ${n.join(", ")} (E: d7b5a283cf4c43ba8659c803800cf826)`);let o=[_t({ibGib:t}),t.sagaFrame,t.sagaFrameMsg];t.signedSessionIdentity&&o.push(t.signedSessionIdentity);let{localSpace:s}=this.opts;for(let c of o)await ut({space:s,ibGibs:[c]}),await gt({space:s,ibGib:c});if((t.data?.["@payloadAddrsDomain"]||[]).length>0&&this.ws.send(JSON.stringify({type:L.sync_frame_response_authenticated,contextAddr:u({ibGib:t})})),this.activeResolve){let c=this.activeResolve;this.activeResolve=void 0,this.activeReject=void 0,c(t)}}handleRuntimeSyncFrameAuthenticated(){let e=this.pendingPayloadsToSend||[];this.pendingPayloadsToSend=[];for(let t of e)this.ws.send(JSON.stringify({type:L.domain_payload,ibGib:t}))}handleRuntimeDomainPayload(e){let t=e.ibGib;this.payloadIbGibsDomainReceived$.next(t)}handleRuntimeSyncError(e){let t=e.message||e.error||"Unknown sync runtime error",n=new Error(`Sync runtime error from receiver: ${t} (E: e983bc1c828d447fa0581da2b8004f26)`);if(this.activeReject){let o=this.activeReject;this.activeResolve=void 0,this.activeReject=void 0,o(n)}else throw n}async sendContextRequest(e){let t=`${this.lc}[${this.sendContextRequest.name}]`;try{if(!this.ws||this.ws.readyState!==WebSocket.OPEN)throw new Error("WebSocket is not connected or open (E: 2979923231b882c5d6529e88b3f16826)");let n=e.payloadIbGibsDomain??[];this.pendingPayloadsToSend=[...n];let o={...e};return delete o.payloadIbGibsDomain,new Promise((s,i)=>{this.activeResolve=s,this.activeReject=i,this.ws.send(JSON.stringify({type:L.sync_frame,context:o}))})}catch(n){throw console.error(`${t} sendContextRequest failed: ${b(n)}`),n}}};var aa={$schema:"../../../../libs/core-gib/dist/keystone/policy/schemas/keystone.medium.schema.json",metadata:{name:"Space-Gib Default Identity Policy",securityLevel:"medium"},pools:{sync:{id:"sync",allowedVerbs:["sync"],algo:"SHA-256",rounds:1,behavior:{size:200,replenish:"top-up",selectSequentially:2,selectRandomly:2,targetBindingCount:5}},manage:{id:"manage",allowedVerbs:["manage"],algo:"SHA-512",rounds:10,behavior:{size:2e3,replenish:"replace-all",selectSequentially:5,selectRandomly:5,targetBindingCount:16}},revoke:{id:"revoke",allowedVerbs:["revoke"],algo:"SHA-512",rounds:10,behavior:{size:2e3,replenish:"delete-all",selectSequentially:5,selectRandomly:5,targetBindingCount:16}},connect:{id:"connect",allowedVerbs:["connect"],algo:"SHA-256",rounds:1,behavior:{size:20,replenish:"top-up",selectSequentially:2,selectRandomly:2,targetBindingCount:3}}}};var On=aa.pools;function Me(r,e){let t=On[r];if(!t)throw new Error(`Pool template not found in space-gib JSON config: ${r}`);return Gt({template:t,salt:e})}h(Me,"getSpaceGibPoolConfig");var V={COMMON:ce.COMMON,DEFAULT_POOL:{ID:"default",SIZE:20,SELECT_SEQUENTIALLY:2,SELECT_RANDOMLY:2,TARGET_BINDING_COUNT:3},CONNECT_POOL:ce.CONNECT_POOL},Nr={MIN_DEFAULT_POOL_SIZE:50,ALLOWED_ALGORITHMS:[Ge.sha_256,Ge.sha_512]};var B=class extends Ct{static{h(this,"SpaceGibApiBridge")}lc="[SpaceGibApiBridge]"},xn=new B;Bt(xn);var N="[dev-tools]",m={};window.ibgibDebugState=m;function a(r){let e=document.getElementById("dev-panel-log");if(!e)return;let t=new Date().toISOString().slice(11,23);e.textContent=`[${t}] ${r}
1
+ import{$d as Wt,A as Xe,Ad as le,Cd as Nt,Dd as Ae,Ea as gt,Eb as E,Ed as tt,G as D,Gb as Et,Hb as Ne,Hd as Pt,Id as Ot,La as yt,M as $e,Ma as St,Mb as ue,N as Le,Nb as It,Nc as Be,Od as xt,Pc as T,Pd as Dt,Qc as Ct,Qd as Oe,Ra as wt,Rb as ge,Rd as Vt,S as Re,Sb as Pe,Sc as Bt,Sd as Mt,Td as Ft,Ud as Kt,Vb as vt,Vd as Ut,Wb as Gt,Wd as xe,Xd as ye,Yb as Je,Yd as Se,Zd as we,_b as W,_d as jt,a as h,ae as Y,bc as se,be as Ht,c as Ge,ce as Yt,d as Ce,de as qt,e as fe,ee as Xt,f as Ye,fb as ee,fd as At,fe as zt,g as z,gb as _t,ge as Jt,h as qe,he as Zt,ia as ze,id as kt,ie as Qt,j as b,jd as Tt,p as u,pd as Ze,qd as Qe,sd as $t,t as M,td as Lt,ua as ft,va as ut,vd as Rt,zd as et}from"./chunk-J7X3XTAI.mjs";var ea=!1,ce={COMMON:{ALGO:Ge.sha_256,TYPE:Et.hash_reveal_v1,ROUNDS:2,REPLENISH:Ne.topUp},CONNECT_POOL:{ID:ge,VERB:It,SIZE:10,SELECT_SEQUENTIALLY:2,SELECT_RANDOMLY:2,TARGET_BINDING_COUNT:0,SERVER_DEMAND_COUNT:3}};function De(r){let e=`[${De.name}]`;try{ea&&console.log(`${e} starting... (I: 3c791af2f978a00a087dfdde90884826)`);let t=(r.data?.challengePools??[]).find(i=>i.id===ce.CONNECT_POOL.ID);if(!t)throw new Error(`Keystone missing "${ce.CONNECT_POOL.ID}" pool (E: 6382e29260e4ddbac42ed18f49733526)`);let n=Object.keys(t.challenges).sort();if(n.length===0)throw new Error("Connect pool has no challenges (E: 1ef62fdbda182a790835c8c796475226)");let o=n[0],s=t.challenges[o];return{challengeId:o,challenge:s}}catch(t){throw console.error(`${e} ${b(t)}`),t}finally{ea&&console.log(`${e} complete.`)}}h(De,"getConnectChallenge");var In="auth-challenge-init",vn="auth-init",Gn="auth-challenge",Cn="auth-proof",Bn="auth-ok",An="auth-fail",kn="sync-frame",Tn="sync-frame-response",$n="sync-frame-authenticated",Ln="sync-frame-response-authenticated",Rn="domain-payload",Nn="sync-error",L={auth_challenge_init:In,auth_init:vn,auth_challenge:Gn,auth_proof:Cn,auth_ok:Bn,auth_fail:An,sync_frame:kn,sync_frame_response:Tn,sync_frame_authenticated:$n,sync_frame_response_authenticated:Ln,domain_payload:Rn,sync_error:Nn},Ve=Object.values(L);function at(r){return Ve.includes(r)}h(at,"isSyncWebSocketMsgType");function ta(r){throw new Error(`Unhandled message type: ${r} (E: e928a3f82cd7469a98ef1bc248a3f826)`)}h(ta,"assertUnreachable");var te=!1,_e=class r extends Ht{static{h(this,"SyncPeerWebSocketSender_V1")}lc=`[${r.name}]`;get classname(){return r.name}get isSocketOpen(){return this.ws!==void 0&&this.ws.readyState===WebSocket.OPEN}ws;activeResolve;activeReject;pendingPayloadsToSend=[];handshakeMessageListener;constructor(e,t){super(e,t)}async preConnectCheck(e){let t=`${this.lc}[${this.preConnectCheck.name}]`;if(!this.data?.wsUrl)throw new Error("Missing wsUrl in peer data (E: 144c6ddf53980554cf08fa0896bd9826)");if(!this.data?.httpEvolveUrl)throw new Error("Missing httpEvolveUrl in peer data (E: 53425c1a13f829b8e8a55c2cea3a4a26)")}async postEstablishToReceiver({newSenderIdentity:e,sessionIdentity:t}){let n=`${this.lc}[${this.postEstablishToReceiver.name}]`;try{if(te&&console.log(`${n} posting evolved keystones to ${this.data.httpEvolveUrl}...`),!this.data)throw new Error("(UNEXPECTED) this.data falsy? (E: d642e8a9af18b532c87c6f581aa53b26)");if(!this.data.httpEvolveUrl)throw new Error("(UNEXPECTED) this.data.httpEvolveUrl falsy? (E: 8589ddbb155914d85c09658881da2c26)");let o=await fetch(this.data.httpEvolveUrl,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({keystoneIbGib:e,relatedKeystoneIbGibs:[t]})});if(!o.ok){let s=await o.json().catch(()=>({})),i=s.message||s.error||"Unknown error";throw new Error(`HTTP ${o.status} evolution post rejected. errorMsg: ${i} (E: e8a478291b88d05c68cf6b385684b826)`)}te&&console.log(`${n} evolve post accepted by server.`)}catch(o){throw console.error(`${n} establish post failed: ${b(o)}`),o}}async connectImpl(e){let t=`${this.lc}[${this.connectImpl.name}]`;try{te&&console.log(`${t} starting...`);let{senderIdentity:n,fnSenderSecret:o,sagaId:s,localMetaspace:i,localSpace:c}=this.opts;if(!n||!o||!s)throw new Error("Missing identity parameters in peer options (E: ed49b6711ac82efcdb42b8a28c5b6826)");let l=await o(),d=await jt({senderSecret:l,sagaId:s}),p=u({ibGib:n}),f=u({ibGib:(n.rel8ns?.past,n)}),y=await i.getLatestAddr({ibGib:n,space:c});if(!y)throw new Error("senderIdentityLatestAddr falsy. we should have a latest addr that is different than the sender identity at this point (done in the peer establish phase) (E: 225607318bef485d7821f82de97b6826)");let w=((await i.get({addrs:[y],space:c})).ibGibs?.[0]).data.proofs.at(0)?.claim.target;if(!w)throw new Error("Could not locate session keystone target from identity (E: 5ec4882f7e5e4c33fbd00ab8b3166726)");let I=(await i.get({addrs:[w],space:c})).ibGibs?.[0];if(!I)throw new Error(`Session keystone not found in local space: ${w} (E: 9ba818e6622808bb4ae749be31f80b26)`);let A=(I.data?.challengePools??[]).find(K=>K.id===ce.CONNECT_POOL.ID);if(!A)throw new Error("Session keystone missing connect pool (E: f50968afca04b6d38ec19824ea201826)");let{challengeId:v}=De(I),G=Je.create({config:A.config}),k=await G.derivePoolSecret({masterSecret:d}),$=await G.generateSolution({poolSecret:k,poolId:ce.CONNECT_POOL.ID,challengeId:v}),P=`${this.data.wsUrl}?sAddr=${encodeURIComponent(w)}&solution=${encodeURIComponent($.value)}`;te&&console.log(`${t} connecting to WebSocket: ${P}`);let O=new WebSocket(P);return this.ws=O,new Promise((K,F)=>{let U=!1;O.addEventListener("open",()=>{te&&console.log(`${t} WebSocket opened. Awaiting challenge...`)}),this.handshakeMessageListener=async j=>{try{let H=JSON.parse(j.data);te&&console.log(`${t} received handshake frame: ${H.type}`);let Q=H.type;if(!at(Q)){let be=Ve.join(", ");throw new Error(`Unknown message type '${Q}' received during connection handshake. Valid types are: ${be} (E: e983271bc84f46928e4695be2409826)`)}switch(Q){case L.auth_challenge_init:await this.handleHandshakeAuthChallengeInit(O,w);break;case L.auth_challenge:await this.handleHandshakeAuthChallenge(O,H,I,d);break;case L.auth_ok:U=!0,this.handleHandshakeAuthOk(O,K);break;case L.auth_fail:this.handleHandshakeAuthFail(H,F);break;case L.sync_error:this.handleHandshakeSyncError(H,F);break;case L.auth_init:case L.auth_proof:case L.sync_frame:case L.sync_frame_response:case L.sync_frame_authenticated:case L.sync_frame_response_authenticated:case L.domain_payload:throw new Error(`Unexpected message type '${Q}' during connection handshake (E: e3f80c68ab2a46c2b1858c8a1e2f8926)`);default:ta(Q)}}catch(H){console.error(`${t} ${b(H)}`),F(H)}},O.addEventListener("message",this.handshakeMessageListener),O.addEventListener("close",j=>{U||(this.disconnect(),F(new Error(`WebSocket closed before connect completed (code: ${j.code})`)))}),O.addEventListener("error",j=>{U||(this.disconnect(),F(new Error("WebSocket connection error")))})})}catch(n){throw console.error(`${t} connect failed: ${b(n)}`),n}}disconnect(){let e=`${this.lc}[${this.disconnect.name}]`;try{if(te&&console.log(`${e} starting... (I: 35c4b85fca0c6e9d042f5ff87cde3826)`),this.ws){this.handshakeMessageListener&&(this.ws.removeEventListener("message",this.handshakeMessageListener),this.handshakeMessageListener=void 0);try{this.ws.close()}catch(t){console.error(`${e} failed to close websocket: ${b(t)}`)}this.ws=void 0}}catch(t){console.error(`${e} ${b(t)}`)}finally{te&&console.log(`${e} complete.`)}}async handleRuntimeMessage(e){let t=`${this.lc}[${this.handleRuntimeMessage.name}]`;try{let n=JSON.parse(e.data);te&&console.log(`${t} received runtime frame: ${n.type}`);let o=n.type;if(!at(o)){let s=Ve.join(", ");throw new Error(`Unknown message type '${o}' received during active sync saga loop. Valid types are: ${s} (E: e23a8d10b74d47fb90518f8e3f4b826)`)}switch(o){case L.sync_frame_response:await this.handleRuntimeSyncFrameResponse(n);break;case L.sync_frame_authenticated:this.handleRuntimeSyncFrameAuthenticated();break;case L.domain_payload:this.handleRuntimeDomainPayload(n);break;case L.sync_error:this.handleRuntimeSyncError(n);break;case L.auth_challenge_init:case L.auth_init:case L.auth_challenge:case L.auth_proof:case L.auth_ok:case L.auth_fail:case L.sync_frame:case L.sync_frame_response_authenticated:throw new Error(`Unexpected message type '${o}' during active sync saga loop (E: e982b12cf92c448bbad0e84b7263c826)`);default:ta(o)}}catch(n){if(console.error(`${t} failed parsing/handling runtime frame: ${b(n)}`),this.disconnect(),this.activeReject){let o=this.activeReject;this.activeResolve=void 0,this.activeReject=void 0,o(n)}}}async handleHandshakeAuthChallengeInit(e,t){e.send(JSON.stringify({type:L.auth_init,sAddr:t}))}async handleHandshakeAuthChallenge(e,t,n,o){let{challengeUuid:s,demandedIds:i}=t;te&&console.log(`${this.lc} solving demanded challenges: ${i.join(", ")}`);let c=await this.signContextConnect({challengeUuid:s,demandedIds:i});if(!c)throw new Error("Failed to sign connect challenge proof (E: e9807f28ae9248bbadd0a7f1a8e9826)");e.send(JSON.stringify({type:L.auth_proof,proofFrame:c}))}handleHandshakeAuthOk(e,t){te&&console.log(`${this.lc} WebSocket connect SUCCESS!`),this.handshakeMessageListener&&(e.removeEventListener("message",this.handshakeMessageListener),this.handshakeMessageListener=void 0),e.addEventListener("message",n=>this.handleRuntimeMessage(n)),t()}handleHandshakeAuthFail(e,t){this.disconnect(),t(new Error(`Handshake auth failed: ${e.message||"Unknown fail reason"} (E: f380b271a2be498db257bc8209fa8926)`))}handleHandshakeSyncError(e,t){this.disconnect(),t(new Error(`Handshake sync error: ${e.message||e.error||"Unknown sync error"} (E: f9208a01fe434cbbad83f210ea8f3426)`))}async handleRuntimeSyncFrameResponse(e){let t=e.context,n=await Wt({context:t});if(n.length>0)throw new Error(`Invalid response context received: ${n.join(", ")} (E: d7b5a283cf4c43ba8659c803800cf826)`);let o=[_t({ibGib:t}),t.sagaFrame,t.sagaFrameMsg];t.signedSessionIdentity&&o.push(t.signedSessionIdentity);let{localSpace:s}=this.opts;for(let c of o)await ut({space:s,ibGibs:[c]}),await gt({space:s,ibGib:c});if((t.data?.["@payloadAddrsDomain"]||[]).length>0&&this.ws.send(JSON.stringify({type:L.sync_frame_response_authenticated,contextAddr:u({ibGib:t})})),this.activeResolve){let c=this.activeResolve;this.activeResolve=void 0,this.activeReject=void 0,c(t)}}handleRuntimeSyncFrameAuthenticated(){let e=this.pendingPayloadsToSend||[];this.pendingPayloadsToSend=[];for(let t of e)this.ws.send(JSON.stringify({type:L.domain_payload,ibGib:t}))}handleRuntimeDomainPayload(e){let t=e.ibGib;this.payloadIbGibsDomainReceived$.next(t)}handleRuntimeSyncError(e){let t=e.message||e.error||"Unknown sync runtime error",n=new Error(`Sync runtime error from receiver: ${t} (E: e983bc1c828d447fa0581da2b8004f26)`);if(this.activeReject){let o=this.activeReject;this.activeResolve=void 0,this.activeReject=void 0,o(n)}else throw n}async sendContextRequest(e){let t=`${this.lc}[${this.sendContextRequest.name}]`;try{if(!this.ws||this.ws.readyState!==WebSocket.OPEN)throw new Error("WebSocket is not connected or open (E: 2979923231b882c5d6529e88b3f16826)");let n=e.payloadIbGibsDomain??[];this.pendingPayloadsToSend=[...n];let o={...e};return delete o.payloadIbGibsDomain,new Promise((s,i)=>{this.activeResolve=s,this.activeReject=i,this.ws.send(JSON.stringify({type:L.sync_frame,context:o}))})}catch(n){throw console.error(`${t} sendContextRequest failed: ${b(n)}`),n}}};var aa={$schema:"../../../../libs/core-gib/dist/keystone/policy/schemas/keystone.medium.schema.json",metadata:{name:"Space-Gib Default Identity Policy",securityLevel:"medium"},pools:{sync:{id:"sync",allowedVerbs:["sync"],algo:"SHA-256",rounds:1,behavior:{size:200,replenish:"top-up",selectSequentially:2,selectRandomly:2,targetBindingCount:5}},manage:{id:"manage",allowedVerbs:["manage"],algo:"SHA-512",rounds:10,behavior:{size:2e3,replenish:"replace-all",selectSequentially:5,selectRandomly:5,targetBindingCount:16}},revoke:{id:"revoke",allowedVerbs:["revoke"],algo:"SHA-512",rounds:10,behavior:{size:2e3,replenish:"delete-all",selectSequentially:5,selectRandomly:5,targetBindingCount:16}},connect:{id:"connect",allowedVerbs:["connect"],algo:"SHA-256",rounds:1,behavior:{size:20,replenish:"top-up",selectSequentially:2,selectRandomly:2,targetBindingCount:3}}}};var On=aa.pools;function Me(r,e){let t=On[r];if(!t)throw new Error(`Pool template not found in space-gib JSON config: ${r}`);return Gt({template:t,salt:e})}h(Me,"getSpaceGibPoolConfig");var V={COMMON:ce.COMMON,DEFAULT_POOL:{ID:"default",SIZE:20,SELECT_SEQUENTIALLY:2,SELECT_RANDOMLY:2,TARGET_BINDING_COUNT:3},CONNECT_POOL:ce.CONNECT_POOL},Nr={MIN_DEFAULT_POOL_SIZE:50,ALLOWED_ALGORITHMS:[Ge.sha_256,Ge.sha_512]};var B=class extends Ct{static{h(this,"SpaceGibApiBridge")}lc="[SpaceGibApiBridge]"},xn=new B;Bt(xn);var N="[dev-tools]",m={};window.ibgibDebugState=m;function a(r){let e=document.getElementById("dev-panel-log");if(!e)return;let t=new Date().toISOString().slice(11,23);e.textContent=`[${t}] ${r}
2
2
  `+e.textContent}h(a,"devLog");async function na({domainI:r,masterSecret:e,syncSalt:t,metaspace:n,space:o,apiBridge:s}){let i=new se,c=await Ye({s:`${e}-sync-delegate`}),l=await i.genesis({masterSecret:c,configs:[Me("sync",`${t}-delegate`)],metaspace:n,space:o,frameDetails:{client:"space-gib-web-dev-delegate",timestamp:fe()}}),d=await i.registerDelegate({parentKeystone:r,delegateKeystone:l,masterSecret:e,signingPoolId:"manage",metaspace:n,space:o,allowedVerbs:[ue]}),p=u({ibGib:r}),f=await s.putEvolveKeystone({domainAddr:p,keystoneIbGib:d,relatedKeystoneIbGibs:[l]});if(!f.success)throw new Error(`Server rejected delegate evolution: ${f.message}`);return{evolvedDomainI:d,delegateKeystone:l,delegateSecret:c}}h(na,"createAndRegisterSyncDelegate");async function nt({domainI:r,masterSecret:e,metaspace:t,space:n}){let o=r,s=h(async()=>e,"fnSenderSecret"),i=Object.values(r.data?.delegates??{}).find(c=>c.allowedVerbs?.includes(ue));if(i){let c=i.delegateTjpAddr;if(c){let l=await t.getLatestAddr({addr:c,space:n});if(l){let d=await t.get({addr:l,space:n});if(d.success&&d.ibGibs&&d.ibGibs.length>0){o=d.ibGibs[0];let p=await Ye({s:`${e}-sync-delegate`});s=h(async()=>p,"fnSenderSecret")}}}}return{senderIdentity:o,fnSenderSecret:s}}h(nt,"getSenderIdentityInfo");async function ae(r){let e=`${N}[performPhaseSetup(${r.phaseText})]`,t=document.getElementById(r.btnId);if(t)try{t.disabled=!0,a(`${r.phaseText} Setup: Generating Alice's long-lived Domain Keystone (I) and Target (X)...`);let n=await E(),o=await n.getLocalUserSpace({});if(!o)throw new Error("No default space found in metaspace.");let i=await new se().genesis({masterSecret:r.masterSecret,configs:[Me("manage",r.manageSalt)],metaspace:n,space:o,frameDetails:{client:"space-gib-web-dev",timestamp:fe()}});a(`${r.phaseText} Setup: \u2713 Domain Keystone (I) created locally: ${u({ibGib:i})}`),a(`${r.phaseText} Setup: Starting postGenesisKeystone...`);let c=new B,l=await c.postGenesisKeystone(i);if(l.success)a(`${r.phaseText} Setup: \u2713 Domain Keystone registered and stored on receiver (server).`);else throw a(`${r.phaseText} Setup: X postGenesisKeystone failed: ${l.message}.`),new Error(`${r.phaseText} Setup: Server rejected genesis domain keystone: ${l.message}`);a(`${r.phaseText} Setup: Generating and registering sync delegate...`);let{evolvedDomainI:d,delegateKeystone:p}=await na({domainI:i,masterSecret:r.masterSecret,syncSalt:r.syncSalt,metaspace:n,space:o,apiBridge:c});m.domainI=d,m.domainIMasterSecret=r.masterSecret,a(`${r.phaseText} Setup: \u2713 Registered Sync Delegate: ${u({ibGib:p})}`);let f=await D.firstGen({parentIbGib:M,ib:r.ib,data:r.data,dna:!0,nCounter:!0,tjp:{uuid:!0,timestamp:!0}}),y=f.newIbGib;await n.persistTransformResult({resTransform:f,space:o}),await n.registerNewIbGib({ibGib:y}),m.targetX=y,a(`${r.phaseText} Setup: \u2713 Target (X) created and persisted locally: ${u({ibGib:y})}`),a(`\u2713 ${r.phaseText} Setup Complete! Ready for ${r.phaseText} Sync.`),t.textContent=`\u2713 ${r.phaseText} Setup Complete`;let S=document.getElementById(r.nextBtnId);S&&(S.disabled=!1)}catch(n){a(`\u2717 ${r.phaseText} Setup FAILED: ${b(n)}`),console.error(`${e} ${r.phaseText} Setup error:`,n),t.disabled=!1}}h(ae,"performPhaseSetup");async function de(r){let e=`${N}[performPhaseSync(${r.phaseText})]`,t=document.getElementById(r.btnId);if(t)try{t.disabled=!0,a(`${r.phaseText} Sync: Executing senderCoordinator.sync(...) using WebSocket Peer...`);let n=m.domainI,o=m.targetX;if(!n||!o){a(`\u26A0 ${r.phaseText} Sync: Missing setup state. Please run Setup first.`),t.disabled=!1;return}let s=u({ibGib:n}),i=await E(),c=await i.getLocalUserSpace({});if(!c)throw new Error("No default space.");let l=location.protocol==="https:"?"wss:":"ws:",d=new _e({classname:"SyncPeerWebSocketSender_V1",httpEvolveUrl:`${location.protocol}//${location.host}/api/keystone/evolve/${encodeURIComponent(s)}`,wsUrl:`${l}//${location.host}/api/sync/ws/${encodeURIComponent(s)}`}),p=new Y,f=await z();m.sagaId=f,m.senderPeer=d;let{senderIdentity:y,fnSenderSecret:S}=await nt({domainI:n,masterSecret:m.domainIMasterSecret,metaspace:i,space:c});await d.initializeOpts({localMetaspace:i,localSpace:c,senderIdentity:y,fnSenderSecret:S,sagaId:f,sessionConnectPoolConfig:V.CONNECT_POOL,sessionSyncPoolConfig:V.DEFAULT_POOL,targetAddrs:[s]});try{await(await p.sync({domainIbGibs:[o],senderIdentityInfo:{senderIdentity:y,senderDomainAddr:s},fnSenderSecret:S,peer:d,localSpace:c,metaspace:i,conflictStrategy:xe.optimisticWithLCS})).done}catch(w){if(r.expectSyncFailure)a(`${r.phaseText} Sync: Coordinator sync executed (${r.failureMessageSuffix??"errors expected"}): ${b(w)}`);else throw w}a(`\u2713 ${r.phaseText} Sync Execution Complete! Ready for State Checks.`),t.textContent=`\u2713 ${r.phaseText} Sync Run`;let g=document.getElementById(r.nextBtnId);g&&(g.disabled=!1)}catch(n){a(`\u2717 ${r.phaseText} Sync FAILED: ${b(n)}`),console.error(`${e} ${r.phaseText} Sync error:`,n),t.disabled=!1}}h(de,"performPhaseSync");async function rt({localI:r,metaspace:e,space:t}){let n=Object.values(r.data?.delegates??{}).find(p=>p.allowedVerbs?.includes(ue));if(!n)return{};let o=n.delegateTjpAddr;if(!o)return{};let s=await e.getLatestAddr({addr:o,space:t});if(!s)return{delegateTjpAddr:o};let c=(await e.get({addrs:[s],space:t})).ibGibs?.[0];if(!c)return{delegateTjpAddr:o,latestLocalDelegateAddr:s};let d=c.data?.proofs?.find(p=>p.claim?.verb==="sync")?.claim?.target;return{delegateTjpAddr:o,latestLocalDelegateAddr:s,localDelegate:c,sessionIdentityTjpAddr:d}}h(rt,"getDelegateAndSessionInfo");async function x({domainIbGibs:r,passLabel:e,metaspace:t,space:n}){let o=m.domainI,s=m.domainIMasterSecret;if(!o||!s)throw new Error(`runSyncPass[${e}]: Missing domain identity or secret in debugState. Run Setup first.`);let i=u({ibGib:o}),c=location.protocol==="https:"?"wss:":"ws:",{senderIdentity:l,fnSenderSecret:d}=await nt({domainI:o,masterSecret:s,metaspace:t,space:n});a(`Sync: ${e} \u2014 using sender: ${u({ibGib:l}).slice(0,40)}...`);let p=new _e({classname:"SyncPeerWebSocketSender_V1",httpEvolveUrl:`${location.protocol}//${location.host}/api/keystone/evolve/${encodeURIComponent(i)}`,wsUrl:`${c}//${location.host}/api/sync/ws/${encodeURIComponent(i)}`}),f=new Y,y=await z();m.sagaId=y,m.senderPeer=p,await p.initializeOpts({localMetaspace:t,localSpace:n,senderIdentity:l,fnSenderSecret:d,sagaId:y,sessionConnectPoolConfig:V.CONNECT_POOL,sessionSyncPoolConfig:V.DEFAULT_POOL,targetAddrs:[i]}),await(await f.sync({domainIbGibs:r,senderIdentityInfo:{senderIdentity:l,senderDomainAddr:i},fnSenderSecret:d,peer:p,localSpace:n,metaspace:t,conflictStrategy:xe.optimisticWithLCS})).done;let g=await t.getLatestAddr({addr:i,space:n});if(g&&g!==u({ibGib:o})){let w=await t.get({addrs:[g],space:n});w.ibGibs?.[0]&&(m.domainI=w.ibGibs[0])}}h(x,"runSyncPass");async function J({domainIbGibs:r,passLabel:e,metaspace:t,space:n,primarySpace:o,domainI:s,masterSecret:i}){let c=u({ibGib:s}),l=location.protocol==="https:"?"wss:":"ws:",{senderIdentity:d,fnSenderSecret:p}=await nt({domainI:s,masterSecret:i,metaspace:t,space:n});a(`Sync: ${e} \u2014 using sender: ${u({ibGib:d}).slice(0,40)}...`);let f=new _e({classname:"SyncPeerWebSocketSender_V1",httpEvolveUrl:`${location.protocol}//${location.host}/api/keystone/evolve/${encodeURIComponent(c)}`,wsUrl:`${l}//${location.host}/api/sync/ws/${encodeURIComponent(c)}`}),y=new Y,S=await z();m.sagaId=S,m.senderPeer=f,await f.initializeOpts({localMetaspace:t,localSpace:n,senderIdentity:d,fnSenderSecret:p,sagaId:S,sessionConnectPoolConfig:V.CONNECT_POOL,sessionSyncPoolConfig:V.DEFAULT_POOL,targetAddrs:[c]}),await(await y.sync({domainIbGibs:r,senderIdentityInfo:{senderIdentity:d,senderDomainAddr:c},fnSenderSecret:p,peer:f,localSpace:n,metaspace:t,conflictStrategy:xe.optimisticWithLCS})).done;let w=await t.getLatestAddr({addr:c,space:n});if(w){let I=(await t.get({addrs:[w],space:n})).ibGibs?.[0];I&&(m.domainI=I,o&&await X({domainI:I,metaspace:t,fromSpace:n,toSpace:o}))}}h(J,"runSyncPassFromSpace");async function q({masterSecret:r,syncSalt:e,manageSalt:t,metaspace:n,space:o,apiBridge:s,phaseText:i}){let l=await new se().genesis({masterSecret:r,configs:[Me("manage",t)],metaspace:n,space:o,frameDetails:{client:"space-gib-web-dev",timestamp:fe()}});a(`${i} Setup: \u2713 Domain Keystone (I) created locally: ${u({ibGib:l})}`),a(`${i} Setup: Starting postGenesisKeystone...`);let d=await s.postGenesisKeystone(l);if(d.success)a(`${i} Setup: \u2713 Domain Keystone registered and stored on receiver (server).`);else throw a(`${i} Setup: X postGenesisKeystone failed: ${d.message}.`),new Error(`${i} Setup: Server rejected genesis domain keystone: ${d.message}`);a(`${i} Setup: Generating and registering sync delegate...`);let{evolvedDomainI:p,delegateKeystone:f}=await na({domainI:l,masterSecret:r,syncSalt:e,metaspace:n,space:o,apiBridge:s});return m.domainI=p,m.domainIMasterSecret=r,{domainI:p,delegateKeystone:f}}h(q,"setupDomainAndDelegateIdentities");async function Ee({localI:r,metaspace:e,space:t,apiBridge:n,domainAddr:o}){let s=await e.getLatestAddr({addr:o,space:t});if(!s)throw new Error("Evolved domain keystone tip NOT found in local space!");a("\u2713 Check: Evolved Domain Keystone exists locally.");let{latestLocalDelegateAddr:i,sessionIdentityTjpAddr:c}=await rt({localI:r,metaspace:e,space:t});if(!i)throw new Error("Evolved delegate keystone tip NOT found in local space!");if(!c)throw new Error("Delegate sync claim does not target a session keystone.");a("\u2713 Check: Delegate Keystone and Sync Claim to Session verified locally.");let l=await n.getIbGib(o,i);if(!l.success||!l.ibGib)throw new Error("Evolved Delegate Keystone NOT found on server!");a("\u2713 Check: Evolved Delegate Keystone exists on server.");let d=await n.getIbGib(o,s);if(!d.success||!d.ibGib)throw new Error("Evolved Domain Keystone NOT found on server!");return a("\u2713 Check: Evolved Domain Keystone exists on server."),{latestLocalIAddr:s,latestLocalDelegateAddr:i,sessionIdentityTjpAddr:c}}h(Ee,"verifyIdentitiesOnServer");async function X({domainI:r,metaspace:e,fromSpace:t,toSpace:n}){let o=u({ibGib:r}),s=await e.getLatestAddr({addr:o,space:t});if(!s)throw new Error("Could not find latest domain I address.");let c=(await e.get({addrs:[s],space:t})).ibGibs?.[0];if(!c)throw new Error("Could not get latest domain I.");let l=await e.getDependencyGraph({ibGibAddr:s,space:t});await e.put({ibGibs:Object.values(l),space:n}),await e.registerNewIbGib({ibGib:c,space:n});let d=Object.values(c.data?.delegates??{}).find(p=>p.allowedVerbs?.includes(ue));if(d){let p=d.delegateTjpAddr;if(p){let f=await e.getLatestAddr({addr:p,space:t});if(f){let S=(await e.get({addrs:[f],space:t})).ibGibs?.[0];if(S){let g=await e.getDependencyGraph({ibGibAddr:f,space:t});await e.put({ibGibs:Object.values(g),space:n}),await e.registerNewIbGib({ibGib:S,space:n})}}}}}h(X,"copyIdentitiesToSpace");var ie=null;function ra(){let r=`${N}[initWsTestButton]`,e=document.getElementById("btn-test-ws");if(!e){console.warn(`${r} btn-test-ws not found \u2014 skipping`);return}e.addEventListener("click",()=>{try{if(ie&&ie.readyState===WebSocket.OPEN){ie.send(JSON.stringify({ping:"hello from client",ts:Date.now()})),a("\u2192 sent ping on existing connection");return}let n=`${location.protocol==="https:"?"wss:":"ws:"}//${location.host}/api/debug/ws-echo`;a(`\u2192 connecting to ${n}`),ie=new WebSocket(n),ie.addEventListener("open",()=>{a("\u2713 WebSocket connected"),e.textContent="Send WS Ping"}),ie.addEventListener("message",o=>{a(`\u2190 ${o.data}`)}),ie.addEventListener("close",o=>{a(`\u2717 WebSocket closed (code ${o.code})`),e.textContent="Test WebSocket",ie=null}),ie.addEventListener("error",o=>{a("\u2717 WebSocket error \u2014 check console"),console.error(`${r} WebSocket error`,o)})}catch(t){a(`\u2717 ${b(t)}`),console.error(`${r} ${b(t)}`)}})}h(ra,"initWsTestButton");function oa(){let r=document.getElementById("btn-print-dev-state");r&&r.addEventListener("click",()=>{a("Printing debug state to console..."),console.dir(m)})}h(oa,"initPrintStateButton");function ia(){let r=`${N}[initCreateDomainKeystoneButton]`,e=document.getElementById("btn-create-domain-keystone");e&&e.addEventListener("click",async()=>{try{e.disabled=!0,a("Generating dummy Domain Keystone (I)...");let t=await E(),n=await t.getLocalUserSpace({});if(!n)throw new Error("No default space found in metaspace.");let o="password",i=await new se().genesis({masterSecret:o,configs:[vt({id:"default",salt:await z(),replenishStrategy:Ne.topUp})],metaspace:t,space:n,frameDetails:{client:"space-gib-web-dev",timestamp:fe()}}),c=u({ibGib:i});a(`\u2713 Local genesis complete: ${c}`),m.domainI=i,m.domainIMasterSecret=o,a("Posting genesis keystone to server...");let d=await new B().postGenesisKeystone(i);if(!d.success){a(`\u2717 Server rejected genesis keystone: ${d.message}`),e.disabled=!1;return}a("\u2713 Server accepted Domain Keystone (I)"),e.textContent="\u2713 Domain Keystone Created";let p=document.getElementById("btn-create-test-ibgib");p&&(p.disabled=!1)}catch(t){a(`\u2717 ${b(t)}`),console.error(`${r} ${b(t)}`),e.disabled=!1}})}h(ia,"initCreateDomainKeystoneButton");function sa(){let r=`${N}[initCreateTestIbGibButton]`,e=document.getElementById("btn-create-test-ibgib");if(!e){console.warn(`${r} btn-create-test-ibgib not found \u2014 skipping`);return}e.addEventListener("click",async()=>{try{a("Generating dummy X^Xtjp ibgib...");let n=(await D.firstGen({parentIbGib:M,ib:"test data",data:{hello:"world",random:Math.random()},dna:!0,nCounter:!0,tjp:{uuid:!0,timestamp:!0}})).newIbGib,o=u({ibGib:n});m.targetX=n,a(`\u2713 Created X: ${o}`),e.textContent="\u2713 Test IbGib (X) Created";let s=document.getElementById("btn-create-session-keystone");s&&(s.disabled=!1)}catch(t){a(`\u2717 ${b(t)}`),console.error(`${r} ${b(t)}`)}})}h(sa,"initCreateTestIbGibButton");function ca(){let r=`${N}[initCreateSessionKeystoneButton]`,e=document.getElementById("btn-create-session-keystone");if(!e){console.warn(`${r} btn-create-session-keystone not found \u2014 skipping`);return}e.addEventListener("click",async()=>{try{a("Generating Session Keystone (S^Stjp)...");let t=m.domainI,n=m.targetX;if(!t){a("\u26A0 No domain keystone (I) found in state. Please Create Domain Keystone first.");return}if(!n){a("\u26A0 No target ibgib (X) found in state. Please Create Test IbGib first.");return}let o=await E(),s=await o.getLocalUserSpace({});if(!s)throw new Error("No default space found in metaspace.");let i="ephemeral-"+Math.random().toString(),c=new se;console.warn(`${N}[NAG] placeholder genesis keystone config right now (W: 69b108687cf8bec0f9a8e148bcca8d26)`);let l=await c.genesis({masterSecret:i,configs:[{id:V.DEFAULT_POOL.ID,salt:await z(),type:V.COMMON.TYPE,algo:V.COMMON.ALGO,rounds:V.COMMON.ROUNDS,behavior:{size:V.DEFAULT_POOL.SIZE,replenish:V.COMMON.REPLENISH,selectSequentially:V.DEFAULT_POOL.SELECT_SEQUENTIALLY,selectRandomly:V.DEFAULT_POOL.SELECT_RANDOMLY,targetBindingCount:V.DEFAULT_POOL.TARGET_BINDING_COUNT},allowedVerbs:[]},{id:V.CONNECT_POOL.ID,salt:await z(),type:V.COMMON.TYPE,algo:V.COMMON.ALGO,rounds:V.COMMON.ROUNDS,behavior:{size:V.CONNECT_POOL.SIZE,replenish:V.COMMON.REPLENISH,selectSequentially:V.CONNECT_POOL.SELECT_SEQUENTIALLY,selectRandomly:V.CONNECT_POOL.SELECT_RANDOMLY,targetBindingCount:V.CONNECT_POOL.TARGET_BINDING_COUNT},allowedVerbs:[V.CONNECT_POOL.VERB]}],metaspace:o,space:s,frameDetails:{client:"space-gib-web-session",target_I:t?u({ibGib:t}):void 0,target_X:n?u({ibGib:n}):void 0}}),d=u({ibGib:l});m.sessionS=l,m.sessionSecret=i,a(`\u2713 Created Session Keystone: ${d}`),e.textContent="\u2713 Session Keystone Created"}catch(t){a(`\u2717 ${b(t)}`),console.error(`${r} ${b(t)}`)}})}h(ca,"initCreateSessionKeystoneButton");function da(){let r=document.getElementById("btn-1b-setup");r&&r.addEventListener("click",()=>{ae({phaseText:"1B",btnId:"btn-1b-setup",nextBtnId:"btn-1b-sync",masterSecret:"test-sender-secret-phase1",syncSalt:"senderidentitysyncsaltphase1",manageSalt:"senderidentitymanagesaltphase1",ib:"test data",data:{hello:"world",random:Math.random()}})})}h(da,"init1bSetupButton");function la(){let r=document.getElementById("btn-1b-sync");r&&r.addEventListener("click",()=>{de({phaseText:"1B",btnId:"btn-1b-sync",nextBtnId:"btn-1b-check",expectSyncFailure:!0,failureMessageSuffix:"establish phase successfully run; connection/sync errors expected in 1B"})})}h(la,"init1bSyncButton");function pa(){let r=`${N}[init1bCheckButton]`,e=document.getElementById("btn-1b-check");e&&e.addEventListener("click",async()=>{try{a("1B Check: Asserting cryptographic and durable state expectations from respec...");let t=await E(),n=await t.getLocalUserSpace({});if(!n)throw new Error("No default space.");let o=m.domainI,s=m.targetX,i=await t.getLatestAddr({addr:u({ibGib:o}),space:n});if(!i){a("\u2717 Check: Evolved domain keystone tip I1 NOT found in local space!");return}a("\u2713 Check: Evolved Domain Keystone (I1) created and stored locally.");let l=(await t.get({addrs:[i],space:n})).ibGibs?.[0];if(!l){a("\u2717 Check: Failed to load I1 from local space.");return}let d=l.data?.proofs?.find(P=>P.claim?.verb==="sync");d?a("\u2713 Check: I1 contains valid sync-verb claim proof."):a("\u2717 Check: I1 is missing sync-verb claim proof!");let p=d?.claim?.target;if(!p){a("\u2717 Check: I1 sync claim does not target a session keystone.");return}a(`\u2713 Check: Sync claim targets session keystone: ${p}`);let y=(await t.get({addrs:[p],space:n})).ibGibs?.[0];if(!y){a("\u2717 Check: Session Keystone (S) NOT found in local space.");return}a("\u2713 Check: Session Keystone (S) successfully created locally.");let S=y.data?.challengePools??[],g=S.some(P=>P.id===ge),w=S.some(P=>P.id===Pe);g&&w?a("\u2713 Check: S contains both connect and sync challenge pools."):a(`\u2717 Check: S is missing challenge pools! (connect: ${g}, sync: ${w})`),a("Check: Verifying registrations on server (receiver metaspace)...");let _=new B,I=!1,A=!1,v=!1,G=u({ibGib:o}),k=await _.getKeystoneGraph(G);if(k.success&&k.graph){let P=k.graph;I=P[G]!==void 0,A=P[i]!==void 0}else a(`\u2717 Check Server: Failed to fetch keystone graph from server: ${k.message}`);let $=await _.getIbGib(G,p);if($.success&&$.ibGib?v=!0:a(`\u2717 Check Server: Failed to fetch session keystone from server: ${$.message}`),I?a("\u2713 Check Server: Genesis Domain Keystone (I) registered on server."):a("\u2717 Check Server: Genesis Domain Keystone (I) missing on server!"),A?a("\u2713 Check Server: Evolved Domain Keystone (I1) accepted and stored on server."):a("\u2717 Check Server: Evolved Domain Keystone (I1) missing on server!"),v?a("\u2713 Check Server: Session Keystone (S) accepted and stored on server."):a("\u2717 Check Server: Session Keystone (S) missing on server!"),I&&A&&v){a("\u{1F389} ALL PHASE 1B ESTABLISH CHECKS PASSED FLAWLESSLY! \u2713"),e.textContent="\u2713 1B All Passed";let P=document.getElementById("btn-2b-setup");P&&(P.disabled=!1)}}catch(t){a(`\u2717 1B Check FAILED: ${b(t)}`),console.error(`${r} 1B Check error:`,t)}})}h(pa,"init1bCheckButton");function ma(){let r=document.getElementById("btn-2b-setup");r&&r.addEventListener("click",()=>{ae({phaseText:"2B",btnId:"btn-2b-setup",nextBtnId:"btn-2b-sync",masterSecret:"test-sender-secret-phase2",syncSalt:"senderidentitysyncsaltphase2",manageSalt:"senderidentitymanagesaltphase2",ib:"test data",data:{hello:"world2",random:Math.random()}})})}h(ma,"init2bSetupButton");function ba(){let r=document.getElementById("btn-2b-sync");r&&r.addEventListener("click",()=>{de({phaseText:"2B",btnId:"btn-2b-sync",nextBtnId:"btn-2b-check",expectSyncFailure:!0,failureMessageSuffix:"connect phase successfully run; subsequent sync errors expected in 2B"})})}h(ba,"init2bSyncButton");function ha(){let r=`${N}[init2bCheckButton]`,e=document.getElementById("btn-2b-check");e&&e.addEventListener("click",async()=>{try{a("2B Check: Asserting cryptographic and WebSocket state expectations...");let t=await E(),n=await t.getLocalUserSpace({});if(!n)throw new Error("No default space.");let o=m.domainI,s=u({ibGib:o}),i=await t.getLatestAddr({addr:s,space:n});if(!i){a("\u2717 Check: Evolved domain keystone tip I1 NOT found in local space!");return}a("\u2713 Check: Evolved Domain Keystone (I1) created and stored locally.");let l=(await t.get({addrs:[i],space:n})).ibGibs?.[0];if(!l){a("\u2717 Check: Failed to load I1 from local space.");return}let p=l.data?.proofs?.find(v=>v.claim?.verb==="sync")?.claim?.target;if(!p){a("\u2717 Check: I1 sync claim does not target a session keystone.");return}a(`\u2713 Check: Sync claim targets session keystone: ${p}`);let f=await t.getLatestAddr({addr:p,space:n});if(!f){a("\u2717 Check: Latest Session Keystone (S) NOT found in local space.");return}a("\u2713 Check: Found latest session keystone (S) locally.");let S=(await t.get({addrs:[f],space:n})).ibGibs?.[0];if(!S){a("\u2717 Check: Failed to load latest Session Keystone (S).");return}let g=S.data?.challengePools??[],w=g.find(v=>v.id===ge),_=g.find(v=>v.id===Pe);if(w&&_)a("\u2713 Check: S contains both connect and sync challenge pools.");else{a(`\u2717 Check: S is missing challenge pools! (connect: ${!!w}, sync: ${!!_})`);return}let I=Object.keys(w.challenges).length;if(I===0)a("\u2713 Check: S connect pool successfully depleted (0 challenges remaining).");else{a(`\u2717 Check: S connect pool not depleted! (${I} challenges remaining)`);return}if(m.senderPeer&&m.senderPeer.isSocketOpen)a("\u2713 Check: WebSocket connection is active and OPEN.");else{a("\u2717 Check: WebSocket connection is NOT open or peer is missing!");return}a("\u{1F389} ALL PHASE 2B CONNECT CHECKS PASSED FLAWLESSLY! \u2713"),e.textContent="\u2713 2B All Passed";let A=document.getElementById("btn-3b-setup");A&&(A.disabled=!1)}catch(t){a(`\u2717 2B Check FAILED: ${b(t)}`),console.error(`${r} 2B Check error:`,t)}})}h(ha,"init2bCheckButton");function fa(){let r=document.getElementById("btn-3b-setup");r&&r.addEventListener("click",()=>{ae({phaseText:"3B",btnId:"btn-3b-setup",nextBtnId:"btn-3b-sync",masterSecret:"test-sender-secret-phase3",syncSalt:"senderidentitysyncsaltphase3",manageSalt:"senderidentitymanagesaltphase3",ib:"test data 3b",data:{hello:"world3",random:Math.random()}})})}h(fa,"init3bSetupButton");function ua(){let r=document.getElementById("btn-3b-sync");r&&r.addEventListener("click",()=>{de({phaseText:"3B",btnId:"btn-3b-sync",nextBtnId:"btn-3b-check"})})}h(ua,"init3bSyncButton");function ga(){let r=`${N}[init3bCheckButton]`,e=document.getElementById("btn-3b-check");e&&e.addEventListener("click",async()=>{try{a("3B Check: Asserting cryptographic and WebSocket state expectations...");let t=await E(),n=await t.getLocalUserSpace({});if(!n)throw new Error("No default space.");let o=m.domainI,s=m.targetX,i=u({ibGib:s}),c=u({ibGib:o}),l=await t.getLatestAddr({addr:i,space:n});if(!l){a("\u2717 Check: Evolved target X NOT found in local space!");return}a(`\u2713 Check: Evolved target X found locally at: ${l}`);let d=await t.getDependencyGraph({ibGibAddr:l,space:n});if(!d||Object.keys(d).length===0){a("\u2717 Check: Failed to load target X dependency graph locally.");return}a(`\u2713 Check: Target X local graph loaded (${Object.keys(d).length} nodes).`);let p=new B,f=await p.getIbGibGraph(c,i,!0);if(!f.success||!f.graph){a(`\u2717 Check: Failed to fetch target X graph from server: ${f.message}`);return}let y=f.graph;if(a(`\u2713 Check: Target X server graph loaded (${Object.keys(y).length} nodes).`),W({graphA:d,graphB:y}))a("\u2713 Check: Target X dependency graphs are equivalent on client and server.");else{a("\u2717 Check: Target X dependency graphs mismatch between client and server!");return}let g=await t.getLatestAddr({addr:c,space:n});if(!g){a("\u2717 Check: Evolved domain keystone tip I1 NOT found in local space!");return}a("\u2713 Check: Evolved Domain Keystone (I1) exists locally.");let _=(await t.get({addrs:[g],space:n})).ibGibs?.[0];if(!_){a("\u2717 Check: Failed to load I1 from local space.");return}let A=_.data?.proofs?.find(H=>H.claim?.verb==="sync")?.claim?.target;if(!A){a("\u2717 Check: I1 sync claim does not target a session keystone.");return}let v=await p.getIbGib(c,g);if(!v.success||!v.ibGib){a("\u2717 Check: Evolved Domain Keystone (I1) NOT found on server!");return}a("\u2713 Check: Evolved Domain Keystone (I1) exists on server.");let G=await t.getLatestAddr({addr:A,space:n});if(!G){a("\u2717 Check: Latest Session Keystone (S) NOT found in local space.");return}a(`\u2713 Check: Found latest session keystone (S) locally: ${G}`);let $=(await t.get({addrs:[G],space:n})).ibGibs?.[0];if(!$){a("\u2717 Check: Failed to load latest Session Keystone (S) locally.");return}let P=$.data?.n;a(`\u2713 Check: S tip evolved to n = ${P}.`),P!==3&&P!==4&&a(`\u26A0 Check: Expected S to evolve to n = 3 or 4, got n = ${P}. Continuing anyway...`);let O=await p.getIbGib(c,G);if(!O.success||!O.ibGib){a("\u2717 Check: Latest Session Keystone (S) NOT found on server!");return}a("\u2713 Check: Latest Session Keystone (S) exists on server.");let K=await t.getDependencyGraph({ibGibAddr:G,space:n}),F=await p.getIbGibGraph(c,A,!0);if(!F.success||!F.graph){a(`\u2717 Check: Failed to fetch session S graph from server: ${F.message}`);return}let U=F.graph;if(W({graphA:K,graphB:U}))a("\u2713 Check: Session Keystone (S) dependency graphs are equivalent on client and server.");else{a("\u2717 Check: Session Keystone (S) dependency graphs mismatch between client and server!");return}a("\u{1F389} ALL PHASE 3B TRANSACTION SYNC CHECKS PASSED FLAWLESSLY! \u2713"),e.textContent="\u2713 3B All Passed"}catch(t){a(`\u2717 3B Check FAILED: ${b(t)}`),console.error(`${r} 3B Check error:`,t)}})}h(ga,"init3bCheckButton");function ya(){let r=document.getElementById("btn-4-1b-setup");r&&r.addEventListener("click",()=>{ae({phaseText:"4.1B",btnId:"btn-4-1b-setup",nextBtnId:"btn-4-1b-sync",masterSecret:"test-sender-secret-phase4-1",syncSalt:"senderidentitysyncsaltphase4-1",manageSalt:"senderidentitymanagesaltphase4-1",ib:"test data 4.1b",data:{hello:"world4_1",random:Math.random()}})})}h(ya,"init4_1bSetupButton");function Sa(){let r=document.getElementById("btn-4-1b-sync");r&&r.addEventListener("click",()=>{de({phaseText:"4.1B",btnId:"btn-4-1b-sync",nextBtnId:"btn-4-1b-check"})})}h(Sa,"init4_1bSyncButton");function wa(){let r=`${N}[init4_1bCheckButton]`,e=document.getElementById("btn-4-1b-check");e&&e.addEventListener("click",async()=>{try{a("4.1B Check: Asserting cryptographic and WebSocket state expectations...");let t=await E(),n=await t.getLocalUserSpace({});if(!n)throw new Error("No default space.");let o=m.domainI,s=m.targetX,i=u({ibGib:s}),c=u({ibGib:o}),l=await t.getLatestAddr({addr:i,space:n});if(!l){a("\u2717 Check: Evolved target X NOT found in local space!");return}a(`\u2713 Check: Evolved target X found locally at: ${l}`);let d=await t.getDependencyGraph({ibGibAddr:l,space:n});if(!d||Object.keys(d).length===0){a("\u2717 Check: Failed to load target X dependency graph locally.");return}a(`\u2713 Check: Target X local graph loaded (${Object.keys(d).length} nodes).`);let p=new B,f=await p.getIbGibGraph(c,i,!0);if(!f.success||!f.graph){a(`\u2717 Check: Failed to fetch target X graph from server: ${f.message}`);return}let y=f.graph;if(a(`\u2713 Check: Target X server graph loaded (${Object.keys(y).length} nodes).`),W({graphA:d,graphB:y}))a("\u2713 Check: Target X dependency graphs are equivalent on client and server.");else{a("\u2717 Check: Target X dependency graphs mismatch between client and server!");return}let g=await t.getLatestAddr({addr:c,space:n});if(!g){a("\u2717 Check: Evolved domain keystone tip I1 NOT found in local space!");return}a("\u2713 Check: Evolved Domain Keystone (I1) exists locally.");let _=(await t.get({addrs:[g],space:n})).ibGibs?.[0];if(!_){a("\u2717 Check: Failed to load I1 from local space.");return}let{latestLocalDelegateAddr:I,sessionIdentityTjpAddr:A}=await rt({localI:_,metaspace:t,space:n});if(!I){a("\u2717 Check: Evolved delegate keystone tip NOT found in local space!");return}if(!A){a("\u2717 Check: Delegate sync claim does not target a session keystone.");return}a("\u2713 Check: Delegate Keystone and Sync Claim to Session verified locally.");let v=await p.getIbGib(c,I);if(!v.success||!v.ibGib){a("\u2717 Check: Evolved Delegate Keystone NOT found on server!");return}a("\u2713 Check: Evolved Delegate Keystone exists on server.");let G=await p.getIbGib(c,g);if(!G.success||!G.ibGib){a("\u2717 Check: Evolved Domain Keystone (I1) NOT found on server!");return}a("\u2713 Check: Evolved Domain Keystone (I1) exists on server.");let k=await t.getLatestAddr({addr:A,space:n});if(!k){a("\u2717 Check: Latest Session Keystone (S) NOT found in local space.");return}a(`\u2713 Check: Found latest session keystone (S) locally: ${k}`);let P=(await t.get({addrs:[k],space:n})).ibGibs?.[0];if(!P){a("\u2717 Check: Failed to load latest Session Keystone (S) locally.");return}let O=P.data?.n;a(`\u2713 Check: S tip evolved to n = ${O}.`),O!==3&&O!==4&&a(`\u26A0 Check: Expected S to evolve to n = 3 or 4, got n = ${O}. Continuing anyway...`);let K=await p.getIbGib(c,k);if(!K.success||!K.ibGib){a("\u2717 Check: Latest Session Keystone (S) NOT found on server!");return}a("\u2713 Check: Latest Session Keystone (S) exists on server.");let F=await t.getDependencyGraph({ibGibAddr:k,space:n}),U=await p.getIbGibGraph(c,A,!0);if(!U.success||!U.graph){a(`\u2717 Check: Failed to fetch session S graph from server: ${U.message}`);return}let j=U.graph;if(W({graphA:F,graphB:j}))a("\u2713 Check: Session Keystone (S) dependency graphs are equivalent on client and server.");else{a("\u2717 Check: Session Keystone (S) dependency graphs mismatch between client and server!");return}a("\u{1F389} ALL PHASE 4.1B TRANSACTION SYNC CHECKS PASSED FLAWLESSLY! \u2713"),e.textContent="\u2713 4.1B All Passed"}catch(t){a(`\u2717 4.1B Check FAILED: ${b(t)}`),console.error(`${r} 4.1B Check error:`,t)}})}h(wa,"init4_1bCheckButton");function _a(){let r=document.getElementById("btn-4-2b-setup");r&&r.addEventListener("click",()=>{ae({phaseText:"4.2B",btnId:"btn-4-2b-setup",nextBtnId:"btn-4-2b-sync",masterSecret:"test-sender-secret-phase4-2",syncSalt:"senderidentitysyncsaltphase4-2",manageSalt:"senderidentitymanagesaltphase4-2",ib:"dummy target 4.2b",data:{hello:"dummy"}})})}h(_a,"init4_2bSetupButton");async function Dn(){let r=`${N}[performPhaseSync4_2b]`,e=document.getElementById("btn-4-2b-sync");if(e)try{if(e.disabled=!0,a("4.2B Sync: Creating Constants and executing three-pass WebSocket Sync..."),!m.domainI){a("\u26A0 4.2B Sync: Missing setup state. Please run Setup first."),e.disabled=!1;return}let t=await E(),n=await t.getLocalUserSpace({});if(!n)throw new Error("No default space.");let o=await D.constant({parentPrimitiveIb:"root",ib:"constant_c1_"+(await z()).slice(0,8),data:{some:"data_4_2b",random:Math.random()}}),s=u({ibGib:o});await t.put({ibGib:o,space:n}),await t.registerNewIbGib({ibGib:o}),m.targetC1=o,a(`4.2B Sync: \u2713 Constant C1 created: ${s}`),a("4.2B Sync: Starting Pass 1 (Sync C1)..."),await x({domainIbGibs:[o],passLabel:"Pass 1 (Sync C1)",metaspace:t,space:n}),a("4.2B Sync: \u2713 Pass 1 Complete."),a("4.2B Sync: Starting Pass 2 (Sync C1 - Idempotent)..."),await x({domainIbGibs:[o],passLabel:"Pass 2 (Sync C1 idempotent)",metaspace:t,space:n}),a("4.2B Sync: \u2713 Pass 2 Complete.");let i=await D.constant({ib:"constant_c2_"+(await z()).slice(0,8),parentPrimitiveIb:"root",rel8ns:{link:[s]}}),c=u({ibGib:i});await t.put({ibGib:i,space:n}),await t.registerNewIbGib({ibGib:i}),m.targetC2=i,a(`4.2B Sync: \u2713 Constant C2 created linking to C1: ${c}`),a("4.2B Sync: Starting Pass 3 (Sync C2)..."),await x({domainIbGibs:[i],passLabel:"Pass 3 (Sync C2)",metaspace:t,space:n}),a("4.2B Sync: \u2713 Pass 3 Complete."),a("\u2713 4.2B Sync Sequence Complete! Ready for State Checks."),e.textContent="\u2713 4.2B Sync Run";let l=document.getElementById("btn-4-2b-check");l&&(l.disabled=!1)}catch(t){a(`\u2717 4.2B Sync FAILED: ${b(t)}`),console.error(`${r} 4.2B Sync error:`,t),e.disabled=!1}}h(Dn,"performPhaseSync4_2b");function Ea(){let r=document.getElementById("btn-4-2b-sync");r&&r.addEventListener("click",()=>{Dn()})}h(Ea,"init4_2bSyncButton");function Ia(){let r=`${N}[init4_2bCheckButton]`,e=document.getElementById("btn-4-2b-check");e&&e.addEventListener("click",async()=>{try{a("4.2B Check: Asserting cryptographic and WebSocket state expectations...");let t=await E(),n=await t.getLocalUserSpace({});if(!n)throw new Error("No default space.");let o=m.domainI,s=m.targetC1,i=m.targetC2,c=u({ibGib:s}),l=u({ibGib:i}),d=u({ibGib:o}),p=new B,f=await t.get({addrs:[c],space:n}),y=await t.get({addrs:[l],space:n});if(!f.success||!f.ibGibs?.[0]){a("\u2717 Check: Constant C1 NOT found locally.");return}if(!y.success||!y.ibGibs?.[0]){a("\u2717 Check: Constant C2 NOT found locally.");return}a("\u2713 Check: Constants C1 and C2 exist locally.");let S=await p.getIbGib(d,c),g=await p.getIbGib(d,l);if(!S.success||!S.ibGib){a(`\u2717 Check: Constant C1 NOT found on server: ${S.message}`);return}if(!g.success||!g.ibGib){a(`\u2717 Check: Constant C2 NOT found on server: ${g.message}`);return}a("\u2713 Check: Constants C1 and C2 exist on server.");let w=await t.getDependencyGraph({ibGibAddr:l,space:n}),_=await p.getIbGibGraph(d,l,!0);if(!_.success||!_.graph){a(`\u2717 Check: Failed to fetch C2 graph from server: ${_.message}`);return}if(!W({graphA:w,graphB:_.graph})){a("\u2717 Check: C2 dependency graphs mismatch between client and server!");return}a("\u2713 Check: C2 dependency graphs are equivalent on client and server.");let I=await t.getLatestAddr({addr:d,space:n});if(!I){a("\u2717 Check: Domain keystone tip not found locally!");return}let v=(await t.get({addrs:[I],space:n})).ibGibs?.[0];if(!v){a("\u2717 Check: Failed to load domain keystone!");return}let G=v.data?.n;if(a(`\u2713 Check: Evolved I tip is at n = ${G}.`),G!==1){a(`\u2717 Check: Expected I to evolve to n = 1 (delegate registration only), got n = ${G}.`);return}let{sessionIdentityTjpAddr:k}=await Ee({localI:v,metaspace:t,space:n,apiBridge:p,domainAddr:d}),$=await t.getLatestAddr({addr:k,space:n});if(!$){a("\u2717 Check: Latest Session Keystone (S) NOT found in local space.");return}a(`\u2713 Check: Found latest session keystone (S) locally: ${$}`);let O=(await t.get({addrs:[$],space:n})).ibGibs?.[0];if(!O){a("\u2717 Check: Failed to load Session Keystone (S) locally.");return}let K=O.data?.n;if(a(`\u2713 Check: Latest session S tip evolved to n = ${K}.`),K!==3){a(`\u2717 Check: Expected latest session S to evolve to n = 3 (connect+sync+disconnect), got n = ${K}.`);return}let F=await p.getIbGib(d,$);if(!F.success||!F.ibGib){a("\u2717 Check: Latest Session Keystone (S) NOT found on server!");return}a("\u2713 Check: Latest Session Keystone (S) exists on server.");let U=await t.getDependencyGraph({ibGibAddr:$,space:n}),j=await p.getIbGibGraph(d,k,!0);if(!j.success||!j.graph){a(`\u2717 Check: Failed to fetch session S graph from server: ${j.message}`);return}if(!W({graphA:U,graphB:j.graph})){a("\u2717 Check: Session Keystone (S) dependency graphs mismatch between client and server!");return}a("\u2713 Check: Session Keystone (S) dependency graphs are equivalent on client and server."),a("\u{1F389} ALL PHASE 4.2B TRANSACTION SYNC CHECKS PASSED FLAWLESSLY! \u2713"),e.textContent="\u2713 4.2B All Passed"}catch(t){a(`\u2717 4.2B Check FAILED: ${b(t)}`),console.error(`${r} 4.2B Check error:`,t)}})}h(Ia,"init4_2bCheckButton");function va(){let r=document.getElementById("btn-4-3b-setup");r&&r.addEventListener("click",async()=>{try{r.disabled=!0,a("4.3B Setup: Generating Domain Keystone (I) and Target timeline V0 -> V1...");let e=await E(),t=await e.getLocalUserSpace({});if(!t)throw new Error("No default space.");let n=new B;await q({masterSecret:"test-sender-secret-phase4-3",syncSalt:"senderidentitysyncsaltphase4-3",manageSalt:"senderidentitymanagesaltphase4-3",metaspace:e,space:t,apiBridge:n,phaseText:"4.3B"});let o=await D.firstGen({parentIbGib:M,ib:"timeline_root_partial_4_3b",data:{type:"root",label:"Root4_3b",random:Math.random()},dna:!0,nCounter:!0,tjp:{uuid:!0,timestamp:!0}}),s=o.newIbGib;await e.persistTransformResult({resTransform:o,space:t}),await e.registerNewIbGib({ibGib:s});let i=await T({timeline:s,mut8Opts:{dataToAddOrPatch:{type:"comment",label:"V1_4_3b"}},metaspace:e,space:t});m.targetC1=i,m.targetX=i,a(`4.3B Setup: \u2713 Timeline V0 -> V1 created and stored locally. V1: ${u({ibGib:i})}`),a("\u2713 4.3B Setup Complete! Ready for 4.3B Sync."),r.textContent="\u2713 4.3B Setup Complete";let c=document.getElementById("btn-4-3b-sync");c&&(c.disabled=!1)}catch(e){a(`\u2717 4.3B Setup FAILED: ${b(e)}`),console.error(e),r.disabled=!1}})}h(va,"init4_3bSetupButton");async function Vn(){let r=`${N}[performPhaseSync4_3b]`,e=document.getElementById("btn-4-3b-sync");if(e)try{e.disabled=!0;let t=m.targetX;if(!m.domainI||!t){a("\u26A0 4.3B Sync: Missing setup state. Please run Setup first."),e.disabled=!1;return}let n=await E(),o=await n.getLocalUserSpace({});if(!o)throw new Error("No default space.");a("4.3B Sync: Starting Pass 1 (Sync V1 to server)..."),await x({domainIbGibs:[t],passLabel:"Pass 1 (Sync V1)",metaspace:n,space:o}),a("4.3B Sync: \u2713 Pass 1 Complete (V1 synced)."),a("4.3B Sync: Mutating V1 to V2 locally...");let s=await T({timeline:t,mut8Opts:{dataToAddOrPatch:{type:"comment",label:"V2_4_3b"}},metaspace:n,space:o});m.targetX=s,a(`4.3B Sync: \u2713 V2 created locally: ${u({ibGib:s})}`),a("4.3B Sync: Starting Pass 2 (Sync V2 delta to server)..."),await x({domainIbGibs:[s],passLabel:"Pass 2 (Sync V2)",metaspace:n,space:o}),a("4.3B Sync: \u2713 Pass 2 Complete (V2 synced)."),a("\u2713 4.3B Sync Sequence Complete! Ready for State Checks."),e.textContent="\u2713 4.3B Sync Run";let i=document.getElementById("btn-4-3b-check");i&&(i.disabled=!1)}catch(t){a(`\u2717 4.3B Sync FAILED: ${b(t)}`),console.error(t),e.disabled=!1}}h(Vn,"performPhaseSync4_3b");function Ga(){let r=document.getElementById("btn-4-3b-sync");r&&r.addEventListener("click",()=>{Vn()})}h(Ga,"init4_3bSyncButton");function Ca(){let r=`${N}[init4_3bCheckButton]`,e=document.getElementById("btn-4-3b-check");e&&e.addEventListener("click",async()=>{try{a("4.3B Check: Asserting cryptographic and WebSocket state expectations...");let t=await E(),n=await t.getLocalUserSpace({});if(!n)throw new Error("No default space.");let o=m.domainI,s=m.targetC1,i=m.targetX,c=u({ibGib:s}),l=u({ibGib:i}),d=u({ibGib:o}),p=new B,f=await t.get({addrs:[c],space:n}),y=await t.get({addrs:[l],space:n});if(!f.success||!f.ibGibs?.[0]){a("\u2717 Check: Timeline frame V1 NOT found locally.");return}if(!y.success||!y.ibGibs?.[0]){a("\u2717 Check: Timeline frame V2 NOT found locally.");return}a("\u2713 Check: Timeline frames V1 and V2 exist locally.");let S=await p.getIbGib(d,l);if(!S.success||!S.ibGib){a(`\u2717 Check: Timeline frame V2 NOT found on server: ${S.message}`);return}a("\u2713 Check: Timeline frame V2 exists on server.");let g=S.ibGib.rel8ns?.past?.at(-1);if(g===c)a("\u2713 Check: Server V2 correctly references V1 in its past relation.");else{a(`\u2717 Check: Server V2 does not reference V1 in past relation! got: ${g}`);return}let w=await t.getDependencyGraph({ibGibAddr:l,space:n}),_=await p.getIbGibGraph(d,l,!0);if(!_.success||!_.graph){a(`\u2717 Check: Failed to fetch V2 graph from server: ${_.message}`);return}if(!W({graphA:w,graphB:_.graph})){a("\u2717 Check: V2 timeline dependency graphs mismatch between client and server!");return}a("\u2713 Check: V2 timeline dependency graphs are equivalent on client and server.");let I=await t.getLatestAddr({addr:d,space:n});if(!I){a("\u2717 Check: Domain keystone tip not found locally!");return}let v=(await t.get({addrs:[I],space:n})).ibGibs?.[0];if(!v){a("\u2717 Check: Failed to load domain keystone!");return}let G=v.data?.n;if(a(`\u2713 Check: Evolved I tip is at n = ${G}.`),G!==1){a(`\u2717 Check: Expected I to evolve to n = 1 (delegate registration only), got n = ${G}.`);return}let{sessionIdentityTjpAddr:k}=await Ee({localI:v,metaspace:t,space:n,apiBridge:p,domainAddr:d}),$=await t.getLatestAddr({addr:k,space:n});if(!$){a("\u2717 Check: Latest Session Keystone (S) NOT found in local space.");return}a(`\u2713 Check: Found latest session keystone (S) locally: ${$}`);let O=(await t.get({addrs:[$],space:n})).ibGibs?.[0];if(!O){a("\u2717 Check: Failed to load Session Keystone (S) locally.");return}let K=O.data?.n;if(a(`\u2713 Check: Latest session S tip evolved to n = ${K}.`),K!==3){a(`\u2717 Check: Expected latest session S to evolve to n = 3, got n = ${K}.`);return}let F=await p.getIbGib(d,$);if(!F.success||!F.ibGib){a("\u2717 Check: Latest Session Keystone (S) NOT found on server!");return}a("\u2713 Check: Latest Session Keystone (S) exists on server.");let U=await t.getDependencyGraph({ibGibAddr:$,space:n}),j=await p.getIbGibGraph(d,k,!0);if(!j.success||!j.graph){a(`\u2717 Check: Failed to fetch session S graph from server: ${j.message}`);return}if(!W({graphA:U,graphB:j.graph})){a("\u2717 Check: Session Keystone (S) dependency graphs mismatch between client and server!");return}a("\u2713 Check: Session Keystone (S) dependency graphs are equivalent on client and server."),a("\u{1F389} ALL PHASE 4.3B TRANSACTION SYNC CHECKS PASSED FLAWLESSLY! \u2713"),e.textContent="\u2713 4.3B All Passed"}catch(t){a(`\u2717 4.3B Check FAILED: ${b(t)}`),console.error(`${r} 4.3B Check error:`,t)}})}h(Ca,"init4_3bCheckButton");function Ba(){let r=document.getElementById("btn-4-4b-setup");r&&r.addEventListener("click",async()=>{try{r.disabled=!0,a("4.4B Setup: Generating Domain Keystone (I) and Target timeline V0 -> V1 -> V2...");let e=await E(),t=await e.getLocalUserSpace({});if(!t)throw new Error("No default space.");let n=new B;await q({masterSecret:"test-sender-secret-phase4-4",syncSalt:"senderidentitysyncsaltphase4-4",manageSalt:"senderidentitymanagesaltphase4-4",metaspace:e,space:t,apiBridge:n,phaseText:"4.4B"});let o=await D.firstGen({parentIbGib:M,ib:"timeline_root_deep_4_4b",data:{type:"root",label:"Root4_4b",random:Math.random()},dna:!0,nCounter:!0,tjp:{uuid:!0,timestamp:!0}}),s=o.newIbGib;await e.persistTransformResult({resTransform:o,space:t}),await e.registerNewIbGib({ibGib:s}),m.targetC1=s;let i=await T({timeline:s,mut8Opts:{dataToAddOrPatch:{type:"comment",label:"V1_4_4b"}},metaspace:e,space:t});m.targetC2=i;let c=await T({timeline:i,mut8Opts:{dataToAddOrPatch:{type:"comment",label:"V2_4_4b"}},metaspace:e,space:t});m.targetX=c,a(`4.4B Setup: \u2713 Timeline V0 -> V1 -> V2 created locally. V2 Tip: ${u({ibGib:c})}`),a("\u2713 4.4B Setup Complete! Ready for 4.4B Sync."),r.textContent="\u2713 4.4B Setup Complete";let l=document.getElementById("btn-4-4b-sync");l&&(l.disabled=!1)}catch(e){a(`\u2717 4.4B Setup FAILED: ${b(e)}`),console.error(e),r.disabled=!1}})}h(Ba,"init4_4bSetupButton");async function Mn(){let r=`${N}[performPhaseSync4_4b]`,e=document.getElementById("btn-4-4b-sync");if(e)try{e.disabled=!0,a("4.4B Sync: Initiating WebSocket Sync of V2 Tip...");let t=m.targetX;if(!m.domainI||!t){a("\u26A0 4.4B Sync: Missing setup state. Please run Setup first."),e.disabled=!1;return}let n=await E(),o=await n.getLocalUserSpace({});if(!o)throw new Error("No default space.");await x({domainIbGibs:[t],passLabel:"Pass 1 (Sync V2 tip)",metaspace:n,space:o}),a("4.4B Sync: \u2713 WebSocket Sync completed."),a("\u2713 4.4B Sync Sequence Complete! Ready for State Checks."),e.textContent="\u2713 4.4B Sync Run";let s=document.getElementById("btn-4-4b-check");s&&(s.disabled=!1)}catch(t){a(`\u2717 4.4B Sync FAILED: ${b(t)}`),console.error(t),e.disabled=!1}}h(Mn,"performPhaseSync4_4b");function Aa(){let r=document.getElementById("btn-4-4b-sync");r&&r.addEventListener("click",()=>{Mn()})}h(Aa,"init4_4bSyncButton");function ka(){let r=`${N}[init4_4bCheckButton]`,e=document.getElementById("btn-4-4b-check");e&&e.addEventListener("click",async()=>{try{a("4.4B Check: Asserting cryptographic and WebSocket state expectations...");let t=await E(),n=await t.getLocalUserSpace({});if(!n)throw new Error("No default space.");let o=m.domainI,s=m.targetC1,i=m.targetC2,c=m.targetX,l=u({ibGib:s}),d=u({ibGib:i}),p=u({ibGib:c}),f=u({ibGib:o}),y=new B,S=await t.get({addrs:[l],space:n}),g=await t.get({addrs:[d],space:n}),w=await t.get({addrs:[p],space:n});if(!S.success||!S.ibGibs?.[0]){a("\u2717 Check: Timeline frame V0 NOT found locally.");return}if(!g.success||!g.ibGibs?.[0]){a("\u2717 Check: Timeline frame V1 NOT found locally.");return}if(!w.success||!w.ibGibs?.[0]){a("\u2717 Check: Timeline frame V2 NOT found locally.");return}a("\u2713 Check: Timeline frames V0, V1, and V2 exist locally.");let _=await y.getIbGib(f,p);if(!_.success||!_.ibGib){a(`\u2717 Check: Timeline frame V2 NOT found on server: ${_.message}`);return}a("\u2713 Check: Timeline frame V2 exists on server.");let I=_.ibGib.rel8ns?.past?.at(-1);if(I===d)a("\u2713 Check: Server V2 correctly references V1 in its past relation.");else{a(`\u2717 Check: Server V2 does not reference V1 in past relation! got: ${I}`);return}let A=await y.getIbGib(f,d);if(!A.success||!A.ibGib){a(`\u2717 Check: Timeline frame V1 NOT found on server: ${A.message}`);return}a("\u2713 Check: Timeline frame V1 exists on server.");let v=A.ibGib.rel8ns?.past?.at(-1);if(v===l)a("\u2713 Check: Server V1 correctly references V0 in its past relation.");else{a(`\u2717 Check: Server V1 does not reference V0 in past relation! got: ${v}`);return}let G=await t.getDependencyGraph({ibGibAddr:p,space:n}),k=await y.getIbGibGraph(f,p,!0);if(!k.success||!k.graph){a(`\u2717 Check: Failed to fetch V2 graph from server: ${k.message}`);return}if(!W({graphA:G,graphB:k.graph})){a("\u2717 Check: V2 timeline dependency graphs mismatch between client and server!");return}a("\u2713 Check: V2 timeline dependency graphs are equivalent on client and server.");let $=await t.getLatestAddr({addr:f,space:n});if(!$){a("\u2717 Check: Domain keystone tip not found locally!");return}let O=(await t.get({addrs:[$],space:n})).ibGibs?.[0];if(!O){a("\u2717 Check: Failed to load domain keystone!");return}a(`\u2713 Check: Evolved Domain Keystone exists locally: ${$}`);let K=O.data?.n;if(a(`\u2713 Check: Evolved I tip is at n = ${K}.`),K!==1){a(`\u2717 Check: Expected I to evolve to n = 1, got n = ${K}.`);return}let{sessionIdentityTjpAddr:F}=await Ee({localI:O,metaspace:t,space:n,apiBridge:y,domainAddr:f}),U=await t.getLatestAddr({addr:F,space:n});if(!U){a("\u2717 Check: Latest Session Keystone (S) NOT found in local space.");return}a(`\u2713 Check: Found latest session keystone (S) locally: ${U}`);let H=(await t.get({addrs:[U],space:n})).ibGibs?.[0];if(!H){a("\u2717 Check: Failed to load Session Keystone (S) locally.");return}let Q=H.data?.n;if(a(`\u2713 Check: Latest session S tip evolved to n = ${Q}.`),Q!==3){a(`\u2717 Check: Expected latest session S to evolve to n = 3, got n = ${Q}.`);return}let be=await y.getIbGib(f,U);if(!be.success||!be.ibGib){a("\u2717 Check: Latest Session Keystone (S) NOT found on server!");return}a("\u2713 Check: Latest Session Keystone (S) exists on server.");let We=await t.getDependencyGraph({ibGibAddr:U,space:n}),he=await y.getIbGibGraph(f,F,!0);if(!he.success||!he.graph){a(`\u2717 Check: Failed to fetch session S graph from server: ${he.message}`);return}if(!W({graphA:We,graphB:he.graph})){a("\u2717 Check: Session Keystone (S) dependency graphs mismatch between client and server!");return}a("\u2713 Check: Session Keystone (S) dependency graphs are equivalent on client and server."),a("\u{1F389} ALL PHASE 4.4B TRANSACTION SYNC CHECKS PASSED FLAWLESSLY! \u2713"),e.textContent="\u2713 4.4B All Passed"}catch(t){a(`\u2717 4.4B Check FAILED: ${b(t)}`),console.error(`${r} 4.4B Check error:`,t)}})}h(ka,"init4_4bCheckButton");var $a={},Ta="test-sender-secret-phase4-5b";function La(){let r=document.getElementById("btn-4-5b-setup");r&&r.addEventListener("click",async()=>{try{r.disabled=!0,a("4.5B Setup: Generating Domain Keystone (I), target timeline, and seeding server from two spaces...");let e=await E(),t=await e.getLocalUserSpace({});if(!t)throw new Error("No default space.");let n=new B;await q({masterSecret:Ta,syncSalt:"senderidentitysyncsaltphase4-5b",manageSalt:"senderidentitymanagesaltphase4-5b",metaspace:e,space:t,apiBridge:n,phaseText:"4.5B"});let o=await D.firstGen({parentIbGib:M,ib:"timeline_root_partial_4_5b",data:{type:"root",label:"Root4_5b",random:Math.random()},dna:!0,nCounter:!0,tjp:{uuid:!0,timestamp:!0}}),s=o.newIbGib;await e.persistTransformResult({resTransform:o,space:t}),await e.registerNewIbGib({ibGib:s,space:t});let i=await T({timeline:s,mut8Opts:{dataToAddOrPatch:{type:"comment",label:"V1_4_5b"}},metaspace:e,space:t});m.targetC1=i,a(`4.5B Setup: \u2713 Local timeline V0 -> V1 created. V1 Tip: ${u({ibGib:i})}`),a("4.5B Setup: Seeding V1 to the server via WebSocket..."),await x({domainIbGibs:[i],passLabel:"Seed V1 to server",metaspace:e,space:t}),a("4.5B Setup: \u2713 Pass 1 Sync (V1 to server) complete."),a('4.5B Setup: Creating secondary local space simulating "remote" client...');let c=`remote-${await z()}`,l=await e.createNewLocalSpace({opts:{allowCancel:!1,spaceName:c,getFnPrompt:e.getFnPrompt}});if(!l)throw new Error("Failed to create remote space");await l.initialized;let d=await e.getDependencyGraph({ibGibAddr:u({ibGib:i}),space:t});await e.put({ibGibs:Object.values(d),space:l}),await e.registerNewIbGib({ibGib:i,space:l});let p=m.domainI;await X({domainI:p,metaspace:e,fromSpace:t,toSpace:l}),a("4.5B Setup: \u2713 Copied V1 and identities (domain and delegate) to remoteSpace."),a("4.5B Setup: Mutating V1 -> V2 in remoteSpace...");let f=await T({timeline:i,mut8Opts:{dataToAddOrPatch:{type:"comment",label:"V2_4_5b"}},metaspace:e,space:l});$a.targetV2=f,a(`4.5B Setup: \u2713 Mutated to V2 in remoteSpace: ${u({ibGib:f})}`),a("4.5B Setup: Syncing V2 from remoteSpace to the server..."),await J({domainIbGibs:[f],passLabel:"Seed V2 from remoteSpace",metaspace:e,space:l,primarySpace:t,domainI:p,masterSecret:Ta}),a("4.5B Setup: \u2713 Pass 2 Sync (V2 to server) complete. debugState.domainI updated."),a("\u2713 4.5B Setup Complete! Server has V2, default local space has V1. Ready for 4.5B Sync."),r.textContent="\u2713 4.5B Setup Complete";let y=document.getElementById("btn-4-5b-sync");y&&(y.disabled=!1)}catch(e){a(`\u2717 4.5B Setup FAILED: ${b(e)}`),console.error(e),r.disabled=!1}})}h(La,"init4_5bSetupButton");function Ra(){let r=document.getElementById("btn-4-5b-sync");r&&r.addEventListener("click",async()=>{try{r.disabled=!0,a("4.5B Sync: Initiating WebSocket Sync from default local space (which has V1, server has V2)...");let e=m.targetC1;if(!m.domainI||!e){a("\u26A0 4.5B Sync: Missing setup state. Please run Setup first."),r.disabled=!1;return}let t=await E(),n=await t.getLocalUserSpace({});if(!n)throw new Error("No default space.");await x({domainIbGibs:[e],passLabel:"Pull V2 from server",metaspace:t,space:n}),a("\u2713 4.5B Sync Execution Complete! Ready for 4.5B Check."),r.textContent="\u2713 4.5B Sync Run";let o=document.getElementById("btn-4-5b-check");o&&(o.disabled=!1)}catch(e){a(`\u2717 4.5B Sync FAILED: ${b(e)}`),console.error(e),r.disabled=!1}})}h(Ra,"init4_5bSyncButton");function Na(){let r=document.getElementById("btn-4-5b-check");r&&r.addEventListener("click",async()=>{try{r.disabled=!0,a("4.5B Check: Verifying that V2 was pulled down to default local space...");let e=$a.targetV2;if(!e||!m.domainI){a("\u26A0 4.5B Check: Missing target V2 in state. Did Setup run?"),r.disabled=!1;return}let t=u({ibGib:e}),n=u({ibGib:m.domainI}),o=await E(),s=await o.getLocalUserSpace({});if(!s)throw new Error("No default space.");let i=await o.get({addr:t,space:s});if(!i.success||i.ibGibs?.length!==1)throw new Error(`V2 tip (${t}) is NOT present in local space!`);let c=i.ibGibs[0];a(`4.5B Check: \u2713 V2 Tip found locally. Label: "${c.data?.label}"`);let l=await o.getDependencyGraph({ibGibAddr:t,space:s});a("4.5B Check: Fetching V2 dependency graph from server...");let p=await new B().getIbGibGraph(n,t,!0);if(!p.success||!p.graph)throw new Error(`Failed to fetch V2 graph from server: ${p.message}`);if(W({graphA:l,graphB:p.graph}))a("\u2713 4.5B Check SUCCESS: V2 and all dependencies are fully equivalent on client and server!"),r.textContent="\u2713 4.5B Check Success";else throw new Error("Dependency graphs on local space and server are NOT equivalent.")}catch(e){a(`\u2717 4.5B Check FAILED: ${b(e)}`),console.error(e),r.disabled=!1}})}h(Na,"init4_5bCheckButton");var Ie={},Fn="test-sender-secret-phase4-6b";function Pa(){let r=document.getElementById("btn-4-6b-setup");r&&r.addEventListener("click",async()=>{try{r.disabled=!0,a("4.6B Setup: Generating Domain Keystone (I) and two independent target timelines (Alpha and Beta)...");let e=await E(),t=await e.getLocalUserSpace({});if(!t)throw new Error("No default space.");let n=new B;await q({masterSecret:Fn,syncSalt:"senderidentitysyncsaltphase4-6b",manageSalt:"senderidentitymanagesaltphase4-6b",metaspace:e,space:t,apiBridge:n,phaseText:"4.6B"});let o=await D.firstGen({parentIbGib:M,ib:"timeline_root_alpha_4_6b",data:{type:"root",label:"Alpha4_6b",random:Math.random()},dna:!0,nCounter:!0,tjp:{uuid:!0,timestamp:!0}}),s=o.newIbGib;await e.persistTransformResult({resTransform:o,space:t}),await e.registerNewIbGib({ibGib:s,space:t});let i=await T({timeline:s,mut8Opts:{dataToAddOrPatch:{type:"comment",label:"A1_4_6b"}},metaspace:e,space:t});Ie.targetAlphaV1=i,m.targetC1=i,a(`4.6B Setup: \u2713 Local Timeline A created. A1 Tip: ${u({ibGib:i})}`);let c=await D.firstGen({parentIbGib:M,ib:"timeline_root_beta_4_6b",data:{type:"root",label:"Beta4_6b",random:Math.random()},dna:!0,nCounter:!0,tjp:{uuid:!0,timestamp:!0}}),l=c.newIbGib;await e.persistTransformResult({resTransform:c,space:t}),await e.registerNewIbGib({ibGib:l,space:t});let d=await T({timeline:l,mut8Opts:{dataToAddOrPatch:{type:"comment",label:"B1_4_6b"}},metaspace:e,space:t}),p=await T({timeline:d,mut8Opts:{dataToAddOrPatch:{type:"comment",label:"B2_4_6b"}},metaspace:e,space:t});Ie.targetBetaV2=p,m.targetC2=p,a(`4.6B Setup: \u2713 Local Timeline B created. B2 Tip: ${u({ibGib:p})}`),a("\u2713 4.6B Setup Complete! Timelines created locally. Ready for 4.6B Sync."),r.textContent="\u2713 4.6B Setup Complete";let f=document.getElementById("btn-4-6b-sync");f&&(f.disabled=!1)}catch(e){a(`\u2717 4.6B Setup FAILED: ${b(e)}`),console.error(e),r.disabled=!1}})}h(Pa,"init4_6bSetupButton");function Oa(){let r=document.getElementById("btn-4-6b-sync");r&&r.addEventListener("click",async()=>{try{r.disabled=!0,a("4.6B Sync: Initiating WebSocket Sync for both Timeline A and Timeline B in one call...");let e=Ie.targetAlphaV1,t=Ie.targetBetaV2;if(!m.domainI||!e||!t){a("\u26A0 4.6B Sync: Missing setup state. Please run Setup first."),r.disabled=!1;return}let n=await E(),o=await n.getLocalUserSpace({});if(!o)throw new Error("No default space.");await x({domainIbGibs:[e,t],passLabel:"Sync Alpha A1 + Beta B2",metaspace:n,space:o}),a("\u2713 4.6B Sync Execution Complete! Ready for 4.6B Check."),r.textContent="\u2713 4.6B Sync Run";let s=document.getElementById("btn-4-6b-check");s&&(s.disabled=!1)}catch(e){a(`\u2717 4.6B Sync FAILED: ${b(e)}`),console.error(e),r.disabled=!1}})}h(Oa,"init4_6bSyncButton");function xa(){let r=document.getElementById("btn-4-6b-check");r&&r.addEventListener("click",async()=>{try{r.disabled=!0,a("4.6B Check: Verifying both Timeline A and Timeline B exist on the server with matching dependency graphs...");let e=Ie.targetAlphaV1,t=Ie.targetBetaV2;if(!m.domainI||!e||!t){a("\u26A0 4.6B Check: Missing state. Did Setup and Sync run?"),r.disabled=!1;return}let n=u({ibGib:m.domainI}),o=u({ibGib:e}),s=u({ibGib:t}),i=await E(),c=await i.getLocalUserSpace({});if(!c)throw new Error("No default space.");let l=new B;a("4.6B Check: Fetching Timeline A dependency graph from server...");let d=await l.getIbGibGraph(n,o,!0);if(!d.success||!d.graph)throw new Error(`Failed to fetch Timeline A graph from server: ${d.message}`);let p=await i.getDependencyGraph({ibGibAddr:o,space:c});if(!W({graphA:p,graphB:d.graph}))throw new Error("Timeline A dependency graphs on local space and server are NOT equivalent.");a("4.6B Check: \u2713 Timeline A graphs are equivalent."),a("4.6B Check: Fetching Timeline B dependency graph from server...");let f=await l.getIbGibGraph(n,s,!0);if(!f.success||!f.graph)throw new Error(`Failed to fetch Timeline B graph from server: ${f.message}`);let y=await i.getDependencyGraph({ibGibAddr:s,space:c});if(!W({graphA:y,graphB:f.graph}))throw new Error("Timeline B dependency graphs on local space and server are NOT equivalent.");a("4.6B Check: \u2713 Timeline B graphs are equivalent."),a("\u2713 4.6B Check SUCCESS: Both independent timelines are fully synced and identical on client and server!"),r.textContent="\u2713 4.6B Check Success"}catch(e){a(`\u2717 4.6B Check FAILED: ${b(e)}`),console.error(e),r.disabled=!1}})}h(xa,"init4_6bCheckButton");var pe={},Da="test-sender-secret-phase4-7b";function Va(){let r=document.getElementById("btn-4-7b-setup");r&&r.addEventListener("click",async()=>{try{r.disabled=!0,a("4.7B Setup: Setting up identities, seeding history, and creating divergent branches...");let e=await E(),t=await e.getLocalUserSpace({});if(!t)throw new Error("No default space.");let n=new B;await q({masterSecret:Da,syncSalt:"senderidentitysyncsaltphase4-7b",manageSalt:"senderidentitymanagesaltphase4-7b",metaspace:e,space:t,apiBridge:n,phaseText:"4.7B"});let o=m.domainI,s=await e.createNewLocalSpace({opts:{allowCancel:!1,spaceName:"remote_space_4_7b",getFnPrompt:e.getFnPrompt}});await s.initialized,await e.put({ibGib:o,space:s}),await e.registerNewIbGib({ibGib:o,space:s});let i=await D.firstGen({parentIbGib:M,ib:"timeline_root_conflict_4_7b",data:{type:"root",label:"CommonRoot",random:Math.random()},dna:!0,nCounter:!0,tjp:{uuid:!0,timestamp:!0}}),c=i.newIbGib;await e.persistTransformResult({resTransform:i,space:t}),await e.registerNewIbGib({ibGib:c,space:t}),pe.testRoot=c;let l=await T({timeline:c,mut8Opts:{dataToAddOrPatch:{type:"comment",label:"V1Common"}},metaspace:e,space:t}),d=await e.getDependencyGraph({ibGibAddr:u({ibGib:c}),space:t}),p=await e.getDependencyGraph({ibGibAddr:u({ibGib:l}),space:t});await e.put({ibGibs:Object.values({...d,...p}),space:s}),await e.registerNewIbGib({ibGib:c,space:s}),await e.registerNewIbGib({ibGib:l,space:s}),a("4.7B Setup: Syncing v1_common to server..."),await x({domainIbGibs:[l],passLabel:"Seed v1_common",metaspace:e,space:t}),a("4.7B Setup: \u2713 Seeding complete on server.");let f=m.domainI;await X({domainI:f,metaspace:e,fromSpace:t,toSpace:s});let y=await T({timeline:l,mut8Opts:{dataToAddOrPatch:{fieldA:"source_edit"}},metaspace:e,space:t});pe.targetAlphaV2a=y,a(`4.7B Setup: \u2713 Created client divergent edit V2a: ${u({ibGib:y})}`);let S=await T({timeline:l,mut8Opts:{dataToAddOrPatch:{fieldB:"dest_edit"}},metaspace:e,space:s});pe.targetBetaV2b=S,a(`4.7B Setup: \u2713 Created remote divergent edit V2b: ${u({ibGib:S})}`),a("4.7B Setup: Pushing V2b from remote space to server..."),await J({domainIbGibs:[S],passLabel:"Push V2b from remoteSpace",metaspace:e,space:s,primarySpace:t,domainI:f,masterSecret:Da}),a("4.7B Setup: \u2713 Server tip is now V2b."),a("\u2713 4.7B Setup Complete! Ready for 4.7B Sync."),r.textContent="\u2713 4.7B Setup Complete";let g=document.getElementById("btn-4-7b-sync");g&&(g.disabled=!1)}catch(e){a(`\u2717 4.7B Setup FAILED: ${b(e)}`),console.error(e),r.disabled=!1}})}h(Va,"init4_7bSetupButton");function Ma(){let r=document.getElementById("btn-4-7b-sync");r&&r.addEventListener("click",async()=>{try{r.disabled=!0,a("4.7B Sync: Initiating WebSocket Sync for divergent edit V2a...");let e=pe.targetAlphaV2a;if(!m.domainI||!e){a("\u26A0 4.7B Sync: Missing setup state. Please run Setup first."),r.disabled=!1;return}let t=await E(),n=await t.getLocalUserSpace({});if(!n)throw new Error("No default space.");await x({domainIbGibs:[e],passLabel:"Sync V2a (conflict merge)",metaspace:t,space:n}),a("\u2713 4.7B Sync Execution Complete! Ready for 4.7B Check."),r.textContent="\u2713 4.7B Sync Run";let o=document.getElementById("btn-4-7b-check");o&&(o.disabled=!1)}catch(e){a(`\u2717 4.7B Sync FAILED: ${b(e)}`),console.error(e),r.disabled=!1}})}h(Ma,"init4_7bSyncButton");function Fa(){let r=document.getElementById("btn-4-7b-check");r&&r.addEventListener("click",async()=>{try{r.disabled=!0,a("4.7B Check: Verifying merged tip (V3) contains both edits on client and server...");let e=pe.testRoot,t=pe.targetAlphaV2a,n=pe.targetBetaV2b;if(!m.domainI||!e||!t||!n){a("\u26A0 4.7B Check: Missing state. Did Setup and Sync run?"),r.disabled=!1;return}let o=u({ibGib:m.domainI}),s=ee({ibGib:e,defaultIfNone:"incomingAddr"})??u({ibGib:e}),i=await E(),c=await i.getLocalUserSpace({});if(!c)throw new Error("No default space.");let d=(await i.getLocalUserSpace({}).then(A=>new Y().getKnowledgeMap({space:A,metaspace:i,domainIbGibs:[e]})))[s];if(a(`4.7B Check: Client tip address: ${d}`),!d)throw new Error("Client default space is missing the timeline tip.");let p=await i.get({addr:d,space:c});if(!p.success||!p.ibGibs?.length)throw new Error("Client tip not found in default local space.");let f=p.ibGibs[0];if(!f.data?.fieldA||!f.data?.fieldB)throw new Error(`Merged client tip missing edits: fieldA: ${f.data?.fieldA}, fieldB: ${f.data?.fieldB}`);a("4.7B Check: \u2713 Client tip has both fieldA and fieldB edits.");let y=f.rel8ns?.[ye];if(!y?.[0])throw new Error("Client tip is missing graftinfo relations.");let S=await i.get({addr:y[0],space:c});if(!S.success||!S.ibGibs?.length)throw new Error("GraftInfo not found in local space.");let g=S.ibGibs[0];if(!g.rel8ns?.[Se]||!g.rel8ns?.[we])throw new Error("GraftInfo is missing graftbase or graftorphan relations.");a("4.7B Check: \u2713 Client graft base and orphan relations are correctly set.");let _=await new B().getIbGibGraph(o,d,!0);if(!_.success||!_.graph)throw new Error(`Failed to fetch merged graph from server: ${_.message}`);let I=_.graph[d];if(!I)throw new Error("Merged V3 tip is not present on the server!");if(I.data?.fieldA!=="source_edit"||I.data?.fieldB!=="dest_edit")throw new Error("Server tip data edits do not match merged values.");a("4.7B Check: \u2713 Server tip has matching merged edits."),a("\u2713 4.7B Check SUCCESS: Divergent branches merged successfully via optimistic graft!"),r.textContent="\u2713 4.7B Check Success"}catch(e){a(`\u2717 4.7B Check FAILED: ${b(e)}`),console.error(e),r.disabled=!1}})}h(Fa,"init4_7bCheckButton");var Z={};function Ka(){let r=document.getElementById("btn-4-8b-setup");r&&r.addEventListener("click",async()=>{try{r.disabled=!0,a("4.8B Setup: Setting up identities, seeding history, and creating divergent branches in client and remote...");let e=await E(),t=await e.getLocalUserSpace({});if(!t)throw new Error("No default space.");let n=new B;await q({masterSecret:"test-sender-secret-phase4-8b",syncSalt:"senderidentitysyncsaltphase4-8b",manageSalt:"senderidentitymanagesaltphase4-8b",metaspace:e,space:t,apiBridge:n,phaseText:"4.8B"});let o=m.domainI;Z.domainI_latest=o;let s=u({ibGib:o});a("4.8B Setup: Creating temporary remote space...");let i=await e.createNewLocalSpace({opts:{allowCancel:!1,spaceName:"remote_space_4_8b",getFnPrompt:e.getFnPrompt}});await i.initialized,await X({domainI:o,metaspace:e,fromSpace:t,toSpace:i});let c=await D.firstGen({parentIbGib:M,ib:"timeline_root_conflict_4_8b",data:{type:"root",label:"CommonRoot",random:Math.random()},dna:!0,nCounter:!0,tjp:{uuid:!0,timestamp:!0}}),l=c.newIbGib;await e.persistTransformResult({resTransform:c,space:t}),await e.registerNewIbGib({ibGib:l,space:t}),Z.testRoot=l;let d=await T({timeline:l,mut8Opts:{dataToAddOrPatch:{type:"comment",label:"V1Common"}},metaspace:e,space:t}),p=await e.getDependencyGraph({ibGibAddr:u({ibGib:l}),space:t}),f=await e.getDependencyGraph({ibGibAddr:u({ibGib:d}),space:t}),y={...p,...f};await e.put({ibGibs:Object.values(y),space:i}),await e.registerNewIbGib({ibGib:l,space:i}),await e.registerNewIbGib({ibGib:d,space:i}),a("4.8B Setup: Syncing v1_common to server..."),await x({domainIbGibs:[d],passLabel:"Seed v1_common",metaspace:e,space:t}),a("4.8B Setup: \u2713 Seeding complete on server."),await X({domainI:m.domainI,metaspace:e,fromSpace:t,toSpace:i});let S=await D.firstGen({parentIbGib:M,ib:"beta_multitimelines_withid_4_8b",data:{fieldA:"beta field A created on source"},dna:!0,nCounter:!0,tjp:{uuid:!0,timestamp:!0}}),g=S.newIbGib;await e.persistTransformResult({resTransform:S,space:t}),await e.registerNewIbGib({ibGib:g,space:t}),Z.targetBetaV0=g,a(`4.8B Setup: \u2713 Created client independent related timeline Beta: ${u({ibGib:g})}`);let w=await T({timeline:d,mut8Opts:{dataToAddOrPatch:{fieldA:"source_edit"}},metaspace:e,space:t}),_=await Be({timeline:w,metaspace:e,space:t,rel8nInfos:[{rel8nName:"testrel8n",ibGibs:[g]}]});Z.targetAlphaV3a=_,a(`4.8B Setup: \u2713 Created client divergent edit V3a: ${u({ibGib:_})}`);let I=await T({timeline:d,mut8Opts:{dataToAddOrPatch:{fieldB:"dest_edit"}},metaspace:e,space:i});a(`4.8B Setup: \u2713 Created remote divergent edit V2b: ${u({ibGib:I})}`),a("4.8B Setup: Pushing V2b from remote space to server..."),await J({domainIbGibs:[I],passLabel:"Push V2b from remoteSpace",metaspace:e,space:i,primarySpace:t,domainI:m.domainI,masterSecret:"test-sender-secret-phase4-8b"}),Z.domainI_latest=m.domainI,a("4.8B Setup: \u2713 Server tip is now V2b. Evolved identity copied back."),a("\u2713 4.8B Setup Complete! Ready for 4.8B Sync."),r.textContent="\u2713 4.8B Setup Complete";let A=document.getElementById("btn-4-8b-sync");A&&(A.disabled=!1)}catch(e){a(`\u2717 4.8B Setup FAILED: ${b(e)}`),console.error(e),r.disabled=!1}})}h(Ka,"init4_8bSetupButton");function Ua(){let r=document.getElementById("btn-4-8b-sync");r&&r.addEventListener("click",async()=>{try{r.disabled=!0,a("4.8B Sync: Initiating WebSocket Sync for divergent edit V3a (with related timeline Beta)...");let e=Z.domainI_latest,t=Z.targetAlphaV3a;if(!e||!t){a("\u26A0 4.8B Sync: Missing setup state. Please run Setup first."),r.disabled=!1;return}let n=await E(),o=await n.getLocalUserSpace({});if(!o)throw new Error("No default space.");await x({domainIbGibs:[t],passLabel:"Sync V3a and merge",metaspace:n,space:o}),Z.domainI_latest=m.domainI,a("\u2713 4.8B Sync Execution Complete! Ready for 4.8B Check."),r.textContent="\u2713 4.8B Sync Run";let s=document.getElementById("btn-4-8b-check");s&&(s.disabled=!1)}catch(e){a(`\u2717 4.8B Sync FAILED: ${b(e)}`),console.error(e),r.disabled=!1}})}h(Ua,"init4_8bSyncButton");function ja(){let r=document.getElementById("btn-4-8b-check");r&&r.addEventListener("click",async()=>{try{r.disabled=!0,a("4.8B Check: Verifying merged tip (V4) contains both edits on client and server...");let e=Z.domainI_latest,t=Z.testRoot,n=Z.targetAlphaV3a,o=Z.targetBetaV0;if(!e||!t||!n||!o){a("\u26A0 4.8B Check: Missing state. Did Setup and Sync run?"),r.disabled=!1;return}let s=u({ibGib:e}),i=ee({ibGib:t,defaultIfNone:"incomingAddr"})??u({ibGib:t}),c=u({ibGib:o}),l=await E(),d=await l.getLocalUserSpace({});if(!d)throw new Error("No default space.");let f=(await l.getLocalUserSpace({}).then(P=>new Y().getKnowledgeMap({space:P,metaspace:l,domainIbGibs:[t]})))[i];if(a(`4.8B Check: Client tip address: ${f}`),!f)throw new Error("Client default space is missing the timeline tip.");let y=await l.get({addr:f,space:d});if(!y.success||!y.ibGibs||y.ibGibs.length===0)throw new Error("Client tip not found in default local space.");let S=y.ibGibs[0];if(!S.data||!S.data.fieldA||!S.data.fieldB)throw new Error(`Merged client tip is missing expected data edits: fieldA: ${S.data?.fieldA}, fieldB: ${S.data?.fieldB}`);a("4.8B Check: \u2713 Client tip has both fieldA and fieldB edits.");let g=S.rel8ns?.[ye];if(!g?.[0])throw new Error("Client tip is missing graftinfo relations.");let w=await l.get({addr:g[0],space:d});if(!w.success||!w.ibGibs||w.ibGibs.length===0)throw new Error("GraftInfo not found in local space.");let _=w.ibGibs[0],I=_.rel8ns?.[Se],A=_.rel8ns?.[we];if(!I||!A)throw new Error("GraftInfo is missing graftbase or graftorphan relations.");a("4.8B Check: \u2713 Client graft base and orphan relations are correctly set.");let v=new B;a("4.8B Check: Fetching server timeline graph...");let G=await v.getIbGibGraph(s,f,!0);if(!G.success||!G.graph)throw new Error(`Failed to fetch merged graph from server: ${G.message}`);let k=G.graph[f];if(!k)throw new Error("Merged V4 tip is not present on the server!");if(k.data?.fieldA!=="source_edit"||k.data?.fieldB!=="dest_edit")throw new Error("Server tip data edits do not match merged values.");a("4.8B Check: \u2713 Server tip has matching merged edits."),a("4.8B Check: Verifying related timeline Beta is present on the server...");let $=await v.getIbGibGraph(s,c,!0);if(!$.success||!$.graph||!$.graph[c])throw new Error(`Related timeline Beta (${c}) is missing from the server!`);a("4.8B Check: \u2713 Related timeline Beta successfully verified on the server."),a("\u2713 4.8B Check SUCCESS: Divergent branches merged successfully and related timeline synced on server!"),r.textContent="\u2713 4.8B Check Success"}catch(e){a(`\u2717 4.8B Check FAILED: ${b(e)}`),console.error(e),r.disabled=!1}})}h(ja,"init4_8bCheckButton");var ne={},Fe=`This is the initial quiz question.
3
3
  It has multiple lines.
4
4
  Students will answer this.`,Wa=`
@@ -1 +1 @@
1
- import{m as e}from"./chunk-FIAGRVBY.mjs";import"./chunk-XLQ3UCQY.mjs";console.log("space-gib early script executing...");e();
1
+ import{m as e}from"./chunk-5DTAUY3E.mjs";import"./chunk-J7X3XTAI.mjs";console.log("space-gib early script executing...");e();
@@ -13,3 +13,4 @@
13
13
  @import './css/cosmic.css';
14
14
  @import './css/activity-bar.css';
15
15
  @import './css/onboarding.css';
16
+ @import './css/tutorial.css';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ibgib/space-gib",
3
- "version": "0.0.35",
3
+ "version": "0.0.36",
4
4
  "type": "module",
5
5
  "description": "ibgib storage and provider service — SaaS at ibgib.space",
6
6
  "scripts": {
@@ -12,11 +12,11 @@
12
12
  "build:test": "tsc -p tsconfig.test.json"
13
13
  },
14
14
  "dependencies": {
15
- "@ibgib/core-gib": "^0.1.89",
15
+ "@ibgib/core-gib": "^0.1.90",
16
16
  "@ibgib/helper-gib": "^0.0.41",
17
17
  "@ibgib/ts-gib": "^0.5.38",
18
- "@ibgib/web-gib": "^0.0.75",
19
- "@ibgib/node-gib": "^0.0.36"
18
+ "@ibgib/web-gib": "^0.0.76",
19
+ "@ibgib/node-gib": "^0.0.37"
20
20
  },
21
21
  "engines": {
22
22
  "node": ">=20.0.0"
@@ -8,4 +8,4 @@
8
8
  /**
9
9
  * Version of space-gib, auto-updated by the build process.
10
10
  */
11
- export const AUTO_GENERATED_VERSION = '0.0.35';
11
+ export const AUTO_GENERATED_VERSION = '0.0.36';