Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : SP Vault8 * File : apple/SharedVaultKit/Tests/Tools/generate-psl-bulk.ts9 * Module : Tools10 * Repository : https://git.spboucher.ai/sp-vault11 * Project Website : https://vault.spboucher.ai12 * Created : 2026-11-1913 * Last Modified : 2026-11-1914 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: support@spboucher.ai23 * Development : dev@spboucher.ai24 * Support : support@spboucher.ai25 * Security/Admin : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243// Optional development check: dumps what tldts (the TypeScript reference's PSL engine) answers for hosts derived44// from every rule of the bundled Public Suffix List, so the Swift matcher can be compared in bulk.45// node --import tsx apple/SharedVaultKit/Tests/Tools/generate-psl-bulk.ts /tmp/psl-bulk.json46// SPV_PSL_BULK=/tmp/psl-bulk.json swift test --filter testBulkAgainstTldts47import { readFileSync, writeFileSync } from "node:fs";48import * as P from "../../../../packages/protocol/src/index.ts";4950const text = readFileSync(new URL("../../Sources/SharedVaultKit/Resources/public_suffix_list.dat", import.meta.url), "utf8");51const hosts = new Set<string>();52for (const line of text.split("\n")) {53 const rule = line.trim().split(/\s/)[0]!;54 if (!rule || rule.startsWith("//")) continue;55 const base = rule.replace(/^!/, "").replace(/^\*\./, "wild.");56 for (const h of [base, "a." + base, "b.a." + base, "c.b.a." + base]) hosts.add(h);57}58const out: [string, string | null][] = [];59for (const h of hosts) { let d: string | null = null; try { d = P.parseOrigin("https://" + h)?.domain ?? null; } catch { d = null; } out.push([h, d]); }60writeFileSync(process.argv[2]!, JSON.stringify(out));61console.log(`${out.length} hosts written to ${process.argv[2]}`);62