feat: add load_ucp_signing_key_from_env helper - #28
Merged
Conversation
Env-driven UCP signing-key loader with concurrent-safe caching. Reads UCP_SIGNING_KEY_JWK_PRIVATE, parses as a JWK, validates kty/crv (OKP+Ed25519 or EC+P-256), and projects to a canonical public JWK. Falls back to an ephemeral keypair when the env var is missing or whitespace-only. Three structurally identical copies of this pattern exist today across core/store/store/lib/ucp_signing.py, martin-estate/src/lib/ucp-signing.ts, and python-commerce/examples/signed_ucp_merchant.py — all collapse to a single load_ucp_signing_key_from_env() call in follow-up migrations. Env-driven precedence: embedded kid in JWK wins over env kid; empty-string kid falls through to options default. Structural kty+crv wins over env alg. Case-insensitive env-alg comparison. Caching keyed by all 5 options fields so a merchant running multiple keys from different env namespaces doesn't collide. Concurrent first-callers share cached result (lock-protected). Error messages name the env var and sanitize underlying joserfc exceptions — class name only, never the raw message, so key bytes never reach stderr/CloudWatch. Tests lock 22 behavior contracts shared with the Node sibling. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Behavior contract
Tests
Test plan
🤖 Generated with Claude Code