Skip to content

Commit e4e2958

Browse files
authored
Updated ERC721 Signature Prepare (#449)
* updated response * updated response to include needed fields * removed uid from input for prepare
1 parent 79bdf09 commit e4e2958

File tree

2 files changed

+68
-23
lines changed

2 files changed

+68
-23
lines changed

src/server/routes/contract/extensions/erc721/read/signaturePrepare.ts

Lines changed: 67 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from "@thirdweb-dev/sdk";
1616
import { ThirdwebStorage } from "@thirdweb-dev/storage";
1717
import BN from "bn.js";
18-
import ethers, { BigNumber, utils } from "ethers";
18+
import ethers, { BigNumber, TypedDataField, utils } from "ethers";
1919
import { FastifyInstance } from "fastify";
2020
import { StatusCodes } from "http-status-codes";
2121
import { v4 as uuid } from "uuid";
@@ -35,9 +35,7 @@ import { checkAndReturnNFTSignaturePayload } from "../../../../../utils/validato
3535

3636
// INPUTS
3737
const requestSchema = erc721ContractParamSchema;
38-
const requestBodySchema = Type.Object({
39-
...signature721InputSchema.properties,
40-
});
38+
const requestBodySchema = Type.Omit(signature721InputSchema, ["uid"]);
4139

4240
// OUTPUT
4341
const responseSchema = Type.Object({
@@ -52,37 +50,75 @@ const responseSchema = Type.Object({
5250
}),
5351
types: Type.Any(),
5452
message: Type.Any(),
53+
primaryType: Type.String(),
5554
}),
5655
}),
5756
});
5857

58+
const EIP721DomainTypes = [
59+
{
60+
name: "name",
61+
type: "string",
62+
},
63+
{
64+
name: "version",
65+
type: "string",
66+
},
67+
{
68+
name: "chainId",
69+
type: "uint256",
70+
},
71+
{
72+
name: "verifyingContract",
73+
type: "address",
74+
},
75+
];
76+
5977
responseSchema.example = {
6078
result: {
6179
mintPayload: {
62-
to: "0x1946267d81Fb8aDeeEa28e6B98bcD446c8248473",
80+
to: "0x...",
6381
price: "0",
64-
currencyAddress: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
82+
currencyAddress: "0x...",
6583
mintStartTime: "1704664293",
6684
mintEndTime: "1751925093",
67-
uid: "0x3732346162373763346432663433333462383134353662343761373166636239",
68-
primarySaleRecipient: "0x0000000000000000000000000000000000000000",
85+
uid: "0x...",
86+
primarySaleRecipient: "0x...",
6987
metadata: {
7088
name: "test token",
7189
description: "test token",
7290
},
73-
royaltyRecipient: "0x0000000000000000000000000000000000000000",
91+
royaltyRecipient: "0x...",
7492
royaltyBps: "0",
7593
quantity: "1",
76-
uri: "ipfs://Qmaf55psrmeckXZ6yo4DTL7fUYeMR4t6XArY5NgMrKN9VA/0",
94+
uri: "ipfs://...",
7795
},
7896
typedDataPayload: {
7997
domain: {
8098
name: "TokenERC721",
8199
version: "1",
82100
chainId: 84532,
83-
verifyingContract: "0x9ca57B9341dCB029a5b11163C9a47FB65BA6F4c3",
101+
verifyingContract: "0x...",
84102
},
85103
types: {
104+
EIP712Domain: [
105+
{
106+
name: "name",
107+
type: "string",
108+
},
109+
{
110+
name: "version",
111+
type: "string",
112+
},
113+
{
114+
name: "chainId",
115+
type: "uint256",
116+
},
117+
{
118+
name: "verifyingContract",
119+
type: "address",
120+
},
121+
],
86122
MintRequest: [
87123
{
88124
name: "to",
@@ -127,17 +163,18 @@ responseSchema.example = {
127163
],
128164
},
129165
message: {
130-
to: "0x1946267d81Fb8aDeeEa28e6B98bcD446c8248473",
131-
royaltyRecipient: "0x0000000000000000000000000000000000000000",
166+
to: "0x...",
167+
royaltyRecipient: "0x...",
132168
royaltyBps: "0",
133-
primarySaleRecipient: "0x0000000000000000000000000000000000000000",
169+
primarySaleRecipient: "0x...",
134170
price: "0",
135-
uri: "ipfs://Qmaf55psrmeckXZ6yo4DTL7fUYeMR4t6XArY5NgMrKN9VA/0",
136-
currency: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
171+
uri: "ipfs://...",
172+
currency: "0x...",
137173
validityEndTimestamp: "1751925093",
138174
validityStartTimestamp: "1704664293",
139-
uid: "0x3732346162373763346432663433333462383134353662343761373166636239",
175+
uid: "0x...",
140176
},
177+
primaryType: "MintRequest",
141178
},
142179
},
143180
};
@@ -176,7 +213,6 @@ export async function erc721SignaturePrepare(fastify: FastifyInstance) {
176213
quantity,
177214
royaltyBps,
178215
royaltyRecipient,
179-
uid,
180216
} = request.body;
181217

182218
const chainId = await getChainIdFromChain(chain);
@@ -202,7 +238,6 @@ export async function erc721SignaturePrepare(fastify: FastifyInstance) {
202238
quantity,
203239
royaltyBps,
204240
royaltyRecipient,
205-
uid,
206241
});
207242

208243
const uri = await uploadOrExtractURI(metadata, storage);
@@ -219,7 +254,10 @@ export async function erc721SignaturePrepare(fastify: FastifyInstance) {
219254

220255
// Build the data fields needed to be signed by a minter wallet.
221256
let domain;
222-
let types;
257+
258+
let types: Record<string, Array<TypedDataField>> = {
259+
EIP712Domain: EIP721DomainTypes,
260+
};
223261
let message:
224262
| ISignatureMintERC721.MintRequestStructOutput
225263
| ITokenERC721.MintRequestStructOutput;
@@ -231,7 +269,10 @@ export async function erc721SignaturePrepare(fastify: FastifyInstance) {
231269
chainId,
232270
verifyingContract: contractAddress,
233271
};
234-
types = { MintRequest: MintRequest721 };
272+
types = {
273+
...types,
274+
MintRequest: MintRequest721,
275+
};
235276
message = mapLegacyPayloadToContractStruct(mintPayload);
236277
sanitizedMessage = {
237278
...message,
@@ -247,7 +288,10 @@ export async function erc721SignaturePrepare(fastify: FastifyInstance) {
247288
chainId,
248289
verifyingContract: contractAddress,
249290
};
250-
types = { MintRequest: MintRequest721withQuantity };
291+
types = {
292+
...types,
293+
MintRequest: MintRequest721withQuantity,
294+
};
251295
message = mapPayloadToContractStruct(mintPayload);
252296
sanitizedMessage = {
253297
...message,
@@ -272,6 +316,7 @@ export async function erc721SignaturePrepare(fastify: FastifyInstance) {
272316
domain,
273317
types,
274318
message: sanitizedMessage,
319+
primaryType: "MintRequest",
275320
},
276321
},
277322
});

src/server/schemas/nft/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ export type ercNFTResponseType = (
305305

306306
signature721InputSchema.examples = [
307307
{
308-
to: "0x1946267d81Fb8aDeeEa28e6B98bcD446c8248473",
308+
to: "0x...",
309309
quantity: "1",
310310
metadata: {
311311
name: "test tokenII",

0 commit comments

Comments
 (0)