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

rename TypedDataUtils.sign to TypedDataUtils.eip712Hash #104

Merged
merged 2 commits into from
Jul 13, 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
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,10 @@ const TypedDataUtils = {
/**
* Signs a typed message as per EIP-712 and returns its keccak hash
Copy link
Member

Choose a reason for hiding this comment

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

Some of these other inline docs could use improvements too, but I can do that in a separate PR

*
* @param {Object} typedData - Types message data to sign
* @param {Object} typedData - Types message data to hash as per eip-712
* @returns {Buffer} - keccak hash of the resulting signed message
*/
sign<T extends MessageTypes>(
eip712Hash<T extends MessageTypes>(
typedData: Partial<TypedData | TypedMessage<T>>,
useV4 = true,
): Buffer {
Expand Down Expand Up @@ -597,7 +597,7 @@ function signTypedData<T extends MessageTypes>(
privateKey: Buffer,
msgParams: MsgParams<TypedData | TypedMessage<T>>,
): string {
const message = TypedDataUtils.sign(msgParams.data, false);
const message = TypedDataUtils.eip712Hash(msgParams.data, false);
const sig = ethUtil.ecsign(message, privateKey);
return ethUtil.bufferToHex(concatSig(sig.v, sig.r, sig.s));
}
Expand All @@ -606,15 +606,15 @@ function signTypedData_v4<T extends MessageTypes>(
privateKey: Buffer,
msgParams: MsgParams<TypedData | TypedMessage<T>>,
): string {
const message = TypedDataUtils.sign(msgParams.data);
const message = TypedDataUtils.eip712Hash(msgParams.data);
const sig = ethUtil.ecsign(message, privateKey);
return ethUtil.bufferToHex(concatSig(sig.v, sig.r, sig.s));
}

function recoverTypedSignature<T extends MessageTypes>(
msgParams: SignedMsgParams<TypedData | TypedMessage<T>>,
): string {
const message = TypedDataUtils.sign(msgParams.data, false);
const message = TypedDataUtils.eip712Hash(msgParams.data, false);
const publicKey = recoverPublicKey(message, msgParams.sig);
const sender = ethUtil.publicToAddress(publicKey);
return ethUtil.bufferToHex(sender);
Expand All @@ -623,7 +623,7 @@ function recoverTypedSignature<T extends MessageTypes>(
function recoverTypedSignature_v4<T extends MessageTypes>(
msgParams: SignedMsgParams<TypedData | TypedMessage<T>>,
): string {
const message = TypedDataUtils.sign(msgParams.data);
const message = TypedDataUtils.eip712Hash(msgParams.data);
const publicKey = recoverPublicKey(message, msgParams.sig);
const sender = ethUtil.publicToAddress(publicKey);
return ethUtil.bufferToHex(sender);
Expand Down
14 changes: 7 additions & 7 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ test('signedTypeData', (t) => {
'0xf2cee375fa42b42143804025fc449deafd50cc031ca257e0b194a650a912090f',
);
t.equal(
ethUtil.bufferToHex(utils.sign(typedData)),
ethUtil.bufferToHex(utils.eip712Hash(typedData)),
'0xbe609aee343fb3c4b28e1df9e632fca64fcfaede20f02e86244efddf30957bd2',
);
t.equal(
Expand Down Expand Up @@ -673,7 +673,7 @@ test('signedTypeData with bytes', (t) => {
'0xf2cee375fa42b42143804025fc449deafd50cc031ca257e0b194a650a912090f',
);
t.equal(
ethUtil.bufferToHex(utils.sign(typedDataWithBytes)),
ethUtil.bufferToHex(utils.eip712Hash(typedDataWithBytes)),
'0xb4aaf457227fec401db772ec22d2095d1235ee5d0833f56f59108c9ffc90fb4b',
);
t.equal(
Expand Down Expand Up @@ -767,7 +767,7 @@ test('signedTypeData with V3 string', (t) => {
'0xf2cee375fa42b42143804025fc449deafd50cc031ca257e0b194a650a912090f',
);
t.equal(
ethUtil.bufferToHex(utils.sign(typedData)),
ethUtil.bufferToHex(utils.eip712Hash(typedData)),
'0xbe609aee343fb3c4b28e1df9e632fca64fcfaede20f02e86244efddf30957bd2',
);
t.equal(
Expand Down Expand Up @@ -924,7 +924,7 @@ test('signedTypeData_v4', (t) => {
'0xf2cee375fa42b42143804025fc449deafd50cc031ca257e0b194a650a912090f',
);
t.equal(
ethUtil.bufferToHex(utils.sign(typedData)),
ethUtil.bufferToHex(utils.eip712Hash(typedData)),
'0xa85c2e2b118698e88db68a8105b794a8cc7cec074e89ef991cb4f5f533819cc2',
);

Expand Down Expand Up @@ -1088,7 +1088,7 @@ test('signedTypeData_v4', (t) => {
'0xf2cee375fa42b42143804025fc449deafd50cc031ca257e0b194a650a912090f',
);
t.equal(
ethUtil.bufferToHex(utils.sign(typedData)),
ethUtil.bufferToHex(utils.eip712Hash(typedData)),
'0xa85c2e2b118698e88db68a8105b794a8cc7cec074e89ef991cb4f5f533819cc2',
);

Expand Down Expand Up @@ -1229,7 +1229,7 @@ test('signedTypeData_v4 with recursive types', (t) => {
'0xfacb2c1888f63a780c84c216bd9a81b516fc501a19bae1fc81d82df590bbdc60',
);
t.equal(
ethUtil.bufferToHex(utils.sign(typedData)),
ethUtil.bufferToHex(utils.eip712Hash(typedData)),
'0x807773b9faa9879d4971b43856c4d60c2da15c6f8c062bd9d33afefb756de19c',
);

Expand Down Expand Up @@ -1370,7 +1370,7 @@ test('signedTypeMessage V4 with recursive types', (t) => {
'0xfacb2c1888f63a780c84c216bd9a81b516fc501a19bae1fc81d82df590bbdc60',
);
t.equal(
ethUtil.bufferToHex(utils.sign(typedData)),
ethUtil.bufferToHex(utils.eip712Hash(typedData)),
'0x807773b9faa9879d4971b43856c4d60c2da15c6f8c062bd9d33afefb756de19c',
);

Expand Down