feat: create named API keys#86
Open
tony8713 wants to merge 1 commit into
Open
Conversation
Allow the whitelist method to be called without the apps secret so the Snapshot UI can create named API keys directly, and fix whitelist test isolation so leftover rows no longer cause flaky 409s. Co-Authored-By: Claude Opus 4.7 <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
Makes it possible to create a named API key directly from the Snapshot UI (snapshot-labs/sx-monorepo#2111).
The UI's
createApiKeyhelper posts{ method: "whitelist", params: { name, address } }to keycard with nosecretheader and expectsresult.keyback. Thewhitelistmethod already accepts{ name, address }and returns a generated{ key }(added in #79), butauthCheckerrejected it because onlygenerate_keywas exempt from the apps secret. This PR addswhitelistto the public methods so the browser call reaches the method.Changes
src/helpers/auth.ts: allowwhitelist(alongsidegenerate_key) without the apps secret.test/e2e/whitelist.test.ts: assert the returned key length, add a "no secret" case, and scopecleanupDbto this suite'sNAMEso leftover rows no longer leak between tests (this was the source of the flaky 409).README.md: documentwhitelistas a public, UI-callable method returning a key.UI -> keycard contract (from sx-monorepo#2111)
Test plan
yarn lintandyarn typecheckpass.yarn test:e2epasses 19/19, stable across 3 runs (incl. the previously flakyalready whitelisted -> 409).For reviewers to decide
generate_keyproves ownership via a signed message;whitelistdoes not. If we want ownership proof for the UI flow, the UI (sx-monorepo#2111) would need to sign and we'd verify here instead of (or in addition to) opening it up.keyshasPRIMARY KEY (owner), so a secondwhitelistfor the same wallet returns409 Address already whitelisted. The UI lists multiple keys per wallet (metadata in localStorage), but the backend currently allows only one. Supporting multiple named keys per wallet needs a schema change (surrogate PK) and reworkingupdateKey/createNewKeyto target a single row; kept out of this PR as it touches the existinggenerate_keyflow.Closes the backend gap for snapshot-labs/sx-monorepo#2111.
🤖 Generated with Claude Code