Skip to content

Commit

Permalink
Merge pull request #143 from AElfProject/release/v3.4.5
Browse files Browse the repository at this point in the history
feat: verify pubKey deprecatedParam
  • Loading branch information
hzz780 committed Feb 26, 2024
2 parents 4c2971b + ee2d12a commit 3b927d1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aelf-sdk",
"version": "3.4.4",
"version": "3.4.5",
"description": "aelf-sdk js library",
"main": "dist/aelf.cjs.js",
"browser": "dist/aelf.umd.js",
Expand Down
21 changes: 20 additions & 1 deletion src/wallet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ const sign = (hexString, keyPair) => {
return getSignature(bytesToBeSign, keyPair);
};

const hexToDecimal = x => ellipticEc.keyFromPrivate(x, "hex").getPrivate().toString(10);

/**
* @param {string} signature Signature
* @param {string} msgHash Message for signing
* @param {string} pubKey deprecatedParam - This parameter is deprecated.
*/
const verify = (signature, msgHash, pubKey) => {
const rHex = signature.substring(0, 64);
const sHex = signature.substring(64, 128);
Expand All @@ -262,7 +269,19 @@ const verify = (signature, msgHash, pubKey) => {
s: new BN(sHex, 16),
recoveryParam: recoveryParamHex.slice(1),
};
return ellipticEc.verify(msgHash, sigObj, Buffer.from(pubKey, "hex"));
let publicKey;
if (!pubKey) {
const key = ellipticEc.recoverPubKey(
hexToDecimal(msgHash),
sigObj,
+sigObj.recoveryParam,
"hex"
);
publicKey = ellipticEc.keyFromPublic(key).getPublic("hex");
} else {
publicKey = pubKey;
}
return ellipticEc.verify(msgHash, sigObj, Buffer.from(publicKey, "hex"));
};

export default {
Expand Down

0 comments on commit 3b927d1

Please sign in to comment.