-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/shielded balance #19
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
Show all changes
9 commits
Select commit
Hold shift + click to select a range
139a4f1
feat: restore auth panel
Dodecahedr0x 4b2370c
feat: centralize mock tee def
Dodecahedr0x 33325dc
feat: remove mock
Dodecahedr0x 8fc18c3
feat: add shielded balances
GabrielePicco beb45a2
feat: simplify
GabrielePicco 109ad89
feat: add send from/to shielded
GabrielePicco 4c29c1c
feat: add send from/to shielded balance
GabrielePicco d79fc82
chore: resolve merge conflicts and dependencies
GabrielePicco f589999
chore: enhance UI
GabrielePicco 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
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,7 @@ | ||
| version: v1.25.0 | ||
| ignore: | ||
| SNYK-JS-BIGINTBUFFER-3364597: | ||
| - "*": | ||
| reason: No patched version is available for this transitive dependency pulled through @bonfida/spl-name-service. | ||
| expires: 2026-08-22T00:00:00.000Z | ||
| patch: {} |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import { NextRequest, NextResponse } from "next/server"; | ||
| import { PublicKey } from "@solana/web3.js"; | ||
| import { | ||
| PAYMENTS_CLUSTER, | ||
| PAYMENTS_ENDPOINTS, | ||
| getPaymentsApiUrl, | ||
| getPaymentsTimeoutSignal, | ||
| } from "@/lib/payments"; | ||
| import { getPaymentsErrorMessage } from "@/lib/payments-errors"; | ||
|
|
||
| interface ShieldBuildRequest { | ||
| mode?: "shield" | "unshield"; | ||
| owner?: string; | ||
| mint?: string; | ||
| amount?: string; | ||
| } | ||
|
|
||
| export async function POST(request: NextRequest) { | ||
| try { | ||
| const body = (await request.json()) as ShieldBuildRequest; | ||
| const { mode, owner, mint, amount } = body; | ||
|
|
||
| if ( | ||
| (mode !== "shield" && mode !== "unshield") || | ||
| typeof owner !== "string" || | ||
| typeof mint !== "string" || | ||
| typeof amount !== "string" | ||
| ) { | ||
| return NextResponse.json( | ||
| { error: "Missing or invalid shield parameters" }, | ||
| { status: 400 } | ||
| ); | ||
| } | ||
|
|
||
| try { | ||
| new PublicKey(owner); | ||
| new PublicKey(mint); | ||
| } catch { | ||
| return NextResponse.json( | ||
| { error: "Invalid owner or mint public key" }, | ||
| { status: 400 } | ||
| ); | ||
| } | ||
|
|
||
| if (!/^[1-9]\d*$/.test(amount)) { | ||
| return NextResponse.json( | ||
| { error: "amount must be a positive integer string" }, | ||
| { status: 400 } | ||
| ); | ||
| } | ||
|
|
||
| const amountBigInt = BigInt(amount); | ||
| if (amountBigInt > BigInt(Number.MAX_SAFE_INTEGER)) { | ||
| return NextResponse.json( | ||
| { error: "amount exceeds the maximum supported integer size" }, | ||
| { status: 400 } | ||
| ); | ||
| } | ||
|
|
||
| const endpoint = | ||
| mode === "shield" | ||
| ? PAYMENTS_ENDPOINTS.deposit | ||
| : PAYMENTS_ENDPOINTS.withdraw; | ||
|
|
||
| const upstreamRes = await fetch(getPaymentsApiUrl(endpoint), { | ||
| method: "POST", | ||
| headers: { "Content-Type": "application/json" }, | ||
| body: JSON.stringify({ | ||
| owner, | ||
| ...(PAYMENTS_CLUSTER ? { cluster: PAYMENTS_CLUSTER } : {}), | ||
| mint, | ||
| amount: Number(amountBigInt), | ||
| initIfMissing: true, | ||
| initAtasIfMissing: true, | ||
| ...(mode === "shield" ? { initVaultIfMissing: true } : {}), | ||
| idempotent: true, | ||
| }), | ||
| signal: getPaymentsTimeoutSignal(), | ||
| cache: "no-store", | ||
| }); | ||
|
|
||
| const responseBody = await upstreamRes.json().catch(() => null); | ||
| if (!upstreamRes.ok) { | ||
| return NextResponse.json( | ||
| { | ||
| error: getPaymentsErrorMessage(upstreamRes.status, responseBody), | ||
| details: responseBody, | ||
| }, | ||
| { status: upstreamRes.status } | ||
| ); | ||
| } | ||
|
|
||
| return NextResponse.json(responseBody); | ||
| } catch (error) { | ||
| console.error("Payments shield build error:", error); | ||
| return NextResponse.json( | ||
| { | ||
| error: | ||
| error instanceof Error | ||
| ? error.message | ||
| : "Failed to build shield transaction", | ||
| }, | ||
| { 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import { NextRequest, NextResponse } from "next/server"; | ||
| import { | ||
| PAYMENTS_CLUSTER, | ||
| PAYMENTS_ENDPOINTS, | ||
| getPaymentsApiUrl, | ||
| getPaymentsTimeoutSignal, | ||
| } from "@/lib/payments"; | ||
| import { getPaymentsErrorMessage } from "@/lib/payments-errors"; | ||
|
|
||
| interface PaymentTransactionSendRequest { | ||
| transactionBase64?: string; | ||
| sendTo?: "base" | "ephemeral"; | ||
| } | ||
|
|
||
| export async function POST(request: NextRequest) { | ||
| try { | ||
| const body = (await request.json()) as PaymentTransactionSendRequest; | ||
| const { | ||
| transactionBase64, | ||
| sendTo, | ||
| } = body; | ||
| const authorization = request.headers.get("authorization")?.trim() ?? ""; | ||
|
|
||
| if ( | ||
| typeof transactionBase64 !== "string" || | ||
| !transactionBase64.trim() || | ||
| (sendTo !== "base" && sendTo !== "ephemeral") | ||
| ) { | ||
| return NextResponse.json( | ||
| { error: "Missing or invalid transaction send parameters" }, | ||
| { status: 400 } | ||
| ); | ||
| } | ||
|
|
||
| if (sendTo === "ephemeral" && !authorization) { | ||
| return NextResponse.json( | ||
| { error: "Shielded transaction submission requires authentication" }, | ||
| { status: 400 } | ||
|
GabrielePicco marked this conversation as resolved.
|
||
| ); | ||
| } | ||
|
|
||
| const upstreamHeaders: HeadersInit = { | ||
| "Content-Type": "application/json", | ||
| }; | ||
| if (authorization) { | ||
| upstreamHeaders.Authorization = authorization; | ||
| } | ||
|
|
||
| const upstreamRes = await fetch( | ||
| getPaymentsApiUrl(PAYMENTS_ENDPOINTS.transactionSend), | ||
| { | ||
| method: "POST", | ||
| headers: upstreamHeaders, | ||
| body: JSON.stringify({ | ||
| transactionBase64, | ||
| sendTo, | ||
| ...(PAYMENTS_CLUSTER ? { cluster: PAYMENTS_CLUSTER } : {}), | ||
| }), | ||
| signal: getPaymentsTimeoutSignal(30_000), | ||
| cache: "no-store", | ||
| } | ||
| ); | ||
|
|
||
| const responseBody = await upstreamRes.json().catch(() => null); | ||
| if (!upstreamRes.ok) { | ||
| return NextResponse.json( | ||
| { | ||
| error: getPaymentsErrorMessage(upstreamRes.status, responseBody), | ||
| details: responseBody, | ||
| }, | ||
| { status: upstreamRes.status } | ||
| ); | ||
| } | ||
|
|
||
| return NextResponse.json(responseBody); | ||
| } catch (error) { | ||
| console.error("Payments transaction send error:", error); | ||
| return NextResponse.json( | ||
| { | ||
| error: | ||
| error instanceof Error | ||
| ? error.message | ||
| : "Failed to send payment transaction", | ||
| }, | ||
| { 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
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.
Uh oh!
There was an error while loading. Please reload this page.