// The breach check's one network act (SHAPES `vault.breach`, step 2): GET// each range address the core named, with the headers it named, and hand the// bodies back by prefix. The addresses are the range service's// (api.pwnedpasswords.com, `cotton_core::keys::health::RANGE_URL`), never a// Cotton server's, and carry no credential: only the five SHA-1 characters in// each address leave the phone, and only when the person taps Check. A range// that does not arrive is left out; the core's toast says so.#if os(iOS)importCottonKitimportFoundationenumVaultBreachFetch {staticfunc ranges(_ asked: [(prefix: String, address: String)], headers: [String: String]) async -> [String: String] {await withTaskGroup(of: (String, String?).self) { group infor (prefix, address) in asked { group.addTask {guardlet url = URL(string: address), url.scheme == "https"else { return (prefix, nil) }var request = URLRequest(url: url, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: 20)for (name, value) in headers { request.setValue(value, forHTTPHeaderField: name) }do {let (data, response) = tryawait URLSession.shared.data(for: request)guard (response as? HTTPURLResponse)?.statusCode == 200else { return (prefix, nil) }return (prefix, String(data: data, encoding: .utf8)) } catch {Log.write("vault: a breach range did not arrive — \(error.localizedDescription)")return (prefix, nil) } } }var bodies: [String: String] = [:]forawait (prefix, body) in group { iflet body { bodies[prefix] = body } }return bodies } }}#endif