Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions apps/fee-payer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
captureEvent,
getRequestContext,
} from './lib/posthog.js'
import { blockSignTransactionMiddleware } from './lib/block-sign-transaction.js'
import { rateLimitMiddleware } from './lib/rate-limit.js'
import { getUsage } from './lib/usage.js'

Expand Down Expand Up @@ -88,7 +87,7 @@ app.get(
},
)

app.all('*', blockSignTransactionMiddleware, rateLimitMiddleware, async (c) => {
app.all('*', rateLimitMiddleware, async (c) => {
const requestContext = getRequestContext(c.req.raw)

const handler = Handler.feePayer({
Expand Down
34 changes: 0 additions & 34 deletions apps/fee-payer/src/lib/block-sign-transaction.ts

This file was deleted.

14 changes: 10 additions & 4 deletions apps/fee-payer/src/lib/rate-limit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,21 @@ export async function rateLimitMiddleware(c: Context, next: Next) {
try {
const clonedRequest = await cloneRawRequest(c.req)
const request = RpcRequest.from((await clonedRequest.json()) as never)
const serialized = request.params?.[0] as `0x76${string}`
const serialized = request.params?.[0]

if (serialized?.startsWith('0x76')) {
const transaction = Transaction.deserialize(serialized)
if (
typeof serialized === 'string' &&
(serialized.startsWith('0x76') || serialized.startsWith('0x78'))
) {
const transaction = Transaction.deserialize(serialized as `0x76${string}`)
// biome-ignore lint/suspicious/noExplicitAny: _
const from = (transaction as any).from

if (!from) {
return c.json({ error: 'Unable to determine sender for rate limiting' }, 400)
return c.json(
{ error: 'Unable to determine sender for rate limiting' },
400,
)
}

const { success } = await env.AddressRateLimiter.limit({ key: from })
Expand Down
6 changes: 2 additions & 4 deletions apps/fee-payer/test/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,11 @@ describe('fee-payer integration', () => {
}),
})

expect(response.status).toBe(403)
expect(response.status).toBe(200)
const data = (await response.json()) as {
error?: { code: number; message: string }
error?: { code: number; name: string }
}
expect(data.error).toBeDefined()
expect(data.error?.code).toBe(-32601)
expect(data.error?.message).toBe('Method not supported')
})

it('handles CORS preflight requests', async () => {
Expand Down
19 changes: 0 additions & 19 deletions apps/fee-payer/test/rate-limit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,4 @@ describe('rate-limit middleware', () => {
expect(response.status).toBe(200)
})

it('blocks eth_signTransaction before rate limiting runs', async () => {
const response = await SELF.fetch('https://fee-payer.test/', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'eth_signTransaction',
params: [{ to: '0x0000000000000000000000000000000000000000' }],
}),
})

expect(response.status).toBe(403)
const data = (await response.json()) as {
error?: { code: number; message: string }
}
expect(data.error?.code).toBe(-32601)
expect(data.error?.message).toBe('Method not supported')
})
})
76 changes: 20 additions & 56 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ catalog:
sonda: ^0.11.1
tailwind-merge: ^3.5.0
tailwindcss: ^4.2.1
tempo.ts: ^0.14.0
tempo.ts: ^0.14.2
testcontainers: ^11.11.0
tidx.ts: ^0.1.0
tw-animate-css: ^1.4.0
Expand Down
Loading