-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
45a54be
commit 58af889
Showing
12 changed files
with
1,184 additions
and
167 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -34,3 +34,6 @@ yarn-error.log* | |
.turbo | ||
**/dist/** | ||
**/node_modules/** | ||
|
||
# cloudflare | ||
.wrangler |
This file contains 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 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 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 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 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 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,6 @@ | ||
|
||
import { unlinkSync } from "node:fs"; | ||
const path = "dist/worker.js"; | ||
const file = Bun.file(path); | ||
await Bun.write("dist/_worker.js", file); | ||
unlinkSync(path); |
This file contains 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,19 @@ | ||
export interface T_FRAME_API_BODY { | ||
untrustedData: { | ||
fid: number | ||
url: string | ||
messageHash: string | ||
timestamp: number | ||
network: number | ||
buttonIndex: number | ||
inputText: string | ||
castId: { | ||
fid: number | ||
hash: string | ||
} | ||
state: string | ||
} | ||
trustedData: { | ||
messageBytes: string | ||
} | ||
} |
This file contains 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,18 @@ | ||
import { | ||
validateFramesMessage as verifyMessageWithAirstack, | ||
ValidateFramesMessageInput, | ||
init | ||
} from '@airstack/frames' | ||
|
||
import type { T_FRAME_API_BODY } from './types' | ||
|
||
|
||
export const verifyMessage = async (body: T_FRAME_API_BODY, AIRSTACK_KEY: string): Promise<{ valid: boolean }> => { | ||
try { | ||
init(AIRSTACK_KEY) | ||
const verify = await verifyMessageWithAirstack(body as ValidateFramesMessageInput) | ||
return { valid: verify.isValid } | ||
} catch (e) { | ||
return { valid: false } | ||
} | ||
} |
This file contains 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,44 @@ | ||
/* eslint-disable no-undef */ | ||
import type { T_FRAME_API_BODY } from './types' | ||
|
||
|
||
interface Env { | ||
ASSETS: Fetcher; | ||
AIRSTACK_KEY: string; | ||
} | ||
|
||
export default { | ||
async fetch (request, env): Promise<Response> { | ||
const url = new URL(request.url); | ||
if (url.pathname.startsWith('/api/miniapp')) { | ||
// get url from query | ||
const url = new URL(request.url); | ||
const query = url.searchParams; | ||
const urlToFetch = query.get('url'); | ||
|
||
// check if method is POST | ||
if (request.method === 'POST') { | ||
const body = await request.json() as T_FRAME_API_BODY; | ||
const { verifyMessage } = await import('./utils') | ||
|
||
verifyMessage(body, env.AIRSTACK_KEY) | ||
} | ||
|
||
const jsonToSend = { | ||
"type": "form", | ||
"title": "Yup Link", | ||
"url": urlToFetch, | ||
} | ||
|
||
return new Response(JSON.stringify(jsonToSend), { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
|
||
} | ||
// Otherwise, serve the static assets. | ||
// Without this, the Worker will error and no assets will be served. | ||
return env.ASSETS.fetch(request); | ||
}, | ||
} satisfies ExportedHandler<Env>; |
This file contains 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 |
---|---|---|
|
@@ -18,5 +18,8 @@ | |
}, | ||
"engines": { | ||
"node": ">=16.0.0" | ||
}, | ||
"dependencies": { | ||
"wrangler": "^3.78.5" | ||
} | ||
} |
Oops, something went wrong.