Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/pages/api/v1/addTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { db } from "@/server/db";
import { verifyJwt } from "@/lib/verifyJwt";
import { cors } from "@/lib/cors";
import { cors, addCorsCacheBustingHeaders } from "@/lib/cors";
import { getProvider } from "@/utils/get-provider";

export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
// Add cache-busting headers for CORS
addCorsCacheBustingHeaders(res);

await cors(req, res);
if (req.method === "OPTIONS") {
return res.status(200).end();
Expand Down
5 changes: 4 additions & 1 deletion src/pages/api/v1/authSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import {
checkSignature,
DataSignature,
} from "@meshsdk/core";
import { cors } from "@/lib/cors";
import { cors, addCorsCacheBustingHeaders } from "@/lib/cors";

export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
// Add cache-busting headers for CORS
addCorsCacheBustingHeaders(res);

await cors(req, res);
if (req.method === "OPTIONS") {
return res.status(200).end();
Expand Down
5 changes: 4 additions & 1 deletion src/pages/api/v1/freeUtxos.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cors } from "@/lib/cors";
import { cors, addCorsCacheBustingHeaders } from "@/lib/cors";
//get all utxos for wallet
//get all pending txs for the wallet
//remove all wallet input utxos found in pending txs from the whole pool of txs.
Expand All @@ -16,6 +16,9 @@ export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
// Add cache-busting headers for CORS
addCorsCacheBustingHeaders(res);

await cors(req, res);
if (req.method === "OPTIONS") {
return res.status(200).end();
Expand Down
55 changes: 32 additions & 23 deletions src/pages/api/v1/getNonce.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,51 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { randomBytes } from "crypto";
import { db } from "@/server/db";
import { cors } from "@/lib/cors";
import { cors, addCorsCacheBustingHeaders } from "@/lib/cors";

export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
// Add cache-busting headers for CORS
addCorsCacheBustingHeaders(res);

await cors(req, res);
if (req.method === "OPTIONS") {
return res.status(200).end();
}

if (req.method === "GET") {
const { address } = req.query;
if (typeof address !== "string") {
return res.status(400).json({ error: "Invalid address" });
}
// Verify that the address exists in the User table
const user = await db.user.findUnique({ where: { address } });
if (!user) {
return res.status(404).json({ error: "Address not found" });
}
try {
const { address } = req.query;
if (typeof address !== "string") {
return res.status(400).json({ error: "Invalid address" });
}

// Verify that the address exists in the User table
const user = await db.user.findUnique({ where: { address } });
if (!user) {
return res.status(404).json({ error: "Address not found" });
}

// Check if a nonce already exists for this address in the database
const existing = await db.nonce.findFirst({ where: { address } });
if (existing) {
return res.status(200).json({ nonce: existing.value });
}
// Check if a nonce already exists for this address in the database
const existing = await db.nonce.findFirst({ where: { address } });
if (existing) {
return res.status(200).json({ nonce: existing.value });
}

const nonce = randomBytes(16).toString("hex");
await db.nonce.create({
data: {
address,
value: nonce,
},
});
return res.status(200).json({ nonce });
const nonce = randomBytes(16).toString("hex");
await db.nonce.create({
data: {
address,
value: nonce,
},
});
return res.status(200).json({ nonce });
} catch (error) {
console.error("Error in getNonce:", error);
return res.status(500).json({ error: "Internal Server Error" });
}
}

res.status(405).end();
Expand Down
5 changes: 4 additions & 1 deletion src/pages/api/v1/lookupMultisigWallet.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { getProvider } from "@/utils/get-provider";
import { cors } from "@/lib/cors";
import { cors, addCorsCacheBustingHeaders } from "@/lib/cors";

export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
// Add cache-busting headers for CORS
addCorsCacheBustingHeaders(res);

await cors(req, res);
if (req.method === "OPTIONS") {
return res.status(200).end();
Expand Down
5 changes: 4 additions & 1 deletion src/pages/api/v1/nativeScript.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cors } from "@/lib/cors";
import { cors, addCorsCacheBustingHeaders } from "@/lib/cors";
import { NextApiRequest, NextApiResponse } from "next";
import { Wallet as DbWallet } from "@prisma/client";
import { buildMultisigWallet } from "@/utils/common";
Expand All @@ -10,6 +10,9 @@ export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
// Add cache-busting headers for CORS
addCorsCacheBustingHeaders(res);

await cors(req, res);
if (req.method === "OPTIONS") {
return res.status(200).end();
Expand Down
5 changes: 4 additions & 1 deletion src/pages/api/v1/submitDatum.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { db } from "@/server/db";
import { verifyJwt } from "@/lib/verifyJwt";
import { cors } from "@/lib/cors";
import { cors, addCorsCacheBustingHeaders } from "@/lib/cors";
import { DataSignature } from "@meshsdk/core";
import { checkSignature } from "@meshsdk/core-cst";

export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
// Add cache-busting headers for CORS
addCorsCacheBustingHeaders(res);

await cors(req, res);
if (req.method === "OPTIONS") {
return res.status(200).end();
Expand Down