@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,75 @@
1
+ import { TrustAnchor } from '@open-charging-cloud/wwcp-poi';
2
+ import type { POIPublicKey } from '@open-charging-cloud/wwcp-poi';
3
+ import type { StoredTrustAnchorData } from './trustAnchorData.js';
4
+ import type { LoadedStationProof } from './stationProofData.js';
5
+ export declare const trustDatabaseName = "ChargyTrustManagement";
6
+ /** Original cached evidence and provenance; no persisted authorization verdict. */
7
+ export interface StoredStationProof {
8
+ readonly effectiveAnchorQRCode?: string;
9
+ readonly origin?: 'embedded';
10
+ readonly id: string;
11
+ readonly anchorPolicyId: string;
12
+ readonly anchorQRCode: string;
13
+ readonly evseId: string;
14
+ readonly sourceURL: string;
15
+ readonly downloadedAt: string;
16
+ readonly checkedAt: string;
17
+ readonly text: string;
18
+ }
19
+ export declare function stationProofStorageId(policyId: string, evseId: string, text: string): string;
20
+ export interface StoredTrustAnchor {
21
+ /** Explicitly accepted original delegation evidence, reverified under current local roots on each operation. */
22
+ readonly transitions?: readonly {
23
+ readonly text: string;
24
+ readonly acceptedAt: string;
25
+ }[];
26
+ readonly id: string;
27
+ readonly qrCode: string;
28
+ readonly sourceText: string;
29
+ readonly importedAt: string;
30
+ /** Explicit local decisions, scoped to this exact anchor policy, never global roots. */
31
+ readonly trustedKeys?: readonly ManuallyTrustedKey[];
32
+ readonly downloadedData?: StoredTrustAnchorData;
33
+ }
34
+ export interface ManuallyTrustedKey {
35
+ readonly id: string;
36
+ readonly acceptedAt: string;
37
+ }
38
+ /** Names/descriptions do not create duplicates between compact and URL forms. */
39
+ export declare function trustAnchorStorageId(anchor: TrustAnchor): string;
40
+ /** Version 2 adds a proof cache, retaining the version-1 anchors and local decisions. */
41
+ export declare class TrustStore {
42
+ /** Compare the complete reviewed policy and exclusions in the same transaction; concurrent decisions cannot be overwritten. */
43
+ appendTrustTransition(expected: StoredTrustAnchor, expectedDeleted: ReadonlySet<string>, text: string, acceptedAt: string, validate: (record: StoredTrustAnchor, deleted: ReadonlySet<string>) => void): Promise<void>;
44
+ private connection;
45
+ private open;
46
+ private transaction;
47
+ listAnchors(): Promise<readonly StoredTrustAnchor[]>;
48
+ hasAnchor(anchor: TrustAnchor): Promise<boolean>;
49
+ getAnchor(anchor: TrustAnchor): Promise<StoredTrustAnchor | undefined>;
50
+ /** An authorization snapshot must not mix an anchor and exclusions read from different transactions. */
51
+ trustSnapshot(anchorPolicyId: string): Promise<{
52
+ readonly record: StoredTrustAnchor | undefined;
53
+ readonly deleted: ReadonlySet<string>;
54
+ }>;
55
+ listTrustSnapshot(): Promise<{
56
+ readonly records: readonly StoredTrustAnchor[];
57
+ readonly deleted: ReadonlySet<string>;
58
+ }>;
59
+ private readTrustSnapshot;
60
+ /** A separate user action; import never calls this. Updating one key preserves concurrent decisions. */
61
+ setKeyTrust(anchorId: string, keyId: string, trusted: boolean): Promise<void>;
62
+ /** The unique-key check and insertion share one transaction, including across tabs. */
63
+ importAnchor(anchor: TrustAnchor, sourceText: string, downloadedData?: StoredTrustAnchorData, signal?: AbortSignal): Promise<"imported" | "exists">;
64
+ deleteAnchor(id: string): Promise<void>;
65
+ /** Delete only the selected identity's policies, never every operator claiming the same network ID. */
66
+ deleteRoamingNetwork(anchorPolicyIds: readonly string[]): Promise<number>;
67
+ deletedBundledKeyIds(): Promise<ReadonlySet<string>>;
68
+ deleteBundledKey(id: string): Promise<void>;
69
+ restoreBundledKey(id: string): Promise<void>;
70
+ saveStationProof(proof: LoadedStationProof, signal?: AbortSignal): Promise<'saved' | 'exists'>;
71
+ listStationProofs(policyId: string, limit?: number): Promise<readonly StoredStationProof[]>;
72
+ deleteStationProof(id: string): Promise<void>;
73
+ }
74
+ export declare function activeBundledPublicKeys(keys: readonly POIPublicKey[], deleted: ReadonlySet<string>): readonly POIPublicKey[];
75
+ //# sourceMappingURL=trustStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trustStore.d.ts","sourceRoot":"","sources":["../src/trustStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA6B,MAAM,+BAA+B,CAAC;AACvF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAGhE,eAAO,MAAM,iBAAiB,0BAA0B,CAAC;AAKzD,mFAAmF;AACnF,MAAM,WAAW,kBAAkB;IAC/B,QAAQ,CAAC,qBAAqB,CAAC,EAAC,MAAM,CAAC;IACvC,QAAQ,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAA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AAG,QAAQ,CAAC;IA4B9F,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,GAAE,MAAW,GAAG,OAAO,CAAC,SAAS,kBAAkB,EAAE,CAAC;IAkB/F,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG7D;AAWD,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,SAAS,YAAY,EAAE,EAAE,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,SAAS,YAAY,EAAE,CAE5H"}
@@ -0,0 +1,408 @@
1
+ import { TrustAnchor, hash, toHex, trustPolicyId } from '@open-charging-cloud/wwcp-poi';
2
+ import { stationEVSEId, stationProofURL } from './poiURLs.js';
3
+ export const trustDatabaseName = "ChargyTrustManagement";
4
+ const anchorsStore = "trustAnchors";
5
+ const deletedKeysStore = "deletedBundledKeys";
6
+ const stationProofsStore = "poiStationProofs";
7
+ export function stationProofStorageId(policyId, evseId, text) {
8
+ const documentHash = toHex(hash('sha256', new TextEncoder().encode(text)));
9
+ return toHex(hash('sha256', new TextEncoder().encode(JSON.stringify({ policyId, evseId, documentHash }))));
10
+ }
11
+ function proofPolicyRange(policyId) {
12
+ return IDBKeyRange.bound([policyId, ''], [policyId, '\uffff', '\uffff']);
13
+ }
14
+ function deletePolicyProofs(transaction, policyId) {
15
+ const request = transaction.objectStore(stationProofsStore).index('byPolicyTime').openCursor(proofPolicyRange(policyId));
16
+ request.onsuccess = () => { const cursor = request.result; if (cursor !== null) {
17
+ cursor.delete();
18
+ cursor.continue();
19
+ } };
20
+ }
21
+ /** Names/descriptions do not create duplicates between compact and URL forms. */
22
+ export function trustAnchorStorageId(anchor) {
23
+ return trustPolicyId(anchor);
24
+ }
25
+ function object(value) {
26
+ if (value === null || typeof value !== "object" || Array.isArray(value))
27
+ throw new Error("Invalid trust management record");
28
+ return value;
29
+ }
30
+ function readAnchor(value) {
31
+ const record = object(value);
32
+ if (typeof record["id"] !== "string" || typeof record["qrCode"] !== "string" ||
33
+ typeof record["sourceText"] !== "string" || typeof record["importedAt"] !== "string" ||
34
+ !Number.isFinite(Date.parse(record["importedAt"])))
35
+ throw new Error("Invalid stored trust anchor");
36
+ const anchor = TrustAnchor.parse(record["qrCode"]);
37
+ if (trustAnchorStorageId(anchor) !== record["id"])
38
+ throw new Error("Stored trust anchor identity does not match its content");
39
+ const trustedKeys = [];
40
+ if (record["trustedKeys"] !== undefined) {
41
+ if (!Array.isArray(record["trustedKeys"]))
42
+ throw new Error("Invalid manual key trust");
43
+ for (const entry of record["trustedKeys"]) {
44
+ const key = object(entry);
45
+ if (typeof key["id"] !== "string" || !anchor.keys.includes(key["id"]) ||
46
+ typeof key["acceptedAt"] !== "string" || !Number.isFinite(Date.parse(key["acceptedAt"])) ||
47
+ trustedKeys.some(existing => existing.id === key["id"]))
48
+ throw new Error("Invalid manual key trust");
49
+ trustedKeys.push({ id: key["id"], acceptedAt: key["acceptedAt"] });
50
+ }
51
+ }
52
+ let downloadedData;
53
+ if (record["downloadedData"] !== undefined) {
54
+ const data = object(record["downloadedData"]);
55
+ if (typeof data["sourceURL"] !== "string" || typeof data["text"] !== "string" ||
56
+ typeof data["downloadedAt"] !== "string" || !Number.isFinite(Date.parse(data["downloadedAt"])))
57
+ throw new Error("Invalid downloaded trust anchor data");
58
+ if (data['origin'] !== undefined && data['origin'] !== 'embedded')
59
+ throw new Error('Invalid KeyStatement origin');
60
+ downloadedData = { sourceURL: data["sourceURL"], text: data["text"], downloadedAt: data["downloadedAt"],
61
+ ...(data['origin'] === 'embedded' ? { origin: 'embedded' } : {}) };
62
+ }
63
+ const transitions = record['transitions'];
64
+ if (transitions !== undefined && (!Array.isArray(transitions) || transitions.length > 32 || new TextEncoder().encode(JSON.stringify(transitions)).length > 8 * 1024 * 1024 || transitions.some(value => {
65
+ const item = object(value);
66
+ return typeof item['text'] !== 'string' || typeof item['acceptedAt'] !== 'string' || !Number.isFinite(Date.parse(item['acceptedAt']));
67
+ })))
68
+ throw new Error('Invalid stored trust transitions');
69
+ return { id: record["id"], qrCode: record["qrCode"], sourceText: record["sourceText"], importedAt: record["importedAt"], trustedKeys,
70
+ ...(transitions === undefined ? {} : { transitions: transitions }),
71
+ ...(downloadedData === undefined ? {} : { downloadedData }) };
72
+ }
73
+ function readStationProof(value) {
74
+ const raw = object(value);
75
+ const fields = ['id', 'anchorPolicyId', 'anchorQRCode', 'evseId', 'sourceURL', 'downloadedAt', 'checkedAt', 'text'];
76
+ for (const field of fields)
77
+ if (typeof raw[field] !== 'string')
78
+ throw new Error('Invalid saved station proof');
79
+ const record = raw;
80
+ if (raw['origin'] !== undefined && raw['origin'] !== 'embedded')
81
+ throw new Error('Invalid station proof origin');
82
+ const anchor = TrustAnchor.parse(record.anchorQRCode);
83
+ const effective = record.effectiveAnchorQRCode === undefined ? anchor : TrustAnchor.parse(record.effectiveAnchorQRCode);
84
+ if (trustAnchorStorageId(anchor) !== record.anchorPolicyId || stationEVSEId(record.evseId) !== record.evseId ||
85
+ (record.origin === undefined ? !effective.urls.some(base => stationProofURL(base, record.evseId) === record.sourceURL)
86
+ : !record.sourceURL.startsWith('input:')) ||
87
+ !Number.isFinite(Date.parse(record.downloadedAt)) || !Number.isFinite(Date.parse(record.checkedAt)) ||
88
+ stationProofStorageId(record.anchorPolicyId, record.evseId, record.text) !== record.id)
89
+ throw new Error('Saved station proof provenance does not match its content');
90
+ return record;
91
+ }
92
+ /** Version 2 adds a proof cache, retaining the version-1 anchors and local decisions. */
93
+ export class TrustStore {
94
+ /** Compare the complete reviewed policy and exclusions in the same transaction; concurrent decisions cannot be overwritten. */
95
+ async appendTrustTransition(expected, expectedDeleted, text, acceptedAt, validate) {
96
+ const db = await this.open();
97
+ await new Promise((resolve, reject) => {
98
+ const tx = db.transaction([anchorsStore, deletedKeysStore], 'readwrite'), store = tx.objectStore(anchorsStore), request = store.get(expected.id), excluded = tx.objectStore(deletedKeysStore).getAll();
99
+ let failure;
100
+ let remaining = 2;
101
+ const ready = () => {
102
+ if (--remaining > 0)
103
+ return;
104
+ try {
105
+ const record = readAnchor(request.result), deleted = readDeletedKeys(excluded.result);
106
+ if (JSON.stringify(record) !== JSON.stringify(readAnchor(expected)) || JSON.stringify([...deleted].sort()) !== JSON.stringify([...expectedDeleted].sort()))
107
+ throw new Error('Local policy or trust changed after transition review');
108
+ validate(record, deleted);
109
+ const transitions = [...record.transitions ?? [], { text, acceptedAt }];
110
+ if (transitions.length > 32 || new TextEncoder().encode(JSON.stringify(transitions)).length > 8 * 1024 * 1024)
111
+ throw new Error('Trust-transition storage capacity reached');
112
+ store.put({ ...record, transitions });
113
+ }
114
+ catch (error) {
115
+ failure = error;
116
+ tx.abort();
117
+ }
118
+ };
119
+ request.onsuccess = ready;
120
+ excluded.onsuccess = ready;
121
+ tx.oncomplete = () => { resolve(); };
122
+ tx.onabort = () => { reject(failure instanceof Error ? failure : tx.error ?? new Error('Could not store trust transition')); };
123
+ });
124
+ }
125
+ connection = null;
126
+ async open() {
127
+ if (this.connection !== null)
128
+ return this.connection;
129
+ const opening = new Promise((resolve, reject) => {
130
+ let blocked = false;
131
+ const request = indexedDB.open(trustDatabaseName, 2);
132
+ request.onupgradeneeded = () => {
133
+ const database = request.result;
134
+ if (!database.objectStoreNames.contains(anchorsStore))
135
+ database.createObjectStore(anchorsStore, { keyPath: "id" });
136
+ if (!database.objectStoreNames.contains(deletedKeysStore))
137
+ database.createObjectStore(deletedKeysStore, { keyPath: "id" });
138
+ if (!database.objectStoreNames.contains(stationProofsStore)) {
139
+ const proofs = database.createObjectStore(stationProofsStore, { keyPath: 'id' });
140
+ proofs.createIndex('byPolicyTime', ['anchorPolicyId', 'downloadedAt', 'id']);
141
+ }
142
+ };
143
+ request.onerror = () => { reject(request.error ?? new Error("Could not open trust management storage")); };
144
+ request.onblocked = () => { blocked = true; reject(new Error("Trust management storage is blocked by another tab")); };
145
+ request.onsuccess = () => {
146
+ const database = request.result;
147
+ if (blocked) {
148
+ database.close();
149
+ return;
150
+ }
151
+ database.onversionchange = () => { database.close(); this.connection = null; };
152
+ database.onclose = () => { this.connection = null; };
153
+ resolve(database);
154
+ };
155
+ });
156
+ this.connection = opening.catch((error) => { this.connection = null; throw error; });
157
+ return this.connection;
158
+ }
159
+ async transaction(name, mode, run, signal) {
160
+ const database = await this.open();
161
+ signal?.throwIfAborted();
162
+ return new Promise((resolve, reject) => {
163
+ const names = typeof name === 'string' ? [name] : [...name];
164
+ const transaction = database.transaction(names, mode);
165
+ const abort = () => { try {
166
+ transaction.abort();
167
+ }
168
+ catch { /* Already committed. */ } };
169
+ signal?.addEventListener("abort", abort, { once: true });
170
+ let result = null;
171
+ transaction.oncomplete = () => {
172
+ signal?.removeEventListener("abort", abort);
173
+ if (result === null)
174
+ reject(new Error("Trust management operation returned no result"));
175
+ else
176
+ resolve(result.value);
177
+ };
178
+ transaction.onabort = () => {
179
+ signal?.removeEventListener("abort", abort);
180
+ reject(transaction.error ?? new Error("Trust management operation was aborted"));
181
+ };
182
+ transaction.onerror = () => { reject(transaction.error ?? new Error("Trust management operation failed")); };
183
+ try {
184
+ run(transaction.objectStore(names[0] ?? anchorsStore), value => { result = { value }; });
185
+ }
186
+ catch (error) {
187
+ transaction.abort();
188
+ reject(error instanceof Error ? error : new Error("Trust management operation failed"));
189
+ }
190
+ });
191
+ }
192
+ async listAnchors() {
193
+ const values = await this.transaction(anchorsStore, "readonly", (store, result) => {
194
+ const request = store.getAll();
195
+ request.onsuccess = () => { result(request.result); };
196
+ });
197
+ return values.map(readAnchor).sort((a, b) => b.importedAt.localeCompare(a.importedAt));
198
+ }
199
+ async hasAnchor(anchor) {
200
+ return this.transaction(anchorsStore, "readonly", (store, result) => {
201
+ const request = store.getKey(trustAnchorStorageId(anchor));
202
+ request.onsuccess = () => { result(request.result !== undefined); };
203
+ });
204
+ }
205
+ async getAnchor(anchor) {
206
+ const value = await this.transaction(anchorsStore, "readonly", (store, result) => {
207
+ const request = store.get(trustAnchorStorageId(anchor));
208
+ request.onsuccess = () => { result(request.result); };
209
+ });
210
+ return value === undefined ? undefined : readAnchor(value);
211
+ }
212
+ /** An authorization snapshot must not mix an anchor and exclusions read from different transactions. */
213
+ async trustSnapshot(anchorPolicyId) {
214
+ const { records, deleted } = await this.readTrustSnapshot(anchorPolicyId);
215
+ return { record: records[0], deleted };
216
+ }
217
+ async listTrustSnapshot() {
218
+ return this.readTrustSnapshot();
219
+ }
220
+ async readTrustSnapshot(anchorPolicyId) {
221
+ const database = await this.open();
222
+ return new Promise((resolve, reject) => {
223
+ const transaction = database.transaction([anchorsStore, deletedKeysStore], 'readonly');
224
+ const anchors = transaction.objectStore(anchorsStore);
225
+ const request = anchorPolicyId === undefined ? anchors.getAll() : anchors.get(anchorPolicyId);
226
+ const exclusions = transaction.objectStore(deletedKeysStore).getAll();
227
+ transaction.onabort = () => { reject(transaction.error ?? new Error('Could not read POI trust decisions')); };
228
+ transaction.onerror = () => { reject(transaction.error ?? new Error('Could not read POI trust decisions')); };
229
+ transaction.oncomplete = () => {
230
+ try {
231
+ const values = anchorPolicyId === undefined ? request.result
232
+ : request.result === undefined ? [] : [request.result];
233
+ const records = values.map(readAnchor).sort((a, b) => b.importedAt.localeCompare(a.importedAt));
234
+ resolve({ records, deleted: readDeletedKeys(exclusions.result) });
235
+ }
236
+ catch (error) {
237
+ reject(error instanceof Error ? error : new Error('Invalid POI trust snapshot'));
238
+ }
239
+ };
240
+ });
241
+ }
242
+ /** A separate user action; import never calls this. Updating one key preserves concurrent decisions. */
243
+ async setKeyTrust(anchorId, keyId, trusted) {
244
+ return this.transaction(anchorsStore, "readwrite", (store, result) => {
245
+ const request = store.get(anchorId);
246
+ request.onsuccess = () => {
247
+ try {
248
+ const record = readAnchor(request.result);
249
+ if (!TrustAnchor.parse(record.qrCode).keys.includes(keyId))
250
+ throw new Error("The key is not part of this trust anchor");
251
+ const keys = [...(record.trustedKeys ?? [])];
252
+ if (trusted && !keys.some(key => key.id === keyId))
253
+ keys.push({ id: keyId, acceptedAt: new Date().toISOString() });
254
+ store.put({ ...record, trustedKeys: trusted ? keys : keys.filter(key => key.id !== keyId) });
255
+ result(undefined);
256
+ }
257
+ catch {
258
+ store.transaction.abort();
259
+ }
260
+ };
261
+ });
262
+ }
263
+ /** The unique-key check and insertion share one transaction, including across tabs. */
264
+ async importAnchor(anchor, sourceText, downloadedData, signal) {
265
+ const record = {
266
+ id: trustAnchorStorageId(anchor), qrCode: anchor.toQRCode(), sourceText,
267
+ importedAt: new Date().toISOString(), ...(downloadedData === undefined ? {} : { downloadedData })
268
+ };
269
+ return this.transaction(anchorsStore, "readwrite", (store, result) => {
270
+ const request = store.get(record.id);
271
+ request.onsuccess = () => {
272
+ if (request.result !== undefined) {
273
+ if (downloadedData !== undefined && (readAnchor(request.result).transitions?.length ?? 0) === 0) {
274
+ try {
275
+ store.put({ ...readAnchor(request.result), downloadedData });
276
+ }
277
+ catch {
278
+ store.transaction.abort();
279
+ return;
280
+ }
281
+ }
282
+ result("exists");
283
+ }
284
+ else {
285
+ store.add(record);
286
+ result("imported");
287
+ }
288
+ };
289
+ }, signal);
290
+ }
291
+ async deleteAnchor(id) {
292
+ return this.transaction([anchorsStore, stationProofsStore], "readwrite", (store, result) => {
293
+ store.delete(id);
294
+ deletePolicyProofs(store.transaction, id);
295
+ result(undefined);
296
+ });
297
+ }
298
+ /** Delete only the selected identity's policies, never every operator claiming the same network ID. */
299
+ async deleteRoamingNetwork(anchorPolicyIds) {
300
+ const selected = new Set(anchorPolicyIds);
301
+ return this.transaction([anchorsStore, stationProofsStore], "readwrite", (store, result) => {
302
+ const request = store.getAll();
303
+ request.onsuccess = () => {
304
+ try {
305
+ const records = request.result.map(readAnchor)
306
+ .filter(record => selected.has(record.id));
307
+ for (const record of records) {
308
+ store.delete(record.id);
309
+ deletePolicyProofs(store.transaction, record.id);
310
+ }
311
+ result(records.length);
312
+ }
313
+ catch {
314
+ store.transaction.abort();
315
+ }
316
+ };
317
+ });
318
+ }
319
+ async deletedBundledKeyIds() {
320
+ const values = await this.transaction(deletedKeysStore, "readonly", (store, result) => {
321
+ const request = store.getAll();
322
+ request.onsuccess = () => { result(request.result); };
323
+ });
324
+ return readDeletedKeys(values);
325
+ }
326
+ async deleteBundledKey(id) {
327
+ if (!/^[0-9a-f]{64}$/.test(id))
328
+ throw new Error("Invalid public key ID");
329
+ return this.transaction(deletedKeysStore, "readwrite", (store, result) => { store.put({ id }); result(undefined); });
330
+ }
331
+ async restoreBundledKey(id) {
332
+ return this.transaction(deletedKeysStore, "readwrite", (store, result) => { store.delete(id); result(undefined); });
333
+ }
334
+ async saveStationProof(proof, signal) {
335
+ const record = readStationProof({
336
+ id: stationProofStorageId(proof.context.anchorPolicyId, proof.evseId, proof.document.text),
337
+ anchorPolicyId: proof.context.anchorPolicyId, anchorQRCode: proof.context.evidence.bootstrapAnchorQRCode ?? proof.context.evidence.anchorQRCode,
338
+ effectiveAnchorQRCode: proof.context.evidence.anchorQRCode,
339
+ evseId: proof.evseId, ...proof.document, checkedAt: new Date(proof.context.evaluatedAt).toISOString()
340
+ });
341
+ return this.transaction([anchorsStore, stationProofsStore], 'readwrite', (anchors, result) => {
342
+ const parent = anchors.get(record.anchorPolicyId);
343
+ parent.onsuccess = () => {
344
+ try {
345
+ if (readAnchor(parent.result).id !== record.anchorPolicyId)
346
+ throw new Error('The anchor was removed');
347
+ const proofs = anchors.transaction.objectStore(stationProofsStore);
348
+ const existing = proofs.get(record.id);
349
+ existing.onsuccess = () => {
350
+ try {
351
+ if (existing.result !== undefined) {
352
+ readStationProof(existing.result);
353
+ result('exists');
354
+ }
355
+ else {
356
+ proofs.add(record);
357
+ result('saved');
358
+ }
359
+ }
360
+ catch {
361
+ anchors.transaction.abort();
362
+ }
363
+ };
364
+ }
365
+ catch {
366
+ anchors.transaction.abort();
367
+ }
368
+ };
369
+ }, signal);
370
+ }
371
+ async listStationProofs(policyId, limit = 10) {
372
+ if (!Number.isInteger(limit) || limit < 1 || limit > 100)
373
+ throw new Error('Invalid saved proof limit');
374
+ return this.transaction(stationProofsStore, 'readonly', (store, result) => {
375
+ const records = [];
376
+ const request = store.index('byPolicyTime').openCursor(proofPolicyRange(policyId), 'prev');
377
+ request.onsuccess = () => {
378
+ try {
379
+ const cursor = request.result;
380
+ if (cursor === null || records.length === limit) {
381
+ result(records);
382
+ return;
383
+ }
384
+ records.push(readStationProof(cursor.value));
385
+ cursor.continue();
386
+ }
387
+ catch {
388
+ store.transaction.abort();
389
+ }
390
+ };
391
+ });
392
+ }
393
+ async deleteStationProof(id) {
394
+ return this.transaction(stationProofsStore, 'readwrite', (store, result) => { store.delete(id); result(undefined); });
395
+ }
396
+ }
397
+ function readDeletedKeys(values) {
398
+ return new Set(values.map(value => {
399
+ const id = object(value)["id"];
400
+ if (typeof id !== "string" || !/^[0-9a-f]{64}$/.test(id))
401
+ throw new Error("Invalid deleted public key record");
402
+ return id;
403
+ }));
404
+ }
405
+ export function activeBundledPublicKeys(keys, deleted) {
406
+ return keys.filter(key => !deleted.has(key.id));
407
+ }
408
+ //# sourceMappingURL=trustStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trustStore.js","sourceRoot":"","sources":["../src/trustStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAC,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAIvF,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE9D,MAAM,CAAC,MAAM,iBAAiB,GAAG,uBAAuB,CAAC;AACzD,MAAM,YAAY,GAAG,cAAc,CAAC;AACpC,MAAM,gBAAgB,GAAG,oBAAoB,CAAC;AAC9C,MAAM,kBAAkB,GAAG,kBAAkB,CAAC;AAgB9C,MAAM,UAAU,qBAAqB,CAAC,QAAgB,EAAE,MAAc,EAAE,IAAY;IAChF,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,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Q,EAAE,CAAC;gBACtB,CAAC;gBACD,MAAM,CAAC;oBAAC,KAAK,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;gBAAC,CAAC;YACxC,CAAC,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC;IAEM,KAAK,CAAC,kBAAkB,CAAC,EAAU;QACtC,OAAO,IAAI,CAAC,WAAW,CAAC,kBAAkB,EAAE,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1H,CAAC;CACJ;AAED,SAAS,eAAe,CAAC,MAA0B;IAC/C,OAAO,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;QAC9B,MAAM,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC;QAC/B,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;YACpD,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACzD,OAAO,EAAE,CAAC;IACd,CAAC,CAAC,CAAC,CAAC;AACR,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,IAA6B,EAAE,OAA4B;IAC/F,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import { TrustAnchor, hash, toHex,trustPolicyId } from '@open-charging-cloud/wwcp-poi';\nimport type { POIPublicKey } from '@open-charging-cloud/wwcp-poi';\nimport type { StoredTrustAnchorData } from './trustAnchorData.js';\nimport type { LoadedStationProof } from './stationProofData.js';\nimport { stationEVSEId, stationProofURL } from './poiURLs.js';\n\nexport const trustDatabaseName = \"ChargyTrustManagement\";\nconst anchorsStore = \"trustAnchors\";\nconst deletedKeysStore = \"deletedBundledKeys\";\nconst stationProofsStore = \"poiStationProofs\";\n\n/** Original cached evidence and provenance; no persisted authorization verdict. */\nexport interface StoredStationProof {\n readonly effectiveAnchorQRCode?:string;\n readonly origin?: 'embedded';\n readonly id: string;\n readonly anchorPolicyId: string;\n readonly anchorQRCode: string;\n readonly evseId: string;\n readonly sourceURL: string;\n readonly downloadedAt: string;\n readonly checkedAt: string;\n readonly text: string;\n}\n\nexport function stationProofStorageId(policyId: string, evseId: string, text: string): string {\n const documentHash = toHex(hash('sha256', new TextEncoder().encode(text)));\n return toHex(hash('sha256', new TextEncoder().encode(JSON.stringify({ policyId, evseId, documentHash }))));\n}\n\nfunction proofPolicyRange(policyId: string): IDBKeyRange {\n return IDBKeyRange.bound([policyId, ''], [policyId, '\\uffff', '\\uffff']);\n}\n\nfunction deletePolicyProofs(transaction: IDBTransaction, policyId: string): void {\n const request = transaction.objectStore(stationProofsStore).index('byPolicyTime').openCursor(proofPolicyRange(policyId));\n request.onsuccess = (): void => { const cursor = request.result; if (cursor !== null) { cursor.delete(); cursor.continue(); } };\n}\n\nexport interface StoredTrustAnchor {\n /** Explicitly accepted original delegation evidence, reverified under current local roots on each operation. */\n readonly transitions?:readonly {readonly text:string;readonly acceptedAt:string}[];\n readonly id: string;\n readonly qrCode: string;\n readonly sourceText: string;\n readonly importedAt: string;\n /** Explicit local decisions, scoped to this exact anchor policy, never global roots. */\n readonly trustedKeys?: readonly ManuallyTrustedKey[];\n readonly downloadedData?: StoredTrustAnchorData;\n}\n\nexport interface ManuallyTrustedKey {\n readonly id: string;\n readonly acceptedAt: string;\n}\n\n/** Names/descriptions do not create duplicates between compact and URL forms. */\nexport function trustAnchorStorageId(anchor: TrustAnchor): string {\n return trustPolicyId(anchor);\n}\n\nfunction object(value: unknown): Record<string, unknown> {\n if (value === null || typeof value !== \"object\" || Array.isArray(value))\n throw new Error(\"Invalid trust management record\");\n return value as Record<string, unknown>;\n}\n\nfunction readAnchor(value: unknown): StoredTrustAnchor {\n const record = object(value);\n if (typeof record[\"id\"] !== \"string\" || typeof record[\"qrCode\"] !== \"string\" ||\n typeof record[\"sourceText\"] !== \"string\" || typeof record[\"importedAt\"] !== \"string\" ||\n !Number.isFinite(Date.parse(record[\"importedAt\"])))\n throw new Error(\"Invalid stored trust anchor\");\n const anchor = TrustAnchor.parse(record[\"qrCode\"]);\n if (trustAnchorStorageId(anchor) !== record[\"id\"])\n throw new Error(\"Stored trust anchor identity does not match its content\");\n const trustedKeys: ManuallyTrustedKey[] = [];\n if (record[\"trustedKeys\"] !== undefined) {\n if (!Array.isArray(record[\"trustedKeys\"]))\n throw new Error(\"Invalid manual key trust\");\n for (const entry of record[\"trustedKeys\"]) {\n const key = object(entry);\n if (typeof key[\"id\"] !== \"string\" || !anchor.keys.includes(key[\"id\"]) ||\n typeof key[\"acceptedAt\"] !== \"string\" || !Number.isFinite(Date.parse(key[\"acceptedAt\"])) ||\n trustedKeys.some(existing => existing.id === key[\"id\"]))\n throw new Error(\"Invalid manual key trust\");\n trustedKeys.push({ id: key[\"id\"], acceptedAt: key[\"acceptedAt\"] });\n }\n }\n let downloadedData: StoredTrustAnchorData | undefined;\n if (record[\"downloadedData\"] !== undefined) {\n const data = object(record[\"downloadedData\"]);\n if (typeof data[\"sourceURL\"] !== \"string\" || typeof data[\"text\"] !== \"string\" ||\n typeof data[\"downloadedAt\"] !== \"string\" || !Number.isFinite(Date.parse(data[\"downloadedAt\"])))\n throw new Error(\"Invalid downloaded trust anchor data\");\n if (data['origin'] !== undefined && data['origin'] !== 'embedded')\n throw new Error('Invalid KeyStatement origin');\n downloadedData = { sourceURL: data[\"sourceURL\"], text: data[\"text\"], downloadedAt: data[\"downloadedAt\"],\n ...(data['origin'] === 'embedded' ? { origin: 'embedded' as const } : {}) };\n }\n const transitions=record['transitions'];\n if(transitions!==undefined&&(!Array.isArray(transitions)||transitions.length>32||new TextEncoder().encode(JSON.stringify(transitions)).length>8*1024*1024||transitions.some(value=>{\n const item=object(value);return typeof item['text']!=='string'||typeof item['acceptedAt']!=='string'||!Number.isFinite(Date.parse(item['acceptedAt']));\n })))throw new Error('Invalid stored trust transitions');\n return { id: record[\"id\"], qrCode: record[\"qrCode\"], sourceText: record[\"sourceText\"], importedAt: record[\"importedAt\"], trustedKeys,\n ...(transitions===undefined?{}:{transitions:transitions as {text:string;acceptedAt:string}[]}),\n ...(downloadedData === undefined ? {} : { downloadedData }) };\n}\n\nfunction readStationProof(value: unknown): StoredStationProof {\n const raw = object(value);\n const fields = ['id', 'anchorPolicyId', 'anchorQRCode', 'evseId', 'sourceURL', 'downloadedAt', 'checkedAt', 'text'] as const;\n for (const field of fields)\n if (typeof raw[field] !== 'string')\n throw new Error('Invalid saved station proof');\n const record = raw as unknown as StoredStationProof;\n if (raw['origin'] !== undefined && raw['origin'] !== 'embedded')\n throw new Error('Invalid station proof origin');\n const anchor = TrustAnchor.parse(record.anchorQRCode);\n const effective=record.effectiveAnchorQRCode===undefined?anchor:TrustAnchor.parse(record.effectiveAnchorQRCode);\n if (trustAnchorStorageId(anchor) !== record.anchorPolicyId || stationEVSEId(record.evseId) !== record.evseId ||\n (record.origin === undefined ? !effective.urls.some(base => stationProofURL(base, record.evseId) === record.sourceURL)\n : !record.sourceURL.startsWith('input:')) ||\n !Number.isFinite(Date.parse(record.downloadedAt)) || !Number.isFinite(Date.parse(record.checkedAt)) ||\n stationProofStorageId(record.anchorPolicyId, record.evseId, record.text) !== record.id)\n throw new Error('Saved station proof provenance does not match its content');\n return record;\n}\n\n/** Version 2 adds a proof cache, retaining the version-1 anchors and local decisions. */\nexport class TrustStore {\n /** Compare the complete reviewed policy and exclusions in the same transaction; concurrent decisions cannot be overwritten. */\n public async appendTrustTransition(expected:StoredTrustAnchor,expectedDeleted:ReadonlySet<string>,text:string,acceptedAt:string,\n validate:(record:StoredTrustAnchor,deleted:ReadonlySet<string>)=>void):Promise<void>{\n const db=await this.open();await new Promise<void>((resolve,reject)=>{\n const tx=db.transaction([anchorsStore,deletedKeysStore],'readwrite'),store=tx.objectStore(anchorsStore),request=store.get(expected.id),excluded=tx.objectStore(deletedKeysStore).getAll();\n let failure:unknown;let remaining=2;\n const ready=():void=>{if(--remaining>0)return;try{\n const record=readAnchor(request.result),deleted=readDeletedKeys(excluded.result as unknown[]);\n if(JSON.stringify(record)!==JSON.stringify(readAnchor(expected))||JSON.stringify([...deleted].sort())!==JSON.stringify([...expectedDeleted].sort()))throw new Error('Local policy or trust changed after transition review');\n validate(record,deleted);const transitions=[...record.transitions??[],{text,acceptedAt}];\n if(transitions.length>32||new TextEncoder().encode(JSON.stringify(transitions)).length>8*1024*1024)throw new Error('Trust-transition storage capacity reached');\n store.put({...record,transitions});\n }catch(error){failure=error;tx.abort();}};\n request.onsuccess=ready;excluded.onsuccess=ready;tx.oncomplete=():void=> { resolve(); };tx.onabort=():void=> { reject(failure instanceof Error?failure:tx.error??new Error('Could not store trust transition')); };\n });\n }\n private connection: Promise<IDBDatabase> | null = null;\n\n private async open(): Promise<IDBDatabase> {\n if (this.connection !== null)\n return this.connection;\n const opening = new Promise<IDBDatabase>((resolve, reject) => {\n let blocked = false;\n const request = indexedDB.open(trustDatabaseName, 2);\n request.onupgradeneeded = (): void => {\n const database = request.result;\n if (!database.objectStoreNames.contains(anchorsStore))\n database.createObjectStore(anchorsStore, { keyPath: \"id\" });\n if (!database.objectStoreNames.contains(deletedKeysStore))\n database.createObjectStore(deletedKeysStore, { keyPath: \"id\" });\n if (!database.objectStoreNames.contains(stationProofsStore)) {\n const proofs = database.createObjectStore(stationProofsStore, { keyPath: 'id' });\n proofs.createIndex('byPolicyTime', ['anchorPolicyId', 'downloadedAt', 'id']);\n }\n };\n request.onerror = (): void => { reject(request.error ?? new Error(\"Could not open trust management storage\")); };\n request.onblocked = (): void => { blocked = true; reject(new Error(\"Trust management storage is blocked by another tab\")); };\n request.onsuccess = (): void => {\n const database = request.result;\n if (blocked) { database.close(); return; }\n database.onversionchange = (): void => { database.close(); this.connection = null; };\n database.onclose = (): void => { this.connection = null; };\n resolve(database);\n };\n });\n this.connection = opening.catch((error: unknown) => { this.connection = null; throw error; });\n return this.connection;\n }\n\n private async transaction<T>(name: string | readonly string[], mode: IDBTransactionMode,\n run: (store: IDBObjectStore, result: (value: T) => void) => void,\n signal?: AbortSignal): Promise<T> {\n const database = await this.open();\n signal?.throwIfAborted();\n return new Promise<T>((resolve, reject) => {\n const names = typeof name === 'string' ? [name] : [...name];\n const transaction = database.transaction(names, mode);\n const abort = (): void => { try { transaction.abort(); } catch { /* Already committed. */ } };\n signal?.addEventListener(\"abort\", abort, { once: true });\n let result: { value: T } | null = null;\n transaction.oncomplete = (): void => {\n signal?.removeEventListener(\"abort\", abort);\n if (result === null)\n reject(new Error(\"Trust management operation returned no result\"));\n else\n resolve(result.value);\n };\n transaction.onabort = (): void => {\n signal?.removeEventListener(\"abort\", abort);\n reject(transaction.error ?? new Error(\"Trust management operation was aborted\"));\n };\n transaction.onerror = (): void => { reject(transaction.error ?? new Error(\"Trust management operation failed\")); };\n try {\n run(transaction.objectStore(names[0] ?? anchorsStore), value => { result = { value }; });\n }\n catch (error) {\n transaction.abort();\n reject(error instanceof Error ? error : new Error(\"Trust management operation failed\"));\n }\n });\n }\n\n public async listAnchors(): Promise<readonly StoredTrustAnchor[]> {\n const values = await this.transaction<unknown[]>(anchorsStore, \"readonly\", (store, result) => {\n const request = store.getAll();\n request.onsuccess = (): void => { result(request.result as unknown[]); };\n });\n return values.map(readAnchor).sort((a, b) => b.importedAt.localeCompare(a.importedAt));\n }\n\n public async hasAnchor(anchor: TrustAnchor): Promise<boolean> {\n return this.transaction(anchorsStore, \"readonly\", (store, result) => {\n const request = store.getKey(trustAnchorStorageId(anchor));\n request.onsuccess = (): void => { result(request.result !== undefined); };\n });\n }\n\n public async getAnchor(anchor: TrustAnchor): Promise<StoredTrustAnchor | undefined> {\n const value = await this.transaction<unknown>(anchorsStore, \"readonly\", (store, result) => {\n const request = store.get(trustAnchorStorageId(anchor));\n request.onsuccess = (): void => { result(request.result); };\n });\n return value === undefined ? undefined : readAnchor(value);\n }\n\n /** An authorization snapshot must not mix an anchor and exclusions read from different transactions. */\n public async trustSnapshot(anchorPolicyId: string): Promise<{\n readonly record: StoredTrustAnchor | undefined; readonly deleted: ReadonlySet<string>;\n }> {\n const { records, deleted } = await this.readTrustSnapshot(anchorPolicyId);\n return { record: records[0], deleted };\n }\n\n public async listTrustSnapshot(): Promise<{\n readonly records: readonly StoredTrustAnchor[]; readonly deleted: ReadonlySet<string>;\n }> {\n return this.readTrustSnapshot();\n }\n\n private async readTrustSnapshot(anchorPolicyId?: string): Promise<{\n readonly records: readonly StoredTrustAnchor[]; readonly deleted: ReadonlySet<string>;\n }> {\n const database = await this.open();\n return new Promise((resolve, reject) => {\n const transaction = database.transaction([anchorsStore, deletedKeysStore], 'readonly');\n const anchors = transaction.objectStore(anchorsStore);\n const request = anchorPolicyId === undefined ? anchors.getAll() : anchors.get(anchorPolicyId);\n const exclusions = transaction.objectStore(deletedKeysStore).getAll();\n transaction.onabort = (): void => { reject(transaction.error ?? new Error('Could not read POI trust decisions')); };\n transaction.onerror = (): void => { reject(transaction.error ?? new Error('Could not read POI trust decisions')); };\n transaction.oncomplete = (): void => {\n try {\n const values = anchorPolicyId === undefined ? request.result as unknown[]\n : request.result === undefined ? [] : [request.result as unknown];\n const records = values.map(readAnchor).sort((a, b) => b.importedAt.localeCompare(a.importedAt));\n resolve({ records, deleted: readDeletedKeys(exclusions.result as unknown[]) });\n }\n catch (error) { reject(error instanceof Error ? error : new Error('Invalid POI trust snapshot')); }\n };\n });\n }\n\n /** A separate user action; import never calls this. Updating one key preserves concurrent decisions. */\n public async setKeyTrust(anchorId: string, keyId: string, trusted: boolean): Promise<void> {\n return this.transaction(anchorsStore, \"readwrite\", (store, result) => {\n const request = store.get(anchorId);\n request.onsuccess = (): void => {\n try {\n const record = readAnchor(request.result);\n if (!TrustAnchor.parse(record.qrCode).keys.includes(keyId))\n throw new Error(\"The key is not part of this trust anchor\");\n const keys = [...(record.trustedKeys ?? [])];\n if (trusted && !keys.some(key => key.id === keyId))\n keys.push({ id: keyId, acceptedAt: new Date().toISOString() });\n store.put({ ...record, trustedKeys: trusted ? keys : keys.filter(key => key.id !== keyId) });\n result(undefined);\n }\n catch {\n store.transaction.abort();\n }\n };\n });\n }\n\n /** The unique-key check and insertion share one transaction, including across tabs. */\n public async importAnchor(anchor: TrustAnchor, sourceText: string, downloadedData?: StoredTrustAnchorData,\n signal?: AbortSignal): Promise<\"imported\" | \"exists\"> {\n const record: StoredTrustAnchor = {\n id: trustAnchorStorageId(anchor), qrCode: anchor.toQRCode(), sourceText,\n importedAt: new Date().toISOString(), ...(downloadedData === undefined ? {} : { downloadedData })\n };\n return this.transaction(anchorsStore, \"readwrite\", (store, result) => {\n const request = store.get(record.id);\n request.onsuccess = (): void => {\n if (request.result !== undefined) {\n if (downloadedData !== undefined && (readAnchor(request.result).transitions?.length??0)===0) {\n try { store.put({ ...readAnchor(request.result), downloadedData }); }\n catch { store.transaction.abort(); return; }\n }\n result(\"exists\");\n }\n else {\n store.add(record);\n result(\"imported\");\n }\n };\n }, signal);\n }\n\n public async deleteAnchor(id: string): Promise<void> {\n return this.transaction([anchorsStore, stationProofsStore], \"readwrite\", (store, result) => {\n store.delete(id); deletePolicyProofs(store.transaction, id); result(undefined);\n });\n }\n\n /** Delete only the selected identity's policies, never every operator claiming the same network ID. */\n public async deleteRoamingNetwork(anchorPolicyIds: readonly string[]): Promise<number> {\n const selected = new Set(anchorPolicyIds);\n return this.transaction([anchorsStore, stationProofsStore], \"readwrite\", (store, result) => {\n const request = store.getAll();\n request.onsuccess = (): void => {\n try {\n const records = (request.result as unknown[]).map(readAnchor)\n .filter(record => selected.has(record.id));\n for (const record of records) {\n store.delete(record.id);\n deletePolicyProofs(store.transaction, record.id);\n }\n result(records.length);\n }\n catch {\n store.transaction.abort();\n }\n };\n });\n }\n\n public async deletedBundledKeyIds(): Promise<ReadonlySet<string>> {\n const values = await this.transaction<unknown[]>(deletedKeysStore, \"readonly\", (store, result) => {\n const request = store.getAll();\n request.onsuccess = (): void => { result(request.result as unknown[]); };\n });\n return readDeletedKeys(values);\n }\n\n public async deleteBundledKey(id: string): Promise<void> {\n if (!/^[0-9a-f]{64}$/.test(id))\n throw new Error(\"Invalid public key ID\");\n return this.transaction(deletedKeysStore, \"readwrite\", (store, result) => { store.put({ id }); result(undefined); });\n }\n\n public async restoreBundledKey(id: string): Promise<void> {\n return this.transaction(deletedKeysStore, \"readwrite\", (store, result) => { store.delete(id); result(undefined); });\n }\n\n public async saveStationProof(proof: LoadedStationProof, signal?: AbortSignal): Promise<'saved' | 'exists'> {\n const record = readStationProof({\n id: stationProofStorageId(proof.context.anchorPolicyId, proof.evseId, proof.document.text),\n anchorPolicyId: proof.context.anchorPolicyId, anchorQRCode: proof.context.evidence.bootstrapAnchorQRCode??proof.context.evidence.anchorQRCode,\n effectiveAnchorQRCode:proof.context.evidence.anchorQRCode,\n evseId: proof.evseId, ...proof.document, checkedAt: new Date(proof.context.evaluatedAt).toISOString()\n });\n return this.transaction([anchorsStore, stationProofsStore], 'readwrite', (anchors, result) => {\n const parent = anchors.get(record.anchorPolicyId);\n parent.onsuccess = (): void => {\n try {\n if (readAnchor(parent.result).id !== record.anchorPolicyId)\n throw new Error('The anchor was removed');\n const proofs = anchors.transaction.objectStore(stationProofsStore);\n const existing = proofs.get(record.id);\n existing.onsuccess = (): void => {\n try {\n if (existing.result !== undefined) { readStationProof(existing.result); result('exists'); }\n else { proofs.add(record); result('saved'); }\n }\n catch { anchors.transaction.abort(); }\n };\n }\n catch { anchors.transaction.abort(); }\n };\n }, signal);\n }\n\n public async listStationProofs(policyId: string, limit: number = 10): Promise<readonly StoredStationProof[]> {\n if (!Number.isInteger(limit) || limit < 1 || limit > 100)\n throw new Error('Invalid saved proof limit');\n return this.transaction(stationProofsStore, 'readonly', (store, result) => {\n const records: StoredStationProof[] = [];\n const request = store.index('byPolicyTime').openCursor(proofPolicyRange(policyId), 'prev');\n request.onsuccess = (): void => {\n try {\n const cursor = request.result;\n if (cursor === null || records.length === limit) { result(records); return; }\n records.push(readStationProof(cursor.value));\n cursor.continue();\n }\n catch { store.transaction.abort(); }\n };\n });\n }\n\n public async deleteStationProof(id: string): Promise<void> {\n return this.transaction(stationProofsStore, 'readwrite', (store, result) => { store.delete(id); result(undefined); });\n }\n}\n\nfunction readDeletedKeys(values: readonly unknown[]): ReadonlySet<string> {\n return new Set(values.map(value => {\n const id = object(value)[\"id\"];\n if (typeof id !== \"string\" || !/^[0-9a-f]{64}$/.test(id))\n throw new Error(\"Invalid deleted public key record\");\n return id;\n }));\n}\n\nexport function activeBundledPublicKeys(keys: readonly POIPublicKey[], deleted: ReadonlySet<string>): readonly POIPublicKey[] {\n return keys.filter(key => !deleted.has(key.id));\n}\n"]}
@@ -0,0 +1,5 @@
1
+ import type { POIPublicKey } from '@open-charging-cloud/wwcp-poi';
2
+ import type { TrustStore, StoredTrustAnchor } from './trustStore.js';
3
+ /** An explicit local decision; pasted/downloaded data never changes trust by itself. */
4
+ export declare function renderTrustTransitionManager(parent: HTMLElement, record: StoredTrustAnchor, store: TrustStore, keys: readonly POIPublicKey[], localize: (key: string) => string, isCurrent: () => boolean, refresh: () => void): void;
5
+ //# sourceMappingURL=trustTransitionView.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trustTransitionView.d.ts","sourceRoot":"","sources":["../src/trustTransitionView.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,+BAA+B,CAAC;AAEhE,OAAO,KAAK,EAAC,UAAU,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAIlE,wFAAwF;AACxF,wBAAgB,4BAA4B,CAAC,MAAM,EAAC,WAAW,EAAC,MAAM,EAAC,iBAAiB,EAAC,KAAK,EAAC,UAAU,EAAC,IAAI,EAAC,SAAS,YAAY,EAAE,EAAC,QAAQ,EAAC,CAAC,GAAG,EAAC,MAAM,KAAG,MAAM,EAAC,SAAS,EAAC,MAAI,OAAO,EAAC,OAAO,EAAC,MAAI,IAAI,GAAE,IAAI,CAuChN"}