Repository navigation
feat: back share links with a persisted ACTA presentation #52
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
apps/credit-history/src/app/api/presentations/[ref]/route.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /** | ||
| * GET /api/presentations/[ref] — resolve a share reference. | ||
| * | ||
| * Expiration is enforced here, not by the caller: an expired reference returns | ||
| * 410 and is dropped from the store, so editing the URL cannot extend a link. | ||
| */ | ||
|
|
||
| import { NextResponse } from 'next/server'; | ||
| import { resolveStoredPresentation } from '@/lib/presentation-store'; | ||
|
|
||
| export const runtime = 'nodejs'; | ||
| export const dynamic = 'force-dynamic'; | ||
|
|
||
| const NO_STORE = { 'Cache-Control': 'no-store' } as const; | ||
|
|
||
| export async function GET( | ||
| _request: Request, | ||
| { params }: { params: Promise<{ ref: string }> } | ||
| ): Promise<NextResponse> { | ||
| const { ref } = await params; | ||
| const resolution = await resolveStoredPresentation(ref); | ||
|
|
||
| if (resolution.status === 'not_found') { | ||
| return NextResponse.json({ reason: 'not_found' }, { status: 404, headers: NO_STORE }); | ||
| } | ||
|
|
||
| if (resolution.status === 'expired') { | ||
| return NextResponse.json( | ||
| { reason: 'expired', expiresAt: resolution.expiresAt }, | ||
| { status: 410, headers: NO_STORE } | ||
| ); | ||
| } | ||
|
|
||
| return NextResponse.json( | ||
| { presentation: resolution.presentation }, | ||
| { status: 200, headers: NO_STORE } | ||
| ); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /** | ||
| * POST /api/presentations — create a shareable presentation. | ||
| * | ||
| * The holder posts the credential ids they picked, the expiration they chose | ||
| * and (when the wallet could produce one) a proof over the presentation | ||
| * digest. The response only contains the opaque reference; the payload itself | ||
| * never leaves the server. | ||
| */ | ||
|
|
||
| import { NextResponse } from 'next/server'; | ||
| import { | ||
| InvalidPresentationError, | ||
| presentationExpiresAt, | ||
| type PresentationProof, | ||
| } from '@acta-products/acta/presentation'; | ||
| import { createStoredPresentation } from '@/lib/presentation-store'; | ||
|
|
||
| export const runtime = 'nodejs'; | ||
| export const dynamic = 'force-dynamic'; | ||
|
|
||
| interface CreateRequestBody { | ||
| holder?: unknown; | ||
| credentialIds?: unknown; | ||
| expiresAt?: unknown; | ||
| createdAt?: unknown; | ||
| proof?: unknown; | ||
| } | ||
|
|
||
| function parseProof(raw: unknown): PresentationProof | undefined { | ||
| if (typeof raw !== 'object' || raw === null) return undefined; | ||
| const proof = raw as Record<string, unknown>; | ||
|
|
||
| if ( | ||
| typeof proof.digest !== 'string' || | ||
| typeof proof.signature !== 'string' || | ||
| typeof proof.verificationMethod !== 'string' | ||
| ) { | ||
| return undefined; | ||
| } | ||
|
|
||
| return { | ||
| type: 'StellarWalletSignature2026', | ||
| created: typeof proof.created === 'string' ? proof.created : new Date().toISOString(), | ||
| verificationMethod: proof.verificationMethod, | ||
| digest: proof.digest, | ||
| signature: proof.signature, | ||
| }; | ||
| } | ||
|
|
||
| export async function POST(request: Request): Promise<NextResponse> { | ||
| let body: CreateRequestBody; | ||
|
|
||
| try { | ||
| body = (await request.json()) as CreateRequestBody; | ||
| } catch { | ||
| return NextResponse.json({ error: 'Malformed JSON body.' }, { status: 400 }); | ||
| } | ||
|
|
||
| const { holder, credentialIds, expiresAt, createdAt } = body; | ||
|
|
||
| if (typeof holder !== 'string' || holder.length === 0) { | ||
| return NextResponse.json({ error: 'A holder DID is required.' }, { status: 400 }); | ||
| } | ||
|
|
||
| if (!Array.isArray(credentialIds)) { | ||
| return NextResponse.json({ error: 'credentialIds must be an array.' }, { status: 400 }); | ||
| } | ||
|
|
||
| if (expiresAt !== null && typeof expiresAt !== 'number') { | ||
| return NextResponse.json( | ||
| { error: 'expiresAt must be a timestamp in milliseconds or null.' }, | ||
| { status: 400 } | ||
| ); | ||
| } | ||
|
|
||
| if (createdAt !== undefined && typeof createdAt !== 'number') { | ||
| return NextResponse.json( | ||
| { error: 'createdAt must be a timestamp in milliseconds.' }, | ||
| { status: 400 } | ||
| ); | ||
| } | ||
|
|
||
| try { | ||
| const { ref, presentation } = await createStoredPresentation({ | ||
| holder, | ||
| credentialIds: credentialIds as string[], | ||
| expiresAt, | ||
| createdAt, | ||
| proof: parseProof(body.proof), | ||
| }); | ||
|
|
||
| return NextResponse.json( | ||
| { ref, expiresAt: presentationExpiresAt(presentation) }, | ||
| { status: 201, headers: { 'Cache-Control': 'no-store' } } | ||
| ); | ||
| } catch (err) { | ||
| if (err instanceof InvalidPresentationError) { | ||
| return NextResponse.json({ error: err.message }, { status: 400 }); | ||
| } | ||
| console.error('Failed to create presentation', err); | ||
| return NextResponse.json({ error: 'Could not create the presentation.' }, { status: 500 }); | ||
| } | ||
| } | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
Repository: ACTA-Team/products-acta
Length of output: 2506
🏁 Script executed:
Repository: ACTA-Team/products-acta
Length of output: 50379
🏁 Script executed:
Repository: ACTA-Team/products-acta
Length of output: 21304
Bind presentation creation to an authorized caller.
POST /api/presentationscurrently trustsholderandcredentialIdsfrom the JSON body after only type checks. There is no route or middleware auth for this endpoint, and the present session flow stores the connected wallet address in client-sidelocalStorage, so an unauthenticated caller can forge arbitraryholder/credentialIdsand get back a live presentation ref. Gate creation behind server-side auth/session enforcement before this ships more broadly.🤖 Prompt for AI Agents