Skip to content

Commit

Permalink
chore: do not store signer key
Browse files Browse the repository at this point in the history
  • Loading branch information
michalkvasnicak committed Dec 19, 2024
1 parent 10cf966 commit 1fccc06
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useFrameAppNotificationsManagerContext } from "../providers/FrameAppNot
import type { GETEventsResponseBody } from "../notifications/[namespaceId]/events/route";
import { Button } from "@/components/ui/button";
import { WithTooltip } from "./with-tooltip";
import { UseFrameAppInIframeReturn } from "@frames.js/render/src/frame-app/iframe";
import type { UseFrameAppInIframeReturn } from "@frames.js/render/frame-app/iframe";

type FrameAppDebuggerNotificationsProps = {
frameApp: Extract<UseFrameAppInIframeReturn, { status: "success" }>;
Expand Down
22 changes: 15 additions & 7 deletions packages/debugger/app/notifications/[namespaceId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,32 @@ export type NotificationUrl = {

export type Notification = Omit<SendNotificationRequest, "tokens">;

const privateKeyParser = z
.string()
.min(1)
.startsWith("0x")
.transform((val) => hexToBytes(val as Hex));

const postRequestBodySchema = z.discriminatedUnion("action", [
z.object({
action: z.literal("add_frame"),
privateKey: privateKeyParser,
}),
z.object({
action: z.literal("remove_frame"),
privateKey: privateKeyParser,
}),
z.object({
action: z.literal("enable_notifications"),
privateKey: privateKeyParser,
}),
z.object({
action: z.literal("disable_notifications"),
privateKey: privateKeyParser,
}),
]);

export type POSTNotificationsDetailRequestBody = z.infer<
export type POSTNotificationsDetailRequestBody = z.input<
typeof postRequestBodySchema
>;

Expand Down Expand Up @@ -80,8 +90,6 @@ export async function POST(
return Response.json({ message: "Not found" }, { status: 404 });
}

const privateKey = hexToBytes(namespace.signerPrivateKey as Hex);

switch (requestBody.data.action) {
case "add_frame": {
const notificationDetails = await storage.addFrame(namespace);
Expand All @@ -102,7 +110,7 @@ export async function POST(
};

sendEvent(event, {
privateKey,
privateKey: requestBody.data.privateKey,
fid: namespace.fid,
webhookUrl: namespace.webhookUrl,
})
Expand Down Expand Up @@ -156,7 +164,7 @@ export async function POST(

sendEvent(event, {
fid: namespace.fid,
privateKey,
privateKey: requestBody.data.privateKey,
webhookUrl: namespace.webhookUrl,
})
.then(() => {
Expand Down Expand Up @@ -212,7 +220,7 @@ export async function POST(

sendEvent(event, {
fid: namespace.fid,
privateKey,
privateKey: requestBody.data.privateKey,
webhookUrl: namespace.webhookUrl,
})
.then(() => {
Expand Down Expand Up @@ -267,7 +275,7 @@ export async function POST(

sendEvent(event, {
fid: namespace.fid,
privateKey,
privateKey: requestBody.data.privateKey,
webhookUrl: namespace.webhookUrl,
})
.then(() => {
Expand Down
4 changes: 1 addition & 3 deletions packages/debugger/app/notifications/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
const postRequestBodySchema = z.object({
fid: z.coerce.number().int().positive(),
frameAppUrl: z.string().url(),
signerPrivateKey: z.string().min(1),
webhookUrl: z.string().url(),
});

Expand All @@ -35,7 +34,7 @@ export async function POST(req: NextRequest) {
}

const redis = createRedis();
const { fid, frameAppUrl, signerPrivateKey, webhookUrl } = body.data;
const { fid, frameAppUrl, webhookUrl } = body.data;
const storage = new RedisNotificationsStorage(redis, req.nextUrl.href);

// Create new namespace
Expand All @@ -44,7 +43,6 @@ export async function POST(req: NextRequest) {
const namespace = await storage.registerNamespace(namespaceId, {
fid,
frameAppUrl,
signerPrivateKey,
webhookUrl,
});

Expand Down
3 changes: 0 additions & 3 deletions packages/debugger/app/notifications/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ type NotificationsNamespace = {
id: string;
fid: number;
frameAppUrl: string;
signerPrivateKey: string;
namespaceUrl: string;
webhookUrl: string;
frame:
Expand All @@ -32,15 +31,13 @@ export class RedisNotificationsStorage {
params: {
fid: number;
frameAppUrl: string;
signerPrivateKey: string;
webhookUrl: string;
}
) {
const namespace: NotificationsNamespace = {
id,
fid: params.fid,
frameAppUrl: params.frameAppUrl,
signerPrivateKey: params.signerPrivateKey,
namespaceUrl: new URL(`/notifications/${id}`, this.serverUrl).toString(),
webhookUrl: params.webhookUrl,
frame: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ export function useFrameAppNotificationsManager({
body: JSON.stringify({
fid: signer.fid,
frameAppUrl: frameUrl,
signerPrivateKey: signer.privateKey,
webhookUrl,
} satisfies POSTNotificationsRequestBody),
});
Expand Down Expand Up @@ -162,6 +161,7 @@ export function useFrameAppNotificationsManager({
async addFrame() {
const result = await sendEvent.mutateAsync({
action: "add_frame",
privateKey: signer.privateKey,
});

if (result.type !== "frame_added") {
Expand All @@ -178,6 +178,7 @@ export function useFrameAppNotificationsManager({
async removeFrame() {
await sendEvent.mutateAsync({
action: "remove_frame",
privateKey: signer.privateKey,
});

// refetch notification settings
Expand All @@ -188,6 +189,7 @@ export function useFrameAppNotificationsManager({
async enableNotifications() {
const result = await sendEvent.mutateAsync({
action: "enable_notifications",
privateKey: signer.privateKey,
});

// refetch notification settings
Expand All @@ -204,6 +206,7 @@ export function useFrameAppNotificationsManager({
async disableNotifications() {
await sendEvent.mutateAsync({
action: "disable_notifications",
privateKey: signer.privateKey,
});

// refetch notification settings
Expand Down

0 comments on commit 1fccc06

Please sign in to comment.