@calimero-network/mero-react 11.2.0 → 11.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -306,8 +306,21 @@ Props, all optional:
306
306
  - `cluster`: the label shown as "Cluster"; by default the provider's cluster. `cluster={null}` leaves the row out.
307
307
  - `compactBelow`: the window width in px at or below which the chip is the icon alone. It is always the icon alone at 560px or narrower.
308
308
  - `appCode`: `(client, url) => Promise<AppCodeCheck>`, the app's own check that node `url` runs its code. It is asked when the popover opens on a real, verified node, and its `match` or `mismatch` is shown as the "App code" row. A new function checks again, so memoise it (`useCallback`).
309
+ - `compact`: `true` shows the chip as the icon alone at every width, whatever `compactBelow` says; for a floating chip.
310
+ - `open` and `onOpenChange`: the popover's open state. Leave `open` out and the shield keeps its own; set it and the shield is controlled, opening and closing only when `open` changes. `onOpenChange(open)` is called either way when the shield asks to change it: on a chip click, Escape or an outside click.
309
311
  - `colors`: colours for this shield (below).
310
312
 
313
+ A floating chip, icon only, that a menu item can also open:
314
+
315
+ ```tsx
316
+ const [shieldOpen, setShieldOpen] = useState(false);
317
+
318
+ <NodeShield compact open={shieldOpen} onOpenChange={setShieldOpen} />
319
+ <button onClick={() => setShieldOpen(true)}>Node details</button>
320
+ ```
321
+
322
+ Opening it from code behaves like a click: the popover is placed by the chip, takes focus and runs the app code check, and closing it returns focus to the chip.
323
+
311
324
  `AppCodeCheck` is the shape an app's own code check returns:
312
325
 
313
326
  ```ts
@@ -0,0 +1,256 @@
1
+ import { createContext, useState, useEffect, useCallback } from 'react';
2
+ import { verifyNodeUrl } from '@calimero-network/mero-js';
3
+
4
+ // src/context/context.ts
5
+ var MeroContext = createContext(null);
6
+
7
+ // #style-inject:#style-inject
8
+ function styleInject(css, { insertAt } = {}) {
9
+ if (!css || typeof document === "undefined") return;
10
+ const head = document.head || document.getElementsByTagName("head")[0];
11
+ const style = document.createElement("style");
12
+ style.type = "text/css";
13
+ if (insertAt === "top") {
14
+ if (head.firstChild) {
15
+ head.insertBefore(style, head.firstChild);
16
+ } else {
17
+ head.appendChild(style);
18
+ }
19
+ } else {
20
+ head.appendChild(style);
21
+ }
22
+ if (style.styleSheet) {
23
+ style.styleSheet.cssText = css;
24
+ } else {
25
+ style.appendChild(document.createTextNode(css));
26
+ }
27
+ }
28
+ var RETRY_BASE_MS = 2e3;
29
+ var RETRY_MAX_MS = 3e4;
30
+ var NODE_POLL_MS = 1e3;
31
+ var retryDelay = (attempt) => Math.min(RETRY_BASE_MS * 2 ** attempt, RETRY_MAX_MS);
32
+ async function check(client) {
33
+ try {
34
+ return await client.verify();
35
+ } catch {
36
+ return null;
37
+ }
38
+ }
39
+ function peek(client) {
40
+ let known;
41
+ try {
42
+ known = client?.verification();
43
+ } catch {
44
+ }
45
+ return known ?? { status: "checking", url: client?.nodeUrl ?? "" };
46
+ }
47
+ function useNodeVerification(client) {
48
+ const [held, setHeld] = useState(() => ({ client, state: peek(client) }));
49
+ const [round, setRound] = useState(0);
50
+ const [url, setUrl] = useState(client?.nodeUrl);
51
+ useEffect(() => {
52
+ setUrl(client?.nodeUrl);
53
+ if (!client) return;
54
+ const poll = setInterval(() => setUrl(client.nodeUrl), NODE_POLL_MS);
55
+ return () => clearInterval(poll);
56
+ }, [client]);
57
+ useEffect(() => {
58
+ if (!client) return;
59
+ let live = true;
60
+ let timer;
61
+ const run = async (attempt) => {
62
+ const next = await check(client);
63
+ if (!live || !next) return;
64
+ setHeld({ client, state: next });
65
+ if (next.status === "unreachable") timer = setTimeout(() => void run(attempt + 1), retryDelay(attempt));
66
+ };
67
+ setHeld({ client, state: peek(client) });
68
+ void run(0);
69
+ return () => {
70
+ live = false;
71
+ clearTimeout(timer);
72
+ };
73
+ }, [client, round, url]);
74
+ const state = held.client === client ? held.state : peek(client);
75
+ const inUse = client?.nodeUrl;
76
+ const shown = inUse && state.url !== inUse ? { status: "checking", url: inUse } : state;
77
+ return [shown, useCallback(() => setRound((n) => n + 1), [])];
78
+ }
79
+ function useAppCode(client, appCode, url) {
80
+ const [result, setResult] = useState(null);
81
+ useEffect(() => {
82
+ if (!client || !appCode || !url) return;
83
+ let live = true;
84
+ void Promise.resolve().then(() => appCode(client, url)).then(
85
+ (code) => live && client.nodeUrl === url && setResult({ client, url, appCode, code }),
86
+ () => void 0
87
+ );
88
+ return () => {
89
+ live = false;
90
+ };
91
+ }, [client, appCode, url]);
92
+ const current = result?.client === client && result?.url === url && result?.appCode === appCode && client?.nodeUrl === url;
93
+ return current ? result.code : null;
94
+ }
95
+ function cardError(e) {
96
+ const status = typeof e === "object" && e !== null && "status" in e ? e.status : void 0;
97
+ if (status === 404) return "This node cannot show app reviews yet.";
98
+ if (status === 401 || status === 403) return "You don't have access to this app's details.";
99
+ return "The review of this app could not load.";
100
+ }
101
+ function useCard(client, release, node) {
102
+ const [state, setState] = useState({ status: "loading" });
103
+ const [round, setRound] = useState(0);
104
+ const gate = node.status === "verified" ? "verified" : node.status === "refused" ? "refused" : "waiting";
105
+ useEffect(() => {
106
+ if (!release.version) {
107
+ setState({ status: "none" });
108
+ return;
109
+ }
110
+ if (!client) {
111
+ setState({ status: "error", message: "Not connected to a node." });
112
+ return;
113
+ }
114
+ if (gate !== "verified") {
115
+ setState(gate === "refused" ? { status: "refused" } : { status: "loading" });
116
+ return;
117
+ }
118
+ let live = true;
119
+ setState({ status: "loading" });
120
+ const { package: pkg, version, service } = release;
121
+ const request = service ? client.packageCapabilities(pkg, version, { service }) : client.packageCapabilities(pkg, version);
122
+ request.then(
123
+ (card) => live && setState({ status: "ready", card }),
124
+ (e) => live && setState({ status: "error", message: cardError(e) })
125
+ );
126
+ return () => {
127
+ live = false;
128
+ };
129
+ }, [client, release.package, release.version, release.service, round, gate]);
130
+ return [state, useCallback(() => setRound((n) => n + 1), [])];
131
+ }
132
+ var SEALED_PROFILE = "locked-read-only";
133
+ var JUST_NOW_SECONDS = 10;
134
+ var AGO = [
135
+ ["day", 86400],
136
+ ["hour", 3600],
137
+ ["minute", 60]
138
+ ];
139
+ var ago = new Intl.RelativeTimeFormat("en");
140
+ var SHIELD_LABEL = {
141
+ checking: "Checking node\u2026",
142
+ verified: "Verified node",
143
+ unsealed: "Test server: not sealed",
144
+ refused: "Node refused"
145
+ };
146
+ function shieldKind(state) {
147
+ if (state.status === "refused") return "refused";
148
+ if (state.status !== "verified") return "checking";
149
+ return !state.mock && state.profile === SEALED_PROFILE ? "verified" : "unsealed";
150
+ }
151
+ function checkedAgo(at, now = Date.now()) {
152
+ const seconds = Math.max(0, Math.round((now - at) / 1e3));
153
+ if (seconds < JUST_NOW_SECONDS) return "just now";
154
+ const [unit, size] = AGO.find(([, size2]) => seconds >= size2) ?? ["second", 1];
155
+ return ago.format(-Math.floor(seconds / size), unit);
156
+ }
157
+ function shortHash(hash) {
158
+ return hash.length > 12 ? `${hash.slice(0, 4)}\u2026${hash.slice(-4)}` : hash;
159
+ }
160
+ function hostOf(url) {
161
+ try {
162
+ return new URL(url).host;
163
+ } catch {
164
+ return url;
165
+ }
166
+ }
167
+ function releaseName(code) {
168
+ return code.package && code.version ? `${code.package} v${code.version}` : null;
169
+ }
170
+ function codeRow(code) {
171
+ if (code?.status === "match") {
172
+ const named = releaseName(code);
173
+ return {
174
+ label: "App code",
175
+ value: named ? `${named} \xB7 ${shortHash(code.appHash)}` : shortHash(code.appHash),
176
+ full: named ? `${named} \xB7 ${code.appHash}` : code.appHash,
177
+ mono: true,
178
+ hash: shortHash(code.appHash)
179
+ };
180
+ }
181
+ if (code?.status === "mismatch") {
182
+ return {
183
+ label: "App code",
184
+ value: `Does not match this app's release (node runs ${shortHash(code.appHash)})`,
185
+ full: `Does not match this app's release (node runs ${code.appHash}, expected ${code.expected})`,
186
+ tone: "bad"
187
+ };
188
+ }
189
+ return null;
190
+ }
191
+ function copy(state, kind, ago2) {
192
+ switch (kind) {
193
+ case "verified":
194
+ return {
195
+ title: "You are talking to a genuine Calimero TEE node",
196
+ sub: `Checked by this browser ${ago2}, before anything was sent.`
197
+ };
198
+ case "unsealed":
199
+ return {
200
+ title: SHIELD_LABEL.unsealed,
201
+ sub: state.status === "verified" && state.mock ? `A test server with no hardware enclave, so its data is not sealed. Checked by this browser ${ago2}.` : `This node did not show it runs the sealed, read-only profile, so its data is not sealed. Checked by this browser ${ago2}.`
202
+ };
203
+ case "refused":
204
+ return { title: SHIELD_LABEL.refused, sub: "This app refused the node and sent nothing." };
205
+ case "checking":
206
+ return {
207
+ title: SHIELD_LABEL.checking,
208
+ sub: state.status === "unreachable" ? "The node could not be reached. Trying again." : "This browser is checking the node before anything is sent."
209
+ };
210
+ }
211
+ }
212
+ function describeShield(state, { cluster, code, now = Date.now() }) {
213
+ const kind = shieldKind(state);
214
+ const real = state.status === "verified" && !state.mock ? state : null;
215
+ const release = real?.release;
216
+ const rows = [];
217
+ if (cluster) rows.push({ label: "Cluster", value: cluster });
218
+ rows.push({ label: "Node", value: hostOf(state.url), full: state.url, mono: true });
219
+ if (real && release) rows.push({ label: "Software", value: `mero-tee v${release}${real.profile ? ` \xB7 ${real.profile}` : ""}` });
220
+ const app = real ? codeRow(code) : null;
221
+ if (app) rows.push(app);
222
+ if (state.status === "refused" || state.status === "unreachable") {
223
+ rows.push({ label: "Reason", value: state.reason, ...state.status === "refused" ? { tone: "bad" } : {} });
224
+ }
225
+ const checked = "checkedAt" in state ? checkedAgo(state.checkedAt, now) : null;
226
+ if (checked) rows.push({ label: "Checked", value: checked });
227
+ const checks = [];
228
+ if (kind === "verified") checks.push("Running in an Intel TDX enclave (not debug)");
229
+ if (real && release) checks.push(`Measurements match the signed v${release} release`);
230
+ if (real) checks.push("Your connection is encrypted to this enclave's key");
231
+ if (app && code?.status === "match") {
232
+ const named = releaseName(code);
233
+ checks.push(named ? `Node runs the code listed for ${named}` : "Node runs the code bundle this app was built for");
234
+ }
235
+ return {
236
+ kind,
237
+ label: SHIELD_LABEL[kind],
238
+ ...copy(state, kind, checked ?? "just now"),
239
+ rows,
240
+ checks,
241
+ verifyUrl: real && release ? verifyNodeUrl(real.url, release) : null
242
+ };
243
+ }
244
+ function shieldDetails(view) {
245
+ return [
246
+ view.title,
247
+ view.sub,
248
+ "",
249
+ ...view.rows.map((r) => `${r.label}: ${r.full ?? r.value}`),
250
+ ...view.checks.length ? ["", ...view.checks.map((c) => `- ${c}`)] : []
251
+ ].join("\n");
252
+ }
253
+
254
+ export { MeroContext, describeShield, hostOf, shieldDetails, shortHash, styleInject, useAppCode, useCard, useNodeVerification };
255
+ //# sourceMappingURL=chunk-MMJOGIM5.js.map
256
+ //# sourceMappingURL=chunk-MMJOGIM5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/context/context.ts","#style-inject:#style-inject","../src/node-shield/nodeChecks.ts","../src/node-shield/shieldView.ts"],"names":["size","ago"],"mappings":";;;;AAIO,IAAM,WAAA,GAAc,cAAuC,IAAI;;;ACH7C,SAAR,YAA6B,GAAA,EAAK,EAAE,QAAA,EAAS,GAAI,EAAC,EAAG;AAC1D,EAAA,IAAI,CAAC,GAAA,IAAO,OAAO,QAAA,KAAa,WAAA,EAAa;AAE7C,EAAA,MAAM,OAAO,QAAA,CAAS,IAAA,IAAQ,SAAS,oBAAA,CAAqB,MAAM,EAAE,CAAC,CAAA;AACrE,EAAA,MAAM,KAAA,GAAQ,QAAA,CAAS,aAAA,CAAc,OAAO,CAAA;AAC5C,EAAA,KAAA,CAAM,IAAA,GAAO,UAAA;AAEb,EAAA,IAAI,aAAa,KAAA,EAAO;AACtB,IAAA,IAAI,KAAK,UAAA,EAAY;AACnB,MAAA,IAAA,CAAK,YAAA,CAAa,KAAA,EAAO,IAAA,CAAK,UAAU,CAAA;AAAA,IAC1C,CAAA,MAAO;AACL,MAAA,IAAA,CAAK,YAAY,KAAK,CAAA;AAAA,IACxB;AAAA,EACF,CAAA,MAAO;AACL,IAAA,IAAA,CAAK,YAAY,KAAK,CAAA;AAAA,EACxB;AAEA,EAAA,IAAI,MAAM,UAAA,EAAY;AACpB,IAAA,KAAA,C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KAAK,KAAK,kDAAkD,CAAA;AAAA,EACnH;AAEA,EAAA,OAAO;AAAA,IACL,IAAA;AAAA,IACA,KAAA,EAAO,aAAa,IAAI,CAAA;AAAA,IACxB,GAAG,IAAA,CAAK,KAAA,EAAO,IAAA,EAAM,WAAW,UAAU,CAAA;AAAA,IAC1C,IAAA;AAAA,IACA,MAAA;AAAA,IACA,WAAW,IAAA,IAAQ,OAAA,GAAU,cAAc,IAAA,CAAK,GAAA,EAAK,OAAO,CAAA,GAAI;AAAA,GAClE;AACF;AAGO,SAAS,cAAc,IAAA,EAA0B;AACtD,EAAA,OAAO;AAAA,IACL,IAAA,CAAK,KAAA;AAAA,IACL,IAAA,CAAK,GAAA;AAAA,IACL,EAAA;AAAA,IACA,GAAG,IAAA,CAAK,IAAA,CAAK,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,EAAG,CAAA,CAAE,KAAK,CAAA,EAAA,EAAK,CAAA,CAAE,IAAA,IAAQ,CAAA,CAAE,KAAK,CAAA,CAAE,CAAA;AAAA,IAC1D,GAAI,IAAA,CAAK,MAAA,CAAO,MAAA,GAAS,CAAC,IAAI,GAAG,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,EAAA,EAAK,CAAC,CAAA,CAAE,CAAC,IAAI;AAAC,GACxE,CAAE,KAAK,IAAI,CAAA;AACb","file":"chunk-MMJOGIM5.js","sourcesContent":["import { createContext } from 'react';\nimport type { MeroContextValue } from '../types';\n\n// Its own module so the node-shield entry shares this one context object with the main entry.\nexport const MeroContext = createContext<MeroContextValue | null>(null);\n","\n export default function styleInject(css, { insertAt } = {}) {\n if (!css || typeof document === 'undefined') return\n \n const head = document.head || document.getElementsByTagName('head')[0]\n const style = document.createElement('style')\n style.type = 'text/css'\n \n if (insertAt === 'top') {\n if (head.firstChild) {\n head.insertBefore(style, head.firstChild)\n } else {\n head.appendChild(style)\n }\n } else {\n head.appendChild(style)\n }\n \n if (style.styleSheet) {\n style.styleSheet.cssText = css\n } else {\n style.appendChild(document.createTextNode(css))\n }\n }\n ","import { useCallback, useEffect, useState } from 'react';\nimport type { CalimeroClient, NodeVerificationState, PackageCapabilities } from '@calimero-network/mero-js';\nimport type { AppCodeCheck } from './shieldView';\n\nconst RETRY_BASE_MS = 2_000;\nconst RETRY_MAX_MS = 30_000;\nconst NODE_POLL_MS = 1_000; // how often to notice that the client failed over\n\n/** An unreachable node is asked again after 2 s, 4 s, 8 s, up to 30 s. */\nconst retryDelay = (attempt: number) => Math.min(RETRY_BASE_MS * 2 ** attempt, RETRY_MAX_MS);\n\n/** The check's outcome, or `null` for a client that cannot be checked: it stays \"checking\" instead of taking the app down. */\nasync function check(client: CalimeroClient): Promise<NodeVerificationState | null> {\n try {\n return await client.verify();\n } catch {\n return null;\n }\n}\n\nfunction peek(client: CalimeroClient | null): NodeVerificationState {\n let known: NodeVerificationState | undefined;\n try {\n known = client?.verification();\n } catch {\n // A client that cannot say is still being checked.\n }\n return known ?? { status: 'checking', url: client?.nodeUrl ?? '' };\n}\n\n/** The check of the node in use, asked again after a failure to reach it, a failover, and whenever `refresh` is called. */\nexport function useNodeVerification(client: CalimeroClient | null): [NodeVerificationState, () => void] {\n // Kept with its client: a state from the previous client is never shown for the next one.\n const [held, setHeld] = useState(() => ({ client, state: peek(client) }));\n const [round, setRound] = useState(0);\n const [url, setUrl] = useState(client?.nodeUrl);\n useEffect(() => {\n setUrl(client?.nodeUrl);\n if (!client) return;\n const poll = setInterval(() => setUrl(client.nodeUrl), NODE_POLL_MS);\n return () => clearInterval(poll);\n }, [client]);\n useEffect(() => {\n if (!client) return;\n let live = true;\n let timer: ReturnType<typeof setTimeout> | undefined;\n const run = async (attempt: number) => {\n const next = await check(client);\n if (!live || !next) return;\n setHeld({ client, state: next });\n if (next.status === 'unreachable') timer = setTimeout(() => void run(attempt + 1), retryDelay(attempt));\n };\n setHeld({ client, state: peek(client) });\n void run(0);\n return () => {\n live = false;\n clearTimeout(timer);\n };\n }, [client, round, url]);\n const state = held.client === client ? held.state : peek(client);\n // Never describe a node the client has moved on from: compared with the node in use now, not the last poll.\n const inUse = client?.nodeUrl;\n const shown: NodeVerificationState = inUse && state.url !== inUse ? { status: 'checking', url: inUse } : state;\n return [shown, useCallback(() => setRound((n) => n + 1), [])];\n}\n\n/** The app's own check that a node runs its code; memoise it, since a new function checks again. */\nexport type AppCodeChecker = (client: CalimeroClient, url: string) => Promise<AppCodeCheck>;\n\n/** `appCode`'s answer for verified node `url`, shown only while the client, node and function are the ones it was asked for. */\nexport function useAppCode(client: CalimeroClient | null, appCode: AppCodeChecker | undefined, url: string | null): AppCodeCheck | null {\n const [result, setResult] = useState<{ client: CalimeroClient; url: string; appCode: AppCodeChecker; code: AppCodeCheck } | null>(null);\n useEffect(() => {\n if (!client || !appCode || !url) return;\n let live = true;\n void Promise.resolve()\n .then(() => appCode(client, url))\n .then(\n (code) => live && client.nodeUrl === url && setResult({ client, url, appCode, code }),\n () => undefined,\n );\n return () => {\n live = false;\n };\n }, [client, appCode, url]);\n const current = result?.client === client && result?.url === url && result?.appCode === appCode && client?.nodeUrl === url;\n return current ? result.code : null;\n}\n\n/** The package release a review is about. */\nexport interface ReviewRelease {\n package: string;\n version: string;\n /** The service of a multi-service release; the card is per service. */\n service?: string;\n}\n\n/** An app with no published release (a dev bundle, a package with no version): there is no signed card to read. */\nexport interface UnreleasedApp {\n package: string;\n version?: undefined;\n service?: undefined;\n}\n\nexport type CardState =\n | { status: 'loading' }\n /** The app has no release, so there is nothing to ask for. */\n | { status: 'none' }\n | { status: 'ready'; card: PackageCapabilities }\n | { status: 'error'; message: string }\n /** The node did not pass its own check, so it is not asked and not retried. */\n | { status: 'refused' };\n\n/** A plain sentence for a failed card request: never the node's raw error text. */\nexport function cardError(e: unknown): string {\n const status = typeof e === 'object' && e !== null && 'status' in e ? (e as { status: unknown }).status : undefined;\n if (status === 404) return 'This node cannot show app reviews yet.';\n if (status === 401 || status === 403) return \"You don't have access to this app's details.\";\n return 'The review of this app could not load.';\n}\n\n/** The release's capability card from the node, asked only once the node's own check verified it, and again on `retry`. */\nexport function useCard(client: CalimeroClient | null, release: ReviewRelease | UnreleasedApp, node: NodeVerificationState): [CardState, () => void] {\n const [state, setState] = useState<CardState>({ status: 'loading' });\n const [round, setRound] = useState(0);\n const gate = node.status === 'verified' ? 'verified' : node.status === 'refused' ? 'refused' : 'waiting';\n useEffect(() => {\n if (!release.version) {\n setState({ status: 'none' });\n return;\n }\n if (!client) {\n setState({ status: 'error', message: 'Not connected to a node.' });\n return;\n }\n if (gate !== 'verified') {\n setState(gate === 'refused' ? { status: 'refused' } : { status: 'loading' });\n return;\n }\n let live = true;\n setState({ status: 'loading' });\n const { package: pkg, version, service } = release;\n const request = service ? client.packageCapabilities(pkg, version, { service }) : client.packageCapabilities(pkg, version);\n request.then(\n (card) => live && setState({ status: 'ready', card }),\n (e: unknown) => live && setState({ status: 'error', message: cardError(e) }),\n );\n return () => {\n live = false;\n };\n }, [client, release.package, release.version, release.service, round, gate]);\n return [state, useCallback(() => setRound((n) => n + 1), [])];\n}\n","/** What the node shield says about a node, from the check mero-js ran: only what that check verified. */\nimport { verifyNodeUrl, type NodeVerificationState } from '@calimero-network/mero-js';\n\nconst SEALED_PROFILE = 'locked-read-only'; // the release profile that seals a node's data\nconst JUST_NOW_SECONDS = 10;\nconst AGO = [\n ['day', 86_400],\n ['hour', 3_600],\n ['minute', 60],\n] as const;\nconst ago = new Intl.RelativeTimeFormat('en');\n\n/** Whether the node runs the app's code: `match` only when both hashes are present and equal; anything not checked is `unknown`. */\nexport type AppCodeCheck =\n | { status: 'match'; appHash: string; checkedAt: number; package?: string; version?: string }\n | { status: 'mismatch'; appHash: string; expected: string }\n | { status: 'unknown'; reason: string };\n\nexport type ShieldKind = 'checking' | 'verified' | 'unsealed' | 'refused';\n\nexport interface ShieldRow {\n label: string;\n value: string;\n /** What `value` abbreviates, for the copied details. */\n full?: string;\n mono?: boolean;\n tone?: 'bad';\n /** The short hash that ends `value`, kept on one line. */\n hash?: string;\n}\n\nexport interface ShieldView {\n kind: ShieldKind;\n /** The chip's text. */\n label: string;\n title: string;\n sub: string;\n rows: ShieldRow[];\n /** Facts the check verified for this node, and nothing else. */\n checks: string[];\n /** The public verifier's page for this node; `null` unless a signed release judged a real quote. */\n verifyUrl: string | null;\n}\n\nconst SHIELD_LABEL: Record<ShieldKind, string> = {\n checking: 'Checking node…',\n verified: 'Verified node',\n unsealed: 'Test server: not sealed',\n refused: 'Node refused',\n};\n\n/** Sealed means the locked profile on a real quote; `unreachable` is no answer yet, so it reads as checking. */\nexport function shieldKind(state: NodeVerificationState): ShieldKind {\n if (state.status === 'refused') return 'refused';\n if (state.status !== 'verified') return 'checking';\n return !state.mock && state.profile === SEALED_PROFILE ? 'verified' : 'unsealed';\n}\n\n/** \"2 minutes ago\", or \"just now\" for the last few seconds. */\nexport function checkedAgo(at: number, now: number = Date.now()): string {\n const seconds = Math.max(0, Math.round((now - at) / 1000));\n if (seconds < JUST_NOW_SECONDS) return 'just now';\n const [unit, size] = AGO.find(([, size]) => seconds >= size) ?? (['second', 1] as const);\n return ago.format(-Math.floor(seconds / size), unit);\n}\n\n/** `7f3a…c91e`. */\nexport function shortHash(hash: string): string {\n return hash.length > 12 ? `${hash.slice(0, 4)}…${hash.slice(-4)}` : hash;\n}\n\nexport function hostOf(url: string): string {\n try {\n return new URL(url).host;\n } catch {\n return url;\n }\n}\n\nfunction releaseName(code: Extract<AppCodeCheck, { status: 'match' }>): string | null {\n return code.package && code.version ? `${code.package} v${code.version}` : null;\n}\n\nfunction codeRow(code: AppCodeCheck | null): ShieldRow | null {\n if (code?.status === 'match') {\n const named = releaseName(code);\n return {\n label: 'App code',\n value: named ? `${named} · ${shortHash(code.appHash)}` : shortHash(code.appHash),\n full: named ? `${named} · ${code.appHash}` : code.appHash,\n mono: true,\n hash: shortHash(code.appHash),\n };\n }\n if (code?.status === 'mismatch') {\n return {\n label: 'App code',\n value: `Does not match this app's release (node runs ${shortHash(code.appHash)})`,\n full: `Does not match this app's release (node runs ${code.appHash}, expected ${code.expected})`,\n tone: 'bad',\n };\n }\n return null;\n}\n\nfunction copy(state: NodeVerificationState, kind: ShieldKind, ago: string): Pick<ShieldView, 'title' | 'sub'> {\n switch (kind) {\n case 'verified':\n return {\n title: 'You are talking to a genuine Calimero TEE node',\n sub: `Checked by this browser ${ago}, before anything was sent.`,\n };\n case 'unsealed':\n return {\n title: SHIELD_LABEL.unsealed,\n sub:\n state.status === 'verified' && state.mock\n ? `A test server with no hardware enclave, so its data is not sealed. Checked by this browser ${ago}.`\n : `This node did not show it runs the sealed, read-only profile, so its data is not sealed. Checked by this browser ${ago}.`,\n };\n case 'refused':\n return { title: SHIELD_LABEL.refused, sub: 'This app refused the node and sent nothing.' };\n case 'checking':\n return {\n title: SHIELD_LABEL.checking,\n sub:\n state.status === 'unreachable'\n ? 'The node could not be reached. Trying again.'\n : 'This browser is checking the node before anything is sent.',\n };\n }\n}\n\n/** Everything the chip and popover show for `state`, in `cluster`, with the app's code check. */\nexport function describeShield(\n state: NodeVerificationState,\n { cluster, code, now = Date.now() }: { cluster?: string | null; code: AppCodeCheck | null; now?: number },\n): ShieldView {\n const kind = shieldKind(state);\n // A mock is never a real node: nothing about releases or app code is claimed for one.\n const real = state.status === 'verified' && !state.mock ? state : null;\n const release = real?.release;\n const rows: ShieldRow[] = [];\n if (cluster) rows.push({ label: 'Cluster', value: cluster });\n rows.push({ label: 'Node', value: hostOf(state.url), full: state.url, mono: true });\n if (real && release) rows.push({ label: 'Software', value: `mero-tee v${release}${real.profile ? ` · ${real.profile}` : ''}` });\n const app = real ? codeRow(code) : null;\n if (app) rows.push(app);\n if (state.status === 'refused' || state.status === 'unreachable') {\n rows.push({ label: 'Reason', value: state.reason, ...(state.status === 'refused' ? { tone: 'bad' as const } : {}) });\n }\n const checked = 'checkedAt' in state ? checkedAgo(state.checkedAt, now) : null;\n if (checked) rows.push({ label: 'Checked', value: checked });\n\n const checks: string[] = [];\n if (kind === 'verified') checks.push('Running in an Intel TDX enclave (not debug)');\n if (real && release) checks.push(`Measurements match the signed v${release} release`);\n if (real) checks.push(\"Your connection is encrypted to this enclave's key\");\n if (app && code?.status === 'match') {\n const named = releaseName(code);\n checks.push(named ? `Node runs the code listed for ${named}` : 'Node runs the code bundle this app was built for');\n }\n\n return {\n kind,\n label: SHIELD_LABEL[kind],\n ...copy(state, kind, checked ?? 'just now'),\n rows,\n checks,\n verifyUrl: real && release ? verifyNodeUrl(real.url, release) : null,\n };\n}\n\n/** The popover's facts as plain text, for \"Copy details\". */\nexport function shieldDetails(view: ShieldView): string {\n return [\n view.title,\n view.sub,\n '',\n ...view.rows.map((r) => `${r.label}: ${r.full ?? r.value}`),\n ...(view.checks.length ? ['', ...view.checks.map((c) => `- ${c}`)] : []),\n ].join('\\n');\n}\n"]}
@@ -0,0 +1,266 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var meroJs = require('@calimero-network/mero-js');
5
+
6
+ // src/context/context.ts
7
+ var MeroContext = react.createContext(null);
8
+
9
+ // #style-inject:#style-inject
10
+ function styleInject(css, { insertAt } = {}) {
11
+ if (!css || typeof document === "undefined") return;
12
+ const head = document.head || document.getElementsByTagName("head")[0];
13
+ const style = document.createElement("style");
14
+ style.type = "text/css";
15
+ if (insertAt === "top") {
16
+ if (head.firstChild) {
17
+ head.insertBefore(style, head.firstChild);
18
+ } else {
19
+ head.appendChild(style);
20
+ }
21
+ } else {
22
+ head.appendChild(style);
23
+ }
24
+ if (style.styleSheet) {
25
+ style.styleSheet.cssText = css;
26
+ } else {
27
+ style.appendChild(document.createTextNode(css));
28
+ }
29
+ }
30
+ var RETRY_BASE_MS = 2e3;
31
+ var RETRY_MAX_MS = 3e4;
32
+ var NODE_POLL_MS = 1e3;
33
+ var retryDelay = (attempt) => Math.min(RETRY_BASE_MS * 2 ** attempt, RETRY_MAX_MS);
34
+ async function check(client) {
35
+ try {
36
+ return await client.verify();
37
+ } catch {
38
+ return null;
39
+ }
40
+ }
41
+ function peek(client) {
42
+ let known;
43
+ try {
44
+ known = client?.verification();
45
+ } catch {
46
+ }
47
+ return known ?? { status: "checking", url: client?.nodeUrl ?? "" };
48
+ }
49
+ function useNodeVerification(client) {
50
+ const [held, setHeld] = react.useState(() => ({ client, state: peek(client) }));
51
+ const [round, setRound] = react.useState(0);
52
+ const [url, setUrl] = react.useState(client?.nodeUrl);
53
+ react.useEffect(() => {
54
+ setUrl(client?.nodeUrl);
55
+ if (!client) return;
56
+ const poll = setInterval(() => setUrl(client.nodeUrl), NODE_POLL_MS);
57
+ return () => clearInterval(poll);
58
+ }, [client]);
59
+ react.useEffect(() => {
60
+ if (!client) return;
61
+ let live = true;
62
+ let timer;
63
+ const run = async (attempt) => {
64
+ const next = await check(client);
65
+ if (!live || !next) return;
66
+ setHeld({ client, state: next });
67
+ if (next.status === "unreachable") timer = setTimeout(() => void run(attempt + 1), retryDelay(attempt));
68
+ };
69
+ setHeld({ client, state: peek(client) });
70
+ void run(0);
71
+ return () => {
72
+ live = false;
73
+ clearTimeout(timer);
74
+ };
75
+ }, [client, round, url]);
76
+ const state = held.client === client ? held.state : peek(client);
77
+ const inUse = client?.nodeUrl;
78
+ const shown = inUse && state.url !== inUse ? { status: "checking", url: inUse } : state;
79
+ return [shown, react.useCallback(() => setRound((n) => n + 1), [])];
80
+ }
81
+ function useAppCode(client, appCode, url) {
82
+ const [result, setResult] = react.useState(null);
83
+ react.useEffect(() => {
84
+ if (!client || !appCode || !url) return;
85
+ let live = true;
86
+ void Promise.resolve().then(() => appCode(client, url)).then(
87
+ (code) => live && client.nodeUrl === url && setResult({ client, url, appCode, code }),
88
+ () => void 0
89
+ );
90
+ return () => {
91
+ live = false;
92
+ };
93
+ }, [client, appCode, url]);
94
+ const current = result?.client === client && result?.url === url && result?.appCode === appCode && client?.nodeUrl === url;
95
+ return current ? result.code : null;
96
+ }
97
+ function cardError(e) {
98
+ const status = typeof e === "object" && e !== null && "status" in e ? e.status : void 0;
99
+ if (status === 404) return "This node cannot show app reviews yet.";
100
+ if (status === 401 || status === 403) return "You don't have access to this app's details.";
101
+ return "The review of this app could not load.";
102
+ }
103
+ function useCard(client, release, node) {
104
+ const [state, setState] = react.useState({ status: "loading" });
105
+ const [round, setRound] = react.useState(0);
106
+ const gate = node.status === "verified" ? "verified" : node.status === "refused" ? "refused" : "waiting";
107
+ react.useEffect(() => {
108
+ if (!release.version) {
109
+ setState({ status: "none" });
110
+ return;
111
+ }
112
+ if (!client) {
113
+ setState({ status: "error", message: "Not connected to a node." });
114
+ return;
115
+ }
116
+ if (gate !== "verified") {
117
+ setState(gate === "refused" ? { status: "refused" } : { status: "loading" });
118
+ return;
119
+ }
120
+ let live = true;
121
+ setState({ status: "loading" });
122
+ const { package: pkg, version, service } = release;
123
+ const request = service ? client.packageCapabilities(pkg, version, { service }) : client.packageCapabilities(pkg, version);
124
+ request.then(
125
+ (card) => live && setState({ status: "ready", card }),
126
+ (e) => live && setState({ status: "error", message: cardError(e) })
127
+ );
128
+ return () => {
129
+ live = false;
130
+ };
131
+ }, [client, release.package, release.version, release.service, round, gate]);
132
+ return [state, react.useCallback(() => setRound((n) => n + 1), [])];
133
+ }
134
+ var SEALED_PROFILE = "locked-read-only";
135
+ var JUST_NOW_SECONDS = 10;
136
+ var AGO = [
137
+ ["day", 86400],
138
+ ["hour", 3600],
139
+ ["minute", 60]
140
+ ];
141
+ var ago = new Intl.RelativeTimeFormat("en");
142
+ var SHIELD_LABEL = {
143
+ checking: "Checking node\u2026",
144
+ verified: "Verified node",
145
+ unsealed: "Test server: not sealed",
146
+ refused: "Node refused"
147
+ };
148
+ function shieldKind(state) {
149
+ if (state.status === "refused") return "refused";
150
+ if (state.status !== "verified") return "checking";
151
+ return !state.mock && state.profile === SEALED_PROFILE ? "verified" : "unsealed";
152
+ }
153
+ function checkedAgo(at, now = Date.now()) {
154
+ const seconds = Math.max(0, Math.round((now - at) / 1e3));
155
+ if (seconds < JUST_NOW_SECONDS) return "just now";
156
+ const [unit, size] = AGO.find(([, size2]) => seconds >= size2) ?? ["second", 1];
157
+ return ago.format(-Math.floor(seconds / size), unit);
158
+ }
159
+ function shortHash(hash) {
160
+ return hash.length > 12 ? `${hash.slice(0, 4)}\u2026${hash.slice(-4)}` : hash;
161
+ }
162
+ function hostOf(url) {
163
+ try {
164
+ return new URL(url).host;
165
+ } catch {
166
+ return url;
167
+ }
168
+ }
169
+ function releaseName(code) {
170
+ return code.package && code.version ? `${code.package} v${code.version}` : null;
171
+ }
172
+ function codeRow(code) {
173
+ if (code?.status === "match") {
174
+ const named = releaseName(code);
175
+ return {
176
+ label: "App code",
177
+ value: named ? `${named} \xB7 ${shortHash(code.appHash)}` : shortHash(code.appHash),
178
+ full: named ? `${named} \xB7 ${code.appHash}` : code.appHash,
179
+ mono: true,
180
+ hash: shortHash(code.appHash)
181
+ };
182
+ }
183
+ if (code?.status === "mismatch") {
184
+ return {
185
+ label: "App code",
186
+ value: `Does not match this app's release (node runs ${shortHash(code.appHash)})`,
187
+ full: `Does not match this app's release (node runs ${code.appHash}, expected ${code.expected})`,
188
+ tone: "bad"
189
+ };
190
+ }
191
+ return null;
192
+ }
193
+ function copy(state, kind, ago2) {
194
+ switch (kind) {
195
+ case "verified":
196
+ return {
197
+ title: "You are talking to a genuine Calimero TEE node",
198
+ sub: `Checked by this browser ${ago2}, before anything was sent.`
199
+ };
200
+ case "unsealed":
201
+ return {
202
+ title: SHIELD_LABEL.unsealed,
203
+ sub: state.status === "verified" && state.mock ? `A test server with no hardware enclave, so its data is not sealed. Checked by this browser ${ago2}.` : `This node did not show it runs the sealed, read-only profile, so its data is not sealed. Checked by this browser ${ago2}.`
204
+ };
205
+ case "refused":
206
+ return { title: SHIELD_LABEL.refused, sub: "This app refused the node and sent nothing." };
207
+ case "checking":
208
+ return {
209
+ title: SHIELD_LABEL.checking,
210
+ sub: state.status === "unreachable" ? "The node could not be reached. Trying again." : "This browser is checking the node before anything is sent."
211
+ };
212
+ }
213
+ }
214
+ function describeShield(state, { cluster, code, now = Date.now() }) {
215
+ const kind = shieldKind(state);
216
+ const real = state.status === "verified" && !state.mock ? state : null;
217
+ const release = real?.release;
218
+ const rows = [];
219
+ if (cluster) rows.push({ label: "Cluster", value: cluster });
220
+ rows.push({ label: "Node", value: hostOf(state.url), full: state.url, mono: true });
221
+ if (real && release) rows.push({ label: "Software", value: `mero-tee v${release}${real.profile ? ` \xB7 ${real.profile}` : ""}` });
222
+ const app = real ? codeRow(code) : null;
223
+ if (app) rows.push(app);
224
+ if (state.status === "refused" || state.status === "unreachable") {
225
+ rows.push({ label: "Reason", value: state.reason, ...state.status === "refused" ? { tone: "bad" } : {} });
226
+ }
227
+ const checked = "checkedAt" in state ? checkedAgo(state.checkedAt, now) : null;
228
+ if (checked) rows.push({ label: "Checked", value: checked });
229
+ const checks = [];
230
+ if (kind === "verified") checks.push("Running in an Intel TDX enclave (not debug)");
231
+ if (real && release) checks.push(`Measurements match the signed v${release} release`);
232
+ if (real) checks.push("Your connection is encrypted to this enclave's key");
233
+ if (app && code?.status === "match") {
234
+ const named = releaseName(code);
235
+ checks.push(named ? `Node runs the code listed for ${named}` : "Node runs the code bundle this app was built for");
236
+ }
237
+ return {
238
+ kind,
239
+ label: SHIELD_LABEL[kind],
240
+ ...copy(state, kind, checked ?? "just now"),
241
+ rows,
242
+ checks,
243
+ verifyUrl: real && release ? meroJs.verifyNodeUrl(real.url, release) : null
244
+ };
245
+ }
246
+ function shieldDetails(view) {
247
+ return [
248
+ view.title,
249
+ view.sub,
250
+ "",
251
+ ...view.rows.map((r) => `${r.label}: ${r.full ?? r.value}`),
252
+ ...view.checks.length ? ["", ...view.checks.map((c) => `- ${c}`)] : []
253
+ ].join("\n");
254
+ }
255
+
256
+ exports.MeroContext = MeroContext;
257
+ exports.describeShield = describeShield;
258
+ exports.hostOf = hostOf;
259
+ exports.shieldDetails = shieldDetails;
260
+ exports.shortHash = shortHash;
261
+ exports.styleInject = styleInject;
262
+ exports.useAppCode = useAppCode;
263
+ exports.useCard = useCard;
264
+ exports.useNodeVerification = useNodeVerification;
265
+ //# sourceMappingURL=chunk-RRETZWNI.cjs.map
266
+ //# sourceMappingURL=chunk-RRETZWNI.cjs.map