feat: replace API key auth with optional affiliate address tracking#11959
feat: replace API key auth with optional affiliate address tracking#119590xApotheosis merged 5 commits intodevelopfrom
Conversation
Replace the X-API-Key header authentication with an optional X-Affiliate-Address header across the Public API and Swap Widget. The API now works without any authentication — when an affiliate address is provided, it's attached to the response for downstream fee attribution. Closes #11958
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughReplace API key-based authentication with optional Arbitrum affiliate address tracking via X-Affiliate-Address header. Remove STATIC_API_KEYS and apiKeyAuth middleware. Introduce affiliateAddress middleware validating EVM addresses. Update response schemas and widget prop from apiKey to affiliateAddress. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Remove the authentication block from the Scalar API reference options that was still referencing apiKeyAuth and the test API key, causing the docs UI to show an Authentication section. Also clean up a stale "no auth required" comment on the health check endpoint. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The server no longer reads X-API-Key, so the deprecated client-side code path was dead code sending a header nobody listens for. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…p endpoints The header now appears in the Scalar UI endpoint views for /v1/swap/rates and /v1/swap/quote. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
0xApotheosis
left a comment
There was a problem hiding this comment.
Does exactly what it says on the box.
Confirmed all API endpoints still work and that the widget still works too.
I also removed backwards compatibility with the API key and updated the widget accordingly. Let's do this in one atomic update as we currently have no external consumers (except maybe @BitHighlander!).
Description
Replaces API key authentication with optional affiliate address tracking across the Public API and Swap Widget packages. Partners can now attribute swaps by passing an Arbitrum address via the
X-Affiliate-Addressheader — no API key required. The API is now fully public.Breaking change: The
apiKeyprop has been removed fromSwapWidgetPropsandApiClientConfig. Consumers using the deprecatedapiKeyprop must switch toaffiliateAddress(or remove the prop entirely — the widget works without it).Key changes:
STATIC_API_KEYS,apiKeyAuth/optionalApiKeyAuthmiddleware,PartnerConfigtype. NewaffiliateAddressmiddleware validates optional EVM addresses (/^0x[0-9a-fA-F]{40}$/), returns 400 for invalid format, passes through silently when missing.affiliateAddressis echoed in quote/rates responses when provided.apiKeyprop withaffiliateAddressonSwapWidgetProps. RemovedapiKeyfromApiClientConfigand allx-api-keyheader logic. Client sendsX-Affiliate-Addressheader whenaffiliateAddressis provided. Updated README and demo app.apiKeyAuthsecurity scheme andsecurityannotations from swap endpoints. RegisteredX-Affiliate-Addressas an OpenAPI header parameter on/v1/swap/ratesand/v1/swap/quote. AddedaffiliateAddressto response schemas. Removed stale auth config from Scalar docs UI.X-Affiliate-Addressinstead ofX-API-Key.What stays the same:
affiliateBpsremains hardcoded atDEFAULT_AFFILIATE_BPS = '60'— only attribution changes, not fee ratesIssue (if applicable)
closes #11958
Risk
Low risk. This PR removes authentication barriers (API keys) and adds optional address tracking. No on-chain transaction changes. No fee calculation changes. The affiliate address is purely metadata for attribution.
None. This only affects the Public API authentication layer and Widget configuration. No on-chain interactions are modified.
Testing
Engineering
Build and start the public API:
yarn workspace @shapeshiftoss/public-api build:bundle && yarn workspace @shapeshiftoss/public-api start:prodAnonymous usage (no affiliate address):
With valid affiliate address:
With invalid affiliate address:
Verify docs UI: Open
http://localhost:3001/docs— no Authentication section should appear, and swap endpoints should showX-Affiliate-Addressas an optional header parameter.Widget demo: Run
yarn devinpackages/swap-widget— confirm demo usesaffiliateAddressprop and network requests includeX-Affiliate-Addressheader.Type check:
yarn type-checkpassesLint:
yarn lintpasses with 0 errorsOperations
This is an API/SDK change only. No user-facing UI changes in the main web app. Widget consumers will opt-in by updating their props.
Screenshots (if applicable)
N/A — no UI changes in the main web application.
Summary by CodeRabbit
Release Notes
New Features
Breaking Changes
apiKeytoaffiliateAddressDocumentation