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

Add salt to the EIP-712 domain type #176

Merged
merged 1 commit into from
Aug 16, 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
16 changes: 8 additions & 8 deletions src/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

exports[`TypedDataUtils.eip712Hash V3 should hash a minimal valid typed message 1`] = `"8d4a3f4082945b7879e2b55f181c31a77c8c0a464b70669458abbaaf99de4c38"`;

exports[`TypedDataUtils.eip712Hash V3 should hash a typed message with a domain separator that uses all fields 1`] = `"122d1c8ef94b76dad44dcb03fa772361e20855c63311a15d5afe02d1b38f6077"`;
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`] = `"122d1c8ef94b76dad44dcb03fa772361e20855c63311a15d5afe02d1b38f6077"`;
exports[`TypedDataUtils.eip712Hash V3 should hash a typed message with data 1`] = `"54ffed5209a17ac210ef3823740b3852ee9cd518b84ee39f0a3fa7f2f9b4205b"`;

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

exports[`TypedDataUtils.eip712Hash V3 should hash a typed message with only custom domain seperator fields 1`] = `"8e713ff4064ccd8d5cf047d72d1417ba966ed0a4df27251e36aae310414a59b6"`;
exports[`TypedDataUtils.eip712Hash V3 should hash a typed message with only custom domain seperator fields 1`] = `"3efa3ef0305f56ba5bba62000500e29fe82c5314bca2f958c64e31b2498560f8"`;

exports[`TypedDataUtils.eip712Hash V4 should hash a minimal valid typed message 1`] = `"8d4a3f4082945b7879e2b55f181c31a77c8c0a464b70669458abbaaf99de4c38"`;

exports[`TypedDataUtils.eip712Hash V4 should hash a typed message with a domain separator that uses all fields. 1`] = `"122d1c8ef94b76dad44dcb03fa772361e20855c63311a15d5afe02d1b38f6077"`;
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`] = `"122d1c8ef94b76dad44dcb03fa772361e20855c63311a15d5afe02d1b38f6077"`;
exports[`TypedDataUtils.eip712Hash V4 should hash a typed message with data 1`] = `"54ffed5209a17ac210ef3823740b3852ee9cd518b84ee39f0a3fa7f2f9b4205b"`;

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

exports[`TypedDataUtils.eip712Hash V4 should hash a typed message with only custom domain seperator fields 1`] = `"8e713ff4064ccd8d5cf047d72d1417ba966ed0a4df27251e36aae310414a59b6"`;
exports[`TypedDataUtils.eip712Hash V4 should hash a typed message with only custom domain seperator fields 1`] = `"3efa3ef0305f56ba5bba62000500e29fe82c5314bca2f958c64e31b2498560f8"`;

exports[`TypedDataUtils.encodeData V3 example data type "address" should encode "0x0" (type "string") 1`] = `"c92db6bca97089c40b3f6512400e065cf2c27db90a50ce13440d951b13ada2990000000000000000000000000000000000000000000000000000000000000000"`;

Expand Down
40 changes: 40 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3160,6 +3160,10 @@ describe('TypedDataUtils.eip712Hash', function () {
name: 'verifyingContract',
type: 'address',
},
{
name: 'salt',
type: 'bytes32',
},
],
},
primaryType: 'EIP712Domain',
Expand All @@ -3168,6 +3172,7 @@ describe('TypedDataUtils.eip712Hash', function () {
version: '1',
chainId: 1,
verifyingContract: '0x0000000000000000000000000000000000000000',
salt: Buffer.from(new Int32Array([1, 2, 3])),
},
message: {},
},
Expand Down Expand Up @@ -3198,6 +3203,10 @@ describe('TypedDataUtils.eip712Hash', function () {
name: 'verifyingContract',
type: 'address',
},
{
name: 'salt',
type: 'bytes32',
},
{
name: 'extraField',
type: 'string',
Expand All @@ -3210,6 +3219,7 @@ describe('TypedDataUtils.eip712Hash', function () {
version: '1',
chainId: 1,
verifyingContract: '0x0000000000000000000000000000000000000000',
salt: Buffer.from(new Int32Array([1, 2, 3])),
extraField: 'stuff',
},
message: {},
Expand Down Expand Up @@ -3241,6 +3251,10 @@ describe('TypedDataUtils.eip712Hash', function () {
name: 'customVerifyingContract',
type: 'address',
},
{
name: 'customSalt',
type: 'bytes32',
},
{
name: 'extraField',
type: 'string',
Expand All @@ -3254,6 +3268,7 @@ describe('TypedDataUtils.eip712Hash', function () {
customChainId: 1,
customVerifyingContract:
'0x0000000000000000000000000000000000000000',
customSalt: Buffer.from(new Int32Array([1, 2, 3])),
extraField: 'stuff',
},
message: {},
Expand Down Expand Up @@ -3285,6 +3300,10 @@ describe('TypedDataUtils.eip712Hash', function () {
name: 'verifyingContract',
type: 'address',
},
{
name: 'salt',
type: 'bytes32',
},
],
Message: [{ name: 'data', type: 'string' }],
},
Expand All @@ -3294,6 +3313,7 @@ describe('TypedDataUtils.eip712Hash', function () {
version: '1',
chainId: 1,
verifyingContract: '0x0000000000000000000000000000000000000000',
salt: Buffer.from(new Int32Array([1, 2, 3])),
},
message: {
data: 'Hello!',
Expand Down Expand Up @@ -3405,6 +3425,10 @@ describe('TypedDataUtils.eip712Hash', function () {
name: 'verifyingContract',
type: 'address',
},
{
name: 'salt',
type: 'bytes32',
},
],
},
primaryType: 'EIP712Domain',
Expand All @@ -3413,6 +3437,7 @@ describe('TypedDataUtils.eip712Hash', function () {
version: '1',
chainId: 1,
verifyingContract: '0x0000000000000000000000000000000000000000',
salt: Buffer.from(new Int32Array([1, 2, 3])),
},
message: {},
},
Expand Down Expand Up @@ -3443,6 +3468,10 @@ describe('TypedDataUtils.eip712Hash', function () {
name: 'verifyingContract',
type: 'address',
},
{
name: 'salt',
type: 'bytes32',
},
{
name: 'extraField',
type: 'string',
Expand All @@ -3455,6 +3484,7 @@ describe('TypedDataUtils.eip712Hash', function () {
version: '1',
chainId: 1,
verifyingContract: '0x0000000000000000000000000000000000000000',
salt: Buffer.from(new Int32Array([1, 2, 3])),
extraField: 'stuff',
},
message: {},
Expand Down Expand Up @@ -3486,6 +3516,10 @@ describe('TypedDataUtils.eip712Hash', function () {
name: 'customVerifyingContract',
type: 'address',
},
{
name: 'customSalt',
type: 'bytes32',
},
{
name: 'extraField',
type: 'string',
Expand All @@ -3499,6 +3533,7 @@ describe('TypedDataUtils.eip712Hash', function () {
customChainId: 1,
customVerifyingContract:
'0x0000000000000000000000000000000000000000',
customSalt: Buffer.from(new Int32Array([1, 2, 3])),
extraField: 'stuff',
},
message: {},
Expand Down Expand Up @@ -3530,6 +3565,10 @@ describe('TypedDataUtils.eip712Hash', function () {
name: 'verifyingContract',
type: 'address',
},
{
name: 'salt',
type: 'bytes32',
},
],
Message: [{ name: 'data', type: 'string' }],
},
Expand All @@ -3539,6 +3578,7 @@ describe('TypedDataUtils.eip712Hash', function () {
version: '1',
chainId: 1,
verifyingContract: '0x0000000000000000000000000000000000000000',
salt: Buffer.from(new Int32Array([1, 2, 3])),
},
message: {
data: 'Hello!',
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface TypedMessage<T extends MessageTypes> {
version?: string;
chainId?: number;
verifyingContract?: string;
salt?: ArrayBuffer;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose ArrayBuffer for the expected type because it seemed like the most reasonable way to communicate raw bytes, since it's the underlying data structure for typed arrays. This is the only cross-platform way to represent bytes I think 🤔.

};
message: Record<string, unknown>;
}
Expand Down