feat: add HMAC-SHA256 challenge ID generation#10
Merged
brendanjryan merged 5 commits intomainfrom Jan 29, 2026
Merged
Conversation
a401b77 to
0ba735d
Compare
Add support for HMAC-bound challenge IDs matching the TypeScript SDK: - Add generate_challenge_id() function for HMAC-SHA256 ID computation - Add Challenge.create() factory method with secret_key parameter - Add Challenge.verify() method for stateless challenge verification - Make secret_key REQUIRED in verify_or_challenge() and @requires_payment - Add cross-SDK compatibility tests using conformance test vectors HMAC input format: realm|method|intent|request_b64|expires|digest Output: base64url(HMAC-SHA256(secret_key, input)) This matches TypeScript's API where secret_key is required for server-side challenge creation (no random ID fallback).
0ba735d to
60c063c
Compare
Aligns Python SDK with TypeScript's Mpay.create() pattern: - Add Mpay class that wraps Method + realm + secret_key - Provides charge() and authorize() methods that use bound secret_key - No need to pass secret_key on every verify_or_challenge() call This enables the simpler API: payment = Mpay(method=TempoMethod(...), realm='...', secret_key='...') result = await payment.charge(authorization, request)
- Update api-server example to use Mpay instead of @requires_payment - Shows the recommended pattern: create handler once, call intents on it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add support for HMAC-bound challenge IDs matching the TypeScript SDK.
Changes
generate_challenge_id()function for HMAC-SHA256 ID computationChallenge.create()factory method withsecret_keyparameterChallenge.verify()method for stateless challenge verificationsecret_keyparameter toverify_or_challenge()and@requires_paymentdecoratormpay-sdksAPI
Challenge.create()
Challenge.verify()
verify_or_challenge() with secret_key
Algorithm
HMAC input format:
realm|method|intent|request_b64|expires|digest(pipe-delimited)Output:
base64url(HMAC-SHA256(secret_key, input))When
secret_keyis omitted, falls back to random IDs (secrets.token_urlsafe(16)).Cross-SDK Compatibility
All 8 conformance test cases pass, matching TypeScript and Rust SDK outputs.
Related: tempoxyz/mpp-rs#23