feat: IPFS pinning + content-type validation for milestone evidence - #3
Open
mohadon0 wants to merge 1 commit into
Open
feat: IPFS pinning + content-type validation for milestone evidence#3mohadon0 wants to merge 1 commit into
mohadon0 wants to merge 1 commit into
Conversation
Extend the validator milestone submission endpoint to validate and pin
evidence before storing. evidence_uri is always persisted as a CID.
Endpoint: POST /api/validators/milestone
- If evidence_uri is already an IPFS CID (v0 or v1), stored as-is
- If evidence_uri is an HTTPS URL:
- Fetch the content (using axios maxContentLength to enforce size)
- Validate Content-Type: accept video/*, image/*, application/pdf,
text/plain; reject others with 422
- Enforce EVIDENCE_MAX_BYTES limit (env var, default 50 MB); 422 on
exceeded
- Pin to IPFS via Pinata pinFileToIPFS; store the returned CID
- Non-CID, non-HTTPS values rejected with 400
New lib: lib/evidencePinner.ts
- isIpfsCid() — CIDv0 and CIDv1 detection
- isAcceptedContentType() — content-type allow-list check
- downloadAndPin() — fetches URL, validates type+size, pins to Pinata
- Typed errors: EvidenceContentTypeError (→422), EvidenceSizeError (→422),
EvidencePinError (→502)
Tests: __tests__/api/validators/milestone/route.test.ts (18 passing)
- Auth guard (401 without session)
- Field validation (400 for missing fields, bad URI format)
- CID passthrough (CIDv0 and CIDv1 stored without Pinata call)
- HTTPS pinning for each accepted type (video, image, PDF, text)
- 422 for unsupported types (application/x-executable, application/zip)
- 422 for oversized files (EVIDENCE_MAX_BYTES exceeded)
- 502 when Pinata upload fails
- Stored record always has evidence_uri as a CID
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.
Summary
Extends
POST /api/validators/milestoneto validateevidence_uricontent type, enforce a maximum file size, and pin HTTPS URLs to IPFS before storage. Theevidence_urifield in the stored record is always a CID — never a raw HTTPS URL.Changes
app/api/validators/milestone/route.ts(new){ playerId, validatorId, description, evidence_uri }in the request bodyevidence_uriis already an IPFS CID (v0 or v1) it is stored as-is — no Pinata callevidence_uriis an HTTPS URL:maxContentLengthenforcesEVIDENCE_MAX_BYTES)Content-Type: acceptvideo/*,image/*,application/pdf,text/plain— reject everything else with 422EVIDENCE_MAX_BYTES(env var, default 50 MB) — 422pinFileToIPFS; store the returned CIDlib/evidencePinner.ts(new)isIpfsCid(value)— detects CIDv0 (Qm…) and CIDv1 (bafy…/z…)isAcceptedContentType(ct)— allow-list checkgetEvidenceMaxBytes()— readsEVIDENCE_MAX_BYTESenv var (default 50 MB)downloadAndPin(url)— fetches, validates, and pins; throws typed errors:EvidenceContentTypeError→ 422EvidenceSizeError→ 422EvidencePinError→ 502ACCEPTED_CONTENT_TYPESexported constantTests
__tests__/api/validators/milestone/route.test.ts— 18 tests covering:video/mp4,image/jpeg,application/pdf,text/plain)application/x-executable,application/zip)EVIDENCE_MAX_BYTESevidence_uriis always a CID, never the original URLAll 18 tests pass.
Acceptance Criteria
application/x-executableURL is rejected with HTTP 422EVIDENCE_MAX_BYTESare rejectedevidence_uriin the DB is always a CID