feat(signup-credit): digest an identity into a keyed fingerprint

The ledger has to outlive the account that wrote it, so it cannot store a
subject id or an email. HMAC under SECRET_KEY rather than a bare hash: the
space of Google subject ids and email addresses is small enough to exhaust
offline against a plain SHA-256.
This commit is contained in:
CREDO23 2026-08-21 11:38:59 +02:00
parent f0da52c766
commit 8639ade964
2 changed files with 21 additions and 0 deletions

View file

@ -0,0 +1 @@
"""The signup credit: granted once per person, not once per account."""

View file

@ -0,0 +1,20 @@
"""One-way, keyed digest of an identity value."""
from __future__ import annotations
import hashlib
import hmac
from app.config import config
def fingerprint(value: str) -> str:
"""Digest an identity so it stays comparable but never readable."""
# Keyed rather than a bare hash: the space of subject ids and email
# addresses is small enough to exhaust offline.
if not config.SECRET_KEY:
raise RuntimeError("SECRET_KEY must be set before identities can be claimed.")
return hmac.new(
config.SECRET_KEY.encode(), value.encode(), hashlib.sha256
).hexdigest()