@open-charging-cloud/chargy-gui 0.0.0-stage → 0.1.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/CHANGELOG.md +75 -0
- package/LICENSE +661 -0
- package/README.md +48 -2
- package/SECURITY.md +21 -0
- package/dist/anchorKeyTrust.d.ts +9 -0
- package/dist/anchorKeyTrust.d.ts.map +1 -0
- package/dist/anchorKeyTrust.js +24 -0
- package/dist/anchorKeyTrust.js.map +1 -0
- package/dist/anchorKeyTrustView.d.ts +14 -0
- package/dist/anchorKeyTrustView.d.ts.map +1 -0
- package/dist/anchorKeyTrustView.js +95 -0
- package/dist/anchorKeyTrustView.js.map +1 -0
- package/dist/browserFiles.d.ts +5 -0
- package/dist/browserFiles.d.ts.map +1 -0
- package/dist/browserFiles.js +100 -0
- package/dist/browserFiles.js.map +1 -0
- package/dist/core/i18n.json +1518 -0
- package/dist/core/package.json +119 -0
- package/dist/core/validationRules.json +8 -0
- package/dist/domHelpers.d.ts +25 -0
- package/dist/domHelpers.d.ts.map +1 -0
- package/dist/domHelpers.js +212 -0
- package/dist/domHelpers.js.map +1 -0
- package/dist/historicalSessionPanel.d.ts +24 -0
- package/dist/historicalSessionPanel.d.ts.map +1 -0
- package/dist/historicalSessionPanel.js +108 -0
- package/dist/historicalSessionPanel.js.map +1 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/liveLinkTrust.d.ts +208 -0
- package/dist/liveLinkTrust.d.ts.map +1 -0
- package/dist/liveLinkTrust.js +452 -0
- package/dist/liveLinkTrust.js.map +1 -0
- package/dist/livePOISession.d.ts +38 -0
- package/dist/livePOISession.d.ts.map +1 -0
- package/dist/livePOISession.js +193 -0
- package/dist/livePOISession.js.map +1 -0
- package/dist/measurementDetailsRenderer.d.ts +25 -0
- package/dist/measurementDetailsRenderer.d.ts.map +1 -0
- package/dist/measurementDetailsRenderer.js +343 -0
- package/dist/measurementDetailsRenderer.js.map +1 -0
- package/dist/poiConsistencyView.d.ts +3 -0
- package/dist/poiConsistencyView.d.ts.map +1 -0
- package/dist/poiConsistencyView.js +14 -0
- package/dist/poiConsistencyView.js.map +1 -0
- package/dist/poiObservedHistory.d.ts +49 -0
- package/dist/poiObservedHistory.d.ts.map +1 -0
- package/dist/poiObservedHistory.js +205 -0
- package/dist/poiObservedHistory.js.map +1 -0
- package/dist/poiTransport.d.ts +12 -0
- package/dist/poiTransport.d.ts.map +1 -0
- package/dist/poiTransport.js +74 -0
- package/dist/poiTransport.js.map +1 -0
- package/dist/poiTrustContext.d.ts +134 -0
- package/dist/poiTrustContext.d.ts.map +1 -0
- package/dist/poiTrustContext.js +243 -0
- package/dist/poiTrustContext.js.map +1 -0
- package/dist/poiTrustLineage.d.ts +10 -0
- package/dist/poiTrustLineage.d.ts.map +1 -0
- package/dist/poiTrustLineage.js +47 -0
- package/dist/poiTrustLineage.js.map +1 -0
- package/dist/poiURLs.d.ts +5 -0
- package/dist/poiURLs.d.ts.map +1 -0
- package/dist/poiURLs.js +24 -0
- package/dist/poiURLs.js.map +1 -0
- package/dist/poiWitnessManagement.d.ts +3 -0
- package/dist/poiWitnessManagement.d.ts.map +1 -0
- package/dist/poiWitnessManagement.js +127 -0
- package/dist/poiWitnessManagement.js.map +1 -0
- package/dist/poiWitnessTrust.d.ts +26 -0
- package/dist/poiWitnessTrust.d.ts.map +1 -0
- package/dist/poiWitnessTrust.js +90 -0
- package/dist/poiWitnessTrust.js.map +1 -0
- package/dist/pricePublicationData.d.ts +19 -0
- package/dist/pricePublicationData.d.ts.map +1 -0
- package/dist/pricePublicationData.js +83 -0
- package/dist/pricePublicationData.js.map +1 -0
- package/dist/roamingNetworks.d.ts +14 -0
- package/dist/roamingNetworks.d.ts.map +1 -0
- package/dist/roamingNetworks.js +33 -0
- package/dist/roamingNetworks.js.map +1 -0
- package/dist/securityFingerprint.d.ts +16 -0
- package/dist/securityFingerprint.d.ts.map +1 -0
- package/dist/securityFingerprint.js +36 -0
- package/dist/securityFingerprint.js.map +1 -0
- package/dist/securityFingerprintView.d.ts +3 -0
- package/dist/securityFingerprintView.d.ts.map +1 -0
- package/dist/securityFingerprintView.js +61 -0
- package/dist/securityFingerprintView.js.map +1 -0
- package/dist/sessionEvidenceStore.d.ts +23 -0
- package/dist/sessionEvidenceStore.d.ts.map +1 -0
- package/dist/sessionEvidenceStore.js +81 -0
- package/dist/sessionEvidenceStore.js.map +1 -0
- package/dist/sessionMeterKeyView.d.ts +9 -0
- package/dist/sessionMeterKeyView.d.ts.map +1 -0
- package/dist/sessionMeterKeyView.js +55 -0
- package/dist/sessionMeterKeyView.js.map +1 -0
- package/dist/sessionPOIData.d.ts +49 -0
- package/dist/sessionPOIData.d.ts.map +1 -0
- package/dist/sessionPOIData.js +161 -0
- package/dist/sessionPOIData.js.map +1 -0
- package/dist/sessionPOIPanel.d.ts +50 -0
- package/dist/sessionPOIPanel.d.ts.map +1 -0
- package/dist/sessionPOIPanel.js +288 -0
- package/dist/sessionPOIPanel.js.map +1 -0
- package/dist/sessionPriceData.d.ts +17 -0
- package/dist/sessionPriceData.d.ts.map +1 -0
- package/dist/sessionPriceData.js +51 -0
- package/dist/sessionPriceData.js.map +1 -0
- package/dist/sessionPricePanel.d.ts +31 -0
- package/dist/sessionPricePanel.d.ts.map +1 -0
- package/dist/sessionPricePanel.js +222 -0
- package/dist/sessionPricePanel.js.map +1 -0
- package/dist/sessionUIState.d.ts +12 -0
- package/dist/sessionUIState.d.ts.map +1 -0
- package/dist/sessionUIState.js +33 -0
- package/dist/sessionUIState.js.map +1 -0
- package/dist/stationProofData.d.ts +38 -0
- package/dist/stationProofData.d.ts.map +1 -0
- package/dist/stationProofData.js +83 -0
- package/dist/stationProofData.js.map +1 -0
- package/dist/stationProofPanel.d.ts +44 -0
- package/dist/stationProofPanel.d.ts.map +1 -0
- package/dist/stationProofPanel.js +304 -0
- package/dist/stationProofPanel.js.map +1 -0
- package/dist/stationProofView.d.ts +9 -0
- package/dist/stationProofView.d.ts.map +1 -0
- package/dist/stationProofView.js +186 -0
- package/dist/stationProofView.js.map +1 -0
- package/dist/trustAnchorData.d.ts +40 -0
- package/dist/trustAnchorData.d.ts.map +1 -0
- package/dist/trustAnchorData.js +91 -0
- package/dist/trustAnchorData.js.map +1 -0
- package/dist/trustAnchorDataView.d.ts +13 -0
- package/dist/trustAnchorDataView.d.ts.map +1 -0
- package/dist/trustAnchorDataView.js +69 -0
- package/dist/trustAnchorDataView.js.map +1 -0
- package/dist/trustAnchorImport.d.ts +5 -0
- package/dist/trustAnchorImport.d.ts.map +1 -0
- package/dist/trustAnchorImport.js +34 -0
- package/dist/trustAnchorImport.js.map +1 -0
- package/dist/trustAnchorPreview.d.ts +37 -0
- package/dist/trustAnchorPreview.d.ts.map +1 -0
- package/dist/trustAnchorPreview.js +180 -0
- package/dist/trustAnchorPreview.js.map +1 -0
- package/dist/trustManagement.d.ts +34 -0
- package/dist/trustManagement.d.ts.map +1 -0
- package/dist/trustManagement.js +405 -0
- package/dist/trustManagement.js.map +1 -0
- package/dist/trustStore.d.ts +75 -0
- package/dist/trustStore.d.ts.map +1 -0
- package/dist/trustStore.js +408 -0
- package/dist/trustStore.js.map +1 -0
- package/dist/trustTransitionView.d.ts +5 -0
- package/dist/trustTransitionView.d.ts.map +1 -0
- package/dist/trustTransitionView.js +110 -0
- package/dist/trustTransitionView.js.map +1 -0
- package/dist/trustedPublicKeys.d.ts +4 -0
- package/dist/trustedPublicKeys.d.ts.map +1 -0
- package/dist/trustedPublicKeys.js +25 -0
- package/dist/trustedPublicKeys.js.map +1 -0
- package/dist/wwcpPoi.d.ts +2 -0
- package/dist/wwcpPoi.d.ts.map +1 -0
- package/dist/wwcpPoi.js +2 -0
- package/dist/wwcpPoi.js.map +1 -0
- package/documentation/AUDIT.md +262 -0
- package/images/NGI0_tag.svg +149 -0
- package/package.json +75 -4
package/README.md
CHANGED
|
@@ -1,3 +1,49 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Chargy GUI - TypeScript
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/OpenChargingCloud/ChargyGUI.TS/actions/workflows/ci.yml)
|
|
4
|
+
[](https://github.com/OpenChargingCloud/ChargyGUI.TS/actions/workflows/nightly.yml)
|
|
5
|
+
[](documentation/AUDIT.md)
|
|
6
|
+
|
|
7
|
+
Shared HTML/DOM presentation, WWCP-POI trust & verification UI components for the Chargy Transparency Software family (**ChargyWebApp**, **ChargyDesktopApp**, **ChargyMobileApp**).
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## Software Separation (WELMEC 7.2 / PTB-A 50.7)
|
|
11
|
+
|
|
12
|
+
`ChargyGUI.TS` establishes a strict three-layer architectural boundary:
|
|
13
|
+
|
|
14
|
+
1. [**`@open-charging-cloud/chargy-core`**](https://github.com/OpenChargingCloud/ChargyCore.TS) – 100% DOM- and HTML-free metrological parsing, signature verification (`@noble/curves`, `@noble/hashes`, `@noble/post-quantum`, strict ASN.1 DER), and structured verification detail models (`IMeasurementDetailModel`).
|
|
15
|
+
2. **`@open-charging-cloud/chargy-gui`** – Safe, XSS-free DOM rendering & shared UI/trust layer:
|
|
16
|
+
- Measurement details renderer (`renderMeasurementDetails`, `renderMeasurementValueDetails`)
|
|
17
|
+
- Safe DOM helpers (`domHelpers`) & session UI registry (`SessionElementRegistry`)
|
|
18
|
+
- Visual fingerprints (`securityFingerprint`, `securityFingerprintView`)
|
|
19
|
+
- Shared WWCP-POI verification, trust store, anchor/witness management, live POI session, station proof, historical evidence, price publication & UI panels (`sessionPOIPanel`, `stationProofPanel`, `trustAnchorDataView`, `historicalSessionPanel`, `sessionPricePanel`, `trustManagement`, `livePOISession`, `poiTrustContext`, `poiTransport`, etc.)
|
|
20
|
+
- Re-exports `@open-charging-cloud/chargy-core`, `./i18n.json`, `./validationRules.json`, `./core/package.json`, and `./wwcp-poi` (single-instance `@open-charging-cloud/wwcp-poi`).
|
|
21
|
+
3. **Platform Shells (`ChargyWebApp`, `ChargyDesktopApp`, `ChargyMobileApp`)** – Thin platform adapters for Browser, Electron (injecting `setDefaultPOIFetch(poiFetch)`), and Cordova.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## Scripts
|
|
25
|
+
|
|
26
|
+
- `npm run typecheck` – strict TypeScript check (`exactOptionalPropertyTypes`, `noUncheckedIndexedAccess`)
|
|
27
|
+
- `npm run lint` – strict type-checked ESLint (`--max-warnings=0`)
|
|
28
|
+
- `npm test` – Vitest suite (including XSS, SSRF, and integrity audit checks)
|
|
29
|
+
- `npm run build` – compile ESM + `.d.ts` into `dist/` and sync core JSON assets
|
|
30
|
+
- `npm run verify` – run all checks above
|
|
31
|
+
- `npm run verify:reproducible` – run two clean builds, assert byte-for-byte reproducibility, and write `artifacts/SHA256SUMS.txt`, `artifacts/SHA512SUMS.txt`, and `artifacts/build-manifest.json`
|
|
32
|
+
- `npm run checksums` – generate SHA-256/SHA-512 checksum manifests for the current build
|
|
33
|
+
- `npm run sbom` – generate deterministic CycloneDX 1.6 (`artifacts/sbom.cdx.json`) and SPDX 2.3 (`artifacts/sbom.spdx.json`) SBOMs
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
## Audit & Compliance Documentation
|
|
37
|
+
|
|
38
|
+
See [documentation/AUDIT.md](documentation/AUDIT.md) for the PTB (EU MID / WELMEC 7.2 / PTB-A 50.7) and EU CRA audit guide, including architectural layer separation, traceability matrix, cryptography inventory, SBOM generation, and reproducible build verification.
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## Funding
|
|
42
|
+
|
|
43
|
+
This Open Source project is partially funded by the [NGI Zero Commons Fund](https://nlnet.nl/commonsfund/) as part of our [EVQI project](https://nlnet.nl/project/EVQI/).
|
|
44
|
+
|
|
45
|
+
We also appreciate any additional funding and long-term support for the Chargy family, for example via [GitHub Sponsors](https://github.com/sponsors/GraphDefined), as it helps us keep the project sustainable, independent and useful for the entire e-mobility community.
|
|
46
|
+
|
|
47
|
+
<center>
|
|
48
|
+
<img src="images/NGI0_tag.svg" height="30">
|
|
49
|
+
</center>
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
The following document gives you an overview of the security policy of the ChargyGUI library (`@open-charging-cloud/chargy-gui`).
|
|
4
|
+
|
|
5
|
+
## Supported Versions
|
|
6
|
+
|
|
7
|
+
The following versions are actively supported for security updates:
|
|
8
|
+
|
|
9
|
+
| Version | Supported |
|
|
10
|
+
| ------- | ------------------ |
|
|
11
|
+
| 0.1.x | :white_check_mark: |
|
|
12
|
+
|
|
13
|
+
## Reporting a Vulnerability
|
|
14
|
+
|
|
15
|
+
Please **do not** report security vulnerabilities through public GitHub issues.
|
|
16
|
+
|
|
17
|
+
Instead, please use GitHub's private vulnerability reporting ("Report a vulnerability" in the Security tab of this repository) or send an encrypted report via email to `info@graphdefined.com` (PGP Key ID `0xC6CBE6A4`, Fingerprint `3CD0 09F4 0008 616A 91D0 7646 2DD3 B48B C6CB E6A4`).
|
|
18
|
+
|
|
19
|
+
Please include as much detail as possible to help reproduce and assess the issue (affected component, minimal input sample, expected vs. actual behavior).
|
|
20
|
+
|
|
21
|
+
Vulnerabilities will be fixed as soon as possible, but remember that the transparency software built on this library has to be certified by German regulators (e.g. PTB) to remain a lawful software under the German calibration law (*Eichrecht*). Release and certification cycles can take days, weeks, or months.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TrustAnchor } from '@open-charging-cloud/wwcp-poi';
|
|
2
|
+
import type { POIPublicKey } from '@open-charging-cloud/wwcp-poi';
|
|
3
|
+
import type { StoredTrustAnchor } from './trustStore.js';
|
|
4
|
+
export type AnchorKeyTrustState = "bundled" | "manual" | "unknown" | "deleted" | "expired";
|
|
5
|
+
/** Trust is scoped to the complete anchor policy, including holder grouping and quorum. */
|
|
6
|
+
export declare function anchorKeyTrustState(anchor: TrustAnchor, keyId: string, record: StoredTrustAnchor | undefined, bundled: readonly POIPublicKey[], deleted: ReadonlySet<string>, at?: number): AnchorKeyTrustState;
|
|
7
|
+
/** App-owned authorization input for the library's TrustContext; no signature or quorum verdict. */
|
|
8
|
+
export declare function trustedAnchorHolders(anchor: TrustAnchor, record: StoredTrustAnchor | undefined, bundled: readonly POIPublicKey[], deleted: ReadonlySet<string>, at?: number): readonly (readonly string[])[];
|
|
9
|
+
//# sourceMappingURL=anchorKeyTrust.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anchorKeyTrust.d.ts","sourceRoot":"","sources":["../src/anchorKeyTrust.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAElE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAE3F,2FAA2F;AAC3F,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,GAAG,SAAS,EACzE,OAAO,EAAE,SAAS,YAAY,EAAE,EAAE,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,EAC9D,EAAE,GAAE,MAAmB,GAAG,mBAAmB,CAYhF;AAED,oGAAoG;AACpG,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,iBAAiB,GAAG,SAAS,EACzD,OAAO,EAAE,SAAS,YAAY,EAAE,EAAE,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,EAC9D,EAAE,GAAE,MAAmB,GAAG,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAK7F"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TrustAnchor } from '@open-charging-cloud/wwcp-poi';
|
|
2
|
+
import { trustAnchorStorageId } from './trustStore.js';
|
|
3
|
+
/** Trust is scoped to the complete anchor policy, including holder grouping and quorum. */
|
|
4
|
+
export function anchorKeyTrustState(anchor, keyId, record, bundled, deleted, at = Date.now()) {
|
|
5
|
+
if (!anchor.keys.includes(keyId))
|
|
6
|
+
return "unknown";
|
|
7
|
+
const known = bundled.find(key => key.id === keyId);
|
|
8
|
+
if (known !== undefined && !known.isValidAt(at))
|
|
9
|
+
return "expired";
|
|
10
|
+
if (known !== undefined && !deleted.has(keyId))
|
|
11
|
+
return "bundled";
|
|
12
|
+
if (record?.id === trustAnchorStorageId(anchor) &&
|
|
13
|
+
trustAnchorStorageId(TrustAnchor.parse(record.qrCode)) === record.id && record.trustedKeys?.some(key => key.id === keyId) === true)
|
|
14
|
+
return "manual";
|
|
15
|
+
return deleted.has(keyId) ? "deleted" : "unknown";
|
|
16
|
+
}
|
|
17
|
+
/** App-owned authorization input for the library's TrustContext; no signature or quorum verdict. */
|
|
18
|
+
export function trustedAnchorHolders(anchor, record, bundled, deleted, at = Date.now()) {
|
|
19
|
+
return anchor.holders.map(holder => holder.filter(id => {
|
|
20
|
+
const state = anchorKeyTrustState(anchor, id, record, bundled, deleted, at);
|
|
21
|
+
return state === "bundled" || state === "manual";
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=anchorKeyTrust.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anchorKeyTrust.js","sourceRoot":"","sources":["../src/anchorKeyTrust.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAE5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAKvD,2FAA2F;AAC3F,MAAM,UAAU,mBAAmB,CAAC,MAAmB,EAAE,KAAa,EAAE,MAAqC,EACzE,OAAgC,EAAE,OAA4B,EAC9D,KAAa,IAAI,C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,SAAS,IAAI,KAAK,KAAK,QAAQ,CAAC;IACrD,CAAC,CAAC,CAAC,CAAC;AACR,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { POIPublicKey, TrustAnchor } from '@open-charging-cloud/wwcp-poi';
|
|
2
|
+
import type { StoredTrustAnchor } from './trustStore.js';
|
|
3
|
+
export interface AnchorKeyTrustOptions {
|
|
4
|
+
readonly record?: StoredTrustAnchor | undefined;
|
|
5
|
+
readonly bundled: readonly POIPublicKey[];
|
|
6
|
+
readonly deleted: ReadonlySet<string>;
|
|
7
|
+
readonly localize: (key: string) => string;
|
|
8
|
+
readonly onChange: (keyId: string, trusted: boolean) => Promise<void>;
|
|
9
|
+
readonly loadedKeys?: readonly POIPublicKey[];
|
|
10
|
+
readonly allowChanges?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** An optional decision after loading and verifying the actual key material. */
|
|
13
|
+
export declare function renderAnchorKeyTrust(anchor: TrustAnchor, options: AnchorKeyTrustOptions): HTMLElement;
|
|
14
|
+
//# sourceMappingURL=anchorKeyTrustView.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anchorKeyTrustView.d.ts","sourceRoot":"","sources":["../src/anchorKeyTrustView.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAE/E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAIzD,MAAM,WAAW,qBAAqB;IAClC,QAAQ,CAAC,MAAM,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAChD,QAAQ,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,CAAC;IAC1C,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACtC,QAAQ,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IAC3C,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACtE,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;IAC9C,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC;CACnC;AAED,gFAAgF;AAChF,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,qBAAqB,GAAG,WAAW,CA2FrG"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { anchorKeyTrustState } from './anchorKeyTrust.js';
|
|
2
|
+
import { toBase64 } from '@open-charging-cloud/wwcp-poi';
|
|
3
|
+
import { renderSecurityFingerprint } from './securityFingerprintView.js';
|
|
4
|
+
/** An optional decision after loading and verifying the actual key material. */
|
|
5
|
+
export function renderAnchorKeyTrust(anchor, options) {
|
|
6
|
+
const root = document.createElement("section");
|
|
7
|
+
root.className = "anchorKeyTrust";
|
|
8
|
+
const text = (parent, value, className = "") => {
|
|
9
|
+
const element = parent.appendChild(document.createElement("p"));
|
|
10
|
+
element.textContent = value;
|
|
11
|
+
element.className = className;
|
|
12
|
+
return element;
|
|
13
|
+
};
|
|
14
|
+
const button = (parent, label, action) => {
|
|
15
|
+
const element = parent.appendChild(document.createElement("button"));
|
|
16
|
+
element.type = "button";
|
|
17
|
+
element.textContent = options.localize(label);
|
|
18
|
+
element.onclick = action;
|
|
19
|
+
return element;
|
|
20
|
+
};
|
|
21
|
+
const heading = root.appendChild(document.createElement("h3"));
|
|
22
|
+
heading.textContent = options.localize("trustManualTitle");
|
|
23
|
+
text(root, options.localize(options.record === undefined ? "trustManualImportFirst" : "trustManualDescription"));
|
|
24
|
+
const change = async (parent, keyId, trusted) => {
|
|
25
|
+
const controls = [...root.querySelectorAll("button")];
|
|
26
|
+
for (const control of controls)
|
|
27
|
+
control.disabled = true;
|
|
28
|
+
parent.querySelector("[role=alert]")?.remove();
|
|
29
|
+
try {
|
|
30
|
+
await options.onChange(keyId, trusted);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
const error = text(parent, options.localize("trustStorageError"), "trustManagementError");
|
|
34
|
+
error.setAttribute("role", "alert");
|
|
35
|
+
for (const control of controls)
|
|
36
|
+
control.disabled = false;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
for (const [index, holder] of anchor.holders.entries()) {
|
|
40
|
+
const group = root.appendChild(document.createElement("div"));
|
|
41
|
+
group.className = "trustAnchorHolder";
|
|
42
|
+
text(group, `${options.localize("trustAnchorHolderLabel")} ${index + 1}`);
|
|
43
|
+
for (const id of holder) {
|
|
44
|
+
const row = group.appendChild(document.createElement("div"));
|
|
45
|
+
row.className = "anchorKeyTrustKey";
|
|
46
|
+
row.dataset["keyId"] = id;
|
|
47
|
+
row.appendChild(renderSecurityFingerprint(id, options.localize));
|
|
48
|
+
const content = row.appendChild(document.createElement("div"));
|
|
49
|
+
content.className = "anchorKeyTrustContent";
|
|
50
|
+
const state = anchorKeyTrustState(anchor, id, options.record, options.bundled, options.deleted);
|
|
51
|
+
const labels = { bundled: "trustNetworkKeyTrusted", manual: "trustManualAccepted", unknown: "trustNetworkKeyUnknown",
|
|
52
|
+
deleted: "trustNetworkKeyDeleted", expired: "trustNetworkKeyExpired" };
|
|
53
|
+
const status = text(content, options.localize(labels[state]), "trustNetworkKeyStatus");
|
|
54
|
+
status.dataset["keyTrust"] = state;
|
|
55
|
+
const material = options.loadedKeys?.find(key => key.id === id);
|
|
56
|
+
if (material !== undefined) {
|
|
57
|
+
const details = content.appendChild(document.createElement("details"));
|
|
58
|
+
const summary = details.appendChild(document.createElement("summary"));
|
|
59
|
+
summary.textContent = options.localize("publicKeyLabel");
|
|
60
|
+
if (material.holder !== undefined)
|
|
61
|
+
text(details, material.holder);
|
|
62
|
+
text(details, toBase64(material.keyBytes), "trustManagementIdentifier trustAnchorMonospace");
|
|
63
|
+
}
|
|
64
|
+
const decision = options.record?.trustedKeys?.find(key => key.id === id);
|
|
65
|
+
if (decision !== undefined) {
|
|
66
|
+
text(content, `${options.localize("trustManualAcceptedAt")}: ${decision.acceptedAt}`);
|
|
67
|
+
const revoke = button(content, "trustManualRevoke", () => { void change(content, id, false); });
|
|
68
|
+
revoke.dataset["action"] = "revoke-key";
|
|
69
|
+
}
|
|
70
|
+
else if (options.record !== undefined && options.allowChanges === true && material !== undefined && state !== "bundled" && state !== "expired") {
|
|
71
|
+
const accept = button(content, "trustManualStart", () => {
|
|
72
|
+
accept.hidden = true;
|
|
73
|
+
const confirmation = content.appendChild(document.createElement("section"));
|
|
74
|
+
confirmation.className = "trustManualConfirmation";
|
|
75
|
+
const explanation = text(confirmation, options.localize("trustManualConfirmDescription"));
|
|
76
|
+
explanation.tabIndex = -1;
|
|
77
|
+
if (state === "deleted")
|
|
78
|
+
text(confirmation, options.localize("trustManualDeletedKeyNote"));
|
|
79
|
+
text(confirmation, `${options.localize("trustAnchorNetworkLabel")}: ${anchor.id}`);
|
|
80
|
+
text(confirmation, `${options.localize("trustAnchorHolderLabel")} ${index + 1} · ${options.localize("trustAnchorQuorumLabel")}: ${anchor.minConsensus} / ${anchor.holders.length}`);
|
|
81
|
+
for (const url of anchor.urls)
|
|
82
|
+
text(confirmation, url, "trustManagementIdentifier");
|
|
83
|
+
confirmation.appendChild(renderSecurityFingerprint(id, options.localize));
|
|
84
|
+
const confirm = button(confirmation, "trustManualConfirm", () => { void change(confirmation, id, true); });
|
|
85
|
+
confirm.dataset["action"] = "confirm-key";
|
|
86
|
+
button(confirmation, "trustManualCancel", () => { confirmation.remove(); accept.hidden = false; accept.focus(); });
|
|
87
|
+
explanation.focus();
|
|
88
|
+
});
|
|
89
|
+
accept.dataset["action"] = "accept-key";
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return root;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=anchorKeyTrustView.js.map
|
|
@@ -0,0 +1 @@
|
|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CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,aAAa,CAAC;oBAC1C,MAAM,CAAC,YAAY,EAAE,mBAAmB,EAAE,GAAG,EAAE,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;oBACnH,WAAW,CAAC,KAAK,EAAE,CAAC;gBACxB,CAAC,CAAC,CAAC;gBACH,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,YAAY,CAAC;YAC5C,CAAC;QACL,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function browserFileTypeFromName(fileName: string, fileType: string): string;
|
|
2
|
+
export declare function browserFileTypeFromNameOrData(fileName: string, fileType: string, data: ArrayBuffer | Uint8Array): string;
|
|
3
|
+
export declare function browserFileNameFromNameAndType(fileName: string, fileType: string): string;
|
|
4
|
+
export declare function normalizeDroppedSVGImageData(fileName: string, fileType: string, data: ArrayBuffer): ArrayBuffer | Uint8Array;
|
|
5
|
+
//# sourceMappingURL=browserFiles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browserFiles.d.ts","sourceRoot":"","sources":["../src/browserFiles.ts"],"names":[],"mappings":"AAAA,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GAAG,MAAM,CA6BhE;AAWD,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAM,WAAW,GAAC,UAAU,GAAG,MAAM,CAYtF;AAED,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GAAG,MAAM,CAYvE;AAsBD,wBAAgB,4BAA4B,CAAC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAM,WAAW,GAAG,WAAW,GAAC,UAAU,CAyE1F"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
export function browserFileTypeFromName(fileName, fileType) {
|
|
2
|
+
const trimmedFileType = fileType.trim();
|
|
3
|
+
if (trimmedFileType !== "")
|
|
4
|
+
return trimmedFileType;
|
|
5
|
+
const lowerFileName = fileName.toLowerCase();
|
|
6
|
+
if (lowerFileName.endsWith(".svg"))
|
|
7
|
+
return "image/svg+xml";
|
|
8
|
+
if (lowerFileName.endsWith(".png"))
|
|
9
|
+
return "image/png";
|
|
10
|
+
if (lowerFileName.endsWith(".jpg") || lowerFileName.endsWith(".jpeg"))
|
|
11
|
+
return "image/jpeg";
|
|
12
|
+
if (lowerFileName.endsWith(".gif"))
|
|
13
|
+
return "image/gif";
|
|
14
|
+
if (lowerFileName.endsWith(".webp"))
|
|
15
|
+
return "image/webp";
|
|
16
|
+
if (lowerFileName.endsWith(".bmp"))
|
|
17
|
+
return "image/bmp";
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
20
|
+
function isSVGImageData(data) {
|
|
21
|
+
const svgText = new TextDecoder().decode(data).trimStart();
|
|
22
|
+
return svgText.startsWith("<svg") ||
|
|
23
|
+
(svgText.startsWith("<?xml") && /<svg\b/i.test(svgText));
|
|
24
|
+
}
|
|
25
|
+
export function browserFileTypeFromNameOrData(fileName, fileType, data) {
|
|
26
|
+
const detectedFileType = browserFileTypeFromName(fileName, fileType);
|
|
27
|
+
if (detectedFileType !== "")
|
|
28
|
+
return detectedFileType;
|
|
29
|
+
if (isSVGImageData(data))
|
|
30
|
+
return "image/svg+xml";
|
|
31
|
+
return "";
|
|
32
|
+
}
|
|
33
|
+
export function browserFileNameFromNameAndType(fileName, fileType) {
|
|
34
|
+
const trimmedFileName = fileName.trim() !== ""
|
|
35
|
+
? fileName.trim()
|
|
36
|
+
: "unknown";
|
|
37
|
+
const lowerFileName = trimmedFileName.toLowerCase();
|
|
38
|
+
if (fileType === "image/svg+xml" && !lowerFileName.endsWith(".svg"))
|
|
39
|
+
return trimmedFileName + ".svg";
|
|
40
|
+
return trimmedFileName;
|
|
41
|
+
}
|
|
42
|
+
function addCrispShapeRenderingToSVGElements(svgText) {
|
|
43
|
+
let changed = false;
|
|
44
|
+
const text = svgText.replace(/<(path|rect)\b([^>]*)>/gi, (match, tagName, attributes) => {
|
|
45
|
+
if (/\sshape-rendering\s*=/.test(attributes))
|
|
46
|
+
return match;
|
|
47
|
+
changed = true;
|
|
48
|
+
return "<" + tagName + " shape-rendering=\"crispEdges\"" + attributes + ">";
|
|
49
|
+
});
|
|
50
|
+
return { text, changed };
|
|
51
|
+
}
|
|
52
|
+
export function normalizeDroppedSVGImageData(fileName, fileType, data) {
|
|
53
|
+
const lowerFileName = fileName.toLowerCase();
|
|
54
|
+
if (fileType !== "image/svg+xml" && !lowerFileName.endsWith(".svg") && !isSVGImageData(data))
|
|
55
|
+
return data;
|
|
56
|
+
const svgText = new TextDecoder().decode(data);
|
|
57
|
+
if (!svgText.trimStart().startsWith("<svg") &&
|
|
58
|
+
!svgText.trimStart().startsWith("<?xml")) {
|
|
59
|
+
return data;
|
|
60
|
+
}
|
|
61
|
+
const svgTagMatch = svgText.match(/<svg\b[^>]*>/i);
|
|
62
|
+
if (svgTagMatch == null)
|
|
63
|
+
return data;
|
|
64
|
+
const svgTag = svgTagMatch[0];
|
|
65
|
+
const svgTagIndex = svgTagMatch.index;
|
|
66
|
+
if (svgTagIndex == null)
|
|
67
|
+
return data;
|
|
68
|
+
let svgAttributes = "";
|
|
69
|
+
if (!/\sshape-rendering\s*=/.test(svgTag))
|
|
70
|
+
svgAttributes += " shape-rendering=\"crispEdges\"";
|
|
71
|
+
if (!/\sstyle\s*=/.test(svgTag))
|
|
72
|
+
svgAttributes += " style=\"image-rendering: pixelated\"";
|
|
73
|
+
const hasWidth = /\swidth\s*=/.test(svgTag);
|
|
74
|
+
const hasHeight = /\sheight\s*=/.test(svgTag);
|
|
75
|
+
const crispElements = addCrispShapeRenderingToSVGElements(svgText);
|
|
76
|
+
if (hasWidth && hasHeight && svgAttributes === "" && !crispElements.changed)
|
|
77
|
+
return data;
|
|
78
|
+
if (!hasWidth || !hasHeight) {
|
|
79
|
+
const viewBoxMatch = svgTag.match(/\sviewBox\s*=\s*["']\s*([0-9.+-]+)\s+([0-9.+-]+)\s+([0-9.+-]+)\s+([0-9.+-]+)\s*["']/i);
|
|
80
|
+
if (viewBoxMatch != null) {
|
|
81
|
+
const width = Number(viewBoxMatch[3]);
|
|
82
|
+
const height = Number(viewBoxMatch[4]);
|
|
83
|
+
if (Number.isFinite(width) && width > 0 &&
|
|
84
|
+
Number.isFinite(height) && height > 0) {
|
|
85
|
+
if (!hasWidth)
|
|
86
|
+
svgAttributes += " width=\"" + width.toString() + "\"";
|
|
87
|
+
if (!hasHeight)
|
|
88
|
+
svgAttributes += " height=\"" + height.toString() + "\"";
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (svgAttributes === "" && !crispElements.changed)
|
|
93
|
+
return data;
|
|
94
|
+
const normalizedSVGText = crispElements.text;
|
|
95
|
+
const normalized = normalizedSVGText.slice(0, svgTagIndex + svgTag.length - 1) +
|
|
96
|
+
svgAttributes +
|
|
97
|
+
normalizedSVGText.slice(svgTagIndex + svgTag.length - 1);
|
|
98
|
+
return new TextEncoder().encode(normalized);
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=browserFiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browserFiles.js","sourceRoot":"","sources":["../src/browserFiles.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,uBAAuB,CAAC,QAAgB,EAChB,QAAgB;IAEpD,MAAM,eAAe,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;IAExC,IAAI,eAAe,KAAK,EAAE;QACtB,OAAO,eAAe,CAAC;IAE3B,MAAM,aAAa,GAAG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