Skip to content

Commit d8951fa

Browse files
authored
fix: Support arbitrary-length UIDs for ERC721 signature prepare (#740)
* fix: Support arbitrary-length UID in ERC721 signature prepare * fix tests
1 parent c73c18d commit d8951fa

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ import { Type, type Static } from "@sinclair/typebox";
22
import { MintRequest721 } from "@thirdweb-dev/sdk";
33
import type { FastifyInstance } from "fastify";
44
import { StatusCodes } from "http-status-codes";
5-
import { getRandomValues } from "node:crypto";
5+
import { createHash, getRandomValues } from "node:crypto";
66
import {
77
ZERO_ADDRESS,
88
getContract,
99
isHex,
10-
stringToHex,
1110
uint8ArrayToHex,
1211
type Hex,
1312
} from "thirdweb";
@@ -286,7 +285,7 @@ export async function erc721SignaturePrepare(fastify: FastifyInstance) {
286285
}
287286
parsedUid = uid;
288287
} else {
289-
parsedUid = stringToHex(uid, { size: 32 });
288+
parsedUid = `0x${createHash("sha256").update(uid).digest("hex")}`;
290289
}
291290
} else {
292291
parsedUid = uint8ArrayToHex(getRandomValues(new Uint8Array(32)));

test/e2e/tests/routes/signaturePrepare.test.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ describe("signaturePrepareRoute", () => {
55
test("Prepare a signature with upload, no uid, no royalty/sale recipients", async () => {
66
const { engine, backendWallet } = await setup();
77

8-
const res = await engine.erc721.erc721SignaturePrepare(
8+
const res = await engine.erc721.signaturePrepare(
99
"84532",
1010
"0x5002e3bF97F376Fe0480109e26c0208786bCDDd4",
1111
{
@@ -138,7 +138,7 @@ describe("signaturePrepareRoute", () => {
138138
test("Prepare a signature with provided hex uid", async () => {
139139
const { engine, backendWallet } = await setup();
140140

141-
const res = await engine.erc721.erc721SignaturePrepare(
141+
const res = await engine.erc721.signaturePrepare(
142142
"84532",
143143
"0x5002e3bF97F376Fe0480109e26c0208786bCDDd4",
144144
{
@@ -153,31 +153,25 @@ describe("signaturePrepareRoute", () => {
153153
expect(res.result.mintPayload.uid).toEqual(
154154
"0x25d29226fc7c310ed308c1eea8a3ed2d9f660d873ba6348b6649da4cae3877a4",
155155
);
156-
expect(res.result.mintPayload.uid).toEqual(
157-
"0x25d29226fc7c310ed308c1eea8a3ed2d9f660d873ba6348b6649da4cae3877a4",
158-
);
159156
});
160157

161158
test("Prepare a signature with string uid", async () => {
162159
const { engine, backendWallet } = await setup();
163160

164-
const res = await engine.erc721.erc721SignaturePrepare(
161+
const res = await engine.erc721.signaturePrepare(
165162
"84532",
166163
"0x5002e3bF97F376Fe0480109e26c0208786bCDDd4",
167164
{
168165
metadata: "ipfs://...",
169166
validityEndTimestamp: 1729194714,
170167
validityStartTimestamp: 1728589914,
171168
to: backendWallet,
172-
uid: "my-test-uuid",
169+
uid: "my-really-long-test-uuid-my-really-long-test-uuid-my-really-long-test-uuid",
173170
},
174171
);
175172

176173
expect(res.result.mintPayload.uid).toEqual(
177-
"0x6d792d746573742d757569640000000000000000000000000000000000000000",
178-
);
179-
expect(res.result.mintPayload.uid).toEqual(
180-
"0x6d792d746573742d757569640000000000000000000000000000000000000000",
174+
"0xa74a3badce5090a5afead99c9d80e08169468a2442a6f79692001aed81acf2bc",
181175
);
182176
});
183177

@@ -186,7 +180,7 @@ describe("signaturePrepareRoute", () => {
186180

187181
let threw = false;
188182
try {
189-
await engine.erc721.erc721SignaturePrepare(
183+
await engine.erc721.signaturePrepare(
190184
"84532",
191185
"0x5002e3bF97F376Fe0480109e26c0208786bCDDd4",
192186
{

0 commit comments

Comments
 (0)