feat: implement API key usage tracking & vault validation hardening#939
Merged
1nonlypiece merged 3 commits intoJun 29, 2026
Merged
Conversation
|
@midexol Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
api key usage tracking plus vault hardening, both land cleanly |
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.
Description
This PR resolves #855 and #882 by introducing organization-scoped API key usage analytics, last-used tracking, and hardening destination-address/memo validation constraints during vault creation.
Key Changes
1. API Key Usage Analytics (#855)
last_used_at(TIMESTAMPTZ),request_count(INTEGER), andlast_ip(TEXT) columns to theapi_keystable.src/services/apiKeys.tsthat flushes updates asynchronously to the database, ensuring zero performance impact on the authentication path.GET /api/orgs/:orgId/api-keys/usageendpoint. Access is restricted to organization owners and admins, and secret keys/hashes are redacted from output.requireOrgAccessto recognize legacyauthUser?.userIdso it runs seamlessly with the API keys user auth middleware.2. Vault Destination Hardening (#882)
G...) and muxed (M...) addresses, and reject contract (C...) addresses.GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAXXXXXXXXXXXXXXXXAAAAWHF) and all-ones (GD7777777777777777777777777777777777777777777777777773DB) public keys for success and failure destinations.M...) addresses (classic addresses lacking memos are rejected).3. Baseline Bug Fixes
validateEnvconfiguration helper insrc/config/env.ts.metricsRateLimitermiddleware reference insrc/app.ts.getLatestListenerLagexport insrc/services/monitor.ts.Verification
Automated Unit Tests
Created and ran new unit test suites:
src/tests/apiKeys.usageAnalytics.test.ts):records API key usage successfully on authenticationGET /api/orgs/:orgId/api-keys/usage returns usage stats and restricts accesssrc/tests/vaultValidation.destination.test.ts):accepts valid classic and muxed addressesrejects contract addresses for verifier and destinationsrejects unsafe zero/burn and all-ones addresses for success/failure destinationsenforces memo via muxed address for exchange destinations requiring a memoAll tests passed successfully on the first run.
closes #855
closes #882