-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds signTypedData Route to Sign EIP712 Messages with Backend Wallets (…
…#414) * feat: adds signTypedData route * fix(signTypedData): remove unused body param
- Loading branch information
1 parent
9f6d5fa
commit ce609ee
Showing
2 changed files
with
55 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import type { TypedDataSigner } from "@ethersproject/abstract-signer"; | ||
import { Static, Type } from "@sinclair/typebox"; | ||
import { FastifyInstance } from "fastify"; | ||
import { StatusCodes } from "http-status-codes"; | ||
import { getWallet } from "../../../utils/cache/getWallet"; | ||
import { standardResponseSchema } from "../../schemas/sharedApiSchemas"; | ||
import { walletAuthSchema } from "../../schemas/wallet"; | ||
|
||
const BodySchema = Type.Object({ | ||
domain: Type.Object({}, { additionalProperties: true }), | ||
types: Type.Object({}, { additionalProperties: true }), | ||
value: Type.Object({}, { additionalProperties: true }), | ||
}); | ||
|
||
const ReplySchema = Type.Object({ | ||
result: Type.String(), | ||
}); | ||
|
||
export async function signTypedData(fastify: FastifyInstance) { | ||
fastify.route<{ | ||
Body: Static<typeof BodySchema>; | ||
Reply: Static<typeof ReplySchema>; | ||
}>({ | ||
method: "POST", | ||
url: "/backend-wallet/sign-typed-data", | ||
schema: { | ||
summary: "Sign a EIP-712 message", | ||
description: "Send a EIP-712 message", | ||
tags: ["Backend Wallet"], | ||
operationId: "signTypedData", | ||
body: BodySchema, | ||
headers: Type.Omit(walletAuthSchema, ["x-account-address"]), | ||
response: { | ||
...standardResponseSchema, | ||
[StatusCodes.OK]: ReplySchema, | ||
}, | ||
}, | ||
handler: async (req, res) => { | ||
const { domain, value, types } = req.body; | ||
const walletAddress = req.headers["x-backend-wallet-address"] as string; | ||
|
||
const wallet = await getWallet({ chainId: 1, walletAddress }); | ||
|
||
const signer = (await wallet.getSigner()) as unknown as TypedDataSigner; | ||
const result = await signer._signTypedData(domain, types, value); | ||
|
||
res.status(200).send({ | ||
result: result, | ||
}); | ||
}, | ||
}); | ||
} |
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