Upload folder using huggingface_hub
Browse filesFiles changed (4)
- EXTRACT.mdAdded+74
- README.mdAdded+39
- bq_download.pyAdded+120
- dcso_bloom_build.pyAdded+97
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374# BigQuery digest extracts (deps.dev, Rekor)
How the `depsdev` and `rekor` filters were produced, 2026-08-01.Everything runs in the free tier: a **billing-free sandbox project**(queries cannot be charged; 1 TB/month processing, 10 GB storage cap),and `tabledata.list` paging for download, which is free and doesn'tcount as query processing.
```shgcloud projects create hashdex-sandbox # NO billing account attachedgcloud config set project hashdex-sandboxbq mk --location=US -d hashdex_extracts```
## deps.dev: 344.9M artifact digests (47 GB scan)
`PackageVersionHashes` is 9.2 TiB across daily snapshot partitions —**always filter to one partition with a literal timestamp** (the`*Latest` views don't prune). Find the newest:
```sqlSELECT partition_id, total_rowsFROM `bigquery-public-data.deps_dev_v1.INFORMATION_SCHEMA.PARTITIONS`WHERE table_name = 'PackageVersionHashes' AND partition_id != '__NULL__'ORDER BY partition_id DESC LIMIT 3```
Extract (store BYTES, not base64 strings — a Hash+HashType stringtable blew the sandbox's 10 GB storage cap; raw bytes squeak under at8.99 GiB, and scheme is recoverable from digest length):
```sqlSELECT DISTINCT FROM_BASE64(`Hash`) AS hFROM `bigquery-public-data.deps_dev_v1.PackageVersionHashes`WHERE TIMESTAMP_TRUNC(SnapshotAt, DAY) = TIMESTAMP('2026-07-20') AND HashType IN ('SHA1','SHA256')```
→ destination table `hashdex_extracts.depsdev_hashes`. Gotchas:`Hash` needs backticks (reserved word); values are base64; dry-runfirst (`bq query --dry_run`) — the free tier is a hard monthly budget.
## Rekor: 8.2M attestation-subject digests (3.2 GB scan)
`rekor.Artifacts.Digest` is `ARRAY<STRING>` of `sha256:<hex>` (someempty):
```sqlSELECT DISTINCT REGEXP_EXTRACT(d, r'^sha256:([0-9a-fA-F]{64})$') AS digestFROM `bigquery-public-data.rekor.Artifacts`, UNNEST(Digest) AS dWHERE REGEXP_CONTAINS(d, r'^sha256:[0-9a-fA-F]{64}$')```
→ `hashdex_extracts.rekor_digests`. Note this is attestation*subjects* only (39M rows). The full `rekor.IndexKeys` (8.4B rows,every hashedrekord digest — where goreleaser release binaries live)costs ~636 GB of quota to distinct-scan and produces a result too bigfor sandbox storage; deferred until a billed GCS staging path or apatient paging session is worth it.
## Download + build
```shtools/bq_download.py all # parallel tabledata.list paging (free), # ~160k rows/s with 24 workers; writes hex # lines split per scheme into # ~/.cache/hashdex/extracts/hdx filters build depsdev sha1 ~/.cache/hashdex/extracts/depsdev.sha1.*.hexhdx filters build depsdev sha256 ~/.cache/hashdex/extracts/depsdev.sha256.*.hexhdx filters build rekor sha256 ~/.cache/hashdex/extracts/rekor.sha256.*.hex```
Key convention (must match `hdx scan`): sha1 keys UPPERCASE hex,sha256 lowercase — `filters build` normalizes.123456789101112131415161718192021222324252627282930313233343536373839---license: cc-by-4.0pretty_name: deps.dev package-file bloom filters (sha1 + sha256)tags:- bloom-filter- file-hashes---
# deps.dev package-file bloom filters
Membership filters over per-file hashes from Google's[deps.dev](https://deps.dev) public BigQuery dataset(`bigquery-public-data.deps_dev_v1`) — files inside npm, PyPI, Maven,Go, NuGet, and Cargo package archives. deps.dev data is CC-BY-4.0(attribution: Google / deps.dev).
- **172,425,526 keys each**: sha1 (UPPERCASE hex) and sha256 (lowercase hex), p = 1e-4, 394 MiB each- Extracted 2026-08-01 via BigQuery free-tier sandbox queries ($0)- Package-registry coverage evolves; this is a point-in-time extract
## Rebuild
`EXTRACT.md` in this repo documents the exact BigQuery queries andthe free-tier setup (billing-free sandbox project, `tabledata.list`download); `bq_download.py` pulls the result tables, then`./dcso_bloom_build.py depsdev.sha1.bloom sha1 *.sha1.hex` (andlikewise sha256).
## Format
DCSO bloom filter format (`github.com/DCSO/bloom`), the same formatCIRCL publishes hashlookup in: 48-byte little-endian u64 header(version, n, p, k, m, N) followed by the bit array. Keys are hexdigest strings — **UPPERCASE for sha1, lowercase for sha256** (thehashlookup convention). Any DCSO-compatible reader works.
Membership answers are probabilistic: p = 1e-4 false-positive rate,no false negatives. Confirm anything important against the source.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120#!/usr/bin/env python3"""Parallel tabledata.list downloader for the hashdex_extracts tables.
tabledata.list is free (no query cost) and supports random access viastartIndex, so N workers page through disjoint row ranges concurrently.Output: hex digest lines split per scheme, ready for `hdx filters build`."""import base64, gzip, io, json, os, subprocess, sys, threading, time, urllib.request
PROJECT = "hashdex-sandbox"DATASET = "hashdex_extracts"OUTDIR = os.path.expanduser("~/.cache/hashdex/extracts")WORKERS = 24PAGE = 80000
_token_lock = threading.Lock()_token = {"v": None, "t": 0}
def token(): with _token_lock: if time.time() - _token["t"] > 1800: _token["v"] = subprocess.check_output( ["gcloud", "auth", "print-access-token"], text=True).strip() _token["t"] = time.time() return _token["v"]
def fetch(url): for attempt in range(6): req = urllib.request.Request(url, headers={ "Authorization": f"Bearer {token()}", "Accept-Encoding": "gzip", }) try: with urllib.request.urlopen(req, timeout=120) as resp: data = resp.read() if resp.headers.get("Content-Encoding") == "gzip": data = gzip.decompress(data) return json.loads(data) except Exception as e: if attempt == 5: raise time.sleep(2 ** attempt) if getattr(e, "code", None) == 401: with _token_lock: _token["t"] = 0
def table_rows(table): meta = fetch(f"https://bigquery.googleapis.com/bigquery/v2/projects/{PROJECT}/datasets/{DATASET}/tables/{table}") return int(meta["numRows"])
progress = {"rows": 0}_plock = threading.Lock()
def worker(table, kind, start, end, wid, files): i = start while i < end: n = min(PAGE, end - i) url = (f"https://bigquery.googleapis.com/bigquery/v2/projects/{PROJECT}" f"/datasets/{DATASET}/tables/{table}/data?startIndex={i}&maxResults={n}&alt=json") d = fetch(url) rows = d.get("rows", []) if not rows: print(f" worker {wid}: empty page at {i}, stopping", file=sys.stderr) break out = {k: [] for k in files} for r in rows: v = r["f"][0]["v"] if v is None: continue if kind == "bytes": raw = base64.b64decode(v) if len(raw) == 20: out["sha1"].append(raw.hex().upper()) elif len(raw) == 32: out["sha256"].append(raw.hex()) else: out["sha256"].append(v.lower()) for k, lines in out.items(): if lines: files[k].write("\n".join(lines) + "\n") i += len(rows) with _plock: progress["rows"] += len(rows)
def run(table, kind, prefix): total = table_rows(table) print(f"{table}: {total} rows", file=sys.stderr) chunk = (total + WORKERS - 1) // WORKERS threads = [] all_files = [] schemes = ["sha1", "sha256"] if kind == "bytes" else ["sha256"] for w in range(WORKERS): files = {s: open(os.path.join(OUTDIR, f"{prefix}.{s}.{w}.hex"), "w", buffering=1 << 20) for s in schemes} all_files.append(files) t = threading.Thread(target=worker, args=( table, kind, w * chunk, min((w + 1) * chunk, total), w, files)) t.start() threads.append(t) t0 = time.time() while any(t.is_alive() for t in threads): time.sleep(10) r = progress["rows"] rate = r / max(time.time() - t0, 1) print(f" {r}/{total} rows ({rate:,.0f}/s)", file=sys.stderr) for t in threads: t.join() for files in all_files: for f in files.values(): f.close() print(f"{table} done: {progress['rows']} rows", file=sys.stderr) progress["rows"] = 0
if __name__ == "__main__": os.makedirs(OUTDIR, exist_ok=True) which = sys.argv[1] if len(sys.argv) > 1 else "all" if which in ("all", "rekor"): run("rekor_digests", "string", "rekor") if which in ("all", "depsdev"): run("depsdev_hashes", "bytes", "depsdev")12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697#!/usr/bin/env python3"""Build a DCSO-format bloom filter from files of hex digest lines.
Standalone, zero dependencies — everything needed to reproduce the.bloom files in this dataset from the digest lists / harvest scriptsalongside it.
Format (github.com/DCSO/bloom, the format CIRCL hashlookup uses):48-byte header of little-endian u64s (version=1, n capacity, p as f64bits, k, m, N inserted) followed by ceil(m/64) u64 words of bit array.Keys are hex digest STRINGS: UPPERCASE for sha1 (the hashlookupconvention), lowercase for everything else.
Membership hashing (Go semantics preserved from the referenceimplementation): h = FNV-1 64(key) mod M with M = 2^64 - 87, then krounds of h = (h * g mod 2^64) mod M with g = 18446744073709550147,setting bit h mod m each round.
Usage: dcso_bloom_build.py OUT.bloom SCHEME HEXFILE... [--fpp 0.0001] (SCHEME in md5|sha1|sha256 — sets required line length + key case)"""import mathimport structimport sys
MOD = 2**64 - 87G = 18446744073709550147MASK = 2**64 - 1
HEX_LEN = {"md5": 32, "sha1": 40, "sha256": 64}
def fnv1_64(data: bytes) -> int: h = 0xCBF29CE484222325 for b in data: h = (h * 0x100000001B3) & MASK h ^= b return h
def main() -> None: args = [a for a in sys.argv[1:] if not a.startswith("--")] fpp = 0.0001 for a in sys.argv[1:]: if a.startswith("--fpp"): fpp = float(a.split("=", 1)[1] if "=" in a else sys.argv[sys.argv.index(a) + 1]) if len(args) < 3 or args[1] not in HEX_LEN: sys.exit(__doc__) out, scheme, inputs = args[0], args[1], args[2:] hex_len = HEX_LEN[scheme] upper = scheme == "sha1"
n = 0 for path in inputs: with open(path) as f: for line in f: t = line.strip() if not t: continue if len(t) != hex_len or not all(c in "0123456789abcdefABCDEF" for c in t): sys.exit(f"{path}: line {t!r} is not a {hex_len}-char hex digest") n += 1 if n == 0: sys.exit("no digests found in input")
ln2 = math.log(2) m = math.ceil(n * -math.log(fpp) / (ln2 * ln2)) k = max(1, round((m / n) * ln2)) words = bytearray((m + 63) // 64 * 8) print(f"building {out}: {n} keys, p={fpp}, {len(words) >> 20} MiB", file=sys.stderr)
done = 0 for path in inputs: with open(path) as f: for line in f: t = line.strip() if not t: continue key = (t.upper() if upper else t.lower()).encode() h = fnv1_64(key) % MOD for _ in range(k): h = (h * G & MASK) % MOD bit = h % m words[bit >> 6 << 3 | (bit >> 3) & 7] |= 1 << (bit & 7) done += 1 if done % 50_000_000 == 0: print(f" … {done}/{n}", file=sys.stderr)
with open(out, "wb") as f: f.write(struct.pack("<6Q", 1, n, struct.unpack("<Q", struct.pack("<d", fpp))[0], k, m, n)) f.write(words) print(f"wrote {out}", file=sys.stderr)
if __name__ == "__main__": main()EXTRACT.mdAdded+74
README.mdAdded+39
bq_download.pyAdded+120
dcso_bloom_build.pyAdded+97