x402-counterpartycheck / tree / scripts/build-data.py ยท raw (this view has old GitHub links rewritten for the mirror; raw is byte-exact)
# Rebuild the bundled data snapshots (run from the repo root):
#   python3 scripts/build-data.py [cdp-bazaar-pull.json]
# 1. src/data/x402-payees.js: payTo addresses listed in the public CDP x402 Bazaar discovery catalog
#    (https://api.cdp.coinbase.com/platform/v2/x402/discovery/resources), with resource counts, hosts and networks.
# 2. src/data/scamsniffer.js: ScamSniffer open-source phishing address blacklist (GPL-3.0, 7-day delayed),
#    https://github.com/scamsniffer/scam-database (blacklist/all.json addresses). Attribution kept in the file header.
import json, os, sys, urllib.request, datetime
from collections import defaultdict
from urllib.parse import urlparse
root = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')
now = datetime.datetime.now(datetime.timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')

def fetch_bazaar():
    items, off = [], 0
    while True:
        u = f'https://api.cdp.coinbase.com/platform/v2/x402/discovery/resources?limit=1000&offset={off}'
        d = json.load(urllib.request.urlopen(urllib.request.Request(u, headers={'user-agent': 'CounterpartyCheck build'}), timeout=60))
        items += d['items']; off += 1000
        if off >= d['pagination']['total'] or not d['items']: return items

src = sys.argv[1] if len(sys.argv) > 1 else None
items = json.load(open(src)) if src else fetch_bazaar()
if isinstance(items, dict): items = items.get('items', [])
pay = defaultdict(lambda: {'n': 0, 'hosts': set(), 'nets': set()})
for r in items:
    h = urlparse(r.get('resource', '')).hostname or ''
    for a in r.get('accepts', []) or []:
        p = a.get('payTo')
        if not isinstance(p, str) or len(p) < 20: continue
        k = p.lower() if p.startswith('0x') else p
        e = pay[k]; e['n'] += 1; e['hosts'].add(h); e['nets'].add(a.get('network', ''))
out = {k: [v['n'], sorted(x for x in v['hosts'] if x)[:3], len(v['hosts']), sorted(x for x in v['nets'] if x)] for k, v in pay.items()}
meta = {'source': 'CDP x402 Bazaar discovery catalog (public)', 'source_url': 'https://api.cdp.coinbase.com/platform/v2/x402/discovery/resources', 'snapshot_at': os.environ.get('BAZAAR_AT', now), 'resources': len(items), 'payees': len(out)}
open(os.path.join(root, 'src/data/x402-payees.js'), 'w').write('// GENERATED by scripts/build-data.py. payTo -> [resources, sample hosts (<=3), host count, networks]. Do not edit by hand.\nexport const X402_META = ' + json.dumps(meta) + ';\nexport const X402_PAYEES = ' + json.dumps(out, separators=(',', ':')) + ';\n')
print('x402 payees', meta)

allj = json.load(urllib.request.urlopen('https://raw.githubusercontent.com/scamsniffer/scam-database/main/blacklist/all.json', timeout=120))
# combined.json maps phishing domains to every address their pages reference, which includes legitimate tokens (USDC, DAI,
# WETH), so only the curated address list is used.
ss = list(allj.get('address', []))
try:
    c = json.load(urllib.request.urlopen(urllib.request.Request('https://api.github.com/repos/scamsniffer/scam-database/commits?path=blacklist/all.json&per_page=1', headers={'user-agent': 'CounterpartyCheck build'}), timeout=30))
    updated = c[0]['commit']['committer']['date']
except Exception:
    updated = now
evm = sorted({a.lower() for a in ss if isinstance(a, str) and a.startswith('0x') and len(a) == 42})
other = sorted({a for a in ss if isinstance(a, str) and not a.startswith('0x') and 32 <= len(a) <= 44})
smeta = {'source': 'ScamSniffer open-source scam database (phishing addresses)', 'source_url': 'https://github.com/scamsniffer/scam-database', 'license': 'GPL-3.0', 'delay': 'public data is delayed 7 days', 'updated_at': updated, 'evm_count': len(evm), 'other_count': len(other)}
open(os.path.join(root, 'src/data/scamsniffer.js'), 'w').write(
    '// SPDX-License-Identifier: GPL-3.0-only\n// Data: ScamSniffer scam-database, blacklist/all.json addresses (https://github.com/scamsniffer/scam-database), licensed GPL-3.0.\n'
    '// Redistributed unmodified as a lookup set (lower-cased EVM addresses). GENERATED by scripts/build-data.py; do not edit by hand.\n'
    'export const SCAM_META = ' + json.dumps(smeta) + ';\nexport const SCAM_EVM = new Set(' + json.dumps(evm, separators=(',', ':')) + ');\nexport const SCAM_OTHER = new Set(' + json.dumps(other, separators=(',', ':')) + ');\n')
print('scamsniffer', smeta)

agentgate-source: code mirror on Cloudflare Pages. All repos