fix(python): use bytes for nonce internally
Description
This bug was seen while working with chaoschain. The problem was that the nonce was being stored as bytes in the payment header, but the sign_payment_header() function expected it to be a hex string. This caused the bytes.fromhex() function to fail.
The existing tests for exact.py were manually converting the nonce to a hex string before signing, which was masking the problem.
ChaosChain SDK uses the x402 library by preparing the payment header, and then signing it immediately with no intermediary steps. I believe this is the main way most users will use the library, which is why I'm submitting this PR.
Standardized on bytes throughout the internal API:
- prepare_payment_header() continues to store nonces as bytes (natural format)
- sign_payment_header() now expects and uses bytes directly
- Conversion to hex string only happens for JSON serialization in encode_payment()
- Better types for the PaymentHeader instead of
Dict[str, Any] - updates uv.lock file (I didn't make any dep changes.. can remove this change if you need me to)
No existing issues nor PRs were found in the github repo.
Tests
Tested various ways by either passing through hex strings or bytes, or accepting both inside sign_payment_header which felt wrong.
Some testing artifacts can be seen at https://gist.github.com/SgtPooki/6dafe4828509534256f624fa56f81e8b, but the primary testing focused on removing workarounds from existing tests, and adding some assertions
Checklist
- [x] I have formatted and linted my code
- [x] All new and existing tests pass
- [x] My commits are signed (required for merge) -- you may need to rebase if you initially pushed unsigned commits
🟡 Heimdall Review Status
| Requirement | Status | More Info | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Reviews |
🟡
0/1
|
Denominator calculation
|
@SgtPooki is attempting to deploy a commit to the Coinbase Team on Vercel.
A member of the Team first needs to authorize it.