Skip to content

Commit

Permalink
fix message parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
arch1995 committed Feb 13, 2024
1 parent 08aee27 commit 30b657a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,18 @@ export const isValidSignature = (data: SetDataInput) => {
r: Buffer.from(decodedSignature.substring(0, 64), "hex"),
s: Buffer.from(decodedSignature.substring(64, 128), "hex"),
};
return elliptic.verify(keccak256(stringify(setData)), ecSignature, pubKey);
// this is to ensure that the signature is valid for both JSON and stringified data
// and for backward compatibility.
const result1 = elliptic.verify(keccak256(stringify(setData)), ecSignature, pubKey);
if (result1) return true;
return elliptic.verify(keccak256(JSON.stringify(setData)), ecSignature, pubKey);
};

export const isValidLockSignature = (lockData: LockDataInput) => {
const { key, signature, data } = lockData;
return elliptic.verify(keccak256(stringify(data)), signature, Buffer.from(key, "hex"));
// this is to ensure that the signature is valid for both JSON and stringified data
// and for backward compatibility.
const result = elliptic.verify(keccak256(Buffer.from(stringify(data), "utf8")), signature, Buffer.from(key, "hex"));
if (result) return result;
return elliptic.verify(keccak256(Buffer.from(JSON.stringify(data), "utf8")), signature, Buffer.from(key, "hex"));
};

0 comments on commit 30b657a

Please sign in to comment.