-
Ethers Version5.2.0 Search TermsNo response Describe the Problemethers cannot differentiate between two EIP712 types Code Snippetexport const EIP712_TYPES = {
Delegation: [
{ name: "delegate", type: "address" },
{ name: "type", type: "string" },
{ name: "timestamp", type: "uint256" },
],
Message: [
{ name: "title", type: "string" },
{ name: "href", type: "string" },
{ name: "type", type: "string" },
{ name: "timestamp", type: "uint256" },
],
};
export async function sign(signer, message) {
const signature = await signer._signTypedData(EIP712_DOMAIN, EIP712_TYPES, message);
return {
...message,
signature,
};
}
test("timestamp minimum value", async (t) => {
const address = "0x0f6A79A579658E401E0B81c6dde1F2cd51d97176";
// NOTE: Don't worry this pk is online in my other repos too
const privateKey =
"0xad54bdeade5537fb0a553190159783e45d02d316a992db05cbed606d3ca36b39";
const signer = new Wallet(privateKey);
t.is(signer.address, address);
env.MIN_TIMESTAMP_SECS = 1672527600;
const text = "hello world";
const href = "https://example.com";
const type = "amplify";
const timestamp = env.MIN_TIMESTAMP_SECS - 1;
const message = create(text, href, type, timestamp);
const signedMessage = await sign(signer, message);
t.deepEqual(signedMessage, {
...message,
signature:
"0x1df128dfe1f86df4e20ecc6ebbd586e0ab56e3fc8d0db9210422c3c765633ad8793af68aa232cf39cc3f75ea18f03260258f7276c2e0d555f98e1cf16672dd201c",
});
t.throws(() => verify(signedMessage));
});
|
Beta Was this translation helpful? Give feedback.
Answered by
ricmoo
Apr 25, 2023
Replies: 1 comment
-
That's a feature, not a bug. :) It doesn't let you put elements which will be discarded, which happens in the case of an ambiguous primary type. Since Message doesn't include a Delegation and delegation doesn't contain a Message, they can't possibly be part of the same message. If you have multiple types, they must form a DAG, of which the root of the DAG is used as the primary type. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
TimDaub
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's a feature, not a bug. :)
It doesn't let you put elements which will be discarded, which happens in the case of an ambiguous primary type.
Since Message doesn't include a Delegation and delegation doesn't contain a Message, they can't possibly be part of the same message. If you have multiple types, they must form a DAG, of which the root of the DAG is used as the primary type.