aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/test/ark/send
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-02-11 17:51:24 -0800
committerAdam Soltys <[email protected]>2026-02-11 17:51:24 -0800
commit13466248004327e9a026cb89f94926f9b060d1c1 (patch)
tree47b4972c33809ccdf866b043c92cd3e0ecf5dcd0 /src/routes/test/ark/send
parent3aa9ce1b5985397d7f568887ec6f881df13c1034 (diff)
downloadcoinos-ui-13466248004327e9a026cb89f94926f9b060d1c1.tar.gz
coinos-ui-13466248004327e9a026cb89f94926f9b060d1c1.zip
linting
Diffstat (limited to 'src/routes/test/ark/send')
-rw-r--r--src/routes/test/ark/send/+server.ts104
1 files changed, 52 insertions, 52 deletions
diff --git a/src/routes/test/ark/send/+server.ts b/src/routes/test/ark/send/+server.ts
index b077c793..8562c6b1 100644
--- a/src/routes/test/ark/send/+server.ts
+++ b/src/routes/test/ark/send/+server.ts
@@ -5,72 +5,72 @@ import { error, json } from "@sveltejs/kit";
let walletPromise: Promise<any> | undefined;
const getWallet = async () => {
- if (!walletPromise) {
- const privateKey = env.ARK_SERVER_WALLET_PRIVATE_KEY;
- const arkServerUrl = env.ARK_SERVER_URL || "http://localhost:7070";
+ if (!walletPromise) {
+ const privateKey = env.ARK_SERVER_WALLET_PRIVATE_KEY;
+ const arkServerUrl = env.ARK_SERVER_URL || "http://localhost:7070";
- if (!privateKey) {
- throw new Error("ARK_SERVER_WALLET_PRIVATE_KEY is not configured");
- }
+ if (!privateKey) {
+ throw new Error("ARK_SERVER_WALLET_PRIVATE_KEY is not configured");
+ }
- const { SingleKey, Wallet } = await import("@arkade-os/sdk");
- const identity = SingleKey.fromHex(privateKey);
- walletPromise = Wallet.create({ identity, arkServerUrl });
- }
+ const { SingleKey, Wallet } = await import("@arkade-os/sdk");
+ const identity = SingleKey.fromHex(privateKey);
+ walletPromise = Wallet.create({ identity, arkServerUrl });
+ }
- return walletPromise;
+ return walletPromise;
};
export async function POST({ request, cookies, fetch }) {
- // Never expose this in production.
- if (env.NODE_ENV === "production") error(404, "Not found");
+ // Never expose this in production.
+ if (env.NODE_ENV === "production") error(404, "Not found");
- // Require explicit opt-in for local/integration test environments.
- if (env.ENABLE_E2E_TEST_ENDPOINTS !== "true") {
- error(404, "Not found");
- }
+ // Require explicit opt-in for local/integration test environments.
+ if (env.ENABLE_E2E_TEST_ENDPOINTS !== "true") {
+ error(404, "Not found");
+ }
- const expectedSecret = env.E2E_TEST_SECRET;
- const providedSecret = request.headers.get("x-test-secret");
- if (!expectedSecret || providedSecret !== expectedSecret) {
- error(401, "Unauthorized");
- }
+ const expectedSecret = env.E2E_TEST_SECRET;
+ const providedSecret = request.headers.get("x-test-secret");
+ if (!expectedSecret || providedSecret !== expectedSecret) {
+ error(401, "Unauthorized");
+ }
- const body = await request.json();
- const address = String(body?.address || "").trim();
- const amount = Number(body?.amount || 1000);
- const iid = typeof body?.iid === "string" ? body.iid : undefined;
+ const body = await request.json();
+ const address = String(body?.address || "").trim();
+ const amount = Number(body?.amount || 1000);
+ const iid = typeof body?.iid === "string" ? body.iid : undefined;
- if (!/^t?ark1[a-z0-9]+$/i.test(address)) {
- error(400, "Invalid ark address");
- }
+ if (!/^t?ark1[a-z0-9]+$/i.test(address)) {
+ error(400, "Invalid ark address");
+ }
- if (!Number.isInteger(amount) || amount <= 0 || amount > 1_000_000) {
- error(400, "Invalid amount");
- }
+ if (!Number.isInteger(amount) || amount <= 0 || amount > 1_000_000) {
+ error(400, "Invalid amount");
+ }
- const wallet = await getWallet();
- const txid = await wallet.sendBitcoin({ address, amount });
+ const wallet = await getWallet();
+ const txid = await wallet.sendBitcoin({ address, amount });
- // Optional: mark an Ark invoice as received right after send.
- if (iid) {
- const token = cookies.get("token");
- if (!token) error(401, "Missing auth token cookie");
+ // Optional: mark an Ark invoice as received right after send.
+ if (iid) {
+ const token = cookies.get("token");
+ if (!token) error(401, "Missing auth token cookie");
- const response = await fetch(`${PUBLIC_COINOS_URL}/ark/receive`, {
- method: "POST",
- headers: {
- "content-type": "application/json",
- accept: "application/json",
- authorization: `Bearer ${token}`,
- },
- body: JSON.stringify({ iid, amount, hash: txid }),
- });
+ const response = await fetch(`${PUBLIC_COINOS_URL}/ark/receive`, {
+ method: "POST",
+ headers: {
+ "content-type": "application/json",
+ accept: "application/json",
+ authorization: `Bearer ${token}`,
+ },
+ body: JSON.stringify({ iid, amount, hash: txid }),
+ });
- if (!response.ok) {
- error(response.status, await response.text());
- }
- }
+ if (!response.ok) {
+ error(response.status, await response.text());
+ }
+ }
- return json({ ok: true, txid, amount, address, iid: iid || null });
+ return json({ ok: true, txid, amount, address, iid: iid || null });
}