Multi-framework middleware (Express, Koa, PassportJS, Well-Known Components) for authenticating HTTP requests signed with @decentraland/SignedFetch. Current stable version is 1.3.0 (June 2024), with minor releases every 6–12 months. Key differentiator: unified auth verification across Node.js web frameworks using Ethereum signature-based identity, suitable for Decentraland dApps. Supports optional verification, configurable expiration, and metadata content verification. Depends on @decentraland/crypto for signature logic.
npm install decentraland-crypto-middlewareVerified import paths — ran on the pinned version, not inferred.
Sets up an Express route protected by Decentraland signature verification using the express() middleware.
Use `req: Request & DecentralandSignatureData` for correct typing.
Remove any `expiration` option passed to middleware – it is ignored.
Use `passport.authenticate('decentraland')` exactly.Set `verifyMetadataContent: false` in options if you don't want metadata content verification.
Check for `authMetadata` existence before accessing its properties.
Ensure the middleware is added to the route and if using `optional: true`, check `req.auth` for undefined.
Verify that the client uses `@decentraland/SignedFetch` correctly and that the signing identity matches the expected address.
Re-sign the request with a fresh timestamp or increase the `expiration` option (though removed in later versions, check version).
Use `req.auth` directly as a string, not `req.auth()`.