Skip to content

Commit c88137a

Browse files
authored
Update typed message (#88)
* Refactor buildTypedData function to accept a Record type for value parameter. Implement new endpoint for setting text records with enhanced validation for name, key, and value fields. Update existing routes to accommodate new data structure and validation logic. * buildTypedData updated now handle EIP712Domain and primaryType for more strict signers
1 parent 0483ce4 commit c88137a

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

clk-gateway/src/helpers.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,17 @@ export function buildTypedData(
377377
chainId: Number(process.env.L2_CHAIN_ID!),
378378
};
379379

380-
return { types, domain, value };
380+
const domainTypes = {
381+
EIP712Domain: [
382+
{ name: "name", type: "string" },
383+
{ name: "version", type: "string" },
384+
{ name: "chainId", type: "uint256" },
385+
],
386+
};
387+
388+
const primaryType = Object.keys(types)?.[0] || "Transaction";
389+
390+
return { types: { ...domainTypes, ...types }, domain, value, primaryType };
381391
}
382392

383393
/**

clk-gateway/src/routes/names.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ router.post(
9797
);
9898
}
9999
const data = matchedData(req);
100-
const [name, sub] = data.name.split(".");
100+
const [name, sub, tld] = data.name.split(".");
101101
const owner = getAddress(data.owner);
102102

103103
const typedData = buildTypedData({
104104
name: data.name,
105-
email: data.email,
105+
email: data.email || "example@not-valid.com",
106106
});
107107

108108
const isValidSignature = validateSignature({
@@ -140,6 +140,7 @@ router.post(
140140
.setCustomUserClaims(decodedToken.uid, { subDomain: sub }); */
141141
res.status(200).send({
142142
txHash: receipt.hash,
143+
name: `${name}.${sub}.${tld}`,
143144
});
144145
})
145146
);
@@ -278,6 +279,8 @@ router.post(
278279

279280
res.status(200).send({
280281
txHash: receipt.hash,
282+
key: data.key,
283+
value: data.value,
281284
});
282285
})
283286
);
@@ -425,7 +428,7 @@ router.post(
425428

426429
const typedData = buildTypedData({
427430
name: data.name,
428-
email: data.email,
431+
email: data.email || "example@not-valid.com",
429432
});
430433

431434
res.status(200).send({

0 commit comments

Comments
 (0)