-
Notifications
You must be signed in to change notification settings - Fork 71
Prepare Stellar Binding #197
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,37 +1,20 @@ | ||
| import { Request, Response } from "express"; | ||
| import { Request, Response } from 'express'; | ||
| import { prepareClaimTx } from '../../use-cases/prepareClaimTx.use-case'; | ||
| import { submitSignedClaim } from '../../use-cases/submitSignedClaim.use-case'; | ||
|
|
||
| /** | ||
| * Stub controller for NFT functionality | ||
| * This replaces the original controller that referenced deleted services | ||
| * TODO: Implement proper NFT controller using new modular architecture | ||
| */ | ||
| class NFTController { | ||
| async createNFT(req: Request, res: Response) { | ||
| res.status(501).json({ | ||
| message: "NFT service temporarily disabled during migration", | ||
| error: "Service migration in progress" | ||
| }); | ||
| export class NFTController { | ||
| static async prepareClaim(req: Request, res: Response) { | ||
| // TODO(security): Validar que el usuario autenticado puede reclamar el NFT. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π‘ Verification agent π§© Analysis chainImplement authorization now; donβt trust claimantPublicKey from the client. Enforce that the authenticated user is allowed to claim this NFT (e.g., tie claimantPublicKey to the session/user and verify nftId is in a claimable state). Return 403 when not authorized. π Script executed: #!/bin/bash
# Check routing and auth gating for these endpoints
rg -nP -C2 "(router|app)\\.(post|use)\\(.*nft/claim/(prepare|submit)" -g '!**/dist/**'
rg -nP -C2 "NFTController\\.(prepareClaim|submitClaim)|new\\s+NFTController\\(\\)"
rg -nP -C2 "(auth|passport|jwt|ensure.*Auth|verify.*Token|requireAuth)"Length of output: 101504 π Script executed: #!/bin/bash
sed -n '1,200p' src/routes/nftRoutes.tsLength of output: 805 π Script executed: #!/bin/bash
sed -n '1,200p' src/modules/nft/presentation/controllers/NFTController.stub.tsLength of output: 897 Enforce authorization on NFT claim flows
π€ Prompt for AI Agents |
||
| const { nftId, claimantPublicKey } = req.body; | ||
| const result = await prepareClaimTx({ nftId, claimantPublicKey }); | ||
| res.status(200).json(result); | ||
| } | ||
|
Comment on lines
+6
to
12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π οΈ Refactor suggestion Add authZ, input validation, and error handling; wire NextFunction and try/catch. Current handlers trust req.body and can throw unhandled rejections. Validate inputs, surface 400s, and forward unexpected errors to the error middleware. Apply within these ranges: - static async prepareClaim(req: Request, res: Response) {
- // TODO(security): Validar que el usuario autenticado puede reclamar el NFT.
- const { nftId, claimantPublicKey } = req.body;
- const result = await prepareClaimTx({ nftId, claimantPublicKey });
- res.status(200).json(result);
- }
+ static async prepareClaim(req: Request, res: Response, next: NextFunction) {
+ try {
+ // TODO(security): Validate that the authenticated user can claim the NFT.
+ const { nftId, claimantPublicKey } = req.body ?? {};
+ if (typeof nftId !== 'string' || typeof claimantPublicKey !== 'string' || !nftId || !claimantPublicKey) {
+ return res.status(400).json({
+ error: 'Invalid payload',
+ details: { nftId: 'required string', claimantPublicKey: 'required string' },
+ });
+ }
+ const result = await prepareClaimTx({ nftId, claimantPublicKey });
+ return res.status(200).json(result);
+ } catch (err) {
+ return next(err);
+ }
+ }- static async submitClaim(req: Request, res: Response) {
- const { nftId, signedXdr } = req.body;
- const result = await submitSignedClaim({ nftId, signedXdr });
- res.status(202).json(result);
- }
+ static async submitClaim(req: Request, res: Response, next: NextFunction) {
+ try {
+ const { nftId, signedXdr } = req.body ?? {};
+ if (typeof nftId !== 'string' || typeof signedXdr !== 'string' || !nftId || !signedXdr) {
+ return res.status(400).json({
+ error: 'Invalid payload',
+ details: { nftId: 'required string', signedXdr: 'required base64 XDR string' },
+ });
+ }
+ const result = await submitSignedClaim({ nftId, signedXdr });
+ return res.status(202).json(result);
+ } catch (err) {
+ return next(err);
+ }
+ }Also update the import (outside the changed ranges): -import { Request, Response } from "express";
+import { Request, Response, NextFunction } from "express";Also applies to: 14-17 π€ Prompt for AI Agentsπ‘ Verification agent π§© Analysis chainStatic-only class vs default instance export will break callers. You export an instance ( Safer bridge fix (keeps static methods and a callable default): -export default new NFTController();
+export default {
+ prepareClaim: NFTController.prepareClaim,
+ submitClaim: NFTController.submitClaim,
+};Alternatively, remove π Script executed: #!/bin/bash
# Find usages that import the default and call controller methods
rg -nP -C2 "import\\s+\\w+\\s+from\\s+['\"]\\.?\\.?/.*NFTController" -g '!**/dist/**'
rg -nP -C2 "\\w+\\.prepareClaim\\(|\\w+\\.submitClaim\\(" -g '!**/dist/**'Length of output: 837 Export mismatch: static methods vs default instance import NFTController from ".../NFTController.stub";
NFTController.prepareClaim(...)will get -export default new NFTController();
+export default NFTController;Alternatively, convert these to instance methods (remove export default {
prepareClaim: NFTController.prepareClaim,
submitClaim: NFTController.submitClaim,
};π€ Prompt for AI Agents |
||
|
|
||
| async getNFTById(req: Request, res: Response) { | ||
| res.status(501).json({ | ||
| message: "NFT service temporarily disabled during migration", | ||
| error: "Service migration in progress" | ||
| }); | ||
| } | ||
|
|
||
| async getNFTsByUserId(req: Request, res: Response) { | ||
| res.status(501).json({ | ||
| message: "NFT service temporarily disabled during migration", | ||
| error: "Service migration in progress" | ||
| }); | ||
| } | ||
|
|
||
| async deleteNFT(req: Request, res: Response) { | ||
| res.status(501).json({ | ||
| message: "NFT service temporarily disabled during migration", | ||
| error: "Service migration in progress" | ||
| }); | ||
| static async submitClaim(req: Request, res: Response) { | ||
| const { nftId, signedXdr } = req.body; | ||
| const result = await submitSignedClaim({ nftId, signedXdr }); | ||
| res.status(202).json(result); | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix duplicate Express import (Biome noRedeclare).
Youβre importing Request/Response twice; Biome flags this and CI will fail.
Apply:
-import { Request, Response } from 'express';π Committable suggestion
π§° Tools
πͺ Biome (2.1.2)
[error] 2-2: Shouldn't redeclare 'Request'. Consider to delete it or rename it.
'Request' is defined here:
(lint/suspicious/noRedeclare)
[error] 2-2: Shouldn't redeclare 'Response'. Consider to delete it or rename it.
'Response' is defined here:
(lint/suspicious/noRedeclare)
π€ Prompt for AI Agents