Skip to content

feat: replace API key auth with optional affiliate address tracking#11959

Merged
0xApotheosis merged 5 commits intodevelopfrom
feat/affiliate-address-tracking
Feb 23, 2026
Merged

feat: replace API key auth with optional affiliate address tracking#11959
0xApotheosis merged 5 commits intodevelopfrom
feat/affiliate-address-tracking

Conversation

@NeOMakinG
Copy link
Collaborator

@NeOMakinG NeOMakinG commented Feb 19, 2026

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-Address header — no API key required. The API is now fully public.

Breaking change: The apiKey prop has been removed from SwapWidgetProps and ApiClientConfig. Consumers using the deprecated apiKey prop must switch to affiliateAddress (or remove the prop entirely — the widget works without it).

Key changes:

  • Public API: Removed STATIC_API_KEYS, apiKeyAuth/optionalApiKeyAuth middleware, PartnerConfig type. New affiliateAddress middleware validates optional EVM addresses (/^0x[0-9a-fA-F]{40}$/), returns 400 for invalid format, passes through silently when missing. affiliateAddress is echoed in quote/rates responses when provided.
  • Widget: Replaced apiKey prop with affiliateAddress on SwapWidgetProps. Removed apiKey from ApiClientConfig and all x-api-key header logic. Client sends X-Affiliate-Address header when affiliateAddress is provided. Updated README and demo app.
  • OpenAPI docs: Removed apiKeyAuth security scheme and security annotations from swap endpoints. Registered X-Affiliate-Address as an OpenAPI header parameter on /v1/swap/rates and /v1/swap/quote. Added affiliateAddress to response schemas. Removed stale auth config from Scalar docs UI.
  • Smoke tests: Removed auth-gate tests (401 checks). Added tests verifying endpoints work without authentication. Updated rate tests to use X-Affiliate-Address instead of X-API-Key.

What stays the same:

  • affiliateBps remains hardcoded at DEFAULT_AFFILIATE_BPS = '60' — only attribution changes, not fee rates
  • All existing swap/quote/rate logic is untouched
  • Anonymous usage (no affiliate address) continues to work exactly as before

Issue (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.

What protocols, transaction types, wallets or contract interactions might be affected by this PR?

None. This only affects the Public API authentication layer and Widget configuration. No on-chain interactions are modified.

Testing

Engineering

  1. Build and start the public API:

    yarn workspace @shapeshiftoss/public-api build:bundle && yarn workspace @shapeshiftoss/public-api start:prod
  2. Anonymous usage (no affiliate address):

    # Should return 200 with rates, no affiliateAddress field in response
    curl "http://localhost:3001/v1/swap/rates?sellAssetId=eip155:1/slip44:60&buyAssetId=eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48&sellAmountCryptoBaseUnit=1000000000000000000"
  3. With valid affiliate address:

    # Should return 200 with affiliateAddress echoed in response
    curl -H "X-Affiliate-Address: 0x1234567890abcdef1234567890abcdef12345678" \
      "http://localhost:3001/v1/swap/rates?sellAssetId=eip155:1/slip44:60&buyAssetId=eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48&sellAmountCryptoBaseUnit=1000000000000000000"
  4. With invalid affiliate address:

    # Should return 400 with INVALID_AFFILIATE_ADDRESS error
    curl -H "X-Affiliate-Address: not-an-address" \
      "http://localhost:3001/v1/swap/rates?sellAssetId=eip155:1/slip44:60&buyAssetId=eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48&sellAmountCryptoBaseUnit=1000000000000000000"
  5. Verify docs UI: Open http://localhost:3001/docs — no Authentication section should appear, and swap endpoints should show X-Affiliate-Address as an optional header parameter.

  6. Widget demo: Run yarn dev in packages/swap-widget — confirm demo uses affiliateAddress prop and network requests include X-Affiliate-Address header.

  7. Type check: yarn type-check passes

  8. Lint: yarn lint passes with 0 errors

Operations

  • 🏁 My feature is behind a flag and doesn't require operations testing (yet)

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

    • Added optional affiliate address tracking via X-Affiliate-Address header for API requests
    • Quote and rate API responses now include affiliate address field
  • Breaking Changes

    • Removed API key authentication requirement for API endpoints
    • Swap widget prop renamed from apiKey to affiliateAddress
  • Documentation

    • Updated API documentation and README with affiliate address tracking guidance

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
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 19, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Replace 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

Cohort / File(s) Summary
Public API Auth & Config
packages/public-api/src/config.ts, packages/public-api/src/middleware/auth.ts, packages/public-api/src/types.ts
Removed STATIC_API_KEYS constant and apiKeyAuth/optionalApiKeyAuth middleware. Introduced affiliateAddress middleware that validates X-Affiliate-Address header against EVM address regex, attaching validated address to request context. Replaced PartnerConfig type with AffiliateInfo containing affiliateAddress field.
Public API Routes & Documentation
packages/public-api/src/index.ts, packages/public-api/src/routes/rates.ts, packages/public-api/src/routes/quote.ts, packages/public-api/src/docs/openapi.ts, packages/public-api/src/routes/docs.ts
Updated swap/rates/quote routes to use affiliateAddress middleware instead of apiKeyAuth. Added affiliateAddress field to QuoteResponse and RateResponse. Removed apiKeyAuth security scheme from OpenAPI docs and added X-Affiliate-Address header documentation. Removed API key configuration from API reference UI setup.
Standalone Server
packages/public-api/src/server-standalone.ts
Replaced API key authentication with affiliate address validation. Updated middleware application, health/startup messages, and mock endpoint comments to reflect affiliate-based tracking instead of API key auth.
Public API Tests
packages/public-api/tests/test-config.ts, packages/public-api/tests/smoke-tests.ts
Replaced TEST_API_KEY export with TEST_AFFILIATE_ADDRESS constant using a sample Arbitrum address. Updated smoke tests to use X-Affiliate-Address header instead of X-API-Key, with corresponding test assertion updates and 30-second timeout additions.
Swap Widget Types & Components
packages/swap-widget/src/types/index.ts, packages/swap-widget/src/api/client.ts, packages/swap-widget/src/components/SwapWidget.tsx, packages/swap-widget/src/demo/App.tsx
Replaced apiKey prop with affiliateAddress in SwapWidgetProps. Updated API client to send x-affiliate-address header instead of x-api-key. Modified widget component to pass affiliateAddress to API client creation. Updated demo app to use sample affiliate address instead of test API key.
Swap Widget Documentation
packages/swap-widget/README.md
Updated Quick Start example, props table, and examples to replace apiKey references with affiliateAddress. Renamed API Key section to Affiliate Address with guidance explaining optional affiliate tracking without registration requirement.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • NeOMakinG
  • gomesalexandre

Poem

🐰 No more keys locked in a static sight,
Just addresses gleaming, open and bright,
Affiliate rewards flow free and clear,
No registration needed, come one and all near!
Authentication melts into the EVM air. 🔗✨

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/affiliate-address-tracking

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

0xApotheosis and others added 4 commits February 23, 2026 16:57
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 0xApotheosis marked this pull request as ready for review February 23, 2026 06:14
@0xApotheosis 0xApotheosis requested a review from a team as a code owner February 23, 2026 06:14
Copy link
Member

@0xApotheosis 0xApotheosis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!).

@0xApotheosis 0xApotheosis merged commit 9d73634 into develop Feb 23, 2026
3 of 4 checks passed
@0xApotheosis 0xApotheosis deleted the feat/affiliate-address-tracking branch February 23, 2026 06:16
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.

feat: Replace API key authentication with Arbitrum affiliate address tracking

2 participants