@kubohiroya/turbowarp-extension-security-dialog 0.13.0 → 0.13.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.
package/README.ja.md CHANGED
@@ -149,6 +149,10 @@ HTTP(S)のソースから説明を読み取り、相対バナーURLは取得後
149
149
  `entry.state.plusFamily` も指定した行だけに Plus マークを表示します。それ以外の信頼済みの行は、
150
150
  ブランドを含まないチェックで示します。`ExtensionRow` 単体では `plusFamily` プロパティで指定します。
151
151
  拡張が自称するメタデータや、ID の一致だけでは所属を決めません。
152
+ 作品を開くときの一括確認では、作品が `data:` アドレスとして持つ拡張のコードも、
153
+ そのバイト列の SHA-256 をカタログと照合します。一致した行は、カタログに載った拡張と同じ扱い
154
+ (信頼済み・Plus マーク・カタログの画像)になり、読み込み元の欄にカタログ上の提供元のアドレスを添えます
155
+ (`entry.state.listedURL`)。Plus マニフェストの埋め込み行も同じです。一致しない行は従来どおり確認します。
152
156
 
153
157
  TurboWarp ギャラリーの拡張は、公式メタデータとコードの完全な URL を照合して画像を取得します。
154
158
  画像取得とソースの説明取得は並行して進み、操作や実行許可を待たせません。
package/README.md CHANGED
@@ -147,6 +147,10 @@ Execution trust and family membership are separate: only rows with host-confirme
147
147
  `entry.state.plusFamily` use the Plus mark. Other trusted rows use an unbranded check.
148
148
  For a standalone `ExtensionRow`, pass `plusFamily` explicitly after checking the host's Plus
149
149
  catalog. Extension-declared metadata and matching IDs alone do not establish membership.
150
+ When a project opens, an extension the project carries as a `data:` address is matched by the
151
+ SHA-256 of its bytes. A listed digest makes the row trusted, family-marked and pictured like the
152
+ catalog's own, and its source line names the catalog's address for the same code
153
+ (`entry.state.listedURL`); embedded Plus manifest rows do the same. Unlisted bytes are asked about.
150
154
 
151
155
  ### Using one row of the list
152
156
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubohiroya/turbowarp-extension-security-dialog",
3
- "version": "0.13.0",
4
- "revision": "a3facf8ee62f7f1ee960db204865991f44aadf4c",
3
+ "version": "0.13.1",
4
+ "revision": "3f2f7c6e3161a2a3ddb34c4d3a10515e5453318d",
5
5
  "sourceState": "commit"
6
6
  }
@@ -0,0 +1,35 @@
1
+ import type { CatalogEntry } from './catalog.js';
2
+ import type { PreviewCatalog } from './catalog-preview.js';
3
+ import type { ReviewEntry } from './review-types.js';
4
+ /**
5
+ * The SHA-256 of the code a project carries in a `data:` address, or nothing for any other address.
6
+ *
7
+ * A project written for standard TurboWarp holds a Plus extension this way, with no address to
8
+ * check. The digest is what a catalog can vouch for instead, the same way it vouches for the
9
+ * embedded forms of a Plus manifest.
10
+ * @param {string} [url] The extension's address.
11
+ * @returns {Promise<string|undefined>} Lowercase hex, or undefined when there is nothing to digest.
12
+ */
13
+ export declare const inlineCodeDigest: (url: string | undefined) => Promise<string | undefined>;
14
+ /**
15
+ * The catalog row for exactly this code: the same ID, and the same address or the same digest.
16
+ *
17
+ * An address is matched only when it is a real one; a `data:` address carries the bytes, so only
18
+ * its digest can say which catalog row it is. A claimed ID alone never matches.
19
+ * @param {Array<object>} entries The parsed catalog.
20
+ * @param {object} entry The review row.
21
+ * @param {string} [digest] The row's digest, when the caller worked it out.
22
+ * @returns {object|undefined} The catalog row.
23
+ */
24
+ export declare const findCatalogEntry: (entries: readonly CatalogEntry[], entry: ReviewEntry, digest?: string) => CatalogEntry | undefined;
25
+ export interface CatalogMatch {
26
+ item?: CatalogEntry;
27
+ icons: Record<string, string>;
28
+ }
29
+ /**
30
+ * Read a host's catalog at most once, and find rows in it.
31
+ * @param {object} [catalog] The host's catalog port.
32
+ * @returns {Function} The catalog row for a review row, with the host's curated icons; the row is
33
+ * undefined without a usable catalog or a match.
34
+ */
35
+ export declare function createCatalogMatcher(catalog?: PreviewCatalog): (entry: ReviewEntry, signal: AbortSignal, digest?: string) => Promise<CatalogMatch>;
package/dist/index.cjs CHANGED
@@ -495,50 +495,71 @@ function createGalleryPreviewResolver() {
495
495
  };
496
496
  }
497
497
 
498
- // src/catalog-preview.ts
499
- function createCatalogPreviewResolver(catalog) {
498
+ // src/catalog-match.ts
499
+ var hex = (bytes) => Array.from(new Uint8Array(bytes), (byte) => byte.toString(16).padStart(2, "0")).join("");
500
+ var dataURLBytes = (url) => {
501
+ const comma = url.indexOf(",");
502
+ if (!url.startsWith("data:") || comma < 0) throw new Error("Not a data URL");
503
+ const content = url.slice(comma + 1);
504
+ if (!/;base64$/i.test(url.slice(0, comma))) return new TextEncoder().encode(decodeURIComponent(content));
505
+ const binary = atob(content);
506
+ const bytes = new Uint8Array(binary.length);
507
+ for (let index = 0; index < binary.length; index++) bytes[index] = binary.charCodeAt(index);
508
+ return bytes;
509
+ };
510
+ var inlineCodeDigest = async (url) => {
511
+ if (typeof url !== "string" || !url.startsWith("data:")) return;
512
+ try {
513
+ return hex(await globalThis.crypto.subtle.digest("SHA-256", dataURLBytes(url)));
514
+ } catch (e) {
515
+ return;
516
+ }
517
+ };
518
+ var findCatalogEntry = (entries, entry, digest) => {
519
+ const source = entry.source;
520
+ const sha256 = digest != null ? digest : "sha256" in source ? source.sha256 : void 0;
521
+ const inline = "url" in source && source.url.startsWith("data:");
522
+ return entries.find((item) => entry.ids.includes(item.id) && ("url" in source && !inline ? item.url === source.url && (sha256 === void 0 || item.sha256 === sha256) : sha256 !== void 0 && item.sha256 === sha256));
523
+ };
524
+ function createCatalogMatcher(catalog) {
500
525
  let pending;
501
- return async (entry, signal) => {
502
- var _a;
503
- if (!catalog || !((_a = entry.state) == null ? void 0 : _a.plusFamily) || signal.aborted) return;
526
+ return async (entry, signal, digest) => {
527
+ if (!catalog || signal.aborted) return { icons: {} };
504
528
  pending != null ? pending : pending = catalog.read(signal).then((read) => ({
505
529
  entries: read.catalog ? parseExtensionCatalog(read.catalog) : [],
506
530
  icons: read.icons || {}
507
- })).catch(() => ({ entries: [], icons: {} }));
531
+ })).catch(() => {
532
+ pending = void 0;
533
+ return { entries: [], icons: {} };
534
+ });
508
535
  const { entries, icons } = await pending;
536
+ if (signal.aborted) return { icons };
537
+ return { item: findCatalogEntry(entries, entry, digest), icons };
538
+ };
539
+ }
540
+
541
+ // src/catalog-preview.ts
542
+ function createCatalogPreviewResolver(catalog) {
543
+ const match = createCatalogMatcher(catalog);
544
+ return async (entry, signal) => {
545
+ var _a;
546
+ if (!catalog || !((_a = entry.state) == null ? void 0 : _a.plusFamily) || signal.aborted) return;
547
+ const { item, icons } = await match(entry, signal);
509
548
  if (signal.aborted) return;
510
- const source = entry.source;
511
- const item = entries.find((item2) => entry.ids.includes(item2.id) && ("url" in source && !source.url.startsWith("data:") ? item2.url === source.url && (!("sha256" in source) || source.sha256 === item2.sha256) : "sha256" in source && source.sha256 === item2.sha256));
512
549
  return item && (icons[item.id] || item.metadata.banner);
513
550
  };
514
551
  }
515
552
 
516
553
  // src/catalog-resources.ts
517
554
  function createCatalogResourceResolver(catalog) {
518
- let pending;
555
+ const match = createCatalogMatcher(catalog);
519
556
  return async (entry, signal) => {
520
- if (!catalog || signal.aborted) return;
521
- pending != null ? pending : pending = catalog.read(signal).then((read) => read.catalog ? parseExtensionCatalog(read.catalog) : []).catch(() => {
522
- pending = void 0;
523
- return [];
524
- });
525
- const entries = await pending;
526
- if (signal.aborted) return;
557
+ var _a;
527
558
  const source = entry.source;
528
- let digest = "sha256" in source ? source.sha256 : void 0;
529
559
  const inline = "url" in source && source.url.startsWith("data:");
530
- if (inline) {
531
- try {
532
- const bytes = new TextEncoder().encode(decodeExtensionDataURL(source.url));
533
- const hash = await globalThis.crypto.subtle.digest("SHA-256", bytes);
534
- digest = Array.from(new Uint8Array(hash), (byte) => byte.toString(16).padStart(2, "0")).join("");
535
- } catch (e) {
536
- return;
537
- }
538
- }
539
- if (signal.aborted) return;
540
- const item = entries.find((item2) => entry.ids.includes(item2.id) && ("url" in source && !inline ? item2.url === source.url && (digest === void 0 || item2.sha256 === digest) : digest !== void 0 && item2.sha256 === digest));
541
- return item == null ? void 0 : item.metadata.resourceDeclaration;
560
+ const digest = inline ? await inlineCodeDigest(source.url) : void 0;
561
+ if (inline && !digest) return;
562
+ return (_a = (await match(entry, signal, digest)).item) == null ? void 0 : _a.metadata.resourceDeclaration;
542
563
  };
543
564
  }
544
565
 
@@ -798,6 +819,7 @@ var messages = {
798
819
  sourceEmbedded: "Stored in the project",
799
820
  sourceLegacy: "A custom extension address",
800
821
  sourceInline: "Written into the project as a data address",
822
+ sourceListed: " (the same code as published at {url})",
801
823
  creator: "Creator (unverified claim)",
802
824
  creatorUnknown: "Not stated",
803
825
  licenseUnknown: "Not stated",
@@ -857,6 +879,7 @@ var messages = {
857
879
  sourceEmbedded: "\u4F5C\u54C1\u306E\u4E2D\u306B\u3042\u308A\u307E\u3059",
858
880
  sourceLegacy: "\u30AB\u30B9\u30BF\u30E0\u62E1\u5F35\u306E\u30A2\u30C9\u30EC\u30B9",
859
881
  sourceInline: "\u4F5C\u54C1\u306E\u4E2D\u306B data: \u30A2\u30C9\u30EC\u30B9\u3068\u3057\u3066\u66F8\u304B\u308C\u3066\u3044\u307E\u3059",
882
+ sourceListed: "\uFF08\u63D0\u4F9B\u5143 {url} \u3068\u540C\u3058\u30B3\u30FC\u30C9\uFF09",
860
883
  creator: "\u88FD\u4F5C\u8005\uFF08\u672A\u691C\u8A3C\u306E\u7533\u544A\uFF09",
861
884
  creatorUnknown: "\u8A18\u8F09\u306A\u3057",
862
885
  licenseUnknown: "\u8A18\u8F09\u306A\u3057",
package/dist/index.mjs CHANGED
@@ -447,50 +447,71 @@ function createGalleryPreviewResolver() {
447
447
  };
448
448
  }
449
449
 
450
- // src/catalog-preview.ts
451
- function createCatalogPreviewResolver(catalog) {
450
+ // src/catalog-match.ts
451
+ var hex = (bytes) => Array.from(new Uint8Array(bytes), (byte) => byte.toString(16).padStart(2, "0")).join("");
452
+ var dataURLBytes = (url) => {
453
+ const comma = url.indexOf(",");
454
+ if (!url.startsWith("data:") || comma < 0) throw new Error("Not a data URL");
455
+ const content = url.slice(comma + 1);
456
+ if (!/;base64$/i.test(url.slice(0, comma))) return new TextEncoder().encode(decodeURIComponent(content));
457
+ const binary = atob(content);
458
+ const bytes = new Uint8Array(binary.length);
459
+ for (let index = 0; index < binary.length; index++) bytes[index] = binary.charCodeAt(index);
460
+ return bytes;
461
+ };
462
+ var inlineCodeDigest = async (url) => {
463
+ if (typeof url !== "string" || !url.startsWith("data:")) return;
464
+ try {
465
+ return hex(await globalThis.crypto.subtle.digest("SHA-256", dataURLBytes(url)));
466
+ } catch (e) {
467
+ return;
468
+ }
469
+ };
470
+ var findCatalogEntry = (entries, entry, digest) => {
471
+ const source = entry.source;
472
+ const sha256 = digest != null ? digest : "sha256" in source ? source.sha256 : void 0;
473
+ const inline = "url" in source && source.url.startsWith("data:");
474
+ return entries.find((item) => entry.ids.includes(item.id) && ("url" in source && !inline ? item.url === source.url && (sha256 === void 0 || item.sha256 === sha256) : sha256 !== void 0 && item.sha256 === sha256));
475
+ };
476
+ function createCatalogMatcher(catalog) {
452
477
  let pending;
453
- return async (entry, signal) => {
454
- var _a;
455
- if (!catalog || !((_a = entry.state) == null ? void 0 : _a.plusFamily) || signal.aborted) return;
478
+ return async (entry, signal, digest) => {
479
+ if (!catalog || signal.aborted) return { icons: {} };
456
480
  pending != null ? pending : pending = catalog.read(signal).then((read) => ({
457
481
  entries: read.catalog ? parseExtensionCatalog(read.catalog) : [],
458
482
  icons: read.icons || {}
459
- })).catch(() => ({ entries: [], icons: {} }));
483
+ })).catch(() => {
484
+ pending = void 0;
485
+ return { entries: [], icons: {} };
486
+ });
460
487
  const { entries, icons } = await pending;
488
+ if (signal.aborted) return { icons };
489
+ return { item: findCatalogEntry(entries, entry, digest), icons };
490
+ };
491
+ }
492
+
493
+ // src/catalog-preview.ts
494
+ function createCatalogPreviewResolver(catalog) {
495
+ const match = createCatalogMatcher(catalog);
496
+ return async (entry, signal) => {
497
+ var _a;
498
+ if (!catalog || !((_a = entry.state) == null ? void 0 : _a.plusFamily) || signal.aborted) return;
499
+ const { item, icons } = await match(entry, signal);
461
500
  if (signal.aborted) return;
462
- const source = entry.source;
463
- const item = entries.find((item2) => entry.ids.includes(item2.id) && ("url" in source && !source.url.startsWith("data:") ? item2.url === source.url && (!("sha256" in source) || source.sha256 === item2.sha256) : "sha256" in source && source.sha256 === item2.sha256));
464
501
  return item && (icons[item.id] || item.metadata.banner);
465
502
  };
466
503
  }
467
504
 
468
505
  // src/catalog-resources.ts
469
506
  function createCatalogResourceResolver(catalog) {
470
- let pending;
507
+ const match = createCatalogMatcher(catalog);
471
508
  return async (entry, signal) => {
472
- if (!catalog || signal.aborted) return;
473
- pending != null ? pending : pending = catalog.read(signal).then((read) => read.catalog ? parseExtensionCatalog(read.catalog) : []).catch(() => {
474
- pending = void 0;
475
- return [];
476
- });
477
- const entries = await pending;
478
- if (signal.aborted) return;
509
+ var _a;
479
510
  const source = entry.source;
480
- let digest = "sha256" in source ? source.sha256 : void 0;
481
511
  const inline = "url" in source && source.url.startsWith("data:");
482
- if (inline) {
483
- try {
484
- const bytes = new TextEncoder().encode(decodeExtensionDataURL(source.url));
485
- const hash = await globalThis.crypto.subtle.digest("SHA-256", bytes);
486
- digest = Array.from(new Uint8Array(hash), (byte) => byte.toString(16).padStart(2, "0")).join("");
487
- } catch (e) {
488
- return;
489
- }
490
- }
491
- if (signal.aborted) return;
492
- const item = entries.find((item2) => entry.ids.includes(item2.id) && ("url" in source && !inline ? item2.url === source.url && (digest === void 0 || item2.sha256 === digest) : digest !== void 0 && item2.sha256 === digest));
493
- return item == null ? void 0 : item.metadata.resourceDeclaration;
512
+ const digest = inline ? await inlineCodeDigest(source.url) : void 0;
513
+ if (inline && !digest) return;
514
+ return (_a = (await match(entry, signal, digest)).item) == null ? void 0 : _a.metadata.resourceDeclaration;
494
515
  };
495
516
  }
496
517
 
@@ -750,6 +771,7 @@ var messages = {
750
771
  sourceEmbedded: "Stored in the project",
751
772
  sourceLegacy: "A custom extension address",
752
773
  sourceInline: "Written into the project as a data address",
774
+ sourceListed: " (the same code as published at {url})",
753
775
  creator: "Creator (unverified claim)",
754
776
  creatorUnknown: "Not stated",
755
777
  licenseUnknown: "Not stated",
@@ -809,6 +831,7 @@ var messages = {
809
831
  sourceEmbedded: "\u4F5C\u54C1\u306E\u4E2D\u306B\u3042\u308A\u307E\u3059",
810
832
  sourceLegacy: "\u30AB\u30B9\u30BF\u30E0\u62E1\u5F35\u306E\u30A2\u30C9\u30EC\u30B9",
811
833
  sourceInline: "\u4F5C\u54C1\u306E\u4E2D\u306B data: \u30A2\u30C9\u30EC\u30B9\u3068\u3057\u3066\u66F8\u304B\u308C\u3066\u3044\u307E\u3059",
834
+ sourceListed: "\uFF08\u63D0\u4F9B\u5143 {url} \u3068\u540C\u3058\u30B3\u30FC\u30C9\uFF09",
812
835
  creator: "\u88FD\u4F5C\u8005\uFF08\u672A\u691C\u8A3C\u306E\u7533\u544A\uFF09",
813
836
  creatorUnknown: "\u8A18\u8F09\u306A\u3057",
814
837
  licenseUnknown: "\u8A18\u8F09\u306A\u3057",
@@ -68,6 +68,7 @@ var messages = {
68
68
  sourceEmbedded: "Stored in the project",
69
69
  sourceLegacy: "A custom extension address",
70
70
  sourceInline: "Written into the project as a data address",
71
+ sourceListed: " (the same code as published at {url})",
71
72
  creator: "Creator (unverified claim)",
72
73
  creatorUnknown: "Not stated",
73
74
  licenseUnknown: "Not stated",
@@ -127,6 +128,7 @@ var messages = {
127
128
  sourceEmbedded: "\u4F5C\u54C1\u306E\u4E2D\u306B\u3042\u308A\u307E\u3059",
128
129
  sourceLegacy: "\u30AB\u30B9\u30BF\u30E0\u62E1\u5F35\u306E\u30A2\u30C9\u30EC\u30B9",
129
130
  sourceInline: "\u4F5C\u54C1\u306E\u4E2D\u306B data: \u30A2\u30C9\u30EC\u30B9\u3068\u3057\u3066\u66F8\u304B\u308C\u3066\u3044\u307E\u3059",
131
+ sourceListed: "\uFF08\u63D0\u4F9B\u5143 {url} \u3068\u540C\u3058\u30B3\u30FC\u30C9\uFF09",
130
132
  creator: "\u88FD\u4F5C\u8005\uFF08\u672A\u691C\u8A3C\u306E\u7533\u544A\uFF09",
131
133
  creatorUnknown: "\u8A18\u8F09\u306A\u3057",
132
134
  licenseUnknown: "\u8A18\u8F09\u306A\u3057",
@@ -42,6 +42,7 @@ var messages = {
42
42
  sourceEmbedded: "Stored in the project",
43
43
  sourceLegacy: "A custom extension address",
44
44
  sourceInline: "Written into the project as a data address",
45
+ sourceListed: " (the same code as published at {url})",
45
46
  creator: "Creator (unverified claim)",
46
47
  creatorUnknown: "Not stated",
47
48
  licenseUnknown: "Not stated",
@@ -101,6 +102,7 @@ var messages = {
101
102
  sourceEmbedded: "\u4F5C\u54C1\u306E\u4E2D\u306B\u3042\u308A\u307E\u3059",
102
103
  sourceLegacy: "\u30AB\u30B9\u30BF\u30E0\u62E1\u5F35\u306E\u30A2\u30C9\u30EC\u30B9",
103
104
  sourceInline: "\u4F5C\u54C1\u306E\u4E2D\u306B data: \u30A2\u30C9\u30EC\u30B9\u3068\u3057\u3066\u66F8\u304B\u308C\u3066\u3044\u307E\u3059",
105
+ sourceListed: "\uFF08\u63D0\u4F9B\u5143 {url} \u3068\u540C\u3058\u30B3\u30FC\u30C9\uFF09",
104
106
  creator: "\u88FD\u4F5C\u8005\uFF08\u672A\u691C\u8A3C\u306E\u7533\u544A\uFF09",
105
107
  creatorUnknown: "\u8A18\u8F09\u306A\u3057",
106
108
  licenseUnknown: "\u8A18\u8F09\u306A\u3057",
@@ -427,50 +427,71 @@ async function loadExtensionInfo(url, signal) {
427
427
  return { source, metadata };
428
428
  }
429
429
 
430
- // src/catalog-preview.ts
431
- function createCatalogPreviewResolver(catalog) {
430
+ // src/catalog-match.ts
431
+ var hex = (bytes) => Array.from(new Uint8Array(bytes), (byte) => byte.toString(16).padStart(2, "0")).join("");
432
+ var dataURLBytes = (url) => {
433
+ const comma = url.indexOf(",");
434
+ if (!url.startsWith("data:") || comma < 0) throw new Error("Not a data URL");
435
+ const content = url.slice(comma + 1);
436
+ if (!/;base64$/i.test(url.slice(0, comma))) return new TextEncoder().encode(decodeURIComponent(content));
437
+ const binary = atob(content);
438
+ const bytes = new Uint8Array(binary.length);
439
+ for (let index = 0; index < binary.length; index++) bytes[index] = binary.charCodeAt(index);
440
+ return bytes;
441
+ };
442
+ var inlineCodeDigest = async (url) => {
443
+ if (typeof url !== "string" || !url.startsWith("data:")) return;
444
+ try {
445
+ return hex(await globalThis.crypto.subtle.digest("SHA-256", dataURLBytes(url)));
446
+ } catch (e) {
447
+ return;
448
+ }
449
+ };
450
+ var findCatalogEntry = (entries, entry, digest) => {
451
+ const source = entry.source;
452
+ const sha256 = digest != null ? digest : "sha256" in source ? source.sha256 : void 0;
453
+ const inline = "url" in source && source.url.startsWith("data:");
454
+ return entries.find((item) => entry.ids.includes(item.id) && ("url" in source && !inline ? item.url === source.url && (sha256 === void 0 || item.sha256 === sha256) : sha256 !== void 0 && item.sha256 === sha256));
455
+ };
456
+ function createCatalogMatcher(catalog) {
432
457
  let pending;
433
- return async (entry, signal) => {
434
- var _a;
435
- if (!catalog || !((_a = entry.state) == null ? void 0 : _a.plusFamily) || signal.aborted) return;
458
+ return async (entry, signal, digest) => {
459
+ if (!catalog || signal.aborted) return { icons: {} };
436
460
  pending != null ? pending : pending = catalog.read(signal).then((read) => ({
437
461
  entries: read.catalog ? parseExtensionCatalog(read.catalog) : [],
438
462
  icons: read.icons || {}
439
- })).catch(() => ({ entries: [], icons: {} }));
463
+ })).catch(() => {
464
+ pending = void 0;
465
+ return { entries: [], icons: {} };
466
+ });
440
467
  const { entries, icons } = await pending;
468
+ if (signal.aborted) return { icons };
469
+ return { item: findCatalogEntry(entries, entry, digest), icons };
470
+ };
471
+ }
472
+
473
+ // src/catalog-preview.ts
474
+ function createCatalogPreviewResolver(catalog) {
475
+ const match = createCatalogMatcher(catalog);
476
+ return async (entry, signal) => {
477
+ var _a;
478
+ if (!catalog || !((_a = entry.state) == null ? void 0 : _a.plusFamily) || signal.aborted) return;
479
+ const { item, icons } = await match(entry, signal);
441
480
  if (signal.aborted) return;
442
- const source = entry.source;
443
- const item = entries.find((item2) => entry.ids.includes(item2.id) && ("url" in source && !source.url.startsWith("data:") ? item2.url === source.url && (!("sha256" in source) || source.sha256 === item2.sha256) : "sha256" in source && source.sha256 === item2.sha256));
444
481
  return item && (icons[item.id] || item.metadata.banner);
445
482
  };
446
483
  }
447
484
 
448
485
  // src/catalog-resources.ts
449
486
  function createCatalogResourceResolver(catalog) {
450
- let pending;
487
+ const match = createCatalogMatcher(catalog);
451
488
  return async (entry, signal) => {
452
- if (!catalog || signal.aborted) return;
453
- pending != null ? pending : pending = catalog.read(signal).then((read) => read.catalog ? parseExtensionCatalog(read.catalog) : []).catch(() => {
454
- pending = void 0;
455
- return [];
456
- });
457
- const entries = await pending;
458
- if (signal.aborted) return;
489
+ var _a;
459
490
  const source = entry.source;
460
- let digest = "sha256" in source ? source.sha256 : void 0;
461
491
  const inline = "url" in source && source.url.startsWith("data:");
462
- if (inline) {
463
- try {
464
- const bytes = new TextEncoder().encode(decodeExtensionDataURL(source.url));
465
- const hash = await globalThis.crypto.subtle.digest("SHA-256", bytes);
466
- digest = Array.from(new Uint8Array(hash), (byte) => byte.toString(16).padStart(2, "0")).join("");
467
- } catch (e) {
468
- return;
469
- }
470
- }
471
- if (signal.aborted) return;
472
- const item = entries.find((item2) => entry.ids.includes(item2.id) && ("url" in source && !inline ? item2.url === source.url && (digest === void 0 || item2.sha256 === digest) : digest !== void 0 && item2.sha256 === digest));
473
- return item == null ? void 0 : item.metadata.resourceDeclaration;
492
+ const digest = inline ? await inlineCodeDigest(source.url) : void 0;
493
+ if (inline && !digest) return;
494
+ return (_a = (await match(entry, signal, digest)).item) == null ? void 0 : _a.metadata.resourceDeclaration;
474
495
  };
475
496
  }
476
497
 
@@ -6706,13 +6727,18 @@ function createProjectSecurityReview({
6706
6727
  duringApproval: duringProjectLoadApproval,
6707
6728
  styles
6708
6729
  }) {
6709
- const hex = (bytes) => Array.from(new Uint8Array(bytes), (byte) => byte.toString(16).padStart(2, "0")).join("");
6730
+ const hex2 = (bytes) => Array.from(new Uint8Array(bytes), (byte) => byte.toString(16).padStart(2, "0")).join("");
6710
6731
  const resolveResources = createCatalogResourceResolver(catalog);
6711
6732
  const withResources = async (entry) => {
6712
6733
  const _a = entry.metadata || {}, { resourceDeclaration: _claim } = _a, metadata = __objRest(_a, ["resourceDeclaration"]);
6713
6734
  const resourceDeclaration = await resolveResources(entry, AbortSignal.timeout(5e3));
6714
6735
  return __spreadProps(__spreadValues({}, entry), { metadata: __spreadValues(__spreadValues({}, metadata), resourceDeclaration ? { resourceDeclaration } : {}) });
6715
6736
  };
6737
+ const matchCatalog = createCatalogMatcher(catalog);
6738
+ const listedURL = async (entry) => {
6739
+ var _a;
6740
+ return (_a = (await matchCatalog(entry, AbortSignal.timeout(5e3))).item) == null ? void 0 : _a.url;
6741
+ };
6716
6742
  const readProjectDocument = async (input) => {
6717
6743
  const verified = reviewedProjectArchive(input);
6718
6744
  if (verified) return verified.project;
@@ -6732,14 +6758,14 @@ function createProjectSecurityReview({
6732
6758
  if (typeof uri === "string") return uri;
6733
6759
  const _b = project, { meta, projectVersion } = _b, content = __objRest(_b, ["meta", "projectVersion"]);
6734
6760
  const canonical = JSON.stringify(content, (key, value) => value && typeof value === "object" && !Array.isArray(value) ? Object.fromEntries(Object.keys(value).sort().map((name) => [name, value[name]])) : value);
6735
- return `sha256:${hex(await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(canonical)))}`;
6761
+ return `sha256:${hex2(await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(canonical)))}`;
6736
6762
  };
6737
6763
  async function verifiedEmbeddedName(spec, readFile) {
6738
6764
  if (spec.source.type !== "embedded-file" || !readFile) return;
6739
6765
  try {
6740
6766
  const bytes = await readFile(spec.source.path);
6741
6767
  const digest = await globalThis.crypto.subtle.digest("SHA-256", bytes);
6742
- if (hex(digest) === spec.sha256) return embeddedExtensionName(bytes, spec.id);
6768
+ if (hex2(digest) === spec.sha256) return embeddedExtensionName(bytes, spec.id);
6743
6769
  } catch (e) {
6744
6770
  }
6745
6771
  }
@@ -6749,6 +6775,7 @@ function createProjectSecurityReview({
6749
6775
  verifiedEmbeddedName(spec, readEmbeddedFile)
6750
6776
  ]);
6751
6777
  const source = typeof spec.source.url === "string" && spec.source.type.startsWith("remote-") ? { kind: spec.source.type, url: spec.source.url, sha256: spec.sha256 } : { kind: spec.source.type, sha256: spec.sha256 };
6778
+ const listed = vouched && !("url" in source) ? await listedURL({ key: spec.id, ids: [spec.id], source }) : void 0;
6752
6779
  return withResources(__spreadValues({
6753
6780
  key: spec.id,
6754
6781
  ids: [spec.id],
@@ -6758,7 +6785,7 @@ function createProjectSecurityReview({
6758
6785
  source,
6759
6786
  requestedExecution: spec.execution,
6760
6787
  dependencies: [...spec.dependencies]
6761
- }, vouched ? { state: { trusted: true, plusFamily: true } } : {}));
6788
+ }, vouched ? { state: __spreadValues({ trusted: true, plusFamily: true }, listed ? { listedURL: listed } : {}) } : {}));
6762
6789
  }));
6763
6790
  const frames = /* @__PURE__ */ new WeakMap();
6764
6791
  const frameFor = (Modal) => {
@@ -6796,10 +6823,19 @@ function createProjectSecurityReview({
6796
6823
  return install(vm, async (entries, initial) => {
6797
6824
  const rows = await Promise.all(entries.map(async (entry) => {
6798
6825
  const url = "url" in entry.source ? entry.source.url : void 0;
6799
- const plusFamily = entry.source.kind === "legacy" && await trusted.isTrustedURL(url);
6800
- const vouched = entry.source.kind === "legacy" && (isTrusted2(url) || plusFamily);
6826
+ const legacy = entry.source.kind === "legacy";
6827
+ const digest = legacy ? await inlineCodeDigest(url) : void 0;
6828
+ const plusFamily = legacy && Boolean(digest ? await trusted.isTrustedCode({ source: { type: "embedded-data" }, actualSHA256: digest }) : await trusted.isTrustedURL(url));
6829
+ const vouched = legacy && (isTrusted2(url) || plusFamily);
6830
+ const source = plusFamily && digest ? __spreadProps(__spreadValues({}, entry.source), { sha256: digest }) : entry.source;
6831
+ const listed = plusFamily && digest ? await listedURL(__spreadProps(__spreadValues({}, entry), { source })) : void 0;
6801
6832
  const banner = bannerFor({ ids: entry.ids, url });
6802
- return withResources(__spreadValues(__spreadValues(__spreadValues({}, entry), banner ? { metadata: __spreadProps(__spreadValues({}, entry.metadata), { banner }) } : {}), vouched ? { state: __spreadProps(__spreadValues({}, entry.state), { trusted: true, plusFamily }) } : {}));
6833
+ return withResources(__spreadValues(__spreadValues(__spreadProps(__spreadValues({}, entry), {
6834
+ source
6835
+ }), banner ? { metadata: __spreadProps(__spreadValues({}, entry.metadata), { banner }) } : {}), vouched ? { state: __spreadValues(__spreadProps(__spreadValues({}, entry.state), {
6836
+ trusted: true,
6837
+ plusFamily
6838
+ }), listed ? { listedURL: listed } : {}) } : {}));
6803
6839
  }));
6804
6840
  const starting = initialDecisions(rows, "open", { recorded: initial });
6805
6841
  if (!requiresReview(rows)) return starting;
@@ -395,50 +395,71 @@ async function loadExtensionInfo(url, signal) {
395
395
  return { source, metadata };
396
396
  }
397
397
 
398
- // src/catalog-preview.ts
399
- function createCatalogPreviewResolver(catalog) {
398
+ // src/catalog-match.ts
399
+ var hex = (bytes) => Array.from(new Uint8Array(bytes), (byte) => byte.toString(16).padStart(2, "0")).join("");
400
+ var dataURLBytes = (url) => {
401
+ const comma = url.indexOf(",");
402
+ if (!url.startsWith("data:") || comma < 0) throw new Error("Not a data URL");
403
+ const content = url.slice(comma + 1);
404
+ if (!/;base64$/i.test(url.slice(0, comma))) return new TextEncoder().encode(decodeURIComponent(content));
405
+ const binary = atob(content);
406
+ const bytes = new Uint8Array(binary.length);
407
+ for (let index = 0; index < binary.length; index++) bytes[index] = binary.charCodeAt(index);
408
+ return bytes;
409
+ };
410
+ var inlineCodeDigest = async (url) => {
411
+ if (typeof url !== "string" || !url.startsWith("data:")) return;
412
+ try {
413
+ return hex(await globalThis.crypto.subtle.digest("SHA-256", dataURLBytes(url)));
414
+ } catch (e) {
415
+ return;
416
+ }
417
+ };
418
+ var findCatalogEntry = (entries, entry, digest) => {
419
+ const source = entry.source;
420
+ const sha256 = digest != null ? digest : "sha256" in source ? source.sha256 : void 0;
421
+ const inline = "url" in source && source.url.startsWith("data:");
422
+ return entries.find((item) => entry.ids.includes(item.id) && ("url" in source && !inline ? item.url === source.url && (sha256 === void 0 || item.sha256 === sha256) : sha256 !== void 0 && item.sha256 === sha256));
423
+ };
424
+ function createCatalogMatcher(catalog) {
400
425
  let pending;
401
- return async (entry, signal) => {
402
- var _a;
403
- if (!catalog || !((_a = entry.state) == null ? void 0 : _a.plusFamily) || signal.aborted) return;
426
+ return async (entry, signal, digest) => {
427
+ if (!catalog || signal.aborted) return { icons: {} };
404
428
  pending != null ? pending : pending = catalog.read(signal).then((read) => ({
405
429
  entries: read.catalog ? parseExtensionCatalog(read.catalog) : [],
406
430
  icons: read.icons || {}
407
- })).catch(() => ({ entries: [], icons: {} }));
431
+ })).catch(() => {
432
+ pending = void 0;
433
+ return { entries: [], icons: {} };
434
+ });
408
435
  const { entries, icons } = await pending;
436
+ if (signal.aborted) return { icons };
437
+ return { item: findCatalogEntry(entries, entry, digest), icons };
438
+ };
439
+ }
440
+
441
+ // src/catalog-preview.ts
442
+ function createCatalogPreviewResolver(catalog) {
443
+ const match = createCatalogMatcher(catalog);
444
+ return async (entry, signal) => {
445
+ var _a;
446
+ if (!catalog || !((_a = entry.state) == null ? void 0 : _a.plusFamily) || signal.aborted) return;
447
+ const { item, icons } = await match(entry, signal);
409
448
  if (signal.aborted) return;
410
- const source = entry.source;
411
- const item = entries.find((item2) => entry.ids.includes(item2.id) && ("url" in source && !source.url.startsWith("data:") ? item2.url === source.url && (!("sha256" in source) || source.sha256 === item2.sha256) : "sha256" in source && source.sha256 === item2.sha256));
412
449
  return item && (icons[item.id] || item.metadata.banner);
413
450
  };
414
451
  }
415
452
 
416
453
  // src/catalog-resources.ts
417
454
  function createCatalogResourceResolver(catalog) {
418
- let pending;
455
+ const match = createCatalogMatcher(catalog);
419
456
  return async (entry, signal) => {
420
- if (!catalog || signal.aborted) return;
421
- pending != null ? pending : pending = catalog.read(signal).then((read) => read.catalog ? parseExtensionCatalog(read.catalog) : []).catch(() => {
422
- pending = void 0;
423
- return [];
424
- });
425
- const entries = await pending;
426
- if (signal.aborted) return;
457
+ var _a;
427
458
  const source = entry.source;
428
- let digest = "sha256" in source ? source.sha256 : void 0;
429
459
  const inline = "url" in source && source.url.startsWith("data:");
430
- if (inline) {
431
- try {
432
- const bytes = new TextEncoder().encode(decodeExtensionDataURL(source.url));
433
- const hash = await globalThis.crypto.subtle.digest("SHA-256", bytes);
434
- digest = Array.from(new Uint8Array(hash), (byte) => byte.toString(16).padStart(2, "0")).join("");
435
- } catch (e) {
436
- return;
437
- }
438
- }
439
- if (signal.aborted) return;
440
- const item = entries.find((item2) => entry.ids.includes(item2.id) && ("url" in source && !inline ? item2.url === source.url && (digest === void 0 || item2.sha256 === digest) : digest !== void 0 && item2.sha256 === digest));
441
- return item == null ? void 0 : item.metadata.resourceDeclaration;
460
+ const digest = inline ? await inlineCodeDigest(source.url) : void 0;
461
+ if (inline && !digest) return;
462
+ return (_a = (await match(entry, signal, digest)).item) == null ? void 0 : _a.metadata.resourceDeclaration;
442
463
  };
443
464
  }
444
465
 
@@ -6677,13 +6698,18 @@ function createProjectSecurityReview({
6677
6698
  duringApproval: duringProjectLoadApproval,
6678
6699
  styles
6679
6700
  }) {
6680
- const hex = (bytes) => Array.from(new Uint8Array(bytes), (byte) => byte.toString(16).padStart(2, "0")).join("");
6701
+ const hex2 = (bytes) => Array.from(new Uint8Array(bytes), (byte) => byte.toString(16).padStart(2, "0")).join("");
6681
6702
  const resolveResources = createCatalogResourceResolver(catalog);
6682
6703
  const withResources = async (entry) => {
6683
6704
  const _a = entry.metadata || {}, { resourceDeclaration: _claim } = _a, metadata = __objRest(_a, ["resourceDeclaration"]);
6684
6705
  const resourceDeclaration = await resolveResources(entry, AbortSignal.timeout(5e3));
6685
6706
  return __spreadProps(__spreadValues({}, entry), { metadata: __spreadValues(__spreadValues({}, metadata), resourceDeclaration ? { resourceDeclaration } : {}) });
6686
6707
  };
6708
+ const matchCatalog = createCatalogMatcher(catalog);
6709
+ const listedURL = async (entry) => {
6710
+ var _a;
6711
+ return (_a = (await matchCatalog(entry, AbortSignal.timeout(5e3))).item) == null ? void 0 : _a.url;
6712
+ };
6687
6713
  const readProjectDocument = async (input) => {
6688
6714
  const verified = reviewedProjectArchive(input);
6689
6715
  if (verified) return verified.project;
@@ -6703,14 +6729,14 @@ function createProjectSecurityReview({
6703
6729
  if (typeof uri === "string") return uri;
6704
6730
  const _b = project, { meta, projectVersion } = _b, content = __objRest(_b, ["meta", "projectVersion"]);
6705
6731
  const canonical = JSON.stringify(content, (key, value) => value && typeof value === "object" && !Array.isArray(value) ? Object.fromEntries(Object.keys(value).sort().map((name) => [name, value[name]])) : value);
6706
- return `sha256:${hex(await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(canonical)))}`;
6732
+ return `sha256:${hex2(await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(canonical)))}`;
6707
6733
  };
6708
6734
  async function verifiedEmbeddedName(spec, readFile) {
6709
6735
  if (spec.source.type !== "embedded-file" || !readFile) return;
6710
6736
  try {
6711
6737
  const bytes = await readFile(spec.source.path);
6712
6738
  const digest = await globalThis.crypto.subtle.digest("SHA-256", bytes);
6713
- if (hex(digest) === spec.sha256) return embeddedExtensionName(bytes, spec.id);
6739
+ if (hex2(digest) === spec.sha256) return embeddedExtensionName(bytes, spec.id);
6714
6740
  } catch (e) {
6715
6741
  }
6716
6742
  }
@@ -6720,6 +6746,7 @@ function createProjectSecurityReview({
6720
6746
  verifiedEmbeddedName(spec, readEmbeddedFile)
6721
6747
  ]);
6722
6748
  const source = typeof spec.source.url === "string" && spec.source.type.startsWith("remote-") ? { kind: spec.source.type, url: spec.source.url, sha256: spec.sha256 } : { kind: spec.source.type, sha256: spec.sha256 };
6749
+ const listed = vouched && !("url" in source) ? await listedURL({ key: spec.id, ids: [spec.id], source }) : void 0;
6723
6750
  return withResources(__spreadValues({
6724
6751
  key: spec.id,
6725
6752
  ids: [spec.id],
@@ -6729,7 +6756,7 @@ function createProjectSecurityReview({
6729
6756
  source,
6730
6757
  requestedExecution: spec.execution,
6731
6758
  dependencies: [...spec.dependencies]
6732
- }, vouched ? { state: { trusted: true, plusFamily: true } } : {}));
6759
+ }, vouched ? { state: __spreadValues({ trusted: true, plusFamily: true }, listed ? { listedURL: listed } : {}) } : {}));
6733
6760
  }));
6734
6761
  const frames = /* @__PURE__ */ new WeakMap();
6735
6762
  const frameFor = (Modal) => {
@@ -6767,10 +6794,19 @@ function createProjectSecurityReview({
6767
6794
  return install(vm, async (entries, initial) => {
6768
6795
  const rows = await Promise.all(entries.map(async (entry) => {
6769
6796
  const url = "url" in entry.source ? entry.source.url : void 0;
6770
- const plusFamily = entry.source.kind === "legacy" && await trusted.isTrustedURL(url);
6771
- const vouched = entry.source.kind === "legacy" && (isTrusted2(url) || plusFamily);
6797
+ const legacy = entry.source.kind === "legacy";
6798
+ const digest = legacy ? await inlineCodeDigest(url) : void 0;
6799
+ const plusFamily = legacy && Boolean(digest ? await trusted.isTrustedCode({ source: { type: "embedded-data" }, actualSHA256: digest }) : await trusted.isTrustedURL(url));
6800
+ const vouched = legacy && (isTrusted2(url) || plusFamily);
6801
+ const source = plusFamily && digest ? __spreadProps(__spreadValues({}, entry.source), { sha256: digest }) : entry.source;
6802
+ const listed = plusFamily && digest ? await listedURL(__spreadProps(__spreadValues({}, entry), { source })) : void 0;
6772
6803
  const banner = bannerFor({ ids: entry.ids, url });
6773
- return withResources(__spreadValues(__spreadValues(__spreadValues({}, entry), banner ? { metadata: __spreadProps(__spreadValues({}, entry.metadata), { banner }) } : {}), vouched ? { state: __spreadProps(__spreadValues({}, entry.state), { trusted: true, plusFamily }) } : {}));
6804
+ return withResources(__spreadValues(__spreadValues(__spreadProps(__spreadValues({}, entry), {
6805
+ source
6806
+ }), banner ? { metadata: __spreadProps(__spreadValues({}, entry.metadata), { banner }) } : {}), vouched ? { state: __spreadValues(__spreadProps(__spreadValues({}, entry.state), {
6807
+ trusted: true,
6808
+ plusFamily
6809
+ }), listed ? { listedURL: listed } : {}) } : {}));
6774
6810
  }));
6775
6811
  const starting = initialDecisions(rows, "open", { recorded: initial });
6776
6812
  if (!requiresReview(rows)) return starting;
package/dist/react.cjs CHANGED
@@ -102,6 +102,7 @@ var messages = {
102
102
  sourceEmbedded: "Stored in the project",
103
103
  sourceLegacy: "A custom extension address",
104
104
  sourceInline: "Written into the project as a data address",
105
+ sourceListed: " (the same code as published at {url})",
105
106
  creator: "Creator (unverified claim)",
106
107
  creatorUnknown: "Not stated",
107
108
  licenseUnknown: "Not stated",
@@ -161,6 +162,7 @@ var messages = {
161
162
  sourceEmbedded: "\u4F5C\u54C1\u306E\u4E2D\u306B\u3042\u308A\u307E\u3059",
162
163
  sourceLegacy: "\u30AB\u30B9\u30BF\u30E0\u62E1\u5F35\u306E\u30A2\u30C9\u30EC\u30B9",
163
164
  sourceInline: "\u4F5C\u54C1\u306E\u4E2D\u306B data: \u30A2\u30C9\u30EC\u30B9\u3068\u3057\u3066\u66F8\u304B\u308C\u3066\u3044\u307E\u3059",
165
+ sourceListed: "\uFF08\u63D0\u4F9B\u5143 {url} \u3068\u540C\u3058\u30B3\u30FC\u30C9\uFF09",
164
166
  creator: "\u88FD\u4F5C\u8005\uFF08\u672A\u691C\u8A3C\u306E\u7533\u544A\uFF09",
165
167
  creatorUnknown: "\u8A18\u8F09\u306A\u3057",
166
168
  licenseUnknown: "\u8A18\u8F09\u306A\u3057",
@@ -7050,9 +7052,13 @@ var contradictsDeclaration = (entry, decision) => decision.execution === "sandbo
7050
7052
  // src/review.tsx
7051
7053
  var isEmbedded = (source) => source.kind === "embedded-file" || source.kind === "embedded-data";
7052
7054
  var sourceLabel = (entry, t) => {
7053
- if (entry.source.kind === "embedded-file") return t("sourceEmbedded");
7055
+ const listed = (label) => {
7056
+ var _a;
7057
+ return ((_a = entry.state) == null ? void 0 : _a.listedURL) ? `${label}${t("sourceListed", { url: entry.state.listedURL })}` : label;
7058
+ };
7059
+ if (entry.source.kind === "embedded-file") return listed(t("sourceEmbedded"));
7054
7060
  if (entry.source.kind === "embedded-data" || String(entry.source.url).startsWith("data:")) {
7055
- return t("sourceInline");
7061
+ return listed(t("sourceInline"));
7056
7062
  }
7057
7063
  if (entry.source.kind === "legacy") return `${t("sourceLegacy")}: ${entry.source.url}`;
7058
7064
  return entry.source.url;
package/dist/react.mjs CHANGED
@@ -66,6 +66,7 @@ var messages = {
66
66
  sourceEmbedded: "Stored in the project",
67
67
  sourceLegacy: "A custom extension address",
68
68
  sourceInline: "Written into the project as a data address",
69
+ sourceListed: " (the same code as published at {url})",
69
70
  creator: "Creator (unverified claim)",
70
71
  creatorUnknown: "Not stated",
71
72
  licenseUnknown: "Not stated",
@@ -125,6 +126,7 @@ var messages = {
125
126
  sourceEmbedded: "\u4F5C\u54C1\u306E\u4E2D\u306B\u3042\u308A\u307E\u3059",
126
127
  sourceLegacy: "\u30AB\u30B9\u30BF\u30E0\u62E1\u5F35\u306E\u30A2\u30C9\u30EC\u30B9",
127
128
  sourceInline: "\u4F5C\u54C1\u306E\u4E2D\u306B data: \u30A2\u30C9\u30EC\u30B9\u3068\u3057\u3066\u66F8\u304B\u308C\u3066\u3044\u307E\u3059",
129
+ sourceListed: "\uFF08\u63D0\u4F9B\u5143 {url} \u3068\u540C\u3058\u30B3\u30FC\u30C9\uFF09",
128
130
  creator: "\u88FD\u4F5C\u8005\uFF08\u672A\u691C\u8A3C\u306E\u7533\u544A\uFF09",
129
131
  creatorUnknown: "\u8A18\u8F09\u306A\u3057",
130
132
  licenseUnknown: "\u8A18\u8F09\u306A\u3057",
@@ -7014,9 +7016,13 @@ var contradictsDeclaration = (entry, decision) => decision.execution === "sandbo
7014
7016
  // src/review.tsx
7015
7017
  var isEmbedded = (source) => source.kind === "embedded-file" || source.kind === "embedded-data";
7016
7018
  var sourceLabel = (entry, t) => {
7017
- if (entry.source.kind === "embedded-file") return t("sourceEmbedded");
7019
+ const listed = (label) => {
7020
+ var _a;
7021
+ return ((_a = entry.state) == null ? void 0 : _a.listedURL) ? `${label}${t("sourceListed", { url: entry.state.listedURL })}` : label;
7022
+ };
7023
+ if (entry.source.kind === "embedded-file") return listed(t("sourceEmbedded"));
7018
7024
  if (entry.source.kind === "embedded-data" || String(entry.source.url).startsWith("data:")) {
7019
- return t("sourceInline");
7025
+ return listed(t("sourceInline"));
7020
7026
  }
7021
7027
  if (entry.source.kind === "legacy") return `${t("sourceLegacy")}: ${entry.source.url}`;
7022
7028
  return entry.source.url;
@@ -78,6 +78,8 @@ export type ReviewSource = {
78
78
  } | {
79
79
  kind: 'legacy';
80
80
  url: string;
81
+ /** Set by the host only for a `data:` address whose bytes its catalog lists by this digest. */
82
+ sha256?: string;
81
83
  };
82
84
  /**
83
85
  * A load that failed, as the host reports it.
@@ -97,6 +99,11 @@ export interface ReviewEntryState {
97
99
  trusted?: boolean;
98
100
  /** Set by the host's Plus catalog lookup, never by extension-declared metadata. */
99
101
  plusFamily?: boolean;
102
+ /**
103
+ * The catalog's address for the bytes a project carries itself, set by the host only after
104
+ * the catalog vouched for their digest. Shown as where the code is published; never fetched.
105
+ */
106
+ listedURL?: string;
100
107
  error?: ReviewFailure;
101
108
  }
102
109
  export interface ReviewEntry {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubohiroya/turbowarp-extension-security-dialog",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "description": "Batch extension security review, previews and per-project defaults for TurboWarp hosts",
5
5
  "type": "module",
6
6
  "author": {
@@ -93,7 +93,7 @@
93
93
  "peerDependencies": {
94
94
  "react": "^16.14.0 || ^17 || ^18 || ^19",
95
95
  "react-dom": "^16.14.0 || ^17 || ^18 || ^19",
96
- "@kubohiroya/turbowarp-extension-loader": ">=0.11.1 <0.12.0 || 0.12.0 || 0.13.0",
96
+ "@kubohiroya/turbowarp-extension-loader": ">=0.11.1 <0.12.0 || 0.12.0 || 0.13.0 || 0.13.1",
97
97
  "@turbowarp/jszip": ">=3.12.0 <4"
98
98
  },
99
99
  "peerDependenciesMeta": {
@@ -116,7 +116,7 @@
116
116
  "react": "^16.14.0",
117
117
  "react-dom": "^16.14.0",
118
118
  "typescript": "^6.0.3",
119
- "@kubohiroya/turbowarp-extension-loader": "0.13.0",
119
+ "@kubohiroya/turbowarp-extension-loader": "0.13.1",
120
120
  "@turbowarp/jszip": "3.12.0"
121
121
  },
122
122
  "packageManager": "pnpm@11.28.8",
@@ -0,0 +1,88 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+ import {parseExtensionCatalog} from './catalog.js';
3
+ import type {CatalogEntry} from './catalog.js';
4
+ import type {PreviewCatalog} from './catalog-preview.js';
5
+ import type {ReviewEntry} from './review-types.js';
6
+
7
+ const hex = (bytes: ArrayBuffer) => Array.from(new Uint8Array(bytes), byte => byte.toString(16).padStart(2, '0')).join('');
8
+
9
+ /**
10
+ * The bytes a `data:` URL hands the VM, base64 or percent-encoded.
11
+ *
12
+ * Base64 is read as raw bytes rather than as text, so the digest is of exactly what loads, whatever
13
+ * its encoding. Percent-encoded text is its UTF-8, which is what the browser fetches for it.
14
+ * @param {string} url The data URL.
15
+ * @returns {Uint8Array} Its bytes.
16
+ */
17
+ const dataURLBytes = (url: string): Uint8Array<ArrayBuffer> => {
18
+ const comma = url.indexOf(',');
19
+ if (!url.startsWith('data:') || comma < 0) throw new Error('Not a data URL');
20
+ const content = url.slice(comma + 1);
21
+ if (!(/;base64$/i).test(url.slice(0, comma))) return new TextEncoder().encode(decodeURIComponent(content));
22
+ const binary = atob(content);
23
+ const bytes = new Uint8Array(binary.length);
24
+ for (let index = 0; index < binary.length; index++) bytes[index] = binary.charCodeAt(index);
25
+ return bytes;
26
+ };
27
+
28
+ /**
29
+ * The SHA-256 of the code a project carries in a `data:` address, or nothing for any other address.
30
+ *
31
+ * A project written for standard TurboWarp holds a Plus extension this way, with no address to
32
+ * check. The digest is what a catalog can vouch for instead, the same way it vouches for the
33
+ * embedded forms of a Plus manifest.
34
+ * @param {string} [url] The extension's address.
35
+ * @returns {Promise<string|undefined>} Lowercase hex, or undefined when there is nothing to digest.
36
+ */
37
+ export const inlineCodeDigest = async (url: string | undefined): Promise<string | undefined> => {
38
+ if (typeof url !== 'string' || !url.startsWith('data:')) return;
39
+ try {
40
+ return hex(await globalThis.crypto.subtle.digest('SHA-256', dataURLBytes(url)));
41
+ } catch {
42
+ return;
43
+ }
44
+ };
45
+
46
+ /**
47
+ * The catalog row for exactly this code: the same ID, and the same address or the same digest.
48
+ *
49
+ * An address is matched only when it is a real one; a `data:` address carries the bytes, so only
50
+ * its digest can say which catalog row it is. A claimed ID alone never matches.
51
+ * @param {Array<object>} entries The parsed catalog.
52
+ * @param {object} entry The review row.
53
+ * @param {string} [digest] The row's digest, when the caller worked it out.
54
+ * @returns {object|undefined} The catalog row.
55
+ */
56
+ export const findCatalogEntry = (entries: readonly CatalogEntry[], entry: ReviewEntry, digest?: string) => {
57
+ const source = entry.source;
58
+ const sha256 = digest ?? ('sha256' in source ? source.sha256 : undefined);
59
+ const inline = 'url' in source && source.url.startsWith('data:');
60
+ return entries.find(item => entry.ids.includes(item.id) && (
61
+ 'url' in source && !inline ? item.url === source.url && (sha256 === undefined || item.sha256 === sha256) :
62
+ sha256 !== undefined && item.sha256 === sha256
63
+ ));
64
+ };
65
+
66
+ export interface CatalogMatch {
67
+ item?: CatalogEntry;
68
+ icons: Record<string, string>;
69
+ }
70
+
71
+ /**
72
+ * Read a host's catalog at most once, and find rows in it.
73
+ * @param {object} [catalog] The host's catalog port.
74
+ * @returns {Function} The catalog row for a review row, with the host's curated icons; the row is
75
+ * undefined without a usable catalog or a match.
76
+ */
77
+ export function createCatalogMatcher(catalog?: PreviewCatalog) {
78
+ let pending: Promise<{entries: CatalogEntry[]; icons: Record<string, string>}> | undefined;
79
+ return async (entry: ReviewEntry, signal: AbortSignal, digest?: string): Promise<CatalogMatch> => {
80
+ if (!catalog || signal.aborted) return {icons: {}};
81
+ pending ??= catalog.read(signal).then(read => ({
82
+ entries: read.catalog ? parseExtensionCatalog(read.catalog) : [], icons: read.icons || {}
83
+ })).catch(() => { pending = undefined; return {entries: [], icons: {}}; });
84
+ const {entries, icons} = await pending;
85
+ if (signal.aborted) return {icons};
86
+ return {item: findCatalogEntry(entries, entry, digest), icons};
87
+ };
88
+ }
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MPL-2.0
2
- import {parseExtensionCatalog} from './catalog.js';
2
+ import {createCatalogMatcher} from './catalog-match.js';
3
3
  import type {ReviewEntry} from './review-types.js';
4
4
 
5
5
  export interface PreviewCatalog {
@@ -8,20 +8,11 @@ export interface PreviewCatalog {
8
8
 
9
9
  /** The catalog already chooses the declared banner or the package's block SVG. */
10
10
  export function createCatalogPreviewResolver(catalog?: PreviewCatalog) {
11
- let pending: Promise<{entries: ReturnType<typeof parseExtensionCatalog>; icons: Record<string, string>}> | undefined;
11
+ const match = createCatalogMatcher(catalog);
12
12
  return async (entry: ReviewEntry, signal: AbortSignal): Promise<string | undefined> => {
13
13
  if (!catalog || !entry.state?.plusFamily || signal.aborted) return;
14
- pending ??= catalog.read(signal).then(read => ({
15
- entries: read.catalog ? parseExtensionCatalog(read.catalog) : [], icons: read.icons || {}
16
- })).catch(() => ({entries: [], icons: {}}));
17
- const {entries, icons} = await pending;
14
+ const {item, icons} = await match(entry, signal);
18
15
  if (signal.aborted) return;
19
- const source = entry.source;
20
- const item = entries.find(item => entry.ids.includes(item.id) && (
21
- 'url' in source && !source.url.startsWith('data:') ? item.url === source.url &&
22
- (!('sha256' in source) || source.sha256 === item.sha256) :
23
- 'sha256' in source && source.sha256 === item.sha256
24
- ));
25
16
  return item && (icons[item.id] || item.metadata.banner);
26
17
  };
27
18
  }
@@ -1,34 +1,16 @@
1
1
  // SPDX-License-Identifier: MPL-2.0
2
- import {parseExtensionCatalog} from './catalog.js';
3
- import {decodeExtensionDataURL} from './metadata.js';
2
+ import {createCatalogMatcher, inlineCodeDigest} from './catalog-match.js';
4
3
  import type {PreviewCatalog} from './catalog-preview.js';
5
4
  import type {ReviewEntry} from './review-types.js';
6
5
 
7
6
  /** Bind declarations to the exact catalog address/digest, never to a project's package-name claim. */
8
7
  export function createCatalogResourceResolver(catalog?: PreviewCatalog) {
9
- let pending: Promise<ReturnType<typeof parseExtensionCatalog>> | undefined;
8
+ const match = createCatalogMatcher(catalog);
10
9
  return async (entry: ReviewEntry, signal: AbortSignal) => {
11
- if (!catalog || signal.aborted) return;
12
- pending ??= catalog.read(signal).then(read => read.catalog ? parseExtensionCatalog(read.catalog) : [])
13
- .catch(() => { pending = undefined; return []; });
14
- const entries = await pending;
15
- if (signal.aborted) return;
16
10
  const source = entry.source;
17
- let digest = 'sha256' in source ? source.sha256 : undefined;
18
11
  const inline = 'url' in source && source.url.startsWith('data:');
19
- if (inline) {
20
- try {
21
- const bytes = new TextEncoder().encode(decodeExtensionDataURL(source.url));
22
- const hash = await globalThis.crypto.subtle.digest('SHA-256', bytes);
23
- digest = Array.from(new Uint8Array(hash), byte => byte.toString(16).padStart(2, '0')).join('');
24
- } catch { return; }
25
- }
26
- if (signal.aborted) return;
27
- const item = entries.find(item => entry.ids.includes(item.id) && (
28
- 'url' in source && !inline ? item.url === source.url &&
29
- (digest === undefined || item.sha256 === digest) :
30
- digest !== undefined && item.sha256 === digest
31
- ));
32
- return item?.metadata.resourceDeclaration;
12
+ const digest = inline ? await inlineCodeDigest(source.url) : undefined;
13
+ if (inline && !digest) return;
14
+ return (await match(entry, signal, digest)).item?.metadata.resourceDeclaration;
33
15
  };
34
16
  }
package/src/messages.ts CHANGED
@@ -43,6 +43,7 @@ const messages: Record<string, Record<string, string>> = {
43
43
  sourceEmbedded: 'Stored in the project',
44
44
  sourceLegacy: 'A custom extension address',
45
45
  sourceInline: 'Written into the project as a data address',
46
+ sourceListed: ' (the same code as published at {url})',
46
47
  creator: 'Creator (unverified claim)',
47
48
  creatorUnknown: 'Not stated',
48
49
  licenseUnknown: 'Not stated',
@@ -105,6 +106,7 @@ const messages: Record<string, Record<string, string>> = {
105
106
  sourceEmbedded: '作品の中にあります',
106
107
  sourceLegacy: 'カスタム拡張のアドレス',
107
108
  sourceInline: '作品の中に data: アドレスとして書かれています',
109
+ sourceListed: '(提供元 {url} と同じコード)',
108
110
  creator: '製作者(未検証の申告)',
109
111
  creatorUnknown: '記載なし',
110
112
  licenseUnknown: '記載なし',
@@ -14,6 +14,7 @@ import React from 'react';
14
14
  import {embeddedExtensionName} from './embedded-extension-name.js';
15
15
  import {createCatalogPreviewResolver} from './catalog-preview.js';
16
16
  import {createCatalogResourceResolver} from './catalog-resources.js';
17
+ import {createCatalogMatcher, inlineCodeDigest} from './catalog-match.js';
17
18
  import type {ReviewEntry} from './review-types.js';
18
19
  import type {PreviewCatalog} from './catalog-preview.js';
19
20
 
@@ -37,6 +38,14 @@ export function createProjectSecurityReview({catalog, trusted: defaultTrusted, p
37
38
  const resourceDeclaration = await resolveResources(entry, AbortSignal.timeout(5000));
38
39
  return {...entry, metadata: {...metadata, ...(resourceDeclaration ? {resourceDeclaration} : {})}};
39
40
  };
41
+ const matchCatalog = createCatalogMatcher(catalog);
42
+ /**
43
+ * Where the catalog publishes the code a project carries itself. Asked only of a row whose
44
+ * digest the catalog already vouched for, so the address names the same bytes.
45
+ * @param {object} entry The review row, with its digest.
46
+ * @returns {Promise<string|undefined>} The catalog's address for this code.
47
+ */
48
+ const listedURL = async (entry: ReviewEntry) => (await matchCatalog(entry, AbortSignal.timeout(5000))).item?.url;
40
49
 
41
50
  /**
42
51
  * The project document a load was handed, whatever form it arrived in.
@@ -106,6 +115,8 @@ export function createProjectSecurityReview({catalog, trusted: defaultTrusted, p
106
115
  ]);
107
116
  const source = typeof spec.source.url === 'string' && spec.source.type.startsWith('remote-') ?
108
117
  {kind: spec.source.type, url: spec.source.url, sha256: spec.sha256} : {kind: spec.source.type, sha256: spec.sha256};
118
+ // Bytes the project carries have no address of their own; the catalog's says where they come from.
119
+ const listed = vouched && !('url' in source) ? await listedURL({key: spec.id, ids: [spec.id], source}) : undefined;
109
120
  return withResources({key: spec.id,
110
121
  ids: [spec.id],
111
122
  metadata: {id: spec.id, ...(name ? {name} : {}), ...(spec.version ? {version: spec.version} : {}),
@@ -113,7 +124,7 @@ export function createProjectSecurityReview({catalog, trusted: defaultTrusted, p
113
124
  source,
114
125
  requestedExecution: spec.execution,
115
126
  dependencies: [...spec.dependencies],
116
- ...(vouched ? {state: {trusted: true, plusFamily: true}} : {})});
127
+ ...(vouched ? {state: {trusted: true, plusFamily: true, ...(listed ? {listedURL: listed} : {})}} : {})});
117
128
  }));
118
129
 
119
130
  const frames = new WeakMap();
@@ -178,14 +189,25 @@ export function createProjectSecurityReview({catalog, trusted: defaultTrusted, p
178
189
  // A trusted row is stated, not asked about: the screen gives it no choice.
179
190
  const rows = await Promise.all(entries.map(async entry => {
180
191
  const url = 'url' in entry.source ? entry.source.url : undefined;
181
- // Only an ordinary custom extension is trusted by its address alone. A Plus row
192
+ const legacy = entry.source.kind === 'legacy';
193
+ // A project written for standard TurboWarp carries a Plus extension as a data:
194
+ // address. Its bytes are judged by digest, as a Plus manifest's embedded forms are;
195
+ // every other ordinary custom extension is trusted by its address alone. A Plus row
182
196
  // arrives already judged by its address and pinned digest together.
183
- const plusFamily = entry.source.kind === 'legacy' && await trusted.isTrustedURL(url);
184
- const vouched = entry.source.kind === 'legacy' && (isTrusted(url) || plusFamily);
197
+ const digest = legacy ? await inlineCodeDigest(url) : undefined;
198
+ const plusFamily = legacy && Boolean(digest ?
199
+ await trusted.isTrustedCode({source: {type: 'embedded-data'}, actualSHA256: digest}) :
200
+ await trusted.isTrustedURL(url));
201
+ const vouched = legacy && (isTrusted(url) || plusFamily);
202
+ // The digest goes on the row only once the catalog vouched for it, so the screen
203
+ // states it and the catalog's artwork and address can be matched to it.
204
+ const source = plusFamily && digest ? {...entry.source, sha256: digest} : entry.source;
205
+ const listed = plusFamily && digest ? await listedURL({...entry, source}) : undefined;
185
206
  const banner = bannerFor({ids: entry.ids, url});
186
- return withResources({...entry,
207
+ return withResources({...entry, source,
187
208
  ...(banner ? {metadata: {...entry.metadata, banner}} : {}),
188
- ...(vouched ? {state: {...entry.state, trusted: true, plusFamily}} : {})});
209
+ ...(vouched ? {state: {...entry.state, trusted: true, plusFamily,
210
+ ...(listed ? {listedURL: listed} : {})}} : {})});
189
211
  }));
190
212
  const starting = initialDecisions(rows, 'open', {recorded: initial});
191
213
  if (!requiresReview(rows)) return starting;
@@ -61,7 +61,9 @@ export type ReviewSource =
61
61
  | {kind: 'remote-cacheable'; url: string; sha256: string}
62
62
  | {kind: 'embedded-file'; sha256: string}
63
63
  | {kind: 'embedded-data'; sha256: string}
64
- | {kind: 'legacy'; url: string};
64
+ | {kind: 'legacy'; url: string;
65
+ /** Set by the host only for a `data:` address whose bytes its catalog lists by this digest. */
66
+ sha256?: string};
65
67
 
66
68
  /**
67
69
  * A load that failed, as the host reports it.
@@ -82,6 +84,11 @@ export interface ReviewEntryState {
82
84
  trusted?: boolean;
83
85
  /** Set by the host's Plus catalog lookup, never by extension-declared metadata. */
84
86
  plusFamily?: boolean;
87
+ /**
88
+ * The catalog's address for the bytes a project carries itself, set by the host only after
89
+ * the catalog vouched for their digest. Shown as where the code is published; never fetched.
90
+ */
91
+ listedURL?: string;
85
92
  error?: ReviewFailure;
86
93
  }
87
94
 
package/src/review.tsx CHANGED
@@ -29,11 +29,15 @@ import {
29
29
  const isEmbedded = (source: ReviewSource): source is Extract<ReviewSource, {kind: 'embedded-file' | 'embedded-data'}> => source.kind === 'embedded-file' || source.kind === 'embedded-data';
30
30
 
31
31
  const sourceLabel = (entry: ReviewEntry, t: Translate) => {
32
- if (entry.source.kind === 'embedded-file') return t('sourceEmbedded');
32
+ // Bytes carried by the project have no address of their own. When the host's catalog vouched
33
+ // for their digest, its address for the same bytes says where they are published.
34
+ const listed = (label: string) => entry.state?.listedURL ?
35
+ `${label}${t('sourceListed', {url: entry.state.listedURL})}` : label;
36
+ if (entry.source.kind === 'embedded-file') return listed(t('sourceEmbedded'));
33
37
  // A project that carries the extension itself has a data: URL for an address. Printing it
34
38
  // would put the whole bundle in the row, so say where the bytes are instead.
35
39
  if (entry.source.kind === 'embedded-data' || String(entry.source.url).startsWith('data:')) {
36
- return t('sourceInline');
40
+ return listed(t('sourceInline'));
37
41
  }
38
42
  if (entry.source.kind === 'legacy') return `${t('sourceLegacy')}: ${entry.source.url}`;
39
43
  return entry.source.url;