Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(indexer): verify call with alchemy signing key #318

Merged
merged 1 commit into from
Aug 21, 2024
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
2 changes: 1 addition & 1 deletion apps/indexer/.env-sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ SEPOLIA_RPC=https://eth-sepolia.g.alchemy.com/v2/xxx
ISSUER_KEY=xxx
ISSUER_ADDRESS=0x
DFUSE_API_KEY=server_xxx
ALCHEMY_SECRET_KEY=xxx
ALCHEMY_ACTIVITY_SIGNING_KEY=xxx
4 changes: 3 additions & 1 deletion apps/indexer/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export const appConfig = {
issuerKey: process.env.ISSUER_KEY || '',
issuerAddress: (process.env.ISSUER_ADDRESS || '') as Address,
issuerAccount: privateKeyToAccount(`0x${process.env.ISSUER_KEY}`),
alchemySecretKey: process.env.ALCHEMY_SECRET_KEY || '',
alchemy: {
activitySigningKey: process.env.ALCHEMY_ACTIVITY_SIGNING_KEY || '',
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (bug_risk): Consider more robust error handling for missing environment variables.

Instead of defaulting to an empty string, it might be better to throw an error or use a more explicit default value for critical configuration items like signing keys. This could prevent silent failures and make troubleshooting easier.

Suggested change
activitySigningKey: process.env.ALCHEMY_ACTIVITY_SIGNING_KEY || '',
activitySigningKey: process.env.ALCHEMY_ACTIVITY_SIGNING_KEY ?? (() => {
throw new Error('ALCHEMY_ACTIVITY_SIGNING_KEY is not set in the environment');
})(),

},
},
...smartsaleEnv.test,
}
5 changes: 4 additions & 1 deletion apps/indexer/src/routes/alchemy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export function alchemyWebhook(req: Request, res: Response) {
function validateAlchemySignature(req: Request): boolean {
const alchemySignature = req.headers['x-alchemy-signature'] as string
const payload = JSON.stringify(req.body)
const hmac = crypto.createHmac('sha256', appConfig.evm.alchemySecretKey)
const hmac = crypto.createHmac(
'sha256',
appConfig.evm.alchemy.activitySigningKey,
)
hmac.update(payload)
return alchemySignature === hmac.digest('hex')
}
Loading