From 08a0fdfb71a66fd446a8c0147744a0225253ae01 Mon Sep 17 00:00:00 2001 From: ertemann Date: Mon, 29 Sep 2025 12:23:08 +0200 Subject: [PATCH 1/3] remove legacy and signing examples, rename main demo page --- .../src/app/api/check-signature/route.ts | 185 ------------------ apps/demo-app/src/app/default-ui/page.tsx | 77 -------- apps/demo-app/src/app/loading-state/page.tsx | 14 -- .../app/{ui-less => loading-states}/page.tsx | 0 apps/demo-app/src/app/page.tsx | 9 +- 5 files changed, 2 insertions(+), 283 deletions(-) delete mode 100644 apps/demo-app/src/app/api/check-signature/route.ts delete mode 100644 apps/demo-app/src/app/default-ui/page.tsx delete mode 100644 apps/demo-app/src/app/loading-state/page.tsx rename apps/demo-app/src/app/{ui-less => loading-states}/page.tsx (100%) diff --git a/apps/demo-app/src/app/api/check-signature/route.ts b/apps/demo-app/src/app/api/check-signature/route.ts deleted file mode 100644 index 64df2d12..00000000 --- a/apps/demo-app/src/app/api/check-signature/route.ts +++ /dev/null @@ -1,185 +0,0 @@ -import { NextRequest, NextResponse } from "next/server"; -import { serializeSignDoc } from "@cosmjs/amino"; -import { Secp256k1, Secp256k1Signature, Sha256 } from "@cosmjs/crypto"; -import { testnetChainInfo } from "@burnt-labs/constants"; -import { QueryGrantsResponse } from "cosmjs-types/cosmos/authz/v1beta1/query"; - -function isString(test: unknown): test is string { - return typeof test === "string"; -} - -function makeADR36AminoSignDoc( - signer: string, - message: string | Uint8Array, -): any { - return { - chain_id: "", - account_number: "0", - sequence: "0", - fee: { - amount: [], - gas: "0", - }, - msgs: [ - { - type: "sign/MsgSignData", - value: { - signer: signer, - data: - typeof message === "string" - ? Buffer.from(message).toString("base64") - : Buffer.from(message).toString("base64"), - }, - }, - ], - memo: "", - }; -} - -async function verifyXionSignature( - address: string, - pubKey: string, - messageString: string, - signature: string, -): Promise { - const signatureBuffer = Buffer.from(signature, "base64"); - const uint8Signature = new Uint8Array(signatureBuffer); - const pubKeyValueBuffer = Buffer.from(pubKey, "base64"); - const pubKeyUint8Array = new Uint8Array(pubKeyValueBuffer); - - const signDoc = makeADR36AminoSignDoc(address, messageString); - const serializedSignDoc = serializeSignDoc(signDoc); - - const messageHash = new Sha256(serializedSignDoc).digest(); - const signatureObject = new Secp256k1Signature( - uint8Signature.slice(0, 32), - uint8Signature.slice(32, 64), - ); - return Secp256k1.verifySignature( - signatureObject, - messageHash, - pubKeyUint8Array, - ); -} - -async function verifyXionSignatureAndGrants( - address: string, - sessionAddress: string, - pubKey: string, - messageString: string, - signature: string, -): Promise { - const isValid = await verifyXionSignature( - sessionAddress, - pubKey, - messageString, - signature, - ); - if (!isValid) { - return false; - } - - return verifyGrants(address, sessionAddress); -} - -async function verifyGrants( - granter: string, - grantee: string, -): Promise { - const baseUrl = `${testnetChainInfo.rest}/cosmos/authz/v1beta1/grants`; - const url = new URL(baseUrl); - const params = new URLSearchParams({ - grantee, - granter, - }); - url.search = params.toString(); - const data = await fetch(url, { - cache: "no-store", - }) - .then((response): Promise => response.json()) - .catch((err) => { - console.error("Could not fetch grants info", err); - }); - - return Boolean(data && data.grants.length > 0); -} - -export async function GET(request: NextRequest) { - const searchParams = request.nextUrl.searchParams; - const userSessionAddress = searchParams.get("userSessionAddress"); - const userSessionPubKey = searchParams.get("userSessionPubKey"); - const metaAccountAddress = searchParams.get("metaAccountAddress"); - const message = searchParams.get("message"); - const signature = searchParams.get("signature"); - - const errors: string[] = []; - if (!userSessionAddress) { - errors.push("userSessionAddress is required"); - } - - if (!userSessionPubKey) { - errors.push("userSessionPubKey is required"); - } - - if (!metaAccountAddress) { - errors.push("metaAccountAddress is required"); - } - - if (!message) { - errors.push("message is required"); - } - - if (!signature) { - errors.push("signature is required"); - } - - if (errors.length > 0) { - return NextResponse.json({ errors }, { status: 400 }); - } - - // These aid TS type inference - if (!isString(userSessionAddress)) { - return NextResponse.json( - { errors: ["userSessionAddress is required to be a string"] }, - { status: 400 }, - ); - } - - if (!isString(userSessionPubKey)) { - return NextResponse.json( - { errors: ["userSessionPubKey is required to be a string"] }, - { status: 400 }, - ); - } - - if (!isString(metaAccountAddress)) { - return NextResponse.json( - { errors: ["metaAccountAddress is required to be a string"] }, - { status: 400 }, - ); - } - - if (!isString(message)) { - return NextResponse.json( - { errors: ["message is required to be a string"] }, - { status: 400 }, - ); - } - - if (!isString(signature)) { - return NextResponse.json( - { errors: ["signature is required to be a string"] }, - { status: 400 }, - ); - } - - const isValid = await verifyXionSignatureAndGrants( - metaAccountAddress, - userSessionAddress, - userSessionPubKey, - message, - signature, - ); - - return NextResponse.json({ valid: isValid }); -} diff --git a/apps/demo-app/src/app/default-ui/page.tsx b/apps/demo-app/src/app/default-ui/page.tsx deleted file mode 100644 index 328f4a87..00000000 --- a/apps/demo-app/src/app/default-ui/page.tsx +++ /dev/null @@ -1,77 +0,0 @@ -"use client"; -import { useState } from "react"; -import { - Abstraxion, - useAbstraxionAccount, - useAbstraxionSigningClient, - useModal, -} from "@burnt-labs/abstraxion"; -import { Button } from "@burnt-labs/ui"; -import "@burnt-labs/ui/dist/index.css"; -import "@burnt-labs/abstraxion/dist/index.css"; -import Link from "next/link"; - -export default function DefaultUIPage(): JSX.Element { - const { data: account } = useAbstraxionAccount(); - const { client, logout } = useAbstraxionSigningClient(); - const [showModal, setShowModal] = useModal(); - - return ( -
-

- Legacy UI Abstraxion Example -

-

- This example uses the legacy Abstraxion modal UI for wallet connection. - Click the button below to open the modal. -

- -
- - - {account.bech32Address && ( - <> -
-

Account Info

-

- Address: {account.bech32Address} -

-

- Client: {client ? "Connected" : "Not connected"} -

-
- - - - )} -
- - { - setShowModal(false); - }} - /> - - - ← Back to examples - -
- ); -} diff --git a/apps/demo-app/src/app/loading-state/page.tsx b/apps/demo-app/src/app/loading-state/page.tsx deleted file mode 100644 index e7f2835f..00000000 --- a/apps/demo-app/src/app/loading-state/page.tsx +++ /dev/null @@ -1,14 +0,0 @@ -"use client"; - -export default function LoadingStatePage() { - return ( -
-
-

You are being redirected...

-

- Use custom UI to render loading state with your own branding -

-
-
- ); -} diff --git a/apps/demo-app/src/app/ui-less/page.tsx b/apps/demo-app/src/app/loading-states/page.tsx similarity index 100% rename from apps/demo-app/src/app/ui-less/page.tsx rename to apps/demo-app/src/app/loading-states/page.tsx diff --git a/apps/demo-app/src/app/page.tsx b/apps/demo-app/src/app/page.tsx index d5371578..0eac0a63 100644 --- a/apps/demo-app/src/app/page.tsx +++ b/apps/demo-app/src/app/page.tsx @@ -10,14 +10,9 @@ export default function Page(): JSX.Element { ABSTRAXION
- + - - -
From 9715a6115aaf2a0e2132d10eb3550e361b29d96e Mon Sep 17 00:00:00 2001 From: ertemann Date: Mon, 29 Sep 2025 12:27:46 +0200 Subject: [PATCH 2/3] add changeset --- .changeset/fruity-pets-lay.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/fruity-pets-lay.md diff --git a/.changeset/fruity-pets-lay.md b/.changeset/fruity-pets-lay.md new file mode 100644 index 00000000..26f0a4ed --- /dev/null +++ b/.changeset/fruity-pets-lay.md @@ -0,0 +1,6 @@ +--- +"demo-app": minor +"@burnt-labs/abstraxion": patch +--- + +remove demo app of legacy modal From 24e32125c0d750fc8eeb33506c1f4e05f1cc2682 Mon Sep 17 00:00:00 2001 From: ertemann Date: Mon, 29 Sep 2025 13:55:48 +0200 Subject: [PATCH 3/3] remove vscode dir --- .vscode/settings.json | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index a84c425c..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "eslint.workingDirectories": [ - { - "mode": "auto" - } - ], - "editor.formatOnSave": true -}