Skip to content

Commit

Permalink
construct message on backend
Browse files Browse the repository at this point in the history
  • Loading branch information
technophile-04 committed Feb 4, 2024
1 parent 8c62443 commit 8d3db88
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
13 changes: 7 additions & 6 deletions packages/nextjs/app/submit-grant/_actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@ import { verifyMessage } from "viem";
import { createGrant } from "~~/services/database/grants";
import { findUserByAddress } from "~~/services/database/users";

type SignedMessage = {
message?: string;
type SignatureAndSigner = {
signature?: `0x${string}`;
address?: string;
};

export const submitGrantAction = async ({ message, signature, address }: SignedMessage, form: FormData) => {
export const submitGrantAction = async ({ signature, address }: SignatureAndSigner, form: FormData) => {
try {
const formData = Object.fromEntries(form.entries());
if (!formData.title || !formData.description || !formData.askAmount) {
throw new Error("Invalid form data");
}
if (!message || !signature || !address) {
throw new Error("Invalid message, signature, or address.");

if (!signature || !address) {
throw new Error("Signature and address are required to submit grant");
}

const isMessageValid = await verifyMessage({ message, signature, address });
const constructedMessage = JSON.stringify(formData);
const isMessageValid = await verifyMessage({ message: constructedMessage, signature, address });
if (!isMessageValid) {
throw new Error("Invalid signature");
}
Expand Down
1 change: 0 additions & 1 deletion packages/nextjs/app/submit-grant/_component/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const Form = () => {
const signedMessageObject = {
signature: signature,
address: connectedAddress,
message: JSON.stringify(formState),
};

// server action
Expand Down

0 comments on commit 8d3db88

Please sign in to comment.