Skip to content

refactor(examples): use load_ucp_signing_key_from_env in signed_ucp_merchant - #29

Merged
vvillait88 merged 1 commit into
mainfrom
tec-302-example-ucp
May 14, 2026
Merged

refactor(examples): use load_ucp_signing_key_from_env in signed_ucp_merchant#29
vvillait88 merged 1 commit into
mainfrom
tec-302-example-ucp

Conversation

@vvillait88

Copy link
Copy Markdown
Contributor

Summary

  • Switch `examples/signed_ucp_merchant.py` from ~50 lines of inline env-loader logic (asyncio.Lock + cached future + JWK parsing + alg detection + ephemeral fallback) to a single `load_ucp_signing_key_from_env` call.
  • Net 43-line reduction (178 → 135 lines).
  • Behavior-equivalent for the env-load happy path; the helper's case-insensitive env-alg comparison is more lenient than the example's prior exact-match check.

Bonus

Fix two pre-existing ty errors in the selftest route (`JSONResponse.body` is typed as `bytes | memoryview[int]`; wrap in `bytes(...)` so `json.loads` accepts both branches). Pre-existing issue not caught by lefthook because `ty` only runs on `agentscore_commerce/`, not `examples/`.

Test plan

  • `uv run pytest` — full suite 1024 pass / 3 skip, coverage 95.24%
  • `uv run ruff check`, `uv run ruff format --check`, `uv run ty check examples/signed_ucp_merchant.py` — all green
  • Line count: 178 → 135 (43-line reduction matches `~45 line` target)

🤖 Generated with Claude Code

…erchant

Switches signed_ucp_merchant.py from inline env-loader logic (~50 lines:
asyncio.Lock + cached future + JWK parsing + alg detection + ephemeral
fallback) to the SDK helper. Behavior equivalent; case-insensitive env alg
comparison via the helper is more lenient than the example's prior
exact-match check.

The example now exercises the same concurrent-safe caching the real
consumers use, without duplicating the wiring. Net reduction: 43 lines
(178 → 135).

Bonus: fix two pre-existing ty errors in the selftest route — wrap
JSONResponse.body in bytes() to satisfy the bytes-or-memoryview union
that json.loads doesn't accept directly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vvillait88
vvillait88 merged commit 7a9b43c into main May 14, 2026
7 checks passed
@vvillait88
vvillait88 deleted the tec-302-example-ucp branch May 14, 2026 16:15
vvillait88 added a commit that referenced this pull request May 14, 2026
## Summary

Additive update to the README inventory table — documents the helpers
that landed in PRs #22#29 + the public-surface guard in #30. Pure docs,
no code changes.

## What was added

**`agentscore_commerce.identity` (package level)** row:
- `load_ucp_signing_key_from_env` + `LoadUCPSigningKeyOptions`
(env-driven UCP signing key loader; cached, alg-detected, sanitized
errors)
- `hash_operator_token` (sha256 hex of plaintext `opc_...` for merchants
persisting `operator_token_id` to their own DB)

**`agentscore_commerce.payment`** row:
- `extract_payment_signer` now documents both the positional
`x402_payment_header` path AND the `authorization_header=` MPP kwarg
(`did:pkh:eip155` / `did:pkh:solana` source DIDs)
- `detect_rail_from_headers` (returns `"x402"` / `"mpp"` / `None`)
- `classify_orchestration_error` (companion to
`classify_x402_settle_result` for orchestration-time exceptions)
- `zero_amount_carve_out` (skip CDP/pympp upstream when settle_cents ==
0)
- `usd_to_atomic` (Decimal-based USD → atomic int, ROUND_HALF_UP)

## Test plan

Docs-only; no code changes. Markdown renders cleanly in the existing
table.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant