Skip to content

Commit

Permalink
rename TypedDataUtils.sign to TypedDataUtils.eip712Hash
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwinYardi authored and Gudahtt committed Jul 13, 2021
1 parent efcc5f3 commit 259a48a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@ const TypedDataUtils = {
/**
* Signs a typed message as per EIP-712 and returns its keccak hash
*
* @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 @@ -672,7 +672,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 @@ -766,7 +766,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 @@ -923,7 +923,7 @@ test('signedTypeData_v4', (t) => {
'0xf2cee375fa42b42143804025fc449deafd50cc031ca257e0b194a650a912090f'
);
t.equal(
ethUtil.bufferToHex(utils.sign(typedData)),
ethUtil.bufferToHex(utils.eip712Hash(typedData)),
'0xa85c2e2b118698e88db68a8105b794a8cc7cec074e89ef991cb4f5f533819cc2'
);

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

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

Expand Down

0 comments on commit 259a48a

Please sign in to comment.