@@ -15,7 +15,7 @@ import {
15
15
} from "@thirdweb-dev/sdk" ;
16
16
import { ThirdwebStorage } from "@thirdweb-dev/storage" ;
17
17
import BN from "bn.js" ;
18
- import ethers , { BigNumber , utils } from "ethers" ;
18
+ import ethers , { BigNumber , TypedDataField , utils } from "ethers" ;
19
19
import { FastifyInstance } from "fastify" ;
20
20
import { StatusCodes } from "http-status-codes" ;
21
21
import { v4 as uuid } from "uuid" ;
@@ -35,9 +35,7 @@ import { checkAndReturnNFTSignaturePayload } from "../../../../../utils/validato
35
35
36
36
// INPUTS
37
37
const requestSchema = erc721ContractParamSchema ;
38
- const requestBodySchema = Type . Object ( {
39
- ...signature721InputSchema . properties ,
40
- } ) ;
38
+ const requestBodySchema = Type . Omit ( signature721InputSchema , [ "uid" ] ) ;
41
39
42
40
// OUTPUT
43
41
const responseSchema = Type . Object ( {
@@ -52,37 +50,75 @@ const responseSchema = Type.Object({
52
50
} ) ,
53
51
types : Type . Any ( ) ,
54
52
message : Type . Any ( ) ,
53
+ primaryType : Type . String ( ) ,
55
54
} ) ,
56
55
} ) ,
57
56
} ) ;
58
57
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
+
59
77
responseSchema . example = {
60
78
result : {
61
79
mintPayload : {
62
- to : "0x1946267d81Fb8aDeeEa28e6B98bcD446c8248473 " ,
80
+ to : "0x... " ,
63
81
price : "0" ,
64
- currencyAddress : "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee " ,
82
+ currencyAddress : "0x... " ,
65
83
mintStartTime : "1704664293" ,
66
84
mintEndTime : "1751925093" ,
67
- uid : "0x3732346162373763346432663433333462383134353662343761373166636239 " ,
68
- primarySaleRecipient : "0x0000000000000000000000000000000000000000 " ,
85
+ uid : "0x... " ,
86
+ primarySaleRecipient : "0x... " ,
69
87
metadata : {
70
88
name : "test token" ,
71
89
description : "test token" ,
72
90
} ,
73
- royaltyRecipient : "0x0000000000000000000000000000000000000000 " ,
91
+ royaltyRecipient : "0x... " ,
74
92
royaltyBps : "0" ,
75
93
quantity : "1" ,
76
- uri : "ipfs://Qmaf55psrmeckXZ6yo4DTL7fUYeMR4t6XArY5NgMrKN9VA/0 " ,
94
+ uri : "ipfs://... " ,
77
95
} ,
78
96
typedDataPayload : {
79
97
domain : {
80
98
name : "TokenERC721" ,
81
99
version : "1" ,
82
100
chainId : 84532 ,
83
- verifyingContract : "0x9ca57B9341dCB029a5b11163C9a47FB65BA6F4c3 " ,
101
+ verifyingContract : "0x... " ,
84
102
} ,
85
103
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
+ ] ,
86
122
MintRequest : [
87
123
{
88
124
name : "to" ,
@@ -127,17 +163,18 @@ responseSchema.example = {
127
163
] ,
128
164
} ,
129
165
message : {
130
- to : "0x1946267d81Fb8aDeeEa28e6B98bcD446c8248473 " ,
131
- royaltyRecipient : "0x0000000000000000000000000000000000000000 " ,
166
+ to : "0x... " ,
167
+ royaltyRecipient : "0x... " ,
132
168
royaltyBps : "0" ,
133
- primarySaleRecipient : "0x0000000000000000000000000000000000000000 " ,
169
+ primarySaleRecipient : "0x... " ,
134
170
price : "0" ,
135
- uri : "ipfs://Qmaf55psrmeckXZ6yo4DTL7fUYeMR4t6XArY5NgMrKN9VA/0 " ,
136
- currency : "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee " ,
171
+ uri : "ipfs://... " ,
172
+ currency : "0x... " ,
137
173
validityEndTimestamp : "1751925093" ,
138
174
validityStartTimestamp : "1704664293" ,
139
- uid : "0x3732346162373763346432663433333462383134353662343761373166636239 " ,
175
+ uid : "0x... " ,
140
176
} ,
177
+ primaryType : "MintRequest" ,
141
178
} ,
142
179
} ,
143
180
} ;
@@ -176,7 +213,6 @@ export async function erc721SignaturePrepare(fastify: FastifyInstance) {
176
213
quantity,
177
214
royaltyBps,
178
215
royaltyRecipient,
179
- uid,
180
216
} = request . body ;
181
217
182
218
const chainId = await getChainIdFromChain ( chain ) ;
@@ -202,7 +238,6 @@ export async function erc721SignaturePrepare(fastify: FastifyInstance) {
202
238
quantity,
203
239
royaltyBps,
204
240
royaltyRecipient,
205
- uid,
206
241
} ) ;
207
242
208
243
const uri = await uploadOrExtractURI ( metadata , storage ) ;
@@ -219,7 +254,10 @@ export async function erc721SignaturePrepare(fastify: FastifyInstance) {
219
254
220
255
// Build the data fields needed to be signed by a minter wallet.
221
256
let domain ;
222
- let types ;
257
+
258
+ let types : Record < string , Array < TypedDataField > > = {
259
+ EIP712Domain : EIP721DomainTypes ,
260
+ } ;
223
261
let message :
224
262
| ISignatureMintERC721 . MintRequestStructOutput
225
263
| ITokenERC721 . MintRequestStructOutput ;
@@ -231,7 +269,10 @@ export async function erc721SignaturePrepare(fastify: FastifyInstance) {
231
269
chainId,
232
270
verifyingContract : contractAddress ,
233
271
} ;
234
- types = { MintRequest : MintRequest721 } ;
272
+ types = {
273
+ ...types ,
274
+ MintRequest : MintRequest721 ,
275
+ } ;
235
276
message = mapLegacyPayloadToContractStruct ( mintPayload ) ;
236
277
sanitizedMessage = {
237
278
...message ,
@@ -247,7 +288,10 @@ export async function erc721SignaturePrepare(fastify: FastifyInstance) {
247
288
chainId,
248
289
verifyingContract : contractAddress ,
249
290
} ;
250
- types = { MintRequest : MintRequest721withQuantity } ;
291
+ types = {
292
+ ...types ,
293
+ MintRequest : MintRequest721withQuantity ,
294
+ } ;
251
295
message = mapPayloadToContractStruct ( mintPayload ) ;
252
296
sanitizedMessage = {
253
297
...message ,
@@ -272,6 +316,7 @@ export async function erc721SignaturePrepare(fastify: FastifyInstance) {
272
316
domain,
273
317
types,
274
318
message : sanitizedMessage ,
319
+ primaryType : "MintRequest" ,
275
320
} ,
276
321
} ,
277
322
} ) ;
0 commit comments