Skip to content

feat(client): add platform API key adapters - #438

Open
kartojal wants to merge 15 commits into
feat/predictions-action-routingfrom
feat/dev-750-platform-api-keys
Open

kartojal wants to merge 15 commits into
feat/predictions-action-routingfrom
feat/dev-750-platform-api-keys

Conversation

@kartojal

@kartojal kartojal commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Adds server-only Platform API Key attribution and a browser-compatible challenge proxy on top of Predictions routing.

platformApiKey keeps X-API-Key on gateway requests. remotePlatformApiKey calls the complete configured challenge URL, and the SDK signs and completes login directly. Refresh and logout use session credentials without another application key exchange. Existing builder and submission authorization remains available through the optional submissionApiKey adapter.

Gasless actions (wallet deployment, gasless transactions, collateral return and session-key revocation) still require a builder or relayer API key, passed directly or as submissionApiKey. The relayer does not list the Gateway Access Token as a /submit credential, so a bearer session alone does not unlock them. The four actions reject a missing key with UserInputError before any signing.

Saved L2 credentials migrate directly through /v1/auth/migrate, even with a remote challenge adapter, without proxying the proof or asking for a new wallet signature. Remote challenge configuration adds no attribution to that migration. Use a server platformApiKey when platform attribution is required. All public session credentials remain plain bearer pairs.

Requests that carry credentials have them redacted from errors, and submission SigningError failures keep their type while untrusted causes are removed. Requests without credentials keep their original response and failure cause. The protected transport reads the global fetch per request, so a later patch of fetch (MSW, tracing) still applies. The adapter factories export PlatformApiKeyError and RemotePlatformApiKeyError.

Rebased onto the current #463 head, including its credential-family signing scope. Gateway headers wrap the scoped API-key headers.

Inherits #437's setup-failure session revocation and deferred new-session credential notifications.

Stack: #442 → #481 → #437 → #463 → #438 → #441.

Validation on 2026-11-03: build, lint and workspace typecheck pass, and 1,128 client tests pass. The live integration suites for public reads pass against production, except the three base-branch failures noted in #463. Live production checks on the previous head covered signed login, automatic saved-L2 migration, authenticated reads, bearer restoration and refresh, and logout with rejected refresh reuse. No trading, transfers, approvals or wallet deployment were performed.

Human approval and outstanding review threads have not been resolved automatically.


Note

Medium Risk
Changes authentication header wiring, challenge routing, and error redaction on gateway and secure clients; mistakes could leak keys or break login, though behavior is heavily tested and builder adapters are unchanged.

Overview
Adds Platform API Key support so apps can bind gateway sessions to server-issued application identity without exposing secrets in the browser.

Server: platformApiKey (from @polymarket/client/node) sends X-API-Key on Predictions gateway traffic (challenge, login, migrate, authenticated routes) while refresh and logout stay bearer-only. Browser: remotePlatformApiKey POSTs only signer / optional wallet fields to a configured challenge URL; login, refresh, and logout still hit the gateway directly. createPlatformChallenge on the node entry supports backend challenge routes.

The apiKey slot can now carry a platform adapter; existing builderApiKey / relayerApiKey / remoteBuilderSigning remain via optional submissionApiKey. Gasless paths (deploy, gasless txs, collateral return, session-key revoke) still require submission credentials—platform attribution alone does not enable gasless.

Login uses requestOwnershipChallenge (gateway or proxy createChallenge) instead of hard-coded challenge POSTs. Gateway headers are merged through authorizeGateway on public and secure Predictions clients. Credential redaction and generic auth transport errors are tightened in protectRequestErrors (including SigningError propagation through ServiceClient); requests without secrets pass through unchanged.

New docs (platform-api-keys.md) and binding types for ownership challenge requests; extensive contract tests and browser/node export boundaries.

Reviewed by Cursor Bugbot for commit 7a19092. Bugbot is set up for automated code reviews on this repo. Configure here.

@kartojal
kartojal force-pushed the feat/dev-750-platform-api-keys branch 2 times, most recently from 397bd13 to 75d9789 Compare October 20, 2026 16:38
@kartojal
kartojal force-pushed the feat/dev-750-platform-api-keys branch 2 times, most recently from 2186a39 to b8e008c Compare October 21, 2026 08:52
@kartojal
kartojal marked this pull request as ready for review October 21, 2026 08:56

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread packages/client/src/node.ts Resolved
@kartojal
kartojal force-pushed the feat/dev-750-platform-api-keys branch from b8e008c to 459c54a Compare October 21, 2026 09:12
@kartojal kartojal mentioned this pull request Oct 21, 2026
@kartojal
kartojal force-pushed the feat/dev-750-platform-api-keys branch 2 times, most recently from f22ced0 to ccc5d62 Compare October 22, 2026 14:39
@kartojal
kartojal removed this pull request from stack #443 October 22, 2026 14:42
@kartojal
kartojal changed the base branch from feat/dev-749-gateway-session to feat/predictions-action-routing October 22, 2026 14:42
@kartojal
kartojal added this pull request to stack #464 October 22, 2026 14:42
@kartojal
kartojal force-pushed the feat/dev-750-platform-api-keys branch from ccc5d62 to 0837ffd Compare October 22, 2026 15:28
@kartojal
kartojal force-pushed the feat/dev-750-platform-api-keys branch 2 times, most recently from 81d703a to 974f81a Compare October 26, 2026 08:28

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread packages/client/src/clients.ts Resolved
@kartojal
kartojal removed this pull request from stack #464 October 26, 2026 15:46
@kartojal
kartojal added this pull request to stack #482 October 26, 2026 15:47
@kartojal
kartojal force-pushed the feat/dev-750-platform-api-keys branch 2 times, most recently from efd841e to 7cfdd2a Compare November 2, 2026 14:23
@kartojal
kartojal force-pushed the feat/dev-750-platform-api-keys branch from 7cfdd2a to 4106448 Compare November 2, 2026 16:55

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4106448. Configure here.

Comment thread packages/client/src/ServiceClient.ts Resolved
kartojal and others added 15 commits November 3, 2026 18:27
…helper

Rename legacyApiKey to submissionApiKey, add createPlatformChallenge to the node entry point for backend challenge proxies, use camelCase in the proxy body, and drop the UserInputError aliases. Gasless actions now share one check that any bearer session satisfies. Move earlier-stack docs, changeset and test out of this PR.
Wallet submissions again require a builder or relayer API key. A bearer
session alone is not a confirmed relayer credential. Requests without
credentials keep their response and failure cause, and the protected
transport reads the global fetch per request. Export error unions for
the platform adapter factories.

Fold the narrow request-error suite into the existing redaction tests
and remove overlapping platform adapter cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Predictions requests carry API-key headers only for the operations of
the key's credential family, so the signing failure cases use the
mapped order read instead of an unmapped path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kartojal
kartojal force-pushed the feat/dev-750-platform-api-keys branch from 281366d to 7a19092 Compare November 3, 2026 17:52
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.

3 participants