@open-charging-cloud/chargy-gui 0.0.0-stage → 0.1.1

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.
Files changed (170) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/LICENSE +661 -0
  3. package/README.md +48 -2
  4. package/SECURITY.md +21 -0
  5. package/dist/anchorKeyTrust.d.ts +9 -0
  6. package/dist/anchorKeyTrust.d.ts.map +1 -0
  7. package/dist/anchorKeyTrust.js +24 -0
  8. package/dist/anchorKeyTrust.js.map +1 -0
  9. package/dist/anchorKeyTrustView.d.ts +14 -0
  10. package/dist/anchorKeyTrustView.d.ts.map +1 -0
  11. package/dist/anchorKeyTrustView.js +95 -0
  12. package/dist/anchorKeyTrustView.js.map +1 -0
  13. package/dist/browserFiles.d.ts +5 -0
  14. package/dist/browserFiles.d.ts.map +1 -0
  15. package/dist/browserFiles.js +100 -0
  16. package/dist/browserFiles.js.map +1 -0
  17. package/dist/core/i18n.json +1518 -0
  18. package/dist/core/package.json +119 -0
  19. package/dist/core/validationRules.json +8 -0
  20. package/dist/domHelpers.d.ts +25 -0
  21. package/dist/domHelpers.d.ts.map +1 -0
  22. package/dist/domHelpers.js +212 -0
  23. package/dist/domHelpers.js.map +1 -0
  24. package/dist/historicalSessionPanel.d.ts +24 -0
  25. package/dist/historicalSessionPanel.d.ts.map +1 -0
  26. package/dist/historicalSessionPanel.js +108 -0
  27. package/dist/historicalSessionPanel.js.map +1 -0
  28. package/dist/index.d.ts +40 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +56 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/liveLinkTrust.d.ts +208 -0
  33. package/dist/liveLinkTrust.d.ts.map +1 -0
  34. package/dist/liveLinkTrust.js +452 -0
  35. package/dist/liveLinkTrust.js.map +1 -0
  36. package/dist/livePOISession.d.ts +38 -0
  37. package/dist/livePOISession.d.ts.map +1 -0
  38. package/dist/livePOISession.js +193 -0
  39. package/dist/livePOISession.js.map +1 -0
  40. package/dist/measurementDetailsRenderer.d.ts +25 -0
  41. package/dist/measurementDetailsRenderer.d.ts.map +1 -0
  42. package/dist/measurementDetailsRenderer.js +343 -0
  43. package/dist/measurementDetailsRenderer.js.map +1 -0
  44. package/dist/poiConsistencyView.d.ts +3 -0
  45. package/dist/poiConsistencyView.d.ts.map +1 -0
  46. package/dist/poiConsistencyView.js +14 -0
  47. package/dist/poiConsistencyView.js.map +1 -0
  48. package/dist/poiObservedHistory.d.ts +49 -0
  49. package/dist/poiObservedHistory.d.ts.map +1 -0
  50. package/dist/poiObservedHistory.js +205 -0
  51. package/dist/poiObservedHistory.js.map +1 -0
  52. package/dist/poiTransport.d.ts +12 -0
  53. package/dist/poiTransport.d.ts.map +1 -0
  54. package/dist/poiTransport.js +74 -0
  55. package/dist/poiTransport.js.map +1 -0
  56. package/dist/poiTrustContext.d.ts +134 -0
  57. package/dist/poiTrustContext.d.ts.map +1 -0
  58. package/dist/poiTrustContext.js +243 -0
  59. package/dist/poiTrustContext.js.map +1 -0
  60. package/dist/poiTrustLineage.d.ts +10 -0
  61. package/dist/poiTrustLineage.d.ts.map +1 -0
  62. package/dist/poiTrustLineage.js +47 -0
  63. package/dist/poiTrustLineage.js.map +1 -0
  64. package/dist/poiURLs.d.ts +5 -0
  65. package/dist/poiURLs.d.ts.map +1 -0
  66. package/dist/poiURLs.js +24 -0
  67. package/dist/poiURLs.js.map +1 -0
  68. package/dist/poiWitnessManagement.d.ts +3 -0
  69. package/dist/poiWitnessManagement.d.ts.map +1 -0
  70. package/dist/poiWitnessManagement.js +127 -0
  71. package/dist/poiWitnessManagement.js.map +1 -0
  72. package/dist/poiWitnessTrust.d.ts +26 -0
  73. package/dist/poiWitnessTrust.d.ts.map +1 -0
  74. package/dist/poiWitnessTrust.js +90 -0
  75. package/dist/poiWitnessTrust.js.map +1 -0
  76. package/dist/pricePublicationData.d.ts +19 -0
  77. package/dist/pricePublicationData.d.ts.map +1 -0
  78. package/dist/pricePublicationData.js +83 -0
  79. package/dist/pricePublicationData.js.map +1 -0
  80. package/dist/roamingNetworks.d.ts +14 -0
  81. package/dist/roamingNetworks.d.ts.map +1 -0
  82. package/dist/roamingNetworks.js +33 -0
  83. package/dist/roamingNetworks.js.map +1 -0
  84. package/dist/securityFingerprint.d.ts +16 -0
  85. package/dist/securityFingerprint.d.ts.map +1 -0
  86. package/dist/securityFingerprint.js +36 -0
  87. package/dist/securityFingerprint.js.map +1 -0
  88. package/dist/securityFingerprintView.d.ts +3 -0
  89. package/dist/securityFingerprintView.d.ts.map +1 -0
  90. package/dist/securityFingerprintView.js +61 -0
  91. package/dist/securityFingerprintView.js.map +1 -0
  92. package/dist/sessionEvidenceStore.d.ts +23 -0
  93. package/dist/sessionEvidenceStore.d.ts.map +1 -0
  94. package/dist/sessionEvidenceStore.js +81 -0
  95. package/dist/sessionEvidenceStore.js.map +1 -0
  96. package/dist/sessionMeterKeyView.d.ts +9 -0
  97. package/dist/sessionMeterKeyView.d.ts.map +1 -0
  98. package/dist/sessionMeterKeyView.js +55 -0
  99. package/dist/sessionMeterKeyView.js.map +1 -0
  100. package/dist/sessionPOIData.d.ts +49 -0
  101. package/dist/sessionPOIData.d.ts.map +1 -0
  102. package/dist/sessionPOIData.js +161 -0
  103. package/dist/sessionPOIData.js.map +1 -0
  104. package/dist/sessionPOIPanel.d.ts +50 -0
  105. package/dist/sessionPOIPanel.d.ts.map +1 -0
  106. package/dist/sessionPOIPanel.js +288 -0
  107. package/dist/sessionPOIPanel.js.map +1 -0
  108. package/dist/sessionPriceData.d.ts +17 -0
  109. package/dist/sessionPriceData.d.ts.map +1 -0
  110. package/dist/sessionPriceData.js +51 -0
  111. package/dist/sessionPriceData.js.map +1 -0
  112. package/dist/sessionPricePanel.d.ts +31 -0
  113. package/dist/sessionPricePanel.d.ts.map +1 -0
  114. package/dist/sessionPricePanel.js +222 -0
  115. package/dist/sessionPricePanel.js.map +1 -0
  116. package/dist/sessionUIState.d.ts +12 -0
  117. package/dist/sessionUIState.d.ts.map +1 -0
  118. package/dist/sessionUIState.js +33 -0
  119. package/dist/sessionUIState.js.map +1 -0
  120. package/dist/stationProofData.d.ts +38 -0
  121. package/dist/stationProofData.d.ts.map +1 -0
  122. package/dist/stationProofData.js +83 -0
  123. package/dist/stationProofData.js.map +1 -0
  124. package/dist/stationProofPanel.d.ts +44 -0
  125. package/dist/stationProofPanel.d.ts.map +1 -0
  126. package/dist/stationProofPanel.js +304 -0
  127. package/dist/stationProofPanel.js.map +1 -0
  128. package/dist/stationProofView.d.ts +9 -0
  129. package/dist/stationProofView.d.ts.map +1 -0
  130. package/dist/stationProofView.js +186 -0
  131. package/dist/stationProofView.js.map +1 -0
  132. package/dist/trustAnchorData.d.ts +40 -0
  133. package/dist/trustAnchorData.d.ts.map +1 -0
  134. package/dist/trustAnchorData.js +91 -0
  135. package/dist/trustAnchorData.js.map +1 -0
  136. package/dist/trustAnchorDataView.d.ts +13 -0
  137. package/dist/trustAnchorDataView.d.ts.map +1 -0
  138. package/dist/trustAnchorDataView.js +69 -0
  139. package/dist/trustAnchorDataView.js.map +1 -0
  140. package/dist/trustAnchorImport.d.ts +5 -0
  141. package/dist/trustAnchorImport.d.ts.map +1 -0
  142. package/dist/trustAnchorImport.js +34 -0
  143. package/dist/trustAnchorImport.js.map +1 -0
  144. package/dist/trustAnchorPreview.d.ts +37 -0
  145. package/dist/trustAnchorPreview.d.ts.map +1 -0
  146. package/dist/trustAnchorPreview.js +180 -0
  147. package/dist/trustAnchorPreview.js.map +1 -0
  148. package/dist/trustManagement.d.ts +34 -0
  149. package/dist/trustManagement.d.ts.map +1 -0
  150. package/dist/trustManagement.js +405 -0
  151. package/dist/trustManagement.js.map +1 -0
  152. package/dist/trustStore.d.ts +75 -0
  153. package/dist/trustStore.d.ts.map +1 -0
  154. package/dist/trustStore.js +408 -0
  155. package/dist/trustStore.js.map +1 -0
  156. package/dist/trustTransitionView.d.ts +5 -0
  157. package/dist/trustTransitionView.d.ts.map +1 -0
  158. package/dist/trustTransitionView.js +110 -0
  159. package/dist/trustTransitionView.js.map +1 -0
  160. package/dist/trustedPublicKeys.d.ts +4 -0
  161. package/dist/trustedPublicKeys.d.ts.map +1 -0
  162. package/dist/trustedPublicKeys.js +25 -0
  163. package/dist/trustedPublicKeys.js.map +1 -0
  164. package/dist/wwcpPoi.d.ts +2 -0
  165. package/dist/wwcpPoi.d.ts.map +1 -0
  166. package/dist/wwcpPoi.js +2 -0
  167. package/dist/wwcpPoi.js.map +1 -0
  168. package/documentation/AUDIT.md +262 -0
  169. package/images/NGI0_tag.svg +149 -0
  170. package/package.json +75 -4
@@ -0,0 +1,40 @@
1
+ import { KeyStatement, POIPublicKey } from '@open-charging-cloud/wwcp-poi';
2
+ import type { TrustAnchor } from '@open-charging-cloud/wwcp-poi';
3
+ import type { StoredTrustAnchor } from './trustStore.js';
4
+ import type { TrustAnchorValidation } from './trustAnchorPreview.js';
5
+ import type { ITransportAllowances } from './liveLinkTrust.js';
6
+ export interface StoredTrustAnchorData {
7
+ readonly origin?: 'embedded';
8
+ readonly sourceURL: string;
9
+ readonly downloadedAt: string;
10
+ /** Original signed JSON, parsed with WWCP's parser again whenever it is used. */
11
+ readonly text: string;
12
+ }
13
+ export interface LoadedTrustAnchorData {
14
+ readonly document: StoredTrustAnchorData;
15
+ readonly statement: KeyStatement;
16
+ readonly identityKeys: readonly POIPublicKey[];
17
+ }
18
+ export interface TrustAnchorDataValidation extends TrustAnchorValidation {
19
+ readonly trustedHolderCount: number;
20
+ readonly requiredConsensus: number;
21
+ readonly signatureCount: number;
22
+ readonly canTrustKeys: boolean;
23
+ readonly verificationError?: string;
24
+ }
25
+ export declare function keyStatementURL(base: string): string;
26
+ /** Accept the signed statement itself or an operator/response embedding it, never a replacement anchor. */
27
+ export declare function parseTrustAnchorData(anchor: TrustAnchor, document: StoredTrustAnchorData, additionalKeys?: readonly POIPublicKey[]): LoadedTrustAnchorData;
28
+ /** Mathematical validity, local authorization and quorum remain separate results. */
29
+ export declare function validateTrustAnchorData(anchor: TrustAnchor, data: LoadedTrustAnchorData, record: StoredTrustAnchor | undefined, bundled: readonly POIPublicKey[], deleted: ReadonlySet<string>, at?: number): TrustAnchorDataValidation;
30
+ /** Historical-reference eligibility uses original validity and fresh local decisions; it never grants trust. */
31
+ export declare function validateHistoricalReferenceData(anchor: TrustAnchor, data: LoadedTrustAnchorData, record: StoredTrustAnchor | undefined, bundled: readonly POIPublicKey[], deleted: ReadonlySet<string>, now?: number): TrustAnchorDataValidation;
32
+ /** Called only after Import. Downloads only /keyStatement, not the complete roaming network. */
33
+ export declare function downloadTrustAnchorData(anchor: TrustAnchor, options: {
34
+ readonly signal: AbortSignal;
35
+ readonly fetch?: typeof fetch;
36
+ readonly allowances?: ITransportAllowances;
37
+ readonly additionalKeys?: readonly POIPublicKey[];
38
+ readonly timeoutMs?: number;
39
+ }): Promise<LoadedTrustAnchorData>;
40
+ //# sourceMappingURL=trustAnchorData.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trustAnchorData.d.ts","sourceRoot":"","sources":["../src/trustAnchorData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,YAAY,EAAyB,YAAY,EAAuB,MAAM,+BAA+B,CAAC;AACrI,OAAO,KAAK,EAAa,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAE5E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAErE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAG/D,MAAM,WAAW,qBAAqB;IAClC,QAAQ,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,iFAAiF;IACjF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACz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AE,OAAO,EAAE;IACxE,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IAC9B,QAAQ,CAAC,UAAU,CAAC,EAAE,oBAAoB,CAAC;IAC3C,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;IAClD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC/B,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAuCjC"}
@@ -0,0 +1,91 @@
1
+ import { TrustContext, KeyStatement, KEY_STATEMENT_CONTEXT, POIPublicKey, isObject, parseJSON } from '@open-charging-cloud/wwcp-poi';
2
+ import { trustedAnchorHolders } from './anchorKeyTrust.js';
3
+ import { pollTargetProblem } from './liveLinkTrust.js';
4
+ import { getDefaultPOIFetch, readResponseWithinLimit } from './poiTransport.js';
5
+ export function keyStatementURL(base) {
6
+ const url = new URL(base);
7
+ url.search = "";
8
+ url.hash = "";
9
+ url.pathname = url.pathname.replace(/\/+$/, "") + "/keyStatement";
10
+ return url.href;
11
+ }
12
+ /** Accept the signed statement itself or an operator/response embedding it, never a replacement anchor. */
13
+ export function parseTrustAnchorData(anchor, document, additionalKeys = []) {
14
+ if (!anchor.urls.some(base => keyStatementURL(base) === document.sourceURL) || !Number.isFinite(Date.parse(document.downloadedAt)))
15
+ throw new Error("The downloaded document is not from a source of this trust anchor");
16
+ const json = parseJSON(document.text);
17
+ if (!isObject(json))
18
+ throw new Error("A key statement response must be an object");
19
+ const operator = isObject(json["operator"]) ? json["operator"] : json;
20
+ const value = json["@context"] === KEY_STATEMENT_CONTEXT ? json : operator["keyStatement"];
21
+ const statement = KeyStatement.parse(value);
22
+ if (statement.roamingNetworkId !== anchor.id)
23
+ throw new Error("The key statement belongs to another roaming network");
24
+ if (value !== json && typeof operator["@id"] === "string" && operator["@id"] !== statement.roamingNetworkOperatorId)
25
+ throw new Error("The key statement belongs to another operator");
26
+ const extra = value === json || operator["identityKeys"] === undefined ? [] : POIPublicKey.parseAll(operator["identityKeys"], "Operator identity keys");
27
+ const keys = new Map();
28
+ // Signed metadata takes precedence over key material supplied independently by the app.
29
+ const needed = new Set([...anchor.keys, ...statement.signatures.map(signature => signature.keyId)]);
30
+ for (const key of [...additionalKeys.filter(key => needed.has(key.id)), ...extra, ...statement.identityKeys])
31
+ keys.set(key.id, key);
32
+ return { document, statement, identityKeys: [...keys.values()] };
33
+ }
34
+ /** Mathematical validity, local authorization and quorum remain separate results. */
35
+ export function validateTrustAnchorData(anchor, data, record, bundled, deleted, at = Date.now()) {
36
+ return TrustContext.evaluate(anchor, data.statement, {
37
+ trustedIdentityKeyIds: trustedAnchorHolders(anchor, record, bundled, deleted, at).flat(),
38
+ otherIdentityKeys: data.identityKeys, at
39
+ });
40
+ }
41
+ /** Historical-reference eligibility uses original validity and fresh local decisions; it never grants trust. */
42
+ export function validateHistoricalReferenceData(anchor, data, record, bundled, deleted, now = Date.now()) {
43
+ if (data.statement.signedAt > now)
44
+ return validateTrustAnchorData(anchor, data, record, bundled, deleted, now);
45
+ return TrustContext.evaluate(anchor, data.statement, {
46
+ trustedIdentityKeyIds: trustedAnchorHolders(anchor, record, bundled, deleted, now).flat(),
47
+ otherIdentityKeys: data.identityKeys, at: data.statement.signedAt
48
+ });
49
+ }
50
+ /** Called only after Import. Downloads only /keyStatement, not the complete roaming network. */
51
+ export async function downloadTrustAnchorData(anchor, options) {
52
+ let invalid;
53
+ for (const base of anchor.urls) {
54
+ options.signal.throwIfAborted();
55
+ const endpoint = keyStatementURL(base);
56
+ const url = new URL(endpoint);
57
+ if (pollTargetProblem(url, false, options.allowances) !== null || url.username !== "" || url.password !== "")
58
+ continue;
59
+ const controller = new AbortController();
60
+ const abort = () => { controller.abort(options.signal.reason); };
61
+ options.signal.addEventListener("abort", abort, { once: true });
62
+ const timer = setTimeout(() => { controller.abort(new Error("Key statement download timed out")); }, options.timeoutMs ?? 15000);
63
+ try {
64
+ const response = await (options.fetch ?? getDefaultPOIFetch())(endpoint, {
65
+ signal: controller.signal, credentials: "omit", redirect: "error", cache: "no-store",
66
+ headers: { Accept: "application/json" }
67
+ });
68
+ if (!response.ok)
69
+ throw new Error("The key statement could not be downloaded");
70
+ const bytes = await readResponseWithinLimit(response, 1024 * 1024);
71
+ options.signal.throwIfAborted();
72
+ const data = parseTrustAnchorData(anchor, { sourceURL: endpoint, downloadedAt: new Date().toISOString(),
73
+ text: new TextDecoder("utf-8", { fatal: true }).decode(bytes) }, options.additionalKeys);
74
+ const result = validateTrustAnchorData(anchor, data, undefined, [], new Set());
75
+ if (result.canTrustKeys)
76
+ return data;
77
+ invalid = data;
78
+ }
79
+ catch {
80
+ options.signal.throwIfAborted();
81
+ }
82
+ finally {
83
+ clearTimeout(timer);
84
+ options.signal.removeEventListener("abort", abort);
85
+ }
86
+ }
87
+ if (invalid !== undefined)
88
+ return invalid;
89
+ throw new Error("No source provided a usable key statement");
90
+ }
91
+ //# sourceMappingURL=trustAnchorData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trustAnchorData.js","sourceRoot":"","sources":["../src/trustAnchorData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,qBAAqB,EAAE,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAErI,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAG3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAwBhF,MAAM,UAAU,eAAe,CAAC,IAAY;IACxC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC;IAC1B,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC;IAChB,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC;IACd,GAAG,CAAC,QAAQ,GAAG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AAC,cAAc,CAAC,CAAC;YAC7F,MAAM,MAAM,GAAG,uBAAuB,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;YAC/E,IAAI,MAAM,CAAC,YAAY;gBACnB,OAAO,IAAI,CAAC;YAChB,OAAO,GAAG,IAAI,CAAC;QACnB,CAAC;QACD,MAAM,CAAC;YACH,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;QACpC,CAAC;gBACO,CAAC;YACL,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACvD,CAAC;IACL,CAAC;IACD,IAAI,OAAO,KAAK,SAAS;QACrB,OAAO,OAAO,CAAC;IACnB,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import { TrustContext, KeyStatement, KEY_STATEMENT_CONTEXT, POIPublicKey, isObject, parseJSON } from '@open-charging-cloud/wwcp-poi';\nimport type { JSONValue, TrustAnchor } from '@open-charging-cloud/wwcp-poi';\nimport { trustedAnchorHolders } from './anchorKeyTrust.js';\nimport type { StoredTrustAnchor } from './trustStore.js';\nimport type { TrustAnchorValidation } from './trustAnchorPreview.js';\nimport { pollTargetProblem } from './liveLinkTrust.js';\nimport type { ITransportAllowances } from './liveLinkTrust.js';\nimport { getDefaultPOIFetch, readResponseWithinLimit } from './poiTransport.js';\n\nexport interface StoredTrustAnchorData {\n readonly origin?: 'embedded';\n readonly sourceURL: string;\n readonly downloadedAt: string;\n /** Original signed JSON, parsed with WWCP's parser again whenever it is used. */\n readonly text: string;\n}\n\nexport interface LoadedTrustAnchorData {\n readonly document: StoredTrustAnchorData;\n readonly statement: KeyStatement;\n readonly identityKeys: readonly POIPublicKey[];\n}\n\nexport interface TrustAnchorDataValidation extends TrustAnchorValidation {\n readonly trustedHolderCount: number;\n readonly requiredConsensus: number;\n readonly signatureCount: number;\n readonly canTrustKeys: boolean;\n readonly verificationError?: string;\n}\n\nexport function keyStatementURL(base: string): string {\n const url = new URL(base);\n url.search = \"\";\n url.hash = \"\";\n url.pathname = url.pathname.replace(/\\/+$/, \"\") + \"/keyStatement\";\n return url.href;\n}\n\n/** Accept the signed statement itself or an operator/response embedding it, never a replacement anchor. */\nexport function parseTrustAnchorData(anchor: TrustAnchor, document: StoredTrustAnchorData,\n additionalKeys: readonly POIPublicKey[] = []): LoadedTrustAnchorData {\n if (!anchor.urls.some(base => keyStatementURL(base) === document.sourceURL) || !Number.isFinite(Date.parse(document.downloadedAt)))\n throw new Error(\"The downloaded document is not from a source of this trust anchor\");\n const json = parseJSON(document.text);\n if (!isObject(json))\n throw new Error(\"A key statement response must be an object\");\n const operator = isObject(json[\"operator\"]) ? json[\"operator\"] : json;\n const value: JSONValue | undefined = json[\"@context\"] === KEY_STATEMENT_CONTEXT ? json : operator[\"keyStatement\"];\n const statement = KeyStatement.parse(value);\n if (statement.roamingNetworkId !== anchor.id)\n throw new Error(\"The key statement belongs to another roaming network\");\n if (value !== json && typeof operator[\"@id\"] === \"string\" && operator[\"@id\"] !== statement.roamingNetworkOperatorId)\n throw new Error(\"The key statement belongs to another operator\");\n const extra = value === json || operator[\"identityKeys\"] === undefined ? [] : POIPublicKey.parseAll(operator[\"identityKeys\"], \"Operator identity keys\");\n const keys = new Map<string, POIPublicKey>();\n // Signed metadata takes precedence over key material supplied independently by the app.\n const needed = new Set([...anchor.keys, ...statement.signatures.map(signature => signature.keyId)]);\n for (const key of [...additionalKeys.filter(key => needed.has(key.id)), ...extra, ...statement.identityKeys])\n keys.set(key.id, key);\n return { document, statement, identityKeys: [...keys.values()] };\n}\n\n/** Mathematical validity, local authorization and quorum remain separate results. */\nexport function validateTrustAnchorData(anchor: TrustAnchor, data: LoadedTrustAnchorData,\n record: StoredTrustAnchor | undefined, bundled: readonly POIPublicKey[],\n deleted: ReadonlySet<string>, at: number = Date.now()): TrustAnchorDataValidation {\n return TrustContext.evaluate(anchor, data.statement, {\n trustedIdentityKeyIds: trustedAnchorHolders(anchor, record, bundled, deleted, at).flat(),\n otherIdentityKeys: data.identityKeys, at\n });\n}\n\n/** Historical-reference eligibility uses original validity and fresh local decisions; it never grants trust. */\nexport function validateHistoricalReferenceData(anchor: TrustAnchor, data: LoadedTrustAnchorData,\n record: StoredTrustAnchor | undefined, bundled: readonly POIPublicKey[], deleted: ReadonlySet<string>, now: number = Date.now()): TrustAnchorDataValidation {\n if (data.statement.signedAt > now) return validateTrustAnchorData(anchor,data,record,bundled,deleted,now);\n return TrustContext.evaluate(anchor,data.statement,{\n trustedIdentityKeyIds:trustedAnchorHolders(anchor,record,bundled,deleted,now).flat(),\n otherIdentityKeys:data.identityKeys,at:data.statement.signedAt\n });\n}\n\n/** Called only after Import. Downloads only /keyStatement, not the complete roaming network. */\nexport async function downloadTrustAnchorData(anchor: TrustAnchor, options: {\n readonly signal: AbortSignal;\n readonly fetch?: typeof fetch;\n readonly allowances?: ITransportAllowances;\n readonly additionalKeys?: readonly POIPublicKey[];\n readonly timeoutMs?: number;\n}): Promise<LoadedTrustAnchorData> {\n let invalid: LoadedTrustAnchorData | undefined;\n for (const base of anchor.urls) {\n options.signal.throwIfAborted();\n const endpoint = keyStatementURL(base);\n const url = new URL(endpoint);\n if (pollTargetProblem(url, false, options.allowances) !== null || url.username !== \"\" || url.password !== \"\")\n continue;\n const controller = new AbortController();\n const abort = (): void => { controller.abort(options.signal.reason); };\n options.signal.addEventListener(\"abort\", abort, { once: true });\n const timer = setTimeout(() => { controller.abort(new Error(\"Key statement download timed out\")); }, options.timeoutMs ?? 15000);\n try {\n const response = await (options.fetch ?? getDefaultPOIFetch())(endpoint, {\n signal: controller.signal, credentials: \"omit\", redirect: \"error\", cache: \"no-store\",\n headers: { Accept: \"application/json\" }\n });\n if (!response.ok)\n throw new Error(\"The key statement could not be downloaded\");\n const bytes = await readResponseWithinLimit(response, 1024 * 1024);\n options.signal.throwIfAborted();\n const data = parseTrustAnchorData(anchor, { sourceURL: endpoint, downloadedAt: new Date().toISOString(),\n text: new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes) }, options.additionalKeys);\n const result = validateTrustAnchorData(anchor, data, undefined, [], new Set());\n if (result.canTrustKeys)\n return data;\n invalid = data;\n }\n catch {\n options.signal.throwIfAborted();\n }\n finally {\n clearTimeout(timer);\n options.signal.removeEventListener(\"abort\", abort);\n }\n }\n if (invalid !== undefined)\n return invalid;\n throw new Error(\"No source provided a usable key statement\");\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import type { POIPublicKey, TrustAnchor } from '@open-charging-cloud/wwcp-poi';
2
+ import type { LoadedTrustAnchorData } from './trustAnchorData.js';
3
+ import type { StoredTrustAnchor } from './trustStore.js';
4
+ /** Step two: source document, real verification and optional trust decisions. Never downloads by itself. */
5
+ export declare function renderTrustAnchorData(anchor: TrustAnchor, data: LoadedTrustAnchorData, options: {
6
+ readonly record: StoredTrustAnchor | undefined;
7
+ readonly bundled: readonly POIPublicKey[];
8
+ readonly deleted: ReadonlySet<string>;
9
+ readonly localize: (key: string) => string;
10
+ readonly onChange: (id: string, trusted: boolean) => Promise<void>;
11
+ readonly historicalReference?: boolean;
12
+ }): HTMLElement;
13
+ //# sourceMappingURL=trustAnchorDataView.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trustAnchorDataView.d.ts","sourceRoot":"","sources":["../src/trustAnchorDataView.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAElE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAMzD,4GAA4G;AAC5G,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,qBAAqB,EAChD,OAAO,EAAE;IACL,QAAQ,CAAC,MAAM,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAC/C,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,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACnE,QAAQ,CAAC,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC1C,GAAG,WAAW,CA2DpD"}
@@ -0,0 +1,69 @@
1
+ import { toBase64 } from '@open-charging-cloud/wwcp-poi';
2
+ import { validateTrustAnchorData, validateHistoricalReferenceData } from './trustAnchorData.js';
3
+ import { activeBundledPublicKeys } from './trustStore.js';
4
+ import { renderTrustAnchorValidation } from './trustAnchorPreview.js';
5
+ import { renderAnchorKeyTrust } from './anchorKeyTrustView.js';
6
+ import { renderSecurityFingerprint } from './securityFingerprintView.js';
7
+ /** Step two: source document, real verification and optional trust decisions. Never downloads by itself. */
8
+ export function renderTrustAnchorData(anchor, data, options) {
9
+ const { localize } = options;
10
+ const root = document.createElement("section");
11
+ root.className = "trustAnchorPreview trustAnchorLoadedData";
12
+ root.dataset["stage"] = "downloaded";
13
+ const heading = root.appendChild(document.createElement("h2"));
14
+ heading.textContent = localize("trustDataTitle");
15
+ const result = validateTrustAnchorData(anchor, data, options.record, options.bundled, options.deleted);
16
+ const historical = options.historicalReference === true ? validateHistoricalReferenceData(anchor, data, options.record, options.bundled, options.deleted) : undefined;
17
+ if (historical !== undefined) {
18
+ const note = root.appendChild(document.createElement('p'));
19
+ note.dataset['historicalReference'] = 'true';
20
+ note.textContent = localize('poiHistoryReferenceImport');
21
+ }
22
+ const status = root.appendChild(document.createElement("p"));
23
+ const saved = options.record?.downloadedData?.text === data.document.text && options.record.downloadedData.sourceURL === data.document.sourceURL;
24
+ status.textContent = localize(saved ? "trustAnchorSavedStatus" : historical !== undefined && options.record?.downloadedData !== undefined ? 'poiHistoryExistingReference' : "trustDataNotSaved");
25
+ root.appendChild(renderTrustAnchorValidation({ ...result, reasons: {
26
+ signatures: localize(result.signatures === "valid" ? "trustAnchorCheckPassed" : "trustAnchorCheckFailed") + ` (${result.signatureCount})`,
27
+ quorum: `${result.trustedHolderCount} / ${result.requiredConsensus} · ${localize(result.quorum === "valid" ? "trustAnchorCheckPassed" : "trustAnchorCheckFailed")}`
28
+ } }, localize, activeBundledPublicKeys(options.bundled, options.deleted).length));
29
+ const fields = root.appendChild(document.createElement("dl"));
30
+ const field = (label, value) => {
31
+ const term = fields.appendChild(document.createElement("dt"));
32
+ term.textContent = localize(label);
33
+ const content = fields.appendChild(document.createElement("dd"));
34
+ content.textContent = value;
35
+ content.className = "trustManagementIdentifier trustAnchorMonospace";
36
+ };
37
+ field("trustAnchorNetworkLabel", data.statement.roamingNetworkId);
38
+ field("trustDataOperatorLabel", data.statement.roamingNetworkOperatorId);
39
+ field("trustDataSignedAtLabel", new Date(data.statement.signedAt).toISOString());
40
+ field("trustDataValidUntilLabel", new Date(data.statement.validUntil).toISOString());
41
+ field(data.document.origin === 'embedded' ? 'poiDeclaredSource' : 'trustDataSourceLabel', data.document.sourceURL);
42
+ field(data.document.origin === 'embedded' ? 'poiReceivedAt' : 'trustDataDownloadedAtLabel', data.document.downloadedAt);
43
+ if (data.document.origin === 'embedded')
44
+ root.appendChild(document.createElement('p')).textContent = localize('poiEmbeddedStatement');
45
+ root.appendChild(renderAnchorKeyTrust(anchor, {
46
+ ...options, loadedKeys: data.identityKeys, allowChanges: result.canTrustKeys || historical?.canTrustKeys === true
47
+ }));
48
+ const keys = root.appendChild(document.createElement("details"));
49
+ const summary = keys.appendChild(document.createElement("summary"));
50
+ summary.textContent = `${localize("trustDataKeysLabel")} (${data.statement.identityKeys.length})`;
51
+ for (const key of data.statement.identityKeys) {
52
+ const item = keys.appendChild(document.createElement("div"));
53
+ const title = item.appendChild(document.createElement("p"));
54
+ title.textContent = key.holder ?? "";
55
+ item.appendChild(renderSecurityFingerprint(key.id, localize));
56
+ const value = item.appendChild(document.createElement("pre"));
57
+ value.textContent = toBase64(key.keyBytes);
58
+ }
59
+ const raw = root.appendChild(document.createElement("details"));
60
+ raw.appendChild(document.createElement("summary")).textContent = localize("trustDataRawLabel");
61
+ raw.appendChild(document.createElement("pre")).textContent = data.document.text;
62
+ if (result.verificationError !== undefined) {
63
+ const error = root.appendChild(document.createElement("details"));
64
+ error.appendChild(document.createElement("summary")).textContent = localize("trustDataDiagnosticLabel");
65
+ error.appendChild(document.createElement("pre")).textContent = result.verificationError;
66
+ }
67
+ return root;
68
+ }
69
+ //# sourceMappingURL=trustAnchorDataView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trustAnchorDataView.js","sourceRoot":"","sources":["../src/trustAnchorDataView.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAGzD,OAAO,EAAE,uBAAuB,EAAE,+BAA+B,EAAE,MAAM,sBAAsB,CAAC;AAEhG,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAEzE,4GAA4G;AAC5G,MAAM,UAAU,qBAAqB,CAAC,MAAmB,EAAE,IAA2B,EAChD,OAOC;IACnC,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC7B,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IAC/C,IAAI,CAAC,SAAS,GAAG,0CAA0C,CAAC;IAC5D,IAAI,CAAC,OAAO,CAAC,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Aa,CAAC,SAAS,CAAC,CAAC,CAAC;QAClE,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,GAAG,QAAQ,CAAC,0BAA0B,CAAC,CAAC;QACxG,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,GAAG,MAAM,CAAC,iBAAiB,CAAC;IAC5F,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC","sourcesContent":["import { toBase64 } from '@open-charging-cloud/wwcp-poi';\nimport type { POIPublicKey, TrustAnchor } from '@open-charging-cloud/wwcp-poi';\nimport type { LoadedTrustAnchorData } from './trustAnchorData.js';\nimport { validateTrustAnchorData, validateHistoricalReferenceData } from './trustAnchorData.js';\nimport type { StoredTrustAnchor } from './trustStore.js';\nimport { activeBundledPublicKeys } from './trustStore.js';\nimport { renderTrustAnchorValidation } from './trustAnchorPreview.js';\nimport { renderAnchorKeyTrust } from './anchorKeyTrustView.js';\nimport { renderSecurityFingerprint } from './securityFingerprintView.js';\n\n/** Step two: source document, real verification and optional trust decisions. Never downloads by itself. */\nexport function renderTrustAnchorData(anchor: TrustAnchor, data: LoadedTrustAnchorData,\n options: {\n readonly record: StoredTrustAnchor | undefined;\n readonly bundled: readonly POIPublicKey[];\n readonly deleted: ReadonlySet<string>;\n readonly localize: (key: string) => string;\n readonly onChange: (id: string, trusted: boolean) => Promise<void>;\n readonly historicalReference?: boolean;\n }): HTMLElement {\n const { localize } = options;\n const root = document.createElement(\"section\");\n root.className = \"trustAnchorPreview trustAnchorLoadedData\";\n root.dataset[\"stage\"] = \"downloaded\";\n const heading = root.appendChild(document.createElement(\"h2\"));\n heading.textContent = localize(\"trustDataTitle\");\n const result = validateTrustAnchorData(anchor, data, options.record, options.bundled, options.deleted);\n const historical = options.historicalReference === true ? validateHistoricalReferenceData(anchor,data,options.record,options.bundled,options.deleted) : undefined;\n if (historical !== undefined) {\n const note = root.appendChild(document.createElement('p')); note.dataset['historicalReference'] = 'true';\n note.textContent = localize('poiHistoryReferenceImport');\n }\n const status = root.appendChild(document.createElement(\"p\"));\n const saved = options.record?.downloadedData?.text === data.document.text && options.record.downloadedData.sourceURL === data.document.sourceURL;\n status.textContent = localize(saved ? \"trustAnchorSavedStatus\" : historical !== undefined && options.record?.downloadedData !== undefined ? 'poiHistoryExistingReference' : \"trustDataNotSaved\");\n root.appendChild(renderTrustAnchorValidation({ ...result, reasons: {\n signatures: localize(result.signatures === \"valid\" ? \"trustAnchorCheckPassed\" : \"trustAnchorCheckFailed\") + ` (${result.signatureCount})`,\n quorum: `${result.trustedHolderCount} / ${result.requiredConsensus} · ${localize(result.quorum === \"valid\" ? \"trustAnchorCheckPassed\" : \"trustAnchorCheckFailed\")}`\n } }, localize, activeBundledPublicKeys(options.bundled, options.deleted).length));\n const fields = root.appendChild(document.createElement(\"dl\"));\n const field = (label: string, value: string): void => {\n const term = fields.appendChild(document.createElement(\"dt\"));\n term.textContent = localize(label);\n const content = fields.appendChild(document.createElement(\"dd\"));\n content.textContent = value;\n content.className = \"trustManagementIdentifier trustAnchorMonospace\";\n };\n field(\"trustAnchorNetworkLabel\", data.statement.roamingNetworkId);\n field(\"trustDataOperatorLabel\", data.statement.roamingNetworkOperatorId);\n field(\"trustDataSignedAtLabel\", new Date(data.statement.signedAt).toISOString());\n field(\"trustDataValidUntilLabel\", new Date(data.statement.validUntil).toISOString());\n field(data.document.origin === 'embedded' ? 'poiDeclaredSource' : 'trustDataSourceLabel', data.document.sourceURL);\n field(data.document.origin === 'embedded' ? 'poiReceivedAt' : 'trustDataDownloadedAtLabel', data.document.downloadedAt);\n if (data.document.origin === 'embedded')\n root.appendChild(document.createElement('p')).textContent = localize('poiEmbeddedStatement');\n root.appendChild(renderAnchorKeyTrust(anchor, {\n ...options, loadedKeys: data.identityKeys, allowChanges: result.canTrustKeys || historical?.canTrustKeys === true\n }));\n const keys = root.appendChild(document.createElement(\"details\"));\n const summary = keys.appendChild(document.createElement(\"summary\"));\n summary.textContent = `${localize(\"trustDataKeysLabel\")} (${data.statement.identityKeys.length})`;\n for (const key of data.statement.identityKeys) {\n const item = keys.appendChild(document.createElement(\"div\"));\n const title = item.appendChild(document.createElement(\"p\"));\n title.textContent = key.holder ?? \"\";\n item.appendChild(renderSecurityFingerprint(key.id, localize));\n const value = item.appendChild(document.createElement(\"pre\"));\n value.textContent = toBase64(key.keyBytes);\n }\n const raw = root.appendChild(document.createElement(\"details\"));\n raw.appendChild(document.createElement(\"summary\")).textContent = localize(\"trustDataRawLabel\");\n raw.appendChild(document.createElement(\"pre\")).textContent = data.document.text;\n if (result.verificationError !== undefined) {\n const error = root.appendChild(document.createElement(\"details\"));\n error.appendChild(document.createElement(\"summary\")).textContent = localize(\"trustDataDiagnosticLabel\");\n error.appendChild(document.createElement(\"pre\")).textContent = result.verificationError;\n }\n return root;\n}\n"]}
@@ -0,0 +1,5 @@
1
+ import type { ChargyInterfaces } from '@open-charging-cloud/chargy-core';
2
+ import type { ScannedTrustAnchor } from './trustAnchorPreview.js';
3
+ /** A preflight router; unrecognized inputs remain available to the existing transparency reader. */
4
+ export declare function findTrustAnchorImport(input: string | ChargyInterfaces.IFileInfo | readonly ChargyInterfaces.IFileInfo[]): Promise<ScannedTrustAnchor>;
5
+ //# sourceMappingURL=trustAnchorImport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trustAnchorImport.d.ts","sourceRoot":"","sources":["../src/trustAnchorImport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAGzE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE,oGAAoG;AACpG,wBAAsB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB,CAAC,SAAS,GAAG,SAAS,gBAAgB,CAAC,SAAS,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAwB3J"}
@@ -0,0 +1,34 @@
1
+ import { readQRCodeTextFromImage } from '@open-charging-cloud/chargy-core';
2
+ import { browserFileTypeFromNameOrData } from './browserFiles.js';
3
+ import { parseTrustAnchorInput } from './trustAnchorPreview.js';
4
+ /** A preflight router; unrecognized inputs remain available to the existing transparency reader. */
5
+ export async function findTrustAnchorImport(input) {
6
+ if (typeof input === "string")
7
+ return parseTrustAnchorInput(input);
8
+ const files = Array.isArray(input) ? input : [input];
9
+ for (const file of files) {
10
+ if (file.data === undefined || file.error !== undefined)
11
+ continue;
12
+ const type = browserFileTypeFromNameOrData(file.name, file.type ?? "", file.data);
13
+ let text;
14
+ if (type.startsWith("image/")) {
15
+ try {
16
+ text = await readQRCodeTextFromImage(file.data, type);
17
+ }
18
+ catch { /* Let the existing reader diagnose unsupported or invalid images. */ }
19
+ }
20
+ else {
21
+ try {
22
+ text = new TextDecoder("utf-8", { fatal: true }).decode(file.data);
23
+ }
24
+ catch { /* Binary transparency formats remain on the existing import path. */ }
25
+ }
26
+ if (text !== undefined) {
27
+ const result = parseTrustAnchorInput(text);
28
+ if (result.kind !== "other")
29
+ return files.length === 1 ? result : { kind: "invalid", message: "Import trust anchor files individually, separately from other files.", messageKey: "trustAnchorSingleFile" };
30
+ }
31
+ }
32
+ return { kind: "other" };
33
+ }
34
+ //# sourceMappingURL=trustAnchorImport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trustAnchorImport.js","sourceRoot":"","sources":["../src/trustAnchorImport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAE3E,OAAO,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAGhE,oGAAoG;AACpG,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,KAAkF;IAC1H,IAAI,OAAO,KAAK,KAAK,QAAQ;QACzB,OAAO,qBAAqB,CAAC,K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L,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAC7B,CAAC","sourcesContent":["import { readQRCodeTextFromImage } from '@open-charging-cloud/chargy-core';\nimport type { ChargyInterfaces } from '@open-charging-cloud/chargy-core';\nimport { browserFileTypeFromNameOrData } from './browserFiles.js';\nimport { parseTrustAnchorInput } from './trustAnchorPreview.js';\nimport type { ScannedTrustAnchor } from './trustAnchorPreview.js';\n\n/** A preflight router; unrecognized inputs remain available to the existing transparency reader. */\nexport async function findTrustAnchorImport(input: string | ChargyInterfaces.IFileInfo | readonly ChargyInterfaces.IFileInfo[]): Promise<ScannedTrustAnchor> {\n if (typeof input === \"string\")\n return parseTrustAnchorInput(input);\n const files: readonly ChargyInterfaces.IFileInfo[] = Array.isArray(input) ? input as readonly ChargyInterfaces.IFileInfo[] : [input as ChargyInterfaces.IFileInfo];\n for (const file of files) {\n if (file.data === undefined || file.error !== undefined)\n continue;\n const type = browserFileTypeFromNameOrData(file.name, file.type ?? \"\", file.data);\n let text: string | undefined;\n if (type.startsWith(\"image/\")) {\n try { text = await readQRCodeTextFromImage(file.data, type); }\n catch { /* Let the existing reader diagnose unsupported or invalid images. */ }\n }\n else {\n try { text = new TextDecoder(\"utf-8\", { fatal: true }).decode(file.data); }\n catch { /* Binary transparency formats remain on the existing import path. */ }\n }\n if (text !== undefined) {\n const result = parseTrustAnchorInput(text);\n if (result.kind !== \"other\")\n return files.length === 1 ? result : { kind: \"invalid\", message: \"Import trust anchor files individually, separately from other files.\", messageKey: \"trustAnchorSingleFile\" };\n }\n }\n return { kind: \"other\" };\n}\n"]}
@@ -0,0 +1,37 @@
1
+ import { TrustAnchor } from '@open-charging-cloud/wwcp-poi';
2
+ export interface TrustAnchorPreview {
3
+ readonly anchor: TrustAnchor;
4
+ readonly text: string;
5
+ }
6
+ export type TrustAnchorCheckState = "valid" | "invalid" | "unavailable";
7
+ /** Results supplied by a verifier, independently of the scanned document. */
8
+ export interface TrustAnchorValidation {
9
+ readonly signatures: TrustAnchorCheckState;
10
+ readonly signers: TrustAnchorCheckState;
11
+ readonly quorum: TrustAnchorCheckState;
12
+ readonly validity?: TrustAnchorCheckState;
13
+ readonly reasons?: Readonly<Partial<Record<"signatures" | "signers" | "quorum" | "validity", string>>>;
14
+ }
15
+ export interface TrustAnchorPreviewOptions {
16
+ readonly busy?: boolean;
17
+ readonly onImport?: () => void;
18
+ readonly onDiscard?: () => void;
19
+ }
20
+ export type ScannedTrustAnchor = {
21
+ readonly kind: "other";
22
+ } | {
23
+ readonly kind: "invalid";
24
+ readonly message: string;
25
+ readonly messageKey?: string;
26
+ } | {
27
+ readonly kind: "anchor";
28
+ readonly preview: TrustAnchorPreview;
29
+ };
30
+ /** Shared by camera, clipboard and files. Never follows URLs or establishes trust. */
31
+ export declare function parseTrustAnchorInput(text: string): ScannedTrustAnchor;
32
+ export declare const parseScannedTrustAnchor: typeof parseTrustAnchorInput;
33
+ /** All three checks must pass before the whole field receives the success appearance. */
34
+ export declare function renderTrustAnchorValidation(result: TrustAnchorValidation, localize: (key: string) => string, activeTrustedKeyCount?: number, unavailableReason?: string): HTMLElement;
35
+ /** Step one contains only the supplied anchor. No storage, downloads, key trust or verification. */
36
+ export declare function renderTrustAnchorPreview(preview: TrustAnchorPreview, language: string, localize: (key: string) => string, options?: TrustAnchorPreviewOptions): HTMLElement;
37
+ //# sourceMappingURL=trustAnchorPreview.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trustAnchorPreview.d.ts","sourceRoot":"","sources":["../src/trustAnchorPreview.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAqE,MAAM,+BAA+B,CAAC;AAG/H,MAAM,WAAW,kBAAkB;IAC/B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,MAAM,qBAAqB,GAAG,OAAO,GAAG,SAAS,GAAG,aAAa,CAAC;AAExE,6EAA6E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AqDnF;AAED,oGAAoG;AACpG,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,kBAAkB,EAC3B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,EACjC,OAAO,GAAE,yBAA8B,GAAG,WAAW,CAkF7F"}
@@ -0,0 +1,180 @@
1
+ import { TrustAnchor, TRUST_ANCHOR_QR_PREFIX, TRUST_ANCHOR_CONTEXT, parseJSON, isObject } from '@open-charging-cloud/wwcp-poi';
2
+ import { renderSecurityFingerprint } from './securityFingerprintView.js';
3
+ /** Shared by camera, clipboard and files. Never follows URLs or establishes trust. */
4
+ export function parseTrustAnchorInput(text) {
5
+ const trimmed = text.trim();
6
+ let candidate = trimmed.startsWith(TRUST_ANCHOR_QR_PREFIX);
7
+ if (trimmed.startsWith("{")) {
8
+ candidate = trimmed.includes(TRUST_ANCHOR_CONTEXT) || /"trustAnchor"\s*:/.test(trimmed);
9
+ try {
10
+ const parsed = parseJSON(trimmed);
11
+ if (isObject(parsed)) {
12
+ const context = parsed["@context"];
13
+ const direct = context === TRUST_ANCHOR_CONTEXT || Array.isArray(context) && context.includes(TRUST_ANCHOR_CONTEXT);
14
+ // Do not consume a charging receipt or evidence bundle merely because it embeds an anchor.
15
+ const responseFields = ["roamingNetworkId", "identityKeyIds", "minConsensus", "uri", "qrCode", "trustAnchor"];
16
+ const response = "trustAnchor" in parsed && Object.keys(parsed).every(key => responseFields.includes(key));
17
+ if (!direct && !response)
18
+ return { kind: "other" };
19
+ const value = response ? parsed["trustAnchor"] : parsed;
20
+ if (isObject(value)) {
21
+ const valueContext = value["@context"];
22
+ if (valueContext === TRUST_ANCHOR_CONTEXT || Array.isArray(valueContext) && valueContext.includes(TRUST_ANCHOR_CONTEXT))
23
+ return { kind: "anchor", preview: { anchor: TrustAnchor.fromJSON(value), text: trimmed } };
24
+ }
25
+ }
26
+ return candidate ? { kind: "invalid", message: "Invalid trust anchor document" } : { kind: "other" };
27
+ }
28
+ catch (error) {
29
+ return candidate ? { kind: "invalid", message: error instanceof Error ? error.message : String(error) } : { kind: "other" };
30
+ }
31
+ }
32
+ if (!candidate) {
33
+ try {
34
+ const url = new URL(trimmed);
35
+ candidate = (url.protocol === "https:" || url.protocol === "http:") &&
36
+ url.pathname.replace(/\/+$/, "").split("/").at(-2) === "RNs" &&
37
+ url.searchParams.has("keys");
38
+ }
39
+ catch {
40
+ return { kind: "other" };
41
+ }
42
+ }
43
+ if (!candidate)
44
+ return { kind: "other" };
45
+ try {
46
+ return { kind: "anchor", preview: { anchor: TrustAnchor.parse(trimmed), text: trimmed } };
47
+ }
48
+ catch (error) {
49
+ return { kind: "invalid", message: error instanceof Error ? error.message : String(error) };
50
+ }
51
+ }
52
+ export const parseScannedTrustAnchor = parseTrustAnchorInput;
53
+ /** All three checks must pass before the whole field receives the success appearance. */
54
+ export function renderTrustAnchorValidation(result, localize, activeTrustedKeyCount = 0, unavailableReason) {
55
+ const validation = document.createElement("section");
56
+ validation.className = "trustAnchorValidation";
57
+ const states = [result.signatures, result.signers, result.quorum, ...(result.validity === undefined ? [] : [result.validity])];
58
+ const allValid = states.every(state => state === "valid");
59
+ validation.dataset["state"] = allValid ? "valid" : states.includes("invalid") ? "invalid" : "unavailable";
60
+ validation.setAttribute("aria-labelledby", "trustAnchorValidationTitle");
61
+ const validationTitle = validation.appendChild(document.createElement("h3"));
62
+ validationTitle.id = "trustAnchorValidationTitle";
63
+ validationTitle.textContent = localize("trustAnchorValidationTitle");
64
+ if (allValid) {
65
+ const icon = document.createElement("i");
66
+ icon.className = "fas fa-check-circle trustAnchorValidationSuccessIcon";
67
+ icon.setAttribute("aria-hidden", "true");
68
+ validationTitle.prepend(icon, document.createTextNode(" "));
69
+ }
70
+ const checks = [
71
+ { id: "signatures", state: result.signatures, label: "trustAnchorSignaturesValid", reason: "trustAnchorNoSignatures" },
72
+ { id: "signers", state: result.signers, label: "trustAnchorSignersTrusted", reason: "trustAnchorSignersNotCheckable" },
73
+ { id: "quorum", state: result.quorum, label: "trustAnchorQuorumMet", reason: "trustAnchorQuorumNotCheckable" }
74
+ ];
75
+ if (result.validity !== undefined)
76
+ checks.push({ id: "validity", state: result.validity, label: "trustDataValidityLabel", reason: "trustDataValidityUnknown" });
77
+ const checkList = validation.appendChild(document.createElement("ul"));
78
+ for (const check of checks) {
79
+ const row = checkList.appendChild(document.createElement("li"));
80
+ row.dataset["check"] = check.id;
81
+ row.dataset["state"] = check.state;
82
+ const icon = row.appendChild(document.createElement("span"));
83
+ icon.className = "trustAnchorCheckIcon";
84
+ icon.setAttribute("aria-hidden", "true");
85
+ if (check.state === "valid")
86
+ icon.classList.add("fas", "fa-check-circle");
87
+ else if (check.state === "invalid")
88
+ icon.classList.add("fas", "fa-times-circle");
89
+ else
90
+ icon.textContent = "○";
91
+ const content = row.appendChild(document.createElement("div"));
92
+ const label = content.appendChild(document.createElement("strong"));
93
+ label.textContent = localize(check.label);
94
+ const reason = content.appendChild(document.createElement("p"));
95
+ reason.textContent = result.reasons?.[check.id] ?? localize(check.state === "valid" ? "trustAnchorCheckPassed" :
96
+ check.state === "invalid" ? "trustAnchorCheckFailed" : unavailableReason ?? check.reason);
97
+ }
98
+ const trustPolicy = validation.appendChild(document.createElement("p"));
99
+ trustPolicy.className = "trustAnchorTrustPolicy";
100
+ trustPolicy.textContent = localize("trustAnchorTrustPolicy");
101
+ const bundledKeyCount = validation.appendChild(document.createElement("p"));
102
+ bundledKeyCount.className = "trustAnchorBundledKeyCount";
103
+ bundledKeyCount.textContent = `${localize("trustAnchorBundledKeysLabel")}: ${activeTrustedKeyCount}`;
104
+ return validation;
105
+ }
106
+ /** Step one contains only the supplied anchor. No storage, downloads, key trust or verification. */
107
+ export function renderTrustAnchorPreview(preview, language, localize, options = {}) {
108
+ const { anchor, text } = preview;
109
+ const section = document.createElement("section");
110
+ section.className = "trustAnchorPreview";
111
+ section.setAttribute("aria-labelledby", "trustAnchorPreviewTitle");
112
+ const title = section.appendChild(document.createElement("h2"));
113
+ title.id = "trustAnchorPreviewTitle";
114
+ title.textContent = localize("trustAnchorPreviewTitle");
115
+ const fields = section.appendChild(document.createElement("dl"));
116
+ const addField = (label, values, monospace = false) => {
117
+ const term = fields.appendChild(document.createElement("dt"));
118
+ term.textContent = label;
119
+ const description = fields.appendChild(document.createElement("dd"));
120
+ if (monospace)
121
+ description.className = "trustAnchorMonospace";
122
+ for (const value of values) {
123
+ const line = description.appendChild(document.createElement("div"));
124
+ line.textContent = value;
125
+ }
126
+ };
127
+ const localizedText = (texts) => texts[language] ?? texts["en"] ?? Object.values(texts)[0] ?? "";
128
+ const name = localizedText(anchor.name);
129
+ if (name !== "")
130
+ addField(localize("trustAnchorNameLabel"), [name]);
131
+ const description = localizedText(anchor.description);
132
+ if (description !== "")
133
+ addField(localize("trustAnchorDescriptionLabel"), [description]);
134
+ addField(localize("trustAnchorNetworkLabel"), [anchor.id]);
135
+ addField(localize("trustAnchorURLsLabel"), anchor.urls, true);
136
+ addField(localize("trustAnchorQuorumLabel"), [`${anchor.minConsensus} / ${anchor.holders.length}`]);
137
+ const keys = section.appendChild(document.createElement("details"));
138
+ keys.open = true;
139
+ const keysSummary = keys.appendChild(document.createElement("summary"));
140
+ keysSummary.textContent = `${localize("trustAnchorIdentityKeysLabel")} (${anchor.keys.length})`;
141
+ const holders = keys.appendChild(document.createElement("div"));
142
+ holders.className = "trustAnchorFingerprintHolders";
143
+ for (const [index, holder] of anchor.holders.entries()) {
144
+ const group = holders.appendChild(document.createElement("div"));
145
+ group.className = "trustAnchorHolder";
146
+ group.style.flexGrow = String(holder.length);
147
+ group.style.flexBasis = `${Math.min(holder.length, 2) * 164}px`;
148
+ const heading = group.appendChild(document.createElement("h3"));
149
+ heading.textContent = `${localize("trustAnchorHolderLabel")} ${index + 1}`;
150
+ const grid = group.appendChild(document.createElement("div"));
151
+ grid.className = "securityFingerprintGrid";
152
+ for (const key of holder)
153
+ grid.appendChild(renderSecurityFingerprint(key, localize));
154
+ }
155
+ const raw = section.appendChild(document.createElement("details"));
156
+ const rawSummary = raw.appendChild(document.createElement("summary"));
157
+ rawSummary.textContent = localize("recognizedContent");
158
+ const rawText = raw.appendChild(document.createElement("pre"));
159
+ rawText.textContent = text;
160
+ const actions = section.appendChild(document.createElement("div"));
161
+ actions.className = "trustAnchorPreviewActions";
162
+ if (options.onImport !== undefined) {
163
+ const button = actions.appendChild(document.createElement("button"));
164
+ button.type = "button";
165
+ button.dataset["action"] = "import";
166
+ button.className = "trustAnchorImport";
167
+ button.textContent = localize("trustAnchorImportLabel");
168
+ button.disabled = options.busy === true;
169
+ button.onclick = options.onImport;
170
+ }
171
+ if (options.onDiscard !== undefined) {
172
+ const button = actions.appendChild(document.createElement("button"));
173
+ button.type = "button";
174
+ button.dataset["action"] = "discard";
175
+ button.textContent = localize("trustManualCancel");
176
+ button.onclick = options.onDiscard;
177
+ }
178
+ return section;
179
+ }
180
+ //# sourceMappingURL=trustAnchorPreview.js.map