Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix eip712Hash tests that included data #184

Merged
merged 2 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`TypedDataUtils.eip712Hash V3 should hash a minimal valid typed message

exports[`TypedDataUtils.eip712Hash V3 should hash a typed message with a domain separator that uses all fields 1`] = `"54ffed5209a17ac210ef3823740b3852ee9cd518b84ee39f0a3fa7f2f9b4205b"`;

exports[`TypedDataUtils.eip712Hash V3 should hash a typed message with data 1`] = `"54ffed5209a17ac210ef3823740b3852ee9cd518b84ee39f0a3fa7f2f9b4205b"`;
exports[`TypedDataUtils.eip712Hash V3 should hash a typed message with data 1`] = `"d2669f23b7849020ad41bcbff5b51372793f91320e0f901641945568ed7322be"`;

exports[`TypedDataUtils.eip712Hash V3 should hash a typed message with extra domain seperator fields 1`] = `"2323c742c20093ee44c2a0abef2b950062a3d70b3453ef4995a072dba9e47d7d"`;

Expand All @@ -14,7 +14,7 @@ exports[`TypedDataUtils.eip712Hash V4 should hash a minimal valid typed message

exports[`TypedDataUtils.eip712Hash V4 should hash a typed message with a domain separator that uses all fields. 1`] = `"54ffed5209a17ac210ef3823740b3852ee9cd518b84ee39f0a3fa7f2f9b4205b"`;

exports[`TypedDataUtils.eip712Hash V4 should hash a typed message with data 1`] = `"54ffed5209a17ac210ef3823740b3852ee9cd518b84ee39f0a3fa7f2f9b4205b"`;
exports[`TypedDataUtils.eip712Hash V4 should hash a typed message with data 1`] = `"d2669f23b7849020ad41bcbff5b51372793f91320e0f901641945568ed7322be"`;

exports[`TypedDataUtils.eip712Hash V4 should hash a typed message with extra domain seperator fields 1`] = `"2323c742c20093ee44c2a0abef2b950062a3d70b3453ef4995a072dba9e47d7d"`;

Expand Down
178 changes: 176 additions & 2 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3307,7 +3307,7 @@ describe('TypedDataUtils.eip712Hash', function () {
],
Message: [{ name: 'data', type: 'string' }],
},
primaryType: 'EIP712Domain',
primaryType: 'Message',
domain: {
name: 'example.metamask.io',
version: '1',
Expand All @@ -3324,6 +3324,93 @@ describe('TypedDataUtils.eip712Hash', function () {

expect(hash.toString('hex')).toMatchSnapshot();
});

it('should ignore message if the primary type is EIP712Domain', function () {
const hashWithMessage = sigUtil.TypedDataUtils.eip712Hash(
{
types: {
EIP712Domain: [
{
name: 'name',
type: 'string',
},
{
name: 'version',
type: 'string',
},
{
name: 'chainId',
type: 'uint256',
},
{
name: 'verifyingContract',
type: 'address',
},
{
name: 'salt',
type: 'bytes32',
},
],
Message: [{ name: 'data', type: 'string' }],
},
primaryType: 'EIP712Domain',
domain: {
name: 'example.metamask.io',
version: '1',
chainId: 1,
verifyingContract: '0x0000000000000000000000000000000000000000',
salt: Buffer.from(new Int32Array([1, 2, 3])),
},
message: {
data: 'Hello!',
},
},
'V3',
);
const hashWithoutMessage = sigUtil.TypedDataUtils.eip712Hash(
{
types: {
EIP712Domain: [
{
name: 'name',
type: 'string',
},
{
name: 'version',
type: 'string',
},
{
name: 'chainId',
type: 'uint256',
},
{
name: 'verifyingContract',
type: 'address',
},
{
name: 'salt',
type: 'bytes32',
},
],
Message: [{ name: 'data', type: 'string' }],
},
primaryType: 'EIP712Domain',
domain: {
name: 'example.metamask.io',
version: '1',
chainId: 1,
verifyingContract: '0x0000000000000000000000000000000000000000',
salt: Buffer.from(new Int32Array([1, 2, 3])),
},
message: {},
},
'V3',
);

expect(hashWithMessage.toString('hex')).toBe(
hashWithoutMessage.toString('hex'),
);
});
});

describe('V4', function () {
Expand Down Expand Up @@ -3572,7 +3659,7 @@ describe('TypedDataUtils.eip712Hash', function () {
],
Message: [{ name: 'data', type: 'string' }],
},
primaryType: 'EIP712Domain',
primaryType: 'Message',
domain: {
name: 'example.metamask.io',
version: '1',
Expand All @@ -3589,6 +3676,93 @@ describe('TypedDataUtils.eip712Hash', function () {

expect(hash.toString('hex')).toMatchSnapshot();
});

it('should ignore message if the primary type is EIP712Domain', function () {
const hashWithMessage = sigUtil.TypedDataUtils.eip712Hash(
{
types: {
EIP712Domain: [
{
name: 'name',
type: 'string',
},
{
name: 'version',
type: 'string',
},
{
name: 'chainId',
type: 'uint256',
},
{
name: 'verifyingContract',
type: 'address',
},
{
name: 'salt',
type: 'bytes32',
},
],
Message: [{ name: 'data', type: 'string' }],
},
primaryType: 'EIP712Domain',
domain: {
name: 'example.metamask.io',
version: '1',
chainId: 1,
verifyingContract: '0x0000000000000000000000000000000000000000',
salt: Buffer.from(new Int32Array([1, 2, 3])),
},
message: {
data: 'Hello!',
},
},
'V4',
);
const hashWithoutMessage = sigUtil.TypedDataUtils.eip712Hash(
{
types: {
EIP712Domain: [
{
name: 'name',
type: 'string',
},
{
name: 'version',
type: 'string',
},
{
name: 'chainId',
type: 'uint256',
},
{
name: 'verifyingContract',
type: 'address',
},
{
name: 'salt',
type: 'bytes32',
},
],
Message: [{ name: 'data', type: 'string' }],
},
primaryType: 'EIP712Domain',
domain: {
name: 'example.metamask.io',
version: '1',
chainId: 1,
verifyingContract: '0x0000000000000000000000000000000000000000',
salt: Buffer.from(new Int32Array([1, 2, 3])),
},
message: {},
},
'V4',
);

expect(hashWithMessage.toString('hex')).toBe(
hashWithoutMessage.toString('hex'),
);
});
});
});

Expand Down