Skip to main content

Receiver-side verifier for the KXCO hybrid HMAC + ML-DSA-65 webhook signature scheme

Project description

kxco-verify (Python)

Receiver-side verifier for the KXCO hybrid HMAC + ML-DSA-65 webhook signature scheme. Wire-format compatible with @kxco/post-quantum (npm), the Go verifier, and the Rust verifier.

Install

pip install kxco-verify           # core (HMAC, envelope, fingerprint)
pip install kxco-verify[oqs]      # adds liboqs-python for ML-DSA
pip install kxco-verify[pqcrypto] # adds pqcrypto for ML-DSA

The HMAC, envelope, fingerprint, and timestamp paths use only the Python standard library. ML-DSA-65 verification is lazy-loaded: it only requires a PQC backend when verify_pq is actually called.

Quick start (FastAPI)

from fastapi import FastAPI, Request, HTTPException
import os
import kxco_verify as kx

PINNED_KID    = "aa29f37ab7f4b2cf"  # current KXCO production kid (refresh from /.well-known if rotated)
PINNED_PUBKEY = bytes.fromhex("...3904 hex chars...")
HMAC_SECRET   = os.environ["KXCO_WEBHOOK_SECRET"].encode()

app = FastAPI()

@app.post("/webhooks/kxco")
async def webhook(request: Request):
    raw_body = await request.body()
    headers = {k.lower(): v for k, v in request.headers.items()}

    result = kx.verify_delivery(
        headers=headers,
        raw_body=raw_body,
        hmac_secret=HMAC_SECRET,
        pq_public_key=PINNED_PUBKEY,
        pinned_kid=PINNED_KID,
    )
    if not result.ok:
        raise HTTPException(401, "invalid signature")

    return {"ok": True}

Running tests

cd python
python test_kxco_verify.py

Expected: All 6 vector tests passed.

This verifies that the Python implementation produces identical outputs to vectors.json — the same file used by the JavaScript, Go, and Rust verifiers.

License

MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kxco_verify-1.0.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kxco_verify-1.0.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file kxco_verify-1.0.0.tar.gz.

File metadata

  • Download URL: kxco_verify-1.0.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for kxco_verify-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ffc5975cf38cb70db58e9cdaff301b27e82d8e963f0dd9613911d7e1fe82f839
MD5 994e953b9bedae15b672fb0add5808cd
BLAKE2b-256 a5525dad10689d7d3bac45f48cde136222f08dd8cb7a60f7047977da6a05f9ed

See more details on using hashes here.

File details

Details for the file kxco_verify-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: kxco_verify-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for kxco_verify-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 919dfc62f2a66d6d6646b1f4bbf44fc2fff577dde12927af804641039ea72b2c
MD5 44ef660214cd01659cdc512372e2bfec
BLAKE2b-256 587d29f39cedf277989e80a9a073a67d883b1f310175f5a247b37b879484cd15

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page